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.numberfour.n4js.ui.navigator.internal.ShowHiddenWorkingSetsDropDownAction.java

private void showWorkingSet(final WorkingSetManager manager, final WorkingSet... workingSets) {
    final WorkingSetDiffBuilder builder = new WorkingSetDiffBuilder(manager);
    final Collection<WorkingSet> visibleItems = newArrayList(manager.getWorkingSets());
    visibleItems.addAll(newArrayList(workingSets));
    final WorkingSet[] newAllItems = manager.getAllWorkingSets();
    final Iterable<WorkingSet> newItems = newArrayList(manager.getAllWorkingSets());
    for (final Iterator<WorkingSet> itr = newItems.iterator(); itr.hasNext(); /**/) {
        final WorkingSet next = itr.next();
        if (!visibleItems.contains(next)) {
            itr.remove();/*from w  ww  .ja v a 2 s  . c o m*/
        }
    }
    final Diff<WorkingSet> diff = builder.build(Iterables.toArray(newItems, WorkingSet.class), newAllItems);
    if (!diff.isEmpty()) {
        manager.updateState(diff);
        manager.saveState(new NullProgressMonitor());
        manager.getWorkingSetManagerBroker().refreshNavigator();
    }
}

From source file:com.clarkparsia.sbol.editor.dialog.InputDialog.java

protected InputDialog(final Component parent, String title, RegistryType registryType) {
    super(JOptionPane.getFrameForComponent(parent), title, true);

    this.registryType = registryType;

    if (registryType != RegistryType.NONE) {
        Registries registries = Registries.get();
        int selectedRegistry = (registryType != RegistryType.PART) ? registries.getPartRegistryIndex()
                : registries.getVersionRegistryIndex();

        if (registries.size() == 0) {
            JOptionPane.showMessageDialog(this,
                    "No parts registries are defined.\nPlease click 'Options' and add a parts registry.");
            endpoint = null;// w w  w. j  a v a 2 s  .c  o m
        } else {
            endpoint = registries.get(selectedRegistry).createEndpoint();
        }

        registrySelection = new JComboBox(Iterables.toArray(registries, Registry.class));
        if (registries.size() > 0) {
            registrySelection.setSelectedIndex(selectedRegistry);
        }
        registrySelection.addActionListener(actionListener);
        registrySelection.setRenderer(registryRenderer);

        builder.add("Registry", registrySelection);
    }
}

From source file:org.onosproject.mapping.impl.MappingManager.java

@Override
public void removeMappingEntriesByAppId(Type type, ApplicationId appId) {
    removeMappingEntries(type, Iterables.toArray(getMappingEntriesByAppId(type, appId), MappingEntry.class));
}

From source file:org.apache.brooklyn.entity.software.base.test.jmx.GeneralisedDynamicMBean.java

public GeneralisedDynamicMBean(Map<String, ?> initialAttributes, Map<?, ?> initialOperations) {
    attributes.putAll(initialAttributes);

    for (Entry<?, ?> entry : initialOperations.entrySet()) {
        checkArgument(entry.getKey() instanceof String || entry.getKey() instanceof MBeanOperationInfo,
                "entry.key=%s", entry.getKey());
        String opName = (entry.getKey() instanceof String) ? (String) entry.getKey()
                : ((MBeanOperationInfo) entry.getKey()).getName();
        operations.put(opName, (Function) entry.getValue());
    }//from   w  ww.  j a  va 2s.  c o  m

    Iterable<MBeanAttributeInfo> attrInfo = Iterables.transform(initialAttributes.entrySet(),
            new Function<Map.Entry<String, ?>, MBeanAttributeInfo>() {
                @Override
                public MBeanAttributeInfo apply(Map.Entry<String, ?> entry) {
                    return new MBeanAttributeInfo(entry.getKey(), entry.getValue().getClass().getName(),
                            entry.getKey(), true, false, false);
                }
            });

    Iterable<MBeanOperationInfo> opInfo = Iterables.transform(initialOperations.keySet(),
            new Function<Object, MBeanOperationInfo>() {
                public MBeanOperationInfo apply(Object it) {
                    if (it instanceof MBeanOperationInfo) {
                        return (MBeanOperationInfo) it;
                    } else if (it instanceof CharSequence) {
                        return new MBeanOperationInfo(it.toString(), "my descr", new MBeanParameterInfo[0],
                                "void", MBeanOperationInfo.ACTION_INFO);
                    } else {
                        throw new IllegalArgumentException("Cannot convert " + it + " to MBeanOperationInfo");
                    }
                }
            });

    mBeanInfo = new MBeanInfo(GeneralisedDynamicMBean.class.getName(), GeneralisedDynamicMBean.class.getName(),
            Iterables.toArray(attrInfo, MBeanAttributeInfo.class), new MBeanConstructorInfo[0],
            Iterables.toArray(opInfo, MBeanOperationInfo.class), new MBeanNotificationInfo[0]);
}

