8 modified files
GeomConverter/src/org/lcsim/detector/identifier
diff -u -r1.6 -r1.7
--- ExpandedIdentifier.java 12 Jul 2007 06:53:42 -0000 1.6
+++ ExpandedIdentifier.java 28 Aug 2007 22:25:46 -0000 1.7
@@ -7,7 +7,7 @@
* Implementation of {@link IExpandedIdentifier}.
*
* @author Jeremy McCormick
- * @version $Id: ExpandedIdentifier.java,v 1.6 2007/07/12 06:53:42 jeremy Exp $
+ * @version $Id: ExpandedIdentifier.java,v 1.7 2007/08/28 22:25:46 jeremy Exp $
*/
public class ExpandedIdentifier
@@ -18,6 +18,22 @@
public ExpandedIdentifier()
{}
+ public ExpandedIdentifier( int reserve )
+ {
+ if (reserve > 64)
+ {
+ throw new RuntimeException("cannot reserve more than 64 fields");
+ }
+
+ if (reserve > 0)
+ {
+ for (int i=0; i<reserve; i++)
+ {
+ addValue(0);
+ }
+ }
+ }
+
public ExpandedIdentifier( int[] values )
{
for ( int value : values )
GeomConverter/src/org/lcsim/detector/identifier
diff -u -r1.8 -r1.9
--- IExpandedIdentifier.java 12 Jul 2007 06:53:42 -0000 1.8
+++ IExpandedIdentifier.java 28 Aug 2007 22:25:46 -0000 1.9
@@ -10,7 +10,7 @@
* see which indices correspond to which field labels.
*
* @author jeremym
- * @version $Id: IExpandedIdentifier.java,v 1.8 2007/07/12 06:53:42 jeremy Exp $
+ * @version $Id: IExpandedIdentifier.java,v 1.9 2007/08/28 22:25:46 jeremy Exp $
*/
public interface IExpandedIdentifier
@@ -77,4 +77,12 @@
* used for the field range.
*/
public int match(IExpandedIdentifier id);
+
+ /**
+ * Compare a single field value.
+ * @param id
+ * @param idx
+ * @return
+ */
+ public int compareField( IExpandedIdentifier id, int idx );
}
GeomConverter/src/org/lcsim/detector/identifier
diff -u -r1.6 -r1.7
--- IIdentifiable.java 25 May 2007 20:16:26 -0000 1.6
+++ IIdentifiable.java 28 Aug 2007 22:25:46 -0000 1.7
@@ -6,7 +6,7 @@
* for performing pack and unpack operations on these objects.
*
* @author Jeremy McCormick
- * @version $Id: IIdentifiable.java,v 1.6 2007/05/25 20:16:26 jeremy Exp $
+ * @version $Id: IIdentifiable.java,v 1.7 2007/08/28 22:25:46 jeremy Exp $
*/
public interface IIdentifiable
{
@@ -23,7 +23,7 @@
*
* @return The ExpandedIdentifier.
*/
- public IExpandedIdentifier getExpandedIdentifier();
+ public IExpandedIdentifier getExpandedIdentifier();
/**
* Get the {@link IIdentifierHelper} associated with this object.
GeomConverter/src/org/lcsim/detector/identifier
diff -u -r1.6 -r1.7
--- IIdentifierDictionary.java 25 May 2007 20:16:26 -0000 1.6
+++ IIdentifierDictionary.java 28 Aug 2007 22:25:46 -0000 1.7
@@ -7,7 +7,7 @@
* that define the fields of an {@link IIdentifier}.
*
* @author Jeremy McCormick
- * @version $Id: IIdentifierDictionary.java,v 1.6 2007/05/25 20:16:26 jeremy Exp $
+ * @version $Id: IIdentifierDictionary.java,v 1.7 2007/08/28 22:25:46 jeremy Exp $
*/
public interface IIdentifierDictionary
{
@@ -23,7 +23,7 @@
*
* @param field A field to add.
*/
- public void addField(IIdentifierField field);
+ public void addField(IIdentifierField field) throws DuplicateFieldException;
/**
* Get a field by name.
@@ -31,7 +31,7 @@
* @param fieldName The field.
* @return The field.
*/
- public IIdentifierField getField(String fieldName);
+ public IIdentifierField getField(String fieldName) throws FieldNotFoundException;
/**
* True if this <code>IdentifierDictionary</code> contains the field.
@@ -45,7 +45,7 @@
* @param fieldName The name of the field.
* @return The index index of the field.
*/
- public int getFieldIndex(String fieldName);
+ public int getFieldIndex(String fieldName) throws FieldNotFoundException;
/**
* Get a field by index.
@@ -53,7 +53,7 @@
* @param index The index.
* @return The field.
*/
- public IIdentifierField getField(int index);
+ public IIdentifierField getField(int index) throws InvalidIndexException;
/**
* Get the mapping of names to fields.
@@ -87,5 +87,39 @@
* @param i The index.
* @return True if has index.
*/
- public boolean hasIndex(int i);
+ public boolean hasIndex(int i);
+
+
+ /**
+ * Thrown when a field lookup fails.
+ */
+ public final class FieldNotFoundException extends Exception
+ {
+ FieldNotFoundException(String field, IIdentifierDictionary dict)
+ {
+ super("The field " + field + " was not found in the dictionary " + dict.getName());
+ }
+ }
+
+ /**
+ * Thrown when an invalid index is passed as an argument.
+ */
+ public final class InvalidIndexException extends Exception
+ {
+ InvalidIndexException(int idx, IIdentifierDictionary dict)
+ {
+ super("The idx " + idx + " is invalid for the dictionary " + dict.getName());
+ }
+ }
+
+ /**
+ * Thrown when trying to add a field that already exists.
+ */
+ public final class DuplicateFieldException extends Exception
+ {
+ DuplicateFieldException(String field, IIdentifierDictionary dict)
+ {
+ super("The field " + field + " already exists in the dictionary " + dict.getName());
+ }
+ }
}
\ No newline at end of file
GeomConverter/src/org/lcsim/detector/identifier
diff -u -r1.4 -r1.5
--- IIdentifierHelper.java 11 May 2007 00:21:09 -0000 1.4
+++ IIdentifierHelper.java 28 Aug 2007 22:25:46 -0000 1.5
@@ -1,5 +1,8 @@
package org.lcsim.detector.identifier;
+import org.lcsim.detector.identifier.IIdentifierDictionary.FieldNotFoundException;
+import org.lcsim.detector.identifier.IIdentifierDictionary.InvalidIndexException;
+
/**
* This class has a reference to a single {@link IIdentifierDictionary}
* that specifies the fields for a 64-bit {@link IIdentifier}.
@@ -23,7 +26,7 @@
* @see IIdentifierDictionary
*
* @author Jeremy McCormick
- * @version $Id: IIdentifierHelper.java,v 1.4 2007/05/11 00:21:09 jeremy Exp $
+ * @version $Id: IIdentifierHelper.java,v 1.5 2007/08/28 22:25:46 jeremy Exp $
*/
public interface IIdentifierHelper
@@ -42,7 +45,7 @@
* @param id The ExpandedIdentifier to be packed.
* @return The compact identfier.
*/
- public IIdentifier pack( IExpandedIdentifier id );
+ public IIdentifier pack( IExpandedIdentifier id ) throws InvalidIndexException;
/**
* Get a single field value using an {@link IIdentifierField}.
@@ -60,7 +63,7 @@
* @param field The field index in the dictionary.
* @return The field value.
*/
- public int getValue( IIdentifier compact, int field );
+ public int getValue( IIdentifier compact, int field ) throws InvalidIndexException;
/**
* Get a single field value by name.
@@ -69,7 +72,7 @@
* @param field The field index in the dictionary.
* @return The field value.
*/
- public int getValue( IIdentifier compact, String field );
+ public int getValue( IIdentifier compact, String field ) throws FieldNotFoundException;
/**
* Pack a subset of fields in an {@link IExpandedIdentifier}.
@@ -78,7 +81,7 @@
* @param start The start index in the ExpandedIdentifier.
* @return An Identifier with the packed fields.
*/
- public IIdentifier pack(IExpandedIdentifier id, int start);
+ public IIdentifier pack(IExpandedIdentifier id, int start) throws InvalidIndexException;
/**
* Pack a subset of fields in an {@link IExpandedIdentifier}.
@@ -88,7 +91,7 @@
* @param endIndex End index.
* @return An Identifier with the packed fields.
*/
- public IIdentifier pack(IExpandedIdentifier id, int startIndex, int endIndex );
+ public IIdentifier pack(IExpandedIdentifier id, int startIndex, int endIndex ) throws InvalidIndexException;
/**
* Upack the {@link IIdentifier} into an {@link IExpandedIdentifier}
@@ -97,7 +100,7 @@
* @param id The Identifier.
* @return An ExpandedIdentifier.
*/
- public IExpandedIdentifier unpack(IIdentifier id);
+ public IExpandedIdentifier unpack(IIdentifier id) throws InvalidIndexException;
/**
*
@@ -112,7 +115,7 @@
* @param endIndex The end index.
* @return An ExpandedIdentifier with the unpacked values.
*/
- public IExpandedIdentifier unpack(IIdentifier id, int startIndex, int endIndex );
+ public IExpandedIdentifier unpack(IIdentifier id, int startIndex, int endIndex ) throws InvalidIndexException;
/**
* Upack the {@link IIdentifier} into an {@link IExpandedIdentifier}
@@ -125,5 +128,5 @@
* @param startIndex The start field index.
* @return An ExpandedIdentifier with the unpacked values.
*/
- public IExpandedIdentifier unpack(IIdentifier id, int startIndex);
+ public IExpandedIdentifier unpack(IIdentifier id, int startIndex) throws InvalidIndexException;
}
\ No newline at end of file
GeomConverter/src/org/lcsim/detector/identifier
diff -u -r1.4 -r1.5
--- IdentifierDictionary.java 18 May 2007 23:47:33 -0000 1.4
+++ IdentifierDictionary.java 28 Aug 2007 22:25:46 -0000 1.5
@@ -8,7 +8,7 @@
* Implementation of {@link IIdentifierDictionary}.
*
* @author Jeremy McCormick
- * @version $Id: IdentifierDictionary.java,v 1.4 2007/05/18 23:47:33 jeremy Exp $
+ * @version $Id: IdentifierDictionary.java,v 1.5 2007/08/28 22:25:46 jeremy Exp $
*/
public class IdentifierDictionary implements IIdentifierDictionary
@@ -17,7 +17,7 @@
Map<Integer,IIdentifierField> fieldOrder = new HashMap<Integer, IIdentifierField>();
Map<String,Integer> nameOrder = new HashMap<String,Integer>();
private String name;
-
+
public IdentifierDictionary(String name)
{
this.name = name;
@@ -28,11 +28,11 @@
return name;
}
- public void addField(IIdentifierField field)
+ public void addField(IIdentifierField field) throws DuplicateFieldException
{
if ( fields.containsKey( field.getLabel() ) )
{
- throw new IllegalArgumentException("Dictionary already has a field called <" + field.getLabel() + ">.");
+ throw new DuplicateFieldException(field.getLabel(),this);
}
// Put into the field map.
@@ -45,18 +45,26 @@
nameOrder.put( field.getLabel(), field.getOrder() );
}
- public IIdentifierField getField(String fieldName)
+ public IIdentifierField getField(String fieldName) throws FieldNotFoundException
{
+ if (!fields.containsKey(fieldName))
+ {
+ throw new FieldNotFoundException(fieldName, this);
+ }
return fields.get(fieldName);
}
- public int getFieldIndex(String fieldName)
+ public int getFieldIndex(String fieldName) throws FieldNotFoundException
{
- return nameOrder.get( fieldName );
+ if (!nameOrder.containsKey(fieldName))
+ throw new FieldNotFoundException(fieldName,this);
+ return nameOrder.get(fieldName);
}
- public IIdentifierField getField(int index)
+ public IIdentifierField getField(int index) throws InvalidIndexException
{
+ if (!isValidIndex(index))
+ throw new InvalidIndexException(index, this);
return (IIdentifierField)fields.values().toArray()[index];
}
GeomConverter/src/org/lcsim/detector/identifier
diff -u -r1.9 -r1.10
--- IdentifierHelper.java 22 May 2007 20:02:05 -0000 1.9
+++ IdentifierHelper.java 28 Aug 2007 22:25:46 -0000 1.10
@@ -1,28 +1,31 @@
package org.lcsim.detector.identifier;
+import org.lcsim.detector.identifier.IIdentifierDictionary.FieldNotFoundException;
+import org.lcsim.detector.identifier.IIdentifierDictionary.InvalidIndexException;
+
/**
*
* Implementation of {@link IIdentifierHelper}.
*
* @author Jeremy McCormick
- * @version $Id: IdentifierHelper.java,v 1.9 2007/05/22 20:02:05 jeremy Exp $
+ * @version $Id: IdentifierHelper.java,v 1.10 2007/08/28 22:25:46 jeremy Exp $
*/
public class IdentifierHelper
implements IIdentifierHelper
{
private IIdentifierDictionary iddict=null;
-
- public IExpandedIdentifier unpack( IIdentifier id, int start, int nfields)
+
+ public IExpandedIdentifier unpack( IIdentifier id, int start, int nfields) throws InvalidIndexException
{
return IdentifierUtil.unpack( iddict, id, start, nfields );
}
- public IExpandedIdentifier unpack( IIdentifier id, int start)
+ public IExpandedIdentifier unpack( IIdentifier id, int start) throws InvalidIndexException
{
return IdentifierUtil.unpack( iddict, id, start );
}
-
+
public IdentifierHelper( IIdentifierDictionary iddict )
{
this.iddict = iddict;
@@ -33,12 +36,12 @@
return iddict;
}
- public IIdentifier pack( IExpandedIdentifier id )
+ public IIdentifier pack( IExpandedIdentifier id ) throws InvalidIndexException
{
return IdentifierUtil.pack(getIdentifierDictionary(), id );
}
- public IExpandedIdentifier unpack( IIdentifier id )
+ public IExpandedIdentifier unpack( IIdentifier id ) throws InvalidIndexException
{
return IdentifierUtil.unpack( iddict, id );
}
@@ -48,22 +51,22 @@
return IdentifierUtil.getValue( compact, desc );
}
- public int getValue( IIdentifier compact, int field )
+ public int getValue( IIdentifier compact, int field ) throws InvalidIndexException
{
return IdentifierUtil.getValue( iddict, compact, field );
}
- public int getValue( IIdentifier compact, String field )
+ public int getValue( IIdentifier compact, String field ) throws FieldNotFoundException
{
return IdentifierUtil.getValue( iddict, compact, field );
}
- public IIdentifier pack(IExpandedIdentifier id, int start)
+ public IIdentifier pack(IExpandedIdentifier id, int start) throws InvalidIndexException
{
return IdentifierUtil.pack( iddict, id, start );
}
- public IIdentifier pack(IExpandedIdentifier id, int start, int nfields)
+ public IIdentifier pack(IExpandedIdentifier id, int start, int nfields) throws InvalidIndexException
{
return IdentifierUtil.pack( iddict, id, start, nfields );
}
GeomConverter/src/org/lcsim/detector/identifier
diff -u -r1.5 -r1.6
--- IdentifierUtil.java 19 May 2007 00:39:51 -0000 1.5
+++ IdentifierUtil.java 28 Aug 2007 22:25:46 -0000 1.6
@@ -1,5 +1,8 @@
package org.lcsim.detector.identifier;
+import org.lcsim.detector.identifier.IIdentifierDictionary.FieldNotFoundException;
+import org.lcsim.detector.identifier.IIdentifierDictionary.InvalidIndexException;
+
/**
* Identifier utility methods for packing {@link IIdentifier}s and
* unpacking {@link IExpandedIdentifier}s using information from an
@@ -15,7 +18,7 @@
* @see IExpandedIdentifier
*
* @author Jeremy McCormick
- * @version $Id: IdentifierUtil.java,v 1.5 2007/05/19 00:39:51 jeremy Exp $
+ * @version $Id: IdentifierUtil.java,v 1.6 2007/08/28 22:25:46 jeremy Exp $
*/
public final class IdentifierUtil
{
@@ -25,17 +28,17 @@
private IdentifierUtil()
{}
- public static IExpandedIdentifier unpack( IIdentifierDictionary iddict, IIdentifier compact, int startIndex )
+ public static IExpandedIdentifier unpack( IIdentifierDictionary iddict, IIdentifier compact, int startIndex ) throws InvalidIndexException
{
return IdentifierUtil.unpack( iddict, compact, startIndex, -1 );
}
- public static IExpandedIdentifier unpack( IIdentifierDictionary iddict, IIdentifier compact )
+ public static IExpandedIdentifier unpack( IIdentifierDictionary iddict, IIdentifier compact ) throws InvalidIndexException
{
return IdentifierUtil.unpack( iddict, compact, 0 );
}
- public static IExpandedIdentifier unpack( IIdentifierDictionary iddict, IIdentifier compact, int startIndex, int endIndex )
+ public static IExpandedIdentifier unpack( IIdentifierDictionary iddict, IIdentifier compact, int startIndex, int endIndex ) throws InvalidIndexException
{
ExpandedIdentifier buffer = new ExpandedIdentifier();
@@ -100,17 +103,17 @@
return desc.unpack(compact);
}
- public static int getValue( IIdentifierDictionary iddict, IIdentifier compact, int field )
+ public static int getValue( IIdentifierDictionary iddict, IIdentifier compact, int field ) throws InvalidIndexException
{
return IdentifierUtil.getValue( compact, iddict.getField( field ) );
}
- public static int getValue( IIdentifierDictionary iddict, IIdentifier compact, String field )
+ public static int getValue( IIdentifierDictionary iddict, IIdentifier compact, String field ) throws FieldNotFoundException
{
return IdentifierUtil.getValue( compact, iddict.getField(field) );
}
- public static IIdentifier pack( IIdentifierDictionary iddict, IExpandedIdentifier id, int startIndex, int endIndex )
+ public static IIdentifier pack( IIdentifierDictionary iddict, IExpandedIdentifier id, int startIndex, int endIndex ) throws InvalidIndexException
{
long result=0;
@@ -154,12 +157,12 @@
return new Identifier( result );
}
- public static IIdentifier pack( IIdentifierDictionary iddict, IExpandedIdentifier id )
+ public static IIdentifier pack( IIdentifierDictionary iddict, IExpandedIdentifier id ) throws InvalidIndexException
{
return IdentifierUtil.pack( iddict, id, 0 );
}
- public static IIdentifier pack( IIdentifierDictionary iddict, IExpandedIdentifier id, int startIndex )
+ public static IIdentifier pack( IIdentifierDictionary iddict, IExpandedIdentifier id, int startIndex ) throws InvalidIndexException
{
return IdentifierUtil.pack( iddict, id, startIndex, -1 );
}
CVSspam 0.2.8