List of usage examples for java.util TreeMap putAll
public void putAll(Map<? extends K, ? extends V> map)
From source file:org.codehaus.enunciate.modules.jersey.JerseyDeploymentModule.java
@Override protected void doBuild() throws EnunciateException, IOException { super.doBuild(); File webappDir = getBuildDir(); webappDir.mkdirs();//from w ww . ja v a2s . co m File webinf = new File(webappDir, "WEB-INF"); File webinfClasses = new File(webinf, "classes"); getEnunciate().copyFile(new File(getGenerateDir(), "jaxrs-providers.list"), new File(webinfClasses, "jaxrs-providers.list")); getEnunciate().copyFile(new File(getGenerateDir(), "jaxrs-root-resources.list"), new File(webinfClasses, "jaxrs-root-resources.list")); getEnunciate().copyFile(new File(getGenerateDir(), "jaxrs-jaxb-types.list"), new File(webinfClasses, "jaxrs-jaxb-types.list")); getEnunciate().copyFile(new File(getGenerateDir(), "media-type-mappings.properties"), new File(webinfClasses, "media-type-mappings.properties")); getEnunciate().copyFile(new File(getGenerateDir(), "ns2prefix.properties"), new File(webinfClasses, "ns2prefix.properties")); BaseWebAppFragment webappFragment = new BaseWebAppFragment(getName()); webappFragment.setBaseDir(webappDir); WebAppComponent servletComponent = new WebAppComponent(); servletComponent.setName("jersey"); servletComponent.setClassname(EnunciateJerseyServletContainer.class.getName()); TreeMap<String, String> initParams = new TreeMap<String, String>(); initParams.putAll(getServletInitParams()); if (!isUsePathBasedConneg()) { initParams.put(JerseyAdaptedHttpServletRequest.FEATURE_PATH_BASED_CONNEG, Boolean.FALSE.toString()); } if (isUseSubcontext()) { initParams.put(JerseyAdaptedHttpServletRequest.PROPERTY_SERVLET_PATH, getRestSubcontext()); } if (getResourceProviderFactory() != null) { initParams.put(JerseyAdaptedHttpServletRequest.PROPERTY_RESOURCE_PROVIDER_FACTORY, getResourceProviderFactory()); } if (getApplicationClass() != null) { initParams.put("javax.ws.rs.Application", getApplicationClass()); } if (getLoadOnStartup() != null) { servletComponent.setLoadOnStartup(getLoadOnStartup()); } servletComponent.setInitParams(initParams); TreeSet<String> urlMappings = new TreeSet<String>(); for (RootResource rootResource : getModel().getRootResources()) { for (ResourceMethod resourceMethod : rootResource.getResourceMethods(true)) { String resourceMethodPattern = resourceMethod.getServletPattern(); for (Set<String> subcontextList : ((Map<String, Set<String>>) resourceMethod.getMetaData() .get("subcontexts")).values()) { for (String subcontext : subcontextList) { String servletPattern; if ("".equals(subcontext)) { servletPattern = isUseWildcardServletMapping() ? "/*" : resourceMethodPattern; } else { servletPattern = isUseWildcardServletMapping() ? subcontext + "/*" : subcontext + resourceMethodPattern; } if (urlMappings.add(servletPattern)) { debug("Resource method %s of resource %s to be made accessible by servlet pattern %s.", resourceMethod.getSimpleName(), resourceMethod.getParent().getQualifiedName(), servletPattern); } } } } } if (urlMappings.contains("/*")) { urlMappings.clear(); urlMappings.add("/*"); } else { Iterator<String> iterator = urlMappings.iterator(); while (iterator.hasNext()) { String mapping = iterator.next(); if (!mapping.endsWith("/*") && urlMappings.contains(mapping + "/*")) { iterator.remove(); } } } servletComponent.setUrlMappings(urlMappings); webappFragment.setServlets(Arrays.asList(servletComponent)); getEnunciate().addWebAppFragment(webappFragment); }
From source file:org.omnaest.utils.structure.map.MapUtils.java
/** * Returns a {@link TreeMap} using the given {@link Comparator} and with the key and values of the given {@link Map} * /*from ww w .j ava 2s .c om*/ * @param map * @param comparator * @return new {@link TreeMap} */ public static <K, V> NavigableMap<K, V> sortedMap(Map<K, V> map, Comparator<K> comparator) { final TreeMap<K, V> treeMap = comparator != null ? new TreeMap<K, V>(comparator) : new TreeMap<K, V>(); if (map != null) { treeMap.putAll(map); } return treeMap; }
From source file:org.trnltk.apps.experiments.AmbiguityMatrixApp.java
private SortedMap<String, Integer> buildSortedTotalAmbiguityMap(final Map<String, Integer> totalAmbiguityMap) { final TreeMap<String, Integer> sortedTotalAmbiguityMap = new TreeMap<String, Integer>( new Comparator<String>() { @Override//from w w w .j a v a 2 s . c o m public int compare(String o1, String o2) { return Ordering.natural().reverse().compare(totalAmbiguityMap.get(o1), totalAmbiguityMap.get(o2)); } }); sortedTotalAmbiguityMap.putAll(totalAmbiguityMap); return sortedTotalAmbiguityMap; }
From source file:eu.edisonproject.training.wsd.BabelNet.java
private Set<Term> babelNetDisambiguation(String language, String lemma, Set<String> ngarms) { if (ngarms.isEmpty()) { return null; }/*from ww w.ja va 2s .com*/ if (ngarms.size() == 1 && ngarms.iterator().next().length() <= 1) { return null; } HashMap<CharSequence, Double> idsMap = new HashMap<>(); Map<CharSequence, Term> termMap = new HashMap<>(); Set<Term> terms = new HashSet<>(); int count = 0; int breaklimit = 1000; int oneElementlimit = 65; int difflimit = 60; Double persent; for (String n : ngarms) { if (n.length() <= 1) { continue; } count++; if (idsMap.size() == 1 && count > oneElementlimit) { // Double score = idsMap.values().iterator().next(); // if (score >= 10) { break; // } } if ((count % 2) == 0 && idsMap.size() >= 2 && count > difflimit) { ValueComparator bvc = new ValueComparator(idsMap); TreeMap<CharSequence, Double> sorted_map = new TreeMap(bvc); sorted_map.putAll(idsMap); Iterator<CharSequence> iter = sorted_map.keySet().iterator(); Double first = idsMap.get(iter.next()); Double second = idsMap.get(iter.next()); persent = first / (first + second); if (persent > 0.65) { break; } } if (count > breaklimit) { break; } String clearNg = n.replaceAll("_", " "); if (clearNg == null) { continue; } if (clearNg.startsWith(" ")) { clearNg = clearNg.replaceFirst(" ", ""); } if (clearNg.endsWith(" ")) { clearNg = clearNg.substring(0, clearNg.length() - 1); } Pair<Term, Double> termPair = null; try { termPair = babelNetDisambiguation(language, lemma, clearNg); } catch (Exception ex) { if (ex.getMessage() != null && ex.getMessage().contains("Your key is not valid")) { try { termPair = babelNetDisambiguation(language, lemma, clearNg); } catch (Exception ex1) { // LOGGER.log(Level.WARNING, ex1, null); } } else { LOGGER.log(Level.WARNING, null, ex); } } if (termPair != null) { termMap.put(termPair.first.getUid(), termPair.first); Double score; if (idsMap.containsKey(termPair.first.getUid())) { score = idsMap.get(termPair.first.getUid()); // score++; score += termPair.second; } else { // score = 1.0; score = termPair.second; } idsMap.put(termPair.first.getUid(), score); } } if (!idsMap.isEmpty()) { ValueComparator bvc = new ValueComparator(idsMap); TreeMap<CharSequence, Double> sorted_map = new TreeMap(bvc); sorted_map.putAll(idsMap); count = 0; Double firstScore = idsMap.get(sorted_map.firstKey()); terms.add(termMap.get(sorted_map.firstKey())); idsMap.remove(sorted_map.firstKey()); for (CharSequence tvID : sorted_map.keySet()) { if (count >= 1) { Double secondScore = idsMap.get(tvID); persent = secondScore / (firstScore + secondScore); if (persent > 0.2) { terms.add(termMap.get(tvID)); } if (count >= 2) { break; } } count++; } return terms; } return null; }
From source file:org.pentaho.platform.uifoundation.component.xml.PropertiesPanelUIComponent.java
protected Document showInputPage(final ISolutionFile file) { Document document = DocumentHelper.createDocument(); Element root = document.addElement(PropertiesPanelUIComponent.INPUT_PAGE_NODE_NAME) .addText(file.getFullPath()); // Add the info for the file we're working on root.addElement(PropertiesPanelUIComponent.FILE_PATH_NODE_NAME).addText(file.getFullPath()); root.addElement(PropertiesPanelUIComponent.DISPLAY_PATH_NODE_NAME) .addText(file.getFullPath()/*from w ww . j a v a 2s . c om*/ .replaceFirst(repository.getRepositoryName(), PropertiesPanelUIComponent.EMPTY_STRING) .replaceFirst("//", "/")); //$NON-NLS-1$//$NON-NLS-2$ root.addElement(PropertiesPanelUIComponent.IS_DIR_NODE_NAME) .addText(file.isDirectory() ? PropertiesPanelUIComponent.TRUE : PropertiesPanelUIComponent.FALSE); Element recipients = root.addElement(PropertiesPanelUIComponent.RECIPIENTS_NODE_NAME); Iterator iter = null; if (includeRoles) { // Add all the possible roles List rList = getAllRolesList(); if (rList != null) { iter = rList.iterator(); while (iter.hasNext()) { recipients.addElement(PropertiesPanelUIComponent.ROLE_NODE_NAME) .addText(iter.next().toString()); } } } if (includeUsers) { // Add all the possible users List uList = getAllUsersList(); if (uList != null) { iter = uList.iterator(); while (iter.hasNext()) { recipients.addElement(PropertiesPanelUIComponent.USER_NODE_NAME) .addText(iter.next().toString()); } } } // Add the names of all the permissions Map permissionsMap = PentahoAclEntry.getValidPermissionsNameMap(); // permissionsMap.remove(Messages.getString("PentahoAclEntry.USER_SUBSCRIBE")); //$NON-NLS-1$ Iterator keyIter = permissionsMap.keySet().iterator(); Element permNames = root.addElement(PropertiesPanelUIComponent.PERMISSION_NAMES_NODE_NAME); while (keyIter.hasNext()) { permNames.addElement(PropertiesPanelUIComponent.NAME_NODE_NAME).addText(keyIter.next().toString()); } Element acListNode = root.addElement(PropertiesPanelUIComponent.ACCESS_CONTROL_LIST_NODE_NAME); TreeMap<IPermissionRecipient, IPermissionMask> sortedMap = new TreeMap<IPermissionRecipient, IPermissionMask>( new Comparator<IPermissionRecipient>() { public int compare(IPermissionRecipient arg0, IPermissionRecipient arg1) { return arg0.getName().compareTo(arg1.getName()); } }); sortedMap.putAll(repository.getPermissions(file)); for (Map.Entry<IPermissionRecipient, IPermissionMask> mapEntry : sortedMap.entrySet()) { IPermissionRecipient permissionRecipient = mapEntry.getKey(); Element acNode = acListNode.addElement(PropertiesPanelUIComponent.ACCESS_CONTROL_NODE_NAME); Element recipientNode = acNode.addElement(PropertiesPanelUIComponent.RECIPIENT_NODE_NAME); recipientNode.setText(permissionRecipient.getName()); recipientNode.addAttribute(PropertiesPanelUIComponent.TYPE_PARAM, (permissionRecipient instanceof SimpleRole) ? PropertiesPanelUIComponent.ROLE_TYPE : PropertiesPanelUIComponent.USER_TYPE); // Add individual permissions for this group for (Iterator keyIterator = permissionsMap.keySet().iterator(); keyIterator.hasNext();) { Element aPermission = acNode.addElement(PropertiesPanelUIComponent.PERMISSION_NODE_NAME); String permName = keyIterator.next().toString(); aPermission.addElement(PropertiesPanelUIComponent.NAME_NODE_NAME).setText(permName); int permMask = ((Integer) permissionsMap.get(permName)).intValue(); // boolean isPermitted = repository.hasAccess(permissionRecipient, file, permMask); // broken on purpose boolean isPermitted = false; aPermission.addElement(PropertiesPanelUIComponent.PERMITTED_NODE_NAME) .addText(isPermitted ? PropertiesPanelUIComponent.TRUE : PropertiesPanelUIComponent.FALSE); } } return document; }
From source file:com.enonic.cms.core.content.ContentEntity.java
/** * Constructor that creates a new instance as a copy of the given content. *//*from w w w. j a v a 2 s. c om*/ public ContentEntity(ContentEntity source) { this(); this.key = source.getKey(); this.createdAt = source.getCreatedAt(); this.timestamp = source.getTimestamp(); this.deleted = source.getDeleted(); this.name = source.getName(); this.priority = source.getPriority(); this.availableFrom = source.getAvailableFrom(); this.availableTo = source.getAvailableTo(); this.owner = source.getOwner(); this.assignee = source.getAssignee(); this.assigner = source.getAssigner(); this.assignmentDueDate = source.getAssignmentDueDate(); this.assignmentDescription = source.getAssignmentDescription(); this.category = source.getCategory(); this.language = source.getLanguage(); this.source = source.getSource(); this.mainVersion = source.getMainVersion(); this.draftVersion = source.getDraftVersion(); this.contentHomes = source.getContentHomesAsMap() != null ? Maps.newTreeMap(source.getContentHomesAsMap()) : null; this.versions = source.getVersions() != null ? Lists.newArrayList(source.getVersions()) : null; this.relatedParents = source.getRelatedParentContentVersions() != null ? Sets.newHashSet(source.getRelatedParentContentVersions()) : null; this.sectionContents = source.getSectionContents() != null ? Sets.newHashSet(source.getSectionContents()) : null; this.directMenuItemPlacements = source.getDirectMenuItemPlacements() != null ? new TreeSet<MenuItemEntity>(source.getDirectMenuItemPlacements()) : null; if (source.getContentAccessRights() != null) { TreeMap<GroupKey, ContentAccessEntity> contentAccessRightsCopy = Maps .newTreeMap(new GroupKeyComparator()); contentAccessRightsCopy.putAll(source.contentAccessRights); this.contentAccessRights = contentAccessRightsCopy; } }
From source file:com.erudika.para.i18n.LanguageUtils.java
/** * Returns a map of all translations for a given language. * Defaults to the default language which must be set. * @param appid appid name of the {@link com.erudika.para.core.App} * @param langCode the 2-letter language code * @return the language map// ww w . j av a 2 s . c o m */ public Map<String, String> readLanguage(String appid, String langCode) { if (StringUtils.isBlank(langCode) || !allLocales.containsKey(langCode)) { return getDefaultLanguage(); } if (search == null || dao == null) { return getDefaultLanguage(); } Sysprop s = dao.read(appid, keyPrefix.concat(langCode)); TreeMap<String, String> lang = new TreeMap<String, String>(); if (s == null || s.getProperties().isEmpty()) { Map<String, Object> terms = new HashMap<String, Object>(); terms.put("locale", langCode); terms.put("approved", true); List<Translation> tlist = search.findTerms(appid, Utils.type(Translation.class), terms, true); Sysprop saved = new Sysprop(keyPrefix.concat(langCode)); lang.putAll(getDefaultLanguage()); // copy default langmap int approved = 0; for (Translation trans : tlist) { lang.put(trans.getThekey(), trans.getValue()); saved.addProperty(trans.getThekey(), trans.getValue()); approved++; } if (approved > 0) { updateTranslationProgressMap(appid, langCode, approved); } dao.create(appid, saved); } else { Map<String, Object> loaded = s.getProperties(); for (String key : loaded.keySet()) { lang.put(key, loaded.get(key).toString()); } } return lang; }
From source file:nl.uva.sne.disambiguators.BabelNet.java
private Set<Term> babelNetDisambiguation(String language, String lemma, Set<String> ngarms) { if (ngarms.isEmpty()) { return null; }/*ww w. jav a2 s . c om*/ if (ngarms.size() == 1 && ngarms.iterator().next().length() <= 1) { return null; } HashMap<String, Double> idsMap = new HashMap<>(); Map<String, Term> termMap = new HashMap<>(); Set<Term> terms = new HashSet<>(); int count = 0; int breaklimit = 1000; int oneElementlimit = 65; int difflimit = 60; Double persent; for (String n : ngarms) { if (n.length() <= 1) { continue; } count++; if (idsMap.size() == 1 && count > oneElementlimit) { // Double score = idsMap.values().iterator().next(); // if (score >= 10) { break; // } } if ((count % 2) == 0 && idsMap.size() >= 2 && count > difflimit) { ValueComparator bvc = new ValueComparator(idsMap); TreeMap<String, Double> sorted_map = new TreeMap(bvc); sorted_map.putAll(idsMap); Iterator<String> iter = sorted_map.keySet().iterator(); Double first = idsMap.get(iter.next()); Double second = idsMap.get(iter.next()); persent = first / (first + second); if (persent > 0.65) { break; } } if (count > breaklimit) { break; } String clearNg = n.replaceAll("_", " "); if (clearNg == null) { continue; } if (clearNg.startsWith(" ")) { clearNg = clearNg.replaceFirst(" ", ""); } if (clearNg.endsWith(" ")) { clearNg = clearNg.substring(0, clearNg.length() - 1); } Pair<Term, Double> termPair = null; try { termPair = babelNetDisambiguation(language, lemma, clearNg); } catch (Exception ex) { if (ex.getMessage() != null && ex.getMessage().contains("Your key is not valid")) { try { termPair = babelNetDisambiguation(language, lemma, clearNg); } catch (Exception ex1) { // Logger.getLogger(BabelNet.class.getName()).log(Level.WARNING, ex1, null); } } else { Logger.getLogger(SemanticUtils.class.getName()).log(Level.WARNING, null, ex); } } if (termPair != null) { termMap.put(termPair.first.getUID(), termPair.first); Double score; if (idsMap.containsKey(termPair.first.getUID())) { score = idsMap.get(termPair.first.getUID()); // score++; score += termPair.second; } else { // score = 1.0; score = termPair.second; } idsMap.put(termPair.first.getUID(), score); } } if (!idsMap.isEmpty()) { ValueComparator bvc = new ValueComparator(idsMap); TreeMap<String, Double> sorted_map = new TreeMap(bvc); sorted_map.putAll(idsMap); count = 0; Double firstScore = idsMap.get(sorted_map.firstKey()); terms.add(termMap.get(sorted_map.firstKey())); idsMap.remove(sorted_map.firstKey()); for (String tvID : sorted_map.keySet()) { if (count >= 1) { Double secondScore = idsMap.get(tvID); persent = secondScore / (firstScore + secondScore); if (persent > 0.2) { terms.add(termMap.get(tvID)); } if (count >= 2) { break; } } count++; } return terms; } return null; }
From source file:FastTreeMap.java
/** * Copy all of the mappings from the specified map to this one, replacing * any mappings with the same keys./*from ww w .java2s.c o m*/ * * @param in the map whose mappings are to be copied */ public void putAll(Map in) { if (fast) { synchronized (this) { TreeMap temp = (TreeMap) map.clone(); temp.putAll(in); map = temp; } } else { synchronized (map) { map.putAll(in); } } }
From source file:edu.utexas.cs.tactex.tariffoptimization.TariffOptimizerBinaryOneShot.java
private TreeMap<Double, TariffSpecification> binarySearchOptimize(List<TariffSpecification> suggestedSpecs, HashMap<TariffSpecification, HashMap<CustomerInfo, Integer>> tariffSubscriptions, List<TariffSpecification> competingTariffs, CostCurvesPredictor costCurvesPredictor, int currentTimeslot, Broker me, HashMap<CustomerInfo, HashMap<TariffSpecification, ShiftedEnergyData>> customer2ShiftedEnergy, HashMap<CustomerInfo, ArrayRealVector> customer2NonShiftedEnergy, HashMap<CustomerInfo, HashMap<TariffSpecification, Double>> customer2RelevantTariffCharges) { TreeMap<Double, TariffSpecification> result = new TreeMap<Double, TariffSpecification>(); // a value of null means no-op ArrayList<TariffSpecification> consideredTariffActions = new ArrayList<TariffSpecification>(); consideredTariffActions.add(null);//from w w w. j a v a2s .co m TreeMap<Double, TariffSpecification> sortedTariffs = utilityEstimator.estimateUtilities( consideredTariffActions, tariffSubscriptions, competingTariffs, customer2RelevantTariffCharges, customer2ShiftedEnergy, customer2NonShiftedEnergy, marketPredictionManager, costCurvesPredictor, currentTimeslot, me); result.putAll(sortedTariffs); // here do the binary search // // initialize with edges and middle TreeMap<Double, Integer> utilToIndex = new TreeMap<Double, Integer>(); int numTariffs = suggestedSpecs.size(); int[] initialIndexes = { 0, numTariffs / 2, numTariffs - 1 }; for (int index : initialIndexes) { evaluateAndRecord(index, utilToIndex, result, suggestedSpecs, consideredTariffActions, tariffSubscriptions, competingTariffs, costCurvesPredictor, currentTimeslot, me, customer2ShiftedEnergy, customer2NonShiftedEnergy, customer2RelevantTariffCharges); } int bestIndex = utilToIndex.lastEntry().getValue(); int secondBestIndex = utilToIndex.lowerEntry(utilToIndex.lastKey()).getValue(); // // binary search while (Math.abs(secondBestIndex - bestIndex) >= 2) { //log.info("evaluating, bestIndex=" + bestIndex + ", secondBestIndex=" + secondBestIndex); int midIndex = (secondBestIndex + bestIndex) / 2; evaluateAndRecord(midIndex, utilToIndex, result, suggestedSpecs, consideredTariffActions, tariffSubscriptions, competingTariffs, costCurvesPredictor, currentTimeslot, me, customer2ShiftedEnergy, customer2NonShiftedEnergy, customer2RelevantTariffCharges); bestIndex = utilToIndex.lastEntry().getValue(); secondBestIndex = utilToIndex.lowerEntry(utilToIndex.lastKey()).getValue(); // TODO: handling a non-convex case (how come happens?) if (midIndex != bestIndex && midIndex != secondBestIndex) { log.warn("non-convex utility values found during binary search. breaking..."); break; } } //log.info("evaluating, bestIndex=" + bestIndex + ", secondBestIndex=" + secondBestIndex); return result; }