Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved some methods in CharSeq, Vector, TreeSet and HashSet classes… #2208

Merged
merged 3 commits into from
Feb 17, 2018

Conversation

NataliiaPrivezentseva
Copy link
Contributor

… using Collections.isEmpty(Iterable) method (#1958)

Copy link
Contributor

@danieldietrich danieldietrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Nataliia, many thanks for you PR :)
I think we should revert two methods, please see my comments.

@ruslansennov is Collections.isEmpty(...) GWT compatible? It internally uses instanceof but I think it is supported.

@@ -494,11 +494,10 @@ private HashSet(HashArrayMappedTrie<T, T> tree) {
final HashSet<T> set = (HashSet<T>) elements;
return set;
}
final HashArrayMappedTrie<T, T> that = addAll(tree, elements);
if (that.size() == tree.size()) {
if (Collections.isEmpty(elements) || this.equals(elements)){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new way is only better when this HashSet and the elements are equal but it adds an overhead for all other cases. Please restore the previous version.

@@ -532,17 +532,16 @@
@Override
public TreeSet<T> addAll(Iterable<? extends T> elements) {
Objects.requireNonNull(elements, "elements is null");
if (Collections.isEmpty(elements) || this.equals(elements)){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A TreeSet is a SortedSet. We can't check for equality here because insertion depends on the underlying Comparator. Please restore the previous version.

@danieldietrich
Copy link
Contributor

🤔 Interestingly the CI tests failed both Java 8 and Java 9 for two Euler tests... Maybe the upcoming changes will heal them again.

@NataliiaPrivezentseva
Copy link
Contributor Author

Thanks for comments! I'll revert those two methods. However it won't heal the problem with test (it is in Vector.ofAll() method). I have an idea, how to fix it.

@ruslansennov
Copy link
Member

@danieldietrich @NataliiaPrivezentseva it is compatible

@danieldietrich
Copy link
Contributor

Thx!

@ruslansennov
Copy link
Member

Sorry, I posted a non-relevant link :( Here we use vavr.collection.Collections class but not implementation of java.util.Collections.

But all is OK, this test works fine, I checked it

package io.vavr.collection;

import com.google.gwt.junit.client.GWTTestCase;

public class CollTestGwt extends GWTTestCase {

    public void testCollectionsIsEmpty() {
        List<Integer> list = List.of(42);
        assertFalse(Collections.isEmpty(list));
    }

    @Override
    public String getModuleName() {
        return "TestModule";
    }
}

@codecov-io
Copy link

Codecov Report

Merging #2208 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2208      +/-   ##
============================================
+ Coverage     97.15%   97.16%   +<.01%     
- Complexity     5270     5273       +3     
============================================
  Files            93       93              
  Lines         12145    12155      +10     
  Branches       1593     1595       +2     
============================================
+ Hits          11800    11810      +10     
  Misses          191      191              
  Partials        154      154
Impacted Files Coverage Δ Complexity Δ
vavr/src/main/java/io/vavr/collection/Vector.java 99.69% <100%> (ø) 212 <0> (+2) ⬆️
vavr/src/main/java/io/vavr/collection/CharSeq.java 99.82% <100%> (ø) 349 <0> (+1) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b6b5b1a...9f27c82. Read the comment docs.

@danieldietrich
Copy link
Contributor

Thanks for the changes and sorry for the delay!!

@danieldietrich danieldietrich merged commit f25ad46 into vavr-io:master Feb 17, 2018
danieldietrich pushed a commit that referenced this pull request Jan 6, 2019
#2208)

* Improved some methods in CharSeq, Vector, TreeSet and HashSet classes using Collections.isEmpty(Iterable) method (#1958)

* Reverted changes in addAll(Iterable) methods in TreeSet and HashSet classes

* Fixed ofAll(Iterable) method in Vector class in order to pass Euler67 and Euler18 tests
@danieldietrich danieldietrich modified the milestones: v1.0.0, v0.9.3 Jan 7, 2019
danieldietrich pushed a commit that referenced this pull request Jan 13, 2019
#2208)

* Improved some methods in CharSeq, Vector, TreeSet and HashSet classes using Collections.isEmpty(Iterable) method (#1958)

* Reverted changes in addAll(Iterable) methods in TreeSet and HashSet classes

* Fixed ofAll(Iterable) method in Vector class in order to pass Euler67 and Euler18 tests
danieldietrich pushed a commit that referenced this pull request Jan 13, 2019
#2208)

* Improved some methods in CharSeq, Vector, TreeSet and HashSet classes using Collections.isEmpty(Iterable) method (#1958)

* Reverted changes in addAll(Iterable) methods in TreeSet and HashSet classes

* Fixed ofAll(Iterable) method in Vector class in order to pass Euler67 and Euler18 tests
danieldietrich pushed a commit that referenced this pull request Jan 16, 2019
#2208)

* Improved some methods in CharSeq, Vector, TreeSet and HashSet classes using Collections.isEmpty(Iterable) method (#1958)

* Reverted changes in addAll(Iterable) methods in TreeSet and HashSet classes

* Fixed ofAll(Iterable) method in Vector class in order to pass Euler67 and Euler18 tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants