Commits

Michael Ludwig committed 0e380df

Switch to new property set() signature.

  • Participants
  • Parent commits 5d401dd

Comments (0)

Files changed (24)

entreri-apt-tests/src/it/MissingPropertyGetComponent/src/main/java/MissingPropertyGetComponent.java

     public void setValue(Object o);
 
     public static class MissingGetterProperty implements Property {
-        public void set(Object o, int index) {
+        public void set(int index, Object o) {
 
         }
 

entreri-apt-tests/src/main/java/com.lhkbob.entreri.components/CustomProperty.java

     private final ObjectProperty<Bletch> property;
 
     public CustomProperty() {
-        property = new ObjectProperty<Bletch>();
+        property = new ObjectProperty<>();
     }
 
     @Override
         return new Bletch();
     }
 
-    public void set(Bletch b, int index) {
-        property.set(b, index);
+    public void set(int index, Bletch b) {
+        property.set(index, b);
     }
 
     public Bletch get(int index) {
             b.value = (!attributes.hasAttribute(IntProperty.DefaultInt.class) ? 0
                                                                               : attributes
                                .getAttribute(IntProperty.DefaultInt.class).value());
-            property.set(b, index);
+            property.set(index, b);
         }
 
         @Override

entreri-apt-tests/src/main/java/com.lhkbob.entreri.components/FloatPropertyFactory.java

 
     @Override
     public void setDefaultValue(FloatProperty p, int index) {
-        p.set(DEFAULT, index);
+        p.set(index, DEFAULT);
     }
 
     @Override
     public void clone(FloatProperty src, int srcIndex, FloatProperty dst, int dstIndex) {
-        dst.set(src.get(srcIndex), dstIndex);
+        dst.set(dstIndex, src.get(srcIndex));
     }
 }

entreri-apt-tests/src/main/java/com.lhkbob.entreri.components/NoFactoryProperty.java

         property = new ObjectProperty<Crass>();
     }
 
