Permalink
Browse files

TermValueLists now have starting and ending offset support.

  • Loading branch information...
1 parent 4a48676 commit a31b44a9ddcfe3c97e2356f02c2138a2251ebb25 Joshua Hartman committed May 15, 2013
View
9 bobo-browse/src/main/java/com/browseengine/bobo/facets/data/TermCharList.java
@@ -49,16 +49,15 @@ public boolean containsWithType(char val)
}
@Override
- public int indexOf(Object o)
- {
+ public int indexOfWithOffset(Object o, int startingOffset, int endingOffset) {
char val;
if (o instanceof String)
val = parse((String)o);
else
val = (Character)o;
- char[] elements=((CharArrayList)_innerList).elements();
- return Arrays.binarySearch(elements, val);
- }
+
+ return Arrays.binarySearch(_elements, startingOffset, endingOffset, val);
+ }
@Override
public int indexOfWithType(Character val)
View
5 bobo-browse/src/main/java/com/browseengine/bobo/facets/data/TermDoubleList.java
@@ -74,15 +74,14 @@ public double getPrimitiveValue(int index)
}
@Override
- public int indexOf(Object o)
- {
+ public int indexOfWithOffset(Object o, int startingOffset, int endingOffset) {
double val = parse((String) o);
if (o instanceof String)
val = parse((String)o);
else
val = (Double)o;
double[] elements = ((DoubleArrayList) _innerList).elements();
- return Arrays.binarySearch(elements, val);
+ return Arrays.binarySearch(elements, startingOffset, endingOffset, val);
}
public int indexOf(double val)
View
7 ...-browse/src/main/java/com/browseengine/bobo/facets/data/TermFixedLengthLongArrayList.java
@@ -247,7 +247,7 @@ protected int binarySearch(long[] key, int low, int high)
while(low <= high)
{
- mid = (low+high)/2;
+ mid = low + ((high - low) >> 1);
index = mid * width;
for (i=0; i<width; ++i, ++index)
{
@@ -267,13 +267,12 @@ else if (cmp < 0)
}
@Override
- public int indexOf(Object o)
- {
+ public int indexOfWithOffset(Object o, int startingOffset, int endingOffset) {
if (withDummy)
{
if (o instanceof String)
o = parse((String)o);
- return binarySearch((long[])o, 1, _elements.length/width - 1);
+ return binarySearch((long[])o, startingOffset, endingOffset/width - 1);
}
else
{
View
5 bobo-browse/src/main/java/com/browseengine/bobo/facets/data/TermFloatList.java
@@ -74,15 +74,14 @@ public float getPrimitiveValue(int index)
}
@Override
- public int indexOf(Object o)
- {
+ public int indexOfWithOffset(Object o, int startingOffset, int endingOffset) {
float val;
if (o instanceof String)
val = parse((String) o);
else
val = (Float)o;
float[] elements = ((FloatArrayList) _innerList).elements();
- return Arrays.binarySearch(elements, val);
+ return Arrays.binarySearch(elements, startingOffset, endingOffset, val);
}
public int indexOf(float o)
View
31 bobo-browse/src/main/java/com/browseengine/bobo/facets/data/TermIntList.java
@@ -86,29 +86,6 @@ public int getPrimitiveValue(int index)
return TermIntList.VALUE_MISSING;
}
- @Override
- public int indexOf(Object o)
- {
- if (withDummy)
- {
- if (o==null) return -1;
- int val;
- if (o instanceof String)
- val = parse((String) o);
- else
- val = (Integer)o;
- return Arrays.binarySearch(_elements, 1, _elements.length, val);
- } else
- {
- int val;
- if (o instanceof String)
- val = parse((String) o);
- else
- val = (Integer)o;
- return Arrays.binarySearch(_elements, val);
- }
- }
-
public int indexOf(Integer value)
{
if (withDummy)
@@ -130,19 +107,19 @@ public int indexOf(int val)
}
@Override
- public int indexOfWithOffset(Object value, int offset)
+ public int indexOfWithOffset(Object value, int startingOffset, int endingOffset)
{
if (withDummy)
{
- if (value == null || offset >= _elements.length)
+ if (value == null)
return -1;
int val = parse(String.valueOf(value));
- return Arrays.binarySearch(_elements, offset, _elements.length, val);
+ return Arrays.binarySearch(_elements, startingOffset, endingOffset, val);
}
else
{
int val = parse(String.valueOf(value));
- return Arrays.binarySearch(_elements, offset, _elements.length, val);
+ return Arrays.binarySearch(_elements, startingOffset, endingOffset, val);
}
}
View
9 bobo-browse/src/main/java/com/browseengine/bobo/facets/data/TermLongList.java
@@ -93,6 +93,11 @@ public long getPrimitiveValue(int index)
@Override
public int indexOf(Object o)
{
+ return indexOfWithOffset(o, 0, _elements.length);
+ }
+
+ @Override
+ public int indexOfWithOffset(Object o, int startingOffset, int endingOffset) {
if (withDummy)
{
if (o==null) return -1;
@@ -101,15 +106,15 @@ public int indexOf(Object o)
val = parse((String) o);
else
val = (Long)o;
- return Arrays.binarySearch(_elements, 1, _elements.length, val);
+ return Arrays.binarySearch(_elements, startingOffset, endingOffset, val);
} else
{
long val;
if (o instanceof String)
val = parse((String) o);
else
val = (Long)o;
- return Arrays.binarySearch(_elements, val);
+ return Arrays.binarySearch(_elements, startingOffset, endingOffset, val);
}
}
View
8 bobo-browse/src/main/java/com/browseengine/bobo/facets/data/TermShortList.java
@@ -86,8 +86,7 @@ public short getPrimitiveValue(int index)
}
@Override
- public int indexOf(Object o)
- {
+ public int indexOfWithOffset(Object o, int startingOffset, int endingOffset) {
if (withDummy)
{
if (o==null) return -1;
@@ -96,17 +95,18 @@ public int indexOf(Object o)
val = parse((String) o);
else
val = (Short)o;
- return Arrays.binarySearch(_elements, 1, _elements.length, val);
+ return Arrays.binarySearch(_elements, startingOffset, endingOffset, val);
} else
{
short val;
if (o instanceof String)
val = parse((String) o);
else
val = (Short)o;
- return Arrays.binarySearch(_elements, val);
+ return Arrays.binarySearch(_elements, startingOffset, endingOffset, val);
}
}
+
public int indexOf(Short val)
{
if (withDummy)
View
37 bobo-browse/src/main/java/com/browseengine/bobo/facets/data/TermStringList.java
@@ -61,28 +61,31 @@ public String format(Object o) {
return (String)o;
}
- @Override
- public int indexOf(Object o)
- {
- if (withDummy)
- {
- if (o == null) return -1;
-
- if (o.equals("")) {
+ @Override
+ public int indexOfWithOffset(Object o, int startingOffset, int endingOffset) {
+ if (withDummy)
+ {
+ if (o == null) return -1;
+
+ if (o.equals("")) {
if (_innerList.size() > 1 && "".equals(_innerList.get(1))) {
return 1;
} else if (_innerList.size() < 2) {
return -1;
- }
- }
- return Collections.binarySearch(((ArrayList<String>)_innerList), (String)o);
- } else
- {
- return Collections.binarySearch(((ArrayList<String>)_innerList), (String)o);
- }
- }
+ }
+ }
+ ArrayList<String> stringList = (ArrayList<String>) _innerList;
+ List<String> sublist = stringList.subList(startingOffset, endingOffset);
+ return Collections.binarySearch(sublist, (String)o);
+ } else
+ {
+ ArrayList<String> stringList = (ArrayList<String>) _innerList;
+ List<String> sublist = stringList.subList(startingOffset, endingOffset);
+ return Collections.binarySearch(sublist, (String)o);
+ }
+ }
- @Override
+ @Override
public void seal() {
((ArrayList<String>)_innerList).trimToSize();
}
View
10 bobo-browse/src/main/java/com/browseengine/bobo/facets/data/TermValueList.java
@@ -104,10 +104,18 @@ public T getRawValue(int index){
public Comparable getComparableValue(int index){
return (Comparable) _innerList.get(index);
}
- abstract public int indexOf(Object o);
+
+ public int indexOf(Object o){
+ return indexOfWithOffset(o, 0, size());
+ }
public int indexOfWithOffset(Object value, int offset)
{
+ return indexOfWithOffset(value, offset, size());
+ }
+
+ public int indexOfWithOffset(Object value, int startingOffset, int endingOffset)
+ {
throw new IllegalStateException("not supported");
}

0 comments on commit a31b44a

Please sign in to comment.