-
Notifications
You must be signed in to change notification settings - Fork 0
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
haniotak
committed
Oct 30, 2024
1 parent
c25e0e9
commit b19de48
Showing
11 changed files
with
364 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,2 @@ | ||
#!/usr/bin/env bash | ||
mvn package exec:java |
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,69 @@ | ||
[ | ||
{ | ||
"name": "alpha", | ||
"ports": [ | ||
{ | ||
"name": "ge-1/1/0", | ||
"vlans": [ | ||
{ | ||
"vlanId": 10, | ||
"customer": 1 | ||
}, | ||
{ | ||
"vlanId": 20, | ||
"customer": 2 | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "beta", | ||
"ports": [ | ||
{ | ||
"name": "ge-2/1/0", | ||
"vlans": [ | ||
{ | ||
"vlanId": 50, | ||
"customer": 3 | ||
}, | ||
{ | ||
"vlanId": 201, | ||
"customer": 3 | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "ge-3/1/0", | ||
"vlans": [ | ||
{ | ||
"vlanId": 102, | ||
"customer": 3 | ||
}, | ||
{ | ||
"vlanId": 105, | ||
"customer": 1 | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "gamma", | ||
"ports": [ | ||
{ | ||
"name": "ge-2/1/0", | ||
"vlans": [ | ||
{ | ||
"vlanId": 1331, | ||
"customer": 1 | ||
}, | ||
{ | ||
"vlanId": 401, | ||
"customer": 2 | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |
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 @@ | ||
I'm not even a json file at all. |
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,3 @@ | ||
{ | ||
"does this file deserialize to a Router[]?": false | ||
} |
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,97 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
|
||
<groupId>net.es</groupId> | ||
<artifactId>java-code-assessment</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<properties> | ||
<maven.compiler.source>21</maven.compiler.source> | ||
<maven.compiler.target>21</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>3.14.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>1.5.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-core</artifactId> | ||
<version>1.5.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.32</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.18.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>2.0.12</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>5.7.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>3.5.0</version> | ||
|
||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
|
||
<configuration> | ||
<mainClass>Main</mainClass> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.13.0</version> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.32</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
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,21 @@ | ||
import lombok.*; | ||
import java.util.*; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
/* | ||
* Holds data about a particular Ethernet Port and all the Vlans that exist on it | ||
*/ | ||
public class EthernetPort { | ||
String name; | ||
List<Vlan> vlans; | ||
|
||
/* | ||
* the @Data annotation provides compile-time generation of | ||
* getters, setters, equals and hashCode (among others) | ||
*/ | ||
|
||
|
||
} |
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,20 @@ | ||
import lombok.*; | ||
|
||
|
||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@Data | ||
public class IntRange { | ||
private int floor; | ||
private int ceiling; | ||
|
||
|
||
/* | ||
* the @Data annotation provides compile-time generation of | ||
* getters, setters, equals and hashCode (among others) | ||
*/ | ||
|
||
|
||
|
||
} |
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,77 @@ | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.InputStream; | ||
|
||
public class Main { | ||
|
||
public void run() { | ||
try { | ||
InputStream is = new FileInputStream("input/data.json"); | ||
|
||
Router[] routers = new ObjectMapper().readValue(is, Router[].class); | ||
for (Router r : routers) { | ||
System.out.println(r.getName()); | ||
} | ||
} catch (Exception ex) { | ||
System.out.println("An exception!" + ex.getMessage()); | ||
} | ||
|
||
/* | ||
==================================================================== | ||
Task 1 | ||
==================================================================== | ||
Instead of printing a list of router names, print out a report by | ||
customers, including all the router / port / vlan ids they are associated with: | ||
customer 1: | ||
- alpha : ge-1/1/0 : 10 | ||
- beta : ge-2/1/0 : 103 | ||
- beta : ge-2/1/0 : 105 | ||
customer 2: | ||
... | ||
==================================================================== | ||
*/ | ||
|
||
|
||
|
||
|
||
/* | ||
==================================================================== | ||
Task 2 | ||
==================================================================== | ||
Print out a report of all unused VLAN ids by router and port in this format: | ||
alpha: | ||
- ge-1/1/0: 0 to 9, 11 to 19, 21 to 4095 | ||
etc | ||
==================================================================== | ||
*/ | ||
|
||
|
||
|
||
/* | ||
==================================================================== | ||
Task 3 | ||
==================================================================== | ||
Generalize this program to use ALL .json files in a directory | ||
as input (instead of just specifically input/data.json). | ||
You may skip any files that cannot be deserialized to Router[], | ||
generating a warning message to the console. | ||
==================================================================== | ||
*/ | ||
|
||
} | ||
|
||
|
||
|
||
public static void main(String[] args) { | ||
Main main = new Main(); | ||
main.run(); | ||
} | ||
|
||
|
||
} |
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,21 @@ | ||
import lombok.*; | ||
import java.util.*; | ||
|
||
/* | ||
* holds data about a particular Router device all the EthernetPorts that exist on it | ||
*/ | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public class Router { | ||
String name; | ||
List<EthernetPort> ports; | ||
|
||
/* | ||
* the @Data annotation provides compile-time generation of | ||
* getters, setters, equals and hashCode (among others) | ||
*/ | ||
|
||
} |
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,30 @@ | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
public class Utility { | ||
|
||
/* | ||
* this takes a collection of IntRange objects and returns a customizable | ||
* human-readable representation. Candidate may modify it, but that should | ||
* not be necessary. | ||
* | ||
* sample retvalue (separator = " to ", rangeseparator = ", ") | ||
* "-2 to 30, 43 to 500, 121 to 122" | ||
*/ | ||
public static String asString(Collection<IntRange> ranges, String separator, String rangeSeparator) { | ||
List<IntRange> listOfRanges = new ArrayList<>(ranges); | ||
listOfRanges.sort(Comparator.comparing(IntRange::getFloor)); | ||
|
||
List<String> parts = new ArrayList<>(); | ||
listOfRanges.forEach(r -> { | ||
if (r.getCeiling() == r.getFloor()) { | ||
parts.add(r.getCeiling() + ""); | ||
} else { | ||
parts.add(r.getFloor() + separator + r.getCeiling()); | ||
} | ||
}); | ||
return String.join(rangeSeparator, parts); | ||
} | ||
} |
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,23 @@ | ||
import lombok.*; | ||
|
||
|
||
/* | ||
holds data about a particular Vlan, specifically the vlan-id (0-4095) and the customer id | ||
associated with it. The customer id is an opaque int, guaranteed to be the same everywehre | ||
for a particular customer. | ||
*/ | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public class Vlan { | ||
int vlanId; | ||
int customer; | ||
|
||
/* | ||
* the @Data annotation provides compile-time generation of | ||
* getters, setters, equals and hashCode (among others) | ||
*/ | ||
|
||
} |