From source file:eu.numberfour.n4js.utils.resources.ExternalProjectBuildOrderProvider.java

/**
 * Computes the global total ordering of all open projects' active buildConfigs in the workspace based on build
 * configuration references. If an existing and open project's build config P references another existing and open
 * project's build config Q, then Q should come before P in the resulting ordering. If a build config references a
 * non-active build config it is added to the resulting ordered list. Closed and non-existent projects/buildConfigs
 * are ignored, and will not appear in the result. References to non-existent or closed projects/buildConfigs are
 * also ignored, as are any self-references.
 * <p>// w  w  w  .ja v a  2 s .c  o m
 * When there are choices, the choice is made in a reasonably stable way. For example, given an arbitrary choice
 * between two project buildConfigs, the one with the lower collating project name and build config name will appear
 * earlier in the list.
 * </p>
 * <p>
 * When the build configuration reference graph contains cyclic references, it is impossible to honor all of the
 * relationships. In this case, the result ignores as few relationships as possible. For example, if P2 references
 * P1, P4 references P3, and P2 and P3 reference each other, then exactly one of the relationships between P2 and P3
 * will have to be ignored. The outcome will be either [P1, P2, P3, P4] or [P1, P3, P2, P4]. The result also
 * contains complete details of any cycles present.
 * </p>
 *
 * @param projects
 *            the projects to calculate the active build configuration order among them.
 *
 * @return result describing the global active build configuration order
 */
public static VertexOrder computeActiveBuildConfigOrder(final Iterable<ExternalProject> projects) {
    // Determine the full set of accessible active project buildConfigs in the workspace,
    // and all the accessible project buildConfigs that they reference. This forms a set
    // of all the project buildConfigs that will be returned.
    // Order the set in descending alphabetical order of project name then build config name,
    // as a secondary sort applied after sorting based on references, to achieve a stable
    // ordering.
    final SortedSet<IBuildConfiguration> allAccessibleBuildConfigs = new TreeSet<>(
            new BuildConfigurationComparator());

    // For each project's active build config, perform a depth first search in the reference graph
    // rooted at that build config.
    // This generates the required subset of the reference graph that is required to order all
    // the dependencies of the active project buildConfigs.
    final ExternalProject[] allProjects = Iterables.toArray(projects, ExternalProject.class);
    final List<IBuildConfiguration[]> edges = new ArrayList<>(allProjects.length);

    for (int i = 0; i < allProjects.length; i++) {
        final ExternalProject project = allProjects[i];
        // Ignore projects that are not accessible
        if (!project.isAccessible()) {
            continue;
        }

        // If the active build configuration hasn't already been explored
        // perform a depth first search rooted at it
        if (!allAccessibleBuildConfigs.contains(project.unsafeGetActiveBuildConfig())) {
            allAccessibleBuildConfigs.add(project.unsafeGetActiveBuildConfig());
            final Stack<IBuildConfiguration> stack = new Stack<>();
            stack.push(project.unsafeGetActiveBuildConfig());

            while (!stack.isEmpty()) {
                final IBuildConfiguration buildConfiguration = stack.pop();

                // Add all referenced buildConfigs from the current configuration
                // (it is guaranteed to be accessible as it was pushed onto the stack)
                final Project subProject = (Project) buildConfiguration.getProject();
                final IBuildConfiguration[] refs = subProject
                        .internalGetReferencedBuildConfigs(buildConfiguration.getName(), false);
                for (int j = 0; j < refs.length; j++) {
                    final IBuildConfiguration ref = refs[j];

                    // Ignore self references and references to projects that are not accessible
                    if (ref.equals(buildConfiguration)) {
                        continue;
                    }

                    // Add the referenced accessible configuration
                    edges.add(new IBuildConfiguration[] { buildConfiguration, ref });

                    // If we have already explored the referenced configuration, don't explore it again
                    if (allAccessibleBuildConfigs.contains(ref)) {
                        continue;
                    }

                    allAccessibleBuildConfigs.add(ref);

                    // Push the referenced configuration onto the stack so that it is explored by the depth first
                    // search
                    stack.push(ref);
                }
            }
        }
    }
    return ComputeProjectOrder.computeVertexOrder(allAccessibleBuildConfigs, edges);
}

From source file:org.kuali.rice.kim.impl.common.attribute.AttributeTransform.java

private Predicate applyCompositePredicate(final CompositePredicate input) {
    Set<Predicate> appliedPredicates = new HashSet<Predicate>();

    for (Predicate predicate : input.getPredicates()) {
        appliedPredicates.add(applyPredicate(predicate));
    }// www .j ava  2 s  .c  om

    Predicate[] appliedPredicatesArray = Iterables.toArray(appliedPredicates, Predicate.class);

    if (input instanceof AndPredicate) {
        return and(appliedPredicatesArray);
    } else if (input instanceof OrPredicate) {
        return or(appliedPredicatesArray);
    }

    return input;
}

From source file:com.zulily.omicron.alert.EmailSender.java

public void sendHTML(final String subject, final String message) throws MessagingException {
    checkArgument(!Strings.isNullOrEmpty(subject), "Cannot send email with a null or empty subject");
    checkArgument(!Strings.isNullOrEmpty(message), "Cannot send email with a null or empty message");

    if (EXAMPLE_ADDRESS.equalsIgnoreCase(from.toString())) {
        dumpEmail(subject, message);// w  w w  .  ja  va2s.c om
        // Allow testing to use a fake address
        return;
    }

    MimeMessage mimeMessage = new MimeMessage(this.smtpSession);
    mimeMessage.setRecipients(Message.RecipientType.TO, Iterables.toArray(recipients, Address.class));
    mimeMessage.setFrom(this.from);
    mimeMessage.setSubject(subject);
    mimeMessage.setContent(formatMessage(message), MediaType.HTML_UTF_8.toString());
    Transport.send(mimeMessage);
}

From source file:com.google.devtools.build.lib.vfs.UnixGlob.java

/**
 * Checks that each pattern is valid, splits it into segments and checks
 * that each segment contains only valid wildcards.
 *
 * @return list of segment arrays/*from w ww  . j  av a  2 s  .c o m*/
 */
private static List<String[]> checkAndSplitPatterns(Collection<String> patterns) {
    List<String[]> list = Lists.newArrayListWithCapacity(patterns.size());
    for (String pattern : patterns) {
        String error = checkPatternForError(pattern);
        if (error != null) {
            throw new IllegalArgumentException(error + " (in glob pattern '" + pattern + "')");
        }
        Iterable<String> segments = Splitter.on('/').split(pattern);
        list.add(Iterables.toArray(segments, String.class));
    }
    return list;
}

From source file:org.apache.apex.malhar.kafka.KafkaConsumer09.java

/**
 * Resume all the partitions//  www .j  a va2  s  . c  o  m
 */
@Override
public void resumeAllPartitions() {
    consumer.resume(Iterables.toArray(this.getPartitions(), TopicPartition.class));
}

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

@Override
public PropertyNode add(String key, Boolean value, Collection<Attribute> attributes) {
    return internalAdd(true, key, value, Iterables.toArray(attributes, Attribute.class));
}