Example usage for com.google.common.collect Iterables toArray

List of usage examples for com.google.common.collect Iterables toArray

Introduction

In this page you can find the example usage for com.google.common.collect Iterables toArray.

Prototype

static <T> T[] toArray(Iterable<? extends T> iterable, T[] array) 

Source Link

Usage

From source file:eu.esdihumboldt.hale.ui.common.graph.content.SimpleCellContentProvider.java

/**
 * @see IGraphContentProvider#getElements(Object)
 */// w ww . j ava 2  s .c o  m
@Override
public Object[] getElements(Object input) {
    // FIXME what about cells that refer to multiple source or target
    // entities?!

    if (input instanceof Alignment) {
        return ((Alignment) input).getCells().toArray();
    }

    if (input instanceof Cell) {
        return new Object[] { input };
    }

    if (input instanceof Iterable<?>) {
        return Iterables.toArray((Iterable<?>) input, Object.class);
    }

    return null;
}

From source file:org.eclipselabs.spray.runtime.graphiti.tb.AbstractSprayToolBehaviorProvider.java

@Override
public IPaletteCompartmentEntry[] getPalette() {
    Iterable<IPaletteCompartmentEntry> palette = buildPaletteCompartments();
    buildCreationTools();//ww  w  .ja v  a  2  s. c  o m
    // remove empty tools
    Predicate<IPaletteCompartmentEntry> filter = new Predicate<IPaletteCompartmentEntry>() {
        @Override
        public boolean apply(IPaletteCompartmentEntry input) {
            return !input.getToolEntries().isEmpty();
        }
    };
    return Iterables.toArray(Iterables.filter(palette, filter), IPaletteCompartmentEntry.class);
}

From source file:org.opentestsystem.authoring.testauth.persistence.BlueprintElementRepositoryImpl.java

@SuppressWarnings({ "unchecked" })
@Override/*from  w w w  .  ja  v a  2  s . c om*/
public String[] findDistinctActiveLevelsByAssessmentId(final String assessmentId) {
    final Query query = new Query();
    query.addCriteria(Criteria.where("assessmentId").is(assessmentId));
    query.addCriteria(Criteria.where("active").is(true));

    return Iterables.toArray(Lists.newArrayList(
            this.mongoOperations.getCollection("blueprintElement").distinct("level", query.getQueryObject())),
            String.class);
}

From source file:com.b2international.index.compat.Highlighting.java

public static int[][] getMatchRegions(final String queryExpression, final String sortKeyLabel) {
    final String lcQuery = queryExpression.toLowerCase();
    final String lcLabel = sortKeyLabel.toLowerCase();

    final Analyzer analyzer = new ComponentTermAnalyzer();

    final List<String> filterTokens = split(analyzer, lcQuery);
    final List<String> labelTokens = split(analyzer, lcLabel);
    final List<int[]> elementMatchRegions = Lists.newArrayList();

    int startIndex = 0;

    for (final String labelToken : labelTokens) {

        startIndex = lcLabel.indexOf(labelToken, startIndex);

        final Iterator<String> itr = filterTokens.iterator();
        while (itr.hasNext()) {
            final String filterToken = itr.next();
            if (labelToken.startsWith(filterToken)) {
                // XXX: the same segment of text may be selected for highlighting multiple times, revisit if this causes problems
                elementMatchRegions.add(new int[] { startIndex, startIndex + filterToken.length() - 1 });
            }//from  w w w .j a v  a2 s . c  o  m
        }

        // Move past this label token
        startIndex += labelToken.length();
    }
    return Iterables.toArray(elementMatchRegions, int[].class);
}

From source file:org.datahack.parkingdb.api.ParkingZoneFacadeREST.java

