| 1 |
// Copyright 2001, FreeHEP. |
| 2 |
package org.freehep.util.io; |
| 3 |
|
| 4 |
import java.util.HashMap; |
| 5 |
import java.util.Map; |
| 6 |
|
| 7 |
/** |
| 8 |
* Class to keep registered Actions, which should be used by the |
| 9 |
* TaggedIn/OutputStream. |
| 10 |
* |
| 11 |
* A set of recognized Actions can be added to this class. A concrete |
| 12 |
* implementation of this stream should install all allowed actions. |
| 13 |
* |
| 14 |
* @author Mark Donszelmann |
| 15 |
* @author Charles Loomis |
| 16 |
* @version $Id: ActionSet.java 8584 2006-08-10 23:06:37Z duns $ |
| 17 |
*/ |
| 18 |
public class ActionSet { |
| 19 |
|
| 20 |
/** |
| 21 |
* This holds the individual actions. |
| 22 |
*/ |
| 23 |
protected Map actions; |
| 24 |
|
| 25 |
protected Action defaultAction; |
| 26 |
|
| 27 |
/** |
| 28 |
* Creates an set for actions |
| 29 |
*/ |
| 30 |
public ActionSet() { |
| 31 |
actions = new HashMap(); |
| 32 |
defaultAction = new Action.Unknown(); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Adds an action to the set |
| 37 |
* |
| 38 |
* @param action to be added |
| 39 |
*/ |
| 40 |
public void addAction(Action action) { |
| 41 |
actions.put(new Integer(action.getCode()), action); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Looks up the corresponding action for an action code. |
| 46 |
* |
| 47 |
* @param actionCode code to be looked for |
| 48 |
* @return corresponding action, or Action.Unknown in case Action is not |
| 49 |
* found. |
| 50 |
*/ |
| 51 |
public Action get(int actionCode) { |
| 52 |
Action action = (Action) actions.get(new Integer(actionCode)); |
| 53 |
if (action == null) |
| 54 |
action = defaultAction; |
| 55 |
return action; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Looks if an Action for code is in this set. |
| 60 |
* |
| 61 |
* @param actionCode code to be looked for |
| 62 |
* @return true if action exists for code |
| 63 |
*/ |
| 64 |
public boolean exists(int actionCode) { |
| 65 |
return (actions.get(new Integer(actionCode)) != null); |
| 66 |
} |
| 67 |
} |