/** Combine values for the same key, resolving conflicts based on their type. */ @SuppressWarnings("unchecked") private Object union(Linker linker, Object a, Object b) { if (a instanceof List) { return union((List<?>) a, (List<?>) b); } else if (a instanceof Map) { return union(linker, (Map<ProtoMember, Object>) a, (Map<ProtoMember, Object>) b); } else { linker.addError("conflicting options: %s, %s", a, b); return a; // Just return any placeholder. } }
private ImmutableMap<ProtoMember, Object> union( Linker linker, Map<ProtoMember, Object> a, Map<ProtoMember, Object> b) { Map<ProtoMember, Object> result = new LinkedHashMap<>(a); for (Map.Entry<ProtoMember, Object> entry : b.entrySet()) { Object aValue = result.get(entry.getKey()); Object bValue = entry.getValue(); Object union = aValue != null ? union(linker, aValue, bValue) : bValue; result.put(entry.getKey(), union); } return ImmutableMap.copyOf(result); }
void link(Linker linker) { ImmutableMap<ProtoMember, Object> map = ImmutableMap.of(); for (OptionElement option : optionElements) { Map<ProtoMember, Object> canonicalOption = canonicalizeOption(linker, optionType, option); if (canonicalOption != null) { map = union(linker, map, canonicalOption); } } this.map = map; }
/** Combine values for the same key, resolving conflicts based on their type. */ @SuppressWarnings("unchecked") private Object union(Linker linker, Object a, Object b) { if (a instanceof List) { return union((List<?>) a, (List<?>) b); } else if (a instanceof Map) { return union(linker, (Map<ProtoMember, Object>) a, (Map<ProtoMember, Object>) b); } else { linker.addError("conflicting options: %s, %s", a, b); return a; // Just return any placeholder. } }
/** Combine values for the same key, resolving conflicts based on their type. */ @SuppressWarnings("unchecked") private Object union(Linker linker, Object a, Object b) { if (a instanceof List) { return union((List<?>) a, (List<?>) b); } else if (a instanceof Map) { return union(linker, (Map<ProtoMember, Object>) a, (Map<ProtoMember, Object>) b); } else { linker.addError("conflicting options: %s, %s", a, b); return a; // Just return any placeholder. } }
private ImmutableMap<ProtoMember, Object> union( Linker linker, Map<ProtoMember, Object> a, Map<ProtoMember, Object> b) { Map<ProtoMember, Object> result = new LinkedHashMap<>(a); for (Map.Entry<ProtoMember, Object> entry : b.entrySet()) { Object aValue = result.get(entry.getKey()); Object bValue = entry.getValue(); Object union = aValue != null ? union(linker, aValue, bValue) : bValue; result.put(entry.getKey(), union); } return ImmutableMap.copyOf(result); }
private ImmutableMap<ProtoMember, Object> union( Linker linker, Map<ProtoMember, Object> a, Map<ProtoMember, Object> b) { Map<ProtoMember, Object> result = new LinkedHashMap<>(a); for (Map.Entry<ProtoMember, Object> entry : b.entrySet()) { Object aValue = result.get(entry.getKey()); Object bValue = entry.getValue(); Object union = aValue != null ? union(linker, aValue, bValue) : bValue; result.put(entry.getKey(), union); } return ImmutableMap.copyOf(result); }
void link(Linker linker) { ImmutableMap<ProtoMember, Object> map = ImmutableMap.of(); for (OptionElement option : optionElements) { Map<ProtoMember, Object> canonicalOption = canonicalizeOption(linker, optionType, option); if (canonicalOption != null) { map = union(linker, map, canonicalOption); } } this.map = map; }
void link(Linker linker) { ImmutableMap<ProtoMember, Object> map = ImmutableMap.of(); for (OptionElement option : optionElements) { Map<ProtoMember, Object> canonicalOption = canonicalizeOption(linker, optionType, option); if (canonicalOption != null) { map = union(linker, map, canonicalOption); } } this.map = map; }