lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From no...@apache.org
Subject lucene-solr:branch_7x: SOLR-12892: MapWriter to use CharSequence instead of String
Date Mon, 22 Oct 2018 00:16:27 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 36ce83bc9 -> 28b75e00a


SOLR-12892: MapWriter to use CharSequence instead of String


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/28b75e00
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/28b75e00
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/28b75e00

Branch: refs/heads/branch_7x
Commit: 28b75e00a9f9bcd6ae461dbdcd77e1230f6e6d91
Parents: 36ce83b
Author: Noble Paul <noble@apache.org>
Authored: Mon Oct 22 11:14:41 2018 +1100
Committer: Noble Paul <noble@apache.org>
Committed: Mon Oct 22 11:16:10 2018 +1100

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  2 ++
 .../cloud/autoscaling/AutoScalingHandler.java   |  4 ++--
 .../org/apache/solr/update/TransactionLog.java  |  4 ++--
 .../solrj/cloud/autoscaling/PolicyHelper.java   |  4 ++--
 .../solrj/cloud/autoscaling/ReplicaInfo.java    |  2 +-
 .../solr/common/ConditionalMapWriter.java       | 20 ++++++++--------
 .../java/org/apache/solr/common/MapWriter.java  | 24 ++++++++++----------
 .../apache/solr/common/util/JavaBinCodec.java   | 16 ++++++-------
 .../apache/solr/common/util/JsonTextWriter.java |  6 ++---
 .../java/org/apache/solr/common/util/Utils.java |  8 +++----
 .../solrj/cloud/autoscaling/TestPolicy.java     |  8 +++----
 11 files changed, 50 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/28b75e00/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 48ae4fe..f397e70 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -135,6 +135,8 @@ Improvements
 * SOLR-10981: Support for stream.url or stream.file pointing to gzipped data.  It's detected
by either a content
   encoding header or file extension. (Andrew Lundgren via David Smiley, Jan H√łydahl)
 
+* SOLR-12892: MapWriter to use CharSequence instead of String (noble)
+
 ==================  7.5.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/28b75e00/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScalingHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScalingHandler.java
