Skip to content

small improvements for collectionUtils#17

Closed
izebit wants to merge 3 commits intoapache:trunkfrom
izebit:trunk
Closed

small improvements for collectionUtils#17
izebit wants to merge 3 commits intoapache:trunkfrom
izebit:trunk

Conversation

@izebit
Copy link

@izebit izebit commented Jul 28, 2016

No description provided.

@coveralls
Copy link

coveralls commented Jul 28, 2016

Coverage Status

Coverage increased (+0.01%) to 85.125% when pulling 0dff24d on izebit:trunk into 1792c34 on apache:trunk.

import org.apache.commons.collections4.collection.TransformedCollection;
import org.apache.commons.collections4.collection.UnmodifiableBoundedCollection;
import org.apache.commons.collections4.collection.UnmodifiableCollection;
import org.apache.commons.collections4.collection.*;
Copy link
Member

Choose a reason for hiding this comment

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

It is preferable to leave import each class individually.

Copy link
Author

Choose a reason for hiding this comment

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

ok, i got it)

@SuppressWarnings("rawtypes") // we deliberately use the raw type here
public static final Collection EMPTY_COLLECTION =
UnmodifiableCollection.unmodifiableCollection(new ArrayList<Object>());
public static final Collection EMPTY_COLLECTION = Collections.emptyList();
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch!

Copy link
Author

Choose a reason for hiding this comment

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

:))

* @return a boolean indicating whether the collection has changed or not.
* @throws NullPointerException if the collection or iterator is null
*/
@SuppressWarnings("unchecked")
Copy link
Member

Choose a reason for hiding this comment

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

Is that necessary? I'm comparing with a local working copy of the trunk branch, looking ad the addAll method I have, it doesn't seem necessary. Perhaps it needs to be rebased and revised against last changes?

Copy link
Author

@izebit izebit May 22, 2017

Choose a reason for hiding this comment

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

Of cource, it is minor. this is not necessary, but if it is applied, warnings about not correct cast will disappear. I talked about this code: collection.addAll((Collection<? extends C>) iterable)

Copy link
Member

Choose a reason for hiding this comment

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

I might still be missing something here... Reviewing online, it didn't seem to be necessary. Just imported the code to Eclipse, and the project has 41 Warnings. This annotation being one of the warnings, being marked as "Unnecessary @SuppressWarnings("unchecked")".

Copy link
Author

Choose a reason for hiding this comment

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

Hmm, It is very interesting. My IDE, (i use intellij idea), warns me about unchecked cast. Maybe, it is a false warning. if you think that is not necessary, i will not persist :)

Copy link
Member

Choose a reason for hiding this comment

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

Removing in NetBeans (how nostalgic it was to use it) also did not raise any warnings. However, NetBeans has a lot of other warnings and errors that do not appear in Eclipse. I thought the IDE's would all agree upon what to check or not, but searching the Internet I found some other reports from differences in Eclipse/IntelliJ regarding these suppresswarnings cases. Let's leave as is for now, and we can revisit it later. So all good to be merged I believe?

screenshot_2017-05-24_11-28-05

Copy link
Author

@izebit izebit May 24, 2017

Choose a reason for hiding this comment

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

I agree with you. You are right. I had try to compile the code by javac with flag -Xlint:all and did not see any warnings. Then Intellij Idea shows false warning or the warning are not for compiler, it is more for a programmer.
Yes, all good to be merged.

P.S. Netbeans is in my heart, too :)

} else if (object instanceof Iterable<?>) {
final Iterable<?> iterable = (Iterable<?>) object;
return IterableUtils.get(iterable, i);
} else if (object instanceof Collection<?>) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this one really safe to remove? It seems to assume that the else condition will handle with the same behaviour, but I have not tested it to confirm.

Might be worth also moving that if (object == null) check to the top.

Copy link
Author

@izebit izebit May 22, 2017

Choose a reason for hiding this comment

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

Removing of this condition is safe. Moreover, this check is useless, because, any collection implements interface Iterable, and if object is Collection, then previous condition (object instanceof Iterable<?>) is true.

Copy link
Member

Choose a reason for hiding this comment

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

Nice. Will check out the code to review with the IDE, plus some coffee 💤 I think it looks good to be merged. Thanks for the quick replies @izebit

Copy link
Member

Choose a reason for hiding this comment

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

Oooohh, just re-read, and finally understood. Sorry, nice catch again.

@coveralls
Copy link

coveralls commented May 22, 2017

Coverage Status

Coverage increased (+0.03%) to 85.147% when pulling aa6b4cc on izebit:trunk into 1792c34 on apache:trunk.

Copy link
Member

@kinow kinow left a comment

Choose a reason for hiding this comment

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

All good, except one SupressWarnings that seems unnecessary?

* @return a boolean indicating whether the collection has changed or not.
* @throws NullPointerException if the collection or iterator is null
*/
@SuppressWarnings("unchecked")
Copy link
Member

Choose a reason for hiding this comment

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

I might still be missing something here... Reviewing online, it didn't seem to be necessary. Just imported the code to Eclipse, and the project has 41 Warnings. This annotation being one of the warnings, being marked as "Unnecessary @SuppressWarnings("unchecked")".

} else if (object instanceof Iterable<?>) {
final Iterable<?> iterable = (Iterable<?>) object;
return IterableUtils.get(iterable, i);
} else if (object instanceof Collection<?>) {
Copy link
Member

Choose a reason for hiding this comment

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

Oooohh, just re-read, and finally understood. Sorry, nice catch again.

@coveralls
Copy link

coveralls commented May 23, 2017

Coverage Status

Coverage increased (+0.02%) to 85.131% when pulling 9b4e2ef on izebit:trunk into 1792c34 on apache:trunk.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 85.147% when pulling 9b4e2ef on izebit:trunk into 1792c34 on apache:trunk.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 85.147% when pulling 9b4e2ef on izebit:trunk into 1792c34 on apache:trunk.

@kinow
Copy link
Member

kinow commented May 24, 2017

Placeholder to keep track of the change https://issues.apache.org/jira/browse/COLLECTIONS-603

@kinow
Copy link
Member

kinow commented May 24, 2017

Merged. Issue created/updated. changes.xml updated. All tests pass, site reports look good, nothing for CollectionUtils in PMD, CPD, FindBugs. No changes in methods signatures.

Thanks for your contribution @izebit !

@asfgit asfgit closed this in 9f0d589 May 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants