Example usage for org.apache.commons.lang3 ArrayUtils getLength

List of usage examples for org.apache.commons.lang3 ArrayUtils getLength

Introduction

In this page you can find the example usage for org.apache.commons.lang3 ArrayUtils getLength.

Prototype

public static int getLength(final Object array) 

Source Link

Document

Returns the length of the specified array.

Usage

From source file:com.mirth.connect.donkey.util.purge.PurgeUtil.java

private static Map.Entry<?, ?> getPurgedEntry(Map.Entry<?, ?> originalEntry) {
    Object originalKey = originalEntry.getKey();
    Object originalValue = originalEntry.getValue();
    String key = StringUtils.uncapitalize(originalKey.toString());
    Object value = originalValue;

    if (originalValue instanceof String[]) {
        key += "Count";
        value = ArrayUtils.getLength(originalValue);
    } else if (originalValue instanceof ArrayList<?>) {
        key += "Count";
        value = ((ArrayList<Object>) originalValue).size();
    } else if (originalValue instanceof Map<?, ?>) {
        key += "Count";
        value = ((Map<Object, Object>) originalValue).size();
    } else {//from ww  w  .jav a 2  s . com
        return null;
    }
    return new AbstractMap.SimpleEntry(key, value);
}

From source file:com.adeptj.modules.commons.jdbc.util.DataSources.java

public static HikariDataSource newDataSource(DataSourceConfig config) {
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setPoolName(config.poolName());
    hikariConfig.setJdbcUrl(config.jdbcUrl());
    hikariConfig.setDriverClassName(config.driverClassName());
    hikariConfig.setUsername(config.username());
    hikariConfig.setPassword(config.password());
    hikariConfig.setAutoCommit(config.autoCommit());
    hikariConfig.setConnectionTimeout(config.connectionTimeout());
    hikariConfig.setIdleTimeout(config.idleTimeout());
    hikariConfig.setMaxLifetime(config.maxLifetime());
    hikariConfig.setMinimumIdle(config.minimumIdle());
    hikariConfig.setMaximumPoolSize(config.maximumPoolSize());
    Stream.of(config.dataSourceProperties()).filter(row -> ArrayUtils.getLength(row.split(EQ)) == 2)
            .map(row -> row.split(EQ))
            .forEach(mapping -> hikariConfig.addDataSourceProperty(mapping[0], mapping[1]));
    return new HikariDataSource(hikariConfig);
}

From source file:de.vandermeer.skb.interfaces.transformers.arrays2d.Array2D_To_NormalizedArray.java

@Override
default String[][] transform(String[][] ar) {
    IsTransformer.super.transform(ar);

    int rows = 0;
    for (int row = 0; row < ar.length; row++) {
        rows = Math.max(rows, ArrayUtils.getLength(ar[row]));
    }/*from  ww w .jav a2s.  c o  m*/
    if (rows == 0) {
        rows = 1;
    }
    String[][] ret = new String[this.getNumberOfColumns()][rows];

    for (int row = 0; row < ar.length; row++) {
        int curSize = 0;
        if (ar[row] != null && ar[row][0] != null) {
            curSize = ar[row][0].length();
        }
        if (ar[row] == null) {
            for (int i = 0; i < rows; i++) {
                ret[row][i] = null;
            }
        } else if (ar[row].length == 0) {
            for (int i = 0; i < rows; i++) {
                ret[row][i] = new StrBuilder().appendPadding(curSize, ' ').toString();
            }
        } else {
            for (int col = 0; col < ar[row].length; col++) {
                ret[row][col] = ar[row][col];
            }
            if (ar[row].length < rows) {
                for (int i = ar[row].length; i < rows; i++) {
                    ret[row][i] = new StrBuilder().appendPadding(curSize, ' ').toString();
                }
            }
        }
    }
    return ret;
}

From source file:de.vandermeer.skb.base.utils.Skb_ArrayUtils.java

/**
 * Returns a transformer that normalises string arrays.
 * @param length number of columns in the transformed string array
 * @return transformer for normalising string arrays
 *//*from   ww w .  j av  a  2  s. co m*/
public static final Skb_Transformer<String[][], String[][]> NORMALISE_ARRAY(final int length) {
    return new Skb_Transformer<String[][], String[][]>() {
        @Override
        public String[][] transform(String[][] ar) {
            int width = 0;
            //get the length of the longest array, use that as width in normalisation
            for (int row = 0; row < ar.length; row++) { //TODO not null safe
                width = Math.max(width, ArrayUtils.getLength(ar[row]));
            }
            if (width == 0) {
                width = 1;
            }
            String[][] ret = new String[length][width];

            for (int row = 0; row < ar.length; row++) { //not null safe
                if (ar[row] == null) {
                    for (int i = 0; i < width; i++) {
                        ret[row][i] = null;
                    }
                } else if (ar[row].length == 0) {
                    for (int i = 0; i < width; i++) {
                        ret[row][i] = "";
                    }
                } else {
                    for (int col = 0; col < ar[row].length; col++) {
                        ret[row][col] = ar[row][col];
                    }
                    if (ar[row].length < width) {
                        for (int i = ar[row].length; i < width; i++) {
                            ret[row][i] = "";
                        }
                    }
                }
            }
            return ret;
        }
    };
}

