Example usage for java.util Collection toArray

List of usage examples for java.util Collection toArray

Introduction

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

Prototype

default <T> T[] toArray(IntFunction<T[]> generator) 

Source Link

Document

Returns an array containing all of the elements in this collection, using the provided generator function to allocate the returned array.

Usage

From source file:com.hypersocket.i18n.I18N.java

private static Object[] formatParameters(Object... arguments) {
    Collection<Object> formatted = new ArrayList<Object>(arguments.length);
    for (Object arg : arguments) {
        if (arg instanceof Date) {
            formatted.add(DateFormat.getDateTimeInstance().format(arg));
        } else {//from ww  w .j  a  va2  s. co m
            formatted.add(arg);
        }
    }
    return formatted.toArray(new Object[formatted.size()]);
}

From source file:com.cloudmine.api.rest.JsonUtilities.java

/**
 * Enclose all the passed in jsonEntities in a JSON collection
 * @param jsonEntities to put into the collection
 * @return { jsonEntities[0].transportableRepresentation, jsonEntities[1].transportableRepresentation, ...}
 *//*w w  w .  j  av  a  2s. c  om*/
public static Transportable jsonCollection(Collection<? extends Transportable> jsonEntities) {
    return jsonCollection(jsonEntities.toArray(new Transportable[jsonEntities.size()]));
}

From source file:hr.fer.spocc.automaton.fsm.DefaultNondeterministicFiniteAutomatonTest.java

@SuppressWarnings("unchecked")
private static <T> Transition<T>[] toTransitionArray(Collection<Transition<T>> transitions) {
    return transitions.toArray(new Transition[0]);
}

From source file:SmartEncodingInputStream.java

/**
 * Retrieves all the available <code>Charset</code>s on the platform, among
 * which the default <code>charset</code>.
 * //w  w  w  .  j  a va2 s  . com
 * @return an array of <code>Charset</code>s.
 */
public static Charset[] getAvailableCharsets() {
    final Collection collection = Charset.availableCharsets().values();
    return (Charset[]) collection.toArray(new Charset[collection.size()]);
}

From source file:com.eviware.soapui.plugins.PluginProxies.java

@SuppressWarnings("unchecked")
static <T> T createProxyFor(T delegate) {

    if (delegate instanceof JComponent) {
        log.warn("Can't proxy JComponent derived classes");
        return delegate;
    }/*from w  w  w  .  j  ava 2s.  c o m*/

    Collection<Class> interfaces = ClassUtils.getAllInterfaces(delegate.getClass());
    if (interfaces.isEmpty()) {
        // this shouldn't really happen, unless reflection is being used in some odd way
        log.warn("Can't proxy instance of {} because the class doesn't implement any interfaces",
                delegate.getClass());
        return delegate;
    }
    interfaces.add(PluginProxy.class);
    return (T) Proxy.newProxyInstance(PluginProxies.class.getClassLoader(),
            interfaces.toArray(new Class[interfaces.size()]), new DelegatingHandler<T>(delegate));
}

From source file:com.fengduo.bee.commons.core.lang.BeanUtils.java

/**
 * ?field,/*from   ww w. j  a  v  a  2 s.com*/
 * 
 * @param fields
 * @param type
 * @return
 */
public static Field[] getAllFields(Collection<Field> fields, Class<?> type) {
    if (Argument.isEmpty(fields)) {
        fields = new HashSet<Field>();
    }
    for (Field field : type.getDeclaredFields()) {
        fields.add(field);
    }
    if (type.getSuperclass() != null) {
        fields.addAll(Arrays.asList(getAllFields(fields, type.getSuperclass())));
    }
    return fields.toArray(new Field[fields.size()]);
}

From source file:com.google.gwt.dev.javac.CachedCompilationUnit.java

