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:com.bah.culvert.data.Result.java

/**
 * Create a result from the provided keyvalues iterable.
 * @param keyValues The keyvalues to put in this result.
 */// w  w w  . j  av  a 2 s . c om
public Result(Iterable<CKeyValue> keyValues) {
    this(Iterables.toArray(keyValues, CKeyValue.class));
}

From source file:org.apache.druid.indexer.path.StaticPathSpec.java

private static void addInputPath(Job job, Iterable<String> pathStrings,
        Class<? extends InputFormat> inputFormatClass) {
    Configuration conf = job.getConfiguration();
    StringBuilder inputFormats = new StringBuilder(
            StringUtils.nullToEmptyNonDruidDataString(conf.get(MultipleInputs.DIR_FORMATS)));

    String[] paths = Iterables.toArray(pathStrings, String.class);
    for (int i = 0; i < paths.length - 1; i++) {
        if (inputFormats.length() > 0) {
            inputFormats.append(',');
        }//w ww .  j a  va  2 s. co m
        inputFormats.append(paths[i]).append(';').append(inputFormatClass.getName());
    }
    if (inputFormats.length() > 0) {
        conf.set(MultipleInputs.DIR_FORMATS, inputFormats.toString());
    }
    // add last one separately for possible initialization in MultipleInputs
    MultipleInputs.addInputPath(job, new Path(paths[paths.length - 1]), inputFormatClass);
}

From source file:nz.co.testamation.testcommon.template.MockitoTestTemplate.java

public <T> T mock(Class<T> toMock) {
    T mock = Mockito.mock(toMock);//w  w  w  .  ja v  a2 s  . c  om
    mocks.add(mock);
    inOrder = Mockito.inOrder(Iterables.toArray(mocks, Object.class));
    return mock;
}

From source file:eu.numberfour.n4js.ui.navigator.internal.ShowHiddenWorkingSetsDropDownAction.java

@Override
protected void createMenuItems(final Menu parent) {
    final WorkingSetManager manager = workingSetManagerBroker.getActiveManager();
    final WorkingSet[] allWorkingSets = manager.getAllWorkingSets();
    final WorkingSet[] workingSets = manager.getWorkingSets();
    for (final WorkingSet workingSet : allWorkingSets) {
        if (!Arrays.contains(workingSets, workingSet)) {
            final MenuItem item = new MenuItem(parent, PUSH);
            item.setText(workingSet.getName());
            item.addSelectionListener(new SelectionAdapter() {

                @Override/* w w w  . j a v  a2 s .c o m*/
                public void widgetSelected(final SelectionEvent e) {
                    showWorkingSet(manager, workingSet);
                }

            });
        }
    }

    createSeparator(parent);
    final MenuItem item = new MenuItem(parent, CHECK);
    item.setText(SHOW_ALL_HIDDEN_WORKING_SETS);
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final Iterable<WorkingSet> difference = difference(newHashSet(allWorkingSets),
                    newHashSet(workingSets));
            final WorkingSet[] toShow = Iterables.toArray(difference, WorkingSet.class);
            showWorkingSet(manager, toShow);
        }

    });

}

From source file:ru.ksu.niimm.cll.mocassin.util.StringUtil.java

public static String asString(List<String> list) {
    return asString(Iterables.toArray(list, String.class));
}

From source file:org.osiam.auth.configuration.LdapAuthentication.java

@Bean
public LdapAuthenticator bindAuthenticator() {
    BindAuthenticator bindAuthenticator = new BindAuthenticator(contextSource());
    bindAuthenticator.setUserDnPatterns(dnPatterns);
    bindAuthenticator//ww  w .  j a  v  a 2  s .co m
            .setUserAttributes(Iterables.toArray(ldapToScimAttributeMapping().ldapAttributes(), String.class));
    return bindAuthenticator;
}

From source file:eu.numberfour.n4js.ui.workingsets.WorkingSetManagerImpl.java

@Override
public WorkingSet[] getWorkingSets() {
    return Iterables.toArray(getOrCreateVisibleWorkingSets(), WorkingSet.class);
}

From source file:com.hpcloud.mon.app.validation.Validation.java

/**
 * @throws WebApplicationException if the {@code value} is null or empty.
 *//*from www .j a va 2s.c o  m*/
public static Map<String, String> parseAndValidateDimensions(String dimensionsStr) {
    Validation.validateNotNullOrEmpty(dimensionsStr, "dimensions");

    Map<String, String> dimensions = new HashMap<String, String>();
    for (String dimensionStr : COMMA_SPLITTER.split(dimensionsStr)) {
        String[] dimensionArr = Iterables.toArray(COLON_SPLITTER.split(dimensionStr), String.class);
        if (dimensionArr.length == 2)
            dimensions.put(dimensionArr[0], dimensionArr[1]);
    }

    String service = dimensions.get(Services.SERVICE_DIMENSION);
    DimensionValidation.validate(dimensions, service);
    return dimensions;
}

From source file:org.onehippo.cms7.essentials.dashboard.instruction.CndInstruction.java

@Override
public InstructionStatus process(final PluginContext context, final InstructionStatus previousStatus) {
    if (Strings.isNullOrEmpty(namespacePrefix)) {
        namespace = context.getProjectNamespacePrefix();
    } else {/*from   w w  w. j  a v a 2  s. co  m*/
        namespace = namespacePrefix;
    }
    final Map<String, Object> data = context.getPlaceholderData();
    processAllPlaceholders(data);
    //

    final String prefix = context.getProjectNamespacePrefix();
    final Session session = context.createSession();
    try {
        // TODO extend so we can define supertypes
        String[] superTypes;
        if (!Strings.isNullOrEmpty(superType)) {
            final Iterable<String> split = Splitter.on(",").omitEmptyStrings().trimResults().split(superType);
            superTypes = Iterables.toArray(split, String.class);
        } else {
            superTypes = ArrayUtils.EMPTY_STRING_ARRAY;
        }
        CndUtils.registerDocumentType(context, prefix, documentType, true, false, superTypes);
        session.save();
        // TODO add message
        eventBus.post(new InstructionEvent(this));
        return InstructionStatus.SUCCESS;
    } catch (NodeTypeExistsException e) {
        // just add already exiting ones:
        GlobalUtils.refreshSession(session, false);

    } catch (RepositoryException e) {
        log.error(String.format("Error registering document type: %s", namespace), e);
        GlobalUtils.refreshSession(session, false);
    } finally {
        GlobalUtils.cleanupSession(session);
    }

    message = messageRegisterError;
    eventBus.post(new InstructionEvent(this));
    return InstructionStatus.FAILED;
}

From source file:org.eclipse.xtext.xbase.lib.Conversions.java

/**
 * Unwraps {@code object} to extract the original array if and only if {@code object} was previously created by
 * {@link #doWrapArray(Object)}./*w  ww  .j  a  va  2  s.c  o m*/
 * 
 * @param value
 *            the object to be unwrapped. May be <code>null</code>.
 * @param componentType
 *            the expected component type of the array. May not be <code>null</code>.
 * @return the previously wrapped array if the given value represents such. Otherwise returns the value unmodified.
 *         May return <code>null</code> if the value was <code>null</code>.
 * @throws ArrayStoreException
 *             if the expected runtime {@code componentType} does not match the actual runtime component type.
 */
@Pure
public static Object unwrapArray(Object value, Class<?> componentType) {
    if (value instanceof WrappedArray<?>) {
        Object result = ((WrappedArray<?>) value).internalToArray();
        return checkComponentType(result, componentType);
    }
    if (value instanceof WrappedPrimitiveArray) {
        Object result = ((WrappedPrimitiveArray) value).internalToArray();
        return checkComponentType(result, componentType);
    }
    if (value instanceof Iterable<?>) {
        if (!componentType.isPrimitive()) {
            @SuppressWarnings({ "unchecked", "rawtypes" })
            Object result = Iterables.toArray((Iterable) value, componentType);
            return result;
        } else {
            try {
                List<?> list = IterableExtensions.toList((Iterable<?>) value);
                Object result = Array.newInstance(componentType, list.size());
                for (int i = 0; i < list.size(); i++) {
                    Object element = list.get(i);
                    if (element == null) {
                        throw new ArrayStoreException("Cannot store <null> in primitive arrays.");
                    }
                    Array.set(result, i, element);
                }
                return result;
            } catch (IllegalArgumentException iae) {
                throw new ArrayStoreException("Primitive conversion failed: " + iae.getMessage());
            }
        }
    }
    return value;
}