List of usage examples for com.google.common.collect Sets newHashSetWithExpectedSize
public static <E> HashSet<E> newHashSetWithExpectedSize(int expectedSize)
From source file:org.graylog2.plugin.Capabilities.java
public static Set<String> toStringSet(Set<ServerStatus.Capability> capabilities) { final Set<String> stringSet = Sets.newHashSetWithExpectedSize(capabilities.size()); for (ServerStatus.Capability capability : capabilities) { stringSet.add(capability.toString()); }//from www. j av a2s. c o m return stringSet; }
From source file:de.sebastianbenz.task.resource.Descriptions.java
public static Set<String> tagsOf(IEObjectDescription description) { String userData = description.getUserData(TAG_KEY); if (userData == null || userData.length() == 0) { return emptySet(); }//from w w w . jav a 2 s . c om String[] tags = userData.split("\\" + SEPARATOR); Set<String> result = Sets.newHashSetWithExpectedSize(tags.length); for (String tag : tags) { result.add(tag); } return result; }
From source file:se.kth.id1020.DoublingRatio.java
private static double timeTrial(int N, SumHandler handler) { int MAX = 10000000; Set<Integer> numbers = Sets.newHashSetWithExpectedSize(N); while (numbers.size() < N) { numbers.add(StdRandom.uniform(-MAX, MAX)); }/*from w ww .j a va2s . c o m*/ Stopwatch timer = new Stopwatch(); int cnt = handler.count(Ints.toArray(numbers)); return timer.elapsedTime(); }
From source file:org.graylog2.grok.GrokPatterns.java
public static Set<GrokPatternSummary> toSummarySet(Set<GrokPattern> patternSet) { final Set<GrokPatternSummary> result = Sets.newHashSetWithExpectedSize(patternSet.size()); for (GrokPattern grokPattern : patternSet) { result.add(toSummary(grokPattern)); }//from w w w. j av a 2 s .co m return result; }
From source file:com.creative.dao.entity.EntityTestFactory.java
public static Set<Environment> createEnvironments() { EnvironmentEnum[] enums = EnvironmentEnum.values(); Set<Environment> environmentSet = Sets.newHashSetWithExpectedSize(enums.length); for (EnvironmentEnum environmentEnumE : enums) { environmentSet.add(createEnvironment(environmentEnumE.name())); }/* w w w . ja va 2 s. com*/ return environmentSet; }
From source file:com.android.tools.idea.editors.strings.FontUtil.java
@NotNull public static Font getFontAbleToDisplay(@NotNull String s, @NotNull Font defaultFont) { if (SystemInfo.isMac // On Macs, all fonts can display all the characters because the system renders using fallback fonts. || isExtendedAscii(s)) { // Assume that default font can handle ASCII return defaultFont; }//www . ja v a2 s.c o m Set<Font> fonts = Sets.newHashSetWithExpectedSize(10); FontPreferences fontPreferences = EditorColorsManager.getInstance().getGlobalScheme().getFontPreferences(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) > 255) { fonts.add(ComplementaryFontsRegistry .getFontAbleToDisplay(s.charAt(i), Font.PLAIN, fontPreferences, null).getFont()); } } if (fonts.isEmpty()) { return defaultFont; } // find the font the can handle the most # of characters Font bestFont = defaultFont; int max = 0; for (Font f : fonts) { int supportedChars = 0; for (int i = 0; i < s.length(); i++) { if (f.canDisplay(s.charAt(i))) { supportedChars++; } } if (supportedChars > max) { max = supportedChars; bestFont = f; } } return bestFont; }
From source file:com.cinchapi.concourse.shell.SyntaxTools.java
/** * Check {@code line} to see if it is a function call that is missing any * commas among arguments.//from ww w . j av a2 s . c o m * * @param line * @param methods * @return the line with appropriate argument commas */ public static String handleMissingArgCommas(String line, List<String> methods) { int hashCode = methods.hashCode(); Set<String> hashedMethods = CACHED_METHODS.get(hashCode); if (hashedMethods == null) { hashedMethods = Sets.newHashSetWithExpectedSize(methods.size()); hashedMethods.addAll(methods); CACHED_METHODS.put(hashCode, hashedMethods); } char[] chars = line.toCharArray(); StringBuilder transformed = new StringBuilder(); StringBuilder gather = new StringBuilder(); boolean foundMethod = false; boolean inSingleQuotes = false; boolean inDoubleQuotes = false; int parenCount = 0; for (char c : chars) { if (Character.isWhitespace(c) && !foundMethod) { transformed.append(gather); transformed.append(c); foundMethod = hashedMethods.contains(gather.toString()); gather.setLength(0); } else if (Character.isWhitespace(c) && foundMethod) { if (transformed.charAt(transformed.length() - 1) != ',' && !inSingleQuotes && !inDoubleQuotes && c != '\n') { transformed.append(","); } transformed.append(c); } else if (c == '(' && !foundMethod) { parenCount++; transformed.append(gather); transformed.append(c); foundMethod = hashedMethods.contains(gather.toString()); gather.setLength(0); } else if (c == '(' && foundMethod) { parenCount++; transformed.append(c); } else if (c == ';') { transformed.append(c); foundMethod = false; parenCount = 0; } else if (c == ')') { parenCount--; transformed.append(c); foundMethod = parenCount == 0 ? false : foundMethod; } else if (c == '"') { transformed.append(c); inSingleQuotes = !inSingleQuotes; } else if (c == '\'') { transformed.append(c); inDoubleQuotes = !inDoubleQuotes; } else if (foundMethod) { transformed.append(c); } else { gather.append(c); } } transformed.append(gather); return transformed.toString(); }
From source file:com.attribyte.relay.HTMLUtil.java
/** * Extracts links for external citations and images. * @param entry The entry./*from w ww . ja va2s.com*/ * @param baseURI The URI used to resolve relative links. */ public static void extractLinks(final ClientProtos.WireMessage.Entry.Builder entry, final String baseURI) { Document doc = Jsoup.parse(entry.getContent(), baseURI); Elements links = doc.select("a[href]"); for (Element link : links) { String href = Strings.nullToEmpty(link.attr("href")).trim(); if (!href.isEmpty()) { entry.addCitationsBuilder().setDirection(ClientProtos.WireMessage.Citation.Direction.OUT) .setLink(href); } } Set<String> imageSources = Sets.newHashSetWithExpectedSize(8); //Don't replace/duplicate any previously added images... if (entry.hasPrimaryImage()) { imageSources.add(entry.getPrimaryImage().getOriginalSrc()); } if (entry.getImagesCount() > 0) { entry.getImagesList().stream().forEach(image -> imageSources.add(image.getOriginalSrc())); } Elements images = doc.select("img[src]"); for (Element image : images) { String src = Strings.nullToEmpty(image.attr("src")).trim(); if (!src.isEmpty() && !imageSources.contains(src)) { imageSources.add(src); ClientProtos.WireMessage.Image.Builder imageBuilder = entry.addImagesBuilder().setOriginalSrc(src); String alt = Strings.nullToEmpty(image.attr("alt")).trim(); if (!alt.isEmpty()) { imageBuilder.setAltText(alt); } String title = Strings.nullToEmpty(image.attr("title")).trim(); if (!title.isEmpty()) { imageBuilder.setTitle(title); } imageBuilder.setSize("original"); String heightStr = Strings.nullToEmpty(image.attr("height")).trim(); String widthStr = Strings.nullToEmpty(image.attr("width")).trim(); if (!heightStr.isEmpty() && !widthStr.isEmpty()) { Integer height = Ints.tryParse(heightStr); Integer width = Ints.tryParse(widthStr); if (height != null && width != null) { imageBuilder.setHeight(height).setWidth(width); } } } } if (!entry.hasPrimaryImage() && entry.getImagesCount() > 0) { //Set the primary image as the first image. entry.setPrimaryImage(entry.getImages(0)); } }
From source file:com.opengamma.financial.comparison.PositionInfo.java
public PositionInfo(final ComparisonContext context, final Position position) { super(context, position); final Collection<Trade> trades = position.getTrades(); if (trades.isEmpty()) { _trades = Collections.emptySet(); } else {/*from w ww.j a v a 2s . c om*/ final Set<TradeInfo> tradeInfos = Sets.newHashSetWithExpectedSize(trades.size()); for (Trade trade : trades) { tradeInfos.add(new TradeInfo(context, trade)); } _trades = Collections.unmodifiableSet(tradeInfos); } _attributes = context.isIgnorePositionAttributes() ? Collections.<String, String>emptyMap() : position.getAttributes(); }
From source file:com.github.steveash.jg2p.align.ProbTable.java
/** * Returns a set of all non-empty x,y pairs from a unioned with all non-empty x,y pairs from b * @param a//from w ww. j a va2 s .c o m * @param b * @return */ public static Set<Pair<String, String>> unionOfAllCells(ProbTable a, ProbTable b) { Set<Pair<String, String>> xys = Sets.newHashSetWithExpectedSize(Math.max(a.xyProb.size(), b.xyProb.size())); addAllPresent(a, xys); addAllPresent(b, xys); return xys; }