b/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScalingHandler.java
index 899c5cd..1ef6c26 100644
--- a/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScalingHandler.java
+++ b/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScalingHandler.java
@@ -124,8 +124,8 @@ public class AutoScalingHandler extends RequestHandlerBase implements
Permission
           autoScalingConf.writeMap(new MapWriter.EntryWriter() {
 
             @Override
-            public MapWriter.EntryWriter put(String k, Object v) throws IOException {
-              rsp.getValues().add(k, v);
+            public MapWriter.EntryWriter put(CharSequence k, Object v) {
+              rsp.getValues().add(k.toString(), v);
               return this;
             }
           });

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/28b75e00/solr/core/src/java/org/apache/solr/update/TransactionLog.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/update/TransactionLog.java b/solr/core/src/java/org/apache/solr/update/TransactionLog.java
index 9bb0878..b11f76a 100644
--- a/solr/core/src/java/org/apache/solr/update/TransactionLog.java
+++ b/solr/core/src/java/org/apache/solr/update/TransactionLog.java
@@ -107,14 +107,14 @@ public class TransactionLog implements Closeable {
     }
 
     @Override
-    public void writeExternString(String s) throws IOException {
+    public void writeExternString(CharSequence s) throws IOException {
       if (s == null) {
         writeTag(NULL);
         return;
       }
 
       // no need to synchronize globalStringMap - it's only updated before the first record
is written to the log
-      Integer idx = globalStringMap.get(s);
+      Integer idx = globalStringMap.get(s.toString());
       if (idx == null) {
         // write a normal string
         writeStr(s);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/28b75e00/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/PolicyHelper.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/PolicyHelper.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/PolicyHelper.java
index d7a7a22..3cf10df 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/PolicyHelper.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/PolicyHelper.java
@@ -203,8 +203,8 @@ public class PolicyHelper {
 
   public static MapWriter getDiagnostics(Policy.Session session) {
     List<Row> sorted = session.getSortedNodes();
-    Set<String> alreadyWritten = new HashSet<>();
-    BiPredicate<String, Object> p = dedupeKeyPredicate(alreadyWritten)
+    Set<CharSequence> alreadyWritten = new HashSet<>();
+    BiPredicate<CharSequence, Object> p = dedupeKeyPredicate(alreadyWritten)
         .and(ConditionalMapWriter.NON_NULL_VAL)
         .and((s, o) -> !(o instanceof Map) || !((Map) o).isEmpty());
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/28b75e00/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaInfo.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaInfo.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaInfo.java
index ca83ad4..9c5cf31 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaInfo.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaInfo.java
@@ -93,7 +93,7 @@ public class ReplicaInfo implements MapWriter {
 
   @Override
   public void writeMap(EntryWriter ew) throws IOException {
-    BiPredicate<String, Object> p = dedupeKeyPredicate(new HashSet<>())
+    BiPredicate<CharSequence, Object> p = dedupeKeyPredicate(new HashSet<>())
         .and(NON_NULL_VAL);
     ew.put(name, (MapWriter) ew1 -> {
       ew1.put(ZkStateReader.CORE_NAME_PROP, core, p)

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/28b75e00/solr/solrj/src/java/org/apache/solr/common/ConditionalMapWriter.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/ConditionalMapWriter.java b/solr/solrj/src/java/org/apache/solr/common/ConditionalMapWriter.java
index d351fc2..1b6b03e 100644
--- a/solr/solrj/src/java/org/apache/solr/common/ConditionalMapWriter.java
+++ b/solr/solrj/src/java/org/apache/solr/common/ConditionalMapWriter.java
@@ -23,9 +23,9 @@ import java.util.function.BiPredicate;
 
 public class ConditionalMapWriter implements MapWriter {
   private final MapWriter delegate;
-  private final BiPredicate<String, Object> predicate;
+  private final BiPredicate<CharSequence, Object> predicate;
 
-  public ConditionalMapWriter(MapWriter delegate, BiPredicate<String, Object> predicate)
{
+  public ConditionalMapWriter(MapWriter delegate, BiPredicate<CharSequence, Object>
predicate) {
     this.delegate = delegate;
     this.predicate = predicate;
   }
@@ -38,33 +38,33 @@ public class ConditionalMapWriter implements MapWriter {
     }
 
     @Override
-    public EntryWriter put(String k, Object v) throws IOException {
+    public EntryWriter put(CharSequence k, Object v) throws IOException {
       if (predicate.test(k, v)) delegate.put(k, v);
       return this;
     }
 
     @Override
-    public EntryWriter put(String k, int v) throws IOException {
+    public EntryWriter put(CharSequence k, int v) throws IOException {
       return put(k, Integer.valueOf(v));
     }
 
     @Override
-    public EntryWriter put(String k, long v) throws IOException {
+    public EntryWriter put(CharSequence k, long v) throws IOException {
       return put(k, Long.valueOf(v));
     }
 
     @Override
-    public EntryWriter put(String k, float v) throws IOException {
+    public EntryWriter put(CharSequence k, float v) throws IOException {
       return put(k, Float.valueOf(v));
     }
 
     @Override
-    public EntryWriter put(String k, double v) throws IOException {
+    public EntryWriter put(CharSequence k, double v) throws IOException {
       return put(k, Double.valueOf(v));
     }
 
     @Override
-    public EntryWriter put(String k, boolean v) throws IOException {
+    public EntryWriter put(CharSequence k, boolean v) throws IOException {
       return put(k, Boolean.valueOf(v));
     }
   }
@@ -74,9 +74,9 @@ public class ConditionalMapWriter implements MapWriter {
     if(delegate!=null) delegate.writeMap(new EntryWriterWrapper(ew));
   }
 
-  public static BiPredicate<String, Object> dedupeKeyPredicate(Set<String> keys)
{
+  public static BiPredicate<CharSequence, Object> dedupeKeyPredicate(Set<CharSequence>
keys) {
     return (k, v) -> keys.add(k);
   }
 
-  public static final BiPredicate<String, Object> NON_NULL_VAL = (s, o) -> o !=
null;
+  public static final BiPredicate<CharSequence, Object> NON_NULL_VAL = (s, o) ->
o != null;
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/28b75e00/solr/solrj/src/java/org/apache/solr/common/MapWriter.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/MapWriter.java b/solr/solrj/src/java/org/apache/solr/common/MapWriter.java
index 9edd630..d2f14d8 100644
--- a/solr/solrj/src/java/org/apache/solr/common/MapWriter.java
+++ b/solr/solrj/src/java/org/apache/solr/common/MapWriter.java
@@ -44,7 +44,7 @@ public interface MapWriter extends MapSerializable {
     try {
       writeMap(new EntryWriter() {
         @Override
-        public EntryWriter put(String k, Object v) {
+        public EntryWriter put(CharSequence k, Object v) {
           if (v instanceof MapWriter) v = ((MapWriter) v).toMap(new LinkedHashMap<>());
           if (v instanceof IteratorWriter) v = ((IteratorWriter) v).toList(new ArrayList<>());
           if (v instanceof Iterable) {
@@ -66,7 +66,7 @@ public interface MapWriter extends MapSerializable {
             }
             v = map;
           }
-          map.put(k, v);
+          map.put(k==null? null : k.toString(), v);
           // note: It'd be nice to assert that there is no previous value at 'k' but it's
possible the passed in
           // map is already populated and the intention is to overwrite.
           return this;
@@ -139,8 +139,8 @@ public interface MapWriter extends MapSerializable {
      * @param k The key
      * @param v The value can be any supported object
      */
-    EntryWriter put(String k, Object v) throws IOException;
-    default EntryWriter putNoEx(String k, Object v) {
+    EntryWriter put(CharSequence k, Object v) throws IOException;
+    default EntryWriter putNoEx(CharSequence k, Object v) {
       try {
         put(k,v);
       } catch (IOException e) {
@@ -149,45 +149,45 @@ public interface MapWriter extends MapSerializable {
       return this;
     }
 
-    default EntryWriter put(String k, Object v, BiPredicate<String, Object> p) throws
IOException {
+    default EntryWriter put(CharSequence k, Object v, BiPredicate<CharSequence, Object>
p) throws IOException {
       if (p.test(k,v)) put(k, v);
       return this;
     }
 
-    default EntryWriter putIfNotNull(String k, Object v) throws IOException {
+    default EntryWriter putIfNotNull(CharSequence k, Object v) throws IOException {
       if(v != null) put(k,v);
       return this;
     }
 
-    default EntryWriter putStringIfNotNull(String k, Object v) throws IOException {
+    default EntryWriter putStringIfNotNull(CharSequence k, Object v) throws IOException {
       if(v != null) put(k,String.valueOf(v));
       return this;
     }
 
 
-    default EntryWriter put(String k, int v) throws IOException {
+    default EntryWriter put(CharSequence k, int v) throws IOException {
       put(k, (Integer) v);
       return this;
     }
 
 
-    default EntryWriter put(String k, long v) throws IOException {
+    default EntryWriter put(CharSequence k, long v) throws IOException {
       put(k, (Long) v);
       return this;
     }
 
 
-    default EntryWriter put(String k, float v) throws IOException {
+    default EntryWriter put(CharSequence k, float v) throws IOException {
       put(k, (Float) v);
       return this;
     }
 
-    default EntryWriter put(String k, double v) throws IOException {
+    default EntryWriter put(CharSequence k, double v) throws IOException {
       put(k, (Double) v);
       return this;
     }
 
-    default EntryWriter put(String k, boolean v) throws IOException {
+    default EntryWriter put(CharSequence k, boolean v) throws IOException {
       put(k, (Boolean) v);
       return this;
     }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/28b75e00/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java b/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
index 8f86e4c..4435e18 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
@@ -405,42 +405,42 @@ public class JavaBinCodec implements PushWriter {
 
   private final MapWriter.EntryWriter ew = new MapWriter.EntryWriter() {
     @Override
-    public MapWriter.EntryWriter put(String k, Object v) throws IOException {
+    public MapWriter.EntryWriter put(CharSequence k, Object v) throws IOException {
       writeExternString(k);
       JavaBinCodec.this.writeVal(v);
       return this;
     }
 
     @Override
-    public MapWriter.EntryWriter put(String k, int v) throws IOException {
+    public MapWriter.EntryWriter put(CharSequence k, int v) throws IOException {
       writeExternString(k);
       JavaBinCodec.this.writeInt(v);
       return this;
     }
 
     @Override
-    public MapWriter.EntryWriter put(String k, long v) throws IOException {
+    public MapWriter.EntryWriter put(CharSequence k, long v) throws IOException {
       writeExternString(k);
       JavaBinCodec.this.writeLong(v);
       return this;
     }
 
     @Override
-    public MapWriter.EntryWriter put(String k, float v) throws IOException {
+    public MapWriter.EntryWriter put(CharSequence k, float v) throws IOException {
       writeExternString(k);
       JavaBinCodec.this.writeFloat(v);
       return this;
     }
 
     @Override
-    public MapWriter.EntryWriter put(String k, double v) throws IOException {
+    public MapWriter.EntryWriter put(CharSequence k, double v) throws IOException {
       writeExternString(k);
       JavaBinCodec.this.writeDouble(v);
       return this;
     }
 
     @Override
-    public MapWriter.EntryWriter put(String k, boolean v) throws IOException {
+    public MapWriter.EntryWriter put(CharSequence k, boolean v) throws IOException {
       writeExternString(k);
       writeBoolean(v);
       return this;
@@ -1062,7 +1062,7 @@ public class JavaBinCodec implements PushWriter {
   private Map<String, Integer> stringsMap;
   private List<String> stringsList;
 
-  public void writeExternString(String s) throws IOException {
+  public void writeExternString(CharSequence s) throws IOException {
     if (s == null) {
       writeTag(NULL);
       return;
@@ -1073,7 +1073,7 @@ public class JavaBinCodec implements PushWriter {
     if (idx == 0) {
       writeStr(s);
       if (stringsMap == null) stringsMap = new HashMap<>();
-      stringsMap.put(s, ++stringsCount);
+      stringsMap.put(s.toString(), ++stringsCount);
     }
 
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/28b75e00/solr/solrj/src/java/org/apache/solr/common/util/JsonTextWriter.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/JsonTextWriter.java b/solr/solrj/src/java/org/apache/solr/common/util/JsonTextWriter.java
index e176bd1..ed8c797 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/JsonTextWriter.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/JsonTextWriter.java
@@ -165,15 +165,15 @@ public interface JsonTextWriter extends TextWriter {
       boolean isFirst = true;
 
       @Override
-      public MapWriter.EntryWriter put(String k, Object v) throws IOException {
+      public MapWriter.EntryWriter put(CharSequence k, Object v) throws IOException {
         if (isFirst) {
           isFirst = false;
         } else {
           JsonTextWriter.this.writeMapSeparator();
         }
         JsonTextWriter.this.indent();
-        JsonTextWriter.this.writeKey(k, true);
-        writeVal(k, v);
+        JsonTextWriter.this.writeKey(k.toString(), true);
+        writeVal(k.toString(), v);
         return this;
       }
     });

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/28b75e00/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
index 095ef57..bdfd03e 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
@@ -123,7 +123,7 @@ public class Utils {
       try {
         m.writeMap(new MapWriter.EntryWriter() {
           @Override
-          public MapWriter.EntryWriter put(String k, Object v) {
+          public MapWriter.EntryWriter put(CharSequence k, Object v) {
             fun.accept(k, v);
             return this;
           }
@@ -471,8 +471,8 @@ public class Utils {
 
   }
 
-  static class MapWriterEntry<V> extends AbstractMap.SimpleEntry<String, V> implements
MapWriter, Map.Entry<String, V> {
-    MapWriterEntry(String key, V value) {
+  static class MapWriterEntry<V> extends AbstractMap.SimpleEntry<CharSequence, V>
implements MapWriter, Map.Entry<CharSequence, V> {
+    MapWriterEntry(CharSequence key, V value) {
       super(key, value);
     }
 
@@ -495,7 +495,7 @@ public class Utils {
         ((MapWriter) obj).writeMap(new MapWriter.EntryWriter() {
           int count = -1;
           @Override
-          public MapWriter.EntryWriter put(String k, Object v) {
+          public MapWriter.EntryWriter put(CharSequence k, Object v) {
             if (result[0] != null) return this;
             if (idx < 0) {
               if (k.equals(key)) result[0] = v;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/28b75e00/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
index 64ba357..7b32567 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
@@ -2661,8 +2661,8 @@ public class TestPolicy extends SolrTestCaseJ4 {
     Set<String> writtenKeys = new HashSet<>();
     policy.writeMap(new MapWriter.EntryWriter() {
       @Override
-      public MapWriter.EntryWriter put(String k, Object v) throws IOException {
-        writtenKeys.add(k);
+      public MapWriter.EntryWriter put(CharSequence k, Object v) throws IOException {
+        writtenKeys.add(k.toString());
         return this;
       }
     });
@@ -2679,8 +2679,8 @@ public class TestPolicy extends SolrTestCaseJ4 {
     assertEquals(policy.getClusterPreferences().size(), defaultPreferences.size());
     policy.writeMap(new MapWriter.EntryWriter() {
       @Override
-      public MapWriter.EntryWriter put(String k, Object v) throws IOException {
-        writtenKeys.add(k);
+      public MapWriter.EntryWriter put(CharSequence k, Object v) throws IOException {
+        writtenKeys.add(k.toString());
         return this;
       }
     });


Mime
View raw message