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.apache.lens.cli.commands.LensDimensionTableCommands.java

/**
 * Gets the all partitions of dim./* w ww .  java 2  s  .c  o m*/
 *
 * @param specPair the spec pair
 * @return the all partitions of dim
 */
@CliCommand(value = "dimtable list partitions", help = "get all partitions associated with dimension table")
public String getAllPartitionsOfDim(
        @CliOption(key = { "", "table" }, mandatory = true, help = "<dimension-table-name> <storageName> "
                + "[optional <partition query filter> to get]") String specPair) {
    Iterable<String> parts = Splitter.on(' ').trimResults().omitEmptyStrings().split(specPair);
    String[] pair = Iterables.toArray(parts, String.class);
    if (pair.length == 2) {
        try {
            return formatJson(
                    mapper.writer(pp).writeValueAsString(getClient().getAllPartitionsOfDim(pair[0], pair[1])));
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        }
    }

    if (pair.length == 3) {
        try {
            return formatJson(mapper.writer(pp)
                    .writeValueAsString(getClient().getAllPartitionsOfDim(pair[0], pair[1], pair[2])));
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        }
    }

    return "Syntax error, please try in following "
            + "format. dim list partitions <table> <storage> [partition values]";
}

From source file:org.glowroot.agent.live.LiveWeavingServiceImpl.java

@RequiresNonNull("instrumentation")
private int reweaveInternal() throws Exception {
    List<InstrumentationConfig> configs = configService.getInstrumentationConfigs();
    adviceCache.updateAdvisors(configs);
    Set<PointcutClassName> pointcutClassNames = Sets.newHashSet();
    for (InstrumentationConfig config : configs) {
        PointcutClassName subTypeRestrictionPointClassName = null;
        String subTypeRestriction = config.subTypeRestriction();
        if (!subTypeRestriction.isEmpty()) {
            subTypeRestrictionPointClassName = PointcutClassName.fromMaybePattern(subTypeRestriction, null,
                    false);/*www.j  av  a  2s .c om*/
        }
        String className = config.className();
        if (!className.isEmpty()) {
            pointcutClassNames.add(PointcutClassName.fromMaybePattern(className,
                    subTypeRestrictionPointClassName, config.methodName().equals("<init>")));
        }
    }
    Set<Class<?>> classes = Sets.newHashSet();
    Set<Class<?>> possibleNewReweavableClasses = getExistingModifiableSubClasses(pointcutClassNames,
            instrumentation.getAllLoadedClasses(), instrumentation);
    // need to remove these classes from AnalyzedWorld, otherwise if a subclass and its parent
    // class are both in the list and the subclass is re-transformed first, it will use the
    // old cached AnalyzedClass for its parent which will have the old AnalyzedMethod advisors
    List<Class<?>> existingReweavableClasses = analyzedWorld.getClassesWithReweavableAdvice(true);
    analyzedWorld.removeClasses(possibleNewReweavableClasses);
    classes.addAll(existingReweavableClasses);
    classes.addAll(possibleNewReweavableClasses);
    if (classes.isEmpty()) {
        return 0;
    }
    instrumentation.retransformClasses(Iterables.toArray(classes, Class.class));
    List<Class<?>> updatedReweavableClasses = analyzedWorld.getClassesWithReweavableAdvice(false);
    // all existing reweavable classes were woven
    int count = existingReweavableClasses.size();
    // now add newly reweavable classes
    for (Class<?> possibleNewReweavableClass : possibleNewReweavableClasses) {
        if (updatedReweavableClasses.contains(possibleNewReweavableClass)
                && !existingReweavableClasses.contains(possibleNewReweavableClass)) {
            count++;
        }
    }
    return count;
}

From source file:ec.ui.ATsCollectionView.java

protected Ts[] removeTsCollection(Ts[] tss) {
    List<Ts> tmp = Lists.newArrayList(tss);
    tmp.removeAll(Arrays.asList(collection.toArray()));
    return Iterables.toArray(tmp, Ts.class);
}

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

@CliCommand(value = "dim get storage", help = "describe storage of dimension table")
public String getStorageFromDim(@CliOption(key = { "",
        "table" }, mandatory = true, help = "<table-name> <storage-spec>") String tablepair) {
    Iterable<String> parts = Splitter.on(' ').trimResults().omitEmptyStrings().split(tablepair);
    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  w w.  j  a  v a 2  s . c o m

    XStorageTableElement element = client.getStorageFromDim(pair[0], pair[1]);
    return FormatUtils.getStorageString(element);
}

From source file:org.blip.workflowengine.transferobject.ModifiablePropertyNode.java

@Override
public PropertyNode addNull(final String key, final Collection<Attribute> attributes) {
    return internalAdd(false, key, null, Iterables.toArray(attributes, Attribute.class));
}

From source file:com.android.build.gradle.internal.dsl.BuildType.java

/**
 * Specifies proguard rule files to be used when processing test code.
 *
 * <p>Test code needs to be processed to apply the same obfuscation as was done to main code.
 *///from  www  .java  2s.c  om
@NonNull
public BuildType setTestProguardFiles(@NonNull Iterable<?> files) {
    getTestProguardFiles().clear();
    testProguardFiles(Iterables.toArray(files, Object.class));
    return this;
}

From source file:hu.akarnokd.utils.database.DBParams.java

/**
 * Add multiple values as parameters.//from   w ww .j av  a  2s.c o m
 * @param os the rest parameters
 * @return this
 * @throws SQLException on error
 */
public DBParams add(Iterable<?> os) throws SQLException {
    return add(Iterables.toArray(os, Object.class));
}

