Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d7f79b3

Browse files
merge
2 parents 8465138 + 69adb0c commit d7f79b3

File tree

62 files changed

+3588
-685
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+3588
-685
lines changed

‎java-cli-demo/pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.zaccoding</groupId>
8+
<artifactId>demo</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<dependencies>
12+
<!-- https://mvnrepository.com/artifact/commons-cli/commons-cli -->
13+
<dependency>
14+
<groupId>commons-cli</groupId>
15+
<artifactId>commons-cli</artifactId>
16+
<version>1.4</version>
17+
</dependency>
18+
</dependencies>
19+
</project>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package cli;
2+
3+
import java.io.PrintWriter;
4+
import java.util.Arrays;
5+
import java.util.Scanner;
6+
import org.apache.commons.cli.CommandLine;
7+
import org.apache.commons.cli.CommandLineParser;
8+
import org.apache.commons.cli.DefaultParser;
9+
import org.apache.commons.cli.HelpFormatter;
10+
import org.apache.commons.cli.Option;
11+
import org.apache.commons.cli.Options;
12+
import org.apache.commons.cli.ParseException;
13+
14+
/**
15+
* @author zacconding
16+
* @Date 2018年11月08日
17+
* @GitHub : https://github.com/zacscoding
18+
*/
19+
public class Main {
20+
private static final Options OPTIONS = generateOptions();
21+
22+
public static void main(String[] args) {
23+
printUsage(OPTIONS);
24+
printHelp(OPTIONS);
25+
26+
Scanner scanner = new Scanner(System.in);
27+
28+
while (true) {
29+
String readLine = scanner.nextLine();
30+
if ("exit".equals(readLine)) {
31+
break;
32+
}
33+
34+
String[] arguments = readLine.substring(5).split("\\s");
35+
try {
36+
CommandLine commandLine = generateCommandLine(OPTIONS, arguments);
37+
Option[] options = commandLine.getOptions();
38+
for (Option option : options) {
39+
System.out.println(option);
40+
System.out.println(String.format("Option : %s | value : %s", option.getOpt(), option.getValue()));
41+
}
42+
} catch (ParseException e) {
43+
// ignore
44+
}
45+
}
46+
}
47+
48+
private static CommandLine generateCommandLine(final Options options, final String[] commandLineArguments) throws ParseException {
49+
final CommandLineParser cmdLineParser = new DefaultParser();
50+
CommandLine commandLine = null;
51+
52+
try {
53+
commandLine = cmdLineParser.parse(options, commandLineArguments);
54+
} catch (ParseException parseException) {
55+
System.err.println(("ERROR: Unable to parse command-line arguments " + Arrays.toString(commandLineArguments) + " due to: " + parseException.getMessage()));
56+
throw parseException;
57+
}
58+
59+
return commandLine;
60+
}
61+
62+
private static Options generateOptions() {
63+
final Option helpOption = Option.builder("h").required(false).hasArg(false).longOpt("help").desc("Display help messages").build();
64+
65+
final Option verboseOption = Option.builder("v")
66+
.required(false)
67+
.hasArg(false)
68+
.longOpt("VERBOSE_OPTION")
69+
.desc("Print status with verbosity.").build();
70+
71+
final Option fileOption = Option.builder("f")
72+
.required()
73+
.longOpt("FILE_OPTION")
74+
.hasArg()
75+
.desc("File to be processed.")
76+
.build();
77+
78+
return new Options().addOption(verboseOption).addOption(fileOption).addOption(helpOption);
79+
}
80+
81+
private static void printUsage(final Options options) {
82+
final HelpFormatter formatter = new HelpFormatter();
83+
final String syntax = "Main";
84+
System.out.println("\n=====");
85+
System.out.println("USAGE");
86+
System.out.println("=====");
87+
final PrintWriter pw = new PrintWriter(System.out);
88+
formatter.printUsage(pw, 80, syntax, options);
89+
pw.flush();
90+
}
91+
92+
private static void printHelp(final Options options) {
93+
final HelpFormatter formatter = new HelpFormatter();
94+
final String syntax = "Main";
95+
final String usageHeader = "Example of Using Apache Commons CLI";
96+
final String usageFooter = "See http://marxsoftware.blogspot.com/ for further details.";
97+
System.out.println("\n====");
98+
System.out.println("HELP");
99+
System.out.println("====");
100+
formatter.printHelp(syntax, usageHeader, options, usageFooter);
101+
}
102+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package apahce.collections.map;
2+
3+
import com.google.common.collect.HashBasedTable;
4+
import com.google.common.collect.Table;
5+
import org.junit.Test;
6+
7+
/**
8+
* @author zacconding
9+
* @Date 2018年11月12日
10+
* @GitHub : https://github.com/zacscoding
11+
*/
12+
public class Temp {
13+
14+
@Test
15+
public void temp() {
16+
Table<String, Long, String> table = HashBasedTable.create();
17+
table.put("0xaa", Long.valueOf(1L), "Block1");
18+
table.put("0xab", Long.valueOf(2L), "Block2");
19+
table.put("0xac", Long.valueOf(3L), "Block3");
20+
}
21+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package guava.collections;
2+
3+
import static org.junit.Assert.fail;
4+
5+
import com.google.common.collect.BiMap;
6+
import com.google.common.collect.HashBiMap;
7+
import com.google.common.collect.HashMultimap;
8+
import com.google.common.collect.Multimap;
9+
import java.util.Map;
10+
import org.junit.Test;
11+
12+
/**
13+
* @author zacconding
14+
* @Date 2018年10月23日
15+
* @GitHub : https://github.com/zacscoding
16+
*/
17+
public class BiMapTest {
18+
19+
@Test
20+
public void defaultBiMap() {
21+
BiMap<String, Integer> users = HashBiMap.create();
22+
23+
users.values();
24+
users.put("Bob", 42);
25+
System.out.println("users.inverse().get(42) : " + users.inverse().get(42));
26+
27+
try {
28+
users.put("Bob2", 42);
29+
System.out.println("users.inverse().get(42) : " + users.inverse().get(42));
30+
fail();
31+
} catch(IllegalArgumentException e) {
32+
}
33+
}
34+
35+
@Test
36+
public void defaultMultiMap() {
37+
Map<String, String> map;
38+
39+
Multimap<String ,Integer> multi = HashMultimap.create();
40+
multi.put("Bob", 42);
41+
multi.put("Bob", 43);
42+
43+
System.out.println(multi.asMap().get("Bob").size());
44+
System.out.println(multi.containsValue(42));
45+
}
46+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package guava.collections;
2+
3+
import com.google.common.collect.ImmutableMap;
4+
import com.google.common.collect.Maps;
5+
import org.junit.Test;
6+
7+
/**
8+
* @author zacconding
9+
* @Date 2018年11月12日
10+
* @GitHub : https://github.com/zacscoding
11+
*/
12+
public class MapsTest {
13+
14+
@Test
15+
public void uniqueIndex() {
16+
17+
}
18+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package guava.collections;
2+
3+
import static com.sun.org.apache.xerces.internal.util.PropertyState.is;
4+
import static org.junit.Assert.assertThat;
5+
6+
import com.google.common.collect.HashBasedTable;
7+
import com.google.common.collect.Table;
8+
import org.junit.Test;
9+
10+
/**
11+
* @author zacconding
12+
* @Date 2018年11月12日
13+
* @GitHub : https://github.com/zacscoding
14+
*/
15+
public class TableTest {
16+
17+
@Test
18+
public void hashBasedTableTest() {
19+
HashBasedTable<String, Long, String> table = HashBasedTable.create();
20+
21+
table.put("0x1", 1L, "Block1");
22+
table.put("0x2", 2L, "Block2");
23+
table.put("0x3", 3L, "Block3");
24+
table.put("0x4", 4L, "Block4");
25+
26+
System.out.println(table.row("0x1").size());
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package guava.graph;
2+
3+
import com.google.common.graph.GraphBuilder;
4+
import com.google.common.graph.Graphs;
5+
import com.google.common.graph.MutableGraph;
6+
import org.junit.Test;
7+
8+
/**
9+
* @author zacconding
10+
* @Date 2018年12月26日
11+
* @GitHub : https://github.com/zacscoding
12+
*/
13+
public class CycleTest {
14+
15+
@Test
16+
public void cycle() throws Exception {
17+
long start = System.currentTimeMillis();
18+
MutableGraph<Integer> graph = GraphBuilder.directed().build();
19+
graph.addNode(1);
20+
graph.addNode(2);
21+
graph.addNode(3);
22+
graph.putEdge(1, 2);
23+
graph.putEdge(2, 3);
24+
System.out.println(Graphs.hasCycle(graph));
25+
long elapsed = System.currentTimeMillis() - start;
26+
System.out.println(elapsed);
27+
}
28+
}

‎javademo/pom.xml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,33 @@
129129
<version>2.6</version>
130130
</dependency>
131131

132+
<!-- apahce commons pool -->
133+
<dependency>
134+
<groupId>org.apache.commons</groupId>
135+
<artifactId>commons-pool2</artifactId>
136+
<version>2.6.0</version>
137+
</dependency>
132138

139+
<!-- jcraft -->
133140
<dependency>
134-
<groupId>com.hierynomus</groupId>
135-
<artifactId>sshj</artifactId>
136-
<version>0.26.0</version>
141+
<groupId>com.jcraft</groupId>
142+
<artifactId>jsch</artifactId>
143+
<version>0.1.54</version>
137144
</dependency>
138145

146+
<!-- guava -->
147+
<dependency>
148+
<groupId>com.google.guava</groupId>
149+
<artifactId>guava</artifactId>
150+
<version>25.1-jre</version>
151+
</dependency>
139152

153+
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
154+
<dependency>
155+
<groupId>org.mockito</groupId>
156+
<artifactId>mockito-core</artifactId>
157+
<version>2.23.0</version>
158+
<scope>test</scope>
159+
</dependency>
140160
</dependencies>
141-
142-
</project>
161+
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package events;
2+
3+
/**
4+
* @author zacconding
5+
* @Date 2018年11月06日
6+
* @GitHub : https://github.com/zacscoding
7+
*/
8+
public abstract class DefaultEvent {
9+
10+
protected final DefaultEventType eventType;
11+
12+
public DefaultEvent(DefaultEventType eventType) {
13+
this.eventType = eventType;
14+
}
15+
16+
public DefaultEventType getType() {
17+
return this.eventType;
18+
}
19+
20+
public enum DefaultEventType {
21+
EVENT_TYPE1, EVENT_TYPE2;
22+
}
23+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package events;
2+
3+
/**
4+
* @author zacconding
5+
* @Date 2018年11月06日
6+
* @GitHub : https://github.com/zacscoding
7+
*/
8+
public class DefaultOneEvent extends DefaultEvent {
9+
10+
public DefaultOneEvent(DefaultEventType eventType) {
11+
super(eventType);
12+
}
13+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /