4242 * Class to store a list of typed constant/variable values.
4343 * (Basically, just a mapping from String to Object)
4444 */
45- public class Values implements Cloneable //implements Comparable
45+ public class Values < T > implements Cloneable //implements Comparable
4646{
4747 protected ArrayList <String > names ;
48- protected ArrayList <Object > values ;
48+ protected ArrayList <T > values ;
4949
5050 // Constructors
5151
@@ -55,22 +55,22 @@ public class Values implements Cloneable //implements Comparable
5555 public Values ()
5656 {
5757 names = new ArrayList <String >();
58- values = new ArrayList <Object >();
58+ values = new ArrayList <>();
5959 }
6060
6161 /**
6262 * Construct a new Values object by copying an existing one.
6363 * If the existing one is null, it is treated as empty.
6464 */
6565 @ SuppressWarnings ("unchecked" )
66- public Values (Values v )
66+ public Values (Values < T > v )
6767 {
6868 if (v == null ) {
6969 names = new ArrayList <String >();
70- values = new ArrayList <Object >();
70+ values = new ArrayList <>();
7171 } else {
7272 names = (ArrayList <String >) v .names .clone ();
73- values = (ArrayList <Object >) v .values .clone ();
73+ values = (ArrayList <T >) v .values .clone ();
7474 }
7575 }
7676
@@ -79,7 +79,7 @@ public Values(Values v)
7979 * There is no checking for duplicates.
8080 * Either can be null and, if so, is treated as empty.
8181 */
82- public Values (Values v1 , Values v2 )
82+ public Values (Values < T > v1 , Values < T > v2 )
8383 {
8484 this (v1 );
8585 addValues (v2 );
@@ -98,7 +98,7 @@ public Values(State s, ModelInfo modelInfo)
9898 if (s == null ) return ;
9999 int n = s .varValues .length ;
100100 for (int i = 0 ; i < n ; i ++) {
101- addValue (modelInfo .getVarName (i ), s .varValues [i ]);
101+ addValue (modelInfo .getVarName (i ), ( T ) s .varValues [i ]);
102102 }
103103 }
104104
@@ -108,7 +108,7 @@ public Values(State s, ModelInfo modelInfo)
108108 * @param name Constant/variable name
109109 * @param value Value
110110 */
111- public void addValue (String name , Object value )
111+ public void addValue (String name , T value )
112112 {
113113 names .add (name );
114114 values .add (value );
@@ -119,7 +119,7 @@ public void addValue(String name, Object value)
119119 * If {@code v} is null, it is treated as empty.
120120 * (Note: there is no checking for duplication/inconsistencies/etc.)
121121 */
122- public void addValues (Values v )
122+ public void addValues (Values < T > v )
123123 {
124124 int i , n ;
125125
@@ -136,7 +136,7 @@ public void addValues(Values v)
136136 * @param name Constant/variable name
137137 * @param value Value
138138 */
139- public int setValue (String name , Object value )
139+ public int setValue (String name , T value )
140140 {
141141 int i = getIndexOf (name );
142142 if (i == -1 ) {
@@ -153,7 +153,7 @@ public int setValue(String name, Object value)
153153 * Set multiple values (overwrite if already present)
154154 * Returns number of values overwritten.
155155 */
156- public int setValues (Values v )
156+ public int setValues (Values < T > v )
157157 {
158158 int i , n , c = 0 ;
159159
@@ -240,7 +240,7 @@ public Type getType(int i)
240240 /**
241241 * Get the {@code i}th value.
242242 */
243- public Object getValue (int i )
243+ public T getValue (int i )
244244 {
245245 return values .get (i );
246246 }
@@ -249,7 +249,7 @@ public Object getValue(int i)
249249 * Get the value for variable/constant {@code name}.
250250 * @throws PrismLangException if no value is present.
251251 */
252- public Object getValueOf (String name ) throws PrismLangException
252+ public T getValueOf (String name ) throws PrismLangException
253253 {
254254 int i ;
255255
@@ -262,13 +262,13 @@ public Object getValueOf(String name) throws PrismLangException
262262 public boolean equals (Object o )
263263 {
264264 int i , j , n ;
265- Values v ;
265+ Values < T > v ;
266266 String s ;
267267
268268 // trivial case: null arg
269269 if (o == null ) return false ;
270270 // another trivial case: wrong type
271- try { v = (Values )o ; } catch (ClassCastException e ) { return false ; }
271+ try { v = (Values < T > )o ; } catch (ClassCastException e ) { return false ; }
272272 // check sizes are equal
273273 n = getNumValues ();
274274 if (v .getNumValues () != n ) return false ;
@@ -320,16 +320,16 @@ public boolean equals(Object o)
320320
321321 @ SuppressWarnings ("unchecked" )
322322 @ Override
323- public Values clone ()
323+ public Values < T > clone ()
324324 {
325- Values clone ;
325+ Values < T > clone ;
326326 try {
327- clone = (Values ) super .clone ();
327+ clone = (Values < T > ) super .clone ();
328328 } catch (CloneNotSupportedException e ) {
329329 throw new InternalError ("Object#clone is expected to work for Cloneable objects." , e );
330330 }
331331 clone .names = (ArrayList <String >) names .clone ();
332- clone .values = (ArrayList <Object >) values .clone ();
332+ clone .values = (ArrayList <T >) values .clone ();
333333 return clone ;
334334 }
335335
0 commit comments