public final class Utils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
Utils.ContextContainer
Simple container that stores and returns a context-local instance of
the global work area.
|
private static class |
Utils.DirectoryHelper
Provides a simple unified API for delegating the querying of a
data type-specific value from the directory.
|
static class |
Utils.DirScope
Define search modes for the directory node lookups.
|
static class |
Utils.InstrumentedMap<K,V>
Utility class extending HashMap functionality
|
static class |
Utils.JarResource
Object returned by a search for a resource in a jar file.
|
private static class |
Utils.MethodData
Global ReflectASM data for
invoke(Method, Object, Object...) . |
private static class |
Utils.WorkArea
Stores global data relating to the state of the current context.
|
private static class |
Utils.ZKey
Auxiliary class for use on the normalizeOrder method
|
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.String,java.lang.reflect.Constructor<?>> |
bdtConstructors
A cache of single-arg constructors in all possible
BaseDataType sub-classes. |
private static boolean |
init
Tracks if the static data has been initialized.
|
private static java.util.logging.Logger |
LOG
logger
|
private static java.util.Map<java.lang.Class<?>,Utils.MethodData> |
METHOD_DATA
Global cache of ReflectASM information for
invoke(Method, Object, Object...) . |
private static java.lang.String |
override
Charset name to use for encoding or
null for default. |
private static java.lang.Object |
token
Logging token that ensures unimplemented feature logging occurs only once.
|
private static Utils.ContextContainer |
work
Stores context-local state variables.
|
Modifier | Constructor and Description |
---|---|
private |
Utils()
Private constructor to prevent instances of this class from being
created.
|
Modifier and Type | Method and Description |
---|---|
static long |
bytesToLongLE(byte[] data)
Converts little-endian bytes to long number.
|
static java.lang.String |
calculateResourcePath(java.lang.String pageContext,
java.lang.Package location,
java.lang.String pageFile)
Calculates a resource path to the target page within its application class path.
|
static java.lang.String |
canonicalizePath(java.lang.String path,
java.lang.String oldSeparator,
java.lang.String newSeparator)
Canonicalize the given file system path as described by
java.io.File.getCanonicalPath() . |
static boolean |
causeChainContains(java.lang.Throwable thr,
java.lang.Class[] criteria)
Determine if the given throwable or one of its causes matches one of the throwable
types given as criteria.
|
static void |
collectInterfaces(java.lang.Class<?> cls,
java.util.Set<java.lang.Class<?>> interfaces)
Collect all the implemented interfaces (directly and from the hierarchy), for the given
class.
|
static boolean |
containsAll(org.roaringbitmap.longlong.Roaring64Bitmap instance,
org.roaringbitmap.longlong.Roaring64Bitmap other)
Check if the given instance contains all elements from the other instance.
|
static boolean |
containsAll(org.roaringbitmap.RoaringBitmap instance,
org.roaringbitmap.RoaringBitmap other)
Check if the given instance contains all elements from the other instance.
|
static int |
convertCodepoint(int codepoint,
java.lang.String cset)
Convert a unicode codepoint into codepoint according to the provided charset.
|
static boolean |
copyFile(java.lang.String source,
java.lang.String target,
int bsize,
boolean append)
Handles the byte for byte copying of a single source file to a target
file, using a buffer size of the caller's choice.
|
static boolean |
copyFileIfNeeded(java.lang.String source,
java.lang.String target,
int bsize)
Conditionally copies a file, byte for byte (no changes) to a new file,
if and only if the source is an accessible file and the target doesn't
exist or the target exists as a file but is older than the source or
has a different size.
|
static boolean |
createPathForTarget(java.lang.String tar)
Creates all subdirectories needed to provide a valid path for the
target filename that is passed in.
|
static java.lang.String |
describeContext()
Get a string which uniquely describes the current context.
|
static void |
dfsClassHierarchy(java.lang.Class<?> cls,
java.util.function.Consumer<java.lang.Class<?>> task)
Do a DFS walk of the class hierarchy and execute the given task when going 'back up' on the tree.
|
static <T> void |
difference(java.util.Set<T> a,
java.util.Set<T> b,
java.util.Set<T> result)
Produces the difference of two sets and puts it into the third set.
|
static int[] |
diffIntArrays(int[] a,
int[] b)
Produces the difference of two int arrays.
|
static void |
disableClientSSLCertificateValidation()
The method disables validation of SSL certificates when initiating HTTPS client connections
using java.net facility.
|
static <T> T |
doWithBoundDS(DirectoryService ds,
boolean _throw,
java.util.function.Function<DirectoryService,T> code)
The method executes the supplied
code with a bound Directory service. |
static boolean |
enumDirectoryNodes(DirectoryService directoryService,
java.lang.String nodeRelativePath,
boolean scope,
java.util.function.Function<java.lang.String,java.lang.Boolean> func)
Enumerates the nodes found at the node given by its relative path.
|
static java.util.List<java.lang.String> |
enumerateNodes(DirectoryService ds,
java.lang.String nodeId,
Utils.DirScope scope,
java.lang.String[] accountIds)
Enumerate nodes in the specified container from the directory if it exists or return
an empty list if the container directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static <T> boolean |
equals(T obj1,
T obj2)
Generic type safe equals.
|
private static java.lang.Object |
executeLookup(DirectoryService ds,
java.lang.String root,
java.lang.String postfix,
java.lang.String nodeId,
java.lang.String expected,
Utils.DirectoryHelper helper)
Builds the node path from its parts, checks that it exists with the
correct data type and if so, returns the value.
|
static java.lang.reflect.Constructor<?> |
findConstructor(java.lang.Class<?> cls,
java.lang.Class<?> arg)
Find the first single-argument constructor which has a single parameter with the argument's
type or any of its super-classes or super-interfaces.
|
static java.lang.String |
findDirectoryNodePath(DirectoryService ds,
java.lang.String nodeId,
java.lang.String expected,
boolean scope)
Obtain the path to the node in the directory if it exists or return
null if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable. |
static java.lang.String |
findDirectoryNodePath(DirectoryService ds,
java.lang.String nodeId,
java.lang.String expected,
Utils.DirScope scope,
java.lang.String[] accountIds)
Obtain the path to the node in the directory if it exists or return
null if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable. |
static java.lang.reflect.Field |
findFieldWithValue(java.lang.Object instance,
java.lang.Class<?> cls,
java.lang.Object val)
Find a field with the specified value, in given class.
|
static java.io.File |
findFileInPath(java.lang.String filename,
java.lang.String[] paths)
Find the specified file in the file system using the specified search
paths and return it.
|
static java.util.List<java.io.File> |
getCaseInsensitiveFilenameMatches(java.lang.String path)
Supply a list of files which case-insensitively match the given file
name.
|
static java.util.List<java.io.File> |
getCaseInsensitiveFilenameMatches(java.lang.String path,
java.lang.String separator)
Supply a list of files which case-insensitively match the given file
name.
|
static java.lang.String |
getCharsetName()
Reports the default character set name.
|
static java.lang.String |
getCharsetOverride()
Reports if the default character set needs to be replaced.
|
static int |
getCodepoint(int keyCode,
java.lang.String cset)
Get the unicode codepoint for the given key code and char set.
|
static <TBean> java.util.List<TBean> |
getDirectoryNodeBeanList(DirectoryService ds,
java.lang.String nodeRelativePath,
java.util.List<TBean> list,
java.lang.Class<TBean> cls,
boolean scope,
boolean attributes) |
static boolean |
getDirectoryNodeBoolean(DirectoryService ds,
java.lang.String nodeId,
boolean initial)
Obtain the specified attribute from the directory if it exists or return
the default value if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static boolean |
getDirectoryNodeBoolean(DirectoryService ds,
java.lang.String nodeId,
boolean initial,
boolean scope)
Obtain the specified attribute from the directory if it exists or return
the default value if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static boolean |
getDirectoryNodeBoolean(DirectoryService ds,
java.lang.String nodeId,
boolean initial,
Utils.DirScope scope,
java.lang.String[] accountIds)
Obtain the specified attribute from the directory if it exists or return
the default value if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static byte[] |
getDirectoryNodeByteArray(DirectoryService ds,
java.lang.String nodeId,
byte[] initial,
Utils.DirScope scope,
java.lang.String[] accountIds)
Obtain the specified attribute from the directory if it exists or return
the default value if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static char |
getDirectoryNodeChar(DirectoryService ds,
java.lang.String nodeId,
char initial)
Obtain the specified attribute from the directory if it exists or return
the default value if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static char |
getDirectoryNodeChar(DirectoryService ds,
java.lang.String nodeId,
char initial,
boolean scope)
Obtain the specified attribute from the directory if it exists or return
the default value if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static char |
getDirectoryNodeChar(DirectoryService ds,
java.lang.String nodeId,
char initial,
Utils.DirScope scope,
java.lang.String[] accountIds)
Obtain the specified attribute from the directory if it exists or return
the default value if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static double |
getDirectoryNodeDouble(DirectoryService ds,
java.lang.String nodeId,
double initial)
Obtain the specified attribute from the directory if it exists or return
the default value if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static double |
getDirectoryNodeDouble(DirectoryService ds,
java.lang.String nodeId,
double initial,
boolean scope)
Obtain the specified attribute from the directory if it exists or return
the default value if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static double |
getDirectoryNodeDouble(DirectoryService ds,
java.lang.String nodeId,
double initial,
Utils.DirScope scope,
java.lang.String[] accountIds)
Obtain the specified attribute from the directory if it exists or return
the default value if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static int |
getDirectoryNodeInt(DirectoryService ds,
java.lang.String nodeId,
int initial)
Obtain the specified attribute from the directory if it exists or return
the default value if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static int |
getDirectoryNodeInt(DirectoryService ds,
java.lang.String nodeId,
int initial,
boolean scope)
Obtain the specified attribute from the directory if it exists or return
the default value if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static int |
getDirectoryNodeInt(DirectoryService ds,
java.lang.String nodeId,
int initial,
Utils.DirScope scope,
java.lang.String[] accountIds)
Obtain the specified attribute from the directory if it exists or return
the default value if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static java.util.Map<java.lang.String,java.lang.String> |
getDirectoryNodeMap(DirectoryService ds,
java.lang.String nodeRelativePath,
java.util.Map<java.lang.String,java.lang.String> map,
boolean scope,
boolean caseInsensitiveKeys)
Fills the provided or new created map with key and values found at the node given by its
relative path.
|
static java.lang.String |
getDirectoryNodeString(DirectoryService ds,
java.lang.String nodeId,
java.lang.String initial)
Obtain the specified attribute from the directory if it exists or return
the default value if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static java.lang.String |
getDirectoryNodeString(DirectoryService ds,
java.lang.String nodeId,
java.lang.String initial,
boolean scope)
Obtain the specified attribute from the directory if it exists or return
the default value if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static java.lang.String |
getDirectoryNodeString(DirectoryService ds,
java.lang.String nodeId,
java.lang.String initial,
Utils.DirScope scope,
java.lang.String[] accountIds)
Obtain the specified attribute from the directory if it exists or return
the default value if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static java.util.List<java.lang.String> |
getDirectoryNodeStrings(DirectoryService ds,
java.lang.String nodeId,
Utils.DirScope scope,
java.lang.String[] accountIds)
Obtain the specified attribute values from the directory if it exists or return
an empty list if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
|
static java.lang.Object |
getDirectoryNodeWorker(DirectoryService directoryService,
java.lang.String nodeId,
java.lang.String expected,
Utils.DirectoryHelper helper,
Utils.DirScope scope,
java.lang.String[] accountIds)
Obtain the specified attribute from the directory if it exists or return the
null if
the directory node doesn't exist with the proper type, the directory paths don't exist or
the directory is unavailable. |
static java.lang.String |
getExt(java.lang.String fileName)
Extract extension from the file name
|
static java.lang.String |
getJarPath(java.lang.Class clazz)
Get the path of the jar file containing the given class.
|
static java.lang.String |
getOrCreateDefaultFwdTemporaryDirectory()
Get or create the default directory for temporary files used by FWD.
|
static java.lang.String |
getOrCreateTemporaryDirectory(java.lang.String folderName)
Get or create a directory for temporary files used by FWD.
|
static PathResolver |
getPathResolver(java.lang.String fileSeparator,
boolean caseSensitive,
java.util.Map<java.lang.String,java.lang.String> pathMap)
Gets the path resolver for the current directory settings.
|
static int |
getPortForService(DirectoryService ds,
java.lang.String name)
Obtain the port number which has been mapped in the directory to a given
service name.
|
static java.lang.String |
getProjectToken()
Get the current project token.
|
static java.lang.String |
getRefinedPathName(java.lang.String nameDirty,
java.lang.String separator)
Gets a resource path string to be cleared from invalid sequences and file separator duplication.
|
static java.lang.String |
getRequiredProperty(java.util.Properties props,
java.lang.String key)
Retrieve the property with the specified
key from within
the specified properties. |
static PathResolverContainer |
getSafePathResolver(java.lang.String fileSeparator,
boolean caseSensitive,
java.util.Map<java.lang.String,java.lang.String> pathMap)
Gets the path resolver that silently logs all cases when UnResolvedPathException is thrown.
|
static int |
getSizeLimitFromString(java.lang.String sizeStr)
Converts string size value to integer one.
|
static java.lang.String |
getUnqualifiedName(java.lang.Class<?> cls)
Get the short name of a class or interface (everything after the last
dot in the fully qualified class name).
|
static int[] |
integerCollectionToPrimitive(java.util.Collection<java.lang.Integer> list)
Convert a collection of wrapper objects into the corresponding array of
primitive types.
|
static int[][] |
integerMapToPrimitive(java.util.Map<java.lang.Integer,java.lang.Integer> map)
Convert a map of wrapper objects into the corresponding array of
primitive types.
|
static boolean |
intersect(org.roaringbitmap.longlong.Roaring64Bitmap a,
org.roaringbitmap.longlong.Roaring64Bitmap b)
Determines whether two sets have common elements.
|
static boolean |
intersect(org.roaringbitmap.RoaringBitmap a,
org.roaringbitmap.RoaringBitmap b)
Determines whether two sets have common elements.
|
static <T> boolean |
intersect(java.util.Set<T> a,
java.util.Set<T> b)
Determines whether two sets have common elements.
|
static <T> void |
intersection(java.util.Set<T> a,
java.util.Set<T> b,
java.util.Set<T> result)
Produces the intersection of two sets and puts it into the third set.
|
static java.lang.Object |
invoke(java.lang.Class<?> cl,
java.lang.reflect.Method entry,
java.lang.Object... args)
Executes the given entry point using reflection, instantiating
the target class first, if necessary.
|
static java.lang.Object |
invoke(java.lang.reflect.Method method,
java.lang.Object instance,
java.lang.Object... args)
Invoke the specified
Method using ReflectASM instead of standard reflection. |
static boolean |
isChUI()
Determine if we are on ChUI or not.
|
static boolean |
isClient()
Determine if we are on the client or not.
|
static boolean |
isGUI()
Determine if we are on GUI or not.
|
static boolean |
isLaterVersion(java.lang.String source,
java.lang.String target)
Determines if a both source and target exist as files and if the target
has a later timestamp.
|
static <T> boolean |
isSame(java.util.Set<T> a,
java.util.Set<T> b)
Check if the two sets are the same.
|
static boolean |
isServer()
Determine if we are on the server or not.
|
static boolean |
isValidValue(int value,
int... validValues)
Check if a given value is a valid value.
|
static java.util.Properties |
loadProperties(java.lang.String filename)
Load and return a
Properties object from a properties
file specified by filename . |
static long[] |
longCollectionToPrimitive(java.util.Collection<java.lang.Long> list)
Convert a collection of wrapper objects into the corresponding array of
primitive types.
|
static byte[] |
longToBytesLE(long l)
Converts long number to little-endian bytes.
|
private static void |
matchPathCaseInsensitively(java.io.File leading,
java.lang.String fullPath,
java.util.List<java.io.File> list)
Find as many files as case-insensitively match the file specified by
fullPath , where the directory specified by
leading represents a leading portion of the given path. |
static java.lang.String |
mimeType(java.lang.String fileName)
Get mimeType of the mouse cursor file
|
static <W> boolean |
moveToBottomInClass(java.util.List<W> widgets,
W widget,
java.util.function.Function<W,ZOrderClass> zorder)
Move the specified widget to the bottom of the widget list considering Z-order class.
|
static <W> boolean |
moveToTopInClass(java.util.List<W> widgets,
W widget,
java.util.function.Function<W,ZOrderClass> zorder)
Move specified widget to the top of the given widget list considering Z-order class.
|
static void |
noHelp()
Serves as a placeholder for some interactive help.
|
static java.lang.String |
nonEmpty(java.lang.Object... args)
The method returns the first non-empty trimmed string represented by the supplied
arguments.
|
static <T> T |
nonNull(T... args)
The method returns the first non-null argument from the supplied array of
arguments.
|
static <W> java.util.Collection<W> |
normalizeZOrder(java.util.Collection<W> widgets,
java.util.function.Function<W,ZOrderClass> zorder)
Reorder widgets according to their ZOrderClass retaining the order within the class.
|
static int[] |
objectToPrimitive(java.lang.Integer[] array)
Convert the array of wrapper objects into the corresponding array of
primitive types.
|
static long[] |
objectToPrimitive(java.lang.Long[] array)
Convert the array of wrapper objects into the corresponding array of
primitive types.
|
static java.util.List<java.lang.Integer> |
primitiveToIntegerList(int[] array)
Convert an array of primitive types into a list of the corresponding
wrapper objects.
|
static java.util.List<java.lang.Long> |
primitiveToLongList(long[] array)
Convert an array of primitive types into a list of the corresponding
wrapper objects.
|
static java.lang.Integer[] |
primitiveToObject(int[] array)
Convert the array of primitives into the corresponding array of wrapper
objects.
|
static java.lang.Long[] |
primitiveToObject(long[] array)
Convert the array of primitives into the corresponding array of wrapper
objects.
|
static void |
printChainedErrors(java.lang.Throwable thr,
java.io.PrintStream out,
int indent)
Extract the error message from a throwable and each of its chained
throwables, printing them on consecutive lines using the specified
print stream.
|
static char[] |
prompt(java.lang.String txt)
Displays a prompt on
stdout and returns the input entered
by the user on stdin . |
static java.util.List<java.lang.String> |
readCSVLine(java.io.Reader r)
Reads a row of CSV values from the reader and returns the values as a Java list.
|
static <T> void |
removeAllIf(java.util.Collection<T> c,
java.util.function.Predicate<T> p)
Remove all items from that collection which satisfy the given condition
|
static boolean |
removeDirectoryNode(DirectoryService ds,
java.lang.String nodeId)
Removes the specified directory node, including all child nodes.
|
static java.lang.String |
replaceSeparator(java.lang.String path,
java.lang.String oldSeparator,
java.lang.String newSeparator)
Replace all instances of
oldSeparator with newSeparator in the given path. |
static <T> java.util.stream.Stream<T> |
reverseStream(java.util.LinkedList<T> list)
The method returns a reverse Stream
from the supplied linked list.
|
static <T> java.util.stream.Stream<T> |
reverseStream(java.util.List<T> list)
The method returns a reverse Stream
from the supplied
list . |
static <T> java.util.stream.Stream<T> |
reverseStream(T[] array)
The method returns a reverse Stream
from the supplied
array . |
static <T> T[] |
scroll(T[] source,
int first)
Scroll given array so element with specified index will be first in
array.
|
static Utils.JarResource |
searchResourceJars(java.lang.String filename,
java.util.function.Function<JarClassLoader,java.util.function.Function<java.lang.String,java.lang.String>> searchFn,
java.util.function.Function<JarClassLoader,java.util.function.Function<java.lang.String,java.lang.String>> propathSearchFn,
java.util.function.Supplier<java.util.List<java.lang.String>> propathSupplier)
Search the resource jar files for the resource with the given filename.
|
static void |
setProjectToken(java.lang.String token)
Set the project token for this context.
|
static boolean |
simpleCopy(java.lang.String src,
java.lang.String tar)
Creates the directory tree to the target if needed and then copies
the source to the target if needed.
|
static <T> void |
split(java.util.Set<T> a,
java.util.Set<T> b,
java.util.Set<T> inter,
java.util.Set<T> diff)
Produces both the intersection and difference of two sets and puts those values into the
given result set instances.
|
static char |
toChar(byte b,
java.lang.String cset)
Convert the given byte to a Unicode character using the given character
set (or the default charset if the given charset name is
null ). |
static char |
toChar(int i)
Convert the given integer to a Unicode character using the character
set defined as the default for the environment, honoring any override
configured.
|
static char |
toChar(int keyCode,
java.lang.String cset)
Convert the given byte to a Unicode character using the given character
set (or the default charset if the given charset name is
null ). |
static int |
toInt(char ch,
java.lang.String cset)
Convert the given Unicode character to an integer value using the given
character set (or the default charset if the given charset name is
null ). |
static <T,S> T |
tryWhileNull(java.util.List<S> list,
java.util.function.Function<S,T> fn)
Apply function to the list elements while the result is
null |
static int |
uniqueId()
Returns a context-wide unique integer value which can be used as an ID.
|
static void |
verifyDirectoryNode(DirectoryService ds,
java.lang.String id,
java.lang.String expected)
Verify that a directory node at a particular, required directory path
exists, and that the class of the node found at that path is that which
is expected.
|
private static final java.util.Map<java.lang.Class<?>,Utils.MethodData> METHOD_DATA
invoke(Method, Object, Object...)
.private static final java.util.logging.Logger LOG
private static Utils.ContextContainer work
private static java.lang.String override
null
for default.private static boolean init
private static java.lang.Object token
private static java.util.Map<java.lang.String,java.lang.reflect.Constructor<?>> bdtConstructors
BaseDataType
sub-classes.private Utils()
public static java.lang.reflect.Constructor<?> findConstructor(java.lang.Class<?> cls, java.lang.Class<?> arg)
cls
- The class where to search for the c'tor.arg
- The argument's type.public static <T> T[] scroll(T[] source, int first)
NOTE: Scrolling is performed "in place", so input array gets updated!
T
- source
- Source array to scroll.first
- The index of element which will be first.public static int[] objectToPrimitive(java.lang.Integer[] array)
array
- The array of wrapper objects. Must not be null
.public static java.lang.Integer[] primitiveToObject(int[] array)
array
- The array of primitive types. Must not be null
.public static int[] integerCollectionToPrimitive(java.util.Collection<java.lang.Integer> list)
list
- The collection of wrapper objects. Must not be
null
.public static int[][] integerMapToPrimitive(java.util.Map<java.lang.Integer,java.lang.Integer> map)
map
- The map of wrapper objects. Must not be
null
.public static java.util.List<java.lang.Integer> primitiveToIntegerList(int[] array)
array
- The primitive array. Must not be null
.public static long[] objectToPrimitive(java.lang.Long[] array)
array
- The array of wrapper objects. Must not be null
.public static java.lang.Long[] primitiveToObject(long[] array)
array
- The array of primitive types. Must not be null
.public static long[] longCollectionToPrimitive(java.util.Collection<java.lang.Long> list)
list
- The collection of wrapper objects. Must not be
null
.public static java.util.List<java.lang.Long> primitiveToLongList(long[] array)
array
- The primitive array. Must not be null
.public static java.util.Properties loadProperties(java.lang.String filename) throws java.io.IOException
Properties
object from a properties
file specified by filename
.filename
- Name of the properties file.filename
.java.io.IOException
- if any error occurs reading the file.public static java.lang.String getRequiredProperty(java.util.Properties props, java.lang.String key) throws MissingDataException
key
from within
the specified properties. Assume key
represents a required
property; an exception is thrown if it is not present.props
- Properties object from which to retrieve required property.key
- Key to the required property.MissingDataException
- if the required property is not present.public static char[] prompt(java.lang.String txt) throws java.io.IOException
stdout
and returns the input entered
by the user on stdin
. The first new line encountered
will end the input reading loop and the text will not include this
new line character.txt
- The text message to display.null
if there was no input provided.java.io.IOException
public static void printChainedErrors(java.lang.Throwable thr, java.io.PrintStream out, int indent)
thr
- Throwable from which to extract message and chained throwables.out
- Print stream to which messages will be written.indent
- Number of spaces to indent each error message.public static boolean causeChainContains(java.lang.Throwable thr, java.lang.Class[] criteria)
thr
- Throwable from which to examine cause chain.criteria
- List of throwables to check for.true
if any of the criteria throwables matches the given
throwable or any throwable in the cause chain.public static java.lang.String getCharsetName()
The assumption (possibly not always correct) is that UTF-8 is not a valid Progress charset and instead, to provide a proper default, we must override with a compatible charset. Note that if the default charset name is not UTF-8, it is assumed that the charset has been overridden already (at JVM startup). In that case, the default is returned unchanged.
public static java.lang.String getCharsetOverride()
If the 4GL environment is actually configured for UTF-8, then this approach won't work. If the default codepage name for the JVM is not UTF-8, it is assumed that the codepage has been overriden already (at JVM startup). In that case, the value reported by the JVM is returned unchanged.
null
if no override is required.public static char toChar(int i)
getCharsetOverride()
.
The normal ASCII range can be converted to a Unicode character by a simple widening conversion from byte to char. But the extended ASCII range (128 through 255 inclusive) will translate to character values that cannot be achieved via a widening conversion. Instead the proper character set must be used to get the right result.
i
- The integer to convert.public static char toChar(byte b, java.lang.String cset)
null
).
The normal ASCII range can be converted to a Unicode character by a simple widening conversion from byte to char. But the extended ASCII range (128 through 255 inclusive) will translate to character values that cannot be achieved via a widening conversion. Instead the proper character set must be used to get the right result.
b
- The byte to convert.cset
- The charset name to use for conversion or null
if the default charset should be used.public static char toChar(int keyCode, java.lang.String cset)
null
).
Only the least significant byte will be converted, all other data is dropped at this time.
The normal ASCII range can be converted to a Unicode character by a simple widening conversion from byte to char. But the extended ASCII range (128 through 255 inclusive) will translate to character values that cannot be achieved via a widening conversion. Instead the proper character set must be used to get the right result.
keyCode
- The number to convert. Must be between 0 and 255 inclusive.cset
- The charset name to use for conversion or null
if the default charset should be used.public static int toInt(char ch, java.lang.String cset)
null
).
The normal ASCII range can be converted from a Unicode character by a simple narrowing conversion from char to byte. But the Unicode characters representing the extended ASCII range (128 through 255 inclusive) are not represented in Unicode via a single byte. So a translation from character values to a number cannot be achieved via a narrowing conversion. Instead the proper character set must be used to get the right result.
ch
- The Unicode character to convert.cset
- The charset name to use for conversion or null
if the default charset should be used.public static int convertCodepoint(int codepoint, java.lang.String cset) throws java.nio.charset.CharacterCodingException, java.nio.charset.UnsupportedCharsetException
codepoint
- The given unicode codepointcset
- The target charset namejava.nio.charset.CharacterCodingException
- If the given unicode codepoint cannot be represented by the target charsetjava.nio.charset.UnsupportedCharsetException
- If the target charset is not supported.public static int getCodepoint(int keyCode, java.lang.String cset)
keyCode
- The given key codecset
- The given char set.public static boolean createPathForTarget(java.lang.String tar)
tar
- Target filename for which paths must be created.true
if the full necessary path already
exists or if it has been created, false
otherwise.public static java.io.File findFileInPath(java.lang.String filename, java.lang.String[] paths) throws java.io.FileNotFoundException
filename
- Name of the source file to find; if this is not an absolute
path, it should be relative to one of the paths in the
searchPaths
array.paths
- Array of absolute paths which are prepended to a relative
filename
.java.io.FileNotFoundException
- if a file named filename
does not exist in the
specified search paths (or at the absolute path provided).public static java.lang.String calculateResourcePath(java.lang.String pageContext, java.lang.Package location, java.lang.String pageFile)
pageContext
- The page root pathlocation
- The package where the target resource is located.pageFile
- The resource name with its extension.public static java.lang.String canonicalizePath(java.lang.String path, java.lang.String oldSeparator, java.lang.String newSeparator) throws java.io.IOException
java.io.File.getCanonicalPath()
. In addition, normalize
the use of the file separator by replacing all instances of
oldSeparator
with newSeparator
.path
- A relative or absolute path to be canonicalized.oldSeparator
- File separator to be replaced.newSeparator
- New file separator.java.io.IOException
- If there is a file system while canonicalizing the path.public static java.lang.String replaceSeparator(java.lang.String path, java.lang.String oldSeparator, java.lang.String newSeparator)
oldSeparator
with newSeparator
in the given path.path
- A file path.oldSeparator
- File separator to be replaced.newSeparator
- New file separator.public static boolean isLaterVersion(java.lang.String source, java.lang.String target)
source
- Source filename.target
- Target filename.true
if the both files exist and the target is
newer, otherwise false
(includes failures).public static boolean simpleCopy(java.lang.String src, java.lang.String tar)
src
- Source filename.tar
- Target filename.true
if the file was copied successfully OR
if the file didn't need to be copied, false
on any failure.public static boolean copyFileIfNeeded(java.lang.String source, java.lang.String target, int bsize)
source
- Source filename.target
- Target filename.bsize
- Buffer size or if 0 the buffer size will default to the file
size or 64Kb whichever is less.true
if the file was copied successfully OR if
the file didn't need to be copied, false
on any
failure.public static boolean copyFile(java.lang.String source, java.lang.String target, int bsize, boolean append)
source
- Source filename.target
- Target filename.bsize
- Buffer size or if 0 the buffer size will default to the file
size or 64Kb whichever is less.append
- true
if the output file should be opened in
append mode.true
if the file was copied successfully,
false
on any failure.public static java.util.List<java.io.File> getCaseInsensitiveFilenameMatches(java.lang.String path, java.lang.String separator) throws java.io.IOException
path
- The file name to be matched. It will be canonicalized before
the search is conducted.separator
- Legacy system file separator which will be replaced with the
target system's file separator (in the result list).null
.java.io.IOException
- if there is any error canonicalizing the path
.public static java.util.List<java.io.File> getCaseInsensitiveFilenameMatches(java.lang.String path) throws java.io.IOException
path
- The file name to be matched. It must already be canonicalized
(see canonicalizePath(java.lang.String, java.lang.String, java.lang.String)
) and with all file separators
converted to the current system's file separator character.null
.java.io.IOException
- if there is any error canonicalizing the path
.public static java.lang.String describeContext()
public static java.lang.Object invoke(java.lang.reflect.Method method, java.lang.Object instance, java.lang.Object... args) throws java.lang.IllegalAccessException, java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException
Method
using ReflectASM instead of standard reflection.
ReflectASM related data is cached in METHOD_DATA
, thread-local, to avoid the concurrent access.
More, the maps are identity-keyed, for fast access.
method
- The method to execute.instance
- The instance on which the call will be made; can be null
for static methods.args
- The method's arguments.java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
public static java.lang.Object invoke(java.lang.Class<?> cl, java.lang.reflect.Method entry, java.lang.Object... args) throws java.lang.NullPointerException, java.lang.IllegalAccessException, java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException, java.lang.InstantiationException
cl
- The class to be instantiated. Must be public. Must have a
public, default constructor, unless entry
is a
static method.entry
- The method to be executed. Must exist within cl
.
May be an instance method or static method; must be
publicly accessible.args
- If the method's signature contains parameters, this is a
variable argument list containing those parameters.void
return then this will return
null
. Note that it is a limitation of the
design of Java method signatures such that we do not
distinguish between a method with a void
return
and a method that has a real return value which is set to
null
.java.lang.NullPointerException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException
public static void verifyDirectoryNode(DirectoryService ds, java.lang.String id, java.lang.String expected) throws java.lang.RuntimeException
ds
- Directory service.id
- ID of node to verify.expected
- Expected class of node.java.lang.RuntimeException
- if directory node does not exist or is of the incorrect class.public static int getDirectoryNodeInt(DirectoryService ds, java.lang.String nodeId, int initial)
This method implements a search algorithm that allows values to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
No exceptions are thrown, the given initial value will always be safely returned.
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).initial
- The default value to return if the directory backed value
cannot be obtained for ANY reason.public static double getDirectoryNodeDouble(DirectoryService ds, java.lang.String nodeId, double initial)
This method implements a search algorithm that allows values to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
No exceptions are thrown, the given initial value will always be safely returned.
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).initial
- The default value to return if the directory backed value
cannot be obtained for ANY reason.public static char getDirectoryNodeChar(DirectoryService ds, java.lang.String nodeId, char initial)
This method implements a search algorithm that allows values to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
No exceptions are thrown, the given initial value will always be safely returned.
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).initial
- The default value to return if the directory backed value
cannot be obtained for ANY reason.public static java.lang.String getDirectoryNodeString(DirectoryService ds, java.lang.String nodeId, java.lang.String initial)
This method implements a search algorithm that allows values to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
No exceptions are thrown, the given initial value will always be safely returned.
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).initial
- The default value to return if the directory backed value
cannot be obtained for ANY reason.public static boolean getDirectoryNodeBoolean(DirectoryService ds, java.lang.String nodeId, boolean initial)
This method implements a search algorithm that allows values to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
No exceptions are thrown, the given initial value will always be safely returned.
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).initial
- The default value to return if the directory backed value
cannot be obtained for ANY reason.public static int getDirectoryNodeInt(DirectoryService ds, java.lang.String nodeId, int initial, boolean scope)
This method implements a search algorithm that allows values to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
No exceptions are thrown, the given initial value will always be safely returned.
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).initial
- The default value to return if the directory backed value
cannot be obtained for ANY reason.scope
- true
if account related search, otherwise server
related search is assumed.public static double getDirectoryNodeDouble(DirectoryService ds, java.lang.String nodeId, double initial, boolean scope)
This method implements a search algorithm that allows values to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
No exceptions are thrown, the given initial value will always be safely returned.
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).initial
- The default value to return if the directory backed value
cannot be obtained for ANY reason.scope
- true
if account related search, otherwise server
related search is assumed.public static char getDirectoryNodeChar(DirectoryService ds, java.lang.String nodeId, char initial, boolean scope)
This method implements a search algorithm that allows values to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
No exceptions are thrown, the given initial value will always be safely returned.
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).initial
- The default value to return if the directory backed value
cannot be obtained for ANY reason.scope
- true
if account related search, otherwise server
related search is assumed.public static java.lang.String getDirectoryNodeString(DirectoryService ds, java.lang.String nodeId, java.lang.String initial, boolean scope)
This method implements a search algorithm that allows values to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
No exceptions are thrown, the given initial value will always be safely returned.
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).initial
- The default value to return if the directory backed value
cannot be obtained for ANY reason.scope
- true
if account related search, otherwise server
related search is assumed.public static boolean getDirectoryNodeBoolean(DirectoryService ds, java.lang.String nodeId, boolean initial, boolean scope)
This method implements a search algorithm that allows values to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
No exceptions are thrown, the given initial value will always be safely returned.
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).initial
- The default value to return if the directory backed value
cannot be obtained for ANY reason.scope
- true
if account related search, otherwise server
related search is assumed.public static java.lang.String findDirectoryNodePath(DirectoryService ds, java.lang.String nodeId, java.lang.String expected, boolean scope)
null
if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
This method implements a search algorithm that allows paths to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
There are two search scopes: account relayed and server related. Account related search is described below. The server related search is a version of the search that is limited to the first two server related levels.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).expected
- Expected class of node. This will be checked with that
found in the directory for consistency.scope
- true
if account related search, otherwise server
related search is assumed.null
if for ANY
reason the directory node cannot be found.public static int getDirectoryNodeInt(DirectoryService ds, java.lang.String nodeId, int initial, Utils.DirScope scope, java.lang.String[] accountIds)
This method implements a search algorithm that allows values to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
No exceptions are thrown, the given initial value will always be safely returned.
If the scope
is set to Utils.DirScope.BOTH
, first a per-account search will be
performed. If the value is not found, it fallbacks to a per-server search.
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).initial
- The default value to return if the directory backed value
cannot be obtained for ANY reason.scope
- Search mode for the directory node lookup.accountIds
- Explicit list of account IDs which should be included in the search. When
null
, the current context's account IDs are resolved and used.public static double getDirectoryNodeDouble(DirectoryService ds, java.lang.String nodeId, double initial, Utils.DirScope scope, java.lang.String[] accountIds)
This method implements a search algorithm that allows values to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
No exceptions are thrown, the given initial value will always be safely returned.
If the scope
is set to Utils.DirScope.BOTH
, first a per-account search will be
performed. If the value is not found, it fallbacks to a per-server search.
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).initial
- The default value to return if the directory backed value
cannot be obtained for ANY reason.scope
- Search mode for the directory node lookup.accountIds
- Explicit list of account IDs which should be included in the search. When
null
, the current context's account IDs are resolved and used.public static char getDirectoryNodeChar(DirectoryService ds, java.lang.String nodeId, char initial, Utils.DirScope scope, java.lang.String[] accountIds)
This method implements a search algorithm that allows values to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
No exceptions are thrown, the given initial value will always be safely returned.
If the scope
is set to Utils.DirScope.BOTH
, first a per-account search will be
performed. If the value is not found, it fallbacks to a per-server search.
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).initial
- The default value to return if the directory backed value
cannot be obtained for ANY reason.scope
- Search mode for the directory node lookup.accountIds
- Explicit list of account IDs which should be included in the search. When
null
, the current context's account IDs are resolved and used.public static java.util.Map<java.lang.String,java.lang.String> getDirectoryNodeMap(DirectoryService ds, java.lang.String nodeRelativePath, java.util.Map<java.lang.String,java.lang.String> map, boolean scope, boolean caseInsensitiveKeys)
<node class="entry" name="entry1">
<node-attribute name="key" value="PAPERSIZE"/>
<node-attribute name="value" value="letter"/>
</node>
<node class="entry" name="entry2">
<node-attribute name="key" value="LANG"/>
<node-attribute name="value" value="en_US"/>
</node>
ds
- The directory servicenodeRelativePath
- The entries container relative pathmap
- The provided map that can be nullscope
- The true value indicates accounts search, otherwise the server search is used onlycaseInsensitiveKeys
- The true value indicates that all map keys are case insensitive and mapped to
their upper cases.public static <TBean> java.util.List<TBean> getDirectoryNodeBeanList(DirectoryService ds, java.lang.String nodeRelativePath, java.util.List<TBean> list, java.lang.Class<TBean> cls, boolean scope, boolean attributes) throws java.lang.Throwable
TBean
- The parameter type representing the class for a java bean object with all public fields.ds
- The directory servicenodeRelativePath
- The entries container relative pathlist
- The list to fill, it can be nullcls
- The class for objects being retrieved from the directory by this method.scope
- The true value indicates accounts search, otherwise the server search is used onlyattributes
- The true value indicates TBean object properties are serialized as node attributes,
otherwise properties are given as nodes.java.lang.Throwable
- If the target class has no default constructor or its fields are not accessible or
the directory service is failed.public static boolean enumDirectoryNodes(DirectoryService directoryService, java.lang.String nodeRelativePath, boolean scope, java.util.function.Function<java.lang.String,java.lang.Boolean> func)
directoryService
- The directory servicenodeRelativePath
- The entries container relative pathscope
- The true value indicates accounts search, otherwise the server search is used onlyfunc
- A function called for every sub-node found at the path given by nodeRelativePath
.
The function is passed node name of every sub-node encountered. The enumeration continues
until all the sub-nodes are enumerated or the function returns any other value than
true
.false
when the node given by nodeRelativePath
is not found, true
otherwise.public static java.lang.String getDirectoryNodeString(DirectoryService ds, java.lang.String nodeId, java.lang.String initial, Utils.DirScope scope, java.lang.String[] accountIds)
This method implements a search algorithm that allows values to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
No exceptions are thrown, the given initial value will always be safely returned.
If the scope
is set to Utils.DirScope.BOTH
, first a per-account search will be
performed. If the value is not found, it fallbacks to a per-server search.
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).initial
- The default value to return if the directory backed value
cannot be obtained for ANY reason.scope
- Search mode for the directory node lookup.accountIds
- Explicit list of account IDs which should be included in the search. When
null
, the current context's account IDs are resolved and used.public static java.util.List<java.lang.String> getDirectoryNodeStrings(DirectoryService ds, java.lang.String nodeId, Utils.DirScope scope, java.lang.String[] accountIds)
scope
is set to Utils.DirScope.BOTH
, first a per-account search will be
performed. If the value is not found, it fallbacks to a per-server search.ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).scope
- Search mode for the directory node lookup.accountIds
- Explicit list of account IDs which should be included in the search. When
null
, the current context's account IDs are resolved and used.public static boolean getDirectoryNodeBoolean(DirectoryService ds, java.lang.String nodeId, boolean initial, Utils.DirScope scope, java.lang.String[] accountIds)
This method implements a search algorithm that allows values to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
No exceptions are thrown, the given initial value will always be safely returned.
If the scope
is set to Utils.DirScope.BOTH
, first a per-account search will be
performed. If the value is not found, it fallbacks to a per-server search.
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).initial
- The default value to return if the directory backed value
cannot be obtained for ANY reason.scope
- Search mode for the directory node lookup.accountIds
- Explicit list of account IDs which should be included in the search. When
null
, the current context's account IDs are resolved and used.public static byte[] getDirectoryNodeByteArray(DirectoryService ds, java.lang.String nodeId, byte[] initial, Utils.DirScope scope, java.lang.String[] accountIds)
This method implements a search algorithm that allows values to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
No exceptions are thrown, the given initial value will always be safely returned.
If the scope
is set to Utils.DirScope.BOTH
, first a per-account search will be
performed. If the value is not found, it fallbacks to a per-server search.
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).initial
- The default value to return if the directory backed value
cannot be obtained for ANY reason.scope
- Search mode for the directory node lookup.accountIds
- Explicit list of account IDs which should be included in the search. When
null
, the current context's account IDs are resolved and used.public static java.util.List<java.lang.String> enumerateNodes(DirectoryService ds, java.lang.String nodeId, Utils.DirScope scope, java.lang.String[] accountIds)
scope
is set to Utils.DirScope.BOTH
, first a per-account search will be
performed. If the value is not found, it fallbacks to a per-server search.ds
- A bound directory service instance. If this is null
then the instance
will be dynamically queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations in which only a single
value is needed. This has negative performance implications in the case where
multiple values are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various paths listed above
(and in the precedence order specified above).scope
- Search mode for the directory node lookup.accountIds
- Explicit list of account IDs which should be included in the search. When
null
, the current context's account IDs are resolved and used.public static java.lang.String findDirectoryNodePath(DirectoryService ds, java.lang.String nodeId, java.lang.String expected, Utils.DirScope scope, java.lang.String[] accountIds)
null
if the directory node doesn't exist with the proper
type, the directory paths don't exist or the directory is unavailable.
This method implements a search algorithm that allows paths to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
There are two search scopes: account relayed and server related. Account related search is described below. The server related search is a version of the search that is limited to the first two server related levels.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/<id>
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/<id>
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/<id>
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/<id>
If the scope
is set to Utils.DirScope.BOTH
, first a per-account search will be
performed. If the value is not found, it fallbacks to a per-server search.
ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various
paths listed above (and in the precedence order specified
above).expected
- Expected class of node. This will be checked with that
found in the directory for consistency.scope
- Search mode for the directory node lookup.accountIds
- Explicit list of account IDs which should be included in the search. When
null
, the current context's account IDs are resolved and used.null
if for ANY
reason the directory node cannot be found.public static java.lang.Object getDirectoryNodeWorker(DirectoryService directoryService, java.lang.String nodeId, java.lang.String expected, Utils.DirectoryHelper helper, Utils.DirScope scope, java.lang.String[] accountIds)
null
if
the directory node doesn't exist with the proper type, the directory paths don't exist or
the directory is unavailable.
This method implements a search algorithm that allows values to be found that are account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under:
projectToken
is configured (same stands for next all pairs below):/server/<serverID>/runtime/<account_or_group>/<id>.<project>
;/server/<serverID>/runtime/<account_or_group>/<id>
;/server/<serverID>/runtime/default/<id>.<project>;
/server/<serverID>/runtime/default/<id>;
/server/<serverID>/runtime
node exists, these are checked (it is the
global default area for all servers):/server/default/runtime/<account_or_group>/<id>.<project>;
/server/default/runtime/<account_or_group>/<id>
/server/default/runtime/default/<id>.<project>;
/server/default/runtime/default/<id>
.null
will always be safely
returned.
If the scope
is set to Utils.DirScope.BOTH
, first a per-account search will be
performed. If the value is not found, it fallbacks to a per-server search.directoryService
- A bound directory service instance. If this is null
then the instance
will be dynamically queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations in which only a single
value is needed. This has negative performance implications in the case where
multiple values are sequentially obtained.nodeId
- ID of node to obtain. This will be appended to the various paths listed above
(and in the precedence order specified above).expected
- Expected class of node or null
. If given, this will be checked with that
found in the directory for consistency.helper
- The data type-specific helper to query the given node.scope
- Search mode for the directory node lookup.accountIds
- Explicit list of account IDs which should be included in the search. When
null
, the current context's account IDs are resolved and used.null
if for ANY reason the directory backed value
cannot be obtained.public static <T> T doWithBoundDS(DirectoryService ds, boolean _throw, java.util.function.Function<DirectoryService,T> code)
code
with a bound Directory service.ds
- If null
, the method will query the service itself and bind it. If an instance is
supplied, the method will bind it unless already bound._throw
- otherwise the method returns null
.
When true
RuntimeException is thrown when directory service can't be resolved,code
- The function to execute. The bound Directory service is passed in.code
.public static PathResolver getPathResolver(java.lang.String fileSeparator, boolean caseSensitive, java.util.Map<java.lang.String,java.lang.String> pathMap)
fileSeparator
- The given legacy file separatorcaseSensitive
- The given case sensitive modepathMap
- The given map of the legacy file system to the host file systempublic static PathResolverContainer getSafePathResolver(java.lang.String fileSeparator, boolean caseSensitive, java.util.Map<java.lang.String,java.lang.String> pathMap)
fileSeparator
- The given legacy file separatorcaseSensitive
- The given case sensitive modepathMap
- The given map of the legacy file system to the host file systempublic static java.lang.String getOrCreateDefaultFwdTemporaryDirectory()
public static java.lang.String getOrCreateTemporaryDirectory(java.lang.String folderName)
folderName
- The name of the folder to be created in the temporary directory.public static boolean removeDirectoryNode(DirectoryService ds, java.lang.String nodeId)
ds
- A bound directory service instance with an editing batch opennodeId
- ID of node to removetrue
if removed the node successfullypublic static java.lang.String getExt(java.lang.String fileName)
fileName
- file namepublic static java.lang.String mimeType(java.lang.String fileName)
fileName
- file namepublic static int getPortForService(DirectoryService ds, java.lang.String name)
getservbyname()
API.
It is partial because it only will return a valid port number for services explicitly mapped in the directory. The current implementation knows nothing of the mappings provided in the standard services file. Thus, it should be used only for custom services mapped to ports in the directory.
The following directory paths are checked for mappings in the following precedence order:
/server/<server_id>/port_services/<service>
/server/default/port_services/<service>
where:
<server_id>
is the unique identifier of the
current P2J server instance; and<service>
is the service name given by the
name
parameter to this method.ds
- A bound directory service instance. If this is
null
then the instance will be dynamically
queried and bound for the duration of the method and then
unbound at the end. This is a convenience for situations
in which only a single value is needed. This has negative
performance implications in the case where multiple values
are sequentially obtained.name
- Service name to look up.public static void noHelp()
public static java.lang.String getUnqualifiedName(java.lang.Class<?> cls)
cls
- Class.public static <T,S> T tryWhileNull(java.util.List<S> list, java.util.function.Function<S,T> fn)
null
list
- the list to be traversedfn
- Function to be appliednull
if none foundprivate static void matchPathCaseInsensitively(java.io.File leading, java.lang.String fullPath, java.util.List<java.io.File> list)
fullPath
, where the directory specified by
leading
represents a leading portion of the given path.
This method calls itself recursively with progressively more specific
leading
directories, until leading
represents
the full path qualifier for the file which is the target of the match.
All paths in this method are processed using the current system's file separator character. This means that any input to this method must have already been properly converted to the system file separator.
leading
- A leading portion of the directory qualifier for the
fullPath
argument. The top-level call to this
method would pass null
here. Recursive calls will
pass a value. If given, this MUST be a valid directory in the
file system AND it must be a valid prefix for the target file
(it must case-insensitively match the begining of the target
filename).fullPath
- A canonicalized path name which represents an absolute path of
the file to be matched. Must NOT be null
.list
- A list in which to store matching File
objects
(which is the result of this processing). Must NOT be
null
.private static java.lang.Object executeLookup(DirectoryService ds, java.lang.String root, java.lang.String postfix, java.lang.String nodeId, java.lang.String expected, Utils.DirectoryHelper helper)
root + "/" + postfix + "/" + nodeId
ds
- A bound directory service instance. Must not be
null
.root
- First part of the path to build.postfix
- Second part of the path to build or null
.nodeId
- ID of node to obtain. This will be appended to the two
paths listed above.expected
- Expected class of node or null
. If given, this
will be checked with that found in the directory for
consistency.helper
- The data type-specific helper to query the given node.null
if for ANY
reason the directory backed value cannot be obtained.public static <T> boolean equals(T obj1, T obj2)
null
objects
without fear of NPE. If both provided objects are null
then
they are assumed equal.T
- Type parameter.obj1
- First object for comparison.obj2
- Second object for comparison.true
if objects are equal.public static int uniqueId()
public static void setProjectToken(java.lang.String token)
token
- the token that identifies the project.java.lang.IllegalArgumentException
- if the project was already set for current context.public static java.lang.String getProjectToken()
null
is returned.null
if not previously set.public static <T> boolean isSame(java.util.Set<T> a, java.util.Set<T> b)
null
instances are allowed for
either set.a
- The first set.b
- The second set.true
if the sets match.public static boolean isValidValue(int value, int... validValues)
value
- Value to check.validValues
- List of valid values.true
if value is in the list of valid values,
otherwise false
.public static boolean isServer()
true
if we are running on the server.public static boolean isClient()
true
if we are running on the client.public static boolean isChUI()
true
if we are running ChUI.public static boolean isGUI()
true
if we are running GUI.public static <T> boolean intersect(java.util.Set<T> a, java.util.Set<T> b)
T
- a
- a setb
- another settrue
if there are common elementspublic static boolean intersect(org.roaringbitmap.RoaringBitmap a, org.roaringbitmap.RoaringBitmap b)
a
- a setb
- another settrue
if there are common elementspublic static boolean intersect(org.roaringbitmap.longlong.Roaring64Bitmap a, org.roaringbitmap.longlong.Roaring64Bitmap b)
a
- a setb
- another settrue
if there are common elementspublic static boolean containsAll(org.roaringbitmap.RoaringBitmap instance, org.roaringbitmap.RoaringBitmap other)
instance
- The first instance.other
- The other instance.true
if the difference between the 'other' and 'instance' is empty.public static boolean containsAll(org.roaringbitmap.longlong.Roaring64Bitmap instance, org.roaringbitmap.longlong.Roaring64Bitmap other)
instance
- The first instance.other
- The other instance.true
if the difference between the 'other' and 'instance' is empty.public static <T> void split(java.util.Set<T> a, java.util.Set<T> b, java.util.Set<T> inter, java.util.Set<T> diff)
T
- The type of the set elements.a
- a setb
- another setinter
- The result set which will contain the intersection results.diff
- The result set which will contain the difference results. This is the set of items in "a"
which are not in "b", but it does not include items in "b" which are not in "a".public static <T> void intersection(java.util.Set<T> a, java.util.Set<T> b, java.util.Set<T> result)
T
- a
- a setb
- another setresult
- result setpublic static <T> void difference(java.util.Set<T> a, java.util.Set<T> b, java.util.Set<T> result)
T
- The element type.a
- The first set.b
- The set to subtract from 'a'.result
- The result set which will contain the difference results. This is the set of items in "a"
which are not in "b", but it does not include items in "b" which are not in "a".public static java.lang.String getRefinedPathName(java.lang.String nameDirty, java.lang.String separator)
nameDirty
- The not yet refined resource path string.separator
- The string representing file separator to use in result.public static Utils.JarResource searchResourceJars(java.lang.String filename, java.util.function.Function<JarClassLoader,java.util.function.Function<java.lang.String,java.lang.String>> searchFn, java.util.function.Function<JarClassLoader,java.util.function.Function<java.lang.String,java.lang.String>> propathSearchFn, java.util.function.Supplier<java.util.List<java.lang.String>> propathSupplier)
The algorithm first attempts to find an exact match for the filename. If not found, it applies the PROPATH to the filename, first prepending the package root to the name.
filename
- Filename of the resource, optionally including a path.searchFn
- The search function for the resource with the given filenamepropathSearchFn
- The propath search function for the resource with the given filename found in PROPATHpropathSupplier
- The propath supplier that list PROPATH entries.JarResult
object, if the search succeeds, else null
.public static java.lang.String getJarPath(java.lang.Class clazz)
clazz
- The given classpublic static int[] diffIntArrays(int[] a, int[] b)
a
- The first array.b
- The second array which is to be subtracted from the first.public static <T> java.util.stream.Stream<T> reverseStream(T[] array)
array
.array
- The array to be reversed in a stream.public static <T> java.util.stream.Stream<T> reverseStream(java.util.LinkedList<T> list)
list
- The linked list to be reversed in a stream.public static <T> java.util.stream.Stream<T> reverseStream(java.util.List<T> list)
list
.list
- The list to be reversed in a stream.@SafeVarargs public static <T> T nonNull(T... args)
args
- An array of arguments.java.lang.IllegalArgumentException
- when zero arguments is passed to the method.java.lang.NullPointerException
- when no non-null value is found in the supplied array of arguments.@SafeVarargs public static java.lang.String nonEmpty(java.lang.Object... args)
args
- An array of arguments.java.lang.IllegalArgumentException
- when zero arguments is passed to the method or no non-empty string is
represented by any of the supplied arguments.public static <W> java.util.Collection<W> normalizeZOrder(java.util.Collection<W> widgets, java.util.function.Function<W,ZOrderClass> zorder)
widgets
- The widget collectionzorder
- The given z-order function defined on widgetspublic static <W> boolean moveToBottomInClass(java.util.List<W> widgets, W widget, java.util.function.Function<W,ZOrderClass> zorder)
W
- widgets
- The given widgets list.widget
- The given widget to move.zorder
- function to get ZOrderClass for the widgetpublic static <W> boolean moveToTopInClass(java.util.List<W> widgets, W widget, java.util.function.Function<W,ZOrderClass> zorder)
W
- widgets
- The given widgets list.widget
- The given widget to move.zorder
- function to get ZOrderClass for the widgetpublic static <T> void removeAllIf(java.util.Collection<T> c, java.util.function.Predicate<T> p)
c
- the collectionp
- the conditionpublic static int getSizeLimitFromString(java.lang.String sizeStr)
sizeStr
- An string representing the integer limit value.public static byte[] longToBytesLE(long l)
l
- A long number.public static long bytesToLongLE(byte[] data)
data
- Bytes to convert.public static java.lang.reflect.Field findFieldWithValue(java.lang.Object instance, java.lang.Class<?> cls, java.lang.Object val)
instance
- The instance where to look for the field.cls
- The field is defined in this class or one of its super-classes.val
- The field must have this exact value, to be found.null
if no field is holding the expected value.public static void collectInterfaces(java.lang.Class<?> cls, java.util.Set<java.lang.Class<?>> interfaces)
cls
- The class from where to get the interfaces.interfaces
- A set where to store the interfaces.public static void dfsClassHierarchy(java.lang.Class<?> cls, java.util.function.Consumer<java.lang.Class<?>> task)
cls
- The class to start the walk.task
- The task to execute.public static java.util.List<java.lang.String> readCSVLine(java.io.Reader r) throws java.io.IOException
r
- Reader to read from.null
if end of stream is reached.java.io.IOException
public static void disableClientSSLCertificateValidation()
All connections initiated with HttpsURLConnection will be made without certificate validations! Do not use on production systems!