List of usage examples for com.google.common.collect Lists newArrayListWithCapacity
@GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayListWithCapacity(int initialArraySize)
From source file:goja.initialize.ctxbox.ClassSearcher.java
public ClassSearcher(Class target) { targets = Lists.newArrayListWithCapacity(11); this.targets.add(target); }
From source file:com.arpnetworking.tsdcore.sinks.FilteringSink.java
/** * {@inheritDoc}// w w w .j a va 2 s .c om */ @Override public void recordAggregateData(final Collection<AggregatedData> data, final Collection<Condition> conditions) { // This is optimistic that most/all of the data will pass the filters. final List<AggregatedData> filteredData = Lists.newArrayListWithCapacity(data.size()); for (final AggregatedData datum : data) { final String metric = datum.getFQDSN().getMetric(); final Boolean cachedResult = _cachedFilterResult.getUnchecked(metric); if (cachedResult.booleanValue()) { filteredData.add(datum); } } final List<Condition> filteredConditions = Lists.newArrayListWithCapacity(conditions.size()); for (final Condition condition : conditions) { final String metric = condition.getFQDSN().getMetric(); final Boolean cachedResult = _cachedFilterResult.getUnchecked(metric); if (cachedResult.booleanValue()) { filteredConditions.add(condition); } } if (!filteredData.isEmpty() || !filteredConditions.isEmpty()) { _sink.recordAggregateData(filteredData, filteredConditions); } }
From source file:org.apache.tez.dag.app.dag.impl.BroadcastEdgeManager.java
@Override public void routeDataMovementEventToDestination(DataMovementEvent event, int sourceTaskIndex, int numDestinationTasks, Map<Integer, List<Integer>> inputIndicesToTaskIndices) { List<Integer> taskIndices = Lists.newArrayListWithCapacity(numDestinationTasks); addAllDestinationTaskIndices(numDestinationTasks, taskIndices); inputIndicesToTaskIndices.put(new Integer(sourceTaskIndex), taskIndices); }
From source file:org.apache.mahout.ga.watchmaker.travellingsalesman.ItineraryPanel.java
ItineraryPanel(Collection<String> cities) { super(new BorderLayout()); Container checkBoxPanel = new JPanel(new GridLayout(0, 1)); checkBoxes = Lists.newArrayListWithCapacity(cities.size()); for (String city : cities) { JCheckBox checkBox = new JCheckBox(city, false); checkBoxes.add(checkBox);/*from w w w . j ava 2s.co m*/ checkBoxPanel.add(checkBox); } add(checkBoxPanel, BorderLayout.CENTER); Container buttonPanel = new JPanel(new GridLayout(2, 1)); selectAllButton = new JButton("Select All"); buttonPanel.add(selectAllButton); clearButton = new JButton("Clear Selection"); buttonPanel.add(clearButton); ActionListener buttonListener = new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { boolean select = actionEvent.getSource() == selectAllButton; for (JCheckBox checkBox : checkBoxes) { checkBox.setSelected(select); } } }; selectAllButton.addActionListener(buttonListener); clearButton.addActionListener(buttonListener); add(buttonPanel, BorderLayout.SOUTH); setBorder(BorderFactory.createTitledBorder("Itinerary")); }
From source file:com.lastcalc.parsers.collections.ApplyTo.java
@Override public ParseResult parse(final TokenList tokens, final int templatePos, final ParserContext context) { final UserDefinedParser udp = (UserDefinedParser) tokens.get(templatePos + 1); final Object datastructure = tokens.get(templatePos + 3); List<Object> ret; if (datastructure instanceof List) { if (udp.variables.size() != 1 || udp.getTemplate().size() != 1) return ParseResult.fail(); final List<Object> list = (List<Object>) datastructure; ret = Lists.newArrayListWithCapacity(list.size() * 4); ret.add("["); for (final Object o : list) { final TokenList r = context.parseEngine .parseAndGetLastStep(udp.parse(TokenList.createD(o), 0).output, context); Iterables.addAll(ret, r);//from ww w .j a va2s . c om ret.add(","); } ret.set(ret.size() - 1, "]"); // Overwrite last comma } else return ParseResult.fail(); return ParseResult.success( tokens.replaceWithTokenList(templatePos, templatePos + template.size(), TokenList.create(ret))); }
From source file:edu.bsu.cybersec.core.narrative.ScriptKiddieAttackEvent.java
@Override public List<? extends Option> options() { List<Option> options = Lists.newArrayListWithCapacity(5); for (Entity e : availableWorkers()) { options.add(new RetaliateOption(e.id)); }//from ww w .j a v a 2 s . c om options.add(new Option.DoNothingOption("Do Nothing")); options.add(new ReportToThePoliceOption()); return options; }
From source file:org.cfr.restlet.ext.shindig.uri.PassthruManager.java
public List<Uri> make(List<ProxyUri> resource, Integer forcedRefresh) { List<Uri> ctx = Lists.newArrayListWithCapacity(resource.size()); for (ProxyUri res : resource) { ctx.add(getUri(res.getResource())); }// w w w.ja v a 2s .c om return ImmutableList.copyOf(ctx); }
From source file:eu.project.ttc.engines.morpho.Segmentation.java
private Segmentation(String word, List<CuttingPoint> cuttingPoints) { super();/*from w ww . j ava 2s . c om*/ this.string = word; this.cuttingPoints = cuttingPoints; this.segments = Lists.newArrayListWithCapacity(cuttingPoints.size() + 1); int lastBegin = 0; for (CuttingPoint cp : this.cuttingPoints) { this.segments.add(Segment.createFromParentString(lastBegin, cp.getIndex(), this.string)); lastBegin = cp.getIndex() + cp.getOffset(); } this.segments.add(Segment.createFromParentString(lastBegin, this.string.length(), this.string)); }
From source file:com.lastcalc.parsers.collections.Filter.java
@Override public ParseResult parse(final TokenList tokens, final int templatePos, final ParserContext context) { final UserDefinedParser udp = (UserDefinedParser) tokens.get(templatePos + 3); final Object datastructure = tokens.get(templatePos + 1); List<Object> ret; if (datastructure instanceof List) { if (udp.variables.size() != 1 || udp.getTemplate().size() != 1) return ParseResult.fail(); final List<Object> list = (List<Object>) datastructure; ret = Lists.newArrayListWithCapacity(list.size() * 4); ret.add("["); for (final Object o : list) { final TokenList result = context.parseEngine .parseAndGetLastStep(udp.parse(TokenList.createD(o), 0).output, context); if (result.size() != 1 || !(result.get(0) instanceof Boolean)) return ParseResult.fail(); if (result.get(0).equals(true)) { ret.add(o);/*from ww w .j a v a 2 s . c om*/ ret.add(","); } } ret.set(ret.size() - 1, "]"); // Overwrite last comma } else return ParseResult.fail(); return ParseResult.success( tokens.replaceWithTokenList(templatePos, templatePos + template.size(), TokenList.create(ret))); }
From source file:org.apache.brooklyn.core.config.external.vault.VaultAppIdExternalConfigSupplier.java
protected String initAndLogIn(Map<String, String> config) { List<String> errors = Lists.newArrayListWithCapacity(1); String appId = config.get("appId"); if (Strings.isBlank(appId)) errors.add("missing configuration 'appId'"); if (!errors.isEmpty()) { String message = String.format("Problem configuration Vault external config supplier '%s': %s", name, Joiner.on(System.lineSeparator()).join(errors)); throw new IllegalArgumentException(message); }/* ww w . java2 s. c o m*/ String userId = getUserId(config); LOG.info("Config supplier named {} using Vault at {} appID {} userID {} path {}", new Object[] { name, endpoint, appId, userId, path }); String path = "v1/auth/app-id/login"; ImmutableMap<String, String> requestData = ImmutableMap.of("app_id", appId, "user_id", userId); ImmutableMap<String, String> headers = MINIMAL_HEADERS; JsonObject response = apiPost(path, headers, requestData); return response.getAsJsonObject("auth").get("client_token").getAsString(); }