robocode.naval
Class ComponentManager

java.lang.Object
  extended by robocode.naval.ComponentManager
All Implemented Interfaces:
Serializable, IComponents

public class ComponentManager
extends Object
implements Serializable, IComponents

Manages the different components that can be assigned to a ship.

Since:
1.8.3.0 Alpha 1
Version:
0.3
Author:
Thales B.V. / Jiri Waning / Thomas Hakkers
See Also:
Serialized Form

Field Summary
static int MAX_COMPONENTS
          The maximum amount of components that can be added to a ship.
 
Constructor Summary
ComponentManager()
           
 
Method Summary
 void addComponent(IComponent component)
          Add a component.
 void addComponent(int index, IComponent component)
          Add a component on the specified index.
static ComponentManager copy(ComponentManager manager)
          Get a copy of the given ComponentManager.
 Color getColor(int index)
          Get the color of the component at the specified index.
<T extends IComponent>
T
getComponent(Class<T> componentClass)
          Get the first component that matches the given class.
 IComponent getComponent(int index)
          Get the component at the specified index.
 ArrayList<IComponent> getComponentArrayList()
           
<T extends IComponent>
T[]
getComponents(Class<T> componentClass)
          Get an array of components that match the given class.
<T extends IComponent>
int
indexOf(T value)
          Get the index of the specified component.
 boolean isValidIndex(int index)
          Determines whether the given index is a valid index for this ComponentManager.
 void removeComponent(int index)
          Remove the component at the specified index.
<T extends IComponent>
void
removeComponent(T component)
          Remove the specified component.
<T extends IComponent>
void
removeComponents(Class<T> componentClass)
          Remove the components that match the specified class.
 void setColor(int index, Color color)
          Set the color of the component at the specified index.
 int size()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_COMPONENTS

public static final int MAX_COMPONENTS
The maximum amount of components that can be added to a ship.

See Also:
Constant Field Values
Constructor Detail

ComponentManager

public ComponentManager()
Method Detail

getComponentArrayList

public ArrayList<IComponent> getComponentArrayList()

copy

public static final ComponentManager copy(ComponentManager manager)
Get a copy of the given ComponentManager.

Parameters:
manager - The manager that has to be copied.
Returns:
A copy of the manager.

size

public int size()


isValidIndex

public boolean isValidIndex(int index)
Determines whether the given index is a valid index for this ComponentManager.

Parameters:
index - The index we want to validate.
Returns:
true when the given index is valid; false otherwise.

indexOf

public <T extends IComponent> int indexOf(T value)
Get the index of the specified component.

-1 when the component has not available.

Specified by:
indexOf in interface IComponents
Parameters:
value - The component from whom to get the index.
Returns:
The index of the component.

removeComponent

public void removeComponent(int index)
Remove the component at the specified index.

Specified by:
removeComponent in interface IComponents
Parameters:
index - The index of the component that has to be removed.

getComponent

public IComponent getComponent(int index)
Get the component at the specified index.

Specified by:
getComponent in interface IComponents
Parameters:
index - The index of the component.
Returns:
The component at the specified index.

addComponent

public void addComponent(IComponent component)
Add a component.

Specified by:
addComponent in interface IComponents
Parameters:
component - The component that has to be added.

addComponent

public void addComponent(int index,
                         IComponent component)
Add a component on the specified index.

Specified by:
addComponent in interface IComponents
Parameters:
index - The index at which the add the component.
component - The component whom has to be added.

removeComponent

public <T extends IComponent> void removeComponent(T component)
Remove the specified component.

Specified by:
removeComponent in interface IComponents
Parameters:
component - The component to remove.

removeComponents

public <T extends IComponent> void removeComponents(Class<T> componentClass)
Remove the components that match the specified class.

Specified by:
removeComponents in interface IComponents
Parameters:
componentClass - The class of the objects to remove.

getComponent

public <T extends IComponent> T getComponent(Class<T> componentClass)
Get the first component that matches the given class.

null when there is no component of the given class.

Specified by:
getComponent in interface IComponents
Parameters:
componentClass - The class of the component.
Returns:
The first component that matches the given class.

getComponents

public <T extends IComponent> T[] getComponents(Class<T> componentClass)
Get an array of components that match the given class.

null when there are no components matching the given class.

Specified by:
getComponents in interface IComponents
Parameters:
componentClass - The common class of the objects.
Returns:
An array of components that match the given class.

setColor

public void setColor(int index,
                     Color color)
Set the color of the component at the specified index.

Parameters:
index - The index of the component.
color - The color that the component should have.

getColor

public Color getColor(int index)
Get the color of the component at the specified index.

Parameters:
index - The index of the component.
Returns:
The color of the component.


Copyright © 2015 Robocode. All Rights Reserved.