1. Michael Ludwig
  2. entreri

Commits

Michael Ludwig  committed 9de484c

Update automated formatting rules in Eclipse

  • Participants
  • Parent commits b4d9f39
  • Branches default

Comments (0)

Files changed (70)

File src/main/java/com/lhkbob/entreri/Attribute.java

View file
 /*
  * 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.
+ * 
+ * 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;
 
+import java.lang.annotation.Documented;
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
-import java.lang.annotation.Documented;
-
 @Documented
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.ANNOTATION_TYPE)
-public @interface Attribute { }
+public @interface Attribute {}

File src/main/java/com/lhkbob/entreri/Attributes.java

View file
 /*
  * 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.
+ * 
+ * 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;
 
 import java.util.HashMap;
 import java.util.Map;
 
-
 public class Attributes {
     private final Map<Class<? extends Annotation>, Annotation> attrs;
-    
+
     public Attributes(Field f) {
-        if (f == null)
+        if (f == null) {
             throw new NullPointerException("Field cannot be null");
-        
+        }
+
         attrs = new HashMap<Class<? extends Annotation>, Annotation>();
-        
-        for (Annotation a: f.getAnnotations()) {
+
+        for (Annotation a : f.getAnnotations()) {
             if (a.annotationType().getAnnotation(Attribute.class) != null) {
                 // the attribute is an annotation
                 attrs.put(a.annotationType(), a);
             }
         }
     }
-    
+
     @SuppressWarnings("unchecked")
     public <T extends Annotation> T getAttribute(Class<T> cls) {
-        if (cls == null)
+        if (cls == null) {
             throw new NullPointerException("Annotation class cannot be null");
+        }
         return (T) attrs.get(cls);
     }
-    
+
     public boolean hasAttribute(Class<? extends Annotation> cls) {
-        if (cls == null)
+        if (cls == null) {
             throw new NullPointerException("Annotation class cannot be null");
+        }
         return attrs.containsKey(cls);
     }
-    
+
     public Collection<Annotation> getAttributes() {
         return attrs.values();
     }

File src/main/java/com/lhkbob/entreri/Component.java

View file
 /*
  * 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.
+ * 
+ * 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;
 
  */
 public final class Component<T extends ComponentData<T>> {
     private final ComponentRepository<T> owner;
-    
+
     int index;
 
     /**
-     * Create a new Component stored in the given ComponentRepository, at the given
-     * array position within the ComponentRepository.
+     * Create a new Component stored in the given ComponentRepository, at the
+     * given array position within the ComponentRepository.
      * 
      * @param owner The ComponentRepository owner
      * @param index The index within the owner
      */
     public T getData() {
         T data = getEntitySystem().createDataInstance(getTypeId());
-        if (data.set(this))
+        if (data.set(this)) {
             return data;
-        else
-            return null; 
+        } else {
+            return null;
+        }
     }
 
     /**
         int entityIndex = owner.getEntityIndex(index);
         return owner.getEntitySystem().getEntityByIndex(entityIndex);
     }
-    
+
     /**
      * @return The EntitySystem that created this component
      */
     public EntitySystem getEntitySystem() {
         return owner.getEntitySystem();
     }
-    
+
     /**
      * @return The TypeId of the ComponentData for this Component
      */
     public TypeId<T> getTypeId() {
         return owner.getTypeId();
     }
-    
+
     /**
      * @return The ComponentRepository owning this Component
      */

File src/main/java/com/lhkbob/entreri/ComponentData.java

View file
 /*
  * 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.
+ * 
+ * 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;
 
-
 /**
  * <p>
  * ComponentData is used to define types of components that can be added to
 public abstract class ComponentData<T extends ComponentData<T>> {
     private int id;
     private int index;
-    
+
     // this should be considered final, but is assigned in ComponentRepository
     // to simplify implementation constructor requirements.
     ComponentRepository<T> owner;
-    
-    protected ComponentData() { }
+
+    protected ComponentData() {}
 
     /**
      * Get the Entity that owns this ComponentData. This is a convenience for
      *         that is still live
      */
     public final boolean isValid() {
-        // we have to check the index of the ComponentData because the ComponentRepository
-        // does not make sure the data's indices stay within bounds of the repository arrays
+        // we have to check the index of the ComponentData because the
+        // ComponentRepository does not make sure the data's indices stay within
+        // bounds of the repository arrays
         if (index != 0 && index < owner.getMaxComponentIndex()) {
             return owner.getId(index) == id;
         }
             return setFast(0);
         } else {
             // we check repository since it is guaranteed type safe
-            if (component.getRepository() != owner)
+            if (component.getRepository() != owner) {
                 throw new IllegalArgumentException("Component not created by expected EntitySystem");
-            
+            }
+
             return setFast(component.index);
         }
     }
      * 
      * @param index The new index
      */
-    protected void onSet(int index) { 
+    protected void onSet(int index) {
         // do nothing in base class
     }
 

File src/main/java/com/lhkbob/entreri/ComponentDataFactory.java

View file
 /*
  * 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.
+ * 
+ * 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;
 
 import java.util.Map;
 
-
 /**
  * <p>
  * ComponentDataFactory is a factory interface used to create instances of

File src/main/java/com/lhkbob/entreri/ComponentIterator.java

View file
 /*
  * 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.
+ * 
+ * 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;
 
 public class ComponentIterator {
     private final EntitySystem system;
     private boolean ignoreEnabled;
-    
+
     private int index;
-    
+
     private ComponentData<?>[] required; // all required except primary
     private ComponentData<?>[] optional;
-    
+
     private ComponentData<?> primary;
 
     /**
      * @throws NullPointerException if system is null
      */
     public ComponentIterator(EntitySystem system) {
-        if (system == null)
+        if (system == null) {
             throw new NullPointerException("System cannot be null");
+        }
         this.system = system;
         required = new ComponentData<?>[0];
         optional = new ComponentData<?>[0];
      *             EntitySystem of this iterator
      */
     public ComponentIterator addRequired(ComponentData<?> data) {
-        if (data == null)
+        if (data == null) {
             throw new NullPointerException("ComponentData cannot be null");
-        if (data.owner.getEntitySystem() != system)
+        }
+        if (data.owner.getEntitySystem() != system) {
             throw new IllegalArgumentException("ComponentData not created by correct EntitySystem");
-        
+        }
+
         // check to see if the data should be the new primary
         if (primary == null) {
             // no other required components, so just set it
                 required[required.length - 1] = data;
             }
         }
-        
+
         return this;
     }
 
      *             EntitySystem of this iterator
      */
     public ComponentIterator addOptional(ComponentData<?> data) {
-        if (data == null)
+        if (data == null) {
             throw new NullPointerException("ComponentData cannot be null");
-        if (data.owner.getEntitySystem() != system)
+        }
+        if (data.owner.getEntitySystem() != system) {
             throw new IllegalArgumentException("ComponentData not created by correct EntitySystem");
+        }
 
         // add the data to the optional array
         optional = Arrays.copyOf(optional, optional.length + 1);
         optional[optional.length - 1] = data;
-        
+
         return this;
     }
 
      *         any present optional components) have been updated to that entity
      */
     public boolean next() {
-        if (primary == null)
+        if (primary == null) {
             return false;
-        
+        }
+
         boolean found;
         int entity;
         int component;
         int count = primary.owner.getMaxComponentIndex();
-        while(index < count - 1) {
+        while (index < count - 1) {
             index++; // always increment one
 
             found = true;
                 if (ignoreEnabled || primary.isEnabled()) {
                     for (int i = 0; i < required.length; i++) {
                         component = required[i].owner.getComponentIndex(entity);
-                        if (!required[i].setFast(component) 
-                            || (!ignoreEnabled && !required[i].isEnabled())) {
+                        if (!required[i].setFast(component) || (!ignoreEnabled && !required[i].isEnabled())) {
                             found = false;
                             break;
                         }
                         // so now set all optional requirements as well
                         for (int i = 0; i < optional.length; i++) {
                             component = optional[i].owner.getComponentIndex(entity);
-                            optional[i].setFast(component); // we don't care if this is valid or not
+                            optional[i].setFast(component); // we don't care if
+                                                            // this is valid or
+                                                            // not
                         }
 
                         return true;
                 }
             }
         }
-        
+
         return false;
     }
 

File src/main/java/com/lhkbob/entreri/ComponentRepository.java

View file
 /*
  * 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.
+ * 
+ * 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;
 
 import com.lhkbob.entreri.property.IntProperty;
 
 /**
- * ComponentRepository manages storing all the componentDatas of a specific type for an
- * EntitySystem. It also controls the IndexedDataStore's for the type's set of
- * properties. It is package-private because its details are low-level and
- * complex.
+ * ComponentRepository manages storing all the componentDatas of a specific type
+ * for an EntitySystem. It also controls the IndexedDataStore's for the type's
+ * set of properties. It is package-private because its details are low-level
+ * and complex.
  * 
  * @author Michael Ludwig
  * @param <T> The type of component stored by the index
     private final TypeId<T> type;
 
     private final ComponentDataFactory<T> factory;
-    
+
     // These three arrays have a special value of 0 or null stored in the 0th
     // index, which allows us to lookup componentDatas or entities when they
     // normally aren't attached.
     private int[] componentIndexToEntityIndex;
     private Component<T>[] components;
     private int componentInsert;
-    
+
     private final List<PropertyStore<?>> declaredProperties;
     private final List<PropertyStore<?>> decoratedProperties;
-    
-    private final BooleanProperty enabledProperty; // this is also contained in decoratedProperties
-    private final IntProperty componentIdProperty; // this is contained in decoratedProperties
+
+    private final BooleanProperty enabledProperty; // this is also contained in
+                                                   // decoratedProperties
+    private final IntProperty componentIdProperty; // this is contained in
+                                                   // decoratedProperties
     private int idSeq;
-     
+
     /**
-     * Create a ComponentRepository for the given system, that will store Components
-     * of the given type.
+     * Create a ComponentRepository for the given system, that will store
+     * Components of the given type.
      * 
      * @param system The owning system
      * @param type The type of component
      * @throws NullPointerException if system or type are null
      */
     @SuppressWarnings({ "rawtypes", "unchecked" })
-    public ComponentRepository(EntitySystem system, TypeId<T> type, ComponentDataFactory<T> factory) {
-        if (system == null || type == null)
+    public ComponentRepository(EntitySystem system,
+                               TypeId<T> type,
+                               ComponentDataFactory<T> factory) {
+        if (system == null || type == null) {
             throw new NullPointerException("Arguments cannot be null");
-        
+        }
+
         this.system = system;
         this.factory = factory;
         this.type = type;
-        
+
         Map<?, PropertyFactory<?>> propertyFactories = factory.getPropertyFactories();
-        
+
         declaredProperties = new ArrayList<PropertyStore<?>>();
-        decoratedProperties = new ArrayList<PropertyStore<?>>(); // empty for now
-        for (Entry<?, PropertyFactory<?>> e: propertyFactories.entrySet()) {
+        decoratedProperties = new ArrayList<PropertyStore<?>>(); // empty for
+                                                                 // now
+        for (Entry<?, PropertyFactory<?>> e : propertyFactories.entrySet()) {
             PropertyStore store = new PropertyStore(e.getValue(), e.getKey());
             declaredProperties.add(store);
         }
-        
-        entityIndexToComponentRepository = new int[1]; // holds default 0 value in 0th index
-        componentIndexToEntityIndex = new int[1]; // holds default 0 value in 0th index
+
+        entityIndexToComponentRepository = new int[1]; // holds default 0 value
+                                                       // in 0th index
+        componentIndexToEntityIndex = new int[1]; // holds default 0 value in
+                                                  // 0th index
         components = new Component[1]; // holds default null value in 0th index
-        
+
         componentInsert = 1;
-        
+
         // Make sure properties' stores hold enough space
         resizePropertyStores(declaredProperties, 1);
-        
-        // decorate the component data with a boolean property to track enabled status
+
+        // decorate the component data with a boolean property to track enabled
+        // status
         enabledProperty = decorate(new BooleanProperty.Factory(true));
-        componentIdProperty = decorate(new IntProperty.Factory(0)); // we'll not assign a default value, since we change the id each time
+        componentIdProperty = decorate(new IntProperty.Factory(0)); // we'll not
+                                                                    // assign a
+                                                                    // default
+                                                                    // value,
+                                                                    // since we
+                                                                    // change
+                                                                    // the id
+                                                                    // each time
         idSeq = 1; // start at 1, just like entity id sequences
     }
-    
+
     /**
      * @return The type of component data stored by this component index
      */
     public int getMaxComponentIndex() {
         return componentInsert;
     }
-    
+
     /**
      * @return The owning EntitySystem
      */
      *         if the component is not attached
      */
     public int getEntityIndex(int componentIndex) {
-        if (componentIndex >= componentIndexToEntityIndex.length) {
-            System.out.println("problem!");
-        }
         return componentIndexToEntityIndex[componentIndex];
     }
 
     }
 
     /**
-     * Ensure that this ComponentRepository has enough internal space to hold its
-     * entity-to-component mapping for the given number of entities.
+     * Ensure that this ComponentRepository has enough internal space to hold
+     * its entity-to-component mapping for the given number of entities.
      * 
      * @param numEntities The new number of entities
      */
     public void expandEntityIndex(int numEntities) {
         if (entityIndexToComponentRepository.length < numEntities) {
-            entityIndexToComponentRepository = Arrays.copyOf(entityIndexToComponentRepository, (int) (numEntities * 1.5f) + 1);
+            entityIndexToComponentRepository = Arrays.copyOf(entityIndexToComponentRepository,
+                                                             (int) (numEntities * 1.5f) + 1);
         }
     }
-    
+
     /**
      * @return Estimated memory usage of this component repository
      */
         for (int i = 0; i < decoratedProperties.size(); i++) {
             total += decoratedProperties.get(i).property.getDataStore().memory();
         }
-        
+
         // also add in an estimate for other structures used by
         // this repository
         total += 4 * entityIndexToComponentRepository.length;
         total += 4 * componentIndexToEntityIndex.length;
-        
-        // estimate each Component object as 4 bytes for a pointer, 
+
+        // estimate each Component object as 4 bytes for a pointer,
         // 4 bytes for its index, 4 bytes for its repository reference
         total += 12 * components.length;
-        
+
         return total;
     }
 
     public void setEnabled(int componentIndex, boolean enabled) {
         enabledProperty.set(enabled, componentIndex);
     }
-    
+
     /**
      * @param componentIndex The component index
      * @return The component id of the component at the given index
     public int getId(int componentIndex) {
         return componentIdProperty.get(componentIndex);
     }
-    
+
     /*
      * As expandEntityIndex() but expands all related component data and arrays
      * to hold the number of components.
      */
     private void expandComponentRepository(int numComponents) {
-        if (numComponents < components.length)
+        if (numComponents < components.length) {
             return;
+        }
 
         int size = (int) (numComponents * 1.5f) + 1;
-        
+
         // Expand the indexed data stores for the properties
         resizePropertyStores(declaredProperties, size);
         resizePropertyStores(decoratedProperties, size);
-        
+
         // Expand the canonical component array
         components = Arrays.copyOf(components, size);
-        
+
         // Expand the component index
         componentIndexToEntityIndex = Arrays.copyOf(componentIndexToEntityIndex, size);
     }
             properties.get(i).property.setDataStore(newStore);
         }
     }
