mirror of https://github.com/apache/lucene.git
LUCENE-10158: Add a new interface Unwrappable to the utils package to ease migration to new MMAPDirectory and its testing (#369)
This commit is contained in:
parent
6f232b6f4b
commit
c94aca7e5d
|
@ -157,6 +157,10 @@ API Changes
|
||||||
|
|
||||||
* LUCENE-9325: Sort is now final, and the `setSort()` method has been removed (Alan Woodward)
|
* LUCENE-9325: Sort is now final, and the `setSort()` method has been removed (Alan Woodward)
|
||||||
|
|
||||||
|
* LUCENE-10158: Add a new interface Unwrappable to the utils package to allow code to
|
||||||
|
unwrap wrappers/delegators that are added by Lucene's testing framework. This will allow
|
||||||
|
testing new MMapDirectory implementation based on JDK Project Panama. (Uwe Schindler)
|
||||||
|
|
||||||
Improvements
|
Improvements
|
||||||
|
|
||||||
* LUCENE-10139: ExternalRefSorter returns a covariant with a subtype of BytesRefIterator
|
* LUCENE-10139: ExternalRefSorter returns a covariant with a subtype of BytesRefIterator
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF 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.apache.lucene.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An object with this interface is a wrapper around another object (e.g., a filter with a
|
||||||
|
* delegate). The method {@link #unwrap()} can be called to get the wrapped object
|
||||||
|
*
|
||||||
|
* @lucene.internal
|
||||||
|
*/
|
||||||
|
public interface Unwrappable<T> {
|
||||||
|
|
||||||
|
/** Unwraps this instance */
|
||||||
|
T unwrap();
|
||||||
|
|
||||||
|
/** Unwraps all {@code Unwrappable}s around the given object. */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T> T unwrapAll(T o) {
|
||||||
|
while (o instanceof Unwrappable) {
|
||||||
|
o = ((Unwrappable<T>) o).unwrap();
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,12 +29,13 @@ import java.nio.file.WatchKey;
|
||||||
import java.nio.file.WatchService;
|
import java.nio.file.WatchService;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import org.apache.lucene.util.SuppressForbidden;
|
import org.apache.lucene.util.SuppressForbidden;
|
||||||
|
import org.apache.lucene.util.Unwrappable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@code FilterPath} contains another {@code Path}, which it uses as its basic source of data,
|
* A {@code FilterPath} contains another {@code Path}, which it uses as its basic source of data,
|
||||||
* possibly transforming the data along the way or providing additional functionality.
|
* possibly transforming the data along the way or providing additional functionality.
|
||||||
*/
|
*/
|
||||||
public class FilterPath implements Path {
|
public class FilterPath implements Path, Unwrappable<Path> {
|
||||||
|
|
||||||
/** The underlying {@code Path} instance. */
|
/** The underlying {@code Path} instance. */
|
||||||
protected final Path delegate;
|
protected final Path delegate;
|
||||||
|
@ -63,6 +64,11 @@ public class FilterPath implements Path {
|
||||||
return delegate;
|
return delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path unwrap() {
|
||||||
|
return delegate;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileSystem getFileSystem() {
|
public FileSystem getFileSystem() {
|
||||||
return fileSystem;
|
return fileSystem;
|
||||||
|
@ -261,10 +267,7 @@ public class FilterPath implements Path {
|
||||||
* @return innermost Path instance
|
* @return innermost Path instance
|
||||||
*/
|
*/
|
||||||
public static Path unwrap(Path path) {
|
public static Path unwrap(Path path) {
|
||||||
while (path instanceof FilterPath) {
|
return Unwrappable.unwrapAll(path);
|
||||||
path = ((FilterPath) path).delegate;
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Override this to customize the return wrapped path from various operations */
|
/** Override this to customize the return wrapped path from various operations */
|
||||||
|
|
Loading…
Reference in New Issue