Package com.github.javaparser.utils
Class Utils
- java.lang.Object
-
- com.github.javaparser.utils.Utils
-
public class Utils extends Object
Any kind of utility.- Author:
- Federico Tomassetti
-
-
Field Summary
Fields Modifier and Type Field Description static String
EOL
Deprecated.New code should useLineSeparator.SYSTEM
if referring to the current host system's line separator, elseLineSeparator.CR
orLineSeparator.LF
orLineSeparator.CRLF
if referring to a specific style of line separator.static String
SYSTEM_EOL
Deprecated.Renamed fromEOL
to make it explicit that we're using the system's line separator.
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static String
assertNonEmpty(String string)
static <T extends Number>
TassertNonNegative(T number)
static <T> T
assertNotNull(T o)
static <T extends Number>
TassertPositive(T number)
static String
camelCaseToScreaming(String input)
static String
capitalize(String s)
Capitalizes the first character in the string.static String
decapitalize(String s)
Lower-cases the first character in the string.static String
escapeEndOfLines(String string)
static boolean
hasUnaryMinusAsParent(Node n)
Checks, if the parent is a unary expression with a minus operator.static StringBuilder
indent(StringBuilder builder, int indentLevel)
Make an indent by appending indentLevel tab characters to the builder.static <E> int
indexOfElementByObjectIdentity(List<E> list, E o)
LikeList.indexOf(Object)
, but using ==, not equals.static <E> boolean
isNullOrEmpty(Collection<E> collection)
static String
nextWord(String string)
Return the next word of the string, in other words it stops when a space is encountered.static String
normalizeEolInTextBlock(String content, LineSeparator desiredEndOfLineCharacter)
static String
normalizeEolInTextBlock(String content, String desiredEndOfLineCharacter)
static String
readerToString(Reader reader)
static <E> void
removeElementByObjectIdentity(List<E> list, E o)
LikeList.remove(Object)
, but using ==, not equals.static String
removeFileExtension(String filename)
static <E> void
replaceElementByObjectIdentity(List<E> list, E oldObject, E newObject)
LikeList.set(int, Object)
atList.indexOf(Object)
, but using ==, not equals.static String
screamingToCamelCase(String original)
Transform a string to the camel case conversion.static <T> Set<T>
set(T... items)
static String
toCamelCase(String original)
Deprecated.use screamingToCamelCasestatic String
trimTrailingSpaces(String line)
LikeString.trim()
, but only the trailing spaces.static boolean
valueIsNullOrEmpty(Object value)
static boolean
valueIsNullOrEmptyStringOrOptional(Object value)
-
-
-
Field Detail
-
EOL
@Deprecated public static final String EOL
Deprecated.New code should useLineSeparator.SYSTEM
if referring to the current host system's line separator, elseLineSeparator.CR
orLineSeparator.LF
orLineSeparator.CRLF
if referring to a specific style of line separator.// TODO: Replace this within the internal codebase.
-
SYSTEM_EOL
@Deprecated public static final String SYSTEM_EOL
Deprecated.Renamed fromEOL
to make it explicit that we're using the system's line separator. New code should useLineSeparator.SYSTEM
if referring to the current host system's line separator, elseLineSeparator.CR
orLineSeparator.LF
orLineSeparator.CRLF
if referring to a specific style of line separator.
-
-
Method Detail
-
isNullOrEmpty
public static <E> boolean isNullOrEmpty(Collection<E> collection)
-
assertNotNull
public static <T> T assertNotNull(T o)
-
assertNonNegative
public static <T extends Number> T assertNonNegative(T number)
-
assertPositive
public static <T extends Number> T assertPositive(T number)
-
escapeEndOfLines
public static String escapeEndOfLines(String string)
- Returns:
- string with ASCII characters 10 and 13 replaced by the text "\n" and "\r".
-
readerToString
public static String readerToString(Reader reader) throws IOException
- Throws:
IOException
-
toCamelCase
@Deprecated public static String toCamelCase(String original)
Deprecated.use screamingToCamelCase
-
screamingToCamelCase
public static String screamingToCamelCase(String original)
Transform a string to the camel case conversion.For example "ABC_DEF" becomes "abcDef"
-
camelCaseToScreaming
public static String camelCaseToScreaming(String input)
- Parameters:
input
- "aCamelCaseString"- Returns:
- "A_CAMEL_CASE_STRING"
-
nextWord
public static String nextWord(String string)
Return the next word of the string, in other words it stops when a space is encountered.
-
indent
public static StringBuilder indent(StringBuilder builder, int indentLevel)
Make an indent by appending indentLevel tab characters to the builder.
-
capitalize
public static String capitalize(String s)
Capitalizes the first character in the string.
-
decapitalize
public static String decapitalize(String s)
Lower-cases the first character in the string.
-
valueIsNullOrEmpty
public static boolean valueIsNullOrEmpty(Object value)
- Returns:
- true if the value is null, an empty Optional, or an empty String.
-
valueIsNullOrEmptyStringOrOptional
public static boolean valueIsNullOrEmptyStringOrOptional(Object value)
-
replaceElementByObjectIdentity
public static <E> void replaceElementByObjectIdentity(List<E> list, E oldObject, E newObject)
LikeList.set(int, Object)
atList.indexOf(Object)
, but using ==, not equals.
-
removeElementByObjectIdentity
public static <E> void removeElementByObjectIdentity(List<E> list, E o)
LikeList.remove(Object)
, but using ==, not equals.
-
indexOfElementByObjectIdentity
public static <E> int indexOfElementByObjectIdentity(List<E> list, E o)
LikeList.indexOf(Object)
, but using ==, not equals.
-
set
@SafeVarargs public static <T> Set<T> set(T... items)
- Returns:
- a set of the items.
-
normalizeEolInTextBlock
public static String normalizeEolInTextBlock(String content, String desiredEndOfLineCharacter)
- Returns:
- content, with all kinds of EOL characters replaced by desiredEndOfLineCharacter
-
normalizeEolInTextBlock
public static String normalizeEolInTextBlock(String content, LineSeparator desiredEndOfLineCharacter)
- Returns:
- content, with all kinds of EOL characters replaced by desiredEndOfLineCharacter
-
removeFileExtension
public static String removeFileExtension(String filename)
- Returns:
- the filename with the last "." and everything following it removed.
-
trimTrailingSpaces
public static String trimTrailingSpaces(String line)
LikeString.trim()
, but only the trailing spaces.
-
hasUnaryMinusAsParent
public static boolean hasUnaryMinusAsParent(Node n)
Checks, if the parent is a unary expression with a minus operator. Used to check for negative literals.
-
-