public static void printResultOfTokenStream(PrintStream out, TokenStream ts) throws IOException { CharTermAttribute termAttr = ts.getAttribute(CharTermAttribute.class); TypeAttribute typeAttr = ts.getAttribute(TypeAttribute.class); OffsetAttribute offAttr = ts.getAttribute(OffsetAttribute.class); PositionIncrementAttribute posIncAttr = ts.getAttribute(PositionIncrementAttribute.class); PositionLengthAttribute posLenAttr = ts.getAttribute(PositionLengthAttribute.class); ts.reset(); Table<String, String, String> contentTable = Tables.newCustomTable(new LinkedHashMap<String, Map<String, String>>(), new Supplier<Map<String, String>>() { @Override public Map<String, String> get() { return Maps.newLinkedHashMap(); } }); int lineNo = 1; int pos = 0; while (ts.incrementToken()) { String lineId = lineNo + "."; contentTable.put(lineId, "term", termAttr.toString()); contentTable.put(lineId, "type", typeAttr.type()); contentTable.put(lineId, "startOffset", offAttr.startOffset() + ""); contentTable.put(lineId, "endOffset", offAttr.endOffset() + ""); contentTable.put(lineId, "posInc", posIncAttr.getPositionIncrement() + ""); contentTable.put(lineId, "posLen", posLenAttr.getPositionLength() + ""); pos += posIncAttr.getPositionIncrement(); contentTable.put(lineId, "pos", pos + ""); lineNo++; } printTable(out, contentTable); }
private ChangeNotesState buildState() { return ChangeNotesState.create( tip.copy(), id, new Change.Key(changeId), createdOn, lastUpdatedOn, ownerId, branch, buildCurrentPatchSetId(), subject, topic, originalSubject, submissionId, assignee != null ? assignee.orElse(null) : null, status, Sets.newLinkedHashSet(Lists.reverse(pastAssignees)), hashtags, patchSets, buildApprovals(), ReviewerSet.fromTable(Tables.transpose(reviewers)), ReviewerByEmailSet.fromTable(Tables.transpose(reviewersByEmail)), pendingReviewers, pendingReviewersByEmail, allPastReviewers, buildReviewerUpdates(), submitRecords, buildAllMessages(), buildMessagesByPatchSet(), comments, readOnlyUntil, isPrivate, workInProgress, hasReviewStarted, revertOf); }
private void parseWorkInProgress(ChangeNotesCommit commit) throws ConfigInvalidException { String raw = parseOneFooter(commit, FOOTER_WORK_IN_PROGRESS); if (raw == null) { // No change to WIP state in this revision. previousWorkInProgressFooter = null; return; } else if (Boolean.TRUE.toString().equalsIgnoreCase(raw)) { // This revision moves the change into WIP. previousWorkInProgressFooter = true; if (workInProgress == null) { // Because this is the first time workInProgress is being set, we know // that this change's current state is WIP. All the reviewer updates // we've seen so far are pending, so take a snapshot of the reviewers // and reviewersByEmail tables. pendingReviewers = ReviewerSet.fromTable(Tables.transpose(ImmutableTable.copyOf(reviewers))); pendingReviewersByEmail = ReviewerByEmailSet.fromTable(Tables.transpose(ImmutableTable.copyOf(reviewersByEmail))); workInProgress = true; } return; } else if (Boolean.FALSE.toString().equalsIgnoreCase(raw)) { previousWorkInProgressFooter = false; hasReviewStarted = true; if (workInProgress == null) { workInProgress = false; } return; } throw invalidFooter(FOOTER_WORK_IN_PROGRESS, raw); }
@Override public Table.Cell<R, C, V> map(int index, ResultSet r, StatementContext ctx) throws SQLException { return Tables.immutableCell( rowMapper.map(index, r, ctx), columnMapper.map(index, r, ctx), valueMapper.map(index, r, ctx) ); }
public static void buildModObjectTable() { if (modObjectTable != null) { throw new IllegalStateException("Illegal call to buildModObjectTable!"); } Map<Integer, Cell<String, String, Integer>> map = Maps.transformValues(idMap, new Function<ItemData,Cell<String,String,Integer>>() { public Cell<String,String,Integer> apply(ItemData data) { if ("Minecraft".equals(data.getModId()) || !data.isOveridden()) { return null; } return Tables.immutableCell(data.getModId(), data.getItemType(), data.getItemId()); } }); Builder<String, String, Integer> tBuilder = ImmutableTable.builder(); for (Cell<String, String, Integer> c : map.values()) { if (c!=null) { tBuilder.put(c); } } modObjectTable = tBuilder.build(); }
/** * Creates a new HashMap backed {@link Table}. */ public static <R, C, V> Table<R, C, V> newHashTable() { return Tables.newCustomTable( new HashMap<R, Map<C, V>>(), new Supplier<Map<C, V>>() { @Override public Map<C, V> get() { return new HashMap<>(); } } ); }
@Override public Table.Cell<Bytes, Bytes, Bytes> apply(AzureEntity input) { return Tables.immutableCell( decode(input.getPartitionKey()), decode(input.getRowKey()), decode(input.getValue())); }
@Test public void contains_delegates_to_table() { Object o1 = new Object(); Object o2 = new Object(); Table.Cell<Object, Object, Object> cell = Tables.immutableCell(o1, o2, new Object()); when(baseAzureTable.contains(o1, o2)).thenReturn(true); assertThat(set.contains(cell), is(equalTo(true))); }
static Iterable<Table.Cell<String, String, String>> combineHeadersWithLinePartsAsTableCells( int index, Iterable<String> headers, Iterable<String> lineParts ) { final String rowKey = "" + index; return transform(zip(headers, lineParts), new Function<Map.Entry<String, String>, Table.Cell<String, String, String>>() { @Override public Table.Cell<String, String, String> apply(Map.Entry<String, String> entry) { checkNotNull(entry, "entry is null"); return Tables.immutableCell(rowKey, entry.getKey(), entry.getValue()); } }); }
@Test @SuppressWarnings("unchecked") public void testCombineHeadersWithLinePartsAsTableCells() { final ImmutableList<String> headers = ImmutableList.of("a", "b"); final ImmutableList<String> lineParts = ImmutableList.of("1", "2"); Iterable<Table.Cell<String, String, String>> cells = ImageTable.combineHeadersWithLinePartsAsTableCells(0, headers, lineParts); assertThat(cells).contains(Tables.immutableCell("0", "a", "1")); }
@Override public Cell<R1, C1, V1> apply(Cell<R, C, V> input) { return Tables.immutableCell( toRowFunction.apply(input.getRowKey()), toColumnFunction.apply(input.getColumnKey()), toValueFunction.apply(input.getValue()) ); }
@Override public Cell<R, C, V> apply(Cell<R1, C1, V1> input) { return Tables.immutableCell( fromRowFunction.apply(input.getRowKey()), fromColumnFunction.apply(input.getColumnKey()), fromValueFunction.apply(input.getValue()) ); }
public void cellSet_delegates_to_backing_table() { Set<Table.Cell<String, String, String>> cellSet = Collections.singleton(Tables.immutableCell(STRING_ROW_KEY_1, STRING_COLUMN_KEY_1, STRING_VALUE_1)); when(backingTableMock.cellSet()).thenReturn(cellSet); Table.Cell<Float, Long, Integer> expectedCell = Tables.immutableCell(ROW_KEY_1, COLUMN_KEY_1, VALUE_1); //noinspection unchecked assertThat(transformingTable.cellSet(), containsInAnyOrder(expectedCell)); }
@Override public Set<Cell<R, C, V>> cellSet() { return new AbstractSet<Cell<R, C, V>>() { @Override public int size() { return TableView.this.size(); } @Override public boolean isEmpty() { return TableView.this.isEmpty(); } @Override public boolean contains(Object o) { if(!(o instanceof Cell)) return false; final Cell cell = (Cell) o; return Objects.equals(get(cell.getRowKey(), cell.getColumnKey()), cell.getValue()); } @Override public Stream<Cell<R, C, V>> stream() { return map.entrySet() .stream() .flatMap(row -> row.getValue() .entrySet() .stream() .map(col -> Tables.immutableCell(row.getKey(), col.getKey(), col.getValue()))); } @Override public Spliterator<Cell<R, C, V>> spliterator() { return stream().spliterator(); } @Override public Iterator<Cell<R, C, V>> iterator() { return Spliterators.iterator(spliterator()); } }; }
@Nonnull @Override public Table<HOLDER, Class<Object>, Object> getAll() { return Tables.unmodifiableTable(metadata); }
public ReflexSparseMatrixValue transpose() { ReflexSparseMatrixValue ret = new ReflexSparseMatrixValue(2); ret.table = Tables.transpose(table); return ret; }
@Override public Table<R, C, V> apply(Table<? extends R, ? extends C, ? extends V> input) { return input == null ? null : Tables.unmodifiableTable(input); }
public PhaseVfsStatistics(ProfilePhase phase) { this.phase = phase; this.statistics = Tables.newCustomTable( new EnumMap<ProfilerTask, Map<String, Stat>>(ProfilerTask.class), HashMap::new); }
@Override public Table<Integer, String, String> load(InlineTable inlineTable){ return Tables.unmodifiableTable(parse(inlineTable)); }
@Test public void contains_value_returns_false_if_does_not_contain_value_in_row() throws StorageException { setAzureTableToContain(Tables.immutableCell(ROW_KEY_1, OTHER_COLUMN_KEY, VALUE_1)); assertThat(rowView.containsValue(VALUE_1), is(equalTo(false))); }
@Test public void contains_value_returns_false_if_does_not_contain_value_in_row() throws StorageException { setAzureTableToContain(Tables.immutableCell(OTHER_ROW_KEY, COLUMN_KEY_1, VALUE_1)); assertThat(columnView.containsValue(VALUE_1), is(equalTo(false))); }
/** * Returns an unmodifiable view of the table of inclusion rules: rows are * metamodel URIs, columns are type names or WILDCARD (meaning all types in * the metamodel) and cells are either sets of slot names or a singleton set * with WILDCARD (meaning "all"). An empty table means "include everything". */ public Table<String, String, ImmutableSet<String>> getInclusionRules() { return Tables.unmodifiableTable(inclusions); }
/** * Returns an unmodifiable view of the table of exclusion rules: rows are * metamodel URIs, columns are type names and cells are either sets of slot * names or a singleton set with WILDCARD (meaning "all"). An empty table * means "exclude nothing". */ public Table<String, String, ImmutableSet<String>> getExclusionRules() { return Tables.unmodifiableTable(exclusions); }