remove dead code

This commit is contained in:
Simon Willnauer 2013-03-31 10:19:17 +02:00
parent 2a09342405
commit b3356d9f8d
16 changed files with 31 additions and 1263 deletions

View File

@ -23,7 +23,6 @@ import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals.Docs;
import org.elasticsearch.index.fielddata.util.BytesRefArrayRef;
/**
*/
@ -212,7 +211,6 @@ public abstract class BytesValues {
public static abstract class WithOrdinals extends BytesValues {
protected final Docs ordinals;
protected final BytesRefArrayRef arrayScratch = new BytesRefArrayRef(new BytesRef[10], 0);
protected WithOrdinals(Ordinals.Docs ordinals) {
super(ordinals.isMultiValued());

View File

@ -21,7 +21,6 @@ package org.elasticsearch.index.fielddata;
import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.index.fielddata.util.GeoPointArrayRef;
/**
*/

View File

@ -19,14 +19,13 @@
package org.elasticsearch.index.fielddata.fieldcomparator;
import java.io.IOException;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.util.BytesRefArrayRef;
import java.io.IOException;
/**
* Sorts by field's natural Term sort order. All

View File

@ -21,11 +21,12 @@ package org.elasticsearch.index.fielddata.plain;
import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.DoubleArrayRef;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
import org.elasticsearch.index.fielddata.util.LongArrayRef;
/**
*/

View File

@ -26,7 +26,6 @@ import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals.Docs;
import org.elasticsearch.index.fielddata.util.BytesRefArrayRef;
/**
*/

View File

@ -21,11 +21,12 @@ package org.elasticsearch.index.fielddata.plain;
import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.DoubleArrayRef;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
import org.elasticsearch.index.fielddata.util.LongArrayRef;
/**
*/

View File

@ -21,13 +21,12 @@ package org.elasticsearch.index.fielddata.plain;
import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.geo.GeoHashUtils;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.AtomicGeoPointFieldData;
import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.GeoPointValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.GeoPointArrayRef;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
import org.elasticsearch.index.fielddata.util.StringArrayRef;
/**
*/

View File

@ -1,172 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.fielddata.util;
import com.google.common.primitives.Bytes;
import org.apache.lucene.util.ArrayUtil;
import java.util.AbstractList;
import java.util.RandomAccess;
/**
*/
public class ByteArrayRef extends AbstractList<Byte> implements RandomAccess {
public static final ByteArrayRef EMPTY = new ByteArrayRef(new byte[0]);
public byte[] values;
public int start;
public int end;
public ByteArrayRef(byte[] values) {
this(values, 0, values.length);
}
public ByteArrayRef(byte[] values, int length) {
this(values, 0, length);
}
public ByteArrayRef(byte[] values, int start, int end) {
this.values = values;
this.start = start;
this.end = end;
}
public void reset(int newLength) {
assert start == 0; // NOTE: senseless if offset != 0
end = 0;
if (values.length < newLength) {
values = new byte[ArrayUtil.oversize(newLength, 32)];
}
}
@Override
public int size() {
return end - start;
}
@Override
public boolean isEmpty() {
return size() == 0;
}
@Override
public Byte get(int index) {
assert index < size();
return values[start + index];
}
@Override
public boolean contains(Object target) {
// Overridden to prevent a ton of boxing
return (target instanceof Byte)
&& indexOf(values, (Byte) target, start, end) != -1;
}
@Override
public int indexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Byte) {
int i = indexOf(values, (Byte) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override
public int lastIndexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Byte) {
int i = lastIndexOf(values, (Byte) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override
public Byte set(int index, Byte element) {
assert index < size();
byte oldValue = values[start + index];
values[start + index] = element;
return oldValue;
}
@Override
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof ByteArrayRef) {
ByteArrayRef that = (ByteArrayRef) object;
int size = size();
if (that.size() != size) {
return false;
}
for (int i = 0; i < size; i++) {
if (values[start + i] != that.values[that.start + i]) {
return false;
}
}
return true;
}
return super.equals(object);
}
@Override
public int hashCode() {
int result = 1;
for (int i = start; i < end; i++) {
result = 31 * result + Bytes.hashCode(values[i]);
}
return result;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder(size() * 10);
builder.append('[').append(values[start]);
for (int i = start + 1; i < end; i++) {
builder.append(", ").append(values[i]);
}
return builder.append(']').toString();
}
private static int indexOf(byte[] array, byte target, int start, int end) {
for (int i = start; i < end; i++) {
if (array[i] == target) {
return i;
}
}
return -1;
}
private static int lastIndexOf(byte[] array, byte target, int start, int end) {
for (int i = end - 1; i >= start; i--) {
if (array[i] == target) {
return i;
}
}
return -1;
}
}

View File

@ -1,63 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.fielddata.util;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.BytesRef;
/**
*/
public class BytesRefArrayRef {
public static final BytesRefArrayRef EMPTY = new BytesRefArrayRef(new BytesRef[0]);
public BytesRef[] values;
public int start;
public int end;
public BytesRefArrayRef(BytesRef[] values) {
this(values, 0, values.length);
}
public BytesRefArrayRef(BytesRef[] values, int length) {
this(values, 0, length);
}
public BytesRefArrayRef(BytesRef[] values, int start, int end) {
this.values = values;
this.start = start;
this.end = end;
}
public void reset(int newLength) {
assert start == 0; // NOTE: senseless if offset != 0
end = 0;
if (values.length < newLength) {
values = new BytesRef[ArrayUtil.oversize(newLength, 32)];
}
}
public boolean isEmpty() {
return size() == 0;
}
public int size() {
return end - start;
}
}

View File

@ -1,172 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.fielddata.util;
import com.google.common.primitives.Doubles;
import org.apache.lucene.util.ArrayUtil;
import java.util.AbstractList;
import java.util.RandomAccess;
/**
*/
public class DoubleArrayRef extends AbstractList<Double> implements RandomAccess {
public static final DoubleArrayRef EMPTY = new DoubleArrayRef(new double[0]);
public double[] values;
public int start;
public int end;
public DoubleArrayRef(double[] values) {
this(values, 0, values.length);
}
public DoubleArrayRef(double[] values, int length) {
this(values, 0, length);
}
public DoubleArrayRef(double[] values, int start, int end) {
this.values = values;
this.start = start;
this.end = end;
}
public void reset(int newLength) {
assert start == 0; // NOTE: senseless if offset != 0
end = 0;
if (values.length < newLength) {
values = new double[ArrayUtil.oversize(newLength, 32)];
}
}
@Override
public int size() {
return end - start;
}
@Override
public boolean isEmpty() {
return size() == 0;
}
@Override
public Double get(int index) {
assert index < size();
return values[start + index];
}
@Override
public boolean contains(Object target) {
// Overridden to prevent a ton of boxing
return (target instanceof Double)
&& indexOf(values, (Double) target, start, end) != -1;
}
@Override
public int indexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Double) {
int i = indexOf(values, (Double) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override
public int lastIndexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Double) {
int i = lastIndexOf(values, (Double) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override
public Double set(int index, Double element) {
assert index < size();
double oldValue = values[start + index];
values[start + index] = element;
return oldValue;
}
@Override
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof DoubleArrayRef) {
DoubleArrayRef that = (DoubleArrayRef) object;
int size = size();
if (that.size() != size) {
return false;
}
for (int i = 0; i < size; i++) {
if (values[start + i] != that.values[that.start + i]) {
return false;
}
}
return true;
}
return super.equals(object);
}
@Override
public int hashCode() {
int result = 1;
for (int i = start; i < end; i++) {
result = 31 * result + Doubles.hashCode(values[i]);
}
return result;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder(size() * 10);
builder.append('[').append(values[start]);
for (int i = start + 1; i < end; i++) {
builder.append(", ").append(values[i]);
}
return builder.append(']').toString();
}
private static int indexOf(double[] array, double target, int start, int end) {
for (int i = start; i < end; i++) {
if (array[i] == target) {
return i;
}
}
return -1;
}
private static int lastIndexOf(double[] array, double target, int start, int end) {
for (int i = end - 1; i >= start; i--) {
if (array[i] == target) {
return i;
}
}
return -1;
}
}

View File

@ -1,172 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.fielddata.util;
import com.google.common.primitives.Floats;
import org.apache.lucene.util.ArrayUtil;
import java.util.AbstractList;
import java.util.RandomAccess;
/**
*/
public class FloatArrayRef extends AbstractList<Float> implements RandomAccess {
public static final FloatArrayRef EMPTY = new FloatArrayRef(new float[0]);
public float[] values;
public int start;
public int end;
public FloatArrayRef(float[] values) {
this(values, 0, values.length);
}
public FloatArrayRef(float[] values, int length) {
this(values, 0, length);
}
public FloatArrayRef(float[] values, int start, int end) {
this.values = values;
this.start = start;
this.end = end;
}
public void reset(int newLength) {
assert start == 0; // NOTE: senseless if offset != 0
end = 0;
if (values.length < newLength) {
values = new float[ArrayUtil.oversize(newLength, 32)];
}
}
@Override
public int size() {
return end - start;
}
@Override
public boolean isEmpty() {
return size() == 0;
}
@Override
public Float get(int index) {
assert index < size();
return values[start + index];
}
@Override
public boolean contains(Object target) {
// Overridden to prevent a ton of boxing
return (target instanceof Float)
&& indexOf(values, (Float) target, start, end) != -1;
}
@Override
public int indexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Float) {
int i = indexOf(values, (Float) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override
public int lastIndexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Float) {
int i = lastIndexOf(values, (Float) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override
public Float set(int index, Float element) {
assert index < size();
float oldValue = values[start + index];
values[start + index] = element;
return oldValue;
}
@Override
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof FloatArrayRef) {
FloatArrayRef that = (FloatArrayRef) object;
int size = size();
if (that.size() != size) {
return false;
}
for (int i = 0; i < size; i++) {
if (values[start + i] != that.values[that.start + i]) {
return false;
}
}
return true;
}
return super.equals(object);
}
@Override
public int hashCode() {
int result = 1;
for (int i = start; i < end; i++) {
result = 31 * result + Floats.hashCode(values[i]);
}
return result;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder(size() * 10);
builder.append('[').append(values[start]);
for (int i = start + 1; i < end; i++) {
builder.append(", ").append(values[i]);
}
return builder.append(']').toString();
}
private static int indexOf(float[] array, float target, int start, int end) {
for (int i = start; i < end; i++) {
if (array[i] == target) {
return i;
}
}
return -1;
}
private static int lastIndexOf(float[] array, float target, int start, int end) {
for (int i = end - 1; i >= start; i--) {
if (array[i] == target) {
return i;
}
}
return -1;
}
}

View File

@ -1,164 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.fielddata.util;
import org.apache.lucene.util.ArrayUtil;
import org.elasticsearch.common.geo.GeoPoint;
import java.util.AbstractList;
import java.util.RandomAccess;
/**
*/
public class GeoPointArrayRef extends AbstractList<GeoPoint> implements RandomAccess {
public static final GeoPointArrayRef EMPTY = new GeoPointArrayRef(new GeoPoint[0]);
public GeoPoint[] values;
public int start;
public int end;
public GeoPointArrayRef(GeoPoint[] values) {
this(values, 0, values.length);
}
public GeoPointArrayRef(GeoPoint[] values, int length) {
this(values, 0, length);
}
public GeoPointArrayRef(GeoPoint[] values, int start, int end) {
this.values = values;
this.start = start;
this.end = end;
for (int i = start; i < end; i++) {
this.values[i] = new GeoPoint();
}
}
public void reset(int newLength) {
assert start == 0; // NOTE: senseless if offset != 0
end = 0;
if (values.length < newLength) {
values = new GeoPoint[ArrayUtil.oversize(newLength, 32)];
for (int i = 0; i < values.length; i++) {
values[i] = new GeoPoint();
}
}
}
@Override
public int size() {
return end - start;
}
@Override
public boolean isEmpty() {
return size() != 0;
}
@Override
public GeoPoint get(int index) {
assert index >= 0 && index < size();
return values[start + index];
}
@Override
public boolean contains(Object target) {
if (!(target instanceof GeoPoint)) {
return false;
}
for (int i = start; i < end; i++) {
if (values[i].equals((GeoPoint) target)) return true;
}
return false;
}
@Override
public int indexOf(Object target) {
if (!(target instanceof GeoPoint)) {
return -1;
}
GeoPoint geoPoint = (GeoPoint) target;
for (int i = start; i < end; i++) {
if (values[i].equals(geoPoint)) return (i - start);
}
return -1;
}
@Override
public int lastIndexOf(Object target) {
if (!(target instanceof GeoPoint)) {
return -1;
}
GeoPoint geoPoint = (GeoPoint) target;
for (int i = end - 1; i >= start; i--) {
if (values[i].equals(target)) return (i - start);
}
return -1;
}
@Override
public GeoPoint set(int index, GeoPoint element) {
assert index >= 0 && index < size();
GeoPoint oldValue = values[start + index];
values[start + index] = element;
return oldValue;
}
@Override
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof GeoPointArrayRef) {
GeoPointArrayRef that = (GeoPointArrayRef) object;
int size = size();
if (that.size() != size) {
return false;
}
for (int i = 0; i < size; i++) {
if (!values[start + i].equals(that.values[that.start + i])) {
return false;
}
}
return true;
}
return super.equals(object);
}
@Override
public int hashCode() {
int result = 1;
for (int i = start; i < end; i++) {
result = 31 * result + values[i].hashCode();
}
return result;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder(size() * 10);
builder.append('[').append(values[start]);
for (int i = start + 1; i < end; i++) {
builder.append(", ").append(values[i]);
}
return builder.append(']').toString();
}
}

View File

@ -1,172 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.fielddata.util;
import com.google.common.primitives.Longs;
import org.apache.lucene.util.ArrayUtil;
import java.util.AbstractList;
import java.util.RandomAccess;
/**
*/
public class LongArrayRef extends AbstractList<Long> implements RandomAccess {
public static final LongArrayRef EMPTY = new LongArrayRef(new long[0]);
public long[] values;
public int start;
public int end;
public LongArrayRef(long[] values) {
this(values, 0, values.length);
}
public LongArrayRef(long[] values, int length) {
this(values, 0, length);
}
public LongArrayRef(long[] values, int start, int end) {
this.values = values;
this.start = start;
this.end = end;
}
public void reset(int newLength) {
assert start == 0; // NOTE: senseless if offset != 0
end = 0;
if (values.length < newLength) {
values = new long[ArrayUtil.oversize(newLength, 32)];
}
}
@Override
public int size() {
return end - start;
}
@Override
public boolean isEmpty() {
return size() == 0;
}
@Override
public Long get(int index) {
assert index < size();
return values[start + index];
}
@Override
public boolean contains(Object target) {
// Overridden to prevent a ton of boxing
return (target instanceof Long)
&& indexOf(values, (Long) target, start, end) != -1;
}
@Override
public int indexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Long) {
int i = indexOf(values, (Long) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override
public int lastIndexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Long) {
int i = lastIndexOf(values, (Long) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override
public Long set(int index, Long element) {
assert index < size();
long oldValue = values[start + index];
values[start + index] = element;
return oldValue;
}
@Override
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof LongArrayRef) {
LongArrayRef that = (LongArrayRef) object;
int size = size();
if (that.size() != size) {
return false;
}
for (int i = 0; i < size; i++) {
if (values[start + i] != that.values[that.start + i]) {
return false;
}
}
return true;
}
return super.equals(object);
}
@Override
public int hashCode() {
int result = 1;
for (int i = start; i < end; i++) {
result = 31 * result + Longs.hashCode(values[i]);
}
return result;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder(size() * 10);
builder.append('[').append(values[start]);
for (int i = start + 1; i < end; i++) {
builder.append(", ").append(values[i]);
}
return builder.append(']').toString();
}
private static int indexOf(long[] array, long target, int start, int end) {
for (int i = start; i < end; i++) {
if (array[i] == target) {
return i;
}
}
return -1;
}
private static int lastIndexOf(long[] array, long target, int start, int end) {
for (int i = end - 1; i >= start; i--) {
if (array[i] == target) {
return i;
}
}
return -1;
}
}

View File

@ -1,172 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.fielddata.util;
import com.google.common.primitives.Shorts;
import org.apache.lucene.util.ArrayUtil;
import java.util.AbstractList;
import java.util.RandomAccess;
/**
*/
public class ShortArrayRef extends AbstractList<Short> implements RandomAccess {
public static final ShortArrayRef EMPTY = new ShortArrayRef(new short[0]);
public short[] values;
public int start;
public int end;
public ShortArrayRef(short[] values) {
this(values, 0, values.length);
}
public ShortArrayRef(short[] values, int length) {
this(values, 0, length);
}
public ShortArrayRef(short[] values, int start, int end) {
this.values = values;
this.start = start;
this.end = end;
}
public void reset(int newLength) {
assert start == 0; // NOTE: senseless if offset != 0
end = 0;
if (values.length < newLength) {
values = new short[ArrayUtil.oversize(newLength, 32)];
}
}
@Override
public int size() {
return end - start;
}
@Override
public boolean isEmpty() {
return size() == 0;
}
@Override
public Short get(int index) {
assert index < size();
return values[start + index];
}
@Override
public boolean contains(Object target) {
// Overridden to prevent a ton of boxing
return (target instanceof Short)
&& indexOf(values, (Short) target, start, end) != -1;
}
@Override
public int indexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Short) {
int i = indexOf(values, (Short) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override
public int lastIndexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Short) {
int i = lastIndexOf(values, (Short) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override
public Short set(int index, Short element) {
assert index < size();
short oldValue = values[start + index];
values[start + index] = element;
return oldValue;
}
@Override
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof ShortArrayRef) {
ShortArrayRef that = (ShortArrayRef) object;
int size = size();
if (that.size() != size) {
return false;
}
for (int i = 0; i < size; i++) {
if (values[start + i] != that.values[that.start + i]) {
return false;
}
}
return true;
}
return super.equals(object);
}
@Override
public int hashCode() {
int result = 1;
for (int i = start; i < end; i++) {
result = 31 * result + Shorts.hashCode(values[i]);
}
return result;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder(size() * 10);
builder.append('[').append(values[start]);
for (int i = start + 1; i < end; i++) {
builder.append(", ").append(values[i]);
}
return builder.append(']').toString();
}
private static int indexOf(short[] array, short target, int start, int end) {
for (int i = start; i < end; i++) {
if (array[i] == target) {
return i;
}
}
return -1;
}
private static int lastIndexOf(short[] array, short target, int start, int end) {
for (int i = end - 1; i >= start; i--) {
if (array[i] == target) {
return i;
}
}
return -1;
}
}

View File

@ -1,149 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.fielddata.util;
import org.apache.lucene.util.ArrayUtil;
import java.util.AbstractList;
import java.util.RandomAccess;
/**
*/
public class StringArrayRef extends AbstractList<String> implements RandomAccess {
public static final StringArrayRef EMPTY = new StringArrayRef(new String[0]);
public String[] values;
public int start;
public int end;
public StringArrayRef(String[] values) {
this(values, 0, values.length);
}
public StringArrayRef(String[] values, int length) {
this(values, 0, length);
}
public StringArrayRef(String[] values, int start, int end) {
this.values = values;
this.start = start;
this.end = end;
}
public void reset(int newLength) {
assert start == 0; // NOTE: senseless if offset != 0
end = 0;
if (values.length < newLength) {
values = new String[ArrayUtil.oversize(newLength, 32)];
}
}
@Override
public int size() {
return end - start;
}
@Override
public boolean isEmpty() {
return size() != 0;
}
@Override
public String get(int index) {
assert index >= 0 && index < size();
return values[start + index];
}
@Override
public boolean contains(Object target) {
String sTarget = target.toString();
for (int i = start; i < end; i++) {
if (values[i].equals(sTarget)) return true;
}
return false;
}
@Override
public int indexOf(Object target) {
String sTarget = target.toString();
for (int i = start; i < end; i++) {
if (values[i].equals(sTarget)) return (i - start);
}
return -1;
}
@Override
public int lastIndexOf(Object target) {
String sTarget = target.toString();
for (int i = end - 1; i >= start; i--) {
if (values[i].equals(sTarget)) return (i - start);
}
return -1;
}
@Override
public String set(int index, String element) {
assert index >= 0 && index < size();
String oldValue = values[start + index];
values[start + index] = element;
return oldValue;
}
@Override
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof StringArrayRef) {
StringArrayRef that = (StringArrayRef) object;
int size = size();
if (that.size() != size) {
return false;
}
for (int i = 0; i < size; i++) {
if (!values[start + i].equals(that.values[that.start + i])) {
return false;
}
}
return true;
}
return super.equals(object);
}
@Override
public int hashCode() {
int result = 1;
for (int i = start; i < end; i++) {
result = 31 * result + values[i].hashCode();
}
return result;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder(size() * 10);
builder.append('[').append(values[start]);
for (int i = start + 1; i < end; i++) {
builder.append(", ").append(values[i]);
}
return builder.append(']').toString();
}
}

View File

@ -19,20 +19,28 @@
package org.elasticsearch.test.unit.index.fielddata;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.search.*;
import org.elasticsearch.index.fielddata.*;
import org.apache.lucene.search.FieldDoc;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TopFieldDocs;
import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.index.fielddata.fieldcomparator.SortMode;
import org.elasticsearch.index.fielddata.util.DoubleArrayRef;
import org.elasticsearch.index.fielddata.util.LongArrayRef;
import org.testng.annotations.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
*/
@Test