Java Code Examples for java.util.LinkedHashMap#putAll()

The following examples show how to use java.util.LinkedHashMap#putAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocumentFilterList.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 6 votes vote down vote up
public DocumentFilterList mergeWith(@NonNull final DocumentFilterList other)
{
	if (isEmpty())
	{
		return other;
	}
	else if (other.isEmpty())
	{
		return this;
	}
	else
	{
		final LinkedHashMap<String, DocumentFilter> filtersByIdNew = new LinkedHashMap<>(this.filtersById);
		filtersByIdNew.putAll(other.filtersById);

		return ofMap(filtersByIdNew);
	}
}
 
Example 2
Source File: JdbcRouteLocator.java    From open-cloud with MIT License 6 votes vote down vote up
/**
 * 加载路由配置
 *
 * @return
 */
@Override
protected Map<String, ZuulProperties.ZuulRoute> locateRoutes() {
    LinkedHashMap<String, ZuulProperties.ZuulRoute> routesMap = Maps.newLinkedHashMap();
    routesMap.putAll(super.locateRoutes());
    //从db中加载路由信息
    routesMap.putAll(loadRoutes());
    //优化一下配置
    LinkedHashMap<String, ZuulProperties.ZuulRoute> values = Maps.newLinkedHashMap();
    for (Map.Entry<String, ZuulProperties.ZuulRoute> entry : routesMap.entrySet()) {
        String path = entry.getKey();
        // Prepend with slash if not already present.
        if (!path.startsWith("/")) {
            path = "/" + path;
        }
        if (StringUtils.hasText(this.properties.getPrefix())) {
            path = this.properties.getPrefix() + path;
            if (!path.startsWith("/")) {
                path = "/" + path;
            }
        }
        values.put(path, entry.getValue());
    }
    return values;
}
 
Example 3
Source File: ClassPath.java    From kite with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting static ImmutableMap<URI, ClassLoader> getClassPathEntries(
    ClassLoader classloader) {
  LinkedHashMap<URI, ClassLoader> entries = Maps.newLinkedHashMap();
  // Search parent first, since it's the order ClassLoader#loadClass() uses.
  ClassLoader parent = classloader.getParent();
  if (parent != null) {
    entries.putAll(getClassPathEntries(parent));
  }
  if (classloader instanceof URLClassLoader) {
    URLClassLoader urlClassLoader = (URLClassLoader) classloader;
    for (URL entry : urlClassLoader.getURLs()) {
      URI uri;
      try {
        uri = entry.toURI();
      } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
      }
      if (!entries.containsKey(uri)) {
        entries.put(uri, classloader);
      }
    }
  }
  return ImmutableMap.copyOf(entries);
}
 
Example 4
Source File: CommonUtils.java    From pacbot with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param notation
 * @param nestedMap
 * @return
 */
@SuppressWarnings("unchecked")
public static LinkedHashMap<String, Object> flatNestedLinkedHashMap(String notation, Map<String, Object> nestedMap) {
	LinkedHashMap<String, Object> flatNestedMap = new LinkedHashMap<String, Object>();
	String prefixKey = notation != null ? notation + "." : "";
	for (Map.Entry<String, Object> entry : nestedMap.entrySet()) {
		if (entry.getValue() instanceof String || entry.getValue() instanceof Long || entry.getValue() instanceof Integer  || entry.getValue() instanceof Float || entry.getValue() instanceof Double) {
			flatNestedMap.put(prefixKey + entry.getKey(), entry.getValue());
		}
		if (entry.getValue() instanceof Map) {
			flatNestedMap.putAll(flatNestedMap(prefixKey + entry.getKey(), (Map<String, Object>) entry.getValue()));
		}
		if (entry.getValue() instanceof ArrayList) {
			Gson gson = new Gson();
			flatNestedMap.put("list",gson.toJson(entry.getValue()));
			
		}
	}
	return flatNestedMap;
}
 
