public class Util
extends java.lang.Object
Constructor and Description |
---|
Util() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
calculateSHA1(java.io.File file)
Calculate the SHA-1 digest of a file and return it as an
upper-case hexadecimal string.
|
static java.awt.geom.Line2D |
clipLineToRectangle(java.awt.geom.Line2D line,
java.awt.geom.Rectangle2D r)
Clips a line to a supplied rectangle.
|
static void |
downloadUrlToFile(java.lang.String url,
java.nio.file.Path outputPath) |
static java.awt.geom.Rectangle2D |
envelope(java.util.Collection<java.awt.geom.Point2D> points)
Returns the rectangular envelope for the supplied points.
|
static java.nio.file.Path |
getAppDataDirectory()
Return a directory where PuffinPlot can store files for "internal"
use.
|
static java.util.BitSet |
numberRangeStringToBitSet(java.lang.String input,
int limit)
Converts a string specification of number ranges to a corresponding
BitSet . |
static double |
parseDoubleSafely(java.lang.String s)
A wrapper around
Double.parseDouble which returns
a default value of 0 if the supplied string cannot
be parsed. |
static java.awt.geom.Line2D |
scaleLine(java.awt.geom.Line2D line,
double scale)
Scales a line around its midpoint.
|
static void |
zipDirectory(java.nio.file.Path dir,
java.nio.file.Path zipFile) |
public static java.util.BitSet numberRangeStringToBitSet(java.lang.String input, int limit)
Converts a string specification of number ranges to a corresponding
BitSet
. The specification is of the form commonly encountered
in Print dialog boxes: a sequence of comma-separated units. Each unit
can be either an integer (meaning that the corresponding item should
be selected) or two integers separated by a hyphen (-) character
(meaning that all items in the corresponding range should be
selected). Example inputs and outputs are shown below.
1 | 1 |
1,3 | 101 |
4-6 | 000111 |
4-6,8-10,10,11,15-16 | 0001110111100011 |
1-4,3-5,10,12-14,17 | 11111000010111001 |
Note that the range specifications are one-based (the first
item is specified by 1, not 0) but the BitSet
output
is zero-based.
Since an error in the specification string might result in an impractically large bitset, this method also takes a limit argument; no bits will be set beyond the specified limit.
input
- a specification stringlimit
- upper limit for bits to set; limit-1
will be the
highest possible set bitpublic static java.awt.geom.Line2D clipLineToRectangle(java.awt.geom.Line2D line, java.awt.geom.Rectangle2D r)
line
- a line (null if none)r
- a clipping rectangle (null if none)public static double parseDoubleSafely(java.lang.String s)
Double.parseDouble
which returns
a default value of 0
if the supplied string cannot
be parsed. (Double.parseDouble
, in contrast, throws
a NumberFormatException
.)s
- A string representation of a floating-point number.double
with a value corresponding to the
supplied string, or 0
if the string could not be
interpreted as a floating-point number.public static java.nio.file.Path getAppDataDirectory() throws java.io.IOException
java.io.IOException
- if there was an error creating or finding the directorypublic static java.awt.geom.Rectangle2D envelope(java.util.Collection<java.awt.geom.Point2D> points)
points
- a set of pointspublic static java.awt.geom.Line2D scaleLine(java.awt.geom.Line2D line, double scale)
line
- the line to scalescale
- the scale factorpublic static void zipDirectory(java.nio.file.Path dir, java.nio.file.Path zipFile) throws java.io.IOException
java.io.IOException
public static java.lang.String calculateSHA1(java.io.File file) throws java.io.IOException, java.security.NoSuchAlgorithmException
file
- the file for which to calculate the digestjava.io.IOException
- if there is an error reading the filejava.security.NoSuchAlgorithmException
- if the SHA-1 algorithm is not availablepublic static void downloadUrlToFile(java.lang.String url, java.nio.file.Path outputPath) throws java.io.IOException
url
- outputPath
- java.io.IOException