List of usage examples for java.util LinkedHashMap keySet
public Set<K> keySet()
From source file:eionet.cr.dao.virtuoso.VirtuosoEndpointHarvestQueryDAO.java
@Override public void move(String endpointUrl, Set<Integer> ids, int direction) throws DAOException { if (StringUtils.isBlank(endpointUrl) || ids == null || ids.isEmpty()) { return;/*from w w w .ja v a 2s .c om*/ } if (direction == 0) { throw new IllegalArgumentException("Direction must not be 0!"); } // Prepare map where we can get queries by position, also find the max and min positions. LinkedHashMap<Integer, EndpointHarvestQueryDTO> queriesByPos = getQueriesByPosition(endpointUrl); if (queriesByPos.isEmpty()) { return; } Set<Integer> positions = queriesByPos.keySet(); int maxPos = Collections.max(positions); int minPos = Collections.min(positions); Connection conn = null; try { conn = getSQLConnection(); conn.setAutoCommit(false); // If even one query is already at position 1 then moving up is not considered possible. // And conversely, if even one query is already at the last position, then moving down // is not considered possible either. boolean isMovingPossible = true; List<Integer> selectedPositions = new ArrayList<Integer>(); List<EndpointHarvestQueryDTO> queries = new ArrayList<EndpointHarvestQueryDTO>(queriesByPos.values()); for (EndpointHarvestQueryDTO query : queries) { if (ids.contains(query.getId())) { int pos = query.getPosition(); if ((direction < 0 && pos == minPos) || (direction > 0 && pos == maxPos)) { isMovingPossible = false; } else { selectedPositions.add(pos); } } } if (isMovingPossible) { if (direction < 0) { for (Integer selectedPosition : selectedPositions) { EndpointHarvestQueryDTO queryToMove = queriesByPos.get(selectedPosition); int i = queries.indexOf(queryToMove); queries.set(i, queries.get(i - 1)); queries.set(i - 1, queryToMove); } } else { for (int j = selectedPositions.size() - 1; j >= 0; j--) { EndpointHarvestQueryDTO queryToMove = queriesByPos.get(selectedPositions.get(j)); int i = queries.indexOf(queryToMove); queries.set(i, queries.get(i + 1)); queries.set(i + 1, queryToMove); } } } SQLUtil.executeUpdate(INCREASE_POSITIONS_SQL, Arrays.asList(maxPos, endpointUrl), conn); for (int i = 0; i < queries.size(); i++) { SQLUtil.executeUpdate(UPDATE_POSITION_SQL, Arrays.asList(i + 1, queries.get(i).getId()), conn); } conn.commit(); } catch (Exception e) { SQLUtil.rollback(conn); throw new DAOException(e.getMessage(), e); } finally { SQLUtil.close(conn); } }
From source file:com.itemanalysis.jmetrik.stats.itemanalysis.ItemAnalysisOutputFile.java
public File saveOutput(LinkedHashMap<VariableName, ClassicalItem> itemTreeMap, boolean allCategories, boolean addDIndex) throws IOException { this.outputfile = getUniqueFile(outputfile); int nItems = itemTreeMap.size(); int maxCategory = 0; ClassicalItem item = null;/* w w w .j a va 2s . co m*/ for (VariableName v : itemTreeMap.keySet()) { item = itemTreeMap.get(v); maxCategory = Math.max(maxCategory, item.numberOfCategories()); } int totalColumns = 4 + 3 * maxCategory; LinkedHashMap<VariableName, VariableAttributes> variableAttributeMap = new LinkedHashMap<VariableName, VariableAttributes>(); VariableAttributes nameAtt = new VariableAttributes(new VariableName("name"), new VariableLabel("Item Name"), DataType.STRING, 0); VariableAttributes difficultyAtt = new VariableAttributes(new VariableName("difficulty"), new VariableLabel("Item Difficulty"), DataType.DOUBLE, 1); VariableAttributes stdDevAtt = new VariableAttributes(new VariableName("stdev"), new VariableLabel("Item Standard Deviation"), DataType.DOUBLE, 2); VariableAttributes discrimAtt = new VariableAttributes(new VariableName("discrimination"), new VariableLabel("Item Discrimination"), DataType.DOUBLE, 3); variableAttributeMap.put(nameAtt.getName(), nameAtt); variableAttributeMap.put(difficultyAtt.getName(), difficultyAtt); variableAttributeMap.put(stdDevAtt.getName(), stdDevAtt); variableAttributeMap.put(discrimAtt.getName(), discrimAtt); VariableAttributes lower = null; VariableAttributes upper = null; VariableAttributes dIndex = null; if (addDIndex) { lower = new VariableAttributes(new VariableName("lower"), new VariableLabel("Difficulty for lower 27%"), DataType.DOUBLE, 4); upper = new VariableAttributes(new VariableName("upper"), new VariableLabel("Difficulty for upper 27%"), DataType.DOUBLE, 5); dIndex = new VariableAttributes(new VariableName("D_index"), new VariableLabel("Discrimination index"), DataType.DOUBLE, 6); variableAttributeMap.put(lower.getName(), lower); variableAttributeMap.put(upper.getName(), upper); variableAttributeMap.put(dIndex.getName(), dIndex); } VariableAttributes vPropAtt = null; VariableAttributes vSDAtt = null; VariableAttributes vCorAtt = null; int colNumber = 4; if (addDIndex) colNumber = 7; if (allCategories) { for (int k = 0; k < maxCategory; k++) { vPropAtt = new VariableAttributes(new VariableName("prop" + (k + 1)), new VariableLabel("Proportion endorsing option " + (k + 1)), DataType.DOUBLE, colNumber++); vSDAtt = new VariableAttributes(new VariableName("stdev" + (k + 1)), new VariableLabel("Std. Dev. for option " + (k + 1)), DataType.DOUBLE, colNumber++); vCorAtt = new VariableAttributes(new VariableName("cor" + (k + 1)), new VariableLabel("Distractor-total correlation for option " + (k + 1)), DataType.DOUBLE, colNumber++); variableAttributeMap.put(vPropAtt.getName(), vPropAtt); variableAttributeMap.put(vSDAtt.getName(), vSDAtt); variableAttributeMap.put(vCorAtt.getName(), vCorAtt); } } int n = 0; try (JmetrikFileWriter writer = new JmetrikFileWriter(outputfile, variableAttributeMap)) { writer.openConnection(); writer.writeHeader(nItems); int index = 0; double df = 0, sd = 0, ds = 0, dL = 0, dU = 0, D = 0; for (VariableName v : itemTreeMap.keySet()) { index = 0; item = itemTreeMap.get(v); writer.writeValue(nameAtt.getName(), item.getName().toString()); df = item.getDifficulty(); if (Double.isNaN(df)) { writer.writeValue(difficultyAtt.getName(), ""); } else { writer.writeValue(difficultyAtt.getName(), df); } index++; sd = item.getStdDev(); if (Double.isNaN(sd)) { writer.writeValue(stdDevAtt.getName(), ""); } else { writer.writeValue(stdDevAtt.getName(), sd); } index++; ds = item.getDiscrimination(); if (Double.isNaN(ds)) { writer.writeValue(discrimAtt.getName(), ""); } else { writer.writeValue(discrimAtt.getName(), ds); } index++; if (addDIndex) { dL = item.getDindexLower(); if (Double.isNaN(dL)) { writer.writeValue(lower.getName(), ""); } else { writer.writeValue(lower.getName(), dL); } index++; dU = item.getDindexUpper(); if (Double.isNaN(dU)) { writer.writeValue(upper.getName(), ""); } else { writer.writeValue(upper.getName(), dU); } index++; D = dU - dL; if (Double.isNaN(D)) { writer.writeValue(dIndex.getName(), ""); } else { writer.writeValue(dIndex.getName(), D); } index++; } if (allCategories) { Object temp; Iterator<Object> iter = item.categoryIterator(); int catIndex = 1; VariableName catProp = null; VariableName catStDev = null; VariableName catDisc = null; while (iter.hasNext()) { temp = iter.next(); catProp = new VariableName("prop" + catIndex); catStDev = new VariableName("stdev" + catIndex); catDisc = new VariableName("cor" + catIndex); vPropAtt = variableAttributeMap.get(catProp); vSDAtt = variableAttributeMap.get(catStDev); vCorAtt = variableAttributeMap.get(catDisc); //category difficulty df = item.getDifficultyAt(temp); if (Double.isNaN(df)) { writer.writeValue(vPropAtt.getName(), ""); } else { writer.writeValue(vPropAtt.getName(), df); } index++; //category sd sd = item.getStdDevAt(temp); if (Double.isNaN(sd)) { writer.writeValue(vSDAtt.getName(), ""); } else { writer.writeValue(vSDAtt.getName(), sd); } index++; //category discrimination ds = item.getDiscriminationAt(temp); if (Double.isNaN(ds)) { writer.writeValue(vCorAtt.getName(), ""); } else { writer.writeValue(vCorAtt.getName(), ds); } index++; catIndex++; } //end loop over categories //index should be equal to totalColumns // if not, add null values to remaining columns // while(index<totalColumns-1){ // writer.writeValue(index++, ""); // } } writer.updateRow(); } //end loop over items } return outputfile; }
From source file:marytts.modules.ModuleRegistry.java
/** * Lookup a list of modules for the given combination of type, locale and voice. * A given lookup will return a list of modules accepting the datatype as input, * ordered by specificity so that the most specific modules come first. * For each output type produced by modules, there will be only one module * producing that type, namely the most specific one found. * Specificity is ordered as follows:/*from ww w .j a va 2 s . c o m*/ * 1. most specific is the full combination of datatype, locale and voice; * 2. the combination of datatype, language-only locale and voice (i.e., for requested locale "en-US" will find modules with locale "en"); * 3. the combination of datatype and locale, ignoring voice; * 4. the combination of datatype and language-only locale, ignoring voice; * 5. least specific is the datatype, ignoring locale and voice. * @param type the type of input data * @param locale the locale * @param voice the voice to use. * @return a list of mary modules accepting the datatype and suitable for * the given locale and voice, ordered by their specificity, * or an empty list if there is no suitable module. * @throws IllegalStateException if called when registration is not yet complete. */ @SuppressWarnings("unchecked") private static List<MaryModule> get(MaryDataType type, Locale locale, Voice voice) throws IllegalStateException { if (!registrationComplete) throw new IllegalStateException("Cannot inquire about modules while registration is ongoing"); LinkedHashMap<MaryDataType, MaryModule> results = new LinkedHashMap<MaryDataType, MaryModule>(); // First, get all results: List<List<MaryModule>> listOfLists = new LinkedList<List<MaryModule>>(); listOfLists.add((List<MaryModule>) mkm.get(type, locale, voice)); Locale langOnly = locale != null ? new Locale(locale.getLanguage()) : null; boolean haveCountry = langOnly == null ? false : !langOnly.equals(locale); if (haveCountry) { listOfLists.add((List<MaryModule>) mkm.get(type, langOnly, voice)); } listOfLists.add((List<MaryModule>) mkm.get(type, locale, null)); if (haveCountry) { listOfLists.add((List<MaryModule>) mkm.get(type, langOnly, null)); } listOfLists.add((List<MaryModule>) mkm.get(type, null, null)); // Now, for each mary output type, keep only the most specific module, // and return the list ordered by the specificity of modules (most specific first): for (List<MaryModule> list : listOfLists) { if (list != null) { for (MaryModule m : list) { if (!results.containsKey(m.outputType())) results.put(m.outputType(), m); } } } List<MaryModule> returnList = new LinkedList<MaryModule>(); for (MaryDataType t : results.keySet()) { returnList.add(results.get(t)); } return returnList; }
From source file:org.splevo.jamopp.extraction.cache.ReferenceCache.java
/** * Resets the cache for the given resource and saves the cache afterwards to prevent old entries * from appearing after loading the resource again. * // ww w.j av a 2s. c o m * @param resource * The resource for which the cache shall be reset. */ public void reset(Resource resource) { if (!isCached(resource)) { return; } final String uriToRemovePrefix = resource.getURI().toString() + "#"; cacheData.getResourceToTargetURIListMap().remove(resource.getURI().toString()); for (LinkedHashMap<String, String> map : cacheData.getResourceToTargetURIListMap().values()) { List<String> toRemove = Lists.newArrayList(); for (Entry<String, String> entry : map.entrySet()) { if (entry.getValue().startsWith(uriToRemovePrefix)) { toRemove.add(entry.getKey()); } } map.keySet().removeAll(toRemove); } save(); }
From source file:net.chris54721.infinitycubed.workers.PackLoader.java
@Override public void run() { try {/*www. j av a 2s .c o m*/ LogHelper.info("Loading and updating modpacks"); String publicJson = Utils.toString(new URL(Reference.FILES_URL + "public.json")); Type stringIntMap = new TypeToken<LinkedHashMap<String, Integer>>() { }.getType(); LinkedHashMap<String, Integer> publicObjects = Reference.DEFAULT_GSON.fromJson(publicJson, stringIntMap); File localJson = new File(Resources.getFolder(Reference.PACKS_FOLDER), "public.json"); List<String> updatePacks = new ArrayList<String>(); if (localJson.isFile()) { String localPublicJson = Files.toString(localJson, Charsets.UTF_8); LinkedHashMap<String, Integer> localPublicObjects = Reference.DEFAULT_GSON.fromJson(localPublicJson, stringIntMap); for (String pack : publicObjects.keySet()) { if (!localPublicObjects.containsKey(pack) || !localPublicObjects.get(pack).equals(publicObjects.get(pack))) { updatePacks.add(pack); } } } else updatePacks.addAll(publicObjects.keySet()); Files.write(publicJson, localJson, Charsets.UTF_8); if (updatePacks.size() > 0) { for (String pack : updatePacks) { LogHelper.info("Updating JSON file for modpack " + pack); URL packJsonURL = Resources.getUrl(Resources.ResourceType.PACK_JSON, pack + ".json"); File packJsonFile = Resources.getFile(Resources.ResourceType.PACK_JSON, pack + ".json"); if (packJsonFile.isFile()) packJsonFile.delete(); Downloadable packJsonDownloadable = new Downloadable(packJsonURL, packJsonFile); if (!packJsonDownloadable.download()) LogHelper.error("Failed updating JSON for modpack " + pack); } } Collection<File> packJsons = FileUtils.listFiles(Resources.getFolder(Reference.DATA_FOLDER), new String[] { "json" }, false); for (File packJsonFile : packJsons) loadPack(FilenameUtils.getBaseName(packJsonFile.getName())); } catch (Exception e) { LogHelper.fatal("Failed updating and loading public packs", e); } }
From source file:org.kuali.kfs.module.cam.businessobject.AssetPaymentDetail.java
/** * Create a key including the/*from w w w . j a va 2s. c o m*/ * <li><b>expenditureFinancialDocumentNumber</b></li> * <li><b>expenditureFinancialDocumentTypeCode</b></li> * with accounting information for asset payment distribution * * Make sure the full accounting line information is part of the key * chartOfAccount, accountNumber, subAccountNumber, objectCode, subObjectCode, projectCode * * @return */ public String getAssetPaymentDetailKey() { LinkedHashMap<String, String> paymentMap = assetPaymentToStringMapper(); paymentMap.put("expenditureFinancialDocumentTypeCode", this.getExpenditureFinancialDocumentTypeCode()); paymentMap.put("expenditureFinancialDocumentNumber", this.getExpenditureFinancialDocumentNumber()); //use SHORT_PREFIX_STYLE so that memory address is not part of the toString output ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); for (String key : paymentMap.keySet()) { builder.append(key, paymentMap.get(key)); } return paymentMap.toString(); }
From source file:org.jahia.ajax.gwt.helper.PublicationHelper.java
public void keepOnlyTranslation(LinkedHashMap<String, GWTJahiaPublicationInfo> all) throws RepositoryException { Set<String> keys = new HashSet<String>(all.keySet()); for (String key : keys) { GWTJahiaPublicationInfo gwtinfo = all.get(key); if (gwtinfo.getI18nUuid() == null) { all.remove(key);// w ww . j av a2 s . c o m } else { gwtinfo.remove("uuid"); } } }
From source file:required.ChartPlotter.java
/** * Creates a sample dataset./*from ww w . j a v a2s. c om*/ * * @return a sample dataset. * @throws IOException * @throws FileNotFoundException * @throws ClassNotFoundException */ @SuppressWarnings("unchecked") private XYDataset createDataset() throws FileNotFoundException, IOException, ClassNotFoundException { LinkedHashMap<String, Long> lhash = new LinkedHashMap<>(); try (InputStream file = new FileInputStream("SortedFreq.r"); InputStream buffer = new BufferedInputStream(file); ObjectInput input = new ObjectInputStream(buffer); ) { //deserialize the List lhash = (LinkedHashMap<String, Long>) input.readObject(); input.close(); buffer.close(); file.close(); System.out.println(lhash.size()); } final XYSeries series2 = new XYSeries("Second"); Iterator<String> it = lhash.keySet().iterator(); for (int i = 0; i < lhash.size(); i++) { if (it.hasNext()) series2.add(i, lhash.get(it.next())); } final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series2); return dataset; }
From source file:org.rapidcontext.app.web.WebDavRequest.java
/** * Adds a resource to the result with the specified properties. * * @param href the root-relative resource link * @param props the resource properties *//* ww w .j a v a 2 s .co m*/ private void addResource(String href, LinkedHashMap props) { StringBuilder buffer = new StringBuilder(); Iterator iter = props.keySet().iterator(); ArrayList fails = new ArrayList(); String key; String value; xmlTagBegin(buffer, 1, "response"); xmlTag(buffer, 2, "href", Helper.encodeUrl(href), false); xmlTagBegin(buffer, 2, "propstat"); xmlTagBegin(buffer, 3, "prop"); while (iter.hasNext()) { key = (String) iter.next(); value = (String) props.get(key); if (value == null) { fails.add(key); } else if (propertyValues) { xmlTag(buffer, 4, key, value, !value.startsWith("<")); } else { xmlTag(buffer, 4, key); } } xmlTagEnd(buffer, 3, "prop"); xmlStatus(buffer, 3, STATUS.OK); xmlTagEnd(buffer, 2, "propstat"); if (fails.size() > 0) { xmlTagBegin(buffer, 2, "propstat"); xmlTagBegin(buffer, 3, "prop"); for (int i = 0; i < fails.size(); i++) { key = (String) fails.get(i); if (key.indexOf(':') > 0) { value = StringUtils.substringBeforeLast(key, ":"); key = StringUtils.substringAfterLast(key, ":"); buffer.append(StringUtils.repeat(" ", 4)); buffer.append("<"); buffer.append(namespace(value)); buffer.append(":"); buffer.append(key); buffer.append(" xmlns:"); buffer.append(namespace(value)); buffer.append("=\""); buffer.append(value); buffer.append("\"/>\n"); } else { xmlTag(buffer, 4, key); } } xmlTagEnd(buffer, 3, "prop"); xmlStatus(buffer, 3, STATUS.NOT_FOUND); xmlTagEnd(buffer, 2, "propstat"); } xmlTagEnd(buffer, 1, "response"); results.add(buffer.toString()); }
From source file:com.espertech.esper.regression.pattern.TestCronParameter.java
private LinkedHashMap<String, Long> makeExternalClockTimes(LinkedHashMap<String, Object> testData, long baseTime, long numMSecBetweenEvents) { LinkedHashMap<String, Long> testDataTimers = new LinkedHashMap<String, Long>(); testDataTimers.put(EventCollection.ON_START_EVENT_ID, baseTime); for (String id : testData.keySet()) { baseTime += numMSecBetweenEvents; testDataTimers.put(id, baseTime); }// w w w . java2 s. co m return testDataTimers; }