Skip to content

Commit 8bb5d55

Browse files
committed
Edited StringUtils and Added NumberUtils and Collection Utils
Marked Most Classes As Final Added Null Checks Renamed ReInitalizeHW to ReInitializeHW Renamed ReInitalizeOS to ReInitializeOS Signed-off-by: Joshua Gager <jlgager@outlook.com>
1 parent 1283939 commit 8bb5d55

21 files changed

+940
-86
lines changed

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Java template
3+
# Compiled class file
4+
*.class
5+
6+
# Log file
7+
*.log
8+
9+
# BlueJ files
10+
*.ctxt
11+
12+
# Mobile Tools for Java (J2ME)
13+
.mtj.tmp/
14+
15+
# Package Files #
16+
*.jar
17+
*.war
18+
*.ear
19+
*.zip
20+
*.tar.gz
21+
*.rar
22+
23+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24+
hs_err_pid*
25+
26+
JavaUltimateTools.ipr
27+
JavaUltimateTools.iws
28+
dependency-reduced-pom.xml
29+
docs/com/jgcomptech/tools/StringUtils.html
30+
docs/com/jgcomptech/tools/authenication/
31+
docs/com/jgcomptech/tools/class-use/StringUtils.html
32+
docs/com/jgcomptech/tools/permissions/
33+
java-ultimate-tools.iml
34+
java-ultimate-tools.ipr
35+
java-ultimate-tools.iws
36+
out/
37+
src/test/resources/
38+
target/

Build.log

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
T E S T S
3838
-------------------------------------------------------
3939
Running com.jgcomptech.tools.tests.Tests
40-
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.566 sec
40+
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.899 sec
4141

4242
Results :
4343

@@ -322,6 +322,7 @@ Generating C:\Programing\Repositories\JavaUltimateTools\target\apidocs\help-doc.
322322
[INFO] Including commons-logging:commons-logging:jar:1.2 in the shaded jar.
323323
[INFO] Including org.apache.maven:maven-model:jar:3.5.0-beta-1 in the shaded jar.
324324
[INFO] Including org.codehaus.plexus:plexus-utils:jar:3.0.24 in the shaded jar.
325+
[INFO] Including org.netbeans.api:org-openide-util-lookup:jar:RELEASE802 in the shaded jar.
325326
[INFO] Replacing original artifact with shaded artifact.
326327
[INFO] Replacing C:\Programing\Repositories\JavaUltimateTools\target\java-ultimate-tools-1.3.1.jar with C:\Programing\Repositories\JavaUltimateTools\target\java-ultimate-tools-1.3.1-shaded.jar
327328
[INFO] Dependency-reduced POM written at: C:\Programing\Repositories\JavaUltimateTools\dependency-reduced-pom.xml
@@ -330,7 +331,7 @@ Generating C:\Programing\Repositories\JavaUltimateTools\target\apidocs\help-doc.
330331
[INFO] ------------------------------------------------------------------------
331332
[INFO] BUILD SUCCESS
332333
[INFO] ------------------------------------------------------------------------
333-
[INFO] Total time: 45.076 s
334-
[INFO] Finished at: 2017-04-09T03:32:00-04:00
335-
[INFO] Final Memory: 36M/300M
334+
[INFO] Total time: 01:04 min
335+
[INFO] Finished at: 2017-04-12T22:11:25-04:00
336+
[INFO] Final Memory: 42M/236M
336337
[INFO] ------------------------------------------------------------------------

pom.xml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</properties>
1515

1616
<name>Java Ultimate Tools</name>
17-
<description>A large repository of scripts for use in any Java program..</description>
17+
<description>A large repository of scripts for use in any Java program.</description>
1818
<url>https://github.com/JGCompTech/JavaUltimateTools</url>
1919
<organization>
2020
<name>J&amp;G CompTech</name>
@@ -67,6 +67,15 @@
6767
<enabled>false</enabled>
6868
</snapshots>
6969
</repository>
70+
<repository>
71+
<id>org.netbeans</id>
72+
<name>netbeans.org</name>
73+
<layout>default</layout>
74+
<url>http://bits.netbeans.org/maven2/</url>
75+
<snapshots>
76+
<enabled>false</enabled>
77+
</snapshots>
78+
</repository>
7079
</repositories>
7180

