Java Array Normalize normalizeArrays(int normalizeToLength, String[]... arraysToNormalize)

Here you can find the source of normalizeArrays(int normalizeToLength, String[]... arraysToNormalize)

Description

Normalize String array lengths for synchronization of arrays within steps

License

Apache License

Declaration


public static String[][] normalizeArrays(int normalizeToLength, String[]... arraysToNormalize) 

Method Source Code

//package com.java2s;
/*! ******************************************************************************
 *
 * Pentaho Data Integration/*  w  w w. j a v a2 s . c o  m*/
 *
 * Copyright (C) 2002-2017 by Hitachi Vantara : http://www.pentaho.com
 *
 *******************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************************/

public class Main {
    /**
     * Normalize String array lengths for synchronization of arrays within steps
     */

    public static String[][] normalizeArrays(int normalizeToLength, String[]... arraysToNormalize) {
        if (arraysToNormalize == null) {
            return null;
        }
        int arraysToProcess = arraysToNormalize.length;
        String[][] rtn = new String[arraysToProcess][];
        for (int i = 0; i < arraysToNormalize.length; i++) {
            String[] nextArray = arraysToNormalize[i];
            if (nextArray != null) {
                if (nextArray.length < normalizeToLength) {
                    String[] newArray = new String[normalizeToLength];
                    System.arraycopy(nextArray, 0, newArray, 0, nextArray.length);
                    rtn[i] = newArray;
                } else {
                    rtn[i] = nextArray;
                }
            } else {
                rtn[i] = new String[normalizeToLength];
            }
        }
        return rtn;
    }

    /**
     * Normalize long array lengths for synchronization of arrays within steps
     */

    public static long[][] normalizeArrays(int normalizeToLength, long[]... arraysToNormalize) {
        if (arraysToNormalize == null) {
            return null;
        }
        int arraysToProcess = arraysToNormalize.length;
        long[][] rtn = new long[arraysToProcess][];
        for (int i = 0; i < arraysToNormalize.length; i++) {
            long[] nextArray = arraysToNormalize[i];
            if (nextArray != null) {
                if (nextArray.length < normalizeToLength) {
                    long[] newArray = new long[normalizeToLength];
                    System.arraycopy(nextArray, 0, newArray, 0, nextArray.length);
                    rtn[i] = newArray;
                } else {
                    rtn[i] = nextArray;
                }
            } else {
                rtn[i] = new long[normalizeToLength];
            }
        }
        return rtn;
    }

    /**
     * Normalize int array lengths for synchronization of arrays within steps
     */

    public static int[][] normalizeArrays(int normalizeToLength, int[]... arraysToNormalize) {
        if (arraysToNormalize == null) {
            return null;
        }
        int arraysToProcess = arraysToNormalize.length;
        int[][] rtn = new int[arraysToProcess][];
        for (int i = 0; i < arraysToNormalize.length; i++) {
            int[] nextArray = arraysToNormalize[i];
            if (nextArray != null) {
                if (nextArray.length < normalizeToLength) {
                    int[] newArray = new int[normalizeToLength];
                    System.arraycopy(nextArray, 0, newArray, 0, nextArray.length);
                    rtn[i] = newArray;
                } else {
                    rtn[i] = nextArray;
                }
            } else {
                rtn[i] = new int[normalizeToLength];
            }
        }
        return rtn;
    }

    /**
     * Normalize boolean array lengths for synchronization of arrays within steps
     */

    public static boolean[][] normalizeArrays(int normalizeToLength, boolean[]... arraysToNormalize) {
        if (arraysToNormalize == null) {
            return null;
        }
        int arraysToProcess = arraysToNormalize.length;
        boolean[][] rtn = new boolean[arraysToProcess][];
        for (int i = 0; i < arraysToNormalize.length; i++) {
            boolean[] nextArray = arraysToNormalize[i];
            if (nextArray != null) {
                if (nextArray.length < normalizeToLength) {
                    boolean[] newArray = new boolean[normalizeToLength];
                    System.arraycopy(nextArray, 0, newArray, 0, nextArray.length);
                    rtn[i] = newArray;
                } else {
                    rtn[i] = nextArray;
                }
            } else {
                rtn[i] = new boolean[normalizeToLength];
            }
        }
        return rtn;
    }

    /**
     * Normalize short array lengths for synchronization of arrays within steps
     */

    public static short[][] normalizeArrays(int normalizeToLength, short[]... arraysToNormalize) {
        if (arraysToNormalize == null) {
            return null;
        }
        int arraysToProcess = arraysToNormalize.length;
        short[][] rtn = new short[arraysToProcess][];
        for (int i = 0; i < arraysToNormalize.length; i++) {
            short[] nextArray = arraysToNormalize[i];
            if (nextArray != null) {
                if (nextArray.length < normalizeToLength) {
                    short[] newArray = new short[normalizeToLength];
                    System.arraycopy(nextArray, 0, newArray, 0, nextArray.length);
                    rtn[i] = newArray;
                } else {
                    rtn[i] = nextArray;
                }
            } else {
                rtn[i] = new short[normalizeToLength];
            }
        }
        return rtn;
    }
}

Related

  1. normalize3(float[] result, float[] a)
  2. normalizeAndInvertValues(double[] values, double maxValue, double minValue)
  3. normalizeArray(double[] array)
  4. normalizeArray(double[] hist)
  5. normalizeArray(String[] raw, int expectedSize)
  6. normalizeCharacterData(char[] ch, int start, int length)
  7. normalizeComplexVectorsToUnitVectors(float[] complex)
  8. normalizeComponentsOverwrite(float[][][][] in)
  9. normalizeContingencyTable(final int[][] table)