.. java:import:: java.util Collection .. java:import:: java.util Iterator .. java:import:: java.util LinkedHashSet SetInstance =========== .. java:package:: com.ampl :noindex: .. java:type:: public class SetInstance extends Instance implements java.util.Set A SetInstance object stores the information regarding a specific instance of a set. The instances can be accessed through the function :java:ref:`Set.get` of the parent entity. The members of the set can be strings, double numbers or :java:ref:`tuples `. Data can be assigned using :java:ref:`Set.setValues` or using :java:ref:`AMPL.setData` and a :java:ref:`DataFrame` object. All the accessors in this class throw a :java:ref:`IllegalStateException` if the instance has been deleted in the underlying AMPL interpreter. Fields ------ value ^^^^^ .. java:field:: LinkedHashSet value :outertype: SetInstance Constructors ------------ SetInstance ^^^^^^^^^^^ .. java:constructor:: SetInstance(Set map, Object key, int initialCapacity) :outertype: SetInstance Construct a new set :param entity: Map :param key: Key Methods ------- add ^^^ .. java:method:: @Override @Deprecated public boolean add(Object e) :outertype: SetInstance Not supported. :throws UnsupportedOperationException: if called. addAll ^^^^^^ .. java:method:: @Override @Deprecated public boolean addAll(Collection c) :outertype: SetInstance Not supported. :throws UnsupportedOperationException: if called. asDoubles ^^^^^^^^^ .. java:method:: double[] asDoubles() :outertype: SetInstance Returns all the members as doubles. It tries to convert strings to doubles and throws an exception if any of the members is not convertible. Validity of conversions from member type and runtime content: .. * (double) 1.1 -> YES * (double) 1 -> YES * (string) "1.1" -> YES * (string) "1" -> YES * (string) "a" -> NO :throws NumberFormatException: if any of the member is not convertible to double asIntegers ^^^^^^^^^^ .. java:method:: int[] asIntegers() :outertype: SetInstance Returns all the members as integers. It tries to convert strings and double to integers and throws an exception if any of the members is not convertible. Validity of conversions from member type and runtime content: .. * (double) 1.1 -> NO * (double) 1 -> YES * (string) "1.1" -> NO * (string) "1" -> YES * (string) "a" -> NO :throws NumberFormatException: if any of the member is not convertible to integer asSet ^^^^^ .. java:method:: @SuppressWarnings java.util.Set asSet() :outertype: SetInstance Get a copy of the elements in this set as a java Set of Objects (Strings, double numbers or :java:ref:`Tuple` in case of multidimensional sets) :return: A copy of the elements in this set asStrings ^^^^^^^^^ .. java:method:: String[] asStrings() :outertype: SetInstance Returns all the members as strings clear ^^^^^ .. java:method:: @Override @Deprecated public void clear() :outertype: SetInstance Not supported. :throws UnsupportedOperationException: if called. contains ^^^^^^^^ .. java:method:: public boolean contains(Object o) :outertype: SetInstance Check contents of the set for members. The object to be found can be a String, a double, a :java:ref:`Tuple` or an array. In this last case, each element in the array is considered as elements of a Tuple to be found. i.e. the following are equivalent: .. parsed-literal:: contains(new Tuple(1, "abc")); and .. parsed-literal:: contains(new Object[]{1, "abc}); :param o: Object to be found (double, String, Tuple or Object[] with the elements of a tuple) :return: True if the object is present. containsAll ^^^^^^^^^^^ .. java:method:: @Override public boolean containsAll(Collection c) :outertype: SetInstance Check if the sets contains all the elements in the collection \ ``c``\ . Each element in the collection can be a double, a String, a Tuple or an array. In case of arrays, each array is considered as a Tuple. Example: considering the AMPL set declared as .. parsed-literal:: set s := {(1, 'abc'), ('def', 2)}; the following is true: .. parsed-literal:: List l = new LinkedList(); list.add(new Tuple("def", 2)); list.add(new Object[] { 1, "abc" }); ampl.getSet("s").get().containsAll(list); :param c: A Collection of objects to be found. See above for the semantics of the objects. :return: True if all the specified objects are present copyFrom ^^^^^^^^ .. java:method:: @Override void copyFrom(Instance from) :outertype: SetInstance getValues ^^^^^^^^^ .. java:method:: public DataFrame getValues() :outertype: SetInstance Get all the members of this set in a DataFrame isEmpty ^^^^^^^ .. java:method:: @Override public boolean isEmpty() :outertype: SetInstance Return true if the set is empty. iterator ^^^^^^^^ .. java:method:: @Override public Iterator iterator() :outertype: SetInstance Get the iterator for this set. remove ^^^^^^ .. java:method:: @Override @Deprecated public boolean remove(Object o) :outertype: SetInstance Not supported. :throws UnsupportedOperationException: if called. removeAll ^^^^^^^^^ .. java:method:: @Override @Deprecated public boolean removeAll(Collection c) :outertype: SetInstance Not supported. :throws UnsupportedOperationException: if called. retainAll ^^^^^^^^^ .. java:method:: @Override @Deprecated public boolean retainAll(Collection c) :outertype: SetInstance Not supported. :throws UnsupportedOperationException: if called. setValues ^^^^^^^^^ .. java:method:: public void setValues(Object... objects) :outertype: SetInstance Assign values to the this set. The values can be strings, doubles, tuples or arrays of objects (which will be converted into tuples). For example, to assign values to a set of tuples: .. parsed-literal:: ampl.eval("set s dimen 2;"); Set s = ampl.getSet("s"); Object[] data = new Object[] { new Tuple(1, "abc"), new Tuple(2, "def") }; s.setValues(data); or alternatively, using arrays of objects: .. parsed-literal:: ampl.eval("set s dimen 2;"); Set s = ampl.getSet("s"); Object[] data = new Object[] {new Object[]{1, "abc"}, new Object{2, "def"}}; s.setValues(data); An alternative way to assign values to a set of tuples of size `n` is to use a flattened array, in which every `n` elements are considered a Tuple. So, an equivalent formulation of the example above is: .. parsed-literal:: ampl.eval("set s dimen 2;"); Set s = ampl.getSet("s"); Object[] data = new Object[] { 1, "abc", 2, "def" }; s.setValues(data); :param objects: Values to be assigned to the set setValues ^^^^^^^^^ .. java:method:: public void setValues(DataFrame data) :outertype: SetInstance size ^^^^ .. java:method:: public int size() :outertype: SetInstance Get the size :return: Cardinality of this set toArray ^^^^^^^ .. java:method:: @Override public Object[] toArray() :outertype: SetInstance Convert this set to an array. Valid only for not indexed sets. toArray ^^^^^^^ .. java:method:: @Override public T[] toArray(T[] a) :outertype: SetInstance Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array. If the set fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this set. If this set fits in the specified array with room to spare (i.e., the array has more elements than this set), the element in the array immediately following the end of the set is set to null. This is useful in determining the length of this set only if the caller knows that this set does not contain any null elements. :param a: An array of the desired type toDouble ^^^^^^^^ .. java:method:: double toDouble(Object o) :outertype: SetInstance toString ^^^^^^^^ .. java:method:: @Override public String toString() :outertype: SetInstance Converts the set to string, showing its name, its index value and its members.