Merge branch 'master' of git://oss.readytalk.com/avian

This commit is contained in:
Matt Weaver
2008-07-16 11:26:29 -06:00
35 changed files with 1055 additions and 204 deletions

View File

@ -106,4 +106,17 @@ public class Arrays {
}
};
}
public static void fill(int[] array, int value) {
for (int i=0;i<array.length;i++) {
array[i] = value;
}
}
public static void fill(char[] array, char value) {
for (int i=0;i<array.length;i++) {
array[i] = value;
}
}
}

View File

@ -0,0 +1,179 @@
/* Copyright (c) 2008, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.util;
import java.io.Serializable;
/**
* @author zsombor
*
*/
public class BitSet implements Serializable, Cloneable {
final static int BITS_PER_LONG = 64;
final static int BITS_PER_LONG_SHIFT = 6;
final static long MASK = 0xFFFFFFFFFFFFFFFFL;
private long[] bits;
private static int longPosition(int index) {
return index >> BITS_PER_LONG_SHIFT;
}
private static long bitPosition(int index) {
return 1L << (index % BITS_PER_LONG);
}
public BitSet(int bitLength) {
if (bitLength % BITS_PER_LONG == 0) {
enlarge(longPosition(bitLength));
} else {
enlarge(longPosition(bitLength) + 1);
}
}
public BitSet() {
enlarge(1);
}
public void and(BitSet otherBits) {
int max = Math.max(bits.length, otherBits.bits.length);
for (int i = 0; i < max; i++) {
bits[i] &= otherBits.bits[i];
}
}
public void andNot(BitSet otherBits) {
int max = Math.max(bits.length, otherBits.bits.length);
enlarge(max);
for (int i = 0; i < max; i++) {
bits[i] &= ~otherBits.bits[i];
}
}
public void or(BitSet otherBits) {
int max = Math.max(bits.length, otherBits.bits.length);
enlarge(max);
for (int i = 0; i < max; i++) {
bits[i] |= otherBits.bits[i];
}
}
public void xor(BitSet otherBits) {
int max = Math.max(bits.length, otherBits.bits.length);
enlarge(max);
for (int i = 0; i < max; i++) {
bits[i] ^= otherBits.bits[i];
}
}
private void enlarge(int newSize) {
if (bits == null || bits.length <= newSize) {
long[] newBits = new long[newSize + 1];
if (bits != null) {
System.arraycopy(bits, 0, newBits, 0, bits.length);
}
bits = newBits;
}
}
public void clear(int index) {
int pos = longPosition(index);
if (pos < bits.length) {
bits[pos] &= (MASK ^ bitPosition(index));
}
}
public boolean get(int index) {
int pos = longPosition(index);
if (pos < bits.length) {
return (bits[pos] & bitPosition(index)) != 0;
}
return false;
}
public void set(int index) {
int pos = longPosition(index);
enlarge(pos);
bits[pos] |= bitPosition(index);
}
public void set(int start, int end) {
for (int i = start; i < end; i++) {
set(i);
}
}
public void clear(int start, int end) {
for (int i = start; i < end; i++) {
clear(i);
}
}
public boolean isEmpty() {
for (int i = 0; i < bits.length; i++) {
if (bits[i] != 0) {
return false;
}
}
return true;
}
public boolean intersects(BitSet otherBits) {
int max = Math.max(bits.length, otherBits.bits.length);
for (int i = 0; i < max; i++) {
if ((bits[i] & otherBits.bits[i]) != 0) {
return true;
}
}
return false;
}
public int length() {
return bits.length << BITS_PER_LONG_SHIFT;
}
public int nextSetBit(int fromIndex) {
return nextBit(fromIndex, false);
}
private int nextBit(int fromIndex, boolean bitClear) {
int pos = longPosition(fromIndex);
if (pos >= bits.length) {
return -1;
}
int current = fromIndex;
do {
long currValue = bits[pos];
if (currValue == 0) {
pos++;
current = pos << BITS_PER_LONG_SHIFT;
} else {
do {
long bitPos = bitPosition(current);
if (((currValue & bitPos) != 0) ^ bitClear) {
return current;
} else {
current++;
}
} while (current % BITS_PER_LONG != 0);
}
pos++;
} while (pos < bits.length);
return -1;
}
public int nextClearBit(int fromIndex) {
return nextBit(fromIndex, true);
}
}

View File

@ -37,6 +37,14 @@ public class Properties extends Hashtable {
return (String)get(key);
}
public String getProperty(String key, String defaultValue) {
String value = (String) get(key);
if (value == null) {
return defaultValue;
}
return value;
}
public void setProperty(String key, String value) {
put(key, value);
}

View File

@ -0,0 +1,106 @@
/* Copyright (c) 2008, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.util.regex;
/**
* This implementation is a skeleton, useful only for compilation. At runtime it
* is need to be replaced by a working implementation, for example one from the
* Apache Harmony project.
*
* @author zsombor
*
*/
public class Matcher {
public boolean matches() {
throw new UnsupportedOperationException();
}
public boolean requireEnd() {
throw new UnsupportedOperationException();
}
public boolean hitEnd() {
throw new UnsupportedOperationException();
}
public boolean lookingAt() {
throw new UnsupportedOperationException();
}
public Matcher reset() {
throw new UnsupportedOperationException();
}
public Matcher reset(CharSequence input) {
throw new UnsupportedOperationException();
}
public int start() {
throw new UnsupportedOperationException();
}
public int start(int group) {
throw new UnsupportedOperationException();
}
public Pattern pattern() {
throw new UnsupportedOperationException();
}
public Matcher region(int start, int end) {
throw new UnsupportedOperationException();
}
public int regionEnd() {
throw new UnsupportedOperationException();
}
public int regionStart() {
throw new UnsupportedOperationException();
}
public String replaceAll(String replacement) {
throw new UnsupportedOperationException();
}
public String replaceFirst(String replacement) {
throw new UnsupportedOperationException();
}
public int end() {
throw new UnsupportedOperationException();
}
public int end(int group) {
throw new UnsupportedOperationException();
}
public boolean find() {
throw new UnsupportedOperationException();
}
public boolean find(int start) {
throw new UnsupportedOperationException();
}
public int groupCount() {
throw new UnsupportedOperationException();
}
public String group() {
throw new UnsupportedOperationException();
}
public String group(int group) {
throw new UnsupportedOperationException();
}
}

View File

@ -0,0 +1,75 @@
/* Copyright (c) 2008, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.util.regex;
/**
* This implementation is a skeleton, useful only for compilation. At runtime it
* is need to be replaced by a working implementation, for example one from the
* Apache Harmony project.
*
* @author zsombor
*
*/
public class Pattern {
public static final int UNIX_LINES = 1;
public static final int CASE_INSENSITIVE = 2;
public static final int COMMENTS = 4;
public static final int MULTILINE = 8;
public static final int LITERAL = 16;
public static final int DOTALL = 32;
public static final int UNICODE_CASE = 64;
public static final int CANON_EQ = 128;
private int patternFlags;
private String pattern;
protected Pattern(String pattern, int flags) {
this.pattern = pattern;
this.patternFlags = flags;
}
public static Pattern compile(String regex) {
return new Pattern(regex, 0);
}
public static Pattern compile(String regex, int flags) {
return new Pattern(regex, flags);
}
public int flags() {
return patternFlags;
}
public Matcher matcher(CharSequence input) {
throw new UnsupportedOperationException();
}
public static boolean matches(String regex, CharSequence input) {
return Pattern.compile(regex).matcher(input).matches();
}
public String pattern() {
return pattern;
}
public static String quote(String s) {
throw new UnsupportedOperationException();
}
public String[] split(CharSequence input) {
throw new UnsupportedOperationException();
}
public String[] split(CharSequence input, int limit) {
throw new UnsupportedOperationException();
}
}