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:org.obm.opush.command.sync.SyncTestUtils.java

public void checkMailFolderHasItems(SyncResponse response, CollectionId serverId, Iterable<ItemChange> changes,
        Iterable<ItemDeletion> deletes) {
    SyncCollectionResponse collection = getCollectionWithId(response, serverId);
    assertThat(collection.getItemChanges()).containsOnly(Iterables.toArray(changes, ItemChange.class));
    assertThat(collection.getItemDeletions()).containsOnly(Iterables.toArray(deletes, ItemDeletion.class));
}

From source file:msi.gaml.compilation.GamlIdiomsProvider.java

private void init() {

    sortedElements = Iterables.toArray(elements, IGamlDescription.class);
    if (titles == null) {
        Arrays.sort(sortedElements, (e1, e2) -> e1.getTitle().compareTo(e2.getTitle()));
    } else {//w  w w  .  ja  va  2s  .c  o m
        Arrays.sort(sortedElements, (e1, e2) -> titles.get(e1).compareTo(titles.get(e2)));
    }
    byName = Multimaps.index(elements, (each) -> each.getName());

}

From source file:org.openengsb.core.edb.jpa.internal.util.QueryRequestCriteriaBuilder.java

private Predicate buildValuePredicate(Set<Object> values, Root<?> subFrom) {
    Expression<String> expression = subFrom.get("value");

    if (!request.isCaseSensitive()) {
        expression = builder.lower(expression);
    }//from ww w.  ja v a  2 s .  c om

    List<Predicate> valuePredicates = Lists.newArrayList();
    for (Object obj : values) {
        String caseCheckedValue = getCaseCheckedValue(obj, request.isCaseSensitive());
        valuePredicates.add(request.isWildcardAware() ? builder.like(expression, caseCheckedValue)
                : builder.equal(expression, caseCheckedValue));
    }
    if (request.isAndJoined()) {
        return builder.and(Iterables.toArray(valuePredicates, Predicate.class));
    } else {
        return builder.or(Iterables.toArray(valuePredicates, Predicate.class));
    }
}

From source file:ratpack.pac4j.internal.RatpackWebContext.java

private Map<String, String[]> flattenMap(Map<String, List<String>> map) {
    Map<String, String[]> result = Maps.newLinkedHashMap();
    for (String key : map.keySet()) {
        result.put(key, Iterables.toArray(map.get(key), String.class));
    }//from www . jav a 2s. co  m
    return result;
}

From source file:edu.umn.msi.tropix.persistence.service.impl.LabsServiceImpl.java

public String[] getProviderIds(final String cagridId) {
    return Iterables.toArray(getProviderDao().getProviderCatalogIds(cagridId), String.class);
}

From source file:co.cask.cdap.explore.service.ExploreServiceUtils.java

/**
 * Builds a class loader with the class path provided.
 *///from w  ww .j  a v  a 2s  .co m
public static ClassLoader getExploreClassLoader() {
    if (exploreClassLoader != null) {
        return exploreClassLoader;
    }

    // EXPLORE_CLASSPATH and EXPLORE_CONF_FILES will be defined in startup scripts if Hive is installed.
    String exploreClassPathStr = System.getProperty(Constants.Explore.EXPLORE_CLASSPATH);
    LOG.debug("Explore classpath = {}", exploreClassPathStr);
    if (exploreClassPathStr == null) {
        throw new RuntimeException("System property " + Constants.Explore.EXPLORE_CLASSPATH + " is not set.");
    }

    String exploreConfPathStr = System.getProperty(Constants.Explore.EXPLORE_CONF_FILES);
    LOG.debug("Explore confPath = {}", exploreConfPathStr);
    if (exploreConfPathStr == null) {
        throw new RuntimeException("System property " + Constants.Explore.EXPLORE_CONF_FILES + " is not set.");
    }

    Iterable<File> hiveClassPath = getClassPathJarsFiles(exploreClassPathStr);
    Iterable<File> hiveConfFiles = getClassPathJarsFiles(exploreConfPathStr);
    ImmutableList.Builder<URL> builder = ImmutableList.builder();
    for (File file : Iterables.concat(hiveClassPath, hiveConfFiles)) {
        try {
            if (file.getName().matches(".*\\.xml")) {
                builder.add(file.getParentFile().toURI().toURL());
            } else {
                builder.add(file.toURI().toURL());
            }
        } catch (MalformedURLException e) {
            LOG.error("Jar URL is malformed", e);
            throw Throwables.propagate(e);
        }
    }
    exploreClassLoader = new URLClassLoader(Iterables.toArray(builder.build(), URL.class),
            ClassLoader.getSystemClassLoader());
    return exploreClassLoader;
}

From source file:org.sonar.cxx.sensors.utils.CxxReportSensor.java

/**
 * @param property String with comma separated items
 * @return//  ww  w  .j  ava2  s  . co m
 */
public static String[] splitProperty(String property) {
    return Iterables.toArray(Splitter.on(',').split(property), String.class);
}

