Commits

Michael Ludwig  committed 47019d7

Simplify package in tests directory, and add more tests to validate component definitions.

  • Participants
  • Parent commits 308051c

Comments (0)

Files changed (19)

File src/test/java/com/lhkbob/entreri/ComponentRepositoryTest.java

 package com.lhkbob.entreri;
 
 import com.lhkbob.entreri.components.ComplexComponent;
+import com.lhkbob.entreri.components.FloatPropertyFactory;
 import com.lhkbob.entreri.components.IntComponent;
 import com.lhkbob.entreri.property.FloatProperty;
-import com.lhkbob.entreri.property.FloatPropertyFactory;
 import com.lhkbob.entreri.property.Property;
 import org.junit.Assert;
 import org.junit.Test;

File src/test/java/com/lhkbob/entreri/ComponentTest.java

 package com.lhkbob.entreri;
 
 import com.lhkbob.entreri.components.ComplexComponent;
+import com.lhkbob.entreri.components.CustomProperty;
+import com.lhkbob.entreri.components.FloatPropertyFactory;
 import com.lhkbob.entreri.components.IntComponent;
-import com.lhkbob.entreri.property.CustomProperty;
-import com.lhkbob.entreri.property.FloatPropertyFactory;
 import junit.framework.Assert;
 import org.junit.Test;
 

File src/test/java/com/lhkbob/entreri/PropertySpecificationTest.java

         doInvalidComponentDefinitionTest(MismatchedTypeComponent.class);
         doInvalidComponentDefinitionTest(NonBeanComponent.class);
         doInvalidComponentDefinitionTest(InvalidPropertyComponent.class);
-        doInvalidComponentDefinitionTest(IllegalSharedPropertyComponent.class);
-
-        // FIXME additional tests
-        // 1. invalid shared instance property on a primitive property type (or anything other than ObjectProperty)
-        // 2. properties that are missing a setter or getter
-        // 3. shareable properties that are missing the extra getter or the create method
+        doInvalidComponentDefinitionTest(InvalidSharedObjectComponent.class);
+        doInvalidComponentDefinitionTest(InvalidSharedPrimitiveComponent.class);
+        doInvalidComponentDefinitionTest(MissingPropertyGetComponent.class);
+        doInvalidComponentDefinitionTest(MissingPropertySetComponent.class);
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })

File src/test/java/com/lhkbob/entreri/components/ComplexComponent.java

 
 import com.lhkbob.entreri.Named;
 import com.lhkbob.entreri.SharedInstance;
-import com.lhkbob.entreri.property.CustomProperty;
 import com.lhkbob.entreri.property.Factory;
-import com.lhkbob.entreri.property.FloatPropertyFactory;
 import com.lhkbob.entreri.property.IntProperty.DefaultInt;
 import com.lhkbob.entreri.property.LongProperty.DefaultLong;
 

File src/test/java/com/lhkbob/entreri/components/CustomProperty.java

