Example usage for java.util Set toArray

List of usage examples for java.util Set toArray

Introduction

In this page you can find the example usage for java.util Set toArray.

Prototype

<T> T[] toArray(T[] a);

Source Link

Document

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.

Usage

From source file:com.apporiented.hermesftp.PluginManager.java

private static File[] collectJars(String[] paths) {
    Set<File> jarList = new HashSet<File>();
    for (String path : paths) {
        File dir = new File(path);
        if (log.isWarnEnabled() && !dir.exists()) {
            log.warn("JAR folder not found: " + dir);
        }/*from   w w w  .j a va2s  . co  m*/
        if (dir.exists() && dir.isDirectory()) {
            File[] files = dir.listFiles(new JarFileFilter());
            Collections.addAll(jarList, files);
        }
    }
    return jarList.toArray(new File[jarList.size()]);
}

From source file:it.infn.ct.downtime.Downtime.java

public static String[] getIntersection(String[] arr1, String[] arr2) {
    Set<String> s1 = new HashSet<String>(Arrays.asList(arr1));
    Set<String> s2 = new HashSet<String>(Arrays.asList(arr2));
    s1.retainAll(s2);//from   w  w  w  . ja v a2s.  co m

    String[] result = s1.toArray(new String[s1.size()]);

    return result;
}

From source file:com.mirth.connect.client.core.api.util.OperationUtil.java

public static String[] getOperationNamesForPermission(String permissionName, Class<?> servletInterface,
        String... extraOperationNames) {
    Set<String> operationNames = new HashSet<String>();

    for (Class<?> coreServletInterface : new Reflections("com.mirth.connect.client.core.api.servlets")
            .getSubTypesOf(BaseServletInterface.class)) {
        addOperationName(permissionName, coreServletInterface, operationNames);
    }/*from  w w  w . j a v a2s . c o m*/

    if (servletInterface != null) {
        addOperationName(permissionName, servletInterface, operationNames);
    }

    if (ArrayUtils.isNotEmpty(extraOperationNames)) {
        operationNames.addAll(Arrays.asList(extraOperationNames));
    }

    return operationNames.toArray(new String[operationNames.size()]);
}

From source file:net.sf.morph.util.ContainerUtils.java

/**
 * Returns the intersection of multiple arrays as an array.  Implementation is O(n<sup>3</sup>).
 *
 * @param arrays//  w w w .  ja va2  s.  com
 *            a List of arrays
 * @param componentType
 *            the runtime type of the returned array
 * @return the intersection of the arrays
 */
public static Object[] intersection(List arrays, Class componentType) {
    if (componentType == null) {
        throw new IllegalArgumentException("componentType must be speciifed");
    }
    if (arrays == null) {
        return null;
    }

    Set intersectionSet = new HashSet();
    intersectionSet.addAll(Arrays.asList(((Object[]) arrays.get(0))));
    for (int i = 1; i < arrays.size(); i++) {
        Object[] array = (Object[]) arrays.get(i);
        for (int j = 0; j < array.length; j++) {
            if (!contains(intersectionSet, array[j])) {
                intersectionSet.remove(array[j]);
            }
        }
    }

    Object[] intersectionArray = (Object[]) ClassUtils.createArray(componentType, intersectionSet.size());
    return intersectionSet.toArray(intersectionArray);
}

From source file:org.eclipse.virgo.ide.runtime.core.ServerUtils.java

/**
 * Returns the targeted runtimes of the given project
 * @param project the project to return the target runtimes for
 *//*from w  w w .  j a  va2 s  .c  o  m*/
public static IRuntime[] getTargettedRuntimes(IProject project) {
    final Set<org.eclipse.wst.server.core.IRuntime> targetedServerRuntimes = new LinkedHashSet<org.eclipse.wst.server.core.IRuntime>();

    ServerRuntimeUtils.execute(project, new ServerRuntimeUtils.ServerRuntimeCallback() {

        public boolean doWithRuntime(ServerRuntime runtime) {
            targetedServerRuntimes.add(runtime.getRuntime());
            return true;
        }
    });

    return targetedServerRuntimes.toArray(new IRuntime[targetedServerRuntimes.size()]);
}

From source file:com.silverpeas.scheduleevent.control.ScheduleEventSessionController.java

private static String[] getContributorsUserIds(Set<Contributor> contributors) {
    Set<String> result = new HashSet<String>(contributors.size());
    for (Contributor subscriber : contributors) {
        if (subscriber.getUserId() != -1) {
            result.add(String.valueOf(subscriber.getUserId()));
        }//from  www .j  av  a 2  s. c om
    }
    return (String[]) result.toArray(new String[result.size()]);
}

From source file:com.haulmont.cuba.web.gui.components.WebComponentsHelper.java

/**
 * Add actions to vaadin action container.
 *
 * @param container any {@link Action.Container}
 * @param actions   map of actions/*from w  w w  .j a va 2 s  .  c  o  m*/
 */
