Created
May 11, 2018 08:19
-
-
Save mcupak/a77b8b64b41864d55957fe2150697cba to your computer and use it in GitHub Desktop.
Session notes from the Clean code with Java 9 talk at Geecon Krakow 2018.
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
1+1 | |
int x = 1+1 | |
System.out.println(x) | |
Thread.sleep(2000) | |
/vars | |
/types | |
/list | |
/l | |
/help | |
Set<String> set = new HashSet<String>() | |
set.add("a") | |
set.add("b") | |
set.add("c") | |
Collections.unmodifiableSet(set) | |
List<Integer> list = List.of(1,2,3) | |
list.add(4) | |
list.getClass() | |
Map.ofEntries(entry(1, "hello")) | |
/open readfile.jsh | |
/l readFile | |
/ed readFile | |
readFile("/tmp/geecon.txt") | |
new FileInputStream("/tmp/geecon.txt").transferTo(System.out) | |
/open myinterface.jsh | |
/l MyInterface | |
/op myclass.jsh | |
/l MyClass | |
new MyClass().abstractMethod() | |
new MyClass().defaultMethod() | |
/ed MyInterface | |
new MyClass().defaultMethod() | |
new MyClass().privateMethod() | |
/open diamond.jsh | |
/l | |
/ed helloSupplier | |
helloSupplier.get() | |
IntStream.iterate(0, i -> i+2).filter(j -> j<100).forEach(System.out::println) | |
IntStream.iterate(0, i -> i+2).limit(50).forEach(System.out::println) | |
IntStream.iterate(0, i -> i+2).takeWhile(j -> j<100).forEach(System.out::println) | |
IntStream.iterate(0, i -> i<100, i -> i+2).forEach(System.out::println) | |
Stream.of(1) | |
Stream.of(null) | |
Stream.ofNullable(null) | |
Stream.ofNullable(null).count() | |
Optional.empty() | |
Optional.of("something") | |
Optional.of("something").ifPresent(System.out::println) | |
Optional.of("something").ifPresentOrElse(System.out::println, () -> System.out.println("empty")) | |
Optional.empty().ifPresentOrElse(System.out::println, () -> System.out.println("empty")) | |
Optional.empty().orElse("empty") | |
Optional.empty().orElseGet(() -> "empty") | |
Optional.empty().or(() -> Optional.of("empty")) | |
Optional.empty().stream().forEach(System.out::println) | |
Optional.of("something").stream().forEach(System.out::println) | |
List.of(Optional.of(1), Optional.empty(), Optional.of(2)).stream().filter(Optional::isPresent).map(Optional::get).forEach(System.out::println) | |
List.of(Optional.of(1), Optional.empty(), Optional.of(2)).stream().flatMap(Optional::stream).forEach(System.out::println) | |
StackTraceElement[] st = new Throwable().getStackTrace() | |
st | |
StackWalker.getInstance().walk(s -> s.collect(toList())) | |
StackWalker.getInstance().walk(s -> s.limit(3).collect(toList())) | |
StackWalker.getInstance(Option.RETAIN_CLASS_REFERENCE).walk(s -> s.map(f -> f.getDeclaringClass()).collect(toList())) | |
StackWalker.getInstance(Option.RETAIN_CLASS_REFERENCE).walk(s -> s.map(f -> f.getDeclaringClass()).filter(c -> c.equals(jdk.jshell.execution.Util.class)).collect(toList())) | |
HttpHandler handler = he -> { | |
String body = "hello geecon"; | |
he.sendResponseHeaders(200, body.length()); | |
try (OutputStream os = he.getResponseBody()) { | |
os.write(body.getBytes()); | |
} | |
} | |
/l | |
HttpServer hs = HttpServer.create(new InetSocketAddress(8000), 0) | |
hs.createContext("/hello", handler) | |
hs.start() | |
URI uri = new URI("http://localhost:8000/hello") | |
HttpURLConnection c = (HttpURLConnection) uri.toURL().openConnection() | |
c.setRequestMethod("GET") | |
c.getResponseCode() | |
new BufferedReader(new InputStreamReader(c.getInputStream())).readLine() | |
HttpClient client = HttpClient.newHttpClient() | |
HttpRequest request = HttpRequest.newBuilder().uri(uri).GET().build() | |
HttpResponse<String> response = client.send(request, BodyHandler.asString()) | |
response.statusCode() | |
response.body() | |
CompletableFuture<HttpResponse<String>> response = client.sendAsync(request, BodyHandler.asString()) | |
response.get().body() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment