JAVA-1522 Split core-java-modules/core-java module

This commit is contained in:
mikr
2020-06-07 16:52:25 +02:00
parent 4cb07819f3
commit aece4e5216
28 changed files with 10 additions and 86 deletions

View File

@@ -9,3 +9,4 @@
- [Differences Between Collection.clear() and Collection.removeAll()](https://www.baeldung.com/java-collection-clear-vs-removeall)
- [Performance of contains() in a HashSet vs ArrayList](https://www.baeldung.com/java-hashset-arraylist-contains-performance)
- [Fail-Safe Iterator vs Fail-Fast Iterator](https://www.baeldung.com/java-fail-safe-vs-fail-fast-iterator)
- [Quick Guide to the Java Stack](https://www.baeldung.com/java-stack)

View File

@@ -14,8 +14,5 @@ public class AsciiArtIntegrationTest {
Settings settings = asciiArt.new Settings(new Font("SansSerif", Font.BOLD, 24), text.length() * 30, 30); // 30 pixel width per character
asciiArt.drawString(text, "*", settings);
throw new NullPointerException();
}
}

View File

@@ -8,4 +8,5 @@ This module contains articles about date operations in Java.
- [Converting Java Date to OffsetDateTime](https://www.baeldung.com/java-convert-date-to-offsetdatetime)
- [How to Set the JVM Time Zone](https://www.baeldung.com/java-jvm-time-zone)
- [How to determine day of week by passing specific date in Java?](https://www.baeldung.com/java-get-day-of-week)
- [Finding Leap Years in Java](https://www.baeldung.com/java-leap-year)
- [[<-- Prev]](/core-java-modules/core-java-date-operations-1)

View File

@@ -12,3 +12,4 @@ This module contains articles about working with the Java Virtual Machine (JVM).
- [Guide to System.gc()](https://www.baeldung.com/java-system-gc)
- [Runtime.getRuntime().halt() vs System.exit() in Java](https://www.baeldung.com/java-runtime-halt-vs-system-exit)
- [Adding Shutdown Hooks for JVM Applications](https://www.baeldung.com/jvm-shutdown-hooks)
- [How to Get the Size of an Object in Java](http://www.baeldung.com/java-size-of-object)

View File

@@ -8,3 +8,5 @@
- [Changing Annotation Parameters At Runtime](http://www.baeldung.com/java-reflection-change-annotation-params)
- [Dynamic Proxies in Java](http://www.baeldung.com/java-dynamic-proxies)
- [What Causes java.lang.reflect.InvocationTargetException?](https://www.baeldung.com/java-lang-reflect-invocationtargetexception)
- [How to Find all Getters Returning Null](http://www.baeldung.com/java-getters-returning-null)
- [How to Get a Name of a Method Being Executed?](http://www.baeldung.com/java-name-of-executing-method)

View File

@@ -12,4 +12,6 @@ This module contains articles about string operations.
- [L-Trim and R-Trim Alternatives in Java](https://www.baeldung.com/java-trim-alternatives)
- [Java Convert PDF to Base64](https://www.baeldung.com/java-convert-pdf-to-base64)
- [Encode a String to UTF-8 in Java](https://www.baeldung.com/java-string-encode-utf-8)
- [Guide to Character Encoding](https://www.baeldung.com/java-char-encoding)
- [Convert Hex to ASCII in Java](https://www.baeldung.com/java-convert-hex-to-ascii) #remove additional readme file
- More articles: [[<-- prev]](../core-java-string-operations)

View File

@@ -6,3 +6,4 @@ This module contains articles about the measurement of time in Java.
- [Guide to the Java Clock Class](http://www.baeldung.com/java-clock)
- [Measure Elapsed Time in Java](http://www.baeldung.com/java-measure-elapsed-time)
- [Overriding System Time for Testing in Java](https://www.baeldung.com/java-override-system-time)
- [Java Timer](http://www.baeldung.com/java-timer-and-timertask)

View File

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

View File

@@ -1,44 +1,6 @@
## Core Java Cookbooks and Examples
### Relevant Articles:
- [Java Timer](http://www.baeldung.com/java-timer-and-timertask)
- [Getting Started with Java Properties](http://www.baeldung.com/java-properties)
- [Introduction to Nashorn](http://www.baeldung.com/java-nashorn)
- [Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency)
- [JVM Log Forging](http://www.baeldung.com/jvm-log-forging)
- [How to Find all Getters Returning Null](http://www.baeldung.com/java-getters-returning-null)
- [How to Get a Name of a Method Being Executed?](http://www.baeldung.com/java-name-of-executing-method)
- [Introduction to Java Serialization](http://www.baeldung.com/java-serialization)
- [Guide to UUID in Java](http://www.baeldung.com/java-uuid)
- [Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin)
- [Quick Guide to the Java Stack](https://www.baeldung.com/java-stack)
- [Compiling Java *.class Files with javac](http://www.baeldung.com/javac)
- [Introduction to Javadoc](http://www.baeldung.com/javadoc)
- [Guide to the Externalizable Interface in Java](http://www.baeldung.com/java-externalizable)
- [ASCII Art in Java](http://www.baeldung.com/ascii-art-in-java)
- [What is the serialVersionUID?](http://www.baeldung.com/java-serial-version-uid)
- [A Guide to the ResourceBundle](http://www.baeldung.com/java-resourcebundle)
- [Java Global Exception Handler](http://www.baeldung.com/java-global-exception-handler)
- [How to Get the Size of an Object in Java](http://www.baeldung.com/java-size-of-object)
- [Common Java Exceptions](http://www.baeldung.com/java-common-exceptions)
- [Merging java.util.Properties Objects](https://www.baeldung.com/java-merging-properties)
- [Java Try with Resources](https://www.baeldung.com/java-try-with-resources)
- [Guide to Character Encoding](https://www.baeldung.com/java-char-encoding)
- [Graphs in Java](https://www.baeldung.com/java-graphs)
- [Read and Write User Input in Java](http://www.baeldung.com/java-console-input-output)
- [Formatting with printf() in Java](https://www.baeldung.com/java-printstream-printf)
- [Retrieve Fields from a Java Class Using Reflection](https://www.baeldung.com/java-reflection-class-fields)
- [Using Curl in Java](https://www.baeldung.com/java-curl)
- [Finding Leap Years in Java](https://www.baeldung.com/java-leap-year)
- [Making a JSON POST Request With HttpURLConnection](https://www.baeldung.com/httpurlconnection-post)
- [How to Find an Exceptions Root Cause in Java](https://www.baeldung.com/java-exception-root-cause)
- [Convert Hex to ASCII in Java](https://www.baeldung.com/java-convert-hex-to-ascii)
#New module structure
###########################
#Leave in core-java:
[Getting Started with Java Properties](http://www.baeldung.com/java-properties)
[Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency)
[Introduction to Java Serialization](http://www.baeldung.com/java-serialization)
@@ -49,47 +11,3 @@
[What is the serialVersionUID?](http://www.baeldung.com/java-serial-version-uid)
[A Guide to the ResourceBundle](http://www.baeldung.com/java-resourcebundle)
[Merging java.util.Properties Objects](https://www.baeldung.com/java-merging-properties)
#Move to language interop (Done)
[Introduction to Nashorn](http://www.baeldung.com/java-nashorn)
#Move to new new package: core-java-console (Done)
[Read and Write User Input in Java](http://www.baeldung.com/java-console-input-output)
[Formatting with printf() in Java](https://www.baeldung.com/java-printstream-printf)
[ASCII Art in Java](http://www.baeldung.com/ascii-art-in-java)
#Move to core-java-string-operations-2
[Guide to Character Encoding](https://www.baeldung.com/java-char-encoding)
[Convert Hex to ASCII in Java](https://www.baeldung.com/java-convert-hex-to-ascii) #remove additional readme file
#Move to core-javadatetime-operations-2
[Finding Leap Years in Java](https://www.baeldung.com/java-leap-year)
#Move to core-java-time-measurements
[Java Timer](http://www.baeldung.com/java-timer-and-timertask)
#Move to core-java-reflection
[How to Get a Name of a Method Being Executed?](http://www.baeldung.com/java-name-of-executing-method)
#Move to core-java-streams
[How to Find all Getters Returning Null](http://www.baeldung.com/java-getters-returning-null)
#Move to core-java-jvm
[How to Get the Size of an Object in Java](http://www.baeldung.com/java-size-of-object)
#Move to data-structures module
[Graphs in Java](https://www.baeldung.com/java-graphs)
#Move to core-java-collections-3
[Quick Guide to the Java Stack](https://www.baeldung.com/java-stack)
#These are already in another module
[Using Curl in Java](https://www.baeldung.com/java-curl) #Core Java Networking (Part 2)
[Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin) # Core Java Sun
[Java Global Exception Handler](http://www.baeldung.com/java-global-exception-handler) #Core Java Exceptions
[Java Try with Resources](https://www.baeldung.com/java-try-with-resources) #Core Java Exceptions
[How to Find an Exceptions Root Cause in Java](https://www.baeldung.com/java-exception-root-cause) #Core Java Exceptions
[JVM Log Forging](http://www.baeldung.com/jvm-log-forging) #Core Java JVM
[Making a JSON POST Request With HttpURLConnection](https://www.baeldung.com/httpurlconnection-post) #Core Java Networking (Part 2)
[Common Java Exceptions](http://www.baeldung.com/java-common-exceptions) #Core Java Exceptions
[Retrieve Fields from a Java Class Using Reflection](https://www.baeldung.com/java-reflection-class-fields) #Core Java Reflection

View File

@@ -1,101 +0,0 @@
package com.baeldung.graph;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class Graph {
private Map<Vertex, List<Vertex>> adjVertices;
Graph() {
this.adjVertices = new HashMap<Vertex, List<Vertex>>();
}
void addVertex(String label) {
adjVertices.putIfAbsent(new Vertex(label), new ArrayList<>());
}
void removeVertex(String label) {
Vertex v = new Vertex(label);
adjVertices.values().stream().forEach(e -> e.remove(v));
adjVertices.remove(new Vertex(label));
}
void addEdge(String label1, String label2) {
Vertex v1 = new Vertex(label1);
Vertex v2 = new Vertex(label2);
adjVertices.get(v1).add(v2);
adjVertices.get(v2).add(v1);
}
void removeEdge(String label1, String label2) {
Vertex v1 = new Vertex(label1);
Vertex v2 = new Vertex(label2);
List<Vertex> eV1 = adjVertices.get(v1);
List<Vertex> eV2 = adjVertices.get(v2);
if (eV1 != null)
eV1.remove(v2);
if (eV2 != null)
eV2.remove(v1);
}
List<Vertex> getAdjVertices(String label) {
return adjVertices.get(new Vertex(label));
}
String printGraph() {
StringBuffer sb = new StringBuffer();
for(Vertex v : adjVertices.keySet()) {
sb.append(v);
sb.append(adjVertices.get(v));
}
return sb.toString();
}
class Vertex {
String label;
Vertex(String label) {
this.label = label;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + getOuterType().hashCode();
result = prime * result + ((label == null) ? 0 : label.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Vertex other = (Vertex) obj;
if (!getOuterType().equals(other.getOuterType()))
return false;
if (label == null) {
if (other.label != null)
return false;
} else if (!label.equals(other.label))
return false;
return true;
}
@Override
public String toString() {
return label;
}
private Graph getOuterType() {
return Graph.this;
}
}
}

View File

@@ -1,44 +0,0 @@
package com.baeldung.graph;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;
import java.util.Stack;
import com.baeldung.graph.Graph.Vertex;
public class GraphTraversal {
static Set<String> depthFirstTraversal(Graph graph, String root) {
Set<String> visited = new LinkedHashSet<String>();
Stack<String> stack = new Stack<String>();
stack.push(root);
while (!stack.isEmpty()) {
String vertex = stack.pop();
if (!visited.contains(vertex)) {
visited.add(vertex);
for (Vertex v : graph.getAdjVertices(vertex)) {
stack.push(v.label);
}
}
}
return visited;
}
static Set<String> breadthFirstTraversal(Graph graph, String root) {
Set<String> visited = new LinkedHashSet<String>();
Queue<String> queue = new LinkedList<String>();
queue.add(root);
visited.add(root);
while (!queue.isEmpty()) {
String vertex = queue.poll();
for (Vertex v : graph.getAdjVertices(vertex)) {
if (!visited.contains(v.label)) {
visited.add(v.label);
queue.add(v.label);
}
}
}
return visited;
}
}

View File

@@ -1,47 +0,0 @@
package com.baeldung.graph;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class GraphUnitTest {
@Test
public void givenAGraph_whenTraversingDepthFirst_thenExpectedResult() {
Graph graph = createGraph();
assertEquals("[Bob, Rob, Maria, Alice, Mark]",
GraphTraversal.depthFirstTraversal(graph, "Bob").toString());
}
@Test
public void givenAGraph_whenTraversingBreadthFirst_thenExpectedResult() {
Graph graph = createGraph();
assertEquals("[Bob, Alice, Rob, Mark, Maria]",
GraphTraversal.breadthFirstTraversal(graph, "Bob").toString());
}
@Test
public void givenAGraph_whenRemoveVertex_thenVertedNotFound() {
Graph graph = createGraph();
assertEquals("[Bob, Alice, Rob, Mark, Maria]",
GraphTraversal.breadthFirstTraversal(graph, "Bob").toString());
graph.removeVertex("Maria");
assertEquals("[Bob, Alice, Rob, Mark]",
GraphTraversal.breadthFirstTraversal(graph, "Bob").toString());
}
Graph createGraph() {
Graph graph = new Graph();
graph.addVertex("Bob");
graph.addVertex("Alice");
graph.addVertex("Mark");
graph.addVertex("Rob");
graph.addVertex("Maria");
graph.addEdge("Bob", "Alice");
graph.addEdge("Bob", "Rob");
graph.addEdge("Alice", "Mark");
graph.addEdge("Rob", "Mark");
graph.addEdge("Alice", "Maria");
graph.addEdge("Rob", "Maria");
return graph;
}
}