Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/FilterImpl.java656
1 files changed, 248 insertions, 408 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/FilterImpl.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/FilterImpl.java
index f718ea1fe..c9f574709 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/FilterImpl.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/FilterImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2019 IBM Corporation and others.
+ * Copyright (c) 2003, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -466,146 +466,112 @@ public abstract class FilterImpl implements Filter {
}
}
- static final class Present extends FilterImpl {
- /** debug mode */
- final boolean debug;
- private final String attr;
-
- Present(String attr, boolean debug) {
- this.attr = attr;
- this.debug = debug;
- }
-
- @Override
- boolean matches0(Map<String, ?> map) {
- if (debug) {
- Debug.println("PRESENT(" + attr + ")"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- return map.get(attr) != null;
- }
-
- @Override
- StringBuilder normalize(StringBuilder sb) {
- return sb.append('(').append(attr).append('=').append('*').append(')');
- }
-
- @Override
- void getAttributesInternal(List<String> results) {
- results.add(attr);
- }
-
- @Override
- void addAttributes(Map<String, String> attributes, Map<String, Range> versionAttrs, boolean not) {
- attributes.put(attr, "*"); //$NON-NLS-1$
- }
- }
-
static abstract class Item extends FilterImpl {
/** debug mode */
final boolean debug;
final String attr;
- final Object value;
- Item(String attr, Object value, boolean debug) {
+ Item(String attr, boolean debug) {
this.attr = attr;
- this.value = value;
this.debug = debug;
}
@Override
boolean matches0(Map<String, ?> map) {
- return compare(map.get(attr), value);
+ return compare(map.get(attr));
}
abstract String operation();
- private boolean compare(Object value1, Object value2) {
+ abstract String value();
+
+ private boolean compare(Object value1) {
if (debug) {
if (value1 == null) {
- Debug.println("compare(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println("compare(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} else if (!(value1.getClass().isArray() || (value1 instanceof Collection<?>))) {
- Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}
if (value1 == null) {
return false;
}
if (value1 instanceof String) {
- return compare_String((String) value1, value2);
+ return compare_String((String) value1);
}
if (value1 instanceof Version) {
- return compare_Version((Version) value1, value2);
+ return compare_Version((Version) value1);
}
Class<?> clazz = value1.getClass();
if (clazz.isArray()) {
Class<?> type = clazz.getComponentType();
if (type.isPrimitive()) {
- return compare_PrimitiveArray(type, value1, value2);
+ return compare_PrimitiveArray(type, value1);
}
- return compare_ObjectArray((Object[]) value1, value2);
+ return compare_ObjectArray((Object[]) value1);
}
if (value1 instanceof Collection<?>) {
- return compare_Collection((Collection<?>) value1, value2);
+ return compare_Collection((Collection<?>) value1);
}
if (value1 instanceof Integer) {
- return compare_Integer(((Integer) value1).intValue(), value2);
+ return compare_Integer(((Integer) value1).intValue());
}
if (value1 instanceof Long) {
- return compare_Long(((Long) value1).longValue(), value2);
+ return compare_Long(((Long) value1).longValue());
}
if (value1 instanceof Byte) {
- return compare_Byte(((Byte) value1).byteValue(), value2);
+ return compare_Byte(((Byte) value1).byteValue());
}
if (value1 instanceof Short) {
- return compare_Short(((Short) value1).shortValue(), value2);
+ return compare_Short(((Short) value1).shortValue());
}
if (value1 instanceof Character) {
- return compare_Character(((Character) value1).charValue(), value2);
+ return compare_Character(((Character) value1).charValue());
}
if (value1 instanceof Float) {
- return compare_Float(((Float) value1).floatValue(), value2);
+ return compare_Float(((Float) value1).floatValue());
}
if (value1 instanceof Double) {
- return compare_Double(((Double) value1).doubleValue(), value2);
+ return compare_Double(((Double) value1).doubleValue());
}
if (value1 instanceof Boolean) {
- return compare_Boolean(((Boolean) value1).booleanValue(), value2);
+ return compare_Boolean(((Boolean) value1).booleanValue());
}
if (value1 instanceof Comparable<?>) {
@SuppressWarnings("unchecked")
Comparable<Object> comparable = (Comparable<Object>) value1;
- return compare_Comparable(comparable, value2);
+ return compare_Comparable(comparable);
}
- return compare_Unknown(value1, value2);
+ return compare_Unknown(value1);
}
- private boolean compare_Collection(Collection<?> collection, Object value2) {
+ private boolean compare_Collection(Collection<?> collection) {
for (Object value1 : collection) {
- if (compare(value1, value2)) {
+ if (compare(value1)) {
return true;
}
}
return false;
}
- private boolean compare_ObjectArray(Object[] array, Object value2) {
+ private boolean compare_ObjectArray(Object[] array) {
for (Object value1 : array) {
- if (compare(value1, value2)) {
+ if (compare(value1)) {
return true;
}
}
return false;
}
- private boolean compare_PrimitiveArray(Class<?> type, Object primarray, Object value2) {
+ private boolean compare_PrimitiveArray(Class<?> type, Object primarray) {
if (Integer.TYPE.isAssignableFrom(type)) {
int[] array = (int[]) primarray;
for (int value1 : array) {
if (debug) {
- Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- if (compare_Integer(value1, value2)) {
+ if (compare_Integer(value1)) {
return true;
}
}
@@ -615,9 +581,9 @@ public abstract class FilterImpl implements Filter {
long[] array = (long[]) primarray;
for (long value1 : array) {
if (debug) {
- Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- if (compare_Long(value1, value2)) {
+ if (compare_Long(value1)) {
return true;
}
}
@@ -627,9 +593,9 @@ public abstract class FilterImpl implements Filter {
byte[] array = (byte[]) primarray;
for (byte value1 : array) {
if (debug) {
- Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- if (compare_Byte(value1, value2)) {
+ if (compare_Byte(value1)) {
return true;
}
}
@@ -639,9 +605,9 @@ public abstract class FilterImpl implements Filter {
short[] array = (short[]) primarray;
for (short value1 : array) {
if (debug) {
- Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- if (compare_Short(value1, value2)) {
+ if (compare_Short(value1)) {
return true;
}
}
@@ -651,9 +617,9 @@ public abstract class FilterImpl implements Filter {
char[] array = (char[]) primarray;
for (char value1 : array) {
if (debug) {
- Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- if (compare_Character(value1, value2)) {
+ if (compare_Character(value1)) {
return true;
}
}
@@ -663,9 +629,9 @@ public abstract class FilterImpl implements Filter {
float[] array = (float[]) primarray;
for (float value1 : array) {
if (debug) {
- Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- if (compare_Float(value1, value2)) {
+ if (compare_Float(value1)) {
return true;
}
}
@@ -675,9 +641,9 @@ public abstract class FilterImpl implements Filter {
double[] array = (double[]) primarray;
for (double value1 : array) {
if (debug) {
- Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- if (compare_Double(value1, value2)) {
+ if (compare_Double(value1)) {
return true;
}
}
@@ -687,9 +653,9 @@ public abstract class FilterImpl implements Filter {
boolean[] array = (boolean[]) primarray;
for (boolean value1 : array) {
if (debug) {
- Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- if (compare_Boolean(value1, value2)) {
+ if (compare_Boolean(value1)) {
return true;
}
}
@@ -698,51 +664,51 @@ public abstract class FilterImpl implements Filter {
return false;
}
- boolean compare_String(String string, Object value2) {
+ boolean compare_String(String string) {
return false;
}
- boolean compare_Version(Version value1, Object value2) {
+ boolean compare_Version(Version value1) {
return false;
}
- boolean compare_Comparable(Comparable<Object> value1, Object value2) {
+ boolean compare_Comparable(Comparable<Object> value1) {
return false;
}
- boolean compare_Unknown(Object value1, Object value2) {
+ boolean compare_Unknown(Object value1) {
return false;
}
- boolean compare_Boolean(boolean boolval, Object value2) {
+ boolean compare_Boolean(boolean boolval) {
return false;
}
- boolean compare_Byte(byte byteval, Object value2) {
+ boolean compare_Byte(byte byteval) {
return false;
}
- boolean compare_Character(char charval, Object value2) {
+ boolean compare_Character(char charval) {
return false;
}
- boolean compare_Double(double doubleval, Object value2) {
+ boolean compare_Double(double doubleval) {
return false;
}
- boolean compare_Float(float floatval, Object value2) {
+ boolean compare_Float(float floatval) {
return false;
}
- boolean compare_Integer(int intval, Object value2) {
+ boolean compare_Integer(int intval) {
return false;
}
- boolean compare_Long(long longval, Object value2) {
+ boolean compare_Long(long longval) {
return false;
}
- boolean compare_Short(short shortval, Object value2) {
+ boolean compare_Short(short shortval) {
return false;
}
@@ -774,62 +740,47 @@ public abstract class FilterImpl implements Filter {
results.add(attr);
}
- static Object valueOf(Class<?> target, String value2) {
- do {
- Method method;
- try {
- method = target.getMethod("valueOf", String.class); //$NON-NLS-1$
- } catch (NoSuchMethodException e) {
- break;
- }
- if (Modifier.isStatic(method.getModifiers()) && target.isAssignableFrom(method.getReturnType())) {
- setAccessible(method);
- try {
- return method.invoke(null, value2.trim());
- } catch (Error e) {
- throw e;
- } catch (Throwable e) {
- return null;
- }
- }
- } while (false);
-
- do {
- Constructor<?> constructor;
- try {
- constructor = target.getConstructor(String.class);
- } catch (NoSuchMethodException e) {
- break;
- }
- setAccessible(constructor);
- try {
- return constructor.newInstance(value2.trim());
- } catch (Error e) {
- throw e;
- } catch (Throwable e) {
- return null;
- }
- } while (false);
+ @Override
+ void addAttributes(Map<String, String> attributes, Map<String, Range> versionAttrs, boolean not) {
+ attributes.put(attr, value());
+ }
+ }
- return null;
+ static final class Present extends Item {
+ Present(String attr, boolean debug) {
+ super(attr, debug);
}
- private static void setAccessible(final AccessibleObject accessible) {
- if (!accessible.isAccessible()) {
- AccessController.doPrivileged(new PrivilegedAction<Void>() {
- @Override
- public Void run() {
- accessible.setAccessible(true);
- return null;
- }
- });
+ @Override
+ boolean matches0(Map<String, ?> map) {
+ if (debug) {
+ Debug.println("PRESENT(" + attr + ")"); //$NON-NLS-1$ //$NON-NLS-2$
}
+ return map.get(attr) != null;
+ }
+
+ @Override
+ String operation() {
+ return "PRESENT"; //$NON-NLS-1$
+ }
+
+ @Override
+ String value() {
+ return "*"; //$NON-NLS-1$
+ }
+
+ @Override
+ StringBuilder normalize(StringBuilder sb) {
+ return sb.append('(').append(attr).append('=').append('*').append(')');
}
}
static final class Substring extends Item {
- Substring(String attr, Object value, boolean debug) {
- super(attr, value, debug);
+ final String[] substrings;
+
+ Substring(String attr, String[] substrings, boolean debug) {
+ super(attr, debug);
+ this.substrings = substrings;
}
@Override
@@ -838,8 +789,12 @@ public abstract class FilterImpl implements Filter {
}
@Override
- boolean compare_String(String string, Object value2) {
- String[] substrings = (String[]) value2;
+ String value() {
+ return value(new StringBuilder()).toString();
+ }
+
+ @Override
+ boolean compare_String(String string) {
int pos = 0;
for (int i = 0, size = substrings.length; i < size; i++) {
String substr = substrings[i];
@@ -896,7 +851,6 @@ public abstract class FilterImpl implements Filter {
}
private StringBuilder value(StringBuilder sb) {
- String[] substrings = (String[]) value;
for (String substr : substrings) {
if (substr == null) /* * */ {
sb.append('*');
@@ -906,16 +860,14 @@ public abstract class FilterImpl implements Filter {
}
return sb;
}
-
- @Override
- void addAttributes(Map<String, String> attributes, Map<String, Range> versionAttrs, boolean not) {
- attributes.put(attr, value(new StringBuilder()).toString());
- }
}
static class Equal extends Item {
- Equal(String attr, Object value, boolean debug) {
- super(attr, value, debug);
+ final String value;
+
+ Equal(String attr, String value, boolean debug) {
+ super(attr, debug);
+ this.value = value;
}
@Override
@@ -924,15 +876,24 @@ public abstract class FilterImpl implements Filter {
}
@Override
- boolean compare_String(String string, Object value2) {
- return string.equals(value2);
+ String value() {
+ return value;
+ }
+
+ boolean comparison(int compare) {
+ return compare == 0;
+ }
+
+ @Override
+ boolean compare_String(String string) {
+ return comparison((string == value) ? 0 : string.compareTo(value));
}
@Override
- boolean compare_Version(Version value1, Object value2) {
+ boolean compare_Version(Version value1) {
try {
- Version version2 = Version.valueOf((String) value2);
- return value1.compareTo(version2) == 0;
+ Version version2 = Version.valueOf(value);
+ return comparison(value1.compareTo(version2));
} catch (Exception e) {
// if the valueOf or compareTo method throws an exception
return false;
@@ -940,85 +901,96 @@ public abstract class FilterImpl implements Filter {
}
@Override
- boolean compare_Boolean(boolean boolval, Object value2) {
- return boolval == Boolean.valueOf(((String) value2).trim()).booleanValue();
+ boolean compare_Boolean(boolean boolval) {
+ boolean boolval2 = Boolean.parseBoolean(value.trim());
+ return comparison(Boolean.compare(boolval, boolval2));
}
@Override
- boolean compare_Byte(byte byteval, Object value2) {
+ boolean compare_Byte(byte byteval) {
+ byte byteval2;
try {
- return byteval == Byte.parseByte(((String) value2).trim());
+ byteval2 = Byte.parseByte(value.trim());
} catch (IllegalArgumentException e) {
return false;
}
+ return comparison(Byte.compare(byteval, byteval2));
}
@Override
- boolean compare_Character(char charval, Object value2) {
+ boolean compare_Character(char charval) {
+ char charval2;
try {
- return charval == ((String) value2).charAt(0);
+ charval2 = value.charAt(0);
} catch (IndexOutOfBoundsException e) {
return false;
}
+ return comparison(Character.compare(charval, charval2));
}
@Override
- boolean compare_Double(double doubleval, Object value2) {
+ boolean compare_Double(double doubleval) {
double doubleval2;
try {
- doubleval2 = Double.parseDouble(((String) value2).trim());
+ doubleval2 = Double.parseDouble(value.trim());
} catch (IllegalArgumentException e) {
return false;
}
- return Double.compare(doubleval, doubleval2) == 0;
+ return comparison(Double.compare(doubleval, doubleval2));
}
@Override
- boolean compare_Float(float floatval, Object value2) {
+ boolean compare_Float(float floatval) {
float floatval2;
try {
- floatval2 = Float.parseFloat(((String) value2).trim());
+ floatval2 = Float.parseFloat(value.trim());
} catch (IllegalArgumentException e) {
return false;
}
- return Float.compare(floatval, floatval2) == 0;
+ return comparison(Float.compare(floatval, floatval2));
}
@Override
- boolean compare_Integer(int intval, Object value2) {
+ boolean compare_Integer(int intval) {
+ int intval2;
try {
- return intval == Integer.parseInt(((String) value2).trim());
+ intval2 = Integer.parseInt(value.trim());
} catch (IllegalArgumentException e) {
return false;
}
+ return comparison(Integer.compare(intval, intval2));
}
@Override
- boolean compare_Long(long longval, Object value2) {
+ boolean compare_Long(long longval) {
+ long longval2;
try {
- return longval == Long.parseLong(((String) value2).trim());
+ longval2 = Long.parseLong(value.trim());
} catch (IllegalArgumentException e) {
return false;
}
+ return comparison(Long.compare(longval, longval2));
}
@Override
- boolean compare_Short(short shortval, Object value2) {
+ boolean compare_Short(short shortval) {
+ short shortval2;
try {
- return shortval == Short.parseShort(((String) value2).trim());
+ shortval2 = Short.parseShort(value.trim());
} catch (IllegalArgumentException e) {
return false;
}
+ return comparison(Short.compare(shortval, shortval2));
}
@Override
- boolean compare_Comparable(Comparable<Object> value1, Object value2) {
- value2 = valueOf(value1.getClass(), (String) value2);
+ boolean compare_Comparable(Comparable<Object> value1) {
+ Object value2 = valueOf(value1.getClass());
if (value2 == null) {
return false;
}
try {
- return value1.compareTo(value2) == 0;
+ return comparison(value1.compareTo(value2));
} catch (Exception e) {
// if the compareTo method throws an exception; return false
return false;
@@ -1026,8 +998,8 @@ public abstract class FilterImpl implements Filter {
}
@Override
- boolean compare_Unknown(Object value1, Object value2) {
- value2 = valueOf(value1.getClass(), (String) value2);
+ boolean compare_Unknown(Object value1) {
+ Object value2 = valueOf(value1.getClass());
if (value2 == null) {
return false;
}
@@ -1042,13 +1014,65 @@ public abstract class FilterImpl implements Filter {
@Override
StringBuilder normalize(StringBuilder sb) {
sb.append('(').append(attr).append('=');
- return encodeValue(sb, (String) value).append(')');
+ return encodeValue(sb, value).append(')');
+ }
+
+ Object valueOf(Class<?> target) {
+ do {
+ Method method;
+ try {
+ method = target.getMethod("valueOf", String.class); //$NON-NLS-1$
+ } catch (NoSuchMethodException e) {
+ break;
+ }
+ if (Modifier.isStatic(method.getModifiers()) && target.isAssignableFrom(method.getReturnType())) {
+ setAccessible(method);
+ try {
+ return method.invoke(null, value.trim());
+ } catch (Error e) {
+ throw e;
+ } catch (Throwable e) {
+ return null;
+ }
+ }
+ } while (false);
+
+ do {
+ Constructor<?> constructor;
+ try {
+ constructor = target.getConstructor(String.class);
+ } catch (NoSuchMethodException e) {
+ break;
+ }
+ setAccessible(constructor);
+ try {
+ return constructor.newInstance(value.trim());
+ } catch (Error e) {
+ throw e;
+ } catch (Throwable e) {
+ return null;
+ }
+ } while (false);
+
+ return null;
+ }
+
+ private static void setAccessible(final AccessibleObject accessible) {
+ if (!accessible.isAccessible()) {
+ AccessController.doPrivileged(new PrivilegedAction<Void>() {
+ @Override
+ public Void run() {
+ accessible.setAccessible(true);
+ return null;
+ }
+ });
+ }
}
@Override
public String getPrimaryKeyValue(String primaryKey) {
- if (attr.equalsIgnoreCase(primaryKey) && (value instanceof String)) {
- return (String) value;
+ if (attr.equalsIgnoreCase(primaryKey)) {
+ return value;
}
return null;
}
@@ -1056,7 +1080,7 @@ public abstract class FilterImpl implements Filter {
@Override
void addAttributes(Map<String, String> attributes, Map<String, Range> versionAttrs, boolean not) {
if (!versionAttrs.containsKey(attr)) {
- attributes.put(attr, (String) value);
+ attributes.put(attr, value);
} else {
// this is an exact range e.g. [value,value]
Range currentRange = versionAttrs.get(attr);
@@ -1064,13 +1088,13 @@ public abstract class FilterImpl implements Filter {
if (not) {
// this is an expanded form of the filter, e.g.:
// [1.0,2.0) -> (&(version>=1.0)(version<=2.0)(!(version=2.0)))
- currentRange.addExclude(Version.valueOf((String) value));
+ currentRange.addExclude(Version.valueOf(value));
} else {
throw new IllegalStateException("Invalid range for: " + attr); //$NON-NLS-1$
}
} else {
currentRange = new Range();
- Version version = Version.valueOf((String) value);
+ Version version = Version.valueOf(value);
currentRange.setLeft('[', version);
currentRange.setRight(']', version);
versionAttrs.put(attr, currentRange);
@@ -1079,8 +1103,8 @@ public abstract class FilterImpl implements Filter {
}
}
- static final class Less extends Equal {
- Less(String attr, Object value, boolean debug) {
+ static final class LessEqual extends Equal {
+ LessEqual(String attr, String value, boolean debug) {
super(attr, value, debug);
}
@@ -1090,106 +1114,14 @@ public abstract class FilterImpl implements Filter {
}
@Override
- boolean compare_String(String string, Object value2) {
- return string.compareTo((String) value2) <= 0;
- }
-
- @Override
- boolean compare_Version(Version value1, Object value2) {
- try {
- Version version2 = Version.valueOf((String) value2);
- return value1.compareTo(version2) <= 0;
- } catch (Exception e) {
- // if the valueOf or compareTo method throws an exception
- return false;
- }
- }
-
- @Override
- boolean compare_Byte(byte byteval, Object value2) {
- try {
- return byteval <= Byte.parseByte(((String) value2).trim());
- } catch (IllegalArgumentException e) {
- return false;
- }
- }
-
- @Override
- boolean compare_Character(char charval, Object value2) {
- try {
- return charval <= ((String) value2).charAt(0);
- } catch (IndexOutOfBoundsException e) {
- return false;
- }
- }
-
- @Override
- boolean compare_Double(double doubleval, Object value2) {
- double doubleval2;
- try {
- doubleval2 = Double.parseDouble(((String) value2).trim());
- } catch (IllegalArgumentException e) {
- return false;
- }
- return Double.compare(doubleval, doubleval2) <= 0;
- }
-
- @Override
- boolean compare_Float(float floatval, Object value2) {
- float floatval2;
- try {
- floatval2 = Float.parseFloat(((String) value2).trim());
- } catch (IllegalArgumentException e) {
- return false;
- }
- return Float.compare(floatval, floatval2) <= 0;
- }
-
- @Override
- boolean compare_Integer(int intval, Object value2) {
- try {
- return intval <= Integer.parseInt(((String) value2).trim());
- } catch (IllegalArgumentException e) {
- return false;
- }
- }
-
- @Override
- boolean compare_Long(long longval, Object value2) {
- try {
- return longval <= Long.parseLong(((String) value2).trim());
- } catch (IllegalArgumentException e) {
- return false;
- }
- }
-
- @Override
- boolean compare_Short(short shortval, Object value2) {
- try {
- return shortval <= Short.parseShort(((String) value2).trim());
- } catch (IllegalArgumentException e) {
- return false;
- }
- }
-
- @Override
- boolean compare_Comparable(Comparable<Object> value1, Object value2) {
- value2 = valueOf(value1.getClass(), (String) value2);
- if (value2 == null) {
- return false;
- }
- try {
- return value1.compareTo(value2) <= 0;
- } catch (Exception e) {
- // if the compareTo method throws an exception; return false
- return false;
- }
+ boolean comparison(int compare) {
+ return compare <= 0;
}
@Override
StringBuilder normalize(StringBuilder sb) {
sb.append('(').append(attr).append('<').append('=');
- return encodeValue(sb, (String) value).append(')');
+ return encodeValue(sb, value).append(')');
}
@Override
@@ -1214,20 +1146,20 @@ public abstract class FilterImpl implements Filter {
}
if (not) {
// this must be a range start "(value"
- if (!currentRange.setLeft('(', Version.valueOf((String) value))) {
+ if (!currentRange.setLeft('(', Version.valueOf(value))) {
throw new IllegalStateException("range start is already processed for attribute: " + attr); //$NON-NLS-1$
}
} else {
// this must be a range end "value]"
- if (!currentRange.setRight(']', Version.valueOf((String) value))) {
+ if (!currentRange.setRight(']', Version.valueOf(value))) {
throw new IllegalStateException("range end is already processed for attribute: " + attr); //$NON-NLS-1$
}
}
}
}
- static final class Greater extends Equal {
- Greater(String attr, Object value, boolean debug) {
+ static final class GreaterEqual extends Equal {
+ GreaterEqual(String attr, String value, boolean debug) {
super(attr, value, debug);
}
@@ -1237,106 +1169,14 @@ public abstract class FilterImpl implements Filter {
}
@Override
- boolean compare_String(String string, Object value2) {
- return string.compareTo((String) value2) >= 0;
- }
-
- @Override
- boolean compare_Version(Version value1, Object value2) {
- try {
- Version version2 = Version.valueOf((String) value2);
- return value1.compareTo(version2) >= 0;
- } catch (Exception e) {
- // if the valueOf or compareTo method throws an exception
- return false;
- }
- }
-
- @Override
- boolean compare_Byte(byte byteval, Object value2) {
- try {
- return byteval >= Byte.parseByte(((String) value2).trim());
- } catch (IllegalArgumentException e) {
- return false;
- }
- }
-
- @Override
- boolean compare_Character(char charval, Object value2) {
- try {
- return charval >= ((String) value2).charAt(0);
- } catch (IndexOutOfBoundsException e) {
- return false;
- }
- }
-
- @Override
- boolean compare_Double(double doubleval, Object value2) {
- double doubleval2;
- try {
- doubleval2 = Double.parseDouble(((String) value2).trim());
- } catch (IllegalArgumentException e) {
- return false;
- }
- return Double.compare(doubleval, doubleval2) >= 0;
- }
-
- @Override
- boolean compare_Float(float floatval, Object value2) {
- float floatval2;
- try {
- floatval2 = Float.parseFloat(((String) value2).trim());
- } catch (IllegalArgumentException e) {
- return false;
- }
- return Float.compare(floatval, floatval2) >= 0;
- }
-
- @Override
- boolean compare_Integer(int intval, Object value2) {
- try {
- return intval >= Integer.parseInt(((String) value2).trim());
- } catch (IllegalArgumentException e) {
- return false;
- }
- }
-
- @Override
- boolean compare_Long(long longval, Object value2) {
- try {
- return longval >= Long.parseLong(((String) value2).trim());
- } catch (IllegalArgumentException e) {
- return false;
- }
- }
-
- @Override
- boolean compare_Short(short shortval, Object value2) {
- try {
- return shortval >= Short.parseShort(((String) value2).trim());
- } catch (IllegalArgumentException e) {
- return false;
- }
- }
-
- @Override
- boolean compare_Comparable(Comparable<Object> value1, Object value2) {
- value2 = valueOf(value1.getClass(), (String) value2);
- if (value2 == null) {
- return false;
- }
- try {
- return value1.compareTo(value2) >= 0;
- } catch (Exception e) {
- // if the compareTo method throws an exception; return false
- return false;
- }
+ boolean comparison(int compare) {
+ return compare >= 0;
}
@Override
StringBuilder normalize(StringBuilder sb) {
sb.append('(').append(attr).append('>').append('=');
- return encodeValue(sb, (String) value).append(')');
+ return encodeValue(sb, value).append(')');
}
@Override
@@ -1361,12 +1201,12 @@ public abstract class FilterImpl implements Filter {
}
if (not) {
// this must be a range end "value)"
- if (!currentRange.setRight(')', Version.valueOf((String) value))) {
+ if (!currentRange.setRight(')', Version.valueOf(value))) {
throw new IllegalStateException("range end is already processed for attribute: " + attr); //$NON-NLS-1$
}
} else {
// this must be a range start "[value"
- if (!currentRange.setLeft('[', Version.valueOf((String) value))) {
+ if (!currentRange.setLeft('[', Version.valueOf(value))) {
throw new IllegalStateException("range start is already processed for attribute: " + attr); //$NON-NLS-1$
}
}
@@ -1374,8 +1214,11 @@ public abstract class FilterImpl implements Filter {
}
static final class Approx extends Equal {
- Approx(String attr, Object value, boolean debug) {
+ final String approx;
+
+ Approx(String attr, String value, boolean debug) {
super(attr, value, debug);
+ this.approx = approxString(value);
}
@Override
@@ -1384,17 +1227,21 @@ public abstract class FilterImpl implements Filter {
}
@Override
- boolean compare_String(String string, Object value2) {
+ String value() {
+ return approx;
+ }
+
+ @Override
+ boolean compare_String(String string) {
string = approxString(string);
- String string2 = approxString((String) value2);
- return string.equalsIgnoreCase(string2);
+ return string.equalsIgnoreCase(approx);
}
@Override
- boolean compare_Character(char charval, Object value2) {
+ boolean compare_Character(char charval) {
char charval2;
try {
- charval2 = ((String) value2).charAt(0);
+ charval2 = approx.charAt(0);
} catch (IndexOutOfBoundsException e) {
return false;
}
@@ -1404,7 +1251,7 @@ public abstract class FilterImpl implements Filter {
@Override
StringBuilder normalize(StringBuilder sb) {
sb.append('(').append(attr).append('~').append('=');
- return encodeValue(sb, approxString((String) value)).append(')');
+ return encodeValue(sb, approx).append(')');
}
/**
@@ -1652,14 +1499,14 @@ public abstract class FilterImpl implements Filter {
case '>' : {
if (filterChars[pos + 1] == '=') {
pos += 2;
- return new FilterImpl.Greater(attr, parse_value(), debug);
+ return new FilterImpl.GreaterEqual(attr, parse_value(), debug);
}
break;
}
case '<' : {
if (filterChars[pos + 1] == '=') {
pos += 2;
- return new FilterImpl.Less(attr, parse_value(), debug);
+ return new FilterImpl.LessEqual(attr, parse_value(), debug);
}
break;
}
@@ -1675,12 +1522,19 @@ public abstract class FilterImpl implements Filter {
}
pos++;
- Object string = parse_substring();
+ String[] substrings = parse_substring();
- if (string instanceof String) {
- return new FilterImpl.Equal(attr, string, debug);
+ int length = substrings.length;
+ if (length == 0) {
+ return new FilterImpl.Equal(attr, "", debug); //$NON-NLS-1$
}
- return new FilterImpl.Substring(attr, string, debug);
+ if (length == 1) {
+ String single = substrings[0];
+ if (single != null) {
+ return new FilterImpl.Equal(attr, single, debug);
+ }
+ }
+ return new FilterImpl.Substring(attr, substrings, debug);
}
}
@@ -1750,7 +1604,7 @@ public abstract class FilterImpl implements Filter {
return sb.toString();
}
- private Object parse_substring() throws InvalidSyntaxException {
+ private String[] parse_substring() throws InvalidSyntaxException {
StringBuilder sb = new StringBuilder(filterChars.length - pos);
List<String> operands = new ArrayList<>(10);
@@ -1798,20 +1652,6 @@ public abstract class FilterImpl implements Filter {
}
}
- int size = operands.size();
-
- if (size == 0) {
- return ""; //$NON-NLS-1$
- }
-
- if (size == 1) {
- String single = operands.get(0);
-
- if (single != null) {
- return single;
- }
- }
-
return operands.toArray(new String[0]);
}

Back to the top