net.von_gagern.martin.confoo.mesh
Class SimpleTriangle<V>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<V>
          extended by net.von_gagern.martin.confoo.mesh.SimpleTriangle<V>
Type Parameters:
V - the class used to represent triangle vertices
All Implemented Interfaces:
Iterable<V>, Collection<V>, List<V>, CorneredTriangle<V>
Direct Known Subclasses:
Triangle2D

public class SimpleTriangle<V>
extends AbstractList<V>
implements CorneredTriangle<V>

Simple implementation for triangles of a mesh.

An arbitrary type may be used to identify indices, and the corners can be identified through their index. For coordinates of the corner, the corresponding LocatedMesh should be queried.

Beside access to the corners as required by LocatedMesh, this implementation also provides access to the corners in form of a List.

Since:
1.0
Author:
Martin von Gagern

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
SimpleTriangle(V c1, V c2, V c3)
           
 
Method Summary
static boolean equal(CorneredTriangle<?> t1, CorneredTriangle<?> t2)
          Equality comparison for cornered triangles.
 boolean equals(Object o)
          Compare two simple triangles for equality.
 V get(int index)
          Get specified corner.
 V getCorner(int index)
          Get specified corner.
 int hashCode()
          Calculate hash code of triangle.
 int size()
          Count corners.
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

SimpleTriangle

public SimpleTriangle(V c1,
                      V c2,
                      V c3)
Method Detail

getCorner

public V getCorner(int index)
Get specified corner.

Specified by:
getCorner in interface CorneredTriangle<V>
Parameters:
index - the index of the corner requested
Returns:
an object identifying the requested corner
Throws:
IndexOutOfBoundsException - unless 0 <= index < 3

get

public V get(int index)
Get specified corner. This is an alias to getCorner(int) in order to implement the List interface.

Specified by:
get in interface List<V>
Specified by:
get in class AbstractList<V>
Parameters:
index - the index of the corner requested
Returns:
an object identifying the requested corner
Throws:
IndexOutOfBoundsException - unless 0 <= index < 3

size

public int size()
Count corners. This method will always return 3.

Specified by:
size in interface Collection<V>
Specified by:
size in interface List<V>
Specified by:
size in class AbstractCollection<V>
Returns:
three

hashCode

public int hashCode()
Calculate hash code of triangle. This hash code is calculated in such a way that it is compatible with the equals(java.lang.Object) method. It is based on the hash codes of the three corner vertices.

Specified by:
hashCode in interface Collection<V>
Specified by:
hashCode in interface List<V>
Overrides:
hashCode in class AbstractList<V>
Returns:
a hash code for the triangle

equals

public boolean equals(Object o)
Compare two simple triangles for equality. Triangles are deemed equal if all their vertices are equal, and if they use the same orientation. They don't have to use the same starting vertex as first vertex. In other words, only the cyclic order of vertices is relevant. Only instances of SimpleTriangle will be considered equal to a SimpleTriangle in order to not break the symmetry of equals.

Specified by:
equals in interface Collection<V>
Specified by:
equals in interface List<V>
Overrides:
equals in class AbstractList<V>
Parameters:
o - another object
Returns:
whether the other object is a SimpleTriangle with the same vertices and orientation

equal

public static boolean equal(CorneredTriangle<?> t1,
                            CorneredTriangle<?> t2)
Equality comparison for cornered triangles. Triangles are deemed equal if all their vertices are equal, and if they use the same orientation. They don't have to use the same starting vertex as first vertex. In other words, only the cyclic order of vertices is relevant. The classes of the triangles are not compared by this implementation. null is equal only to null.

This static method can be used by implementations of CorneredTriangle that wish to implement the same equality semantics. It can also be used by applications that wish to use this semantics regardless of the actual triangle implementation in use.

Parameters:
t1 - one triangle
t2 - a second triangle
Returns:
whether the two triangles have the same vertices and orientation
See Also:
Object.equals(java.lang.Object)


Copyright © 2008-2009 Martin von Gagern. All Rights Reserved.