-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82b15d0
commit 33ebe6d
Showing
4 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
public class Edge { | ||
|
||
private String id; | ||
private Vertex vertex1 = new Vertex(); | ||
private Vertex vertex2 = new Vertex(); | ||
private int weight; | ||
|
||
public Edge() { | ||
} | ||
|
||
public Edge(String id, Vertex vertex1, Vertex vertex2, int weight) { | ||
this.id = id; | ||
this.vertex1 = vertex1; | ||
this.vertex2 = vertex2; | ||
this.weight = weight; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public Vertex getVertex1() { | ||
return vertex1; | ||
} | ||
|
||
public void setVertex1(Vertex vertex1) { | ||
this.vertex1 = vertex1; | ||
} | ||
|
||
public Vertex getVertex2() { | ||
return vertex2; | ||
} | ||
|
||
public void setVertex2(Vertex vertex2) { | ||
this.vertex2 = vertex2; | ||
} | ||
|
||
public int getWeight() { | ||
return weight; | ||
} | ||
|
||
public void setWeight(int weight) { | ||
this.weight = weight; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Graph { | ||
|
||
private List<Edge> edges = new ArrayList<>(); | ||
private List<Vertex> vertices = new ArrayList<>(); | ||
|
||
public Graph(List<Edge> edges, List<Vertex> vertices) { | ||
this.edges = edges; | ||
this.vertices = vertices; | ||
} | ||
|
||
public List<Edge> getEdges() { | ||
return edges; | ||
} | ||
|
||
public void setEdges(List<Edge> edges) { | ||
this.edges = edges; | ||
} | ||
|
||
public List<Vertex> getVertices() { | ||
return vertices; | ||
} | ||
|
||
public void setVertices(List<Vertex> vertices) { | ||
this.vertices = vertices; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import java.util.List; | ||
import java.util.Random; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
|
||
public class Rand { | ||
|
||
public List<Integer> generateRandomInts(boolean negativeAllowed, int startInclusive, int endInclusive, int limit) { | ||
|
||
List<Integer> intList; | ||
|
||
Random random = new Random(System.currentTimeMillis()); | ||
intList = random.ints() | ||
.map(x -> x % (Math.max(Math.abs(startInclusive), endInclusive)) + 1) | ||
.map(x -> negativeAllowed ? x : Math.abs(x)) | ||
.filter(x -> x >= startInclusive && x <= endInclusive) | ||
.boxed() | ||
.limit(limit) | ||
.collect(Collectors.toList()); | ||
|
||
return intList; | ||
} | ||
|
||
public List<Integer> generateInts(boolean negativeAllowed, int startInclusive, int endInclusive, int interval) { | ||
List<Integer> intList; | ||
IntStream intStream; | ||
|
||
intStream = IntStream.range(startInclusive, endInclusive + 1); | ||
intList = intStream | ||
.map(x -> negativeAllowed ? x : Math.abs(x)) | ||
.filter(x -> x % interval == 0) | ||
.boxed() | ||
.collect(Collectors.toList()); | ||
|
||
return intList; | ||
} | ||
|
||
|
||
public void printGeneratedInts(List<Integer> integers) { | ||
|
||
for (Integer integer : integers) { | ||
System.out.println(integer); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
|
||
Rand rand = new Rand(); | ||
|
||
List<Integer> randomInts = rand.generateRandomInts(true, 0, 20, 10); | ||
rand.printGeneratedInts(randomInts); | ||
|
||
List<Integer> integers = rand.generateInts(false, 0, 20, 5); | ||
rand.printGeneratedInts(integers); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Vertex { | ||
|
||
private String id; | ||
private Vertex prev = new Vertex(); | ||
private List<Vertex> adjVertices = new ArrayList<>(); | ||
|
||
Vertex() { | ||
} | ||
|
||
public Vertex(String id, Vertex prev, List<Vertex> adjVertices) { | ||
this.id = id; | ||
this.prev = prev; | ||
this.adjVertices = adjVertices; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public Vertex getPrev() { | ||
return prev; | ||
} | ||
|
||
public void setPrev(Vertex prev) { | ||
this.prev = prev; | ||
} | ||
|
||
public List<Vertex> getAdjVertices() { | ||
return adjVertices; | ||
} | ||
|
||
public void setAdjVertices(List<Vertex> adjVertices) { | ||
this.adjVertices = adjVertices; | ||
} | ||
} |