List of usage examples for java.util LinkedHashMap LinkedHashMap
public LinkedHashMap()
From source file:org.grails.plugins.elasticsearch.mapping.ElasticSearchMappingFactory.java
public static Map<String, Object> getElasticMapping(SearchableClassMapping scm) { Map<String, Object> elasticTypeMappingProperties = new LinkedHashMap<String, Object>(); if (!scm.isAll()) { // "_all" : {"enabled" : true} elasticTypeMappingProperties.put("_all", Collections.singletonMap("enabled", false)); }// ww w . j a v a 2s.co m // Map each domain properties in supported format, or object for complex type for (SearchableClassPropertyMapping scpm : scm.getPropertiesMapping()) { // Does it have custom mapping? String propType = scpm.getGrailsProperty().getTypePropertyName(); Map<String, Object> propOptions = new LinkedHashMap<String, Object>(); // Add the custom mapping (searchable static property in domain model) propOptions.putAll(scpm.getAttributes()); if (!(SUPPORTED_FORMAT.contains(scpm.getGrailsProperty().getTypePropertyName()))) { // Handle embedded persistent collections, ie List<String> listOfThings if (scpm.getGrailsProperty().isBasicCollectionType()) { String basicType = ClassUtils.getShortName(scpm.getGrailsProperty().getReferencedPropertyType()) .toLowerCase(Locale.ENGLISH); if (SUPPORTED_FORMAT.contains(basicType)) { propType = basicType; } // Handle arrays } else if (scpm.getGrailsProperty().getReferencedPropertyType().isArray()) { String basicType = ClassUtils .getShortName(scpm.getGrailsProperty().getReferencedPropertyType().getComponentType()) .toLowerCase(Locale.ENGLISH); if (SUPPORTED_FORMAT.contains(basicType)) { propType = basicType; } } else if (isDateType(scpm.getGrailsProperty().getReferencedPropertyType())) { propType = "date"; } else if (GrailsClassUtils.isJdk5Enum(scpm.getGrailsProperty().getReferencedPropertyType())) { propType = "string"; } else if (scpm.getConverter() != null) { // Use 'string' type for properties with custom converter. // Arrays are automatically resolved by ElasticSearch, so no worries. propType = "string"; } else { propType = "object"; } if (scpm.getReference() != null) { propType = "object"; // fixme: think about composite ids. } else if (scpm.isComponent()) { // Proceed with nested mapping. // todo limit depth to avoid endless recursion? propType = "object"; //noinspection unchecked propOptions.putAll((Map<String, Object>) (getElasticMapping(scpm.getComponentPropertyMapping()) .values().iterator().next())); } // Once it is an object, we need to add id & class mappings, otherwise // ES will fail with NullPointer. if (scpm.isComponent() || scpm.getReference() != null) { @SuppressWarnings({ "unchecked" }) Map<String, Object> props = (Map<String, Object>) propOptions.get("properties"); if (props == null) { props = new LinkedHashMap<String, Object>(); propOptions.put("properties", props); } props.put("id", defaultDescriptor("long", "not_analyzed", true)); props.put("class", defaultDescriptor("string", "no", true)); props.put("ref", defaultDescriptor("string", "no", true)); } } propOptions.put("type", propType); // See http://www.elasticsearch.com/docs/elasticsearch/mapping/all_field/ if (!propType.equals("object") && scm.isAll()) { // does it make sense to include objects into _all? if (scpm.shouldExcludeFromAll()) { propOptions.put("include_in_all", false); } else { propOptions.put("include_in_all", true); } } // todo only enable this through configuration... if (propType.equals("string") && scpm.isAnalyzed()) { propOptions.put("term_vector", "with_positions_offsets"); } elasticTypeMappingProperties.put(scpm.getPropertyName(), propOptions); } Map<String, Object> mapping = new LinkedHashMap<String, Object>(); mapping.put(scm.getElasticTypeName(), Collections.singletonMap("properties", elasticTypeMappingProperties)); return mapping; }
From source file:gov.nih.nci.cabig.caaers.web.fields.InputFieldGroupMap.java
public InputFieldGroupMap() { super(new LinkedHashMap<String, InputFieldGroup>(), new RepeatingFieldGroupTransformer()); }
From source file:com.none.tom.simplerssreader.utils.SearchUtils.java
public static LinkedHashMap<Integer, Integer> getIndicesForQuery(final String str, final String query) { final LinkedHashMap<Integer, Integer> indices = new LinkedHashMap<>(); int start = StringUtils.indexOfIgnoreCase(str, query); indices.put(start, start + query.length()); for (++start; (start = StringUtils.indexOfIgnoreCase(str, query, start)) > 0; start++) { indices.put(start, start + query.length()); }//w w w . j a v a 2s . c o m return indices; }
From source file:io.github.swagger2markup.internal.utils.TagUtils.java
/** * Converts the global Tag list into a Map where the tag name is the key and the Tag the value. * Either ordered or as-is, if the comparator is null. * * @param tags the List of tags// ww w .j av a 2 s . co m * @param comparator the comparator to use. * @return the Map of tags. Either ordered or as-is, if the comparator is null. */ public static Map<String, Tag> toSortedMap(List<Tag> tags, Comparator<String> comparator) { Map<String, Tag> sortedMap; if (comparator == null) sortedMap = new LinkedHashMap<>(); else sortedMap = new TreeMap<>(comparator); tags.forEach(tag -> sortedMap.put(tag.getName(), tag)); return sortedMap; }
From source file:com.netflix.dyno.contrib.consul.ConsulHelper.java
public static Map<String, String> getMetadata(List<String> tags) { LinkedHashMap<String, String> metadata = new LinkedHashMap<>(); if (tags != null) { for (String tag : tags) { String[] parts = StringUtils.split(tag, "="); switch (parts.length) { case 0: break; case 1: metadata.put(parts[0], parts[0]); break; case 2: metadata.put(parts[0], parts[1]); break; default: String[] end = Arrays.copyOfRange(parts, 1, parts.length); metadata.put(parts[0], StringUtils.join(end, "=")); break; }/*from w w w . j ava2s . c o m*/ } } return metadata; }
From source file:ch.wisv.areafiftylan.utils.ResponseEntityBuilder.java
/** * Create a standard response for all requests to the API * * @param httpStatus The HTTP Status of the response * @param httpHeaders Optional Http Headers for the response. * @param message The message in human readable String format * @param object Optional object related to the request (like a created User) * * @return The ResponseEntity in standard Area FiftyLAN format. *///from w w w .j ava 2 s. c o m public static ResponseEntity<?> createResponseEntity(HttpStatus httpStatus, HttpHeaders httpHeaders, String message, Object object) { Map<String, Object> responseBody = new LinkedHashMap<>(); responseBody.put("status", httpStatus.toString()); responseBody.put("timestamp", LocalDateTime.now().toString()); responseBody.put("message", message); responseBody.put("object", object); if (httpHeaders == null) { httpHeaders = new HttpHeaders(); } return new ResponseEntity<>(responseBody, httpHeaders, httpStatus); }
From source file:org.jhk.pulsing.pulse.TrendingPulseSubTest.java
@BeforeClass public static void setup() { _objectMapper = new ObjectMapper(); _validResult = new LinkedHashMap<>(); _validResult.put(500L, "Mocked 500"); //5 count _validResult.put(200L, "Mocked 200"); //2 count _validResult.put(100L, "Mocked 100"); //1 count }
From source file:com.feilong.commons.core.lang.ClassUtil.java
/** * class info map for log.// ww w.j ava 2 s. com * * @param klass * the clz * @return the map for log */ public static Map<String, Object> getClassInfoMapForLog(Class<?> klass) { Map<String, Object> map = new LinkedHashMap<String, Object>(); //"clz.getCanonicalName()": "com.feilong.commons.core.date.DatePattern", //"clz.getName()": "com.feilong.commons.core.date.DatePattern", //"clz.getSimpleName()": "DatePattern", // getCanonicalName ( Java Language Specification ??) && getName //??class?array? // getName[[Ljava.lang.String?getCanonicalName? map.put("clz.getCanonicalName()", klass.getCanonicalName()); map.put("clz.getName()", klass.getName()); map.put("clz.getSimpleName()", klass.getSimpleName()); map.put("clz.getComponentType()", klass.getComponentType()); // ?? voidboolean?byte?char?short?int?long?float double? map.put("clz.isPrimitive()", klass.isPrimitive()); // ??, map.put("clz.isLocalClass()", klass.isLocalClass()); // ????,?????? map.put("clz.isMemberClass()", klass.isMemberClass()); //isSynthetic()?Class????java??false?trueJVM???java?????? map.put("clz.isSynthetic()", klass.isSynthetic()); map.put("clz.isArray()", klass.isArray()); map.put("clz.isAnnotation()", klass.isAnnotation()); //??true map.put("clz.isAnonymousClass()", klass.isAnonymousClass()); map.put("clz.isEnum()", klass.isEnum()); return map; // Class<?> klass = this.getClass(); // // TypeVariable<?>[] typeParameters = klass.getTypeParameters(); // TypeVariable<?> typeVariable = typeParameters[0]; // // Type[] bounds = typeVariable.getBounds(); // // Type bound = bounds[0]; // // if (log.isDebugEnabled()){ // log.debug("" + (bound instanceof ParameterizedType)); // } // // Class<T> modelClass = ReflectUtil.getGenericModelClass(klass); // return modelClass; }
From source file:com.textquo.dreamcode.server.JSONHelper.java
public static Map<String, Object> parseJson(String jsonText) { Map<String, Object> json = null; try {//from www.j av a 2 s . c o m org.json.simple.parser.JSONParser parser = new org.json.simple.parser.JSONParser(); ContainerFactory containerFactory = new ContainerFactory() { public List creatArrayContainer() { return new LinkedList(); } public Map createObjectContainer() { return new LinkedHashMap(); } }; json = (Map<String, Object>) parser.parse(jsonText, containerFactory); Iterator iter = json.entrySet().iterator(); LOG.info("==iterate result=="); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); LOG.info(entry.getKey() + "=>" + entry.getValue()); } LOG.info("==toJSONString()=="); LOG.info(org.json.simple.JSONValue.toJSONString(json)); } catch (ParseException e) { e.printStackTrace(); } return json; }
From source file:ca.sfu.federation.utils.IContextUtils.java
public static Map<String, INamed> getDependancies(Map<String, INamed> ElementMap) { // init/*ww w . j ava2s .c om*/ LinkedHashMap<String, INamed> results = new LinkedHashMap<String, INamed>(); HashSet dependancies = new HashSet(); // scenario dependancies come from contextual object references Iterator iter = ElementMap.values().iterator(); while (iter.hasNext()) { INamed named = (INamed) iter.next(); dependancies.add(named.getContext()); } // convert set to map iter = dependancies.iterator(); while (iter.hasNext()) { INamed named = (INamed) iter.next(); results.put(named.getName(), named); } // return result return results; }