@SuppressWarnings("unchecked") private KeyedObjectMap(Iterable<? extends T> objs, KeyExtractor<? super T> ex, boolean sorted) { if (sorted) { if (objs instanceof ImmutableList) { data = (ImmutableList<T>) objs; } else { data = ImmutableList.copyOf(objs); } } else { data = Keys.keyOrdering(ex).immutableSortedCopy((Iterable<T>) objs); } extractor = ex; }
/** * Create a new keyed object map. * @param objs A collection of objects to put in the map. * @param <T> The keyed object type. * @return A keyed object map of the objects in {@code objs}. */ public static <T extends KeyedObject> KeyedObjectMap<T> create(Collection<? extends T> objs) { return new KeyedObjectMap<>(objs, Keys.selfExtractor()); }
/** * Create a new builder for a keyed object map over a self-keying type. * @param <T> The keyed object type. * @return A builder for a keyed object map. */ public static <T extends KeyedObject> KeyedObjectMapBuilder<T> newBuilder() { return new KeyedObjectMapBuilder<>(Keys.selfExtractor()); }
@SuppressWarnings("unchecked") private KeyedObjectMap(Iterable<? extends T> objs, KeyExtractor<? super T> ex, boolean sorted) { if (sorted) { if (objs instanceof ImmutableList) { data = (ImmutableList<T>) objs; } else { data = ImmutableList.copyOf(objs); } } else { data = Keys.keyOrdering(ex).immutableSortedCopy((Iterable<T>) objs); } extractor = ex; }
/** * Create a new builder for a keyed object map over a self-keying type. * @param <T> The keyed object type. * @return A builder for a keyed object map. */ public static <T extends KeyedObject> KeyedObjectMapBuilder<T> newBuilder() { return new KeyedObjectMapBuilder<>(Keys.selfExtractor()); }
/** * Create a new keyed object map. * @param objs A collection of objects to put in the map. * @param <T> The keyed object type. * @return A keyed object map of the objects in {@code objs}. */ public static <T extends KeyedObject> KeyedObjectMap<T> create(Collection<? extends T> objs) { return new KeyedObjectMap<>(objs, Keys.selfExtractor()); }