@Generates private static <K, V> ArrayListMultimap<K, V> generateArrayListMultimap(K key, V value) { ArrayListMultimap<K, V> multimap = ArrayListMultimap.create(); multimap.put(key, value); return multimap; }
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) { if (type == ArrayListMultimap.class) { ArrayListMultimap multimap = ArrayListMultimap.create(); JSONObject object = parser.parseObject(); for (Map.Entry entry : object.entrySet()) { Object value = entry.getValue(); if (value instanceof Collection) { multimap.putAll(entry.getKey(), (List) value); } else { multimap.put(entry.getKey(), value); } } return (T) multimap; } return null; }
@Override public Optional<Multimap<String, String>> validate() { final ArrayListMultimap<String, String> errors = ArrayListMultimap.create(); final Path path = Paths.get(path()); if (!Files.exists(path)) { errors.put("path", "The file does not exist."); } else if (!Files.isReadable(path)) { errors.put("path", "The file cannot be read."); } return errors.isEmpty() ? Optional.empty() : Optional.of(errors); }
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) { if (type == ArrayListMultimap.class) { ArrayListMultimap multimap = ArrayListMultimap.create(); JSONObject object = parser.parseObject(); for (Map.Entry entry : object.entrySet()) { Object value = entry.getValue(); if (value instanceof Collection) { multimap.putAll(entry.getKey(), (List) value); } else { multimap.put(entry.getKey(), value); } } return (T) multimap; } return null; }
@Override public Optional<Multimap<String, String>> validate() { final ArrayListMultimap<String, String> errors = ArrayListMultimap.create(); final Path path = Paths.get(path()); if (!Files.exists(path)) { errors.put("path", "The file does not exist."); } else if (!Files.isReadable(path)) { errors.put("path", "The file cannot be read."); } return errors.isEmpty() ? Optional.empty() : Optional.of(errors); }
public void testCopyOfWithDuplicates() { ArrayListMultimap<Object, Object> input = ArrayListMultimap.create(); input.put("foo", 1); input.put("bar", 2); input.put("foo", 3); input.put("foo", 1); ImmutableSetMultimap<Object, Object> copy = ImmutableSetMultimap.copyOf(input); assertEquals(3, copy.size()); }
public void testCopyOfWithDuplicates() { ArrayListMultimap<String, Integer> input = ArrayListMultimap.create(); input.put("foo", 1); input.put("bar", 2); input.put("foo", 3); input.put("foo", 1); Multimap<String, Integer> multimap = ImmutableListMultimap.copyOf(input); assertEquals(multimap, input); assertEquals(input, multimap); }
public synchronized void tryRelease(Channel channel) { String host = channel.attr(hostKey).getAndSet(null); List<Channel> channels = channelPool.get(host); if (channels == null || channels.size() < maxConnPerHost) { LOGGER.debug("tryRelease channel success, host={}", host); channelPool.put(host, channel); } else { LOGGER.debug("tryRelease channel pool size over limit={}, host={}, channel closed.", maxConnPerHost, host); channel.close(); } }
@Override public Optional<Multimap<String, String>> validate() { final ArrayListMultimap<String, String> errors = ArrayListMultimap.create(); if (HttpUrl.parse(url()) == null) { errors.put("url", "Unable to parse url: " + url()); } return errors.isEmpty() ? Optional.empty() : Optional.of(errors); }
@Override public Optional<Multimap<String, String>> validate() { final ArrayListMultimap<String, String> errors = ArrayListMultimap.create(); if (StringUtils.isNotBlank(serverIps()) && !DnsClient.allIpAddressesValid(serverIps())) { errors.put(FIELD_SERVER_IPS, "Invalid server IP address and/or port. " + "Please enter one or more comma-separated IPv4 addresses with optional ports (eg. 192.168.1.1:5353, 192.168.1.244)."); } if (requestTimeout() < 1) { errors.put(FIELD_REQUEST_TIMEOUT, "Value cannot be smaller than 1"); } return errors.isEmpty() ? Optional.empty() : Optional.of(errors); }
@Override public Optional<Multimap<String, String>> validate() { final ArrayListMultimap<String, String> errors = ArrayListMultimap.create(); if (HttpUrl.parse(url()) == null) { errors.put("url", "Invalid URL."); } try { final JsonPath jsonPath = JsonPath.compile(singleValueJSONPath()); if (!jsonPath.isDefinite()) { errors.put("single_value_jsonpath", "JSONPath does not return a single value."); } } catch (InvalidPathException e) { errors.put("single_value_jsonpath", "Invalid JSONPath."); } if (multiValueJSONPath().isPresent()) { try { JsonPath.compile(multiValueJSONPath().get()); } catch (InvalidPathException e) { errors.put("multi_value_jsonpath", "Invalid JSONPath."); } } return errors.isEmpty() ? Optional.empty() : Optional.of(errors); }
public Configuration(Set<Pipeline> pipelines) { if (pipelines.isEmpty()) { initialStage = extent[0] = extent[1] = 0; return; } pipelines.forEach(pipeline -> { // skip pipelines without any stages, they don't contribute any rules to run final SortedSet<Stage> stages = pipeline.stages(); if (stages.isEmpty()) { return; } extent[0] = Math.min(extent[0], stages.first().stage()); extent[1] = Math.max(extent[1], stages.last().stage()); stages.forEach(stage -> stageMultimap.put(stage.stage(), stage)); }); if (extent[0] == Integer.MIN_VALUE) { throw new IllegalArgumentException("First stage cannot be at " + Integer.MIN_VALUE); } // the stage before the first stage. initialStage = extent[0] - 1; }
public void testCopyOfNullKey() { ArrayListMultimap<String, Integer> input = ArrayListMultimap.create(); input.put(null, 1); try { ImmutableListMultimap.copyOf(input); fail(); } catch (NullPointerException expected) { } }
public void testTrimToSize() { ArrayListMultimap<String, Integer> multimap = ArrayListMultimap.create(); multimap.put("foo", 1); multimap.put("foo", 2); multimap.put("bar", 3); multimap.trimToSize(); assertEquals(3, multimap.size()); assertThat(multimap.get("foo")).containsExactly(1, 2).inOrder(); assertThat(multimap.get("bar")).contains(3); } }
private ArrayListMultimap<String, AggregateFunction<?, ?>> getAggregateFunctionMultimap() { ArrayListMultimap<String, AggregateFunction<?, ?>> reductionMultimap = ArrayListMultimap.create(); for (String name: summarizedColumns) { Column<?> column = temp.column(name); ColumnType type = column.type(); for (AggregateFunction<?, ?> reduction : reductions) { if (reduction.isCompatibleColumn(type)) { reductionMultimap.put(name, reduction); } } } if (reductionMultimap.isEmpty()) { throw new IllegalArgumentException("None of the aggregate functions provided apply to the summarized column type(s)."); } return reductionMultimap; }
private static ArrayListMultimap<String, TableScanOperator> splitTableScanOpsByTable( ParseContext pctx) { ArrayListMultimap<String, TableScanOperator> tableNameToOps = ArrayListMultimap.create(); // Sort by operator ID so we get deterministic results Map<String, TableScanOperator> sortedTopOps = new TreeMap<>(pctx.getTopOps()); for (Entry<String, TableScanOperator> e : sortedTopOps.entrySet()) { TableScanOperator tsOp = e.getValue(); tableNameToOps.put( tsOp.getConf().getTableMetadata().getDbName() + "." + tsOp.getConf().getTableMetadata().getTableName(), tsOp); } return tableNameToOps; }
if( (end == from.length()) || (from.charAt(end) != '{') ) { _placeholders.put(pname, new Placeholder(cur.clone(), cur.clone())); } else { throw new ArrayIndexOutOfBoundsException("Missing } after replacement group"); _placeholders.put(pname, new Placeholder(cur.clone(), cur.clone(), from.substring(start, end))); ++end;
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { ArrayListMultimap<Object, Object> map = ArrayListMultimap.create(); while (reader.hasMoreChildren()) { reader.moveDown(); String key = reader.getAttribute("key"); Object value = null; // in this case we also support complex objects while (reader.hasMoreChildren()) { reader.moveDown(); value = readItem(reader, context, map); reader.moveUp(); } reader.moveUp(); if (value != null) { map.put(key, value); } } return map; } }
public GraphExplorer(Graph graph, Weighting accessEgressWeighting, PtFlagEncoder flagEncoder, GtfsStorage gtfsStorage, RealtimeFeed realtimeFeed, boolean reverse, List<VirtualEdgeIteratorState> extraEdges, boolean walkOnly, double walkSpeedKmh) { this.graph = graph; this.accessEgressWeighting = accessEgressWeighting; DefaultEdgeFilter accessEgressIn = DefaultEdgeFilter.inEdges(accessEgressWeighting.getFlagEncoder()); DefaultEdgeFilter accessEgressOut = DefaultEdgeFilter.outEdges(accessEgressWeighting.getFlagEncoder()); DefaultEdgeFilter ptIn = DefaultEdgeFilter.inEdges(flagEncoder); DefaultEdgeFilter ptOut = DefaultEdgeFilter.outEdges(flagEncoder); EdgeFilter in = edgeState -> accessEgressIn.accept(edgeState) || ptIn.accept(edgeState); EdgeFilter out = edgeState -> accessEgressOut.accept(edgeState) || ptOut.accept(edgeState); this.edgeExplorer = graph.createEdgeExplorer(reverse ? in : out); this.flagEncoder = flagEncoder; this.gtfsStorage = gtfsStorage; this.realtimeFeed = realtimeFeed; this.reverse = reverse; this.extraEdges.addAll(extraEdges); for (VirtualEdgeIteratorState extraEdge : extraEdges) { if (extraEdge == null) { throw new RuntimeException(); } extraEdgesBySource.put(extraEdge.getBaseNode(), extraEdge); extraEdgesByDestination.put(extraEdge.getAdjNode(), new VirtualEdgeIteratorState(extraEdge.getOriginalTraversalKey(), extraEdge.getEdge(), extraEdge.getAdjNode(), extraEdge.getBaseNode(), extraEdge.getDistance(), extraEdge.getFlags(), extraEdge.getName(), extraEdge.fetchWayGeometry(3))); } this.walkOnly = walkOnly; this.walkSpeedKmH = walkSpeedKmh; }