Skip to content

Commit

Permalink
minor formatting cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenp committed Aug 24, 2017
1 parent 74e67d6 commit 1cba1b0
Show file tree
Hide file tree
Showing 194 changed files with 1,160 additions and 1,018 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ public void run() {
try {
generateNumbers();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
Thread.currentThread()
.interrupt();
}
}

private void generateNumbers() throws InterruptedException {
for (int i = 0; i < 100; i++) {
numbersQueue.put(ThreadLocalRandom.current().nextInt(100));
numbersQueue.put(ThreadLocalRandom.current()
.nextInt(100));
}
for (int j = 0; j < poisonPillPerProducer; j++) {
numbersQueue.put(poisonPill);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public int compareTo(Delayed o) {

@Override
public String toString() {
return "{" +
"data='" + data + '\'' +
", startTime=" + startTime +
'}';
return "{" + "data='" + data + '\'' + ", startTime=" + startTime + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ public class LuxuryCarsSpeed {
public double bugattiVeyronInMPH() {
return 268;
}

public double mcLarenInMPH() {
return 241;
}

public double astonMartinInMPH() {
return 220;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public interface LuxuryCarsSpeedAdapter {
public double bugattiVeyronInKMPH();

public double mcLarenInKMPH();

public double astonMartinInKMPH();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class Blue implements Color {

@Override
public void fillColor() {
public void fillColor() {
LOG.info("Color : Blue");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
public class DecoratorPatternDriver {

public static void main(String[] args) {
//christmas tree with just one Garland
// christmas tree with just one Garland
ChristmasTree tree1 = new Garland(new ChristmasTreeImpl());
LOG.info(tree1.decorate());

//christmas tree with two Garlands and one Bubble lights
ChristmasTree tree2 = new BubbleLights(new Garland(
new Garland(new ChristmasTreeImpl()))
);

// christmas tree with two Garlands and one Bubble lights
ChristmasTree tree2 = new BubbleLights(new Garland(new Garland(new ChristmasTreeImpl())));
LOG.info(tree2.decorate());

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ public class ExpensiveObjectImpl implements ExpensiveObject {
public ExpensiveObjectImpl() {
heavyInitialConfiguration();
}

@Override
public void process() {
LOG.info("processing complete.");
}

private void heavyInitialConfiguration() {
LOG.info("Loading initial configuration...");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private Collection<CustomRecursiveAction> createSubtasks() {

private void processing(String work) {
String result = work.toUpperCase();
logger.info("This result - (" + result + ") - was processed by " + Thread.currentThread().getName());
logger.info("This result - (" + result + ") - was processed by " + Thread.currentThread()
.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

@Retention(RetentionPolicy.RUNTIME)
public @interface Greeter {
public String greet() default "";

public String greet() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public void iterateUsingLambda(Map<String, Integer> map) {
}

public void iterateUsingIteratorAndEntry(Map<String, Integer> map) {
Iterator<Map.Entry<String, Integer>> iterator = map.entrySet().iterator();
Iterator<Map.Entry<String, Integer>> iterator = map.entrySet()
.iterator();
while (iterator.hasNext()) {
Map.Entry<String, Integer> pair = iterator.next();
System.out.println(pair.getKey() + ":" + pair.getValue());
Expand All @@ -58,7 +59,9 @@ public void iterateUsingKeySetAndForeach(Map<String, Integer> map) {
}

public void iterateUsingStreamAPI(Map<String, Integer> map) {
map.entrySet().stream().forEach(e -> System.out.println(e.getKey() + ":" + e.getValue()));
map.entrySet()
.stream()
.forEach(e -> System.out.println(e.getKey() + ":" + e.getValue()));
}

public void iterateKeys(Map<String, Integer> map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static void main(String[] args) {

BigInteger numStarsMilkyWay = new BigInteger("8731409320171337804361260816606476");
BigInteger numStarsAndromeda = new BigInteger("5379309320171337804361260816606476");

BigInteger totalStars = numStarsMilkyWay.add(numStarsAndromeda);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class PersistentCookieStore implements CookieStore, Runnable {
public PersistentCookieStore() {
store = new CookieManager().getCookieStore();
// deserialize cookies into store
Runtime.getRuntime().addShutdownHook(new Thread(this));
Runtime.getRuntime()
.addShutdownHook(new Thread(this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public Screenshot(String path) {
}

public void getScreenshot(int timeToWait) throws Exception {
Rectangle rectangle = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
Rectangle rectangle = new Rectangle(Toolkit.getDefaultToolkit()
.getScreenSize());
Robot robot = new Robot();
BufferedImage img = robot.createScreenCapture(rectangle);
ImageIO.write(img, "jpg", new File(path));
Expand Down
38 changes: 18 additions & 20 deletions core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
import java.util.UUID;

public class UUIDGenerator {

/**
* These are predefined UUID for name spaces
*/
private static final String NAMESPACE_DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
private static final String NAMESPACE_URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
private static final String NAMESPACE_OID = "6ba7b812-9dad-11d1-80b4-00c04fd430c8";
private static final String NAMESPACE_X500 = "6ba7b814-9dad-11d1-80b4-00c04fd430c8";
private static final String NAMESPACE_DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
private static final String NAMESPACE_URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
private static final String NAMESPACE_OID = "6ba7b812-9dad-11d1-80b4-00c04fd430c8";
private static final String NAMESPACE_X500 = "6ba7b814-9dad-11d1-80b4-00c04fd430c8";

private static final char[] hexArray = "0123456789ABCDEF".toCharArray();
private static final char[] hexArray = "0123456789ABCDEF".toCharArray();

public static void main(String[] args) {
try {
Expand All @@ -35,7 +35,7 @@ public static UUID generateType4UUID() {
UUID uuid = UUID.randomUUID();
return uuid;
}

/**
* Type 3 UUID Generation
*
Expand All @@ -47,7 +47,7 @@ public static UUID generateType3UUID(String namespace, String name) throws Unsup
UUID uuid = UUID.nameUUIDFromBytes(bytes);
return uuid;
}

/**
* Type 5 UUID Generation
*
Expand All @@ -59,8 +59,7 @@ public static UUID generateType5UUID(String namespace, String name) throws Unsup
UUID uuid = type5UUIDFromBytes(bytes);
return uuid;
}



public static UUID type5UUIDFromBytes(byte[] name) {
MessageDigest md;
try {
Expand All @@ -69,27 +68,26 @@ public static UUID type5UUIDFromBytes(byte[] name) {
throw new InternalError("MD5 not supported", nsae);
}
byte[] bytes = md.digest(name);
bytes[6] &= 0x0f; /* clear version */
bytes[6] |= 0x50; /* set to version 5 */
bytes[8] &= 0x3f; /* clear variant */
bytes[8] |= 0x80; /* set to IETF variant */
bytes[6] &= 0x0f; /* clear version */
bytes[6] |= 0x50; /* set to version 5 */
bytes[8] &= 0x3f; /* clear variant */
bytes[8] |= 0x80; /* set to IETF variant */
return constructType5UUID(bytes);
}

private static UUID constructType5UUID(byte[] data) {
long msb = 0;
long lsb = 0;
assert data.length == 16 : "data must be 16 bytes in length";
for (int i=0; i<8; i++)

for (int i = 0; i < 8; i++)
msb = (msb << 8) | (data[i] & 0xff);
for (int i=8; i<16; i++)

for (int i = 8; i < 16; i++)
lsb = (lsb << 8) | (data[i] & 0xff);
return new UUID(msb, lsb);
}


/**
* Unique Keys Generation Using Message Digest and Type 4 UUID
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class CompletableFutureLongRunningUnitTest {

private static final Logger LOG = LoggerFactory.getLogger(CompletableFutureLongRunningUnitTest.class);


@Test
public void whenRunningCompletableFutureAsynchronously_thenGetMethodWaitsForResult() throws InterruptedException, ExecutionException {
Future<String> completableFuture = calculateAsync();
Expand All @@ -27,11 +26,12 @@ public void whenRunningCompletableFutureAsynchronously_thenGetMethodWaitsForResu
private Future<String> calculateAsync() throws InterruptedException {
CompletableFuture<String> completableFuture = new CompletableFuture<>();

Executors.newCachedThreadPool().submit(() -> {
Thread.sleep(500);
completableFuture.complete("Hello");
return null;
});
Executors.newCachedThreadPool()
.submit(() -> {
Thread.sleep(500);
completableFuture.complete("Hello");
return null;
});

return completableFuture;
}
Expand All @@ -47,11 +47,12 @@ public void whenRunningCompletableFutureWithResult_thenGetMethodReturnsImmediate
private Future<String> calculateAsyncWithCancellation() throws InterruptedException {
CompletableFuture<String> completableFuture = new CompletableFuture<>();

Executors.newCachedThreadPool().submit(() -> {
Thread.sleep(500);
completableFuture.cancel(false);
return null;
});
Executors.newCachedThreadPool()
.submit(() -> {
Thread.sleep(500);
completableFuture.cancel(false);
return null;
});

return completableFuture;
}
Expand Down Expand Up @@ -98,21 +99,24 @@ public void whenAddingThenApplyToFuture_thenFunctionExecutesAfterComputationIsFi

@Test
public void whenUsingThenCompose_thenFuturesExecuteSequentially() throws ExecutionException, InterruptedException {
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> "Hello").thenCompose(s -> CompletableFuture.supplyAsync(() -> s + " World"));
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> "Hello")
.thenCompose(s -> CompletableFuture.supplyAsync(() -> s + " World"));

assertEquals("Hello World", completableFuture.get());
}

@Test
public void whenUsingThenCombine_thenWaitForExecutionOfBothFutures() throws ExecutionException, InterruptedException {
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> "Hello").thenCombine(CompletableFuture.supplyAsync(() -> " World"), (s1, s2) -> s1 + s2);
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> "Hello")
.thenCombine(CompletableFuture.supplyAsync(() -> " World"), (s1, s2) -> s1 + s2);

assertEquals("Hello World", completableFuture.get());
}

@Test
public void whenUsingThenAcceptBoth_thenWaitForExecutionOfBothFutures() throws ExecutionException, InterruptedException {
CompletableFuture.supplyAsync(() -> "Hello").thenAcceptBoth(CompletableFuture.supplyAsync(() -> " World"), (s1, s2) -> LOG.debug(s1 + s2));
CompletableFuture.supplyAsync(() -> "Hello")
.thenAcceptBoth(CompletableFuture.supplyAsync(() -> " World"), (s1, s2) -> LOG.debug(s1 + s2));
}

@Test
Expand All @@ -131,7 +135,9 @@ public void whenFutureCombinedWithAllOfCompletes_thenAllFuturesAreDone() throws
assertTrue(future2.isDone());
assertTrue(future3.isDone());

String combined = Stream.of(future1, future2, future3).map(CompletableFuture::join).collect(Collectors.joining(" "));
String combined = Stream.of(future1, future2, future3)
.map(CompletableFuture::join)
.collect(Collectors.joining(" "));

assertEquals("Hello Beautiful World", combined);
}
Expand All @@ -147,7 +153,8 @@ public void whenFutureThrows_thenHandleMethodReceivesException() throws Executio
throw new RuntimeException("Computation error!");
}
return "Hello, " + name;
}).handle((s, t) -> s != null ? s : "Hello, Stranger!");
})
.handle((s, t) -> s != null ? s : "Hello, Stranger!");

assertEquals("Hello, Stranger!", completableFuture.get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public class UseLocalDateTimeUnitTest {

@Test
public void givenString_whenUsingParse_thenLocalDateTime() {
assertEquals(LocalDate.of(2016, Month.MAY, 10), useLocalDateTime.getLocalDateTimeUsingParseMethod("2016-05-10T06:30").toLocalDate());
assertEquals(LocalTime.of(6, 30), useLocalDateTime.getLocalDateTimeUsingParseMethod("2016-05-10T06:30").toLocalTime());
assertEquals(LocalDate.of(2016, Month.MAY, 10), useLocalDateTime.getLocalDateTimeUsingParseMethod("2016-05-10T06:30")
.toLocalDate());
assertEquals(LocalTime.of(6, 30), useLocalDateTime.getLocalDateTimeUsingParseMethod("2016-05-10T06:30")
.toLocalTime());
}
}
Loading

0 comments on commit 1cba1b0

Please sign in to comment.