@Override public SortedMap<String, String> create(Entry<String, String>[] entries) { return ImmutableSortedMap.copyOf(Arrays.asList(entries)); } }
public FeatureVector(Map<Integer, Double> features) { this.features = ImmutableSortedMap.copyOf(features); }
private static SortedMap sort(Map map) { return ImmutableSortedMap.copyOf(map); } }
/** * Returns an immutable map containing the given entries, with keys sorted by the provided * comparator. * * <p>This method is not type-safe, as it may be called on a map with keys that are not mutually * comparable. * * @throws NullPointerException if any key or value in {@code map} is null * @throws IllegalArgumentException if any two keys are equal according to the comparator * @since 19.0 */ @Beta public static <K, V> ImmutableSortedMap<K, V> copyOf( Iterable<? extends Entry<? extends K, ? extends V>> entries) { // Hack around K not being a subtype of Comparable. // Unsafe, see ImmutableSortedSetFauxverideShim. @SuppressWarnings("unchecked") Ordering<K> naturalOrder = (Ordering<K>) NATURAL_ORDER; return copyOf(entries, naturalOrder); }
BaseEntity(Builder<K, ?> builder) { this.key = builder.key; this.properties = ImmutableSortedMap.copyOf(builder.properties); }
@Override public <K extends Comparable<K>, V> SortedMap<K, V> create(Map<K, V> map) { return ImmutableSortedMap.copyOf(map); } };
/** * Concurrency: idToSegments argument might be a {@link java.util.concurrent.ConcurrentMap} that is being updated * concurrently while this constructor is executed. */ public ImmutableDruidDataSource(String name, Map<String, String> properties, Map<SegmentId, DataSegment> idToSegments) { this.name = Preconditions.checkNotNull(name); this.properties = ImmutableMap.copyOf(properties); this.idToSegments = ImmutableSortedMap.copyOf(idToSegments); this.totalSizeOfSegments = idToSegments.values().stream().mapToLong(DataSegment::getSize).sum(); }
public RowGroupStatistics(OrcWriteValidationMode validationMode, Map<Integer, ColumnStatistics> columnStatistics) { this.validationMode = validationMode; requireNonNull(columnStatistics, "columnStatistics is null"); if (validationMode == HASHED) { this.columnStatistics = ImmutableSortedMap.of(); hash = hashColumnStatistics(ImmutableSortedMap.copyOf(columnStatistics)); } else if (validationMode == DETAILED) { this.columnStatistics = ImmutableSortedMap.copyOf(columnStatistics); hash = 0; } else if (validationMode == BOTH) { this.columnStatistics = ImmutableSortedMap.copyOf(columnStatistics); hash = hashColumnStatistics(this.columnStatistics); } else { throw new IllegalArgumentException("Unsupported validation mode"); } }
/** * Creates a new file tree with the given root directories. */ FileTree(Map<Name, Directory> roots) { this.roots = ImmutableSortedMap.copyOf(roots, Name.canonicalOrdering()); }
public void testImmutableSortedMapCopyOfMap() { Map<Object, Object> original = ImmutableMap.of(new Object(), new Object(), new Object(), new Object()); try { ImmutableSortedMap.copyOf(original); fail(); } catch (ClassCastException expected) { } }
public RegexTemplate(String template) { this.template = requireNonNull(template, "template is null"); try { this.pattern = Pattern.compile(template); } catch (Exception e) { throw new IllegalArgumentException("Invalid template: " + template, e); } Map<String, Integer> namedGroups; try { namedGroups = (Map<String, Integer>) NAMED_GROUPS_METHOD.invoke(pattern); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } ImmutableSortedMap<Integer, String> sortedGroups = ImmutableSortedMap.copyOf(ImmutableBiMap.copyOf(namedGroups).inverse()); this.fieldNames = ImmutableList.copyOf(sortedGroups.values()); }
public void testCopyOf() { Map<String, Integer> original = new LinkedHashMap<>(); original.put("one", 1); original.put("two", 2); original.put("three", 3); ImmutableSortedMap<String, Integer> copy = ImmutableSortedMap.copyOf(original); assertMapEquals(copy, "one", 1, "three", 3, "two", 2); assertSame(copy, ImmutableSortedMap.copyOf(copy)); assertSame(Ordering.natural(), copy.comparator()); }
public void testNullValuesInCopyOfEntries() { for (int i = 1; i <= 10; i++) { for (int j = 0; j < i; j++) { Map<Integer, Integer> source = new TreeMap<>(); for (int k = 0; k < i; k++) { source.put(k, k); } source.put(j, null); try { ImmutableSortedMap.copyOf(source.entrySet()); fail("Expected NullPointerException in copyOf(" + source.entrySet() + ")"); } catch (NullPointerException expected) { } } } }
public void testNullValuesInCopyOfMap() { for (int i = 1; i <= 10; i++) { for (int j = 0; j < i; j++) { Map<Integer, Integer> source = new TreeMap<>(); for (int k = 0; k < i; k++) { source.put(k, k); } source.put(j, null); try { ImmutableSortedMap.copyOf(source); fail("Expected NullPointerException in copyOf(" + source + ")"); } catch (NullPointerException expected) { } } } }
public void testCopyOfExplicitComparator() { Comparator<String> comparator = Ordering.natural().reverse(); Map<String, Integer> original = new LinkedHashMap<>(); original.put("one", 1); original.put("two", 2); original.put("three", 3); ImmutableSortedMap<String, Integer> copy = ImmutableSortedMap.copyOf(original, comparator); assertMapEquals(copy, "two", 2, "three", 3, "one", 1); assertSame(copy, ImmutableSortedMap.copyOf(copy, comparator)); assertSame(comparator, copy.comparator()); }
public void testCopyOfEmptyMap() { ImmutableSortedMap<String, Integer> copy = ImmutableSortedMap.copyOf(Collections.<String, Integer>emptyMap()); assertEquals(Collections.<String, Integer>emptyMap(), copy); assertSame(copy, ImmutableSortedMap.copyOf(copy)); assertSame(Ordering.natural(), copy.comparator()); }
Frame(RelNode oldRel, RelNode r, SortedMap<CorDef, Integer> corDefOutputs, Map<Integer, Integer> oldToNewOutputs) { this.r = Preconditions.checkNotNull(r); this.corDefOutputs = ImmutableSortedMap.copyOf(corDefOutputs); this.oldToNewOutputs = ImmutableSortedMap.copyOf(oldToNewOutputs); assert allLessThan(corDefOutputs.values(), r.getRowType().getFieldCount(), Litmus.THROW); assert allLessThan(oldToNewOutputs.keySet(), oldRel.getRowType().getFieldCount(), Litmus.THROW); assert allLessThan(oldToNewOutputs.values(), r.getRowType().getFieldCount(), Litmus.THROW); } }
public void testCopyOfImmutableSortedSetDifferentComparator() { Comparator<String> comparator = Ordering.natural().reverse(); Map<String, Integer> original = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3); ImmutableSortedMap<String, Integer> copy = ImmutableSortedMap.copyOf(original, comparator); assertMapEquals(copy, "two", 2, "three", 3, "one", 1); assertSame(copy, ImmutableSortedMap.copyOf(copy, comparator)); assertSame(comparator, copy.comparator()); }
public void testCopyOfDuplicateKey() { Map<IntegerDiv10, String> original = ImmutableMap.of( new IntegerDiv10(3), "three", new IntegerDiv10(20), "twenty", new IntegerDiv10(11), "eleven", new IntegerDiv10(35), "thirty five", new IntegerDiv10(12), "twelve"); try { ImmutableSortedMap.copyOf(original); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }