List of usage examples for org.apache.commons.collections BidiMap put
Object put(Object key, Object value);
From source file:org.apache.qpid.disttest.controller.ParticipatingClients.java
private BidiMap mapConfiguredToRegisteredClientNames(List<String> configuredClientNamesForTest, ClientRegistry clientRegistry) { BidiMap configuredToRegisteredNameMap = new DualHashBidiMap(); TreeSet<String> registeredClients = new TreeSet<String>(clientRegistry.getClients()); for (String configuredClientName : configuredClientNamesForTest) { String allocatedClientName = registeredClients.pollFirst(); if (allocatedClientName == null) { throw new IllegalArgumentException("Too few clients in registry " + clientRegistry + " configured clients " + configuredClientNamesForTest); }/* ww w.j a va 2 s . com*/ configuredToRegisteredNameMap.put(configuredClientName, allocatedClientName); } return configuredToRegisteredNameMap; }
From source file:org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl.java
/** Activates this component, called by SCR before registering as a service */ protected void activate(ComponentContext componentContext) { this.componentContext = componentContext; Dictionary<?, ?> properties = componentContext.getProperties(); BidiMap virtuals = new TreeBidiMap(); String[] virtualList = (String[]) properties.get(PROP_VIRTUAL); for (int i = 0; virtualList != null && i < virtualList.length; i++) { String[] parts = Mapping.split(virtualList[i]); virtuals.put(parts[0], parts[2]); }/*from w w w. j a v a 2s . co m*/ virtualURLMap = virtuals; List<Mapping> maps = new ArrayList<Mapping>(); String[] mappingList = (String[]) properties.get(PROP_MAPPING); for (int i = 0; mappingList != null && i < mappingList.length; i++) { maps.add(new Mapping(mappingList[i])); } Mapping[] tmp = maps.toArray(new Mapping[maps.size()]); // check whether direct mappings are allowed Boolean directProp = (Boolean) properties.get(PROP_ALLOW_DIRECT); allowDirect = (directProp != null) ? directProp.booleanValue() : true; if (allowDirect) { Mapping[] tmp2 = new Mapping[tmp.length + 1]; tmp2[0] = Mapping.DIRECT; System.arraycopy(tmp, 0, tmp2, 1, tmp.length); mappings = tmp2; } else { mappings = tmp; } // from configuration if available searchPath = OsgiUtil.toStringArray(properties.get(PROP_PATH)); if (searchPath != null && searchPath.length > 0) { for (int i = 0; i < searchPath.length; i++) { // ensure leading slash if (!searchPath[i].startsWith("/")) { searchPath[i] = "/" + searchPath[i]; } // ensure trailing slash if (!searchPath[i].endsWith("/")) { searchPath[i] += "/"; } } } if (searchPath == null) { searchPath = new String[] { "/" }; } // namespace mangling mangleNamespacePrefixes = OsgiUtil.toBoolean(properties.get(PROP_MANGLE_NAMESPACES), false); // bind resource providers not bound yet for (ServiceReference reference : delayedResourceProviders) { bindResourceProvider(reference); } delayedResourceProviders.clear(); this.processDelayedJcrResourceTypeProviders(); // set up the map entries from configuration try { mapEntries = new MapEntries(this, getRepository()); plugin = new JcrResourceResolverWebConsolePlugin(componentContext.getBundleContext(), this); } catch (Exception e) { log.error("activate: Cannot access repository, failed setting up Mapping Support", e); } }
From source file:org.apache.sling.resourceresolver.impl.ResourceResolverFactoryActivator.java
/** * Activates this component (called by SCR before) *///from w ww.ja v a2 s . co m @Activate protected void activate(final ComponentContext componentContext) { this.componentContext = componentContext; final Dictionary<?, ?> properties = componentContext.getProperties(); final BidiMap virtuals = new TreeBidiMap(); final String[] virtualList = PropertiesUtil.toStringArray(properties.get(PROP_VIRTUAL)); for (int i = 0; virtualList != null && i < virtualList.length; i++) { final String[] parts = Mapping.split(virtualList[i]); virtuals.put(parts[0], parts[2]); } virtualURLMap = virtuals; final List<Mapping> maps = new ArrayList<Mapping>(); final String[] mappingList = (String[]) properties.get(PROP_MAPPING); for (int i = 0; mappingList != null && i < mappingList.length; i++) { maps.add(new Mapping(mappingList[i])); } final Mapping[] tmp = maps.toArray(new Mapping[maps.size()]); // check whether direct mappings are allowed final Boolean directProp = (Boolean) properties.get(PROP_ALLOW_DIRECT); allowDirect = (directProp != null) ? directProp.booleanValue() : true; if (allowDirect) { final Mapping[] tmp2 = new Mapping[tmp.length + 1]; tmp2[0] = Mapping.DIRECT; System.arraycopy(tmp, 0, tmp2, 1, tmp.length); mappings = tmp2; } else { mappings = tmp; } // from configuration if available searchPath = PropertiesUtil.toStringArray(properties.get(PROP_PATH)); if (searchPath != null && searchPath.length > 0) { for (int i = 0; i < searchPath.length; i++) { // ensure leading slash if (!searchPath[i].startsWith("/")) { searchPath[i] = "/" + searchPath[i]; } // ensure trailing slash if (!searchPath[i].endsWith("/")) { searchPath[i] += "/"; } } } if (searchPath == null) { searchPath = new String[] { "/" }; } // namespace mangling mangleNamespacePrefixes = PropertiesUtil.toBoolean(properties.get(PROP_MANGLE_NAMESPACES), false); // the root of the resolver mappings mapRoot = PropertiesUtil.toString(properties.get(PROP_MAP_LOCATION), MapEntries.DEFAULT_MAP_ROOT); defaultVanityPathRedirectStatus = PropertiesUtil.toInteger( properties.get(PROP_DEFAULT_VANITY_PATH_REDIRECT_STATUS), MapEntries.DEFAULT_DEFAULT_VANITY_PATH_REDIRECT_STATUS); this.enableVanityPath = PropertiesUtil.toBoolean(properties.get(PROP_ENABLE_VANITY_PATH), DEFAULT_ENABLE_VANITY_PATH); // vanity path white list this.vanityPathWhiteList = null; String[] vanityPathPrefixes = PropertiesUtil.toStringArray(properties.get(PROP_ALLOWED_VANITY_PATH_PREFIX)); if (vanityPathPrefixes != null) { final List<String> prefixList = new ArrayList<String>(); for (final String value : vanityPathPrefixes) { if (value.trim().length() > 0) { if (value.trim().endsWith("/")) { prefixList.add(value.trim()); } else { prefixList.add(value.trim() + "/"); } } } if (prefixList.size() > 0) { this.vanityPathWhiteList = prefixList.toArray(new String[prefixList.size()]); } } // vanity path black list this.vanityPathBlackList = null; vanityPathPrefixes = PropertiesUtil.toStringArray(properties.get(PROP_DENIED_VANITY_PATH_PREFIX)); if (vanityPathPrefixes != null) { final List<String> prefixList = new ArrayList<String>(); for (final String value : vanityPathPrefixes) { if (value.trim().length() > 0) { if (value.trim().endsWith("/")) { prefixList.add(value.trim()); } else { prefixList.add(value.trim() + "/"); } } } if (prefixList.size() > 0) { this.vanityPathBlackList = prefixList.toArray(new String[prefixList.size()]); } } this.enableOptimizeAliasResolution = PropertiesUtil.toBoolean( properties.get(PROP_ENABLE_OPTIMIZE_ALIAS_RESOLUTION), DEFAULT_ENABLE_OPTIMIZE_ALIAS_RESOLUTION); this.maxCachedVanityPathEntries = PropertiesUtil.toLong(properties.get(PROP_MAX_CACHED_VANITY_PATHS), DEFAULT_MAX_CACHED_VANITY_PATHS); this.maxCachedVanityPathEntriesStartup = PropertiesUtil.toBoolean( properties.get(PROP_MAX_CACHED_VANITY_PATHS_STARTUP), DEFAULT_MAX_CACHED_VANITY_PATHS_STARTUP); this.vanityBloomFilterMaxBytes = PropertiesUtil.toInteger( properties.get(PROP_VANITY_BLOOM_FILTER_MAX_BYTES), DEFAULT_VANITY_BLOOM_FILTER_MAX_BYTES); this.vanityPathPrecedence = PropertiesUtil.toBoolean(properties.get(PROP_VANITY_PATH_PRECEDENCE), DEFAULT_VANITY_PATH_PRECEDENCE); this.logResourceResolverClosing = PropertiesUtil.toBoolean( properties.get(PROP_LOG_RESOURCE_RESOLVER_CLOSING), DEFAULT_LOG_RESOURCE_RESOLVER_CLOSING); this.paranoidProviderHandling = PropertiesUtil.toBoolean(properties.get(PROP_PARANOID_PROVIDER_HANDLING), DEFAULT_PARANOID_PROVIDER_HANDLING); final BundleContext bc = componentContext.getBundleContext(); // check for required property final String[] requiredResourceProvidersLegacy = PropertiesUtil .toStringArray(properties.get(PROP_REQUIRED_PROVIDERS_LEGACY)); final String[] requiredResourceProviderNames = PropertiesUtil .toStringArray(properties.get(PROP_REQUIRED_PROVIDERS)); if (requiredResourceProvidersLegacy != null && requiredResourceProvidersLegacy.length > 0) { boolean hasRealValue = false; for (final String name : requiredResourceProvidersLegacy) { if (name != null && !name.trim().isEmpty()) { hasRealValue = true; break; } } if (hasRealValue) { logger.error("ResourceResolverFactory is using deprecated required providers configuration (" + PROP_REQUIRED_PROVIDERS_LEGACY + "). Please change to use the property " + PROP_REQUIRED_PROVIDERS + " for values: " + Arrays.toString(requiredResourceProvidersLegacy)); } } // for testing: if we run unit test, both trackers are set from the outside if (this.resourceProviderTracker == null) { this.resourceProviderTracker = new ResourceProviderTracker(); this.changeListenerWhiteboard = new ResourceChangeListenerWhiteboard(); this.preconds.activate(bc, requiredResourceProvidersLegacy, requiredResourceProviderNames, resourceProviderTracker); this.changeListenerWhiteboard.activate(this.componentContext.getBundleContext(), this.resourceProviderTracker, searchPath); this.resourceProviderTracker.activate(this.componentContext.getBundleContext(), this.eventAdmin, new ChangeListener() { @Override public void providerAdded() { if (factoryRegistration == null) { checkFactoryPreconditions(null, null); } } @Override public void providerRemoved(final String name, final String pid, final boolean stateful, final boolean isUsed) { if (factoryRegistration != null) { if (isUsed && (stateful || paranoidProviderHandling)) { unregisterFactory(); } checkFactoryPreconditions(name, pid); } } }); } else { this.preconds.activate(bc, requiredResourceProvidersLegacy, requiredResourceProviderNames, resourceProviderTracker); this.checkFactoryPreconditions(null, null); } }
From source file:org.kuali.kfs.sys.document.web.AccountingLineViewField.java
/** * parse the given lookup parameter string into a bidirectinal map * * @param lookupParameters the lookup parameter string * @param accountingLinePrefix the actual accounting line prefix * @return a bidirectinal map that holds all the given lookup parameters *///from w ww . ja v a 2s . co m private BidiMap buildBidirecionalMapFromParameters(String parameters, String accountingLinePrefix) { BidiMap parameterMap = new DualHashBidiMap(); // if we didnt get any incoming parameters, then just return an empty parameterMap if (StringUtils.isBlank(parameters)) { return parameterMap; } String[] parameterArray = StringUtils.split(parameters, KFSConstants.FIELD_CONVERSIONS_SEPERATOR); for (String parameter : parameterArray) { String[] entrySet = StringUtils.split(parameter, KFSConstants.FIELD_CONVERSION_PAIR_SEPERATOR); if (entrySet != null) { String parameterKey = escapeAccountingLineName(entrySet[0], accountingLinePrefix); String parameterValue = escapeAccountingLineName(entrySet[1], accountingLinePrefix); parameterMap.put(parameterKey, parameterValue); } } return parameterMap; }
From source file:org.kuali.ole.sys.document.web.AccountingLineViewField.java
/** * parse the given lookup parameter string into a bidirectinal map * //ww w . ja v a2s .c o m * @param lookupParameters the lookup parameter string * @param accountingLinePrefix the actual accounting line prefix * @return a bidirectinal map that holds all the given lookup parameters */ private BidiMap buildBidirecionalMapFromParameters(String parameters, String accountingLinePrefix) { BidiMap parameterMap = new DualHashBidiMap(); // if we didnt get any incoming parameters, then just return an empty parameterMap if (StringUtils.isBlank(parameters)) { return parameterMap; } String[] parameterArray = StringUtils.split(parameters, OLEConstants.FIELD_CONVERSIONS_SEPERATOR); for (String parameter : parameterArray) { String[] entrySet = StringUtils.split(parameter, OLEConstants.FIELD_CONVERSION_PAIR_SEPERATOR); if (entrySet != null) { String parameterKey = escapeAccountingLineName(entrySet[0], accountingLinePrefix); String parameterValue = escapeAccountingLineName(entrySet[1], accountingLinePrefix); parameterMap.put(parameterKey, parameterValue); } } return parameterMap; }
From source file:org.LexGrid.LexBIG.example.ScoreTerm.java
/** * Runs the score algorithm for a specific term. * //from w w w . j a va 2 s .com * @param term * The text to evaluate. * @param score * Lower cutoff (percentage); a value less than or equal to 0 * indicates no cutoff. * @throws Exception */ public void run(String term, float minScore) throws Exception { // Allow the user to pick the target coding scheme. // This could also be hardcoded to a specific coding scheme. CodingSchemeSummary css = Util.promptForCodeSystem(); if (css != null) { // Determine the set of individual words to compare against. SortedSet compareWords = toWords(term); // Create a bucket to store results. // Sort the results by score (highest score first) and code key. BidiMap scoredResult = new TreeBidiMap(); // Resolve and iterate through matches to score each. // For this example, we keep the highest score per coded concept. for (ResolvedConceptReferencesIterator matches = resolveConcepts(css, term); matches.hasNext();) { // Work in chunks of 100. ResolvedConceptReferenceList refs = matches.next(100); for (int i = 0; i < refs.getResolvedConceptReferenceCount(); i++) { ResolvedConceptReference ref = refs.getResolvedConceptReference(i); String code = ref.getConceptCode(); Entity node = ref.getEntity(); Presentation[] allTermsForConcept = node.getPresentation(); for (int j = 0; j < allTermsForConcept.length; j++) { Presentation p = allTermsForConcept[j]; String text = p.getValue().getContent(); float score = score(toWords(text), compareWords); if (score > minScore) { // Check for a previous match on this code for a // different presentation. // If already present save the item of most // relevance. if (scoredResult.containsKey(code)) { ScoredTerm scoredTerm = (ScoredTerm) scoredResult.get(code); if (scoredTerm.score > score) continue; } ScoredTerm scoredTerm = new ScoredTerm(); scoredTerm.term = text; scoredTerm.score = score; scoredResult.put(code, scoredTerm); } } } } // Print the results. printReport(scoredResult); } }
From source file:org.lockss.servlet.LockssServlet.java
/** Get the ID with which the object is associated in the session, * creating a new ID if the object doesn't already have one. */ protected String getSessionObjectId(Object obj) { HttpSession session = getSession();//from w w w . ja v a 2 s .co m BidiMap map; synchronized (session) { map = (BidiMap) session.getAttribute(SESSION_KEY_OBJ_MAP); if (map == null) { map = new DualHashBidiMap(); session.setAttribute(SESSION_KEY_OBJ_MAP, map); } } synchronized (map) { String id = (String) map.get(obj); if (id == null) { id = getNewSessionObjectId(); map.put(obj, id); } return id; } }
From source file:relationalFramework.agentObservations.NonRedundantBackgroundKnowledge.java
/** * Converts a {@link RelationalPredicate} condition to a constant-form * variable string. Also assigns mappings between {@link RelationalArgument} * s and string IDs.//w ww . jav a 2 s .co m * * @param cond * The predicate being converted. * @param variableMap * the map to fill with mappings for changing it back. * @return An equivalent String of cond. */ public String toConstantFormFull(RelationalPredicate cond, BidiMap variableMap) { if (variableMap.containsKey(cond)) return (String) variableMap.get(cond); StringBuffer condStr = new StringBuffer("("); if (cond.isNegated()) condStr.append(NEG_PREFIX); condStr.append(cond.getFactName()); for (RelationalArgument arg : cond.getRelationalArguments()) { if (variableMap.containsKey(arg)) condStr.append(" " + variableMap.get(arg)); else if (arg.isFreeVariable()) condStr.append(" " + FREE_SYMBOL); else { String id = ID_PREFIX + variableMap.size(); variableMap.put(arg, id); condStr.append(" " + id); } } condStr.append(")"); String result = condStr.toString(); return result; }
From source file:test.LocalCrossEntropyDistributionTest.java
@Test public void testCoverState() throws Exception { Rete state = StateSpec.getInstance().getRete(); state.eval("(assert (clear a))"); state.eval("(assert (clear b))"); state.eval("(assert (clear c))"); state.eval("(assert (clear d))"); state.eval("(assert (clear e))"); state.eval("(assert (clear f))"); state.eval("(assert (highest a))"); state.eval("(assert (highest b))"); state.eval("(assert (highest c))"); state.eval("(assert (highest d))"); state.eval("(assert (highest e))"); state.eval("(assert (highest f))"); state.eval("(assert (onFloor a))"); state.eval("(assert (onFloor b))"); state.eval("(assert (onFloor c))"); state.eval("(assert (onFloor d))"); state.eval("(assert (onFloor e))"); state.eval("(assert (onFloor f))"); state.eval("(assert (block a))"); state.eval("(assert (block b))"); state.eval("(assert (block c))"); state.eval("(assert (block d))"); state.eval("(assert (block e))"); state.eval("(assert (block f))"); MultiMap<String, String[]> validActions = StateSpec.getInstance().generateValidActions(state); MultiMap<String, String[]> activatedActions = MultiMap .createSortedSetMultiMap(ArgumentComparator.getInstance()); BidiMap goalReplacements = new DualHashBidiMap(); goalReplacements.put("z", "?G_0"); goalReplacements.put("x", "?G_1"); List<RelationalRule> rlggRules = sut_.coverState(null, new RRLObservations(state, validActions, new double[] { 0, 0 }, goalReplacements, 0), activatedActions, null);/*from w w w. j av a2s . com*/ RelationalRule rlggRule = new RelationalRule("(above ?X ?) (height ?X ?#_0) (clear ?X) => (moveFloor ?X)"); List<RelationalArgument> queryParameters = new ArrayList<RelationalArgument>(); queryParameters.add(new RelationalArgument("?G_0")); queryParameters.add(new RelationalArgument("?G_1")); rlggRule.setQueryParams(queryParameters); assertTrue(rlggRules.contains(rlggRule)); rlggRule = new RelationalRule("(clear ?X) (clear ?Y) => (move ?X ?Y)"); rlggRule.setQueryParams(queryParameters); assertTrue(rlggRules.contains(rlggRule)); assertEquals(rlggRules.size(), 2); // [e] // [b][d] // [f][a][c] state.reset(); state.eval("(assert (clear d))"); state.eval("(assert (clear e))"); state.eval("(assert (clear c))"); state.eval("(assert (highest e))"); state.eval("(assert (on d a))"); state.eval("(assert (on e b))"); state.eval("(assert (on b f))"); state.eval("(assert (above e b))"); state.eval("(assert (above e f))"); state.eval("(assert (above b f))"); state.eval("(assert (above d a))"); state.eval("(assert (onFloor c))"); state.eval("(assert (onFloor a))"); state.eval("(assert (onFloor f))"); state.eval("(assert (block a))"); state.eval("(assert (block b))"); state.eval("(assert (block c))"); state.eval("(assert (block d))"); state.eval("(assert (block e))"); state.eval("(assert (block f))"); validActions = StateSpec.getInstance().generateValidActions(state); rlggRules = sut_.coverState(null, new RRLObservations(state, validActions, new double[] { 0, 0 }, goalReplacements, 0), activatedActions, null); assertTrue(rlggRules.isEmpty()); // Test the state of the slot generator Collection<Slot> slotGenerator = sut_.getPolicyGenerator().getGenerator(); for (Slot slot : slotGenerator) { if (slot.getAction().equals("move")) assertEquals(slot.size(), 25); else if (slot.getAction().equals("moveFloor")) assertEquals(slot.size(), 11); } }