List of usage examples for com.google.common.collect Iterables toArray
static <T> T[] toArray(Iterable<? extends T> iterable, T[] array)
From source file:jflowmap.models.map.MapArea.java
public MapArea(String id, String name, Iterable<Polygon> polygons) { this(id, name, Iterables.toArray(polygons, Polygon.class), false); }
From source file:org.apache.isis.core.metamodel.facets.object.membergroups.annotprop.MemberGroupLayoutFacetProperties.java
static String[] asGroupList(Properties properties, final String key) { final String property = properties.getProperty(key); if (property == null) { return new String[0]; }/*from w w w . ja v a 2 s. c o m*/ final Iterable<String> split = Splitter.on(',').split(property); return Iterables.toArray( Iterables.filter(Iterables.transform(split, StringFunctions.TRIM), StringPredicates.NOT_EMPTY), String.class); }
From source file:ratpack.newrelic.internal.RatpackRequest.java
@Override public String[] getParameterValues(String name) { return Iterables.toArray(request.getQueryParams().getAll(name), String.class); }
From source file:net.link.util.pkix.ClientCrypto.java
@Override public X509Certificate[] getX509Certificates(final CryptoType cryptoType) throws WSSecurityException { logger.dbg("getCertificates for cryptotype: %s", cryptoType); return Iterables.toArray(certificateChain.getOrderedCertificateChain(), X509Certificate.class); }
From source file:com.b2international.commons.arrays.Arrays2.java
/** * Non-lazily computes a copy of the unfiltered array where all elements are applicable to the given predicate. The result array size is trimmed * to fit matching members only.// w w w . jav a2 s .co m * <p> * If the given source array is empty, it is returned unchanged. If it is not empty, but no elements match the supplied predicate, a new empty * array will be returned. * * @param unfiltered the source array (may not be {@code null}) * @param predicate the filtering predicate (may not be {@code null}) * @return the filtered array */ public static <T> T[] filter(final T[] unfiltered, final Predicate<? super T> predicate) { checkNotNull(unfiltered, "unfiltered"); checkNotNull(predicate, "predicate"); if (0 == unfiltered.length) { return unfiltered; } final Collection<T> wrapper = Arrays.asList(unfiltered); final Collection<T> filteredCollection = Collections2.filter(wrapper, predicate); @SuppressWarnings("unchecked") final Class<T> componentType = (Class<T>) unfiltered.getClass().getComponentType(); return Iterables.toArray(filteredCollection, componentType); }
From source file:hmi.animation.RenamingMap.java
public static BiMap<String, String> renamingMap(String renaming) { BiMap<String, String> renamingMap = HashBiMap.create(); Splitter split = Splitter//from ww w .j a v a 2 s. c o m .on(CharMatcher.WHITESPACE .or(CharMatcher.is('\n').or(CharMatcher.is('\r').or(CharMatcher.is('\f'))))) .trimResults().omitEmptyStrings(); String[] splittedStr = Iterables.toArray(split.split(renaming), String.class); if (splittedStr.length % 2 > 0) { throw new IllegalArgumentException("renaming string does not contain an even amount of names"); } for (int i = 0; i < splittedStr.length / 2; i++) { renamingMap.put(splittedStr[i * 2], splittedStr[i * 2 + 1]); } return renamingMap; }
From source file:eu.numberfour.n4js.ui.workingsets.WorkingSetDiffBuilder.java
/** * Builds the difference based on the new items and all new items arguments. This is just a sugar for * {@link #build(WorkingSet[], WorkingSet[])} method. *//*from ww w.j a va 2s . com*/ public Diff<WorkingSet> build(final Iterable<? extends WorkingSet> newItems, final Iterable<? extends WorkingSet> newAllItems) { return build(Iterables.toArray(newItems, WorkingSet.class), Iterables.toArray(newAllItems, WorkingSet.class)); }
From source file:playground.michalm.util.matrices.MatrixUtils.java
public static Matrix createMatrix(String id, Iterable<?> ids, double[][] values, boolean denseMatrix) { Matrix matrix = new Matrix(id, null); Object[] idArray = Iterables.toArray(ids, Object.class); for (int i = 0; i < idArray.length; i++) { for (int j = 0; j < idArray.length; j++) { if (denseMatrix || values[i][j] != 0) { matrix.createEntry(idArray[i].toString(), idArray[j].toString(), values[i][j]); }/*w ww. j av a 2 s . c om*/ } } return matrix; }
From source file:cc.gospy.core.util.UrlBundle.java
private static List<String> parseFirstGroup(List<String> urls) { int startPos, endPos; Iterator<String> parents = urls.iterator(); List<String> children = Lists.newArrayList(); while (parents.hasNext()) { String rule = parents.next(); if ((startPos = rule.indexOf('{')) == -1 || (endPos = rule.indexOf('}')) == -1) { return urls; }/*from w w w .j ava2 s. c o m*/ if (startPos > endPos) { throw new RuntimeException("invalid bound, '}' matched '{': " + rule); } String firstGroup = rule.substring(startPos + 1, endPos); if (firstGroup.contains("&")) { for (String subRule : firstGroup.split("&")) { children.add(String.format("%s{%s}%s", rule.substring(0, startPos), subRule, rule.substring(endPos + 1))); } } else { String[] params = Iterables.toArray(Splitter.on('~').trimResults().split(firstGroup), String.class); if (params.length < 2 || params.length > 3) { throw new RuntimeException( String.format("invalid param size %d, in '%s'", params.length, firstGroup)); } if (params[0].length() == 1 && params[1].length() == 1 && Character.isLetter(params[0].charAt(0)) && Character.isLetter(params[1].charAt(0))) { String lowercase = "abcdefghijklmnopqrstuvwxyz"; String uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; boolean isLowercase; if (lowercase.contains(params[0]) && lowercase.contains(params[1])) { isLowercase = true; } else if (uppercase.contains(params[0]) && uppercase.contains(params[1])) { isLowercase = false; } else { throw new RuntimeException("letter case crashed, in group " + firstGroup); } int startChar = isLowercase ? lowercase.indexOf(params[0]) : uppercase.indexOf(params[0]); int endChar = isLowercase ? lowercase.indexOf(params[1]) : uppercase.indexOf(params[1]); boolean upward = startChar < endChar; try { int step = params.length == 3 ? Integer.parseInt(params[2]) : (upward ? 1 : -1); if (step == 0 || step > 0 && !upward || step < 0 && upward) { throw new RuntimeException( "infinite iteration, please check the 'step', in group: " + firstGroup); } for (int i = startChar; upward ? i <= endChar : i >= endChar; i = i + step) { children.add(rule.substring(0, startPos) + (isLowercase ? lowercase.charAt(i) : uppercase.charAt(i)) + rule.substring(endPos + 1)); } } catch (Exception e) { throw new RuntimeException(e.getMessage()); } } else { int startValue; int endValue; try { startValue = Integer.parseInt(params[0]); endValue = Integer.parseInt(params[1]); boolean upward = startValue <= endValue; int step = params.length == 3 ? Integer.parseInt(params[2]) : (upward ? 1 : -1); if (step == 0 || step > 0 && !upward || step < 0 && upward) { throw new RuntimeException( "infinite iteration, please check 'step', in group: " + firstGroup); } for (int i = startValue; upward ? i <= endValue : i >= endValue; i = i + step) { children.add(rule.substring(0, startPos) + i + rule.substring(endPos + 1)); } } catch (Exception e) { throw new RuntimeException(e.getMessage()); } } } } return parseFirstGroup(children); }
From source file:rvsnoop.ui.MultiLineToolTipUI.java
@Override public Dimension getPreferredSize(JComponent c) { int w = 0, h = 0; final String[] lines = Iterables.toArray(splitter.split(((JToolTip) c).getTipText()), String.class); if (lines.length > 0) { final Font font = c.getFont(); final FontMetrics fontMetrics = c.getFontMetrics(font); h += lines.length * fontMetrics.getHeight(); final Graphics g = c.getGraphics(); w = 0;// w w w. j a v a 2 s.c o m for (int i = 0, imax = lines.length; i < imax; ++i) w = Math.max(w, (int) fontMetrics.getStringBounds(lines[i], g).getWidth()); } return new Dimension(w + 2 * INSET, h + 2 * INSET); }