Class Util
- java.lang.Object
-
- org.apache.jackrabbit.core.query.lucene.Util
-
public class Util extends Object
Util
provides various static utility methods.
-
-
Constructor Summary
Constructors Constructor Description Util()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
closeOrRelease(IndexReader reader)
Depending on the type of thereader
this method either closes or releases the reader.static int
compare(Comparable<?>[] c1, Comparable<?>[] c2)
Compares two arrays of Comparable(s) in the same style ascompare(Value[], Value[])
.static int
compare(Comparable c1, Comparable c2)
Compares valuesc1
andc2
.static int
compare(Value[] a, Value[] b)
Compares two arrays of Value(s) in the same style ascompare(Comparable[], Comparable[])
.static int
compare(Value v1, Value v2)
Compares the two values.static IOException
createIOException(Throwable t)
Creates anIOException
witht
as its cause.static Query
createMatchAllQuery(String name, IndexFormatVersion version, org.apache.jackrabbit.core.query.lucene.PerQueryCache cache)
Depending on the index format this method returns a query that matches all nodes that have a property with a givenname
.static Pattern
createRegexp(String likePattern)
Creates a regexp fromlikePattern
.static void
disposeDocument(Document old)
Disposes the documentold
.static Comparable
getComparable(Value value)
Returns a comparable for the internalvalue
.static Comparable
getComparable(InternalValue value)
Returns a comparable for the internalvalue
.static long
getLength(InternalValue value)
Returns length of the internal value.static boolean
isDocumentReady(Document doc)
Returnstrue
if the document is ready to be added to the index.
-
-
-
Method Detail
-
disposeDocument
public static void disposeDocument(Document old)
Disposes the documentold
. Closes any potentially open readers held by the document.- Parameters:
old
- the document to dispose.
-
isDocumentReady
public static boolean isDocumentReady(Document doc)
Returnstrue
if the document is ready to be added to the index. That is all text extractors have finished their work.- Parameters:
doc
- the document to check.- Returns:
true
if the document is ready;false
otherwise.
-
createMatchAllQuery
public static Query createMatchAllQuery(String name, IndexFormatVersion version, org.apache.jackrabbit.core.query.lucene.PerQueryCache cache)
Depending on the index format this method returns a query that matches all nodes that have a property with a givenname
.- Parameters:
name
- the property name.version
- the index format version.- Returns:
- Query that matches all nodes that have a property with the given
name
.
-
createIOException
public static IOException createIOException(Throwable t)
Creates anIOException
witht
as its cause.- Parameters:
t
- the cause.
-
closeOrRelease
public static void closeOrRelease(IndexReader reader) throws IOException
Depending on the type of thereader
this method either closes or releases the reader. The reader is released if it implementsReleaseableIndexReader
.- Parameters:
reader
- the index reader to close or release.- Throws:
IOException
- if an error occurs while closing or releasing the index reader.
-
getComparable
public static Comparable getComparable(InternalValue value) throws RepositoryException
Returns a comparable for the internalvalue
.- Parameters:
value
- an internal value.- Returns:
- a comparable for the given
value
. - Throws:
RepositoryException
- if retrieving theComparable
fails.
-
getComparable
public static Comparable getComparable(Value value) throws ValueFormatException, RepositoryException
Returns a comparable for the internalvalue
.- Parameters:
value
- an internal value.- Returns:
- a comparable for the given
value
. - Throws:
ValueFormatException
- if the givenvalue
cannot be converted into a comparable (i.e. unsupported type).RepositoryException
- if an error occurs while converting the value.
-
compare
public static int compare(Comparable c1, Comparable c2)
Compares valuesc1
andc2
. If the values have differing types, then the order is defined on the type itself by callingcompareTo()
on the respective type class names.- Parameters:
c1
- the first value.c2
- the second value.- Returns:
- a negative integer if
c1
should come beforec2
a positive integer ifc1
should come afterc2
0
if they are equal.
-
compare
public static int compare(Comparable<?>[] c1, Comparable<?>[] c2)
Compares two arrays of Comparable(s) in the same style ascompare(Value[], Value[])
. The 2 methods *have* to work in the same way for the sort to be consistent
-
compare
public static int compare(Value[] a, Value[] b) throws RepositoryException
Compares two arrays of Value(s) in the same style ascompare(Comparable[], Comparable[])
. The 2 methods *have* to work in the same way for the sort to be consistent- Throws:
RepositoryException
-
compare
public static int compare(Value v1, Value v2) throws ValueFormatException, RepositoryException
Compares the two values. If the values have differing types, then an attempt is made to convert the second value into the type of the first value.Comparison of binary values is not supported.
- Parameters:
v1
- the first value.v2
- the second value.- Returns:
- result of the comparison as specified in
Comparable.compareTo(Object)
. - Throws:
ValueFormatException
- if the givenvalue
cannot be converted into a comparable (i.e. unsupported type).RepositoryException
- if an error occurs while converting the value.
-
createRegexp
public static Pattern createRegexp(String likePattern)
Creates a regexp fromlikePattern
.- Parameters:
likePattern
- the pattern.- Returns:
- the regular expression
Pattern
.
-
getLength
public static long getLength(InternalValue value)
Returns length of the internal value.- Parameters:
value
- a value.- Returns:
- the length of the internal value or
-1
if the length cannot be determined.
-
-