From c20209e651ebcd421467e6de8c18748bcc467181 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 22 Jul 2015 22:43:50 +0300 Subject: [PATCH] Rewrite with lambdas some more code --- .../classlib/java/nio/TByteBufferImpl.java | 16 +-- teavm-jso/src/main/java/org/teavm/jso/JS.java | 48 ++++---- .../teavm/jso/plugin/JSNativeGenerator.java | 6 +- .../jso/plugin/JavascriptNativeProcessor.java | 7 +- .../NativeJavascriptClassRepository.java | 14 +-- .../plugin/AnnotationDependencySupport.java | 29 ++--- .../platform/plugin/AsyncMethodGenerator.java | 27 ++--- .../plugin/ClassLookupDependencySupport.java | 20 ++-- .../plugin/EnumDependencySupport.java | 18 ++- .../plugin/NewInstanceDependencySupport.java | 11 +- .../platform/plugin/PlatformGenerator.java | 2 +- .../java/org/teavm/samples/video/Player.java | 104 +++--------------- 12 files changed, 95 insertions(+), 207 deletions(-) diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TByteBufferImpl.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TByteBufferImpl.java index 62441e072..b33cbbf70 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TByteBufferImpl.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TByteBufferImpl.java @@ -264,9 +264,9 @@ class TByteBufferImpl extends TByteBuffer { int d = array[start + position + 3] & 0xFF; position += 4; if (order == TByteOrder.BIG_ENDIAN) { - return (int)((a << 24) | (b << 16) | (c << 8) | d); + return (a << 24) | (b << 16) | (c << 8) | d; } else { - return (int)((d << 24) | (c << 16) | (b << 8) | a); + return (d << 24) | (c << 16) | (b << 8) | a; } } @@ -302,9 +302,9 @@ class TByteBufferImpl extends TByteBuffer { int c = array[start + index + 2] & 0xFF; int d = array[start + index + 3] & 0xFF; if (order == TByteOrder.BIG_ENDIAN) { - return (int)((a << 24) | (b << 16) | (c << 8) | d); + return (a << 24) | (b << 16) | (c << 8) | d; } else { - return (int)((d << 24) | (c << 16) | (b << 8) | a); + return (d << 24) | (c << 16) | (b << 8) | a; } } @@ -355,9 +355,9 @@ class TByteBufferImpl extends TByteBuffer { long h = array[start + position + 7] & 0xFF; position += 8; if (order == TByteOrder.BIG_ENDIAN) { - return (long)((a << 56) | (b << 48) | (c << 40) | (d << 32) | (e << 24) | (f << 16) | (g << 8) | h); + return (a << 56) | (b << 48) | (c << 40) | (d << 32) | (e << 24) | (f << 16) | (g << 8) | h; } else { - return (long)((h << 56) | (g << 48) | (f << 40) | (e << 32) | (d << 24) | (c << 16) | (b << 8) | a); + return (h << 56) | (g << 48) | (f << 40) | (e << 32) | (d << 24) | (c << 16) | (b << 8) | a; } } @@ -406,9 +406,9 @@ class TByteBufferImpl extends TByteBuffer { long h = array[start + index + 7] & 0xFF; position += 8; if (order == TByteOrder.BIG_ENDIAN) { - return (long)((a << 56) | (b << 48) | (c << 40) | (d << 32) | (e << 24) | (f << 16) | (g << 8) | h); + return (a << 56) | (b << 48) | (c << 40) | (d << 32) | (e << 24) | (f << 16) | (g << 8) | h; } else { - return (long)((h << 56) | (g << 48) | (f << 40) | (e << 32) | (d << 24) | (c << 16) | (b << 8) | a); + return (h << 56) | (g << 48) | (f << 40) | (e << 32) | (d << 24) | (c << 16) | (b << 8) | a; } } diff --git a/teavm-jso/src/main/java/org/teavm/jso/JS.java b/teavm-jso/src/main/java/org/teavm/jso/JS.java index 3ca2a1d76..d76f1f34f 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/JS.java +++ b/teavm-jso/src/main/java/org/teavm/jso/JS.java @@ -515,39 +515,31 @@ public final class JS { JSObject c, JSObject d, JSObject e, JSObject f, JSObject g, JSObject h); public static Iterable iterate(final JSArrayReader array) { - return new Iterable() { - @Override public Iterator iterator() { - return new Iterator() { - int index; - @Override public boolean hasNext() { - return index < array.getLength(); - } - @Override public T next() { - return array.get(index++); - } - @Override public void remove() { - throw new UnsupportedOperationException(); - } - }; + return () -> new Iterator() { + int index; + @Override public boolean hasNext() { + return index < array.getLength(); + } + @Override public T next() { + return array.get(index++); + } + @Override public void remove() { + throw new UnsupportedOperationException(); } }; } public static Iterable iterate(final JSStringArrayReader array) { - return new Iterable() { - @Override public Iterator iterator() { - return new Iterator() { - int index; - @Override public boolean hasNext() { - return index < array.getLength(); - } - @Override public String next() { - return array.get(index++); - } - @Override public void remove() { - throw new UnsupportedOperationException(); - } - }; + return () -> new Iterator() { + int index; + @Override public boolean hasNext() { + return index < array.getLength(); + } + @Override public String next() { + return array.get(index++); + } + @Override public void remove() { + throw new UnsupportedOperationException(); } }; } diff --git a/teavm-jso/src/main/java/org/teavm/jso/plugin/JSNativeGenerator.java b/teavm-jso/src/main/java/org/teavm/jso/plugin/JSNativeGenerator.java index d88acf320..01a71db0a 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/plugin/JSNativeGenerator.java +++ b/teavm-jso/src/main/java/org/teavm/jso/plugin/JSNativeGenerator.java @@ -166,11 +166,7 @@ public class JSNativeGenerator implements Injector, DependencyPlugin, Generator case "instantiate": case "function": for (int i = 0; i < method.getReference().parameterCount(); ++i) { - method.getVariable(i).addConsumer(new DependencyConsumer() { - @Override public void consume(DependencyType type) { - achieveFunctorMethods(agent, type.getName(), method); - } - }); + method.getVariable(i).addConsumer(type -> achieveFunctorMethods(agent, type.getName(), method)); } break; case "unwrapString": diff --git a/teavm-jso/src/main/java/org/teavm/jso/plugin/JavascriptNativeProcessor.java b/teavm-jso/src/main/java/org/teavm/jso/plugin/JavascriptNativeProcessor.java index c866ee8d6..951107d38 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/plugin/JavascriptNativeProcessor.java +++ b/teavm-jso/src/main/java/org/teavm/jso/plugin/JavascriptNativeProcessor.java @@ -115,7 +115,7 @@ class JavascriptNativeProcessor { return null; } Map methods = new HashMap<>(); - getFunctorMethods(className, new HashSet(), methods); + getFunctorMethods(className, new HashSet<>(), methods); if (methods.size() == 1) { return methods.values().iterator().next(); } @@ -267,7 +267,7 @@ class JavascriptNativeProcessor { public void makeSync(ClassHolder cls) { Set methods = new HashSet<>(); - findInheritedMethods(cls, methods, new HashSet()); + findInheritedMethods(cls, methods, new HashSet<>()); for (MethodHolder method : cls.getMethods()) { if (methods.contains(method.getDescriptor()) && method.getAnnotations().get(Sync.class.getName()) == null) { AnnotationHolder annot = new AnnotationHolder(Sync.class.getName()); @@ -544,9 +544,8 @@ class JavascriptNativeProcessor { // create program that invokes proxy method program = new Program(); BasicBlock block = program.createBasicBlock(); - List params = new ArrayList<>(); for (int i = 0; i < paramCount; ++i) { - params.add(program.createVariable()); + program.createVariable(); } if (isStatic) { program.createVariable(); diff --git a/teavm-jso/src/main/java/org/teavm/jso/plugin/NativeJavascriptClassRepository.java b/teavm-jso/src/main/java/org/teavm/jso/plugin/NativeJavascriptClassRepository.java index b7429789c..52f15a137 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/plugin/NativeJavascriptClassRepository.java +++ b/teavm-jso/src/main/java/org/teavm/jso/plugin/NativeJavascriptClassRepository.java @@ -59,17 +59,12 @@ class NativeJavascriptClassRepository { if (cls == null || !(cls.hasModifier(ElementModifier.INTERFACE) || cls.hasModifier(ElementModifier.ABSTRACT))) { return false; } - for (String iface : cls.getInterfaces()) { - if (isJavaScriptClass(iface)) { - return true; - } - } if (cls.getParent() != null && !cls.getParent().equals(cls.getName())) { if (isJavaScriptClass(cls.getParent())) { return true; } } - return false; + return cls.getInterfaces().stream().anyMatch(iface -> isJavaScriptClass(iface)); } private boolean examineIfJavaScriptImplementation(String className) { @@ -85,11 +80,6 @@ class NativeJavascriptClassRepository { return true; } } - for (String iface : cls.getInterfaces()) { - if (isJavaScriptClass(iface)) { - return true; - } - } - return false; + return cls.getInterfaces().stream().anyMatch(iface -> isJavaScriptClass(iface)); } } diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/AnnotationDependencySupport.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/AnnotationDependencySupport.java index e16b8b48e..2f190d94e 100644 --- a/teavm-platform/src/main/java/org/teavm/platform/plugin/AnnotationDependencySupport.java +++ b/teavm-platform/src/main/java/org/teavm/platform/plugin/AnnotationDependencySupport.java @@ -18,9 +18,7 @@ package org.teavm.platform.plugin; import java.lang.annotation.Annotation; import org.teavm.dependency.AbstractDependencyListener; import org.teavm.dependency.DependencyAgent; -import org.teavm.dependency.DependencyConsumer; import org.teavm.dependency.DependencyNode; -import org.teavm.dependency.DependencyType; import org.teavm.dependency.MethodDependency; import org.teavm.model.CallLocation; import org.teavm.model.MethodReference; @@ -46,27 +44,24 @@ public class AnnotationDependencySupport extends AbstractDependencyListener { } @Override - public void methodReached(final DependencyAgent agent, final MethodDependency method, - final CallLocation location) { + public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) { if (method.getReference().getClassName().equals(Platform.class.getName()) && method.getReference().getName().equals("getAnnotations")) { method.getResult().propagate(agent.getType("[" + Annotation.class.getName())); agent.linkMethod(new MethodReference(PlatformAnnotationProvider.class, "getAnnotations", Annotation[].class), location); - allClasses.addConsumer(new DependencyConsumer() { - @Override public void consume(DependencyType type) { - if (type.getName().endsWith("$$__annotations__$$")) { - return; - } - String className = type.getName() + "$$__annotations__$$"; - agent.linkMethod(new MethodReference(className, "", ValueType.VOID), location) - .propagate(0, className) - .use(); - MethodDependency readMethod = agent.linkMethod(new MethodReference(className, - "getAnnotations", ValueType.parse(Annotation[].class)), location); - readMethod.getResult().getArrayItem().connect(method.getResult().getArrayItem()); - readMethod.use(); + allClasses.addConsumer(type -> { + if (type.getName().endsWith("$$__annotations__$$")) { + return; } + String className = type.getName() + "$$__annotations__$$"; + agent.linkMethod(new MethodReference(className, "", ValueType.VOID), location) + .propagate(0, className) + .use(); + MethodDependency readMethod = agent.linkMethod(new MethodReference(className, + "getAnnotations", ValueType.parse(Annotation[].class)), location); + readMethod.getResult().getArrayItem().connect(method.getResult().getArrayItem()); + readMethod.use(); }); } } diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/AsyncMethodGenerator.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/AsyncMethodGenerator.java index 0cd6acb24..f9a7daccd 100644 --- a/teavm-platform/src/main/java/org/teavm/platform/plugin/AsyncMethodGenerator.java +++ b/teavm-platform/src/main/java/org/teavm/platform/plugin/AsyncMethodGenerator.java @@ -19,12 +19,16 @@ import java.io.IOException; import org.teavm.codegen.SourceWriter; import org.teavm.dependency.DependencyAgent; import org.teavm.dependency.DependencyPlugin; -import org.teavm.dependency.DependencyType; -import org.teavm.dependency.DependencyTypeFilter; import org.teavm.dependency.MethodDependency; import org.teavm.javascript.spi.Generator; import org.teavm.javascript.spi.GeneratorContext; -import org.teavm.model.*; +import org.teavm.model.CallLocation; +import org.teavm.model.ClassReader; +import org.teavm.model.ClassReaderSource; +import org.teavm.model.ElementModifier; +import org.teavm.model.MethodReader; +import org.teavm.model.MethodReference; +import org.teavm.model.ValueType; import org.teavm.platform.async.AsyncCallback; /** @@ -95,7 +99,7 @@ public class AsyncMethodGenerator implements Generator, DependencyPlugin { } @Override - public void methodAchieved(final DependencyAgent checker, final MethodDependency method, CallLocation location) { + public void methodAchieved(DependencyAgent checker, MethodDependency method, CallLocation location) { MethodReference asyncRef = getAsyncReference(method.getReference()); MethodDependency asyncMethod = checker.linkMethod(asyncRef, location); int paramCount = method.getReference().parameterCount(); @@ -107,12 +111,8 @@ public class AsyncMethodGenerator implements Generator, DependencyPlugin { MethodDependency completeMethod = checker.linkMethod( new MethodReference(AsyncCallbackWrapper.class, "complete", Object.class, void.class), null); if (method.getResult() != null) { - completeMethod.getVariable(1).connect(method.getResult(), new DependencyTypeFilter() { - @Override - public boolean match(DependencyType type) { - return isSubtype(checker.getClassSource(), type.getName(), method.getReference().getReturnType()); - } - }); + completeMethod.getVariable(1).connect(method.getResult(), type -> isSubtype(checker.getClassSource(), + type.getName(), method.getReference().getReturnType())); } completeMethod.use(); @@ -150,11 +150,6 @@ public class AsyncMethodGenerator implements Generator, DependencyPlugin { return true; } } - for (String iface : cls.getInterfaces()) { - if (isSubclass(classSource, iface, baseClass)) { - return true; - } - } - return false; + return cls.getInterfaces().stream().anyMatch(iface -> isSubclass(classSource, iface, baseClass)); } } diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/ClassLookupDependencySupport.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/ClassLookupDependencySupport.java index 39b92cc72..17e539de4 100644 --- a/teavm-platform/src/main/java/org/teavm/platform/plugin/ClassLookupDependencySupport.java +++ b/teavm-platform/src/main/java/org/teavm/platform/plugin/ClassLookupDependencySupport.java @@ -37,19 +37,17 @@ public class ClassLookupDependencySupport extends AbstractDependencyListener { } @Override - public void methodReached(final DependencyAgent agent, MethodDependency method, final CallLocation location) { + public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) { MethodReference ref = method.getReference(); if (ref.getClassName().equals(Platform.class.getName()) && ref.getName().equals("lookupClass")) { - allClasses.addConsumer(new DependencyConsumer() { - @Override public void consume(DependencyType type) { - ClassReader cls = agent.getClassSource().get(type.getName()); - if (cls == null) { - return; - } - MethodReader initMethod = cls.getMethod(new MethodDescriptor("", void.class)); - if (initMethod != null) { - agent.linkMethod(initMethod.getReference(), location).use(); - } + allClasses.addConsumer(type -> { + ClassReader cls = agent.getClassSource().get(type.getName()); + if (cls == null) { + return; + } + MethodReader initMethod = cls.getMethod(new MethodDescriptor("", void.class)); + if (initMethod != null) { + agent.linkMethod(initMethod.getReference(), location).use(); } }); } diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/EnumDependencySupport.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/EnumDependencySupport.java index e3b01789e..784958e4d 100644 --- a/teavm-platform/src/main/java/org/teavm/platform/plugin/EnumDependencySupport.java +++ b/teavm-platform/src/main/java/org/teavm/platform/plugin/EnumDependencySupport.java @@ -17,9 +17,7 @@ package org.teavm.platform.plugin; import org.teavm.dependency.AbstractDependencyListener; import org.teavm.dependency.DependencyAgent; -import org.teavm.dependency.DependencyConsumer; import org.teavm.dependency.DependencyNode; -import org.teavm.dependency.DependencyType; import org.teavm.dependency.MethodDependency; import org.teavm.model.CallLocation; import org.teavm.model.ClassReader; @@ -51,19 +49,17 @@ public class EnumDependencySupport extends AbstractDependencyListener { } @Override - public void methodReached(final DependencyAgent agent, MethodDependency method, CallLocation location) { + public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) { if (method.getReference().getClassName().equals(Platform.class.getName()) && method.getReference().getName().equals("getEnumConstants")) { allEnums.connect(method.getResult().getArrayItem()); final MethodReference ref = method.getReference(); - allEnums.addConsumer(new DependencyConsumer() { - @Override public void consume(DependencyType type) { - ClassReader cls = agent.getClassSource().get(type.getName()); - MethodReader method = cls.getMethod(new MethodDescriptor("values", - ValueType.arrayOf(ValueType.object(cls.getName())))); - if (method != null) { - agent.linkMethod(method.getReference(), new CallLocation(ref)).use(); - } + allEnums.addConsumer(type -> { + ClassReader cls = agent.getClassSource().get(type.getName()); + MethodReader valuesMethod = cls.getMethod(new MethodDescriptor("values", + ValueType.arrayOf(ValueType.object(cls.getName())))); + if (valuesMethod != null) { + agent.linkMethod(valuesMethod.getReference(), new CallLocation(ref)).use(); } }); method.getResult().propagate(agent.getType("[java.lang.Enum")); diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/NewInstanceDependencySupport.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/NewInstanceDependencySupport.java index 631eefd15..8f84b6b5b 100644 --- a/teavm-platform/src/main/java/org/teavm/platform/plugin/NewInstanceDependencySupport.java +++ b/teavm-platform/src/main/java/org/teavm/platform/plugin/NewInstanceDependencySupport.java @@ -47,16 +47,13 @@ public class NewInstanceDependencySupport extends AbstractDependencyListener { } @Override - public void methodReached(final DependencyAgent agent, MethodDependency method, CallLocation location) { + public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) { MethodReader reader = method.getMethod(); if (reader.getOwnerName().equals(Platform.class.getName()) && reader.getName().equals("newInstanceImpl")) { allClassesNode.connect(method.getResult()); - final MethodReference methodRef = reader.getReference(); - method.getResult().addConsumer(new DependencyConsumer() { - @Override public void consume(DependencyType type) { - attachConstructor(agent, type.getName(), new CallLocation(methodRef)); - } - }); + MethodReference methodRef = reader.getReference(); + method.getResult().addConsumer(type -> attachConstructor(agent, type.getName(), + new CallLocation(methodRef))); } } diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java index 833bf2b48..f9f4b5d14 100644 --- a/teavm-platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java +++ b/teavm-platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java @@ -70,7 +70,7 @@ public class PlatformGenerator implements Generator, Injector, DependencyPlugin case "classFromResource": case "objectFromResource": context.writeExpr(context.getArgument(0)); - return; + break; } } diff --git a/teavm-samples/teavm-samples-video/src/main/java/org/teavm/samples/video/Player.java b/teavm-samples/teavm-samples-video/src/main/java/org/teavm/samples/video/Player.java index dd7c37fe2..f7ad15f0c 100644 --- a/teavm-samples/teavm-samples-video/src/main/java/org/teavm/samples/video/Player.java +++ b/teavm-samples/teavm-samples-video/src/main/java/org/teavm/samples/video/Player.java @@ -16,8 +16,6 @@ package org.teavm.samples.video; import org.teavm.dom.browser.Window; -import org.teavm.dom.events.EventListener; -import org.teavm.dom.events.MouseEvent; import org.teavm.dom.html.HTMLBodyElement; import org.teavm.dom.html.HTMLButtonElement; import org.teavm.dom.html.HTMLDocument; @@ -53,7 +51,7 @@ public final class Player { HTMLElement p = document.createElement("p"); p.appendChild(document.createTextNode("Your user agent does not support the HTML5 Video element.")); - final HTMLVideoElement video = (HTMLVideoElement)document.createElement("video"); + HTMLVideoElement video = (HTMLVideoElement)document.createElement("video"); video.setAttribute("id", "video"); video.setControls(true); video.setPreload("none"); @@ -69,129 +67,61 @@ public final class Player { HTMLButtonElement loadButton = (HTMLButtonElement)document.createElement("button"); loadButton.appendChild(document.createTextNode("load()")); - loadButton.addEventListener("click", new EventListener() { - @Override - public void handleEvent(MouseEvent evt) { - video.load(); - } - }); + loadButton.addEventListener("click", evt -> video.load()); HTMLButtonElement playButton = (HTMLButtonElement)document.createElement("button"); playButton.appendChild(document.createTextNode("play()")); - playButton.addEventListener("click", new EventListener() { - @Override - public void handleEvent(MouseEvent evt) { - video.play(); - } - }); + playButton.addEventListener("click", evt -> video.play()); HTMLButtonElement pauseButton = (HTMLButtonElement)document.createElement("button"); pauseButton.appendChild(document.createTextNode("pause()")); - pauseButton.addEventListener("click", new EventListener() { - @Override - public void handleEvent(MouseEvent evt) { - video.pause(); - } - }); + pauseButton.addEventListener("click", evt -> video.pause()); HTMLButtonElement currentTimePlusButton = (HTMLButtonElement)document.createElement("button"); currentTimePlusButton.appendChild(document.createTextNode("currentTime+=10")); - currentTimePlusButton.addEventListener("click", new EventListener() { - @Override - public void handleEvent(MouseEvent evt) { - video.setCurrentTime(video.getCurrentTime() + 10); - } - }); + currentTimePlusButton.addEventListener("click", evt -> video.setCurrentTime(video.getCurrentTime() + 10)); HTMLButtonElement currentTimeMinusButton = (HTMLButtonElement)document.createElement("button"); currentTimeMinusButton.appendChild(document.createTextNode("currentTime-=10")); - currentTimeMinusButton.addEventListener("click", new EventListener() { - @Override - public void handleEvent(MouseEvent evt) { - video.setCurrentTime(video.getCurrentTime() - 10); - } - }); + currentTimeMinusButton.addEventListener("click", evt -> video.setCurrentTime(video.getCurrentTime() - 10)); HTMLButtonElement currentTime50Button = (HTMLButtonElement)document.createElement("button"); currentTime50Button.appendChild(document.createTextNode("currentTime=50")); - currentTime50Button.addEventListener("click", new EventListener() { - @Override - public void handleEvent(MouseEvent evt) { - video.setCurrentTime(50); - } - }); + currentTime50Button.addEventListener("click", evt -> video.setCurrentTime(50)); HTMLButtonElement playbackRateIncrementButton = (HTMLButtonElement)document.createElement("button"); playbackRateIncrementButton.appendChild(document.createTextNode("playbackRate++")); - playbackRateIncrementButton.addEventListener("click", new EventListener() { - @Override - public void handleEvent(MouseEvent evt) { - video.setPlaybackRate(video.getPlaybackRate() + 1); - } - }); + playbackRateIncrementButton.addEventListener("click", evt -> video.setPlaybackRate( + video.getPlaybackRate() + 1)); HTMLButtonElement playbackRateDecrementButton = (HTMLButtonElement)document.createElement("button"); playbackRateDecrementButton.appendChild(document.createTextNode("playbackRate--")); - playbackRateDecrementButton.addEventListener("click", new EventListener() { - @Override - public void handleEvent(MouseEvent evt) { - video.setPlaybackRate(video.getPlaybackRate() - 1); - } - }); + playbackRateDecrementButton.addEventListener("click", evt -> video.setPlaybackRate( + video.getPlaybackRate() - 1)); HTMLButtonElement playbackRatePlusButton = (HTMLButtonElement)document.createElement("button"); playbackRatePlusButton.appendChild(document.createTextNode("playbackRate+=0.1")); - playbackRatePlusButton.addEventListener("click", new EventListener() { - @Override - public void handleEvent(MouseEvent evt) { - video.setPlaybackRate(video.getPlaybackRate() + 0.1); - } - }); + playbackRatePlusButton.addEventListener("click", evt -> video.setPlaybackRate(video.getPlaybackRate() + 0.1)); HTMLButtonElement playbackRateMinusButton = (HTMLButtonElement)document.createElement("button"); playbackRateMinusButton.appendChild(document.createTextNode("playbackRate-=0.1")); - playbackRateMinusButton.addEventListener("click", new EventListener() { - @Override - public void handleEvent(MouseEvent evt) { - video.setPlaybackRate(video.getPlaybackRate() - 0.1); - } - }); + playbackRateMinusButton.addEventListener("click", evt -> video.setPlaybackRate(video.getPlaybackRate() - 0.1)); HTMLButtonElement volumePlusButton = (HTMLButtonElement)document.createElement("button"); volumePlusButton.appendChild(document.createTextNode("volume+=0.1")); - volumePlusButton.addEventListener("click", new EventListener() { - @Override - public void handleEvent(MouseEvent evt) { - video.setVolume(video.getVolume() + 0.1f); - } - }); + volumePlusButton.addEventListener("click", evt -> video.setVolume(video.getVolume() + 0.1f)); HTMLButtonElement volumeMinusButton = (HTMLButtonElement)document.createElement("button"); volumeMinusButton.appendChild(document.createTextNode("volume-=0.1")); - volumeMinusButton.addEventListener("click", new EventListener() { - @Override - public void handleEvent(MouseEvent evt) { - video.setVolume(video.getVolume() - 0.1f); - } - }); + volumeMinusButton.addEventListener("click", evt -> video.setVolume(video.getVolume() - 0.1f)); HTMLButtonElement muteButton = (HTMLButtonElement)document.createElement("button"); muteButton.appendChild(document.createTextNode("muted=true")); - muteButton.addEventListener("click", new EventListener() { - @Override - public void handleEvent(MouseEvent evt) { - video.setMuted(true); - } - }); + muteButton.addEventListener("click", evt -> video.setMuted(true)); HTMLButtonElement unmuteButton = (HTMLButtonElement)document.createElement("button"); unmuteButton.appendChild(document.createTextNode("muted=false")); - unmuteButton.addEventListener("click", new EventListener() { - @Override - public void handleEvent(MouseEvent evt) { - video.setMuted(false); - } - }); + unmuteButton.addEventListener("click", evt -> video.setMuted(false)); HTMLElement divButtons = document.createElement("div"); divButtons.setAttribute("id", "buttons");