/*
* Svjatoslav Commons - shared library of common functionality.
* Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 3 of the GNU Lesser General Public License
* or later as published by the Free Software Foundation.
/**
* Ask boolean value from user on command-line.
+ *
+ * @param prompt
+ * to show to the user
+ * @return <code>true</code> is user answered affirmative.
*/
public static boolean askBoolean(final String prompt) {
/**
* Ask numerical long value from user on command-line.
+ *
+ * @param prompt
+ * to show to the user
+ * @return value given by user
*/
public static long askLong(final String prompt) {
/**
* Ask string value from user on command-line.
+ *
+ * @param prompt
+ * to show to the user
+ * @return value given by the user
*/
public static String askString(final String prompt) {
this.argumentCount = argumentCount;
}
+ @SuppressWarnings("unchecked")
public T addAliases(final String... aliasArray) {
// save aliases
}
/**
+ * @param argumentString
+ * argument to add
* @return <code>true</code> if no errors were found. <code>false</code>
* otherwise.
*/
}
/**
+ * @param alias
+ * alias to check against
* @return <code>true</code> if given alias is registered for this
* parameter.
*/
return true;
}
+ @SuppressWarnings("unchecked")
public T setMandatory() {
mandatory = true;
return (T) this;
}
/**
+ * @param value
+ * value to validate
* @return <code>true</code> if value is correct, <code>false</code>
* otherwise.
*/
*/
public class Parser {
- private final ArrayList<Parameter> parameters = new ArrayList<Parameter>();
+ private final ArrayList<Parameter<?>> parameters = new ArrayList<Parameter<?>>();
- public <E extends Parameter> E add(final E parameter) {
+ public <E extends Parameter<?>> E add(final E parameter) {
parameters.add(parameter);
return parameter;
}
*/
private boolean checkMandatoryArgumentsPresent() {
- for (final Parameter parameter : parameters)
+ for (final Parameter<?> parameter : parameters)
if (parameter.isMandatory() && (!parameter.isParameterSpecified())) {
System.out.println("Error! Mandatory parameter ("
+ parameter.getAliases() + ") is not specified.");
/**
* Return parameter by given alias or <code>null</code> if no parameter
* exists for given alias.
+ *
+ * @param alias
+ * parameter alias
+ * @return found parameter or <code>null</code> if parameter was not found.
*/
- public Parameter findParameterByAlias(final String alias) {
+ public Parameter<?> findParameterByAlias(final String alias) {
- for (final Parameter parameter : parameters)
+ for (final Parameter<?> parameter : parameters)
if (parameter.matchesAlias(alias))
return parameter;
}
/**
+ * @param args
+ * commandline arguments
* @return <code>true</code> if no errors were found. <code>false</code>
* otherwise.
*/
public boolean parse(final String[] args) {
- Parameter currentParameter = null;
+ Parameter<?> currentParameter = null;
for (final String argument : args) {
- final Parameter parameterForAlias = findParameterByAlias(argument);
+ final Parameter<?> parameterForAlias = findParameterByAlias(argument);
if (parameterForAlias == null) {
if (currentParameter == null) {
System.out.println("Unknown commandline parameter: "
}
public void showHelp() {
- for (final Parameter parameter : parameters)
+ for (final Parameter<?> parameter : parameters)
System.out.println(parameter.getHelp());
}
/*
* Svjatoslav Commons - shared library of common functionality.
* Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 3 of the GNU Lesser General Public License
* or later as published by the Free Software Foundation.
/**
* This method tries to guess user desktop directory. Implementation is
* pretty lousy. Need to improve it some day.
+ *
+ * @return file that points to user desktop directory.
+ * @throws RuntimeException
+ * if user desktop directory is not found.
*/
public static File getDesktopDirectory() {
/**
* Deletes files and directories recursively. WARNING!!! Follows symlinks!!!
+ *
+ * @param file
+ * directory to delete with entire contents.
+ *
+ * @throws IOException
+ * if filesystem error happens
*/
public static void deleteRecursively(final File file) throws IOException {
if (file.isDirectory()) {
* then leaves file as-is. If content differs, then overrides file with the
* new content.
*
+ * @param file
+ * file to potentially overwrite
+ * @param newContent
+ * new content
* @return <code>true</code> if file was overwritten.
+ *
+ * @throws FileNotFoundException
+ * if file is not found.
+ * @throws IOException
+ * if error happens during file IO.
*/
public static boolean overwriteFileIfContentDiffers(final File file,
final byte[] newContent) throws FileNotFoundException, IOException {
/*
* Svjatoslav Commons - shared library of common functionality.
* Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 3 of the GNU Lesser General Public License
* or later as published by the Free Software Foundation.
/**
* This method is for testing
+ *
+ * @param args
+ * commandline arguments
*/
public static void main(final String[] args) {
try {
final String requestPath = new URL(requestUrl).getPath();
+ @SuppressWarnings("unchecked")
final NI match = (NI) rootNavigationItem
.getMatchingNavigationItem(requestPath);
return getDefaultNavigationItem();
}
+ @SuppressWarnings("unchecked")
public String getTopMenu(final HttpServletRequest request) {
final String currentLocale = localeConfiguration
/*
* Svjatoslav Commons - shared library of common functionality.
* Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 3 of the GNU Lesser General Public License
* or later as published by the Free Software Foundation.
}
/**
- * Cut given amount of characters from the left of the string. Return cutted
- * part.
+ * Cut given amount of characters from the left of the string.
+ *
+ * @param cutAmount
+ * of characters to cut
+ * @return cutted part.
*/
public String cutLeft(final int cutAmount) {
/*
* Svjatoslav Commons - shared library of common functionality.
* Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 3 of the GNU Lesser General Public License
* or later as published by the Free Software Foundation.
* * -- corresponds to any amount of characters.
* ? -- corresponds to any single character.
* </pre>
+ *
+ * @param inputString
+ * input string
+ * @param wildcardExpression
+ * wildcard expression
+ * @return <code>true</code> if input string matches input pattern
*/
-
public static boolean match(final String inputString,
final String wildcardExpression) {