List of usage examples for java.util LinkedHashMap keySet
public Set<K> keySet()
From source file:com.hp.saas.agm.service.EntityService.java
private String orderToString(EntityQuery query) { StringBuffer buf = new StringBuffer(); LinkedHashMap<String, SortOrder> order = query.getOrder(); for (String name : order.keySet()) { if (buf.length() > 0) { buf.append("; "); }/*www .java 2 s . co m*/ buf.append(name); buf.append("["); buf.append(order.get(name) == SortOrder.ASCENDING ? "ASC" : "DESC"); buf.append("]"); } return buf.toString(); }
From source file:com.smhumayun.mi_plus.impl.MIMethodResolverImpl.java
/** * Resolve method based on following strategy: * - Iterate over composed objects (order will be the same as defined in {@link com.smhumayun.mi_plus.MISupport} * - For each composed object, check if there's a matching 'accessible' method based on the algorithm defined by * {@link MethodUtils#getAccessibleMethod(Class, String, Class[])} i.e. it finds an accessible method that matches * the given name and has compatible parameters. Compatible parameters mean that every method parameter is * assignable from the given parameters. In other words, it finds a method with the given name that will take the * parameters given./* ww w . j av a 2s . c om*/ * - If a match is found, break the iteration and exit from the loop; * - Return the corresponding composed object and the matched method * * @param miContainerClass MI Container class * @param composedObjects map of composed objects * @param methodCall method call made on Proxy * @param methodCallArgs method call arguments * @return resolved target method and object * @throws com.smhumayun.mi_plus.MIException {@link com.smhumayun.mi_plus.MIException} */ public Pair<Object, Method> resolve(Class miContainerClass, LinkedHashMap<Class, Object> composedObjects, Method methodCall, Object[] methodCallArgs) throws MIException { logger.info("resolve " + methodCall.toGenericString()); Class[] methodCallArgsClasses = utils.getClasses(methodCallArgs); logger.fine("methodCallArgs classes = " + Arrays.toString(methodCallArgsClasses)); Object targetObject = null; Method targetMethod = null; for (Class composedObjectClass : composedObjects.keySet()) { try { targetMethod = MethodUtils.getMatchingAccessibleMethod(composedObjectClass, methodCall.getName(), methodCallArgsClasses); if (targetMethod != null) { logger.info("matching method found! " + targetMethod.toGenericString()); targetObject = composedObjects.get(composedObjectClass); break; } } catch (Exception e) { /* SWALLOW */ } } //if not found if (targetMethod == null) //throw exception throw new UnsupportedOperationException("method '" + methodCall.toGenericString() + "' not found"); //else return the target object and method to caller return new Pair<Object, Method>(targetObject, targetMethod); }
From source file:com.hp.alm.ali.idea.services.EntityService.java
private String queryToString(EntityQuery query) { ServerStrategy cust = restService.getServerStrategy(); EntityQuery clone = cust.preProcess(query.clone()); StringBuffer buf = new StringBuffer(); buf.append("fields="); LinkedHashMap<String, Integer> columns = clone.getColumns(); buf.append(StringUtils.join(columns.keySet().toArray(new String[columns.size()]), ",")); buf.append("&query="); buf.append(EntityQuery//from w w w . j av a2 s . c om .encode("{" + filterToString(clone, project, project.getComponent(MetadataService.class)) + "}")); buf.append("&order-by="); buf.append(EntityQuery.encode("{" + orderToString(clone) + "}")); if (query.getPageSize() != null) { buf.append("&page-size="); buf.append(query.getPageSize()); } if (query.getStartIndex() != null) { buf.append("&start-index="); buf.append(query.getStartIndex()); } return buf.toString(); }
From source file:edu.jhuapl.openessence.web.util.ControllerUtils.java
public static LinkedHashMap<String, ChartData> getSortedAndLimitedChartDataMap( LinkedHashMap<String, ChartData> map, Integer limit, String limitLabel) { //test if we need to trim if (limit <= 0 || limit >= map.size()) { return map; }//from w w w . ja v a 2 s. c o m //sort by value Map<String, ChartData> sortedMap = ControllerUtils.getSortedByChartDataMap(map); //limit and combine results Map<String, ChartData> sortedLimitedMap = ControllerUtils.getLimitedChartDataMap(sortedMap, limit, limitLabel); //put the original sort order back (minus the values combined) LinkedHashMap<String, ChartData> originalSortResultMap = new LinkedHashMap<String, ChartData>(limit); LinkedHashMap<String, ChartData> passedValuesMap = new LinkedHashMap<String, ChartData>(map.size()); int i = 0; for (String key : map.keySet()) { if (i < limit) { if (sortedLimitedMap.containsKey(key)) { ChartData value = sortedLimitedMap.get(key); //if value is not null/zero, add it and increment if (value != null && value.getCount() != null && !Double.isNaN(value.getCount()) && value.getCount() > 0) { originalSortResultMap.put(key, value); i++; } else { //put it in a list of passed up values for inclusion at the end passedValuesMap.put(key, value); } } } } //if we still have room after adding all sorted non zero values... fill the rest with passed values if (i < limit) { for (String key : passedValuesMap.keySet()) { if (i < limit) { originalSortResultMap.put(key, passedValuesMap.get(key)); i++; } } } //add combined field if it is not null (indicates it was used even if the value is 0) ChartData cVal = sortedLimitedMap.get(limitLabel); if (cVal != null && cVal.getCount() != null && !Double.isNaN(cVal.getCount())) { originalSortResultMap.put(limitLabel, cVal); } return originalSortResultMap; }
From source file:jp.primecloud.auto.api.ApiFilter.java
/** * * URI(Signature????)?// w ww .ja va 2s . c om * * @param decodeParamMap base64?? * @param uri URI() * @return ???URL(Signature????) */ private String createUriQueryParams(LinkedHashMap<String, String> decodeParamMap, URI uri) { String baseUriText = uri.getScheme() + "://" + uri.getAuthority() + uri.getPath() + "?"; StringBuffer uriText = new StringBuffer(baseUriText); String splitChar = ""; for (String key : decodeParamMap.keySet()) { if (PARAM_NAME_SIGNATURE.equals(key) == false) { uriText.append(splitChar + key + "=" + decodeParamMap.get(key)); splitChar = "&"; } } return uriText.toString(); }
From source file:com.redhat.rcm.version.Cli.java
private static String formatHelpMap(final LinkedHashMap<String, Object> map, final String itemSeparator) { final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); final int max = maxKeyLength(map.keySet()); final int descMax = 75 - max; final String fmt = "%-" + max + "s %-" + descMax + "s" + itemSeparator; for (final Map.Entry<String, Object> entry : map.entrySet()) { final String key = entry.getKey(); final String description = entry.getValue() == null ? "-NONE-" : String.valueOf(entry.getValue()); printKVLine(key, description, fmt, descMax, pw); }//w w w . j a v a 2 s. com return sw.toString(); }
From source file:com.hp.saas.agm.service.EntityService.java
private String queryToString(EntityQuery query) { ServerStrategy cust = restService.getServerStrategy(); EntityQuery clone = cust.preProcess(query.clone()); StringBuffer buf = new StringBuffer(); buf.append("fields="); LinkedHashMap<String, Integer> columns = clone.getColumns(); buf.append(TextUtils.join(",", columns.keySet().toArray(new String[columns.size()]))); buf.append("&query="); buf.append(EntityQuery.encode("{" + filterToString(clone, ApplicationManager.getMetadataService()) + "}")); buf.append("&order-by="); buf.append(EntityQuery.encode("{" + orderToString(clone) + "}")); if (query.getPageSize() != null) { buf.append("&page-size="); buf.append(query.getPageSize()); }//from ww w. j a va 2 s . c o m if (query.getStartIndex() != null) { buf.append("&start-index="); buf.append(query.getStartIndex()); } return buf.toString(); }
From source file:com.smartbear.collab.client.Client.java
public JsonrpcResponse sendRequest(List<JsonrpcCommand> methods) { JsonrpcResponse result = new JsonrpcResponse(); List<LinkedHashMap<String, LinkedHashMap<String, String>>> results = new ArrayList<LinkedHashMap<String, LinkedHashMap<String, String>>>(); ObjectMapper mapper = new ObjectMapper(); try {/* ww w . j a va 2s .c om*/ logger.info(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(methods)); } catch (JsonProcessingException jpe) { } results = target.request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity(methods, MediaType.APPLICATION_JSON_TYPE), List.class); try { logger.info(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(results)); } catch (JsonProcessingException jpe) { } List<JsonrpcCommandResponse> commandResponses = new ArrayList<JsonrpcCommandResponse>(); for (LinkedHashMap commandResultMap : results) { JsonrpcCommandResponse commandResponse = new JsonrpcCommandResponse(); if (commandResultMap.get("result") != null) { JsonrpcResult commandResult = new JsonrpcResult(); LinkedHashMap<String, String> commandResultValue = (LinkedHashMap<String, String>) commandResultMap .get("result"); if (commandResultValue.size() > 0) { commandResult.setCommand(commandResultValue.keySet().iterator().next()); commandResult.setValue(commandResultValue.get(commandResult.getCommand())); commandResponse.setResult(commandResult); } } if (commandResultMap.get("errors") != null) { List<LinkedHashMap<String, String>> errors = (List<LinkedHashMap<String, String>>) commandResultMap .get("errors"); List<JsonrpcError> jsonrpcErrors = new ArrayList<JsonrpcError>(); for (LinkedHashMap<String, String> error : errors) { JsonrpcError jsonrpcError = new JsonrpcError(); jsonrpcError.setCode(error.get("code")); jsonrpcError.setMessage(error.get("message")); jsonrpcErrors.add(jsonrpcError); } commandResponse.setErrors(jsonrpcErrors); } commandResponses.add(commandResponse); } result.setResults(commandResponses); return result; }
From source file:biz.netcentric.cq.tools.actool.configReader.YamlConfigReader.java
private Collection getConfigSection(final String sectionName, final Collection yamlList) { final List<LinkedHashMap<?, ?>> yamList = new ArrayList<LinkedHashMap<?, ?>>(yamlList); for (final LinkedHashMap<?, ?> currMap : yamList) { if (sectionName.equals(currMap.keySet().iterator().next())) { return (List<LinkedHashMap>) currMap.get(sectionName); }/*w w w. j a va2s . com*/ } return null; }
From source file:com.streamsets.pipeline.stage.lib.hive.HiveQueryExecutor.java
/** * Returns {@link Pair} of Column Type Info and Partition Type Info. * @param qualifiedTableName qualified table name. * @return {@link Pair} of Column Type Info and Partition Type Info. * @throws StageException in case of any {@link SQLException} *///from ww w .j a v a 2 s.c o m public Pair<LinkedHashMap<String, HiveType>, LinkedHashMap<String, HiveType>> executeDescTableQuery( String qualifiedTableName) throws StageException { String sql = buildDescTableQuery(qualifiedTableName); LOG.debug("Executing SQL:", sql); Statement statement = null; try (Connection con = DriverManager.getConnection(jdbcUrl)) { statement = con.createStatement(); ResultSet rs = statement.executeQuery(sql); LinkedHashMap<String, HiveType> columnTypeInfo = extractTypeInfo(rs); processDelimiter(rs, "#"); processDelimiter(rs, "#"); processDelimiter(rs, ""); LinkedHashMap<String, HiveType> partitionTypeInfo = extractTypeInfo(rs); //Remove partition columns from the columns map. for (String partitionCol : partitionTypeInfo.keySet()) { columnTypeInfo.remove(partitionCol); } return Pair.of(columnTypeInfo, partitionTypeInfo); } catch (SQLException e) { LOG.error("SQL Exception happened when adding partition", e); throw new StageException(Errors.HIVE_20, sql, e.getMessage()); } finally { closeStatement(statement); } }