Package eu.simuline.util
Class AbstractMultiSet.MultiplicityImpl
- java.lang.Object
-
- eu.simuline.util.AbstractMultiSet.MultiplicityImpl
-
- All Implemented Interfaces:
MultiSet.Multiplicity,java.lang.Comparable<MultiSet.Multiplicity>
- Enclosing class:
- AbstractMultiSet<MAP extends java.util.Map<T,MultiSet.Multiplicity>,T>
public static final class AbstractMultiSet.MultiplicityImpl extends java.lang.Object implements MultiSet.Multiplicity
Serves as a wrapper object for a multiplicitymult. Unlikeints we have realObjects which can be stored in a map, e.g.AbstractMultiSet.obj2multand unlikeIntegers these objects are mutable.
-
-
Field Summary
Fields Modifier and Type Field Description private intmultA positive integer representing a multiplicity.
-
Constructor Summary
Constructors Modifier Constructor Description privateMultiplicityImpl(int mult)Creates a newMultiplicityinstance representing a positive multiplicity.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intadd(int mult)Adds the specified multiplicity (which may well be negative) to the wrapped multiplicitymultwhich is thus modified.intcompareTo(MultiSet.Multiplicity mult)Defines the natural ordering on natural numbers.protected static AbstractMultiSet.MultiplicityImplcreate(int mult)booleanequals(java.lang.Object obj)Returnstrueif and only ifobjis also an instance ofMultiplicityand if the wrapped multiplicities coincide.intget()Returns the wrapped multiplicity.inthashCode()intset(int mult)Sets the multiplicity wrapped by this object to the specified value.java.lang.StringtoString()
-
-
-
Constructor Detail
-
MultiplicityImpl
private MultiplicityImpl(int mult)
Creates a newMultiplicityinstance representing a positive multiplicity.- Parameters:
mult- a strictly positiveintvalue representing a multiplicity.- Throws:
java.lang.IllegalArgumentException- ifmultis not strictly positive.- See Also:
set(int)
-
-
Method Detail
-
create
protected static AbstractMultiSet.MultiplicityImpl create(int mult)
-
set
public int set(int mult)
Sets the multiplicity wrapped by this object to the specified value.- Specified by:
setin interfaceMultiSet.Multiplicity- Parameters:
mult- a strictly positiveintvalue representing the old multiplicity.- Throws:
java.lang.IllegalArgumentException- ifmultis not strictly positive.
-
add
public int add(int mult)
Adds the specified multiplicity (which may well be negative) to the wrapped multiplicitymultwhich is thus modified.- Specified by:
addin interfaceMultiSet.Multiplicity- Parameters:
mult- anintsuch thatthis.mult + mult > 0holds.- Returns:
- the new multiplicity
this.mult + mult. - Throws:
java.lang.IllegalArgumentException- ifthis.mult + mult < 0holds.java.lang.IllegalStateException- ifthis.mult + mult == 0holds. This cannot occur: if it does this is a bug within this class.
-
get
public int get()
Returns the wrapped multiplicity.- Specified by:
getin interfaceMultiSet.Multiplicity- Returns:
mult.
-
compareTo
public int compareTo(MultiSet.Multiplicity mult)
Defines the natural ordering on natural numbers.- Specified by:
compareToin interfacejava.lang.Comparable<MultiSet.Multiplicity>- Specified by:
compareToin interfaceMultiSet.Multiplicity- Parameters:
mult- aMultiplicitywhich should in fact be anotherMultiSet.Multiplicity.- Returns:
- the difference of the wrapped
mult-values. - Throws:
java.lang.NullPointerException- formult == null.java.lang.ClassCastException- ifmultis neithernullnor an instance ofMultiSet.Multiplicity.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
Returnstrueif and only ifobjis also an instance ofMultiplicityand if the wrapped multiplicities coincide.- Specified by:
equalsin interfaceMultiSet.Multiplicity- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- anObjectvalue which may well benull.- Returns:
- a
booleanvalue which indicates whetherobjis also an instance ofMultiplicityand whether the wrapped multiplicity coincides with this one. - See Also:
compareTo(eu.simuline.util.MultiSet.Multiplicity)
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-