Java Code Examples for com.google.common.collect.Table.Cell

The following are top voted examples for showing how to use com.google.common.collect.Table.Cell. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: guava-mock   File: TablesTest.java   Source Code and License 6 votes vote down vote up
public void testToTable() {
  Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector =
      Tables.toTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue, HashBasedTable::create);
  Equivalence<Table<String, String, Integer>> equivalence =
      Equivalence.equals().<Cell<String, String, Integer>>pairwise().onResultOf(Table::cellSet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          new ImmutableTable.Builder<String, String, Integer>()
              .put("one", "uno", 1)
              .put("two", "dos", 2)
              .put("three", "tres", 3)
              .build(),
          Tables.immutableCell("one", "uno", 1),
          Tables.immutableCell("two", "dos", 2),
          Tables.immutableCell("three", "tres", 3));
}
 
Example 2
Project: guava-mock   File: TablesTest.java   Source Code and License 6 votes vote down vote up
public void testToTableNullMerge() {
  Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector =
      Tables.toTable(
          Cell::getRowKey,
          Cell::getColumnKey,
          Cell::getValue,
          (Integer v1, Integer v2) -> null,
          HashBasedTable::create);
  Equivalence<Table<String, String, Integer>> equivalence =
      Equivalence.equals().<Cell<String, String, Integer>>pairwise().onResultOf(Table::cellSet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          ImmutableTable.of(),
          Tables.immutableCell("one", "uno", 1),
          Tables.immutableCell("one", "uno", 2));
}
 
Example 3
Project: guava-mock   File: TablesTest.java   Source Code and License 6 votes vote down vote up
public void testToTableMerging() {
  Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector =
      Tables.toTable(
          Cell::getRowKey,
          Cell::getColumnKey,
          Cell::getValue,
          Integer::sum,
          HashBasedTable::create);
  Equivalence<Table<String, String, Integer>> equivalence =
      Equivalence.equals().<Cell<String, String, Integer>>pairwise().onResultOf(Table::cellSet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          new ImmutableTable.Builder<String, String, Integer>()
              .put("one", "uno", 1)
              .put("two", "dos", 6)
              .put("three", "tres", 3)
              .build(),
          Tables.immutableCell("one", "uno", 1),
          Tables.immutableCell("two", "dos", 2),
          Tables.immutableCell("three", "tres", 3),
          Tables.immutableCell("two", "dos", 4));
}
 
Example 4
Project: guava-mock   File: ImmutableTableTest.java   Source Code and License 6 votes vote down vote up
public void testToImmutableTable() {
  Collector<Cell<String, String, Integer>, ?, ImmutableTable<String, String, Integer>> collector =
      ImmutableTable.toImmutableTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue);
  Equivalence<ImmutableTable<String, String, Integer>> equivalence =
      Equivalence.equals()
          .<Cell<String, String, Integer>>pairwise()
          .onResultOf(ImmutableTable::cellSet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          new ImmutableTable.Builder<String, String, Integer>()
              .put("one", "uno", 1)
              .put("two", "dos", 2)
              .put("three", "tres", 3)
              .build(),
          Tables.immutableCell("one", "uno", 1),
          Tables.immutableCell("two", "dos", 2),
          Tables.immutableCell("three", "tres", 3));
}
 
Example 5
Project: guava-mock   File: ImmutableTableTest.java   Source Code and License 6 votes vote down vote up
public void testToImmutableTableMerging() {
  Collector<Cell<String, String, Integer>, ?, ImmutableTable<String, String, Integer>> collector =
      ImmutableTable.toImmutableTable(
          Cell::getRowKey, Cell::getColumnKey, Cell::getValue, Integer::sum);
  Equivalence<ImmutableTable<String, String, Integer>> equivalence =
      Equivalence.equals()
          .<Cell<String, String, Integer>>pairwise()
          .onResultOf(ImmutableTable::cellSet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          new ImmutableTable.Builder<String, String, Integer>()
              .put("one", "uno", 1)
              .put("two", "dos", 6)
              .put("three", "tres", 3)
              .build(),
          Tables.immutableCell("one", "uno", 1),
          Tables.immutableCell("two", "dos", 2),
          Tables.immutableCell("three", "tres", 3),
          Tables.immutableCell("two", "dos", 4));
}
 
Example 6
Project: googles-monorepo-demo   File: TablesTest.java   Source Code and License 6 votes vote down vote up
public void testToTable() {
  Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector =
      Tables.toTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue, HashBasedTable::create);
  Equivalence<Table<String, String, Integer>> equivalence =
      Equivalence.equals().<Cell<String, String, Integer>>pairwise().onResultOf(Table::cellSet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          new ImmutableTable.Builder<String, String, Integer>()
              .put("one", "uno", 1)
              .put("two", "dos", 2)
              .put("three", "tres", 3)
              .build(),
          Tables.immutableCell("one", "uno", 1),
          Tables.immutableCell("two", "dos", 2),
          Tables.immutableCell("three", "tres", 3));
}
 
