List of usage examples for com.google.common.collect Iterables toArray
static <T> T[] toArray(Iterable<? extends T> iterable, T[] array)
From source file:com.streamsets.pipeline.lib.el.FileEL.java
@ElFunction(prefix = "file", name = "pathElement", description = "Returns element (directory or file name) from given index. On path /path/to/file.txt, 'path' have index 0, 'to' have index 1 and file.txt have index 2.") public static String pathElement(@ElParam("filePath") String filePath, @ElParam("index") int index) { if (isEmpty(filePath)) { return null; }/*from ww w .j a va 2 s .com*/ // Array of elements of the path Path[] elements = Iterables.toArray(Paths.get(filePath), Path.class); // Accept negative index to count from the end of array if (index < 0) { // Using + as the number is negative, so the resulting operation is actually subtraction index = elements.length + index; } // Index have to be in range, otherwise return null (which will be very likely converted to empty string by EL engine) if (index < 0 || index >= elements.length) { return null; } return elements[index].toString(); }
From source file:com.b2international.commons.TypeSafeAdapterFactory.java
private Class<?>[] getAdapterListSafe() { return Iterables.toArray(supportedClasses, Class.class); }
From source file:org.apache.brooklyn.location.jclouds.templates.customize.InboundPortsOption.java
private int[] toIntPortArray(Object v) { PortRange portRange = PortRanges.fromIterable(Collections.singletonList(v)); return ArrayUtils.toPrimitive(Iterables.toArray(portRange, Integer.class)); }
From source file:org.isisaddons.module.scheduler.dom.AbstractIsisJob.java
AuthenticationSession newAuthSession(JobExecutionContext context) { String user = getKey(context, AbstractSchedulerService.USER_KEY); String rolesStr = getKey(context, AbstractSchedulerService.ROLES_KEY); String[] roles = Iterables.toArray(Splitter.on(",").split(rolesStr), String.class); return new SimpleSession(user, roles); }
From source file:org.renjin.sexp.StringArrayVector.java
public StringArrayVector(Iterable<String> properties) { this(Iterables.toArray(properties, String.class), AttributeMap.EMPTY); }
From source file:com.android.builder.shrinker.FilterMembersVisitor.java
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {// w w w .j a va2s .c o m List<String> interfacesToKeep = Lists.newArrayList(); for (String iface : interfaces) { if (mKeepInterface.apply(iface)) { interfacesToKeep.add(iface); } } super.visit(version, access, name, signature, superName, Iterables.toArray(interfacesToKeep, String.class)); }
From source file:org.immutables.check.IterableChecker.java
public final void hasAll(Iterable<? extends T> elements) { verifyUsingMatcher(CoreMatchers.hasItems((T[]) Iterables.toArray(elements, Object.class))); }
From source file:com.android.build.gradle.shrinker.FilterMembersVisitor.java
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {// ww w.j a va 2 s.c om List<String> interfacesToKeep = Lists.newArrayList(); for (String iface : interfaces) { if (mClassKeptPredicate.apply(iface)) { interfacesToKeep.add(iface); } } super.visit(version, access, name, signature, superName, Iterables.toArray(interfacesToKeep, String.class)); }
From source file:org.sonatype.nexus.maven.staging.workflow.rc.AbstractStagingRcActionMojo.java
protected String[] getStagingRepositoryIds() throws MojoExecutionException { if (stagingRepositoryId == null) { throw new MojoExecutionException( "The staging repository to operate against is not defined! (use \"-DstagingRepositoryId=foo1,foo2\" on CLI)"); }//from w w w .jav a 2s .c om final String[] result = Iterables.toArray(Splitter.on(",").split(stagingRepositoryId), String.class); if (result == null || result.length == 0) { throw new MojoExecutionException( "The staging repository to operate against is not defined! (use \"-DstagingRepositoryId=foo1,foo2\" on CLI)"); } return result; }
From source file:org.apache.brooklyn.util.JavaGroovyEquivalents.java
public static <T> T elvis(Iterable<?> preferences) { return elvis(Iterables.toArray(preferences, Object.class)); }