GeezerVison is showing github.com — Fix some IDEA warnings. Change toString() methods. Suppress InfiniteL… · odissea/sample-java-programs@0dec388
File treeExpand file treeCollapse file tree Open diff view settings allocations/src/main/java/com/github/chrishantha/sample/allocations base/src/main/java/com/github/chrishantha/sample/base deadlock/src/main/java/com/github/chrishantha/sample/deadlock highcpu/src/main/java/com/github/chrishantha/sample/highcpu hotmethods/src/main/java/com/github/chrishantha/sample/hotmethods latencies/src/main/java/com/github/chrishantha/sample/latencies memoryleak/src/main/java/com/github/chrishantha/sample/memoryleak
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: allocations/src/main/java/com/github/chrishantha/sample/allocations/AllocationsApplication.java +4-6Lines changed: 4 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,7 +23,7 @@ public class AllocationsApplication implements SampleApplication { | 23 | 23 | @Parameter(names = "--max", description = "Max Numbers") | 24 | 24 | private long max = 10_000_000L; | 25 | 25 |
| 26 | | - boolean isPrime(Long n) { | | 26 | + private boolean isPrime(Long n) { | 27 | 27 | //check if n is a multiple of 2 | 28 | 28 | if (n % 2 == 0) return false; | 29 | 29 | //if not, then just check the odds | @@ -47,10 +47,8 @@ public void start() { | 47 | 47 |
| 48 | 48 | @Override | 49 | 49 | public String toString() { | 50 | | - StringBuilder builder = new StringBuilder(); | 51 | | - builder.append("AllocationsApplication [max="); | 52 | | - builder.append(max); | 53 | | - builder.append("]"); | 54 | | - return builder.toString(); | | 50 | + return "AllocationsApplication{" + | | 51 | + "max=" + max + | | 52 | + '}'; | 55 | 53 | } | 56 | 54 | } |
Collapse file Copy file name to clipboardExpand all lines: base/src/main/java/com/github/chrishantha/sample/base/App.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,7 +26,7 @@ public class App { | 26 | 26 |
| 27 | 27 | private static class CommonArgs { | 28 | 28 | @Parameter(names = {"-h", "--help"}, description = "Display Help", help = true) | 29 | | - private boolean help; | | 29 | + private boolean help = false; | 30 | 30 | } | 31 | 31 |
| 32 | 32 | public static void main(String[] args) { | |
Collapse file Copy file name to clipboardExpand all lines: deadlock/src/main/java/com/github/chrishantha/sample/deadlock/DeadlockApplication.java +4-7Lines changed: 4 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -79,12 +79,9 @@ public void start() { | 79 | 79 |
| 80 | 80 | @Override | 81 | 81 | public String toString() { | 82 | | - StringBuilder builder = new StringBuilder(); | 83 | | - builder.append("DeadlockApplication [count="); | 84 | | - builder.append(count); | 85 | | - builder.append(", delay="); | 86 | | - builder.append(delay); | 87 | | - builder.append("]"); | 88 | | - return builder.toString(); | | 82 | + return "DeadlockApplication{" + | | 83 | + "count=" + count + | | 84 | + ", delay=" + delay + | | 85 | + '}'; | 89 | 86 | } | 90 | 87 | } |
Collapse file Copy file name to clipboardExpand all lines: highcpu/src/main/java/com/github/chrishantha/sample/highcpu/HashingWorker.java +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,14 +31,15 @@ public HashingWorker(long length, String algorithm) { | 31 | 31 | this.algorithm = algorithm; | 32 | 32 | } | 33 | 33 |
| | 34 | + @SuppressWarnings("InfiniteLoopStatement") | 34 | 35 | @Override | 35 | 36 | public void run() { | 36 | 37 | while (true) { | 37 | | - String data = ""; | | 38 | + StringBuilder data = new StringBuilder(); | 38 | 39 |
| 39 | 40 | // Some random data | 40 | 41 | for (int i = 0; i < length; i++) { | 41 | | - data += UUID.randomUUID().toString(); | | 42 | + data.append(UUID.randomUUID().toString()); | 42 | 43 | } | 43 | 44 |
| 44 | 45 | MessageDigest digest; | @@ -49,7 +50,7 @@ public void run() { | 49 | 50 | } | 50 | 51 |
| 51 | 52 | // Hash | 52 | | - digest.update(data.getBytes()); | | 53 | + digest.update(data.toString().getBytes()); | 53 | 54 | byte[] computedHash = digest.digest(); | 54 | 55 | if (lastComputedHash != null && computedHash.length != lastComputedHash.length) { | 55 | 56 | throw new IllegalStateException("Is the hash computation correct??"); | |
Collapse file Copy file name to clipboardExpand all lines: highcpu/src/main/java/com/github/chrishantha/sample/highcpu/HighCpuApplication.java +11-21Lines changed: 11 additions & 21 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -77,26 +77,16 @@ private void startThread(int i, String name, Runnable worker) { | 77 | 77 |
| 78 | 78 | @Override | 79 | 79 | public String toString() { | 80 | | - StringBuilder builder = new StringBuilder(); | 81 | | - builder.append("HighCpuApplication [runHashing="); | 82 | | - builder.append(runHashing); | 83 | | - builder.append(", runSleeping="); | 84 | | - builder.append(runSleeping); | 85 | | - builder.append(", runMath="); | 86 | | - builder.append(runMath); | 87 | | - builder.append(", hashingWorkers="); | 88 | | - builder.append(hashingWorkers); | 89 | | - builder.append(", sleepingWorkers="); | 90 | | - builder.append(sleepingWorkers); | 91 | | - builder.append(", mathWorkers="); | 92 | | - builder.append(mathWorkers); | 93 | | - builder.append(", hashDataLength="); | 94 | | - builder.append(hashDataLength); | 95 | | - builder.append(", hashingAlgorithm="); | 96 | | - builder.append(hashingAlgorithm); | 97 | | - builder.append(", exitTimeoutInSeconds="); | 98 | | - builder.append(exitTimeoutInSeconds); | 99 | | - builder.append("]"); | 100 | | - return builder.toString(); | | 80 | + return "HighCpuApplication{" + | | 81 | + "runHashing=" + runHashing + | | 82 | + ", runSleeping=" + runSleeping + | | 83 | + ", runMath=" + runMath + | | 84 | + ", hashingWorkers=" + hashingWorkers + | | 85 | + ", sleepingWorkers=" + sleepingWorkers + | | 86 | + ", mathWorkers=" + mathWorkers + | | 87 | + ", hashDataLength=" + hashDataLength + | | 88 | + ", hashingAlgorithm='" + hashingAlgorithm + '\'' + | | 89 | + ", exitTimeoutInSeconds=" + exitTimeoutInSeconds + | | 90 | + '}'; | 101 | 91 | } | 102 | 92 | } |
Collapse file Copy file name to clipboardExpand all lines: highcpu/src/main/java/com/github/chrishantha/sample/highcpu/MathWorker.java +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,9 +22,7 @@ public class MathWorker implements Runnable { | 22 | 22 |
| 23 | 23 | private Random random = new Random(); | 24 | 24 |
| 25 | | - public MathWorker() { | 26 | | - } | 27 | | - | | 25 | + @SuppressWarnings("InfiniteLoopStatement") | 28 | 26 | @Override | 29 | 27 | public void run() { | 30 | 28 | BigDecimal bigDecimal = BigDecimal.ZERO; | |
Collapse file Copy file name to clipboardExpand all lines: highcpu/src/main/java/com/github/chrishantha/sample/highcpu/SleepingWorker.java +3-5Lines changed: 3 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,12 +21,10 @@ public class SleepingWorker implements Runnable { | 21 | 21 |
| 22 | 22 | private Random random = new Random(); | 23 | 23 |
| 24 | | - public SleepingWorker() { | 25 | | - } | 26 | | - | | 24 | + @SuppressWarnings("InfiniteLoopStatement") | 27 | 25 | @Override | 28 | 26 | public void run() { | 29 | | - Long l = 0l; | | 27 | + Long l = 0L; | 30 | 28 | while (true) { | 31 | 29 | l++; | 32 | 30 | try { | @@ -35,7 +33,7 @@ public void run() { | 35 | 33 | e.printStackTrace(); | 36 | 34 | } | 37 | 35 | if (l == Long.MAX_VALUE) { | 38 | | - l = 0l; | | 36 | + l = 0L; | 39 | 37 | } | 40 | 38 | } | 41 | 39 | } | |
Collapse file Copy file name to clipboardExpand all lines: hotmethods/src/main/java/com/github/chrishantha/sample/hotmethods/HotMethodsApplication.java +4-7Lines changed: 4 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -63,12 +63,9 @@ public void start() { | 63 | 63 |
| 64 | 64 | @Override | 65 | 65 | public String toString() { | 66 | | - StringBuilder builder = new StringBuilder(); | 67 | | - builder.append("HotMethodsApplication [randomNumbersCount="); | 68 | | - builder.append(randomNumbersCount); | 69 | | - builder.append(", max="); | 70 | | - builder.append(max); | 71 | | - builder.append("]"); | 72 | | - return builder.toString(); | | 66 | + return "HotMethodsApplication{" + | | 67 | + "randomNumbersCount=" + randomNumbersCount + | | 68 | + ", max=" + max + | | 69 | + '}'; | 73 | 70 | } | 74 | 71 | } |
Collapse file Copy file name to clipboardExpand all lines: latencies/src/main/java/com/github/chrishantha/sample/latencies/LatenciesApplication.java +3-5Lines changed: 3 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -77,10 +77,8 @@ public void start() { | 77 | 77 |
| 78 | 78 | @Override | 79 | 79 | public String toString() { | 80 | | - StringBuilder builder = new StringBuilder(); | 81 | | - builder.append("LatenciesApplication [count="); | 82 | | - builder.append(count); | 83 | | - builder.append("]"); | 84 | | - return builder.toString(); | | 80 | + return "LatenciesApplication{" + | | 81 | + "count=" + count + | | 82 | + '}'; | 85 | 83 | } | 86 | 84 | } |
Collapse file Copy file name to clipboardExpand all lines: memoryleak/src/main/java/com/github/chrishantha/sample/memoryleak/MemoryLeakApplication.java +6-9Lines changed: 6 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,6 +37,7 @@ private enum KeyType { | 37 | 37 | @Parameter(names = "--key-type", description = "Key Type: Good or Bad") | 38 | 38 | private KeyType keyType = KeyType.BAD; | 39 | 39 |
| | 40 | + @SuppressWarnings("InfiniteLoopStatement") | 40 | 41 | @Override | 41 | 42 | public void start() { | 42 | 43 | Map<Key, String> map = new HashMap<>(); | @@ -52,14 +53,10 @@ public void start() { | 52 | 53 |
| 53 | 54 | @Override | 54 | 55 | public String toString() { | 55 | | - StringBuilder builder = new StringBuilder(); | 56 | | - builder.append("MemoryLeakApplication [length="); | 57 | | - builder.append(length); | 58 | | - builder.append(", max="); | 59 | | - builder.append(max); | 60 | | - builder.append(", keyType="); | 61 | | - builder.append(keyType); | 62 | | - builder.append("]"); | 63 | | - return builder.toString(); | | 56 | + return "MemoryLeakApplication{" + | | 57 | + "length=" + length + | | 58 | + ", max=" + max + | | 59 | + ", keyType=" + keyType + | | 60 | + '}'; | 64 | 61 | } | 65 | 62 | } |
|