de.interactive_instruments.ShapeChange
Class StructuredNumber

java.lang.Object
  extended by de.interactive_instruments.ShapeChange.StructuredNumber
All Implemented Interfaces:
Comparable<StructuredNumber>

public class StructuredNumber
extends Object
implements Comparable<StructuredNumber>

This class represents structured integers of the form x.y.z..., where the number of components is determined at object creation time.


Field Summary
 int[] components
          The component array
 
Constructor Summary
StructuredNumber(int n)
          Out-of-integer ctor.
StructuredNumber(String sn)
          Out-of-string ctor.
 
Method Summary
 int compareTo(StructuredNumber sn)
          Comparison method.
 StructuredNumber createCopy()
           
 StructuredNumber createCopyWithSuffix(int number)
          Creates a copy of this StructuredNumber, appending the given number.
 boolean equals(StructuredNumber sn)
          Checks if this StructuredNumber is equal to the given one.
 String getString()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

components

public int[] components
The component array

Constructor Detail

StructuredNumber

public StructuredNumber(String sn)
Out-of-string ctor. This converts strings of the form x.y.z. Note that this covers also simple integers coded as strings.

Parameters:
sn - string of the form x.y.z

StructuredNumber

public StructuredNumber(int n)
Out-of-integer ctor. Make a StructuredNumber from from one single integer.

Parameters:
n - integer value
Method Detail

compareTo

public int compareTo(StructuredNumber sn)
Comparison method. Comparison proceeds from front to back, while there are components existing in both comparands. When the common part turns out to be equal, the longer comparand will be regarded the one with the higher value. Only comparands of equal length can compare with equal result.

Specified by:
compareTo in interface Comparable<StructuredNumber>
Parameters:
sn - other structured number to compare with

getString

public String getString()

createCopyWithSuffix

public StructuredNumber createCopyWithSuffix(int number)
Creates a copy of this StructuredNumber, appending the given number. For example: if this StructuredNumber represents "1.1.1" and "3" is given as parameter, the result is a new StructuredNumber representing "1.1.1.3".

Parameters:
number - the integer to append
Returns:
a copy of this StructuredNumber, with the given number appended to it.

createCopy

public StructuredNumber createCopy()

equals

public boolean equals(StructuredNumber sn)
Checks if this StructuredNumber is equal to the given one. This is true if the StructuredNumbers have the same components (length and content).

Parameters:
sn -
Returns:

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2015. All rights reserved.