com.scudata.array.ByteBufferArray Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of esproc Show documentation
Show all versions of esproc Show documentation
SPL(Structured Process Language) A programming language specially for structured data computing.
package com.scudata.array;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Comparator;
import com.scudata.common.MessageManager;
import com.scudata.common.RQException;
import com.scudata.expression.Relation;
import com.scudata.resources.EngineMessage;
import com.scudata.util.Variant;
/**
* String?????????һ??ʵ?֣???byte[]??ƫ?ƣ????? ????????String??ֵ??
* ֻ֧?ֱ???ʽ???˼??㣬??֧?????????еļ???
* ֻ????ʽ?α??ڲ?????ʱ?á????ᱻȡ????
* @author LW
*
*/
public class ByteBufferArray implements IArray {
private static final long serialVersionUID = 1L;
private byte[] buffer;//???õ?????
private int[] pos;//ÿ??Ԫ????buffer?Ŀ?ʼλ??
private byte[] len;//ÿ??Ԫ????buffer?ij???
private int size;
public ByteBufferArray(byte[] buffer, int[] pos, byte[] len, int size) {
this.buffer = buffer;
this.pos = pos;
this.len = len;
this.size = size;
}
public ByteBufferArray(byte[] buffer, int initialCapacity) {
pos = new int[++initialCapacity];
len = new byte[initialCapacity];
this.buffer = buffer;
}
private static int compareArrays(byte[] b1, int pos1, int len1, byte[] b2) {
int len2 = b2.length;
if (len1 == len2) {
for(int i = 0; i < len1; ++i) {
if (b1[i + pos1] < b2[i]) {
return -1;
} else if (b1[i + pos1] > b2[i]) {
return 1;
}
}
return 0;
} else if (len1 < len2) {
for(int i = 0; i < len1; ++i) {
if (b1[i + pos1] < b2[i]) {
return -1;
} else if (b1[i + pos1] > b2[i]) {
return 1;
}
}
return -1;
} else {
for(int i = 0; i < len2; ++i) {
if (b1[i + pos1] < b2[i]) {
return -1;
} else if (b1[i + pos1] > b2[i]) {
return 1;
}
}
return 1;
}
}
public static int compare(byte[] d1, int pos1, int len1, byte[] d2) {
if (pos1 == -1) {
return d2 == null ? 0 : -1;
} else if (d2 == null) {
return 1;
} else {
int cmp = compareArrays(d1, pos1, len1, d2);
return cmp < 0 ? -1 : (cmp > 0 ? 1 : 0);
}
}
private static int compare(byte[] d1, int pos1, int len1, Object d2) {
if (d2 instanceof byte[]) {
if (d1 == null) {
return -1;
} else {
int cmp = compareArrays(d1, pos1, len1, (byte[]) d2);
return cmp < 0 ? -1 : (cmp > 0 ? 1 : 0);
}
} else if (d2 == null) {
return d1 == null ? 0 : 1;
} else {
MessageManager mm = EngineMessage.get();
throw new RQException(mm.getMessage("Variant2.illCompare", d1, d2,
mm.getMessage("DataType.String"), Variant.getDataType(d2)));
}
}
public byte[] getBuffer() {
return buffer;
}
/**
* ȡ????????ʹ??????ڴ?????Ϣ??ʾ
* @return ???ʹ?
*/
public String getDataType() {
throw new RuntimeException();
}
/**
* ????????
* @return
*/
public IArray dup() {
throw new RuntimeException();
}
/**
* д???ݵ???
* @param out ?????
* @throws IOException
*/
public void writeExternal(ObjectOutput out) throws IOException {
throw new RuntimeException();
}
/**
* ?????ж?????
* @param in ??????
* @throws IOException
* @throws ClassNotFoundException
*/
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
throw new RuntimeException();
}
public byte[] serialize() throws IOException{
throw new RuntimeException();
}
public void fillRecord(byte[] buf) throws IOException, ClassNotFoundException {
throw new RuntimeException();
}
/**
* ????һ??ͬ???͵?????
* @param count
* @return
*/
public IArray newInstance(int count) {
throw new RuntimeException();
}
/**
* ??Ԫ?أ???????Ͳ????????׳??쳣
* @param o Ԫ??ֵ
*/
public void add(Object o) {
throw new RuntimeException();
}
/**
* ??һ??Ԫ?أ???????Ͳ????????׳??쳣
* @param array Ԫ??????
*/
public void addAll(IArray array) {
throw new RuntimeException();
}
/**
* ??һ??Ԫ?أ???????Ͳ????????׳??쳣
* @param array Ԫ??????
* @param count Ԫ?ظ???
*/
public void addAll(IArray array, int count) {
throw new RuntimeException();
}
/**
* ??һ??Ԫ?أ???????Ͳ????????׳??쳣
* @param array Ԫ??????
* @param index Ҫ????????ݵ???ʼλ??
* @param count ????
*/
public void addAll(IArray array, int index, int count) {
throw new RuntimeException();
}
/**
* ??һ??Ԫ?أ???????Ͳ????????׳??쳣
* @param array Ԫ??????
*/
public void addAll(Object []array) {
throw new RuntimeException();
}
/**
* ????Ԫ?أ???????Ͳ????????׳??쳣
* @param index ????λ?ã???1??ʼ????
* @param o Ԫ??ֵ
*/
public void insert(int index, Object o) {
throw new RuntimeException();
}
/**
* ??ָ??λ?ò???һ??Ԫ?أ???????Ͳ????????׳??쳣
* @param pos λ?ã???1??ʼ????
* @param array Ԫ??????
*/
public void insertAll(int pos, IArray array) {
throw new RuntimeException();
}
/**
* ??ָ??λ?ò???һ??Ԫ?أ???????Ͳ????????׳??쳣
* @param pos λ?ã???1??ʼ????
* @param array Ԫ??????
*/
public void insertAll(int pos, Object []array) {
throw new RuntimeException();
}
public void push(byte[] str) {
throw new RuntimeException();
}
public void pushString(byte[] str) {
throw new RuntimeException();
}
/**
* ??Ԫ?أ??????????????Ϊ???㹻?ռ???Ԫ?أ?????????Ͳ????????׳??쳣
* @param o Ԫ??ֵ
*/
public void push(Object o) {
throw new RuntimeException();
}
/**
* ??һ???ճ?Ա???????????????Ϊ???㹻?ռ???Ԫ?أ?
*/
public void pushNull() {
throw new RuntimeException();
}
/**
* ??array?еĵ?index??Ԫ?????ӵ???ǰ?????У???????Ͳ????????׳??쳣
* @param array ????
* @param index Ԫ??????????1??ʼ????
*/
public void push(IArray array, int index) {
throw new RuntimeException();
}
/**
* ??array?еĵ?index??Ԫ?????ӵ???ǰ?????У???????Ͳ????????׳??쳣
* @param array ????
* @param index Ԫ??????????1??ʼ????
*/
public void add(IArray array, int index) {
throw new RuntimeException();
}
/**
* ??array?еĵ?index??Ԫ?????????ǰ?????ָ??Ԫ?أ???????Ͳ????????׳??쳣
* @param curIndex ??ǰ?????Ԫ??????????1??ʼ????
* @param array ????
* @param index Ԫ??????????1??ʼ????
*/
public void set(int curIndex, IArray array, int index) {
throw new RuntimeException();
}
/**
* ȡָ??λ??Ԫ??
* @param index ????????1??ʼ????
* @return
*/
public Object get(int index) {
return new String(buffer, pos[index], len[index]);
}
/**
* ȡָ??λ??Ԫ?ص?????ֵ
* @param index ????????1??ʼ????
* @return ??????ֵ
*/
public int getInt(int index) {
throw new RuntimeException();
}
/**
* ȡָ??λ??Ԫ?صij?????ֵ
* @param index ????????1??ʼ????
* @return ??????ֵ
*/
public long getLong(int index) {
throw new RuntimeException();
}
/**
* ȡָ??λ??Ԫ???????????
* @param indexArray λ??????
* @return IArray
*/
public IArray get(int []indexArray) {
throw new RuntimeException();
}
/**
* ȡָ??λ??Ԫ???????????
* @param indexArray λ??????
* @param start ??ʼλ?ã?????
* @param end ????λ?ã?????
* @param doCheck true??λ?ÿ??ܰ???0??0??λ????null??䣬false?????????0
* @return IArray
*/
public IArray get(int []indexArray, int start, int end, boolean doCheck) {
throw new RuntimeException();
}
/**
* ȡָ??λ??Ԫ???????????
* @param IArray λ??????
* @return IArray
*/
public IArray get(IArray indexArray) {
throw new RuntimeException();
}
/**
* ȡijһ?????????????
* @param start ??ʼλ?ã???????
* @param end ????λ?ã?????????
* @return IArray
*/
public IArray get(int start, int end) {
throw new RuntimeException();
}
/**
* ʹ?б?????????С??minCapacity
* @param minCapacity ??С????
*/
public void ensureCapacity(int minCapacity) {
throw new RuntimeException();
}
/**
* ??????????ʹ????Ԫ???????
*/
public void trimToSize() {
throw new RuntimeException();
}
/**
* ?ж?ָ??λ?õ?Ԫ???Ƿ??ǿ?
* @param index ????????1??ʼ????
* @return
*/
public boolean isNull(int index) {
return pos[index] == -1;
}
/**
* ?ж?Ԫ???Ƿ???True
* @return BoolArray
*/
public BoolArray isTrue() {
int size = this.size;
int[] pos = this.pos;
boolean []resultDatas = new boolean[size + 1];
for (int i = 1; i <= size; ++i) {
resultDatas[i] = pos[i] >= 0;
}
BoolArray result = new BoolArray(resultDatas, size);
result.setTemporary(true);
return result;
}
/**
* ?ж?Ԫ???Ƿ??Ǽ?
* @return BoolArray
*/
public BoolArray isFalse() {
int size = this.size;
int[] pos = this.pos;
boolean []resultDatas = new boolean[size + 1];
for (int i = 1; i <= size; ++i) {
resultDatas[i] = pos[i] < 0;
}
BoolArray result = new BoolArray(resultDatas, size);
result.setTemporary(true);
return result;
}
/**
* ?ж?ָ??λ?õ?Ԫ???Ƿ???True
* @param index ????????1??ʼ????
* @return
*/
public boolean isTrue(int index) {
// ?ǿ?????true
return pos[index] != -1;
}
/**
* ?ж?ָ??λ?õ?Ԫ???Ƿ???False
* @param index ????????1??ʼ????
* @return
*/
public boolean isFalse(int index) {
// ??????false
return pos[index] == -1;
}
/**
* ?Ƿ??Ǽ??????????ʱ?????????飬??ʱ?????Ŀ??Ա??ģ????? f1+f2+f3??ֻ?????һ???????Ž??
* @return true??????ʱ?????????飬false????????ʱ??????????
*/
public boolean isTemporary() {
return false;
}
/**
* ?????Ƿ??Ǽ??????????ʱ??????????
* @param ifTemporary true??????ʱ?????????飬false????????ʱ??????????
*/
public void setTemporary(boolean ifTemporary) {
}
/**
* ɾ?????һ??Ԫ??
*/
public void removeLast() {
throw new RuntimeException();
}
/**
* ɾ??ָ??λ?õ?Ԫ??
* @param index ????????1??ʼ????
*/
public void remove(int index) {
throw new RuntimeException();
}
/**
* ɾ??ָ???????ڵ?Ԫ??
* @param from ??ʼλ?ã?????
* @param to ????λ?ã?????
*/
public void removeRange(int fromIndex, int toIndex) {
throw new RuntimeException();
}
/**
* ɾ??ָ??λ?õ?Ԫ?أ???Ŵ?С????????
* @param seqs ????????
*/
public void remove(int []seqs) {
throw new RuntimeException();
}
/**
* ????ָ???????ڵ?????
* @param start ??ʼλ?ã???????
* @param end ????λ?ã???????
*/
public void reserve(int start, int end) {
throw new RuntimeException();
}
public int size() {
return size;
}
/**
* ????????ķǿ?Ԫ????Ŀ
* @return ?ǿ?Ԫ????Ŀ
*/
public int count() {
int[] pos = this.pos;
int size = this.size;
int count = size;
for (int i = 1; i <= size; ++i) {
if (pos[i] == -1) {
count--;
}
}
return count;
}
/**
* ?ж??????Ƿ???ȡֵΪtrue??Ԫ??
* @return true???У?false??û??
*/
public boolean containTrue() {
int size = this.size;
if (size == 0) {
return false;
}
int[] pos = this.pos;
for (int i = 1; i <= size; ++i) {
if (pos[i] != -1) {
return true;
}
}
return false;
}
/**
* ???ص?һ????Ϊ?յ?Ԫ??
* @return Object
*/
public Object ifn() {
throw new RuntimeException();
}
/**
* ??????ָ??Ԫ?ص?ֵ????????Ͳ????????׳??쳣
* @param index ????????1??ʼ????
* @param obj ֵ
*/
public void set(int index, Object obj) {
throw new RuntimeException();
}
/**
* ɾ?????е?Ԫ??
*/
public void clear() {
throw new RuntimeException();
}
/**
* ???ַ?????ָ??Ԫ??
* @param elem
* @return int Ԫ?ص?????,????????ڷ??ظ??IJ???λ??.
*/
public int binarySearch(Object elem) {
if (elem instanceof String) {
byte[] v = ((String)elem).getBytes();
byte[] buf = this.buffer;
int[] pos = this.pos;
byte[] len = this.len;
int low = 1, high = size;
while (low <= high) {
int mid = (low + high) >> 1;
int cmp = compare(buf, pos[mid], len[mid], v);
if (cmp < 0) {
low = mid + 1;
} else if (cmp > 0) {
high = mid - 1;
} else {
return mid; // key found
}
}
return -low; // key not found
} else if (elem == null) {
if (size > 0 && pos[1] == -1) {
return 1;
} else {
return -1;
}
} else {
MessageManager mm = EngineMessage.get();
throw new RQException(mm.getMessage("Variant2.illCompare"));
}
}
/**
* ???ַ?????ָ??Ԫ??
* @param elem
* @param start ??ʼ????λ?ã???????
* @param end ????????λ?ã???????
* @return Ԫ?ص?????,????????ڷ??ظ??IJ???λ??.
*/
public int binarySearch(Object elem, int start, int end) {
if (elem instanceof String) {
byte[] v = ((String)elem).getBytes();
byte[] buffer = this.buffer;
int[] pos = this.pos;
byte[] len = this.len;
int low = start, high = end;
while (low <= high) {
int mid = (low + high) >> 1;
int cmp = compare(buffer, pos[mid], len[mid], v);
if (cmp < 0) {
low = mid + 1;
} else if (cmp > 0) {
high = mid - 1;
} else {
return mid; // key found
}
}
return -low; // key not found
} else if (elem == null) {
if (end > 0 && pos[start] == -1) {
return start;
} else {
return -1;
}
} else {
MessageManager mm = EngineMessage.get();
throw new RQException(mm.getMessage("Variant2.illCompare"));
}
}
/**
* ?????б????Ƿ????ָ??Ԫ??
* @param elem Object ?????ҵ?Ԫ??
* @return boolean true????????false????????
*/
public boolean contains(Object elem) {
if (elem instanceof String) {
byte[] v = ((String)elem).getBytes();
byte[] buffer = this.buffer;
int[] pos = this.pos;
byte[] len = this.len;
int size = this.size;
for (int i = 1; i <= size; ++i) {
if (pos[i] != -1 && compare(buffer, pos[i], len[i], v) == 0) {
return true;
}
}
return false;
} else if (elem == null) {
int size = this.size;
int[] pos = this.pos;
for (int i = 1; i <= size; ++i) {
if (pos[i] == -1) {
return true;
}
}
return false;
} else {
return false;
}
}
/**
* ?ж??????Ԫ???Ƿ??ڵ?ǰ??????
* @param isSorted ??ǰ?????Ƿ?????
* @param array ????
* @param result ???ڴ?Ž????ֻ??ȡֵΪtrue??
*/
public void contains(boolean isSorted, IArray array, BoolArray result) {
int resultSize = result.size();
if (isSorted) {
for (int i = 1; i <= resultSize; ++i) {
if (result.isTrue(i) && binarySearch(array.get(i)) < 1) {
result.set(i, false);
}
}
} else {
for (int i = 1; i <= resultSize; ++i) {
if (result.isTrue(i) && !contains(array.get(i))) {
result.set(i, false);
}
}
}
}
/**
* ?????б????Ƿ????ָ??Ԫ?أ?ʹ?õȺűȽ?
* @param elem
* @return boolean true????????false????????
*/
public boolean objectContains(Object elem) {
throw new RuntimeException();
}
/**
* ????Ԫ???????????״γ??ֵ?λ??
* @param elem ?????ҵ?Ԫ??
* @param start ??ʼ????λ?ã???????
* @return ???Ԫ?ش?????ֵ????0??????0
*/
public int firstIndexOf(Object elem, int start) {
throw new RuntimeException();
}
/**
* ????Ԫ???????????????ֵ?λ??
* @param elem ?????ҵ?Ԫ??
* @param start ?Ӻ??濪ʼ???ҵ?λ?ã???????
* @return ???Ԫ?ش?????ֵ????0??????0
*/
public int lastIndexOf(Object elem, int start) {
throw new RuntimeException();
}
/**
* ????Ԫ?????????????г??ֵ?λ??
* @param elem ?????ҵ?Ԫ??
* @param start ??ʼ????λ?ã???????
* @param isSorted ??ǰ?????Ƿ?????
* @param isFromHead true????ͷ??ʼ??????false????β??ǰ??ʼ????
* @return IntArray
*/
public IntArray indexOfAll(Object elem, int start, boolean isSorted, boolean isFromHead) {
throw new RuntimeException();
}
/**
* ???????Ա?????ֵ
* @return IArray ????ֵ????
*/
public IArray abs() {
MessageManager mm = EngineMessage.get();
throw new RuntimeException(getDataType() + mm.getMessage("Variant2.illAbs"));
}
/**
* ???????Ա??
* @return IArray ??ֵ????
*/
public IArray negate() {
throw new RuntimeException();
}
/**
* ???????Ա???
* @return IArray ??ֵ????
*/
public IArray not() {
int[] pos = this.pos;
int size = this.size;
boolean []newDatas = new boolean[size + 1];
for (int i = 1; i <= size; ++i) {
newDatas[i] = pos[i] == -1;
}
IArray result = new BoolArray(newDatas, size);
result.setTemporary(true);
return result;
}
/**
* ?ж?????ij?Ա?Ƿ?????????????null??
* @return true??????????false?????з?????ֵ
*/
public boolean isNumberArray() {
return false;
}
/**
* ????????????????Ӧ?ij?Ա?ĺ?
* @param array ?Ҳ?????
* @return ??????
*/
public IArray memberAdd(IArray array) {
throw new RuntimeException();
}
/**
* ????????ij?Ա??ָ???????ĺ?
* @param value ????
* @return ??????
*/
public IArray memberAdd(Object value) {
throw new RuntimeException();
}
/**
* ????????????????Ӧ?ij?Ա?IJ?
* @param array ?Ҳ?????
* @return ??????
*/
public IArray memberSubtract(IArray array) {
MessageManager mm = EngineMessage.get();
throw new RQException(getDataType() + mm.getMessage("Variant2.with") +
array.getDataType() + mm.getMessage("Variant2.illSubtract"));
}
/**
* ????????????????Ӧ?ij?Ա?Ļ?
* @param array ?Ҳ?????
* @return ??????
*/
public IArray memberMultiply(IArray array) {
MessageManager mm = EngineMessage.get();
throw new RQException(getDataType() + mm.getMessage("Variant2.with") +
array.getDataType() + mm.getMessage("Variant2.illMultiply"));
}
/**
* ????????ij?Ա??ָ???????Ļ?
* @param value ????
* @return ??????
*/
public IArray memberMultiply(Object value) {
MessageManager mm = EngineMessage.get();
throw new RQException(getDataType() + mm.getMessage("Variant2.with") +
Variant.getDataType(value) + mm.getMessage("Variant2.illMultiply"));
}
/**
* ???Ҳ?????ij?Ա???Stringƴ?ӵ????????ij?Ա??
* @param array ?Ҳ?????
* @return ??????
*/
public IArray memberDivide(IArray array) {
throw new RuntimeException();
}
/**
* ????????????????Ӧ??????Աȡ??????г?Ա?????
* @param array ?Ҳ?????
* @return ??????????????????????
*/
public IArray memberMod(IArray array) {
MessageManager mm = EngineMessage.get();
throw new RQException(getDataType() + mm.getMessage("Variant2.with") +
array.getDataType() + mm.getMessage("Variant2.illMod"));
}
/**
* ?????????????????Ա?????????г?Ա?
* @param array ?Ҳ?????
* @return ????ֵ????????в????
*/
public IArray memberIntDivide(IArray array) {
MessageManager mm = EngineMessage.get();
throw new RQException(getDataType() + mm.getMessage("Variant2.with") +
array.getDataType() + mm.getMessage("Variant2.illDivide"));
}
/**
* ????????????????Ӧ?ij?Ա?Ĺ?ϵ????
* @param array ?Ҳ?????
* @param relation ?????ϵ??????Relation?????ڡ?С?ڡ????ڡ?...??
* @return ??ϵ??????????
*/
public BoolArray calcRelation(IArray array, int relation) {
if (array instanceof ConstArray) {
return calcRelation(array.get(1), relation);
} else {
return array.calcRelation(this, Relation.getInverseRelation(relation));
}
}
/**
* ????????????????Ӧ?ij?Ա?Ĺ?ϵ????
* @param array ?Ҳ?????
* @param relation ?????ϵ??????Relation?????ڡ?С?ڡ????ڡ?...??
* @return ??ϵ??????????
*/
public BoolArray calcRelation(Object value, int relation) {
if (value instanceof String) {
return calcRelation(((String)value).getBytes(), relation);
} else if (value == null) {
return calcRelationNull(pos, size, relation);
} else {
boolean b = Variant.isTrue(value);
int size = this.size;
int[] pos = this.pos;
if (relation == Relation.AND) {
BoolArray result;
if (!b) {
result = new BoolArray(false, size);
} else {
boolean []resultDatas = new boolean[size + 1];
for (int i = 1; i <= size; ++i) {
resultDatas[i] = pos[i] != -1;
}
result = new BoolArray(resultDatas, size);
}
result.setTemporary(true);
return result;
} else if (relation == Relation.OR) {
BoolArray result;
if (b) {
result = new BoolArray(true, size);
} else {
boolean []resultDatas = new boolean[size + 1];
for (int i = 1; i <= size; ++i) {
resultDatas[i] = pos[i] != -1;
}
result = new BoolArray(resultDatas, size);
}
result.setTemporary(true);
return result;
} else {
MessageManager mm = EngineMessage.get();
throw new RQException(mm.getMessage("Variant2.illCompare", get(1), value,
getDataType(), Variant.getDataType(value)));
}
}
}
/**
* ????????ij?Ա??null?Ĺ?ϵ
* @param signs ?????Ա?Ƿ?Ϊ?ձ?־??trueΪ??
* @param size ?????Ա??
* @param relation ?ȽϹ?ϵ
* @return BoolArray ?Ƚ?ֵ????
*/
private static BoolArray calcRelationNull(int []pos, int size, int relation) {
boolean[] signs = null;
for (int i = 1; i <= size; ++i) {
if (pos[i] == -1) {
if (signs == null) signs = new boolean[size];
signs[i] = true;
}
}
boolean []resultDatas = new boolean[size + 1];
if (relation == Relation.EQUAL) {
// ?Ƿ?????ж?
if (signs != null) {
System.arraycopy(signs, 1, resultDatas, 1, size);
}
} else if (relation == Relation.GREATER) {
// ?Ƿ?????ж?
if (signs == null) {
for (int i = 1; i <= size; ++i) {
resultDatas[i] = true;
}
} else {
for (int i = 1; i <= size; ++i) {
if (!signs[i]) {
resultDatas[i] = true;
}
}
}
} else if (relation == Relation.GREATER_EQUAL) {
// ?Ƿ???ڵ????ж?
for (int i = 1; i <= size; ++i) {
resultDatas[i] = true;
}
} else if (relation == Relation.LESS) {
// ?Ƿ?С???ж?
} else if (relation == Relation.LESS_EQUAL) {
// ?Ƿ?С?ڵ????ж?
if (signs != null) {
System.arraycopy(signs, 1, resultDatas, 1, size);
}
} else if (relation == Relation.NOT_EQUAL) {
// ?Ƿ????ж?
if (signs == null) {
for (int i = 1; i <= size; ++i) {
resultDatas[i] = true;
}
} else {
for (int i = 1; i <= size; ++i) {
if (!signs[i]) {
resultDatas[i] = true;
}
}
}
} else if (relation == Relation.OR) {
if (signs == null) {
for (int i = 1; i <= size; ++i) {
resultDatas[i] = true;
}
} else {
for (int i = 1; i <= size; ++i) {
resultDatas[i] = !signs[i];
}
}
}
BoolArray result = new BoolArray(resultDatas, size);
result.setTemporary(true);
return result;
}
private BoolArray calcRelation(byte[] value, int relation) {
int size = this.size;
int[] pos = this.pos;
byte[] len = this.len;
byte[] d1 = this.buffer;
boolean []resultDatas = new boolean[size + 1];
if (relation == Relation.EQUAL) {
// ?Ƿ?????ж?
for (int i = 1; i <= size; ++i) {
resultDatas[i] = compare(d1, pos[i], len[i], value) == 0;
}
} else if (relation == Relation.GREATER) {
// ?Ƿ?????ж?
for (int i = 1; i <= size; ++i) {
resultDatas[i] = compare(d1, pos[i], len[i], value) > 0;
}
} else if (relation == Relation.GREATER_EQUAL) {
// ?Ƿ???ڵ????ж?
for (int i = 1; i <= size; ++i) {
resultDatas[i] = compare(d1, pos[i], len[i], value) >= 0;
}
} else if (relation == Relation.LESS) {
// ?Ƿ?С???ж?
for (int i = 1; i <= size; ++i) {
resultDatas[i] = compare(d1, pos[i], len[i], value) < 0;
}
} else if (relation == Relation.LESS_EQUAL) {
// ?Ƿ?С?ڵ????ж?
for (int i = 1; i <= size; ++i) {
resultDatas[i] = compare(d1, pos[i], len[i], value) <= 0;
}
} else if (relation == Relation.NOT_EQUAL) {
// ?Ƿ????ж?
for (int i = 1; i <= size; ++i) {
resultDatas[i] = compare(d1, pos[i], len[i], value) != 0;
}
} else if (relation == Relation.AND) {
for (int i = 1; i <= size; ++i) {
resultDatas[i] = pos[i] != -1;
}
} else { // Relation.OR
for (int i = 1; i <= size; ++i) {
resultDatas[i] = true;
}
}
BoolArray result = new BoolArray(resultDatas, size);
result.setTemporary(true);
return result;
}
/**
* ?Ƚ?????????Ĵ?С
* @param array ?Ҳ?????
* @return 1????ǰ?????0????????????ȣ?-1????ǰ????С
*/
public int compareTo(IArray array) {
throw new RuntimeException();
}
/**
* ?????????2????Ա?ıȽ?ֵ
* @param index1 ??Ա1
* @param index2 ??Ա2
* @return
*/
public int memberCompare(int index1, int index2) {
throw new RuntimeException();
}
/**
* ?ж????????????Ա?Ƿ????
* @param index1 ??Ա1
* @param index2 ??Ա2
* @return
*/
public boolean isMemberEquals(int index1, int index2) {
throw new RuntimeException();
}
/**
* ?ж??????????ָ??Ԫ???Ƿ???ͬ
* @param curIndex ??ǰ?????Ԫ?ص?????
* @param array Ҫ?Ƚϵ?????
* @param index Ҫ?Ƚϵ??????Ԫ?ص?????
* @return true????ͬ??false??????ͬ
*/
public boolean isEquals(int curIndex, IArray array, int index) {
throw new RuntimeException();
}
/**
* ?ж??????ָ??Ԫ???Ƿ??????ֵ???
* @param curIndex ????Ԫ??????????1??ʼ????
* @param value ֵ
* @return true????ȣ?false???????
*/
public boolean isEquals(int curIndex, Object value) {
if (value instanceof String) {
return compare(buffer, pos[curIndex], len[curIndex], ((String)value).getBytes()) == 0;
} else if (value == null) {
return pos[curIndex] == -1;
} else {
return false;
}
}
/**
* ?ж??????????ָ??Ԫ?صĴ?С
* @param curIndex ??ǰ?????Ԫ?ص?????
* @param array Ҫ?Ƚϵ?????
* @param index Ҫ?Ƚϵ??????Ԫ?ص?????
* @return С?ڣ?С??0?????ڣ?0?????ڣ?????0
*/
public int compareTo(int curIndex, IArray array, int index) {
return compare(buffer, pos[curIndex], len[curIndex], array.get(index));
}
/**
* ?Ƚ??????ָ??Ԫ???????ֵ?Ĵ?С
* @param curIndex ??ǰ?????Ԫ?ص?????
* @param value Ҫ?Ƚϵ?ֵ
* @return
*/
public int compareTo(int curIndex, Object value) {
return compare(buffer, pos[curIndex], len[curIndex], value);
}
/**
* ȡָ????Ա?Ĺ?ϣֵ
* @param index ??Ա????????1??ʼ????
* @return ָ????Ա?Ĺ?ϣֵ
*/
public int hashCode(int index) {
if (pos[index] != -1) {
return get(index).hashCode();
} else {
return 0;
}
}
/**
* ???Ա??
* @return
*/
public Object sum() {
return null;
}
/**
* ??ƽ??ֵ
* @return
*/
public Object average() {
return null;
}
/**
* ?õ????ij?Ա
* @return
*/
public Object max() {
throw new RuntimeException();
}
/**
* ?õ???С?ij?Ա
* @return
*/
public Object min() {
throw new RuntimeException();
}
/**
* ????????????????Ӧ?ij?Ա?Ĺ?ϵ???㣬ֻ????resultΪ?????
* @param array ?Ҳ?????
* @param relation ?????ϵ??????Relation?????ڡ?С?ڡ????ڡ?...??
* @param result ????????????ǰ??ϵ????????Ҫ???????????&&????||????
* @param isAnd true????????? && ???㣬false????????? || ????
*/
public void calcRelations(IArray array, int relation, BoolArray result, boolean isAnd) {
if (array instanceof ConstArray) {
calcRelations(array.get(1), relation, result, isAnd);
} else {
MessageManager mm = EngineMessage.get();
throw new RQException(mm.getMessage("Variant2.illCompare", get(1), array.get(1),
getDataType(), array.getDataType()));
}
}
/**
* ????????????????Ӧ?ij?Ա?Ĺ?ϵ???㣬ֻ????resultΪ?????
* @param array ?Ҳ?????
* @param relation ?????ϵ??????Relation?????ڡ?С?ڡ????ڡ?...??
* @param result ????????????ǰ??ϵ????????Ҫ???????????&&????||????
* @param isAnd true????????? && ???㣬false????????? || ????
*/
public void calcRelations(Object value, int relation, BoolArray result, boolean isAnd) {
if (value instanceof String) {
calcRelations(((String)value).getBytes(), relation, result, isAnd);
} else if (value == null) {
calcRelationsNull(pos, size, relation, result, isAnd);
} else {
MessageManager mm = EngineMessage.get();
throw new RQException(mm.getMessage("Variant2.illCompare", get(1), value,
getDataType(), Variant.getDataType(value)));
}
}
/**
* ????????ij?Ա??null?Ĺ?ϵ
* @param signs ?????Ա?Ƿ?Ϊ?ձ?־??trueΪ??
* @param size ?????Ա??
* @param relation ?ȽϹ?ϵ
* @param result ????????????ǰ??ϵ????????Ҫ???????????&&????||????
* @param isAnd true????????? && ???㣬false????????? || ????
*/
private static void calcRelationsNull(int []pos, int size, int relation, BoolArray result, boolean isAnd) {
boolean[] signs = null;
for (int i = 1; i <= size; ++i) {
if (pos[i] == -1) {
if (signs == null) signs = new boolean[size];
signs[i] = true;
}
}
boolean []resultDatas = result.getDatas();
if (isAnd) {
// ???????ִ??&&????
if (relation == Relation.EQUAL) {
// ?Ƿ?????ж?
if (signs == null) {
for (int i = 1; i <= size; ++i) {
resultDatas[i] = false;
}
} else {
for (int i = 1; i <= size; ++i) {
if (!signs[i]) {
resultDatas[i] = false;
}
}
}
} else if (relation == Relation.GREATER) {
// ?Ƿ?????ж?
if (signs != null) {
for (int i = 1; i <= size; ++i) {
if (signs[i]) {
resultDatas[i] = false;
}
}
}
} else if (relation == Relation.GREATER_EQUAL) {
// ?Ƿ???ڵ????ж?
} else if (relation == Relation.LESS) {
// ?Ƿ?С???ж?
for (int i = 1; i <= size; ++i) {
resultDatas[i] = false;
}
} else if (relation == Relation.LESS_EQUAL) {
// ?Ƿ?С?ڵ????ж?
if (signs != null) {
for (int i = 1; i <= size; ++i) {
if (!signs[i]) {
resultDatas[i] = false;
}
}
}
} else if (relation == Relation.NOT_EQUAL) {
// ?Ƿ????ж?
if (signs != null) {
for (int i = 1; i <= size; ++i) {
if (signs[i]) {
resultDatas[i] = false;
}
}
}
} else {
throw new RuntimeException();
}
} else {
// ???????ִ??||????
if (relation == Relation.EQUAL) {
// ?Ƿ?????ж?
if (signs != null) {
for (int i = 1; i <= size; ++i) {
if (signs[i]) {
resultDatas[i] = true;
}
}
}
} else if (relation == Relation.GREATER) {
// ?Ƿ?????ж?
if (signs == null) {
for (int i = 1; i <= size; ++i) {
resultDatas[i] = true;
}
} else {
for (int i = 1; i <= size; ++i) {
if (!signs[i]) {
resultDatas[i] = true;
}
}
}
} else if (relation == Relation.GREATER_EQUAL) {
// ?Ƿ???ڵ????ж?
for (int i = 1; i <= size; ++i) {
resultDatas[i] = true;
}
} else if (relation == Relation.LESS) {
// ?Ƿ?С???ж?
} else if (relation == Relation.LESS_EQUAL) {
// ?Ƿ?С?ڵ????ж?
if (signs != null) {
for (int i = 1; i <= size; ++i) {
if (signs[i]) {
resultDatas[i] = true;
}
}
}
} else if (relation == Relation.NOT_EQUAL) {
// ?Ƿ????ж?
if (signs == null) {
for (int i = 1; i <= size; ++i) {
resultDatas[i] = true;
}
} else {
for (int i = 1; i <= size; ++i) {
if (!signs[i]) {
resultDatas[i] = true;
}
}
}
} else {
throw new RuntimeException();
}
}
}
private void calcRelations(byte[] value, int relation, BoolArray result, boolean isAnd) {
int size = this.size;
byte[] d1 = this.buffer;
int[] pos = this.pos;
byte[] len = this.len;
boolean []resultDatas = result.getDatas();
if (isAnd) {
// ???????ִ??&&????
if (relation == Relation.EQUAL) {
// ?Ƿ?????ж?
for (int i = 1; i <= size; ++i) {
if (resultDatas[i] && compare(d1, pos[i], len[i], value) != 0) {
resultDatas[i] = false;
}
}
} else if (relation == Relation.GREATER) {
// ?Ƿ?????ж?
for (int i = 1; i <= size; ++i) {
if (resultDatas[i] && compare(d1, pos[i], len[i], value) <= 0) {
resultDatas[i] = false;
}
}
} else if (relation == Relation.GREATER_EQUAL) {
// ?Ƿ???ڵ????ж?
for (int i = 1; i <= size; ++i) {
if (resultDatas[i] && compare(d1, pos[i], len[i], value) < 0) {
resultDatas[i] = false;
}
}
} else if (relation == Relation.LESS) {
// ?Ƿ?С???ж?
for (int i = 1; i <= size; ++i) {
if (resultDatas[i] && compare(d1, pos[i], len[i], value) >= 0) {
resultDatas[i] = false;
}
}
} else if (relation == Relation.LESS_EQUAL) {
// ?Ƿ?С?ڵ????ж?
for (int i = 1; i <= size; ++i) {
if (resultDatas[i] && compare(d1, pos[i], len[i], value) > 0) {
resultDatas[i] = false;
}
}
} else if (relation == Relation.NOT_EQUAL) {
// ?Ƿ????ж?
for (int i = 1; i <= size; ++i) {
if (resultDatas[i] && compare(d1, pos[i], len[i], value) == 0) {
resultDatas[i] = false;
}
}
} else {
throw new RuntimeException();
}
} else {
// ???????ִ??||????
if (relation == Relation.EQUAL) {
// ?Ƿ?????ж?
for (int i = 1; i <= size; ++i) {
if (!resultDatas[i] && compare(d1, pos[i], len[i], value) == 0) {
resultDatas[i] = true;
}
}
} else if (relation == Relation.GREATER) {
// ?Ƿ?????ж?
for (int i = 1; i <= size; ++i) {
if (!resultDatas[i] && compare(d1, pos[i], len[i], value) > 0) {
resultDatas[i] = true;
}
}
} else if (relation == Relation.GREATER_EQUAL) {
// ?Ƿ???ڵ????ж?
for (int i = 1; i <= size; ++i) {
if (!resultDatas[i] && compare(d1, pos[i], len[i], value) >= 0) {
resultDatas[i] = true;
}
}
} else if (relation == Relation.LESS) {
// ?Ƿ?С???ж?
for (int i = 1; i <= size; ++i) {
if (!resultDatas[i] && compare(d1, pos[i], len[i], value) < 0) {
resultDatas[i] = true;
}
}
} else if (relation == Relation.LESS_EQUAL) {
// ?Ƿ?С?ڵ????ж?
for (int i = 1; i <= size; ++i) {
if (!resultDatas[i] && compare(d1, pos[i], len[i], value) <= 0) {
resultDatas[i] = true;
}
}
} else if (relation == Relation.NOT_EQUAL) {
// ?Ƿ????ж?
for (int i = 1; i <= size; ++i) {
if (!resultDatas[i] && compare(d1, pos[i], len[i], value) != 0) {
resultDatas[i] = true;
}
}
} else {
throw new RuntimeException();
}
}
}
/**
* ????????????????Ӧ?ij?Ա?İ?λ??
* @param array ?Ҳ?????
* @return ??λ????????
*/
public IArray bitwiseAnd(IArray array) {
MessageManager mm = EngineMessage.get();
throw new RQException("and" + mm.getMessage("function.paramTypeError"));
}
/**
* ????????????????Ӧ?ij?Ա?İ?λ??
* @param array ?Ҳ?????
* @return ??λ????????
*/
public IArray bitwiseOr(IArray array) {
MessageManager mm = EngineMessage.get();
throw new RQException("or" + mm.getMessage("function.paramTypeError"));
}
/**
* ????????????????Ӧ?ij?Ա?İ?λ???
* @param array ?Ҳ?????
* @return ??λ?????????
*/
public IArray bitwiseXOr(IArray array) {
MessageManager mm = EngineMessage.get();
throw new RQException("xor" + mm.getMessage("function.paramTypeError"));
}
/**
* ?????????Ա?İ?λȡ??
* @return ??Ա??λȡ?????????
*/
public IArray bitwiseNot() {
MessageManager mm = EngineMessage.get();
throw new RQException("not" + mm.getMessage("function.paramTypeError"));
}
/**
* ȡ????ʶ????ȡֵΪ????ж?Ӧ?????ݣ??????????
* @param signArray ??ʶ????
* @return IArray
*/
public IArray select(IArray signArray) {
throw new RuntimeException();
}
/**
* ȡijһ???α?ʶ????ȡֵΪ??????????????
* @param start ??ʼλ?ã???????
* @param end ????λ?ã?????????
* @param signArray ??ʶ????
* @return IArray
*/
public IArray select(int start, int end, IArray signArray) {
throw new RuntimeException();
}
/**
* ??array??ָ??Ԫ?ؼӵ???ǰ?????ָ??Ԫ????
* @param curIndex ??ǰ?????Ԫ?ص?????
* @param array Ҫ??ӵ?????
* @param index Ҫ??ӵ??????Ԫ?ص?????
* @return IArray
*/
public IArray memberAdd(int curIndex, IArray array, int index) {
MessageManager mm = EngineMessage.get();
throw new RQException(getDataType() + mm.getMessage("Variant2.with") +
array.getDataType() + mm.getMessage("Variant2.illAdd"));
}
/**
* ?ѳ?Աת?ɶ??????鷵??
* @return ????????
*/
public Object[] toArray() {
throw new RuntimeException();
}
/**
* ?ѳ?Ա?ָ????????
* @param result ???ڴ?ų?Ա??????
*/
public void toArray(Object []result) {
throw new RuntimeException();
}
/**
* ???????ָ??λ?ò??????????
* @param pos λ?ã?????
* @return ???غ?벿??Ԫ?ع??ɵ?????
*/
public IArray split(int pos) {
throw new RuntimeException();
}
/**
* ??ָ??????Ԫ?ط???????????????
* @param from ??ʼλ?ã?????
* @param to ????λ?ã?????
* @return
*/
public IArray split(int from, int to) {
throw new RuntimeException();
}
/**
* ???????Ԫ?ؽ???????
*/
public void sort() {
throw new RuntimeException();
}
/**
* ???????Ԫ?ؽ???????
* @param comparator ?Ƚ???
*/
public void sort(Comparator
© 2015 - 2024 Weber Informatics LLC | Privacy Policy