summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/data/type/VectorTypeInformation.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/data/type/VectorTypeInformation.java')
-rw-r--r--src/de/lmu/ifi/dbs/elki/data/type/VectorTypeInformation.java84
1 files changed, 64 insertions, 20 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/data/type/VectorTypeInformation.java b/src/de/lmu/ifi/dbs/elki/data/type/VectorTypeInformation.java
index 7d568a55..8334e88d 100644
--- a/src/de/lmu/ifi/dbs/elki/data/type/VectorTypeInformation.java
+++ b/src/de/lmu/ifi/dbs/elki/data/type/VectorTypeInformation.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.type;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -24,7 +24,7 @@ package de.lmu.ifi.dbs.elki.data.type;
*/
import de.lmu.ifi.dbs.elki.data.FeatureVector;
-import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer;
+import de.lmu.ifi.dbs.elki.utilities.io.ByteBufferSerializer;
/**
* Construct a type information for vector spaces with fixed dimensionality.
@@ -37,31 +37,43 @@ import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer;
*/
public class VectorTypeInformation<V extends FeatureVector<?>> extends SimpleTypeInformation<V> {
/**
- * Minimum dimensionality.
+ * Object factory for producing new instances.
*/
- protected final int mindim;
+ private final FeatureVector.Factory<V, ?> factory;
/**
- * Maximum dimensionality.
+ * Constructor for a type request without dimensionality constraints.
+ *
+ * @param cls Class constraint
+ * @param <V> vector type
*/
- protected final int maxdim;
-
+ public static <V extends FeatureVector<?>> VectorTypeInformation<V> typeRequest(Class<? super V> cls) {
+ return new VectorTypeInformation<>(cls, -1, Integer.MAX_VALUE);
+ }
+
/**
- * Constructor for an actual type.
+ * Constructor for a type request with dimensionality constraints.
*
- * @param cls base class
- * @param serializer Serializer
+ * @param cls Class constraint
* @param mindim Minimum dimensionality
* @param maxdim Maximum dimensionality
+ * @param <V> vector type
*/
- public VectorTypeInformation(Class<? super V> cls, ByteBufferSerializer<? super V> serializer, int mindim, int maxdim) {
- super(cls, serializer);
- assert (this.mindim <= this.maxdim);
- this.mindim = mindim;
- this.maxdim = maxdim;
+ public static <V extends FeatureVector<?>> VectorTypeInformation<V> typeRequest(Class<? super V> cls, int mindim, int maxdim) {
+ return new VectorTypeInformation<>(cls, mindim, maxdim);
}
/**
+ * Minimum dimensionality.
+ */
+ protected final int mindim;
+
+ /**
+ * Maximum dimensionality.
+ */
+ protected final int maxdim;
+
+ /**
* Constructor for a type request.
*
* @param cls base class
@@ -69,16 +81,27 @@ public class VectorTypeInformation<V extends FeatureVector<?>> extends SimpleTyp
* @param maxdim Maximum dimensionality
*/
public VectorTypeInformation(Class<? super V> cls, int mindim, int maxdim) {
- this(cls, null, mindim, maxdim);
+ super(cls);
+ this.factory = null;
+ assert (mindim <= maxdim);
+ this.mindim = mindim;
+ this.maxdim = maxdim;
}
/**
- * Constructor for a type request without dimensionality constraints.
+ * Constructor for an actual type.
*
- * @param cls Class constraint
+ * @param factory Vector factory
+ * @param serializer Serializer
+ * @param mindim Minimum dimensionality
+ * @param maxdim Maximum dimensionality
*/
- public VectorTypeInformation(Class<? super V> cls) {
- this(cls, null, -1, Integer.MAX_VALUE);
+ public VectorTypeInformation(FeatureVector.Factory<V, ?> factory, ByteBufferSerializer<? super V> serializer, int mindim, int maxdim) {
+ super(factory.getRestrictionClass(), serializer);
+ this.factory = factory;
+ assert (mindim <= maxdim);
+ this.mindim = mindim;
+ this.maxdim = maxdim;
}
@Override
@@ -122,6 +145,18 @@ public class VectorTypeInformation<V extends FeatureVector<?>> extends SimpleTyp
}
/**
+ * Get the object type factory.
+ *
+ * @return the factory
+ */
+ public FeatureVector.Factory<V, ?> getFactory() {
+ if(factory == null) {
+ throw new UnsupportedOperationException("Requesting factory for a type request!");
+ }
+ return factory;
+ }
+
+ /**
* Get the minimum dimensionality of the occurring vectors.
*
* @return dimensionality
@@ -145,6 +180,15 @@ public class VectorTypeInformation<V extends FeatureVector<?>> extends SimpleTyp
return maxdim;
}
+ /**
+ * Get the multiplicity of the vector.
+ *
+ * @return Multiplicity {@code 1} (except for subclasses)
+ */
+ public int getMultiplicity() {
+ return 1;
+ }
+
@Override
public String toString() {
StringBuilder buf = new StringBuilder(super.toString());