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.twitter.ambrose.util.JSONUtil.java

private static ObjectMapper newMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
    mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, false);
    mapper.disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE);
    mapper.disable(SerializationFeature.CLOSE_CLOSEABLE);
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

    Reflections reflections = new Reflections("com.twitter.ambrose");
    Set<Class<? extends Job>> jobSubTypes = reflections.getSubTypesOf(Job.class);
    mapper.registerSubtypes(jobSubTypes.toArray(new Class<?>[jobSubTypes.size()]));
    return mapper;
}

From source file:ke.co.tawi.babblesms.server.utils.StringUtil.java

/**
 * Eliminate repetitions from an array of Strings.
 * //from ww  w . j  av  a 2 s.c o m
 * @param strArray
 * @return an array of Strings where there are no duplicates
 */
public static String[] removeDuplicates(String[] strArray) {
    List<String> list = Arrays.asList(strArray);
    Set<String> set = new HashSet<String>(list);

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

    return result;
}

From source file:com.bstek.dorado.core.io.ResourceUtils.java

/**
 * ??????//from  w  ww  .  j a v a2 s .c  o m
 * 
 * @param resourceLocations
 *            ?
 * @return ???
 * @throws IOException
 */
public static Resource[] getResources(String[] resourceLocations) throws IOException {
    Set<Resource> resourceSet = getResourceSet(resourceLocations);
    Resource[] resources = new Resource[resourceSet.size()];
    resourceSet.toArray(resources);
    return resources;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> T[] toArray(Set<T> items, Class<T> tClass) {
    if (items == null || items.size() == 0)
        return null;
    int size = items.size();
    try {//from  www .  j a  v a 2  s .  c o  m
        T[] array = (T[]) Array.newInstance(tClass, size);
        return items.toArray(array);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.microsoft.tfs.core.util.CodePageData.java

/**
 * Gets the array of code pages that are configured and can be mapped to a
 * charset/* w  ww .  j a  va2 s .c o m*/
 *
 * @return the code pages that can be resolved to charsets
 */
static Integer[] getCodePages() {
    synchronized (lock) {
        if (!initialized) {
            initialize();
        }

        final Set codePageSet = codePageToCharsetNames.keySet();
        return (Integer[]) codePageSet.toArray(new Integer[codePageSet.size()]);
    }
}

From source file:com.microsoft.tfs.core.util.CodePageData.java

/**
 * Gets the array of charset names that are configured and can be mapped to
 * a code page.//from w ww .  j  a v a2 s .c o  m
 *
 * @return the charset names that can be resolved to code pages
 */
static String[] getCharsetNames() {
    synchronized (lock) {
        if (!initialized) {
            initialize();
        }

        final Set charsetNameSet = charsetNameToCodePage.keySet();
        return (String[]) charsetNameSet.toArray(new String[charsetNameSet.size()]);
    }
}

From source file:com.linkedin.paldb.impl.GenerateTestData.java

public static Integer[] generateRandomIntKeys(int count, int range, long seed) {
    Random random = new Random(seed);
    Set<Integer> set = new HashSet<Integer>(count);
    while (set.size() < count) {
        set.add(random.nextInt(range));/*w w w.j  ava2 s  .co m*/
    }
    return set.toArray(new Integer[0]);
}

From source file:info.dolezel.fatrat.plugins.helpers.NativeHelpers.java

public static Class[] findAnnotatedClasses(String path, String packageName, String annotation)
        throws IOException, ClassNotFoundException {
    URL url = new URL("jar", "", "file:" + path + "!/");
    Set<Class> classes = findClasses(new File(url.getFile()), packageName, Class.forName(annotation));
    return classes.toArray(new Class[classes.size()]);
}

From source file:mml.handler.scratch.Scratch.java

/**
 * Get a version that may or may not be in scratch. If not put it there.
 * @param docid the docid //from w ww .  ja va  2s . c om
 * @param version the desired single version or null if default
 * @param dbase the database it is in
 * @return a ScratchVersion object or null
 * @throws MMLException 
 */
public static ScratchVersion getVersion(String docid, String version, String dbase) throws MMLException {
    try {
        ScratchVersion sv = null;
        if (version != null)
            sv = getScratchVersion(docid, version, dbase);
        if (sv == null) {
            EcdosisMVD mvd = doGetMVD(dbase, docid);
            if (mvd != null) {
                if (version == null)
                    version = mvd.getVersion1();
                String base = Layers.stripLayer(version);
                HashMap<String, char[]> layers = new HashMap<String, char[]>();
                int numVersions = mvd.numVersions();
                for (int i = 1; i <= numVersions; i++) {
                    String vName = mvd.getVersionId((short) i);
                    if (vName.lastIndexOf(base) == 0)
                        layers.put(vName, mvd.getVersion(i));
                }
                if (!layers.isEmpty()) {
                    Set<String> keys = layers.keySet();
                    String[] arr = new String[keys.size()];
                    keys.toArray(arr);
                    Arrays.sort(arr);
                    String[] all = mvd.getAllVersions();
                    short id = mvd.getVersionId(version);
                    String longName = mvd.getVersionLongName(id);
                    sv = new ScratchVersion(base, longName, docid, dbase, null, false);
                    for (int i = 0; i < arr.length; i++) {
                        String updatedName = Layers.upgradeLayerName(all, arr[i]);
                        sv.addLayer(layers.get(arr[i]), ScratchVersion.layerNumber(updatedName));
                    }
                    // save it for next time
                    Connection conn = Connector.getConnection();
                    conn.putToDb(Database.SCRATCH, dbase, docid, version, sv.toJSON());
                    return sv;
                }
            }
            return null;
        } else
            return sv;
    } catch (DbException e) {
        throw new MMLException(e);
    }
}

From source file:com.devnexus.ting.config.PersistenceConfig.java

public static Class<?>[] getAnnotatedPersistenceClasses() {
    Reflections reflections = new Reflections(PERSISTENCE_BASE_PACKAGE);
    Set<Class<?>> entityClasses = reflections.getTypesAnnotatedWith(Entity.class);
    entityClasses.addAll(reflections.getTypesAnnotatedWith(MappedSuperclass.class));
    return entityClasses.toArray(new Class<?>[0]);
}