Search in sources :

Example 1 with CompoundOrPrimitive

use of pcgen.cdom.primitive.CompoundOrPrimitive in project pcgen by PCGen.

the class ChoiceSetLoadUtilities method getPrimitive.

public static <T extends CDOMObject> PrimitiveCollection<T> getPrimitive(LoadContext context, SelectionCreator<T> sc, String joinedOr) {
    if (joinedOr.isEmpty() || hasIllegalSeparator('|', joinedOr)) {
        return null;
    }
    List<PrimitiveCollection<T>> pcfOrList = new ArrayList<>();
    ParsingSeparator pipe = new ParsingSeparator(joinedOr, '|');
    pipe.addGroupingPair('[', ']');
    pipe.addGroupingPair('(', ')');
    for (; pipe.hasNext(); ) {
        String joinedAnd = pipe.next();
        if (joinedAnd.isEmpty() || hasIllegalSeparator(',', joinedAnd)) {
            return null;
        }
        List<PrimitiveCollection<T>> pcfAndList = new ArrayList<>();
        ParsingSeparator comma = new ParsingSeparator(joinedAnd, ',');
        comma.addGroupingPair('[', ']');
        comma.addGroupingPair('(', ')');
        for (; comma.hasNext(); ) {
            String primitive = comma.next();
            if (primitive == null || primitive.isEmpty()) {
                Logging.addParseMessage(Logging.LST_ERROR, "Choice argument was null or empty: " + primitive);
                return null;
            }
            PrimitiveCollection<T> pcf = getSimplePrimitive(context, sc, primitive);
            if (pcf == null) {
                Logging.addParseMessage(Logging.LST_ERROR, "Choice argument was not valid: " + primitive);
                return null;
            } else {
                pcfAndList.add(pcf);
            }
        }
        if (pcfAndList.size() == 1) {
            pcfOrList.add(pcfAndList.get(0));
        } else {
            pcfOrList.add(new CompoundAndPrimitive<>(pcfAndList));
        }
    }
    if (pcfOrList.size() == 1) {
        return pcfOrList.get(0);
    } else {
        return new CompoundOrPrimitive<>(pcfOrList);
    }
}
Also used : CompoundOrPrimitive(pcgen.cdom.primitive.CompoundOrPrimitive) ParsingSeparator(pcgen.base.text.ParsingSeparator) ArrayList(java.util.ArrayList) PrimitiveCollection(pcgen.cdom.base.PrimitiveCollection)

Aggregations

ArrayList (java.util.ArrayList)1 ParsingSeparator (pcgen.base.text.ParsingSeparator)1 PrimitiveCollection (pcgen.cdom.base.PrimitiveCollection)1 CompoundOrPrimitive (pcgen.cdom.primitive.CompoundOrPrimitive)1