Example usage for org.apache.commons.lang ArrayUtils toString

List of usage examples for org.apache.commons.lang ArrayUtils toString

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils toString.

Prototype

public static String toString(Object array) 

Source Link

Document

Outputs an array as a String, treating null as an empty array.

Usage

From source file:org.bdval.SurvivalMeasures.java

public void calculateStat() {
    final double alpha = 0.05;
    double[] time = null;
    double[] censor = null;
    double[] group = null;
    try {/*from ww w . ja v  a  2s. co  m*/
        final int numSamples = timeList.size();
        time = timeList.toArray(new double[numSamples]);
        censor = censorList.toArray(new double[numSamples]);
        group = binaryDecisionList.toArray(new double[numSamples]);
        final double[] decisionScore = decisionList.toArray(new double[numSamples]);
        final double[][] covariateWithScore = new double[nCov + 1][numSamples];

        for (int k = 0; k < nCov + 1; k++) {
            final double[] arr = covariateList.get(k).toArray(new double[numSamples]);
            System.arraycopy(arr, 0, covariateWithScore[k], 0, numSamples); //turn 2D list into  2Darray
        }

        coxRegressionByJava(alpha, time, censor, covariateWithScore);
        //     coxRegressionByRScript(time, censor, covariateWithScore);

        logRankByRscript(time, censor, group);

    } catch (Exception e) {
        LOG.warn(String.format(
                "Cannot calculate stats for time=%s, censor=%s,group=%s, size=%d, size=%d, size=%d",
                ArrayUtils.toString(time), ArrayUtils.toString(censor), ArrayUtils.toString(group), time.length,
                censor.length, group.length), e);
    }
}

From source file:org.beangle.model.transfer.importer.MultiEntityImporter.java

public void transferItem() {
    if (logger.isDebugEnabled()) {
        logger.debug("tranfer index:" + getTranferIndex() + ":" + ArrayUtils.toString(values));
    }// w w w  .j  av  a 2  s  .co m
    // 
    for (int i = 0; i < attrs.length; i++) {
        Object value = values.get(attrs[i]);
        // 
        if (StringUtils.isBlank(attrs[i]))
            continue;
        // ?trim
        if (value instanceof String) {
            String strValue = (String) value;
            if (StringUtils.isBlank(strValue)) {
                value = null;
            } else {
                value = StringUtils.trim(strValue);
            }
        }
        // ?null
        if (null == value) {
            continue;
        } else {
            if (value.equals(Model.NULL)) {
                value = null;
            }
        }
        Object entity = getCurrent(attrs[i]);
        String attr = processAttr(attrs[i]);
        String entityName = getEntityName(attrs[i]);
        // 
        if (StringUtils.contains(attr, '.')) {
            if (null != foreignerKeys) {
                boolean isForeigner = isForeigner(attr);
                // ,?parentPath?
                // ,?.
                if (isForeigner) {
                    String parentPath = StringUtils.substringBeforeLast(attr, ".");
                    ObjectAndType propertyType = populator.initProperty(entity, entityName, parentPath);
                    Object property = propertyType.getObj();
                    if (property instanceof Entity<?>) {
                        if (((Entity<?>) property).isPersisted()) {
                            populator.populateValue(entity, parentPath, null);
                            populator.initProperty(entity, entityName, parentPath);
                        }
                    }
                }
            }
        }
        populator.populateValue(entity, attr, value);
    }
}

From source file:org.cesecore.certificates.ca.CA.java

/** Sets the CA token. */
public void setCAToken(CAToken catoken) throws InvalidAlgorithmException {
    // Check that the signature algorithm is one of the allowed ones, only check if there is a sigAlg though
    // things like a NulLCryptoToken does not have signature algorithms
    final String sigAlg = catoken.getSignatureAlgorithm();
    if (StringUtils.isNotEmpty(sigAlg)) {
        if (!ArrayUtils.contains(AlgorithmConstants.AVAILABLE_SIGALGS, sigAlg)) {
            final String msg = intres.getLocalizedMessage("createcert.invalidsignaturealg", sigAlg,
                    ArrayUtils.toString(AlgorithmConstants.AVAILABLE_SIGALGS));
            throw new InvalidAlgorithmException(msg);
        }/*  ww w  .jav  a 2  s  .  co m*/
    }
    final String encAlg = catoken.getEncryptionAlgorithm();
    if (StringUtils.isNotEmpty(encAlg)) {
        if (!ArrayUtils.contains(AlgorithmConstants.AVAILABLE_SIGALGS, encAlg)) {
            final String msg = intres.getLocalizedMessage("createcert.invalidsignaturealg", encAlg,
                    ArrayUtils.toString(AlgorithmConstants.AVAILABLE_SIGALGS));
            throw new InvalidAlgorithmException(msg);
        }
    }
    data.put(CATOKENDATA, catoken.saveData());
    this.caToken = catoken;
}

From source file:org.codehaus.grepo.core.context.GrepoTestContextLoader.java

/**
 * {@inheritDoc}//from   ww w . j  av  a  2 s . co m
 */
@Override
protected BeanDefinitionReader createBeanDefinitionReader(GenericApplicationContext context) {
    BeanDefinitionReader bdr = super.createBeanDefinitionReader(context);
    ResourcePatternResolver rpr = new PathMatchingResourcePatternResolver();
    try {
        Resource[] resources = rpr.getResources("classpath*:/META-INF/grepo/grepo-testcontext.xml");
        logger.debug("Found grepo-testcontexts: {}", ArrayUtils.toString(resources));
        bdr.loadBeanDefinitions(resources);

        String addPattern = getAdditionalConfigPattern();
        if (!StringUtils.isEmpty(addPattern)) {
            Resource[] addResources = rpr.getResources(addPattern);
            if (addResources != null) {
                logger.debug("Found additional spring-configs: {}", ArrayUtils.toString(addResources));
                bdr.loadBeanDefinitions(addResources);
            }
        }
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    return bdr;
}

From source file:org.codehaus.grepo.core.validator.GenericValidationUtils.java

/**
 * Validates the given {@code result} using the given {@link ResultValidator} {@code clazz}.
 *
 * @param mpi The method parameter info.
 * @param clazz The validator clazz (must not be null).
 * @param result The result to validate.
 * @throws Exception in case of errors (like validation errors).
 * @throws ValidationException if the given {@link ResultValidator} cannot be instantiated.
 *///from  w  w w . j a va2s. c o  m
public static void validateResult(MethodParameterInfo mpi, Class<? extends ResultValidator> clazz,
        Object result) throws Exception, ValidationException {
    if (isValidResultValidator(clazz)) {
        ResultValidator validator = null;
        try {
            logger.debug("Using result validator '{}' for validating result '{}'", clazz, result);
            validator = clazz.newInstance();
        } catch (InstantiationException e) {
            String msg = String.format("Unable to create new instance of '%s': '%s'", clazz.getName(),
                    e.getMessage());
            throw new ValidationException(msg, e);
        } catch (IllegalAccessException e) {
            String msg = String.format("Unable to create new instance of '%s': '%s'", clazz.getName(),
                    e.getMessage());
            throw new ValidationException(msg, e);
        }

        try {
            validator.validate(result);
        } catch (Exception e) {
            logger.debug("Validation error occured: {}", e.getMessage());

            if (mpi.isMethodCompatibleWithException(e)) {
                throw e;
            } else {
                String m = "Exception '%s' is not compatible with  method '%s' (exeptionTypes: %s) "
                        + "- exception will be wrapped in a ValidationException";
                String msg = String.format(m, e.getClass().getName(), mpi.getMethodName(),
                        ArrayUtils.toString(mpi.getMethod().getExceptionTypes()));
                logger.error(msg);
                throw new ValidationException(msg);
            }
        }
    }
}

From source file:org.codehaus.griffon.plugins.DefaultGriffonPluginManager.java

/**
 * This method will attempt to load that plug-ins not loaded in the first pass
 *
 */// w  ww.  jav a 2 s .  c  o  m
private void loadDelayedPlugins() {
    while (!delayedLoadPlugins.isEmpty()) {
        GriffonPlugin plugin = (GriffonPlugin) delayedLoadPlugins.remove(0);
        if (areDependenciesResolved(plugin)) {
            registerPlugin(plugin);
        } else {
            // ok, it still hasn't resolved the dependency after the initial
            // load of all plugins. All hope is not lost, however, so lets first
            // look inside the remaining delayed loads before giving up
            boolean foundInDelayed = false;
            for (Iterator i = delayedLoadPlugins.iterator(); i.hasNext();) {
                GriffonPlugin remainingPlugin = (GriffonPlugin) i.next();
                if (isDependentOn(plugin, remainingPlugin)) {
                    foundInDelayed = true;
                    break;
                }
            }
            if (foundInDelayed)
                delayedLoadPlugins.add(plugin);
            else {
                failedPlugins.put(plugin.getName(), plugin);
                LOG.warn(
                        "WARNING: Plugin [" + plugin.getName() + "] cannot be loaded because its dependencies ["
                                + ArrayUtils.toString(plugin.getDependencyNames()) + "] cannot be resolved");
            }

        }
    }
}

From source file:org.codehaus.groovy.grails.commons.metaclass.AbstractDynamicMethods.java

public Object invokeMethod(Object object, String methodName, Object[] arguments, InvocationCallback callback) {
    if (LOG.isTraceEnabled()) {
        LOG.debug("[DynamicMethods] Attempting invocation of dynamic method [" + methodName + "] on target ["
                + object + "] with arguments [" + ArrayUtils.toString(arguments) + "]");
    }//from w  w w  .j a  v  a  2  s  . c  om
    for (DynamicMethodInvocation methodInvocation : dynamicMethodInvocations) {
        if (methodInvocation.isMethodMatch(methodName)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(
                        "[DynamicMethods] Dynamic method [" + methodName + "] matched, attempting to invoke.");
            }

            try {
                Object result = methodInvocation.invoke(object, methodName, arguments);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("[DynamicMethods] Instance method [" + methodName
                            + "] invoked successfully with result [" + result + "]. Marking as invoked");
                }
                callback.setInvoker(methodInvocation);
                callback.markInvoked();
                return result;
            } catch (MissingMethodException e) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("[DynamicMethods] Instance method [" + methodName
                            + "] threw MissingMethodException. Returning null and falling back to standard MetaClass",
                            e);
                }
                return null;
            }
        }
    }
    return null;
}

