shady.common.multi
Class MultiShadyCommon

java.lang.Object
  extended by shady.common.multi.MultiShadyCommon
All Implemented Interfaces:
MultiShadyCommonAPI
Direct Known Subclasses:
MultiShadySim

public abstract class MultiShadyCommon
extends java.lang.Object
implements MultiShadyCommonAPI

MultiShady implementation subset that is shared between the simulator and the hardware.

Copyright (C) 2006 Marsette A. Vona, III

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Author:
Marsette (Marty) A. Vona, III

Nested Class Summary
 
Nested classes/interfaces inherited from interface shady.common.multi.MultiShadyCommonAPI
MultiShadyCommonAPI.MemberProcessor
 
Field Summary
(package private) static java.lang.String cvsid
          CVS id.
protected  java.util.Set members
          Our members.
protected  java.util.Map membersByIndex
          Our members mapped by index (zero-based).
protected  java.util.Map membersByName
          Our members mapped by name.
protected  java.util.Set unmodifiableMembers
          Unmodifiable view of members.
 
Constructor Summary
MultiShadyCommon()
          Create a new MultiShadyCommon with zero members.
MultiShadyCommon(MemberShadyCommonAPI member)
          Create a new MultiShadyCommon with one member.
MultiShadyCommon(MemberShadyCommonAPI[] member)
          Create a new MultiShadyCommon.
 
Method Summary
 int addMember(MemberShadyCommonAPI newMember)
          Add a member at the end of the list.
 int addMember(ShadyPose pose)
          Make and add a new member at the end of the list.
 void clearMembers()
          Remove all members.
 void exec(java.util.Collection operations)
          Atomically execute the specified BoundOperations, in order.
 void forEachMember(MultiShadyCommonAPI.MemberProcessor processor)
          Atomically process all members.
 void forMembers(java.util.Collection keys, MultiShadyCommonAPI.MemberProcessor processor)
          Atomically process a subset of the members.
 MemberShadyCommonAPI getMember(int index)
          Get a member by index.
 MemberShadyCommonAPI getMember(java.lang.Integer index)
          Get a member by index.
 MemberShadyCommonAPI getMember(java.lang.String name)
          Get a member by name.
 java.util.Set getMembers()
          Get an unmodifiable view of the set of MemberShadys in this MultiShady.
 int getNumActiveActuators()
          Get sum of ShadyCommonAPI.getNumActiveActuators() over all members.
abstract  MemberShadyCommonAPI makeMember(ShadyPose pose)
          Make and a new member but don't add it.
protected  java.lang.String makeMemberName(MemberShadyCommonAPI member, int index)
          Make a name for a member.
 int numMembers()
          Get the number of MemberShadys in this MultiShady.
 MemberShadyCommonAPI removeLastMember()
          Remove the last member.
 void reset()
          ShadyCommonAPI.reset() all members.
 void stop(boolean estop)
          ShadyCommonAPI.stop(boolean) all members.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface shady.common.multi.MultiShadyCommonAPI
getClock
 

Field Detail

cvsid

static final java.lang.String cvsid

CVS id.

See Also:
Constant Field Values

members

protected java.util.Set members

Our members.


membersByName

protected java.util.Map membersByName

Our members mapped by name.


membersByIndex

protected java.util.Map membersByIndex

Our members mapped by index (zero-based).


unmodifiableMembers

protected java.util.Set unmodifiableMembers

Unmodifiable view of members.

Constructor Detail

MultiShadyCommon

public MultiShadyCommon(MemberShadyCommonAPI[] member)

Create a new MultiShadyCommon.

The members will have thier index and MultiShady reference set, and their name set iff not previously set.

Parameters:
member - the members, null for none

MultiShadyCommon

public MultiShadyCommon(MemberShadyCommonAPI member)

Create a new MultiShadyCommon with one member.

Parameters:
member - the member, null for none

MultiShadyCommon

public MultiShadyCommon()

Create a new MultiShadyCommon with zero members.

Method Detail

makeMemberName

protected java.lang.String makeMemberName(MemberShadyCommonAPI member,
                                          int index)

Make a name for a member.

Does not actually set the name.

Parameters:
member - the meber to name
index - the index of the member

numMembers

public int numMembers()

Get the number of MemberShadys in this MultiShady.

Specified by:
numMembers in interface MultiShadyCommonAPI
Returns:
the number of MemberShadys in this MultiShady

getMembers

public java.util.Set getMembers()

Get an unmodifiable view of the set of MemberShadys in this MultiShady.

