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

Class BasicIndirect

PCGen-base/code/src/java/pcgen/base/util/BasicIndirect.java:33–107  ·  view source on GitHub ↗

A BasicIndirect is a simple container for storing an object that is accessed indirectly (meaning the resolvesTo() method of the BasicIndirect will be called at Runtime). This is generally used for wrapping "known" objects so that all objects are dealt with indirectly. (In some cases, items cannot b

Source from the content-addressed store, hash-verified

31 * The format (class) of object that the BasicIndirect contains
32 */
33public class BasicIndirect<T> implements Indirect<T>
34{
35
36 /**
37 * Contains the FormatManager that can handle the object contained in this
38 * BasicIndirect.
39 */
40 private final FormatManager<T> formatManager;
41
42 /**
43 * Contains the single object contained in this BasicIndirect.
44 */
45 private final T object;
46
47 /**
48 * Constructs a new BasicIndirect containing the single object provided.
49 *
50 * @param fmtManager
51 * The FormatManager usable to manage the given object
52 * @param obj
53 * The single object that this BasicIndirect will contain
54 * @throws IllegalArgumentException
55 * if the given object is not compatible with the given FormatManager
56 */
57 public BasicIndirect(FormatManager<T> fmtManager, T obj)
58 {
59 //Validate the generics ;)
60 if (!fmtManager.getManagedClass().isAssignableFrom(obj.getClass()))
61 {
62 throw new IllegalArgumentException("Object of class "
63 + obj.getClass()
64 + " is not compatible with provided Format Manager: "
65 + fmtManager.getManagedClass());
66 }
67 object = obj;
68 formatManager = fmtManager;
69 }
70
71 @Override
72 public T get()
73 {
74 return object;
75 }
76
77 @Override
78 public String getUnconverted()
79 {
80 return formatManager.unconvert(object);
81 }
82
83 @Override
84 public String toString()
85 {
86 return String.valueOf(object);
87 }
88
89 @Override
90 public boolean equals(Object obj)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected