[Swift-commit] r7841 - in trunk/src/org/griphyn/vdl/type: . impl
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Thu May 8 23:48:06 CDT 2014
Author: hategan
Date: 2014-05-08 23:48:06 -0500 (Thu, 08 May 2014)
New Revision: 7841
Modified:
trunk/src/org/griphyn/vdl/type/Field.java
trunk/src/org/griphyn/vdl/type/Type.java
trunk/src/org/griphyn/vdl/type/impl/FieldImpl.java
trunk/src/org/griphyn/vdl/type/impl/ImmutableField.java
trunk/src/org/griphyn/vdl/type/impl/TypeImpl.java
trunk/src/org/griphyn/vdl/type/impl/UnresolvedType.java
Log:
support fields that are indexed and a bunch of other things
Modified: trunk/src/org/griphyn/vdl/type/Field.java
===================================================================
--- trunk/src/org/griphyn/vdl/type/Field.java 2014-05-09 04:46:37 UTC (rev 7840)
+++ trunk/src/org/griphyn/vdl/type/Field.java 2014-05-09 04:48:06 UTC (rev 7841)
@@ -55,8 +55,7 @@
* of Field.
*/
- public static final class Factory
- {
+ public static final class Factory {
private static final Map<Field, Field> fieldCache = new HashMap<Field, Field>();
public static Field newInstance() {
return new FieldImpl();
@@ -77,6 +76,14 @@
return cached;
}
}
- }
+ }
+
+ public static final Field GENERIC_STRING = new FieldImpl("?", Types.STRING);
+ public static final Field GENERIC_ANY = new FieldImpl("?", Types.ANY);
+ public static final Field GENERIC_BOOLEAN = new FieldImpl("?", Types.BOOLEAN);
+ public static final Field GENERIC_INT = new FieldImpl("?", Types.INT);
+ public static final Field GENERIC_FLOAT = new FieldImpl("?", Types.FLOAT);
+
+ public static final Field GENERIC_STRING_ARRAY = new FieldImpl("?", Types.STRING.arrayType());
}
Modified: trunk/src/org/griphyn/vdl/type/Type.java
===================================================================
--- trunk/src/org/griphyn/vdl/type/Type.java 2014-05-09 04:46:37 UTC (rev 7840)
+++ trunk/src/org/griphyn/vdl/type/Type.java 2014-05-09 04:48:06 UTC (rev 7841)
@@ -111,7 +111,9 @@
* @return Field
* @throws NoSuchFieldException
*/
- public Field getField(String name) throws NoSuchFieldException;
+ public Field getField(String name) throws NoSuchFieldException;
+
+ public int getFieldIndex(String name) throws NoSuchFieldException;
/**
* get a list of field names
@@ -187,7 +189,7 @@
}
- public boolean hasNonPrimitiveComponents();
+ public boolean hasMappedComponents();
public boolean hasArrayComponents();
}
Modified: trunk/src/org/griphyn/vdl/type/impl/FieldImpl.java
===================================================================
--- trunk/src/org/griphyn/vdl/type/impl/FieldImpl.java 2014-05-09 04:46:37 UTC (rev 7840)
+++ trunk/src/org/griphyn/vdl/type/impl/FieldImpl.java 2014-05-09 04:48:06 UTC (rev 7841)
@@ -23,21 +23,13 @@
public class FieldImpl implements Field {
private Comparable<?> id;
private Type type;
- private boolean array = false;
-
+
public FieldImpl() {
}
-
- public FieldImpl(Comparable<?> id, Type type, boolean array) {
- this.id = id;
- this.type = type;
- this.array = array;
- }
public FieldImpl(Comparable<?> id, Type type) {
this.id = id;
this.type = type;
- this.array = false;
}
public Comparable<?> getId() {
@@ -48,14 +40,6 @@
this.id = id;
}
- public boolean isArray() {
- return array;
- }
-
- public void setArray() {
- array = true;
- }
-
public Type getType() {
return type;
}
Modified: trunk/src/org/griphyn/vdl/type/impl/ImmutableField.java
===================================================================
--- trunk/src/org/griphyn/vdl/type/impl/ImmutableField.java 2014-05-09 04:46:37 UTC (rev 7840)
+++ trunk/src/org/griphyn/vdl/type/impl/ImmutableField.java 2014-05-09 04:48:06 UTC (rev 7841)
@@ -23,11 +23,6 @@
}
@Override
- public void setArray() {
- throw new UnsupportedOperationException();
- }
-
- @Override
public void setType(Type type) {
throw new UnsupportedOperationException();
}
Modified: trunk/src/org/griphyn/vdl/type/impl/TypeImpl.java
===================================================================
--- trunk/src/org/griphyn/vdl/type/impl/TypeImpl.java 2014-05-09 04:46:37 UTC (rev 7840)
+++ trunk/src/org/griphyn/vdl/type/impl/TypeImpl.java 2014-05-09 04:48:06 UTC (rev 7841)
@@ -30,9 +30,10 @@
public class TypeImpl extends UnresolvedType {
private boolean primitive;
- private Map<String, Field> fields;
+ private Map<String, Field> fields;
+ private Map<String, Integer> fieldIndices;
private Type baseType;
- private Boolean hasNonPrimitiveComponents, hasArrayComponents;
+ private Boolean hasMappedComponents, hasArrayComponents;
public TypeImpl() {
this((URI) null, null, false);
@@ -71,7 +72,11 @@
throw new DuplicateFieldException(name);
}
else {
- fields.put(name, field);
+ fields.put(name, field);
+ if (fieldIndices == null) {
+ fieldIndices = new HashMap<String, Integer>();
+ }
+ fieldIndices.put(name, fieldIndices.size());
}
}
@@ -92,6 +97,17 @@
else {
throw new NoSuchFieldException(name);
}
+ }
+
+ public int getFieldIndex(String name) throws NoSuchFieldException {
+ if (fieldIndices == null) {
+ throw new NoSuchFieldException("The type " + this + " has no fields");
+ }
+ Integer i = fieldIndices.get(name);
+ if (i == null) {
+ throw new NoSuchFieldException("The type " + this + " has no field named '" + name + "'");
+ }
+ return i;
}
public List<String> getFieldNames() {
@@ -132,37 +148,37 @@
return isArray() || !fields.isEmpty();
}
- public synchronized boolean hasNonPrimitiveComponents() {
- if (hasNonPrimitiveComponents == null) {
+ public synchronized boolean hasMappedComponents() {
+ if (hasMappedComponents == null) {
if (isPrimitive()) {
- hasNonPrimitiveComponents = false;
+ hasMappedComponents = false;
}
else if (!isComposite()) {
// mapped
- hasNonPrimitiveComponents = true;
+ hasMappedComponents = true;
}
else if (isArray()) {
- if (keyType().hasNonPrimitiveComponents()) {
- hasNonPrimitiveComponents = true;
+ if (keyType().hasMappedComponents()) {
+ hasMappedComponents = true;
}
- else if (itemType().hasNonPrimitiveComponents()) {
- hasNonPrimitiveComponents = true;
+ else if (itemType().hasMappedComponents()) {
+ hasMappedComponents = true;
}
else {
- hasNonPrimitiveComponents = false;
+ hasMappedComponents = false;
}
}
else {
// struct
for (Field f : getFields()) {
- if (f.getType().hasNonPrimitiveComponents()) {
- return hasNonPrimitiveComponents = true;
+ if (f.getType().hasMappedComponents()) {
+ return hasMappedComponents = true;
}
}
- hasNonPrimitiveComponents = false;
+ hasMappedComponents = false;
}
}
- return hasNonPrimitiveComponents;
+ return hasMappedComponents;
}
public synchronized boolean hasArrayComponents() {
Modified: trunk/src/org/griphyn/vdl/type/impl/UnresolvedType.java
===================================================================
--- trunk/src/org/griphyn/vdl/type/impl/UnresolvedType.java 2014-05-09 04:46:37 UTC (rev 7840)
+++ trunk/src/org/griphyn/vdl/type/impl/UnresolvedType.java 2014-05-09 04:48:06 UTC (rev 7841)
@@ -85,9 +85,14 @@
}
@Override
- public boolean hasNonPrimitiveComponents() {
+ public int getFieldIndex(String name) throws NoSuchFieldException {
throw new UnsupportedOperationException();
}
+
+ @Override
+ public boolean hasMappedComponents() {
+ throw new UnsupportedOperationException();
+ }
@Override
public boolean hasArrayComponents() {
More information about the Swift-commit
mailing list