Search in sources :

Example 41 with IdentityHashMap

use of java.util.IdentityHashMap in project translationstudio8 by heartsome.

the class TermBaseSearchDialog method sortMap.

/**
	 * 对搜索结果按相似度进行排序
	 * @param mapItem
	 * @return ;
	 */
private LinkedHashMap<String, Object[]> sortMap(LinkedHashMap<MetaData, HashMap<String, IdentityHashMap<String, String>>> mapItem) {
    Iterator<Entry<MetaData, HashMap<String, IdentityHashMap<String, String>>>> it = mapItem.entrySet().iterator();
    LinkedHashMap<String, Object[]> mapData = new LinkedHashMap<String, Object[]>();
    while (it.hasNext()) {
        Entry<MetaData, HashMap<String, IdentityHashMap<String, String>>> entry = it.next();
        MetaData metaData = entry.getKey();
        HashMap<String, IdentityHashMap<String, String>> mapTerm = entry.getValue();
        Iterator<Entry<String, IdentityHashMap<String, String>>> iterator = mapTerm.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, IdentityHashMap<String, String>> e = (Map.Entry<String, IdentityHashMap<String, String>>) iterator.next();
            String strGroupIdString = e.getKey();
            IdentityHashMap<String, String> map = e.getValue();
            String key = metaData.getDatabaseName() + "_" + metaData.getServerName() + "_" + strGroupIdString;
            Object[] arrObj = new Object[] { metaData, map };
            mapData.put(key, arrObj);
        }
    }
    ArrayList<Entry<String, Object[]>> entryList = new ArrayList<Entry<String, Object[]>>(mapData.entrySet());
    Collections.sort(entryList, new Comparator<Map.Entry<String, Object[]>>() {

        @SuppressWarnings("unchecked")
        public int compare(Map.Entry<String, Object[]> arg0, Map.Entry<String, Object[]> arg1) {
            IdentityHashMap<String, String> map0 = (IdentityHashMap<String, String>) arg0.getValue()[1];
            IdentityHashMap<String, String> map1 = (IdentityHashMap<String, String>) arg1.getValue()[1];
            String strSimilarity0 = map0.get("similarity");
            String strSimilarity1 = map1.get("similarity");
            if (strSimilarity0 == null || strSimilarity1 == null) {
                if (strSimilarity0 != null) {
                    return -1;
                } else if (strSimilarity1 != null) {
                    return 1;
                } else {
                    return 0;
                }
            } else {
                int intData0 = Integer.parseInt(strSimilarity0);
                int intData1 = Integer.parseInt(strSimilarity1);
                if (intData0 > intData1) {
                    return -1;
                } else if (intData0 < intData1) {
                    return 1;
                } else {
                    return 0;
                }
            }
        }
    });
    mapData.clear();
    for (Entry<String, Object[]> entry : entryList) {
        String key = entry.getKey();
        Object[] obj = entry.getValue();
        mapData.put(key, obj);
    }
    return mapData;
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) MetaData(net.heartsome.cat.common.bean.MetaData) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 42 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 43 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 44 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 45 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)131 Map (java.util.Map)43 HashMap (java.util.HashMap)38 ArrayList (java.util.ArrayList)27 HashSet (java.util.HashSet)19 LinkedHashMap (java.util.LinkedHashMap)17 Collection (java.util.Collection)16 Set (java.util.Set)16 TreeMap (java.util.TreeMap)16 Iterator (java.util.Iterator)14 AbstractMap (java.util.AbstractMap)13 Test (org.junit.Test)11 DependencyNode (org.sonatype.aether.graph.DependencyNode)10 WeakHashMap (java.util.WeakHashMap)8 LinkedList (java.util.LinkedList)7 List (java.util.List)7 TreeSet (java.util.TreeSet)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 Tree (edu.stanford.nlp.trees.Tree)6 Entry (java.util.Map.Entry)5