Search in sources :

Example 6 with CaseInsensitiveString

use of pcgen.base.lang.CaseInsensitiveString in project pcgen by PCGen.

the class InfoLst method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject cdo) {
    MapChanges<CaseInsensitiveString, MessageFormat> changes = context.getObjectContext().getMapChanges(cdo, MapKey.INFO);
    if (changes == null || changes.isEmpty()) {
        return null;
    }
    Set<String> set = new TreeSet<>();
    for (CaseInsensitiveString key : changes.getAdded().keySet()) {
        MessageFormat value = changes.getAdded().get(key);
        set.add(new StringBuilder().append(key).append(Constants.PIPE).append(value.toPattern()).toString());
    }
    return set.toArray(new String[set.size()]);
}
Also used : MessageFormat(java.text.MessageFormat) TreeSet(java.util.TreeSet) CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString) CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString)

Example 7 with CaseInsensitiveString

use of pcgen.base.lang.CaseInsensitiveString in project pcgen by PCGen.

the class InfoVarsLst method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject cdo, String value) {
    int pipeLoc = value.indexOf(Constants.PIPE);
    if (pipeLoc == -1) {
        return new ParseResult.Fail(getTokenName() + " expecting '|', format is: InfoName|Info value was: " + value, context);
    }
    String key = value.substring(0, pipeLoc);
    //key length 0 caught by charAt(0) test above
    String[] val = value.substring(pipeLoc + 1).split("\\|");
    VariableContext varContext = context.getVariableContext();
    for (String name : val) {
        LegalScope scope = context.getActiveScope().getLegalScope();
        if (!varContext.isLegalVariableID(scope, name)) {
            return new ParseResult.Fail(getTokenName() + " found an error. " + name + " is not a legal variable name in scope " + scope.getName() + " in " + cdo.getClass().getSimpleName() + ' ' + cdo.getKeyName(), context);
        }
    }
    CaseInsensitiveString cis = new CaseInsensitiveString(key);
    context.getObjectContext().put(cdo, MapKey.INFOVARS, cis, val);
    return ParseResult.SUCCESS;
}
Also used : LegalScope(pcgen.base.formula.base.LegalScope) CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString) VariableContext(pcgen.rules.context.VariableContext) CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString)

Example 8 with CaseInsensitiveString

use of pcgen.base.lang.CaseInsensitiveString in project pcgen by PCGen.

the class AbstractReferenceManufacturer method forgetObject.

/**
	 * Remove the given object from this AbstractReferenceManufacturer. Returns
	 * true if the object was removed from this AbstractReferenceManufacturer;
	 * false otherwise.
	 * 
	 * @param item
	 *            The object to be removed from this
	 *            AbstractReferenceManufacturer.
	 * @return true if the object was removed from this
	 *         AbstractReferenceManufacturer; false otherwise.
	 */
@Override
public boolean forgetObject(T item) {
    if (!factory.isMember(item)) {
        throw new IllegalArgumentException("Object to be forgotten does not match Class " + "of this AbstractReferenceManufacturer");
    }
    String key = active.getKeyFor(item);
    if (key == null) {
        /*
			 * TODO This is a bug - the key name is not necessarily loaded into
			 * the object, it may have been consumed by the object context... :P
			 */
        CaseInsensitiveString ocik = new CaseInsensitiveString(item.getKeyName());
        duplicates.removeFromListFor(ocik, item);
    } else {
        CaseInsensitiveString ocik = new CaseInsensitiveString(key);
        List<T> list = duplicates.getListFor(ocik);
        if (list == null) {
            // No replacement
            active.remove(key);
        } else {
            T newActive = duplicates.getElementInList(ocik, 0);
            duplicates.removeFromListFor(ocik, newActive);
            active.put(key, newActive);
        }
    }
    return true;
}
Also used : CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString) CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString)

Example 9 with CaseInsensitiveString

use of pcgen.base.lang.CaseInsensitiveString in project pcgen by PCGen.

the class InfoModel method getVars.

private Object[] getVars(CaseInsensitiveString cis) {
    String[] vars = cdo.get(MapKey.INFOVARS, cis);
    int varCount = vars != null ? vars.length : 0;
    Object[] replacedvars = new Object[varCount];
    if (varCount == 0) {
        return replacedvars;
    }
    ResultFacet resultFacet = FacetLibrary.getFacet(ResultFacet.class);
    for (int i = 0; i < varCount; i++) {
        String varIdent = vars[i];
        replacedvars[i] = resultFacet.getLocalVariable(id, cdo, varIdent);
    }
    return replacedvars;
}
Also used : ResultFacet(pcgen.cdom.facet.analysis.ResultFacet) CDOMObject(pcgen.cdom.base.CDOMObject) CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString)

Example 10 with CaseInsensitiveString

use of pcgen.base.lang.CaseInsensitiveString in project pcgen by PCGen.

the class VisionType method getVisionType.

public static VisionType getVisionType(String s) {
    if (typeMap == null) {
        buildMap();
    }
    CaseInsensitiveString caseInsensitiveS = new CaseInsensitiveString(s);
    /*
		 * CONSIDER Now this is CASE INSENSITIVE. Should this really be the
		 * case? - thpr 10/28/06
		 */
    VisionType o = typeMap.get(caseInsensitiveS);
    if (o == null) {
        o = new VisionType();
        typeMap.put(caseInsensitiveS, o);
    }
    return o;
}
Also used : CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString)

Aggregations

CaseInsensitiveString (pcgen.base.lang.CaseInsensitiveString)12 MessageFormat (java.text.MessageFormat)4 TreeSet (java.util.TreeSet)2 CDOMObject (pcgen.cdom.base.CDOMObject)2 WeakReference (java.lang.ref.WeakReference)1 Field (java.lang.reflect.Field)1 LegalScope (pcgen.base.formula.base.LegalScope)1 ObjectWrapperFacet (pcgen.cdom.facet.ObjectWrapperFacet)1 ResultFacet (pcgen.cdom.facet.analysis.ResultFacet)1 VariableContext (pcgen.rules.context.VariableContext)1 ParseResult (pcgen.rules.persistence.token.ParseResult)1