Skip to content

Commit

Permalink
OAK-8995: polish code of changed classes (patch by Fabrizio)
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1876547 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
tihom88 committed Apr 15, 2020
1 parent dba7cfb commit 80b32f5
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void contentChanged(@NotNull NodeState root, @NotNull CommitInfo info) {

@Override @NotNull
public List<QueryIndex> getQueryIndexes(NodeState nodeState) {
return ImmutableList.<QueryIndex> of(new AggregateIndex(newLuceneIndex()), newLucenePropertyIndex());
return ImmutableList.of(new AggregateIndex(newLuceneIndex()), newLucenePropertyIndex());
}

protected LuceneIndex newLuceneIndex() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import javax.management.NotCompliantMBeanException;

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -362,8 +360,7 @@ public class LuceneIndexProviderService {
private AsyncIndexesSizeStatsUpdate asyncIndexesSizeStatsUpdate;

@Activate
private void activate(BundleContext bundleContext, Map<String, ?> config)
throws NotCompliantMBeanException, IOException {
private void activate(BundleContext bundleContext, Map<String, ?> config) throws IOException {
asyncIndexesSizeStatsUpdate = new AsyncIndexesSizeStatsUpdateImpl(
PropertiesUtil.toLong(config.get(LUCENE_INDEX_STATS_UPDATE_INTERVAL),
LUCENE_INDEX_STATS_UPDATE_INTERVAL_DEFAULT) * 1000); // convert seconds to millis
Expand Down Expand Up @@ -532,7 +529,7 @@ private void registerIndexEditor(BundleContext bundleContext, IndexTracker track
editorProvider.setIndexingQueue(checkNotNull(documentQueue));
}

Dictionary<String, Object> props = new Hashtable<String, Object>();
Dictionary<String, Object> props = new Hashtable<>();
props.put("type", TYPE_LUCENE);
regs.add(bundleContext.registerService(IndexEditorProvider.class.getName(), editorProvider, props));
oakRegs.add(registerMBean(whiteboard,
Expand Down Expand Up @@ -590,14 +587,9 @@ ExecutorService getExecutorService(){

private ExecutorService createExecutor() {
ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 5, 60L, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(), new ThreadFactory() {
new LinkedBlockingQueue<>(), new ThreadFactory() {
private final AtomicInteger counter = new AtomicInteger();
private final Thread.UncaughtExceptionHandler handler = new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
log.warn("Error occurred in asynchronous processing ", e);
}
};
private final Thread.UncaughtExceptionHandler handler = (t, e) -> log.warn("Error occurred in asynchronous processing ", e);
@Override
public Thread newThread(@NotNull Runnable r) {
Thread thread = new Thread(r, createName());
Expand Down Expand Up @@ -824,7 +816,7 @@ private void registerPropertyIndexCleaner(Map<String, ?> config, BundleContext b
}

private void registerLuceneFileSystemStats(LuceneIndexFileSystemStatistics luceneIndexFSStats, long delayInSeconds) {
Map<String, Object> config = ImmutableMap.<String, Object>of(
Map<String, Object> config = ImmutableMap.of(
"scheduler.name", LuceneIndexFileSystemStatistics.class.getName()
);
oakRegs.add(scheduleWithFixedDelay(whiteboard, luceneIndexFSStats, config, delayInSeconds, false, true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ private Map<String, String> getExcerpt(Query query, Set<String> excerptFields,
final boolean requireNodeLevelExcerpt = nodeExcerptColumns.size() > 0;

int docID = doc.doc;
List<String> names = new LinkedList<String>();
List<String> names = new LinkedList<>();

for (IndexableField field : searcher.getIndexReader().document(docID).getFields()) {
String name = field.name();
Expand All @@ -643,9 +643,7 @@ private Map<String, String> getExcerpt(Query query, Set<String> excerptFields,

if (names.size() > 0) {
int[] maxPassages = new int[names.size()];
for (int i = 0; i < maxPassages.length; i++) {
maxPassages[i] = 1;
}
Arrays.fill(maxPassages, 1);
try {
Map<String, String[]> stringMap = postingsHighlighter.highlightFields(names.toArray(new String[names.size()]),
query, searcher, new int[]{docID}, maxPassages);
Expand Down Expand Up @@ -693,7 +691,7 @@ private Map<String, String> getExcerpt(Query query, Set<String> excerptFields,
}
}
} catch (InvalidTokenOffsetsException e) {
LOG.error("higlighting failed", e);
LOG.error("highlighting failed", e);
}
}
}
Expand All @@ -702,9 +700,7 @@ private Map<String, String> getExcerpt(Query query, Set<String> excerptFields,
if (requireNodeLevelExcerpt) {
String nodeExcerpt = Joiner.on("...").join(columnNameToExcerpts.values());

nodeExcerptColumns.forEach( nodeExcerptColumnName -> {
columnNameToExcerpts.put(nodeExcerptColumnName, nodeExcerpt);
});
nodeExcerptColumns.forEach( nodeExcerptColumnName -> columnNameToExcerpts.put(nodeExcerptColumnName, nodeExcerpt));
}

columnNameToExcerpts.keySet().retainAll(excerptFields);
Expand Down Expand Up @@ -806,7 +802,7 @@ private static List<OrderEntry> removeNativeSort(List<OrderEntry> original) {
if (original == null || original.isEmpty()) {
return original;
}
ArrayList<OrderEntry> result = new ArrayList<OrderEntry>();
ArrayList<OrderEntry> result = new ArrayList<>();
for(OrderEntry oe : original) {
if (!isNativeSort(oe)) {
result.add(oe);
Expand Down Expand Up @@ -852,7 +848,7 @@ private static SortField.Type toLuceneSortType(OrderEntry oe, PropertyDefinition
*/
private static LuceneRequestFacade getLuceneRequest(IndexPlan plan, IndexAugmentorFactory augmentorFactory, IndexReader reader) {
FulltextQueryTermsProvider augmentor = getIndexAgumentor(plan, augmentorFactory);
List<Query> qs = new ArrayList<Query>();
List<Query> qs = new ArrayList<>();
Filter filter = plan.getFilter();
FullTextExpression ft = filter.getFullTextConstraint();
PlanResult planResult = getPlanResult(plan);
Expand Down Expand Up @@ -898,12 +894,12 @@ private static LuceneRequestFacade getLuceneRequest(IndexPlan plan, IndexAugment
} else if (query.startsWith("spellcheck?")) {
String spellcheckQueryString = query.replace("spellcheck?", "");
if (reader != null) {
return new LuceneRequestFacade<SpellcheckHelper.SpellcheckQuery>(SpellcheckHelper.getSpellcheckQuery(spellcheckQueryString, reader));
return new LuceneRequestFacade<>(SpellcheckHelper.getSpellcheckQuery(spellcheckQueryString, reader));
}
} else if (query.startsWith("suggest?")) {
String suggestQueryString = query.replace("suggest?", "");
if (reader != null) {
return new LuceneRequestFacade<SuggestHelper.SuggestQuery>(SuggestHelper.getSuggestQuery(suggestQueryString));
return new LuceneRequestFacade<>(SuggestHelper.getSuggestQuery(suggestQueryString));
}
} else {
try {
Expand Down Expand Up @@ -979,7 +975,7 @@ public static LuceneRequestFacade<Query> performAdditionalWraps(@NotNull List<Qu
ibq.add(new MatchAllDocsQuery(), BooleanClause.Occur.SHOULD);
}
}
return new LuceneRequestFacade<Query>(qs.get(0));
return new LuceneRequestFacade<>(qs.get(0));
}
BooleanQuery bq = new BooleanQuery();
for (Query q : qs) {
Expand All @@ -992,7 +988,7 @@ public static LuceneRequestFacade<Query> performAdditionalWraps(@NotNull List<Qu
bq.add(q, MUST);
}
}
return new LuceneRequestFacade<Query>(bq);
return new LuceneRequestFacade<>(bq);
}

/**
Expand Down Expand Up @@ -1375,7 +1371,7 @@ static Query getFullTextQuery(final IndexPlan plan, FullTextExpression ft,
final PlanResult pr = getPlanResult(plan);
// a reference to the query, so it can be set in the visitor
// (a "non-local return")
final AtomicReference<Query> result = new AtomicReference<Query>();
final AtomicReference<Query> result = new AtomicReference<>();
ft.accept(new FullTextVisitor() {

@Override
Expand Down Expand Up @@ -1540,7 +1536,7 @@ private static Iterator<FulltextResultRow> mergePropertyIndexResult(IndexPlan pl
NodeStateUtils.getNode(rootState, pr.indexPath), plan.getPathPrefix(), false);
PropertyIndexResult pir = pr.getPropertyIndexResult();

FluentIterable<String> paths = null;
FluentIterable<String> paths;
if (pir != null) {
Iterable<String> queryResult = lookup.query(plan.getFilter(), pir.propertyName, pir.pr);
paths = FluentIterable.from(queryResult)
Expand Down Expand Up @@ -1632,7 +1628,7 @@ public List<Facet> getFacets(int numberOfFacets, String columnName) throws IOExc
String facetFieldName = FulltextIndex.parseFacetField(columnName);

if (facets != null) {
ImmutableList.Builder res = new ImmutableList.Builder<Facet>();
ImmutableList.Builder<Facet> res = new ImmutableList.Builder<>();
FacetResult topChildren = facets.getTopChildren(numberOfFacets, facetFieldName);

if (topChildren != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class LuceneIndexAugmentTest extends AbstractQueryTest {
private LuceneIndexNode indexNode;

@Override
protected void createTestIndexNode() throws Exception {
protected void createTestIndexNode() {
setTraversalEnabled(false);
}

Expand Down Expand Up @@ -190,7 +190,7 @@ public Iterable<Field> getAugmentedFields(String path, NodeState document, NodeS
assertEquals(TestUtil.NT_TEST, document.getName(JcrConstants.JCR_PRIMARYTYPE));
assertEquals(IndexConstants.INDEX_DEFINITIONS_NODE_TYPE,
indexDefinition.getName(JcrConstants.JCR_PRIMARYTYPE));
return Lists.<Field>newArrayList(new StringField("barbar", "1", Field.Store.NO));
return Lists.newArrayList(new StringField("barbar", "1", Field.Store.NO));
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ public void defaultSetup() throws Exception{
}

@Test
public void typeProperty() throws Exception{
public void typeProperty() {
MockOsgi.activate(service, context.bundleContext(), getDefaultConfig());
ServiceReference sr = context.bundleContext().getServiceReference(IndexEditorProvider.class.getName());
assertEquals(TYPE_LUCENE, sr.getProperty("type"));
}

@Test
public void disableOpenIndexAsync() throws Exception{
public void disableOpenIndexAsync() {
Map<String,Object> config = getDefaultConfig();
config.put("enableOpenIndexAsync", false);
MockOsgi.activate(service, context.bundleContext(), config);
Expand All @@ -175,7 +175,7 @@ public void disableOpenIndexAsync() throws Exception{
}

@Test
public void enableCopyOnWrite() throws Exception{
public void enableCopyOnWrite() {
Map<String,Object> config = getDefaultConfig();
config.put("enableCopyOnWriteSupport", true);
MockOsgi.activate(service, context.bundleContext(), config);
Expand Down Expand Up @@ -236,7 +236,7 @@ public void disableCoRCoW() throws Exception {
}

@Test
public void enablePrefetchIndexFiles() throws Exception{
public void enablePrefetchIndexFiles() {
Map<String,Object> config = getDefaultConfig();
config.put("prefetchIndexFiles", true);
MockOsgi.activate(service, context.bundleContext(), config);
Expand All @@ -248,7 +248,7 @@ public void enablePrefetchIndexFiles() throws Exception{
}

@Test
public void debugLogging() throws Exception{
public void debugLogging() {
Map<String,Object> config = getDefaultConfig();
config.put("debug", true);
MockOsgi.activate(service, context.bundleContext(), config);
Expand All @@ -258,7 +258,7 @@ public void debugLogging() throws Exception{
}

@Test
public void enableExtractedTextCaching() throws Exception{
public void enableExtractedTextCaching() {
Map<String,Object> config = getDefaultConfig();
config.put("extractedTextCacheSizeInMB", 11);
MockOsgi.activate(service, context.bundleContext(), config);
Expand All @@ -275,7 +275,7 @@ public void enableExtractedTextCaching() throws Exception{
}

@Test
public void preExtractedTextProvider() throws Exception{
public void preExtractedTextProvider() {
MockOsgi.activate(service, context.bundleContext(), getDefaultConfig());
LuceneIndexEditorProvider editorProvider =
(LuceneIndexEditorProvider) context.getService(IndexEditorProvider.class);
Expand All @@ -290,7 +290,7 @@ public void preExtractedTextProvider() throws Exception{
}

@Test
public void preExtractedProviderBindBeforeActivate() throws Exception{
public void preExtractedProviderBindBeforeActivate() {
service.bindExtractedTextProvider(mock(PreExtractedTextProvider.class));
MockOsgi.activate(service, context.bundleContext(), getDefaultConfig());
LuceneIndexEditorProvider editorProvider =
Expand All @@ -299,7 +299,7 @@ public void preExtractedProviderBindBeforeActivate() throws Exception{
}

@Test
public void alwaysUsePreExtractedCache() throws Exception{
public void alwaysUsePreExtractedCache() {
Map<String,Object> config = getDefaultConfig();
config.put("alwaysUsePreExtractedCache", "true");
MockOsgi.activate(service, context.bundleContext(), config);
Expand All @@ -309,7 +309,7 @@ public void alwaysUsePreExtractedCache() throws Exception{
}

@Test
public void booleanQuerySize() throws Exception{
public void booleanQuerySize() {
Map<String,Object> config = getDefaultConfig();
config.put("booleanClauseLimit", 4000);
MockOsgi.activate(service, context.bundleContext(), config);
Expand All @@ -318,7 +318,7 @@ public void booleanQuerySize() throws Exception{
}

@Test
public void indexDefnStorafe() throws Exception{
public void indexDefnStorafe() {
Map<String,Object> config = getDefaultConfig();
config.put("disableStoredIndexDefinition", true);
MockOsgi.activate(service, context.bundleContext(), config);
Expand Down Expand Up @@ -355,20 +355,14 @@ public void executorPoolBehaviour() throws Exception{
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);

Callable cb1 = new Callable() {
@Override
public Object call() throws Exception {
latch1.await();
return null;
}
Callable<Object> cb1 = () -> {
latch1.await();
return null;
};

Callable cb2 = new Callable() {
@Override
public Object call() throws Exception {
latch2.countDown();
return null;
}
Callable<Object> cb2 = () -> {
latch2.countDown();
return null;
};

executor.submit(cb1);
Expand All @@ -383,7 +377,7 @@ public Object call() throws Exception {


@Test
public void singleBlobPerIndexFileConfig() throws Exception {
public void singleBlobPerIndexFileConfig() {
Map<String, Object> config = getDefaultConfig();
config.put("enableSingleBlobIndexFiles", "true");
MockOsgi.activate(service, context.bundleContext(), config);
Expand Down Expand Up @@ -432,7 +426,7 @@ private void reactivate() {
}

private Map<String,Object> getDefaultConfig(){
Map<String,Object> config = new HashMap<String, Object>();
Map<String,Object> config = new HashMap<>();
config.put("localIndexDir", folder.getRoot().getAbsolutePath());
return config;
}
Expand Down
Loading

0 comments on commit 80b32f5

Please sign in to comment.