Last active
August 29, 2015 14:09
-
-
Save uggds/31ebe2b948ed60bb7eaa to your computer and use it in GitHub Desktop.
This file contains 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
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.Random; | |
import java.util.function.Predicate; | |
import java.util.stream.Collectors; | |
import java.util.stream.Stream; | |
public class BonJoviGenerator { | |
private static String name; | |
private static final String SEPARATOR = "・"; | |
private static final List<String> list = new ArrayList<String>(); | |
public static void main(String[] args) { | |
// 条件判定するラムダ式用クラス | |
Predicate<String> printBadName = (String t) -> { | |
list.add(t); | |
if (list.size() < 3) { | |
System.out.print(t + SEPARATOR); | |
return false; | |
} | |
name = String.join(SEPARATOR, list.subList(list.size() - 3, list.size())); | |
if ("ジョン・ボン・ジョヴィ".equals(name)) { | |
System.out.println(name); | |
System.out.println(list.size() + " Bon Jovis"); | |
System.out.println("_人人人人人人人人人人人人人人_"); | |
System.out.println("> You Give Love a Bad Name <"); | |
System.out.println(" ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄"); | |
return true; | |
} | |
System.out.print(name + SEPARATOR); | |
return false; | |
}; | |
List<String> data = Arrays.asList("ボ", "ン", "ジョ", "ヴィ"); | |
Random rnd = new Random(); | |
Stream.iterate(0, i -> i) | |
.map(i -> rnd.ints(0, data.size()).limit(2).mapToObj(data::get).collect(Collectors.joining())) | |
.anyMatch(s -> printBadName.test(s)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment