- }\r
- \r
- public String toString(Object value) throws BindingException {\r
- BindingPrintContext ctx = new BindingPrintContext();\r
- toString(value, ctx);\r
- return ctx.b.toString();\r
- }\r
-\r
- public String toStringUnchecked(Object value) {\r
- try {\r
- BindingPrintContext ctx = new BindingPrintContext();\r
- toString(value, ctx);\r
- return ctx.b.toString();\r
- } catch ( BindingException e ) {\r
- return e.toString();\r
- }\r
- }\r
- \r
- public String toString(Object value, boolean singleLine) throws BindingException {\r
- BindingPrintContext ctx = new BindingPrintContext();\r
- ctx.singleLine = singleLine;\r
- toString(value, ctx);\r
- return ctx.b.toString();\r
- }\r
-\r
- protected abstract void toString(Object value, BindingPrintContext ctx) throws BindingException;\r
- \r
- \r
- /** \r
- * Get component binding count\r
- * \r
- * @return component count\r
- */\r
- public abstract int getComponentCount();\r
- \r
- /**\r
- * Get a component value of a structured data object.\r
- * @param object The structured data object\r
- * @param ref The child component reference\r
- * @return The value of the data component\r
- * @throws BindingException\r
- */\r
- public Object getComponent(Object object, ChildReference ref) throws BindingException {\r
- Variant value = new MutableVariant(this, object);\r
- try {\r
- return value.getComponent(ref).getValue();\r
- } catch ( AccessorConstructionException e ) {\r
- throw new BindingException("Component access failed.", e);\r
- }\r
- }\r
- \r
- /**\r
- * Get a component value of a structured data object.\r
- * @param object The structured data object\r
- * @param ref The child component reference\r
- * @param binding The output data binding for the component value\r
- * @return The value of the data component\r
- * @throws BindingException\r
- */\r
- public Object getComponent(Object object, ChildReference ref, Binding binding) throws BindingException {\r
- Binding componentBinding = getComponentBinding( ref );\r
- Variant value = new MutableVariant(this, object);\r
- try {\r
- return Bindings.adapt( value.getComponent( ref ), componentBinding, binding );\r
- } catch ( AdaptException | AccessorConstructionException e ) {\r
- throw new BindingException("Component access failed.", e);\r
- }\r
- }\r
- \r
- /**\r
- * Set the value of a component in a structured data object.\r
- * @param object The structured data object\r
- * @param ref The child component reference\r
- * @param binding Data type binding for the component value\r
- * @param componentValue The new child component value\r
- * @throws BindingException\r
- */\r
- public void setComponent( Object object, ChildReference ref, Binding binding, Object componentValue ) throws BindingException {\r
- MutableVariant value = new MutableVariant( this, object );\r
- try {\r
- value.setComponent( ref, binding, componentValue );\r
- } catch ( AccessorException | AccessorConstructionException e ) {\r
- throw new BindingException("Component access failed.", e );\r
- }\r
- }\r
- \r
- /**\r
- * Get component binding\r
- * @param index\r
- * @return binding\r
- */\r
- public abstract Binding getComponentBinding(int index);\r
- \r
- /**\r
- * Get component binding\r
- * @param path child path or <tt>null</tt> to return this.\r
- * @return binding \r
- * @throws IllegalArgumentException if path cannot be applied to this binding\r
- */\r
- public abstract Binding getComponentBinding(ChildReference path);\r
- \r
- @Override\r
- /**\r
- * Each child class implements #deepEquals or #baseEquals or neither, depending on\r
- * whether it includes references to child Binding instances or other fields.\r
- * @see java.lang.Object#equals(java.lang.Object)\r
- */\r
- final public boolean equals(Object obj) {\r
- if (this == obj) return true;\r
- if (obj == null) return false;\r
- if (this.getClass() != obj.getClass()) return false;\r
- \r
- return equals(obj, new HashSet<IdentityPair<Binding, Binding>>());\r
- }\r
- \r
- /**\r
- * Perform a deep equality check between this Binding object and another,\r
- * with a memory for recursive references. Child classes should implement either the\r
- * #deepEquals or #baseEquals method, or neither if there is no new data to compare.\r
- */\r
- final protected boolean equals(Object obj, Set<IdentityPair<Binding, Binding>> compareHistory) {\r
- if (this == obj) return true;\r
- if (this.getClass() != obj.getClass()) return false;\r
- \r
- IdentityPair<Binding, Binding> pair = new IdentityPair<Binding, Binding>(this, (Binding)obj); \r
- if (compareHistory.contains(pair)) return true;\r
- \r
- compareHistory.add(pair);\r
- return deepEquals(obj, compareHistory);\r
- }\r
- \r
- /**\r
- * Perform a comparison of the fields of this Binding instance. Always make a call to super.baseEquals().\r
- */\r
- protected boolean baseEquals(Object obj) {\r
- return type == null ? ((Binding)obj).type == null : type.equals(((Binding)obj).type);\r
- }\r
- \r
- /**\r
- * Perform a deep comparison of this Binding object with another.\r
- * Matching child Binding instances must be compared with #equals(Object, Set<IdentityPair<Binding, Binding>>).\r
- * Child classes should always make a call to super.deepEquals().\r
- */\r
- protected boolean deepEquals(Object obj, Set<IdentityPair<Binding, Binding>> compareHistory) {\r
- return baseEquals(obj);\r
- }\r
- \r
- @Override\r
- /**\r
- * Each child class implements #deepHashCode, #baseHashCode or neither, depending on whether it\r
- * includes child Binding references or other fields.\r
- */\r
- final public int hashCode() {\r
- return deepHashCode(new IdentityHashMap<Object,Object>());\r
- }\r
- \r
- /**\r
- * Calculate a deep hash code for this Binding instance.\r
- * Child classes should implement either deepHashCode or baseHashCode, or neither, if there is no new data.\r
- */\r
- final protected int hashCode(IdentityHashMap<Object, Object> hashedObjects) {\r
- if (hashedObjects.containsKey(this)) return 0;\r
- hashedObjects.put(this, null);\r
- return deepHashCode(hashedObjects);\r
- }\r
- \r
- /**\r
- * Calculate a hash code based on the fields of this Binding instance. Child classes must always make a call to super.baseHashCode(). \r
- */\r
- protected int baseHashCode() {\r
- return getClass().hashCode() + (type != null ? 3 * type.hashCode() : 0);\r
- }\r
- \r
- /**\r
- * Perform deep hash code calculation for this Binding instance.\r
- * Child instance hash codes must be calculated with #hashCode(IdentityHashMap<Object, Object>),\r
- * passing on the value provided to #deepHashCode.\r
- */\r
- protected int deepHashCode(IdentityHashMap<Object, Object> hashedObjects) {\r
- return baseHashCode();\r
- }\r
-}\r
+ }
+
+ public String toString(Object value) throws BindingException {
+ BindingPrintContext ctx = new BindingPrintContext();
+ toString(value, ctx);
+ return ctx.b.toString();
+ }
+
+ public String toStringUnchecked(Object value) {
+ try {
+ BindingPrintContext ctx = new BindingPrintContext();
+ toString(value, ctx);
+ return ctx.b.toString();
+ } catch ( BindingException e ) {
+ return e.toString();
+ }
+ }
+
+ public String toString(Object value, boolean singleLine) throws BindingException {
+ BindingPrintContext ctx = new BindingPrintContext();
+ ctx.singleLine = singleLine;
+ toString(value, ctx);
+ return ctx.b.toString();
+ }
+
+ protected abstract void toString(Object value, BindingPrintContext ctx) throws BindingException;
+
+
+ /**
+ * Get component binding count
+ *
+ * @return component count
+ */
+ public abstract int getComponentCount();
+
+ /**
+ * Get a component value of a structured data object.
+ * @param object The structured data object
+ * @param ref The child component reference
+ * @return The value of the data component
+ * @throws BindingException
+ */
+ public Object getComponent(Object object, ChildReference ref) throws BindingException {
+ Variant value = new MutableVariant(this, object);
+ try {
+ return value.getComponent(ref).getValue();
+ } catch ( AccessorConstructionException e ) {
+ throw new BindingException("Component access failed.", e);
+ }
+ }
+
+ /**
+ * Get a component value of a structured data object.
+ * @param object The structured data object
+ * @param ref The child component reference
+ * @param binding The output data binding for the component value
+ * @return The value of the data component
+ * @throws BindingException
+ */
+ public Object getComponent(Object object, ChildReference ref, Binding binding) throws BindingException {
+ Binding componentBinding = getComponentBinding( ref );
+ Variant value = new MutableVariant(this, object);
+ try {
+ return Bindings.adapt( value.getComponent( ref ), componentBinding, binding );
+ } catch ( AdaptException | AccessorConstructionException e ) {
+ throw new BindingException("Component access failed.", e);
+ }
+ }
+
+ /**
+ * Set the value of a component in a structured data object.
+ * @param object The structured data object
+ * @param ref The child component reference
+ * @param binding Data type binding for the component value
+ * @param componentValue The new child component value
+ * @throws BindingException
+ */
+ public void setComponent( Object object, ChildReference ref, Binding binding, Object componentValue ) throws BindingException {
+ MutableVariant value = new MutableVariant( this, object );
+ try {
+ value.setComponent( ref, binding, componentValue );
+ } catch ( AccessorException | AccessorConstructionException e ) {
+ throw new BindingException("Component access failed.", e );
+ }
+ }
+
+ /**
+ * Get component binding
+ * @param index
+ * @return binding
+ */
+ public abstract Binding getComponentBinding(int index);
+
+ /**
+ * Get component binding
+ * @param path child path or <tt>null</tt> to return this.
+ * @return binding
+ * @throws IllegalArgumentException if path cannot be applied to this binding
+ */
+ public abstract Binding getComponentBinding(ChildReference path);
+
+ @Override
+ /**
+ * Each child class implements #deepEquals or #baseEquals or neither, depending on
+ * whether it includes references to child Binding instances or other fields.
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ final public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (this.getClass() != obj.getClass()) return false;
+
+ return equals(obj, new HashSet<IdentityPair<Binding, Binding>>());
+ }
+
+ /**
+ * Perform a deep equality check between this Binding object and another,
+ * with a memory for recursive references. Child classes should implement either the
+ * #deepEquals or #baseEquals method, or neither if there is no new data to compare.
+ */
+ final protected boolean equals(Object obj, Set<IdentityPair<Binding, Binding>> compareHistory) {
+ if (this == obj) return true;
+ if (this.getClass() != obj.getClass()) return false;
+
+ IdentityPair<Binding, Binding> pair = new IdentityPair<Binding, Binding>(this, (Binding)obj);
+ if (compareHistory.contains(pair)) return true;
+
+ compareHistory.add(pair);
+ return deepEquals(obj, compareHistory);
+ }
+
+ /**
+ * Perform a comparison of the fields of this Binding instance. Always make a call to super.baseEquals().
+ */
+ protected boolean baseEquals(Object obj) {
+ return type == null ? ((Binding)obj).type == null : type.equals(((Binding)obj).type);
+ }
+
+ /**
+ * Perform a deep comparison of this Binding object with another.
+ * Matching child Binding instances must be compared with #equals(Object, Set<IdentityPair<Binding, Binding>>).
+ * Child classes should always make a call to super.deepEquals().
+ */
+ protected boolean deepEquals(Object obj, Set<IdentityPair<Binding, Binding>> compareHistory) {
+ return baseEquals(obj);
+ }
+
+ @Override
+ /**
+ * Each child class implements #deepHashCode, #baseHashCode or neither, depending on whether it
+ * includes child Binding references or other fields.
+ */
+ final public int hashCode() {
+ return deepHashCode(new IdentityHashMap<Object,Object>());
+ }
+
+ /**
+ * Calculate a deep hash code for this Binding instance.
+ * Child classes should implement either deepHashCode or baseHashCode, or neither, if there is no new data.
+ */
+ final protected int hashCode(IdentityHashMap<Object, Object> hashedObjects) {
+ if (hashedObjects.containsKey(this)) return 0;
+ hashedObjects.put(this, null);
+ return deepHashCode(hashedObjects);
+ }
+
+ /**
+ * Calculate a hash code based on the fields of this Binding instance. Child classes must always make a call to super.baseHashCode().
+ */
+ protected int baseHashCode() {
+ return getClass().hashCode() + (type != null ? 3 * type.hashCode() : 0);
+ }
+
+ /**
+ * Perform deep hash code calculation for this Binding instance.
+ * Child instance hash codes must be calculated with #hashCode(IdentityHashMap<Object, Object>),
+ * passing on the value provided to #deepHashCode.
+ */
+ protected int deepHashCode(IdentityHashMap<Object, Object> hashedObjects) {
+ return baseHashCode();
+ }
+}