Skip to content

Commit e3bd260

Browse files
committed
minor items
1 parent fead705 commit e3bd260

1 file changed

Lines changed: 63 additions & 61 deletions

File tree

src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java

Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10700,36 +10700,36 @@ public static <K, V> Map.Entry<K, V> min(Map<K, V> self, @ClosureParams(value=Fr
1070010700
* Create a Set composed of the elements of the first Set minus the
1070110701
* elements of the given Collection.
1070210702
*
10703-
* @param self a Set object
10704-
* @param removeMe the items to remove from the Set
10705-
* @return the resulting Set
10703+
* @param self a Set
10704+
* @param removeMe the elements to exclude
10705+
* @return a new Set
1070610706
* @since 1.5.0
1070710707
*/
1070810708
@SuppressWarnings("unchecked")
1070910709
public static <T> Set<T> minus(Set<T> self, Collection<?> removeMe) {
10710-
Comparator comparator = (self instanceof SortedSet) ? ((SortedSet) self).comparator() : null;
10711-
final Set<T> ansSet = createSimilarSet(self);
10712-
ansSet.addAll(self);
10710+
Comparator comparator = self instanceof SortedSet set ? set.comparator() : null;
10711+
Set<T> answer = createSimilarSet(self);
10712+
answer.addAll(self);
1071310713
if (removeMe != null) {
1071410714
for (T o1 : self) {
1071510715
for (Object o2 : removeMe) {
1071610716
boolean areEqual = (comparator != null) ? (comparator.compare(o1, o2) == 0) : coercedEquals(o1, o2);
1071710717
if (areEqual) {
10718-
ansSet.remove(o1);
10718+
answer.remove(o1);
1071910719
}
1072010720
}
1072110721
}
1072210722
}
10723-
return ansSet;
10723+
return answer;
1072410724
}
1072510725

1072610726
/**
1072710727
* Create a Set composed of the elements of the first Set minus the
1072810728
* elements from the given Iterable.
1072910729
*
10730-
* @param self a Set object
10731-
* @param removeMe the items to remove from the Set
10732-
* @return the resulting Set
10730+
* @param self a Set
10731+
* @param removeMe the elements to exclude
10732+
* @return a new Set
1073310733
* @since 1.8.7
1073410734
*/
1073510735
public static <T> Set<T> minus(Set<T> self, Iterable<?> removeMe) {
@@ -10739,29 +10739,29 @@ public static <T> Set<T> minus(Set<T> self, Iterable<?> removeMe) {
1073910739
/**
1074010740
* Create a Set composed of the elements of the first Set minus the given element.
1074110741
*
10742-
* @param self a Set object
10743-
* @param removeMe the element to remove from the Set
10744-
* @return the resulting Set
10742+
* @param self a Set
10743+
* @param removeMe the element to exclude
10744+
* @return a new Set
1074510745
* @since 1.5.0
1074610746
*/
1074710747
@SuppressWarnings("unchecked")
1074810748
public static <T> Set<T> minus(Set<T> self, Object removeMe) {
10749-
Comparator comparator = (self instanceof SortedSet) ? ((SortedSet) self).comparator() : null;
10750-
final Set<T> ansSet = createSimilarSet(self);
10749+
Comparator comparator = self instanceof SortedSet set ? set.comparator() : null;
10750+
Set<T> answer = createSimilarSet(self);
1075110751
for (T t : self) {
10752-
boolean areEqual = (comparator != null)? (comparator.compare(t, removeMe) == 0) : coercedEquals(t, removeMe);
10753-
if (!areEqual) ansSet.add(t);
10752+
boolean areEqual = (comparator != null) ? (comparator.compare(t, removeMe) == 0) : coercedEquals(t, removeMe);
10753+
if (!areEqual) answer.add(t);
1075410754
}
10755-
return ansSet;
10755+
return answer;
1075610756
}
1075710757

1075810758
/**
1075910759
* Create a SortedSet composed of the elements of the first SortedSet minus the
1076010760
* elements of the given Collection.
1076110761
*
10762-
* @param self a SortedSet object
10763-
* @param removeMe the items to remove from the SortedSet
10764-
* @return the resulting SortedSet
10762+
* @param self a SortedSet
10763+
* @param removeMe the elements to exclude
10764+
* @return a new SortedSet
1076510765
* @since 2.4.0
1076610766
*/
1076710767
public static <T> SortedSet<T> minus(SortedSet<T> self, Collection<?> removeMe) {
@@ -10772,9 +10772,9 @@ public static <T> SortedSet<T> minus(SortedSet<T> self, Collection<?> removeMe)
1077210772
* Create a SortedSet composed of the elements of the first SortedSet minus the
1077310773
* elements of the given Iterable.
1077410774
*
10775-
* @param self a SortedSet object
10776-
* @param removeMe the items to remove from the SortedSet
10777-
* @return the resulting SortedSet
10775+
* @param self a SortedSet
10776+
* @param removeMe the elements to exclude
10777+
* @return a new SortedSet
1077810778
* @since 2.4.0
1077910779
*/
1078010780
public static <T> SortedSet<T> minus(SortedSet<T> self, Iterable<?> removeMe) {
@@ -10784,9 +10784,9 @@ public static <T> SortedSet<T> minus(SortedSet<T> self, Iterable<?> removeMe) {
1078410784
/**
1078510785
* Create a SortedSet composed of the elements of the first SortedSet minus the given element.
1078610786
*
10787-
* @param self a SortedSet object
10788-
* @param removeMe the element to remove from the SortedSet
10789-
* @return the resulting SortedSet
10787+
* @param self a SortedSet
10788+
* @param removeMe the element to exclude
10789+
* @return a new SortedSet
1079010790
* @since 2.4.0
1079110791
*/
1079210792
public static <T> SortedSet<T> minus(SortedSet<T> self, Object removeMe) {
@@ -10799,8 +10799,8 @@ public static <T> SortedSet<T> minus(SortedSet<T> self, Object removeMe) {
1079910799
* <pre class="groovyTestCase">assert [1, "a", true, true, false, 5.3] - [true, 5.3] == [1, "a", false]</pre>
1080010800
*
1080110801
* @param self a List
10802-
* @param removeMe a Collection of elements to remove
10803-
* @return a List with the given elements removed
10802+
* @param removeMe the elements to exclude
10803+
* @return a new List
1080410804
* @since 1.0
1080510805
*/
1080610806
public static <T> List<T> minus(List<T> self, Collection<?> removeMe) {
@@ -10813,8 +10813,8 @@ public static <T> List<T> minus(List<T> self, Collection<?> removeMe) {
1081310813
* <pre class="groovyTestCase">assert [1, "a", true, true, false, 5.3] - [true, 5.3] == [1, "a", false]</pre>
1081410814
*
1081510815
* @param self a Collection
10816-
* @param removeMe a Collection of elements to remove
10817-
* @return a Collection with the given elements removed
10816+
* @param removeMe the elements to exclude
10817+
* @return a new Collection
1081810818
* @since 2.4.0
1081910819
*/
1082010820
public static <T> Collection<T> minus(Collection<T> self, Collection<?> removeMe) {
@@ -10827,8 +10827,8 @@ public static <T> Collection<T> minus(Collection<T> self, Collection<?> removeMe
1082710827
* <pre class="groovyTestCase">assert [1, "a", true, true, false, 5.3] - [true, 5.3] == [1, "a", false]</pre>
1082810828
*
1082910829
* @param self a List
10830-
* @param removeMe an Iterable of elements to remove
10831-
* @return a new List with the given elements removed
10830+
* @param removeMe the elements to exclude
10831+
* @return a new List
1083210832
* @since 1.8.7
1083310833
*/
1083410834
public static <T> List<T> minus(List<T> self, Iterable<?> removeMe) {
@@ -10843,8 +10843,8 @@ public static <T> List<T> minus(List<T> self, Iterable<?> removeMe) {
1084310843
* </pre>
1084410844
*
1084510845
* @param self an Iterable
10846-
* @param removeMe an Iterable of elements to remove
10847-
* @return a new Collection with the given elements removed
10846+
* @param removeMe the elements to exclude
10847+
* @return a new Collection
1084810848
* @since 2.4.0
1084910849
*/
1085010850
public static <T> Collection<T> minus(Iterable<T> self, Iterable<?> removeMe) {
@@ -10858,10 +10858,10 @@ public static <T> Collection<T> minus(Iterable<T> self, Iterable<?> removeMe) {
1085810858
* assert ['a', 'B', 'c', 'D', 'E'].minus(['b', 'C', 'D']) { it.toLowerCase() } == ['a', 'E']
1085910859
* </pre>
1086010860
*
10861-
* @param self an Iterable
10862-
* @param removeMe an Iterable of elements to remove
10863-
* @param condition a Closure used to determine unique items
10864-
* @return a new Collection with the given elements removed
10861+
* @param self an Iterable
10862+
* @param removeMe the elements to exclude
10863+
* @param condition a Closure used to determine uniqueness
10864+
* @return a new Collection
1086510865
* @since 4.0.0
1086610866
*/
1086710867
public static <T> Collection<T> minus(Iterable<T> self, Iterable<?> removeMe, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure condition) {
@@ -10878,10 +10878,10 @@ public static <T> Collection<T> minus(Iterable<T> self, Iterable<?> removeMe, @C
1087810878
* assert ['a', 'B', 'c', 'D', 'E'].minus(['b', 'C', 'D'], {@code (i, j) -> i.toLowerCase() <=> j.toLowerCase()}) == ['a', 'E']
1087910879
* </pre>
1088010880
*
10881-
* @param self an Iterable
10882-
* @param removeMe an Iterable of elements to remove
10881+
* @param self an Iterable
10882+
* @param removeMe the elements to exclude
1088310883
* @param comparator a Comparator
10884-
* @return a new Collection with the given elements removed
10884+
* @return a new Collection
1088510885
* @since 4.0.0
1088610886
*/
1088710887
@SuppressWarnings("unchecked")
@@ -10933,9 +10933,9 @@ public static <T> Collection<T> minus(Iterable<T> self, Iterable<?> removeMe, Co
1093310933
* given element to remove.
1093410934
* <pre class="groovyTestCase">assert ["a", 5, 5, true] - 5 == ["a", true]</pre>
1093510935
*
10936-
* @param self a List object
10937-
* @param removeMe an element to remove from the List
10938-
* @return the resulting List with the given element removed
10936+
* @param self a List
10937+
* @param removeMe the element to exclude
10938+
* @return a new List
1093910939
* @since 1.0
1094010940
*/
1094110941
public static <T> List<T> minus(List<T> self, Object removeMe) {
@@ -10947,41 +10947,43 @@ public static <T> List<T> minus(List<T> self, Object removeMe) {
1094710947
* given element to remove.
1094810948
* <pre class="groovyTestCase">assert ["a", 5, 5, true] - 5 == ["a", true]</pre>
1094910949
*
10950-
* @param self an Iterable object
10951-
* @param removeMe an element to remove from the Iterable
10952-
* @return the resulting Collection with the given element removed
10950+
* @param self an Iterable
10951+
* @param removeMe an element to exclude
10952+
* @return a new Collection
1095310953
* @since 2.4.0
1095410954
*/
1095510955
public static <T> Collection<T> minus(Iterable<T> self, Object removeMe) {
10956-
Collection<T> ansList = createSimilarCollection(self);
10956+
Collection<T> answer = createSimilarCollection(self);
1095710957
for (T t : self) {
10958-
if (!coercedEquals(t, removeMe)) ansList.add(t);
10958+
if (!coercedEquals(t, removeMe)) {
10959+
answer.add(t);
10960+
}
1095910961
}
10960-
return ansList;
10962+
return answer;
1096110963
}
1096210964

1096310965
/**
1096410966
* Create a Map composed of the entries of the first map minus the
1096510967
* entries of the given map.
1096610968
*
10967-
* @param self a map object
10968-
* @param removeMe the entries to remove from the map
10969-
* @return the resulting map
10969+
* @param self a Map
10970+
* @param removeMe the entries to exclude
10971+
* @return a new Map
1097010972
* @since 1.7.4
1097110973
*/
1097210974
public static <K,V> Map<K,V> minus(Map<K,V> self, Map removeMe) {
10973-
final Map<K,V> ansMap = createSimilarMap(self);
10974-
ansMap.putAll(self);
10975+
Map<K,V> answer = createSimilarMap(self);
10976+
answer.putAll(self);
1097510977
if (removeMe != null && !removeMe.isEmpty()) {
10976-
for (Map.Entry<K, V> e1 : self.entrySet()) {
10977-
for (Object e2 : removeMe.entrySet()) {
10978+
for (var e1 : self.entrySet()) {
10979+
for (var e2 : removeMe.entrySet()) {
1097810980
if (DefaultTypeTransformation.compareEqual(e1, e2)) {
10979-
ansMap.remove(e1.getKey());
10981+
answer.remove(e1.getKey());
1098010982
}
1098110983
}
1098210984
}
1098310985
}
10984-
return ansMap;
10986+
return answer;
1098510987
}
1098610988

1098710989
/**

0 commit comments

Comments
 (0)