-
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
1 parent
bde3ad1
commit 87c391a
Showing
21 changed files
with
233 additions
and
75 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
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
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
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
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
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
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
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
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,38 @@ | ||
package com.jrutil.io; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileVisitResult; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.SimpleFileVisitor; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
|
||
public class FileUtils { | ||
|
||
public static void removeRecursive(Path path) throws IOException { | ||
Files.walkFileTree(path, new SimpleFileVisitor<Path>() { | ||
@Override | ||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) | ||
throws IOException { | ||
Files.delete(file); | ||
return FileVisitResult.CONTINUE; | ||
} | ||
|
||
@Override | ||
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { | ||
Files.delete(file); | ||
return FileVisitResult.CONTINUE; | ||
} | ||
|
||
@Override | ||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { | ||
if (exc == null) { | ||
Files.delete(dir); | ||
return FileVisitResult.CONTINUE; | ||
} else { | ||
throw exc; | ||
} | ||
} | ||
}); | ||
} | ||
} |
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,72 @@ | ||
package com.jrutil.math; | ||
|
||
import java.math.RoundingMode; | ||
import java.text.DecimalFormat; | ||
import java.util.Random; | ||
|
||
public class MathHelper { | ||
|
||
/** | ||
* Generates a random int from the range provided. | ||
* | ||
* @param start The start range. | ||
* @param end The end range. | ||
* @return The random number | ||
*/ | ||
public static int randomInt(int start, int end) { | ||
return new Random().nextInt(end - start + 1) + start; | ||
} | ||
|
||
/** | ||
* Generates a random float from the range provided. | ||
* | ||
* @param start The start range. | ||
* @param end The end range. | ||
* @return The random number. | ||
*/ | ||
public static float randomFloat(float start, float end) { | ||
return start + (end - start) * new Random().nextFloat(); | ||
} | ||
|
||
/** | ||
* Generates a random double from the range provided. | ||
* | ||
* @param start The start range. | ||
* @param end The end range. | ||
* @return The random number. | ||
*/ | ||
public static double randomDouble(double start, double end) { | ||
return start + (end - start) * new Random().nextDouble(); | ||
} | ||
|
||
/** | ||
* Rounds the given float to the provided number of decimal places. | ||
* | ||
* @param in The float given in. | ||
* @param numberOfDP The number of decimal places expected. | ||
* @return The new float. | ||
*/ | ||
public static String roundFloatToXDP(float in, int numberOfDP) { | ||
StringBuilder n = new StringBuilder("0."); | ||
for (int i = 0; i < numberOfDP; i++) n.append("0"); | ||
DecimalFormat df = new DecimalFormat(n.toString()); | ||
df.setRoundingMode(RoundingMode.HALF_UP); | ||
return df.format(in); | ||
} | ||
|
||
/** | ||
* Rounds the given double to the provided number of decimal places. | ||
* | ||
* @param in The double given in. | ||
* @param numberOfDP The number of decimal places expected. | ||
* @return The new double. | ||
*/ | ||
public static String roundDoubleToXDP(double in, int numberOfDP) { | ||
StringBuilder n = new StringBuilder("0."); | ||
for (int i = 0; i < numberOfDP; i++) n.append("0"); | ||
DecimalFormat df = new DecimalFormat(n.toString()); | ||
df.setRoundingMode(RoundingMode.HALF_UP); | ||
return df.format(in); | ||
} | ||
|
||
} |
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
Oops, something went wrong.