Skip to content

Instantly share code, notes, and snippets.

@yyYank
Last active August 29, 2015 14:27
Show Gist options
  • Save yyYank/80cc962af055c78b41dd to your computer and use it in GitHub Desktop.
Save yyYank/80cc962af055c78b41dd to your computer and use it in GitHub Desktop.
ダイヤモンドオペレータでいけタワー(JUnit使えよという)
import java.util.*;
import java.util.stream.*;
public class Test {
public static void main(String... args) {
new Test().test();
}
public void test() {
List<HogeBean> hogeList = createStub();
List<Pair<String, String>> pairList = hogeList.stream()
.map(h -> new Pair<>(h.getName(), h.getValue()))
.collect(Collectors.toList());
pairList.stream().forEach(p -> System.out.println(p.getKey() + ":" + p.getValue()));
}
private List<HogeBean> createStub() {
List<HogeBean> hogeList = new ArrayList<>();
hogeList.add(new HogeBean("a", "あ"));
hogeList.add(new HogeBean("b", "い"));
hogeList.add(new HogeBean("c", "う"));
hogeList.add(new HogeBean("d", "え"));
return hogeList;
}
private class HogeBean {
private String name;
private String value;
HogeBean(String name, String value) {
this.name = name;
this.value = value;
}
public String getName() {
return this.name;
}
public String getValue() {
return this.value;
}
}
private class Pair <K, V> {
private K key;
private V value;
Pair(K key, V value) {
this.key = key;
this.value = value;
}
public K getKey() {
return this.key;
}
public V getValue() {
return this.value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment