List of usage examples for com.google.common.collect LinkedListMultimap create
public static <K, V> LinkedListMultimap<K, V> create()
From source file:pt.org.aguiaj.core.typewidgets.WidgetFactory.java
private WidgetFactory() { widgetTypeTable = newHashMap(); objectWidgetTypeTable = LinkedListMultimap.create(); }
From source file:org.eigenbase.rel.WindowRel.java
/** * Creates a WindowRel.//from ww w . ja v a 2 s . co m */ public static RelNode create(RelOptCluster cluster, RelTraitSet traitSet, RelNode child, final RexProgram program, RelDataType outRowType) { // Build a list of distinct windows, partitions and aggregate // functions. final Multimap<WindowKey, RexOver> windowMap = LinkedListMultimap.create(); // Build a list of windows, partitions, and aggregate functions. Each // aggregate function will add its arguments as outputs of the input // program. for (RexNode agg : program.getExprList()) { if (agg instanceof RexOver) { addWindows(windowMap, (RexOver) agg); } } final Map<RexOver, WindowRelBase.RexWinAggCall> aggMap = new HashMap<RexOver, WindowRelBase.RexWinAggCall>(); List<Window> windowList = new ArrayList<Window>(); for (Map.Entry<WindowKey, Collection<RexOver>> entry : windowMap.asMap().entrySet()) { final WindowKey windowKey = entry.getKey(); final List<RexWinAggCall> aggCalls = new ArrayList<RexWinAggCall>(); for (RexOver over : entry.getValue()) { final RexWinAggCall aggCall = new RexWinAggCall(over.getAggOperator(), over.getType(), toInputRefs(over.operands), aggMap.size()); aggCalls.add(aggCall); aggMap.put(over, aggCall); } windowList.add(new Window(windowKey.groupSet, windowKey.isRows, windowKey.lowerBound, windowKey.upperBound, windowKey.orderKeys, aggCalls)); } // Figure out the type of the inputs to the output program. // They are: the inputs to this rel, followed by the outputs of // each window. final List<WindowRelBase.RexWinAggCall> flattenedAggCallList = new ArrayList<WindowRelBase.RexWinAggCall>(); List<Map.Entry<String, RelDataType>> fieldList = new ArrayList<Map.Entry<String, RelDataType>>( child.getRowType().getFieldList()); final int offset = fieldList.size(); // Use better field names for agg calls that are projected. Map<Integer, String> fieldNames = new HashMap<Integer, String>(); for (Ord<RexLocalRef> ref : Ord.zip(program.getProjectList())) { final int index = ref.e.getIndex(); if (index >= offset) { fieldNames.put(index - offset, outRowType.getFieldNames().get(ref.i)); } } for (Ord<Window> window : Ord.zip(windowList)) { for (Ord<RexWinAggCall> over : Ord.zip(window.e.aggCalls)) { // Add the k-th over expression of // the i-th window to the output of the program. String name = fieldNames.get(over.i); if (name == null || name.startsWith("$")) { name = "w" + window.i + "$o" + over.i; } fieldList.add(Pair.of(name, over.e.getType())); flattenedAggCallList.add(over.e); } } final RelDataType intermediateRowType = cluster.getTypeFactory().createStructType(fieldList); final int inputFieldCount = child.getRowType().getFieldCount(); // The output program is the windowed agg's program, combined with // the output calc (if it exists). RexShuttle shuttle = new RexShuttle() { public RexNode visitOver(RexOver over) { // Look up the aggCall which this expr was translated to. final WindowRelBase.RexWinAggCall aggCall = aggMap.get(over); assert aggCall != null; assert RelOptUtil.eq("over", over.getType(), "aggCall", aggCall.getType(), true); // Find the index of the aggCall among all partitions of all // windows. final int aggCallIndex = flattenedAggCallList.indexOf(aggCall); assert aggCallIndex >= 0; // Replace expression with a reference to the window slot. final int index = inputFieldCount + aggCallIndex; assert RelOptUtil.eq("over", over.getType(), "intermed", intermediateRowType.getFieldList().get(index).getType(), true); return new RexInputRef(index, over.getType()); } public RexNode visitLocalRef(RexLocalRef localRef) { final int index = localRef.getIndex(); if (index < inputFieldCount) { // Reference to input field. return localRef; } return new RexLocalRef(flattenedAggCallList.size() + index, localRef.getType()); } }; // TODO: The order that the "over" calls occur in the windows and // partitions may not match the order in which they occurred in the // original expression. We should add a project to permute them. WindowRel window = new WindowRel(cluster, traitSet, child, intermediateRowType, windowList); return CalcRel.createProject(window, new AbstractList<RexNode>() { public RexNode get(int index) { final RexLocalRef ref = program.getProjectList().get(index); return new RexInputRef(ref.getIndex(), ref.getType()); } public int size() { return program.getProjectList().size(); } }, outRowType.getFieldNames()); }
From source file:bgu.dcr.az.exen.util.TaskMonitor.java
public TaskMonitor(T monitored) { this.monitored = monitored; this.state = ""; this.progress = 0; this.maxProgress = 0; this.running = false; this.started = false; this.children = LinkedListMultimap.create(); this.listeners = new LinkedList<TaskMonitorListener<T>>(); }
From source file:com.madvay.tools.android.perf.apat.CommandLine.java
public CommandLine(String[] argv) { if (argv.length < 1) { throw new IllegalArgumentException("1st argument must be name of a command."); }//from w w w . j a va 2 s . c o m command = argv[0]; args = new ArrayList<>(); flags = LinkedListMultimap.create(); List<String> allArgs = Lists.newArrayList(argv); allArgs.remove(0); parseArgs(allArgs); }
From source file:br.com.caelum.vraptor.serialization.Serializee.java
public Multimap<String, Class<?>> getExcludes() { if (excludes == null) { excludes = LinkedListMultimap.create(); } return excludes; }
From source file:springfox.documentation.builders.BuilderDefaults.java
/** * Returns an empty map if the input is null * * @param newValue - nullable map value/*from w w w.j av a 2 s .c o m*/ * @param <K> - map key * @param <V> - map value * @return non-null Map */ public static <K, V> Multimap<K, V> nullToEmptyMultimap(Multimap<K, V> newValue) { if (newValue == null) { return LinkedListMultimap.create(); } return newValue; }
From source file:com.rackspacecloud.blueflood.io.AbstractMetricsRW.java
/** * Convert a collection of {@link com.rackspacecloud.blueflood.types.IMetric} * to a {@link com.google.common.collect.Multimap} * * @param metrics//from w w w .java2 s .c om * @return */ protected Multimap<Locator, IMetric> asMultimap(Collection<IMetric> metrics) { Multimap<Locator, IMetric> map = LinkedListMultimap.create(); for (IMetric metric : metrics) map.put(metric.getLocator(), metric); return map; }
From source file:com.github.rinde.rinsim.central.RandomSolver.java
@Override public ImmutableList<ImmutableList<Parcel>> solve(GlobalStateObject state) { checkArgument(!state.getVehicles().isEmpty(), "Need at least one vehicle."); final LinkedListMultimap<VehicleStateObject, Parcel> map = LinkedListMultimap.create(); final Set<Parcel> available = newLinkedHashSet(state.getAvailableParcels()); final Set<Parcel> destinations = newLinkedHashSet(); for (final VehicleStateObject vso : state.getVehicles()) { destinations.addAll(vso.getDestination().asSet()); }/* w w w.ja v a2 s .com*/ available.removeAll(destinations); // do random assignment of available parcels for (final Parcel p : available) { final int index = randomGenerator.nextInt(state.getVehicles().size()); map.put(state.getVehicles().get(index), p); map.put(state.getVehicles().get(index), p); } final ImmutableList.Builder<ImmutableList<Parcel>> builder = ImmutableList.builder(); // insert contents, shuffle ordering, insert destination if applicable for (final VehicleStateObject vso : state.getVehicles()) { final List<Parcel> assigned = newArrayList(map.get(vso)); final List<Parcel> conts = newArrayList(vso.getContents()); conts.removeAll(vso.getDestination().asSet()); assigned.addAll(conts); if (vso.getDestination().isPresent() && state.getAvailableParcels().contains(vso.getDestination().get())) { assigned.add(vso.getDestination().get()); } Collections.shuffle(assigned, new RandomAdaptor(randomGenerator)); if (vso.getDestination().isPresent()) { assigned.add(0, vso.getDestination().get()); } builder.add(ImmutableList.copyOf(assigned)); } return builder.build(); }
From source file:org.kitesdk.data.spi.KeyRangeIterable.java
@Override @SuppressWarnings("unchecked") public Iterator<MarkerRange> iterator() { // this should be part of PartitionStrategy final LinkedListMultimap<String, FieldPartitioner> partitioners = LinkedListMultimap.create(); for (FieldPartitioner fp : strategy.getFieldPartitioners()) { partitioners.put(fp.getSourceName(), fp); }//from w w w . jav a2 s.c om Iterator<MarkerRange.Builder> current = start(new MarkerRange.Builder(cmp)); // primarily loop over sources because the logical constraints are there for (String source : partitioners.keySet()) { Predicate constraint = predicates.get(source); List<FieldPartitioner> fps = partitioners.get(source); FieldPartitioner first = fps.get(0); if (first instanceof CalendarFieldPartitioner) { current = TimeDomain.get(strategy, source).addStackedIterator(constraint, current); } else if (constraint instanceof Predicates.In) { current = add((Predicates.In) constraint, fps, current); } else if (constraint instanceof Range) { current = add((Range) constraint, fps, current); } } return Iterators.transform(current, new ToMarkerRangeFunction()); }
From source file:org.sonar.server.search.Result.java
public Result(@Nullable BaseIndex<K, ?, ?> index, SearchResponse response) { this.index = index; this.scrollId = response.getScrollId(); this.facets = LinkedListMultimap.create(); this.total = (int) response.getHits().totalHits(); this.hits = new ArrayList<K>(); if (index != null) { for (SearchHit hit : response.getHits()) { this.hits.add(index.toDoc(hit.getSource())); }/*from ww w .j ava2s . co m*/ } if (response.getAggregations() != null) { for (Map.Entry<String, Aggregation> facet : response.getAggregations().asMap().entrySet()) { this.processAggregation(facet.getValue()); } } }