Skip to content

Instantly share code, notes, and snippets.

import org.apache.commons.beanutils.BeanUtils;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
/**
* Created by koduki on 1/30/14.
*/
public class Main {
@koduki
koduki / HelloJDK8.java
Created March 19, 2014 16:22
JDK8 リリース記念
import java.util.Arrays;
import java.util.List;
/**
*
* @author koduki
*/
public class HelloJDK8 {
/**
@koduki
koduki / Person.java
Created May 22, 2014 10:50
Java SE 8からdefault interfaceでmix-inできるか試してみたら多少小技は居るけど問題なく動きそうね。
class Person implements Compare {
public Person self(){ return this; }
public String getName(){
return "Koduki";
}
}
interface Compare<T> {
T self();
default boolean compare(T x){
@koduki
koduki / FizzBuzz.java
Created May 24, 2014 12:31
FizzBuzz Java8対応版
import java.util.stream.IntStream;
/**
*
* @author koduki
*/
public class FizzBuzz {
public static void main(String[] args) {
fizzBuzzWithOldStyle();
/**
* Ancient Style.
*/
public static void useWile() {
int i = 1;
while (i <= 100) {
if (i % 15 == 0) {
System.out.println("FizzBuzz");
} else if (i % 3 == 0) {
System.out.println("Fizz");
/**
* Lost Magic.
*/
public static void useGoto() {
int i = 1;
LOOP:
if (i <= 100) {
if (i % 15 == 0) {
System.out.println("FizzBuzz");
} else if (i % 3 == 0) {
/**
* Old Style.
*/
public static void useForLoop() {
for (int i = 1; i <= 100; i++) {
if (i % 15 == 0) {
System.out.println("FizzBuzz");
} else if (i % 3 == 0) {
System.out.println("Fizz");
} else if (i % 5 == 0) {
/**
* Java 8 New Style.
*/
public static void useStreamAPI() {
String line = IntStream.rangeClosed(1, 100).boxed()
.map(n
-> (n % 15 == 0) ? "FizzBuzz"
: (n % 3 == 0) ? "Fizz"
: (n % 5 == 0) ? "Buzz"
: n.toString())
public static void useList() {
List<String> result = fizzbuzz();
for (String x : result) {
System.out.println(x);
}
}
public static List<String> fizzbuzz() {
List<String> result = new ArrayList<>();
public static void useList() {
List<String> result = fizzbuzz(list(1, 100));
for (String x : result) {
System.out.println(x);
}
}
public static List<String> fizzbuzz(List<Integer> source) {
List<String> result = new ArrayList<>();