Skip to content

Instantly share code, notes, and snippets.

@oscarryz
Last active December 27, 2015 05:19
Show Gist options
  • Save oscarryz/7273416 to your computer and use it in GitHub Desktop.
Save oscarryz/7273416 to your computer and use it in GitHub Desktop.
//A) This
countries = ImmutableList.copyOf( Collections2.filter(
Sets.newLinkedHashSet(Iterables.concat(someCountries, someOthers)),
availableCountries));
//B) vs. That
countries = ImmutableList.copyOf(
Collections2.filter(
Sets.newLinkedHashSet(Iterables.concat(someCountries, someOthers)),
availableCountries
)
);
@karlthepagan
Copy link

// C) or this
Set<String> mergedCountries = Sets.newLinkedHashSet(Iterables.concat(someCountries, someOthers));
Collection<String> filteredCountries = Collections2.filter(mergedCountries,availableCountries);
countries = ImmutableList.copyOf(filteredCountries);

@ElderMael
Copy link

Definitively B.

But what about:

countries = ImmutableList.copyOf(
                filter( 
                     newLinkedHashSet(
                                 concat(someCountries, someOthers)
                     ), 
                     availableCountries
                )
            );

I mean, static imports remove a lot of noise.

@oscarryz
Copy link
Author

oscarryz commented Nov 2, 2013

@ElderMael with static import all the things?

countries = copyOf( 
    filter ( 
        newLinkedHashSet( concat( someCountries, someOthers ), 
        availableCountries 
     )
);

@karlthepagan Yeah, I notice it today :) mmmhhh too many temp vars... (2 haha)

Yeah, looking forward for Java 8, we should just use it the moment it is available... hahah

@ElderMael
Copy link

@oscarryz

Well... perhaps not all the things. I want to know the return type without having to backtrack to the variable declaration.

@oscarryz
Copy link
Author

oscarryz commented Nov 4, 2013

@ElderMael yeah, I like that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment