summaryrefslogtreecommitdiff
path: root/src/proguard/util
diff options
context:
space:
mode:
authorYing Wang <wangying@google.com>2013-09-20 16:17:43 -0700
committerYing Wang <wangying@google.com>2013-09-20 16:32:42 -0700
commitb9cc48a43ed984587c939d02fba5316bf5c0df6e (patch)
tree7d42e31a97264803b1147ef6001e8a5e6968a122 /src/proguard/util
parent54f59ac04f3e21d5aecdd46bb1e7f4577924ab92 (diff)
downloadproguard-b9cc48a43ed984587c939d02fba5316bf5c0df6e.tar.gz
Upgrade Proguard to 4.10.
Downloaded from: http://sourceforge.net/projects/proguard/files/proguard/4.10/ Bug: 8992787 Change-Id: Ia07cc5b3feed443982b7e8f2a1f361479e735b18
Diffstat (limited to 'src/proguard/util')
-rw-r--r--src/proguard/util/AndMatcher.java2
-rw-r--r--src/proguard/util/ArrayUtil.java960
-rw-r--r--src/proguard/util/ClassNameParser.java2
-rw-r--r--src/proguard/util/ConstantMatcher.java2
-rw-r--r--src/proguard/util/EmptyStringMatcher.java2
-rw-r--r--src/proguard/util/ExtensionMatcher.java2
-rw-r--r--src/proguard/util/FileNameParser.java2
-rw-r--r--src/proguard/util/FixedStringMatcher.java2
-rw-r--r--src/proguard/util/ListMatcher.java2
-rw-r--r--src/proguard/util/ListParser.java4
-rw-r--r--src/proguard/util/ListUtil.java15
-rw-r--r--src/proguard/util/NameParser.java2
-rw-r--r--src/proguard/util/NotMatcher.java2
-rw-r--r--src/proguard/util/ObjectUtil.java67
-rw-r--r--src/proguard/util/OrMatcher.java2
-rw-r--r--src/proguard/util/SettableMatcher.java2
-rw-r--r--src/proguard/util/StringMatcher.java2
-rw-r--r--src/proguard/util/StringParser.java2
-rw-r--r--src/proguard/util/VariableStringMatcher.java2
19 files changed, 1055 insertions, 21 deletions
diff --git a/src/proguard/util/AndMatcher.java b/src/proguard/util/AndMatcher.java
index 94a37e5..1aa3726 100644
--- a/src/proguard/util/AndMatcher.java
+++ b/src/proguard/util/AndMatcher.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
diff --git a/src/proguard/util/ArrayUtil.java b/src/proguard/util/ArrayUtil.java
new file mode 100644
index 0000000..8584700
--- /dev/null
+++ b/src/proguard/util/ArrayUtil.java
@@ -0,0 +1,960 @@
+/*
+ * ProGuard -- shrinking, optimization, obfuscation, and preverification
+ * of Java bytecode.
+ *
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package proguard.util;
+
+import java.lang.reflect.Array;
+import java.util.Arrays;
+
+/**
+ * This class contains utility methods operating on arrays.
+ */
+public class ArrayUtil
+{
+ /**
+ * Returns whether the elements of the two given arrays are the same.
+ * @param array1 the first array.
+ * @param array2 the second array.
+ * @param size the size of the arrays to be checked.
+ * @return whether the elements are the same.
+ */
+ public static boolean equal(byte[] array1, byte[] array2, int size)
+ {
+ for (int index = 0; index < size; index++)
+ {
+ if (array1[index] != array2[index])
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ /**
+ * Returns whether the elements of the two given arrays are the same.
+ * @param array1 the first array.
+ * @param array2 the second array.
+ * @param size the size of the arrays to be checked.
+ * @return whether the elements are the same.
+ */
+ public static boolean equal(short[] array1, short[] array2, int size)
+ {
+ for (int index = 0; index < size; index++)
+ {
+ if (array1[index] != array2[index])
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ /**
+ * Returns whether the elements of the two given arrays are the same.
+ * @param array1 the first array.
+ * @param array2 the second array.
+ * @param size the size of the arrays to be checked.
+ * @return whether the elements are the same.
+ */
+ public static boolean equal(int[] array1, int[] array2, int size)
+ {
+ for (int index = 0; index < size; index++)
+ {
+ if (array1[index] != array2[index])
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ /**
+ * Returns whether the elements of the two given arrays are the same.
+ * @param array1 the first array.
+ * @param array2 the second array.
+ * @param size the size of the arrays to be checked.
+ * @return whether the elements are the same.
+ */
+ public static boolean equal(Object[] array1, Object[] array2, int size)
+ {
+ for (int index = 0; index < size; index++)
+ {
+ if (!array1[index].equals(array2[index]))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ /**
+ * Returns a hash code for the elements of the given array.
+ * @param array the array.
+ * @param size the size of the array to be taken into account.
+ * @return a hash code.
+ */
+ public static int hashCode(byte[] array, int size)
+ {
+ int hashCode = 0;
+
+ for (int index = 0; index < size; index++)
+ {
+ hashCode ^= array[index];
+ }
+
+ return hashCode;
+ }
+
+
+ /**
+ * Returns a hash code for the elements of the given array.
+ * @param array the array.
+ * @param size the size of the array to be taken into account.
+ * @return a hash code.
+ */
+ public static int hashCode(short[] array, int size)
+ {
+ int hashCode = 0;
+
+ for (int index = 0; index < size; index++)
+ {
+ hashCode ^= array[index];
+ }
+
+ return hashCode;
+ }
+
+
+ /**
+ * Returns a hash code for the elements of the given array.
+ * @param array the array.
+ * @param size the size of the array to be taken into account.
+ * @return a hash code.
+ */
+ public static int hashCode(int[] array, int size)
+ {
+ int hashCode = 0;
+
+ for (int index = 0; index < size; index++)
+ {
+ hashCode ^= array[index];
+ }
+
+ return hashCode;
+ }
+
+
+ /**
+ * Returns a hash code for the elements of the given array.
+ * @param array the array.
+ * @param size the size of the array to be taken into account.
+ * @return a hash code.
+ */
+ public static int hashCode(Object[] array, int size)
+ {
+ int hashCode = 0;
+
+ for (int index = 0; index < size; index++)
+ {
+ hashCode ^= array[index].hashCode();
+ }
+
+ return hashCode;
+ }
+
+
+ /**
+ * Compares the elements of the two given arrays.
+ * @param array1 the first array.
+ * @param size1 the size of the first array.
+ * @param array2 the second array.
+ * @param size2 the size of the second array.
+ * @return 0 if all elements are the same,
+ * -1 if the first different element in the first array is smaller
+ * than the corresponding element in the second array,
+ * or 1 if it is larger.
+ */
+ public static int compare(byte[] array1, int size1,
+ byte[] array2, int size2)
+ {
+ int minSize = Math.min(size1, size2);
+
+ for (int index = 0; index < minSize; index++)
+ {
+ if (array1[index] < array2[index])
+ {
+ return -1;
+ }
+ else if (array1[index] > array2[index])
+ {
+ return 1;
+ }
+ }
+
+ return size1 < size2 ? -1 :
+ size1 == size2 ? 0 :
+ 1;
+ }
+
+
+ /**
+ * Compares the elements of the two given arrays.
+ * @param array1 the first array.
+ * @param size1 the size of the first array.
+ * @param array2 the second array.
+ * @param size2 the size of the second array.
+ * @return 0 if all elements are the same,
+ * -1 if the first different element in the first array is smaller
+ * than the corresponding element in the second array,
+ * or 1 if it is larger.
+ */
+ public static int compare(short[] array1, int size1,
+ short[] array2, int size2)
+ {
+ int minSize = Math.min(size1, size2);
+
+ for (int index = 0; index < minSize; index++)
+ {
+ if (array1[index] < array2[index])
+ {
+ return -1;
+ }
+ else if (array1[index] > array2[index])
+ {
+ return 1;
+ }
+ }
+
+ return size1 < size2 ? -1 :
+ size1 == size2 ? 0 :
+ 1;
+ }
+
+
+ /**
+ * Compares the elements of the two given arrays.
+ * @param array1 the first array.
+ * @param size1 the size of the first array.
+ * @param array2 the second array.
+ * @param size2 the size of the second array.
+ * @return 0 if all elements are the same,
+ * -1 if the first different element in the first array is smaller
+ * than the corresponding element in the second array,
+ * or 1 if it is larger.
+ */
+ public static int compare(int[] array1, int size1,
+ int[] array2, int size2)
+ {
+ int minSize = Math.min(size1, size2);
+
+ for (int index = 0; index < minSize; index++)
+ {
+ if (array1[index] < array2[index])
+ {
+ return -1;
+ }
+ else if (array1[index] > array2[index])
+ {
+ return 1;
+ }
+ }
+
+ return size1 < size2 ? -1 :
+ size1 == size2 ? 0 :
+ 1;
+ }
+
+
+ /**
+ * Compares the elements of the two given arrays.
+ * @param array1 the first array.
+ * @param size1 the size of the first array.
+ * @param array2 the second array.
+ * @param size2 the size of the second array.
+ * @return 0 if all elements are the same,
+ * -1 if the first different element in the first array is smaller
+ * than the corresponding element in the second array,
+ * or 1 if it is larger.
+ */
+ public static int compare(Comparable[] array1, int size1,
+ Comparable[] array2, int size2)
+ {
+ int minSize = Math.min(size1, size2);
+
+ for (int index = 0; index < minSize; index++)
+ {
+ int comparison = ObjectUtil.compare(array1[index], array2[index]);
+ if (comparison != 0)
+ {
+ return comparison;
+ }
+ }
+
+ return size1 < size2 ? -1 :
+ size1 == size2 ? 0 :
+ 1;
+ }
+
+
+ /**
+ * Ensures the given array has a given size.
+ * @param array the array.
+ * @param size the target size of the array.
+ * @return the original array, or a copy if it had to be extended.
+ */
+ public static boolean[] extendArray(boolean[] array, int size)
+ {
+ // Reuse the existing array if possible.
+ if (array.length >= size)
+ {
+ return array;
+ }
+
+ // Otherwise create and initialize a new array.
+ boolean[] newArray = new boolean[size];
+
+ System.arraycopy(array, 0,
+ newArray, 0,
+ array.length);
+
+ return newArray;
+ }
+
+
+ /**
+ * Ensures the given array has a given size.
+ * @param array the array.
+ * @param size the target size of the array.
+ * @param initialValue the initial value of the elements.
+ * @return the original array, or a copy if it had to be
+ * extended.
+ */
+ public static boolean[] ensureArraySize(boolean[] array,
+ int size,
+ boolean initialValue)
+ {
+ // Is the existing array large enough?
+ if (array.length >= size)
+ {
+ // Reinitialize the existing array.
+ Arrays.fill(array, 0, size, initialValue);
+ }
+ else
+ {
+ // Otherwise create and initialize a new array.
+ array = new boolean[size];
+
+ if (initialValue)
+ {
+ Arrays.fill(array, 0, size, initialValue);
+ }
+ }
+
+ return array;
+ }
+
+
+ /**
+ * Adds the given element to the given array.
+ * The array is extended if necessary.
+ * @param array the array.
+ * @param size the original size of the array.
+ * @param element the element to be added.
+ * @return the original array, or a copy if it had to be extended.
+ */
+ public static byte[] add(byte[] array, int size, byte element)
+ {
+ array = extendArray(array, size + 1);
+
+ array[size] = element;
+
+ return array;
+ }
+
+
+ /**
+ * Inserts the given element in the given array.
+ * The array is extended if necessary.
+ * @param array the array.
+ * @param size the original size of the array.
+ * @param index the index at which the element is to be added.
+ * @param element the element to be added.
+ * @return the original array, or a copy if it had to be extended.
+ */
+ public static byte[] insert(byte[] array, int size, int index, byte element)
+ {
+ array = extendArray(array, size + 1);
+
+ // Move the last part.
+ System.arraycopy(array, index,
+ array, index + 1,
+ size - index);
+
+ array[index] = element;
+
+ return array;
+ }
+
+
+ /**
+ * Removes the specified element from the given array.
+ * @param array the array.
+ * @param size the original size of the array.
+ * @param index the index of the element to be removed.
+ */
+ public static void remove(byte[] array, int size, int index)
+ {
+ System.arraycopy(array, index + 1,
+ array, index,
+ array.length - index - 1);
+
+ array[size - 1] = 0;
+ }
+
+
+ /**
+ * Ensures the given array has a given size.
+ * @param array the array.
+ * @param size the target size of the array.
+ * @return the original array, or a copy if it had to be extended.
+ */
+ public static byte[] extendArray(byte[] array, int size)
+ {
+ // Reuse the existing array if possible.
+ if (array.length >= size)
+ {
+ return array;
+ }
+
+ // Otherwise create and initialize a new array.
+ byte[] newArray = new byte[size];
+
+ System.arraycopy(array, 0,
+ newArray, 0,
+ array.length);
+
+ return newArray;
+ }
+
+
+ /**
+ * Ensures the given array has a given size.
+ * @param array the array.
+ * @param size the target size of the array.
+ * @param initialValue the initial value of the elements.
+ * @return the original array, or a copy if it had to be
+ * extended.
+ */
+ public static byte[] ensureArraySize(byte[] array,
+ int size,
+ byte initialValue)
+ {
+ // Is the existing array large enough?
+ if (array.length >= size)
+ {
+ // Reinitialize the existing array.
+ Arrays.fill(array, 0, size, initialValue);
+ }
+ else
+ {
+ // Otherwise create and initialize a new array.
+ array = new byte[size];
+
+ if (initialValue != 0)
+ {
+ Arrays.fill(array, 0, size, initialValue);
+ }
+ }
+
+ return array;
+ }
+
+
+ /**
+ * Adds the given element to the given array.
+ * The array is extended if necessary.
+ * @param array the array.
+ * @param size the original size of the array.
+ * @param element the element to be added.
+ * @return the original array, or a copy if it had to be extended.
+ */
+ public static short[] add(short[] array, int size, short element)
+ {
+ array = extendArray(array, size + 1);
+
+ array[size] = element;
+
+ return array;
+ }
+
+
+ /**
+ * Inserts the given element in the given array.
+ * The array is extended if necessary.
+ * @param array the array.
+ * @param size the original size of the array.
+ * @param index the index at which the element is to be added.
+ * @param element the element to be added.
+ * @return the original array, or a copy if it had to be extended.
+ */
+ public static short[] insert(short[] array, int size, int index, short element)
+ {
+ array = extendArray(array, size + 1);
+
+ // Move the last part.
+ System.arraycopy(array, index,
+ array, index + 1,
+ size - index);
+
+ array[index] = element;
+
+ return array;
+ }
+
+
+ /**
+ * Removes the specified element from the given array.
+ * @param array the array.
+ * @param size the original size of the array.
+ * @param index the index of the element to be removed.
+ */
+ public static void remove(short[] array, int size, int index)
+ {
+ System.arraycopy(array, index + 1,
+ array, index,
+ array.length - index - 1);
+
+ array[size - 1] = 0;
+ }
+
+
+ /**
+ * Ensures the given array has a given size.
+ * @param array the array.
+ * @param size the target size of the array.
+ * @return the original array, or a copy if it had to be extended.
+ */
+ public static short[] extendArray(short[] array, int size)
+ {
+ // Reuse the existing array if possible.
+ if (array.length >= size)
+ {
+ return array;
+ }
+
+ // Otherwise create and initialize a new array.
+ short[] newArray = new short[size];
+
+ System.arraycopy(array, 0,
+ newArray, 0,
+ array.length);
+
+ return newArray;
+ }
+
+
+ /**
+ * Ensures the given array has a given size.
+ * @param array the array.
+ * @param size the target size of the array.
+ * @param initialValue the initial value of the elements.
+ * @return the original array, or a copy if it had to be
+ * extended.
+ */
+ public static short[] ensureArraySize(short[] array,
+ int size,
+ short initialValue)
+ {
+ // Is the existing array large enough?
+ if (array.length >= size)
+ {
+ // Reinitialize the existing array.
+ Arrays.fill(array, 0, size, initialValue);
+ }
+ else
+ {
+ // Otherwise create and initialize a new array.
+ array = new short[size];
+
+ if (initialValue != 0)
+ {
+ Arrays.fill(array, 0, size, initialValue);
+ }
+ }
+
+ return array;
+ }
+
+
+ /**
+ * Adds the given element to the given array.
+ * The array is extended if necessary.
+ * @param array the array.
+ * @param size the original size of the array.
+ * @param element the element to be added.
+ * @return the original array, or a copy if it had to be extended.
+ */
+ public static int[] add(int[] array, int size, int element)
+ {
+ array = extendArray(array, size + 1);
+
+ array[size] = element;
+
+ return array;
+ }
+
+
+ /**
+ * Inserts the given element in the given array.
+ * The array is extended if necessary.
+ * @param array the array.
+ * @param size the original size of the array.
+ * @param index the index at which the element is to be added.
+ * @param element the element to be added.
+ * @return the original array, or a copy if it had to be extended.
+ */
+ public static int[] insert(int[] array, int size, int index, int element)
+ {
+ array = extendArray(array, size + 1);
+
+ // Move the last part.
+ System.arraycopy(array, index,
+ array, index + 1,
+ size - index);
+
+ array[index] = element;
+
+ return array;
+ }
+
+
+ /**
+ * Removes the specified element from the given array.
+ * @param array the array.
+ * @param size the original size of the array.
+ * @param index the index of the element to be removed.
+ */
+ public static void remove(int[] array, int size, int index)
+ {
+ System.arraycopy(array, index + 1,
+ array, index,
+ array.length - index - 1);
+
+ array[size - 1] = 0;
+ }
+
+
+ /**
+ * Ensures the given array has a given size.
+ * @param array the array.
+ * @param size the target size of the array.
+ * @return the original array, or a copy if it had to be extended.
+ */
+ public static int[] extendArray(int[] array, int size)
+ {
+ // Reuse the existing array if possible.
+ if (array.length >= size)
+ {
+ return array;
+ }
+
+ // Otherwise create and initialize a new array.
+ int[] newArray = new int[size];
+
+ System.arraycopy(array, 0,
+ newArray, 0,
+ array.length);
+
+ return newArray;
+ }
+
+
+ /**
+ * Ensures the given array has a given size.
+ * @param array the array.
+ * @param size the target size of the array.
+ * @param initialValue the initial value of the elements.
+ * @return the original array, or a copy if it had to be
+ * extended.
+ */
+ public static int[] ensureArraySize(int[] array,
+ int size,
+ int initialValue)
+ {
+ // Is the existing array large enough?
+ if (array.length >= size)
+ {
+ // Reinitialize the existing array.
+ Arrays.fill(array, 0, size, initialValue);
+ }
+ else
+ {
+ // Otherwise create and initialize a new array.
+ array = new int[size];
+
+ if (initialValue != 0)
+ {
+ Arrays.fill(array, 0, size, initialValue);
+ }
+ }
+
+ return array;
+ }
+
+
+ /**
+ * Adds the given element to the given array.
+ * The array is extended if necessary.
+ * @param array the array.
+ * @param size the original size of the array.
+ * @param element the element to be added.
+ * @return the original array, or a copy if it had to be extended.
+ */
+ public static long[] add(long[] array, int size, long element)
+ {
+ array = extendArray(array, size + 1);
+
+ array[size] = element;
+
+ return array;
+ }
+
+
+ /**
+ * Inserts the given element in the given array.
+ * The array is extended if necessary.
+ * @param array the array.
+ * @param size the original size of the array.
+ * @param index the index at which the element is to be added.
+ * @param element the element to be added.
+ * @return the original array, or a copy if it had to be extended.
+ */
+ public static long[] insert(long[] array, int size, int index, long element)
+ {
+ array = extendArray(array, size + 1);
+
+ // Move the last part.
+ System.arraycopy(array, index,
+ array, index + 1,
+ size - index);
+
+ array[index] = element;
+
+ return array;
+ }
+
+
+ /**
+ * Removes the specified element from the given array.
+ * @param array the array.
+ * @param size the original size of the array.
+ * @param index the index of the element to be removed.
+ */
+ public static void remove(long[] array, int size, int index)
+ {
+ System.arraycopy(array, index + 1,
+ array, index,
+ array.length - index - 1);
+
+ array[size - 1] = 0;
+ }
+
+
+ /**
+ * Ensures the given array has a given size.
+ * @param array the array.
+ * @param size the target size of the array.
+ * @return the original array, or a copy if it had to be extended.
+ */
+ public static long[] extendArray(long[] array, int size)
+ {
+ // Reuse the existing array if possible.
+ if (array.length >= size)
+ {
+ return array;
+ }
+
+ // Otherwise create and initialize a new array.
+ long[] newArray = new long[size];
+
+ System.arraycopy(array, 0,
+ newArray, 0,
+ array.length);
+
+ return newArray;
+ }
+
+
+ /**
+ * Ensures the given array has a given size.
+ * @param array the array.
+ * @param size the target size of the array.
+ * @param initialValue the initial value of the elements.
+ * @return the original array, or a copy if it had to be
+ * extended.
+ */
+ public static long[] ensureArraySize(long[] array,
+ int size,
+ long initialValue)
+ {
+ // Is the existing array large enough?
+ if (array.length >= size)
+ {
+ // Reinitialize the existing array.
+ Arrays.fill(array, 0, size, initialValue);
+ }
+ else
+ {
+ // Otherwise create and initialize a new array.
+ array = new long[size];
+
+ if (initialValue != 0L)
+ {
+ Arrays.fill(array, 0, size, initialValue);
+ }
+ }
+
+ return array;
+ }
+
+
+ /**
+ * Adds the given element to the given array.
+ * The array is extended if necessary.
+ * @param array the array.
+ * @param size the original size of the array.
+ * @param element the element to be added.
+ * @return the original array, or a copy if it had to be extended.
+ */
+ public static Object[] add(Object[] array, int size, Object element)
+ {
+ array = extendArray(array, size + 1);
+
+ array[size] = element;
+
+ return array;
+ }
+
+
+ /**
+ * Inserts the given element in the given array.
+ * The array is extended if necessary.
+ * @param array the array.
+ * @param size the original size of the array.
+ * @param index the index at which the element is to be added.
+ * @param element the element to be added.
+ * @return the original array, or a copy if it had to be extended.
+ */
+ public static Object[] insert(Object[] array, int size, int index, Object element)
+ {
+ array = extendArray(array, size + 1);
+
+ // Move the last part.
+ System.arraycopy(array, index,
+ array, index + 1,
+ size - index);
+
+ array[index] = element;
+
+ return array;
+ }
+
+
+ /**
+ * Removes the specified element from the given array.
+ * @param array the array.
+ * @param size the original size of the array.
+ * @param index the index of the element to be removed.
+ */
+ public static void remove(Object[] array, int size, int index)
+ {
+ System.arraycopy(array, index + 1,
+ array, index,
+ array.length - index - 1);
+
+ array[size - 1] = null;
+ }
+
+
+ /**
+ * Ensures the given array has a given size.
+ * @param array the array.
+ * @param size the target size of the array.
+ * @return the original array, or a copy if it had to be extended.
+ */
+ public static Object[] extendArray(Object[] array, int size)
+ {
+ // Reuse the existing array if possible.
+ if (array.length >= size)
+ {
+ return array;
+ }
+
+ // Otherwise create and initialize a new array.
+ Object[] newArray = (Object[])Array.newInstance(array.getClass().getComponentType(), size);
+
+ System.arraycopy(array, 0,
+ newArray, 0,
+ array.length);
+
+ return newArray;
+ }
+
+
+ /**
+ * Ensures the given array has a given size.
+ * @param array the array.
+ * @param size the target size of the array.
+ * @param initialValue the initial value of the elements.
+ * @return the original array, or a copy if it had to be
+ * extended.
+ */
+ public static Object[] ensureArraySize(Object[] array,
+ int size,
+ Object initialValue)
+ {
+ // Is the existing array large enough?
+ if (array.length >= size)
+ {
+ // Reinitialize the existing array.
+ Arrays.fill(array, 0, size, initialValue);
+ }
+ else
+ {
+ // Otherwise create and initialize a new array.
+ array = (Object[])Array.newInstance(array.getClass().getComponentType(), size);
+
+ if (initialValue != null)
+ {
+ Arrays.fill(array, 0, size, initialValue);
+ }
+ }
+
+ return array;
+ }
+}
diff --git a/src/proguard/util/ClassNameParser.java b/src/proguard/util/ClassNameParser.java
index ee972f0..22a0703 100644
--- a/src/proguard/util/ClassNameParser.java
+++ b/src/proguard/util/ClassNameParser.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
diff --git a/src/proguard/util/ConstantMatcher.java b/src/proguard/util/ConstantMatcher.java
index 1764caa..8c0f1e1 100644
--- a/src/proguard/util/ConstantMatcher.java
+++ b/src/proguard/util/ConstantMatcher.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
diff --git a/src/proguard/util/EmptyStringMatcher.java b/src/proguard/util/EmptyStringMatcher.java
index 543f446..f07c666 100644
--- a/src/proguard/util/EmptyStringMatcher.java
+++ b/src/proguard/util/EmptyStringMatcher.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
diff --git a/src/proguard/util/ExtensionMatcher.java b/src/proguard/util/ExtensionMatcher.java
index 5a9f658..eeb627a 100644
--- a/src/proguard/util/ExtensionMatcher.java
+++ b/src/proguard/util/ExtensionMatcher.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
diff --git a/src/proguard/util/FileNameParser.java b/src/proguard/util/FileNameParser.java
index 913f22d..9ec6d22 100644
--- a/src/proguard/util/FileNameParser.java
+++ b/src/proguard/util/FileNameParser.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
diff --git a/src/proguard/util/FixedStringMatcher.java b/src/proguard/util/FixedStringMatcher.java
index c1eb3f4..2f02271 100644
--- a/src/proguard/util/FixedStringMatcher.java
+++ b/src/proguard/util/FixedStringMatcher.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
diff --git a/src/proguard/util/ListMatcher.java b/src/proguard/util/ListMatcher.java
index b2559c8..e07bff0 100644
--- a/src/proguard/util/ListMatcher.java
+++ b/src/proguard/util/ListMatcher.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
diff --git a/src/proguard/util/ListParser.java b/src/proguard/util/ListParser.java
index cec803b..b3b4518 100644
--- a/src/proguard/util/ListParser.java
+++ b/src/proguard/util/ListParser.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
@@ -68,7 +68,7 @@ public class ListParser implements StringParser
// Loop over all simple regular expressions, backward, creating a
// linked list of matchers.
- for (int index = regularExpressions.size()-1; index >=0; index--)
+ for (int index = regularExpressions.size()-1; index >= 0; index--)
{
String regularExpression = (String)regularExpressions.get(index);
diff --git a/src/proguard/util/ListUtil.java b/src/proguard/util/ListUtil.java
index 570dbe8..18bdce2 100644
--- a/src/proguard/util/ListUtil.java
+++ b/src/proguard/util/ListUtil.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
@@ -34,7 +34,7 @@ public class ListUtil
/**
* Creates a comma-separated String from the given List of String objects.
*/
- public static String commaSeparatedString(List list)
+ public static String commaSeparatedString(List list, boolean quoteStrings)
{
if (list == null)
{
@@ -50,7 +50,14 @@ public class ListUtil
buffer.append(',');
}
- buffer.append(quotedString((String)list.get(index)));
+ String string = (String)list.get(index);
+
+ if (quoteStrings)
+ {
+ string = quotedString(string);
+ }
+
+ buffer.append(string);
}
return buffer.toString();
@@ -165,7 +172,7 @@ public class ListUtil
System.out.println("["+list.get(index)+"]");
}
- String string = commaSeparatedString(list);
+ String string = commaSeparatedString(list, true);
System.out.println("Resulting string: ["+string+"]");
}
diff --git a/src/proguard/util/NameParser.java b/src/proguard/util/NameParser.java
index e311fbf..f25d52e 100644
--- a/src/proguard/util/NameParser.java
+++ b/src/proguard/util/NameParser.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
diff --git a/src/proguard/util/NotMatcher.java b/src/proguard/util/NotMatcher.java
index f2a9a51..af539d0 100644
--- a/src/proguard/util/NotMatcher.java
+++ b/src/proguard/util/NotMatcher.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
diff --git a/src/proguard/util/ObjectUtil.java b/src/proguard/util/ObjectUtil.java
new file mode 100644
index 0000000..c5de36a
--- /dev/null
+++ b/src/proguard/util/ObjectUtil.java
@@ -0,0 +1,67 @@
+/*
+ * ProGuard -- shrinking, optimization, obfuscation, and preverification
+ * of Java bytecode.
+ *
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package proguard.util;
+
+/**
+ * This class contains utility methods operating on objects.
+ */
+public class ObjectUtil
+{
+ /**
+ * Returns whether the given objects are the same.
+ * @param object1 the first object, may be null.
+ * @param object2 the second object, may be null.
+ * @return whether the objects are the same.
+ */
+ public static boolean equal(Object object1, Object object2)
+ {
+ return object1 == null ?
+ object2 == null :
+ object1.equals(object2);
+ }
+
+
+ /**
+ * Returns the hash code of the given object, or 0 if it is null.
+ * @param object the object, may be null.
+ * @return the hash code.
+ */
+ public static int hashCode(Object object)
+ {
+ return object == null ? 0 : object.hashCode();
+ }
+
+
+ /**
+ * Returns a comparison of the two given objects.
+ * @param object1 the first object, may be null.
+ * @param object2 the second object, may be null.
+ * @return -1, 0, or 1.
+ * @see Comparable#compareTo(Object)
+ */
+ public static int compare(Comparable object1, Comparable object2)
+ {
+ return object1 == null ?
+ object2 == null ? 0 : -1 :
+ object2 == null ? 1 : object1.compareTo(object2);
+ }
+}
diff --git a/src/proguard/util/OrMatcher.java b/src/proguard/util/OrMatcher.java
index 097c6c6..7ad85c4 100644
--- a/src/proguard/util/OrMatcher.java
+++ b/src/proguard/util/OrMatcher.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
diff --git a/src/proguard/util/SettableMatcher.java b/src/proguard/util/SettableMatcher.java
index 9557f62..8650ccc 100644
--- a/src/proguard/util/SettableMatcher.java
+++ b/src/proguard/util/SettableMatcher.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
diff --git a/src/proguard/util/StringMatcher.java b/src/proguard/util/StringMatcher.java
index bd66dcc..146dbfc 100644
--- a/src/proguard/util/StringMatcher.java
+++ b/src/proguard/util/StringMatcher.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
diff --git a/src/proguard/util/StringParser.java b/src/proguard/util/StringParser.java
index 29f4f16..39d04d5 100644
--- a/src/proguard/util/StringParser.java
+++ b/src/proguard/util/StringParser.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
diff --git a/src/proguard/util/VariableStringMatcher.java b/src/proguard/util/VariableStringMatcher.java
index 1e41323..5a07c2a 100644
--- a/src/proguard/util/VariableStringMatcher.java
+++ b/src/proguard/util/VariableStringMatcher.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free