7281
<pluginRepositories>
@@ -223,7 +232,7 @@
223232
<artifactId>maven-shade-plugin</artifactId>
224233
<version>3.0.0</version>
225234
<executions>
226-
<!-- Run shade goal on package phase -->
235+
<!-- Run shade goal on package plugin -->
227236
<execution>
228237
<phase>package</phase>
229238
<goals>
@@ -328,5 +337,10 @@
328337
<artifactId>maven-model</artifactId>
329338
<version>3.5.0-beta-1</version>
330339
</dependency>
340+
<dependency>
341+
<groupId>org.netbeans.api</groupId>
342+
<artifactId>org-openide-util-lookup</artifactId>
343+
<version>RELEASE802</version>
344+
</dependency>
331345
</dependencies>
332346
</project>
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package com.jgcomptech.tools;
2+
3+
import java.util.*;
4+
import java.util.function.Predicate;
5+
6+
public final class CollectionUtils {
7+
/**
8+
* Converts a map into a delimited string value.
9+
* A '=' seperates the keys and values and a '&' seperates the key pairs.
10+
* @param stringMap map to convert
11+
* @return string representation of map
12+
*/
13+
public static String convertMapToString(Map<String, String> stringMap) {
14+
final StringBuilder sb = new StringBuilder();
15+
final char KeySeparator = '=';
16+
final char PairSeparator = '&';
17+
for(final Map.Entry<String, String> pair:stringMap.entrySet())
18+
{
19+
sb.append(pair.getKey());
20+
sb.append(KeySeparator);
21+
sb.append(pair.getValue());
22+
sb.append(PairSeparator);
23+
}
24+
return sb.toString().substring(0, sb.length() - 1);
25+
}
26+
27+
/**
28+
* Converts a delimited string value into a map.
29+
* Expects that '=' seperates the keys and values and a '&' seperates the key pairs.
30+
* @param value map to convert
31+
* @return string representation of map
32+
*/
33+
public static Map<String, String> convertStringToMap(String value) {
34+
final Map<String, String> myMap = new HashMap<>();
35+
final String KeySeparator = "=";
36+
final String PairSeparator = "&";
37+
final String[] pairs = value.split(PairSeparator);
38+
for(final String pair : pairs) {
39+
final String[] keyValue = pair.split(KeySeparator);
40+
myMap.put(keyValue[0], keyValue[1]);
41+
}
42+
return myMap;
43+
}
44+
45+
/**
46+
* Checks if an item exists in a HashSet that matches the specified Predicate.
47+
* @param set the HashSet to check against
48+
* @param condition the Predicate to check
49+
* @param <T> the type of objects in the HashSet
50+
* @return true if condition is true
51+
* @throws IllegalArgumentException if HashSet or Predicate is null
52+
*/
53+
public static <T> boolean doesItemExistInHashSet(HashSet<T> set, Predicate<T> condition) {
54+
if(set == null) throw new IllegalArgumentException("HashSet cannot be null!");
55+
if(condition == null) throw new IllegalArgumentException("Predicate cannot be null!");
56+
for(final T object : set) if (condition.test(object)) return true;
57+
return false;
58+
}
59+
60+
/**
61+
* Checks if a value exists in a HashMap that matches the specified Predicate.
62+
* @param map the HashMap to check against
63+
* @param condition the Predicate to check
64+
* @param <K> the type of the Key in the HashMap
65+
* @param <V> the type of the Value in the HashMap
66+
* @return true if condition is true
67+
* @throws IllegalArgumentException if HashMap or Predicate is null
68+
*/
69+
public static <K, V> boolean doesItemExistInHashMap(HashMap<K, V> map, Predicate<V> condition) {
70+
if(map == null) throw new IllegalArgumentException("HashMap cannot be null!");
71+
if(condition == null) throw new IllegalArgumentException("Predicate cannot be null!");
72+
for(final Map.Entry<K, V> entry : map.entrySet()) if (condition.test(entry.getValue())) return true;
73+
return false;
74+
}
75+
76+
/**
77+
* Returns item in HashSet that matches the specified Predicate
78+
* @param set the HashSet to check against
79+
* @param condition the Predicate to check
80+
* @param <T> the type of objects in the HashSet
81+
* @return an Optional containing the matching object, Empty if not found
82+
* @throws IllegalArgumentException if HashSet or Predicate is null
83+
*/
84+
public static <T> Optional<T> getItemInHashSet(HashSet<T> set, Predicate<T> condition) {
85+
if(set == null) throw new IllegalArgumentException("HashSet cannot be null!");
86+
if(condition == null) throw new IllegalArgumentException("Predicate cannot be null!");
87+
for(final T object : set) if (condition.test(object)) return Optional.of(object);
88+
return Optional.empty();
89+
}
90+
91+
/**
92+
* Returns a HashSet of values in a HashMap that match the specified Predicate
93+
* @param map the HashMap to check against
94+
* @param condition the Predicate to check
95+
* @param <K> the type of the Key in the HashMap
96+
* @param <V> the type of the Value in the HashMap
97+
* @return a HashSet of values matching the predicate, empty HashSet if no results found
98+
* @throws IllegalArgumentException if HashMap or Predicate is null
99+
*/
100+
public static <K, V> HashSet<V> getValuesInHashMap(HashMap<K, V> map, Predicate<V> condition) {
101+
final HashSet<V> matchingValues = new HashSet<>();
102+
103+
if(map == null) throw new IllegalArgumentException("HashMap cannot be null!");
104+
if(condition == null) throw new IllegalArgumentException("Predicate cannot be null!");
105+
106+
map.forEach((key, value) -> { if(condition.test(value)) matchingValues.add(value); });
107+
108+
return matchingValues;
109+
}
110+
111+
/**
112+
* Returns the first item found in a HashMap that matches the specified Predicate
113+
* @param map the HashMap to check against
114+
* @param condition the Predicate to check
115+
* @param <K> the type of the Key in the HashMap
116+
* @param <V> the type of the Value in the HashMap
117+
* @return an Optional containing the matching value, Empty if no results found
118+
* @throws IllegalArgumentException if HashMap or Predicate is null
119+
*/
120+
public static <K, V> Optional<V> getValueInHashMap(HashMap<K, V> map, Predicate<V> condition) {
121+
V matchingValue = null;
122+
123+
if(map == null) throw new IllegalArgumentException("HashMap cannot be null!");
124+
if(condition == null) throw new IllegalArgumentException("Predicate cannot be null!");
125+
126+
for(final Map.Entry<K, V> entry : map.entrySet()) {
127+
if(condition.test(entry.getValue())) {
128+
matchingValue = entry.getValue();
129+
break;
130+
}
131+
}
132+
133+
return matchingValue == null ? Optional.empty() : Optional.of(matchingValue);
134+
}
135+
}