-    
+
     /**
      * @param componentIndex The component index whose component is fetched
      * @return The component reference at the given index, may be null
      */
     @SuppressWarnings({ "unchecked", "rawtypes" })
     public Component<T> addComponent(int entityIndex, Component<T> fromTemplate) {
-        if (fromTemplate.getEntitySystem() != getEntitySystem())
+        if (fromTemplate.getEntitySystem() != getEntitySystem()) {
             throw new IllegalArgumentException("Component not owned by expected EntitySystem");
-        if (!fromTemplate.getTypeId().equals(type))
-            throw new IllegalArgumentException("Component not of expected type, expected: " + type + ", but was: " + type);
-        if (!fromTemplate.isLive())
+        }
+        if (!fromTemplate.getTypeId().equals(type)) {
+            throw new IllegalArgumentException("Component not of expected type, expected: " + type
+                                               + ", but was: "
+                                               + type);
+        }
+        if (!fromTemplate.isLive()) {
             throw new IllegalStateException("Template component is not live");
-        
+        }
+
         Component<T> instance = addComponent(entityIndex);
         for (int i = 0; i < declaredProperties.size(); i++) {
             PropertyStore store = declaredProperties.get(i);
             store.clone(fromTemplate.index, store.property, instance.index);
         }
-        
+
         // fire add-event listener after cloning is completed
         system.getControllerManager().fireComponentAdd(instance);
         return instance;
      */
     public Component<T> addComponent(int entityIndex) {
         Component<T> instance = allocateComponent(entityIndex);
-        
+
         // fire add-event listener after initialization is completed
         system.getControllerManager().fireComponentAdd(instance);
         return instance;
     }
-    
+
     /*
      * Allocate and store a new component, but don't initialize it yet.
      */
     private Component<T> allocateComponent(int entityIndex) {
-        if (entityIndexToComponentRepository[entityIndex] != 0)
+        if (entityIndexToComponentRepository[entityIndex] != 0) {
             removeComponent(entityIndex);
-        
+        }
+
         int componentIndex = componentInsert++;
-        if (componentIndex >= components.length)
+        if (componentIndex >= components.length) {
             expandComponentRepository(componentIndex + 1);
+        }
 
         Component<T> instance = new Component<T>(this, componentIndex);
         components[componentIndex] = instance;
         for (int i = 0; i < declaredProperties.size(); i++) {
             declaredProperties.get(i).setValue(componentIndex);
         }
-        
+
         for (int i = 0; i < decoratedProperties.size(); i++) {
             decoratedProperties.get(i).setValue(componentIndex);
         }
-        
+
         // although there could be a custom PropertyFactory for setting the id,
         // it's easier to assign a new id here
         componentIdProperty.set(idSeq++, componentIndex);
-        
+
         return instance;
     }
 
      * @return A new data instance
      */
     public T createDataInstance() {
-        // create a new instance from the factory - it will be completely detached
+        // create a new instance from the factory - it will be completely
+        // detached
         T t = factory.createInstance();
-        
+
         // attach it to this data index, at the 0th index
-        //  - at this point the ComponentData's owner should be considered final
+        // - at this point the ComponentData's owner should be considered final
         t.owner = this;
-        
+
         // assign all property values
         for (int i = 0; i < declaredProperties.size(); i++) {
             PropertyStore<?> p = declaredProperties.get(i);
             factory.setProperty(t, p.key, p.property);
         }
-        
+
         t.set(null);
         return t;
     }
         }
 
         components[componentIndex] = null;