-    public void set(Crass b, int index) {
-        property.set(b, index);
+    public void set(int index, Crass b) {
+        property.set(index, b);
     }
 
     public Crass get(int index) {

entreri-apt-tests/src/test/java/com/lhkbob/entreri/PropertyFactoryTest.java

         factory.setDefaultValue(p2, 0);
 
         Object val = new Object();
-        p1.set(val, 0);
+        p1.set(0, val);
 
         Assert.assertSame(val, p1.get(0));
         Assert.assertNull(p2.get(0));
         factory.setDefaultValue(p2, 0);
 
         Object val = new Object();
-        p1.set(val, 0);
+        p1.set(0, val);
 
         Assert.assertSame(val, p1.get(0));
         Assert.assertNull(p2.get(0));
         factory.setDefaultValue(p2, 0);
 
         Object val = new Object();
-        p1.set(val, 0);
+        p1.set(0, val);
 
         Assert.assertSame(val, p1.get(0));
         Assert.assertNull(p2.get(0));
         factory.setDefaultValue(p2, 0);
 
         CloneObject val = new CloneObject(5);
-        p1.set(val, 0);
+        p1.set(0, val);
 
         Assert.assertSame(val, p1.get(0));
         Assert.assertNull(p2.get(0));
         factory.setDefaultValue(p1, 0);
         factory.setDefaultValue(p2, 0);
 
-        p1.set(4.0, 0);
+        p1.set(0, 4.0);
 
         Assert.assertEquals(4.0, p1.get(0), 0.0001);
         Assert.assertEquals(1.0, p2.get(0), 0.0001);
         factory.setDefaultValue(p1, 0);
         factory.setDefaultValue(p2, 0);
 
-        p1.set(4.0, 0);
+        p1.set(0, 4.0);
 
         Assert.assertEquals(4.0, p1.get(0), 0.0001);
         Assert.assertEquals(2.0, p2.get(0), 0.0001);
         factory.setDefaultValue(p1, 0);
         factory.setDefaultValue(p2, 0);
 
-        p1.set(4.0, 0);
+        p1.set(0, 4.0);
 
         Assert.assertEquals(4.0, p1.get(0), 0.0001);
         Assert.assertEquals(0.0, p2.get(0), 0.0001);
         factory.setDefaultValue(p1, 0);
         factory.setDefaultValue(p2, 0);
 
-        p1.set(4.0, 0);
+        p1.set(0, 4.0);
 
         Assert.assertEquals(4.0, p1.get(0), 0.0001);
         Assert.assertEquals(0.0, p2.get(0), 0.0001);

entreri-core/src/main/java/com/lhkbob/entreri/impl/ComponentFactoryProvider.java

         for (PropertyDeclaration p : params) {
             int idx = properties.indexOf(p);
             sb.append("\t\t").append(PROPERTY_FIELD_PREFIX).append(idx).append(".set(")
-              .append(SETTER_PARAM_PREFIX).append(idx).append(", ")
-              .append(INDEX_FIELD_NAME).append(");\n");
+              .append(INDEX_FIELD_NAME).append(", ").append(SETTER_PARAM_PREFIX)
+              .append(idx).append(");\n");
         }
 
         sb.append("\t\t").append(REPO_FIELD_NAME).append('.')

entreri-core/src/main/java/com/lhkbob/entreri/impl/ComponentRepository.java

         idSeq = 1; // start at 1, just like entity id sequences versionSeq = 0;
 
         // initialize version for the 0th index
-        componentVersionProperty.set(-1, 0);
+        componentVersionProperty.set(0, -1);
     }
 
     /**
         if (componentIndex != 0) {
             // clamp it to be above 0, instead of going negative
             int newVersion = (0xefffffff & (versionSeq++));
-            componentVersionProperty.set(newVersion, componentIndex);
+            componentVersionProperty.set(componentIndex, newVersion);
         }
     }
 
 
         // although there could be a custom PropertyFactory for setting the id,
         // it's easier to assign a new id here
-        componentIdProperty.set(idSeq++, componentIndex);
+        componentIdProperty.set(componentIndex, idSeq++);
         // same goes for assigning a new owner delegate
-        ownerDelegatesProperty.set(new OwnerSupport(instance), componentIndex);
+        ownerDelegatesProperty.set(componentIndex, new OwnerSupport(instance));
 
         // start with a unique version as well
         incrementVersion(componentIndex);
         components[componentIndex] = null;
         entityIndexToComponentRepository[entityIndex] = 0; // entity does not have component
         componentIndexToEntityIndex[componentIndex] = 0; // component does not have entity
-        componentIdProperty.set(0, componentIndex); // clear id
+        componentIdProperty.set(componentIndex, 0); // clear id
+        ownerDelegatesProperty.set(componentIndex, null);
 
         return oldComponent != null;
     }

entreri-core/src/main/java/com/lhkbob/entreri/impl/MirrorComponentSpecification.java

                 throw fail(declaringClass,
                            propertyType + " does not implement " + baseType + " get()");
             }
-            // FIXME switch back to int, type method but then we have to update all the property defs
-            if (!findMethod(methods, tu, "set", voidType, baseType, intType)) {
+            if (!findMethod(methods, tu, "set", voidType, intType, baseType)) {
                 throw fail(declaringClass,
-                           propertyType + " does not implement void set(" + baseType +
-                           ", int)");
+                           propertyType + " does not implement void set(int, " +
+                           baseType + ")");
             }
 
             if (isShared) {

entreri-core/src/main/java/com/lhkbob/entreri/impl/ReflectionComponentSpecification.java

         // since this is an interface, we're only dealing with public methods
         // so getMethods() returns everything we're interested in plus the methods
         // declared in Component, which we'll have to exclude
-        Method[] methods = type.getMethods();
         Map<String, Method> getters = new HashMap<>();
         Map<String, Method> setters = new HashMap<>();
         Map<String, Integer> setterParameters = new HashMap<>();
 
-        for (int i = 0; i < methods.length; i++) {
+        for (Method method : type.getMethods()) {
             // exclude methods defined in Component, Owner, Ownable, and Object
-            Class<?> md = methods[i].getDeclaringClass();
+            Class<?> md = method.getDeclaringClass();
             if (md.equals(Component.class) || md.equals(Owner.class) ||
                 md.equals(Ownable.class) || md.equals(Object.class)) {
                 continue;
             }
 
-            if (!Component.class.isAssignableFrom(methods[i].getDeclaringClass())) {
-                throw fail(md, methods[i] + ", method is not declared by a component");
+            if (!Component.class.isAssignableFrom(method.getDeclaringClass())) {
+                throw fail(md, method + ", method is not declared by a component");
             }
 
-            if (methods[i].getName().startsWith("is")) {
-                processGetter(methods[i], "is", getters);
-            } else if (methods[i].getName().startsWith("has")) {
-                processGetter(methods[i], "has", getters);
-            } else if (methods[i].getName().startsWith("get")) {
-                processGetter(methods[i], "get", getters);
-            } else if (methods[i].getName().startsWith("set")) {
-                processSetter(methods[i], setters, setterParameters);
+            if (method.getName().startsWith("is")) {
+                processGetter(method, "is", getters);
+            } else if (method.getName().startsWith("has")) {
+                processGetter(method, "has", getters);
+            } else if (method.getName().startsWith("get")) {
+                processGetter(method, "get", getters);
+            } else if (method.getName().startsWith("set")) {
+                processSetter(method, setters, setterParameters);
             } else {
-                throw fail(md, methods[i] + " is an illegal property method");
+                throw fail(md, method + " is an illegal property method");
             }
         }
 
     }
 
     private static String getNameFromParameter(Method m, int p) {
-        Annotation[] annots = m.getParameterAnnotations()[p];
-        for (int i = 0; i < annots.length; i++) {
-            if (annots[i] instanceof Named) {
-                return ((Named) annots[i]).value();
+        for (Annotation annot : m.getParameterAnnotations()[p]) {
+            if (annot instanceof Named) {
+                return ((Named) annot).value();
             }
         }
         return null;
                                propertyType + " does not implement " + baseType +
                                " get()");
                 }
-                // FIXME switch back to int, type method but then we have to update all the property defs
-                Method s = propertyType.getMethod("set", baseType, int.class);
+                Method s = propertyType.getMethod("set", int.class, baseType);
                 if (!s.getReturnType().equals(void.class)) {
                     throw fail(getter.getDeclaringClass(),
-                               propertyType + " does not implement void set(" + baseType +
-                               ", int)");
+                               propertyType + " does not implement void set(int, " +
+                               baseType + ")");
                 }
             } catch (NoSuchMethodException e) {
                 throw fail(getter.getDeclaringClass(),

entreri-core/src/main/java/com/lhkbob/entreri/property/BooleanProperty.java

     /**
      * Store <var>val</var> in this property for the given component index.
      *
+     * @param componentIndex The index of the component being modified
      * @param val            The value to store
-     * @param componentIndex The index of the component being modified
      *
      * @throws ArrayIndexOutOfBoundsException if the componentIndex is invalid
      */
-    public void set(boolean val, int componentIndex) {
+    public void set(int componentIndex, boolean val) {
         data[componentIndex] = val;
     }
 
 
         @Override
         public void setDefaultValue(BooleanProperty property, int index) {
-            property.set(defaultValue, index);
+            property.set(index, defaultValue);
         }
 
         @Override
                 // fall through, since default implementation of INVOKE_CLONE is to
                 // just function like JAVA_DEFAULT
             case JAVA_DEFAULT:
-                dst.set(src.get(srcIndex), dstIndex);
+                dst.set(dstIndex, src.get(srcIndex));
                 break;
             default:
                 throw new UnsupportedOperationException(

entreri-core/src/main/java/com/lhkbob/entreri/property/ByteProperty.java

     /**
      * Store <var>val</var> in this property for the given component index.
      *
+     * @param componentIndex The index of the component being modified
      * @param val            The value to store
-     * @param componentIndex The index of the component being modified
      *
      * @throws ArrayIndexOutOfBoundsException if the componentIndex is invalid
      */
-    public void set(byte val, int componentIndex) {
+    public void set(int componentIndex, byte val) {
         data[componentIndex] = val;
     }
 
 
         @Override
         public void setDefaultValue(ByteProperty property, int index) {
-            property.set(defaultValue, index);
+            property.set(index, defaultValue);
         }
 
         @Override
                 // fall through, since default implementation of INVOKE_CLONE is to
                 // just function like JAVA_DEFAULT
             case JAVA_DEFAULT:
-                dst.set(src.get(srcIndex), dstIndex);
+                dst.set(dstIndex, src.get(srcIndex));
                 break;
             default:
                 throw new UnsupportedOperationException(

entreri-core/src/main/java/com/lhkbob/entreri/property/CharProperty.java

     /**
      * Store <var>val</var> in this property for the given component index.
      *
+     * @param componentIndex The index of the component being modified
      * @param val            The value to store, can be null
-     * @param componentIndex The index of the component being modified
      *
      * @throws ArrayIndexOutOfBoundsException if the componentIndex is invalid
      */
-    public void set(char val, int componentIndex) {
+    public void set(int componentIndex, char val) {
         data[componentIndex] = val;
     }
 
 
         @Override
         public void setDefaultValue(CharProperty property, int index) {
-            property.set(defaultValue, index);
+            property.set(index, defaultValue);
         }
 
         @Override
                 // fall through, since default implementation of INVOKE_CLONE is to
                 // just function like JAVA_DEFAULT
             case JAVA_DEFAULT:
-                dst.set(src.get(srcIndex), dstIndex);
+                dst.set(dstIndex, src.get(srcIndex));
                 break;
             default:
                 throw new UnsupportedOperationException(

entreri-core/src/main/java/com/lhkbob/entreri/property/DoubleProperty.java

     /**
      * Store <var>val</var> in this property for the given component index.
      *
+     * @param componentIndex The index of the component being modified
      * @param val            The value to store, can be null
-     * @param componentIndex The index of the component being modified
      *
      * @throws ArrayIndexOutOfBoundsException if the componentIndex is invalid
      */
-    public void set(double val, int componentIndex) {
+    public void set(int componentIndex, double val) {
         data[componentIndex] = val;
     }
 
 
         @Override
         public void setDefaultValue(DoubleProperty property, int index) {
-            property.set(defaultValue, index);
+            property.set(index, defaultValue);
         }
 
         @Override
                 // fall through, since default implementation of INVOKE_CLONE is to
                 // just function like JAVA_DEFAULT
             case JAVA_DEFAULT:
-                dst.set(src.get(srcIndex), dstIndex);
+                dst.set(dstIndex, src.get(srcIndex));
                 break;
             default:
                 throw new UnsupportedOperationException(

entreri-core/src/main/java/com/lhkbob/entreri/property/FloatProperty.java

     /**
      * Store <var>val</var> in this property for the given component index.
      *
+     * @param componentIndex The index of the component being modified
      * @param val            The value to store, can be null
-     * @param componentIndex The index of the component being modified
      *
      * @throws ArrayIndexOutOfBoundsException if the componentIndex is invalid
      */
-    public void set(float val, int componentIndex) {
+    public void set(int componentIndex, float val) {
         data[componentIndex] = val;
     }
 
 
         @Override
         public void setDefaultValue(FloatProperty property, int index) {
-            property.set(defaultValue, index);
+            property.set(index, defaultValue);
         }
 
         @Override
                 // fall through, since default implementation of INVOKE_CLONE is to
                 // just function like JAVA_DEFAULT
             case JAVA_DEFAULT:
-                dst.set(src.get(srcIndex), dstIndex);
+                dst.set(dstIndex, src.get(srcIndex));
                 break;
             default:
                 throw new UnsupportedOperationException(

entreri-core/src/main/java/com/lhkbob/entreri/property/IntProperty.java

     /**
      * Store <var>val</var> in this property for the given component index.
      *
+     * @param componentIndex The index of the component being modified
      * @param val            The value to store, can be null
-     * @param componentIndex The index of the component being modified
      *
      * @throws ArrayIndexOutOfBoundsException if the componentIndex is invalid
      */
-    public void set(int val, int componentIndex) {
+    public void set(int componentIndex, int val) {
         data[componentIndex] = val;
     }
 
 
         @Override
         public void setDefaultValue(IntProperty property, int index) {
-            property.set(defaultValue, index);
+            property.set(index, defaultValue);
         }
 
         @Override
                 // fall through, since default implementation of INVOKE_CLONE is to
                 // just function like JAVA_DEFAULT
             case JAVA_DEFAULT:
-                dst.set(src.get(srcIndex), dstIndex);
+                dst.set(dstIndex, src.get(srcIndex));
                 break;
             default:
                 throw new UnsupportedOperationException(

entreri-core/src/main/java/com/lhkbob/entreri/property/LongProperty.java

     /**
      * Store <var>val</var> in this property for the given component index.
      *
+     * @param componentIndex The index of the component being modified
      * @param val            The value to store, can be null
-     * @param componentIndex The index of the component being modified
      *
      * @throws ArrayIndexOutOfBoundsException if the componentIndex is invalid
      */
-    public void set(long val, int componentIndex) {
+    public void set(int componentIndex, long val) {
         data[componentIndex] = val;
     }
 
 
         @Override
         public void setDefaultValue(LongProperty property, int index) {
-            property.set(defaultValue, index);
+            property.set(index, defaultValue);
         }
 
         @Override
                 // fall through, since default implementation of INVOKE_CLONE is to
                 // just function like JAVA_DEFAULT
             case JAVA_DEFAULT:
-                dst.set(src.get(srcIndex), dstIndex);
+                dst.set(dstIndex, src.get(srcIndex));
                 break;
             default:
                 throw new UnsupportedOperationException(

entreri-core/src/main/java/com/lhkbob/entreri/property/ObjectProperty.java

     /**
      * Store <var>val</var> in this property for the given component index.
      *
+     * @param componentIndex The index of the component being modified
      * @param val            The value to store, can be null
-     * @param componentIndex The index of the component being modified
      *
      * @throws ArrayIndexOutOfBoundsException if the componentIndex is invalid
      */
-    public void set(T val, int componentIndex) {
+    public void set(int componentIndex, T val) {
         data[componentIndex] = val;
     }
 
 
         @Override
         public void setDefaultValue(ObjectProperty property, int index) {
-            property.set(defaultValue, index);
+            property.set(index, defaultValue);
         }
 
         @Override
                         // be public and take no arguments
                         Method cloneMethod = orig.getClass().getMethod("clone");
                         Object cloned = cloneMethod.invoke(orig);
-                        dst.set(cloned, dstIndex);
+                        dst.set(dstIndex, cloned);
                         break;
                     } catch (Exception e) {
                         // if they implement Cloneable, this shouldn't fail
                 }
                 // else fall through to java default
             case JAVA_DEFAULT:
-                dst.set(src.get(srcIndex), dstIndex);
+                dst.set(dstIndex, src.get(srcIndex));
                 break;
             default:
                 throw new UnsupportedOperationException(

entreri-core/src/main/java/com/lhkbob/entreri/property/Property.java

  * same data store, and the two 'b' properties would share another store.
  * <p/>
  * All property implementations must expose two methods: <code>T get(int)</code> and
- * <code>void set(T, int)</code> to get and set values at a particular index. To support
+ * <code>void set(int, T)</code> to get and set values at a particular index. To support
  * primitives without boxing, they are not part of the interface definition but are
  * required. The exposed get() and set() methods, and potentially a bulk accessor (such as
  * returning the underlying array) are the supported methods for manipulating decorated

entreri-core/src/main/java/com/lhkbob/entreri/property/ShortProperty.java

     /**
      * Store <var>val</var> in this property for the given component index.
      *
+     * @param componentIndex The index of the component being modified
      * @param val            The value to store, can be null
-     * @param componentIndex The index of the component being modified
      *
      * @throws ArrayIndexOutOfBoundsException if the componentIndex is invalid
      */
-    public void set(short val, int componentIndex) {
+    public void set(int componentIndex, short val) {
         data[componentIndex] = val;
     }
 
 
         @Override
         public void setDefaultValue(ShortProperty property, int index) {
-            property.set(defaultValue, index);
+            property.set(index, defaultValue);
         }
 
         @Override
                 // fall through, since default implementation of INVOKE_CLONE is to
                 // just function like JAVA_DEFAULT
             case JAVA_DEFAULT:
-                dst.set(src.get(srcIndex), dstIndex);
+                dst.set(dstIndex, src.get(srcIndex));
                 break;
             default:
                 throw new UnsupportedOperationException(

entreri-core/src/test/java/com/lhkbob/entreri/PropertyFactoryTest.java

         factory.setDefaultValue(p2, 0);
 
         Object val = new Object();
-        p1.set(val, 0);
+        p1.set(0, val);
 
         Assert.assertSame(val, p1.get(0));
         Assert.assertNull(p2.get(0));
         factory.setDefaultValue(p2, 0);
 
         Object val = new Object();
-        p1.set(val, 0);
+        p1.set(0, val);
 
         Assert.assertSame(val, p1.get(0));
         Assert.assertNull(p2.get(0));
         factory.setDefaultValue(p2, 0);
 
         Object val = new Object();
-        p1.set(val, 0);
+        p1.set(0, val);
 
         Assert.assertSame(val, p1.get(0));
         Assert.assertNull(p2.get(0));
         factory.setDefaultValue(p2, 0);
 
         CloneObject val = new CloneObject(5);
-        p1.set(val, 0);
+        p1.set(0, val);
 
         Assert.assertSame(val, p1.get(0));
         Assert.assertNull(p2.get(0));
         factory.setDefaultValue(p1, 0);
         factory.setDefaultValue(p2, 0);
 
-        p1.set(4.0, 0);
+        p1.set(0, 4.0);
 
         Assert.assertEquals(4.0, p1.get(0), 0.0001);
         Assert.assertEquals(1.0, p2.get(0), 0.0001);
         factory.setDefaultValue(p1, 0);
         factory.setDefaultValue(p2, 0);
 
-        p1.set(4.0, 0);
+        p1.set(0, 4.0);
 
         Assert.assertEquals(4.0, p1.get(0), 0.0001);
         Assert.assertEquals(2.0, p2.get(0), 0.0001);
         factory.setDefaultValue(p1, 0);
         factory.setDefaultValue(p2, 0);
 
-        p1.set(4.0, 0);
+        p1.set(0, 4.0);
 
         Assert.assertEquals(4.0, p1.get(0), 0.0001);
         Assert.assertEquals(0.0, p2.get(0), 0.0001);
         factory.setDefaultValue(p1, 0);
         factory.setDefaultValue(p2, 0);
 
-        p1.set(4.0, 0);
+        p1.set(0, 4.0);
 
         Assert.assertEquals(4.0, p1.get(0), 0.0001);
         Assert.assertEquals(0.0, p2.get(0), 0.0001);

entreri-core/src/test/java/com/lhkbob/entreri/components/CustomProperty.java

         return new Bletch();
     }
 
-    public void set(Bletch b, int index) {
-        property.set(b, index);
+    public void set(int index, Bletch b) {
+        property.set(index, b);
     }
 
     public Bletch get(int index) {
             b.value = (!attributes.hasAttribute(IntProperty.DefaultInt.class) ? 0
                                                                               : attributes
                                .getAttribute(IntProperty.DefaultInt.class).value());
-            property.set(b, index);
+            property.set(index, b);
         }
 
         @Override

entreri-core/src/test/java/com/lhkbob/entreri/components/FloatPropertyFactory.java

 
     @Override
     public void setDefaultValue(FloatProperty p, int index) {
-        p.set(DEFAULT, index);
+        p.set(index, DEFAULT);
     }
 
     @Override
     public void clone(FloatProperty src, int srcIndex, FloatProperty dst, int dstIndex) {
-        dst.set(src.get(srcIndex), dstIndex);
+        dst.set(dstIndex, src.get(srcIndex));
     }
 }

entreri-core/src/test/java/com/lhkbob/entreri/components/MissingPropertyGetComponent.java

     public void setValue(Object o);
 
     public static class MissingGetterProperty implements Property {
-        public void set(Object o, int index) {
+        public void set(int index, Object o) {
 
         }
 

entreri-core/src/test/java/com/lhkbob/entreri/components/NoFactoryProperty.java

     private final ObjectProperty<Crass> property;
 
     public NoFactoryProperty() {
-        property = new ObjectProperty<Crass>();
+        property = new ObjectProperty<>();
     }
 
-    public void set(Crass b, int index) {
-        property.set(b, index);
+    public void set(int index, Crass b) {
+        property.set(index, b);
     }
 
     public Crass get(int index) {