From source file:org.apache.tez.runtime.library.shuffle.common.impl.ShuffleManager.java

public ShuffleManager(InputContext inputContext, Configuration conf, int numInputs, int bufferSize,
        boolean ifileReadAheadEnabled, int ifileReadAheadLength, CompressionCodec codec,
        FetchedInputAllocator inputAllocator) throws IOException {
    this.inputContext = inputContext;
    this.numInputs = numInputs;

    this.shuffledInputsCounter = inputContext.getCounters().findCounter(TaskCounter.NUM_SHUFFLED_INPUTS);
    this.failedShufflesCounter = inputContext.getCounters().findCounter(TaskCounter.NUM_FAILED_SHUFFLE_INPUTS);
    this.bytesShuffledCounter = inputContext.getCounters().findCounter(TaskCounter.SHUFFLE_BYTES);
    this.decompressedDataSizeCounter = inputContext.getCounters()
            .findCounter(TaskCounter.SHUFFLE_BYTES_DECOMPRESSED);
    this.bytesShuffledToDiskCounter = inputContext.getCounters().findCounter(TaskCounter.SHUFFLE_BYTES_TO_DISK);
    this.bytesShuffledToMemCounter = inputContext.getCounters().findCounter(TaskCounter.SHUFFLE_BYTES_TO_MEM);
    this.bytesShuffledDirectDiskCounter = inputContext.getCounters()
            .findCounter(TaskCounter.SHUFFLE_BYTES_DISK_DIRECT);

    this.ifileBufferSize = bufferSize;
    this.ifileReadAhead = ifileReadAheadEnabled;
    this.ifileReadAheadLength = ifileReadAheadLength;
    this.codec = codec;
    this.inputManager = inputAllocator;
    this.localDiskFetchEnabled = conf.getBoolean(TezRuntimeConfiguration.TEZ_RUNTIME_OPTIMIZE_LOCAL_FETCH,
            TezRuntimeConfiguration.TEZ_RUNTIME_OPTIMIZE_LOCAL_FETCH_DEFAULT);
    this.sharedFetchEnabled = conf.getBoolean(TezRuntimeConfiguration.TEZ_RUNTIME_OPTIMIZE_SHARED_FETCH,
            TezRuntimeConfiguration.TEZ_RUNTIME_OPTIMIZE_SHARED_FETCH_DEFAULT);

    this.srcNameTrimmed = TezUtilsInternal.cleanVertexName(inputContext.getSourceVertexName());

    completedInputSet = Collections.newSetFromMap(new ConcurrentHashMap<InputIdentifier, Boolean>(numInputs));
    completedInputs = new LinkedBlockingQueue<FetchedInput>(numInputs);
    knownSrcHosts = new ConcurrentHashMap<String, InputHost>();
    pendingHosts = new LinkedBlockingQueue<InputHost>();
    obsoletedInputs = Collections.newSetFromMap(new ConcurrentHashMap<InputAttemptIdentifier, Boolean>());
    runningFetchers = Collections.newSetFromMap(new ConcurrentHashMap<Fetcher, Boolean>());

    int maxConfiguredFetchers = conf.getInt(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_PARALLEL_COPIES,
            TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_PARALLEL_COPIES_DEFAULT);

    this.numFetchers = Math.min(maxConfiguredFetchers, numInputs);

    ExecutorService fetcherRawExecutor = Executors.newFixedThreadPool(numFetchers, new ThreadFactoryBuilder()
            .setDaemon(true).setNameFormat("Fetcher [" + srcNameTrimmed + "] #%d " + localhostName).build());
    this.fetcherExecutor = MoreExecutors.listeningDecorator(fetcherRawExecutor);

    ExecutorService schedulerRawExecutor = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder()
            .setDaemon(true).setNameFormat("ShuffleRunner [" + srcNameTrimmed + "]").build());
    this.schedulerExecutor = MoreExecutors.listeningDecorator(schedulerRawExecutor);
    this.schedulerCallable = new RunShuffleCallable(conf);

    this.startTime = System.currentTimeMillis();
    this.lastProgressTime = startTime;

    this.shuffleSecret = ShuffleUtils.getJobTokenSecretFromTokenBytes(
            inputContext.getServiceConsumerMetaData(TezConstants.TEZ_SHUFFLE_HANDLER_SERVICE_ID));
    httpConnectionParams = ShuffleUtils.constructHttpShuffleConnectionParams(conf);

    this.localFs = (RawLocalFileSystem) FileSystem.getLocal(conf).getRaw();

    this.localDirAllocator = new LocalDirAllocator(TezRuntimeFrameworkConfigs.LOCAL_DIRS);

    this.localDisks = Iterables.toArray(localDirAllocator.getAllLocalPathsToRead(".", conf), Path.class);

    Arrays.sort(this.localDisks);

    LOG.info(this.getClass().getSimpleName() + " : numInputs=" + numInputs + ", compressionCodec="
            + (codec == null ? "NoCompressionCodec" : codec.getClass().getName()) + ", numFetchers="
            + numFetchers + ", ifileBufferSize=" + ifileBufferSize + ", ifileReadAheadEnabled=" + ifileReadAhead
            + ", ifileReadAheadLength=" + ifileReadAheadLength + ", " + "localDiskFetchEnabled="
            + localDiskFetchEnabled + ", " + "sharedFetchEnabled=" + sharedFetchEnabled + ", "
            + httpConnectionParams.toString());
}

From source file:com.google.cloud.datastore.DatastoreImpl.java

@Override
public Iterator<Entity> get(Iterable<Key> keys, ReadOption... options) {
    return get(toReadOptionsPb(options), Iterables.toArray(keys, Key.class));
}