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;
}
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;
}
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);
}
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);
}
}
}
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");
}
Aggregations