Search in sources :

Example 1 with FixedStringList

use of pcgen.base.util.FixedStringList in project pcgen by PCGen.

the class Equipment method getAssociationList.

public List<String> getAssociationList(CDOMObject obj) {
    List<String> list = new ArrayList<>();
    List<FixedStringList> assocList = assocSupt.getAssocList(obj, AssociationListKey.CHOICES);
    if (assocList != null) {
        for (FixedStringList ac : assocList) {
            final String choiceStr = ac.get(0);
            if (Constants.EMPTY_STRING.equals(choiceStr)) {
                list.add(null);
            } else {
                list.add(choiceStr);
            }
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) FixedStringList(pcgen.base.util.FixedStringList)

Example 2 with FixedStringList

use of pcgen.base.util.FixedStringList in project pcgen by PCGen.

the class AbstractReferenceManufacturer method resolveGroupReferences.

private boolean resolveGroupReferences() {
    for (T obj : getAllObjects()) {
        if (allRef != null) {
            allRef.addResolution(obj);
        }
        for (Map.Entry<FixedStringList, WeakReference<CDOMGroupRef<T>>> me : typeReferences.entrySet()) {
            CDOMGroupRef<T> trt = me.getValue().get();
            if (trt != null) {
                boolean typeOkay = true;
                for (String type : me.getKey()) {
                    if (!obj.isType(type)) {
                        typeOkay = false;
                        break;
                    }
                }
                if (typeOkay) {
                    trt.addResolution(obj);
                }
            }
        }
    }
    if (allRef != null && allRef.getObjectCount() == 0) {
        Logging.errorPrint("Error: No " + factory.getReferenceDescription() + " objects were loaded but were referred to in the data");
        fireUnconstuctedEvent(allRef);
        return false;
    }
    return true;
}
Also used : WeakReference(java.lang.ref.WeakReference) FixedStringList(pcgen.base.util.FixedStringList) CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString) TreeMap(java.util.TreeMap) KeyMap(pcgen.base.util.KeyMap) Map(java.util.Map)

Example 3 with FixedStringList

use of pcgen.base.util.FixedStringList in project pcgen by PCGen.

the class AbstractReferenceManufacturer method getTypeReference.

/**
	 * Gets a reference to the Class or Class/Context provided by this
	 * AbstractReferenceManufacturer. The reference will be a reference to the
	 * objects identified by the given types.
	 * 
	 * @param types
	 *            An array of the types of objects to which the returned
	 *            CDOMReference will refer.
	 * @return A CDOMGroupRef which is intended to contain objects of a given
	 *         Type for the Class or Class/Context this
	 *         AbstractReferenceManufacturer represents.
	 * @throws IllegalArgumentException
	 *             if any of the given Strings is null, empty (length is zero),
	 *             or contains a period (.), equals (=), comma (,) or pipe (|)
	 */
@Override
public CDOMGroupRef<T> getTypeReference(String... types) {
    for (String type : types) {
        if (type == null || type.isEmpty()) {
            throw new IllegalArgumentException("Attempt to acquire empty Type " + "(the type String contains a null or empty element)");
        }
        if (type.indexOf('.') != -1) {
            throw new IllegalArgumentException("Cannot build Reference with type conaining a period: " + type);
        }
        if (type.indexOf('=') != -1) {
            throw new IllegalArgumentException("Cannot build Reference with type conaining an equals: " + type);
        }
        if (type.indexOf(',') != -1) {
            throw new IllegalArgumentException("Cannot build Reference with type conaining a comma: " + type);
        }
        if (type.indexOf('|') != -1) {
            throw new IllegalArgumentException("Cannot build Reference with type conaining a pipe: " + type);
        }
    }
    Arrays.sort(types);
    FixedStringList typeList = new FixedStringList(types);
    WeakReference<CDOMGroupRef<T>> ref = typeReferences.get(typeList);
    if (ref != null) {
        CDOMGroupRef<T> trt = ref.get();
        if (trt != null) {
            return trt;
        }
    }
    // Didn't find the appropriate key, create new
    CDOMGroupRef<T> cgr = factory.getTypeReference(types);
    typeReferences.put(typeList, new WeakReference<>(cgr));
    return cgr;
}
Also used : CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString) FixedStringList(pcgen.base.util.FixedStringList)

Aggregations

FixedStringList (pcgen.base.util.FixedStringList)3 CaseInsensitiveString (pcgen.base.lang.CaseInsensitiveString)2 WeakReference (java.lang.ref.WeakReference)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 KeyMap (pcgen.base.util.KeyMap)1