src/main/java/com/jgcomptech/tools/CommandInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import static com.jgcomptech.tools.OSInfo.CheckIf.isWindows;
1414

1515
/** Allows you to run console commands and either run them elevated or not and return the result to a string */
16-
public class CommandInfo {
16+
public final class CommandInfo {
1717

1818
/**
1919
* Runs command and returns results to ArrayList in Output object

src/main/java/com/jgcomptech/tools/ComputerInfo.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
import java.io.IOException;
44

55
/** Returns Information about the current OS and Hardware on the current system */
6-
public class ComputerInfo {
6+
public final class ComputerInfo {
77
public OSInfo.OSObject OS;
88
public HWInfo.HWObject HW;
99

1010
public ComputerInfo() throws IOException, InterruptedException {
11-
HW = ReInitalizeHW();
12-
OS = ReInitalizeOS();
11+
HW = ReInitializeHW();
12+
OS = ReInitializeOS();
1313
}
1414

1515
/* Reprocesses the OS information and returns a new OSObject */
16-
public static OSInfo.OSObject ReInitalizeOS() throws IOException, InterruptedException {
16+
public static OSInfo.OSObject ReInitializeOS() throws IOException, InterruptedException {
1717
final OSInfo.VersionObject vobj = new OSInfo.VersionObject();
1818
vobj.Build = OSInfo.Windows.Version.Build();
1919
vobj.Main = OSInfo.Windows.Version.Main();
@@ -45,7 +45,7 @@ public static OSInfo.OSObject ReInitalizeOS() throws IOException, InterruptedExc
4545
}
4646

4747
/* Reprocesses the Hardware information and returns a new HWObject */
48-
public static HWInfo.HWObject ReInitalizeHW() throws IOException {
48+
public static HWInfo.HWObject ReInitializeHW() throws IOException {
4949
final HWInfo.BIOSObject biosobj = new HWInfo.BIOSObject();
5050
biosobj.Name = HWInfo.BIOS.getVendor() + " " + HWInfo.BIOS.getVersion();
5151
biosobj.ReleaseDate = HWInfo.BIOS.getReleaseDate();

0 commit comments

Comments
 (0)