List of usage examples for com.google.common.collect Table size
int size();
From source file:com.android.tools.idea.uibuilder.property.NlPropertiesPanel.java
@NotNull private static List<NlPropertyItem> extractPropertiesForTable( @NotNull Table<String, String, NlPropertyItem> properties) { Map<String, NlPropertyItem> androidProperties = properties.row(SdkConstants.ANDROID_URI); Map<String, NlPropertyItem> autoProperties = properties.row(SdkConstants.AUTO_URI); Map<String, NlPropertyItem> designProperties = properties.row(TOOLS_URI); Map<String, NlPropertyItem> bareProperties = properties.row(""); // Include all auto (app) properties and all android properties that are not also auto properties. List<NlPropertyItem> result = new ArrayList<>(properties.size()); result.addAll(autoProperties.values()); for (Map.Entry<String, NlPropertyItem> entry : androidProperties.entrySet()) { if (!autoProperties.containsKey(entry.getKey())) { result.add(entry.getValue()); }// ww w . j ava 2 s . c o m } result.addAll(designProperties.values()); result.addAll(bareProperties.values()); return result; }
From source file:qa.qcri.nadeef.test.udf.MyTestRule1.java
@Override public void iterator(Collection<Table> blocks, IteratorResultHandler iteratorResultHandler) { Table table = blocks.iterator().next(); for (int i = 0; i < table.size(); i++) { iteratorResultHandler.handle(table.get(i)); }/* ww w . ja v a2s .c o m*/ }
From source file:qa.qcri.nadeef.test.udf.AdultRule2.java
@Override public void iterator(Collection<Table> tables, IteratorResultHandler iteratorResultHandler) { Table table = tables.iterator().next(); ArrayList<TuplePair> result = new ArrayList<>(); for (int i = 0; i < table.size(); i++) { for (int j = i + 1; j < table.size(); j++) { Tuple left = table.get(i);//from ww w. j a v a 2s . c o m Tuple right = table.get(j); if (!left.get("fnlwgt").equals(right.get("fnlwgt"))) { TuplePair pair = new TuplePair(table.get(i), table.get(j)); iteratorResultHandler.handle(pair); break; } } } }
From source file:qa.qcri.nadeef.core.datamodel.PairTupleRule.java
/** * Iterator operation.//ww w. j a va 2 s . co m * * @param tables input tuple */ @Override public void iterator(Collection<Table> tables, IteratorResultHandler iteratorResultHandler) { List<Table> collectionList = Lists.newArrayList(tables); if (collectionList.size() == 1) { Table tuples = collectionList.get(0); for (int i = 0; i < tuples.size(); i++) { for (int j = i + 1; j < tuples.size(); j++) { TuplePair pair = new TuplePair(tuples.get(i), tuples.get(j)); iteratorResultHandler.handle(pair); } } } else { Table left = collectionList.get(0); Table right = collectionList.get(1); for (int i = 0; i < left.size(); i++) { for (int j = 0; j < right.size(); j++) { TuplePair pair = new TuplePair(left.get(i), right.get(j)); iteratorResultHandler.handle(pair); } } } }
From source file:org.dishevelled.analysis.AnalysisUtils.java
/** * Convert the specified table to a binary key map. * * @param <N> table row and column key type * @param <E> table value type and binary key map value type * @param table table to convert, must not be null * @return the specified table converted to a binary key map *//*from w w w. j a v a 2 s.c o m*/ public static <N, E> BinaryKeyMap<N, N, E> toBinaryKeyMap(final Table<N, N, E> table) { if (table == null) { throw new IllegalArgumentException("table must not be null"); } int e = Math.max(DEFAULT_SIZE, table.size()); final BinaryKeyMap<N, N, E> binaryKeyMap = createBinaryKeyMap(e); for (Table.Cell<N, N, E> cell : table.cellSet()) { binaryKeyMap.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue()); } return binaryKeyMap; }
From source file:qa.qcri.nadeef.test.udf.MyRule3.java
/** * Default iterator operation./* ww w . j a v a 2 s . c o m*/ * * @param tables input tables. */ @Override public void iterator(Collection<Table> tables, IteratorResultHandler iteratorResultHandler) { Table table = tables.iterator().next(); table.orderBy(rightHandSide); int pos1 = 0, pos2 = 0; boolean findViolation = false; // --------------------------------------------------- // two pointer loop via the block. Linear scan // --------------------------------------------------- while (pos1 < table.size()) { for (pos2 = pos1 + 1; pos2 < table.size(); pos2++) { Tuple left = table.get(pos1); Tuple right = table.get(pos2); findViolation = !left.hasSameValue(right); // generates all the violations between pos1 - pos2. if (findViolation) { for (int i = pos1; i < pos2; i++) { for (int j = pos2; j < table.size(); j++) { TuplePair pair = new TuplePair(table.get(i), table.get(j)); iteratorResultHandler.handle(pair); } } break; } } pos1 = pos2; } }
From source file:qa.qcri.nadeef.core.datamodel.PairTupleRule.java
/** * Incremental iterator interface.//from www. ja va2 s .co m * @param blocks blocks. * @param newTuples new tuples comes in. * @param iteratorResultHandler output stream. */ public final void iterator(Collection<Table> blocks, ConcurrentMap<String, HashSet<Integer>> newTuples, IteratorResultHandler iteratorResultHandler) { // We are dealing with two table rule. if (blocks.size() > 1) { Iterator<Table> iterator = blocks.iterator(); Table table1 = iterator.next(); Table table2 = iterator.next(); String tableName1 = table1.getSchema().getTableName(); String tableName2 = table2.getSchema().getTableName(); HashSet<Integer> tableSet1 = newTuples.get(tableName1); HashSet<Integer> tableSet2 = newTuples.get(tableName2); for (int i = 0; i < table1.size(); i++) { Tuple tuple1 = table1.get(i); if (!tableSet1.contains(tuple1.getTid())) continue; for (int j = 0; j < table2.size(); j++) { Tuple tuple2 = table2.get(j); iteratorResultHandler.handle(new TuplePair(tuple1, tuple2)); } } for (int i = 0; i < table2.size(); i++) { Tuple tuple2 = table2.get(i); if (!tableSet2.contains(tuple2.getTid())) continue; for (int j = 0; j < table1.size(); j++) { Tuple tuple1 = table1.get(j); if (tableSet1.contains(tuple1.getTid())) continue; iteratorResultHandler.handle(new TuplePair(tuple1, tuple2)); } } } else { // One table rule Table block = blocks.iterator().next(); String tableName = block.getSchema().getTableName(); if (newTuples.containsKey(tableName)) { HashSet<Integer> newTuplesIDs = newTuples.get(tableName); // iterating all the tuples for (int i = 0; i < block.size(); i++) { Tuple tuple1 = block.get(i); if (newTuplesIDs.contains(tuple1.getTid())) { for (int j = 0; j < block.size(); j++) { if (j != i) { Tuple tuple2 = block.get(j); if (newTuplesIDs.contains(tuple2.getTid())) { // Both are new tuples, check once if (j > i) { iteratorResultHandler.handle(new TuplePair(tuple1, tuple2)); } } else { // Compare with old tuples iteratorResultHandler.handle(new TuplePair(tuple1, tuple2)); } } } } } } } }
From source file:org.dishevelled.analysis.AnalysisUtils.java
/** * Convert the specified table to a graph, adding edges for values accepted * by the specified predicate. The row key value will be the source node and the column * key value the target node in edges in the returned graph. * * @param <N> table row and column key type and graph node type * @param <E> table value type and graph edge type * @param table table to convert, must not be null * @param predicate table value predicate, must not be null * @return the specified table converted to a graph *///from ww w . jav a2s . co m public static <N, E> Graph<N, E> toGraph(final Table<N, N, E> table, final UnaryPredicate<E> predicate) { if (table == null) { throw new IllegalArgumentException("table must not be null"); } if (predicate == null) { throw new IllegalArgumentException("predicate must not be null"); } int n = Math.max(DEFAULT_SIZE, Math.max(table.columnKeySet().size(), table.rowKeySet().size())); int e = Math.max(DEFAULT_SIZE, table.size()); Map<N, Node<N, E>> nodes = createMap(n); Graph<N, E> graph = createGraph(n, e); for (Table.Cell<N, N, E> cell : table.cellSet()) { N sourceValue = cell.getRowKey(); N targetValue = cell.getColumnKey(); E value = cell.getValue(); if (!nodes.containsKey(sourceValue)) { nodes.put(sourceValue, graph.createNode(sourceValue)); } if (!nodes.containsKey(targetValue)) { nodes.put(targetValue, graph.createNode(targetValue)); } if (value != null && predicate.test(value)) { graph.createEdge(nodes.get(sourceValue), nodes.get(targetValue), value); } } return graph; }
From source file:org.joda.beans.ser.GuavaSerIteratorFactory.java
/** * Gets an iterator wrapper for {@code Table}. * // www . j a v a 2 s . c o m * @param table the collection, not null * @param declaredType the declared type, not null * @param rowType the row type, not null * @param colType the col type, not null * @param valueType the value type, not null * @param valueTypeTypes the generic parameters of the value type * @return the iterator, not null */ @SuppressWarnings("rawtypes") public static final SerIterator table(final Table<?, ?, ?> table, final Class<?> declaredType, final Class<?> rowType, final Class<?> colType, final Class<?> valueType, final List<Class<?>> valueTypeTypes) { return new SerIterator() { private final Iterator it = table.cellSet().iterator(); private Cell current; @Override public String metaTypeName() { return "Table"; } @Override public boolean metaTypeRequired() { return Table.class.isAssignableFrom(declaredType) == false; } @Override public SerCategory category() { return SerCategory.TABLE; } @Override public int size() { return table.size(); } @Override public boolean hasNext() { return it.hasNext(); } @Override public void next() { current = (Cell) it.next(); } @Override public Class<?> keyType() { return rowType; } @Override public Object key() { return current.getRowKey(); } @Override public Class<?> columnType() { return colType; } @Override public Object column() { return current.getColumnKey(); } @Override public Class<?> valueType() { return valueType; } @Override public List<Class<?>> valueTypeTypes() { return valueTypeTypes; } @Override public Object value() { return current.getValue(); } }; }
From source file:org.caleydo.data.importer.tcga.FirehoseProvider.java
private static File parseMAF(File maf) { File out = new File(maf.getParentFile(), "P" + maf.getName()); if (out.exists()) return out; log.fine(maf.getAbsolutePath() + " parsing maf file"); final String TAB = "\t"; try (BufferedReader reader = Files.newBufferedReader(maf.toPath(), Charset.forName("UTF-8"))) { List<String> header = Arrays.asList(reader.readLine().split(TAB)); int geneIndex = header.indexOf("Hugo_Symbol"); int sampleIndex = header.indexOf("Tumor_Sample_Barcode"); // gene x sample x mutated Table<String, String, Boolean> mutated = TreeBasedTable.create(); String line = null;/*from w w w .j av a 2s. co m*/ while ((line = reader.readLine()) != null) { String[] columns = line.split(TAB); mutated.put(columns[geneIndex], columns[sampleIndex], Boolean.TRUE); } File tmp = new File(out.getParentFile(), out.getName() + ".tmp"); PrintWriter w = new PrintWriter(tmp); w.append("Hugo_Symbol"); List<String> cols = new ArrayList<>(mutated.columnKeySet()); for (String sample : cols) { w.append(TAB).append(sample); } w.println(); Set<String> rows = mutated.rowKeySet(); for (String gene : rows) { w.append(gene); for (String sample : cols) { w.append(TAB).append(mutated.contains(gene, sample) ? '1' : '0'); } w.println(); } w.close(); Files.move(tmp.toPath(), out.toPath(), StandardCopyOption.REPLACE_EXISTING); log.fine(maf.getAbsolutePath() + " parsed maf file stats: " + mutated.size() + " " + rows.size() + " " + cols.size()); return out; } catch (IOException e) { log.log(Level.SEVERE, maf.getAbsolutePath() + " maf parsing error: " + e.getMessage(), e); } return null; }