Example 7
Project: googles-monorepo-demo   File: TablesTest.java   Source Code and License 6 votes vote down vote up
public void testToTableNullMerge() {
  Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector =
      Tables.toTable(
          Cell::getRowKey,
          Cell::getColumnKey,
          Cell::getValue,
          (Integer v1, Integer v2) -> null,
          HashBasedTable::create);
  Equivalence<Table<String, String, Integer>> equivalence =
      Equivalence.equals().<Cell<String, String, Integer>>pairwise().onResultOf(Table::cellSet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          ImmutableTable.of(),
          Tables.immutableCell("one", "uno", 1),
          Tables.immutableCell("one", "uno", 2));
}
 
Example 8
Project: googles-monorepo-demo   File: TablesTest.java   Source Code and License 6 votes vote down vote up
public void testToTableMerging() {
  Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector =
      Tables.toTable(
          Cell::getRowKey,
          Cell::getColumnKey,
          Cell::getValue,
          Integer::sum,
          HashBasedTable::create);
  Equivalence<Table<String, String, Integer>> equivalence =
      Equivalence.equals().<Cell<String, String, Integer>>pairwise().onResultOf(Table::cellSet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          new ImmutableTable.Builder<String, String, Integer>()
              .put("one", "uno", 1)
              .put("two", "dos", 6)
              .put("three", "tres", 3)
              .build(),
          Tables.immutableCell("one", "uno", 1),
          Tables.immutableCell("two", "dos", 2),
          Tables.immutableCell("three", "tres", 3),
          Tables.immutableCell("two", "dos", 4));
}
 
Example 9
Project: googles-monorepo-demo   File: ImmutableTableTest.java   Source Code and License 6 votes vote down vote up
public void testToImmutableTable() {
  Collector<Cell<String, String, Integer>, ?, ImmutableTable<String, String, Integer>> collector =
      ImmutableTable.toImmutableTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue);
  Equivalence<ImmutableTable<String, String, Integer>> equivalence =
      Equivalence.equals()
          .<Cell<String, String, Integer>>pairwise()
          .onResultOf(ImmutableTable::cellSet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          new ImmutableTable.Builder<String, String, Integer>()
              .put("one", "uno", 1)
              .put("two", "dos", 2)
              .put("three", "tres", 3)
              .build(),
          Tables.immutableCell("one", "uno", 1),
          Tables.immutableCell("two", "dos", 2),
          Tables.immutableCell("three", "tres", 3));
}
 
Example 10
Project: googles-monorepo-demo   File: ImmutableTableTest.java   Source Code and License 6 votes vote down vote up
public void testToImmutableTableMerging() {
  Collector<Cell<String, String, Integer>, ?, ImmutableTable<String, String, Integer>> collector =
      ImmutableTable.toImmutableTable(
          Cell::getRowKey, Cell::getColumnKey, Cell::getValue, Integer::sum);
  Equivalence<ImmutableTable<String, String, Integer>> equivalence =
      Equivalence.equals()
          .<Cell<String, String, Integer>>pairwise()
          .onResultOf(ImmutableTable::cellSet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          new ImmutableTable.Builder<String, String, Integer>()
              .put("one", "uno", 1)
              .put("two", "dos", 6)
              .put("three", "tres", 3)
              .build(),
          Tables.immutableCell("one", "uno", 1),
          Tables.immutableCell("two", "dos", 2),
          Tables.immutableCell("three", "tres", 3),
          Tables.immutableCell("two", "dos", 4));
}
 
Example 11
Project: famf   File: SparseMatrix.java   Source Code and License 6 votes vote down vote up
/**
 * Construct a sparse matrix with CRS structures (CCS structure optional).
 * 
 * @deprecated I don't recommend to use this method as it (takes time and)
 *             is better to constructe the column structure at the time when
 *             you construct the row structure (of data table). This method
 *             is put here (as an example) to show how to construct column
 *             structure according to the data table.
 */
public SparseMatrix(int rows, int cols,
		Table<Integer, Integer, Float> dataTable, boolean isCCSUsed) {
	numRows = rows;
	numColumns = cols;

	Multimap<Integer, Integer> colMap = null;

	if (isCCSUsed) {
		colMap = HashMultimap.create();
		for (Cell<Integer, Integer, Float> cell : dataTable.cellSet())
			colMap.put(cell.getColumnKey(), cell.getRowKey());
	}

	construct(dataTable, colMap);
}
 
Example 12
Project: Rapture   File: FoldNode.java   Source Code and License 6 votes vote down vote up
private ReflexValue accumMatrix(IReflexDebugger debugger, Scope scope, ReflexValue arg) {
    Function f = functions.getFunction(FunctionFactory.createFunctionKey(fnName, 4)); // 2
                                                                              // parameters,
                                                                              // accumulator
                                                                              // and
    // array value
    ReflexValue accum = accumulator.evaluate(debugger, scope);
    ReflexSparseMatrixValue smv = arg.asMatrix();
    
    for (Cell<ReflexValue, ReflexValue, ReflexValue> cell : smv.getCells()) {
        List<ReflexNode> params = new ArrayList<ReflexNode>();
        params.add(new AtomNode(lineNumber, handler, scope, accum));
        params.add(new AtomNode(lineNumber, handler, scope, cell.getRowKey()));
        params.add(new AtomNode(lineNumber, handler, scope, cell.getColumnKey()));
        params.add(new AtomNode(lineNumber, handler, scope, cell.getValue()));
        accum = f.invoke(debugger, lineNumber, params, functions, handler, scope, importHandler);
    }
    return accum;
}
 
