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

Class AbstractListFacet

code/src/java/pcgen/cdom/facet/base/AbstractListFacet.java:47–528  ·  view source on GitHub ↗

A AbstractListFacet is a DataFacet that contains information about Objects that are contained in a Player Character when a Player Character may have more than one of that type of Object (e.g. Language, PCTemplate). This is not used for Objects where the Player Character only possesses one of that ty

Source from the content-addressed store, hash-verified

45 * The Type of object stored in this AbstractListFacet
46 */
47public abstract class AbstractListFacet<IDT extends PCGenIdentifier, T> extends AbstractDataFacet<IDT, T>
48{
49 /**
50 * Add the given object to the list of objects stored in this
51 * AbstractListFacet for the Player Character represented by the given
52 * PCGenIdentifier
53 *
54 * @param id
55 * The PCGenIdentifier representing the Player Character for
56 * which the given item should be added
57 * @param obj
58 * The object to be added to the list of objects stored in this
59 * AbstractListFacet for the Player Character represented by the
60 * given PCGenIdentifier
61 * @return true if the object was added; false otherwise
62 */
63 public boolean add(IDT id, T obj)
64 {
65 Objects.requireNonNull(obj, "Object to add may not be null");
66
67 if (getConstructingCachedSet(id).add(obj))
68 {
69 fireDataFacetChangeEvent(id, obj, DataFacetChangeEvent.DATA_ADDED);
70 return true;
71 }
72 else
73 {
74 return false;
75 }
76 }
77
78 /**
79 * Adds all of the objects in the given Collection to the list of objects
80 * stored in this AbstractListFacet for the Player Character represented by
81 * the given PCGenIdentifier
82 *
83 * @param id
84 * The PCGenIdentifier representing the Player Character for
85 * which the given items should be added
86 * @param c
87 * The Collection of objects to be added to the list of objects
88 * stored in this AbstractListFacet for the Player Character
89 * represented by the given PCGenIdentifier
90 * @throws NullPointerException
91 * if the given Collection is null
92 */
93 public void addAll(IDT id, Collection<T> c)
94 {
95 if (c.isEmpty())
96 {
97 return;
98 }
99 Collection<T> set = getConstructingCachedSet(id);
100 for (T obj : c)
101 {
102 Objects.requireNonNull(obj, "Object to add may not be null");
103 if (set.add(obj))
104 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected