Example usage for java.util Collection toString

List of usage examples for java.util Collection toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.nuunframework.kernel.Kernel.java

/**
 * /*from w w w  . j av a 2  s .c  om*/
 */
private void checkPlugins() {
    logger.info("Plugins initialisation ");
    plugins.clear();

    List<Class<? extends Plugin>> pluginClasses = new ArrayList<Class<? extends Plugin>>();

    for (Plugin plugin : fetchedPlugins) {

        String pluginName = plugin.name();
        logger.info("checking Plugin {}.", pluginName);
        if (!Strings.isNullOrEmpty(pluginName)) {
            Object ok = plugins.put(pluginName, plugin);
            if (ok == null) {
                // Check for required param
                // ========================
                Collection<KernelParamsRequest> kernelParamsRequests = plugin.kernelParamsRequests();
                Collection<String> computedMandatoryParams = new HashSet<String>();
                for (KernelParamsRequest kernelParamsRequest : kernelParamsRequests) {
                    if (kernelParamsRequest.requestType == KernelParamsRequestType.MANDATORY) {
                        computedMandatoryParams.add(kernelParamsRequest.keyRequested);
                    }
                }

                if (kernelParamsAndAlias.containsAllKeys(computedMandatoryParams))
                // if (kernelParams.keySet().containsAll(computedMandatoryParams))
                {
                    pluginClasses.add(plugin.getClass());
                } else {
                    logger.error("plugin {} miss parameter/s : {}", pluginName,
                            kernelParamsRequests.toString());
                    throw new KernelException(
                            "plugin " + pluginName + " miss parameter/s : " + kernelParamsRequests.toString());
                }

            } else {
                logger.error(
                        "Can not have 2 Plugin {} of the same type {}. please fix this before the kernel can start.",
                        pluginName, plugin.getClass().getName());
                throw new KernelException(
                        "Can not have 2 Plugin %s of the same type %s. please fix this before the kernel can start.",
                        pluginName, plugin.getClass().getName());
            }
        } else {
            logger.warn("Plugin {} has no correct name it won't be installed.", plugin.getClass());
            throw new KernelException("Plugin %s has no correct name it won't be installed.", pluginName);
        }

    }

    // Check for required and dependent plugins 
    for (Plugin plugin : plugins.values()) {
        {
            Collection<Class<? extends Plugin>> pluginDependenciesRequired = plugin.requiredPlugins();

            if (pluginDependenciesRequired != null && !pluginDependenciesRequired.isEmpty()
                    && !pluginClasses.containsAll(pluginDependenciesRequired)) {
                logger.error("plugin {} misses the following plugin/s as dependency/ies {}", plugin.name(),
                        pluginDependenciesRequired.toString());
                throw new KernelException("plugin %s misses the following plugin/s as dependency/ies %s",
                        plugin.name(), pluginDependenciesRequired.toString());
            }
        }

        {
            Collection<Class<? extends Plugin>> dependentPlugin = plugin.dependentPlugins();

            if (dependentPlugin != null && !dependentPlugin.isEmpty()
                    && !pluginClasses.containsAll(dependentPlugin)) {
                logger.error("plugin {} misses the following plugin/s as dependee/s {}", plugin.name(),
                        dependentPlugin.toString());
                throw new KernelException("plugin %s misses the following plugin/s as dependee/s %s",
                        plugin.name(), dependentPlugin.toString());
            }
        }
    }
}

From source file:eu.medsea.mimeutil.MimeUtil2.java

/**
 * Get all of the matching mime types for this InputStream object.
 * The method delegates down to each of the registered MimeHandler(s) and returns a
 * normalised list of all matching mime types. If no matching mime types are found the returned
 * Collection will contain the unknownMimeType passed in.
 * @param in the InputStream object to detect.
 * @param unknownMimeType.//from  w  ww  .  jav a  2 s  .  c  o  m
 * @return the Collection of matching mime types. If the collection would be empty i.e. no matches then this will
 * contain the passed in parameter unknownMimeType
 * @throws MimeException if there are problems such as reading files generated when the MimeHandler(s)
 * executed.
 */
public final Collection getMimeTypes(final InputStream in, final MimeType unknownMimeType)
        throws MimeException {
    Collection mimeTypes = new MimeTypeHashSet();

    if (in == null) {
        log.error("InputStream reference cannot be null.");
    } else {
        if (!in.markSupported()) {
            throw new MimeException("InputStream must support the mark() and reset() methods.");
        }
        if (log.isDebugEnabled()) {
            log.debug("Getting MIME types for InputSteam [" + in + "].");
        }
        mimeTypes.addAll(mimeDetectorRegistry.getMimeTypes(in));

        // We don't want the unknownMimeType added to the collection by MimeDetector(s)
        mimeTypes.remove(unknownMimeType);
    }
    // If the collection is empty we want to add the unknownMimetype
    if (mimeTypes.isEmpty()) {
        mimeTypes.add(unknownMimeType);
    }
    if (log.isDebugEnabled()) {
        log.debug("Retrieved MIME types [" + mimeTypes.toString() + "]");
    }
    return mimeTypes;
}

From source file:org.kuali.kfs.module.cam.batch.service.impl.AssetDepreciationServiceImpl.java

@Override
public Collection<AssetObjectCode> getAssetObjectCodes(Integer fiscalYear) {
    LOG.debug("DepreciableAssetsDAoOjb.getAssetObjectCodes() -  started");
    LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Getting asset object codes.");

    Collection<AssetObjectCode> assetObjectCodesCollection;
    HashMap<String, Object> fields = new HashMap<String, Object>();
    fields.put(CamsPropertyConstants.AssetObject.UNIVERSITY_FISCAL_YEAR, fiscalYear);
    fields.put(CamsPropertyConstants.AssetObject.ACTIVE, Boolean.TRUE);
    assetObjectCodesCollection = businessObjectService.findMatching(AssetObjectCode.class, fields);

    LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Finished getting asset object codes - which are:"
            + assetObjectCodesCollection.toString());
    LOG.debug("DepreciableAssetsDAoOjb.getAssetObjectCodes() -  ended");
    return assetObjectCodesCollection;
}

From source file:eu.medsea.mimeutil.MimeUtil2.java

/**
 * Get a Collection of possible MimeType(s) that this byte array could represent
 * according to the registered MimeDetector(s). If no MimeType(s) are detected
 * then the returned Collection will contain only the passed in unknownMimeType
 * @param data/*from w w  w.  j  av a  2 s .c o m*/
 * @param unknownMimeType used if the registered MimeDetector(s) fail to match any MimeType(s)
 * @return all matching MimeType(s)
 * @throws MimeException
 */
public final Collection getMimeTypes(final byte[] data, final MimeType unknownMimeType) throws MimeException {
    Collection mimeTypes = new MimeTypeHashSet();
    if (data == null) {
        log.error("byte array cannot be null.");
    } else {
        if (log.isDebugEnabled()) {
            try {
                log.debug("Getting MIME types for byte array [" + StringUtil.getHexString(data) + "].");
            } catch (UnsupportedEncodingException e) {
                throw new MimeException(e);
            }
        }
        mimeTypes.addAll(mimeDetectorRegistry.getMimeTypes(data));

        // We don't want the unknownMimeType added to the collection by MimeDetector(s)
        mimeTypes.remove(unknownMimeType);
    }

    // If the collection is empty we want to add the unknownMimetype
    if (mimeTypes.isEmpty()) {
        mimeTypes.add(unknownMimeType);
    }
    if (log.isDebugEnabled()) {
        log.debug("Retrieved MIME types [" + mimeTypes.toString() + "]");
    }
    return mimeTypes;
}

From source file:com.turbospaces.model.BO.java

/**
 * create business object over actual basic persistent entity
 * // w ww  .j a va2  s .c  o m
 * @param delegate
 *            the actual persistent entity meta-data provider
 * @throws NoSuchMethodException
 *             re-throw cglib exception
 * @throws SecurityException
 *             re-throw cglib exception
 * @throws IntrospectionException
 *             re-throw exceptions
 */
public BO(final BasicPersistentEntity delegate)
        throws SecurityException, NoSuchMethodException, IntrospectionException {
    this.delegate = delegate;
    this.fastConstructor = FastClass.create(delegate.getType())
            .getConstructor(delegate.getType().getConstructor());

    // find optimistic lock version/routing fields
    {
        final Collection<PersistentProperty> versionCandidates = Lists.newLinkedList();
        final Collection<PersistentProperty> routingCandidates = Lists.newLinkedList();
        delegate.doWithProperties(new PropertyHandler() {
            @Override
            public void doWithPersistentProperty(final PersistentProperty persistentProperty) {
                PropertyDescriptor propertyDescriptor = persistentProperty.getPropertyDescriptor();
                Field field = persistentProperty.getField();

                if (hasAnnotation(propertyDescriptor, field, Version.class))
                    versionCandidates.add(persistentProperty);
                if (hasAnnotation(propertyDescriptor, field, Routing.class))
                    routingCandidates.add(persistentProperty);
            }

            private boolean hasAnnotation(final PropertyDescriptor descriptor, final Field field,
                    final Class annotation) {
                if (descriptor != null && descriptor.getReadMethod() != null
                        && descriptor.getReadMethod().getAnnotation(annotation) != null)
                    return true;
                if (field != null && field.getAnnotation(annotation) != null)
                    return true;
                return false;
            }
        });
        Preconditions.checkArgument(versionCandidates.size() <= 1,
                "too many fields marked with @Version annotation, candidates = "
                        + versionCandidates.toString());
        Preconditions.checkArgument(routingCandidates.size() <= 1,
                "too many fields marked with @Routing annotation, candidates = "
                        + routingCandidates.toString());

        if (!versionCandidates.isEmpty())
            optimisticLockVersionProperty = versionCandidates.iterator().next();
        if (!routingCandidates.isEmpty())
            routingProperty = routingCandidates.iterator().next();
    }

    {
        // Java Beans convention marker
        AtomicBoolean propertyAccess = new AtomicBoolean(true);

        List<String> setters = Lists.newLinkedList();
        List<String> getters = Lists.newLinkedList();
        List<Class<?>> types = Lists.newLinkedList();

        for (PersistentProperty<?> persistentProperty : getOrderedProperties()) {
            PropertyDescriptor propertyDescriptor = persistentProperty.getPropertyDescriptor();
            if (propertyDescriptor != null) {
                if (propertyDescriptor.getReadMethod() != null && propertyDescriptor.getWriteMethod() != null) {
                    setters.add(propertyDescriptor.getWriteMethod().getName());
                    getters.add(propertyDescriptor.getReadMethod().getName());
                    types.add(persistentProperty.getType());
                }
            } else {
                propertyAccess.set(false);
                brokenProperties.add(persistentProperty);
            }
        }

        if (propertyAccess.get())
            // create properties extract for all persistent properties
            bulkBean = BulkBean.create(delegate.getType(), getters.toArray(new String[getters.size()]),
                    setters.toArray(new String[setters.size()]), types.toArray(new Class[types.size()]));
        else
            Log.warn(String.format(
                    "PropetiesSerializer-%s unable to use getters-setters access optimization. Suspected/Corrupted properties = %s",
                    delegate.getType().getSimpleName(), getBrokenProperties()));

        boolean canOptimizeIdProperty = hasReadWriteMethods(delegate.getIdProperty());
        boolean canOptimizeVersionProperty = hasReadWriteMethods(getOptimisticLockVersionProperty());
        boolean canOptimizeRoutingProperty = hasReadWriteMethods(getRoutingProperty());

        // create id/version/routing bulk fields extractor
        if (canOptimizeIdProperty && canOptimizeVersionProperty && canOptimizeRoutingProperty) {
            String[] g = new String[] {
                    delegate.getIdProperty().getPropertyDescriptor().getReadMethod().getName(),
                    getOptimisticLockVersionProperty().getPropertyDescriptor().getReadMethod().getName(),
                    getRoutingProperty().getPropertyDescriptor().getReadMethod().getName() };
            String[] s = new String[] {
                    delegate.getIdProperty().getPropertyDescriptor().getWriteMethod().getName(),
                    getOptimisticLockVersionProperty().getPropertyDescriptor().getWriteMethod().getName(),
                    getRoutingProperty().getPropertyDescriptor().getWriteMethod().getName() };
            Class<?>[] c = new Class[] { delegate.getIdProperty().getType(),
                    getOptimisticLockVersionProperty().getType(), getRoutingProperty().getType() };

            idVersionRoutingBulkBean = BulkBean.create(delegate.getType(), g, s, c);
        }
    }
}

From source file:de.escidoc.core.test.aa.UserAttributeTestBase.java

/**
 * Check if xml is valid and contains all attributes that are in given attributeList and only these attributes.
 *
 * @param attributesXml xml with user-attributes
 * @param userId        userId/*from   w w  w. j a v a2 s.c o  m*/
 * @param attributeList list of expected user-attributes
 * @throws Exception If anything fails.
 */
//CHECKSTYLE:OFF
protected void assertValidUserAttributes(final String attributesXml, final String userId,
        Collection<String> attributeList) throws Exception {
    //CHECKSTYLE:ON

    assertXmlValidAttributes(attributesXml);

    String href = "/aa/user-account/" + userId + "/resources/attributes";
    Document attributesXmlDocument = getDocument(attributesXml);
    selectSingleNodeAsserted(attributesXmlDocument, "/attributes/@base");
    selectSingleNodeAsserted(attributesXmlDocument, "/attributes[@href = '" + href + "']");
    int count = attributeList.size();
    if (count > 0) {
        selectSingleNodeAsserted(attributesXmlDocument, "/attributes/attribute[" + count + "]");
    }

    // check if every entry from given collection is in the document
    NodeList attributeElements = selectNodeList(attributesXmlDocument, "/attributes/attribute");
    int elementCount = attributeElements.getLength();
    // iterate elements of the xml document
    for (int i = 0; i < elementCount; i++) {
        // check if key value pair is in given map
        String attributeName = attributeElements.item(i).getAttributes().getNamedItem("name").getNodeValue();
        String attributeValue = attributeElements.item(i).getTextContent();
        String isInternal = attributeElements.item(i).getAttributes().getNamedItem("internal").getNodeValue();
        if (!attributeList.contains(attributeName + attributeValue + isInternal)) {
            fail("Unexpected attribute found. [" + attributeName + attributeValue + isInternal + "]");
        }
        attributeList.remove(attributeName + attributeValue + isInternal);
    }
    // all entries should be removed from hashes(-out-of-map), now
    if (!attributeList.isEmpty()) {
        fail("Expected attributes not found. [" + attributeList.toString() + "]");
    }
}

From source file:eu.medsea.mimeutil.MimeUtil2.java

/**
 * Get all of the matching mime types for this file object.
 * The method delegates down to each of the registered MimeHandler(s) and returns a
 * normalised list of all matching mime types. If no matching mime types are found the returned
 * Collection will contain the unknownMimeType passed in.
 * @param file the File object to detect.
 * @param unknownMimeType.//from  w w  w . ja  va  2  s  .  co  m
 * @return the Collection of matching mime types. If the collection would be empty i.e. no matches then this will
 * contain the passed in parameter unknownMimeType
 * @throws MimeException if there are problems such as reading files generated when the MimeHandler(s)
 * executed.
 */
public final Collection getMimeTypes(final File file, final MimeType unknownMimeType) throws MimeException {
    Collection mimeTypes = new MimeTypeHashSet();

    if (file == null) {
        log.error("File reference cannot be null.");
    } else {

        if (log.isDebugEnabled()) {
            log.debug("Getting MIME types for file [" + file.getAbsolutePath() + "].");
        }

        if (file.isDirectory()) {
            mimeTypes.add(MimeUtil2.DIRECTORY_MIME_TYPE);
        } else {
            // Defer this call to the file name and stream methods
            mimeTypes.addAll(mimeDetectorRegistry.getMimeTypes(file));

            // We don't want the unknownMimeType added to the collection by MimeDetector(s)
            mimeTypes.remove(unknownMimeType);
        }
    }
    // If the collection is empty we want to add the unknownMimetype
    if (mimeTypes.isEmpty()) {
        mimeTypes.add(unknownMimeType);
    }
    if (log.isDebugEnabled()) {
        log.debug("Retrieved MIME types [" + mimeTypes.toString() + "]");
    }
    return mimeTypes;
}

From source file:eu.medsea.mimeutil.MimeUtil2.java

/**
 * Get all of the matching mime types for this file name .
 * The method delegates down to each of the registered MimeHandler(s) and returns a
 * normalised list of all matching mime types. If no matching mime types are found the returned
 * Collection will contain the unknownMimeType passed in.
 * @param fileName the name of a file to detect.
 * @param unknownMimeType.//w  w w. j ava 2s. c o  m
 * @return the Collection of matching mime types. If the collection would be empty i.e. no matches then this will
 * contain the passed in parameter unknownMimeType
 * @throws MimeException if there are problems such as reading files generated when the MimeHandler(s)
 * executed.
 */
public final Collection getMimeTypes(final String fileName, final MimeType unknownMimeType)
        throws MimeException {
    Collection mimeTypes = new MimeTypeHashSet();

    if (fileName == null) {
        log.error("fileName cannot be null.");
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Getting MIME types for file name [" + fileName + "].");
        }

        // Test if this is a directory
        File file = new File(fileName);

        if (file.isDirectory()) {
            mimeTypes.add(MimeUtil2.DIRECTORY_MIME_TYPE);
        } else {
            mimeTypes.addAll(mimeDetectorRegistry.getMimeTypes(fileName));

            // We don't want the unknownMimeType added to the collection by MimeDetector(s)
            mimeTypes.remove(unknownMimeType);
        }
    }
    // If the collection is empty we want to add the unknownMimetype
    if (mimeTypes.isEmpty()) {
        mimeTypes.add(unknownMimeType);
    }
    if (log.isDebugEnabled()) {
        log.debug("Retrieved MIME types [" + mimeTypes.toString() + "]");
    }
    return mimeTypes;

}

From source file:org.alfresco.repo.workflow.jbpm.AlfrescoJobExecutorThread.java

@SuppressWarnings("rawtypes")
@Override/*ww w .j a  va2  s  .  c o m*/
protected Collection acquireJobs() {
    Collection jobs = Collections.EMPTY_LIST;

    if ((isActive) && (!alfrescoJobExecutor.getTransactionService().isReadOnly())) {
        try {
            jobs = alfrescoJobExecutor.getTransactionService().getRetryingTransactionHelper()
                    .doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Collection>() {
                        public Collection execute() throws Throwable {
                            if (jobLockToken != null) {
                                refreshExecutorLock(jobLockToken);
                            } else {
                                jobLockToken = getExecutorLock();
                            }

                            try {
                                return AlfrescoJobExecutorThread.super.acquireJobs();
                            } catch (Throwable t) {
                                logger.error("Failed to acquire jobs");
                                releaseExecutorLock(jobLockToken);
                                jobLockToken = null;
                                throw t;
                            }
                        }
                    });

            if (jobs != null) {
                if (logger.isDebugEnabled() && (!logger.isTraceEnabled()) && (!jobs.isEmpty())) {
                    logger.debug("acquired " + jobs.size() + " job" + ((jobs.size() != 1) ? "s" : ""));
                }

                if (logger.isTraceEnabled()) {
                    logger.trace("acquired " + jobs.size() + " job" + ((jobs.size() != 1) ? "s" : "")
                            + ((jobs.size() > 0) ? ": " + jobs.toString() : ""));
                }

                if (jobs.size() == 0) {
                    releaseExecutorLock(jobLockToken);
                    jobLockToken = null;
                }
            }
        } catch (LockAcquisitionException e) {
            // ignore
            jobLockToken = null;
        }
    }

    return jobs;
}

From source file:eu.medsea.mimeutil.MimeUtil2.java

public final Collection getMimeTypes(final URL url, final MimeType unknownMimeType) throws MimeException {
    Collection mimeTypes = new MimeTypeHashSet();

    if (url == null) {
        log.error("URL reference cannot be null.");
    } else {//from   w ww .j  av  a2 s.  c  o m
        if (log.isDebugEnabled()) {
            log.debug("Getting MIME types for URL [" + url + "].");
        }

        // Test if this is a directory
        File file = new File(url.getPath());
        if (file.isDirectory()) {
            mimeTypes.add(MimeUtil2.DIRECTORY_MIME_TYPE);
        } else {
            // defer these calls to the file name and stream methods
            mimeTypes.addAll(mimeDetectorRegistry.getMimeTypes(url));

            // We don't want the unknownMimeType added to the collection by MimeDetector(s)
            mimeTypes.remove(unknownMimeType);
        }
    }
    // If the collection is empty we want to add the unknownMimetype
    if (mimeTypes.isEmpty()) {
        mimeTypes.add(unknownMimeType);
    }
    if (log.isDebugEnabled()) {
        log.debug("Retrieved MIME types [" + mimeTypes.toString() + "]");
    }
    return mimeTypes;
}