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.ecyrd.jspwiki.ui.TemplateManager.java

/**
 *  Returns all those types that have been requested so far.
 *
 * @param ctx the wiki context//from ww  w . j a va 2 s. c  o  m
 * @return the array of types requested
 */
@SuppressWarnings("unchecked")
public static String[] getResourceTypes(WikiContext ctx) {
    String[] res = new String[0];

    if (ctx != null) {
        HashMap<String, String> hm = (HashMap<String, String>) ctx.getVariable(RESOURCE_INCLUDES);

        if (hm != null) {
            Set<String> keys = hm.keySet();

            res = keys.toArray(res);
        }
    }

    return res;
}

From source file:com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.java

/**
 * Retrieve the array of excluded attributes. This array should be
 * constructed in the renderer class and then passed in to the
 * PassThruAttributeRenderer.//  w  ww.  java 2s. co m
 *
 * @return a String array of excluded attributes.
 */
public static String[] getExcludesArray(Set excludes) {
    String[] excludesArray = new String[excludes.size()];
    excludes.toArray(excludesArray);
    return excludesArray;
}

From source file:adalid.commons.properties.PropertiesHandler.java

private static String[] getPathArray(String key) {
    String[] strings = bootstrapping.getStringArray(key);
    if (strings == null || strings.length == 0) {
        return null;
    }//from  w ww .  ja  va2s. c o  m
    String path;
    Set<String> set = new LinkedHashSet<>();
    for (String string : strings) {
        path = FilUtils.fixPath(string);
        if (StringUtils.isNotBlank(path)) {
            set.add(path);
        }
    }
    return set.toArray(new String[0]);
}

From source file:com.microsoft.tfs.client.eclipse.ui.actions.ActionHelpers.java

/**
 * Returns the {@link IProject}s that are contained in this selection.
 *
 * @param selection/*from  www  .  j  a v  a 2  s . co  m*/
 *        The selected resources (not <code>null</code>)
 * @return All {@link IProject}s contained by the selection (never
 *         <code>null</code>)
 */
public static IProject[] getProjectsFromSelection(final ISelection selection) {
    Check.notNull(selection, "selection"); //$NON-NLS-1$

    if (!(selection instanceof IStructuredSelection)) {
        return new IProject[0];
    }

    final Set<IProject> projectSet = new HashSet<IProject>();

    @SuppressWarnings("rawtypes")
    final Iterator i;

    for (i = ((IStructuredSelection) selection).iterator(); i.hasNext();) {
        final IResource resource = (IResource) i.next();

        final IProject project = resource.getProject();

        if (project != null) {
            projectSet.add(project);
        }
    }

    return projectSet.toArray(new IProject[projectSet.size()]);
}

From source file:cc.kave.commons.utils.json.JsonUtils.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private static void identifyHierarchiesAndRegisterAll(GsonBuilder gb, Class<?>[] eventsAndRelatedTypes) {
    Map<Class, Set<Class>> baseToSubs = Maps.newHashMap();

    for (Class<?> elem : eventsAndRelatedTypes) {
        if (elem.isEnum()) {
            registerEnum(gb, (Class<Enum>) elem);
            continue;
        }//from w w  w. ja va  2  s.  c o m

        for (Class<?> base : getAllTypesFromHierarchyExceptObject(elem, false)) {
            Set<Class> subs = baseToSubs.get(base);
            if (subs == null) {
                subs = Sets.newHashSet();
                baseToSubs.put(base, subs);
            }
            subs.add(elem);
        }
        registerHierarchy(gb, elem, new Class[] { elem });
    }

    for (Class base : baseToSubs.keySet()) {
        Set<Class> subs = baseToSubs.get(base);
        Class[] arr = subs.toArray(new Class[0]);
        registerHierarchy(gb, base, arr);
    }
}

From source file:com.espertech.esper.epl.join.plan.NStreamOuterQueryPlanBuilder.java

/**
 * Recusivly builds a substream-per-stream ordered tree graph using the
 * join information supplied for outer joins and from the query graph (where clause).
 * <p>/*  ww w .  j  av  a2 s .  c  om*/
 * Required streams are considered first and their lookup is placed first in the list
 * to gain performance.
 * @param streamNum is the root stream number that supplies the incoming event to build the tree for
 * @param queryGraph contains where-clause stream relationship info
 * @param completedStreams is a temporary holder for streams already considered
 * @param substreamsPerStream is the ordered, tree-like structure to be filled
 * @param streamCallStack the query plan call stack of streams available via cursor
 * @param dependencyGraph - dependencies between historical streams
 * @throws ExprValidationException if the query planning failed
 */
