| Modifier and Type | Class and Description |
|---|---|
static interface |
Utils.Function<A,B>
Represents a function that can be applied to objects of
A and
returns objects of B. |
| Modifier and Type | Field and Description |
|---|---|
private static double |
EPSILON |
private static char[] |
HEX_ARRAY |
| Modifier | Constructor and Description |
|---|---|
private |
Utils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
close(Closeable c)
Utility method for closing a
Closeable object. |
static void |
close(ZipFile zip)
Utility method for closing a
ZipFile. |
static Integer |
color_float2int(Float val)
convert float range 0 <= x <= 1 to integer range 0..255
when dealing with colors and color alpha value
|
static Float |
color_int2float(Integer val)
convert back
|
static Color |
complement(Color clr) |
static char[] |
copyArray(char[] array)
Copies the given array.
|
static <T> T[] |
copyArray(T[] array)
Copies the given array.
|
static void |
copyFile(File in,
File out)
Simple file copy function that will overwrite the target file.
|
static int |
copyStream(InputStream source,
OutputStream destination) |
static boolean |
copyToClipboard(String s)
Copies the string
s to system clipboard. |
static boolean |
deleteDirectory(File path) |
static void |
ensure(boolean condition,
String message,
Object... data) |
static <T> boolean |
equal(T a,
T b)
for convenience: test whether 2 objects are either both null or a.equals(b)
|
static boolean |
equalsEpsilon(double a,
double b)
Determines if the two given double values are equal (their delta being smaller than a fixed epsilon)
|
static String |
execOutput(List<String> command)
Runs an external command and returns the standard output.
|
static <T> boolean |
exists(Iterable<? extends T> collection,
Predicate<? super T> predicate) |
static <T> boolean |
exists(Iterable<T> collection,
Class<? extends T> klass) |
static <T> Collection<T> |
filter(Collection<? extends T> collection,
Predicate<? super T> predicate) |
static <S,T extends S> |
filteredCollection(Collection<S> collection,
Class<T> klass)
Filter a collection by (sub)class.
|
static <T> T |
find(Iterable<? extends T> collection,
Predicate<? super T> predicate) |
static <T> T |
find(Iterable<? super T> collection,
Class<? extends T> klass) |
static <T> T |
firstNonNull(T... items) |
static String |
getClipboardContent()
Extracts clipboard content as string.
|
static String |
getDurationString(long elapsedTime)
Returns a simple human readable (hours, minutes, seconds) string for a given duration in milliseconds.
|
static File |
getJosmTempDir()
Returns the JOSM temp directory.
|
static Color |
hexToColor(String s)
Convert Hex String to Color.
|
static <T> int |
indexOf(Iterable<? extends T> collection,
Predicate<? super T> predicate) |
static String |
join(String sep,
Collection<?> values)
Joins a list of strings (or objects that can be converted to string via
Object.toString()) into a single string with fields separated by sep.
|
static String |
joinAsHtmlUnorderedList(Collection<?> values) |
static int |
max(int a,
int b,
int c,
int d) |
static String |
md5Hex(String data)
Calculate MD5 hash of a string and output in hexadecimal format.
|
static int |
min(int a,
int b,
int c)
Get minimum of 3 values
|
static int |
mod(int a,
int n)
return the modulus in the range [0, n)
|
static HttpURLConnection |
openHttpConnection(URL httpURL)
Opens a HTTP connection to the given URL and sets the User-Agent property to JOSM's one.
|
static HttpURLConnection |
openHttpConnection(URL httpURL,
boolean keepAlive)
Opens a HTTP connection to the given URL, sets the User-Agent property to JOSM's one and optionnaly disables Keep-Alive.
|
static InputStream |
openURL(URL url)
Opens a connection to the given URL and sets the User-Agent property to JOSM's one.
|
static InputStream |
openURLAndDecompress(URL url,
boolean decompress)
Opens a connection to the given URL, sets the User-Agent property to JOSM's one, and decompresses stream if necessary.
|
static BufferedReader |
openURLReader(URL url)
Opens a connection to the given URL and sets the User-Agent property to JOSM's one.
|
static BufferedReader |
openURLReaderAndDecompress(URL url,
boolean decompress)
Opens a connection to the given URL and sets the User-Agent property to JOSM's one.
|
static URLConnection |
setupURLConnection(URLConnection connection)
Setups the given URL connection to match JOSM needs by setting its User-Agent and timeout properties.
|
static String |
strip(String str)
An alternative to
String.trim() to effectively remove all leading and trailing white characters, including Unicode ones. |
static String |
toHexString(byte[] bytes)
Converts a byte array to a string of hexadecimal characters.
|
static <T> List<T> |
topologicalSort(MultiMap<T,T> dependencies)
Topological sort.
|
static String |
toString(Color c)
convert Color to String
(Color.toString() omits alpha value)
|
static <A,B> Collection<B> |
transform(Collection<? extends A> c,
Utils.Function<A,B> f)
Transforms the collection
c into an unmodifiable collection and
applies the Utils.Function f on each element upon access. |
static <A,B> List<B> |
transform(List<? extends A> l,
Utils.Function<A,B> f)
Transforms the list
l into an unmodifiable list and
applies the Utils.Function f on each element upon access. |
private static final double EPSILON
private static final char[] HEX_ARRAY
private Utils()
public static <T> boolean exists(Iterable<? extends T> collection, Predicate<? super T> predicate)
public static <T> Collection<T> filter(Collection<? extends T> collection, Predicate<? super T> predicate)
public static <T> T firstNonNull(T... items)
public static <S,T extends S> SubclassFilteredCollection<S,T> filteredCollection(Collection<S> collection, Class<T> klass)
public static <T> int indexOf(Iterable<? extends T> collection, Predicate<? super T> predicate)
public static int min(int a, int b, int c)
public static int max(int a, int b, int c, int d)
public static <T> boolean equal(T a, T b)
public static int mod(int a, int n)
public static String join(String sep, Collection<?> values)
sep - the separatorvalues - collection of objects, null is converted to the
empty stringpublic static String joinAsHtmlUnorderedList(Collection<?> values)
public static String toString(Color c)
public static Integer color_float2int(Float val)
public static Float color_int2float(Integer val)
public static Color complement(Color clr)
public static <T> T[] copyArray(T[] array)
Arrays.copyOf(T[], int), this method is null-safe.array - The array to copynull if array is nullpublic static char[] copyArray(char[] array)
Arrays.copyOf(T[], int), this method is null-safe.array - The array to copynull if array is nullpublic static void copyFile(File in, File out) throws IOException
in - The source fileout - The destination fileIOException - If any I/O error occurspublic static int copyStream(InputStream source, OutputStream destination) throws IOException
IOExceptionpublic static boolean deleteDirectory(File path)
public static void close(Closeable c)
Utility method for closing a Closeable object.
c - the closeable object. May be null.public static void close(ZipFile zip)
Utility method for closing a ZipFile.
zip - the zip file. May be null.public static boolean equalsEpsilon(double a, double b)
a - The first double value to compareb - The second double value to comparetrue if abs(a - b) <= 1e-11, false otherwisepublic static boolean copyToClipboard(String s)
s to system clipboard.s - string to be copied to clipboard.public static String getClipboardContent()
null otherwise.public static String md5Hex(String data)
data - arbitrary Stringpublic static String toHexString(byte[] bytes)
bytes - the byte arraypublic static <T> List<T> topologicalSort(MultiMap<T,T> dependencies)
dependencies - contains mappings (key -> value). In the final list of sorted objects, the key will come
after the value. (In other words, the key depends on the value(s).)
There must not be cyclic dependencies.public static <A,B> Collection<B> transform(Collection<? extends A> c, Utils.Function<A,B> f)
c into an unmodifiable collection and
applies the Utils.Function f on each element upon access.A - class of input collectionB - class of transformed collectionc - a collectionf - a function that transforms objects of A to objects of Bpublic static <A,B> List<B> transform(List<? extends A> l, Utils.Function<A,B> f)
l into an unmodifiable list and
applies the Utils.Function f on each element upon access.A - class of input collectionB - class of transformed collectionl - a collectionf - a function that transforms objects of A to objects of Bpublic static Color hexToColor(String s)
s - Must be of the form "#34a300" or "#3f2", otherwise throws Exception.
Upper/lower case does not matter.public static HttpURLConnection openHttpConnection(URL httpURL) throws IOException
httpURL - The HTTP url to open (must use http:// or https://)IOException - if an I/O exception occurs.public static InputStream openURL(URL url) throws IOException
url - The url to openIOException - if an I/O exception occurs.public static InputStream openURLAndDecompress(URL url, boolean decompress) throws IOException
url - The url to opendecompress - whether to wrap steam in a GZIPInputStream or CBZip2InputStream
if the Content-Type header is set accordingly.IOException - if an I/O exception occurs.public static URLConnection setupURLConnection(URLConnection connection)
connection - The connection to setupconnection, with updated propertiespublic static BufferedReader openURLReader(URL url) throws IOException
url - The url to openIOException - if an I/O exception occurs.public static BufferedReader openURLReaderAndDecompress(URL url, boolean decompress) throws IOException
url - The url to opendecompress - whether to wrap steam in a GZIPInputStream or CBZip2InputStream
if the Content-Type header is set accordingly.IOException - if an I/O exception occurs.public static HttpURLConnection openHttpConnection(URL httpURL, boolean keepAlive) throws IOException
httpURL - The HTTP url to open (must use http:// or https://)keepAlive - whether not to set header Connection=closeIOException - if an I/O exception occurs.public static String strip(String str)
String.trim() to effectively remove all leading and trailing white characters, including Unicode ones.str - The string to stripstr, without leading and trailing characters, according to
Character.isWhitespace(char) and Character.isSpaceChar(char).public static String execOutput(List<String> command) throws IOException
command - the command with argumentsIOException - when there was an error, e.g. command does not existpublic static File getJosmTempDir()
<java.io.tmpdir>/JOSM), or null if java.io.tmpdir is not definedpublic static String getDurationString(long elapsedTime) throws IllegalArgumentException
elapsedTime - The duration in millisecondsIllegalArgumentException - if elapsedTime is < 0