Example 5
Source File: UDFMapBuildTest.java    From hive-third-functions with Apache License 2.0 6 votes vote down vote up
@Test
public void testMapBuild() throws Exception {
    UDFMapBuild udf = new UDFMapBuild();
    ObjectInspector keyArrayOI = ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector);
    ObjectInspector valueArrayOI = ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector);
    ObjectInspector[] arguments = {keyArrayOI, valueArrayOI};
    udf.initialize(arguments);

    List<String> keyArray = ImmutableList.of("key1", "key2", "key3");
    List<String> valueArray = ImmutableList.of("value1", "value2", "value3");
    DeferredObject keyArrayObj = new DeferredJavaObject(keyArray);
    DeferredObject valueArrayObj = new DeferredJavaObject(valueArray);
    DeferredObject[] args = {keyArrayObj, valueArrayObj};
    LinkedHashMap<String, String> output = (LinkedHashMap<String, String>) udf.evaluate(args);
    LinkedHashMap<String, String> expect = Maps.newLinkedHashMap();
    expect.putAll(ImmutableMap.<String, String>of("key1", "value1", "key2", "value2", "key3", "value3"));

    Assert.assertEquals("map_build() test", true, MapUtils.mapEquals(output, expect));
}
 
Example 6
Source File: UDFMapConcatTest.java    From hive-third-functions with Apache License 2.0 6 votes vote down vote up
@Test
public void testMapConcat() throws Exception {
    UDFMapConcat udf = new UDFMapConcat();
    ObjectInspector leftMapOI = ObjectInspectorFactory.getStandardMapObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.javaStringObjectInspector);
    ObjectInspector rightMapOI = ObjectInspectorFactory.getStandardMapObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.javaStringObjectInspector);
    ObjectInspector[] arguments = {leftMapOI, rightMapOI};
    udf.initialize(arguments);

    LinkedHashMap<String, String> leftMap = Maps.newLinkedHashMap();
    leftMap.putAll(ImmutableMap.<String, String>of("key1", "11", "key2", "12", "key3", "13"));
    LinkedHashMap<String, String> rightMap = Maps.newLinkedHashMap();
    rightMap.putAll(ImmutableMap.<String, String>of("key3", "21", "key4", "22", "key5", "23"));

    DeferredObject leftMapObj = new DeferredJavaObject(leftMap);
    DeferredObject rightMapObj = new DeferredJavaObject(rightMap);
    DeferredObject[] args = {leftMapObj, rightMapObj};
    LinkedHashMap<String, String> output = (LinkedHashMap<String, String>) udf.evaluate(args);
    LinkedHashMap<String, String> expect = Maps.newLinkedHashMap();
    expect.putAll(ImmutableMap.<String, String>of("key1", "11", "key2", "12", "key3", "21", "key4", "22", "key5", "23"));

    Assert.assertEquals("map_concat() test", true, MapUtils.mapEquals(output, expect));
}
 
Example 7
Source File: DynamicRouteLocator.java    From Taroco with Apache License 2.0 6 votes vote down vote up
/**
 * 重写路由配置
 *
 * @return 路由表
 */
@Override
protected LinkedHashMap<String, ZuulProperties.ZuulRoute> locateRoutes() {
    //读取properties配置、eureka默认配置
    LinkedHashMap<String, ZuulProperties.ZuulRoute> routesMap = new LinkedHashMap<>(super.locateRoutes());
    log.debug("初始默认的路由配置完成");
    routesMap.putAll(locateRoutesFromCache());
    LinkedHashMap<String, ZuulProperties.ZuulRoute> values = new LinkedHashMap<>();
    for (Map.Entry<String, ZuulProperties.ZuulRoute> entry : routesMap.entrySet()) {
        String path = entry.getKey();
        if (!path.startsWith("/")) {
            path = "/" + path;
        }
        if (StrUtil.isNotBlank(this.properties.getPrefix())) {
            path = this.properties.getPrefix() + path;
            if (!path.startsWith("/")) {
                path = "/" + path;
            }
        }
        values.put(path, entry.getValue());
    }
    return values;
}
 
Example 8
Source File: PropertiesMap.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Builds a HashMap containing all of the key,value pairs stored in this PropertyTree
 *
 * @return
 */
