List of usage examples for java.util SortedMap putAll
void putAll(Map<? extends K, ? extends V> m);
From source file:org.apache.jackrabbit.oak.plugins.segment.file.TarReader.java
/** * Creates a TarReader instance for reading content from a tar file. * If there exist multiple generations of the same tar file, they are * all passed to this method. The latest generation with a valid tar * index (which is a good indication of general validity of the file) * is opened and the other generations are removed to clean things up. * If none of the generations has a valid index, then something must have * gone wrong and we'll try recover as much content as we can from the * existing tar generations.//from w w w .j a va2s .com * * @param files * @param memoryMapping * @return * @throws IOException */ static TarReader open(Map<Character, File> files, boolean memoryMapping) throws IOException { SortedMap<Character, File> sorted = newTreeMap(); sorted.putAll(files); List<File> list = newArrayList(sorted.values()); Collections.reverse(list); TarReader reader = openFirstFileWithValidIndex(list, memoryMapping); if (reader != null) { return reader; } // no generation has a valid index, so recover as much as we can log.warn("Could not find a valid tar index in {}, recovering...", list); LinkedHashMap<UUID, byte[]> entries = newLinkedHashMap(); for (File file : sorted.values()) { collectFileEntries(file, entries, true); } // regenerate the first generation based on the recovered data File file = sorted.values().iterator().next(); generateTarFile(entries, file); reader = openFirstFileWithValidIndex(singletonList(file), memoryMapping); if (reader != null) { return reader; } else { throw new IOException("Failed to open recovered tar file " + file); } }
From source file:com.github.fge.jsonschema.syntax.checkers.draftv3.DraftV3PropertiesSyntaxChecker.java
@Override protected void extraChecks(final ProcessingReport report, final SchemaTree tree) throws ProcessingException { final SortedMap<String, JsonNode> map = Maps.newTreeMap(); map.putAll(JacksonUtils.asMap(tree.getNode().get(keyword))); String member;/* w w w .j ava2 s .com*/ JsonNode required; NodeType type; for (final Map.Entry<String, JsonNode> entry : map.entrySet()) { member = entry.getKey(); required = entry.getValue().get("required"); if (required == null) continue; type = NodeType.getNodeType(required); if (type != NodeType.BOOLEAN) { report.error(newMsg(tree, "draftv3PropertiesRequired").put("property", member) .put("expected", NodeType.BOOLEAN).put("found", type)); } } }
From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.draftv3.DraftV3PropertiesSyntaxChecker.java
@Override protected void extraChecks(final ProcessingReport report, final MessageBundle bundle, final SchemaTree tree) throws ProcessingException { final SortedMap<String, JsonNode> map = Maps.newTreeMap(); map.putAll(JacksonUtils.asMap(tree.getNode().get(keyword))); String member;//from w w w. j a v a2 s. c om JsonNode required; NodeType type; for (final Map.Entry<String, JsonNode> entry : map.entrySet()) { member = entry.getKey(); required = entry.getValue().get("required"); if (required == null) continue; type = NodeType.getNodeType(required); if (type != NodeType.BOOLEAN) { report.error(newMsg(tree, bundle, "draftv3.properties.required.incorrectType") .putArgument("property", member).putArgument("found", type) .put("expected", NodeType.BOOLEAN)); } } }
From source file:org.apache.accumulo.core.iterators.user.RowEncodingIteratorTest.java
@Test(expected = BufferOverflowException.class) public void testEncodeSome() throws IOException { byte[] kbVal = new byte[1024]; // This code is shamelessly borrowed from the WholeRowIteratorTest. SortedMap<Key, Value> map1 = new TreeMap<Key, Value>(); pkv(map1, "row1", "cf1", "cq1", "cv1", 5, kbVal); pkv(map1, "row1", "cf1", "cq2", "cv1", 6, kbVal); SortedMap<Key, Value> map = new TreeMap<Key, Value>(); map.putAll(map1); SortedMapIterator src = new SortedMapIterator(map); Range range = new Range(new Text("row1"), true, new Text("row2"), true); RowEncodingIteratorImpl iter = new RowEncodingIteratorImpl(); Map<String, String> bigBufferOpts = new HashMap<String, String>(); bigBufferOpts.put(RowEncodingIterator.MAX_BUFFER_SIZE_OPT, "1K"); iter.init(src, bigBufferOpts, new DummyIteratorEnv()); iter.seek(range, new ArrayList<ByteSequence>(), false); // BufferOverflowException should be thrown as RowEncodingIterator can't fit the whole row into its buffer. }
From source file:org.apache.accumulo.core.iterators.user.RowEncodingIteratorTest.java
@Test public void testEncodeAll() throws IOException { byte[] kbVal = new byte[1024]; // This code is shamelessly borrowed from the WholeRowIteratorTest. SortedMap<Key, Value> map1 = new TreeMap<Key, Value>(); pkv(map1, "row1", "cf1", "cq1", "cv1", 5, kbVal); pkv(map1, "row1", "cf1", "cq2", "cv1", 6, kbVal); SortedMap<Key, Value> map2 = new TreeMap<Key, Value>(); pkv(map2, "row2", "cf1", "cq1", "cv1", 5, kbVal); pkv(map2, "row2", "cf1", "cq2", "cv1", 6, kbVal); SortedMap<Key, Value> map3 = new TreeMap<Key, Value>(); pkv(map3, "row3", "cf1", "cq1", "cv1", 5, kbVal); pkv(map3, "row3", "cf1", "cq2", "cv1", 6, kbVal); SortedMap<Key, Value> map = new TreeMap<Key, Value>(); map.putAll(map1); map.putAll(map2);// w w w . j ava 2 s . c o m map.putAll(map3); SortedMapIterator src = new SortedMapIterator(map); Range range = new Range(new Text("row1"), true, new Text("row2"), true); RowEncodingIteratorImpl iter = new RowEncodingIteratorImpl(); Map<String, String> bigBufferOpts = new HashMap<String, String>(); bigBufferOpts.put(RowEncodingIterator.MAX_BUFFER_SIZE_OPT, "3K"); iter.init(src, bigBufferOpts, new DummyIteratorEnv()); iter.seek(range, new ArrayList<ByteSequence>(), false); assertTrue(iter.hasTop()); assertEquals(map1, RowEncodingIteratorImpl.decodeRow(iter.getTopKey(), iter.getTopValue())); // simulate something continuing using the last key from the iterator // this is what client and server code will do range = new Range(iter.getTopKey(), false, range.getEndKey(), range.isEndKeyInclusive()); iter.seek(range, new ArrayList<ByteSequence>(), false); assertTrue(iter.hasTop()); assertEquals(map2, RowEncodingIteratorImpl.decodeRow(iter.getTopKey(), iter.getTopValue())); iter.next(); assertFalse(iter.hasTop()); }
From source file:org.opentides.service.impl.UserGroupServiceImpl.java
/** * @param authorities// ww w .ja va 2 s . co m * the authorities to set */ public void setAuthorities(Map<String, String> authorities) { // added process of sorting the authoritiesMap by the values in ascending order SortedMap<String, String> sortedData = new TreeMap<String, String>( new UserGroupServiceImpl.ValueComparer(authorities)); sortedData.putAll(authorities); this.authorities = sortedData; }
From source file:no.dusken.barweb.admin.InvoiceController.java
/** * @param transaksjons on invoice// w ww . j a v a2s . c o m * @return a map with person as key and how much the transaksjons given sum for each BarPerson. */ private Map<BarPerson, Integer> getPersonOwes(List<Transaksjon> transaksjons) { Map<BarPerson, Integer> map = new HashMap<BarPerson, Integer>(); for (Transaksjon t : transaksjons) { BarPerson p = t.getBarPerson(); Integer sum = map.get(p); if (sum == null) { map.put(p, t.getSum()); } else { map.put(p, sum + t.getSum()); } } SortedMap<BarPerson, Integer> sortedMap = new TreeMap<BarPerson, Integer>(new ValueComparator(map)); sortedMap.putAll(map); return sortedMap; }
From source file:org.springframework.batch.item.database.JdbcPagingQueryIntegrationTests.java
private List<Object> getParameterList(Map<String, Object> values, Map<String, Object> sortKeyValue) { SortedMap<String, Object> sm = new TreeMap<String, Object>(); if (values != null) { sm.putAll(values); }/*from w w w . j a va2 s .c om*/ List<Object> parameterList = new ArrayList<Object>(); parameterList.addAll(sm.values()); if (sortKeyValue != null && sortKeyValue.size() > 0) { List<Map.Entry<String, Object>> keys = new ArrayList<Map.Entry<String, Object>>( sortKeyValue.entrySet()); for (int i = 0; i < keys.size(); i++) { for (int j = 0; j < i; j++) { parameterList.add(keys.get(j).getValue()); } parameterList.add(keys.get(i).getValue()); } } if (logger.isDebugEnabled()) { logger.debug("Using parameterList:" + parameterList); } return parameterList; }
From source file:com.atolcd.alfresco.audit.web.scripts.ExportGet.java
private void buildTree(List<String> parameters, Map<String, Object> model) { List<Functionality> functionalities = new ArrayList<Functionality>(); for (int i = 0; i < parameters.size(); i++) { SortedMap<Date, Integer> resQuery = new TreeMap<Date, Integer>(); switch (EnumFonctionnalite.valueOf(parameters.get(i))) { case createddocs: resQuery.putAll(auditQueriesService.countCreateDocs(new Calendar[] { startDate, endDate }, "none")); generateTree("createddocs", resQuery, functionalities); break; case modifieddocs: resQuery.putAll(auditQueriesService.countCheckins(new Calendar[] { startDate, endDate }, "none")); generateTree("modifieddocs", resQuery, functionalities); break; case readdocs: resQuery.putAll(auditQueriesService.countReadDocs(new Calendar[] { startDate, endDate }, "none")); generateTree("readdocs", resQuery, functionalities); break; case conn: resQuery.putAll(/* www . j a va 2 s . c om*/ auditQueriesService.countConnections(new Calendar[] { startDate, endDate }, "none")); generateTree("conn", resQuery, functionalities); break; case createduser: resQuery.putAll( auditQueriesService.countCreateUsers(new Calendar[] { startDate, endDate }, "none")); generateTree("createduser", resQuery, functionalities); break; case createdwork: resQuery.putAll(auditQueriesService.countWorkflows(new Calendar[] { startDate, endDate }, "none")); generateTree("createdwork", resQuery, functionalities); break; } } model.put("functionalities", functionalities); }
From source file:org.apache.pirk.querier.wideskies.encrypt.EncryptQuery.java
private SortedMap<Integer, BigInteger> parallelEncrypt(Map<Integer, Integer> selectorQueryVecMapping, int numThreads) throws InterruptedException, PIRException { // Encrypt and form the query vector ExecutorService es = Executors.newCachedThreadPool(); List<Future<SortedMap<Integer, BigInteger>>> futures = new ArrayList<>(numThreads); int numElements = 1 << queryInfo.getHashBitSize(); // 2^hashBitSize // Split the work across the requested number of threads int elementsPerThread = numElements / numThreads; for (int i = 0; i < numThreads; ++i) { // Grab the range for this thread int start = i * elementsPerThread; int stop = start + elementsPerThread - 1; if (i == numThreads - 1) { stop = numElements - 1;//from w ww .j a v a 2 s .c o m } // Create the runnable and execute EncryptQueryTask runEnc = new EncryptQueryTask(queryInfo.getDataPartitionBitSize(), paillier, selectorQueryVecMapping, start, stop); futures.add(es.submit(runEnc)); } // Pull all encrypted elements and add to resultMap SortedMap<Integer, BigInteger> queryElements = new TreeMap<>(); try { for (Future<SortedMap<Integer, BigInteger>> future : futures) { queryElements.putAll(future.get(1, TimeUnit.DAYS)); } } catch (TimeoutException | ExecutionException e) { throw new PIRException("Exception in encryption threads.", e); } es.shutdown(); return queryElements; }