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

Object[] toArray();

Source Link

Document

Returns an array containing all of the elements in this collection.

Usage

From source file:com.swtxml.util.parser.Splitter.java

public String join(Collection<?> values) {
    return this.join(values.toArray());

}

From source file:edu.ku.brc.af.ui.forms.BaseBusRules.java

/**
 * Removed an Object from a Collection by Id.
 * @param collection the Java Collection
 * @param dataObj the data object to be removed
 *///from w  ww  . j  a v a  2s.co m
public static int countDataObjectById(final Collection<?> collection, final FormDataObjIFace dataObj) {
    int cnt = 0;
    for (Object obj : collection.toArray()) {
        if (obj instanceof FormDataObjIFace) {
            FormDataObjIFace colObj = (FormDataObjIFace) obj;
            if (dataObj == colObj || (colObj.getId() != null && dataObj.getId() != null
                    && dataObj.getId().equals(colObj.getId()))) {
                cnt++;
            }
        }
    }
    return cnt;
}

From source file:com.esofthead.mycollab.core.arguments.SetSearchField.java

@SuppressWarnings("unchecked")
public SetSearchField(String oper, Collection<T> vals) {
    this(oper, (T[]) vals.toArray());
}

From source file:com.bancvue.mongomigrate.MigrationFileRepositoryTests.java

@Test
public void shouldBeAbleToLoadAllMigrationFilesFromFolder() throws IOException {
    Files.createFile(Paths.get("20130629200000_migration1.js"));
    Files.createFile(Paths.get("20130629200000_migration2.js"));

    IMigrationFileRepository repository = new MigrationFileRepository(".");

    Collection<File> files = repository.findAll();

    assertThat(files.toArray(), hasItemInArray(hasProperty("name", equalTo("20130629200000_migration1.js"))));
    assertThat(files.toArray(), hasItemInArray(hasProperty("name", equalTo("20130629200000_migration2.js"))));
}

From source file:FastArray.java

public FastArray(Collection c) {
    this(c.toArray());
}

From source file:gov.nih.nci.protexpress.ui.validators.HibernateValidator.java

/**
 * {@inheritDoc}/*from   www.j a  v a 2s.co m*/
 */
public void validate(Object object) throws ValidationException {
    String fieldName = getFieldName();
    Object value = getFieldValue(fieldName, object);
    ValueStack stack = ActionContext.getContext().getValueStack();
    stack.push(object);
    if (value instanceof Collection) {
        Collection coll = (Collection) value;
        Object[] array = coll.toArray();
        validateArrayElements(array, fieldName);
    } else if (value instanceof Object[]) {
        Object[] array = (Object[]) value;
        validateArrayElements(array, fieldName);
    } else {
        validateObject(fieldName, value);
    }
    stack.pop();
}

From source file:com.snowstore.mercury.indicator.MemcachedHealthIndicator.java

@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
    if (valid) {/*from  w w w . j a v a2 s  .  co  m*/
        Collection<SocketAddress> info = cacheFactory.getCache().getAvailableServers();
        builder.up().withDetail(SERVER, info.toArray());
        addBuilder(builder);
    } else {
        builder.none();
    }
}

From source file:org.openmrs.module.logmanager.web.view.AutocompleteView.java

@SuppressWarnings("rawtypes")
@Override// ww  w  . j a v  a  2  s .c o m
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    PrintWriter writer = response.getWriter();
    Object source = model.get(sourceKey);

    // Disable caching
    response.setHeader("Pragma", "No-cache");
    response.setDateHeader("Expires", 0);
    response.setHeader("Cache-Control", "no-cache");
    response.setContentType("application/json");

    writer.write("[");

    if (source != null) {
        if (source instanceof Collection) {
            Collection<?> collection = (Collection<?>) source;
            Object[] items = collection.toArray();
            for (int i = 0; i < items.length; i++) {
                Object item = items[i];
                String label = (item instanceof LoggerProxy) ? ((LoggerProxy) item).getName() : item.toString();

                if (i > 0)
                    writer.write(',');

                writer.write("{\"label\":\"" + label + "\", \"value\":\"" + label + "\"}");
            }
        }
    } else
        writer.write("\"ERROR: Source object is null\"");

    writer.write("]");
}

From source file:me.schiz.functions.Base64DecodeFunction.java

public synchronized void setParameters(Collection<CompoundVariable> parameters)
        throws InvalidVariableException {
    checkMinParameterCount(parameters, 1);
    values = parameters.toArray();
}

From source file:net.sf.ehcache.loader.ExceptionThrowingLoader.java

/**
 * Load using both a key and an argument.
 * <p/>//from   ww  w.j  av a2  s. c  om
 * JCache will use the loadAll(key) method where the argument is null.
 *
 * @param keys
 * @param argument
 * @return
 * @throws net.sf.jsr107cache.CacheException
 *
 */
public Map loadAll(Collection keys, Object argument) throws CacheException {
    throw new CacheException("Some exception with key " + keys.toArray()[0]);
}