private Map collectEntries(String prefix, boolean flattenEntries) {
    LinkedHashMap entryMap = new LinkedHashMap();

    for (Iterator i = this.children.entrySet().iterator(); i.hasNext();) {
        Entry e = (Entry) i.next();
        PropertyTree child = (PropertyTree) e.getValue();
        String childKey = (String) e.getKey();

        // handle children with values
        if (child.hasDirectValue()) {
            String entryKey = (prefix == null) ? childKey : prefix + "." + childKey;
            String entryValue = child.getDirectValue();

            entryMap.put(entryKey, entryValue);
        }

        // handle children with children
        if (!flattenEntries && child.hasChildren()) {
            String childPrefix = (prefix == null) ? childKey : prefix + "." + childKey;

            entryMap.putAll(child.collectEntries(childPrefix, flattenEntries));
        }
    }

    return entryMap;
}
 
Example 9
Source File: GenerateGrapqlSDL.java    From barleydb with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addAllNodes(EntitySpec et, LinkedHashMap<String, FieldDefinition> fds, boolean inputFields) {
	if (et.getParentEntity() != null) {
		addAllNodes(et.getParentEntity(), fds, inputFields);
	}
	fds.putAll(et.getNodeSpecs().stream()
		.map( ns -> inputFields ? new InputFieldDefinition(ns) : new QueryFieldDefinition(ns))
		.collect(Collectors.toMap(FieldDefinition::getName, fd -> fd)));		
}
 
Example 10
Source File: FunctionParser.java    From weex-uikit with MIT License 5 votes vote down vote up
private LinkedHashMap<K, V> definition() {
  LinkedHashMap<K, V> result = new LinkedHashMap<>();
  do {
    result.putAll(function());
  } while (lexer.getCurrentToken() == Token.FUNC_NAME);
  return result;
}
 
Example 11
Source File: LinkedHashMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void test_removeEldestEntry_removeKey() {
    LinkedHashMap<String, String> m = new LinkedHashMap<String, String>() {
        @Override
        protected boolean removeEldestEntry(Entry<String, String> eldest) {
            int size = size();
            if (size > 2) {
                remove(eldest.getKey());
            }
            return false;
        }
    };
    m.putAll(createMap("K1", "V1", "K2", "V2", "K3", "V3", "K4", "V4"));
    assertEquals(createMap("K3", "V3", "K4", "V4"), m);
}
 
Example 12
Source File: VertexImpl.java    From tez with Apache License 2.0 5 votes vote down vote up
protected void addTask(Task task) {
  synchronized (tasksSyncHandle) {
    if (lazyTasksCopyNeeded) {
      LinkedHashMap<TezTaskID, Task> newTasks = new LinkedHashMap<TezTaskID, Task>();
      newTasks.putAll(tasks);
      tasks = newTasks;
      lazyTasksCopyNeeded = false;
    }
  }
  tasks.put(task.getTaskId(), task);
  // TODO Metrics
  //metrics.waitingTask(task);
}
 
Example 13
Source File: PZFactory.java    From InflatableDonkey with MIT License 5 votes vote down vote up
ProtectionZone protectionZone(LinkedHashMap<KeyID, Key<ECPrivateKey>> keys, String protectionInfoTag,
        ProtectionInfo protectionInfo) {
    List<byte[]> masterKeys = assistant.masterKeys(protectionInfo, keys);
    masterKeys.forEach(u -> logger.trace("-- protectionZone() - master key: 0x{}", Hex.toHexString(u)));
    List<byte[]> decryptKeys = masterKeys.stream()
            .map(kdf::apply)
            .collect(toList());
    decryptKeys.forEach(u -> logger.trace("-- protectionZone() - decrypt key: 0x{}", Hex.toHexString(u)));

    // Ordering is important here. The latest protection zone should be iterated first.
    LinkedHashMap newKeys = keys(assistant.keys(protectionInfo, decryptKeys));
    newKeys.putAll(keys);
    return new ProtectionZone(unwrapKey, masterKeys, decryptKeys, newKeys, protectionInfoTag);
}
 
Example 14
Source File: GrokTextReader.java    From logsniffer with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public LinkedHashMap<String, FieldBaseTypes> getFieldTypes() throws FormatException {
	init();
	final LinkedHashMap<String, FieldBaseTypes> fields = super.getFieldTypes();
	fields.putAll(grokBean.getGrok(groksRegistry).getFieldTypes());
	if (overflowAttribute != null && !fields.containsKey(overflowAttribute)) {
		fields.put(overflowAttribute, FieldBaseTypes.STRING);
	}
	return fields;
}
 
