You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2017/12/06 04:21:23 UTC
[1/4] groovy git commit: Refine GPathResult's equals and hashCode
Repository: groovy
Updated Branches:
refs/heads/GROOVY_2_4_X 54c4dfd95 -> 8e7652e7a
Refine GPathResult's equals and hashCode
(cherry picked from commit 7c09249)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/a2c130f6
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/a2c130f6
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/a2c130f6
Branch: refs/heads/GROOVY_2_4_X
Commit: a2c130f6f06f73144d953086237269bbbd33c219
Parents: 54c4dfd
Author: sunlan <su...@apache.org>
Authored: Wed Dec 6 07:46:34 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Wed Dec 6 12:19:38 2017 +0800
----------------------------------------------------------------------
.../java/groovy/util/slurpersupport/GPathResult.java | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/a2c130f6/subprojects/groovy-xml/src/main/java/groovy/util/slurpersupport/GPathResult.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-xml/src/main/java/groovy/util/slurpersupport/GPathResult.java b/subprojects/groovy-xml/src/main/java/groovy/util/slurpersupport/GPathResult.java
index 5aca4b6..47dec63 100644
--- a/subprojects/groovy-xml/src/main/java/groovy/util/slurpersupport/GPathResult.java
+++ b/subprojects/groovy-xml/src/main/java/groovy/util/slurpersupport/GPathResult.java
@@ -369,10 +369,17 @@ public abstract class GPathResult extends GroovyObjectSupport implements Writabl
return this;
}
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
+ @Override
+ public int hashCode() {
+ return text().hashCode();
+ }
+
+ @Override
public boolean equals(Object obj) {
+ if (null == obj) {
+ return false;
+ }
+
return text().equals(obj.toString());
}
[3/4] groovy git commit: Minor refactoring (cherry picked from commit
64d1fc1)
Posted by su...@apache.org.
Minor refactoring
(cherry picked from commit 64d1fc1)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/6ac2f9e0
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/6ac2f9e0
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/6ac2f9e0
Branch: refs/heads/GROOVY_2_4_X
Commit: 6ac2f9e05491f04c2f81df946ad9dab3771dcbb8
Parents: bba0dd2
Author: sunlan <su...@apache.org>
Authored: Wed Dec 6 09:17:40 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Wed Dec 6 12:20:33 2017 +0800
----------------------------------------------------------------------
src/main/groovy/lang/GString.java | 48 ++++++++++++++++++++--------------
1 file changed, 29 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/6ac2f9e0/src/main/groovy/lang/GString.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/GString.java b/src/main/groovy/lang/GString.java
index 6e2a4d6..7f55862 100644
--- a/src/main/groovy/lang/GString.java
+++ b/src/main/groovy/lang/GString.java
@@ -27,8 +27,8 @@ import java.io.Serializable;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
-import java.util.ArrayList;
import java.util.Arrays;
+import java.util.LinkedList;
import java.util.List;
import java.util.regex.Pattern;
@@ -51,10 +51,12 @@ public abstract class GString extends GroovyObjectSupport implements Comparable,
* A GString containing a single empty String and no values.
*/
public static final GString EMPTY = new GString(new Object[0]) {
+ @Override
public String[] getStrings() {
return new String[]{""};
}
};
+ public static final String[] EMPTY_STRING_ARRAY = new String[0];
private Object[] values;
@@ -75,6 +77,7 @@ public abstract class GString extends GroovyObjectSupport implements Comparable,
* so that any method that can't be evaluated on this
* object will be forwarded to the toString() object instead.
*/
+ @Override
public Object invokeMethod(String name, Object args) {
try {
return super.invokeMethod(name, args);
@@ -90,28 +93,26 @@ public abstract class GString extends GroovyObjectSupport implements Comparable,
}
public GString plus(GString that) {
- List<String> stringList = new ArrayList<String>();
- List<Object> valueList = new ArrayList<Object>();
-
- stringList.addAll(Arrays.asList(getStrings()));
- valueList.addAll(Arrays.asList(getValues()));
+ List<String> stringList = new LinkedList<String>(Arrays.asList(getStrings()));
+ List<Object> valueList = new LinkedList<Object>(Arrays.asList(getValues()));
List<String> thatStrings = Arrays.asList(that.getStrings());
- if (stringList.size() > valueList.size()) {
- thatStrings = new ArrayList<String>(thatStrings);
+
+ int stringListSize = stringList.size();
+ if (stringListSize > valueList.size()) {
+ thatStrings = new LinkedList<String>(thatStrings);
// merge onto end of previous GString to avoid an empty bridging value
- String s = stringList.get(stringList.size() - 1);
- s += thatStrings.get(0);
- thatStrings.remove(0);
- stringList.set(stringList.size() - 1, s);
+ int lastIndexOfStringList = stringListSize - 1;
+ String s = stringList.get(lastIndexOfStringList);
+ s += thatStrings.remove(0);
+ stringList.set(lastIndexOfStringList, s);
}
stringList.addAll(thatStrings);
valueList.addAll(Arrays.asList(that.getValues()));
- final String[] newStrings = new String[stringList.size()];
- stringList.toArray(newStrings);
- Object[] newValues = valueList.toArray();
+ final String[] newStrings = stringList.toArray(EMPTY_STRING_ARRAY);
+ final Object[] newValues = valueList.toArray();
return new GStringImpl(newValues, newStrings);
}
@@ -149,6 +150,7 @@ public abstract class GString extends GroovyObjectSupport implements Comparable,
return values[idx];
}
+ @Override
public String toString() {
StringWriter buffer = new StringWriter();
try {
@@ -160,6 +162,7 @@ public abstract class GString extends GroovyObjectSupport implements Comparable,
return buffer.toString();
}
+ @Override
public Writer writeTo(Writer out) throws IOException {
String[] s = getStrings();
int numberOfValues = values.length;
@@ -191,6 +194,7 @@ public abstract class GString extends GroovyObjectSupport implements Comparable,
* @see groovy.lang.Buildable#build(groovy.lang.GroovyObject)
*/
+ @Override
public void build(final GroovyObject builder) {
final String[] s = getStrings();
final int numberOfValues = values.length;
@@ -205,6 +209,12 @@ public abstract class GString extends GroovyObjectSupport implements Comparable,
}
}
+ @Override
+ public int hashCode() {
+ return 37 + toString().hashCode();
+ }
+
+ @Override
public boolean equals(Object that) {
if (that instanceof GString) {
return equals((GString) that);
@@ -216,22 +226,22 @@ public abstract class GString extends GroovyObjectSupport implements Comparable,
return toString().equals(that.toString());
}
- public int hashCode() {
- return 37 + toString().hashCode();
- }
-
+ @Override
public int compareTo(Object that) {
return toString().compareTo(that.toString());
}
+ @Override
public char charAt(int index) {
return toString().charAt(index);
}
+ @Override
public int length() {
return toString().length();
}
+ @Override
public CharSequence subSequence(int start, int end) {
return toString().subSequence(start, end);
}
[2/4] groovy git commit: Close the InputStream instance
Posted by su...@apache.org.
Close the InputStream instance
(cherry picked from commit d425df3)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/bba0dd25
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/bba0dd25
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/bba0dd25
Branch: refs/heads/GROOVY_2_4_X
Commit: bba0dd25d7f5272110df198f98a70c17eed5b39b
Parents: a2c130f
Author: sunlan <su...@apache.org>
Authored: Wed Dec 6 09:13:56 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Wed Dec 6 12:20:08 2017 +0800
----------------------------------------------------------------------
src/main/org/codehaus/groovy/runtime/ProcessGroovyMethods.java | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/bba0dd25/src/main/org/codehaus/groovy/runtime/ProcessGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/ProcessGroovyMethods.java b/src/main/org/codehaus/groovy/runtime/ProcessGroovyMethods.java
index d9d26cf..02204c5 100644
--- a/src/main/org/codehaus/groovy/runtime/ProcessGroovyMethods.java
+++ b/src/main/org/codehaus/groovy/runtime/ProcessGroovyMethods.java
@@ -405,6 +405,7 @@ public class ProcessGroovyMethods extends DefaultGroovyMethodsSupport {
throw new GroovyRuntimeException("exception while reading process stream", e);
} finally {
closeWithWarning(out);
+ closeWithWarning(in);
}
}
}).start();
[4/4] groovy git commit: Minor refactoring
Posted by su...@apache.org.
Minor refactoring
(cherry picked from commit 3301d65)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/8e7652e7
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/8e7652e7
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/8e7652e7
Branch: refs/heads/GROOVY_2_4_X
Commit: 8e7652e7a7840aad5aa6d13f6f519476decd9d44
Parents: 6ac2f9e
Author: sunlan <su...@apache.org>
Authored: Wed Dec 6 11:02:25 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Wed Dec 6 12:20:42 2017 +0800
----------------------------------------------------------------------
src/main/groovy/lang/GString.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/8e7652e7/src/main/groovy/lang/GString.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/GString.java b/src/main/groovy/lang/GString.java
index 7f55862..f195e50 100644
--- a/src/main/groovy/lang/GString.java
+++ b/src/main/groovy/lang/GString.java
@@ -27,8 +27,8 @@ import java.io.Serializable;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
+import java.util.ArrayList;
import java.util.Arrays;
-import java.util.LinkedList;
import java.util.List;
import java.util.regex.Pattern;
@@ -93,14 +93,14 @@ public abstract class GString extends GroovyObjectSupport implements Comparable,
}
public GString plus(GString that) {
- List<String> stringList = new LinkedList<String>(Arrays.asList(getStrings()));
- List<Object> valueList = new LinkedList<Object>(Arrays.asList(getValues()));
+ List<String> stringList = new ArrayList<String>(Arrays.asList(getStrings()));
+ List<Object> valueList = new ArrayList<Object>(Arrays.asList(getValues()));
List<String> thatStrings = Arrays.asList(that.getStrings());
int stringListSize = stringList.size();
if (stringListSize > valueList.size()) {
- thatStrings = new LinkedList<String>(thatStrings);
+ thatStrings = new ArrayList<String>(thatStrings);
// merge onto end of previous GString to avoid an empty bridging value
int lastIndexOfStringList = stringListSize - 1;
String s = stringList.get(lastIndexOfStringList);