From source file:com.linkedin.pinot.core.segment.creator.ColumnIndexCreationInfo.java

public int getDistinctValueCount() {
    return ArrayUtils.getLength(sortedUniqueElementsArray);
}

From source file:com.linkedin.pinot.core.segment.creator.impl.SegmentDictionaryCreator.java

public SegmentDictionaryCreator(boolean hasNulls, Object sortedList, FieldSpec spec, File indexDir,
        char paddingChar) throws IOException {
    rowCount = ArrayUtils.getLength(sortedList);

    Object first = null;// w w  w .  j a v a  2  s . c  om
    Object last = null;

    if (0 < rowCount) {
        if (sortedList instanceof int[]) {
            int[] intSortedList = (int[]) sortedList;
            first = intSortedList[0];
            last = intSortedList[rowCount - 1];
        } else if (sortedList instanceof long[]) {
            long[] longSortedList = (long[]) sortedList;
            first = longSortedList[0];
            last = longSortedList[rowCount - 1];
        } else if (sortedList instanceof float[]) {
            float[] floatSortedList = (float[]) sortedList;
            first = floatSortedList[0];
            last = floatSortedList[rowCount - 1];
        } else if (sortedList instanceof double[]) {
            double[] doubleSortedList = (double[]) sortedList;
            first = doubleSortedList[0];
            last = doubleSortedList[rowCount - 1];
        } else if (sortedList instanceof String[]) {
            String[] intSortedList = (String[]) sortedList;
            first = intSortedList[0];
            last = intSortedList[rowCount - 1];
        } else if (sortedList instanceof Object[]) {
            Object[] intSortedList = (Object[]) sortedList;
            first = intSortedList[0];
            last = intSortedList[rowCount - 1];
        }
    }

    // make hll column log info different than other columns, since range makes no sense for hll column
    if (spec instanceof MetricFieldSpec
            && ((MetricFieldSpec) spec).getDerivedMetricType() == MetricFieldSpec.DerivedMetricType.HLL) {
        LOGGER.info(
                "Creating segment for column {}, hasNulls = {}, cardinality = {}, dataType = {}, single value field = {}, is HLL derived column",
                spec.getName(), hasNulls, rowCount, spec.getDataType(), spec.isSingleValueField());
    } else {
        LOGGER.info(
                "Creating segment for column {}, hasNulls = {}, cardinality = {}, dataType = {}, single value field = {}, range = {} to {}",
                spec.getName(), hasNulls, rowCount, spec.getDataType(), spec.isSingleValueField(), first, last);
    }
    this.sortedList = sortedList;
    this.spec = spec;
    this.paddingChar = paddingChar;
    dictionaryFile = new File(indexDir, spec.getName() + ".dict");
    FileUtils.touch(dictionaryFile);
}

From source file:de.vandermeer.asciitable.commons.ArrayTransformations.java

/**
 * Normalizes an array of strings./*from   w  ww  . j  ava2 s  .  com*/
 * @param length number of columns in the transformed string array
 * @param ar input array which will be normalized
 * @return a normalized array
 */
public static final String[][] NORMALISE_ARRAY(final int length, String[][] ar) {
    int width = 0;
    //get the length of the longest array, use that as width in normalization
    for (int row = 0; row < ar.length; row++) { //TODO not null safe
        width = Math.max(width, ArrayUtils.getLength(ar[row]));
    }
    if (width == 0) {
        width = 1;
    }
    String[][] ret = new String[length][width];

    for (int row = 0; row < ar.length; row++) { //not null safe
        if (ar[row] == null) {
            for (int i = 0; i < width; i++) {
                ret[row][i] = null;
            }
        } else if (ar[row].length == 0) {
            for (int i = 0; i < width; i++) {
                ret[row][i] = "";
            }
        } else {
            for (int col = 0; col < ar[row].length; col++) {
                ret[row][col] = ar[row][col];
            }
            if (ar[row].length < width) {
                for (int i = ar[row].length; i < width; i++) {
                    ret[row][i] = "";
                }
            }
        }
    }
    return ret;
}

From source file:com.adeptj.modules.data.jpa.core.JpaProperties.java

public static Map<String, Object> from(EntityManagerFactoryConfig config) {
    Map<String, Object> jpaProperties = new HashMap<>();
    jpaProperties.put(DDL_GENERATION, config.ddlGeneration());
    jpaProperties.put(DDL_GENERATION_MODE, config.ddlGenerationOutputMode());
    // DEPLOY_ON_STARTUP must be a string value
    jpaProperties.put(DEPLOY_ON_STARTUP, Boolean.toString(config.deployOnStartup()));
    jpaProperties.put(LOGGING_LEVEL, config.loggingLevel());
    jpaProperties.put(TRANSACTION_TYPE, config.persistenceUnitTransactionType());
    jpaProperties.put(ECLIPSELINK_PERSISTENCE_XML, config.persistenceXmlLocation());
    jpaProperties.put(SHARED_CACHE_MODE, config.sharedCacheMode());
    jpaProperties.put(VALIDATION_MODE, config.validationMode());
    jpaProperties.put(PERSISTENCE_PROVIDER, config.persistenceProviderClassName());
    if (config.useExceptionHandler()) {
        jpaProperties.put(EXCEPTION_HANDLER_CLASS, JpaExceptionHandler.class.getName());
    }/*from   ww  w  .  jav  a  2  s .c  om*/
    // Extra properties are in [key=value] format.
    jpaProperties.putAll(Stream.of(config.jpaProperties()).filter(StringUtils::isNotEmpty)
            .map(row -> row.split(EQ)).filter(mapping -> ArrayUtils.getLength(mapping) == 2)
            .collect(Collectors.toMap(elem -> elem[0], elem -> elem[1])));
    return jpaProperties;
}

From source file:com.jkoolcloud.tnt4j.streams.transform.FuncGetObjectName.java

private static String resolveObjectName(String objectName, List<?> args) {
    String option = args.size() > 1 ? (String) args.get(1) : null;
    Options opt;/*from  w  w  w .j  ava  2 s  .co m*/

    try {
        opt = StringUtils.isEmpty(option) ? Options.DEFAULT : Options.valueOf(option.toUpperCase());
    } catch (IllegalArgumentException exc) {
        opt = Options.DEFAULT;
    }

    switch (opt) {
    case FULL:
        break;
    case BEFORE:
        String sSymbol = args.size() > 2 ? (String) args.get(2) : null;
        if (StringUtils.isNotEmpty(sSymbol)) {
            objectName = StringUtils.substringBefore(objectName, sSymbol);
        }
        break;
    case AFTER:
        sSymbol = args.size() > 2 ? (String) args.get(2) : null;
        if (StringUtils.isNotEmpty(sSymbol)) {
            objectName = StringUtils.substringAfter(objectName, sSymbol);
        }
        break;
    case REPLACE:
        sSymbol = args.size() > 2 ? (String) args.get(2) : null;
        if (StringUtils.isNotEmpty(sSymbol)) {
            String rSymbol = args.size() > 3 ? (String) args.get(3) : null;
            objectName = StringUtils.replaceChars(objectName, sSymbol, rSymbol == null ? "" : rSymbol);
        }
        break;
    case SECTION:
        String idxStr = args.size() > 2 ? (String) args.get(2) : null;
        int idx;
        try {
            idx = Integer.parseInt(idxStr);
        } catch (Exception exc) {
            idx = -1;
        }

        if (idx >= 0) {
            sSymbol = args.size() > 3 ? (String) args.get(3) : null;
            String[] onTokens = StringUtils.split(objectName,
                    StringUtils.isEmpty(sSymbol) ? OBJ_NAME_TOKEN_DELIMITERS : sSymbol);
            objectName = idx < ArrayUtils.getLength(onTokens) ? onTokens[idx] : objectName;
        }
        break;
    case DEFAULT:
    default:
        idx = StringUtils.indexOfAny(objectName, OBJ_NAME_TOKEN_DELIMITERS);
        if (idx > 0) {
            objectName = StringUtils.substring(objectName, 0, idx);
        }
        break;
    }

    return objectName;
}

From source file:com.adeptj.modules.jaxrs.core.jwt.feature.JwtDynamicFeature.java

/**
 * Registers the {@link com.adeptj.modules.jaxrs.core.jwt.filter.internal.DynamicJwtFilter} for interception
 * in case of a match of configured resource class and methods.
 * <p>/*from  w w w.j  a v a2 s . c  o m*/
 * See documentation on {@link JwtDynamicFeature#filterMapping} to know how the algo will work.
 *
 * @param resourceInfo containing the resource class and method
 * @param context      to register the DynamicJwtFilter for interception in case of a match
 */
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    String resource = resourceInfo.getResourceClass().getName();
    String method = resourceInfo.getResourceMethod().getName();
    Stream.of(this.filterMapping).filter(row -> ArrayUtils.getLength(row.split(EQ)) == 2)
            .map(row -> row.split(EQ))
            .filter(mapping -> resource.equals(mapping[0]) && containsAny(mapping[1], method, ASTERISK))
            .forEach(mapping -> {
                context.register(this.dynamicJwtFilter, AUTHENTICATION);
                LOGGER.info(FILTER_REG_MSG, resource, method);
            });
}