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:io.wcm.handler.mediasource.dam.impl.DefaultRenditionHandler.java

/**
 * Get merged list of file extensions from both media formats and media args.
 * @param mediaArgs Media args/*from w w w.  j ava2  s . com*/
 * @return Array of file extensions.
 *         Returns empty array if all file extensions are allowed.
 *         Returns null if different file extensions are requested in media formats and media args
 *         and the file extension filtering is not fulfillable.
 */
private String[] getRequestedFileExtensions(MediaArgs mediaArgs) {
    // get file extension defined in media args
    Set<String> mediaArgsFileExtensions = new HashSet<String>();
    if (mediaArgs.getFileExtensions() != null && mediaArgs.getFileExtensions().length > 0) {
        mediaArgsFileExtensions.addAll(ImmutableList.copyOf(mediaArgs.getFileExtensions()));
    }

    // get file extensions from media formats
    final Set<String> mediaFormatFileExtensions = new HashSet<String>();
    visitMediaFormats(mediaArgs, new MediaFormatVisitor<Object>() {
        @Override
        public Object visit(MediaFormat mediaFormat) {
            if (mediaFormat.getExtensions() != null && mediaFormat.getExtensions().length > 0) {
                mediaFormatFileExtensions.addAll(ImmutableList.copyOf(mediaFormat.getExtensions()));
            }
            return null;
        }
    });

    // if extensions are defined both in mediaargs and media formats use intersection of both
    final String[] fileExtensions;
    if (!mediaArgsFileExtensions.isEmpty() && !mediaFormatFileExtensions.isEmpty()) {
        Collection<String> intersection = Sets.intersection(mediaArgsFileExtensions, mediaFormatFileExtensions);
        if (intersection.isEmpty()) {
            // not intersected file extensions - return null to singal no valid file extension request
            return null;
        } else {
            fileExtensions = intersection.toArray(new String[intersection.size()]);
        }
    } else if (!mediaArgsFileExtensions.isEmpty()) {
        fileExtensions = mediaArgsFileExtensions.toArray(new String[mediaArgsFileExtensions.size()]);
    } else {
        fileExtensions = mediaFormatFileExtensions.toArray(new String[mediaFormatFileExtensions.size()]);
    }

    return fileExtensions;
}

From source file:info.magnolia.cms.util.ClasspathResourcesUtil.java

/**
 * Return a collection containing the resource names which passed the filter.
 *
 * @param filter//from ww  w. j  a  v a  2 s . co m
 * @return
 * @throws IOException
 */
public static String[] findResources(Filter filter) {

    Collection resources = new ArrayList();

    ClassLoader cl = ClasspathResourcesUtil.class.getClassLoader();

    // if the classloader is an URLClassloader we have a better method for discovering resources
    // whis will also fetch files from jars outside WEB-INF/lib, useful during development
    if (cl instanceof URLClassLoader) {
        // tomcat classloader is org.apache.catalina.loader.WebappClassLoader
        URL[] urls = ((URLClassLoader) cl).getURLs();

        for (int j = 0; j < urls.length; j++) {
            URL url = urls[j];
            File tofile = new File(url.getFile());
            collectFiles(resources, tofile, filter);
        }
    } else {

        // no way, we have to assume a standard war structure and look in the WEB-INF/lib and WEB-INF/classes dirs

        // read the jars in the lib dir
        File dir = new File(Path.getAbsoluteFileSystemPath("WEB-INF/lib")); //$NON-NLS-1$
        if (dir.exists()) {
            File[] files = dir.listFiles(new FilenameFilter() {

                public boolean accept(File file, String name) {
                    return name.endsWith(".jar");
                }
            });

            for (int i = 0; i < files.length; i++) {
                collectFiles(resources, files[i], filter);
            }
        }

        // read files in WEB-INF/classes
        collectFiles(resources, new File(Path.getAbsoluteFileSystemPath("WEB-INF/classes")), filter);
    }

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

From source file:com.jaspersoft.jasperserver.remote.services.impl.BatchRepositoryServicePeganatedSearchTest.java

private void assertResult(final List<ClientResourceLookup> result, final String... resourceLabels) {
    assertEquals(result.size(), resourceLabels.length);

    Collection<String> resultColl = CollectionUtils.collect(result, new Transformer() {
        @Override/*w  ww. j  a  v  a  2 s.  c  om*/
        public String transform(Object input) {
            final ClientResourceLookup entity = (ClientResourceLookup) input;
            return entity.getLabel();
        }
    });

    String[] resultAsArray = Arrays.copyOf(resultColl.toArray(new String[resultColl.size()]),
            resultColl.size());

    assertEquals(resultAsArray, resourceLabels);
}

From source file:com.qualogy.qafe.gwt.server.processor.impl.EventProcessorImpl.java

public GDataObject execute(EventDataGVO eventData, ApplicationIdentifier appId,
        SessionContainer sessionContainer) {

    ApplicationContext context = ApplicationCluster.getInstance().get(appId);
    EventHandler eventHandler = context.getEventHandler();

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*from   w  w  w.jav a2 s . co m*/

    GDataObject data = new GDataObject();
    data.setSenderId(eventData.getSender());
    data.setListenerType(eventData.getListenerType());
    data.setEventId(eventData.getEventId());
    data.setUuid(eventData.getUuid());
    data.setParent(eventData.getParent());
    ApplicationStoreIdentifier appStoreId = new ApplicationStoreIdentifier(eventData.getUuid());
    String[] senderInfo = StringUtils.split(eventData.getSender(), '|');
    logger.fine(eventData.toString() + ", WindowID " + senderInfo[1]);

    String windowId = "";
    if (senderInfo.length == 2 || senderInfo.length == 3) {
        if (senderInfo.length == 2) {// dealing with a RootPanel only
            windowId = senderInfo[0];
        }
        if (senderInfo.length == 3) {

            windowId = senderInfo[1];
        }
        try {

            List<InputVariable> inputVariables = new ArrayList<InputVariable>();

            if (eventData.getInputVariables() != null && eventData.getInputVariables().size() > 0) {
                for (InputVariableGVO inVar : eventData.getInputVariables()) {
                    inputVariables.add(
                            new InputVariable(inVar.getName(), inVar.getReference(), inVar.getDefaultValue(),
                                    inVar.getComponentValue(), convert(inVar.getDataContainerObject())));
                }
            }

            EventDataObject eventDataObject = new EventDataObject(eventData.getEventId(),
                    eventData.getSourceInfo(), appId, eventData.getListenerType(), inputVariables,
                    eventData.getInternalVariables(), senderInfo[0], eventData.getSenderName(), windowId,
                    eventData.getUuid(), eventData.getUserUID(), eventData.getWindowSession(),
                    eventData.getRequest(), eventData.getParameters(), eventData.getMouse());
            eventDataObject.setApplicationStoreIdentifier(appStoreId);

            Collection<?> builtInFunctionsToExecute = eventHandler.manage(eventDataObject);
            Iterator<?> itr = builtInFunctionsToExecute.iterator();
            Collection<BuiltInFunctionGVO> builtInFunctions = new ArrayList<BuiltInFunctionGVO>();
            while (itr.hasNext()) {
                BuiltInFunction builtInFunctionToExecute = (BuiltInFunction) itr.next();
                BuiltInFunctionGVO builtInFunction = EventUIAssembler
                        .convert((EventItem) builtInFunctionToExecute, eventData, context, sessionContainer);
                if (builtInFunction != null) {
                    builtInFunctions.add(builtInFunction);
                }
            }
            data.setFunctions((BuiltInFunctionGVO[]) builtInFunctions.toArray(new BuiltInFunctionGVO[] {}));
        } catch (RuntimeException e) {
            ExceptionHelper.printStackTrace(e);
            throw e;

        } catch (ExternalException e) {
            ExceptionHelper.printStackTrace(e.getCause());
            throw new RuntimeException(e.getMessage(), e);
        }
    } else {
        logger.warning("Error in sender string (is not partionable in size 2) : " + eventData.getSender());
    }
    stopWatch.stop();

    logger.warning("EventProcessorImpl uuid:[" + eventData.getUuid() + "], sender[" + eventData.getSender()
            + "], eventId [" + eventData.getEventName() + "]  took  [" + stopWatch.getTime() + "]ms ");
    return data;
}

From source file:eu.stratosphere.core.testing.GenericTestPlan.java

/**
 * Initializes TestPlan with the given {@link Operator<?>}s. Like the original {@link Plan}, the contracts may be
 * {@link GenericDataSinkBase<T>}s. However, it
 * is also possible to add arbitrary Operators, to which GenericDataSinkOperators
 * are automatically added.//ww  w. j a v a  2  s. c o m
 * 
 * @param defaultConfig
 *        the {@link TypeConfig} that is used for the plan if no specific config is given
 * @param contracts
 *        a list of Operators with at least one element.
 */
public GenericTestPlan(final TypeConfig<T> defaultConfig, final Collection<? extends Operator<?>> contracts) {
    this(defaultConfig, contracts.toArray(new Operator<?>[contracts.size()]));
}

From source file:com.g3net.tool.StringUtils.java

/**
 * Copy the given Collection into a String array. The Collection must
 * contain String elements only./*w w w.j a  v  a  2  s. com*/
 * 
 * @param collection
 *            the Collection to copy
 * @return the String array (<code>null</code> if the passed-in Collection
 *         was <code>null</code>)
 */
public static String[] toStringArray(Collection<String> collection) {
    if (collection == null) {
        return null;
    }
    return (String[]) collection.toArray(new String[collection.size()]);
}

From source file:com.microsoft.tfs.util.temp.TempStorageService.java

/**
 * Cleans up (deletes) files and directories allocated by this service. Can
 * be called multiple times on a single {@link TempStorageService} instance.
 *///from  w  ww  .j  av a  2s.c o  m
public synchronized void cleanUpAllItems() {
    final Collection<CleanUpItem> values = cleanUpItems.values();

    if (values.size() == 0) {
        return;
    }

    // Sort them so we delete them in the order created.
    final CleanUpItem[] items = values.toArray(new CleanUpItem[values.size()]);
    Arrays.sort(items);

    for (int i = 0; i < items.length; i++) {
        cleanUpItemInternal(items[i]);
    }

    cleanUpItems.clear();
}

From source file:blue.lapis.pore.impl.PoreServer.java

@Override
public Player[] _INVALID_getOnlinePlayers() {
    Collection<? extends Player> online = getOnlinePlayers();
    return online.toArray(new Player[online.size()]);
}

From source file:com.openbravo.pos.ticket.TicketInfo.java

public TicketTaxInfo[] getTaxLines() {

    Map<String, TicketTaxInfo> m = new HashMap<>();

    TicketLineInfo oLine;/* ww w .j  a  v  a 2  s .co  m*/
    for (Iterator<TicketLineInfo> i = m_aLines.iterator(); i.hasNext();) {
        oLine = i.next();

        TicketTaxInfo t = m.get(oLine.getTaxInfo().getId());
        if (t == null) {
            t = new TicketTaxInfo(oLine.getTaxInfo());
            m.put(t.getTaxInfo().getId(), t);
        }
        t.add(oLine.getSubValue());
    }

    Collection<TicketTaxInfo> avalues = m.values();
    return avalues.toArray(new TicketTaxInfo[avalues.size()]);
}

From source file:net.ion.radon.impl.let.webdav.FCKConnectorRestlet.java

protected VFSPathToken[] list(final VFSPath path) throws IOException {
    final Collection<VFSPathToken> list = new ArrayList<VFSPathToken>();
    final VFSPathToken[] tokens = vfs.list(path);
    for (VFSPathToken token : tokens) {
        final VFSMetadata md;
        try {//  ww  w.  j  a  va  2 s.  co m
            md = vfs.getMetadata(path.child(token));
        } catch (Exception e) {
            continue;
        }
        if (!md.isHidden())
            list.add(token);
    }
    return list.toArray(new VFSPathToken[list.size()]);
}