-        entityIndexToComponentRepository[entityIndex] = 0; // entity does not have component
-        componentIndexToEntityIndex[componentIndex] = 0; // component does not have entity
+        entityIndexToComponentRepository[entityIndex] = 0; // entity does not
+                                                           // have component
+        componentIndexToEntityIndex[componentIndex] = 0; // component does not
+                                                         // have entity
         componentIdProperty.set(0, componentIndex);
         enabledProperty.set(false, componentIndex);
-        
+
         return oldComponent != null;
     }
 
         for (int i = 0; i < properties.size(); i++) {
             PropertyStore<?> p = properties.get(i);
             IndexedDataStore origStore = p.property.getDataStore();
-            
+
             p.property.setDataStore(update(origStore, p.swap, newToOldMap));
             p.swap = origStore;
         }
      * Update all component data in src to be in dst by shuffling it to match
      * newToOldMap.
      */
-    private IndexedDataStore update(IndexedDataStore src, IndexedDataStore dst, 
+    private IndexedDataStore update(IndexedDataStore src,
+                                    IndexedDataStore dst,
                                     Component<T>[] newToOldMap) {
         int dstSize = newToOldMap.length;
-        
-        if (dst == null || dst.size() < dstSize)
+
+        if (dst == null || dst.size() < dstSize) {
             dst = src.create(dstSize);
-        
+        }
+
         int i;
         int lastIndex = -1;
         int copyIndexNew = -1;
                 // we've hit the end of existing componentDatas, so break
                 break;
             }
-            
+
             if (newToOldMap[i].index != lastIndex + 1) {
                 // we are not in a contiguous section
                 if (copyIndexOld >= 0) {
                     // we have to copy over the last section
                     src.copy(copyIndexOld, (i - copyIndexNew), dst, copyIndexNew);
                 }
-                
+
                 // set the copy indices
                 copyIndexNew = i;
                 copyIndexOld = newToOldMap[i].index;
             }
             lastIndex = newToOldMap[i].index;
         }