+/*
+ * Entreri, an entity-component framework in Java
+ *
+ * Copyright (c) 2012, Michael Ludwig
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ *     Redistributions of source code must retain the above copyright notice,
+ *         this list of conditions and the following disclaimer.
+ *     Redistributions in binary form must reproduce the above copyright notice,
+ *         this list of conditions and the following disclaimer in the
+ *         documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.lhkbob.entreri.components;
+
+import com.lhkbob.entreri.property.*;
+
+@Factory(CustomProperty.CustomFactoryWithAttributes.class)
+public class CustomProperty implements ShareableProperty<CustomProperty.Bletch> {
+    private final ObjectProperty<Bletch> property;
+
+    public CustomProperty() {
+        property = new ObjectProperty<Bletch>();
+    }
+
+    @Override
+    public IndexedDataStore getDataStore() {
+        return property.getDataStore();
+    }
+
+    @Override
+    public void setDataStore(IndexedDataStore store) {
+        property.setDataStore(store);
+    }
+
+    @Override
+    public Bletch createShareableInstance() {
+        return new Bletch();
+    }
+
+    public void set(Bletch b, int index) {
+        property.set(b, index);
+    }
+
+    public Bletch get(int index) {
+        return property.get(index);
+    }
+
+    @Override
+    public void get(int index, Bletch b) {
+        b.value = property.get(index).value;
+    }
+
+    public static class CustomFactoryWithAttributes
+            extends AbstractPropertyFactory<CustomProperty> {
+        public CustomFactoryWithAttributes(Attributes attrs) {
+            super(attrs);
+        }
+
+        @Override
+        public CustomProperty create() {
+            return new CustomProperty();
+        }
+
+        @Override
+        public void setDefaultValue(CustomProperty property, int index) {
+            Bletch b = new Bletch();
+            b.value = (!attributes.hasAttribute(IntProperty.DefaultInt.class) ? 0
+                                                                              : attributes
+                               .getAttribute(IntProperty.DefaultInt.class).value());
+            property.set(b, index);
+        }
+    }
+
+    public static class Bletch {
+        public int value;
+    }
+}

File src/test/java/com/lhkbob/entreri/components/FloatPropertyFactory.java

+/*
+ * Entreri, an entity-component framework in Java
+ *
+ * Copyright (c) 2012, Michael Ludwig
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ *     Redistributions of source code must retain the above copyright notice,
+ *         this list of conditions and the following disclaimer.
+ *     Redistributions in binary form must reproduce the above copyright notice,
+ *         this list of conditions and the following disclaimer in the
+ *         documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.lhkbob.entreri.components;
+
+import com.lhkbob.entreri.property.AbstractPropertyFactory;
+import com.lhkbob.entreri.property.FloatProperty;
+
+public class FloatPropertyFactory extends AbstractPropertyFactory<FloatProperty> {
+    public static final float DEFAULT = 5f;
+
+    public FloatPropertyFactory() {
+        super(null);
+    }
+
+    @Override
+    public FloatProperty create() {
+        return new FloatProperty();
+    }
+
+    @Override
+    public void setDefaultValue(FloatProperty p, int index) {
+        p.set(DEFAULT, index);
+    }
+}

File src/test/java/com/lhkbob/entreri/components/IllegalSharedPropertyComponent.java

-/*
- * Entreri, an entity-component framework in Java
- *
- * Copyright (c) 2012, Michael Ludwig
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *     Redistributions of source code must retain the above copyright notice,
- *         this list of conditions and the following disclaimer.
- *     Redistributions in binary form must reproduce the above copyright notice,
- *         this list of conditions and the following disclaimer in the
- *         documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.lhkbob.entreri.components;
-
-import com.lhkbob.entreri.Component;
-import com.lhkbob.entreri.SharedInstance;
-
-/**
- * Invalid component definition that double checks that we fail when using a shared
- * instance annotation with an incompatible type
- */
-public interface IllegalSharedPropertyComponent extends Component {
-    @SharedInstance
-    public Object getValue();
-
-    public void setValue(Object v);
-}

File src/test/java/com/lhkbob/entreri/components/InvalidFactoryComponent.java

 
 import com.lhkbob.entreri.Component;
 import com.lhkbob.entreri.property.Factory;
-import com.lhkbob.entreri.property.FloatPropertyFactory;
 
 /**
  * A test component that mis-configures a component so that the property factory has the

File src/test/java/com/lhkbob/entreri/components/InvalidPropertyComponent.java

 package com.lhkbob.entreri.components;
 
 import com.lhkbob.entreri.Component;
-import com.lhkbob.entreri.property.NoFactoryProperty;
 
 /**
  * Test component that uses the invalid property type NoFactoryProperty.

File src/test/java/com/lhkbob/entreri/components/InvalidSharedComponent.java

-/*
- * Entreri, an entity-component framework in Java
- *
- * Copyright (c) 2012, Michael Ludwig
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *     Redistributions of source code must retain the above copyright notice,
- *         this list of conditions and the following disclaimer.
- *     Redistributions in binary form must reproduce the above copyright notice,
- *         this list of conditions and the following disclaimer in the
- *         documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.lhkbob.entreri.components;
-
-import com.lhkbob.entreri.Component;
-import com.lhkbob.entreri.SharedInstance;
-
-/**
- * Invalid component type that tries to have a shared instance from a property that
- * doesn't support it.
- */
-public interface InvalidSharedComponent extends Component {
-    @SharedInstance
-    public int getSharedValue();
-
-    public void setSharedValue(int v);
-}

File src/test/java/com/lhkbob/entreri/components/InvalidSharedObjectComponent.java

+/*
+ * Entreri, an entity-component framework in Java
+ *
+ * Copyright (c) 2012, Michael Ludwig
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ *     Redistributions of source code must retain the above copyright notice,
+ *         this list of conditions and the following disclaimer.
+ *     Redistributions in binary form must reproduce the above copyright notice,
+ *         this list of conditions and the following disclaimer in the
+ *         documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.lhkbob.entreri.components;
+
+import com.lhkbob.entreri.Component;
+import com.lhkbob.entreri.SharedInstance;
+
+/**
+ * Invalid component definition that double checks that we fail when using a shared
+ * instance annotation with a object properties.
+ */
+public interface InvalidSharedObjectComponent extends Component {
+    @SharedInstance
+    public Object getValue();
+
+    public void setValue(Object v);
+}

File src/test/java/com/lhkbob/entreri/components/InvalidSharedPrimitiveComponent.java

+/*
+ * Entreri, an entity-component framework in Java
+ *
+ * Copyright (c) 2012, Michael Ludwig
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ *     Redistributions of source code must retain the above copyright notice,
+ *         this list of conditions and the following disclaimer.
+ *     Redistributions in binary form must reproduce the above copyright notice,
+ *         this list of conditions and the following disclaimer in the
+ *         documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.lhkbob.entreri.components;
+
+import com.lhkbob.entreri.Component;
+import com.lhkbob.entreri.SharedInstance;
+
+/**
+ * Invalid component type that tries to have a shared instance from a property that
+ * doesn't support it. Note that this failure also extends to any other property type that
+ * isn't ObjectProperty that doesn't implement ShareableProperty.
+ */
+public interface InvalidSharedPrimitiveComponent extends Component {
+    @SharedInstance
+    public int getSharedValue();
+
+    public void setSharedValue(int v);
+}

File src/test/java/com/lhkbob/entreri/components/MissingPropertyGetComponent.java

+package com.lhkbob.entreri.components;
+
+import com.lhkbob.entreri.Component;
+import com.lhkbob.entreri.property.*;
+
+/**
+ * Invalid component type because it references a property type that doesn't have the
+ * expected get method.
+ */
+public interface MissingPropertyGetComponent extends Component {
+    @Factory(MissingGetterFactory.class)
+    public Object getValue();
+
+    public void setValue(Object o);
+
+    public static class MissingGetterProperty implements Property {
+        public void set(Object o, int index) {
+
+        }
+
+        // we don't really have to implement these because the component
+        // will fail validation
+        @Override
+        public IndexedDataStore getDataStore() {
+            return null;
+        }
+
+        @Override
+        public void setDataStore(IndexedDataStore store) {
+        }
+    }
+
+    public static class MissingGetterFactory
+            extends AbstractPropertyFactory<MissingGetterProperty> {
+
+        public MissingGetterFactory(Attributes attrs) {
+            super(attrs);
+        }
+
+        @Override
+        public MissingGetterProperty create() {
+            return new MissingGetterProperty();
+        }
+
+        @Override
+        public void setDefaultValue(MissingGetterProperty property, int index) {
+        }
+    }
+}

File src/test/java/com/lhkbob/entreri/components/MissingPropertySetComponent.java

+package com.lhkbob.entreri.components;
+
+import com.lhkbob.entreri.Component;
+import com.lhkbob.entreri.property.*;
+
+/**
+ * Invalid component type because it references a property type that doesn't have the
+ * expected set method.
+ */
+public interface MissingPropertySetComponent extends Component {
+    @Factory(MissingSetterFactory.class)
+    public Object getValue();
+
+    public void setValue(Object o);
+
+    public static class MissingSetterProperty implements Property {
+        public Object get(int index) {
+            return null;
+        }
+
+        // we don't really have to implement these because the component
+        // will fail validation
+        @Override
+        public IndexedDataStore getDataStore() {
+            return null;
+        }
+
+        @Override
+        public void setDataStore(IndexedDataStore store) {
+        }
+    }
+
+    public static class MissingSetterFactory
+            extends AbstractPropertyFactory<MissingSetterProperty> {
+
+        public MissingSetterFactory(Attributes attrs) {
+            super(attrs);
+        }
+
+        @Override
+        public MissingSetterProperty create() {
+            return new MissingSetterProperty();
+        }
+
+        @Override
+        public void setDefaultValue(MissingSetterProperty property, int index) {
+        }
+    }
+}

File src/test/java/com/lhkbob/entreri/components/NoFactoryProperty.java