From source file:org.codehaus.groovy.grails.commons.metaclass.AbstractDynamicMethods.java

public Object invokeConstructor(Object[] arguments, InvocationCallback callBack) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("[DynamicMethods] Attempting invocation of dynamic constructor with arguments ["
                + ArrayUtils.toString(arguments) + "]");
    }/*from   w  w  w .  j a v a 2  s.  c o  m*/

    for (DynamicConstructor constructor : dynamicConstructors) {
        if (constructor.isArgumentsMatch(arguments)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("[DynamicMethods] Dynamic constructor found, marked and invoking...");
            }
            callBack.markInvoked();
            return constructor.invoke(clazz, arguments);
        }
    }
    return null;
}

From source file:org.codehaus.groovy.grails.commons.metaclass.AbstractDynamicMethods.java

public Object invokeStaticMethod(Object object, String methodName, Object[] arguments,
        InvocationCallback callBack) {// www.  j  a v  a2 s  .  co  m
    if (LOG.isDebugEnabled()) {
        LOG.debug("[DynamicMethods] Attempting invocation of dynamic static method [" + methodName
                + "] on target [" + object + "] with arguments [" + ArrayUtils.toString(arguments) + "]");
    }
    for (StaticMethodInvocation methodInvocation : staticMethodInvocations) {
        if (methodInvocation.isMethodMatch(methodName)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("[DynamicMethods] Static method matched, attempting to invoke");
            }

            try {
                Object result = methodInvocation.invoke(clazz, methodName, arguments);

                if (LOG.isDebugEnabled()) {
                    LOG.debug("[DynamicMethods] Static method [" + methodName
                            + "] invoked successfully with result [" + result + "]. Marking as invoked");
                }
                callBack.markInvoked();
                return result;
            } catch (MissingMethodException e) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("[DynamicMethods] Static method [" + methodName
                            + "] threw MissingMethodException. Returning null and falling back to standard MetaClass",
                            e);
                }
                return null;
            }
        }
    }
    return null;
}

From source file:org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateCriterionAdapter.java

/**
 * utility method that generically returns a criterion using methods in Restrictions
 *
 * @param constraintName - the criteria//ww w  .  j  a  v a2s.com
 */
protected Criterion callRestrictionsMethod(String constraintName, Class<?>[] paramTypes, Object[] params) {
    final Method restrictionsMethod = ReflectionUtils.findMethod(Restrictions.class, constraintName,
            paramTypes);
    Assert.notNull(restrictionsMethod,
            "Could not find method: " + constraintName + " in class Restrictions for parameters: "
                    + ArrayUtils.toString(params) + " with types: " + ArrayUtils.toString(paramTypes));
    return (Criterion) ReflectionUtils.invokeMethod(restrictionsMethod, null, params);
}