Skip to content

Commit e788859

Browse files
hashCode for GenericScope
1 parent b5c67ca commit e788859

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

SerialX-core/src/main/java/org/ugp/serialx/GenericScope.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
/**
26-
* This collection is some sort of hybrid between {@link List} and {@link Map} which allow you to have both variables and independent values managed by one Object. <br>
26+
* This collection is some sort of hybrid, or more accurately "union" between {@link List} and {@link Map} which allow you to have both variables and independent values managed by one Object. <br>
2727
* Note: Variables are managed and accessed classically via {@link Map} methods such as <code>put(KeyT key, Object)</code> and array of independent values is accessed by via {@link List} methods such as <code>add(Object)</code> and <code>get(int)</code><br>
2828
* Also this is java representation of JUSS GenericScope group such as:
2929
* <pre>
@@ -117,10 +117,19 @@ public boolean equals(Object obj)
117117
public String toString()
118118
{
119119
String name = getClass().getSimpleName();
120-
if (variablesCount() > 0 ^ valuesCount() > 0)
121-
return name + (variablesCount() > 0 ? variables() : values());
122-
else
123-
return name + toUnifiedList();
120+
final int varCount;
121+
if ((varCount = variablesCount()) > 0 ^ valuesCount() > 0)
122+
return name + (varCount > 0 ? variables() : values());
123+
return name + toUnifiedList();
124+
}
125+
126+
@Override
127+
public int hashCode()
128+
{
129+
final int varCount;
130+
if ((varCount = variablesCount()) > 0 ^ valuesCount() > 0)
131+
return (varCount > 0 ? variables() : values()).hashCode();
132+
return Objects.hash(variables(), values());
124133
}
125134

126135
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)