List of usage examples for java.util SortedMap get
V get(Object key);
From source file:org.openehr.rm.binding.DADLBinding.java
public List<String> toDADL(Object obj, int indent, List<String> lines) throws Exception { log.debug("toDADL on obj.getClass: " + obj.getClass().getCanonicalName() + ", indent: " + indent + ", line.size: " + lines.size()); Class klass = obj.getClass(); String className = klass.getSimpleName(); String rmName = toUnderscoreSeparated(className).toUpperCase(); String typeHeader = "(" + rmName + ") <"; int size = lines.size(); if (size == 0) { lines.add(typeHeader);/*from w w w. jav a2 s.com*/ } else { String l = lines.get(size - 1); l += typeHeader; lines.set(size - 1, l); } SortedMap<String, Attribute> attributes = attributeMap(obj.getClass()); String name = null; Object value = null; StringBuffer buf = null; for (Iterator<String> names = attributes.keySet().iterator(); names.hasNext();) { name = names.next(); Attribute attribute = attributes.get(name); if (attribute.system()) { continue; } if ("parent".equals(attribute.name())) { continue; // causing dead-loops } Method getter = getter(name, obj.getClass()); if (getter != null) { value = getter.invoke(obj, null); buf = new StringBuffer(); if (value != null) { for (int i = 0; i < indent; i++) { buf.append("\t"); } buf.append(toUnderscoreSeparated(name)); buf.append(" = "); if (isOpenEHRRMClass(value) && !(value instanceof ProportionKind)) { lines.add(buf.toString()); log.debug("fetching attribute: " + name); toDADL(value, indent + 1, lines); } else if (value instanceof List) { buf.append("<"); lines.add(buf.toString()); List list = (List) value; for (int i = 0, j = list.size(); i < j; i++) { buf = new StringBuffer(); for (int k = 0; k < indent + 1; k++) { buf.append("\t"); } lines.add(buf.toString() + "[" + (i + 1) + "] = "); toDADL(list.get(i), indent + 2, lines); } buf = new StringBuffer(); for (int i = 0; i < indent; i++) { buf.append("\t"); } buf.append(">"); lines.add(buf.toString()); } else { buf.append("<"); if (value instanceof String || value instanceof Boolean) { buf.append("\""); buf.append(value); buf.append("\""); } else { buf.append(value.toString()); } buf.append(">"); lines.add(buf.toString()); } } } } buf = new StringBuffer(); for (int i = 0; i < indent - 1; i++) { buf.append("\t"); } buf.append(">"); lines.add(buf.toString()); return lines; }
From source file:org.apache.hadoop.hbase.regionserver.wal.TestHLogFiltering.java
@Test public void testFlushedSequenceIdsSentToHMaster() throws IOException, InterruptedException, ServiceException { SortedMap<byte[], Long> allFlushedSequenceIds = new TreeMap<byte[], Long>(Bytes.BYTES_COMPARATOR); for (int i = 0; i < NUM_RS; ++i) { flushAllRegions(i);//from w w w. j a va 2 s . c o m } Thread.sleep(10000); HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); for (int i = 0; i < NUM_RS; ++i) { for (byte[] regionName : getRegionsByServer(i)) { if (allFlushedSequenceIds.containsKey(regionName)) { GetLastFlushedSequenceIdRequest req = RequestConverter .buildGetLastFlushedSequenceIdRequest(regionName); assertEquals((long) allFlushedSequenceIds.get(regionName), master.getLastFlushedSequenceId(null, req).getLastFlushedSequenceId()); } } } }
From source file:tajo.master.GlobalPlanner.java
@VisibleForTesting public static Map<String, List<URI>> hashFetches(SubQueryId sid, List<URI> uriList) { SortedMap<String, List<URI>> hashed = new TreeMap<String, List<URI>>(); String uriPath, key;//from w w w . j a v a2 s . c om for (URI uri : uriList) { // TODO uriPath = uri.toString(); key = uriPath.substring(uriPath.lastIndexOf("=") + 1); if (hashed.containsKey(key)) { hashed.get(key).add(uri); } else { List<URI> list = new ArrayList<URI>(); list.add(uri); hashed.put(key, list); } } return combineURIByHost(hashed); }
From source file:de.micromata.genome.gwiki.plugin.rogmp3_1_0.Mp3Db.java
public SortedMap<String, Integer> getComposersCountries() { SortedMap<String, Integer> ret = new TreeMap<String, Integer>(); for (String[] comp : composers.table) { Composer cp = new Composer(this, comp); String rcountry = cp.get(Composer.COUNTRY); List<String> ccl = Arrays.asList(StringUtils.split(rcountry, ";")); for (String country : ccl) { Integer c = ret.get(country); if (c == null) { ret.put(country, 1);/*from www. jav a 2s. c o m*/ } else { ret.put(country, c + 1); } } } return ret; }
From source file:org.eclipse.skalli.core.persistence.XStreamPersistenceTest.java
@Test public void testSaveLoadCycle() throws Exception { TestExtensibleEntityBase entity = getExtensibleEntity(); TestExtensibleEntityEntityService entityService = new TestExtensibleEntityEntityService( CURRENT_MODEL_VERSION);/* w w w . ja v a 2s . c o m*/ TestExtension ext1 = entity.getExtension(TestExtension.class); ext1.setStr(TEXT1); ext1.setBool(false); Map<String, Class<?>> aliases = getAliases(); Set<Converter> converters = getConverters(); TestXStreamPersistence xp = new TestXStreamPersistence(); //saveEntity Calendar beforeSaveDate = Calendar.getInstance(); xp.saveEntity(entityService, entity, USER0, aliases, converters); Calendar afterSaveDate = Calendar.getInstance(); //test that entity is now in the HashMap available and lastModified is set. Document savedHashMapDoc = xp.getDocumentFromHashMap(entity); String lastModified = xp.getLastModifiedAttribute(savedHashMapDoc.getDocumentElement()); assertNotNull(lastModified); assertIsXsdDateTime(lastModified); Calendar lastModifiedDate = DatatypeConverter.parseDateTime(lastModified); assertTrue(beforeSaveDate.compareTo(lastModifiedDate) <= 0); assertTrue(lastModifiedDate.compareTo(afterSaveDate) <= 0); //test that lastModifiedDate is set for extensions as well SortedMap<String, Element> extensions = xp.getExtensionsByAlias(savedHashMapDoc, aliases); assertEquals(2, extensions.size()); String lastModifiedExt1 = xp.getLastModifiedAttribute(extensions.get(ALIAS_EXT1)); assertIsXsdDateTime(lastModifiedExt1); String lastModifiedExt2 = xp.getLastModifiedAttribute(extensions.get(ALIAS_EXT1)); assertIsXsdDateTime(lastModifiedExt2); //loadEntity again Set<ClassLoader> entityClassLoaders = getTestExtensibleEntityBaseClassLodades(); TestExtensibleEntityBase loadedEntity = xp.loadEntity(entityService, entity.getUuid().toString(), entityClassLoaders, null, aliases, converters); assertLoadedEntityIsExpectedOne(loadedEntity, USER0, USER0, USER0, lastModified, lastModifiedExt1, lastModifiedExt2, TEXT1, false); // and check that loadEntities can read it List<? extends TestExtensibleEntityBase> loadedEntities = xp.loadEntities(entityService, entityClassLoaders, null, aliases, converters); assertEquals(1, loadedEntities.size()); assertLoadedEntityIsExpectedOne(loadedEntities.get(0), USER0, USER0, USER0, lastModified, lastModifiedExt1, lastModifiedExt2, TEXT1, false); //change the entity and save again ext1 = entity.getExtension(TestExtension.class); ext1.setStr(TEXT1 + " is now updated"); xp.saveEntity(entityService, entity, USER1, aliases, converters); TestExtensibleEntityBase updatedEntity = xp.loadEntity(entityService, entity.getUuid().toString(), entityClassLoaders, null, aliases, converters); Document updatedHashMapDoc = xp.getDocumentFromHashMap(entity); lastModified = xp.getLastModifiedAttribute(updatedHashMapDoc.getDocumentElement()); SortedMap<String, Element> updatedExtensions = xp.getExtensionsByAlias(updatedHashMapDoc, aliases); lastModifiedExt1 = xp.getLastModifiedAttribute(updatedExtensions.get(ALIAS_EXT1)); assertLoadedEntityIsExpectedOne(updatedEntity, USER1, USER1, USER0, lastModified, lastModifiedExt1, lastModifiedExt2, TEXT1 + " is now updated", false); }
From source file:org.kuali.coeus.common.framework.custom.CustomDataHelperBase.java
/** * This method builds the custom data collections used on the form * @param customAttributeGroups//from w ww . j a va2s . co m */ @SuppressWarnings("unchecked") public void buildCustomDataCollectionsOnNewDocument(SortedMap<String, List> customAttributeGroups) { for (Map.Entry<String, CustomAttributeDocument> customAttributeDocumentEntry : getCustomAttributeDocuments() .entrySet()) { String groupName = customAttributeDocumentEntry.getValue().getCustomAttribute().getGroupName(); addToCustomDataList(customAttributeDocumentEntry); if (StringUtils.isEmpty(groupName)) { groupName = "No Group"; } List<CustomAttributeDocument> customAttributeDocumentList = customAttributeGroups.get(groupName); if (customAttributeDocumentList == null) { customAttributeDocumentList = new ArrayList<CustomAttributeDocument>(); customAttributeGroups.put(groupName, customAttributeDocumentList); } customAttributeDocumentList.add( getCustomAttributeDocuments().get(customAttributeDocumentEntry.getValue().getId().toString())); Collections.sort(customAttributeDocumentList, new LabelComparator()); } }
From source file:org.eclipse.skalli.core.persistence.XStreamPersistenceTest.java
@Test public void testGetExtensionsByAlias() throws Exception { Document doc = XMLUtils.documentFromString(XML_WITH_EXTENSIONS); Map<String, Class<?>> aliases = getAliases(); XStreamPersistence xp = new TestXStreamPersistence(); SortedMap<String, Element> extensions = xp.getExtensionsByAlias(doc, aliases); assertEquals(2, extensions.size());/*from w w w . ja v a 2 s .c o m*/ for (String alias : extensions.keySet()) { assertTrue(aliases.containsKey(alias)); assertEquals(alias, extensions.get(alias).getNodeName()); } //check that the content of ext1 is the expected one assertEquals("string", extensions.get("ext1").getFirstChild().getNodeName()); assertEquals("string", extensions.get("ext1").getFirstChild().getTextContent()); }
From source file:com.tesobe.obp.transport.spi.DefaultResponder.java
@SuppressWarnings("ComparatorMethodParameterNotUsed") protected Comparator<Map<String, Object>> sorter(Decoder.Pager p) { Comparator<Map<String, Object>> equal = (o1, o2) -> 0; return p.sorter().map(s -> { SortedMap<String, SortOrder> fields = s.fields(); if (fields != null) { Set<String> names = fields.keySet(); return (Comparator<Map<String, Object>>) (o1, o2) -> { for (String name : names) { int delta = 0; Object v1 = o1.get(name); Object v2 = o2.get(name); if (v1 == null) { delta = v2 == null ? 0 : -1; } else if (v2 != null) { SortOrder order = fields.get(name); if (SortOrder.ascending == order) { delta = compare(v1, v2); } else if (SortOrder.descending == order) { delta = compare(v2, v1); }/*from w w w . j a va2s . c o m*/ } else { return 1; } if (delta != 0) { return delta; } } return 0; }; } return equal; }).orElse(equal); }
From source file:se.tillvaxtverket.ttsigvalws.ttwebservice.TTSigValServlet.java
private void checkEncoding(byte[] attrBytes) { SortedMap<String, Charset> availableCharsets = Charset.availableCharsets(); Set<String> keySet = availableCharsets.keySet(); List<String> charsets = new ArrayList<String>(); List<String> decoded = new ArrayList<String>(); for (String key : keySet) { Charset cs = availableCharsets.get(key); charsets.add(key);//from ww w. j a v a 2 s . c om decoded.add(new String(attrBytes, cs)); } int i = 0; }
From source file:hivemall.topicmodel.OnlineLDAModel.java
@Nonnull public SortedMap<Float, List<String>> getTopicWords(@Nonnegative final int k, @Nonnegative int topN) { double lambdaSum = 0.d; final SortedMap<Float, List<String>> sortedLambda = new TreeMap<Float, List<String>>( Collections.reverseOrder()); for (Map.Entry<String, float[]> e : _lambda.entrySet()) { final float lambda_k = e.getValue()[k]; lambdaSum += lambda_k;/*w ww . j ava 2 s . c om*/ List<String> labels = sortedLambda.get(lambda_k); if (labels == null) { labels = new ArrayList<String>(); sortedLambda.put(lambda_k, labels); } labels.add(e.getKey()); } final SortedMap<Float, List<String>> ret = new TreeMap<Float, List<String>>(Collections.reverseOrder()); topN = Math.min(topN, _lambda.keySet().size()); int tt = 0; for (Map.Entry<Float, List<String>> e : sortedLambda.entrySet()) { float key = (float) (e.getKey().floatValue() / lambdaSum); ret.put(Float.valueOf(key), e.getValue()); if (++tt == topN) { break; } } return ret; }