protected static void recursiveBuildInnerJoin(int streamNum, Stack<Integer> streamCallStack,
        QueryGraph queryGraph, Set<Integer> completedStreams, LinkedHashMap<Integer, int[]> substreamsPerStream,
        DependencyGraph dependencyGraph) throws ExprValidationException {
    // add this stream to the set of completed streams
    completedStreams.add(streamNum);

    // check if the dependencies have been satisfied
    if (dependencyGraph.hasDependency(streamNum)) {
        Set<Integer> dependencies = dependencyGraph.getDependenciesForStream(streamNum);
        for (Integer dependentStream : dependencies) {
            if (!streamCallStack.contains(dependentStream)) {
                throw new ExprValidationException(
                        "Historical stream " + streamNum + " parameter dependency originating in stream "
                                + dependentStream + " cannot or may not be satisfied by the join");
            }
        }
    }

    // Determine the streams we can navigate to from this stream
    Set<Integer> navigableStreams = queryGraph.getNavigableStreams(streamNum);

    // remove streams with a dependency on other streams not yet processed
    Integer[] navigableStreamArr = navigableStreams.toArray(new Integer[navigableStreams.size()]);
    for (int navigableStream : navigableStreamArr) {
        if (dependencyGraph.hasUnsatisfiedDependency(navigableStream, completedStreams)) {
            navigableStreams.remove(navigableStream);
        }
    }

    // remove those already done
    navigableStreams.removeAll(completedStreams);

    // if we are a leaf node, we are done
    if (navigableStreams.isEmpty()) {
        substreamsPerStream.put(streamNum, new int[0]);
        return;
    }

    // First the outer (required) streams to this stream, then the inner (optional) streams
    int[] substreams = new int[navigableStreams.size()];
    substreamsPerStream.put(streamNum, substreams);
    int count = 0;
    for (int stream : navigableStreams) {
        substreams[count++] = stream;
        completedStreams.add(stream);
    }

    for (int stream : navigableStreams) {
        streamCallStack.push(stream);
        recursiveBuildInnerJoin(stream, streamCallStack, queryGraph, completedStreams, substreamsPerStream,
                dependencyGraph);
        streamCallStack.pop();
    }
}

From source file:com.espertech.esper.event.bean.BeanEventType.java

private static void removeJavaLibInterfaces(Set<Class> classes) {
    for (Class clazz : classes.toArray(new Class[0])) {
        if (clazz.getName().startsWith("java")) {
            classes.remove(clazz);/*  ww w. j a  v a2s. co  m*/
        }
    }
}

From source file:org.eclipse.gemini.blueprint.test.internal.util.jar.ManifestUtils.java

/**
 * Determine the Import-Package value based on the Export-Package entries in
 * the jars given as Resources.//  w w w  .  j a  va  2 s. com
 * @param resources
 * @return
 */
public static String[] determineImportPackages(Resource[] resources) {
    Set collection = new LinkedHashSet();
    // for each resource
    for (int i = 0; i < resources.length; i++) {
        Resource resource = resources[i];
        Manifest man = JarUtils.getManifest(resource);
        if (man != null) {
            // read the manifest
            // get the Export-Package
            Attributes attrs = man.getMainAttributes();
            String exportedPackages = attrs.getValue(Constants.EXPORT_PACKAGE);
            // add it to the StringBuilder
            if (StringUtils.hasText(exportedPackages)) {
                collection.addAll(StringUtils.commaDelimitedListToSet(exportedPackages));
            }
        }
    }
    // return the result as string
    String[] array = (String[]) collection.toArray(new String[collection.size()]);

    // clean whitespace just in case
    for (int i = 0; i < array.length; i++) {
        array[i] = StringUtils.trimWhitespace(array[i]);
    }
    return array;
}

From source file:com.none.tom.simplerssreader.utils.SharedPrefUtils.java

public static String[] getSubscriptionCategories(final Context context, final boolean edit) {
    final LinkedListMultimap<String, String> subscriptions = getSubscriptions(context);
    final Set<String> categories = new TreeSet<>();

    if (!edit) {//w w  w.ja  va 2s  . c  o m
        categories.add(context.getString(R.string.all_categories));
    } else {
        categories.add(context.getString(R.string.clear_category));
    }

    for (final String title : subscriptions.asMap().keySet()) {
        categories.add(subscriptions.get(title).get(0));
    }

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

From source file:org.uimafit.factory.TypeSystemDescriptionFactory.java

/**
 * Resolve a list of patterns to a set of URLs.
 *
 * @return an array of locations./*from w  w w  .  j  ava 2 s.  com*/
 * @throws ResourceInitializationException
 *             if the locations could not be resolved.
 */
public static String[] resolve(String... patterns) throws ResourceInitializationException {
    Set<String> locations = new HashSet<String>();
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    try {
        // Scan auto-import locations. Using a set to avoid scanning a pattern twice.
        for (String pattern : new TreeSet<String>(Arrays.asList(patterns))) {
            String p = pattern.trim();
            if (p.length() == 0) {
                continue;
            }
            for (Resource r : resolver.getResources(pattern)) {
                locations.add(r.getURL().toString());
            }
        }
        return locations.toArray(new String[locations.size()]);
    } catch (IOException e) {
        throw new ResourceInitializationException(e);
    }
}