List of usage examples for org.apache.commons.collections BidiMap put
Object put(Object key, Object value);
From source file:HashMapExampleV1.java
public static void main(String args[]) { BidiMap agentToCode = new DualHashBidiMap(); agentToCode.put("007", "Bond"); agentToCode.put("006", "Trevelyan"); agentToCode.put("002", "Fairbanks"); System.err.println("Agent name from code: " + agentToCode.get("007")); System.err.println("Code from Agent name: " + agentToCode.getKey("Bond")); }
From source file:BidiMapExample.java
public static void main(String args[]) { BidiMap agentToCode = new DualHashBidiMap(); agentToCode.put("007", "Bond"); agentToCode.put("006", "Joe"); agentToCode = UnmodifiableBidiMap.decorate(agentToCode); agentToCode.put("002", "Fairbanks"); // throws Exception agentToCode.remove("007"); // throws Exception agentToCode.removeValue("Bond"); // throws Exception }
From source file:gov.nih.nci.lmp.mimGpml.CommonHelper.java
/** * Initialize the interaction types. This is the mapping from the GPML to * MIM-Vis interactions; not the MIM-Vis to MIM-Bio mapping. * /*from w w w . ja v a 2 s . co m*/ * @return the mapping of GPML to MIMVis arrowheads */ public static BidiMap getGpmlToMimVisArrowHeadMap() { BidiMap arrowHash = new DualHashBidiMap(); arrowHash.put("mim-necessary-stimulation", "NecessaryStimulation"); arrowHash.put("mim-stimulation", "Stimulation"); arrowHash.put("mim-inhibition", "Inhibition"); arrowHash.put("mim-absolute-inhibition", "AbsoluteInhibition"); arrowHash.put("mim-catalysis", "Catalysis"); arrowHash.put("mim-cleavage", "CovalentBondCleavage"); arrowHash.put("mim-binding", "NonCovalentReversibleBinding"); arrowHash.put("mim-covalent-bond", "CovalentIrreversibleBinding"); arrowHash.put("mim-modification", "CovalentModification"); arrowHash.put("mim-production-wo-loss", "ProductionWithoutLoss"); arrowHash.put("mim-conversion", "StochiometricConversion"); arrowHash.put("mim-transcription-translation", "TemplateReaction"); arrowHash.put("Line", "Line"); arrowHash.put("mim-next-feature", "NextFeature"); arrowHash.put("mim-first-feature", "FirstFeature"); arrowHash.put("mim-branching-right", "BranchingRight"); arrowHash.put("mim-branching-left", "BranchingLeft"); arrowHash.put("mim-state-combination", "StateCombination"); //TODO: To be added in a future MIM specification //arrowHash.put("mim-gap", ArrowHeadEnumType.GAP); return arrowHash; }
From source file:com.salesmanager.core.util.StringUtil.java
public static Map parseTokenLine(String line, String delimiter) { BidiMap returnMap = new TreeBidiMap(); if (StringUtils.isBlank(line) || StringUtils.isBlank(delimiter)) { return returnMap; }/*from w w w . j a v a2 s . c o m*/ StringTokenizer st = new StringTokenizer(line, delimiter); int count = 0; while (st.hasMoreTokens()) { String value = st.nextToken(); returnMap.put(value, count); count++; } return returnMap; }
From source file:de.tudarmstadt.ukp.dkpro.tc.svmhmm.util.SVMHMMUtils.java
/** * Maps names to numbers (numbers are required by SVMLight format) * * @param names names (e.g., features, outcomes) * @return bidirectional map of name:number *//* w w w .j a v a2 s . c o m*/ public static BidiMap mapVocabularyToIntegers(SortedSet<String> names) { BidiMap result = new DualTreeBidiMap(); // start numbering from 1 int index = 1; for (String featureName : names) { result.put(featureName, index); index++; } return result; }
From source file:com.urbancode.x2o.xml.NamespaceConfiguration.java
public void loadNameSpaceFromClassPath(String nameSpace) { BidiMap biMap = new DualHashBidiMap(); String filePath = nameSpace.replaceAll("\\.", Matcher.quoteReplacement("/")); String resourceName = filePath + "/" + NAMESPACE_FILE; ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Properties props = new Properties(); log.debug("Looking for resource: " + resourceName); try {//w w w .j av a 2s . c om props.load(classLoader.getResourceAsStream(resourceName)); } catch (IOException e) { log.error(e.getClass() + " caught in " + this.getClass()); // swallow } // build the biDirectionalMap for (Object prop : props.keySet()) { biMap.put(prop, props.getProperty((String) prop)); } log.debug("added following elements into map: " + biMap.keySet()); log.debug("Added following value: " + biMap.values()); nameSpaces.put(nameSpace, biMap); }
From source file:cerrla.modular.ModularPolicy.java
/** * Transforms the given goal replacements into potentially different (but * always smaller/equal size) replacements based on how this policy is * defined./*from w w w . j a v a 2 s . c om*/ * * @param originalGoalReplacements * The original goal replacements to modify. * @return The transformed replacements. Always smaller/equal size and using * the same args. */ private BidiMap transformGoalReplacements(BidiMap originalGoalReplacements) { // Modify the goal replacements based on the moduleParamReplacements BidiMap goalReplacements = originalGoalReplacements; if (moduleParamReplacements_ != null && !moduleParamReplacements_.isEmpty()) { // Swap any terms shown in the replacements BidiMap modGoalReplacements = new DualHashBidiMap(); for (RelationalArgument ruleParam : moduleParamReplacements_.keySet()) { RelationalArgument goalParam = moduleParamReplacements_.get(ruleParam); modGoalReplacements.put(goalReplacements.getKey(goalParam), ruleParam); } goalReplacements = modGoalReplacements; } return goalReplacements; }
From source file:com.runwaysdk.mobile.IdConversionTest.java
public void testConvertGlobalAndLocalIds() { mobileIdToSessionId = new DualHashBidiMap(); // Maps a session to a bi-directional hash map BidiMap<globalId, localId> final HashMap<String, BidiMap> idMap = new HashMap<String, BidiMap>(); // Log all our threads in, and map the session ids to our mobile ids. // Do it twice so that we can ensure we can update an existing sessionId mapping with no problem. for (int i = 0; i < 2; ++i) { lock = new CountDownLatch(mobileIds.length); for (final String mobileId : mobileIds) { Thread t = new Thread() { public void run() { idConverter = IdConverter.getInstance(); ClientSession clientSession = ClientSession.createUserSession("default", customUsernameAndPassword, customUsernameAndPassword, new Locale[] { CommonProperties.getDefaultLocale() }); mobileIdToSessionId.put(mobileId, clientSession.getSessionId()); idConverter.mapSessionIdToMobileId(clientSession.getSessionId(), mobileId); onThreadStart(mobileId); onThreadEnd();// ww w . j av a2 s .com clientSession.logout(); } }; t.setDaemon(true); t.start(); } waitOnThreads(); } System.out.println("Session ids mapped to mobile ids."); // Generate a bunch of local ids lock = new CountDownLatch(mobileIds.length); for (final String mobileId : mobileIds) { Thread t = new Thread() { public void run() { onThreadStart(mobileId); BidiMap globalIdToLocalIdMap = new DualHashBidiMap(); idMap.put(mobileId, globalIdToLocalIdMap); for (String globalId : globalIds) { String localId = idConverter.generateLocalIdFromGlobalId(mobileId, globalId); globalIdToLocalIdMap.put(globalId, localId); //System.out.println(mobileId + "\n" + globalId + "\n" + localId + "\n\n"); } onThreadEnd(); } }; t.setDaemon(true); t.start(); } waitOnThreads(); System.out.println("localIds generated and mapped to globalIds"); // Assert that we can get the globalId back from the localId lock = new CountDownLatch(mobileIds.length); for (final String mobileId : mobileIds) { Thread t = new Thread() { @SuppressWarnings("unchecked") public void run() { onThreadStart(mobileId); BidiMap globalIdToLocalIdMap = idMap.get(mobileId); Collection<String> localIds = globalIdToLocalIdMap.values(); for (String localId : localIds) { String globalId = idConverter.getGlobalIdFromLocalId(mobileId, localId); assertEquals((String) globalIdToLocalIdMap.getKey(localId), globalId); } onThreadEnd(); } }; t.setDaemon(true); t.start(); } waitOnThreads(); System.out.println("globalIds retrieved from localIds."); // Generate local ids from the same mobile ids again and make sure we got the same local ids lock = new CountDownLatch(mobileIds.length); for (final String mobileId : mobileIds) { Thread t = new Thread() { public void run() { onThreadStart(mobileId); BidiMap globalIdToLocalIdMap = idMap.get(mobileId); for (String globalId : globalIds) { String localId = idConverter.generateLocalIdFromGlobalId(mobileId, globalId); assertEquals(localId, (String) globalIdToLocalIdMap.get(globalId)); } onThreadEnd(); } }; t.setDaemon(true); t.start(); } waitOnThreads(); System.out.println("Generated local ids from the same mobile ids."); // Delete all the global ids idConverter = IdConverter.getInstance(); lock = new CountDownLatch(globalIds.length); for (final String globalId : globalIds) { Thread t = new Thread() { public void run() { waitRandomAmount(); //System.out.println("Invalidating globalId " + globalId); idConverter.invalidateGlobalId(globalId); onThreadEnd(); } }; t.setDaemon(true); t.start(); } waitOnThreads(); System.out.println("Deleted all global ids."); // Try to retrieve them and assert that they're null. lock = new CountDownLatch(mobileIds.length); for (final String mobileId : mobileIds) { Thread t = new Thread() { public void run() { onThreadStart(mobileId); BidiMap globalIdToLocalIdMap = idMap.get(mobileId); for (String globalId : globalIds) { try { String retval = idConverter.getGlobalIdFromLocalId(mobileId, (String) globalIdToLocalIdMap.get(globalId)); fail("The globalId is still mapped. globalId = " + retval); } catch (IdConversionException e) { } } onThreadEnd(); } }; t.setDaemon(true); t.start(); } waitOnThreads(); System.out.println("Tried to retrieve previously deleted global ids."); // Generate more localIds, just to flex the stacks lock = new CountDownLatch(mobileIds.length); for (final String mobileId : mobileIds) { Thread t = new Thread() { public void run() { onThreadStart(mobileId); BidiMap globalIdToLocalIdMap = new DualHashBidiMap(); idMap.put(mobileId, globalIdToLocalIdMap); for (String globalId : globalIds) { String localId = idConverter.generateLocalIdFromGlobalId(mobileId, globalId); globalIdToLocalIdMap.put(globalId, localId); } onThreadEnd(); } }; t.setDaemon(true); t.start(); } waitOnThreads(); System.out.println("Generated more localIds, to flex the stacks."); // Assert that we can get the globalId back from the localId lock = new CountDownLatch(mobileIds.length); for (final String mobileId : mobileIds) { Thread t = new Thread() { @SuppressWarnings("unchecked") public void run() { onThreadStart(mobileId); BidiMap globalIdToLocalIdMap = idMap.get(mobileId); Collection<String> localIds = globalIdToLocalIdMap.values(); for (String localId : localIds) { String globalId = idConverter.getGlobalIdFromLocalId(mobileId, localId); assertEquals((String) globalIdToLocalIdMap.getKey(localId), globalId); } onThreadEnd(); } }; t.setDaemon(true); t.start(); } waitOnThreads(); System.out.println("globalids retrieved from localids."); // Delete all the global ids idConverter = IdConverter.getInstance(); lock = new CountDownLatch(globalIds.length); for (final String globalId : globalIds) { Thread t = new Thread() { public void run() { waitRandomAmount(); //System.out.println("Invalidating globalId " + globalId); idConverter.invalidateGlobalId(globalId); onThreadEnd(); } }; t.setDaemon(true); t.start(); } waitOnThreads(); System.out.println("Deleted all global id, test complete."); }
From source file:br.ufal.cideei.soot.instrument.FeatureModelInstrumentorTransformer.java
@Override protected void internalTransform(Body body, String phase, Map options) { preTransform(body);//from w ww .j a v a 2 s. c o m // #ifdef METRICS long startTransform = System.nanoTime(); // #endif /* * Iterate over all units, look up for their colors and add a new FeatureTag to each of them, and also compute * all the colors found in the whole body. Units with no colors receive an empty FeatureTag. */ Iterator<Unit> unitIt = body.getUnits().iterator(); /* * After the following loop, allPresentFeatures will hold all the colors found in the body. Used to calculate a * "local" power set. */ Set<String> allPresentFeatures = new HashSet<String>(); /* * The set of features are represented as bits, for a more compact representation. The mapping between a feature * and it's ID is stored in the FeatureTag of the body. * * This is necessary so that clients, such as r.d. analysis, can safely iterate over all configurations without * explicitly invoking Set operations like containsAll(); * * TODO: check redundancy between allPresentFeatures & allPresentFeaturesId */ // String->Integer BidiMap allPresentFeaturesId = new DualHashBidiMap(); FeatureTag emptyFeatureTag; // #ifdef LAZY BitVectorFeatureRep emptyBitVectorRep = new BitVectorFeatureRep(Collections.EMPTY_SET, allPresentFeaturesId); emptyFeatureTag = new FeatureTag(emptyBitVectorRep); // #else //@ emptyFeatureTag = new FeatureTag(new BitFeatureRep(Collections.EMPTY_SET, allPresentFeaturesId)); //@ // #endif // #ifdef LAZY /* * in the lazy approach, the representation can only be consolidate after all features have been discovery. All * IFeatureRep will stored so that it is possible to consolidate later. */ List<BitVectorFeatureRep> generateVectorLater = new ArrayList<BitVectorFeatureRep>(); // #endif int idGen = 1; while (unitIt.hasNext()) { Unit nextUnit = unitIt.next(); SourceLnPosTag lineTag = (SourceLnPosTag) nextUnit.getTag("SourceLnPosTag"); if (lineTag == null) { nextUnit.addTag(emptyFeatureTag); } else { int unitLine = lineTag.startLn(); Set<String> nextUnitColors = currentColorMap.get(unitLine); if (nextUnitColors != null) { for (String color : nextUnitColors) { if (!allPresentFeaturesId.containsKey(color)) { allPresentFeaturesId.put(color, idGen); idGen = idGen << 1; } } /* * increment local powerset with new found colors. */ allPresentFeatures.addAll(nextUnitColors); IFeatureRep featRep; FeatureTag featureTag; // #ifdef LAZY featRep = new BitVectorFeatureRep(nextUnitColors, allPresentFeaturesId); generateVectorLater.add((BitVectorFeatureRep) featRep); featureTag = new FeatureTag(featRep); nextUnit.addTag(featureTag); // #else //@ //@ featRep = new BitFeatureRep(nextUnitColors, allPresentFeaturesId); //@ // #endif featureTag = new FeatureTag(featRep); nextUnit.addTag(featureTag); } else { nextUnit.addTag(emptyFeatureTag); } } } UnmodifiableBidiMap unmodAllPresentFeaturesId = (UnmodifiableBidiMap) UnmodifiableBidiMap .decorate(allPresentFeaturesId); // #ifdef LAZY /* * generate vectors */ for (BitVectorFeatureRep featureRep : generateVectorLater) { featureRep.generateBitVector(idGen); } // #endif // #ifdef METRICS long transformationDelta = System.nanoTime() - startTransform; if (sink != null) { sink.flow(body, FeatureModelInstrumentorTransformer.INSTRUMENTATION, transformationDelta); } FeatureModelInstrumentorTransformer.transformationTime += transformationDelta; // #endif ConfigTag configTag; // #ifdef LAZY BitVectorConfigRep localConfigurations = BitVectorConfigRep.localConfigurations(idGen, unmodAllPresentFeaturesId // #ifdef FEATUREMODEL //@ , checker // #endif ); emptyBitVectorRep.generateBitVector(idGen); Set<IConfigRep> lazyConfig = new HashSet<IConfigRep>(); lazyConfig.add(localConfigurations); configTag = new ConfigTag(lazyConfig); body.addTag(configTag); // #else //@ //@ configTag = new ConfigTag(BitConfigRep.localConfigurations(idGen, unmodAllPresentFeaturesId // #ifdef FEATUREMODEL //@ , checker // #endif //@ ).getConfigs()); //@ body.addTag(configTag); //@ // #endif }
From source file:nmsu.cs.DocParser.java
public static BidiMap createOid2OIdx(Set<Integer> pubids) { //return createPubId2BugsId(pubids, 0); BidiMap pubid2bugsid = new DualHashBidiMap(); int idx = 0;//from w w w . j a v a2 s .c o m for (int id : pubids) { pubid2bugsid.put(id, idx); idx++; } return pubid2bugsid; }