Example 13
Project: Rapture   File: MapFnNode.java   Source Code and License 6 votes vote down vote up
private ReflexValue mapMatrix(IReflexDebugger debugger, Scope scope, ReflexValue arg) {
    Function f = functions.getFunction(FunctionFactory.createFunctionKey(fnName, 3)); // 1
    // parameter
    ReflexSparseMatrixValue smv = arg.asMatrix();
    ReflexSparseMatrixValue mappedSmv = new ReflexSparseMatrixValue(2);
    mappedSmv.copyOrder(smv);
    for(Cell<ReflexValue, ReflexValue, ReflexValue> cell : smv.getCells()) {
        List<ReflexNode> params = new ArrayList<ReflexNode>();
        params.add(new AtomNode(lineNumber, handler, scope, cell.getRowKey()));
        params.add(new AtomNode(lineNumber, handler, scope, cell.getColumnKey()));
        params.add(new AtomNode(lineNumber, handler, scope, cell.getValue()));
        ReflexValue ret = f.invoke(debugger, lineNumber, params, functions, handler, scope, importHandler);
        // Ret should be a list [ row, col, value ]
        if (ret.isList()) {
            List<ReflexValue> mappedValues = ret.asList();
            if (mappedValues.size() == 3) {
                mappedSmv.set(mappedValues.get(0), mappedValues.get(1), mappedValues.get(2));
            }
        }
    }
    return new ReflexValue(mappedSmv);
}
 
Example 14
Project: Rapture   File: FilterFnNode.java   Source Code and License 6 votes vote down vote up
private ReflexValue workOnMatrix(IReflexDebugger debugger, Scope scope, ReflexValue arg) {
    Function f = functions.getFunction(FunctionFactory.createFunctionKey(fnName, 3));
    ReflexSparseMatrixValue smb = arg.asMatrix();
    ReflexSparseMatrixValue filteredMatrix = new ReflexSparseMatrixValue(2);
    for(Cell<ReflexValue, ReflexValue, ReflexValue> cell : smb.getCells()) {
        List<ReflexNode> params = new ArrayList<ReflexNode>();
        params.add(new AtomNode(lineNumber, handler, scope, cell.getRowKey()));
        params.add(new AtomNode(lineNumber, handler, scope, cell.getColumnKey()));
        params.add(new AtomNode(lineNumber, handler, scope, cell.getValue()));
        ReflexValue innerRet = f.invoke(debugger, lineNumber, params, functions, handler, scope, importHandler);
        if (innerRet.isBoolean() && innerRet.asBoolean() == true) {
            filteredMatrix.set(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
        }          
    }
    return new ReflexValue(filteredMatrix);
}
 
Example 15
Project: JAADAS   File: JimpleIDESolver.java   Source Code and License 6 votes vote down vote up
public void dumpResults() {
	try {
		PrintWriter out = new PrintWriter(new FileOutputStream("ideSolverDump"+System.currentTimeMillis()+".csv"));
		List<String> res = new ArrayList<String>();
		for(Cell<Unit, D, V> entry: val.cellSet()) {
			SootMethod methodOf = (SootMethod) icfg.getMethodOf(entry.getRowKey());
			PatchingChain<Unit> units = methodOf.getActiveBody().getUnits();
			int i=0;
			for (Unit unit : units) {
				if(unit==entry.getRowKey())
					break;
				i++;
			}

			res.add(methodOf+";"+entry.getRowKey()+"@"+i+";"+entry.getColumnKey()+";"+entry.getValue());
		}
		Collections.sort(res);
		for (String string : res) {
			out.println(string);
		}
		out.flush();
		out.close();
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	}
}
 
Example 16
Project: JAADAS   File: IDESolver.java   Source Code and License 6 votes vote down vote up
public void run() {
	int sectionSize = (int) Math.floor(values.length / numThreads) + numThreads;
	for(int i = sectionSize * num; i < Math.min(sectionSize * (num+1),values.length); i++) {
		N n = values[i];
		for(N sP: icfg.getStartPointsOf(icfg.getMethodOf(n))) {					
			Set<Cell<D, D, EdgeFunction<V>>> lookupByTarget;
			lookupByTarget = jumpFn.lookupByTarget(n);
			for(Cell<D, D, EdgeFunction<V>> sourceValTargetValAndFunction : lookupByTarget) {
				D dPrime = sourceValTargetValAndFunction.getRowKey();
				D d = sourceValTargetValAndFunction.getColumnKey();
				EdgeFunction<V> fPrime = sourceValTargetValAndFunction.getValue();
				synchronized (val) {
					setVal(n,d,valueLattice.join(val(n,d),fPrime.computeTarget(val(sP,dPrime))));
				}
				flowFunctionApplicationCount++;
			}
		}
	}
}
 
Example 17
Project: cerebro-layout   File: JungCommunityComputer.java   Source Code and License 6 votes vote down vote up
private void populateFromFlows(DynamicFlowGraph flowGraph) {
  int eid = 0;
  for(Cell<Integer, Integer, Integer> edge : flowGraph.getEdges()) {
    int from = edge.getRowKey();
    int to = edge.getColumnKey();
    if(!jungGraph.containsVertex(from)) {
      jungGraph.addVertex(from);
    }
    
    if(!jungGraph.containsVertex(to)) {
      jungGraph.addVertex(to);
    }
    
    int edgeCount = edge.getValue();
    
    for(int i = 0; i < edgeCount; i += 1) {
      jungGraph.addEdge(eid, from, to, EdgeType.DIRECTED);
      eid += 1;
    }
  }
}
 
Example 18
Project: cerebro-layout   File: Spine.java   Source Code and License 6 votes vote down vote up
public void initGraphicGraph() {
  int uniqId = 0;
  for(Cell<Integer, Integer, Integer> edge : flowGraph.getEdges()) {
    double weight = edge.getValue();
    System.out.format("%s %s %s\n", edge.getRowKey(), edge.getColumnKey(), weight);
    String fromId = String.valueOf(edge.getRowKey());
    String toId = String.valueOf(edge.getColumnKey());
    
    Node from = this.addNode(fromId);
    Node to = this.addNode(toId);
    
    int id = uniqId++;
    addEdge(from, to, id);
  }
  
  weighEdges();
}
 
Example 19
Project: cerebro-layout   File: RossalExecCsvReader.java   Source Code and License 6 votes vote down vote up
public DynamicFlowGraph readAll(File ... rossalCsvs) {
  DynamicFlowGraph graph = new DynamicFlowGraph();
  for(File csv : rossalCsvs) {
    if(csv == null || !csv.exists() || !csv.isFile() 
        || !csv.getName().endsWith(".csv")) {
      continue;
    }
    
    DynamicFlowGraph tempGraph = read(csv);
    for(Cell<Integer, Integer, Integer> edge : tempGraph.getEdges()) {
      int fromId = edge.getRowKey();
      SourceLineNode from = tempGraph.getNode(fromId);
      from = graph.addNode(SourceLineNode.clone(from));
      
      int toId = edge.getColumnKey();
      SourceLineNode to = tempGraph.getNode(toId);
      
      to = graph.addNode(SourceLineNode.clone(to));
      
      int count = edge.getValue();
      graph.addEdge(from, to, count);
    }
  }
  return graph;
}
 
Example 20
Project: codebuff   File: RegularImmutableTable.java   Source Code and License 6 votes vote down vote up
/**
 * A factory that chooses the most space-efficient representation of the
 * table.
 */

private static final <R, C, V> RegularImmutableTable<R, C, V> forCellsInternal(Iterable<Cell<R, C, V>> cells, @Nullable Comparator<? super R> rowComparator, @Nullable Comparator<? super C> columnComparator) {
  Set<R> rowSpaceBuilder = new LinkedHashSet<R>();
  Set<C> columnSpaceBuilder = new LinkedHashSet<C>();
  ImmutableList<Cell<R, C, V>> cellList = ImmutableList.copyOf(cells);
  for (Cell<R, C, V> cell : cells) {
    rowSpaceBuilder.add(cell.getRowKey());
    columnSpaceBuilder.add(cell.getColumnKey());
  }
  ImmutableSet<R> rowSpace = (rowComparator == null)
    ? ImmutableSet.copyOf(rowSpaceBuilder)
    : ImmutableSet.copyOf(Ordering.from(rowComparator).immutableSortedCopy(rowSpaceBuilder));
  ImmutableSet<C> columnSpace = (columnComparator == null)
    ? ImmutableSet.copyOf(columnSpaceBuilder)
    : ImmutableSet.copyOf(Ordering.from(columnComparator).immutableSortedCopy(columnSpaceBuilder));

  // use a dense table if more than half of the cells have values
  // TODO(gak): tune this condition based on empirical evidence
  return (cellList.size() > (((long) rowSpace.size() * columnSpace.size()) / 2)) ? new DenseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace) : new SparseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace);
}
 
Example 21
Project: codebuff   File: RegularImmutableTable.java   Source Code and License 6 votes vote down vote up
/**
 * A factory that chooses the most space-efficient representation of the
 * table.
 */

private static final <R, C, V> RegularImmutableTable<R, C, V> forCellsInternal(Iterable<Cell<R, C, V>> cells, @Nullable Comparator<? super R> rowComparator, @Nullable Comparator<? super C> columnComparator) {
  Set<R> rowSpaceBuilder = new LinkedHashSet<R>();
  Set<C> columnSpaceBuilder = new LinkedHashSet<C>();
  ImmutableList<Cell<R, C, V>> cellList = ImmutableList.copyOf(cells);
  for (Cell<R, C, V> cell : cells) {
    rowSpaceBuilder.add(cell.getRowKey());
    columnSpaceBuilder.add(cell.getColumnKey());
  }
  ImmutableSet<R> rowSpace = (rowComparator == null)
    ? ImmutableSet.copyOf(rowSpaceBuilder)
    : ImmutableSet.copyOf(Ordering.from(rowComparator).immutableSortedCopy(rowSpaceBuilder));
  ImmutableSet<C> columnSpace = (columnComparator == null)
    ? ImmutableSet.copyOf(columnSpaceBuilder)
    : ImmutableSet.copyOf(Ordering.from(columnComparator).immutableSortedCopy(columnSpaceBuilder));

  // use a dense table if more than half of the cells have values
  // TODO(gak): tune this condition based on empirical evidence
  return (cellList.size() > (((long) rowSpace.size() * columnSpace.size()) / 2)) ? new DenseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace) : new SparseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace);
}
 
Example 22
Project: codebuff   File: RegularImmutableTable.java   Source Code and License 6 votes vote down vote up
/**
 * A factory that chooses the most space-efficient representation of the
 * table.
 */

private static final <R, C, V> RegularImmutableTable<R, C, V> forCellsInternal(Iterable<Cell<R, C, V>> cells, @Nullable Comparator<? super R> rowComparator, @Nullable Comparator<? super C> columnComparator) {
  Set<R> rowSpaceBuilder = new LinkedHashSet<R>();
  Set<C> columnSpaceBuilder = new LinkedHashSet<C>();
  ImmutableList<Cell<R, C, V>> cellList = ImmutableList.copyOf(cells);
  for (Cell<R, C, V> cell : cells) {
    rowSpaceBuilder.add(cell.getRowKey());
    columnSpaceBuilder.add(cell.getColumnKey());
  }
  ImmutableSet<R> rowSpace =
    (rowComparator == null)
      ? ImmutableSet.copyOf(rowSpaceBuilder)
      : ImmutableSet.copyOf(Ordering.from(rowComparator).immutableSortedCopy(rowSpaceBuilder));
  ImmutableSet<C> columnSpace =
    (columnComparator == null)
      ? ImmutableSet.copyOf(columnSpaceBuilder)
      : ImmutableSet.copyOf(Ordering.from(columnComparator).immutableSortedCopy(columnSpaceBuilder));

  // use a dense table if more than half of the cells have values
  // TODO(gak): tune this condition based on empirical evidence
  return (cellList.size() > (((long) rowSpace.size() * columnSpace.size()) / 2)) ? new DenseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace) : new SparseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace);
}
 
Example 23
Project: codebuff   File: RegularImmutableTable.java   Source Code and License 6 votes vote down vote up
/**
 * A factory that chooses the most space-efficient representation of the
 * table.
 */

private static final <R, C, V> RegularImmutableTable<R, C, V> forCellsInternal(Iterable<Cell<R, C, V>> cells, @Nullable Comparator<? super R> rowComparator, @Nullable Comparator<? super C> columnComparator) {
  Set<R> rowSpaceBuilder = new LinkedHashSet<R>();
  Set<C> columnSpaceBuilder = new LinkedHashSet<C>();
  ImmutableList<Cell<R, C, V>> cellList = ImmutableList.copyOf(cells);
  for (Cell<R, C, V> cell : cells) {
    rowSpaceBuilder.add(cell.getRowKey());
    columnSpaceBuilder.add(cell.getColumnKey());
  }
  ImmutableSet<R> rowSpace = (rowComparator == null)
    ? ImmutableSet.copyOf(rowSpaceBuilder)
    : ImmutableSet.copyOf(Ordering.from(rowComparator).immutableSortedCopy(rowSpaceBuilder));
  ImmutableSet<C> columnSpace = (columnComparator == null)
    ? ImmutableSet.copyOf(columnSpaceBuilder)
    : ImmutableSet.copyOf(Ordering.from(columnComparator).immutableSortedCopy(columnSpaceBuilder));

  // use a dense table if more than half of the cells have values
  // TODO(gak): tune this condition based on empirical evidence
  return (cellList.size() > (((long) rowSpace.size() * columnSpace.size()) / 2)) ? new DenseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace) : new SparseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace);
}
 
Example 24
Project: turnus   File: BufferSizeEditor.java   Source Code and License 6 votes vote down vote up
@Override
public void modify(Object o, String property, Object value) {
	// int columnIndex = Arrays.asList(columnNames).indexOf(property);
	if (property.equals(columnNames[SIZE])) {
		String intString = (String) value;
		if (intString.matches("[+]?\\d+")) {
			TableItem item = (TableItem) o;
			@SuppressWarnings("unchecked")
			Cell<Pair<String, String>, Pair<String, String>, Integer> element = (Cell<Pair<String, String>, Pair<String, String>, Integer>) item
					.getData();
			int oldValue = element.getValue();
			int newValue = Integer.parseInt(intString);
			if (oldValue != newValue) {
				Pair<String, String> src = element.getRowKey();
				Pair<String, String> tgt = element.getColumnKey();
				bufferSize.setSize(src.v1, src.v2, tgt.v1, tgt.v2, newValue);
				setDirty(true);
			}
			viewer.refresh();

		}
	}

}
 
Example 25
Project: turnus   File: FileExporterFactory.java   Source Code and License 6 votes vote down vote up
/**
 * Get the set of supported input file extension for a given output file
 * extension
 * 
 * @param output
 *            the output file extension (with or without {@code "."})
 * @return the set of supported input file extensions (without {@code "."})
 */
public Set<String> getSupportedInputs(String output) {
	Set<String> inputs = new HashSet<>();

	// check not null
	if (output == null) {
		return inputs;
	} else if (output.startsWith(".")) { // clean the format
		output = output.replaceFirst(".", "");
	}

	for (Cell<String, String, FileExporter<?>> e : exporters.cellSet()) {
		if (e.getColumnKey().equals(output))
			inputs.add(e.getRowKey());
	}
	return inputs;
}
 
Example 26
Project: turnus   File: AverageTraceWeighter.java   Source Code and License 6 votes vote down vote up
/**
 * Create a weighter (average values) given the network weights
 * 
 * @param networkWeights
 */
public AverageTraceWeighter(NetworkWeight networkWeights) {
	this.networkWeights = networkWeights;

	weightTable = HashBasedTable.create();
	varianceTable = HashBasedTable.create();
	for (Cell<String, String, ClockCycles> cell : networkWeights.asTable().cellSet()) {
		String actor = cell.getRowKey();
		String action = cell.getColumnKey();
		ClockCycles w = cell.getValue();

		double avg = w.getMeanClockCycles();
		double min = Math.min(w.getMinClockCycles(), avg);
		double max = Math.max(avg, w.getMaxClockCycles());
		double variance = Math.pow(((max - min) / 6.0), 2);

		weightTable.put(actor, action, avg);
		varianceTable.put(actor, action, variance);
	}
}
 
Example 27
Project: turnus   File: NormalDistributionTraceWeighter.java   Source Code and License 6 votes vote down vote up
/**
 * Create a normal distribution weighter given the network weights
 * 
 * @param networkWeights
 */
public NormalDistributionTraceWeighter(NetworkWeight networkWeights) {
	this.networkWeights = networkWeights;

	weightTable = HashBasedTable.create();
	varianceTable = HashBasedTable.create();
	for (Cell<String, String, ClockCycles> cell : networkWeights.asTable().cellSet()) {
		String actor = cell.getRowKey();
		String action = cell.getColumnKey();
		ClockCycles w = cell.getValue();

		double avg = w.getMeanClockCycles();
		double min = Math.min(w.getMinClockCycles(), avg);
		double max = Math.max(avg, w.getMaxClockCycles());

		double weight = (min + 4 * avg + max) / 6.0;
		double variance = Math.pow(((max - min) / 6.0), 2);

		weightTable.put(actor, action, weight);
		varianceTable.put(actor, action, variance);
	}
}
 
Example 28
Project: EasySRL   File: AbstractParser.java   Source Code and License 6 votes vote down vote up
public AbstractParser(final ParserBuilder<?> builder) {
	this.unaryRules = builder.getUnaryRules();
	this.seenRules = builder.getSeenRules();
	this.lexicalCategories = builder.getLexicalCategories();
	this.possibleRootCategories = ImmutableSet.copyOf(builder.getValidRootCategories());
	this.nbest = builder.getNbest();
	this.maxLength = builder.getMaxSentenceLength();
	this.binaryRules = builder.getCombinators();
	this.allowUnseenRules = builder.getAllowUnseenRules();
	this.normalForm = builder.getNormalForm();
	this.nbestBeam = builder.getNbestBeam();

	for (final Cell<Category, Category, List<RuleProduction>> entry : seenRules.ruleTable().cellSet()) {
		// Cache out all the rules in advance.
		getRules(entry.getRowKey(), entry.getColumnKey());
	}
}
 
Example 29
Project: EasySRL   File: ParallelCorpusReader.java   Source Code and License 6 votes vote down vote up
private static Collection<SRLParse> getPropbankSection(final String section) throws IOException {
	final Table<String, Integer, TreebankParse> PTB = new PennTreebank().readCorpus(WSJ);
	final Table<String, Integer, SRLParse> srlParses = SRLParse.parseCorpus(PTB,
			Util.readFileLineByLine(new File(PROPBANK, "prop.txt")),
			USING_NOMBANK ? Util.readFileLineByLine(NOMBANK) : null);

	final Table<String, Integer, SRLParse> goldParses = TreeBasedTable.create();
	for (final Cell<String, Integer, TreebankParse> cell : PTB.cellSet()) {

		// Propbank files skip sentences with no SRL deps. Add a default
		// empty parse for all sentences.
		goldParses.put(cell.getRowKey(), cell.getColumnKey(), new SRLParse(cell.getValue().getWords()));
	}
	goldParses.putAll(srlParses);

	final Collection<SRLParse> result = new ArrayList<>();
	for (final Cell<String, Integer, SRLParse> entry : goldParses.cellSet()) {
		if (entry.getRowKey().startsWith("wsj_" + section)) {
			result.add(entry.getValue());
		}
	}
	return result;
}
 
Example 30
Project: bue-common-open   File: ProvenancedConfusionMatrix.java   Source Code and License 6 votes vote down vote up
/**
 * Return a new {@code ProvenancedConfusionMatrix} containing only those provenance entries
 * matching the provided predicate.
 */
public ProvenancedConfusionMatrix<CellFiller> filteredCopy(Predicate<CellFiller> predicate) {
  final ImmutableTable.Builder<Symbol, Symbol, List<CellFiller>> newTable =
      ImmutableTable.builder();

  for (final Cell<Symbol, Symbol, List<CellFiller>> curCell : table.cellSet()) {
    final List<CellFiller> newFiller = FluentIterable.from(curCell.getValue())
        .filter(predicate).toList();
    if (!newFiller.isEmpty()) {
      newTable.put(curCell.getRowKey(), curCell.getColumnKey(), newFiller);
    }

  }

  return new ProvenancedConfusionMatrix<CellFiller>(newTable.build());
}
 
Example 31
Project: guava   File: TablesTest.java   Source Code and License 6 votes vote down vote up
public void testToTable() {
  Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector =
      Tables.toTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue, HashBasedTable::create);
  Equivalence<Table<String, String, Integer>> equivalence =
      Equivalence.equals().<Cell<String, String, Integer>>pairwise().onResultOf(Table::cellSet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          new ImmutableTable.Builder<String, String, Integer>()
              .put("one", "uno", 1)
              .put("two", "dos", 2)
              .put("three", "tres", 3)
              .build(),
          Tables.immutableCell("one", "uno", 1),
          Tables.immutableCell("two", "dos", 2),
          Tables.immutableCell("three", "tres", 3));
}
 
Example 32
Project: guava   File: TablesTest.java   Source Code and License 6 votes vote down vote up
public void testToTableNullMerge() {
  Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector =
      Tables.toTable(
          Cell::getRowKey,
          Cell::getColumnKey,
          Cell::getValue,
          (Integer v1, Integer v2) -> null,
          HashBasedTable::create);
  Equivalence<Table<String, String, Integer>> equivalence =
      Equivalence.equals().<Cell<String, String, Integer>>pairwise().onResultOf(Table::cellSet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          ImmutableTable.of(),
          Tables.immutableCell("one", "uno", 1),
          Tables.immutableCell("one", "uno", 2));
}
 
Example 33
Project: guava   File: TablesTest.java   Source Code and License 6 votes vote down vote up
public void testToTableMerging() {
  Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector =
      Tables.toTable(
          Cell::getRowKey,
          Cell::getColumnKey,
          Cell::getValue,
          Integer::sum,
          HashBasedTable::create);
  Equivalence<Table<String, String, Integer>> equivalence =
      Equivalence.equals().<Cell<String, String, Integer>>pairwise().onResultOf(Table::cellSet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          new ImmutableTable.Builder<String, String, Integer>()
              .put("one", "uno", 1)
              .put("two", "dos", 6)
              .put("three", "tres", 3)
              .build(),
          Tables.immutableCell("one", "uno", 1),
          Tables.immutableCell("two", "dos", 2),
          Tables.immutableCell("three", "tres", 3),
          Tables.immutableCell("two", "dos", 4));
}
 
Example 34
Project: guava   File: ImmutableTableTest.java   Source Code and License 6 votes vote down vote up
public void testToImmutableTable() {
  Collector<Cell<String, String, Integer>, ?, ImmutableTable<String, String, Integer>> collector =
      ImmutableTable.toImmutableTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue);
  Equivalence<ImmutableTable<String, String, Integer>> equivalence =
      Equivalence.equals()
          .<Cell<String, String, Integer>>pairwise()
          .onResultOf(ImmutableTable::cellSet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          new ImmutableTable.Builder<String, String, Integer>()
              .put("one", "uno", 1)
              .put("two", "dos", 2)
              .put("three", "tres", 3)
              .build(),
          Tables.immutableCell("one", "uno", 1),
          Tables.immutableCell("two", "dos", 2),
          Tables.immutableCell("three", "tres", 3));
}
 
Example 35
Project: guava   File: ImmutableTableTest.java   Source Code and License 6 votes vote down vote up
public void testToImmutableTableMerging() {
  Collector<Cell<String, String, Integer>, ?, ImmutableTable<String, String, Integer>> collector =
      ImmutableTable.toImmutableTable(
          Cell::getRowKey, Cell::getColumnKey, Cell::getValue, Integer::sum);
  Equivalence<ImmutableTable<String, String, Integer>> equivalence =
      Equivalence.equals()
          .<Cell<String, String, Integer>>pairwise()
          .onResultOf(ImmutableTable::cellSet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          new ImmutableTable.Builder<String, String, Integer>()
              .put("one", "uno", 1)
              .put("two", "dos", 6)
              .put("three", "tres", 3)
              .build(),
          Tables.immutableCell("one", "uno", 1),
          Tables.immutableCell("two", "dos", 2),
          Tables.immutableCell("three", "tres", 3),
          Tables.immutableCell("two", "dos", 4));
}
 
Example 36
Project: kidneyExchange   File: MinWaitingTimeKepSolver.java   Source Code and License 6 votes vote down vote up
private ImmutableTable<V, V, Double> getPrecedenceVariableValues(
    VariableSet.VariableExtractor variableExtractor) {
  ImmutableTable.Builder<V, V, Double> ans = ImmutableTable.builder();
  List<Cell<V, V, IloNumVar>> varsAsList = Lists
      .newArrayList(this.precedenceVariables.cellSet());
  IloNumVar[] varArray = new IloNumVar[varsAsList.size()];
  int i = 0;
  for (Cell<V, V, IloNumVar> cell : varsAsList) {
    varArray[i++] = cell.getValue();
  }
  double[] varVals;
  try {
    varVals = variableExtractor.getValuesVE(varArray);
  } catch (IloException e) {
    throw new RuntimeException(e);
  }
  for (int j = 0; j < varsAsList.size(); j++) {
    ans.put(varsAsList.get(j).getRowKey(), varsAsList.get(j).getColumnKey(),
        varVals[j]);
  }
  return ans.build();
}
 
Example 37
Project: kidneyExchange   File: MinWaitingTimeKepSolver.java   Source Code and License 6 votes vote down vote up
private void printDeltaVars(VariableSet.VariableExtractor variableExtractor) {

    List<Cell<V, V, IloNumVar>> varsAsList = Lists
        .newArrayList(this.precedenceVariables.cellSet());
    IloNumVar[] varArray = new IloNumVar[varsAsList.size()];
    int i = 0;
    for (Cell<V, V, IloNumVar> cell : varsAsList) {
      varArray[i++] = cell.getValue();
    }
    double[] varVals;
    try {
      varVals = variableExtractor.getValuesVE(varArray);
    } catch (IloException e) {
      throw new RuntimeException(e);
    }
    for (int j = 0; j < varsAsList.size(); j++) {
      System.out.println(varsAsList.get(j).getRowKey() + ", "
          + varsAsList.get(j).getColumnKey() + " = " + varVals[j]);
    }
  }
 
Example 38
Project: guava-mock   File: Tables.java   Source Code and License 5 votes vote down vote up
/**
 * Returns a {@link Collector} that accumulates elements into a {@code Table} created using the
 * specified supplier, whose cells are generated by applying the provided mapping functions to the
 * input elements. Cells are inserted into the generated {@code Table} in encounter order.
 *
 * <p>If multiple input elements map to the same row and column, the specified merging function is
 * used to combine the values. Like {@link
 * java.util.stream.Collectors#toMap(java.util.function.Function, java.util.function.Function,
 * BinaryOperator, java.util.function.Supplier)}, this Collector throws a {@code
 * NullPointerException} on null values returned from {@code valueFunction}, and treats nulls
 * returned from {@code mergeFunction} as removals of that row/column pair.
 *
 * @since 21.0
 */
public static <T, R, C, V, I extends Table<R, C, V>> Collector<T, ?, I> toTable(
    java.util.function.Function<? super T, ? extends R> rowFunction,
    java.util.function.Function<? super T, ? extends C> columnFunction,
    java.util.function.Function<? super T, ? extends V> valueFunction,
    BinaryOperator<V> mergeFunction,
    java.util.function.Supplier<I> tableSupplier) {
  checkNotNull(rowFunction);
  checkNotNull(columnFunction);
  checkNotNull(valueFunction);
  checkNotNull(mergeFunction);
  checkNotNull(tableSupplier);
  return Collector.of(
      tableSupplier,
      (table, input) ->
          merge(
              table,
              rowFunction.apply(input),
              columnFunction.apply(input),
              valueFunction.apply(input),
              mergeFunction),
      (table1, table2) -> {
        for (Table.Cell<R, C, V> cell2 : table2.cellSet()) {
          merge(table1, cell2.getRowKey(), cell2.getColumnKey(), cell2.getValue(), mergeFunction);
        }
        return table1;
      });
}
 
Example 39
Project: guava-mock   File: Tables.java   Source Code and License 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
  if (obj == this) {
    return true;
  }
  if (obj instanceof Cell) {
    Cell<?, ?, ?> other = (Cell<?, ?, ?>) obj;
    return Objects.equal(getRowKey(), other.getRowKey())
        && Objects.equal(getColumnKey(), other.getColumnKey())
        && Objects.equal(getValue(), other.getValue());
  }
  return false;
}
 
Example 40
Project: guava-mock   File: Tables.java   Source Code and License 5 votes vote down vote up
Function<Cell<R, C, V1>, Cell<R, C, V2>> cellFunction() {
  return new Function<Cell<R, C, V1>, Cell<R, C, V2>>() {
    @Override
    public Cell<R, C, V2> apply(Cell<R, C, V1> cell) {
      return immutableCell(
          cell.getRowKey(), cell.getColumnKey(), function.apply(cell.getValue()));
    }
  };
}