feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,147 @@
/*
* Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* The Original Code is HAT. The Initial Developer of the
* Original Code is Bill Foote, with contributions from others
* at JavaSoft/Sun.
*/
package com.sun.tools.hat.internal.util;
import java.util.*;
/**
* A singleton utility class that sorts an array of objects.
* <p>
* Use:
* <pre>
*
* Stuff[] arr = ...;
* ArraySorter.sort(arr, new Comparer() {
* public int compare(Object lhs, Object rhs) {
* return ((String) lhs).compareTo((String) rhs);
* }
* });
* </pre>
*
* @author Bill Foote
*/
public class ArraySorter {
/**
* Sort the given array, using c for comparison
**/
static public void sort(Object[] arr, Comparer c) {
quickSort(arr, c, 0, arr.length-1);
}
/**
* Sort an array of strings, using String.compareTo()
**/
static public void sortArrayOfStrings(Object[] arr) {
sort(arr, new Comparer() {
public int compare(Object lhs, Object rhs) {
return ((String) lhs).compareTo((String) rhs);
}
});
}
static private void swap(Object[] arr, int a, int b) {
Object tmp = arr[a];
arr[a] = arr[b];
arr[b] = tmp;
}
//
// Sorts arr between from and to, inclusive. This is a quick, off-the-top-
// of-my-head quicksort: I haven't put any thought into optimizing it.
// I _did_ put thought into making sure it's safe (it will always
// terminate). Worst-case it's O(n^2), but it will usually run in
// in O(n log n). It's well-behaved if the list is already sorted,
// or nearly so.
//
static private void quickSort(Object[] arr, Comparer c, int from, int to) {
if (to <= from)
return;
int mid = (from + to) / 2;
if (mid != from)
swap(arr, mid, from);
Object pivot = arr[from]; // Simple-minded, but reasonable
int highestBelowPivot = from - 1;
int low = from+1;
int high = to;
// We now move low and high toward each other, maintaining the
// invariants:
// arr[i] <= pivot for all i < low
// arr[i] > pivot for all i > high
// As long as these invariants hold, and every iteration makes
// progress, we are safe.
while (low <= high) {
int cmp = c.compare(arr[low], pivot);
if (cmp <= 0) { // arr[low] <= pivot
if (cmp < 0) {
highestBelowPivot = low;
}
low++;
} else {
int c2;
for (;;) {
// arr[high] > pivot:
c2 = c.compare(arr[high], pivot);
if (c2 > 0) {
high--;
if (low > high) {
break;
}
} else {
break;
}
}
// At this point, low is never == high, BTW
if (low <= high) {
swap(arr, low, high);
if (c2 < 0) {
highestBelowPivot = low;
}
low++;
high--;
}
}
}
// At this point, low == high+1
// Now we just need to sort from from..highestBelowPivot
// and from high+1..to
if (highestBelowPivot > from) {
// pivot == pivot, so ensure algorithm terminates
swap(arr, from, highestBelowPivot);
quickSort(arr, c, from, highestBelowPivot-1);
}
quickSort(arr, c, high+1, to);
}
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* The Original Code is HAT. The Initial Developer of the
* Original Code is Bill Foote, with contributions from others
* at JavaSoft/Sun.
*/
package com.sun.tools.hat.internal.util;
/**
* Base class for comparison of two objects.
* @see VectorSorter
*
* @author Bill Foote
*/
abstract public class Comparer {
/**
* @return a number <, == or > 0 depending on lhs compared to rhs
* @see java.lang.String.compareTo
**/
abstract public int compare(Object lhs, Object rhs);
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* The Original Code is HAT. The Initial Developer of the
* Original Code is Bill Foote, with contributions from others
* at JavaSoft/Sun.
*/
package com.sun.tools.hat.internal.util;
import java.util.Enumeration;
import java.util.NoSuchElementException;
public class CompositeEnumeration implements Enumeration {
Enumeration e1;
Enumeration e2;
public CompositeEnumeration(Enumeration e1, Enumeration e2) {
this.e1 = e1;
this.e2 = e2;
}
public boolean hasMoreElements() {
return e1.hasMoreElements() || e2.hasMoreElements();
}
public Object nextElement() {
if (e1.hasMoreElements()) {
return e1.nextElement();
}
if (e2.hasMoreElements()) {
return e2.nextElement();
}
throw new NoSuchElementException();
}
}

View File

@@ -0,0 +1,112 @@
/*
* Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* The Original Code is HAT. The Initial Developer of the
* Original Code is Bill Foote, with contributions from others
* at JavaSoft/Sun.
*/
package com.sun.tools.hat.internal.util;
import java.util.*;
/**
* Miscellaneous functions I couldn't think of a good place to put.
*
* @author Bill Foote
*/
public class Misc {
private static char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
public final static String toHex(int addr) {
char[] buf = new char[8];
int i = 0;
for (int s = 28; s >= 0; s -= 4) {
buf[i++] = digits[(addr >> s) & 0xf];
}
return "0x" + new String(buf);
}
public final static String toHex(long addr) {
return "0x" + Long.toHexString(addr);
}
public final static long parseHex(String value) {
long result = 0;
if (value.length() < 2 || value.charAt(0) != '0' ||
value.charAt(1) != 'x') {
return -1L;
}
for(int i = 2; i < value.length(); i++) {
result *= 16;
char ch = value.charAt(i);
if (ch >= '0' && ch <= '9') {
result += (ch - '0');
} else if (ch >= 'a' && ch <= 'f') {
result += (ch - 'a') + 10;
} else if (ch >= 'A' && ch <= 'F') {
result += (ch - 'A') + 10;
} else {
throw new NumberFormatException("" + ch
+ " is not a valid hex digit");
}
}
return result;
}
public static String encodeHtml(String str) {
final int len = str.length();
StringBuffer buf = new StringBuffer();
for (int i = 0; i < len; i++) {
char ch = str.charAt(i);
if (ch == '<') {
buf.append("&lt;");
} else if (ch == '>') {
buf.append("&gt;");
} else if (ch == '"') {
buf.append("&quot;");
} else if (ch == '\'') {
buf.append("&#039;");
} else if (ch == '&') {
buf.append("&amp;");
} else if (ch < ' ') {
buf.append("&#" + Integer.toString(ch) + ";");
} else {
int c = (ch & 0xFFFF);
if (c > 127) {
buf.append("&#" + Integer.toString(c) + ";");
} else {
buf.append(ch);
}
}
}
return buf.toString();
}
}

View File

@@ -0,0 +1,148 @@
/*
* Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* The Original Code is HAT. The Initial Developer of the
* Original Code is Bill Foote, with contributions from others
* at JavaSoft/Sun.
*/
package com.sun.tools.hat.internal.util;
import java.util.*;
/**
* A singleton utility class that sorts a vector.
* <p>
* Use:
* <pre>
*
* Vector v = <a vector of, say, String objects>;
* VectorSorter.sort(v, new Comparer() {
* public int compare(Object lhs, Object rhs) {
* return ((String) lhs).compareTo((String) rhs);
* }
* });
* </pre>
*
* @author Bill Foote
*/
public class VectorSorter {
/**
* Sort the given vector, using c for comparison
**/
static public void sort(Vector<Object> v, Comparer c) {
quickSort(v, c, 0, v.size()-1);
}
/**
* Sort a vector of strings, using String.compareTo()
**/
static public void sortVectorOfStrings(Vector<Object> v) {
sort(v, new Comparer() {
public int compare(Object lhs, Object rhs) {
return ((String) lhs).compareTo((String) rhs);
}
});
}
static private void swap(Vector<Object> v, int a, int b) {
Object tmp = v.elementAt(a);
v.setElementAt(v.elementAt(b), a);
v.setElementAt(tmp, b);
}
//
// Sorts v between from and to, inclusive. This is a quick, off-the-top-
// of-my-head quicksort: I haven't put any thought into optimizing it.
// I _did_ put thought into making sure it's safe (it will always
// terminate). Worst-case it's O(n^2), but it will usually run in
// in O(n log n). It's well-behaved if the list is already sorted,
// or nearly so.
//
static private void quickSort(Vector<Object> v, Comparer c, int from, int to) {
if (to <= from)
return;
int mid = (from + to) / 2;
if (mid != from)
swap(v, mid, from);
Object pivot = v.elementAt(from);
// Simple-minded, but reasonable
int highestBelowPivot = from - 1;
int low = from+1;
int high = to;
// We now move low and high toward eachother, maintaining the
// invariants:
// v[i] <= pivot for all i < low
// v[i] > pivot for all i > high
// As long as these invariants hold, and every iteration makes
// progress, we are safe.
while (low <= high) {
int cmp = c.compare(v.elementAt(low), pivot);
if (cmp <= 0) { // v[low] <= pivot
if (cmp < 0) {
highestBelowPivot = low;
}
low++;
} else {
int c2;
for (;;) {
c2 = c.compare(v.elementAt(high), pivot);
// v[high] > pivot:
if (c2 > 0) {
high--;
if (low > high) {
break;
}
} else {
break;
}
}
// At this point, low is never == high
if (low <= high) {
swap(v, low, high);
if (c2 < 0) {
highestBelowPivot = low;
}
low++;
high--;
}
}
}
// Now we just need to sort from from..highestBelowPivot
// and from high+1..to
if (highestBelowPivot > from) {
// pivot == pivot, so ensure algorithm terminates
swap(v, from, highestBelowPivot);
quickSort(v, c, from, highestBelowPivot-1);
}
quickSort(v, c, high+1, to);
}
}