Specified by:
getMembers in interface MultiShadyCommonAPI
Returns:
an unmodifiable view of the (synchronized) set of MemberShadys in this MultiShady (will track the set of members as it evolves)

getMember

public MemberShadyCommonAPI getMember(int index)

Get a member by index.

Specified by:
getMember in interface MultiShadyCommonAPI
Parameters:
index - the index of the member to get, zero-based

getMember

public MemberShadyCommonAPI getMember(java.lang.Integer index)

Get a member by index.

Specified by:
getMember in interface MultiShadyCommonAPI
Parameters:
index - the index of the member to get, zero-based

getMember

public MemberShadyCommonAPI getMember(java.lang.String name)

Get a member by name.

Specified by:
getMember in interface MultiShadyCommonAPI
Parameters:
name - the name of the member to get

addMember

public int addMember(MemberShadyCommonAPI newMember)

Add a member at the end of the list.

newMember has its index and MultiShady reference set, and has its name set iff it was not previously set.

Specified by:
addMember in interface MultiShadyCommonAPI
Parameters:
newMember - the new member to add
Returns:
the new number of members

addMember

public int addMember(ShadyPose pose)

Make and add a new member at the end of the list.

Calls MultiShadyCommonAPI.makeMember(shady.common.ShadyPose) and then MultiShadyCommonAPI.addMember(MemberShadyCommonAPI).

Specified by:
addMember in interface MultiShadyCommonAPI
Parameters:
pose - the pose of the new member
Returns:
the new number of members

makeMember

public abstract MemberShadyCommonAPI makeMember(ShadyPose pose)

Make and a new member but don't add it.

Specified by:
makeMember in interface MultiShadyCommonAPI
Parameters:
pose - the pose of the new member
Returns:
the new number of members

removeLastMember

public MemberShadyCommonAPI removeLastMember()

Remove the last member.

By the convention defined in the class header doc, implementations should be synchronized.

The removed member has its index set to -1 and its MultiShady reference nulled, but does not have its name changed.

Specified by:
removeLastMember in interface MultiShadyCommonAPI
Returns:
the removed member, or null if none

clearMembers

public void clearMembers()

Remove all members.

By the convention defined in the class header doc, implementations should be synchronized.

Specified by:
clearMembers in interface MultiShadyCommonAPI

forEachMember

public void forEachMember(MultiShadyCommonAPI.MemberProcessor processor)

Atomically process all members.

By the convention defined in the class header doc, implementations should be synchronized.

The extra parameter of MultiShadyCommonAPI.MemberProcessor.process(shady.common.multi.MemberShadyCommonAPI, java.lang.Object) will be set null by default.

Specified by:
forEachMember in interface MultiShadyCommonAPI
Parameters:
processor - the non-null processor to call for each member

forMembers

public void forMembers(java.util.Collection keys,
                       MultiShadyCommonAPI.MemberProcessor processor)

Atomically process a subset of the members.

By the convention defined in the class header doc, implementations should be synchronized.

The extra parameter of MultiShadyCommonAPI.MemberProcessor.process(shady.common.multi.MemberShadyCommonAPI, java.lang.Object) will be set to the corresponding key.

Specified by:
forMembers in interface MultiShadyCommonAPI
Parameters:
keys - a non-null collection of MemberShadyCommonAPI, String, or Integer identifying members directly, by name, or by index, respectively. If multiple keys resolve to the same member the member will be processed multiple times.
processor - the non-null processor to call for each member corresponding to each key

exec

public void exec(java.util.Collection operations)

Atomically execute the specified BoundOperations, in order.

By the convention defined in the class header doc, implementations should be synchronized.

Specified by:
exec in interface MultiShadyCommonAPI
Parameters:
operations - the BoundOperations to execute, in iterator order, not null

stop

public void stop(boolean estop)

ShadyCommonAPI.stop(boolean) all members.

By the convention defined in the class header doc, implementations should be synchronized.

Specified by:
stop in interface MultiShadyCommonAPI

reset

public void reset()

ShadyCommonAPI.reset() all members.

By the convention defined in the class header doc, implementations should be synchronized.

Specified by:
reset in interface MultiShadyCommonAPI

getNumActiveActuators

public int getNumActiveActuators()

Get sum of ShadyCommonAPI.getNumActiveActuators() over all members.

By the convention defined in the class header doc, implementations should be synchronized.

Specified by:
getNumActiveActuators in interface MultiShadyCommonAPI
Returns:
sum of MemberShadyCommonAPI.getNumActiveActuators() over all members