org.smurn.jply
Class Element

java.lang.Object
  extended by org.smurn.jply.Element
All Implemented Interfaces:
Cloneable

public final class Element
extends Object
implements Cloneable

Element of a PLY file.

Each element has a number of values that describe its properties. The type of an element describes which properties are present in an element.


Constructor Summary
Element(ElementType type)
          Creates an instance with default values.
 
Method Summary
 Element clone()
           
 boolean equals(Element rhs, double epsilon)
          Checks if two elements are approximately equal.
 boolean equals(Object obj)
           
 double getDouble(String propertyName)
          Gets a property value of this element.
 double[] getDoubleList(String propertyName)
          Gets a property value list of this element.
 int getInt(String propertyName)
          Gets a property value of this element.
 int[] getIntList(String propertyName)
          Gets a property value list of this element.
 ElementType getType()
          Gets the type of this element.
 int hashCode()
           
 void setDouble(String propertyName, double value)
          Sets the value of a property-list.
 void setDoubleList(String propertyName, double[] values)
          Sets the value of a property-list.
 void setInt(String propertyName, int value)
          Sets the value of a property-list.
 void setIntList(String propertyName, int[] values)
          Sets the value of a property-list.
 String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Element

public Element(ElementType type)
Creates an instance with default values.

Properties are set to 0, list properties are set to an empty list.

Parameters:
type - Type of the element to create.
Method Detail

getType

public ElementType getType()
Gets the type of this element.

Returns:
Element type. Is never null.

getInt

public int getInt(String propertyName)
Gets a property value of this element.

If the property is a list-property, the first element is returned.

Parameters:
propertyName - Name of the property.
Returns:
Value of the current element casted to int.
Throws:
NullPointerException - if propertyName is null.
IllegalArgumentException - if the element type does not have a property with the given name.
IndexOutOfBoundsException - if the requested property is a list property with zero elements.

getDouble

public double getDouble(String propertyName)
Gets a property value of this element.

If the property is a list-property, the first element is returned.

Parameters:
propertyName - Name of the property.
Returns:
Value of the current element casted to double.
Throws:
NullPointerException - if propertyName is null.
IllegalArgumentException - if the element type does not have a property with the given name.
IndexOutOfBoundsException - if the requested property is a list property with zero elements.

getIntList

public int[] getIntList(String propertyName)
Gets a property value list of this element.

If the property is not list-property, a list with a single element is returned.

Parameters:
propertyName - Name of the property.
Returns:
Values of the current element, each casted to int.
Throws:
NullPointerException - if propertyName is null.
IllegalArgumentException - if the element type does not have a property with the given name.

getDoubleList

public double[] getDoubleList(String propertyName)
Gets a property value list of this element.

If the property is not list-property, a list with a single element is returned.

Parameters:
propertyName - Name of the property.
Returns:
Values of the current element, each casted to double.
Throws:
NullPointerException - if propertyName is null.
IllegalArgumentException - if the element type does not have a property with the given name.

setDoubleList

public void setDoubleList(String propertyName,
                          double[] values)
Sets the value of a property-list. If the property is not a list, the first element is used.

Parameters:
propertyName - Name of the property to set.
values - Values to set for that property.
Throws:
NullPointerException - if propertyName is null.
IllegalArgumentException - if the element type does not have a property with the given name.
IndexOutOfBoundsException - if the property is not a list property and the given array does not have exactly one element.

setDouble

public void setDouble(String propertyName,
                      double value)
Sets the value of a property-list. If the property is a list, the list will be set to a single entry.

Parameters:
propertyName - Name of the property to set.
value - Value to set for that property.
Throws:
NullPointerException - if propertyName is null.
IllegalArgumentException - if the element type does not have a property with the given name.

setIntList

public void setIntList(String propertyName,
                       int[] values)
Sets the value of a property-list. If the property is not a list, the first element is used.

Parameters:
propertyName - Name of the property to set.
values - Values to set for that property.
Throws:
NullPointerException - if propertyName is null.
IllegalArgumentException - if the element type does not have a property with the given name.
IndexOutOfBoundsException - if the property is not a list property and the given array does not have exactly one element.

setInt

public void setInt(String propertyName,
                   int value)
Sets the value of a property-list. If the property is a list, the list will be set to a single entry.

Parameters:
propertyName - Name of the property to set.
value - Value to set for that property.
Throws:
NullPointerException - if propertyName is null.
IllegalArgumentException - if the element type does not have a property with the given name.

clone

public Element clone()
Overrides:
clone in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

equals

public boolean equals(Element rhs,
                      double epsilon)
Checks if two elements are approximately equal.

Other than equals(java.lang.Object) this method allows to be tolerant to small numerical differences in the values.

Parameters:
rhs - Element to compare against.
epsilon - Maximal allowed difference between two values.
Returns:
true if they have the same type and structure and no value differs by more than epsilon.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011. All Rights Reserved.