Search in sources :

Example 1 with IdentityHashMap

use of java.util.IdentityHashMap in project che by eclipse.

the class AnnotationModelImpl method shiftLines.

// TODO evaluate: keep?
public void shiftLines(final int fromLine, final int lineDelta, final int charDelta) {
    final Map<Annotation, Position> modified = new IdentityHashMap<>();
    for (final Entry<Annotation, Position> entry : this.annotations.entrySet()) {
        final Position position = entry.getValue();
        final TextPosition textPos = docHandle.getDocument().getPositionFromIndex(position.getOffset());
        int horizontal;
        if (textPos.getLine() == fromLine) {
            horizontal = charDelta;
        } else if (textPos.getLine() >= fromLine) {
            horizontal = 0;
        } else {
            continue;
        }
        final TextPosition newTextPos = new TextPosition(fromLine + lineDelta, textPos.getCharacter() + horizontal);
        final int newOffset = docHandle.getDocument().getIndexFromPosition(newTextPos);
        final Position newPos = new Position(newOffset, position.getLength());
        modified.put(entry.getKey(), newPos);
    }
    // merge changes in the annotartion map
    this.annotations.putAll(modified);
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) IdentityHashMap(java.util.IdentityHashMap) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation)

Example 2 with IdentityHashMap

use of java.util.IdentityHashMap in project pcgen by PCGen.

the class ConditionalTemplateFacet method levelChanged.

/**
	 * Adds (or removes) all of the conditional Templates available to the
	 * Player Character to this ConditionalTemplateFacet. This requires a global
	 * check of all Templates granted to the Player Character, since this is
	 * occurring when the Player Character level changes.
	 * 
	 * Triggered when the Level of the Player Character changes.
	 * 
	 * @param lce
	 *            The LevelChangeEvent containing the information about the
	 *            level change
	 * 
	 * @see pcgen.cdom.facet.analysis.LevelFacet.LevelChangeListener#levelChanged(pcgen.cdom.facet.analysis.LevelFacet.LevelChangeEvent)
	 */
@Override
public void levelChanged(LevelChangeEvent lce) {
    CharID id = lce.getCharID();
    Collection<PCTemplate> oldSet = getSet(id);
    int totalLevels = levelFacet.getTotalLevels(id);
    int totalHitDice = levelFacet.getMonsterLevelCount(id);
    Map<PCTemplate, PCTemplate> newMap = new IdentityHashMap<>();
    for (PCTemplate sourceTempl : templateFacet.getSet(id)) {
        List<PCTemplate> conditionalTemplates = sourceTempl.getConditionalTemplates(totalLevels, totalHitDice);
        for (PCTemplate condTempl : conditionalTemplates) {
            newMap.put(condTempl, sourceTempl);
        }
    }
    // Delete items that the PC no longer has
    for (PCTemplate a : oldSet) {
        if (!newMap.containsKey(a)) {
            remove(id, a);
        }
    }
    //Add new items
    for (Map.Entry<PCTemplate, PCTemplate> me : newMap.entrySet()) {
        PCTemplate a = me.getKey();
        // We need to check for presence by object identity (==) rather than equality (.equals)
        boolean found = false;
        for (PCTemplate pcTemplate : oldSet) {
            if (a == pcTemplate) {
                found = true;
            }
        }
        if (!found) {
            add(id, a);
        }
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) PCTemplate(pcgen.core.PCTemplate) CharID(pcgen.cdom.enumeration.CharID) IdentityHashMap(java.util.IdentityHashMap) Map(java.util.Map)

Example 3 with IdentityHashMap

use of java.util.IdentityHashMap in project pcgen by PCGen.

the class PCGVer2Parser method parseEquipSetTempBonusLine.

/**
	 * ###############################################################
	 * EquipSet Temp Bonuses
	 * ###############################################################
	 * @param line
	 **/
private void parseEquipSetTempBonusLine(final String line) {
    PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
        "Warnings.PCGenParser.IllegalEquipSetTempBonus", line, pcgpex.getMessage());
        warnings.add(msg);
        return;
    }
    String tag;
    String tagString = null;
    for (PCGElement element : tokens.getElements()) {
        tag = element.getName();
        if (IOConstants.TAG_EQSETBONUS.equals(tag)) {
            tagString = EntityEncoder.decode(element.getText());
        }
    }
    if (tagString == null) {
        final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
        "Warnings.PCGenParser.InvalidEquipSetTempBonus", line);
        warnings.add(msg);
        return;
    }
    final EquipSet eSet = thePC.getEquipSetByIdPath(tagString);
    if (eSet == null) {
        return;
    }
    //# EquipSet Temp Bonuses
    //EQSETBONUS:0.2|TEMPBONUS:NAME=Haste|TBTARGET:PC|TEMPBONUS:SPELL=Shield of Faith|TBTARGET:PC
    final Map<BonusObj, BonusManager.TempBonusInfo> aList = new IdentityHashMap<>();
    for (final PCGElement element : tokens.getElements()) {
        tag = element.getName();
        if (IOConstants.TAG_TEMPBONUSBONUS.equals(tag)) {
            final String aString = EntityEncoder.decode(element.getText());
            // Parse aString looking for
            // TEMPBONUS and TBTARGET pairs
            StringTokenizer aTok = new StringTokenizer(aString, IOConstants.TAG_SEPARATOR);
            if (aTok.countTokens() < 2) {
                continue;
            }
            String sName = aTok.nextToken();
            String tName = aTok.nextToken();
            aList.putAll(getBonusFromName(sName, tName));
        }
    }
    eSet.setTempBonusList(aList);
}
Also used : TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) StringTokenizer(java.util.StringTokenizer) BonusObj(pcgen.core.bonus.BonusObj) EquipSet(pcgen.core.character.EquipSet) IdentityHashMap(java.util.IdentityHashMap)

