org.intermine.api.util
Class NameUtil

java.lang.Object
  extended by org.intermine.api.util.NameUtil

public final class NameUtil
extends java.lang.Object

Utility methods for naming queries and lists.


Method Summary
static java.lang.String findNewQueryName(java.util.Set<java.lang.String> savedQueries)
          Return a query name that isn't currently in use.
static java.lang.String findNewQueryName(java.util.Set<java.lang.String> savedQueries, java.lang.String name)
          Return a query name that isn't currently in use, returning the given name if it is available.
static java.lang.String generateNewName(java.util.Set<java.lang.String> listNames, java.lang.String listName)
          Generate a new name for a list.
static boolean isValidName(java.lang.String name)
          Verifies names (bags, queries, etc) only contain A-Z, a-z, 0-9, underscores and dashes.
static boolean isValidName(java.lang.String name, boolean specialChars)
          Verifies names (bags, queries, etc) only contain A-Z, a-z, 0-9, underscores and dashes.
static java.lang.String validateName(java.util.Collection<java.lang.String> names, java.lang.String name)
          Checks that the name doesn't already exist and returns a numbered name if it does.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isValidName

public static boolean isValidName(java.lang.String name)
Verifies names (bags, queries, etc) only contain A-Z, a-z, 0-9, underscores and dashes. And spaces. And dots.

Parameters:
name - Name of bag/query/template to be validated
Returns:
isValid Returns true if this name is correct, false if this name contains a bad char

isValidName

public static boolean isValidName(java.lang.String name,
                                  boolean specialChars)
Verifies names (bags, queries, etc) only contain A-Z, a-z, 0-9, underscores and dashes. if specialChars boolean is TRUE, then dot and space are allowed. If specialChars is FALSE, it likely means the name is going to be handled by javascript, in URLS, etc and we don't want to have to encode it. eg. template name.

Parameters:
name - Name of bag/query/template to be validated
specialChars - if true, then special characters DOT and SPACE are allowed in name
Returns:
isValid Returns true if this name is correct, false if this name contains a bad char

generateNewName

public static java.lang.String generateNewName(java.util.Set<java.lang.String> listNames,
                                               java.lang.String listName)
Generate a new name for a list. Used in situations where the user has a new list without creating one via the upload form, eg. when copying or posting a list from another site

Parameters:
listName - original name for the list
listNames - a list of all lists
Returns:
a unique name for the list

validateName

public static java.lang.String validateName(java.util.Collection<java.lang.String> names,
                                            java.lang.String name)
Checks that the name doesn't already exist and returns a numbered name if it does. Used in situations where prompting the user for a good name wouldn't work, eg. query import

Parameters:
name - the query or list name
names - list of current names
Returns:
a validated name for the query

findNewQueryName

public static java.lang.String findNewQueryName(java.util.Set<java.lang.String> savedQueries)
Return a query name that isn't currently in use.

Parameters:
savedQueries - the Map of current saved queries
Returns:
the new query name

findNewQueryName

public static java.lang.String findNewQueryName(java.util.Set<java.lang.String> savedQueries,
                                                java.lang.String name)
Return a query name that isn't currently in use, returning the given name if it is available.

Parameters:
savedQueries - the Map of current saved queries
name - name to return if it's available
Returns:
the new query name