code
stringlengths 25
201k
| docstring
stringlengths 19
96.2k
| func_name
stringlengths 0
235
| language
stringclasses 1
value | repo
stringlengths 8
51
| path
stringlengths 11
314
| url
stringlengths 62
377
| license
stringclasses 7
values |
|---|---|---|---|---|---|---|---|
public static String MIMETypeForFileExtension (String extension, // NOPMD
String defaultMIMEType)
{
return MIMETypeForFileName ("test." + extension, defaultMIMEType);
}
|
Get the MIME type for a filename extension.
@param extension the extension, without the "."
@param defaultMIMEType the default MIME type to use if one cannot
be determined from the extension, or null to
use {@link #DEFAULT_MIME_TYPE}
@return the MIME type, or the default MIME type
@see #MIMETypeForFileExtension(String)
@see #MIMETypeForFile(File)
@see #MIMETypeForFile(File,String)
@see #MIMETypeForFileName(String)
@see #MIMETypeForFileName(String,String)
|
MIMETypeForFileExtension
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MIMETypeUtil.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MIMETypeUtil.java
|
MIT
|
public static String MIMETypeForFile (File file) // NOPMD
{
return MIMETypeForFileName (file.getName(), DEFAULT_MIME_TYPE);
}
|
Get the MIME type for a file. This method is simply a convenient
front-end for <tt>java.net.FileNameMap.getContentTypeFor()</tt>,
but it applies a consistent default when <tt>getContentTypeFor()</tt>
returns null (which can happen).
@param file the file
@return the MIME type to use
@see #MIMETypeForFile(File,String)
@see #MIMETypeForFileName(String)
@see #MIMETypeForFileExtension(String)
@see #MIMETypeForFileExtension(String,String)
@see #DEFAULT_MIME_TYPE
|
MIMETypeForFile
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MIMETypeUtil.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MIMETypeUtil.java
|
MIT
|
public static String MIMETypeForFile (File file, // NOPMD
String defaultMIMEType)
{
return MIMETypeForFileName (file.getName(), defaultMIMEType);
}
|
Get the MIME type for a file. This method is simply a convenient
front-end for <tt>java.net.FileNameMap.getContentTypeFor()</tt>,
but it applies the supplied default when <tt>getContentTypeFor()</tt>
returns null (which can happen).
@param file the file
@param defaultMIMEType the default MIME type to use if one cannot
be determined from the file's name, or null to
use {@link #DEFAULT_MIME_TYPE}
@return the MIME type to use
@see #MIMETypeForFile(File)
@see #MIMETypeForFileName(String,String)
@see #MIMETypeForFileExtension(String)
@see #MIMETypeForFileExtension(String,String)
@see #DEFAULT_MIME_TYPE
|
MIMETypeForFile
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MIMETypeUtil.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MIMETypeUtil.java
|
MIT
|
public static String MIMETypeForFileName (String fileName) // NOPMD
{
return MIMETypeForFileName (fileName, DEFAULT_MIME_TYPE);
}
|
Get the MIME type for a name file. This method is simply a convenient
front-end for <tt>java.net.FileNameMap.getContentTypeFor()</tt>,
but it applies a consistent default when <tt>getContentTypeFor()</tt>
returns null (which can happen).
@param fileName the file name
@return the MIME type to use
@see #MIMETypeForFile(File)
@see #MIMETypeForFileName(String,String)
@see #DEFAULT_MIME_TYPE
|
MIMETypeForFileName
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MIMETypeUtil.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MIMETypeUtil.java
|
MIT
|
public static String MIMETypeForFileName (String fileName, // NOPMD
String defaultMIMEType)
{
String mimeType = null;
FileNameMap fileNameMap = URLConnection.getFileNameMap();
// Check ours first.
loadMappings();
String extension = FileUtil.getFileNameExtension (fileName);
mimeType = (String) extensionToMIMETypeMap.get (extension);
if (mimeType == null)
{
// Check the system one.
mimeType = fileNameMap.getContentTypeFor (fileName);
}
if (mimeType != null)
{
if (mimeType.equals (DEFAULT_MIME_TYPE) &&
(defaultMIMEType != null))
{
// Substitute the caller's default, if there is one, on the
// assumption that it'll be more useful.
mimeType = defaultMIMEType;
}
}
else
{
mimeType = (defaultMIMEType == null) ? DEFAULT_MIME_TYPE
: defaultMIMEType;
}
return mimeType;
}
|
Get the MIME type for a file name. This method is simply a convenient
front-end for <tt>java.net.FileNameMap.getContentTypeFor()</tt>,
but it applies the supplied default when <tt>getContentTypeFor()</tt>
returns null (which can happen).
@param fileName the file name
@param defaultMIMEType the default MIME type to use if one cannot
be determined from the file name, or null to
use {@link #DEFAULT_MIME_TYPE}
@return the MIME type to use
@see #MIMETypeForFile(File,String)
@see #MIMETypeForFileName(String)
@see #MIMETypeForFileExtension(String)
@see #MIMETypeForFileExtension(String,String)
@see #DEFAULT_MIME_TYPE
|
MIMETypeForFileName
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MIMETypeUtil.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MIMETypeUtil.java
|
MIT
|
public static void parseContentTypeHeader (String contentTypeHeader,
StringBuffer mimeType,
Map<String, String> parameters)
{
// ContentType header is required, and either the MIME type or the
// parameters (or both) must be set. Otherwise, we do nothing.
if ( ((mimeType != null) || (parameters != null))
&&
(! TextUtil.stringIsEmpty (contentTypeHeader)) )
{
if (mimeType == null)
mimeType = new StringBuffer();
if (parameters == null)
parameters = new HashMap<String, String>();
String[] tokens = TextUtil.split(contentTypeHeader, " ;");
mimeType.setLength(0);
mimeType.append(tokens[0]);
parameters.clear();
for (int i = 1; i < tokens.length; i++)
{
String[] nv = TextUtil.split(tokens[i], "=");
parameters.put(nv[0], (nv.length == 1) ? "" : nv[1]);
}
}
}
|
<p>This method parses an HTTP-style "<tt>Content-type</tt>" header into
its constituent pieces. The HTTP specification (RFC 2616) defines
the <tt>Content-type</tt> header as:</p>
<blockquote><pre>"Content-type" ":" <media-type></pre></blockquote>
<p>A <i>media-type</i> is a MIME type ("type/subtype"), with optional
name=value pair parameters. The parameters are separated from the
media type, and from each other, by ";" characters.</p>
<p>A common example of a <tt>Content-type</tt> header is:</p>
<blockquote><pre>Content-type: text/html; charset=ISO-8859-1</pre>
</blockquote>
<p>This method parses apart the MIME type and the parameters, saving
each one separately in caller-supplied objects.</p>
@param contentTypeHeader the header value (without the
<tt>Content-type:</tt> prefix). This value
is what's typically returned by
<tt>URLConnection.getContentType()</tt>.
@param mimeType a <tt>StringBuffer</tt> to receive the
MIME type, or null if you don't care about
the MIME type. This method clears the string
buffer before storing anything in it.
@param parameters a <tt>Map</tt> to receive the parameters,
or null if you don't care about the
parameters. The parameter names are used
as the map's keys. This method clears the
map before storing anything in it.
|
parseContentTypeHeader
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MIMETypeUtil.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MIMETypeUtil.java
|
MIT
|
private static synchronized void loadMappings()
{
if (mimeTypeToExtensionMap != null)
return;
mimeTypeToExtensionMap = new HashMap<String, String>();
extensionToMIMETypeMap = new HashMap<String, String>();
// First, check the user's home directory.
String fileSep = System.getProperty ("file.separator");
StringBuffer buf = new StringBuffer();
buf.append (System.getProperty ("user.home"));
buf.append (fileSep);
buf.append (".mime.types");
loadMIMETypesFile (buf.toString());
// Now, check every directory in the classpath.
String pathSep = System.getProperty ("path.separator");
String classPath = System.getProperty ("java.class.path");
String[] pathComponents = TextUtil.split (classPath, pathSep);
int i;
for (i = 0; i < pathComponents.length; i++)
{
buf.setLength (0);
buf.append (pathComponents[i]);
buf.append (fileSep);
buf.append ("mime.types");
loadMIMETypesFile (buf.toString());
}
// Finally, load the resource bundle.
ResourceBundle bundle = ResourceBundle.getBundle(MIME_MAPPINGS_BUNDLE);
for (Enumeration e = bundle.getKeys(); e.hasMoreElements(); )
{
String type = (String) e.nextElement();
try
{
String[] extensions = TextUtil.split (bundle.getString (type));
if (mimeTypeToExtensionMap.get (type) == null)
{
log.debug ("Internal: " + type + " -> \"" + extensions[0] +
"\"");
mimeTypeToExtensionMap.put (type, extensions[0]);
}
for (i = 0; i < extensions.length; i++)
{
if (extensionToMIMETypeMap.get (extensions[i]) == null)
{
log.debug ("Internal: " + "\"" + extensions[i] +
"\" -> " + type);
extensionToMIMETypeMap.put (extensions[i], type);
}
}
}
catch (MissingResourceException ex)
{
log.error ("While reading internal bundle \"" +
MIME_MAPPINGS_BUNDLE +
"\", got unexpected error on key \"" +
type + "\"",
ex);
}
}
}
|
Load the MIME type mappings into memory.
|
loadMappings
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MIMETypeUtil.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MIMETypeUtil.java
|
MIT
|
private static void loadMIMETypesFile (String path)
{
try
{
File f = new File (path);
log.debug ("Attempting to load MIME types file \"" + path + "\"");
if (! (f.exists() && f.isFile()))
log.debug ("Regular file \"" + path + "\" does not exist.");
else
{
LineNumberReader r = new LineNumberReader (new FileReader (f));
String line;
while ((line = r.readLine()) != null)
{
line = line.trim();
if ((line.length() == 0) || (line.startsWith ("#")))
continue;
String[] fields = TextUtil.split (line);
// Skip lines without at least two tokens.
if (fields.length < 2)
continue;
// Special case: Scan the extensions, and make sure we
// have at least one valid extension. Some .mime.types
// files have entries like this:
//
// mime/type desc="xxx" exts="jnlp"
//
// We don't handle those.
List<String> extensions = new ArrayList<String>();
for (int i = 1; i < fields.length; i++)
{
if (fields[i].indexOf ('=') != -1)
continue;
if (fields[i].indexOf ('"') != -1)
continue;
// Treat as valid. Remove any leading "."
if (fields[i].startsWith ("."))
{
if (fields[i].length() == 1)
continue;
fields[i] = fields[i].substring (1);
}
extensions.add (fields[i]);
}
if (extensions.size() == 0)
continue;
// If the MIME type doesn't have a "/", skip it
String mimeType = fields[0];
String extension;
if (mimeType.indexOf ('/') == -1)
continue;
// The first field is the preferred extension. Keep any
// existing mapping for the MIME type.
if (mimeTypeToExtensionMap.get (mimeType) == null)
{
extension = (String) extensions.get (0);
log.debug ("File \"" + path + "\": " + mimeType +
" -> \"" + extension + "\"");
mimeTypeToExtensionMap.put (mimeType, extension);
}
// Map the extensions back to the MIME type
for (Iterator it = extensions.iterator(); it.hasNext(); )
{
extension = (String) it.next();
if (extensionToMIMETypeMap.get (extension) == null)
{
log.debug ("File \"" + path + "\": \"" +
extension + "\" -> " + mimeType);
extensionToMIMETypeMap.put (extension, mimeType);
}
}
}
r.close();
}
}
catch (IOException ex)
{
log.debug ("Error reading \"" + path + "\"", ex);
}
}
|
Attempt to load a MIME types file. Throws no exceptions.
@param path path to the file
@param map map to load
|
loadMIMETypesFile
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MIMETypeUtil.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MIMETypeUtil.java
|
MIT
|
public void addCollection (Collection<T> collection)
{
aggregation.add (collection.iterator());
}
|
<p>Add a <tt>Collection</tt> to the end of the list of composite
objects being iterated over. It's safe to call this method while
iterating, as long as you haven't reached the end of the last
composite object currently in the iterator.</p>
<p><b>Note</b>: This method is simply shorthand for:</p>
<blockquote>
<pre>addIterator (collection.iterator());</pre>
</blockquote>
@param collection The <tt>Collection</tt> to add.
@see #addIterator
@see #addEnumeration
|
addCollection
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiIterator.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiIterator.java
|
MIT
|
public void addIterator (Iterator<T> iterator)
{
aggregation.add (iterator);
}
|
Add an <tt>Iterator</tt> to the end of the list of composite objects
being iterated over. It's safe to call this method while iterating,
as long as you haven't reached the end of the last composite object
currently in the iterator.
@param iterator The <tt>Iterator</tt> to add.
@see #addCollection
@see #addEnumeration
|
addIterator
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiIterator.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiIterator.java
|
MIT
|
public void addEnumeration (Enumeration<T> enumeration)
{
aggregation.add (new EnumerationIterator<T> (enumeration));
}
|
Add an <tt>Enumeration</tt> to the end of the list of composite
objects being iterated over. It's safe to call this method while
iterating, as long as you haven't reached the end of the last
composite object currently in the iterator.
<p><b>Note</b>: This method is simply shorthand for:</p>
<blockquote><pre>
{@code
addIterator (new EnumerationIterator<T> (enumeration));
}
</pre></blockquote>
@param enumeration The <tt>Enumeration</tt> to add.
@see #addCollection
@see #addIterator
@see EnumerationIterator
|
addEnumeration
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiIterator.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiIterator.java
|
MIT
|
public boolean hasNext()
{
boolean someLeft = false;
checkIterator();
if (it != null)
someLeft = it.hasNext();
return someLeft;
}
|
Determine whether the underlying <tt>Iterator</tt> has more
elements.
@return <tt>true</tt> if and only if a call to
<tt>nextElement()</tt> will return an element,
<tt>false</tt> otherwise.
@see #next
|
hasNext
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiIterator.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiIterator.java
|
MIT
|
public T next() throws NoSuchElementException
{
T result = null;
checkIterator();
if (it != null)
result = it.next();
return result;
}
|
Get the next element from the underlying array.
@return the next element from the underlying array
@throws NoSuchElementException No more elements exist
@see java.util.Iterator#next
|
next
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiIterator.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiIterator.java
|
MIT
|
public void clear()
{
map.clear();
}
|
Removes all mappings from this map.
|
clear
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
public Object clone() // NOPMD
throws CloneNotSupportedException
{
MultiValueMap<K,V> newMap = new MultiValueMap<K,V>();
makeShallowCopyInto (newMap);
return newMap;
}
|
Returns a shallow copy of this <tt>MultivalueMap</tt> instance.
The keys and values themselves are not cloned.
@throws CloneNotSupportedException never, but it's part of the signature
|
clone
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
public boolean containsValue(Object value)
{
boolean found = false;
Iterator<Collection<V>> it = map.values().iterator();
while ((! found) && it.hasNext())
{
Collection<V> values = it.next();
if (values.contains(value))
found = true;
}
return found;
}
|
Returns <tt>true</tt> if this map maps one or more keys to the
specified value. The values are compared via their
<tt>compareTo()</tt> and/or <tt>equals()</tt> methods, so this method
is only useful if the map contains values of the same type.
@param value value whose presence in this map is to be tested.
@return <tt>true</tt> if this map maps one or more keys to the
specified value, <tt>false</tt> otherwise.
|
containsValue
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
public boolean containsKeyValue(K key, V value)
{
boolean found = false;
Collection<V> values = getCollection(key);
if (values != null)
{
for (V possibleValue : values)
{
found = value.equals(possibleValue);
if (found)
break;
}
}
return found;
}
|
Returns <tt>true</tt> if this map contains the specified value for
the specified key. The values are compared via their
<tt>compareTo()</tt> and/or <tt>equals()</tt> methods.
@param key the key
@param value the value
@return <tt>true</tt> if the set of values for the specified key
contains the specified value
|
containsKeyValue
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
public boolean equals (Object o)
{
boolean eq = false;
if (o instanceof MultiValueMap)
eq = ((MultiValueMap) o).entrySet().equals(this.entrySet());
return eq;
}
|
<p>Compares the specified object with this map for equality. Returns
<tt>true</tt> if the given object is also a <tt>MultivalueMap</tt>
and the two maps represent the same mappings.
maps <tt>t1</tt> and <tt>t2</tt> represent the same mappings if
<tt>t1.entrySet().equals(t2.entrySet())</tt>. This ensures that the
<tt>equals</tt> method works properly across different
implementations of the <tt>Map</tt> interface.</p>
<p><b>Warning:</b>: Because this method must compare the actual
values stored in the map, and the values in a file, this method can
be quite slow.</p>
@param o object to be compared for equality with this map.
@return <tt>true</tt> if the specified object is equal to this map.
|
equals
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
public V get(Object key)
{
V result = null;
Collection<V> values = map.get(key);
if (values != null)
result = values.iterator().next();
return result;
}
|
Synonym for {@link #getFirstValueForKey}, required by the <tt>Map</tt>
interface.
@param key the key
@return the first value for the key, or null if not found
|
get
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
public int hashCode()
{
Set<Map.Entry<K,V>> entries = this.entrySet();
int result = 0;
for (Map.Entry<K,V> entry : entries)
result |= entry.hashCode();
return result;
}
|
<p>Returns the hash code value for this map. The hash code of a map
is defined to be the sum of the hash codes of each entry in the
map's <tt>entrySet()</tt> view. This ensures that
<tt>t1.equals(t2)</tt> implies that
<tt>t1.hashCode()==t2.hashCode()</tt> for any two maps <tt>t1</tt>
and <tt>t2</tt>, as required by the general contract of
Object.hashCode.</p>
@return the hash code value for this map.
@see #equals(Object)
|
hashCode
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
public boolean isEmpty()
{
return map.isEmpty();
}
|
Determine whether the map is empty.
@return <tt>true</tt> if this map contains no key-value mappings.
|
isEmpty
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
public Set<K> keySet()
{
return map.keySet();
}
|
Returns a <tt>Set</tt> containing all the keys in this map.
<p>The set is backed by the map, so changes to the map are reflected
in the set. If the map is modified while an iteration over the set
is in progress, the results of the iteration are undefined. Neither
the set nor its associated iterator supports any of the
set-modification methods (e.g., <tt>add()</tt>, <tt>remove()</tt>,
etc). If you attempt to call any of those methods, the called method
will throw an <tt>UnsupportedOperationException</tt>.</p>
@return a set view of the keys contained in this map.
@see #getValuesForKey
@see #values()
|
keySet
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
public void putAll(Map<? extends K,? extends V> fromMap)
{
for (K key : fromMap.keySet())
{
V value = fromMap.get(key);
if (value != null)
this.put(key, value);
}
}
|
<p>Copies all of the mappings from the specified <tt>Map</tt> to
this map. These mappings will be added to any mappings that this map
had for any of the keys currently in the specified map.</p>
@param fromMap Mappings to be stored in this map.
@throws ClassCastException if the class of a key or value in the
specified map prevents it from being
stored in this map.
@throws IllegalArgumentException some aspect of a key or value in the
specified map prevents it from being
stored in this map.
@throws NullPointerException the specified key or value is
<tt>null</tt>.
|
putAll
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
public void putAll (MultiValueMap<K,V> fromMap)
{
for (K key : fromMap.keySet())
{
Collection<V> values = fromMap.getCollection(key);
if (values != null)
{
for (V value : values)
this.put(key, value);
}
}
}
|
<p>Copies all of the mappings from the specified
<tt>MultivalueMap</tt> to this map. These mappings will be added to
any mappings that this map had for any of the keys currently in the
specified map.</p>
@param fromMap Mappings to be stored in this map.
@throws ClassCastException if the class of a key or value in the
specified map prevents it from being
stored in this map.
@throws IllegalArgumentException some aspect of a key or value in the
specified map prevents it from being
stored in this map.
@throws NullPointerException the specified key or value is
<tt>null</tt>.
|
putAll
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
public void putAll(K key, Collection<V> values)
{
for (V value : values)
put (key, value);
}
|
Assocates all the objects in a <tt>Collection</tt> with a key. This
method is equivalent to the following code fragment:
<blockquote><pre>
for (Iterator it = values.iterator(); it.hasNext(); )
map.put (key, it.next());
</pre></blockquote>
@param key the key
@param values the collection of values to associate with the key
|
putAll
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
public Collection<V> delete(K key)
{
return this.map.remove(key);
}
|
<p>Removes all mappings for a key from this map, if present.</p>
@param key key whose mappings are to be removed from the map.
@return <tt>Collection</tt> of values associated with specified key,
or <tt>null</tt> if there was no mapping for key.
|
delete
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
public boolean remove(Object key, Object value)
{
boolean removed = false;
synchronized (this)
{
Collection<V> values = map.get(key);
if (values != null)
{
removed = values.remove(value);
if (values.size() == 0)
map.remove(key);
}
}
return removed;
}
|
Removes a single value from the set of values associated with a
key.
@param key the key
@param value the value to find and remove
@return <tt>true</tt> if the value was found and removed.
<tt>false</tt> if the value isn't associated with the key.
|
remove
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
public int size()
{
int total = 0;
for (K key : keySet())
{
Collection<V> valuesForKey = map.get(key);
if (valuesForKey != null)
total += valuesForKey.size();
}
return total;
}
|
<p>Returns the number of key-value mappings in this map. If the map
contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
<tt>Integer.MAX_VALUE</tt>.</p>
@return the number of key-value mappings in this map.
|
size
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
public Collection<V> values()
{
Collection<V> result = new ArrayList<V>();
for (K key : keySet())
result.addAll(getCollection(key));
return result;
}
|
<p>Returns a collection view of the values contained in this map.
The returned collection is a "thin" view of the values contained in
this map. If a value is associated with more than one key (as
determined by the value's <tt>equals()</tt> method), it will only
appear once in the returned <tt>Collection</tt>. The values are
sorted (via their <tt>compareTo()</tt> methods) in the returned
<tt>Collection</tt>.</p>
<p>Warning: Unlike the SDK's <tt>Map</tt> class, the returned
<tt>Collection</tt> is <b>not</b> backed by this map; instead, it
represents a snapshot of the values in the map. Subsequent changes
to this map object are <b>not</b> reflected in the returned
<tt>Collection</tt>.</p>
@return a collection view of the values contained in this map.
@see #keySet
@see #getValuesForKey
|
values
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
private int keyValueHashCode (Object key, Object value)
{
// Put the string representations of the key and value together,
// with a delimiter that's unlikely to be in the string
// representation, and use that string's hash code. If the value
// is null, use an unlikely placeholder.
if (value == null)
value = "\u0002";
return (new String (key.toString() + "\u0001" + value.toString()))
.hashCode();
}
|
Calculate a combined hash code for a key/value pair.
@param key the key
@param value the value
@return the hash code
|
keyValueHashCode
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
private void makeShallowCopyInto (MultiValueMap<K,V> otherMap)
{
for (K key : map.keySet())
{
// Copy the collection, though, don't just pass a reference to
// the same one.
Collection<V> values = this.map.get(key);
Collection<V> newValues =
this.valuesCollectionAllocator.newValuesCollection();
newValues.addAll(values);
otherMap.map.put(key, newValues);
}
}
|
Create a shallow copy of this map into another, existing (presumably
empty) map.
@param otherMap the other map to receive the values
|
makeShallowCopyInto
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/MultiValueMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MultiValueMap.java
|
MIT
|
public String getMessage()
{
return getMessage(Locale.getDefault());
}
|
Returns the error message string for this exception. If the
exception was instantiated with a message of its own, then that
message is returned. Otherwise, this method returns the class name,
along with the class name of the first nested exception, if any.
Unlike the parent <tt>Exception</tt> class, this method will never
return null.
@return the error message string for this exception
|
getMessage
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/NestedException.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/NestedException.java
|
MIT
|
public String getMessage(Locale locale)
{
StringBuilder buf = new StringBuilder();
String msg = null;
if ((resourceBundleName != null) && (bundleMessageKey != null))
{
msg = BundleUtil.getMessage(resourceBundleName,
locale,
bundleMessageKey,
defaultMessage,
messageParams);
}
if (msg == null)
{
msg = defaultMessage;
if (msg == null)
msg = super.getMessage();
}
if (msg != null)
buf.append (msg);
else
{
Throwable containedException = getCause();
while ((containedException != null) && (msg == null))
{
if (containedException instanceof NestedException)
{
// It'll drill in itself.
msg = ((NestedException) containedException)
.getMessage(locale);
break;
}
else
{
msg = containedException.getMessage();
}
containedException = containedException.getCause();
}
if (msg != null)
buf.append (msg);
else
{
buf.append(this.getClass().getName());
if (containedException != null)
{
buf.append(" (contains ");
buf.append(containedException.getClass().getName());
buf.append(")");
}
}
}
return buf.toString();
}
|
Returns the error message string for this exception. If the
exception was instantiated with a message of its own, then that
message is returned. Otherwise, this method returns the class name,
along with the class name of the first nested exception, if any.
Unlike the parent <tt>Exception</tt> class, this method will never
return null. If a localized version of the message is available, it
will be returned.
@param locale the locale to use, or null for the default
@return the error message string for this exception
|
getMessage
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/NestedException.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/NestedException.java
|
MIT
|
public String getMessages()
{
return getMessages(false);
}
|
Get all the messages of all the nested exceptions, as one
string, with each message on a separate line. To run all the messages
together into one line, use {@link #getMessages(boolean)}, with a
parameter of <tt>true</tt>.
@return the aggregated messages
@see #getMessages(boolean)
|
getMessages
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/NestedException.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/NestedException.java
|
MIT
|
public String getMessages(boolean elideNewlines)
{
return getMessages(elideNewlines, null);
}
|
Get all the messages of all the nested exceptions, as one string. If
the <tt>elideNewlines</tt> parameter is <tt>true</tt>, then the
messages are joined so that there are no newlines in the resulting
string. Otherwise, (a) any existing newlines in the messages are
preserved, and (b) each nested message occupies its own line.
@param elideNewlines whether to elide newlines or not
@return the aggregated messages
|
getMessages
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/NestedException.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/NestedException.java
|
MIT
|
public String getMessages(boolean elideNewlines, Locale locale)
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Throwable ex = this;
StringBuffer buf = null;
if (locale == null)
locale = Locale.getDefault();
if (elideNewlines)
buf = new StringBuffer();
// It's possible for some of the messages to be identical, especially
// when a nested exception doesn't have a message of its own.
// (Calling getMessage() in that case gets the message of the first
// nested exception that actually has a message.) To avoid
// repetition, weed out the ones that are dups. Use a LinkedHashSet
// to maintain order.
Set<String> messages = new LinkedHashSet<String>();
while (ex != null)
{
String s;
if (ex instanceof NestedException)
s = ((NestedException) ex).getMessage(locale);
else
s = ex.getMessage();
if (s == null)
s = ex.toString();
if (elideNewlines)
{
// Must remove any newlines in this message,
try
{
LineNumberReader r =
new LineNumberReader(new StringReader(s));
String line;
String sep = "";
buf.setLength (0);
while ((line = r.readLine()) != null)
{
buf.append(sep);
buf.append(line);
sep = " ";
}
s = buf.toString();
}
catch (IOException ioEx)
{
// Shouldn't happen. If it does, just use the original
// string.
}
}
if (! messages.contains(s))
messages.add(s);
ex = ex.getCause();
}
// Now, add the accumulated messages to the buffer.
// Note: Last exception message dumped should not have a newline.
String sep = "";
for (String message : messages)
{
if (elideNewlines)
{
pw.print(sep);
pw.print(message);
sep = ": ";
}
else
{
pw.println(message);
}
}
return sw.getBuffer().toString();
}
|
Get all the messages of all the nested exceptions, as one string. If
the <tt>elideNewlines</tt> parameter is <tt>true</tt>, then the
messages are joined so that there are no newlines in the resulting
string. Otherwise, (a) any existing newlines in the messages are
preserved, and (b) each nested message occupies its own line.
@param elideNewlines whether to elide newlines or not
@param locale the locale to use, or null for the default
@return the aggregated messages
|
getMessages
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/NestedException.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/NestedException.java
|
MIT
|
public Throwable getNestedException()
{
return getCause();
}
|
Gets the exception that's nested within this <tt>NestedException</tt>,
if any.
@return the nested exception, or null
@deprecated Use <tt>java.lang.Throwable.getCause()</tt> instead
|
getNestedException
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/NestedException.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/NestedException.java
|
MIT
|
public String toString()
{
String s = getClass().getName();
String message = getMessage();
return (message != null) ? (s + ": " + message) : s;
}
|
Returns a short description of this exception. If this object was
created with an error message string, then the result is the
concatenation of three strings:
<ul>
<li> The name of the actual class of this object
<li> ": " (a colon and a space)
<li> The result of the {@link #getMessage} method for this object
</ul>
If this object was created with no error message string, then the
name of the actual class of this object is returned.
@return a string representation of this object
|
toString
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/NestedException.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/NestedException.java
|
MIT
|
public void printStackTrace()
{
this.printStackTrace(System.err);
}
|
Print a stack trace to standard error.
@see #printStackTrace(Locale)
@see #printStackTrace(PrintWriter)
@see #printStackTrace(PrintStream)
|
printStackTrace
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/NestedException.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/NestedException.java
|
MIT
|
public void printStackTrace (Locale locale)
{
this.printStackTrace(System.err, locale);
}
|
Print a stack trace to standard error, using the specified locale.
@param locale the locale to use, or null for the default
@see #printStackTrace(Locale)
@see #printStackTrace(PrintWriter)
@see #printStackTrace(PrintStream)
|
printStackTrace
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/NestedException.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/NestedException.java
|
MIT
|
public void printStackTrace(PrintWriter out)
{
super.printStackTrace(out);
}
|
Print a stack trace.
@param out where to dump the stack trace
@see #printStackTrace()
@see #printStackTrace(PrintWriter,Locale)
@see #printStackTrace(PrintStream)
|
printStackTrace
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/NestedException.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/NestedException.java
|
MIT
|
public void printStackTrace(PrintWriter out, Locale locale)
{
if (locale == null)
super.printStackTrace(out);
else
{
Locale oldLocale = Locale.getDefault();
Locale.setDefault(locale);
super.printStackTrace(out);
out.flush();
Locale.setDefault(oldLocale);
}
}
|
Print a stack trace, using a specific locale for the output.
@param out where to dump the stack trace
@param locale the locale to use, or null for the default
@see #printStackTrace()
@see #printStackTrace(PrintWriter)
@see #printStackTrace(PrintStream,Locale)
|
printStackTrace
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/NestedException.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/NestedException.java
|
MIT
|
public void printStackTrace(PrintStream out)
{
super.printStackTrace(out);
}
|
Print a stack trace.
@param out where to dump the stack trace
@see #printStackTrace()
@see #printStackTrace(PrintStream,Locale)
@see #printStackTrace(PrintWriter)
|
printStackTrace
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/NestedException.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/NestedException.java
|
MIT
|
public void printStackTrace(PrintStream out, Locale locale)
{
this.printStackTrace(new PrintWriter(out), locale);
}
|
Print a stack trace, using a specific locale for the output.
@param out where to dump the stack trace
@param locale the locale to use, or null for the default
@see #printStackTrace()
@see #printStackTrace(PrintStream)
@see #printStackTrace(PrintWriter,Locale)
|
printStackTrace
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/NestedException.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/NestedException.java
|
MIT
|
public boolean acquire (long timeout)
throws SemaphoreException
{
boolean acquired = false;
synchronized (this)
{
if (count > 0)
acquired = true;
else if (timeout == 0)
{
waitForever();
acquired = true;
}
else if (timeout > 0)
{
// Have to wait for it to become available.
acquired = waitOrTimeOut (timeout);
}
if (acquired)
count--;
notifyAll();
}
return acquired;
}
|
Acquire this semaphore. If the semaphore isn't available, the
current thread is put to sleep until either (a) the semaphore is
available, or (b) the timeout period expires.
@param timeout Timeout period, in milliseconds. A value of 0 means
"wait forever, until the semaphore is available." A
negative value means "return immediately if the
semaphore is not available."
@return <tt>true</tt> if the semaphore was successfully acquired,
<tt>false</tt> if the timeout expired.
@throws SemaphoreException error attempting to acquire semaphore
@see #acquire()
|
acquire
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/ObjectLockSemaphore.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/ObjectLockSemaphore.java
|
MIT
|
public boolean acquire()
throws SemaphoreException
{
return acquire (0);
}
|
Acquire this semaphore. If the semaphore isn't available, this
method waits forever for the semaphore to become available. Calling
this version of <tt>acquire()</tt> is exactly equivalent to calling
{@link #acquire(long)} with a timeout value of 0.
@throws SemaphoreException error attempting to acquire semaphore
@see #acquire(long)
|
acquire
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/ObjectLockSemaphore.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/ObjectLockSemaphore.java
|
MIT
|
public synchronized void addToCount (int delta)
throws SemaphoreException
{
count += delta;
notifyAll();
}
|
Increment the semaphore's current value, as well as its maximum value.
This method is useful in cases where the semaphore is controlling
access to multiple instances of a resource (e.g, database connections,
file descriptors, etc.), and more instances of the controlled resource
have become available.
@param delta The amount by which to increment the count.
@throws SemaphoreException error updating semaphore's count
|
addToCount
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/ObjectLockSemaphore.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/ObjectLockSemaphore.java
|
MIT
|
public synchronized int getValue()
throws SemaphoreException
{
return count;
}
|
Get the semaphore's current value (i.e., its count).
@return the current value of the semaphore
@throws SemaphoreException error getting semaphore's value
|
getValue
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/ObjectLockSemaphore.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/ObjectLockSemaphore.java
|
MIT
|
public synchronized void release()
throws SemaphoreException
{
count++;
notifyAll();
}
|
Release this semaphore, incrementing its counter.
@throws SemaphoreException error getting semaphore's value
|
release
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/ObjectLockSemaphore.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/ObjectLockSemaphore.java
|
MIT
|
public String toString()
{
StringBuilder buf = new StringBuilder();
buf.append ("Semaphore[");
buf.append (Integer.toHexString (hashCode()));
buf.append (", value=");
buf.append (String.valueOf (count));
buf.append (']');
return buf.toString();
}
|
Return a string representation of the semaphore.
@return A printable representation of the semaphore.
|
toString
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/ObjectLockSemaphore.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/ObjectLockSemaphore.java
|
MIT
|
private void waitForever()
{
boolean available = false;
while (! available)
{
try
{
wait();
if (count > 0)
available = true;
}
catch (InterruptedException ex)
{
}
}
}
|
Wait forever for the semaphore to become available. This method must
be called from within a block that's synchronized on the semaphore.
|
waitForever
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/ObjectLockSemaphore.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/ObjectLockSemaphore.java
|
MIT
|
private boolean waitOrTimeOut (long timeout)
{
boolean available = false;
Date start = new Date();
long elapsed = 0;
while ( (! available) && (elapsed < timeout) )
{
// Wait until timeout or until we're notified. Note that we can
// be awakened even though the timeout hasn't expired. Since
// many threads can be waiting for the same notification, we
// have to check for the semaphore's availability every time we
// awaken.
try
{
wait (timeout);
}
catch (InterruptedException ex)
{
}
Date end = new Date();
elapsed += end.getTime() - start.getTime();
// Awake. Did the timeout occur, or do we have the semaphore?
if (count > 0)
available = true;
}
return available;
}
|
Wait for the semaphore to become available, or until the specified
timeout expires. The timeout must be positive. This method must
be called from within a block that's synchronized on this object.
@param timeout The timeout.
@return <tt>true</tt> if the semaphore is available,
<tt>false</tt> if the timeout expired. <b>This method
does not modify the semaphore's counter value.</b>
|
waitOrTimeOut
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/ObjectLockSemaphore.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/ObjectLockSemaphore.java
|
MIT
|
public int getKeysInInsertionOrder (List<? super K> list)
{
// Casting to Collection removes a stupid JDK 1.6-beta compiler
// complaint. Doing this:
//
// list.addAll(keysInOrder)
//
// results in this compiler error:
//
// reference to addAll is ambiguous, both method
// addAll(java.util.Collection<? extends E>) in
// java.util.Collection<capture#142 of ? super K> and method
// addAll(java.util.Collection<? extends E>) in
// java.util.List<capture#142 of ? super K> match
//
// This problem is new with 1.6. Casting solves the problem.
((Collection<? super K>) list).addAll(keysInOrder);
return keysInOrder.size();
}
|
Get the keys in the order they were added to this map.
@param list the <tt>List</tt> to receive the keys
@return the number of keys added to the list
@see #keysInInsertionOrder
|
getKeysInInsertionOrder
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/OrderedHashMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/OrderedHashMap.java
|
MIT
|
public List<K> keysInInsertionOrder()
{
return new ArrayList<K> (keysInOrder);
}
|
Get the keys in the order they were added to this map.
@return a new <tt>List</tt> containing the keys in insertion order
@see #getKeysInInsertionOrder
|
keysInInsertionOrder
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/OrderedHashMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/OrderedHashMap.java
|
MIT
|
public Object clone() // NOPMD
{
return new OrderedHashMap<K,V> (this);
}
|
Returns a shallow copy of this instance. The keys and values themselves
are not cloned.
@return a shallow copy of this map
|
clone
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/OrderedHashMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/OrderedHashMap.java
|
MIT
|
public void putAll (Map<? extends K, ? extends V> map)
{
for (Iterator<? extends K> it = map.keySet().iterator();
it.hasNext(); )
{
K key = it.next();
V value = map.get (key);
this.put (key, value);
}
}
|
Copies all of the mappings from a specified map to this one. These
mappings replace any mappings that this map had for any of the keys
in this map. Since there's no way of knowing in what order entries
were made in the original map, they are appended to the key
insertion order list in the order they are returned by the map's
<tt>keySet()</tt> method.
@param map the map whose mappings are to be copied
@see #putAll(OrderedHashMap)
|
putAll
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/OrderedHashMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/OrderedHashMap.java
|
MIT
|
public void putAll (OrderedHashMap<? extends K, ? extends V> map)
{
for (Iterator<? extends K> it = map.keysInInsertionOrder().iterator();
it.hasNext(); )
{
K key = it.next();
V value = map.get (key);
this.put (key, value);
}
}
|
Copies all of the mappings from a specified map to this one. These
mappings replace any mappings that this map had for any of the keys
in this map. The keys are appended to this map's key insertion order
list in the order they were originally added to <tt>map</tt>.
@param map the map whose mappings are to be copied
@see #putAll(OrderedHashMap)
@see #keysInInsertionOrder
|
putAll
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/OrderedHashMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/OrderedHashMap.java
|
MIT
|
public V remove (Object key)
{
V oldValue = super.remove (key);
keysInOrder.remove (key);
return oldValue;
}
|
Removes the mapping for a key, if there is one. The key is also removed
from the key insertion order list.
@param key the key to remove
@return the previous value associated with the key, or null if (a) there
was no previous value, or (b) the previous value was a null
|
remove
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/OrderedHashMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/OrderedHashMap.java
|
MIT
|
public Set<Map.Entry<String, String>> entrySet()
{
synchronized (this)
{
if (entrySetResult == null)
entrySetResult = new EntrySet();
}
return entrySetResult;
}
|
Get a set view of the mappings in this map. Each element in this set
is a <tt>Map.Entry</tt>. The collection is backed by the map, so
changes to the map are reflected in the collection, and vice-versa.
The collection supports element removal, which removes the
corresponding mapping from the map, via the
<tt>Iterator.remove</tt>, <tt>Collection.remove</tt>,
<tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt>
operations. It does not support the <tt>add</tt> or <tt>addAll</tt>
operations.
@return nothing
@throws UnsupportedOperationException unconditionally
|
entrySet
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/PropertiesMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/PropertiesMap.java
|
MIT
|
public String get (Object key)
{
return properties.getProperty ((String) key);
}
|
Retrieve an object from the map. Retrieving an object from an
LRU map "refreshes" the object so that it is among the most recently
used objects.
@param key the object's key in the map. Must be a string.
@return the associated object, or null if not found
@throws ClassCastException if <tt>key</tt> is not a string
|
get
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/PropertiesMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/PropertiesMap.java
|
MIT
|
public Set<String> keySet()
{
return new KeySet();
}
|
<p>Return a <tt>Set</tt> view of the keys in the map. The set is
partially backed by the map. Changes to the map are not necessarily
reflected in the set, and vice-versa. The set does not support
element removal.</p>
@return the set of keys in this map
|
keySet
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/PropertiesMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/PropertiesMap.java
|
MIT
|
public String remove (Object key)
{
throw new UnsupportedOperationException();
}
|
Removes the mapping for a key, if there is one. Not supported by
this class.
@param key the key to remove
@return the previous value associated with the key, or null if (a) there
was no previous value, or (b) the previous value was a null
@throws UnsupportedOperationException unconditionally
|
remove
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/PropertiesMap.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/PropertiesMap.java
|
MIT
|
@Override
public void add(int index, T element)
{
if (index < 0)
{
throw new IndexOutOfBoundsException("Index " + index +
" is negative.");
}
if (index >= size())
set(index, element);
else
super.add(index, element);
}
|
Inserts the specified element at the specified position in this
list. Shifts the element currently at that position (if any) and
any subsequent elements to the right (adds one to their indices). If
the specified index is beyond the end of the list, then this method
behaves exactly like {@link #set(int,Object)}.
@param index index at which the specified element is to be inserted.
@param element element to be inserted.
@throws IndexOutOfBoundsException if the index is negative.
|
add
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/SparseArrayList.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/SparseArrayList.java
|
MIT
|
@Override
public T set(int index, T element)
throws IndexOutOfBoundsException
{
if (index < 0)
{
throw new IndexOutOfBoundsException("Index " + index +
" is negative.");
}
int curSize = size();
if (index >= curSize)
{
int newSize = index + 1;
ensureCapacity (newSize);
while (curSize++ < newSize)
super.add(null);
}
return super.set(index, element);
}
|
Replaces the element at the specified position in this list with the
specified element. Unlike a regular <tt>ArrayList</tt>, this method
does not throw an exception if the passed-in index is beyond the end
of the array; instead, it extends the array (via
<tt>ensureCapacity()</tt>) so that the index is legal. (But, the
index <strong>must</strong> be positive.)
@param index index of element to replace or store
@param element element to be stored at the specified position
@return the element previously at the specified position, or null
@throws IndexOutOfBoundsException if <tt>index</tt> is negative
|
set
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/SparseArrayList.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/SparseArrayList.java
|
MIT
|
public static Version getInstance()
{
return new Version();
}
|
Get an instance of this class.
@return a singleton instance of this class.
|
getInstance
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/Version.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/Version.java
|
MIT
|
protected String getBuildInfoBundleName()
{
return BUILD_INFO_BUNDLE_NAME;
}
|
Get the class name of the build info resource bundle, which contains
data about when the product was built, generated (presumably)
during the build by
{@link BuildInfo#makeBuildInfoBundle BuildInfo.makeBuildInfoBundle()}.
@return the name of the build info resource bundle
|
getBuildInfoBundleName
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/Version.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/Version.java
|
MIT
|
protected String getVersionKey()
{
return "api.version";
}
|
Get the key for the version string. This key is presumed to be
in the version resource bundle.
@return the version string key
|
getVersionKey
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/Version.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/Version.java
|
MIT
|
protected String getApplicationNameKey()
{
return "api.name";
}
|
Get the key for the name of the utility or application.
@return the key
|
getApplicationNameKey
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/Version.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/Version.java
|
MIT
|
public static void main (String[] args)
{
System.out.println(getInstance().getVersionDisplay());
System.exit (0);
}
|
Display the build information
@param args command-line parameters (ignored)
|
main
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/Version.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/Version.java
|
MIT
|
public String getVersion()
{
return BundleUtil.getString(getVersionBundleName(),
getVersionKey(),
"?");
}
|
Get the version number.
@return the version number
|
getVersion
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/VersionBase.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/VersionBase.java
|
MIT
|
public String getApplicationName()
{
return BundleUtil.getString(getVersionBundleName(),
getApplicationNameKey(),
"?");
}
|
Get the application name.
@return the application name
|
getApplicationName
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/VersionBase.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/VersionBase.java
|
MIT
|
public String getVersionDisplay()
{
BuildInfo buildInfo = new BuildInfo(getBuildInfoBundleName());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
String versionBundle = getVersionBundleName();
pw.print(BundleUtil.getString(versionBundle,
getApplicationNameKey(),
"Unknown application"));
pw.print(", version ");
pw.println(getVersion());
pw.println(getCopyright());
pw.println();
pw.println("Build: " + buildInfo.getBuildID());
pw.println("Build date: " + buildInfo.getBuildDate());
pw.println("Built by: " + buildInfo.getBuildUserID());
pw.println("Built on: " +
buildInfo.getBuildOperatingSystem());
pw.println("Build Java VM: " +
buildInfo.getBuildJavaVM());
pw.println("Build compiler: " +
buildInfo.getBuildJavaCompiler());
pw.print("Ant version: " +
buildInfo.getBuildAntVersion());
return sw.getBuffer().toString();
}
|
Get the multiline version output. The returned string will have
embedded newlines, but no trailing newline.
@return the multiline version output.
|
getVersionDisplay
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/VersionBase.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/VersionBase.java
|
MIT
|
public String getExpectedVersion()
{
return expectedVersion;
}
|
Get the expected version string from this exception.
@return the expected version string
|
getExpectedVersion
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/VersionMismatchException.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/VersionMismatchException.java
|
MIT
|
public String getFoundVersion()
{
return foundVersion;
}
|
Get the found version string from this exception.
@return the found version string
|
getFoundVersion
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/VersionMismatchException.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/VersionMismatchException.java
|
MIT
|
public XDate convertToTimeZone (TimeZone tz)
{
Calendar calFrom = new GregorianCalendar (TimeZone.getDefault());
Calendar calTo = new GregorianCalendar (tz);
calFrom.setTimeInMillis (getTime());
calTo.setTimeInMillis (calFrom.getTimeInMillis());
return new XDate (calTo.getTime());
}
|
Convert this date from its time zone to another. Sample use:
<pre>
// Convert time in default time zone to UTC
XDate now = new XDate();
TimeZone tzUTC = TimeZone.getTimeZone ("UTC");
Date utc = now.convertToTimeZone (tzUTC);
DateFormat fmt = new SimpleDateFormat ("yyyy/MM/dd HH:mm:ss z");
fmt.setTimeZone (tzUTC);
System.out.println (fmt.format (utc));
</pre>
<p>Or, more simply:</p>
<pre>
XDate now = new XDate();
System.out.println (now.formatInTimeZone ("yyyy/MM/dd HH:mm:ss z",
TimeZone.getTimeZone ("UTC")));
</pre>
@param tz the time zone to convert the date to
@return a new <tt>XDate</tt> object, appropriately converted. This
result can safely be stored in a <tt>java.util.Date</tt>
reference.
@see #formatInTimeZone
|
convertToTimeZone
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/XDate.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/XDate.java
|
MIT
|
public String formatInTimeZone (String dateFormat, TimeZone tz)
{
Date tzDate = convertToTimeZone (tz);
DateFormat fmt = new SimpleDateFormat (dateFormat);
fmt.setTimeZone (tz);
return fmt.format (tzDate);
}
|
Convenience method to produce a printable date in a specified time
zone, using a <tt>SimpleDateFormat</tt>. Calling this method is
roughly equivalent to:
<pre>
XDate now = new XDate();
TimeZone tzUTC = TimeZone.getTimeZone ("UTC");
Date utc = now.convertToTimeZone (tzUTC);
DateFormat fmt = new SimpleDateFormat ("yyyy/MM/dd HH:mm:ss z");
fmt.setTimeZone (tzUTC);
String formattedDate = fmt.format (utc);
</pre>
@param dateFormat the date format string to use, in a form that's
compatible with <tt>java.text.SimpleDateFormat</tt>
@param tz the desired time zone
@return the formatted date string
|
formatInTimeZone
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/XDate.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/XDate.java
|
MIT
|
public static XResourceBundle getXResourceBundle(String baseName)
{
ResourceBundle bundle = ResourceBundle.getBundle(baseName);
return (bundle == null) ? null : new XResourceBundle(bundle);
}
|
Analogous to the equivalent <tt>getBundle</tt> method in the JDK's
<tt>ResourceBundle</tt> class.
@param baseName base name of the bundle to retrieve, a fully
qualified class name
@return the bundle
@throws NullPointerException if <tt>baseName</tt> is null
@throws MissingResourceException no bundle available
|
getXResourceBundle
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/XResourceBundle.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/XResourceBundle.java
|
MIT
|
public static XResourceBundle getXResourceBundle(String baseName,
Locale locale)
{
ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale);
return (bundle == null) ? null : new XResourceBundle(bundle);
}
|
Analogous to the equivalent <tt>getBundle</tt> method in the JDK's
<tt>ResourceBundle</tt> class.
@param baseName base name of the bundle to retrieve, a fully
qualified class name
@param locale the locale for which a resource bundle is desired
@return the bundle
@throws NullPointerException if <tt>baseName</tt> is null
@throws MissingResourceException no bundle available
|
getXResourceBundle
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/XResourceBundle.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/XResourceBundle.java
|
MIT
|
public static XResourceBundle getXResourceBundle(String baseName,
Locale locale,
ClassLoader classLoader)
{
ResourceBundle bundle = ResourceBundle.getBundle(baseName,
locale,
classLoader);
return (bundle == null) ? null : new XResourceBundle(bundle);
}
|
Analogous to the equivalent <tt>getBundle</tt> method in the JDK's
<tt>ResourceBundle</tt> class.
@param baseName base name of the bundle to retrieve, a fully
qualified class name
@param locale the locale for which a resource bundle is desired
@param classLoader class loader to use
@return the bundle
@throws NullPointerException if <tt>baseName</tt> is null
@throws MissingResourceException no bundle available
|
getXResourceBundle
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/XResourceBundle.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/XResourceBundle.java
|
MIT
|
public Enumeration<String> getKeys()
{
return super.parent.getKeys();
}
|
Returns an enumeration of the keys.
@return the enumeration of the keys
|
getKeys
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/XResourceBundle.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/XResourceBundle.java
|
MIT
|
public String getString(String key, String defaultValue)
{
String result = null;
try
{
result = super.parent.getString(key);
}
catch (MissingResourceException ex)
{
result = defaultValue;
}
return result;
}
|
Get a string for the given key from this resource bundle, applying a
default if not found. There's no equivalent for this method in the
<tt>ResourceBundle</tt> class.
@param key the key for the desired string
@param defaultValue the default value, if not found
@return the value for the key, which may be the default
|
getString
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/XResourceBundle.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/XResourceBundle.java
|
MIT
|
protected Object handleGetObject(String key)
{
// Always delegate to the parent (wrapped) bundle.
return null;
}
|
Gets an object for the given key from this resource bundle.
Returns null if this resource bundle does not contain an
object for the given key.
@param key the key for the desired object
@exception NullPointerException if <code>key</code> is <code>null</code>
@return the object for the given key, or null
|
handleGetObject
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/misc/XResourceBundle.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/XResourceBundle.java
|
MIT
|
public String substitute(String s, VariableDereferencer deref)
throws VariableSyntaxException,
UndefinedVariableException,
VariableSubstitutionException
{
return substitute(s, deref, null);
}
|
<p>Substitute all variable references in the supplied string, using
a Unix Bourne Shell-style variable syntax. This method uses a
supplied <tt>VariableDereferencer</tt> object to resolve variable
values. Note that this method throws no exceptions. Syntax errors in
the variable references are silently ignored. Variables that have no
value are substituted as the empty string. This method assumes that
variable names may consist solely of alphanumeric characters,
underscores and periods. This syntax is sufficient to substitute
variables from <tt>System.properties</tt>, for instance. If you want
more control over the legal characters, use the one of the other
<tt>substitute</tt> methods.</p>
<p>Calling this method is equivalent to:</p>
<blockquote><pre>substitute(s, deref, null)</pre></blockquote>
@param s the string containing possible variable references
@param deref the <tt>VariableDereferencer</tt> object
to use to resolve the variables' values.
@return The (possibly) expanded string.
@throws UndefinedVariableException undefined variable, and
{@link #getAbortOnUndefinedVariable}
returns true
@throws VariableSyntaxException syntax error, and
{@link #getAbortOnSyntaxError}
returns true
@throws VariableSubstitutionException substitution error
@see #substitute(String,VariableDereferencer,VariableNameChecker,Object)
@see VariableDereferencer#getVariableValue(String,Object)
|
substitute
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/AbstractVariableSubstituter.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/AbstractVariableSubstituter.java
|
MIT
|
public String substitute(String s,
VariableDereferencer deref,
Object context)
throws VariableSyntaxException,
UndefinedVariableException,
VariableSubstitutionException
{
return substitute(s, deref, null, context);
}
|
<p>Substitute all variable references in the supplied string, using
a Unix Bourne Shell-style variable syntax. This method uses a
supplied <tt>VariableDereferencer</tt> object to resolve variable
values. Note that this method throws no exceptions. Syntax errors in
the variable references are silently ignored. Variables that have no
value are substituted as the empty string. This method assumes that
variable names may consist solely of alphanumeric characters,
underscores and periods. This syntax is sufficient to substitute
variables from <tt>System.properties</tt>, for instance. If you want
more control over the legal characters, use the one of the other
<tt>substitute</tt> methods.</p>
@param s the string containing possible variable references
@param deref the <tt>VariableDereferencer</tt> object
to use to resolve the variables' values.
@param context an optional context object, passed through unmodified
to the <tt>deref</tt> object's
{@link VariableDereferencer#getVariableValue} method.
This object can be anything at all (and, in fact, may
be null if you don't care.) It's primarily useful
for passing context information from the caller to
the (custom) <tt>VariableDereferencer</tt>.
@return The (possibly) expanded string.
@throws UndefinedVariableException undefined variable, and
{@link #getAbortOnUndefinedVariable}
returns true
@throws VariableSyntaxException syntax error, and
{@link #getAbortOnSyntaxError}
returns true
@throws VariableSubstitutionException substitution error
@see #substitute(String,VariableDereferencer,VariableNameChecker,Object)
@see VariableDereferencer#getVariableValue(String,Object)
|
substitute
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/AbstractVariableSubstituter.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/AbstractVariableSubstituter.java
|
MIT
|
public boolean getAbortOnSyntaxError()
{
return abortOnSyntaxError;
}
|
Get the value of the flag that controls whether the
<tt>substitute()</tt> methods will abort when they encounter a
syntax error. If this flag is clear, then this object will recover
from a syntax error (usually by leaving the syntactically bad
variable reference untouched in the resulting string). If this flag
is set, then a syntax error results in a
{@link VariableSyntaxException}.
@return <tt>true</tt> if the "abort on syntax error" capability
is enabled, <tt>false</tt> if it is disabled.
@see #setAbortOnUndefinedVariable
|
getAbortOnSyntaxError
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/AbstractVariableSubstituter.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/AbstractVariableSubstituter.java
|
MIT
|
public void setAbortOnSyntaxError(boolean enable)
{
abortOnSyntaxError = enable;
}
|
Set or clear the flag that controls whether the
<tt>substitute()</tt> methods will abort when they encounter a
syntax error. If this flag is clear, then this object will recover
from a syntax error (usually by leaving the syntactically bad
variable reference untouched in the resulting string). If this flag
is set, then a syntax error results in a
{@link VariableSyntaxException}. The flag defaults to <tt>false</tt>.
@param enable <tt>true</tt> to enable the "abort on syntax error"
flag, <tt>false</tt> to disable it.
@see #getAbortOnUndefinedVariable
|
setAbortOnSyntaxError
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/AbstractVariableSubstituter.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/AbstractVariableSubstituter.java
|
MIT
|
public void setAbortOnUndefinedVariable(boolean enable)
{
abortOnUndefinedVariable = enable;
}
|
Set or clear the flag that controls whether the <tt>substitute()</tt>
methods will abort when they encounter an undefined variable. If this
flag is clear, then an undefined variable is expanded to an empty
string. If this flag is set, then an undefined value results in an
{@link UndefinedVariableException}. The flag defaults to <tt>false</tt>.
@param enable <tt>true</tt> to enable the "abort on undefined variable"
flag, <tt>false</tt> to disable it.
@see #getAbortOnUndefinedVariable
|
setAbortOnUndefinedVariable
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/AbstractVariableSubstituter.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/AbstractVariableSubstituter.java
|
MIT
|
public long getDuration()
{
return duration_in_ms;
}
|
Get the stored duration value, in milliseconds.
@return the stored duration value
|
getDuration
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/Duration.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/Duration.java
|
MIT
|
public String format()
{
return format(Locale.getDefault());
}
|
Format the duration value as a string, like the kind of string
handled by the {@link #parse} method. This version formats the string
using the default locale. For a complete description of what this
method produces, see {@link #format(Locale)}.
@return the formatted string
|
format
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/Duration.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/Duration.java
|
MIT
|
public String format(Locale locale)
{
Map<DurationType,DurationForFormat> map = getFormatterMap(locale);
long milliseconds = duration_in_ms;
long days = milliseconds / DAY_MS;
milliseconds -= (days * DAY_MS);
long hours = milliseconds / HOUR_MS;
milliseconds -= (hours * HOUR_MS);
long minutes = milliseconds / MINUTE_MS;
milliseconds -= (minutes * MINUTE_MS);
long seconds = milliseconds / SECOND_MS;
milliseconds -= (seconds * SECOND_MS);
StringBuilder buf = new StringBuilder();
String sep = "";
if (days > 0)
{
formatForDurationUnit(days, map.get(DurationType.DAY), buf, sep);
sep = ", ";
}
if (hours > 0)
{
formatForDurationUnit(hours, map.get(DurationType.HOUR), buf, sep);
sep = ", ";
}
if (minutes > 0)
{
formatForDurationUnit(minutes, map.get(DurationType.MINUTE), buf, sep);
sep = ", ";
}
if (seconds > 0)
{
formatForDurationUnit(seconds, map.get(DurationType.SECOND), buf, sep);
sep = ", ";
}
if (milliseconds > 0)
{
formatForDurationUnit(milliseconds, map.get(DurationType.MILLISECOND), buf, sep);
sep = ", ";
}
return buf.toString();
}
|
<p>Format the duration value as a string, like the kind of string
handled by the {@link #parse} method. For instance, a duration value
of 1 is formatted as "1 millisecond". A duration value of 86460000
is formatted as "1 day, 1 hour".</p>
@param locale Locale to use for the strings, or null for the default.
If there's no bundle for the specified locale, English
is used.
@return the string
|
format
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/Duration.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/Duration.java
|
MIT
|
public void parse(String s)
throws ParseException
{
parse(s, Locale.getDefault());
}
|
Parse a string containing a textual description of a duration,
setting this object's value to the result of the parse. This method
parses the tokens using the default locale. See the version of
{@link #parse(String,Locale) parse()} that takes a <tt>Locale</tt>
parameter for a more complete explanation of the supported tokens.
@param s the string to parse
@throws ParseException parse error
|
parse
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/Duration.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/Duration.java
|
MIT
|
public void parse(String s, Locale locale)
throws ParseException
{
// First, get the list of legal tokens.
Map<String,DurationType> tokenMap = getParserMap(locale);
// Next, break the incoming string into tokens on white space and
// commas. There must be an even number of tokens.
String[] tokens = TextUtil.split(s, ", ");
if ((tokens.length % 2) != 0)
{
throw new ParseException("Malformed duration string \"" + s + "\"",
0);
}
// Now, parse each pair. The first value in each pair must be a number.
// The second value must be a duration token.
duration_in_ms = 0;
for (int i = 0; i < tokens.length; i += 2)
{
// First, parse the number.
long num = 0;
try
{
num = Long.parseLong(tokens[i]);
if (num < 0)
{
throw new ParseException("Unexpected negative value in \"" +
s + "\"",
0);
}
}
catch (NumberFormatException ex)
{
throw new ParseException("In \"" + s +
"\", Expected numeric token \"" +
tokens[i] + "\" is not numeric.",
0);
}
// Next, the duration string.
DurationType t = tokenMap.get(tokens[i+1].toLowerCase());
if (t == null)
{
throw new ParseException("In \"" + s + "\", found unknown " +
"duration \"" + tokens[i + 1] + "\"",
0);
}
switch (t)
{
case MILLISECOND:
duration_in_ms += num;
break;
case SECOND:
duration_in_ms += (num * SECOND_MS);
break;
case MINUTE:
duration_in_ms += (num * MINUTE_MS);
break;
case HOUR:
duration_in_ms += (num * HOUR_MS);
break;
case DAY:
duration_in_ms += (num * DAY_MS);
break;
case WEEK:
duration_in_ms += (num * WEEK_MS);
break;
default:
assert(false);
}
}
}
|
Parse a string containing a textual description of a duration,
setting this object's value to the result of the parse. The string
contains one or more token pairs. The token pairs are separated by
commas or white space. Each resulting token pair has a numeric token
followed by a duration value. Examples will clarify:
<ul>
<li>3 days, 19 hours
<li>12 minutes
<li>1 hour, 10 minutes, 33 seconds, 5 milliseconds
<li>5 minutes 3 seconds
</ul>
@param s the string to parse
@param locale the locale to use when interpreting the tokens, or null
for the default.
@throws ParseException parse error
|
parse
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/Duration.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/Duration.java
|
MIT
|
public final void addMap(Map<String,String> map)
{
mapList.add(map);
}
|
Add a map to the list of maps to use when dereferencing variable values.
The map is added to the end of the list.
@param map The map to add
|
addMap
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/MultipleMapVariableDereferencer.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/MultipleMapVariableDereferencer.java
|
MIT
|
public static boolean booleanFromString(String s)
throws IllegalArgumentException
{
boolean result;
s = s.toLowerCase();
if (s.equals("true") ||
s.equals("1") ||
s.equals("yes") ||
s.equals("y"))
{
result = true;
}
else if (s.equals("false") ||
s.equals("0") ||
s.equals("no") ||
s.equals("n"))
{
result = false;
}
else
{
throw new IllegalArgumentException("Bad boolean string: \"" +
s + "\"");
}
return result;
}
|
Convert a boolean string to a boolean value. This method is more
generous than <tt>java.lang.Boolean.booleanValue()</tt>. The following
strings (in upper or lower case) are recognized as <tt>true</tt>:
"1", "true", "yes", "y". The following
strings (in upper or lower case) are recognized as <tt>false</tt>:
"0", "false", "no", "n".
@param s string to convert
@return <tt>true</tt> or <tt>false</tt>
@throws IllegalArgumentException string isn't a boolean
|
booleanFromString
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/TextUtil.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/TextUtil.java
|
MIT
|
public static boolean stringIsEmpty(String s)
{
boolean isEmpty = true;
if (s != null)
{
char[] chars = s.toCharArray();
for (int i = 0; i < chars.length; i++)
{
if (! Character.isWhitespace(chars[i]))
{
isEmpty = false;
break;
}
}
}
return isEmpty;
}
|
Determine whether a given string is empty. A string is empty if it
is null, zero-length, or comprised entirely of white space. This method
is more efficient than calling <tt>s.trim().length()</tt>, because it
does not create a new string just to test its length.
@param s the string to test
@return <tt>true</tt> if it's empty, <tt>false</tt> if not.
|
stringIsEmpty
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/TextUtil.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/TextUtil.java
|
MIT
|
public static String rightJustifyString(String s, int width)
{
return rightJustifyString(s, width, ' ');
}
|
Right justify a string in a fixed-width field, using blanks for
padding. If the string is already longer than the field width, it is
returned unchanged.
@param s the string
@param width the desired field width
@return a right-justified version of the string
@see #rightJustifyString(String,int,char)
@see #leftJustifyString(String,int)
@see #centerString(String,int)
|
rightJustifyString
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/TextUtil.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/TextUtil.java
|
MIT
|
public static String rightJustifyString(String s, int width, char c)
{
StringBuilder paddedString = new StringBuilder (width);
int paddingNeeded;
int len = s.length();
paddingNeeded = (width < len) ? 0 : (width - len);
for (int i = 0; i < paddingNeeded; i++)
paddedString.append(c);
paddedString.append(s);
return paddedString.toString();
}
|
Right justify a string in a fixed-width field, using the specified
character for padding. If the string is already longer than the
field width, it is returned unchanged.
@param s the string
@param width the desired field width
@param c the pad character
@return a right-justified version of the string
@see #rightJustifyString(String,int)
@see #leftJustifyString(String,int,char)
@see #centerString(String,int,char)
|
rightJustifyString
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/TextUtil.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/TextUtil.java
|
MIT
|
public static String leftJustifyString(String s, int width)
{
return leftJustifyString(s, width, ' ');
}
|
Left justify a string in a fixed-width field, using blanks for
padding. If the string is already longer than the field width, it is
returned unchanged.
@param s the string
@param width the desired field width
@return a left-justified version of the string
@see #leftJustifyString(String,int,char)
@see #rightJustifyString(String,int)
@see #centerString(String,int)
|
leftJustifyString
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/TextUtil.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/TextUtil.java
|
MIT
|
public static String leftJustifyString(String s, int width, char c)
{
StringBuilder paddedString = new StringBuilder (width);
int paddingNeeded;
int len = s.length();
paddingNeeded = (width < len) ? 0 : (width - len);
paddedString.append(s);
for (int i = 0; i < paddingNeeded; i++)
paddedString.append(c);
return paddedString.toString();
}
|
Left justify a string in a fixed-width field, using the specified
character for padding. If the string is already longer than the
field width, it is returned unchanged.
@param s the string
@param width the desired field width
@param c the pad character
@return a left-justified version of the string
@see #leftJustifyString(String,int)
@see #rightJustifyString(String,int,char)
@see #centerString(String,int,char)
|
leftJustifyString
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/TextUtil.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/TextUtil.java
|
MIT
|
public static String centerString(String s, int width)
{
return centerString(s, width, ' ');
}
|
Center a string in a fixed-width field, using blanks for padding. If
the string is already longer than the field width, it is returned
unchanged.
@param s the string
@param width the desired field width
@return a centered version of the string
@see #centerString(String,int,char)
@see #rightJustifyString(String,int)
@see #leftJustifyString(String,int)
|
centerString
|
java
|
kiooeht/ModTheSpire
|
src/main/java/org/clapper/util/text/TextUtil.java
|
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/text/TextUtil.java
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.