-\r
- protected void toStringAux(Object value, BindingPrintContext ctx) throws BindingException {\r
- ctx.b.append('{');\r
- Component[] components = type().getComponents();\r
- boolean first = true;\r
- for(int i=0;i<components.length;++i) {\r
- if(first)\r
- first = false;\r
- else {\r
- ctx.b.append(", ");\r
- if (!ctx.singleLine) ctx.b.append('\n');\r
- }\r
- Binding binding = getComponentBinding(i);\r
- Object cval = getComponent(value, i);\r
- if(binding instanceof OptionalBinding && \r
- !((OptionalBinding)binding).hasValue(cval))\r
- continue;\r
- Component component = components[i]; \r
- ctx.b.append(component.name);\r
- ctx.b.append(" = ");\r
- binding.toString(cval, ctx);\r
- }\r
- ctx.b.append('}');\r
- }\r
- \r
- @Override\r
- protected void toString(Object value, BindingPrintContext ctx) throws BindingException {\r
- if(type().isReferable()) {\r
- if(ctx.refs.contains(value)) {\r
- int val = ctx.refs.get(value);\r
- if(val < 0) {\r
- val = ctx.nameCount.value++;\r
- ctx.refs.put(value, val);\r
- }\r
- ctx.b.append((char)('a' + val));\r
- }\r
- else {\r
- ctx.refs.put(value, -1);\r
- toStringAux(value, ctx);\r
- int val = ctx.refs.remove(value);\r
- if(val >= 0) {\r
- ctx.b.append("/");\r
- ctx.b.append((char)('a' + val));\r
- }\r
- }\r
- }\r
- else {\r
- toStringAux(value, ctx);\r
- }\r
+
+ protected void toStringAux(Object value, BindingPrintContext ctx) throws BindingException {
+ ctx.b.append('{');
+ Component[] components = type().getComponents();
+ boolean first = true;
+ for(int i=0;i<components.length;++i) {
+ if(first)
+ first = false;
+ else {
+ ctx.b.append(", ");
+ if (!ctx.singleLine) ctx.b.append('\n');
+ }
+ Binding binding = getComponentBinding(i);
+ Object cval = getComponent(value, i);
+ if(binding instanceof OptionalBinding &&
+ !((OptionalBinding)binding).hasValue(cval))
+ continue;
+ Component component = components[i];
+ ctx.b.append(component.name);
+ ctx.b.append(" = ");
+ binding.toString(cval, ctx);
+ }
+ ctx.b.append('}');
+ }
+
+ @Override
+ protected void toString(Object value, BindingPrintContext ctx) throws BindingException {
+ if(type().isReferable()) {
+ if(ctx.refs.contains(value)) {
+ int val = ctx.refs.get(value);
+ if(val < 0) {
+ val = ctx.nameCount.value++;
+ ctx.refs.put(value, val);
+ }
+ ctx.b.append((char)('a' + val));
+ }
+ else {
+ ctx.refs.put(value, -1);
+ toStringAux(value, ctx);
+ int val = ctx.refs.remove(value);
+ if(val >= 0) {
+ ctx.b.append("/");
+ ctx.b.append((char)('a' + val));
+ }
+ }
+ }
+ else {
+ toStringAux(value, ctx);
+ }
+ }
+
+ @Override
+ public Binding getComponentBinding(ChildReference path) throws IllegalArgumentException {
+ if (path==null) return this;
+ if (path instanceof IndexReference) {
+ IndexReference ir = (IndexReference) path;
+ return componentBindings[ir.index].getComponentBinding(path.childReference);
+ }
+ if (path instanceof NameReference) {
+ NameReference nr = (NameReference) path;
+ return getComponentBinding( nr.name ).getComponentBinding(path.childReference);
+ }
+ if (path instanceof LabelReference) {
+ LabelReference lr = (LabelReference) path;
+ try {
+ Integer i = new Integer(lr.label);
+ return getComponentBinding( i ).getComponentBinding(path.childReference);
+ } catch (NumberFormatException nfe) {
+ return getComponentBinding( lr.label ).getComponentBinding(path.childReference);
+ }
+ }
+ throw new IllegalArgumentException();
+ }
+
+ @Override
+ public boolean isImmutable() {
+ return getComponentCount() == 0;
+ }
+
+ public void setBoolean(Object r, int index, boolean z) throws BindingException
+ {
+ setComponent(r, index, ((BooleanBinding)componentBindings[index]).create(z));
+ }
+
+ public boolean getBoolean(Object r, int index) throws BindingException
+ {
+ return ((BooleanBinding)componentBindings[index]).getValue_( getComponent(r, index) );
+ }
+
+ public void setByte(Object r, int index, byte x) throws BindingException
+ {
+ setComponent(r, index, ((ByteBinding)componentBindings[index]).create(x));
+ }
+
+ public byte getByte(Object r, int index) throws BindingException
+ {
+ return ((ByteBinding)componentBindings[index]).getValue_( getComponent(r, index) );
+ }
+
+ public void setInt(Object r, int index, int x) throws BindingException
+ {
+ setComponent(r, index, ((IntegerBinding)componentBindings[index]).create(x));
+ }
+
+ public int getInt(Object r, int index) throws BindingException
+ {
+ return ((IntegerBinding)componentBindings[index]).getValue_( getComponent(r, index) );
+ }
+
+ public void setLong(Object r, int index, long x) throws BindingException
+ {
+ setComponent(r, index, ((LongBinding)componentBindings[index]).create(x));
+ }
+
+ public long getLong(Object r, int index) throws BindingException
+ {
+ return ((LongBinding)componentBindings[index]).getValue_( getComponent(r, index) );
+ }
+
+ public void setFloat(Object r, int index, float x) throws BindingException
+ {
+ setComponent(r, index, ((FloatBinding)componentBindings[index]).create(x));
+ }
+
+ public float getFloat(Object r, int index) throws BindingException
+ {
+ return ((FloatBinding)componentBindings[index]).getValue_( getComponent(r, index) );
+ }
+
+ public void setDouble(Object r, int index, double x) throws BindingException
+ {
+ setComponent(r, index, ((DoubleBinding)componentBindings[index]).create(x));
+ }
+
+ public double getDouble(Object r, int index) throws BindingException
+ {
+ return ((DoubleBinding)componentBindings[index]).getValue_( getComponent(r, index) );
+ }
+
+ @Override
+ protected boolean deepEquals(Object obj,
+ Set<IdentityPair<Binding, Binding>> compareHistory) {
+ RecordBinding o = (RecordBinding)obj;
+ if (!super.deepEquals( obj, compareHistory ))
+ return false;
+
+ if (componentBindings.length != o.componentBindings.length) return false;
+
+ for (int i = 0; i < componentBindings.length; i++)
+ if (!componentBindings[i].equals(o.componentBindings[i], compareHistory))
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public int deepHashCode(IdentityHashMap<Object, Object> hashedObjects) {
+ int code = super.deepHashCode(hashedObjects);
+ for (int i = 0; i < componentBindings.length; i++)
+ code = 17 * code + componentBindings[i].hashCode(hashedObjects);
+ return code;