Package org.plumelib.util
Class UtilP
java.lang.Object
org.plumelib.util.UtilP
Utility methods that do not belong elsewhere in the plume package: BitSet; hashing;
ProcessBuilder; properties; Throwable.
-
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable StringappendProperty(Properties p, String key, String value) Set the property to its previous value concatenated to the given value.static StringExecute the given command in the given directory, and return all its output as a string.static StringExecute the given command in the given directory, and return all its output as a string.static StringExecute the given command, and return all its output as a string.static StringExecute the given command, and return all its output as a string.static <T> @PolyNull @PolySigned Tclone(@PolyNull @PolySigned T data) Clones the given object by callingclone()reflectively.static <T> TfirstNonNull(T first, T second) Returns the first argument if it is non-null, otherwise returns the second argument.static booleangetBooleanProperty(Properties p, String key) Returns true if a property has a string value that represents true: "true", "yes", or "1".static booleangetBooleanProperty(Properties p, String key, boolean defaultValue) Returns true if a property has a string value that represents true: "true", "yes", or "1".static inthash(double @Nullable [] a, double @Nullable [] b) Returns a hash of the arguments.static inthash(long @Nullable [] a, long @Nullable [] b) Returns a hash of the arguments.static @Nullable StringsetDefaultMaybe(Properties p, String key, String value) Set the property only if it was not previously set.static StringReturns a String representation of the stack trace (the backtrace) of the given Throwable.
-
Method Details
-
clone
public static <T> @PolyNull @PolySigned T clone(@PolyNull @PolySigned T data) Clones the given object by callingclone()reflectively. It is not possible to callObject.clone()directly because it has protected visibility.- Type Parameters:
T- the type of the object to clone- Parameters:
data- the object to clone- Returns:
- a clone of the object
-
firstNonNull
public static <T> T firstNonNull(T first, T second) Returns the first argument if it is non-null, otherwise returns the second argument. Throws an exception if both arguments are null.- Type Parameters:
T- the type of the arguments- Parameters:
first- a referencesecond- a reference- Returns:
- the first argument that is non-null
-
hash
public static int hash(double @Nullable [] a, double @Nullable [] b) Returns a hash of the arguments.- Parameters:
a- value to be hashedb- value to be hashed- Returns:
- a hash of the arguments
-
hash
public static int hash(long @Nullable [] a, long @Nullable [] b) Returns a hash of the arguments.- Parameters:
a- value to be hashedb- value to be hashed- Returns:
- a hash of the arguments
-
backticks
Execute the given command, and return all its output as a string.- Parameters:
command- a command to execute on the command line- Returns:
- all the output of the command
-
backticks
Execute the given command in the given directory, and return all its output as a string.- Parameters:
dir- the directory in which to execute the commandcommand- a command to execute on the command line- Returns:
- all the output of the command
-
backticks
Execute the given command, and return all its output as a string.- Parameters:
command- a command to execute on the command line, as a list of strings (the command, then its arguments)- Returns:
- all the output of the command
-
backticks
Execute the given command in the given directory, and return all its output as a string.- Parameters:
dir- the directory in which to execute the commandcommand- a command to execute on the command line, as a list of strings (the command, then its arguments)- Returns:
- all the output of the command
-
getBooleanProperty
Returns true if a property has a string value that represents true: "true", "yes", or "1". Errs if the property is set to a value that is not one of "true", "false", "yes", "no", "1", or "0".- Parameters:
p- a Properties object in which to look up the propertykey- name of the property to look updefaultValue- the value to return if the property is not set- Returns:
- true iff the property has value "true", "yes", or "1"
- See Also:
-
getBooleanProperty
Returns true if a property has a string value that represents true: "true", "yes", or "1". Errs if the property is set to a value that is not one of "true", "false", "yes", "no", "1", or "0".- Parameters:
p- a Properties object in which to look up the propertykey- name of the property to look up- Returns:
- true iff the property has value "true", "yes", or "1"
- See Also:
-
appendProperty
Set the property to its previous value concatenated to the given value. Return the previous value.- Parameters:
p- a Properties object in which to look up the propertykey- name of the property to look upvalue- value to concatenate to the previous value of the property- Returns:
- the previous value of the property
- See Also:
-
setDefaultMaybe
Set the property only if it was not previously set.- Parameters:
p- a Properties object in which to look up the propertykey- name of the property to look upvalue- value to set the property to, if it is not already set- Returns:
- the previous value of the property
- See Also:
-
stackTraceToString
Returns a String representation of the stack trace (the backtrace) of the given Throwable. For a stack trace at the current location, dostackTraceToString(new Throwable()).- Parameters:
t- the Throwable to obtain a stack trace of- Returns:
- a String representation of the stack trace of the given Throwable
-