summaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-04-20 18:03:51 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2017-04-20 18:03:51 +0200
commit5ead1f878f50e19b67a4d7deb7dc307b43672014 (patch)
treea7cb780d1d730dffb5d403903821237c723b0e43 /config-model
parentfb3610d6c02de6393ee5f258c329c4e56f55cc65 (diff)
Simplify with streams and ImmutableMap.of
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/content/ContentSearchCluster.java22
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/search/test/DocumentDatabaseTestCase.java11
2 files changed, 14 insertions, 19 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/ContentSearchCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/content/ContentSearchCluster.java
index f5e3bb7e55b..e97d35501be 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/content/ContentSearchCluster.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/content/ContentSearchCluster.java
@@ -264,16 +264,12 @@ public class ContentSearchCluster extends AbstractConfigProducer implements Prot
this.redundancy = redundancy;
}
- private StreamingSearchCluster findStreamingCluster(String docType) {
- for (AbstractSearchCluster sc : getClusters().values()) {
- if (sc instanceof StreamingSearchCluster) {
- StreamingSearchCluster ssc = (StreamingSearchCluster) sc;
- if (docType.equals(ssc.getSdConfig().getSearch().getName())) {
- return ssc;
- }
- }
- }
- return null;
+ private Optional<StreamingSearchCluster> findStreamingCluster(String docType) {
+ return getClusters().values().stream()
+ .filter(StreamingSearchCluster.class::isInstance)
+ .map(StreamingSearchCluster.class::cast)
+ .filter(ssc -> ssc.getSdConfig().getSearch().getName().equals(docType))
+ .findFirst();
}
@Override
@@ -286,9 +282,9 @@ public class ContentSearchCluster extends AbstractConfigProducer implements Prot
.configid(getConfigId())
.visibilitydelay(visibilityDelay)
.global(isGloballyDistributed(type));
- StreamingSearchCluster ssc = findStreamingCluster(docTypeName);
- if (ssc != null) {
- ddbB.inputdoctypename(type.getFullName().getName()).configid(ssc.getDocumentDBConfigId());
+ Optional<StreamingSearchCluster> ssc = findStreamingCluster(docTypeName);
+ if (ssc.isPresent()) {
+ ddbB.inputdoctypename(type.getFullName().getName()).configid(ssc.get().getDocumentDBConfigId());
} else if (hasIndexedCluster()) {
getIndexed().fillDocumentDBConfig(type.getFullName().getName(), ddbB);
}
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/search/test/DocumentDatabaseTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/search/test/DocumentDatabaseTestCase.java
index 9cf99dc5c9f..6d1028e13bc 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/search/test/DocumentDatabaseTestCase.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/search/test/DocumentDatabaseTestCase.java
@@ -1,6 +1,7 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.search.test;
+import com.google.common.collect.ImmutableMap;
import com.yahoo.vespa.config.search.IndexschemaConfig;
import com.yahoo.vespa.config.search.core.ProtonConfig;
import com.yahoo.vespa.config.search.RankProfilesConfig;
@@ -253,17 +254,15 @@ public class DocumentDatabaseTestCase {
@Test
public void testThatAttributesConfigIsProducedForIndexed() {
- Map<String, List<String>> expectedAttributesMap = new HashMap<>();
- expectedAttributesMap.put("type1", Arrays.asList("f2"));
assertAttributesConfigIndependentOfMode("index", Arrays.asList("type1"),
- Arrays.asList("test/search/cluster.test/type1"), expectedAttributesMap);
+ Arrays.asList("test/search/cluster.test/type1"),
+ ImmutableMap.of("type1", Arrays.asList("f2")));
}
@Test
public void testThatAttributesConfigIsProducedForStreamingForFastAccessFields() {
- Map<String, List<String>> expectedAttributesMap = new HashMap<>();
- expectedAttributesMap.put("type1", Arrays.asList("f2"));
assertAttributesConfigIndependentOfMode("streaming", Arrays.asList("type1"),
- Arrays.asList("test/search/cluster.test.type1/type1"), expectedAttributesMap);
+ Arrays.asList("test/search/cluster.test.type1/type1"),
+ ImmutableMap.of("type1", Arrays.asList("f2")));
}
@Test
public void testThatAttributesConfigIsNotProducedForStoreOnlyEvenForFastAccessFields() {