Example 4 with IdentityHashMap

use of java.util.IdentityHashMap in project pcgen by PCGen.

the class BonusManager method getAllActiveBonuses.

private Map<BonusObj, Object> getAllActiveBonuses() {
    Map<BonusObj, Object> ret = new IdentityHashMap<>();
    for (final BonusContainer pobj : pc.getBonusContainerList()) {
        // the equipment they belong to.
        if (pobj != null && !(pobj instanceof EquipmentModifier)) {
            boolean use = true;
            if (pobj instanceof PCClass) {
                // Class bonuses are only included if the level is greater
                // than 0
                // This is because 0 levels of a class can be added to
                // access spell casting etc
                use = pc.getLevel(((PCClass) pobj)) > 0;
            }
            if (use) {
                pobj.activateBonuses(pc);
                List<BonusObj> abs = pobj.getActiveBonuses(pc);
                for (BonusObj bo : abs) {
                    ret.put(bo, pobj);
                }
            }
        }
    }
    if (pc.getUseTempMods()) {
        ret.putAll(getTempBonuses());
    }
    return ret;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) IdentityHashMap(java.util.IdentityHashMap) CDOMObject(pcgen.cdom.base.CDOMObject) MissingObject(pcgen.core.bonus.util.MissingObject) BonusContainer(pcgen.cdom.base.BonusContainer)

Example 5 with IdentityHashMap

use of java.util.IdentityHashMap in project pcgen by PCGen.

the class DamageReductionFacetTest method testGetDRString.

/**
	 * Test the retrieval of the DR String
	 */
public void testGetDRString() {
    DamageReductionFacet drFacet = new DamageReductionFacet();
    drFacet.setPrerequisiteFacet(new PrerequisiteFacet());
    drFacet.setFormulaResolvingFacet(new FormulaResolvingFacet());
    drFacet.setBonusCheckingFacet(new BonusCheckingFacet() {

        @Override
        public double getBonus(CharID id, String bonusType, String bonusName) {
            return 0.0d;
        }
    });
    Map<DamageReduction, Set<Object>> drList = new IdentityHashMap<>();
    String listResult = drFacet.getDRString(id, drList);
    assertEquals("", listResult);
    Set<Object> sourceSet = new HashSet<>();
    sourceSet.add(new Object());
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("10/magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("10/good and magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("10/good and magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(5), "good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("10/good and magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("10/good and magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(5), "good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("10/good and magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(15), "Good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(5), "good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic and good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(5), "evil"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic or good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic or good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(5), "good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic and good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(5), "magic and good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic or good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(5), "magic and good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic or good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(15), "magic"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/good and magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic or good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/good and magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(15), "magic and good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/good and magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic or lawful"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/good and magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(15), "magic and good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/good and magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic and good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/good and magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic and lawful"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/good and magic; 10/lawful; 5/evil"));
    Map<DamageReduction, Set<Object>> drList1 = new IdentityHashMap<>();
    drList1.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "epic"), sourceSet);
    drList1.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "lawful or good"), sourceSet);
    listResult = drFacet.getDRString(id, drList1);
    assertTrue(listResult.equalsIgnoreCase("10/epic; 10/lawful or good"));
    drList1.clear();
    drList1.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "epic and good or epic and lawful"), sourceSet);
    listResult = drFacet.getDRString(id, drList1);
    assertTrue(listResult.equalsIgnoreCase("10/epic and good or epic and lawful"));
// TODO Better consolidation: Can't handle this case at the moment.
// drList1.add(new DamageReduction(FormulaFactory.getFormulaFor(10),
// "lawful"));
// listResult = drFacet.getDRString(null, drList1);
// System.out.println("DR List: " + drList1.toString() + " = " +
// listResult);
// assertTrue(listResult.equalsIgnoreCase("10/epic and lawful");
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IdentityHashMap(java.util.IdentityHashMap) CharID(pcgen.cdom.enumeration.CharID) DamageReduction(pcgen.cdom.content.DamageReduction) CDOMObject(pcgen.cdom.base.CDOMObject) HashSet(java.util.HashSet)

Aggregations

IdentityHashMap (java.util.IdentityHashMap)274 Map (java.util.Map)82 HashMap (java.util.HashMap)76 ArrayList (java.util.ArrayList)58 HashSet (java.util.HashSet)40 Set (java.util.Set)39 List (java.util.List)32 TreeMap (java.util.TreeMap)30 Collection (java.util.Collection)29 Iterator (java.util.Iterator)29 LinkedHashMap (java.util.LinkedHashMap)26 AbstractMap (java.util.AbstractMap)21 TreeSet (java.util.TreeSet)19 Test (org.junit.Test)17 IOException (java.io.IOException)15 WeakHashMap (java.util.WeakHashMap)13 LinkedList (java.util.LinkedList)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 DependencyNode (org.sonatype.aether.graph.DependencyNode)10 Collections (java.util.Collections)9