List of usage examples for java.util Map values
Collection<V> values();
From source file:mondrian.rolap.RolapAggregationManager.java
/** * Translates a Map<BitKey, List<RolapMember>> of the same * compound member into {@link ListPredicate} by traversing a list of * members or tuples./*w w w .j a v a2s.c o m*/ * * <p>1. The example below is for list of tuples * * <blockquote> * group 1: [Gender].[M], [Store].[USA].[CA]<br/> * group 2: [Gender].[F], [Store].[USA].[CA] * </blockquote> * * is translated into * * <blockquote> * (Gender=M AND Store_State=CA AND Store_Country=USA)<br/> * OR<br/> * (Gender=F AND Store_State=CA AND Store_Country=USA) * </blockquote> * * <p>The caller of this method will translate this representation into * appropriate SQL form as * <blockquote> * where (gender = 'M'<br/> * and Store_State = 'CA'<br/> * AND Store_Country = 'USA')<br/> * OR (Gender = 'F'<br/> * and Store_State = 'CA'<br/> * AND Store_Country = 'USA') * </blockquote> * * <p>2. The example below for a list of members * <blockquote> * group 1: [USA].[CA], [Canada].[BC]<br/> * group 2: [USA].[CA].[San Francisco], [USA].[OR].[Portland] * </blockquote> * * is translated into: * * <blockquote> * (Country=USA AND State=CA)<br/> * OR (Country=Canada AND State=BC)<br/> * OR (Country=USA AND State=CA AND City=San Francisco)<br/> * OR (Country=USA AND State=OR AND City=Portland) * </blockquote> * * <p>The caller of this method will translate this representation into * appropriate SQL form. For exmaple, if the underlying DB supports multi * value IN-list, the second group will turn into this predicate: * * <blockquote> * where (country, state, city) IN ((USA, CA, San Francisco), * (USA, OR, Portland)) * </blockquote> * * or, if the DB does not support multi-value IN list: * * <blockquote> * where country=USA AND * ((state=CA AND city = San Francisco) OR * (state=OR AND city=Portland)) * </blockquote> * * @param compoundGroupMap Map from dimensionality to groups * @param baseCube base cube if virtual * @return compound predicate for a tuple or a member */ private static StarPredicate makeCompoundPredicate(Map<BitKey, List<RolapCubeMember[]>> compoundGroupMap, RolapCube baseCube) { List<StarPredicate> compoundPredicateList = new ArrayList<StarPredicate>(); for (List<RolapCubeMember[]> group : compoundGroupMap.values()) { // e.g {[USA].[CA], [Canada].[BC]} StarPredicate compoundGroupPredicate = null; for (RolapCubeMember[] tuple : group) { // [USA].[CA] StarPredicate tuplePredicate = null; for (RolapCubeMember member : tuple) { tuplePredicate = makeCompoundPredicateForMember(member, baseCube, tuplePredicate); } if (tuplePredicate != null) { if (compoundGroupPredicate == null) { compoundGroupPredicate = tuplePredicate; } else { compoundGroupPredicate = compoundGroupPredicate.or(tuplePredicate); } } } if (compoundGroupPredicate != null) { // Sometimes the compound member list does not constrain any // columns; for example, if only AllLevel is present. compoundPredicateList.add(compoundGroupPredicate); } } StarPredicate compoundPredicate = null; if (compoundPredicateList.size() > 1) { compoundPredicate = new OrPredicate(compoundPredicateList); } else if (compoundPredicateList.size() == 1) { compoundPredicate = compoundPredicateList.get(0); } return compoundPredicate; }
From source file:com.github.gekoh.yagen.util.MappingUtils.java
public static Iterator<Class> getClassesSequenceIterator(EntityManagerFactory emf, boolean topDown) throws Exception { Map<Class, TreeEntity> treeEntities = new HashMap<Class, TreeEntity>(); for (EntityType entityType : emf.getMetamodel().getEntities()) { Class entityClass = entityType.getJavaType(); if (!treeEntities.containsKey(entityClass)) { treeEntities.put(entityClass, new TreeEntity(entityClass)); }// w ww.j a v a2 s . c om fillTreeEntityMap(treeEntities, entityType.getAttributes(), entityClass); } for (TreeEntity treeEntity : treeEntities.values()) { if (topDown) { treeEntity.calculateMaxLevel(treeEntities); } else { treeEntity.calculateMinLevel(treeEntities); } } List<TreeEntity> sorted = new ArrayList<TreeEntity>(treeEntities.values()); Collections.sort(sorted); if (!topDown) { Collections.reverse(sorted); } List<Class> sortedClasses = new ArrayList<Class>(sorted.size()); for (TreeEntity treeEntity : sorted) { sortedClasses.add(treeEntity.getEntityClass()); } return sortedClasses.iterator(); }
From source file:controllers.SiteApp.java
public static Result mailList() { Set<String> emails = new HashSet<>(); Map<String, String[]> projects = request().body().asFormUrlEncoded(); if (!UserApp.currentUser().isSiteManager()) { return forbidden(ErrorViews.Forbidden.render("error.auth.unauthorized.waringMessage")); }/* w w w .j av a 2 s . c o m*/ if (!request().accepts("application/json")) { return status(Http.Status.NOT_ACCEPTABLE); } if (projects == null) { return ok(toJson(new HashSet<String>())); } if (projects.containsKey("all")) { if (projects.get("all")[0].equals("true")) { for (User user : User.find.findList()) { emails.add(user.email); } } } else { for (String[] projectNames : projects.values()) { String projectName = projectNames[0]; String[] parts = projectName.split("/"); String owner = parts[0]; String name = parts[1]; Project project = Project.findByOwnerAndProjectName(owner, name); for (ProjectUser projectUser : ProjectUser.findMemberListByProject(project.id)) { Logger.debug(projectUser.user.email); emails.add(projectUser.user.email); } } } return ok(toJson(emails)); }
From source file:jp.go.nict.langrid.p2pgridbasis.data.langrid.converter.ConvertUtil.java
static public DataAttributes encode(Object data) throws DataConvertException { setLangridConverter();/* ww w.j av a 2 s .c o m*/ logger.debug("##### encode #####"); try { DataAttributes attr = new DataAttributes(); for (PropertyDescriptor descriptor : PropertyUtils.getPropertyDescriptors(data)) { if (PropertyUtils.isReadable(data, descriptor.getName())) { if (descriptor.getName().equalsIgnoreCase("supportedLanguages")) { //supportedLanguages attr.setAttribute(descriptor.getName(), (String) converter.lookup(descriptor.getPropertyType()).convert(String.class, PropertyUtils.getProperty(data, descriptor.getName()))); continue; } else if (descriptor.getName().equalsIgnoreCase("instance")) { // // continue; } else if (descriptor.getName().equalsIgnoreCase("wsdl")) { // // continue; } else if (descriptor.getName().equalsIgnoreCase("interfaceDefinitions")) { // // ServiceType type = (ServiceType) data; Map<String, ServiceInterfaceDefinition> map = new HashMap<String, ServiceInterfaceDefinition>(); map = type.getInterfaceDefinitions(); String str = ""; try { for (ServiceInterfaceDefinition s : map.values()) { str = str + "ProtocolId=" + s.getProtocolId() + "\n"; str = str + "Definition=" + Base64.encode(StreamUtil.readAsBytes(s.getDefinition().getBinaryStream())) + "\n"; str = str + "###ServiceInterfaceDefinition###\n"; } } catch (IOException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } attr.setAttribute("interfaceDefinition_list", str); continue; } else if (descriptor.getName().equalsIgnoreCase("allowedAppProvision")) { Service s = (Service) data; String value = ""; for (String str : s.getAllowedAppProvision()) { value = value + str + "\n"; } attr.setAttribute("allowedAppProvision", value); continue; } else if (descriptor.getName().equalsIgnoreCase("allowedUse")) { Service s = (Service) data; String value = ""; for (String str : s.getAllowedUse()) { value = value + str + "\n"; } attr.setAttribute("allowedUse", value); continue; } else if (descriptor.getName().equalsIgnoreCase("supportedDomains")) { Grid g = (Grid) data; List<Domain> list = g.getSupportedDomains(); String value = ""; for (Domain d : list) { value = value + d.getDomainId() + "\n"; } attr.setAttribute("supportedDomain_list", value); continue; } else if (descriptor.getName().equalsIgnoreCase("partnerServiceNamespaceURIs")) { //partnerServiceNamespaceURIs BPELService s = (BPELService) data; List<String> list = s.getPartnerServiceNamespaceURIs(); String value = ""; for (String str : list) { value = value + str + "\n"; } attr.setAttribute("partnerServiceNamespaceURI_list", value); continue; } else if (descriptor.getName().equalsIgnoreCase("serviceDeployments")) { //ServiceDeployment Service s = (Service) data; String str = ""; for (ServiceDeployment sd : s.getServiceDeployments()) { str = str + "GridId=" + sd.getGridId() + "\n"; str = str + "ServiceId=" + sd.getServiceId() + "\n"; str = str + "NodeId=" + sd.getNodeId() + "\n"; str = str + "ServicePath=" + sd.getServicePath() + "\n"; str = str + "Enabled=" + String.valueOf(sd.isEnabled()) + "\n"; str = str + "CreateTime=" + String.valueOf(sd.getCreatedDateTime().getTimeInMillis()) + "\n"; str = str + "UpdateTime=" + String.valueOf(sd.getUpdatedDateTime().getTimeInMillis()) + "\n"; if (sd.getDisabledByErrorDate() != null) { str = str + "ErrorDate=" + String.valueOf(sd.getDisabledByErrorDate().getTimeInMillis()) + "\n"; } if (sd.getDeployedDateTime() != null) { str = str + "DeployedTime=" + String.valueOf(sd.getDeployedDateTime().getTimeInMillis()) + "\n"; } str = str + "###ServiceDeployment###\n"; } attr.setAttribute("deployment_list", str); continue; } else if (descriptor.getName().equalsIgnoreCase("serviceEndpoints")) { //ServiceEndpoint StringBuilder str = new StringBuilder(); Service s = (Service) data; for (ServiceEndpoint se : s.getServiceEndpoints()) { str.append("GridId=" + se.getGridId() + "\n"); str.append("ProtocolId=" + se.getProtocolId() + "\n"); str.append("ServiceId=" + se.getServiceId() + "\n"); str.append("Enabled=" + String.valueOf(se.isEnabled()) + "\n"); str.append("Url=" + se.getUrl().toString() + "\n"); str.append("AuthUserName=" + se.getAuthUserName() + "\n"); str.append("AuthPassword=" + se.getAuthPassword() + "\n"); str.append("DisableReason=" + se.getDisableReason() + "\n"); str.append("CreateTime=" + String.valueOf(se.getCreatedDateTime().getTimeInMillis()) + "\n"); str.append("UpdateTime=" + String.valueOf(se.getUpdatedDateTime().getTimeInMillis()) + "\n"); if (se.getDisabledByErrorDate() != null) { str.append("ErrorDate=" + String.valueOf(se.getDisabledByErrorDate().getTimeInMillis()) + "\n"); } str.append("###ServiceEndpoint###\n"); } attr.setAttribute("endpoint_list", str.toString()); continue; } else if (descriptor.getName().equalsIgnoreCase("invocations")) { //Invocation String str = ""; Service s = (Service) data; for (Invocation in : s.getInvocations()) { str = str + "InvocationName=" + in.getInvocationName() + "\n"; str = str + "OwnerServiceGridId=" + in.getOwnerServiceGridId() + "\n"; str = str + "OwnerServiceId=" + in.getOwnerServiceId() + "\n"; str = str + "ServiceGridId=" + in.getServiceGridId() + "\n"; str = str + "ServiceId=" + in.getServiceId() + "\n"; str = str + "ServiceName=" + in.getServiceName() + "\n"; str = str + "CreateTime=" + String.valueOf(in.getCreatedDateTime().getTimeInMillis()) + "\n"; str = str + "UpdateTime=" + String.valueOf(in.getUpdatedDateTime().getTimeInMillis()) + "\n"; str = str + "###Invocation###\n"; } attr.setAttribute("invocations_list", str); continue; } else if (descriptor.getName().equalsIgnoreCase("metaAttributes")) { //metaAttributes String str = ""; if (data.getClass().getName().endsWith("ResourceType")) { ResourceType r = (ResourceType) data; for (ResourceMetaAttribute a : r.getMetaAttributes().values()) { str = str + "DomainId=" + a.getDomainId() + "\n"; str = str + "AttributeId=" + a.getAttributeId() + "\n"; str = str + "###MetaAttribute###\n"; } } else if (data.getClass().getName().endsWith("ServiceType")) { ServiceType s = (ServiceType) data; for (ServiceMetaAttribute a : s.getMetaAttributes().values()) { str = str + "DomainId=" + a.getDomainId() + "\n"; str = str + "AttributeId=" + a.getAttributeId() + "\n"; str = str + "###MetaAttribute###\n"; } } else { logger.info("metaAttributes : " + data.getClass().getName()); } attr.setAttribute("metaAttribute_list", str); continue; } else if (descriptor.getName().equalsIgnoreCase("attributes")) { //attribute String str = ""; if (data.getClass().getName().endsWith("User")) { User u = (User) data; for (UserAttribute a : u.getAttributes()) { str = str + "attribute_GridId=" + a.getGridId() + "\n"; str = str + "attribute_Id=" + a.getUserId() + "\n"; str = str + "attribute_Name=" + a.getName() + "\n"; str = str + "attribute_Value=" + a.getValue() + "\n"; str = str + "attribute_CreateTime=" + String.valueOf(a.getCreatedDateTime().getTimeInMillis()) + "\n"; str = str + "attribute_UpdateTime=" + String.valueOf(a.getUpdatedDateTime().getTimeInMillis()) + "\n"; str = str + "###Attribute###\n"; } } else if (data.getClass().getName().endsWith("Service")) { Service s = (Service) data; for (ServiceAttribute a : s.getAttributes()) { str = str + "attribute_GridId=" + a.getGridId() + "\n"; str = str + "attribute_Id=" + a.getServiceId() + "\n"; str = str + "attribute_Name=" + a.getName() + "\n"; str = str + "attribute_Value=" + a.getValue() + "\n"; str = str + "attribute_CreateTime=" + String.valueOf(a.getCreatedDateTime().getTimeInMillis()) + "\n"; str = str + "attribute_UpdateTime=" + String.valueOf(a.getUpdatedDateTime().getTimeInMillis()) + "\n"; str = str + "###Attribute###\n"; } } else if (data.getClass().getName().endsWith("Node")) { Node s = (Node) data; for (NodeAttribute a : s.getAttributes()) { str = str + "attribute_GridId=" + a.getGridId() + "\n"; str = str + "attribute_Id=" + a.getNodeId() + "\n"; str = str + "attribute_Name=" + a.getName() + "\n"; str = str + "attribute_Value=" + a.getValue() + "\n"; str = str + "attribute_CreateTime=" + String.valueOf(a.getCreatedDateTime().getTimeInMillis()) + "\n"; str = str + "attribute_UpdateTime=" + String.valueOf(a.getUpdatedDateTime().getTimeInMillis()) + "\n"; str = str + "###Attribute###\n"; } } else if (data.getClass().getName().endsWith("Grid")) { Grid s = (Grid) data; for (GridAttribute a : s.getAttributes()) { str = str + "attribute_GridId=" + a.getGridId() + "\n"; str = str + "attribute_Name=" + a.getName() + "\n"; str = str + "attribute_Value=" + a.getValue() + "\n"; str = str + "attribute_CreateTime=" + String.valueOf(a.getCreatedDateTime().getTimeInMillis()) + "\n"; str = str + "attribute_UpdateTime=" + String.valueOf(a.getUpdatedDateTime().getTimeInMillis()) + "\n"; str = str + "###Attribute###\n"; } } else if (data.getClass().getName().endsWith("Resource")) { Resource s = (Resource) data; for (ResourceAttribute a : s.getAttributes()) { str = str + "attribute_GridId=" + a.getGridId() + "\n"; str = str + "attribute_Id=" + a.getResourceId() + "\n"; str = str + "attribute_Name=" + a.getName() + "\n"; str = str + "attribute_Value=" + a.getValue() + "\n"; str = str + "attribute_CreateTime=" + String.valueOf(a.getCreatedDateTime().getTimeInMillis()) + "\n"; str = str + "attribute_UpdateTime=" + String.valueOf(a.getUpdatedDateTime().getTimeInMillis()) + "\n"; str = str + "###Attribute###\n"; } } attr.setAttribute("attribute_list", str); continue; } else if (data instanceof Service && (descriptor.getName().equals("alternateServiceId") || descriptor.getName().equals("useAlternateServices"))) { // // continue; } //Read OK if (data instanceof BPELService && descriptor.getName().equals("transferExecution")) { // ignore } else { attr.setAttribute(descriptor.getName(), BeanUtils.getProperty(data, descriptor.getName())); } } else if (descriptor.getPropertyType().isArray()) { logger.debug("name : " + descriptor.getName() + " isArray"); // // attr.setAttribute(descriptor.getName(), (String) converter.lookup(descriptor.getPropertyType()) .convert(String.class, PropertyUtils.getProperty(data, descriptor.getName()))); } else { logger.debug("Name : " + descriptor.getName()); for (Method m : data.getClass().getMethods()) { if (m.getName().equalsIgnoreCase("get" + descriptor.getName()) || m.getName().equalsIgnoreCase("is" + descriptor.getName())) { if (m.getParameterTypes().length != 0) { // // logger.debug("class : " + data.getClass().getName()); logger.debug("?:Skip"); break; } else { // // logger.debug("value : " + m.invoke(data)); } attr.setAttribute(descriptor.getName(), m.invoke(data).toString()); break; } } } } return attr; } catch (InvocationTargetException e) { throw new DataConvertException(e); } catch (IllegalArgumentException e) { throw new DataConvertException(e); } catch (IllegalAccessException e) { throw new DataConvertException(e); } catch (NoSuchMethodException e) { throw new DataConvertException(e); } }
From source file:com.opengamma.engine.view.client.ViewDeltaResultCalculator.java
private static void computeDeltaModel(DeltaDefinition deltaDefinition, InMemoryViewDeltaResultModel deltaModel, ComputationTargetSpecification targetSpec, String calcConfigName, ViewCalculationResultModel previousCalcModel, ViewCalculationResultModel resultCalcModel) { final Map<Pair<String, ValueProperties>, ComputedValueResult> resultValues = resultCalcModel .getValues(targetSpec);/* w ww . j a va 2 s .c om*/ if (resultValues != null) { if (previousCalcModel == null) { // Everything is new/delta because this is a new calculation context. for (Map.Entry<Pair<String, ValueProperties>, ComputedValueResult> resultEntry : resultValues .entrySet()) { deltaModel.addValue(calcConfigName, resultEntry.getValue()); } } else { final Map<Pair<String, ValueProperties>, ComputedValueResult> previousValues = previousCalcModel .getValues(targetSpec); if (previousValues == null) { // Everything is new/delta because this is a new target. for (ComputedValueResult result : resultValues.values()) { deltaModel.addValue(calcConfigName, result); } } else { // Have to individual delta. for (Map.Entry<Pair<String, ValueProperties>, ComputedValueResult> resultEntry : resultValues .entrySet()) { ComputedValueResult resultValue = resultEntry.getValue(); ComputedValueResult previousValue = previousValues.get(resultEntry.getKey()); // REVIEW jonathan 2010-05-07 -- The previous value that we're comparing with is the value from the last // computation cycle, not the value that we last emitted as a delta. It is therefore important that the // DeltaComparers take this into account in their implementation of isDelta. E.g. they should compare the // values after truncation to the required decimal place, rather than testing whether the difference of the // full values is greater than some threshold; this way, there will always be a point beyond which a change // is detected, even in the event of gradual creep. if (deltaDefinition.isDelta(previousValue, resultValue) || !ObjectUtils.equals(previousValue.getAggregatedExecutionLog(), resultValue.getAggregatedExecutionLog())) { deltaModel.addValue(calcConfigName, resultEntry.getValue()); } } } } } }
From source file:com.aurel.track.exchange.msProject.exchange.MsProjectExchangeBL.java
/** * Gets the taskUID to workItemID mapping for existing tasks * * @param trackPlusTasks/*from w ww. j a v a2 s. co m*/ * @return */ public static Map<Integer, Integer> getTaskUIDToWorkItemIDMap(Map<Integer, TMSProjectTaskBean> trackPlusTasks) { Map<Integer, Integer> taskUIDToWorkItemIDMap = new HashMap<Integer, Integer>(); Iterator<TMSProjectTaskBean> itrMSProjectTasks = trackPlusTasks.values().iterator(); while (itrMSProjectTasks.hasNext()) { TMSProjectTaskBean projectTaskBean = itrMSProjectTasks.next(); taskUIDToWorkItemIDMap.put(projectTaskBean.getUniqueID(), projectTaskBean.getWorkitem()); } return taskUIDToWorkItemIDMap; }
From source file:com.aurel.track.exchange.msProject.exchange.MsProjectExchangeBL.java
/** * Gets the workItemID to taskUID mapping for existing tasks * * @param trackPlusTasks//w w w. j av a 2s . com * @return */ public static Map<Integer, Integer> getWorkItemIDToTaskUIDMap(Map<Integer, TMSProjectTaskBean> trackPlusTasks) { Map<Integer, Integer> workItemIDToTaskUIDToMap = new HashMap<Integer, Integer>(); Iterator<TMSProjectTaskBean> itrMSProjectTasks = trackPlusTasks.values().iterator(); while (itrMSProjectTasks.hasNext()) { TMSProjectTaskBean projectTaskBean = itrMSProjectTasks.next(); workItemIDToTaskUIDToMap.put(projectTaskBean.getWorkitem(), projectTaskBean.getUniqueID()); } return workItemIDToTaskUIDToMap; }
From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java
/** * @param vehicleDistances//from w w w . j a v a 2 s .c om * @param string * @return */ public static String summarizeVehicles(Map<Id<Vehicle>, double[]> vehicleDistances, String del) { DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(2); format.setGroupingUsed(false); DescriptiveStatistics driven = new DescriptiveStatistics(); DescriptiveStatistics revenue = new DescriptiveStatistics(); DescriptiveStatistics occupied = new DescriptiveStatistics(); DescriptiveStatistics empty = new DescriptiveStatistics(); for (double[] dist : vehicleDistances.values()) { driven.addValue(dist[0]); revenue.addValue(dist[1]); occupied.addValue(dist[2]); double emptyD = dist[0] - dist[2]; empty.addValue(emptyD); } double d_r_d_t = revenue.getSum() / driven.getSum(); // bw.write("iteration;vehicles;totalDistance;totalEmptyDistance;emptyRatio;totalRevenueDistance;averageDrivenDistance;averageEmptyDistance;averageRevenueDistance"); String result = vehicleDistances.size() + del + format.format(driven.getSum()) + del + format.format(empty.getSum()) + del + format.format(empty.getSum() / driven.getSum()) + del + format.format(revenue.getSum()) + del + format.format(driven.getMean()) + del + format.format(empty.getMean()) + del + format.format(revenue.getMean()) + del + format.format(d_r_d_t); return result; }
From source file:com.baidu.rigel.biplatform.ma.report.utils.QueryUtils.java
/** * measuremeasuremeasurecube//from ww w.jav a 2 s . c o m * @param measures * @param oriCube */ private static void modifyMeasures(Map<String, Measure> measures, Cube oriCube) { Set<String> refMeasuers = Sets.newHashSet(); measures.values().stream().filter(m -> { return m.getType() == MeasureType.CAL || m.getType() == MeasureType.RR || m.getType() == MeasureType.SR; }).forEach(m -> { ExtendMinicubeMeasure tmp = (ExtendMinicubeMeasure) m; if (m.getType() == MeasureType.CAL) { refMeasuers.addAll(PlaceHolderUtils.getPlaceHolderKeys(tmp.getFormula())); } else { final String refName = m.getName().substring(0, m.getName().length() - 3); refMeasuers.add(refName); if (m.getType() == MeasureType.RR) { tmp.setFormula("rRate(${" + refName + "})"); } else if (m.getType() == MeasureType.SR) { tmp.setFormula("sRate(${" + refName + "})"); } } tmp.setAggregator(Aggregator.CALCULATED); }); refMeasuers.stream().filter(str -> { return !measures.containsKey(str); }).map(str -> { Set<Map.Entry<String, Measure>> entry = oriCube.getMeasures().entrySet(); for (Map.Entry<String, Measure> tmp : entry) { if (str.equals(tmp.getValue().getName())) { return tmp.getValue(); } } return null; }).forEach(m -> { if (m != null) { measures.put(m.getName(), m); } }); }
From source file:io.brooklyn.camp.brooklyn.spi.dsl.methods.BrooklynDslCommon.java
/** * Return an instance of the specified class with its fields set according * to the {@link Map} or a {@link BrooklynDslDeferredSupplier} if the arguments are not * yet fully resolved.//from w w w. j av a 2 s.co m */ @SuppressWarnings("unchecked") public static Object object(Map<String, Object> arguments) { ConfigBag config = ConfigBag.newInstance(arguments); String typeName = BrooklynYamlTypeInstantiator.InstantiatorFromKey.extractTypeName("object", config) .orNull(); Map<String, Object> objectFields = (Map<String, Object>) config.getStringKeyMaybe("object.fields") .or(MutableMap.of()); Map<String, Object> brooklynConfig = (Map<String, Object>) config.getStringKeyMaybe("brooklyn.config") .or(MutableMap.of()); try { // TODO Should use catalog's classloader, rather than Class.forName; how to get that? Should we return a future?! Class<?> type = Class.forName(typeName); if (!Reflections.hasNoArgConstructor(type)) { throw new IllegalStateException( String.format("Cannot construct %s bean: No public no-arg constructor available", type)); } if ((objectFields.isEmpty() || DslUtils.resolved(objectFields.values())) && (brooklynConfig.isEmpty() || DslUtils.resolved(brooklynConfig.values()))) { return DslObject.create(type, objectFields, brooklynConfig); } else { return new DslObject(type, objectFields, brooklynConfig); } } catch (ClassNotFoundException e) { throw Exceptions.propagate(e); } }