MCPcopy Create free account
hub / github.com/PCGen/pcgen / StatAdapter

Class StatAdapter

code/src/java/pcgen/output/channel/compat/StatAdapter.java:32–97  ·  view source on GitHub ↗

A StatAdapter is the historical compatibility interface (facade) used to wrap to the gui2 non-channel system for setting and retrieving PCStat values.

Source from the content-addressed store, hash-verified

30 * gui2 non-channel system for setting and retrieving PCStat values.
31 */
32public final class StatAdapter extends AbstractAdapter<Number>
33 implements WriteableReferenceFacade<Number>, ScopeFacetChangeListener<CharID, PCStat, Number>
34{
35 private StatValueFacet statValueFacet = FacetLibrary.getFacet(StatValueFacet.class);
36
37 private final CharID id;
38 private final PCStat stat;
39 private Number lastKnown;
40
41 private StatAdapter(CharID id, PCStat stat)
42 {
43 this.id = id;
44 this.stat = stat;
45 lastKnown = 0;
46 }
47
48 @Override
49 public Number get()
50 {
51 return statValueFacet.get(id, stat);
52 }
53
54 @Override
55 public void set(Number value)
56 {
57 statValueFacet.set(id, stat, value);
58 }
59
60 /**
61 * Returns a StatAdapter for the PlayerCharacter represented by the given CharID and
62 * the given PCStat.
63 *
64 * @param id
65 * The CharID representing the PlayerCharacter for which the given
66 * StatAdapter should be returned
67 * @param stat
68 * The PCStat for which the StatAdapter will operate
69 * @return A StatAdapter for the PlayerCharacter represented by the given CharID and
70 * the given PCStat.
71 */
72 public static StatAdapter generate(CharID id, PCStat stat)
73 {
74 StatAdapter sa = new StatAdapter(id, stat);
75 sa.statValueFacet.addScopeFacetChangeListener(sa);
76 return sa;
77 }
78
79 @Override
80 public void dataAdded(ScopeFacetChangeEvent<CharID, PCStat, Number> dfce)
81 {
82 if (dfce.getCharID().equals(id) && dfce.getScope().equals(stat))
83 {
84 fireReferenceChangedEvent(this, lastKnown, dfce.getCDOMObject());
85 }
86 }
87
88 @Override
89 public void dataRemoved(ScopeFacetChangeEvent<CharID, PCStat, Number> dfce)

Callers

nothing calls this directly

Calls 1

getFacetMethod · 0.95

Tested by

no test coverage detected