List of usage examples for java.util SortedMap put
V put(K key, V value);
From source file:edu.cornell.mannlib.vitro.webapp.controller.accounts.UserAccountsPage.java
/** * Create a list of possible profile types. * //from w w w . ja v a 2 s. c o m * TODO Right now, these are foaf:Person and it's sub-classes. What will it * be for Vitro? */ protected SortedMap<String, String> buildProfileTypesList() { String seedClassUri = PERSON_CLASS_URI; List<String> classUris = vclassDao.getAllSubClassURIs(seedClassUri); classUris.add(seedClassUri); SortedMap<String, String> types = new TreeMap<String, String>(); for (String classUri : classUris) { VClass vclass = vclassDao.getVClassByURI(classUri); if (vclass != null) { types.put(classUri, vclass.getName()); } } return types; }
From source file:com.uber.hoodie.common.table.log.avro.AvroLogAppenderTest.java
@Test public void testCompositeAvroLogReader() throws IOException, URISyntaxException, InterruptedException { // Set a small threshold so that every block is a new version HoodieLogAppendConfig logConfig = HoodieLogAppendConfig.newBuilder().onPartitionPath(partitionPath) .withLogFileExtension(HoodieLogFile.DELTA_EXTENSION).withFileId("test-fileid1") .withBaseCommitTime("100").withSchema(SchemaTestUtil.getSimpleSchema()).withSizeThreshold(500) .withFs(fs).build();// w w w.j a va 2s.c om RollingAvroLogAppender logAppender = new RollingAvroLogAppender(logConfig); long size1 = logAppender.getCurrentSize(); List<IndexedRecord> input1 = SchemaTestUtil.generateTestRecords(0, 100); logAppender.append(input1.iterator()); logAppender.close(); // Need to rebuild config to set the latest version as path logConfig = HoodieLogAppendConfig.newBuilder().onPartitionPath(partitionPath) .withLogFileExtension(HoodieLogFile.DELTA_EXTENSION).withFileId("test-fileid1") .withBaseCommitTime("100").withSchema(SchemaTestUtil.getSimpleSchema()).withSizeThreshold(500) .withFs(fs).build(); logAppender = new RollingAvroLogAppender(logConfig); long size2 = logAppender.getCurrentSize(); List<IndexedRecord> input2 = SchemaTestUtil.generateTestRecords(100, 100); logAppender.append(input2.iterator()); logAppender.close(); logConfig = HoodieLogAppendConfig.newBuilder().onPartitionPath(partitionPath) .withLogFileExtension(HoodieLogFile.DELTA_EXTENSION).withFileId("test-fileid1") .withBaseCommitTime("100").withSchema(SchemaTestUtil.getSimpleSchema()).withSizeThreshold(500) .withFs(fs).build(); List<HoodieLogFile> allLogFiles = FSUtils .getAllLogFiles(fs, partitionPath, logConfig.getLogFile().getFileId(), HoodieLogFile.DELTA_EXTENSION, logConfig.getLogFile().getBaseCommitTime()) .collect(Collectors.toList()); assertEquals("", 2, allLogFiles.size()); SortedMap<Integer, List<Long>> offsets = Maps.newTreeMap(); offsets.put(1, Lists.newArrayList(size1)); offsets.put(2, Lists.newArrayList(size2)); CompositeAvroLogReader reader = new CompositeAvroLogReader(partitionPath, logConfig.getLogFile().getFileId(), logConfig.getLogFile().getBaseCommitTime(), fs, logConfig.getSchema(), HoodieLogFile.DELTA_EXTENSION); Iterator<GenericRecord> results = reader.readBlocks(offsets); List<GenericRecord> totalBatch = IteratorUtils.toList(results); assertEquals("Stream collect should return all 200 records", 200, totalBatch.size()); input1.addAll(input2); assertEquals("CompositeAvroLogReader should return 200 records from 2 versions", input1, totalBatch); }
From source file:com.haulmont.cuba.web.sys.WebJarResourceResolver.java
protected SortedMap<String, String> getFullPathIndex(Set<String> assetPaths) { SortedMap<String, String> assetPathIndex = new TreeMap<>(); for (String assetPath : assetPaths) { assetPathIndex.put(reversePath(assetPath), assetPath); }//from ww w. ja va 2s.com return assetPathIndex; }
From source file:org.sakaiproject.metaobj.utils.ioc.ApplicationContextFactory.java
public String[] getConfigLocations(Properties props) throws IOException { SortedMap configFiles = new TreeMap(); for (Enumeration e = props.keys(); e.hasMoreElements();) { Integer key = new Integer((String) e.nextElement()); String curFile = props.getProperty(key.toString()); curFile = (!curFile.startsWith("/")) ? "/" + curFile : curFile; configFiles.put(key, curFile);// w w w . j a v a2s.c o m logger.info("registering '" + curFile + "' in position " + key + " as spring bean definition file"); } return convertToArray(configFiles.values()); }
From source file:net.ripe.rpki.commons.crypto.rfc3779.ResourceExtensionEncoder.java
/** * Encode the IP Address Block extension for Resource Certificates. This * extension is identified by {@link #OID_IP_ADDRESS_BLOCKS}. * * @param inheritIpv4 inherit IPv4 resources from signing certificate. * @param inheritIpv6 inherit IPv6 resources from signing certificate. * @param resources the set of IPv4 and IPv6 resources. * @return the DER encoding of the IP Address Block Extension. *//*w w w . j av a 2 s. c o m*/ public ASN1Object encodeIpAddressBlocks(boolean inheritIpv4, boolean inheritIpv6, IpResourceSet resources) { SortedMap<AddressFamily, IpResourceSet> addressBlocks = new TreeMap<AddressFamily, IpResourceSet>(); if (inheritIpv4) { addressBlocks.put(AddressFamily.IPV4, null); } else if (resources.containsType(IpResourceType.IPv4)) { addressBlocks.put(AddressFamily.IPV4, resources); } if (inheritIpv6) { addressBlocks.put(AddressFamily.IPV6, null); } else if (resources.containsType(IpResourceType.IPv6)) { addressBlocks.put(AddressFamily.IPV6, resources); } return addressBlocks.isEmpty() ? null : ipAddressBlocksToDer(addressBlocks); }
From source file:annis.model.DataObject.java
@Override public int hashCode() { // sort fields by name for predictable results final SortedMap<String, Object> fieldValues = new TreeMap<String, Object>(); final Object _this = this; forEachFieldDo(new FieldCallBack() { public void doForField(Field field) throws IllegalAccessException { fieldValues.put(field.getName(), field.get(_this)); }//from w ww. j a v a 2 s .c o m }); HashCodeBuilder hashCodeBuilder = new HashCodeBuilder(); for (Object fieldValue : fieldValues.values()) hashCodeBuilder.append(fieldValue); return hashCodeBuilder.toHashCode(); }
From source file:com.palantir.atlasdb.keyvalue.impl.AssertLockedKeyValueService.java
@Override public void put(String tableName, Map<Cell, byte[]> values, long timestamp) { if (tableName.equals(TransactionConstants.TRANSACTION_TABLE)) { SortedMap<LockDescriptor, LockMode> mapToAssertLockHeld = Maps.newTreeMap(); SortedMap<LockDescriptor, LockMode> mapToAssertLockNotHeld = Maps.newTreeMap(); for (Map.Entry<Cell, byte[]> e : values.entrySet()) { if (Arrays.equals(e.getValue(), TransactionConstants.getValueForTimestamp(TransactionConstants.FAILED_COMMIT_TS))) { mapToAssertLockNotHeld.put(AtlasRowLockDescriptor.of(tableName, e.getKey().getRowName()), LockMode.READ);/*from w w w.ja va 2 s . c o m*/ } else { mapToAssertLockHeld.put(AtlasRowLockDescriptor.of(tableName, e.getKey().getRowName()), LockMode.READ); } } try { if (!mapToAssertLockHeld.isEmpty()) { LockRequest request = LockRequest.builder(mapToAssertLockHeld).doNotBlock() .lockAsManyAsPossible().build(); LockRefreshToken lock = lockService.lockAnonymously(request); Validate.isTrue(lock == null, "these should already be held"); } if (!mapToAssertLockNotHeld.isEmpty()) { LockRequest request = LockRequest.builder(mapToAssertLockNotHeld).doNotBlock().build(); LockRefreshToken lock = lockService.lockAnonymously(request); Validate.isTrue(lock != null, "these should already be waited for"); } } catch (InterruptedException e) { throw Throwables.throwUncheckedException(e); } } super.put(tableName, values, timestamp); }
From source file:com.cloudera.oryx.kmeans.computation.local.SamplingRun.java
@Override public Collection<RealVector> call() throws Exception { SortedMap<Double, RealVector> reservoir = Maps.newTreeMap(); for (RealVector v : vecs) { Distance d = index.getDistance(v, foldId, true); if (d.getSquaredDistance() > 0.0) { double score = Math.log(random.nextDouble()) / d.getSquaredDistance(); if (reservoir.size() < sampleCount) { reservoir.put(score, v); } else if (score > reservoir.firstKey()) { reservoir.remove(reservoir.firstKey()); reservoir.put(score, v); }/* w w w. ja v a 2s .c om*/ } } return reservoir.values(); }
From source file:com.splicemachine.derby.utils.SpliceAdmin.java
public static void SYSCS_GET_REGION_SERVER_CONFIG_INFO(final String configRoot, final int showDisagreementsOnly, final ResultSet[] resultSet) throws StandardException, SQLException { Map<String, DatabaseVersion> dbVersions = EngineDriver.driver().dbAdministrator() .getClusterDatabaseVersions(); boolean matchName = (configRoot != null && !configRoot.equals("")); int hostIdx = 0; String hostName;// w w w . j a va 2s . c o m ResultSetBuilder rsBuilder; RowBuilder rowBuilder; try { rsBuilder = new ResultSetBuilder(); rsBuilder.getColumnBuilder().addColumn("HOST_NAME", Types.VARCHAR, 32) .addColumn("CONFIG_NAME", Types.VARCHAR, 128).addColumn("CONFIG_VALUE", Types.VARCHAR, 128); rowBuilder = rsBuilder.getRowBuilder(); // We arbitrarily pick DatabaseVersion MBean even though // we do not fetch anything from it. We just use it as our // mechanism for our region server context. SortedMap<String, String> configMap = new TreeMap<>(); SConfiguration config = EngineDriver.driver().getConfiguration(); Map<String, Object> configRootMap = config.getConfigMap(); for (Map.Entry<String, DatabaseVersion> databaseVersion : dbVersions.entrySet()) { hostName = databaseVersion.getKey(); configMap.clear(); for (Map.Entry<String, Object> conf : configRootMap.entrySet()) { configMap.put(conf.getKey(), conf.getValue().toString()); } // Iterate through sorted configs and add to result set Set<Entry<String, String>> configSet = configMap.entrySet(); for (Entry<String, String> configEntry : configSet) { rowBuilder.getDvd(0).setValue(hostName); rowBuilder.getDvd(1).setValue(configEntry.getKey()); rowBuilder.getDvd(2).setValue(configEntry.getValue()); rowBuilder.addRow(); } hostIdx++; } resultSet[0] = rsBuilder.buildResultSet((EmbedConnection) getDefaultConn()); configMap.clear(); } catch (StandardException se) { throw PublicAPI.wrapStandardException(se); } }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step6GraphTransitivityCleaner.java
public static SortedMap<String, DescriptiveStatistics> collectStatisticsOverGraphCleaningResults( Collection<GraphCleaningResults> results) throws IllegalAccessException { SortedMap<String, DescriptiveStatistics> result = new TreeMap<>(); for (GraphCleaningResults r : results) { Field[] declaredFields = GraphCleaningResults.class.getDeclaredFields(); // System.out.println(Arrays.toString(declaredFields)); for (Field field : declaredFields) { String fieldName = field.getName(); if (!result.containsKey(fieldName)) { result.put(fieldName, new DescriptiveStatistics()); }// w w w . ja v a 2s .c om Object value = field.get(r); double doubleVal; if (value instanceof Integer) { doubleVal = ((Integer) value).doubleValue(); } else if (value instanceof Double) { doubleVal = (Double) value; } else { throw new IllegalStateException("Unkown type " + value.getClass()); } // System.out.println(doubleVal); result.get(fieldName).addValue(doubleVal); } } return result; }