+/*
+ * Entreri, an entity-component framework in Java
+ *
+ * Copyright (c) 2012, Michael Ludwig
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ *     Redistributions of source code must retain the above copyright notice,
+ *         this list of conditions and the following disclaimer.
+ *     Redistributions in binary form must reproduce the above copyright notice,
+ *         this list of conditions and the following disclaimer in the
+ *         documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.lhkbob.entreri.components;
+
+import com.lhkbob.entreri.property.IndexedDataStore;
+import com.lhkbob.entreri.property.ObjectProperty;
+import com.lhkbob.entreri.property.Property;
+
+public class NoFactoryProperty implements Property {
+    private final ObjectProperty<Crass> property;
+
+    public NoFactoryProperty() {
+        property = new ObjectProperty<Crass>();
+    }
+
+    @Override
+    public IndexedDataStore getDataStore() {
+        return property.getDataStore();
+    }
+
+    @Override
+    public void setDataStore(IndexedDataStore store) {
+        property.setDataStore(store);
+    }
+
+    public void set(Crass b, int index) {
+        property.set(b, index);
+    }
+
+    public Crass get(int index) {
+        return property.get(index);
+    }
+
+    public static class Crass {
+
+    }
+}

File src/test/java/com/lhkbob/entreri/property/CustomProperty.java

-/*
- * Entreri, an entity-component framework in Java
- *
- * Copyright (c) 2012, Michael Ludwig
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *     Redistributions of source code must retain the above copyright notice,
- *         this list of conditions and the following disclaimer.
- *     Redistributions in binary form must reproduce the above copyright notice,
- *         this list of conditions and the following disclaimer in the
- *         documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.lhkbob.entreri.property;
-
-@Factory(CustomProperty.CustomFactoryWithAttributes.class)
-public class CustomProperty implements ShareableProperty<CustomProperty.Bletch> {
-    private final ObjectProperty<Bletch> property;
-
-    public CustomProperty() {
-        property = new ObjectProperty<Bletch>();
-    }
-
-    @Override
-    public IndexedDataStore getDataStore() {
-        return property.getDataStore();
-    }
-
-    @Override
-    public void setDataStore(IndexedDataStore store) {
-        property.setDataStore(store);
-    }
-
-    @Override
-    public Bletch createShareableInstance() {
-        return new Bletch();
-    }
-
-    public void set(Bletch b, int index) {
-        property.set(b, index);
-    }
-
-    public Bletch get(int index) {
-        return property.get(index);
-    }
-
-    @Override
-    public void get(int index, Bletch b) {
-        b.value = property.get(index).value;
-    }
-
-    public static class CustomFactoryWithAttributes
-            extends AbstractPropertyFactory<CustomProperty> {
-        public CustomFactoryWithAttributes(Attributes attrs) {
-            super(attrs);
-        }
-
-        @Override
-        public CustomProperty create() {
-            return new CustomProperty();
-        }
-
-        @Override
-        public void setDefaultValue(CustomProperty property, int index) {
-            Bletch b = new Bletch();
-            b.value = (!attributes.hasAttribute(IntProperty.DefaultInt.class) ? 0
-                                                                              : attributes
-                               .getAttribute(IntProperty.DefaultInt.class).value());
-            property.set(b, index);
-        }
-    }
-
-    public static class Bletch {
-        public int value;
-    }
-}

File src/test/java/com/lhkbob/entreri/property/FloatPropertyFactory.java

-/*
- * Entreri, an entity-component framework in Java
- *
- * Copyright (c) 2012, Michael Ludwig
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *     Redistributions of source code must retain the above copyright notice,
- *         this list of conditions and the following disclaimer.
- *     Redistributions in binary form must reproduce the above copyright notice,
- *         this list of conditions and the following disclaimer in the
- *         documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.lhkbob.entreri.property;
-
-public class FloatPropertyFactory extends AbstractPropertyFactory<FloatProperty> {
-    public static final float DEFAULT = 5f;
-
-    public FloatPropertyFactory() {
-        super(null);
-    }
-
-    @Override
-    public FloatProperty create() {
-        return new FloatProperty();
-    }
-
-    @Override
-    public void setDefaultValue(FloatProperty p, int index) {
-        p.set(DEFAULT, index);
-    }
-}

File src/test/java/com/lhkbob/entreri/property/NoFactoryProperty.java

-/*
- * Entreri, an entity-component framework in Java
- *
- * Copyright (c) 2012, Michael Ludwig
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *     Redistributions of source code must retain the above copyright notice,
- *         this list of conditions and the following disclaimer.
- *     Redistributions in binary form must reproduce the above copyright notice,
- *         this list of conditions and the following disclaimer in the
- *         documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.lhkbob.entreri.property;
-
-public class NoFactoryProperty implements Property {
-    private final ObjectProperty<Crass> property;
-
-    public NoFactoryProperty() {
-        property = new ObjectProperty<Crass>();
-    }
-
-    @Override
-    public IndexedDataStore getDataStore() {
-        return property.getDataStore();
-    }
-
-    @Override
-    public void setDataStore(IndexedDataStore store) {
-        property.setDataStore(store);
-    }
-
-    public void set(Crass b, int index) {
-        property.set(b, index);
-    }
-
-    public Crass get(int index) {
-        return property.get(index);
-    }
-
-    public static class Crass {
-
-    }
-}

File src/test/resources/entreri-mapping.properties

-com.lhkbob.entreri.property.CustomProperty$Bletch=com.lhkbob.entreri.property.CustomProperty
-com.lhkbob.entreri.property.NoFactoryProperty$Crass=com.lhkbob.entreri.property.NoFactoryProperty
+com.lhkbob.entreri.components.CustomProperty$Bletch=com.lhkbob.entreri.components.CustomProperty
+com.lhkbob.entreri.components.NoFactoryProperty$Crass=com.lhkbob.entreri.components.NoFactoryProperty