@GET
@Produces({ "application/json" })
public List<ParkingZone> find(@QueryParam("minLat") Double minLat, @QueryParam("minLon") Double minLon,
        @QueryParam("maxLat") Double maxLat, @QueryParam("maxLon") Double maxLon) {

    CriteriaBuilder cb = this.getEntityManager().getCriteriaBuilder();

    CriteriaQuery<ParkingZone> q = cb.createQuery(ParkingZone.class);
    Root<ParkingZone> pz = q.from(ParkingZone.class);

    List<Predicate> predicates = new ArrayList();

    if (minLat != null) {
        predicates.add(cb.ge(pz.get(ParkingZone_.latitude), minLat));
    }//www  .  jav  a  2s  . c o  m

    if (minLon != null) {
        predicates.add(cb.ge(pz.get(ParkingZone_.longitude), minLon));
    }

    if (maxLat != null) {
        predicates.add(cb.le(pz.get(ParkingZone_.latitude), maxLat));
    }

    if (maxLon != null) {
        predicates.add(cb.le(pz.get(ParkingZone_.longitude), maxLon));
    }

    Predicate[] arr = Iterables.toArray(predicates, Predicate.class);
    q = q.where(arr);

    TypedQuery<ParkingZone> pzQuery = em.createQuery(q);

    return pzQuery.getResultList();

}

From source file:com.android.tools.idea.databinding.DataBindingComponentClassFinder.java

@NotNull
@Override/*from  ww w.  ja  va2s  .  c  om*/
public PsiClass[] findClasses(@NotNull String qualifiedName, @NotNull final GlobalSearchScope scope) {
    if (!isEnabled() || !SdkConstants.CLASS_DATA_BINDING_COMPONENT.equals(qualifiedName)) {
        return PsiClass.EMPTY_ARRAY;
    }
    Iterable<PsiClass> filtered = Iterables.filter(myClasses.getValue(), input -> check(input, scope));
    if (filtered.iterator().hasNext()) {
        return Iterables.toArray(filtered, PsiClass.class);
    }
    return PsiClass.EMPTY_ARRAY;
}

From source file:msi.gama.metamodel.agent.GamlAgent.java

@Override
public IPopulation<? extends IAgent>[] getMicroPopulations() {
    if (getAttributes() == null) {
        return NO_POP;
    }//from   w  w w  . j  a v  a2s .  c  om
    if (microPopulations == null) {
        microPopulations = Iterables.toArray(
                Iterables.transform(Iterables.filter(getAttributes().keySet(), input -> isPopulation(input)),
                        input -> (IPopulation<?>) getAttributes().get(input)),
                IPopulation.class);
        if (microPopulations.length == 0)
            microPopulations = NO_POP;
        Arrays.sort(microPopulations, (p1, p2) -> p1.isGrid() ? p2.isGrid() ? 0 : 1 : p2.isGrid() ? -1 : 0);
    }
    return microPopulations;
}

From source file:com.inmobi.grill.cli.commands.GrillCubeCommands.java

@CliCommand(value = "update cube", help = "update cube")
public String updateCube(
        @CliOption(key = { "", "cube" }, mandatory = true, help = "<cube-name> <cube-spec>") String specPair) {
    Iterable<String> parts = Splitter.on(' ').trimResults().omitEmptyStrings().split(specPair);
    String[] pair = Iterables.toArray(parts, String.class);
    if (pair.length != 2) {
        return "Syntax error, please try in following "
                + "format. create fact <fact spec path> <storage spec path>";
    }/*w ww  .  ja  v a  2 s .  c o m*/

    File f = new File(pair[1]);

    if (!f.exists()) {
        return "Fact spec path" + f.getAbsolutePath() + " does not exist. Please check the path";
    }

    APIResult result = client.updateCube(pair[0], pair[1]);
    if (result.getStatus() == APIResult.Status.SUCCEEDED) {
        return "Update of " + pair[0] + " succeeded";
    } else {
        return "Update of " + pair[0] + " failed";
    }
}

From source file:org.eclipse.rcptt.ui.utils.WriteAccessChecker.java

private IResource[] findReadOnly(IResource... files) {
    List<IResource> readOnly = new ArrayList<IResource>();
    for (IResource file : files) {
        if (isReadOnly(file) && !readOnly.contains(file)) {
            readOnly.add(file);/*from  w ww  . ja va  2  s  .  c  o  m*/
        }
    }
    return Iterables.toArray(readOnly, IResource.class);
}

From source file:org.cloudifysource.cosmo.kvstore.KVStoreServlet.java

private String toJson(Iterable<URI> uris) {
    return Arrays.toString(Iterables.toArray(Iterables.transform(uris, new Function<URI, String>() {

        @Override//from  w  ww .jav a  2  s .c  om
        public String apply(URI input) {
            return "\"" + input + "\"";
        }
    }), String.class));
}