From source file:c5db.log.SequentialLogWithHeader.java

private static HeaderWithSize writeHeaderToPersistence(BytePersistence persistence, OLogHeader header)
        throws IOException {

    final List<ByteBuffer> serializedHeader = encodeWithLengthAndCrc(HEADER_SCHEMA, header);
    persistence.append(Iterables.toArray(serializedHeader, ByteBuffer.class));

    return new HeaderWithSize(header, persistence.size());
}

From source file:com.opera.core.systems.runner.launcher.OperaLauncherRunner.java

private void init() {
    try {//from ww  w . java2  s.c om
        binary = new OperaLauncherBinary(settings.getLauncher().getCanonicalPath(),
                Iterables.toArray(arguments, String.class));
    } catch (IOException e) {
        throw new OperaRunnerException("Unable to start launcher: " + e.getMessage());
    }

    logger.fine("Waiting for launcher connection on port " + launcherPort);

    ServerSocket listenerServer = null;
    try {
        // Setup listener server
        listenerServer = new ServerSocket(launcherPort);
        // TODO(andreastt): Unsafe int cast
        listenerServer.setSoTimeout((int) OperaIntervals.LAUNCHER_CONNECT_TIMEOUT.getMs());

        // Try to connect
        protocol = new OperaLauncherProtocol(listenerServer.accept());

        // We did it!
        logger.fine("Connected with launcher on port " + launcherPort);

        // Do the handshake!
        LauncherHandshakeRequest.Builder request = LauncherHandshakeRequest.newBuilder();
        ResponseEncapsulation res = protocol.sendRequest(MessageType.MSG_HELLO, request.build().toByteArray());

        // Are we happy?
        if (res.isSuccess()) {
            logger.finer("Got launcher handshake: " + res.getResponse().toString());
        } else {
            throw new OperaRunnerException("Did not get launcher handshake: " + res.getResponse().toString());
        }
    } catch (SocketTimeoutException e) {
        throw new OperaRunnerException("Timeout waiting for launcher to connect on port " + launcherPort, e);
    } catch (IOException e) {
        throw new OperaRunnerException("Unable to listen to launcher port " + launcherPort, e);
    } finally {
        Closeables.closeQuietly(listenerServer);
    }
}

From source file:com.google.errorprone.bugpatterns.formatstring.FormatStringValidation.java

private static ValidationResult validate(String formatString, Iterable<Object> arguments) {
    try {//w  w w .ja  v a2s  .co  m
        String unused = String.format(formatString, Iterables.toArray(arguments, Object.class));
    } catch (DuplicateFormatFlagsException e) {
        return ValidationResult.create(e, String.format("duplicate format flags: %s", e.getFlags()));
    } catch (FormatFlagsConversionMismatchException e) {
        return ValidationResult.create(e,
                String.format("format specifier '%%%s' is not compatible with the given flag(s): %s",
                        e.getConversion(), e.getFlags()));
    } catch (IllegalFormatCodePointException e) {
        return ValidationResult.create(e, String.format("invalid Unicode code point: %x", e.getCodePoint()));
    } catch (IllegalFormatConversionException e) {
        return ValidationResult.create(e,
                String.format("illegal format conversion: '%s' cannot be formatted using '%%%s'",
                        e.getArgumentClass().getName(), e.getConversion()));
    } catch (IllegalFormatFlagsException e) {
        return ValidationResult.create(e, String.format("illegal format flags: %s", e.getFlags()));
    } catch (IllegalFormatPrecisionException e) {
        return ValidationResult.create(e, String.format("illegal format precision: %d", e.getPrecision()));
    } catch (IllegalFormatWidthException e) {
        return ValidationResult.create(e, String.format("illegal format width: %s", e.getWidth()));
    } catch (MissingFormatArgumentException e) {
        return ValidationResult.create(e,
                String.format("missing argument for format specifier '%s'", e.getFormatSpecifier()));
    } catch (MissingFormatWidthException e) {
        return ValidationResult.create(e, String.format("missing format width: %s", e.getFormatSpecifier()));
    } catch (UnknownFormatConversionException e) {
        return ValidationResult.create(e, unknownFormatConversion(e.getConversion()));
    } catch (UnknownFormatFlagsException e) {
        // TODO(cushon): I don't think the implementation ever throws this.
        return ValidationResult.create(e, String.format("unknown format flag(s): %s", e.getFlags()));
    }

    try {
        // arguments are specified as type descriptors, and all we care about checking is the arity
        String[] argDescriptors = Collections.nCopies(Iterables.size(arguments), "Ljava/lang/Object;")
                .toArray(new String[0]);
        Formatter.check(formatString, argDescriptors);
    } catch (ExtraFormatArgumentsException e) {
        return ValidationResult.create(e,
                String.format("extra format arguments: used %d, provided %d", e.used, e.provided));
    } catch (Exception ignored) {
        // everything else is validated by String.format above
    }
    return null;
}