List of usage examples for java.util Map entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:com.ocs.dynamo.ui.ServiceLocator.java
/** * Returns a service that is used to manage a certain type of entity * //from w w w . j av a 2 s . c o m * @param entityClass * the entity class * @return */ @SuppressWarnings("rawtypes") public static <T> BaseService<?, ?> getServiceForEntity(Class<T> entityClass) { Map<String, BaseService> services = getContext().getBeansOfType(BaseService.class, false, true); for (Entry<String, BaseService> e : services.entrySet()) { if (e.getValue().getEntityClass() != null && e.getValue().getEntityClass().equals(entityClass)) { return (BaseService<?, ?>) e.getValue(); } } return null; }
From source file:com.github.fge.jsonschema.NewAPIPerfTest.java
private static void doValidate(final Map<String, JsonNode> schemas, final int i) throws ProcessingException { String name;//www.ja va 2s. c o m JsonNode value; ProcessingReport report; for (final Map.Entry<String, JsonNode> entry : schemas.entrySet()) { name = entry.getKey(); value = entry.getValue(); report = SCHEMA.validate(value); if (!report.isSuccess()) { System.err.println("ERROR: schema " + name + " did not " + "validate (iteration " + i + ')'); System.exit(1); } } }
From source file:com.netflix.aegisthus.tools.AegisthusSerializer.java
protected static void serializeColumns(StringBuilder sb, Map<String, Object> columns) { int count = 0; for (Map.Entry<String, Object> e : columns.entrySet()) { if (count++ > 0) { sb.append(", "); }/*from w w w.j av a 2s . c om*/ @SuppressWarnings("unchecked") List<Object> list = (List<Object>) e.getValue(); sb.append("["); sb.append("\"").append(((String) list.get(0)).replace("\\", "\\\\").replace("\"", "\\\"")).append("\"") .append(","); sb.append("\"").append(list.get(1)).append("\"").append(","); sb.append(list.get(2)); if (list.size() > 3) { sb.append(",").append("\"").append(list.get(3)).append("\""); } for (int i = 4; i < list.size(); i++) { sb.append(",").append(list.get(i)); } sb.append("]"); } }
From source file:net.adamcin.commons.testing.sling.RequestBuilderUtil.java
/** * Transforms a {@code Map} of properties into a multipart params entity * @param entity the entity to add the property values to * @param props a map of String properties * @throws UnsupportedEncodingException//w w w. ja v a 2 s . c om */ public static void setMultipartParamsFromProps(MultipartEntity entity, Map<String, Object> props) throws UnsupportedEncodingException { if (entity != null) { if (props != null) { for (Map.Entry<String, Object> e : props.entrySet()) { entity.addPart(e.getKey(), new StringBody(e.getValue().toString())); } } } }
From source file:com.microsoft.rest.Validator.java
/** * Validates a user provided required parameter to be not null. * A {@link ServiceException} is thrown if a property fails the validation. * * @param parameter the parameter to validate * @throws ServiceException failures wrapped in {@link ServiceException} *///from w w w. j a va 2 s . c o m public static void validate(Object parameter) throws ServiceException { // Validation of top level payload is done outside if (parameter == null) { return; } Class parameterType = parameter.getClass(); if (ClassUtils.isPrimitiveOrWrapper(parameterType) || parameterType.isEnum() || ClassUtils.isAssignable(parameterType, LocalDate.class) || ClassUtils.isAssignable(parameterType, DateTime.class) || ClassUtils.isAssignable(parameterType, String.class) || ClassUtils.isAssignable(parameterType, DateTimeRfc1123.class) || ClassUtils.isAssignable(parameterType, Period.class)) { return; } Field[] fields = FieldUtils.getAllFields(parameterType); for (Field field : fields) { field.setAccessible(true); JsonProperty annotation = field.getAnnotation(JsonProperty.class); Object property; try { property = field.get(parameter); } catch (IllegalAccessException e) { throw new ServiceException(e); } if (property == null) { if (annotation != null && annotation.required()) { throw new ServiceException( new IllegalArgumentException(field.getName() + " is required and cannot be null.")); } } else { try { Class propertyType = property.getClass(); if (ClassUtils.isAssignable(propertyType, List.class)) { List<?> items = (List<?>) property; for (Object item : items) { Validator.validate(item); } } else if (ClassUtils.isAssignable(propertyType, Map.class)) { Map<?, ?> entries = (Map<?, ?>) property; for (Map.Entry<?, ?> entry : entries.entrySet()) { Validator.validate(entry.getKey()); Validator.validate(entry.getValue()); } } else if (parameter.getClass().getDeclaringClass() != propertyType) { Validator.validate(property); } } catch (ServiceException ex) { IllegalArgumentException cause = (IllegalArgumentException) (ex.getCause()); if (cause != null) { // Build property chain throw new ServiceException( new IllegalArgumentException(field.getName() + "." + cause.getMessage())); } else { throw ex; } } } } }
From source file:Main.java
public static List join(Map map, String separator) { if (map == null) return null; List list = new ArrayList(); if (map == null || map.size() == 0) return list; for (Iterator i$ = map.entrySet().iterator(); i$.hasNext();) { java.util.Map.Entry entry = (java.util.Map.Entry) i$.next(); String key = (String) entry.getKey(); String value = (String) entry.getValue(); if (value == null || value.length() == 0) list.add(key);/*www . j a v a 2s. c om*/ else list.add((new StringBuilder()).append(key).append(separator).append(value).toString()); } return list; }
From source file:Main.java
/** * Add an opening tag for an element in a XML document buffer * * @param strXmlBuffer/*from w ww . j a v a 2 s.c o m*/ * The XML document buffer * @param strTag * The tag name of the element to add * @param attrList * The attributes list */ public static void beginElement(StringBuffer strXmlBuffer, String strTag, Map<?, ?> attrList) { strXmlBuffer.append(TAG_BEGIN); strXmlBuffer.append(strTag); if (attrList != null) { for (Entry<?, ?> entry : attrList.entrySet()) { String code = (String) entry.getKey(); strXmlBuffer.append( TAG_SEPARATOR + code + TAG_ASSIGNMENT + TAG_ENCLOSED + entry.getValue() + TAG_ENCLOSED); } } strXmlBuffer.append(TAG_END); }
From source file:at.wada811.android.library.demos.CrashExceptionHandler.java
/** * Preferences?// w w w . j a va 2 s. c om * * @return * @throws JSONException */ private static JSONObject getPreferencesInfo(Context context) { SharedPreferences preferences = PreferenceUtils.getDefaultSharedPreferences(context); JSONObject json = new JSONObject(); Map<String, ?> map = preferences.getAll(); for (Entry<String, ?> entry : map.entrySet()) { try { json.put(entry.getKey(), entry.getValue()); } catch (JSONException e) { e.printStackTrace(); } } return json; }
From source file:Main.java
public static <K, V> String toString(Map<K, V> paramMap) { if (paramMap == null) return ""; if (paramMap.isEmpty()) return "{}"; StringBuilder localStringBuilder = new StringBuilder(); Iterator localIterator = paramMap.entrySet().iterator(); while (localIterator.hasNext()) { Map.Entry localEntry = (Map.Entry) localIterator.next(); Object[] arrayOfObject = new Object[2]; arrayOfObject[0] = localEntry.getKey().toString(); arrayOfObject[1] = localEntry.getValue().toString(); localStringBuilder.append(String.format(", %s -> %s ", arrayOfObject)); }/*from ww w . j a v a 2 s .c om*/ return "{" + localStringBuilder.substring(1) + "}"; }
From source file:Main.java
/** * Creates a new sorted map, based on the values from the given map and Comparator. * /* www . ja v a 2s.c o m*/ * @param map the map which needs to be sorted * @param valueComparator the Comparator * @return a new sorted map */ public static <K, V> Map<K, V> sortMapByValue(Map<K, V> map, Comparator<Entry<K, V>> valueComparator) { if (map == null) { return Collections.emptyMap(); } List<Entry<K, V>> entriesList = new LinkedList<>(map.entrySet()); // Sort based on the map's values Collections.sort(entriesList, valueComparator); Map<K, V> orderedMap = new LinkedHashMap<>(entriesList.size()); for (Entry<K, V> entry : entriesList) { orderedMap.put(entry.getKey(), entry.getValue()); } return orderedMap; }