List of usage examples for java.util Map.Entry get
V get(Object key);
From source file:org.apereo.portal.persondir.LocalAccountPersonAttributeDao.java
protected LocalAccountQuery generateQuery(Map<String, List<Object>> query) { LocalAccountQuery queryBuilder = new LocalAccountQuery(); String userNameAttribute = this.getConfiguredUserNameAttribute(); for (final Map.Entry<String, List<Object>> queryEntry : query.entrySet()) { String attrName = queryEntry.getKey(); if (userNameAttribute.equals(attrName)) { String value = queryEntry.getValue().get(0).toString(); queryBuilder.setUserName(value); } else {//from w w w . j av a2s . c om List<String> values = new ArrayList<String>(); for (Object o : queryEntry.getValue()) { values.add(o.toString()); } queryBuilder.setAttribute(attrName, values); } } if (this.logger.isDebugEnabled()) { this.logger.debug("Generated query builder '" + queryBuilder + "' from query Map " + query + "."); } return queryBuilder; }
From source file:keel.Algorithms.UnsupervisedLearning.AssociationRules.Visualization.keelassotiationrulesboxplot.ResultsProccessor.java
public void writeToFile(String outName) throws FileNotFoundException, UnsupportedEncodingException, IOException { //calcMeans(); // Create JFreeChart Dataset DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); HashMap<String, ArrayList<Double>> measuresFirst = algorithmMeasures.entrySet().iterator().next() .getValue();/*from w ww. j a v a 2 s .com*/ for (Map.Entry<String, ArrayList<Double>> measure : measuresFirst.entrySet()) { String measureName = measure.getKey(); //Double measureValue = measure.getValue(); dataset.clear(); for (Map.Entry<String, HashMap<String, ArrayList<Double>>> entry : algorithmMeasures.entrySet()) { String alg = entry.getKey(); ArrayList<Double> measureValues = entry.getValue().get(measureName); // Parse algorithm name to show it correctly String aName = alg.substring(0, alg.length() - 1); int startAlgName = aName.lastIndexOf("/"); aName = aName.substring(startAlgName + 1); dataset.add(measureValues, aName, measureName); } // Tutorial: http://www.java2s.com/Code/Java/Chart/JFreeChartBoxAndWhiskerDemo.htm final CategoryAxis xAxis = new CategoryAxis("Algorithm"); final NumberAxis yAxis = new NumberAxis("Value"); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); // Black and White int numItems = algorithmMeasures.size(); for (int i = 0; i < numItems; i++) { Color color = Color.DARK_GRAY; if (i % 2 == 1) { color = Color.LIGHT_GRAY; } renderer.setSeriesPaint(i, color); renderer.setSeriesOutlinePaint(i, Color.BLACK); } renderer.setMeanVisible(false); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("SansSerif", Font.BOLD, 10); //ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jchart = new JFreeChart("Assotiation Rules Measures - BoxPlot", font, plot, true); //StandardChartTheme.createLegacyTheme().apply(jchart); int width = 640 * 2; /* Width of the image */ int height = 480 * 2; /* Height of the image */ // JPEG File chart = new File(outName + "_" + measureName + "_boxplot.jpg"); ChartUtilities.saveChartAsJPEG(chart, jchart, width, height); // SVG SVGGraphics2D g2 = new SVGGraphics2D(width, height); Rectangle r = new Rectangle(0, 0, width, height); jchart.draw(g2, r); File BarChartSVG = new File(outName + "_" + measureName + "_boxplot.svg"); SVGUtils.writeToSVG(BarChartSVG, g2.getSVGElement()); } }
From source file:cc.kave.episodes.mining.evaluation.Evaluation.java
private void getTargetResults(int targetID, Episode target) { TargetResults episodeResults = new TargetResults(); episodeResults.setTarget(target);// w w w .j a v a 2 s . c o m sb.append("Target query " + targetID + "\t"); for (Map.Entry<Double, List<Averager>> entry : avgQueryProposal.entrySet()) { sb.append(MathUtils.round(entry.getKey(), 2) + ": [ "); for (int p = 0; p < PROPOSALS; p++) { double qp = entry.getValue().get(p).average(); if (qp > 0.0) { double tp = avgTargetProposal.get(entry.getKey()).get(p).average(); episodeResults.addResult(entry.getKey(), qp, tp); sb.append("<" + MathUtils.round(qp, 2) + ", " + MathUtils.round(tp, 2) + ">; "); } } sb.append("]\t"); } sb.append(target.getNumEvents() - 1 + "\n"); results.add(episodeResults); }
From source file:com.flipkart.foxtrot.core.parsers.ElasticsearchMappingParser.java
private Set<FieldTypeMapping> generateFieldMappings(String parentField, JsonNode jsonNode) { Set<FieldTypeMapping> fieldTypeMappings = new HashSet<FieldTypeMapping>(); Iterator<Map.Entry<String, JsonNode>> iterator = jsonNode.fields(); while (iterator.hasNext()) { Map.Entry<String, JsonNode> entry = iterator.next(); if (entry.getKey().equals(ElasticsearchUtils.DOCUMENT_META_FIELD_NAME)) { continue; }/*www . j ava 2 s . c o m*/ String currentField = (parentField == null) ? entry.getKey() : (String.format("%s.%s", parentField, entry.getKey())); if (entry.getValue().has("properties")) { fieldTypeMappings.addAll(generateFieldMappings(currentField, entry.getValue().get("properties"))); } else { FieldType fieldType = getFieldType(entry.getValue().get("type")); fieldTypeMappings.add(new FieldTypeMapping(currentField, fieldType)); } } return fieldTypeMappings; }
From source file:com.virtlink.commons.configuration2.jackson.JacksonConfiguration.java
/** * Gets a serialization object from a node. * * @param node The node.//from www . j a v a 2 s. c om * @return The object representing the node. */ private Object fromNode(final ImmutableNode node) { if (!node.getChildren().isEmpty()) { final Map<String, List<ImmutableNode>> children = getChildrenWithName(node); final HashMap<String, Object> map = new HashMap<>(); for (final Map.Entry<String, List<ImmutableNode>> entry : children.entrySet()) { assert !entry.getValue().isEmpty(); if (entry.getValue().size() == 1) { // Just one node. final ImmutableNode child = entry.getValue().get(0); final Object childValue = fromNode(child); map.put(entry.getKey(), childValue); } else { // Multiple nodes. final ArrayList<Object> list = new ArrayList<>(); for (final ImmutableNode child : entry.getValue()) { final Object childValue = fromNode(child); list.add(childValue); } map.put(entry.getKey(), list); } } return map; } else { return node.getValue(); } }
From source file:com.kakao.hbase.common.Args.java
@Override public String toString() { if (optionSet == null) return ""; String nonOptionArgs = ""; if (optionSet.nonOptionArguments() != null) { int i = 0; for (Object object : optionSet.nonOptionArguments()) { if (i > 0) nonOptionArgs += " "; nonOptionArgs += "\"" + object.toString() + "\""; i++;// w ww . jav a2 s. co m } } String optionArgs = ""; if (optionSet.asMap() != null) { int i = 0; for (Map.Entry<OptionSpec<?>, List<?>> entry : optionSet.asMap().entrySet()) { if (entry.getValue().size() > 0) { if (i > 0) optionArgs += " "; optionArgs += "--" + entry.getKey().options().get(0) + "=\"" + entry.getValue().get(0) + "\""; i++; } } } return nonOptionArgs + " " + optionArgs; }
From source file:com.netflix.simianarmy.resources.chaos.ChaosMonkeyResource.java
/** * Gets the chaos events. Creates GET /api/v1/chaos api which outputs the chaos events in json. Users can specify * cgi query params to filter the results and use "since" query param to set the start of a timerange. "since" will * number of milliseconds since the epoch. * * @param uriInfo//w ww . java 2 s. c om * the uri info * @return the chaos events json response * @throws IOException * Signals that an I/O exception has occurred. */ @GET public Response getChaosEvents(@Context UriInfo uriInfo) throws IOException { Map<String, String> query = new HashMap<String, String>(); Date date = null; for (Map.Entry<String, List<String>> pair : uriInfo.getQueryParameters().entrySet()) { if (pair.getValue().isEmpty()) { continue; } if (pair.getKey().equals("since")) { date = new Date(Long.parseLong(pair.getValue().get(0))); } else { query.put(pair.getKey(), pair.getValue().get(0)); } } // if "since" not set, default to 24 hours ago if (date == null) { Calendar now = monkey.context().calendar().now(); now.add(Calendar.DAY_OF_YEAR, -1); date = now.getTime(); } List<Event> evts = monkey.context().recorder().findEvents(ChaosMonkey.Type.CHAOS, ChaosMonkey.EventTypes.CHAOS_TERMINATION, query, date); ByteArrayOutputStream baos = new ByteArrayOutputStream(); JsonGenerator gen = JSON_FACTORY.createJsonGenerator(baos, JsonEncoding.UTF8); gen.writeStartArray(); for (Event evt : evts) { gen.writeStartObject(); gen.writeStringField("monkeyType", evt.monkeyType().name()); gen.writeStringField("eventType", evt.eventType().name()); gen.writeNumberField("eventTime", evt.eventTime().getTime()); gen.writeStringField("region", evt.region()); for (Map.Entry<String, String> pair : evt.fields().entrySet()) { gen.writeStringField(pair.getKey(), pair.getValue()); } gen.writeEndObject(); } gen.writeEndArray(); gen.close(); return Response.status(Response.Status.OK).entity(baos.toString("UTF-8")).build(); }
From source file:org.jpublish.module.restpathactions.RestPathAction.java
public void execute(JPublishContext context, Configuration configuration) throws Exception { String method = context.getRequest().getMethod(); // no need .toUpperCase() it String pathInfo = GENERIC_PATH_INFO; boolean resourceNotFound = true; try {/*from w ww .j a va 2 s. c o m*/ pathInfo = context.getRequest().getPathInfo(); String path = pathInfo.replaceFirst(modulePath, EMPTY_STRING); if (module.isProfiling()) { UtilTimerStack.push(pathInfo); } for (RestPathActionModel rm : module.getRestModels()) { final UriTemplateMatcher matcher = rm.matcher(); boolean methodMatchesToo = rm.getMethods() != null && rm.getMethods().contains(method); if (matcher.matches(path) && methodMatchesToo) { resourceNotFound = false; if (module.isDebug()) { log.info(matcher.toString()); } MultivaluedMap<String, String> multivaluedMap = matcher.getVariables(true); for (Map.Entry<String, List<String>> entry : multivaluedMap.entrySet()) { if (entry.getValue() != null) { context.put(entry.getKey(), entry.getValue().size() > 1 ? entry.getValue() : entry.getValue().get(0)); } } module.execute(rm.getAction(), context, rm.getConfiguration()); String content = null; final String pagePath = rm.getPage(); String viewType = rm.getContentType(); if (pagePath != null) { RepositoryWrapper repository = (RepositoryWrapper) context .get(module.getDefaultRepository()); viewType = PathUtilities.extractPageType(pagePath); if (repository != null) { content = repository.get(pagePath); } } if (content == null) { content = (String) context.get(RestPathActionsModule.RESPONSE); } HttpServletResponse response = context.getResponse(); if (content != null && response != null) { InputStream in; if (content == null) { content = EMPTY_STRING; } String callback = context.getRequest().getParameter(module.getCallbackParameter()); if (method.equalsIgnoreCase("get") && callback != null) { //experimental code content = String.format("%s( %s)", callback, content); } in = new ByteArrayInputStream(content.getBytes( module.getSite().getCharacterEncodingManager().getMap(path).getResponseEncoding())); setResponseContentType(context, path, viewType); long contentLength = FileCopyUtils.copy(in, response.getOutputStream()); response.setContentLength((int) contentLength); } break; } } if (resourceNotFound) { if (module.isDebug()) { log.info(String.format("%s not found;", pathInfo)); } context.getResponse().setStatus(HttpServletResponse.SC_NOT_FOUND); } } finally { context.setStopProcessing(); if (module.isProfiling()) { UtilTimerStack.pop(pathInfo); } } }
From source file:org.alfresco.rest.framework.tools.ResponseWriter.java
/** * The response status must be set before the response is written by Jackson (which will by default close and commit the response). * In a r/w txn, web script buffered responses ensure that it doesn't really matter but for r/o txns this is important. * If you set content information via the contentInfo object and ALSO the headers then "headers" will win because they are * set last.//from ww w .j av a 2 s .co m * * @param res * @param status * @param cache * @param contentInfo * @param headers */ default void setResponse(final WebScriptResponse res, int status, Cache cache, ContentInfo contentInfo, Map<String, List<String>> headers) { res.setStatus(status); if (cache != null) res.setCache(cache); setContentInfoOnResponse(res, contentInfo); if (headers != null && !headers.isEmpty()) { for (Map.Entry<String, List<String>> header : headers.entrySet()) { for (int i = 0; i < header.getValue().size(); i++) { if (i == 0) { //If its the first one then set the header overwriting. res.setHeader(header.getKey(), header.getValue().get(i)); } else { //If its not the first one than update the header res.addHeader(header.getKey(), header.getValue().get(i)); } } } } }
From source file:org.yes.cart.service.vo.impl.VoShippingServiceImpl.java
@Override public void fillShopSummaryDetails(final VoShopSummary summary, final long shopId, final String lang) throws Exception { if (federationFacade.isShopAccessibleByCurrentManager(summary.getShopId())) { final Map<CarrierDTO, Boolean> all = dtoCarrierService.findAllByShopId(shopId); for (final Map.Entry<CarrierDTO, Boolean> dto : all.entrySet()) { String name = dto.getKey().getName(); if (MapUtils.isNotEmpty(dto.getKey().getDisplayNames()) && dto.getKey().getDisplayNames().get(lang) != null) { name = dto.getKey().getDisplayNames().get(lang); }/* ww w . j ava2 s. c o m*/ summary.getCarriers().add(MutablePair.of(name, dto.getValue())); } } else { throw new AccessDeniedException("Access is denied"); } }