Skip to content

Commit a6709b2

Browse files
committed
Make code look more like Java 8
1 parent 4d53e06 commit a6709b2

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

src/main/java/gr/gousiosg/javacg/dyn/Instrumenter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646

4747
public class Instrumenter implements ClassFileTransformer {
4848

49-
static List<Pattern> pkgIncl = new ArrayList<Pattern>();
50-
static List<Pattern> pkgExcl = new ArrayList<Pattern>();
49+
static List<Pattern> pkgIncl = new ArrayList<>();
50+
static List<Pattern> pkgExcl = new ArrayList<>();
5151

5252
public static void premain(String argument, Instrumentation instrumentation) {
5353

@@ -63,14 +63,14 @@ public static void premain(String argument, Instrumentation instrumentation) {
6363
String[] tokens = argument.split(";");
6464

6565
if (tokens.length < 1) {
66-
err("Missing delimeter ;");
66+
err("Missing delimiter ;");
6767
return;
6868
}
6969

7070
for (String token : tokens) {
7171
String[] args = token.split("=");
7272
if (args.length < 2) {
73-
err("Missing argument delimeter =:" + token);
73+
err("Missing argument delimiter =:" + token);
7474
return;
7575
}
7676

@@ -118,7 +118,7 @@ public byte[] transform(ClassLoader loader, String className, Class clazz,
118118
for (Pattern p : pkgExcl) {
119119
Matcher m = p.matcher(name);
120120
if (m.matches()) {
121-
err("Not enhansing class: " + name);
121+
err("Skipping class: " + name);
122122
enhanceClass = false;
123123
break;
124124
}

src/main/java/gr/gousiosg/javacg/dyn/MethodStack.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,36 @@
3333
import java.io.IOException;
3434
import java.util.ArrayList;
3535
import java.util.Collections;
36-
import java.util.Comparator;
3736
import java.util.HashMap;
3837
import java.util.List;
3938
import java.util.Map;
4039
import java.util.Stack;
4140

4241
public class MethodStack {
4342

44-
private static Stack<String> stack = new Stack<String>();
45-
private static Map<Pair<String, String>, Integer> callgraph = new HashMap<Pair<String,String>, Integer>();
43+
private static Stack<String> stack = new Stack<>();
44+
private static Map<Pair<String, String>, Integer> callgraph = new HashMap<>();
4645
static FileWriter fw;
4746
static StringBuffer sb;
4847
static long threadid = -1L;
49-
48+
5049
static {
5150
Runtime.getRuntime().addShutdownHook(new Thread() {
5251
public void run() {
5352
try {
5453
fw.close();
5554
} catch (IOException e) {
56-
// TODO Auto-generated catch block
5755
e.printStackTrace();
5856
}
5957
//Sort by number of calls
60-
List<Pair<String, String>> keys = new ArrayList<Pair<String, String>>();
58+
List<Pair<String, String>> keys = new ArrayList<>();
6159
keys.addAll(callgraph.keySet());
62-
Collections.sort(keys, new Comparator<Object>() {
63-
public int compare(Object o1, Object o2) {
64-
Integer v1 = callgraph.get(o1);
65-
Integer v2 = callgraph.get(o2);
66-
return v1.compareTo(v2);
67-
}
60+
Collections.sort(keys, (o1, o2) -> {
61+
Integer v1 = callgraph.get(o1);
62+
Integer v2 = callgraph.get(o2);
63+
return v1.compareTo(v2);
6864
});
69-
65+
7066
for (Pair<String, String> key : keys) {
7167
System.out.println(key + " " + callgraph.get(key));
7268
}
@@ -89,7 +85,7 @@ public static void push(String callname) throws IOException {
8985
return;
9086

9187
if (!stack.isEmpty()) {
92-
Pair<String, String> p = new Pair<String, String>(stack.peek(), callname);
88+
Pair<String, String> p = new Pair<>(stack.peek(), callname);
9389
if (callgraph.containsKey(p))
9490
callgraph.put(p, callgraph.get(p) + 1);
9591
else

0 commit comments

Comments
 (0)