/** * @see #sortedTable(GroupExpression, GroupExpression, GroupExpression, Comparator, Comparator) */ public static <R, C, V, R2> AbstractGroupExpression<Triplet<R, C, V>, RowSortedTable<R2, C, V>> sortedTable( GroupExpression<R, R2> row, Expression<C> column, Expression<V> value, Comparator<? super R2> rowComparator, Comparator<? super C> columnComparator) { return sortedTable(row, new GOne<C>(column), new GOne<V>(value), rowComparator, columnComparator); }
/** * @see #sortedTable(GroupExpression, GroupExpression, GroupExpression, Comparator, Comparator) */ public static <R, C, V, C2> AbstractGroupExpression<Triplet<R, C, V>, RowSortedTable<R, C2, V>> sortedTable( Expression<R> row, GroupExpression<C, C2> column, Expression<V> value, Comparator<? super R> rowComparator, Comparator<? super C2> columnComparator) { return sortedTable(new GOne<R>(row), column, new GOne<V>(value), rowComparator, columnComparator); }
/** * @see #sortedTable(GroupExpression, GroupExpression, GroupExpression, Comparator, Comparator) */ public static <R, C, V, R2, C2> AbstractGroupExpression<Triplet<R, C, V>, RowSortedTable<R2, C2, V>> sortedTable( GroupExpression<R, R2> row, GroupExpression<C, C2> column, Expression<V> value, Comparator<? super R2> rowComparator, Comparator<? super C2> columnComparator) { return sortedTable(row, column, new GOne<V>(value), rowComparator, columnComparator); }
/** * @see #sortedTable(GroupExpression, GroupExpression, GroupExpression, Comparator, Comparator) */ public static <R, C, V, V2> AbstractGroupExpression<Triplet<R, C, V>, RowSortedTable<R, C, V2>> sortedTable( Expression<R> row, Expression<C> column, GroupExpression<V, V2> value, Comparator<? super R> rowComparator, Comparator<? super C> columnComparator) { return sortedTable(new GOne<R>(row), new GOne<C>(column), value, rowComparator, columnComparator); }
/** * @see #sortedTable(GroupExpression, GroupExpression, GroupExpression, Comparator, Comparator) */ public static <R, C, V, R2, V2> AbstractGroupExpression<Triplet<R, C, V>, RowSortedTable<R2, C, V2>> sortedTable( GroupExpression<R, R2> row, Expression<C> column, GroupExpression<V, V2> value, Comparator<? super R2> rowComparator, Comparator<? super C> columnComparator) { return sortedTable(row, new GOne<C>(column), value, rowComparator, columnComparator); }
/** * @see #sortedTable(GroupExpression, GroupExpression, GroupExpression, Comparator, Comparator) */ public static <R, C, V, C2, V2> AbstractGroupExpression<Triplet<R, C, V>, RowSortedTable<R, C2, V2>> sortedTable( Expression<R> row, GroupExpression<C, C2> column, GroupExpression<V, V2> value, Comparator<? super R> rowComparator, Comparator<? super C2> columnComparator) { return sortedTable(new GOne<R>(row), column, value, rowComparator, columnComparator); }
@SuppressWarnings("rawtypes") public static <R extends Comparable, C extends Comparable, V> GTable<R, C, V, RowSortedTable<R, C, V>> createSorted(QTriplet<R, C, V> expr) { return new GTable<R, C, V, RowSortedTable<R, C, V>>(expr) { private static final long serialVersionUID = 1L; @Override protected RowSortedTable<R, C, V> createTable() { return TreeBasedTable.<R, C, V>create(); } }; }
public static <R, C, V> GTable<R, C, V, RowSortedTable<R, C, V>> createSorted(QTriplet<R, C, V> expr, final Comparator<? super R> rowComparator, final Comparator<? super C> columnComparator) { return new GTable<R, C, V, RowSortedTable<R, C, V>>(expr) { private static final long serialVersionUID = 1L; @Override protected RowSortedTable<R, C, V> createTable() { return TreeBasedTable.<R, C, V>create(rowComparator, columnComparator); } }; }
@Override public Iterator<T> iterator() { final List<Iterator<T>> its = new ArrayList<>(); for (final Entry<Double, RowSortedTable<Long, Double, SortedSet<T>>> entry : data .entrySet()) { for (final SortedSet<T> set : entry.getValue().values()) { its.add(set.iterator()); } } return Iterators.concat(its.iterator()); }
@SuppressWarnings("rawtypes") // TreeBasedTable.create() is defined as such @Generates private static <R extends Comparable, C extends Comparable, V> RowSortedTable<R, C, V> generateRowSortedTable(R row, C column, V value) { return generateTreeBasedTable(row, column, value); }
public void testRowSortedTable() { assertFreshInstance(new TypeToken<RowSortedTable<String, ?, ?>>() {}); }
public void testGet_collections() { assertEquals(ImmutableSet.of().iterator(), ArbitraryInstances.get(Iterator.class)); assertFalse(ArbitraryInstances.get(PeekingIterator.class).hasNext()); assertFalse(ArbitraryInstances.get(ListIterator.class).hasNext()); assertEquals(ImmutableSet.of(), ArbitraryInstances.get(Iterable.class)); assertEquals(ImmutableSet.of(), ArbitraryInstances.get(Set.class)); assertEquals(ImmutableSet.of(), ArbitraryInstances.get(ImmutableSet.class)); assertEquals(ImmutableSortedSet.of(), ArbitraryInstances.get(SortedSet.class)); assertEquals(ImmutableSortedSet.of(), ArbitraryInstances.get(ImmutableSortedSet.class)); assertEquals(ImmutableList.of(), ArbitraryInstances.get(Collection.class)); assertEquals(ImmutableList.of(), ArbitraryInstances.get(ImmutableCollection.class)); assertEquals(ImmutableList.of(), ArbitraryInstances.get(List.class)); assertEquals(ImmutableList.of(), ArbitraryInstances.get(ImmutableList.class)); assertEquals(ImmutableMap.of(), ArbitraryInstances.get(Map.class)); assertEquals(ImmutableMap.of(), ArbitraryInstances.get(ImmutableMap.class)); assertEquals(ImmutableSortedMap.of(), ArbitraryInstances.get(SortedMap.class)); assertEquals(ImmutableSortedMap.of(), ArbitraryInstances.get(ImmutableSortedMap.class)); assertEquals(ImmutableMultiset.of(), ArbitraryInstances.get(Multiset.class)); assertEquals(ImmutableMultiset.of(), ArbitraryInstances.get(ImmutableMultiset.class)); assertTrue(ArbitraryInstances.get(SortedMultiset.class).isEmpty()); assertEquals(ImmutableMultimap.of(), ArbitraryInstances.get(Multimap.class)); assertEquals(ImmutableMultimap.of(), ArbitraryInstances.get(ImmutableMultimap.class)); assertTrue(ArbitraryInstances.get(SortedSetMultimap.class).isEmpty()); assertEquals(ImmutableTable.of(), ArbitraryInstances.get(Table.class)); assertEquals(ImmutableTable.of(), ArbitraryInstances.get(ImmutableTable.class)); assertTrue(ArbitraryInstances.get(RowSortedTable.class).isEmpty()); assertEquals(ImmutableBiMap.of(), ArbitraryInstances.get(BiMap.class)); assertEquals(ImmutableBiMap.of(), ArbitraryInstances.get(ImmutableBiMap.class)); assertTrue(ArbitraryInstances.get(ImmutableClassToInstanceMap.class).isEmpty()); assertTrue(ArbitraryInstances.get(ClassToInstanceMap.class).isEmpty()); assertTrue(ArbitraryInstances.get(ListMultimap.class).isEmpty()); assertTrue(ArbitraryInstances.get(ImmutableListMultimap.class).isEmpty()); assertTrue(ArbitraryInstances.get(SetMultimap.class).isEmpty()); assertTrue(ArbitraryInstances.get(ImmutableSetMultimap.class).isEmpty()); assertTrue(ArbitraryInstances.get(MapDifference.class).areEqual()); assertTrue(ArbitraryInstances.get(SortedMapDifference.class).areEqual()); assertEquals(Range.all(), ArbitraryInstances.get(Range.class)); assertTrue(ArbitraryInstances.get(NavigableSet.class).isEmpty()); assertTrue(ArbitraryInstances.get(NavigableMap.class).isEmpty()); assertTrue(ArbitraryInstances.get(LinkedList.class).isEmpty()); assertTrue(ArbitraryInstances.get(Deque.class).isEmpty()); assertTrue(ArbitraryInstances.get(Queue.class).isEmpty()); assertTrue(ArbitraryInstances.get(PriorityQueue.class).isEmpty()); assertTrue(ArbitraryInstances.get(BitSet.class).isEmpty()); assertTrue(ArbitraryInstances.get(TreeSet.class).isEmpty()); assertTrue(ArbitraryInstances.get(TreeMap.class).isEmpty()); assertFreshInstanceReturned( LinkedList.class, Deque.class, Queue.class, PriorityQueue.class, BitSet.class, TreeSet.class, TreeMap.class); }
/** * Outputs the set of options available to be set for the passed in {@link PipelineOptions} * interface. The output is in a human readable format. The format is: * <pre> * OptionGroup: * ... option group description ... * * --option1={@code <type>} or list of valid enum choices * Default: value (if available, see {@link Default}) * ... option description ... (if available, see {@link Description}) * Required groups (if available, see {@link Required}) * --option2={@code <type>} or list of valid enum choices * Default: value (if available, see {@link Default}) * ... option description ... (if available, see {@link Description}) * Required groups (if available, see {@link Required}) * </pre> * This method will attempt to format its output to be compatible with a terminal window. */ public static void printHelp(PrintStream out, Class<? extends PipelineOptions> iface) { checkNotNull(out); checkNotNull(iface); validateWellFormed(iface, REGISTERED_OPTIONS); Set<PipelineOptionSpec> properties = PipelineOptionsReflector.getOptionSpecs(iface); RowSortedTable<Class<?>, String, Method> ifacePropGetterTable = TreeBasedTable.create( ClassNameComparator.INSTANCE, Ordering.natural()); for (PipelineOptionSpec prop : properties) { ifacePropGetterTable.put(prop.getDefiningInterface(), prop.getName(), prop.getGetterMethod()); } for (Map.Entry<Class<?>, Map<String, Method>> ifaceToPropertyMap : ifacePropGetterTable.rowMap().entrySet()) { Class<?> currentIface = ifaceToPropertyMap.getKey(); Map<String, Method> propertyNamesToGetters = ifaceToPropertyMap.getValue(); SortedSetMultimap<String, String> requiredGroupNameToProperties = getRequiredGroupNamesToProperties(propertyNamesToGetters); out.format("%s:%n", currentIface.getName()); prettyPrintDescription(out, currentIface.getAnnotation(Description.class)); out.println(); List<String> lists = Lists.newArrayList(propertyNamesToGetters.keySet()); Collections.sort(lists, String.CASE_INSENSITIVE_ORDER); for (String propertyName : lists) { Method method = propertyNamesToGetters.get(propertyName); String printableType = method.getReturnType().getSimpleName(); if (method.getReturnType().isEnum()) { printableType = Joiner.on(" | ").join(method.getReturnType().getEnumConstants()); } out.format(" --%s=<%s>%n", propertyName, printableType); Optional<String> defaultValue = getDefaultValueFromAnnotation(method); if (defaultValue.isPresent()) { out.format(" Default: %s%n", defaultValue.get()); } prettyPrintDescription(out, method.getAnnotation(Description.class)); prettyPrintRequiredGroups(out, method.getAnnotation(Validation.Required.class), requiredGroupNameToProperties); } out.println(); } }
/** * @see #sortedTable(GroupExpression, GroupExpression, GroupExpression) */ public static <R extends Comparable<? super R>, C extends Comparable<? super C>, V> AbstractGroupExpression<Triplet<R, C, V>, RowSortedTable<R, C, V>> sortedTable( Expression<R> row, Expression<C> column, Expression<V> value) { return GTable.createSorted(QTriplet.create(row, column, value)); }
/** * @see #sortedTable(GroupExpression, GroupExpression, GroupExpression) */ public static <R, C extends Comparable<? super C>, V, R2 extends Comparable<? super R2>> AbstractGroupExpression<Triplet<R, C, V>, RowSortedTable<R2, C, V>> sortedTable( GroupExpression<R, R2> row, Expression<C> column, Expression<V> value) { return sortedTable(row, new GOne<C>(column), new GOne<V>(value)); }
/** * @see #sortedTable(GroupExpression, GroupExpression, GroupExpression) */ public static <R extends Comparable<? super R>, C, V, C2 extends Comparable<? super C2>> AbstractGroupExpression<Triplet<R, C, V>, RowSortedTable<R, C2, V>> sortedTable( Expression<R> row, GroupExpression<C, C2> column, Expression<V> value) { return sortedTable(new GOne<R>(row), column, new GOne<V>(value)); }
/** * @see #sortedTable(GroupExpression, GroupExpression, GroupExpression) */ public static <R, C, V, R2 extends Comparable<? super R2>, C2 extends Comparable<? super C2>> AbstractGroupExpression<Triplet<R, C, V>, RowSortedTable<R2, C2, V>> sortedTable( GroupExpression<R, R2> row, GroupExpression<C, C2> column, Expression<V> value) { return sortedTable(row, column, new GOne<V>(value)); }
/** * @see #sortedTable(GroupExpression, GroupExpression, GroupExpression) */ public static <R extends Comparable<? super R>, C extends Comparable<? super C>, V, V2> AbstractGroupExpression<Triplet<R, C, V>, RowSortedTable<R, C, V2>> sortedTable( Expression<R> row, Expression<C> column, GroupExpression<V, V2> value) { return sortedTable(new GOne<R>(row), new GOne<C>(column), value); }
/** * @see #sortedTable(GroupExpression, GroupExpression, GroupExpression) */ public static <R, C extends Comparable<? super C>, V, R2 extends Comparable<? super R2>, V2> AbstractGroupExpression<Triplet<R, C, V>, RowSortedTable<R2, C, V2>> sortedTable( GroupExpression<R, R2> row, Expression<C> column, GroupExpression<V, V2> value) { return sortedTable(row, new GOne<C>(column), value); }
/** * @see #sortedTable(GroupExpression, GroupExpression, GroupExpression) */ public static <R extends Comparable<? super R>, C, V, C2 extends Comparable<? super C2>, V2> AbstractGroupExpression<Triplet<R, C, V>, RowSortedTable<R, C2, V2>> sortedTable( Expression<R> row, GroupExpression<C, C2> column, GroupExpression<V, V2> value) { return sortedTable(new GOne<R>(row), column, value); }
/** * @see #sortedTable(GroupExpression, GroupExpression, GroupExpression, Comparator, Comparator) */ public static <R, C, V> AbstractGroupExpression<Triplet<R, C, V>, RowSortedTable<R, C, V>> sortedTable( Expression<R> row, Expression<C> column, Expression<V> value, Comparator<? super R> rowComparator, Comparator<? super C> columnComparator) { return GTable.createSorted(QTriplet.create(row, column, value), rowComparator, columnComparator); }
private Dataset(Comparator<T> comp) { comparator = comp; data = new TreeMap<Double, RowSortedTable<Long, Double, SortedSet<T>>>(); valuesSet = new HashSet<>(); }
/** * Create a new aggregating table expression using a backing HashBasedRowSortedTable * * @param row * row for the sortedTable entries * @param column * column for the sortedTable entries * @param value * value for the sortedTable entries * @return wrapper expression */ public static <R, C, V, R2 extends Comparable<? super R2>, C2 extends Comparable<? super C2>, V2> AbstractGroupExpression<Triplet<R, C, V>, RowSortedTable<R2, C2, V2>> sortedTable( GroupExpression<R, R2> row, GroupExpression<C, C2> column, GroupExpression<V, V2> value) { return new GTable.Mixin<R, C, V, R2, C2, V2, RowSortedTable<R2, C2, V2>>( row, column, value, GTable.createSorted(QTriplet.create(row, column, value)) ); }
/** * Create a new aggregating table expression using a backing HashBasedRowSortedTable * * @param row * row for the sortedTable entries * @param column * column for the sortedTable entries * @param value * value for the sortedTable entries * @return wrapper expression */ public static <R, C, V, R2, C2, V2> AbstractGroupExpression<Triplet<R, C, V>, RowSortedTable<R2, C2, V2>> sortedTable( GroupExpression<R, R2> row, GroupExpression<C, C2> column, GroupExpression<V, V2> value, Comparator<? super R2> rowComparator, Comparator<? super C2> columnComparator) { return new GTable.Mixin<R, C, V, R2, C2, V2, RowSortedTable<R2, C2, V2>>( row, column, value, GTable.createSorted(QTriplet.create(row, column, value), rowComparator, columnComparator) ); }