-        
+
         if (copyIndexOld >= 0) {
             // final copy
             src.copy(copyIndexOld, (i - copyIndexNew), dst, copyIndexNew);
 
         return dst;
     }
-    
+
     /**
      * <p>
      * Compact the data of this ComponentRepository to account for removals and
-     * additions to the index. This will ensure that all active componentDatas are
-     * packed into the underlying arrays, and that they will be accessed in the
-     * same order as iterating over the entities directly.
+     * additions to the index. This will ensure that all active componentDatas
+     * are packed into the underlying arrays, and that they will be accessed in
+     * the same order as iterating over the entities directly.
      * </p>
      * <p>
      * The map from old to new entity index must be used to properly update the
         Arrays.sort(components, 1, componentInsert, new Comparator<Component<T>>() {
             @Override
             public int compare(Component<T> o1, Component<T> o2) {
-                if (o1 != null && o2 != null)
+                if (o1 != null && o2 != null) {
                     return componentIndexToEntityIndex[o1.index] - componentIndexToEntityIndex[o2.index];
-                else if (o1 != null)
+                } else if (o1 != null) {
                     return -1; // push null o2 to end of array
-                else if (o2 != null)
+                } else if (o2 != null) {
                     return 1; // push null o1 to end of array
-                else
+                } else {
                     return 0; // both null so they are "equal"
+                }
             }
         });
-        
-        // Update all of the property stores to match up with the componentDatas new positions
+
+        // Update all of the property stores to match up with the componentDatas
+        // new positions
         update(declaredProperties, components);
         update(decoratedProperties, components);
-        
+
         // Repair the componentToEntityIndex and the component.index values
         componentInsert = 1;
         int[] newComponentRepository = new int[components.length];
             }
         }
         componentIndexToEntityIndex = newComponentRepository;
-        
+
         // Possibly compact the component data
         if (componentInsert < .6f * components.length) {
             int newSize = (int) (1.2f * componentInsert) + 1;
             components = Arrays.copyOf(components, newSize);
-            componentIndexToEntityIndex = Arrays.copyOf(componentIndexToEntityIndex, newSize);
+            componentIndexToEntityIndex = Arrays.copyOf(componentIndexToEntityIndex,
+                                                        newSize);
             resizePropertyStores(declaredProperties, newSize);
             resizePropertyStores(decoratedProperties, newSize);
         }
-        
-        // Repair entityIndexToComponentRepository - and possible shrink the index
+
+        // Repair entityIndexToComponentRepository - and possible shrink the
+        // index
         // based on the number of packed entities
-        if (numEntities < .6f * entityIndexToComponentRepository.length)
+        if (numEntities < .6f * entityIndexToComponentRepository.length) {
             entityIndexToComponentRepository = new int[(int) (1.2f * numEntities) + 1];
-        else
+        } else {
             Arrays.fill(entityIndexToComponentRepository, 0);
-        
-        for (int i = 1; i < componentInsert; i++)
+        }
+
+        for (int i = 1; i < componentInsert; i++) {
             entityIndexToComponentRepository[componentIndexToEntityIndex[i]] = i;
+        }
     }
 
     /**
-     * Decorate the type information of this ComponentRepository to add a property
-     * created by the given factory. The returned property will have default
-     * data assigned for each current Component in the index, and will have the
-     * default value assigned for each new Component. Decorators can then access
-     * the returned property to manipulate the decorated component data.
+     * Decorate the type information of this ComponentRepository to add a
+     * property created by the given factory. The returned property will have
+     * default data assigned for each current Component in the index, and will
+     * have the default value assigned for each new Component. Decorators can
+     * then access the returned property to manipulate the decorated component
+     * data.
      * 
      * @param <P> The type of property created
      * @param factory The factory that will create a unique Property instance
      */
     public <P extends Property> P decorate(PropertyFactory<P> factory) {
         int size = (declaredProperties.isEmpty() ? componentInsert
-                                                 : declaredProperties.get(0).property.getDataStore().size());
-        
+                                                : declaredProperties.get(0).property.getDataStore()
+                                                                                    .size());
+
         PropertyStore<P> pstore = new PropertyStore<P>(factory, "decorated");
 
         // Set values from factory to all component slots
         for (int i = 1; i < size; i++) {
             pstore.setValue(i);
         }
-        
+
         decoratedProperties.add(pstore);
         return pstore.property;
     }
      */
     public void undecorate(Property p) {
         Iterator<PropertyStore<?>> it = decoratedProperties.iterator();
-        while(it.hasNext()) {
+        while (it.hasNext()) {
             if (it.next().property == p) {
                 it.remove();
                 break;
             }
         }
     }
-    
+
     /*
      * Type wrapping a key, property, and factory, as well as an auxiliary data
      * store for compaction.
         final P property;
         final PropertyFactory<P> creator;
         IndexedDataStore swap; // may be null
-        
+
         public PropertyStore(PropertyFactory<P> creator, Object key) {
             this.creator = creator;
             this.key = key;
             property = creator.create();
         }
-        
+
         private void clone(int srcIndex, P dst, int dstIndex) {
             creator.clone(property, srcIndex, dst, dstIndex);
         }
-        
+
         private void setValue(int index) {
             creator.setDefaultValue(property, index);
         }

File src/main/java/com/lhkbob/entreri/Controller.java

View file
 /*
  * 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.
+ * 
+ * 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;
 
     public void postProcess(double dt);
 
     /**
-     * Invoked when a Controller is added to an EntitySystem. This method
-     * should initialize any system-specific state used by the controller,
-     * such as ComponentIterators, ComponentData instances, or decorated
-     * properties.
+     * Invoked when a Controller is added to an EntitySystem. This method should
+     * initialize any system-specific state used by the controller, such as
+     * ComponentIterators, ComponentData instances, or decorated properties.
      * 
      * @param system The new EntitySystem this controller is attached to
      * @throws IllegalStateException if the controller is already attached to
      * @param c The component being removed
      */
     public void onComponentRemove(Component<?> c);
-    
+
     /**
      * Invoked when any other Controller reports a Result to the
      * ControllerManager of this controller. Implementations may filter based on

File src/main/java/com/lhkbob/entreri/ControllerManager.java

View file
 /*
  * 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.
+ * 
+ * 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;
 
  */
 public class ControllerManager {
     /**
-     * The Phase enum represents the different phases of
-     * processing that an EntitySystem can go through during
-     * what is often considered a "frame".
+     * The Phase enum represents the different phases of processing that an
+     * EntitySystem can go through during what is often considered a "frame".
      */
     public static enum Phase {
         /**
          * The PREPROCESS phase is invoked before all other phases. All
          * controllers in a manager will have their
-         * {@link Controller#preProcess(double)} method called
-         * before moving to the next phase.
+         * {@link Controller#preProcess(double)} method called before moving to
+         * the next phase.
          */
         PREPROCESS,
 
         /**
          * The PROCESS phase is invoked between PREPROCESS and POSTPROCESS. All
          * controllers in the manager will have their
-         * {@link Controller#process(double)} method called before
-         * moving to the next phase.
+         * {@link Controller#process(double)} method called before moving to the
+         * next phase.
          */
         PROCESS,
 
     private final Map<Controller, ProfileData> profile;
 
     private final EntitySystem system;
-    
+
     private long lastProcessTime;
     private final Set<Class<?>> singletonResults;
-    
+
     private Phase currentPhase;
 
     /**
      * @throws NullPointerException if system is null
      */
     public ControllerManager(EntitySystem system) {
-        if (system == null)
+        if (system == null) {
             throw new NullPointerException("EntitySystem cannot be null");
-        
+        }
+
         this.system = system;
         controllers = new ArrayList<Controller>();
-        
+
         profile = new HashMap<Controller, ProfileData>();
         singletonResults = new HashSet<Class<?>>();
         lastProcessTime = -1L;
-        
+
         currentPhase = null;
     }
-    
+
     /**
      * Get an unmodifiable view of the controllers registered with this manager.
      * 
     public List<Controller> getControllers() {
         return Collections.unmodifiableList(controllers);
     }
-    
+
     /**
      * Report the given Result to all registered Controllers in this manager.
      * This can only be called while a Phase is being processed.
      *             this frame
      */
     public void report(Result result) {
-        if (currentPhase == null)
-            throw new IllegalStateException("Can only report results while processing a phase"); 
+        if (currentPhase == null) {
+            throw new IllegalStateException("Can only report results while processing a phase");
+        }
         if (result.isSingleton()) {
-            if (!singletonResults.add(result.getClass()))
-                throw new IllegalStateException("Singleton result of type " + result.getClass() + " already reported this frame");
+            if (!singletonResults.add(result.getClass())) {
+                throw new IllegalStateException("Singleton result of type " + result.getClass()
+                                                + " already reported this frame");
+            }
         }
-        
+
         int ct = controllers.size();
         for (int i = 0; i < ct; i++) {
             controllers.get(i).report(result);
      * @throws NullPointerException if controller is null
      */
     public void addController(Controller controller) {
-        if (controller == null)
+        if (controller == null) {
             throw new NullPointerException("Controller cannot be null");
-        
+        }
+
         // remove it first - which does nothing if not in the list
         boolean removed = controllers.remove(controller);
         // now add it to the end
         controllers.add(controller);
-        
+
         if (!removed) {
             // perform initialization steps if we've never seen the controller
             profile.put(controller, new ProfileData());
      * @throws NullPointerException if controller is null
      */
     public void removeController(Controller controller) {
-        if (controller == null)
+        if (controller == null) {
             throw new NullPointerException("Controller cannot be null");
+        }
         boolean removed = controllers.remove(controller);
         if (removed) {
             controller.destroy();
             profile.remove(controller);
         }
     }
-    
+
     /**
      * Return the last execution time for the given controller and phase. This
      * will return 0 if the controller has not been added to the manager.
      * @return The last execution time of the controller in nanoseconds.
      */
     public long getExecutionTime(Controller controller, Phase phase) {
-        if (controller == null || phase == null)
+        if (controller == null || phase == null) {
             throw new NullPointerException("Arguments cannot be null");
-        
+        }
+
         ProfileData c = profile.get(controller);
-        
+
         if (c != null) {
-            switch(phase) {
+            switch (phase) {
             case POSTPROCESS:
                 return c.postprocessTime;
             case PREPROCESS:
                 return c.processTime;
             }
         }
-        
+
         return 0L;
     }
-    
+
     /**
      * Return the last execution time for the given controller, for all its
      * phases, in nanoseconds.
      * @return The last total execution time of the controller
      */
     public long getExecutionTime(Controller controller) {
-        return getExecutionTime(controller, Phase.PREPROCESS) + getExecutionTime(controller, Phase.POSTPROCESS) + getExecutionTime(controller, Phase.PROCESS);
+        return getExecutionTime(controller, Phase.PREPROCESS) + getExecutionTime(controller,
+                                                                                 Phase.POSTPROCESS)
+               + getExecutionTime(controller, Phase.PROCESS);
     }
-    
+
     /**
      * Run all phases of the manager using the time delta from the last time the
      * post-process phase was executed. This means that the time delta is
      * call.
      */
     public void process() {
-        if (lastProcessTime < 0)
+        if (lastProcessTime < 0) {
             process(0);
-        else
+        } else {
             process((System.nanoTime() - lastProcessTime) / 1e9);
+        }
     }
 
     /**
      * @throws NullPointerException if phase is null
      */
     public void process(Phase phase, double dt) {
-        if (phase == null)
+        if (phase == null) {
             throw new NullPointerException("Phase cannot be null");
-        
+        }
+
         currentPhase = phase;
-        switch(phase) {
+        switch (phase) {
         case PREPROCESS:
-            firePreProcess(dt); break;
+            firePreProcess(dt);
+            break;
         case PROCESS:
-            fireProcess(dt); break;
+            fireProcess(dt);
+            break;
         case POSTPROCESS:
-            firePostProcess(dt); 
+            firePostProcess(dt);
             break;
         }
         currentPhase = null;
      * @param e The entity being added
      */
     void fireEntityAdd(Entity e) {
-        for (int i = 0; i < controllers.size(); i++)
+        for (int i = 0; i < controllers.size(); i++) {
             controllers.get(i).onEntityAdd(e);
+        }
     }
-    
+
     /**
      * Invoke onEntityRemove() for all controllers.
      * 
      * @param e The entity being removed
      */
     void fireEntityRemove(Entity e) {
-        for (int i = 0; i < controllers.size(); i++)
+        for (int i = 0; i < controllers.size(); i++) {
             controllers.get(i).onEntityRemove(e);
+        }
     }
-    
+
     /**
      * Invoke onComponentAdd() for all controllers.
      * 
      * @param c The component being added
      */
     void fireComponentAdd(Component<?> c) {
-        for (int i = 0; i < controllers.size(); i++)
+        for (int i = 0; i < controllers.size(); i++) {
             controllers.get(i).onComponentAdd(c);
+        }
     }
-    
+
     /**
      * Invoke onComponentRemove() for all controllers.
      * 
      * @param c The component being removed
      */
     void fireComponentRemove(Component<?> c) {
-        for (int i = 0; i < controllers.size(); i++)
+        for (int i = 0; i < controllers.size(); i++) {
             controllers.get(i).onComponentRemove(c);
+        }
     }
-    
+
     private void firePreProcess(double dt) {
         lastProcessTime = System.nanoTime();
 
             profile.get(controllers.get(i)).preprocessTime = System.nanoTime() - start;
         }
     }
-    
+
     private void fireProcess(double dt) {
         for (int i = 0; i < controllers.size(); i++) {
             long start = System.nanoTime();
             profile.get(controllers.get(i)).processTime = System.nanoTime() - start;
         }
     }
-    
+
     private void firePostProcess(double dt) {
         for (int i = 0; i < controllers.size(); i++) {
             long start = System.nanoTime();
             controllers.get(i).postProcess(dt);
             profile.get(controllers.get(i)).postprocessTime = System.nanoTime() - start;
         }
-        
+
         singletonResults.clear();
     }
-    
+
     private static class ProfileData {
         private long processTime;
         private long preprocessTime;
         private long postprocessTime;
-        
+
         public ProfileData() {
             processTime = 0;
             preprocessTime = 0;

File src/main/java/com/lhkbob/entreri/DefaultFactory.java

View file
 /*
  * 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.
+ * 
+ * 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;
 
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
-
 /**
  * <p>
  * DefaultFactory is a type-level annotation that can be added to ComponentData

File src/main/java/com/lhkbob/entreri/Entity.java

View file
 /*
  * 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