Created
November 7, 2012 18:36
-
-
Save vladimirdlc/4033473 to your computer and use it in GitHub Desktop.
Transform a List from a type into another type List using Guava. Practical example.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final List<State> states = new ArrayList<State>(); | |
final int n = 10; | |
for (int i = 0; i < n; i++) { | |
final State state = new State(i, DeliveryReceiptState.ACCEPTD); | |
states.add(state); | |
} | |
final List<Status<DeliveryReceiptState>> statuses = Lists.transform( | |
states, new Function<State, Status<DeliveryReceiptState>>() { | |
@Override | |
public Status<DeliveryReceiptState> apply(final State input) { | |
final Status<DeliveryReceiptState> status = new Status<DeliveryReceiptState>( | |
input.getId(), input.getDeliveryReceiptState()); | |
return status; | |
} | |
}); | |
for (final Status<DeliveryReceiptState> status : statuses) { | |
System.out.println(status); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment