Merge pull request #13 from eugenp/master

update master
This commit is contained in:
Maiklins 2019-12-18 09:07:13 +01:00 committed by GitHub
commit 91633ff4cf
849 changed files with 2305 additions and 1440 deletions

View File

@ -1,3 +1,4 @@
**UPDATE**: The price of "Learn Spring Security OAuth" will permanently change on the 11th of December, along with the upcoming OAuth2 material: http://bit.ly/github-lss
The Courses The Courses
============================== ==============================

View File

@ -0,0 +1,33 @@
package com.baeldung.algorithms.mergesortedarrays;
public class SortedArrays {
public static int[] merge(int[] foo, int[] bar) {
int fooLength = foo.length;
int barLength = bar.length;
int[] merged = new int[fooLength + barLength];
int fooPosition, barPosition, mergedPosition;
fooPosition = barPosition = mergedPosition = 0;
while (fooPosition < fooLength && barPosition < barLength) {
if (foo[fooPosition] < bar[barPosition]) {
merged[mergedPosition++] = foo[fooPosition++];
} else {
merged[mergedPosition++] = bar[barPosition++];
}
}
while (fooPosition < fooLength) {
merged[mergedPosition++] = foo[fooPosition++];
}
while (barPosition < barLength) {
merged[mergedPosition++] = bar[barPosition++];
}
return merged;
}
}

View File

@ -0,0 +1,29 @@
package com.baeldung.algorithms.mergesortedarrays;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import org.junit.jupiter.api.Test;
import com.baeldung.algorithms.mergesortedarrays.SortedArrays;
public class SortedArraysUnitTest {
@Test
public void givenTwoSortedArrays_whenMerged_thenReturnMergedSortedArray() {
int[] foo = { 3, 7 };
int[] bar = { 4, 8, 11 };
int[] merged = { 3, 4, 7, 8, 11 };
assertArrayEquals(merged, SortedArrays.merge(foo, bar));
}
@Test
public void givenTwoSortedArraysWithDuplicates_whenMerged_thenReturnMergedSortedArray() {
int[] foo = { 3, 3, 7 };
int[] bar = { 4, 8, 8, 11 };
int[] merged = { 3, 3, 4, 7, 8, 8, 11 };
assertArrayEquals(merged, SortedArrays.merge(foo, bar));
}
}

View File

@ -1,6 +1,6 @@
## AWS ## AWS
This module contains articles about AWS This module contains articles about Amazon Web Services (AWS)
### Relevant articles ### Relevant articles

View File

@ -1,5 +1,3 @@
=========
## Core Java Concurrency Advanced Examples ## Core Java Concurrency Advanced Examples
This module contains articles about advanced topics about multithreading with core Java. This module contains articles about advanced topics about multithreading with core Java.

View File

@ -1,6 +1,6 @@
========= ## Core Java Concurrency Basic
## Core Java Concurrency Basic 2 Examples This module contains articles about basic Java concurrency
### Relevant Articles: ### Relevant Articles:
- [How to Delay Code Execution in Java](https://www.baeldung.com/java-delay-code-execution) - [How to Delay Code Execution in Java](https://www.baeldung.com/java-delay-code-execution)
@ -8,3 +8,4 @@
- [Difference Between Wait and Sleep in Java](https://www.baeldung.com/java-wait-and-sleep) - [Difference Between Wait and Sleep in Java](https://www.baeldung.com/java-wait-and-sleep)
- [Guide to the Synchronized Keyword in Java](https://www.baeldung.com/java-synchronized) - [Guide to the Synchronized Keyword in Java](https://www.baeldung.com/java-synchronized)
- [Life Cycle of a Thread in Java](https://www.baeldung.com/java-thread-lifecycle) - [Life Cycle of a Thread in Java](https://www.baeldung.com/java-thread-lifecycle)
- [[<-- Prev]](/core-java-modules/core-java-concurrency-basic)

View File

@ -17,3 +17,4 @@ This module contains articles about core java exceptions
- [Common Java Exceptions](https://www.baeldung.com/java-common-exceptions) - [Common Java Exceptions](https://www.baeldung.com/java-common-exceptions)
- [How to Find an Exceptions Root Cause in Java](https://www.baeldung.com/java-exception-root-cause) - [How to Find an Exceptions Root Cause in Java](https://www.baeldung.com/java-exception-root-cause)
- [Is It a Bad Practice to Catch Throwable?](https://www.baeldung.com/java-catch-throwable-bad-practice) - [Is It a Bad Practice to Catch Throwable?](https://www.baeldung.com/java-catch-throwable-bad-practice)
- [[Next -->]](/core-java-modules/core-java-exceptions-2)

View File

@ -156,10 +156,16 @@ public class FileClassUnitTest {
private static File makeDir(String name) { private static File makeDir(String name) {
File directory = new File(name); File directory = new File(name);
directory.mkdir();
if (directory.isDirectory()) { // If the directory already exists, make sure we create it 'from scratch', i.e. all the files inside are deleted first
if (directory.exists()) {
removeDir(directory);
}
if (directory.mkdir()) {
return directory; return directory;
} }
throw new RuntimeException("'" + name + "' not made!"); throw new RuntimeException("'" + name + "' not made!");
} }

View File

@ -0,0 +1,22 @@
package com.baeldung.overflow;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class OverflowUnitTest {
@Test
public void positive_and_negative_zero_are_not_always_equal() {
double a = +0f;
double b = -0f;
assertTrue(a == b);
assertTrue(1/a == Double.POSITIVE_INFINITY);
assertTrue(1/b == Double.NEGATIVE_INFINITY);
assertTrue(1/a != 1/b);
}
}

View File

@ -0,0 +1,37 @@
package com.baeldung.printbinarytree;
public class BinaryTreeModel {
private Object value;
private BinaryTreeModel left;
private BinaryTreeModel right;
public BinaryTreeModel(Object value) {
this.value = value;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
public BinaryTreeModel getLeft() {
return left;
}
public void setLeft(BinaryTreeModel left) {
this.left = left;
}
public BinaryTreeModel getRight() {
return right;
}
public void setRight(BinaryTreeModel right) {
this.right = right;
}
}

View File

@ -0,0 +1,63 @@
package com.baeldung.printbinarytree;
import java.io.PrintStream;
public class BinaryTreePrinter {
private BinaryTreeModel tree;
public BinaryTreePrinter(BinaryTreeModel tree) {
this.tree = tree;
}
private String traversePreOrder(BinaryTreeModel root) {
if (root == null) {
return "";
}
StringBuilder sb = new StringBuilder();
sb.append(root.getValue());
String pointerRight = "└──";
String pointerLeft = (root.getRight() != null) ? "├──" : "└──";
traverseNodes(sb, "", pointerLeft, root.getLeft(), root.getRight() != null);
traverseNodes(sb, "", pointerRight, root.getRight(), false);
return sb.toString();
}
private void traverseNodes(StringBuilder sb, String padding, String pointer, BinaryTreeModel node,
boolean hasRightSibling) {
if (node != null) {
sb.append("\n");
sb.append(padding);
sb.append(pointer);
sb.append(node.getValue());
StringBuilder paddingBuilder = new StringBuilder(padding);
if (hasRightSibling) {
paddingBuilder.append("");
} else {
paddingBuilder.append(" ");
}
String paddingForBoth = paddingBuilder.toString();
String pointerRight = "└──";
String pointerLeft = (node.getRight() != null) ? "├──" : "└──";
traverseNodes(sb, paddingForBoth, pointerLeft, node.getLeft(), node.getRight() != null);
traverseNodes(sb, paddingForBoth, pointerRight, node.getRight(), false);
}
}
public void print(PrintStream os) {
os.print(traversePreOrder(tree));
}
}

View File

@ -0,0 +1,178 @@
package com.baeldung.printbinarytree;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.baeldung.printbinarytree.BinaryTreeModel;
import com.baeldung.printbinarytree.BinaryTreePrinter;
public class PrintingBinaryTreeModelUnitTest {
private BinaryTreeModel balanced;
private BinaryTreeModel leftSkewed;
private BinaryTreeModel rightSkewed;
private OutputStream output;
@Before
public void setup() {
balanced = createBalancedTree();
leftSkewed = createLeftUnbalancedTree();
rightSkewed = createRightUnbalancedTree();
output = new ByteArrayOutputStream();
System.setOut(new PrintStream(output));
}
@After
public void tearDown() {
System.setOut(System.out);
}
private BinaryTreeModel createBalancedTree() {
BinaryTreeModel root = new BinaryTreeModel("root");
BinaryTreeModel node1 = new BinaryTreeModel("node1");
BinaryTreeModel node2 = new BinaryTreeModel("node2");
root.setLeft(node1);
root.setRight(node2);
BinaryTreeModel node3 = new BinaryTreeModel("node3");
BinaryTreeModel node4 = new BinaryTreeModel("node4");
node1.setLeft(node3);
node1.setRight(node4);
node2.setLeft(new BinaryTreeModel("node5"));
node2.setRight(new BinaryTreeModel("node6"));
BinaryTreeModel node7 = new BinaryTreeModel("node7");
node3.setLeft(node7);
node7.setLeft(new BinaryTreeModel("node8"));
node7.setRight(new BinaryTreeModel("node9"));
return root;
}
private BinaryTreeModel createLeftUnbalancedTree() {
BinaryTreeModel root = new BinaryTreeModel("root");
BinaryTreeModel node1 = new BinaryTreeModel("node1");
root.setLeft(node1);
root.setRight(new BinaryTreeModel("node2"));
BinaryTreeModel node3 = new BinaryTreeModel("node3");
node1.setLeft(node3);
BinaryTreeModel node4 = new BinaryTreeModel("node4");
node3.setLeft(node4);
BinaryTreeModel node5 = new BinaryTreeModel("node5");
node4.setLeft(node5);
BinaryTreeModel node6 = new BinaryTreeModel("node6");
node5.setLeft(node6);
BinaryTreeModel node7 = new BinaryTreeModel("node7");
node6.setLeft(node7);
node7.setLeft(new BinaryTreeModel("node8"));
return root;
}
private BinaryTreeModel createRightUnbalancedTree() {
BinaryTreeModel root = new BinaryTreeModel("root");
BinaryTreeModel node2 = new BinaryTreeModel("node2");
root.setLeft(new BinaryTreeModel("node1"));
root.setRight(node2);
BinaryTreeModel node3 = new BinaryTreeModel("node3");
node2.setRight(node3);
BinaryTreeModel node4 = new BinaryTreeModel("node4");
node3.setRight(node4);
BinaryTreeModel node5 = new BinaryTreeModel("node5");
node4.setRight(node5);
BinaryTreeModel node6 = new BinaryTreeModel("node6");
node5.setRight(node6);
BinaryTreeModel node7 = new BinaryTreeModel("node7");
node6.setRight(node7);
node7.setRight(new BinaryTreeModel("node8"));
return root;
}
@Test
public void givenBinaryTreeModelBalanced_whenPrintWithBinaryTreePrinter_thenProduceCorrectOutput() {
StringBuilder expected = new StringBuilder();
expected.append("root").append("\n");
expected.append("├──node1").append("\n");
expected.append("│ ├──node3").append("\n");
expected.append("│ │ └──node7").append("\n");
expected.append("│ │ ├──node8").append("\n");
expected.append("│ │ └──node9").append("\n");
expected.append("│ └──node4").append("\n");
expected.append("└──node2").append("\n");
expected.append(" ├──node5").append("\n");
expected.append(" └──node6");
new BinaryTreePrinter(balanced).print(System.out);
assertEquals(expected.toString(), output.toString());
}
@Test
public void givenBinaryTreeModelLeftUnbalanced_whenPrintWithBinaryTreePrinter_thenProduceCorrectOutput() {
StringBuilder expected = new StringBuilder();
expected.append("root").append("\n");
expected.append("├──node1").append("\n");
expected.append("│ └──node3").append("\n");
expected.append("│ └──node4").append("\n");
expected.append("│ └──node5").append("\n");
expected.append("│ └──node6").append("\n");
expected.append("│ └──node7").append("\n");
expected.append("│ └──node8").append("\n");
expected.append("└──node2");
new BinaryTreePrinter(leftSkewed).print(System.out);
assertEquals(expected.toString(), output.toString());
}
@Test
public void givenBinaryTreeModelRightUnbalanced_whenPrintWithBinaryTreePrinter_thenProduceCorrectOutput() {
StringBuilder expected = new StringBuilder();
expected.append("root").append("\n");
expected.append("├──node1").append("\n");
expected.append("└──node2").append("\n");
expected.append(" └──node3").append("\n");
expected.append(" └──node4").append("\n");
expected.append(" └──node5").append("\n");
expected.append(" └──node6").append("\n");
expected.append(" └──node7").append("\n");
expected.append(" └──node8");
new BinaryTreePrinter(rightSkewed).print(System.out);
assertEquals(expected.toString(), output.toString());
}
}

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.entities; package com.baeldung.gson.entities;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.entities; package com.baeldung.gson.entities;
public abstract class Animal { public abstract class Animal {
public String type = "Animal"; public String type = "Animal";

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.entities; package com.baeldung.gson.entities;
public class Cow extends Animal { public class Cow extends Animal {
private String breed; private String breed;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.entities; package com.baeldung.gson.entities;
public class Dog extends Animal { public class Dog extends Animal {
private String petName; private String petName;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.entities; package com.baeldung.gson.entities;
public class Employee { public class Employee {
private int id; private int id;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.entities; package com.baeldung.gson.entities;
import java.util.List; import java.util.List;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.entities; package com.baeldung.gson.entities;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.entities; package com.baeldung.gson.entities;
import java.util.Objects; import java.util.Objects;

View File

@ -1,19 +1,19 @@
package org.baeldung.gson.entities; package com.baeldung.gson.entities;
public class User { public class User {
private int id; private int id;
private String name; private String name;
private transient String nationality; private transient String nationality;
public User(int id, String name, String nationality) { public User(int id, String name, String nationality) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.nationality = nationality; this.nationality = nationality;
} }
public User(int id, String name) { public User(int id, String name) {
this(id, name, null); this(id, name, null);
} }
} }

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.entities; package com.baeldung.gson.entities;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.primitives.models; package com.baeldung.gson.primitives.models;
public class BooleanExample { public class BooleanExample {
public boolean value; public boolean value;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.primitives.models; package com.baeldung.gson.primitives.models;
public class ByteExample { public class ByteExample {
public byte value = (byte) 1; public byte value = (byte) 1;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.primitives.models; package com.baeldung.gson.primitives.models;
public class CharExample { public class CharExample {
public char value; public char value;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.primitives.models; package com.baeldung.gson.primitives.models;
public class DoubleExample { public class DoubleExample {
public double value; public double value;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.primitives.models; package com.baeldung.gson.primitives.models;
public class FloatExample { public class FloatExample {
public float value; public float value;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.primitives.models; package com.baeldung.gson.primitives.models;
public class InfinityValuesExample { public class InfinityValuesExample {
public float negativeInfinity; public float negativeInfinity;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.primitives.models; package com.baeldung.gson.primitives.models;
public class LongExample { public class LongExample {
public long value = 1; public long value = 1;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.primitives.models; package com.baeldung.gson.primitives.models;
public class PrimitiveBundle { public class PrimitiveBundle {
public byte byteValue; public byte byteValue;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.primitives.models; package com.baeldung.gson.primitives.models;
public class PrimitiveBundleInitialized { public class PrimitiveBundleInitialized {
// @formatter:off // @formatter:off

View File

@ -1,11 +1,11 @@
package org.baeldung.gson.serialization; package com.baeldung.gson.serialization;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import org.baeldung.gson.entities.ActorGson; import com.baeldung.gson.entities.ActorGson;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializationContext;

View File

@ -1,10 +1,10 @@
package org.baeldung.gson.serialization; package com.baeldung.gson.serialization;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer; import com.google.gson.JsonSerializer;
import org.baeldung.gson.entities.ActorGson; import com.baeldung.gson.entities.ActorGson;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.serialization; package com.baeldung.gson.serialization;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializationContext;
@ -8,7 +8,7 @@ import com.google.gson.JsonObject;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.baeldung.gson.entities.Animal; import com.baeldung.gson.entities.Animal;
public class AnimalDeserializer implements JsonDeserializer<Animal> { public class AnimalDeserializer implements JsonDeserializer<Animal> {
private String animalTypeElementName; private String animalTypeElementName;

View File

@ -1,12 +1,11 @@
package org.baeldung.gson.serialization; package com.baeldung.gson.serialization;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.baeldung.gson.entities.Employee; import com.baeldung.gson.entities.Employee;
import com.google.gson.*; import com.google.gson.*;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.serialization; package com.baeldung.gson.serialization;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.text.ParseException; import java.text.ParseException;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.serializationwithexclusions; package com.baeldung.gson.serializationwithexclusions;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.serializationwithexclusions; package com.baeldung.gson.serializationwithexclusions;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.serializationwithexclusions; package com.baeldung.gson.serializationwithexclusions;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.serializationwithexclusions; package com.baeldung.gson.serializationwithexclusions;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.serializationwithexclusions; package com.baeldung.gson.serializationwithexclusions;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.serializationwithexclusions; package com.baeldung.gson.serializationwithexclusions;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.serializationwithexclusions; package com.baeldung.gson.serializationwithexclusions;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.serializationwithexclusions; package com.baeldung.gson.serializationwithexclusions;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.serializationwithexclusions; package com.baeldung.gson.serializationwithexclusions;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;

View File

@ -1,8 +1,9 @@
package org.baeldung.gson.advance; package com.baeldung.gson.advance;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import com.baeldung.gson.entities.Dog;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
@ -10,11 +11,10 @@ import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.baeldung.gson.entities.Animal; import com.baeldung.gson.entities.Animal;
import org.baeldung.gson.entities.Cow; import com.baeldung.gson.entities.Cow;
import org.baeldung.gson.entities.Dog; import com.baeldung.gson.entities.MyClass;
import org.baeldung.gson.entities.MyClass; import com.baeldung.gson.serialization.AnimalDeserializer;
import org.baeldung.gson.serialization.AnimalDeserializer;
import org.junit.Test; import org.junit.Test;
public class GsonAdvanceUnitTest { public class GsonAdvanceUnitTest {

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.advance; package com.baeldung.gson.advance;
/* /*
* Copyright (C) 2011 Google Inc. * Copyright (C) 2011 Google Inc.

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.conversion; package com.baeldung.gson.conversion;
import com.google.gson.*; import com.google.gson.*;
import org.junit.Assert; import org.junit.Assert;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.deserialization; package com.baeldung.gson.deserialization;
public class Foo { public class Foo {
public int intValue; public int intValue;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.deserialization; package com.baeldung.gson.deserialization;
import java.lang.reflect.Type; import java.lang.reflect.Type;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.deserialization; package com.baeldung.gson.deserialization;
import java.lang.reflect.Type; import java.lang.reflect.Type;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.deserialization; package com.baeldung.gson.deserialization;
import java.lang.reflect.Type; import java.lang.reflect.Type;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.deserialization; package com.baeldung.gson.deserialization;
public class FooWithInner { public class FooWithInner {
public int intValue; public int intValue;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.deserialization; package com.baeldung.gson.deserialization;
public class GenericFoo<T> { public class GenericFoo<T> {

View File

@ -1,8 +1,8 @@
package org.baeldung.gson.deserialization; package com.baeldung.gson.deserialization;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import org.baeldung.gson.entities.Weather; import com.baeldung.gson.entities.Weather;
import org.junit.Test; import org.junit.Test;
import com.google.gson.Gson; import com.google.gson.Gson;

View File

@ -1,10 +1,10 @@
package org.baeldung.gson.deserialization; package com.baeldung.gson.deserialization;
import java.text.ParseException; import java.text.ParseException;
import org.baeldung.gson.entities.ActorGson; import com.baeldung.gson.entities.Movie;
import org.baeldung.gson.entities.Movie; import com.baeldung.gson.serialization.ActorGsonDeserializer;
import org.baeldung.gson.serialization.ActorGsonDeserializer; import com.baeldung.gson.entities.ActorGson;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.deserialization; package com.baeldung.gson.deserialization;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.text.ParseException; import java.text.ParseException;
@ -6,9 +6,9 @@ import java.util.Date;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.baeldung.gson.entities.Employee; import com.baeldung.gson.entities.Employee;
import org.baeldung.gson.serialization.MapDeserializer; import com.baeldung.gson.serialization.MapDeserializer;
import org.baeldung.gson.serialization.StringDateMapDeserializer; import com.baeldung.gson.serialization.StringDateMapDeserializer;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.deserialization.test; package com.baeldung.gson.deserialization.test;
import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.instanceOf;
@ -10,11 +10,11 @@ import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import org.baeldung.gson.deserialization.Foo; import com.baeldung.gson.deserialization.Foo;
import org.baeldung.gson.deserialization.FooDeserializerFromJsonWithDifferentFields; import com.baeldung.gson.deserialization.FooDeserializerFromJsonWithDifferentFields;
import org.baeldung.gson.deserialization.FooInstanceCreator; import com.baeldung.gson.deserialization.FooInstanceCreator;
import org.baeldung.gson.deserialization.FooWithInner; import com.baeldung.gson.deserialization.FooWithInner;
import org.baeldung.gson.deserialization.GenericFoo; import com.baeldung.gson.deserialization.GenericFoo;
import org.junit.Test; import org.junit.Test;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;

View File

@ -1,7 +1,7 @@
package org.baeldung.gson.primitives; package com.baeldung.gson.primitives;
import com.baeldung.gson.primitives.models.*;
import com.google.gson.*; import com.google.gson.*;
import org.baeldung.gson.primitives.models.*;
import org.junit.Test; import org.junit.Test;
import java.lang.reflect.Type; import java.lang.reflect.Type;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.serialization; package com.baeldung.gson.serialization;
import java.lang.reflect.Type; import java.lang.reflect.Type;

View File

@ -1,11 +1,11 @@
package org.baeldung.gson.serialization; package com.baeldung.gson.serialization;
import com.baeldung.gson.entities.Movie;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import org.baeldung.gson.entities.ActorGson; import com.baeldung.gson.entities.ActorGson;
import org.baeldung.gson.entities.Movie; import com.baeldung.gson.entities.MovieWithNullValue;
import org.baeldung.gson.entities.MovieWithNullValue;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.serialization; package com.baeldung.gson.serialization;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.serialization; package com.baeldung.gson.serialization;
import java.lang.reflect.Type; import java.lang.reflect.Type;

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.serialization; package com.baeldung.gson.serialization;
public class SourceClass { public class SourceClass {
private int intValue; private int intValue;

View File

@ -1,18 +1,16 @@
package org.baeldung.gson.serialization.test; package com.baeldung.gson.serialization.test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Calendar;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar;
import org.baeldung.gson.serialization.DifferentNameSerializer; import com.baeldung.gson.serialization.DifferentNameSerializer;
import org.baeldung.gson.serialization.IgnoringFieldsNotMatchingCriteriaSerializer; import com.baeldung.gson.serialization.IgnoringFieldsNotMatchingCriteriaSerializer;
import org.baeldung.gson.serialization.IgnoringFieldsSerializer; import com.baeldung.gson.serialization.IgnoringFieldsSerializer;
import org.baeldung.gson.serialization.SourceClass; import com.baeldung.gson.serialization.SourceClass;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.junit.Test; import org.junit.Test;

View File

@ -1,43 +1,43 @@
package org.baeldung.gson.serialization.test; package com.baeldung.gson.serialization.test;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.Writer; import java.io.Writer;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import org.baeldung.gson.entities.User; import com.baeldung.gson.entities.User;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters; import org.junit.runners.Parameterized.Parameters;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
@RunWith(Parameterized.class) @RunWith(Parameterized.class)
public class JsonFileUnitTest { public class JsonFileUnitTest {
@Parameter @Parameter
public Object object; public Object object;
@Parameters @Parameters
public static Object[] data() { public static Object[] data() {
return new Object[] { 123.45, new User(1, "Tom", "American") }; return new Object[] { 123.45, new User(1, "Tom", "American") };
} }
@Test @Test
public void givenProperData_whenStoredInFile_shouldSaveJsonSuccessfully() { public void givenProperData_whenStoredInFile_shouldSaveJsonSuccessfully() {
String filePath = "target/output.json"; String filePath = "target/output.json";
try (Writer writer = new FileWriter(filePath)) { try (Writer writer = new FileWriter(filePath)) {
Gson gson = new GsonBuilder().setPrettyPrinting().create(); Gson gson = new GsonBuilder().setPrettyPrinting().create();
gson.toJson(object, writer); gson.toJson(object, writer);
Assert.assertTrue(Files.exists(Paths.get(filePath))); Assert.assertTrue(Files.exists(Paths.get(filePath)));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }

View File

@ -1,4 +1,4 @@
package org.baeldung.gson.serializationwithexclusions; package com.baeldung.gson.serializationwithexclusions;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava; package com.baeldung.guava;
public class CustomEvent { public class CustomEvent {
private String action; private String action;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava; package com.baeldung.guava;
import com.google.common.eventbus.DeadEvent; import com.google.common.eventbus.DeadEvent;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava.memoizer; package com.baeldung.guava.memoizer;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Random; import java.util.Random;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava.memoizer; package com.baeldung.guava.memoizer;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;

View File

@ -1,11 +1,10 @@
package org.baeldung.guava.memoizer; package com.baeldung.guava.memoizer;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.concurrent.TimeUnit;
public class FibonacciSequence { public class FibonacciSequence {

View File

@ -1,4 +1,4 @@
package org.baeldung.guava; package com.baeldung.guava;
import com.google.common.hash.BloomFilter; import com.google.common.hash.BloomFilter;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava; package com.baeldung.guava;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava; package com.baeldung.guava;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava; package com.baeldung.guava;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava; package com.baeldung.guava;
import static org.junit.Assert.*; import static org.junit.Assert.*;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava; package com.baeldung.guava;
import com.google.common.eventbus.EventBus; import com.google.common.eventbus.EventBus;
import org.junit.After; import org.junit.After;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava; package com.baeldung.guava;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava; package com.baeldung.guava;
import static org.junit.Assert.*; import static org.junit.Assert.*;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava; package com.baeldung.guava;
import static org.junit.Assert.*; import static org.junit.Assert.*;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava; package com.baeldung.guava;
import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.*; import static org.junit.Assert.*;

View File

@ -1,9 +1,9 @@
package org.baeldung.guava; package com.baeldung.guava;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
import org.baeldung.guava.memoizer.CostlySupplier; import com.baeldung.guava.memoizer.CostlySupplier;
import org.baeldung.guava.memoizer.Factorial; import com.baeldung.guava.memoizer.Factorial;
import org.baeldung.guava.memoizer.FibonacciSequence; import com.baeldung.guava.memoizer.FibonacciSequence;
import org.junit.Test; import org.junit.Test;
import java.math.BigInteger; import java.math.BigInteger;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava; package com.baeldung.guava;
import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.util.Arrays; import java.util.Arrays;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava; package com.baeldung.guava;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava; package com.baeldung.guava;
import com.google.common.util.concurrent.RateLimiter; import com.google.common.util.concurrent.RateLimiter;

View File

@ -1,4 +1,4 @@
package org.baeldung.httpclient; package com.baeldung.httpclient;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;

View File

@ -1,4 +1,4 @@
package org.baeldung.httpclient; package com.baeldung.httpclient;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
@ -38,7 +38,7 @@ public class HttpClientMultipartLiveTest {
private static final String TEXTFILENAME = "temp.txt"; private static final String TEXTFILENAME = "temp.txt";
private static final String IMAGEFILENAME = "image.jpg"; private static final String IMAGEFILENAME = "image.jpg";
private static final String ZIPFILENAME = "zipFile.zip"; private static final String ZIPFILENAME = "zipFile.zip";
private static final Logger LOGGER = Logger.getLogger("org.baeldung.httpclient.HttpClientMultipartLiveTest"); private static final Logger LOGGER = Logger.getLogger("com.baeldung.httpclient.HttpClientMultipartLiveTest");
private CloseableHttpClient client; private CloseableHttpClient client;
private HttpPost post; private HttpPost post;
private BufferedReader rd; private BufferedReader rd;

View File

@ -1,4 +1,4 @@
package org.baeldung.httpclient; package com.baeldung.httpclient;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;

View File

@ -1,4 +1,4 @@
package org.baeldung.httpclient; package com.baeldung.httpclient;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;

View File

@ -1,4 +1,4 @@
package org.baeldung.httpclient.advancedconfig; package com.baeldung.httpclient.advancedconfig;
import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.github.tomakehurst.wiremock.junit.WireMockRule;

View File

@ -1,5 +1,6 @@
package org.baeldung.httpclient.base; package com.baeldung.httpclient.base;
import com.baeldung.httpclient.ResponseUtil;
import org.apache.http.auth.AuthenticationException; import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
@ -8,7 +9,6 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.impl.auth.BasicScheme; import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.baeldung.httpclient.ResponseUtil;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -1,5 +1,6 @@
package org.baeldung.httpclient.base; package com.baeldung.httpclient.base;
import com.baeldung.httpclient.ResponseUtil;
import org.apache.http.Header; import org.apache.http.Header;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders; import org.apache.http.HttpHeaders;
@ -11,7 +12,6 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager; import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
import org.baeldung.httpclient.ResponseUtil;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -1,5 +1,6 @@
package org.baeldung.httpclient.base; package com.baeldung.httpclient.base;
import com.baeldung.httpclient.ResponseUtil;
import org.apache.http.auth.AuthScope; import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider; import org.apache.http.client.CredentialsProvider;
@ -8,7 +9,6 @@ import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.baeldung.httpclient.ResponseUtil;
import org.junit.Test; import org.junit.Test;
import java.io.IOException; import java.io.IOException;

View File

@ -1,4 +1,4 @@
package org.baeldung.httpclient.conn; package com.baeldung.httpclient.conn;
import org.apache.http.HeaderElement; import org.apache.http.HeaderElement;
import org.apache.http.HeaderElementIterator; import org.apache.http.HeaderElementIterator;

Some files were not shown because too many files have changed in this diff Show More