Corrected Indentation using formatter. (#1541)

This commit is contained in:
Devendra Tiwari 2017-03-30 23:51:17 +05:30 committed by Grzegorz Piwowarek
parent e28dfe6a4a
commit ce589cc7b5
14 changed files with 119 additions and 145 deletions

View File

@ -6,19 +6,18 @@ public class AtomicLongMapTutorials {
private AtomicLongMap<String> atomicLongMap;
public AtomicLongMapTutorials(){
public AtomicLongMapTutorials() {
atomicLongMap = AtomicLongMap.create();
}
public void addKeys(){
atomicLongMap.addAndGet("apple",250);
atomicLongMap.addAndGet("bat",350);
atomicLongMap.addAndGet("cat",450);
atomicLongMap.addAndGet("dog",550);
public void addKeys() {
atomicLongMap.addAndGet("apple", 250);
atomicLongMap.addAndGet("bat", 350);
atomicLongMap.addAndGet("cat", 450);
atomicLongMap.addAndGet("dog", 550);
}
public static void main(String[] args){
public static void main(String[] args) {
AtomicLongMapTutorials atomicLongMapTutorials = new AtomicLongMapTutorials();
atomicLongMapTutorials.addKeys();

View File

@ -8,12 +8,10 @@ import java.util.List;
public class ComparatorsExamples {
public static void main(String[] args){
public static void main(String[] args) {
List<Integer> integers = Arrays.asList(1,2,3,4,4,6,7,8,9,10);
//This will return true
List<Integer> integers = Arrays.asList(1, 2, 3, 4, 4, 6, 7, 8, 9, 10);
boolean isInAscendingOrder = Comparators.isInOrder(integers, new AscedingOrderComparator());
System.out.println(isInAscendingOrder);
}

View File

@ -5,7 +5,7 @@ import com.google.common.collect.Streams;
import java.util.stream.Stream;
public class ConcatStreams {
public static Stream concatStreams(Stream stream1, Stream stream2, Stream stream3){
return Streams.concat(stream1,stream2,stream3);
public static Stream concatStreams(Stream stream1, Stream stream2, Stream stream3) {
return Streams.concat(stream1, stream2, stream3);
}
}

View File

@ -3,16 +3,12 @@ package com.baeldung.guava.tutorial;
import com.google.common.collect.Interner;
import com.google.common.collect.Interners;
import static com.google.common.collect.Interners.newBuilder;
public class InternerBuilderExample {
public static void main(String[] args){
Interner<Integer> interners = Interners.<Integer>newBuilder()
.concurrencyLevel(2)
.strong()
.<Integer>build();
public static void main(String[] args) {
Interner<Integer> interners = Interners.<Integer> newBuilder()
.concurrencyLevel(2)
.strong().<Integer> build();
}

View File

@ -4,7 +4,6 @@ import com.google.common.util.concurrent.Monitor;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BooleanSupplier;
public class MonitorExample {
private List<String> students = new ArrayList<String>();
@ -12,7 +11,6 @@ public class MonitorExample {
private Monitor monitor = new Monitor();
public void addToCourse(String item) throws InterruptedException {
Monitor.Guard studentsBelowCapacity = monitor.newGuard(this::isStudentsCapacityUptoLimit);
monitor.enterWhen(studentsBelowCapacity);
@ -23,7 +21,7 @@ public class MonitorExample {
}
}
public Boolean isStudentsCapacityUptoLimit(){
public Boolean isStudentsCapacityUptoLimit() {
return students.size() > MAX_SIZE;
}
}

View File

@ -10,8 +10,9 @@ public class MoreCollectorsExample {
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(1);
Optional<Integer> number = numbers.stream()
.map(e -> e * 2)
.collect(MoreCollectors.toOptional());
Optional<Integer> number = numbers
.stream()
.map(e -> e * 2)
.collect(MoreCollectors.toOptional());
}
}

View File

@ -10,9 +10,9 @@ import java.util.stream.Stream;
public class StreamsUtility {
public static void main(String[] args){
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(1,2,3,4,5,6,7,8,9,10,11,11,12,13,14,15,16,17,18,19,20);
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
//Using Collection
Stream<Integer> streamFromCollection = Streams.stream(numbers);
//Using Iterator
@ -28,15 +28,12 @@ public class StreamsUtility {
//Using OptionalDouble to DoubleStream
DoubleStream streamFromOptionalDouble = Streams.stream(OptionalDouble.of(1.0));
Stream<Integer> concatenatedStreams = Streams.concat(streamFromCollection,streamFromIterable,streamFromIterator);
Stream<Integer> concatenatedStreams = Streams.concat(streamFromCollection, streamFromIterable, streamFromIterator);
List<Integer> integers = Arrays.asList(1,2,3,4,5,6,7,8,9,10);
List<Integer> integers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
//This will return 10
Optional<Integer> lastItem = Streams.findLast(integers.stream());
Streams.zip(
Stream.of("candy", "chocolate", "bar"),
Stream.of("$1", "$2","$3"),
(arg1, arg2) -> arg1 + ":" + arg2);
Streams.zip(Stream.of("candy", "chocolate", "bar"), Stream.of("$1", "$2", "$3"), (arg1, arg2) -> arg1 + ":" + arg2);
}
}

View File

@ -1,5 +1,4 @@
import com.google.common.util.concurrent.AtomicLongMap;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@ -12,35 +11,28 @@ public class AtomicLongMapTests {
AtomicLongMap<String> courses = AtomicLongMap.create();
public void setUp(){
public void setUp() {
courses.put(SPRING_COURSE_KEY, 1056);
courses.put(HIBERNATE_COURSE_KEY, 259);
courses.put(GUAVA_COURSE_KEY, 78);
}
@Test
public void accumulateAndGet_withLongBinaryOperator_thenSuccessful() {
long noOfStudents = 56;
long oldValue = courses.get(SPRING_COURSE_KEY);
@Test
public void accumulateAndGet_withLongBinaryOperator_thenSuccessful(){
long noOfStudents = 56;
long oldValue = courses.get(SPRING_COURSE_KEY);
long totalNotesRequired = courses.accumulateAndGet("Guava", noOfStudents, (x, y) -> (x * y));
long totalNotesRequired = courses.accumulateAndGet(
"Guava",
noOfStudents,
(x,y) -> (x * y));
assertEquals(totalNotesRequired, oldValue * noOfStudents );
}
assertEquals(totalNotesRequired, oldValue * noOfStudents);
}
@Test
public void getAndAccumulate_withLongBinaryOperator_thenSuccessful(){
public void getAndAccumulate_withLongBinaryOperator_thenSuccessful() {
long noOfStudents = 56;
long beforeUpdate = courses.get(SPRING_COURSE_KEY);
long onUpdate = courses.accumulateAndGet("Guava",
noOfStudents,
(x,y) -> (x * y)
);
long onUpdate = courses.accumulateAndGet("Guava", noOfStudents, (x, y) -> (x * y));
long afterUpdate = courses.get(SPRING_COURSE_KEY);
@ -48,17 +40,15 @@ public void accumulateAndGet_withLongBinaryOperator_thenSuccessful(){
assertEquals(afterUpdate, beforeUpdate * noOfStudents);
}
@Test
public void updateAndGet_withLongUnaryOperator_thenSuccessful(){
long beforeUpdate = courses.get(SPRING_COURSE_KEY);
@Test
public void updateAndGet_withLongUnaryOperator_thenSuccessful() {
long beforeUpdate = courses.get(SPRING_COURSE_KEY);
long onUpdate = courses.updateAndGet(
"Guava",
(x) -> (x/2));
long onUpdate = courses.updateAndGet("Guava", (x) -> (x / 2));
long afterUpdate = courses.get(SPRING_COURSE_KEY);
long afterUpdate = courses.get(SPRING_COURSE_KEY);
assertEquals(onUpdate, afterUpdate);
assertEquals(afterUpdate, beforeUpdate/2);
}
assertEquals(onUpdate, afterUpdate);
assertEquals(afterUpdate, beforeUpdate / 2);
}
}

View File

@ -2,7 +2,9 @@ import com.google.common.collect.Comparators;
import org.junit.Assert;
import org.junit.Test;
import java.util.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import java.util.function.ToDoubleFunction;
import java.util.function.ToIntFunction;
@ -11,9 +13,9 @@ import java.util.function.ToLongFunction;
public class ComparatorsUnitTests {
@Test
public void isInOrderTest(){
public void isInOrderTest() {
List<Integer> numbers = Arrays.asList(1,2,3,4,4,6,7,8,9,10);
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 4, 6, 7, 8, 9, 10);
boolean isInAscendingOrder = Comparators.isInOrder(numbers, new AscendingOrderComparator<Number>());
@ -21,17 +23,16 @@ public class ComparatorsUnitTests {
}
@Test
public void isInStrictOrderTest(){
public void isInStrictOrderTest() {
List<Integer> numbers = Arrays.asList(1,2,3,4,3,6,7,8,9,10);
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 3, 6, 7, 8, 9, 10);
boolean isInAscendingOrder = Comparators.isInOrder(numbers, new AscendingOrderComparator<Number>());
Assert.assertFalse(isInAscendingOrder);
}
private class AscendingOrderComparator<I extends Number> implements Comparator<Integer>{
private class AscendingOrderComparator<I extends Number> implements Comparator<Integer> {
@Override
public int compare(Integer o1, Integer o2) {

View File

@ -14,13 +14,12 @@ public class GauavaStreamsTests {
List<Integer> numbers;
@Before
public void setUp(){
numbers = Arrays.asList(1,2,3,4,5,6,7,8,9,10,11,11,12,13,14,15,16,17,18,19,20);
public void setUp() {
numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
}
@Test
public void createStreamsWithCollection(){
public void createStreamsWithCollection() {
//Deprecated API to create stream from collection
Stream streamFromCollection = Streams.stream(numbers);
@ -29,7 +28,7 @@ public class GauavaStreamsTests {
}
@Test
public void createStreamsWithIterable(){
public void createStreamsWithIterable() {
Iterable<Integer> numbersIterable = (Iterable<Integer>) numbers;
Stream streamFromIterable = Streams.stream(numbersIterable);
@ -39,7 +38,7 @@ public class GauavaStreamsTests {
}
@Test
public void createStreamsWithIterator(){
public void createStreamsWithIterator() {
Iterator<Integer> numbersIterator = numbers.iterator();
Stream streamFromIterator = Streams.stream(numbersIterator);
@ -49,7 +48,7 @@ public class GauavaStreamsTests {
}
@Test
public void createStreamsWithOptional(){
public void createStreamsWithOptional() {
Stream streamFromOptional = Streams.stream(Optional.of(1));
@ -58,7 +57,7 @@ public class GauavaStreamsTests {
}
@Test
public void createStreamsWithOptionalLong(){
public void createStreamsWithOptionalLong() {
LongStream streamFromOptionalLong = Streams.stream(OptionalLong.of(1));
@ -67,7 +66,7 @@ public class GauavaStreamsTests {
}
@Test
public void createStreamsWithOptionalInt(){
public void createStreamsWithOptionalInt() {
IntStream streamFromOptionalInt = Streams.stream(OptionalInt.of(1));
@ -76,7 +75,7 @@ public class GauavaStreamsTests {
}
@Test
public void createStreamsWithOptionalDouble(){
public void createStreamsWithOptionalDouble() {
DoubleStream streamFromOptionalDouble = Streams.stream(OptionalDouble.of(1.0));
@ -86,41 +85,44 @@ public class GauavaStreamsTests {
}
@Test
public void concatStreamsOfSameType(){
Stream oddNumbers = Arrays.asList(1,3,5,7,9,11,13,15,17,19).stream();
Stream evenNumbers = Arrays.asList(2,4,6,8,10,12,14,16,18,20).stream();
public void concatStreamsOfSameType() {
Stream oddNumbers = Arrays
.asList(1, 3, 5, 7, 9, 11, 13, 15, 17, 19)
.stream();
Stream evenNumbers = Arrays
.asList(2, 4, 6, 8, 10, 12, 14, 16, 18, 20)
.stream();
Stream combinedStreams = Streams.concat(oddNumbers,evenNumbers);
Stream combinedStreams = Streams.concat(oddNumbers, evenNumbers);
//Assert.assertNotNull(combinedStreams);
StreamUtility.assertStreamEquals(combinedStreams, Stream.concat(oddNumbers, evenNumbers));
}
@Test
public void concatStreamsOfTypeLongStream(){
LongStream firstTwenty = LongStream.range(1,20);
LongStream nextTwenty = LongStream.range(21,40);
public void concatStreamsOfTypeLongStream() {
LongStream firstTwenty = LongStream.range(1, 20);
LongStream nextTwenty = LongStream.range(21, 40);
LongStream combinedStreams = Streams.concat(firstTwenty,nextTwenty);
LongStream combinedStreams = Streams.concat(firstTwenty, nextTwenty);
Assert.assertNotNull(combinedStreams);
StreamUtility.assertStreamEquals(combinedStreams, LongStream.concat(firstTwenty, nextTwenty));
}
@Test
public void concatStreamsOfTypeIntStream(){
IntStream firstTwenty = IntStream.range(1,20);
IntStream nextTwenty = IntStream.range(21,40);
public void concatStreamsOfTypeIntStream() {
IntStream firstTwenty = IntStream.range(1, 20);
IntStream nextTwenty = IntStream.range(21, 40);
IntStream combinedStreams = Streams.concat(firstTwenty,nextTwenty);
IntStream combinedStreams = Streams.concat(firstTwenty, nextTwenty);
Assert.assertNotNull(combinedStreams);
StreamUtility.assertStreamEquals(combinedStreams, IntStream.concat(firstTwenty, nextTwenty));
}
@Test
public void findLastOfStream(){
public void findLastOfStream() {
Optional<Integer> lastElement = Streams.findLast(numbers.stream());
Assert.assertNotNull(lastElement.get());
@ -128,28 +130,29 @@ public class GauavaStreamsTests {
}
@Test
public void mapWithIndexTest(){
Stream stringSream = Stream.of("a","b","c");
public void mapWithIndexTest() {
Stream stringSream = Stream.of("a", "b", "c");
Stream<String> mappedStream = Streams.mapWithIndex(stringSream,(str,index) -> str +":"+ index);
Stream<String> mappedStream = Streams.mapWithIndex(stringSream, (str, index) -> str + ":" + index);
//Assert.assertNotNull(mappedStream);
Assert.assertEquals(mappedStream.findFirst().get(), "a:0");
Assert.assertEquals(mappedStream
.findFirst()
.get(), "a:0");
}
@Test
public void streamsZipTest(){
Stream stringSream = Stream.of("a","b","c");
Stream intStream = Stream.of(1,2,3);
Stream<String> mappedStream = Streams.zip(stringSream,intStream, (str,index) -> str +":"+ index);
public void streamsZipTest() {
Stream stringSream = Stream.of("a", "b", "c");
Stream intStream = Stream.of(1, 2, 3);
Stream<String> mappedStream = Streams.zip(stringSream, intStream, (str, index) -> str + ":" + index);
//Assert.assertNotNull(mappedStream);
Assert.assertEquals(mappedStream.findFirst().get(), "a:1");
Assert.assertEquals(mappedStream
.findFirst()
.get(), "a:1");
}
}

View File

@ -6,12 +6,11 @@ import org.junit.Test;
public class InternBuilderUnitTests {
@Test
public void interBuilderTest(){
public void interBuilderTest() {
Interner<Integer> interners = Interners.<Integer>newBuilder()
.concurrencyLevel(2)
.strong()
.<Integer>build();
Interner<Integer> interners = Interners.<Integer> newBuilder()
.concurrencyLevel(2)
.strong().<Integer> build();
Assert.assertNotNull(interners);
}

View File

@ -2,14 +2,6 @@ import com.google.common.util.concurrent.Monitor;
import org.junit.Assert;
import org.junit.Test;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import static com.google.common.util.concurrent.Uninterruptibles.joinUninterruptibly;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class MonitorUnitTests {
@Test
@ -19,11 +11,11 @@ public class MonitorUnitTests {
Monitor.Guard gaurdCondition = monitor.newGuard(this::returnTrue);
if(monitor.enterIf(gaurdCondition)){
try{
if (monitor.enterIf(gaurdCondition)) {
try {
System.out.println("Entered in critical section");
enteredInCriticalSection = true;
}finally {
} finally {
monitor.leave();
}
}
@ -39,11 +31,11 @@ public class MonitorUnitTests {
Monitor.Guard gaurdCondition = monitor.newGuard(this::returnFalse);
if(monitor.enterIf(gaurdCondition)){
try{
if (monitor.enterIf(gaurdCondition)) {
try {
System.out.println("Entered in critical section");
enteredInCriticalSection = true;
}finally {
} finally {
monitor.leave();
}
}
@ -51,11 +43,11 @@ public class MonitorUnitTests {
Assert.assertFalse(enteredInCriticalSection);
}
private boolean returnTrue(){
private boolean returnTrue() {
return true;
}
private boolean returnFalse(){
private boolean returnFalse() {
return false;
}
}

View File

@ -9,28 +9,28 @@ import java.util.Optional;
public class MoreCollectorsUnitTests {
@Test
public void toOptionalTest(){
public void toOptionalTest() {
List<Integer> numbers = Arrays.asList(1);
Optional<Integer> number = numbers.stream()
.map( e -> e*2)
.collect(MoreCollectors.toOptional());
Optional<Integer> number = numbers
.stream()
.map(e -> e * 2)
.collect(MoreCollectors.toOptional());
Assert.assertEquals(number.get(),new Integer(2));
Assert.assertEquals(number.get(), new Integer(2));
}
@Test
public void onlyElementTest(){
public void onlyElementTest() {
List<Integer> numbers = Arrays.asList(1);
Integer number = numbers.stream()
.map( e -> e*2)
.collect(MoreCollectors.onlyElement());
Integer number = numbers
.stream()
.map(e -> e * 2)
.collect(MoreCollectors.onlyElement());
Assert.assertEquals(number,new Integer(2));
Assert.assertEquals(number, new Integer(2));
}
}

View File

@ -8,12 +8,12 @@ import java.util.stream.Stream;
public class StreamUtility {
public static <T> boolean assertStreamEquals(Stream<T> stream1, Stream<T> stream2){
public static <T> boolean assertStreamEquals(Stream<T> stream1, Stream<T> stream2) {
Iterator<T> iterator1 = stream1.iterator();
Iterator<T> iterator2 = stream2.iterator();
while (iterator1.hasNext()){
while (iterator1.hasNext()) {
Assert.assertEquals(iterator1.next(), iterator2.next());
}
@ -27,7 +27,7 @@ public class StreamUtility {
Iterator iterator1 = stream1.iterator();
Iterator iterator2 = stream2.iterator();
while (iterator1.hasNext()){
while (iterator1.hasNext()) {
Assert.assertEquals(iterator1.next(), iterator2.next());
}
@ -41,7 +41,7 @@ public class StreamUtility {
Iterator iterator1 = stream1.iterator();
Iterator iterator2 = stream2.iterator();
while (iterator1.hasNext()){
while (iterator1.hasNext()) {
Assert.assertEquals(iterator1.next(), iterator2.next());
}
@ -55,7 +55,7 @@ public class StreamUtility {
Iterator iterator1 = stream1.iterator();
Iterator iterator2 = stream2.iterator();
while (iterator1.hasNext()){
while (iterator1.hasNext()) {
Assert.assertEquals(iterator1.next(), iterator2.next());
}