@Test public void testNormalizeArraysMethods() { String[] s1 = new String[] { "one" }; String[] s2 = new String[] { "one", "two" }; String[] s3 = new String[] { "one", "two", "three" }; long[] l1 = new long[] { 1 }; long[] l2 = new long[] { 1, 2 }; long[] l3 = new long[] { 1, 2, 3 }; short[] sh1 = new short[] { 1 }; short[] sh2 = new short[] { 1, 2 }; short[] sh3 = new short[] { 1, 2, 3 }; boolean[] b1 = new boolean[] { true }; boolean[] b2 = new boolean[] { true, false }; boolean[] b3 = new boolean[] { true, false, true }; int[] i1 = new int[] { 1 }; int[] i2 = new int[] { 1, 2 }; int[] i3 = new int[] { 1, 3 }; String[][] newS = Utils.normalizeArrays( 3, s1, s2 ); assertEquals( 2, newS.length ); assertEquals( 3, newS[ 0 ].length ); assertEquals( 3, newS[ 1 ].length ); newS = Utils.normalizeArrays( 3, s1, null ); assertEquals( 2, newS.length ); assertEquals( 3, newS[ 0 ].length ); assertEquals( 3, newS[ 1 ].length ); newS = Utils.normalizeArrays( 2, s2 ); assertEquals( 1, newS.length ); assertEquals( 2, newS[ 0 ].length ); assertArrayEquals( newS[ 0 ], s2 ); assertTrue( newS[ 0 ] == s2 ); long[][] newL = Utils.normalizeArrays( 3, l1, l2 ); assertEquals( 2, newL.length ); assertEquals( 3, newL[ 0 ].length ); assertEquals( 3, newL[ 1 ].length ); newL = Utils.normalizeArrays( 3, l1, null ); assertEquals( 2, newL.length ); assertEquals( 3, newL[ 0 ].length ); assertEquals( 3, newL[ 1 ].length ); newL = Utils.normalizeArrays( 2, l2 ); assertEquals( 1, newL.length ); assertEquals( 2, newL[ 0 ].length ); assertArrayEquals( newL[ 0 ], l2 ); assertTrue( newL[ 0 ] == l2 ); short[][] newSh = Utils.normalizeArrays( 3, sh1, sh2 ); assertEquals( 2, newSh.length ); assertEquals( 3, newSh[ 0 ].length ); assertEquals( 3, newSh[ 1 ].length ); newSh = Utils.normalizeArrays( 3, sh1, null ); assertEquals( 2, newSh.length ); assertEquals( 3, newSh[ 0 ].length ); assertEquals( 3, newSh[ 1 ].length ); newSh = Utils.normalizeArrays( 2, sh2 ); assertEquals( 1, newSh.length ); assertEquals( 2, newSh[ 0 ].length ); assertArrayEquals( newSh[ 0 ], sh2 ); assertTrue( newSh[ 0 ] == sh2 ); boolean[][] newB = Utils.normalizeArrays( 3, b1, b2 ); assertEquals( 2, newB.length ); assertEquals( 3, newB[ 0 ].length ); assertEquals( 3, newB[ 1 ].length ); newB = Utils.normalizeArrays( 3, b1, null ); assertEquals( 2, newB.length ); assertEquals( 3, newB[ 0 ].length ); assertEquals( 3, newB[ 1 ].length ); newB = Utils.normalizeArrays( 2, b2 ); assertEquals( 1, newB.length ); assertEquals( 2, newB[ 0 ].length ); assertTrue( newB[ 0 ] == b2 ); int[][] newI = Utils.normalizeArrays( 3, i1, i2 ); assertEquals( 2, newI.length ); assertEquals( 3, newI[ 0 ].length ); assertEquals( 3, newI[ 1 ].length ); newI = Utils.normalizeArrays( 3, i1, null ); assertEquals( 2, newI.length ); assertEquals( 3, newI[ 0 ].length ); assertEquals( 3, newI[ 1 ].length ); newI = Utils.normalizeArrays( 2, i2 ); assertEquals( 1, newI.length ); assertEquals( 2, newI[ 0 ].length ); assertArrayEquals( newI[ 0 ], i2 ); assertTrue( newI[ 0 ] == i2 ); }
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; }
Utils { 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; } }
Utils { 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; }  }
Utils { 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; }  static int getDamerauLevenshteinDistance( String s, String t ); static boolean isEmpty( CharSequence val ); static boolean isEmpty( CharSequence[] strings ); static boolean isEmpty( Object[] array ); static boolean isEmpty( List<?> list ); static String resolvePassword( VariableSpace variables, String password ); static String[][] normalizeArrays( int normalizeToLength, String[]... arraysToNormalize ); static long[][] normalizeArrays( int normalizeToLength, long[]... arraysToNormalize ); static int[][] normalizeArrays( int normalizeToLength, int[]... arraysToNormalize ); static boolean[][] normalizeArrays( int normalizeToLength, boolean[]... arraysToNormalize ); static short[][] normalizeArrays( int normalizeToLength, short[]... arraysToNormalize ); }
Utils { 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; }  static int getDamerauLevenshteinDistance( String s, String t ); static boolean isEmpty( CharSequence val ); static boolean isEmpty( CharSequence[] strings ); static boolean isEmpty( Object[] array ); static boolean isEmpty( List<?> list ); static String resolvePassword( VariableSpace variables, String password ); static String[][] normalizeArrays( int normalizeToLength, String[]... arraysToNormalize ); static long[][] normalizeArrays( int normalizeToLength, long[]... arraysToNormalize ); static int[][] normalizeArrays( int normalizeToLength, int[]... arraysToNormalize ); static boolean[][] normalizeArrays( int normalizeToLength, boolean[]... arraysToNormalize ); static short[][] normalizeArrays( int normalizeToLength, short[]... arraysToNormalize );  }