public static void save(SourceFileCompilationUnit unit, OutputStream outputStream) throws Exception {
    DataOutputStream dos = null;//  w w w  . jav  a 2s .  c o m
    try {
        dos = new DataOutputStream(new BufferedOutputStream(outputStream));
        // version
        dos.writeLong(CompilationUnitDiskCache.CACHE_VERSION);
        // simple stuff
        dos.writeLong(unit.getLastModified());
        dos.writeUTF(unit.getDisplayLocation());
        dos.writeUTF(unit.getTypeName());
        dos.writeUTF(unit.getContentId().get());
        dos.writeBoolean(unit.isSuperSource());
        // compiled classes
        {
            Collection<CompiledClass> compiledClasses = unit.getCompiledClasses();
            int size = compiledClasses.size();
            dos.writeInt(size);
            if (size > 0) {
                // sort in enclosing order to be able to restore enclosing classes by name
                CompiledClass[] compiledClassesArray = compiledClasses
                        .toArray(new CompiledClass[compiledClasses.size()]);
                Arrays.sort(compiledClassesArray, new Comparator<CompiledClass>() {
                    public int compare(CompiledClass o1, CompiledClass o2) {
                        int o1count = countMatches(o1.getInternalName(), Signature.C_DOLLAR);
                        int o2count = countMatches(o2.getInternalName(), Signature.C_DOLLAR);
                        return o1count - o2count;
                    }
                });
                // store
                for (CompiledClass compiledClass : compiledClassesArray) {
                    // internal name
                    dos.writeUTF(compiledClass.getInternalName());
                    // is local
                    dos.writeBoolean(compiledClass.isLocal());
                    // bytes
                    byte[] bytes = compiledClass.getBytes();
                    dos.writeInt(bytes.length);
                    dos.write(bytes);
                    // enclosing class, write the name only
                    CompiledClass enclosingClass = compiledClass.getEnclosingClass();
                    String enclosingClassName = enclosingClass != null ? enclosingClass.getInternalName() : "";
                    dos.writeUTF(enclosingClassName);
                }
            }
        }
        // dependencies
        {
            Set<ContentId> dependencies = unit.getDependencies();
            int size = dependencies.size();
            dos.writeInt(size);
            if (size > 0) {
                for (ContentId contentId : dependencies) {
                    dos.writeUTF(contentId.get());
                }
            }
        }
        // JSNI methods
        {
            List<JsniMethod> jsniMethods = unit.getJsniMethods();
            int size = jsniMethods.size();
            dos.writeInt(size);
            if (size > 0) {
                for (JsniMethod jsniMethod : jsniMethods) {
                    dos.writeUTF(jsniMethod.name());
                    JsFunction function = jsniMethod.function();
                    SourceInfo sourceInfo = function.getSourceInfo();
                    dos.writeInt(sourceInfo.getStartPos());
                    dos.writeInt(sourceInfo.getEndPos());
                    dos.writeInt(sourceInfo.getStartLine());
                    dos.writeUTF(function.toSource());
                }
            }
        }
        // Method lookup
        {
            MethodArgNamesLookup methodArgs = unit.getMethodArgs();
            MethodArgNamesLookup.save(methodArgs, dos);
        }
    } finally {
        IOUtils.closeQuietly(dos);
    }
}

From source file:com.jroossien.boxx.util.Str.java

/** @see Str#implode(Object[], String, String, int, int) */
public static String implode(Collection<?> args, String glue, String lastGlue, int start, int end) {
    if (args == null || args.isEmpty()) {
        return "";
    }//from   ww w.j  a  v a 2  s  . c o m
    return implode(args.toArray(new Object[args.size()]), glue, lastGlue, start, end);
}

From source file:com.medallia.tiny.Strings.java

/** Collection version of join */
public static String join(String sep, Collection<String> c) {
    return join(sep, c.toArray(new String[0]));
}

From source file:com.medallia.tiny.Strings.java

/** Collection version of join */
public static String join(String sep, boolean foldEmpty, Collection<String> c) {
    return join(sep, foldEmpty, c.toArray(new String[0]));
}