diff options
Diffstat (limited to 'israfil-foundation-nspace')
12 files changed, 1097 insertions, 0 deletions
diff --git a/israfil-foundation-nspace/pom.xml b/israfil-foundation-nspace/pom.xml new file mode 100644 index 0000000..969dae5 --- /dev/null +++ b/israfil-foundation-nspace/pom.xml @@ -0,0 +1,21 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.israfil.foundation</groupId> + <artifactId>israfil-foundation-all</artifactId> + <version>5-SNAPSHOT</version> + </parent> + <artifactId>israfil-foundation-nspace</artifactId> + <name>Israfil Foundation N-Dimensional Array</name> + <version>0.1-SNAPSHOT</version> + <url>http://www.israfil.net/projects/foundation/${artifactId}</url> + <inceptionYear>2003</inceptionYear> + <licenses> + <license> + <name>BSD</name> + <distribution>repo</distribution> + <url>http://www.israfil.net/israfil-license-bsd.txt</url> + <comments>A simple open-source license with minimal restrictions</comments> + </license> + </licenses> +</project>
\ No newline at end of file diff --git a/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/Coordinate.java b/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/Coordinate.java new file mode 100755 index 0000000..620124a --- /dev/null +++ b/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/Coordinate.java @@ -0,0 +1,56 @@ +/*
+ * Copyright (c) 2003, Mishkin Berteig and Christian Gruber
+ *
+ * $Id: Coordinate.java 254 2003-02-10 16:01:01Z cgruber $
+ */
+package net.israfil.foundation.collections.nspace;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Logically an array of tuples
+ *
+ * @author <a href="mailto:mishkin@berteig.com">Mishkin Berteig</a>
+ * @author <a href="mailto:cgruber@israfil.net">Christian Gruber</a>
+ * @version $Revision: 254 $
+ */
+public interface Coordinate {
+
+ /**
+ * A single empty Coordinate, which can be passed in to point-NSpaces, where
+ * no dimension constraint is required.
+ */
+ public final static Coordinate EMPTY =
+ new Coordinate() {
+ private final Set<String> dim = new HashSet<String>();
+
+ public Set<String> getDimensions() {
+ return dim;
+ }
+ public long getDimensionality() { return 0; }
+ public String getOrdinal(String dimensionName) {
+ if (false) dimensionName.hashCode(); //quiet compiler warning.
+ return null;
+ }
+ };
+
+ /**
+ * Returns a set of names of contained dimensions.
+ * @return Set
+ */
+ public Set<String> getDimensions();
+
+ /**
+ * Returns the number of dimensions
+ * @return long
+ */
+ public long getDimensionality();
+
+ /**
+ * Returns the ordinal of the given named dimension..
+ * @return Set
+ */
+ public String getOrdinal(String dimensionName);
+
+}
diff --git a/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/Dimension.java b/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/Dimension.java new file mode 100755 index 0000000..f4e73bb --- /dev/null +++ b/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/Dimension.java @@ -0,0 +1,36 @@ +/*
+ * Copyright (c) 2003, Mishkin Berteig and Christian Gruber
+ *
+ * $Id: Dimension.java 260 2005-05-15 13:08:53Z cgruber $
+ */
+package net.israfil.foundation.collections.nspace;
+
+import java.util.Collection;
+import java.util.Set;
+
+/**
+ * A named set of positions within an nspace
+ *
+ * @author <a href="mailto:mishkin@berteig.com">Mishkin Berteig</a>
+ * @author <a href="mailto:cgruber@israfil.net">Christian Gruber</a>
+ * @version $Revision: 260 $
+ */
+public interface Dimension extends Set<String> {
+
+ /**
+ * Returns the name of the position
+ * @return String
+ */
+ public String getName();
+
+
+ void getWithNSpace(NSpace space);
+ void abandonNSpace(NSpace space);
+ void getWithNSpaces(Collection<NSpace> spaces);
+ void abandonNSpaces(Collection<NSpace> spaces);
+
+ public Dimension addPosition(String s);
+ public Dimension deletePosition(String s);
+
+
+}
diff --git a/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/DimensionExistsException.java b/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/DimensionExistsException.java new file mode 100755 index 0000000..e53397a --- /dev/null +++ b/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/DimensionExistsException.java @@ -0,0 +1,38 @@ +/*
+ * Copyright (c) 2003, Mishkin Berteig and Christian Gruber
+ *
+ * $Id: DimensionExistsException.java 249 2003-02-02 03:33:46Z cgruber $
+ */
+package net.israfil.foundation.collections.nspace;
+
+/**
+ * Thrown if a dimension is added to an NSpace which already defines a
+ * Dimension with that name.
+ *
+ * @author <a href="mailto:mishkin@berteig.com">Mishkin Berteig</a>
+ * @author <a href="mailto:cgruber@israfil.net">Christian Gruber</a>
+ * @version $Revision: 249 $
+ */
+public class DimensionExistsException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -801633377290441235L;
+
+ /**
+ * Constructor for DimensionExistsException.
+ */
+ public DimensionExistsException() {
+ super();
+ }
+
+ /**
+ * Constructor for DimensionExistsException.
+ * @param arg0
+ */
+ public DimensionExistsException(String arg0) {
+ super(arg0);
+ }
+
+}
diff --git a/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/InvalidDimensionalityException.java b/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/InvalidDimensionalityException.java new file mode 100755 index 0000000..3a12d31 --- /dev/null +++ b/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/InvalidDimensionalityException.java @@ -0,0 +1,39 @@ +/*
+ * Copyright (c) 2003, Mishkin Berteig and Christian Gruber
+ *
+ * $Id: InvalidDimensionalityException.java 249 2003-02-02 03:33:46Z cgruber $
+ */
+package net.israfil.foundation.collections.nspace;
+
+/**
+ * Thrown when the provided Coodinate inadequately specifies, or incorrectly
+ * specifies the dimensions relative to the NSpace. Primarily used with
+ * setters.
+ *
+ * @author <a href="mailto:mishkin@berteig.com">Mishkin Berteig</a>
+ * @author <a href="mailto:cgruber@israfil.net">Christian Gruber</a>
+ * @version $Revision: 249 $
+ */
+public class InvalidDimensionalityException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -5349982487272515716L;
+
+ /**
+ * Constructor for InvalidDimensionalityException.
+ */
+ public InvalidDimensionalityException() {
+ super();
+ }
+
+ /**
+ * Constructor for InvalidDimensionalityException.
+ * @param arg0
+ */
+ public InvalidDimensionalityException(String arg0) {
+ super(arg0);
+ }
+
+}
diff --git a/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/NSpace.java b/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/NSpace.java new file mode 100755 index 0000000..196f4e9 --- /dev/null +++ b/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/NSpace.java @@ -0,0 +1,98 @@ +/*
+ * Copyright (c) 2003, Mishkin Berteig and Christian Gruber
+ *
+ * $Id: NSpace.java 259 2004-08-23 21:30:01Z mberteig $
+ */
+package net.israfil.foundation.collections.nspace;
+
+import java.util.Set;
+
+/**
+ * An N-Dimensional Space representation, such that:
+ * <ol>
+ * <li>Each dimension is named</li>
+ * <li>Each co-ordinate is specified using names not numbers <subscript>IOW:
+ * Domain of each dim. is specified as an ordered set of names
+ * </subscript></li>
+ * <li>Number of dimensions can change throughout lifecycle</li>
+ * <li>Dimensions
+ * </ol>
+ * <p>
+ * A SparseNSpace represents a set of tuples of the form (D1,D2,D3,...,Dn;V)
+ * where Dx represents a location in dimension x and V represents a value in
+ * the n-dimensional space at a location specified by the dimensional locations
+ * D1..Dn. Dimensions can be added or removed at any time with well-defined
+ * results.</p>
+ * <p><strong>Note:</strong> Maybe have origin</p>
+ *
+ * @author <a href="mailto:mishkin@berteig.com">Mishkin Berteig</a>
+ * @author <a href="mailto:cgruber@israfil.net">Christian Gruber</a>
+ * @version $Revision: 259 $
+ */
+public interface NSpace {
+
+ /*
+ * Content Management
+ */
+
+ /**
+ * Returns an NSpace such that each coordinate of the receiver that contains the values of the passed in
+ * coordinate becomes a part of the resulting NSpace. The dimensionality of the resulting NSpace is the difference
+ * of the dimensionality of the receiver and the coordinate. E.g. say we have 3-NSpace with dimensions (D1,D2,D3)
+ * and data [0,0,0;A], [0,1,0;B], [1,0,0;C], [1,1,0;D]. If we lookup a coordinate with dimensions (D2,D3) and values
+ * [0,0] we will get a resulting 1-NSpace with dimension (D1) and data [0;A], [1;C].
+ */
+ public NSpace lookup(Coordinate c);
+
+ /**
+ * Returns an NSpace such that each coordinate of the receiver that contains the values of the passed in
+ * coordinate is not a part of the resulting NSpace. The dimensionality of the resulting NSpace is the dimensionality
+ * of the receiver. E.g. say we have 3-NSpace with dimensions (D1,D2,D3)
+ * and data [0,0,0;A], [0,1,0;B], [1,0,0;C], [1,1,0;D]. If we slice with a coordinate with dimensions (D2,D3) and values
+ * [0,0] we will get a resulting 3-NSpace with dimension (D1,D2,D3) and data [0,1,0;B], [1,1,0;D].
+ */
+ public NSpace slice(Coordinate c);
+
+ /**
+ * Returns an array of NSpace instances such that for each ordinal in Dimension d, there is an NSpace in the array
+ * of dimensionality one less than the receiver that contains the data from the receiver that contains the ordinal.
+ * E.g. say we have 3-NSpace with dimensions (D1,D2,D3)
+ * and data [0,0,0;A], [0,1,0;B], [1,0,0;C], [1,1,0;D].
+ * then slicing on dimension D2 would give us two 2-NSpaces with dimensions (D1,D3):
+ * [0,0;A], [1,0;C] and
+ * [0,0;B], [1,0;D]
+ * @param d the dimension to use to make the cuts in the receiver
+ * @return all the sub-NSpaces, one for each ordinal of d
+ */
+ public NSpace[] slice(Dimension d);
+
+ /**
+ * Returns true if NSpace contains zero dimensions, or if the size of each
+ * dimension == 1.
+ * @return boolean
+ */
+ public boolean isPoint();
+ public Object getValue(Coordinate c);
+
+ public NSpace setValue(Coordinate c, Object value)
+ throws InvalidDimensionalityException;
+ public NSpace setValue(Coordinate c, NSpace value)
+ throws InvalidDimensionalityException;
+
+ /*
+ * Dimension Management
+ */
+ public Dimension createDimension(String name, String initialSlot)
+ throws DimensionExistsException;
+ public void deleteDimension(Dimension dimension);
+ public Set<Dimension> getDimensions();
+ public Dimension getDimension(String name);
+
+ /*
+ * Notifications
+ */
+
+ void dimensionAddedPosition(Dimension dimension,String position);
+ void dimensionRemovedPosition(Dimension dimension, String position);
+
+}
diff --git a/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/SimpleDimension.java b/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/SimpleDimension.java new file mode 100755 index 0000000..52250fa --- /dev/null +++ b/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/SimpleDimension.java @@ -0,0 +1,225 @@ +package net.israfil.foundation.collections.nspace;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * @author cgruber
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class SimpleDimension implements Dimension {
+
+ private final String name;
+ private final Set<String> positions = new HashSet<String>();
+ private final Set<NSpace> spaces = new HashSet<NSpace>();
+
+ public SimpleDimension() {
+ name = null;
+ }
+
+ public SimpleDimension(String name, String ordinal) {
+ this.name = name;
+ positions.add(ordinal);
+ }
+
+ /**
+ * @see org.frugenplat.framework.nspace.Dimension#getName()
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * @see java.util.Collection#size()
+ */
+ public int size() {
+ return this.positions.size();
+ }
+
+ /**
+ * @see java.util.Collection#isEmpty()
+ */
+ public boolean isEmpty() {
+ throw new UnsupportedOperationException("Dimension cannot have no positions. Remove the dimension.");
+ }
+
+ /**
+ * @see java.util.Collection#contains(java.lang.Object)
+ */
+ public boolean contains(Object positions) {
+ return this.positions.contains(positions);
+ }
+
+ /**
+ * @see java.util.Collection#iterator()
+ */
+ public Iterator<String> iterator() {
+ return this.positions.iterator();
+ }
+
+ /**
+ * @see java.util.Collection#toArray()
+ */
+ public String[] toArray() {
+ return this.positions.toArray(new String[size()]);
+ }
+
+ /**
+ * @see java.util.Collection#toArray(java.lang.Object)
+ */
+ public <T> T[] toArray(T[] array) {
+ return this.positions.toArray(array);
+ }
+
+ /**
+ * @see java.util.Collection#add(java.lang.Object)
+ */
+ public boolean add(String
+ position) {
+ boolean result = this.positions.add(position);
+ notifyAddPosition((String)position);
+ return result;
+ }
+
+ /**
+ * @see java.util.Collection#remove(java.lang.Object)
+ */
+ public boolean remove(Object position) {
+ boolean result = this.positions.remove(position);
+ notifyRemovePosition((String)position);
+ return result;
+ }
+
+ /**
+ * @see java.util.Collection#containsAll(java.util.Collection)
+ */
+ public boolean containsAll(Collection<?> positions) {
+ return this.positions.containsAll(positions);
+ }
+
+ /**
+ * @see java.util.Collection#addAll(java.util.Collection)
+ */
+ public boolean addAll(Collection<? extends String> positions) {
+ return this.positions.addAll(positions);
+ }
+
+ /**
+ * @see java.util.Collection#retainAll(java.util.Collection)
+ */
+ public boolean retainAll(Collection<?> positions) {
+ return this.positions.retainAll(positions);
+ }
+
+ /**
+ * @see java.util.Collection#removeAll(java.util.Collection)
+ */
+ public boolean removeAll(Collection<?> positions) {
+ return this.positions.removeAll(positions);
+ }
+
+ /**
+ * @see java.util.Collection#clear()
+ */
+ public void clear() {
+ throw new UnsupportedOperationException("Dimensions must always have one ordinal");
+ }
+
+
+
+ /**
+ * @see org.frugenplat.framework.nspace.Dimension#abandonNSpace(org.frugenplat.framework.nspace.NSpace)
+ */
+ public void abandonNSpace(NSpace n) {
+ this.spaces.remove(n);
+ }
+
+ /**
+ * @see org.frugenplat.framework.nspace.Dimension#getWithNSpace(org.frugenplat.framework.nspace.NSpace)
+ */
+ public void getWithNSpace(NSpace n) {
+ this.spaces.add(n);
+ }
+
+ /**
+ * @see org.frugenplat.framework.nspace.Dimension#abandonNSpace(org.frugenplat.framework.nspace.NSpace)
+ */
+ public void abandonNSpaces(Collection<NSpace> spaces) {
+ this.spaces.removeAll(spaces);
+ }
+
+ /**
+ * @see org.frugenplat.framework.nspace.Dimension#getWithNSpace(org.frugenplat.framework.nspace.NSpace)
+ */
+ public void getWithNSpaces(Collection<NSpace> spaces) {
+ this.spaces.addAll(spaces);
+ }
+
+ private void notifyAddPosition(String position) {
+ for (NSpace space : spaces) {
+ space.dimensionAddedPosition(this,position);
+ }
+ }
+
+ private void notifyRemovePosition(String position) {
+ for (NSpace space : spaces) {
+ space.dimensionRemovedPosition(this,position);
+ }
+ }
+
+ @SuppressWarnings("unused")
+ private void notifyAddPositions(Collection<String> positions) {
+
+ }
+
+ @SuppressWarnings("unused")
+ private void notifyRemovePositions(Collection<String> positions) {
+
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(super.toString());
+ sb.append(" [");
+ sb.append(name);
+ sb.append("] {");
+ for (String s : positions) sb.append(s);
+ sb.append("}");
+ return sb.toString();
+ }
+
+ /**
+ * @see org.frugenplat.framework.nspace.Dimension#addPosition(java.lang.String)
+ */
+ public Dimension addPosition(String s) {
+ add(s);
+ return this;
+ }
+
+ /**
+ * @see org.frugenplat.framework.nspace.Dimension#deletePosition(java.lang.String)
+ */
+ public Dimension deletePosition(String s) {
+ remove(s);
+ return this;
+ }
+
+
+
+}
diff --git a/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/SparseNSpace.java b/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/SparseNSpace.java new file mode 100755 index 0000000..4c48842 --- /dev/null +++ b/israfil-foundation-nspace/src/main/java/net/israfil/foundation/collections/nspace/SparseNSpace.java @@ -0,0 +1,165 @@ +/*
+ * Copyright (c) 2003, Mishkin Berteig and Christian Gruber
+ *
+ * $Id: SparseNSpace.java 260 2005-05-15 13:08:53Z cgruber $
+ */
+package net.israfil.foundation.collections.nspace;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * An implementatino of NSpace that is sparsely populated.
+ *
+ * @author <a href="mailto:mishkin@berteig.com">Mishkin Berteig</a>
+ * @author <a href="mailto:cgruber@israfil.net">Christian Gruber</a>
+ * @version $Revision: 260 $
+ */
+public class SparseNSpace implements NSpace {
+
+ private final Set<Dimension> dimensions = new HashSet<Dimension>();
+
+ public SparseNSpace() {
+ super();
+ }
+
+ public SparseNSpace(Set<Dimension> initialDimensions) {
+ this();
+ for (Dimension d : dimensions) {
+ // This is temporary, until we have an internal protected mutator.
+ dimensions.add(d);
+ }
+ }
+
+ /**
+ * @see org.frugenplat.framework.nspace.NSpace#createDimension(java.lang.String, java.lang.String)
+ */
+ public Dimension createDimension(String name, String initialSlot)
+ throws DimensionExistsException {
+ Dimension d = new SimpleDimension(name,initialSlot);
+ dimensions.add(d);
+ return d;
+ }
+
+ /**
+ * @see org.frugenplat.framework.nspace.NSpace#deleteDimension(org.frugenplat.framework.nspace.Dimension)
+ */
+ public void deleteDimension(Dimension dimension) {
+ throw new UnsupportedOperationException("Not yet implemented.");
+ }
+
+ /**
+ * @see org.frugenplat.framework.nspace.NSpace#dimensionAddedPosition(org.frugenplat.framework.nspace.Dimension, java.lang.String)
+ */
+ public void dimensionAddedPosition(Dimension dimension, String position) {
+ throw new UnsupportedOperationException("Not yet implemented.");
+ }
+
+ /**
+ * @see org.frugenplat.framework.nspace.NSpace#dimensionRemovedPosition(org.frugenplat.framework.nspace.Dimension, java.lang.String)
+ */
+ public void dimensionRemovedPosition(
+ Dimension dimension,
+ String position) {
+ throw new UnsupportedOperationException("Not yet implemented.");
+ }
+
+ /**
+ * @see org.frugenplat.framework.nspace.NSpace#getDimension(java.lang.String)
+ */
+ public Dimension getDimension(String name) {
+ throw new UnsupportedOperationException("Not yet implemented.");
+ }
+
+ /**
+ * Returns an immutable set of dimensions for inspection..
+ * @see org.frugenplat.framework.nspace.NSpace#getDimensions()
+ */
+ public Set<Dimension> getDimensions() {
+ return Collections.unmodifiableSet(dimensions);
+ }
+
+ /**
+ * Exposes the internal dimensions set to any children
+ * @return Set
+ */
+ protected Set<Dimension> getInternalDimensions() {
+ return dimensions;
+ }
+
+ /**
+ * @see org.frugenplat.framework.nspace.NSpace#getValue()
+ */
+ public Object getValue(Coordinate c) {
+ // SparseNSpace s = _slice(c);
+ throw new UnsupportedOperationException("Not yet implemented.");
+ }
+
+ Object _findValue() {
+ throw new UnsupportedOperationException("Not yet implemented.");
+ }
+
+ /**
+ * @see org.frugenplat.framework.nspace.NSpace#isPoint()
+ */
+ public boolean isPoint() {
+ if (dimensions.size() == 0) return true;
+ else {
+ boolean hasThinDimensions = true;
+ for(Dimension d : dimensions){
+ hasThinDimensions = hasThinDimensions &&
+ (d.size() == 1);
+ }
+ return hasThinDimensions;
+ }
+
+ }
+
+ /**
+ * @see org.frugenplat.framework.nspace.NSpace#lookup(org.frugenplat.framework.nspace.Coordinate)
+ */
+ public NSpace lookup(Coordinate c) {
+ return _lookup(c);
+ }
+
+ /**
+ * @see org.frugenplat.framework.nspace.NSpace#setValue(org.frugenplat.framework.nspace.Coordinate, org.frugenplat.framework.nspace.NSpace)
+ */
+ public NSpace setValue(Coordinate c, NSpace value)
+ throws InvalidDimensionalityException {
+ throw new UnsupportedOperationException("Not yet implemented.");
+ }
+
+ /**
+ * @see org.frugenplat.framework.nspace.NSpace#setValue(org.frugenplat.framework.nspace.Coordinate, java.lang.Object)
+ */
+ public NSpace setValue(Coordinate c, Object value)
+ throws InvalidDimensionalityException {
+ throw new UnsupportedOperationException("Not yet implemented.");
+ }
+
+ /**
+ * @see org.frugenplat.framework.nspace.NSpace#slice(org.frugenplat.framework.nspace.Coordinate)
+ */
+ public NSpace slice(Coordinate c) {
+ return _slice(c);
+ }
+
+ private SparseNSpace _lookup(Coordinate c) {
+ if (c.equals(Coordinate.EMPTY)) return this;
+ throw new UnsupportedOperationException("Not yet implemented.");
+ }
+
+ private SparseNSpace _slice(Coordinate c) {
+ if (c.equals(Coordinate.EMPTY)) return this;
+ throw new UnsupportedOperationException("Not yet implemented.");
+ }
+ /* (non-Javadoc)
+ * @see org.frugenplat.framework.nspace.NSpace#slice(org.frugenplat.framework.nspace.Dimension)
+ */
+ public NSpace[] slice(Dimension d) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/israfil-foundation-nspace/src/site/apt/Specification.apt b/israfil-foundation-nspace/src/site/apt/Specification.apt new file mode 100755 index 0000000..5da06ac --- /dev/null +++ b/israfil-foundation-nspace/src/site/apt/Specification.apt @@ -0,0 +1,63 @@ +This doc defines the theoretical nature of an NSpace and Sparse NSpace implementation.
+
+
+
+NSpace
+
+ Definition:
+ - N-Dimensional Space representation
+ - NSpace is set of Dimensions
+ - Dimension is a set of Positions
+ - Each dimension is named
+ - Each co-ordinate is specified using names not numbers
+ IOW: Domain of each dim. is specified as a set of names
+ - Number of dimensions can change throughout lifecycle
+ - Dimensions are not ordered in a Space.
+ - Positions are not ordered in a Dimension
+ - value at fully-qualified-coordinate is of type Object
+
+
+ Operations
+ - When looking up co-ordinate - specify dimension + position
+ - 2 kinds of search (lookup and extract)
+
+ Questions:
+ - can an NSpace hold an (NSpace)value
+
+
+Dimension
+
+ Definition
+
+SparseNSpace
+
+ Characteristics:
+
+
+
+ Questions
+
+Example:
+
+ lookup()
+ Given a 5Space
+ specify 3 ordinates in lookup
+ Get a 5Space (3 dims have size of 1)
+
+ extractSlice()
+ Given a 5Space
+ specify 3 ordinates in lookup
+ Get a 2Space
+
+ getDimensions()
+ returns a set of Dimensions
+
+ getDimension(String name)
+ returns a set of Positions
+
+ space.addDimension(Dimension dimension, String origin)
+ all the points in the current system have to know of new dim.
+
+
+
+
diff --git a/israfil-foundation-nspace/src/site/resources/org.frugenplat.framework.nspace.ucd b/israfil-foundation-nspace/src/site/resources/org.frugenplat.framework.nspace.ucd new file mode 100755 index 0000000..dae310b --- /dev/null +++ b/israfil-foundation-nspace/src/site/resources/org.frugenplat.framework.nspace.ucd @@ -0,0 +1,58 @@ +<editmodel:ClassDiagramEditModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:editmodel="editmodel.xmi" size="1088,378" id="fenestratedcgruberSparseNSpace0" metadata="nsuml-1.4" initialized="true"> + <children xsi:type="editmodel:InterfaceEditModel" location="73,103" size="184,265" id="fenestratedcgruberSparseNSpace2" runTimeClassModel="fenestratedcgruberSparseNSpace54;fenestratedcgruberSparseNSpace73;fenestratedcgruberSparseNSpace7;fenestratedcgruberSparseNSpace121;fenestratedcgruberSparseNSpace32;fenestratedcgruberSparseNSpace123;fenestratedcgruberSparseNSpace13;fenestratedcgruberSparseNSpace119;fenestratedcgruberSparseNSpace116;fenestratedcgruberSparseNSpace21;fenestratedcgruberSparseNSpace69;fenestratedcgruberSparseNSpace30"> + <children xsi:type="editmodel:CompartmentEditModel" size="4,4" viewSorter="Name"/> + <children xsi:type="editmodel:CompartmentEditModel" size="4,4" viewSorter="Name"> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace54"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace116"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace69"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace73"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace32"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace30"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace121"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace21"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace119"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace7"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace13"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace123"/> + </children> + <children xsi:type="editmodel:CompartmentEditModel" size="4,4" viewSorter="Name"/> + </children> + <children xsi:type="editmodel:InterfaceEditModel" location="304,226" size="140,139" id="fenestratedcgruberSparseNSpace36" runTimeClassModel="fenestratedcgruberSparseNSpace161;fenestratedcgruberSparseNSpace156;fenestratedcgruberSparseNSpace427;fenestratedcgruberSparseNSpace164;fenestratedcgruberSparseNSpace158;fenestratedcgruberSparseNSpace167;fenestratedcgruberSparseNSpace430"> + <children xsi:type="editmodel:CompartmentEditModel" size="4,4" viewSorter="Name"/> + <children xsi:type="editmodel:CompartmentEditModel" size="121,94" viewSorter="Name"> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace161"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace167"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace427"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace430"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace156"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace158"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace164"/> + </children> + <children xsi:type="editmodel:CompartmentEditModel" size="4,4" viewSorter="Name"/> + </children> + <children xsi:type="editmodel:InterfaceEditModel" location="311,47" size="137,103" id="fenestratedcgruberSparseNSpace150" runTimeClassModel="fenestratedcgruberSparseNSpace171;fenestratedcgruberSparseNSpace175;fenestratedcgruberSparseNSpace173;fenestratedcgruberSparseNSpace177"> + <children xsi:type="editmodel:CompartmentEditModel" size="4,4" viewSorter="Name"/> + <children xsi:type="editmodel:CompartmentEditModel" size="118,58" viewSorter="Name"> + <children xsi:type="editmodel:MethodEditModel" location="299,84" id="fenestratedcgruberSparseNSpace175"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace173"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace177"/> + </children> + <children xsi:type="editmodel:CompartmentEditModel" size="4,4" viewSorter="Name"/> + </children> + <children xsi:type="editmodel:ClassEditModel" location="528,39" size="213,33" id="fenestratedcgruberSparseNSpace258" runTimeClassModel="fenestratedcgruberSparseNSpace419;fenestratedcgruberSparseNSpace417"> + <children xsi:type="editmodel:CompartmentEditModel" size="4,4" viewSorter="Name"/> + <children xsi:type="editmodel:CompartmentEditModel" size="4,4" viewSorter="Name"> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace419"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace417"/> + </children> + <children xsi:type="editmodel:CompartmentEditModel" size="4,4" viewSorter="Name"/> + </children> + <children xsi:type="editmodel:ClassEditModel" location="487,158" size="247,33" id="fenestratedcgruberSparseNSpace261" runTimeClassModel="fenestratedcgruberSparseNSpace414;fenestratedcgruberSparseNSpace412"> + <children xsi:type="editmodel:CompartmentEditModel" size="4,4" viewSorter="Name"/> + <children xsi:type="editmodel:CompartmentEditModel" size="4,4" viewSorter="Name"> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace414"/> + <children xsi:type="editmodel:MethodEditModel" id="fenestratedcgruberSparseNSpace412"/> + </children> + <children xsi:type="editmodel:CompartmentEditModel" size="4,4" viewSorter="Name"/> + </children> +</editmodel:ClassDiagramEditModel> diff --git a/israfil-foundation-nspace/src/test/java/net/israfil/foundation/collections/nspace/SimpleDimensionTest.java b/israfil-foundation-nspace/src/test/java/net/israfil/foundation/collections/nspace/SimpleDimensionTest.java new file mode 100755 index 0000000..cd2d4d4 --- /dev/null +++ b/israfil-foundation-nspace/src/test/java/net/israfil/foundation/collections/nspace/SimpleDimensionTest.java @@ -0,0 +1,211 @@ +package net.israfil.foundation.collections.nspace;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.testng.Assert;
+import org.testng.SkipException;
+import org.testng.annotations.Test;
+
+/**
+ * @author cgruber
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+@Test
+public class SimpleDimensionTest {
+
+ Object o1 = "TestValue1";
+ String d1Name = "TestDimension1";
+ String ordinal1 = "TestOrdinal1";
+ String ordinal2 = "TestOrdinal2";
+ String ordinal3 = "TestOrdinal3";
+
+ /**
+ * test {@link Dimension.Dimension(String,String) Dimension(String,String)}
+ */
+ public void testConstructor_String_String() {
+ Dimension d = new SimpleDimension(d1Name, ordinal1);
+ Assert.assertEquals(d1Name,d.getName(),"Name doesn't equal provided string.");
+ Assert.assertTrue(d.size() == 1,"Size is not equal to 1");
+
+ }
+
+
+ /**
+ * test {@link Dimension.getName() getName()}
+ */
+ public void testGetName() {
+ Dimension d = new SimpleDimension(d1Name, ordinal1);
+ Assert.assertEquals(d1Name,d.getName());
+ }
+
+ /**
+ * test {@link Dimension.register(NSpace) register(NSpace)}
+ */
+ public void testRegister_NSpace() {
+ throw new SkipException("Unimplemented Test");
+ }
+
+ /**
+ * test {@link Dimension.deregister(NSpace) deregister(NSpace)}
+ */
+ public void testDeregister_NSpace() {
+ throw new SkipException("Unimplemented Test");
+ }
+
+ /**
+ * test {@link Dimension.register(NSpace[]) register(NSpace[])}
+ */
+ public void testRegister_NSpaceArray() {
+ throw new SkipException("Unimplemented Test");
+ }
+
+ /**
+ * test {@link Dimension.deregister(NSpace[]) deregister(NSpace[])}
+ */
+ public void testDeregister_NSpaceArray() {
+ throw new SkipException("Unimplemented Test");
+ }
+
+ /**
+ * test {@link Dimension.add(Object) add(Object)}
+ */
+ public void testAdd_Object() {
+ Dimension d = new SimpleDimension(d1Name,ordinal1);
+ d.add(ordinal2);
+ Assert.assertTrue(d.contains(ordinal2),"Dimension doesn't contain added position.");
+ }
+
+ /**
+ * test {@link Dimension.addAll(Collection) addAll(Collection)}
+ */
+ public void testAddAll_Collection() {
+ Dimension d = new SimpleDimension(d1Name,ordinal1);
+ Collection<String> c = new HashSet<String>();
+ c.add(ordinal2);
+ c.add(ordinal3);
+
+ d.addAll(c);
+ Assert.assertTrue(d.contains(ordinal2),"Dimension doesn't contain added position.");
+ Assert.assertTrue(d.contains(ordinal3),"Dimension doesn't contain added position.");
+ }
+
+ @Test(expectedExceptions={UnsupportedOperationException.class})
+ public void testClear() {
+ new SimpleDimension(d1Name,ordinal1).clear();
+ }
+
+ /**
+ * test {@link Dimension.containsAll(Collection) containsAll(Collection)}
+ */
+ public void testContainsAll_Collection() {
+ Dimension d = new SimpleDimension(d1Name,ordinal1);
+ d.add(ordinal2);
+
+ Collection<String> c = new HashSet<String>();
+ c.add(ordinal1);
+ c.add(ordinal2);
+ Assert.assertTrue(d.containsAll(c),"Dimension doesn't contain added positions.");
+
+ d = new SimpleDimension(d1Name,ordinal1);
+ Assert.assertFalse(d.containsAll(c),"Dimension claims to contain positions it shouldn't.");
+ }
+
+ @Test(expectedExceptions={UnsupportedOperationException.class})
+ public void testIsEmpty() {
+ new SimpleDimension(d1Name,ordinal1).isEmpty();
+ }
+
+ /**
+ * test {@link Dimension.iterator() iterator()}
+ */
+ public void testIterator() {
+ Dimension d = new SimpleDimension(d1Name,ordinal1);
+ Iterator<String> i = d.iterator();
+ Assert.assertEquals(ordinal1,i.next());
+ Assert.assertFalse(i.hasNext());
+ }
+
+ /**
+ * test (@link Dimension.remove(Object) remove(Object)}
+ */
+ public void testRemove_Object() {
+ String toBeRemoved = ordinal2;
+ Dimension d = new SimpleDimension(d1Name,ordinal1)
+ .addPosition(toBeRemoved);
+ Assert.assertTrue(d.contains(toBeRemoved));
+ d.remove(toBeRemoved);
+ Assert.assertFalse(d.contains(toBeRemoved));
+ }
+
+ /**
+ * test {@link Dimension.removeAll(Collection) removeAll(Collection)}
+ * TODO: This should test removing every position
+ */
+ public void testRemoveAll_Collection() {
+ Dimension d = new SimpleDimension(d1Name,ordinal1)
+ .addPosition(ordinal2)
+ .addPosition(ordinal3);
+
+ Assert.assertTrue(d.contains(ordinal2));
+ Assert.assertTrue(d.contains(ordinal3));
+
+ Collection<String> c = new HashSet<String>();
+ c.add(ordinal2);
+ c.add(ordinal3);
+ d.removeAll(c);
+ Assert.assertEquals(d.size(),1);
+ }
+
+ /**
+ * test {@link Dimension.retainAll(Collection) retainAll(Collection)}
+ */
+ public void testRetainAll_Collection() {
+ Dimension d = new SimpleDimension(d1Name,ordinal1)
+ .addPosition(ordinal2)
+ .addPosition(ordinal3);
+
+ Assert.assertTrue(d.contains(ordinal2));
+ Assert.assertTrue(d.contains(ordinal3));
+
+ Collection<String> c = new HashSet<String>();
+ c.add(ordinal2);
+ c.add(ordinal3);
+ d.retainAll(c);
+ Assert.assertEquals(d.size(),2);
+ }
+
+ /**
+ * test {@link Dimensions.size() size()}
+ */
+ public void testSize() {
+ Dimension d = new SimpleDimension(d1Name,ordinal1)
+ .addPosition(ordinal2)
+ .addPosition(ordinal3);
+ Assert.assertEquals(d.size(),3);
+ }
+
+ /**
+ * test {@link Dimensions.toArray() toArray()}
+ */
+ public void testToArray() {
+ Dimension d = new SimpleDimension(d1Name,ordinal1);
+ String[] sa = (String[])d.toArray();
+ Assert.assertEquals(sa[0],ordinal1);
+ }
+
+ /**
+ * test {@link Dimension.toArray(Object[]) toArray(Object[])}
+ */
+ public void testToArray_ObjectArray() {
+ Dimension d = new SimpleDimension(d1Name,ordinal1);
+ String[] sa = (String[])d.toArray(new String[d.size()]);
+ Assert.assertEquals(sa[0],ordinal1);
+ }
+
+}
diff --git a/israfil-foundation-nspace/src/test/java/net/israfil/foundation/collections/nspace/SparseNSpaceTest.java b/israfil-foundation-nspace/src/test/java/net/israfil/foundation/collections/nspace/SparseNSpaceTest.java new file mode 100755 index 0000000..b291a23 --- /dev/null +++ b/israfil-foundation-nspace/src/test/java/net/israfil/foundation/collections/nspace/SparseNSpaceTest.java @@ -0,0 +1,87 @@ +/*
+ * Copyright (c) 2003, Mishkin Berteig and Christian Gruber
+ *
+ * $Id: SparseNSpaceTest.java 261 2005-05-15 13:36:26Z cgruber $
+ */
+package net.israfil.foundation.collections.nspace;
+
+import org.testng.Assert;
+import org.testng.SkipException;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:mishkin@berteig.com">Mishkin Berteig</a>
+ * @author <a href="mailto:cgruber@israfil.net">Christian Gruber</a>
+ * @version $Revision: 261 $
+ */
+@Test
+public class SparseNSpaceTest {
+
+ public void testCreateDimension_String_String() {
+ throw new SkipException("Unimplemented Test");
+ }
+
+ public void testDeleteDimension_Dimension() {
+ throw new SkipException("Unimplemented Test");
+ }
+
+ public void testDimensionAddedPosition() {
+ throw new SkipException("Unimplemented Test");
+ }
+
+ public void testDimensionRemovedPosition() {
+ throw new SkipException("Unimplemented Test");
+ }
+
+ public void testGetDimension_String() {
+ throw new SkipException("Unimplemented Test");
+ }
+
+ public void testGetDimensions() {
+ throw new SkipException("Unimplemented Test");
+ }
+
+ public void testGetValue() throws InvalidDimensionalityException {
+ NSpace space = new SparseNSpace();
+ throw new SkipException("Unimplemented Test");
+ }
+
+ public void testIsPoint() throws DimensionExistsException {
+ NSpace space = new SparseNSpace();
+ Assert.assertTrue(space.isPoint());
+
+ // Create two "thin" dimensions.
+ space.createDimension("TestDimension1","TestOrdinal");
+ space.createDimension("TestDimension2","TestOrdinal");
+
+ Assert.assertTrue(space.isPoint());
+ /*
+ space.createDimension("TestDimension3","TestOrdinal1")
+ .addPosition("TestOrdinal2");
+ Assert.assertFalse(space.isPoint());
+ */
+ }
+
+ public void testLookup_Coordinate() {
+ throw new SkipException("Unimplemented Test");
+ }
+
+ /*
+ * Test for NSpace setValue(Coordinate, NSpace)
+ */
+ public void testSetValue_Coordinate_NSpace() {
+ throw new SkipException("Unimplemented Test");
+ }
+
+ /*
+ * Test for NSpace setValue(Coordinate, Object)
+ */
+ public void testSetValue_Coordinate_Object() {
+ throw new SkipException("Unimplemented Test");
+ }
+
+ public void testSlice() {
+ throw new SkipException("Unimplemented Test");
+ }
+
+}
|
