Java 11 migrate c-d (remaining) (#1111)

* Moves converter pattern to Java 11

* Moves cqrs pattern to Java 11

* Moves dao pattern to Java 11

* Moves data-bus pattern to Java 11

* Moves data-locality pattern to Java 11

* Moves data-mapper pattern to Java 11

* Moves data-transfer-object pattern to Java 11

* Moves decorator pattern to Java 11

* Moves delegation pattern to Java 11

* Moves dependency-injection to Java 11

* Moves dirty-flag to Java 11

* Moves double-buffer to Java 11

* Moves double-checked-locking to Java 11

* Moves double-dispatch to Java 11

* Corrects with changes thats breaking test cases
This commit is contained in:
Anurag Agarwal
2019-12-15 00:02:45 +05:30
committed by Ilkka Seppälä
parent 5681684157
commit ea57934db6
75 changed files with 576 additions and 713 deletions

View File

@ -23,10 +23,8 @@
package com.iluwatar.doublebuffer;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.tuple.MutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -48,37 +46,34 @@ public class App {
*/
public static void main(String[] args) {
final var scene = new Scene();
List<Pair<Integer, Integer>> drawPixels = new ArrayList<>();
Pair<Integer, Integer> pixel1 = new MutablePair<>(1, 1);
Pair<Integer, Integer> pixel2 = new MutablePair<>(5, 6);
Pair<Integer, Integer> pixel3 = new MutablePair<>(3, 2);
drawPixels.add(pixel1);
drawPixels.add(pixel2);
drawPixels.add(pixel3);
scene.draw(drawPixels);
var drawPixels1 = List.of(
new MutablePair<>(1, 1),
new MutablePair<>(5, 6),
new MutablePair<>(3, 2)
);
scene.draw(drawPixels1);
var buffer1 = scene.getBuffer();
printBlackPixelCoordinate(buffer1);
drawPixels.clear();
Pair<Integer, Integer> pixel4 = new MutablePair<>(3, 7);
Pair<Integer, Integer> pixel5 = new MutablePair<>(6, 1);
drawPixels.add(pixel4);
drawPixels.add(pixel5);
scene.draw(drawPixels);
Buffer buffer2 = scene.getBuffer();
var drawPixels2 = List.of(
new MutablePair<>(3, 7),
new MutablePair<>(6, 1)
);
scene.draw(drawPixels2);
var buffer2 = scene.getBuffer();
printBlackPixelCoordinate(buffer2);
}
private static void printBlackPixelCoordinate(Buffer buffer) {
var log = "Black Pixels: ";
Pixel[] pixels = buffer.getPixels();
StringBuilder log = new StringBuilder("Black Pixels: ");
var pixels = buffer.getPixels();
for (var i = 0; i < pixels.length; ++i) {
if (pixels[i] == Pixel.BLACK) {
var y = i / FrameBuffer.WIDTH;
var x = i % FrameBuffer.WIDTH;
log += " (" + x + ", " + y + ")";
log.append(" (").append(x).append(", ").append(y).append(")");
}
}
LOGGER.info(log);
LOGGER.info(log.toString());
}
}

View File

@ -23,6 +23,8 @@
package com.iluwatar.doublebuffer;
import java.util.Arrays;
/**
* FrameBuffer implementation class.
*/
@ -49,9 +51,7 @@ public class FrameBuffer implements Buffer {
@Override
public void clearAll() {
for (var i = 0; i < pixels.length; ++i) {
pixels[i] = Pixel.WHITE;
}
Arrays.fill(pixels, Pixel.WHITE);
}
@Override

View File

@ -57,15 +57,15 @@ public class Scene {
*
* @param coordinateList list of pixels of which the color should be black
*/
public void draw(List<Pair<Integer, Integer>> coordinateList) {
public void draw(List<? extends Pair<Integer, Integer>> coordinateList) {
LOGGER.info("Start drawing next frame");
LOGGER.info("Current buffer: " + current + " Next buffer: " + next);
frameBuffers[next].clearAll();
for (Pair<Integer, Integer> coordinate : coordinateList) {
coordinateList.forEach(coordinate -> {
var x = coordinate.getKey();
var y = coordinate.getValue();
frameBuffers[next].draw(x, y);
}
});
LOGGER.info("Swap current and next buffer");
swap();
LOGGER.info("Finish swapping");