项目:guava-mock
文件:TablesTest.java
public void testToTable() {
Collector<Cell<String,String,Integer>,?,Table<String,Integer>> collector =
Tables.toTable(Cell::getRowKey,Cell::getColumnKey,Cell::getValue,HashBasedTable::create);
Equivalence<Table<String,Integer>> equivalence =
Equivalence.equals().<Cell<String,Integer>>pairwise().onResultOf(Table::cellSet);
CollectorTester.of(collector,equivalence)
.expectCollects(
new ImmutableTable.Builder<String,Integer>()
.put("one","uno",1)
.put("two","dos",2)
.put("three","tres",3)
.build(),Tables.immutableCell("one",1),Tables.immutableCell("two",2),Tables.immutableCell("three",3));
}
项目:guava-mock
文件:TablesTest.java
public void testToTableNullMerge() {
Collector<Cell<String,Integer>> collector =
Tables.toTable(
Cell::getRowKey,(Integer v1,Integer v2) -> null,equivalence)
.expectCollects(
ImmutableTable.of(),2));
}
项目:guava-mock
文件:TablesTest.java
public void testToTableMerging() {
Collector<Cell<String,Integer::sum,6)
.put("three",3),4));
}
项目:guava-mock
文件:ImmutableTableTest.java
public void testToImmutableTable() {
Collector<Cell<String,ImmutableTable<String,Integer>> collector =
ImmutableTable.toImmutableTable(Cell::getRowKey,Cell::getValue);
Equivalence<ImmutableTable<String,Integer>> equivalence =
Equivalence.equals()
.<Cell<String,Integer>>pairwise()
.onResultOf(ImmutableTable::cellSet);
CollectorTester.of(collector,3));
}
项目:guava-mock
文件:ImmutableTableTest.java
public void testToImmutableTableMerging() {
Collector<Cell<String,Integer>> collector =
ImmutableTable.toImmutableTable(
Cell::getRowKey,Integer::sum);
Equivalence<ImmutableTable<String,4));
}
项目:googles-monorepo-demo
文件:TablesTest.java
public void testToTable() {
Collector<Cell<String,3));
}
项目:googles-monorepo-demo
文件:TablesTest.java
public void testToTableNullMerge() {
Collector<Cell<String,2));
}
项目:googles-monorepo-demo
文件:TablesTest.java
public void testToTableMerging() {
Collector<Cell<String,4));
}
项目:googles-monorepo-demo
文件:ImmutableTableTest.java
public void testToImmutableTable() {
Collector<Cell<String,3));
}
项目:googles-monorepo-demo
文件:ImmutableTableTest.java
public void testToImmutableTableMerging() {
Collector<Cell<String,4));
}
项目:famf
文件:SparseMatrix.java
/**
* 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,Float> cell : dataTable.cellSet())
colMap.put(cell.getColumnKey(),cell.getRowKey());
}
construct(dataTable,colMap);
}
项目:Rapture
文件:FoldNode.java
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,cell.getRowKey()));
params.add(new AtomNode(lineNumber,cell.getColumnKey()));
params.add(new AtomNode(lineNumber,cell.getValue()));
accum = f.invoke(debugger,lineNumber,params,functions,importHandler);
}
return accum;
}
项目:Rapture
文件:MapFnNode.java
private ReflexValue mapMatrix(IReflexDebugger debugger,3)); // 1
// parameter
ReflexSparseMatrixValue smv = arg.asMatrix();
ReflexSparseMatrixValue mappedSmv = new ReflexSparseMatrixValue(2);
mappedSmv.copyOrder(smv);
for(Cell<ReflexValue,cell.getValue()));
ReflexValue ret = f.invoke(debugger,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);
}
项目:Rapture
文件:FilterFnNode.java
private ReflexValue workOnMatrix(IReflexDebugger debugger,3));
ReflexSparseMatrixValue smb = arg.asMatrix();
ReflexSparseMatrixValue filteredMatrix = new ReflexSparseMatrixValue(2);
for(Cell<ReflexValue,ReflexValue> cell : smb.getCells()) {
List<ReflexNode> params = new ArrayList<ReflexNode>();
params.add(new AtomNode(lineNumber,cell.getValue()));
ReflexValue innerRet = f.invoke(debugger,importHandler);
if (innerRet.isBoolean() && innerRet.asBoolean() == true) {
filteredMatrix.set(cell.getRowKey(),cell.getColumnKey(),cell.getValue());
}
}
return new ReflexValue(filteredMatrix);
}
项目:JAADAS
文件:JimpleIDESolver.java
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();
}
}
项目:JAADAS
文件:IDESolver.java
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,EdgeFunction<V>>> lookupByTarget;
lookupByTarget = jumpFn.lookupByTarget(n);
for(Cell<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++;
}
}
}
}
项目:cerebro-layout
文件:JungCommunityComputer.java
private void populateFromFlows(DynamicFlowGraph flowGraph) {
int eid = 0;
for(Cell<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;
}
}
}
项目:cerebro-layout
文件:Spine.java
public void initGraphicGraph() {
int uniqId = 0;
for(Cell<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,id);
}
weighEdges();
}
项目:cerebro-layout
文件:RossalExecCsvReader.java
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> 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,count);
}
}
return graph;
}
项目:codebuff
文件:RegularImmutableTable.java
/**
* A factory that chooses the most space-efficient representation of the
* table.
*/
private static final <R,C,V> RegularImmutableTable<R,V> forCellsInternal(Iterable<Cell<R,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,V>> cellList = ImmutableList.copyOf(cells);
for (Cell<R,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,V>(cellList,rowSpace,columnSpace) : new SparseImmutableTable<R,columnSpace);
}
项目:codebuff
文件:RegularImmutableTable.java
/**
* A factory that chooses the most space-efficient representation of the
* table.
*/
private static final <R,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,columnSpace);
}
项目:turnus
文件:BufferSizeEditor.java
@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,Integer> element = (Cell<Pair<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();
}
}
}
项目:turnus
文件:FileExporterFactory.java
/**
* 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,FileExporter<?>> e : exporters.cellSet()) {
if (e.getColumnKey().equals(output))
inputs.add(e.getRowKey());
}
return inputs;
}
项目:turnus
文件:AverageTraceWeighter.java
/**
* 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,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,variance);
}
}
项目:turnus
文件:NormalDistributionTraceWeighter.java
/**
* 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,w.getMaxClockCycles());
double weight = (min + 4 * avg + max) / 6.0;
double variance = Math.pow(((max - min) / 6.0),weight);
varianceTable.put(actor,variance);
}
}
项目:EasySRL
文件:AbstractParser.java
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());
}
}
项目:EasySRL
文件:ParallelCorpusReader.java
private static Collection<SRLParse> getPropbankSection(final String section) throws IOException {
final Table<String,TreebankParse> PTB = new PennTreebank().readCorpus(WSJ);
final Table<String,SRLParse> srlParses = SRLParse.parseCorpus(PTB,Util.readFileLineByLine(new File(PROPBANK,"prop.txt")),USING_NOMBANK ? Util.readFileLineByLine(NOMBANK) : null);
final Table<String,SRLParse> goldParses = TreeBasedTable.create();
for (final Cell<String,TreebankParse> cell : PTB.cellSet()) {
// Propbank files skip sentences with no SRL deps. Add a default
// empty parse for all sentences.
goldParses.put(cell.getRowKey(),new SRLParse(cell.getValue().getWords()));
}
goldParses.putAll(srlParses);
final Collection<SRLParse> result = new ArrayList<>();
for (final Cell<String,SRLParse> entry : goldParses.cellSet()) {
if (entry.getRowKey().startsWith("wsj_" + section)) {
result.add(entry.getValue());
}
}
return result;
}
项目:bue-common-open
文件:ProvenancedConfusionMatrix.java
/**
* 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,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());
}
项目:guava
文件:TablesTest.java
public void testToTable() {
Collector<Cell<String,3));
}
项目:guava
文件:TablesTest.java
public void testToTableNullMerge() {
Collector<Cell<String,2));
}
项目:guava
文件:TablesTest.java
public void testToTableMerging() {
Collector<Cell<String,4));
}
项目:guava
文件:ImmutableTableTest.java
public void testToImmutableTable() {
Collector<Cell<String,3));
}
项目:guava
文件:ImmutableTableTest.java
public void testToImmutableTableMerging() {
Collector<Cell<String,4));
}
项目:kidneyExchange
文件:MinWaitingTimeKepSolver.java
private ImmutableTable<V,V,Double> getPrecedenceVariableValues(
VariableSet.VariableExtractor variableExtractor) {
ImmutableTable.Builder<V,Double> ans = ImmutableTable.builder();
List<Cell<V,IloNumVar>> varsAsList = Lists
.newArrayList(this.precedenceVariables.cellSet());
IloNumVar[] varArray = new IloNumVar[varsAsList.size()];
int i = 0;
for (Cell<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();
}
项目:kidneyExchange
文件:MinWaitingTimeKepSolver.java
private void printDeltaVars(VariableSet.VariableExtractor variableExtractor) {
List<Cell<V,IloNumVar>> varsAsList = Lists
.newArrayList(this.precedenceVariables.cellSet());
IloNumVar[] varArray = new IloNumVar[varsAsList.size()];
int i = 0;
for (Cell<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]);
}
}
项目:guava-mock
文件:Tables.java
/**
* 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,I extends Table<R,V>> Collector<T,I> toTable(
java.util.function.Function<? super T,? extends R> rowFunction,java.util.function.Function<? super T,? extends C> columnFunction,? 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,V> cell2 : table2.cellSet()) {
merge(table1,cell2.getRowKey(),cell2.getColumnKey(),cell2.getValue(),mergeFunction);
}
return table1;
});
}
项目:guava-mock
文件:Tables.java
@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;
}
项目:guava-mock
文件:Tables.java
Function<Cell<R,V1>,Cell<R,V2>> cellFunction() {
return new Function<Cell<R,V2>>() {
@Override
public Cell<R,V2> apply(Cell<R,V1> cell) {
return immutableCell(
cell.getRowKey(),function.apply(cell.getValue()));
}
};
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。