Example 15
Source File: AbstractRequestBuilder.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
/**
 * Gets api parameters.
 *
 * @param method the method
 * @return the api parameters
 */
private Map<String, io.swagger.v3.oas.annotations.Parameter> getApiParameters(Method method) {
	Class<?> declaringClass = method.getDeclaringClass();

	Set<io.swagger.v3.oas.annotations.Parameters> apiParametersDoc = AnnotatedElementUtils
			.findAllMergedAnnotations(method, io.swagger.v3.oas.annotations.Parameters.class);
	LinkedHashMap<String, io.swagger.v3.oas.annotations.Parameter> apiParametersMap = apiParametersDoc.stream()
			.flatMap(x -> Stream.of(x.value())).collect(Collectors.toMap(io.swagger.v3.oas.annotations.Parameter::name, x -> x, (e1, e2) -> e2,
					LinkedHashMap::new));

	Set<io.swagger.v3.oas.annotations.Parameters> apiParametersDocDeclaringClass = AnnotatedElementUtils
			.findAllMergedAnnotations(declaringClass, io.swagger.v3.oas.annotations.Parameters.class);
	LinkedHashMap<String, io.swagger.v3.oas.annotations.Parameter> apiParametersDocDeclaringClassMap = apiParametersDocDeclaringClass.stream()
			.flatMap(x -> Stream.of(x.value())).collect(Collectors.toMap(io.swagger.v3.oas.annotations.Parameter::name, x -> x, (e1, e2) -> e2,
					LinkedHashMap::new));
	apiParametersMap.putAll(apiParametersDocDeclaringClassMap);

	Set<io.swagger.v3.oas.annotations.Parameter> apiParameterDoc = AnnotatedElementUtils
			.findAllMergedAnnotations(method, io.swagger.v3.oas.annotations.Parameter.class);
	LinkedHashMap<String, io.swagger.v3.oas.annotations.Parameter> apiParameterDocMap = apiParameterDoc.stream()
			.collect(Collectors.toMap(io.swagger.v3.oas.annotations.Parameter::name, x -> x, (e1, e2) -> e2,
					LinkedHashMap::new));
	apiParametersMap.putAll(apiParameterDocMap);

	Set<io.swagger.v3.oas.annotations.Parameter> apiParameterDocDeclaringClass = AnnotatedElementUtils
			.findAllMergedAnnotations(declaringClass, io.swagger.v3.oas.annotations.Parameter.class);
	LinkedHashMap<String, io.swagger.v3.oas.annotations.Parameter> apiParameterDocDeclaringClassMap = apiParameterDocDeclaringClass.stream()
			.collect(Collectors.toMap(io.swagger.v3.oas.annotations.Parameter::name, x -> x, (e1, e2) -> e2,
					LinkedHashMap::new));
	apiParametersMap.putAll(apiParameterDocDeclaringClassMap);

	return apiParametersMap;
}
 
Example 16
Source File: ReflectionTableParser.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
private Map<String, ColumnDefinition> getColumnDefinitions(Object object) {
    LinkedHashMap<String, ColumnDefinition> columnDefinitions = new LinkedHashMap<>();
    columnDefinitions.putAll(getColumnDefinitionsFromMethods(object));
    columnDefinitions.putAll(getColumnDefinitionsFromFields(object));

    return columnDefinitions;
}
 