public static void setActions(Action.Container container, Map<Action, Runnable> actions) {
    container.addActionHandler(new Action.Handler() {
        @Override
        public Action[] getActions(Object target, Object sender) {
            Set<Action> shortcuts = actions.keySet();
            return shortcuts.toArray(new Action[shortcuts.size()]);
        }

        @Override
        public void handleAction(Action action, Object sender, Object target) {
            Runnable runnable = actions.get(action);
            if (runnable != null) {
                runnable.run();
            }
        }
    });
}

From source file:net.sf.morph.util.TransformerUtils.java

/**
 * Get the set of source classes available from the specified Transformer for the specified destination type.
 * @param transformer//from w w w  . ja va  2 s .  c  o  m
 * @param destinationType
 * @return Class[]
 */
public static Class[] getSourceClasses(Transformer transformer, Class destinationType) {
    if (!ClassUtils.inheritanceContains(transformer.getDestinationClasses(), destinationType)) {
        return CLASS_NONE;
    }
    Class[] sourceTypes = transformer.getSourceClasses();
    if (transformer instanceof ExplicitTransformer) {
        Set result = ContainerUtils.createOrderedSet();
        for (int i = 0; i < sourceTypes.length; i++) {
            if (((ExplicitTransformer) transformer).isTransformable(destinationType, sourceTypes[i])) {
                result.add(sourceTypes[i]);
            }
        }
        return result.isEmpty() ? CLASS_NONE : (Class[]) result.toArray(new Class[result.size()]);
    }
    return sourceTypes;
}

From source file:net.sf.morph.util.TransformerUtils.java

/**
 * Get the set of destination classes available from the specified Transformer for the specified source type.
 * @param transformer/* ww  w.  j a v a  2s  . co m*/
 * @param sourceType
 * @return Class[]
 * @since Morph 1.1
 */
public static Class[] getDestinationClasses(Transformer transformer, Class sourceType) {
    if (!ClassUtils.inheritanceContains(transformer.getSourceClasses(), sourceType)) {
        return CLASS_NONE;
    }
    Class[] destinationTypes = transformer.getDestinationClasses();
    if (transformer instanceof ExplicitTransformer) {
        Set result = ContainerUtils.createOrderedSet();
        for (int i = 0; i < destinationTypes.length; i++) {
            if (((ExplicitTransformer) transformer).isTransformable(destinationTypes[i], sourceType)) {
                result.add(destinationTypes[i]);
            }
        }
        return result.isEmpty() ? CLASS_NONE : (Class[]) result.toArray(new Class[result.size()]);
    }
    return destinationTypes;
}

From source file:com.vmware.bdd.cli.commands.CommandsUtils.java

/**
 * Show a table(include table column names and table contents) by left
 * justifying. More specifically, the {@code columnNamesWithGetMethodNames}
 * argument is a map struct, the key is table column name and value is method
 * name list which it will be invoked by reflection. The {@code entities}
 * argument is traversed entity array.It is source of table data. In
 * addition,the method name must be each of the {@code entities} argument 's
 * member. The {@code spacesBeforeStart} argument is whitespace in the front
 * of the row./*ww  w .j  a  va  2s .  c o m*/
 * <p>
 *
 * @param columnNamesWithGetMethodNames
 *           the container of table column name and invoked method name.
 * @param entities
 *           the traversed entity array.
 * @param spacesBeforeStart
 *           the whitespace in the front of the row.
 * @throws Exception
 */
public static void printInTableFormat(LinkedHashMap<String, List<String>> columnNamesWithGetMethodNames,
        Object[] entities, String spacesBeforeStart) throws Exception {
    if (entities != null && entities.length > 0) {
        // get number of columns
        int columnNum = columnNamesWithGetMethodNames.size();

        String[][] table = new String[entities.length + 1][columnNum];

        //build table header: column names
        String[] tableHeader = new String[columnNum];
        Set<String> columnNames = columnNamesWithGetMethodNames.keySet();
        columnNames.toArray(tableHeader);

        //put table column names into the first row
        table[0] = tableHeader;

        //build table contents
        Collection<List<String>> getMethodNamesCollect = columnNamesWithGetMethodNames.values();
        int i = 1;
        for (Object entity : entities) {
            int j = 0;
            for (List<String> getMethodNames : getMethodNamesCollect) {
                Object tempValue = null;
                int k = 0;
                for (String methodName : getMethodNames) {
                    if (tempValue == null)
                        tempValue = entity;
                    Object value = tempValue.getClass().getMethod(methodName).invoke(tempValue);
                    if (k == getMethodNames.size() - 1) {
                        table[i][j] = value == null ? ""
                                : ((value instanceof Double) ? String.valueOf(
                                        round(((Double) value).doubleValue(), 2, BigDecimal.ROUND_FLOOR))
                                        : value.toString());
                        if (isJansiAvailable() && !isBlank(table[i][j])) {
                            table[i][j] = transferEncoding(table[i][j]);
                        }
                        j++;
                    } else {
                        tempValue = value;
                        k++;
                    }
                }
            }
            i++;
        }

        printTable(table, spacesBeforeStart);
    }
}