File tree Expand file tree Collapse file tree 2 files changed +5
-22
lines changed
aima-core/src/main/java/aima/core/search/csp Expand file tree Collapse file tree 2 files changed +5
-22
lines changed Original file line number Diff line number Diff line change @@ -73,13 +73,11 @@ public Assignment<VAR, VAL> clone() {
7373
7474 @ Override
7575 public String toString () {
76- boolean comma = false ;
7776 StringBuilder result = new StringBuilder ("{" );
7877 for (Map .Entry <VAR , VAL > entry : variableToValueMap .entrySet ()) {
79- if (comma )
78+ if (result . length () > 1 )
8079 result .append (", " );
8180 result .append (entry .getKey ()).append ("=" ).append (entry .getValue ());
82- comma = true ;
8381 }
8482 result .append ("}" );
8583 return result .toString ();
Original file line number Diff line number Diff line change @@ -62,36 +62,21 @@ public List<VAL> asList() {
6262
6363 @ Override
6464 public boolean equals (Object obj ) {
65- if (obj != null && getClass () == obj .getClass ()) {
66- Domain d = (Domain ) obj ;
67- if (d .values .length != values .length )
68- return false ;
69- for (int i = 0 ; i < values .length ; i ++)
70- if (!values [i ].equals (d .values [i ]))
71- return false ;
72- return true ;
73- }
74- return false ;
65+ return obj != null && getClass () == obj .getClass () && Arrays .equals (values , ((Domain ) obj ).values );
7566 }
7667
7768 @ Override
7869 public int hashCode () {
79- int hash = 9 ; // arbitrary seed value
80- int multiplier = 13 ; // arbitrary multiplier value
81- for (Object value : values )
82- hash = hash * multiplier + value .hashCode ();
83- return hash ;
70+ return Arrays .hashCode (values );
8471 }
8572
8673 @ Override
8774 public String toString () {
8875 StringBuilder result = new StringBuilder ("{" );
89- boolean comma = false ;
9076 for (Object value : values ) {
91- if (comma )
77+ if (result . length () > 1 )
9278 result .append (", " );
93- result .append (value .toString ());
94- comma = true ;
79+ result .append (value );
9580 }
9681 result .append ("}" );
9782 return result .toString ();
You can’t perform that action at this time.
0 commit comments