Example 17
Source File: JdbcMetadataProcessor.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@Override
protected void process(Record record, BatchMaker batchMaker) throws StageException {
  try {
    ELVars variables = getContext().createELVars();
    RecordEL.setRecordInContext(variables, record);
    TimeEL.setCalendarInContext(variables, Calendar.getInstance());
    TimeNowEL.setTimeNowInContext(variables, new Date());

    String schema = (schemaEL != null) ? elEvals.dbNameELEval.eval(variables, schemaEL, String.class) : null;
    String tableName = elEvals.tableNameELEval.eval(variables, tableNameEL, String.class);

    if (StringUtils.isEmpty(schema)) {
      schema = null;
    }

    // Obtain the record structure from current record
    LinkedHashMap<String, JdbcTypeInfo> recordStructure = JdbcMetastoreUtil.convertRecordToJdbcType(
        record,
        decimalDefaultsConfig.precisionAttribute,
        decimalDefaultsConfig.scaleAttribute,
        schemaWriter);

    if (recordStructure.isEmpty()) {
      batchMaker.addRecord(record);
      return;
    }

    LinkedHashMap<String, JdbcTypeInfo> tableStructure = null;
    try {
      tableStructure = tableCache.get(Pair.of(schema, tableName));
    } catch (ExecutionException e) {
      throw new JdbcStageCheckedException(JdbcErrors.JDBC_203, e.getMessage(), e);
    }

    if (tableStructure.isEmpty()) {
      // Create table
      schemaWriter.createTable(schema, tableName, recordStructure);
      tableCache.put(Pair.of(schema, tableName), recordStructure);
    } else {
      // Compare tables
      LinkedHashMap<String, JdbcTypeInfo> columnDiff = JdbcMetastoreUtil.getDiff(tableStructure, recordStructure);
      if (!columnDiff.isEmpty()) {
        LOG.trace("Detected drift for table {} - new columns: {}",
            tableName,
            StringUtils.join(columnDiff.keySet(), ",")
        );
        schemaWriter.alterTable(schema, tableName, columnDiff);
        tableStructure.putAll(columnDiff);
        tableCache.put(Pair.of(schema, tableName), tableStructure);
      }
    }

    batchMaker.addRecord(record);
  } catch (JdbcStageCheckedException error) {
    LOG.error("Error happened when processing record", error);
    LOG.trace("Record that caused the error: {}", record.toString());
    errorRecordHandler.onError(new OnRecordErrorException(record, error.getErrorCode(), error.getParams()));
  }
}
 
Example 18
Source File: RegexFilter.java    From logsniffer with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void filterKnownFields(final LinkedHashMap<String, FieldBaseTypes> knownFields) throws FormatException {
	knownFields.putAll(grokBean.getGrok(groksRegistry).getFieldTypes());

}
 
Example 19
Source File: XMLHelper.java    From stategen with GNU Affero General Public License v3.0 4 votes vote down vote up
public LinkedHashMap<String,String> nodeNameAsAttributes(String nodeNameKey) {
	LinkedHashMap map = new LinkedHashMap();
    map.putAll(attributes);
    map.put(nodeNameKey, nodeName);
    return map;
}
 
Example 20
Source File: RuleKeyDifferTest.java    From buck with Apache License 2.0 4 votes vote down vote up
@Test
public void handlesDifferencesForBaseTypes()
    throws MaxDifferencesException, GraphTraversalException {
  Map<String, Value> onlyInOriginal = generateSampleValues(1, 1);
  Map<String, Value> changedInOriginal = generateSampleValues(2, 1);
  Map<String, Value> changedInNew = generateSampleValues(2, 2);
  Map<String, Value> common = generateSampleValues(3, 1);
  Map<String, Value> onlyInNew = generateSampleValues(4, 1);

  LinkedHashMap<String, Value> originalValues = new LinkedHashMap<>();
  originalValues.putAll(onlyInOriginal);
  originalValues.putAll(changedInOriginal);
  originalValues.putAll(common);

  LinkedHashMap<String, Value> newValues = new LinkedHashMap<>();
  newValues.putAll(onlyInNew);
  newValues.putAll(changedInNew);
  newValues.putAll(common);

  FullRuleKey originalRuleKey =
      new FullRuleKey("original_hash", "//:target1", "rule_type", originalValues);

  FullRuleKey newRuleKey = new FullRuleKey("new_hash", "//:target1", "rule_type", newValues);

  ParsedRuleKeyFile originalFile = createParsedFile(Paths.get("file1"), originalRuleKey);
  ParsedRuleKeyFile newFile = createParsedFile(Paths.get("file2"), newRuleKey);

  List<String> expectedLines =
      generateExpectedStrings(
          ImmutableList.<String>builder()
              .addAll(onlyInOriginal.keySet())
              .addAll(onlyInNew.keySet())
              .addAll(changedInOriginal.keySet())
              .build(),
          originalFile,
          newFile);

  differ.printDiff(originalFile, newFile);
  List<String> lines = Arrays.asList(stream.getOutputLines());

  Assert.assertEquals(expectedLines.size(), lines.size());
  Assert.assertEquals(expectedLines, lines);
}