List of usage examples for java.util SortedMap get
V get(Object key);
From source file:org.mule.devkit.doclet.Doclava.java
public static void writeLists() { Data data = makeHDF();/* w w w . j av a 2s.co m*/ ClassInfo[] classes = Converter.rootClasses(); SortedMap<String, Object> sorted = new TreeMap<String, Object>(); for (ClassInfo cl : classes) { if (cl.isHidden()) { continue; } sorted.put(cl.qualifiedName(), cl); PackageInfo pkg = cl.containingPackage(); String name; if (pkg == null) { name = ""; } else { name = pkg.name(); } sorted.put(name, pkg); for (MethodInfo method : cl.methods()) { if (method.isProcessor() || method.isSource() || method.isTransformer()) { sorted.put(method.elementName(), method); } } } int i = 0; for (String s : sorted.keySet()) { data.setValue("docs.pages." + i + ".id", "" + i); data.setValue("docs.pages." + i + ".label", s); Object o = sorted.get(s); if (o instanceof PackageInfo) { PackageInfo pkg = (PackageInfo) o; data.setValue("docs.pages." + i + ".link", "java/" + pkg.htmlPage()); data.setValue("docs.pages." + i + ".type", "package"); } else if (o instanceof ClassInfo) { ClassInfo cl = (ClassInfo) o; data.setValue("docs.pages." + i + ".link", "java/" + cl.htmlPage()); data.setValue("docs.pages." + i + ".type", "class"); } else if (o instanceof MethodInfo) { MethodInfo mi = (MethodInfo) o; data.setValue("docs.pages." + i + ".id", "" + i); data.setValue("docs.pages." + i + ".link", "mule/" + mi.relativeModulePath()); data.setValue("docs.pages." + i + ".type", "method"); } i++; } ClearPage.write(data, "lists.cs", javadocDir + "lists.js"); }
From source file:org.wrml.runtime.schema.Prototype.java
/** * Creates a new Prototype to represent the identified schema. * * @param schemaLoader The schema loader for this prototype's schema. * @param schemaUri The schema identifier. * @throws PrototypeException Thrown if there are problems with the initial prototyping of the schema. *//* w w w. j ava 2 s. c om*/ Prototype(final SchemaLoader schemaLoader, final URI schemaUri) throws PrototypeException { LOGGER.debug("Creating Prototype for schema ID: {}", new Object[] { schemaUri }); _SchemaLoader = schemaLoader; if (_SchemaLoader == null) { throw new PrototypeException("The SchemaLoader parameter value cannot be *null*.", null, this); } _SchemaUri = schemaUri; if (_SchemaUri == null) { throw new PrototypeException("The undefined (aka *null*) schema can not be prototyped.", null, this); } if (schemaUri.equals(schemaLoader.getResourceTemplateSchemaUri())) { LOGGER.debug("Creating Prototype for ResourceTemplate"); } _UniqueName = new UniqueName(_SchemaUri); // // Use the SchemaLoader and the schema uri to get the schema's Java Class // representation. // final Class<?> schemaInterface = getSchemaInterface(); if (ValueType.JAVA_TYPE_ABSTRACT.equals(schemaInterface)) { _IsAbstract = true; } else if (Document.class.equals(schemaInterface)) { _IsDocument = true; } // // Introspect the associated class, extracting metadata from the parent // schema's Java interfaces (up to but not including the Model // interface). // _SchemaBean = new JavaBean(schemaInterface, ValueType.JAVA_TYPE_MODEL, LinkSlot.class); _AllBaseSchemaUris = new LinkedHashSet<>(); _BaseSchemaUris = new LinkedHashSet<>(); _AllSlotNames = new TreeSet<>(); _ProtoSlots = new TreeMap<>(); _CollectionPropertyProtoSlots = new TreeMap<>(); _LinkRelationUris = new TreeMap<>(); _LinkProtoSlots = new TreeMap<>(); _SlotAliases = new TreeMap<>(); _SearchableSlots = new TreeSet<>(); // initBaseSchemas(...) { // // Use Java reflection to get all implemented interfaces and then turn // them into schema ids. With reflection we get de-duplication and // recursive traversal for free. // final List<Class<?>> allBaseInterfaces = ClassUtils.getAllInterfaces(schemaInterface); // Loop backwards to achieve desired key mapping precedence/overriding for (final Class<?> baseInterface : allBaseInterfaces) { if (ValueType.isSchemaInterface(baseInterface) && (baseInterface != ValueType.JAVA_TYPE_MODEL)) { final URI baseSchemaUri = _SchemaLoader.getTypeUri(baseInterface); _AllBaseSchemaUris.add(baseSchemaUri); if (Document.class.equals(baseInterface)) { _IsDocument = true; } if (AggregateDocument.class.equals(baseInterface)) { _IsAggregate = true; } } } // Store the immediate base schemas as well final Class<?>[] baseInterfaces = schemaInterface.getInterfaces(); if (baseInterfaces != null) { for (final Class<?> baseInterface : baseInterfaces) { if (ValueType.isSchemaInterface(baseInterface) && (baseInterface != ValueType.JAVA_TYPE_MODEL)) { final URI baseSchemaUri = _SchemaLoader.getTypeUri(baseInterface); _BaseSchemaUris.add(baseSchemaUri); } if (ValueType.JAVA_TYPE_ABSTRACT.equals(baseInterface)) { _IsAbstract = true; } } } } // End of base schema init // initKeys(...) { final WRML wrml = schemaInterface.getAnnotation(WRML.class); if (wrml != null) { final String[] keySlotNameArray = wrml.keySlotNames(); if ((keySlotNameArray != null) && (keySlotNameArray.length > 0)) { _KeySlotNames = new TreeSet<>(Arrays.asList(keySlotNameArray)); if (_KeySlotNames.size() == 1) { final String keySlotName = _KeySlotNames.first(); final Property property = _SchemaBean.getProperties().get(keySlotName); if (property != null) { _KeyType = property.getType(); } else { throw new PrototypeException("The named key slot, \"" + keySlotName + "\", is not defined for Schema: " + schemaUri + ".", null, this); } } else { // Schemas with Keys that use more than one slot value to // determine uniqueness use the CompositeKey type (at // runtime) as their key object. // _KeyType = ValueType.JAVA_TYPE_COMPOSITE_KEY; } } final String[] comparableSlotNameArray = wrml.comparableSlotNames(); if ((comparableSlotNameArray != null) && (comparableSlotNameArray.length > 0)) { _ComparableSlotNames = new LinkedHashSet<String>(Arrays.asList(comparableSlotNameArray)); } final String titleSlotName = wrml.titleSlotName(); if (StringUtils.isNotBlank(titleSlotName)) { _TitleSlotName = titleSlotName; } } } // End of the key initialization // initMiscAnnotations(...) { final Description schemaDescription = schemaInterface.getAnnotation(Description.class); if (schemaDescription != null) { _Description = schemaDescription.value(); } else { _Description = null; } final Title schemaTitle = schemaInterface.getAnnotation(Title.class); if (schemaTitle != null) { _Title = schemaTitle.value(); } else { _Title = schemaInterface.getSimpleName(); } final ThumbnailImage thumbnailImage = schemaInterface.getAnnotation(ThumbnailImage.class); if (thumbnailImage != null) { _ThumbnailLocation = URI.create(thumbnailImage.value()); } else { _ThumbnailLocation = null; } _ReadOnly = (schemaInterface.getAnnotation(ReadOnly.class) != null) ? true : false; final Version schemaVersion = schemaInterface.getAnnotation(Version.class); if (schemaVersion != null) { _Version = schemaVersion.value(); } else { // TODO: Look for the "static final long serialVersionUID" ? _Version = 1L; } final Tags tags = schemaInterface.getAnnotation(Tags.class); if (tags != null) { final String[] tagArray = tags.value(); if ((tagArray != null) && (tagArray.length > 0)) { _Tags = new TreeSet<String>(Arrays.asList(tagArray)); } } } // End of annotation-based initialization // initPropertySlots(...) { final Map<String, Property> properties = _SchemaBean.getProperties(); for (final String slotName : properties.keySet()) { final Property property = properties.get(slotName); final PropertyProtoSlot propertyProtoSlot; final CollectionSlot collectionSlot = property.getAnnotation(CollectionSlot.class); if (collectionSlot != null) { propertyProtoSlot = new CollectionPropertyProtoSlot(this, slotName, property); } else { propertyProtoSlot = new PropertyProtoSlot(this, slotName, property); } addProtoSlot(propertyProtoSlot); } } // initLinkSlots(...) { // // Map the the schema bean's "other" (non-Property) methods. // final SortedMap<String, SortedSet<JavaMethod>> otherMethods = _SchemaBean.getOtherMethods(); final Set<String> otherMethodNames = otherMethods.keySet(); for (final String methodName : otherMethodNames) { final SortedSet<JavaMethod> methodSet = otherMethods.get(methodName); if (methodSet.size() != 1) { throw new PrototypeException("The link method: " + methodName + " cannot be overloaded.", this); } final JavaMethod javaMethod = methodSet.first(); final Method method = javaMethod.getMethod(); final LinkSlot linkSlot = method.getAnnotation(LinkSlot.class); if (linkSlot == null) { throw new PrototypeException("The method: " + javaMethod + " is not a link method", null, this); } final String relationUriString = linkSlot.linkRelationUri(); final URI linkRelationUri = URI.create(relationUriString); if (_LinkProtoSlots.containsKey(linkRelationUri)) { throw new PrototypeException( "A schema cannot use the same link relation for more than one method. Duplicate link relation: " + linkRelationUri + " found in link method: " + javaMethod, this); } final org.wrml.model.rest.Method relMethod = linkSlot.method(); String slotName = methodName; if (relMethod == org.wrml.model.rest.Method.Get && slotName.startsWith(JavaBean.GET)) { slotName = slotName.substring(3); slotName = Character.toLowerCase(slotName.charAt(0)) + slotName.substring(1); } _LinkRelationUris.put(slotName, linkRelationUri); if (_ProtoSlots.containsKey(slotName)) { throw new PrototypeException( "A schema cannot use the same name for more than one slot. Duplicate slot name: " + slotName + " found in link method: " + javaMethod, this); } final LinkProtoSlot linkProtoSlot = new LinkProtoSlot(this, slotName, javaMethod); if ((linkProtoSlot.isEmbedded() || isAggregate()) && (relMethod == org.wrml.model.rest.Method.Get)) { _ContainsEmbeddedLink = true; } _LinkProtoSlots.put(linkRelationUri, linkProtoSlot); addProtoSlot(linkProtoSlot); } } // End of link slot init if (!_SlotAliases.isEmpty()) { for (final String alias : _SlotAliases.keySet()) { final ProtoSlot protoSlot = _ProtoSlots.get(alias); protoSlot.setAlias(true); final String realName = _SlotAliases.get(alias); protoSlot.setRealName(realName); } } }
From source file:com.aurel.track.fieldType.bulkSetters.CustomSingleSelectBulkSetter.java
/** * Sets the workItemBean's attribute depending on the value and bulkRelation * @param workItemBean/*from w w w . java 2s . c o m*/ * @param fieldID * @param parameterCode * @param bulkTranformContext * @param selectContext * @param value * @return ErrorData if an error is found */ @Override public ErrorData setWorkItemAttribute(TWorkItemBean workItemBean, Integer fieldID, Integer parameterCode, BulkTranformContext bulkTranformContext, SelectContext selectContext, Object value) { if (getRelation() == BulkRelations.SET_NULL) { workItemBean.setAttribute(fieldID, parameterCode, null); return null; } if (getRelation() == BulkRelations.SET_TO && value != null) { SortedMap<Integer, Integer[]> valueMap = (SortedMap<Integer, Integer[]>) value; Map<Integer, Map<Integer, Map<Integer, Integer>>> fieldToProjectToIssueTypeToListMap = bulkTranformContext .getFieldToProjectToIssueTypeToListMap(); if (fieldToProjectToIssueTypeToListMap != null) { Map<Integer, Map<Integer, Integer>> projectToIssueTypeToListMap = fieldToProjectToIssueTypeToListMap .get(fieldID); if (projectToIssueTypeToListMap != null) { Integer projectID = workItemBean.getProjectID(); Map<Integer, Integer> issueTypeToListMap = projectToIssueTypeToListMap.get(projectID); if (issueTypeToListMap != null) { Integer issueTypeID = workItemBean.getListTypeID(); Integer listID = issueTypeToListMap.get(issueTypeID); if (listID != null) { Integer[] selectedValue = valueMap.get(listID); workItemBean.setAttribute(fieldID, selectedValue); } } } } } return null; //TODO uncomment this when TConfigOptionsRole is used //to avoid unnecessary access to the database /*Object oldValue = workItemBean.getAttribute(fieldID); if (newValue==null) { if (oldValue!=null) { //mark as changed workItemChangesMap.put(fieldID, null); } return null; } else { IFieldTypeRT fieldTypeRT = FieldTypeManager.getFieldTypeRT(fieldID); if (oldValue==null || fieldTypeRT.valueModified(newValue, oldValue)) { Integer newValueInt = null; if (newValue.length>0) { newValueInt = newValue[0]; } //test whether it is found in the datasouce ISelect selectFieldType = (ISelect)fieldTypeRT; //selectContext.setFieldID(fieldID); List allowedIBeanList = selectFieldType.loadEditDataSource(selectContext); if (allowedIBeanList!=null) { Iterator iterator = allowedIBeanList.iterator(); while (iterator.hasNext()) { IBeanID beanID = (IBeanID) iterator.next(); if (newValueInt.equals(beanID.getObjectID())) { //if target value found among the possible values then set as allowed change workItemChangesMap.put(fieldID, newValue); return null; } } } //not found among the possible values, add the error key in the list return new ErrorData("itemov.massOperation.err.targetValueNotAllowed"); } else { return null; } }*/ }
From source file:com.aurel.track.fieldType.runtime.custom.select.CustomDependentSelectRT.java
/** * Loads the datasource and value for configuring the field change * @param workflowContext//from w ww . j a va 2 s .co m * @param fieldChangeValue * @param parameterCode * @param personBean * @param locale */ @Override public void loadFieldChangeDatasourceAndValue(WorkflowContext workflowContext, FieldChangeValue fieldChangeValue, Integer parameterCode, TPersonBean personBean, Locale locale) { SortedMap<Integer, Integer[]> actualValuesMap = null; try { actualValuesMap = (SortedMap<Integer, Integer[]>) fieldChangeValue.getValue(); } catch (Exception e) { LOGGER.warn("ValueModified: converting the massOperationExpression values to map failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } if (actualValuesMap == null || actualValuesMap.isEmpty()) { return; } Integer fieldID = fieldChangeValue.getFieldID(); SortedMap<Integer, List<IBeanID>> compositeDataSource = (SortedMap<Integer, List<IBeanID>>) fieldChangeValue .getPossibleValues(); Object actualParentValue = actualValuesMap.get(parentID); Integer[] parentIntArr = null; Integer parentIntValue = null; try { parentIntArr = (Integer[]) actualParentValue; if (parentIntArr != null && parentIntArr.length > 0) { parentIntValue = parentIntArr[0]; } } catch (Exception e) { LOGGER.warn("Converting the parent value to Integer[] failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } List<IBeanID> possiblePartValues = null; if (parentIntValue != null) { TOptionBean optionBean = OptionBL.loadByPrimaryKey(parentIntValue); Integer parentListID = optionBean.getList(); //get the childNumber'th child list of the parentListID TListBean childListBean = ListBL.getChildList(parentListID, childNumber); if (childListBean != null) { possiblePartValues = LocalizeUtil.localizeDropDownList( optionDAO.loadCreateDataSourceByListAndParents(childListBean.getObjectID(), parentIntArr), locale); } actualValuesMap.put(parameterCode, getBulkSelectValue(null, fieldID, parameterCode, actualValuesMap.get(parameterCode), possiblePartValues)); } if (possiblePartValues != null) { compositeDataSource.put(parameterCode, possiblePartValues); } }
From source file:org.wrml.runtime.format.text.html.WrmldocFormatter.java
protected ObjectNode buildLinksNode(final ObjectMapper objectMapper, final Map<URI, ObjectNode> schemaNodes, final Map<URI, LinkRelation> linkRelationCache, final ApiNavigator apiNavigator, final Resource resource, final Prototype defaultPrototype) { final Context context = getContext(); final SchemaLoader schemaLoader = context.getSchemaLoader(); final SyntaxLoader syntaxLoader = context.getSyntaxLoader(); final URI defaultSchemaUri = (defaultPrototype != null) ? defaultPrototype.getSchemaUri() : null; final ObjectNode linksNode = objectMapper.createObjectNode(); final Set<URI> responseSchemaUris = new HashSet<>(); if (defaultSchemaUri != null) { responseSchemaUris.add(defaultSchemaUri); }//from w w w . j a v a 2 s . c o m for (final Method method : Method.values()) { final Set<URI> methodResponseSchemaUris = resource.getResponseSchemaUris(method); if (methodResponseSchemaUris != null && !methodResponseSchemaUris.isEmpty()) { responseSchemaUris.addAll(methodResponseSchemaUris); } } final ConcurrentHashMap<URI, LinkTemplate> linkTemplates = resource.getLinkTemplates(); for (final URI schemaUri : responseSchemaUris) { final Prototype prototype = schemaLoader.getPrototype(schemaUri); final SortedMap<URI, LinkProtoSlot> linkProtoSlots = prototype.getLinkProtoSlots(); if (linkProtoSlots == null || linkProtoSlots.isEmpty()) { continue; } final ObjectNode linkTemplatesNode = objectMapper.createObjectNode(); final Set<URI> linkRelationUris = linkProtoSlots.keySet(); for (final URI linkRelationUri : linkRelationUris) { final LinkProtoSlot linkProtoSlot = linkProtoSlots.get(linkRelationUri); if (schemaLoader.getDocumentSchemaUri().equals(linkProtoSlot.getDeclaringSchemaUri())) { // Skip over the built-in system-level link relations (which are all self-referential). continue; } final ObjectNode linkTemplateNode = objectMapper.createObjectNode(); final String linkSlotName = linkProtoSlot.getName(); linkTemplatesNode.put(linkSlotName, linkTemplateNode); final LinkRelation linkRelation = getLinkRelation(linkRelationCache, linkRelationUri); final Method method = linkRelation.getMethod(); linkTemplateNode.put(PropertyName.method.name(), method.getProtocolGivenName()); linkTemplateNode.put(PropertyName.rel.name(), syntaxLoader.formatSyntaxValue(linkRelationUri)); linkTemplateNode.put(PropertyName.relationTitle.name(), linkRelation.getTitle()); final URI responseSchemaUri; final URI requestSchemaUri; if (linkTemplates.containsKey(linkRelationUri)) { final LinkTemplate linkTemplate = linkTemplates.get(linkRelationUri); responseSchemaUri = linkTemplate.getResponseSchemaUri(); requestSchemaUri = linkTemplate.getRequestSchemaUri(); final UUID endPointId = linkTemplate.getEndPointId(); if (endPointId != null) { final Resource endPointResource = apiNavigator.getResource(endPointId); final ObjectNode endPointNode = objectMapper.createObjectNode(); endPointNode.put(PropertyName.id.name(), syntaxLoader.formatSyntaxValue(endPointId)); endPointNode.put(PropertyName.pathSegment.name(), endPointResource.getPathSegment()); endPointNode.put(PropertyName.fullPath.name(), endPointResource.getPathText()); endPointNode.put(PropertyName.uriTemplate.name(), endPointResource.getUriTemplate().getUriTemplateString()); linkTemplateNode.put(PropertyName.endpoint.name(), endPointNode); } } else { responseSchemaUri = linkProtoSlot.getResponseSchemaUri(); requestSchemaUri = linkProtoSlot.getRequestSchemaUri(); } if (responseSchemaUri != null) { final ObjectNode responseSchemaNode = getSchemaNode(objectMapper, schemaNodes, responseSchemaUri, schemaLoader); linkTemplateNode.put(PropertyName.responseSchema.name(), responseSchemaNode); } if (requestSchemaUri != null) { final ObjectNode requestSchemaNode = getSchemaNode(objectMapper, schemaNodes, requestSchemaUri, schemaLoader); linkTemplateNode.put(PropertyName.requestSchema.name(), requestSchemaNode); } final String signature = buildLinkSignature(linkSlotName, responseSchemaUri, requestSchemaUri, schemaUri); linkTemplateNode.put(PropertyName.signature.name(), signature); } if (linkTemplatesNode.size() > 0) { final ObjectNode schemaNode = objectMapper.createObjectNode(); final ObjectNode schemaDetailsNode = getSchemaNode(objectMapper, schemaNodes, schemaUri, schemaLoader); schemaNode.put(PropertyName.schema.name(), schemaDetailsNode); schemaNode.put(PropertyName.linkTemplates.name(), linkTemplatesNode); linksNode.put(prototype.getUniqueName().getLocalName(), schemaNode); } } return linksNode; }
From source file:org.opencms.module.CmsModule.java
/** * Resolves the module property "additionalresources" to the resource list and * vice versa.<p>/*ww w . j a v a 2 s .c om*/ * * This "special" module property is required as long as we do not have a new * GUI for editing of module resource entries. Once we have the new GUI, the * handling of "additionalresources" will be moved to the import of the module * and done only if the imported module is a 5.0 module.<p> */ private void initOldAdditionalResources() { SortedMap<String, String> parameters = new TreeMap<String, String>(m_parameters); List<String> resources = new ArrayList<String>(m_resources); String additionalResources; additionalResources = parameters.get(MODULE_PROPERTY_ADDITIONAL_RESOURCES); if (additionalResources != null) { StringTokenizer tok = new StringTokenizer(additionalResources, MODULE_PROPERTY_ADDITIONAL_RESOURCES_SEPARATOR); while (tok.hasMoreTokens()) { String resource = tok.nextToken().trim(); if ((!"-".equals(resource)) && (!resources.contains(resource))) { resources.add(resource); } } } m_resources = resources; }
From source file:com.restfb.util.InsightUtilsTest.java
@Test public void executeInsightQueriesByDate2() throws IOException, ParseException, JSONException { // note that the query that is passed to the FacebookClient WebRequestor is // ignored,//from ww w . j a va 2 s. c om // so arguments of executeInsightQueriesByDate: // (String pageObjectId, Set<String> metrics, Period period) // are effectively ignored. In this test we are validating the // WebRequestor's json // is properly processed Date d20030629_0000pst = sdfPST.parse("20030629_0000"); Date d20030630_0000pst = sdfPST.parse("20030630_0000"); Date d20030701_0000pst = sdfPST.parse("20030701_0000"); Date d20030702_0000pst = sdfPST.parse("20030702_0000"); // intentionally using (chaotic) HashSet to ensure implementation is // tolerant of that collection Set<Date> periodEndDates = new HashSet<Date>(); periodEndDates.add(d20030629_0000pst); periodEndDates.add(d20030630_0000pst); periodEndDates.add(d20030701_0000pst); periodEndDates.add(d20030702_0000pst); SortedMap<Date, JsonArray> results = executeInsightQueriesByDate( createFixedResponseFacebookClient("multiResponse_2metrics_4dates.json"), TEST_PAGE_OBJECT, toStringSet("page_active_users", "page_tab_views_login_top_unique"), Period.DAY, periodEndDates); Assert.assertNotNull(results); assertEquals(4, results.size()); // not ideal that this test requires on a stable JsonArray.toString() String expectedString; String actualString; expectedString = new JsonArray( "[{\"metric\":\"page_active_users\",\"value\":761},{\"metric\":\"page_tab_views_login_top_unique\",\"value\":{\"photos\":2,\"app_4949752878\":3,\"wall\":30}}]") .toString(); actualString = results.get(d20030629_0000pst).toString(); JSONAssert.assertEquals(expectedString, actualString, JSONCompareMode.NON_EXTENSIBLE); expectedString = new JsonArray( "[{\"metric\":\"page_active_users\",\"value\":705},{\"metric\":\"page_tab_views_login_top_unique\",\"value\":{\"app_4949752878\":1,\"photos\":1,\"app_2373072738\":2,\"wall\":23}}]") .toString(); actualString = results.get(d20030630_0000pst).toString(); JSONAssert.assertEquals(expectedString, actualString, JSONCompareMode.NON_EXTENSIBLE); expectedString = new JsonArray( "[{\"metric\":\"page_active_users\",\"value\":582},{\"metric\":\"page_tab_views_login_top_unique\",\"value\":{\"app_4949752878\":1,\"wall\":12}}]") .toString(); actualString = results.get(d20030701_0000pst).toString(); JSONAssert.assertEquals(expectedString, actualString, JSONCompareMode.NON_EXTENSIBLE); expectedString = new JsonArray( "[{\"metric\":\"page_active_users\",\"value\":125},{\"metric\":\"page_tab_views_login_top_unique\",\"value\":{\"photos\":1,\"wall\":11}}]") .toString(); actualString = results.get(d20030702_0000pst).toString(); JSONAssert.assertEquals(expectedString, actualString, JSONCompareMode.NON_EXTENSIBLE); }
From source file:org.formix.dsx.serialization.XmlSerializer.java
/** * Deserialize an XML tree into the given type. * //from w w w .j a v a2 s . c om * @param root * The XML root element. * * @param type * The type of the desired object. * * @param <T> * The infered type for the parameter {code type}. * * @return a deserialized object from the given XML. * * @throws XmlException * Thrown when a problem occurs during deserialization. */ public <T> T deserialize(XmlElement root, Class<T> type) throws XmlException { if (type.toString().equals("class [B")) { @SuppressWarnings("unchecked") T value = (T) Base64.decodeBase64(root.getChild(0).toString()); return value; } // If the type is a base type from java.util or java.sql or is a // collection then decode it directly. if (type.getName().startsWith("java.") || Collection.class.isAssignableFrom(type)) { @SuppressWarnings("unchecked") T value = (T) this.getValue(root, type, null, null); return value; } String rootName = this.capitalize(root.getName()); String childName = ""; XmlElement childElem = null; if (root.getChild(0) instanceof XmlElement) { childElem = (XmlElement) root.getChild(0); childName = this.capitalize(childElem.getName()); if (rootName.equals(childName)) return this.deserialize(childElem, type); } T target; try { target = type.newInstance(); } catch (Exception e) { throw new XmlException("Unable to instanciate type " + type.getName(), e); } this.onBeforeDeserialization(new SerializationEvent(this, root, target)); SortedMap<String, Method> methods = this.createMethodMap(type); for (XmlContent content : root.getChilds()) { if (content instanceof XmlElement) { XmlElement elem = (XmlElement) content; String methodName = "set" + this.capitalize(elem.getName()); String signature = methods.tailMap(methodName).firstKey(); // If the setter is not found for the specified methodName, skip // this setter. if (signature.startsWith(methodName)) { Method setMethod = methods.get(signature); Class<?> paramType = setMethod.getParameterTypes()[0]; try { Object value = this.getValue(elem, paramType, methods, target); setMethod.invoke(target, new Object[] { value }); } catch (Exception e) { String msg = String.format( "Unable to assign the XMLElement %s to" + " the property [%s.%s] (%s)", elem, type.getName(), setMethod.getName(), signature); throw new XmlException(msg, e); } } else { throw new XmlException(String.format("Unable to find the method %s.", methodName)); } } } this.onAfterDeserialization(new SerializationEvent(this, root, target)); return target; }
From source file:org.squale.squaleweb.util.graph.KiviatMaker.java
/** * Ajoute les d'un composant. <br /> * <b>Attention : </b> pour assurer la cohrences des donnes, si cette mthode est appelle plusieurs fois, pValues * doit avoir chaque fois la meme taille et les mme cls. * /*from w w w .ja v a 2s. c o m*/ * @param pName nom associ la future courbe. * @param pValues SortedMap contenant en cl (tri!) des facteurs sous forme de String et en valeur des nombres * (Double). * @param pRequest pour avoir le nom des facteurs internationaliss */ public void addValues(String pName, SortedMap pValues, HttpServletRequest pRequest) { Set keys = pValues.keySet(); // Ajoute les donnes Iterator it = keys.iterator(); // Pour chaque axe, on cre l'axe avec son titre et on ajoute les valeurs while (it.hasNext()) { // Internationalisation du nom // On a besoin d'un tokenizer pour ne pas prendre en compte la partie entre () String key = (String) it.next(); StringTokenizer st = new StringTokenizer(key, "("); String axis = WebMessages.getString(pRequest, ("factor.internationalise.name." + st.nextToken()).trim()); // le facteur peut ne pas avoir de note, dans ce cas il n'y a plus de tokens // le premier token contient tout if (st.hasMoreTokens()) { axis += "(" + st.nextToken(); } mDataset.addValue(1.0D, "1.0", axis); mDataset.addValue(2.0D, "2.0", axis); final double thirdValue = 3.0D; mDataset.addValue(thirdValue, "3.0", axis); Number number = ((Number) pValues.get(key)); if (number != null && number.doubleValue() >= 0.0) { mDataset.addValue(number.doubleValue(), pName, axis); } } }
From source file:eu.stratosphere.pact.runtime.hash.HashFunctionCollisionBenchmark.java
/** * Create histogram over bucket sizes/*from w w w. ja va2 s .c o m*/ * * @param map * Map to be analyzed * @param level * Level on which the map is located in * @return The total count of hashed values in the map */ private int collectStatistics(HashMap<Integer, Object> map, int level) { SortedMap<Integer, Integer> bucketSizesForLevel = bucketSizesPerLevel.get(level); Iterator<Object> bucketIterator = map.values().iterator(); int bucketCount = 0; int totalValueCount = 0; while (bucketIterator.hasNext()) { bucketCount++; Integer hashValuesInBucket; // If we are already on the deepest level, get the count in the // bucket, otherwise // recursively examine the subtree if (level == maxLevel - 1) { hashValuesInBucket = (Integer) bucketIterator.next(); } else { @SuppressWarnings("unchecked") HashMap<Integer, Object> nextMap = (HashMap<Integer, Object>) bucketIterator.next(); hashValuesInBucket = collectStatistics(nextMap, level + 1); } totalValueCount += hashValuesInBucket; Integer countOfBucketSizes = bucketSizesForLevel.get(hashValuesInBucket); if (countOfBucketSizes == null) { countOfBucketSizes = 1; } else { countOfBucketSizes += 1; } bucketSizesForLevel.put(hashValuesInBucket, countOfBucketSizes); } Integer countOfEmptyBuckets = bucketSizesForLevel.get(0); if (countOfEmptyBuckets == null) { countOfEmptyBuckets = rangeCalculators[level].getBucketCount() - bucketCount; } else { countOfEmptyBuckets += rangeCalculators[level].getBucketCount() - bucketCount; } bucketSizesForLevel.put(0, countOfEmptyBuckets); return totalValueCount; }