Some minor clean-up before release.

- Removing some deprecated stuff
- Moving unused classes to sandbox
This commit is contained in:
Harald Kuhr 2009-10-20 21:10:20 +02:00
parent b5a5d9b79f
commit ac68a31c36
15 changed files with 726 additions and 715 deletions

View File

@ -878,7 +878,7 @@ public final class FileUtil {
File folder = resolve(pFolder);
if (!(/*folder.exists() &&*/folder.isDirectory() && folder.canRead())) {
// NOTE: exists is implictly called by isDirectory
// NOTE: exists is implicitly called by isDirectory
throw new FileNotFoundException("\"" + pFolder + "\" is not a directory or is not readable.");
}

View File

@ -156,8 +156,8 @@ public class FilenameMaskFilter implements FilenameFilter {
* This method implements the {@code java.io.FilenameFilter} interface.
*
* @param pDir the directory in which the file was found.
* @param pName the pName of the file.
* @return {@code true} if the pName should be included in the file
* @param pName the name of the file.
* @return {@code true} if the file {@code pName} should be included in the file
* list; {@code false} otherwise.
*/
public boolean accept(File pDir, String pName) {

View File

@ -53,7 +53,7 @@ public class StringArrayReader extends StringReader {
/**
* Create a new string array reader.
*
* @param pStrings <tt>String</tt>s providing the character stream.
* @param pStrings {@code String}s providing the character stream.
*/
public StringArrayReader(final String[] pStrings) {
super("");

View File

@ -28,37 +28,35 @@
package com.twelvemonkeys.util.regex;
import com.twelvemonkeys.util.DebugUtil;
import java.io.PrintStream;
/**
* This class parses arbitrary strings against a wildcard string mask provided.
* The wildcard characters are '*' and '?'.
* <p>
* <p/>
* The string masks provided are treated as case sensitive.<br>
* Null-valued string masks as well as null valued strings to be parsed, will lead to rejection.
*
* <p>
*
* <p/>
* <p/>
* <p/>
* <i>This class is custom designed for wildcard string parsing and is several times faster than the implementation based on the Jakarta Regexp package.</i>
*
* <p/>
* <p><hr style="height=1"><p>
*
* <p/>
* This task is performed based on regular expression techniques.
* The possibilities of string generation with the well-known wildcard characters stated above,
* represent a subset of the possibilities of string generation with regular expressions.<br>
* The '*' corresponds to ([Union of all characters in the alphabet])*<br>
* The '?' corresponds to ([Union of all characters in the alphabet])<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<small>These expressions are not suited for textual representation at all, I must say. Is there any math tags included in HTML?</small>
*
* <p>
*
* <p/>
* <p/>
* <p/>
* The complete meta-language for regular expressions are much larger.
* This fact makes it fairly straightforward to build data structures for parsing because the amount of rules of building these structures are quite limited, as stated below.
*
* <p>
*
* <p/>
* <p/>
* <p/>
* To bring this over to mathematical terms:
* The parser ia a <b>nondeterministic finite automaton</b> (latin) representing the <b>grammar</b> which is stated by the string mask.
* The <b>language</b> accepted by this automaton is the set of all strings accepted by this automaton.<br>
@ -92,9 +90,9 @@ import java.io.PrintStream;
* Parsing faults must be reported to the author.
* </small>
* </ol>
*
* <p/>
* <p><hr style="height=1"><p>
*
* <p/>
* Examples of usage:<br>
* This example will return "Accepted!".
* <pre>
@ -105,14 +103,15 @@ import java.io.PrintStream;
* System.out.println("Not accepted!");
* }
* </pre>
*
* <p/>
* <p><hr style="height=1"><p>
*
* <p/>
* Theories and concepts are based on the book <i>Elements of the Theory of Computation</i>, by Harry l. Lewis and Christos H. Papadimitriou, (c) 1981 by Prentice Hall.
* <p/>
* <p/>
*
* <p>
* @author <a href="mailto:eirik.torske@iconmedialab.no">Eirik Torske</a>
* @see com.twelvemonkeys.util.regex.REWildcardStringParser
* @deprecated Will probably be removed in the near future
*/
public class WildcardStringParser {
@ -144,7 +143,8 @@ public class WildcardStringParser {
/**
* Creates a wildcard string parser.
* <p>
* <p/>
*
* @param pStringMask the wildcard string mask.
*/
public WildcardStringParser(final String pStringMask) {
@ -153,7 +153,8 @@ public class WildcardStringParser {
/**
* Creates a wildcard string parser.
* <p>
* <p/>
*
* @param pStringMask the wildcard string mask.
* @param pDebugging {@code true} will cause debug messages to be emitted to {@code System.out}.
*/
@ -163,7 +164,8 @@ public class WildcardStringParser {
/**
* Creates a wildcard string parser.
* <p>
* <p/>
*
* @param pStringMask the wildcard string mask.
* @param pDebugging {@code true} will cause debug messages to be emitted.
* @param pDebuggingPrintStream the {@code java.io.PrintStream} to which the debug messages will be emitted.
@ -206,9 +208,7 @@ public class WildcardStringParser {
return false;
}
/**
* @return {@code true} if and only if the string mask only consists of free-range wildcard character(s).
*/
/** @return {@code true} if and only if the string mask only consists of free-range wildcard character(s). */
private boolean isTrivialAutomaton() {
for (int i = 0; i < mStringMask.length(); i++) {
@ -237,8 +237,9 @@ public class WildcardStringParser {
runnerState = newState;
mInitialState = runnerState;
mInitialState.mAutomatonStateNumber = 0;
} else {
System.err.println(DebugUtil.getPrefixErrorMessage(this) + "string mask provided are null or empty - aborting!");
}
else {
System.err.println("string mask provided are null or empty - aborting!");
return false;
}
@ -248,8 +249,7 @@ public class WildcardStringParser {
// Check if the char is an element in the alphabet or is a wildcard character
if (!((isInAlphabet(activeChar)) || (isWildcardCharacter(activeChar)))) {
System.err.println(DebugUtil.getPrefixErrorMessage(this)
+ "one or more characters in string mask are not legal characters - aborting!");
System.err.println("one or more characters in string mask are not legal characters - aborting!");
return false;
}
@ -283,9 +283,7 @@ public class WildcardStringParser {
return true;
}
/**
* Tests if a certain character is a valid character in the alphabet that is applying for this automaton.
*/
/** Tests if a certain character is a valid character in the alphabet that is applying for this automaton. */
public static boolean isInAlphabet(final char pCharToCheck) {
for (int i = 0; i < ALPHABET.length; i++) {
@ -296,30 +294,25 @@ public class WildcardStringParser {
return false;
}
/**
* Tests if a certain character is the designated "free-range" character ('*').
*/
/** Tests if a certain character is the designated "free-range" character ('*'). */
public static boolean isFreeRangeCharacter(final char pCharToCheck) {
return pCharToCheck == FREE_RANGE_CHARACTER;
}
/**
* Tests if a certain character is the designated "free-pass" character ('?').
*/
/** Tests if a certain character is the designated "free-pass" character ('?'). */
public static boolean isFreePassCharacter(final char pCharToCheck) {
return pCharToCheck == FREE_PASS_CHARACTER;
}
/**
* Tests if a certain character is a wildcard character ('*' or '?').
*/
/** Tests if a certain character is a wildcard character ('*' or '?'). */
public static boolean isWildcardCharacter(final char pCharToCheck) {
return ((isFreeRangeCharacter(pCharToCheck)) || (isFreePassCharacter(pCharToCheck)));
}
/**
* Gets the string mask that was used when building the parser atomaton.
* <p>
* <p/>
*
* @return the string mask used for building the parser automaton.
*/
public String getStringMask() {
@ -328,14 +321,15 @@ public class WildcardStringParser {
/**
* Parses a string according to the rules stated above.
* <p>
* <p/>
*
* @param pStringToParse the string to parse.
* @return {@code true} if and only if the string are accepted by the automaton.
*/
public boolean parseString(final String pStringToParse) {
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this) + "parsing \"" + pStringToParse + "\"...");
out.println("parsing \"" + pStringToParse + "\"...");
}
// Update statistics
@ -344,7 +338,7 @@ public class WildcardStringParser {
// Check string to be parsed for nullness
if (pStringToParse == null) {
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this) + "string to be parsed is null - rejection!");
out.println("string to be parsed is null - rejection!");
}
return false;
}
@ -355,23 +349,21 @@ public class WildcardStringParser {
// Check string to be parsed
if (!parsableString.checkString()) {
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this)
+ "one or more characters in string to be parsed are not legal characters - rejection!");
out.println("one or more characters in string to be parsed are not legal characters - rejection!");
}
return false;
}
// Check if automaton is correctly initialized
if (!mInitialized) {
System.err.println(DebugUtil.getPrefixErrorMessage(this) + "automaton is not initialized - rejection!");
System.err.println("automaton is not initialized - rejection!");
return false;
}
// Check if automaton is trivial (accepts all strings)
if (isTrivialAutomaton()) {
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this)
+ "automaton represents a trivial string mask (accepts all strings) - acceptance!");
out.println("automaton represents a trivial string mask (accepts all strings) - acceptance!");
}
return true;
}
@ -379,7 +371,7 @@ public class WildcardStringParser {
// Check if string to be parsed is empty
if (parsableString.isEmpty()) {
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this) + "string to be parsed is empty and not trivial automaton - rejection!");
out.println("string to be parsed is empty and not trivial automaton - rejection!");
}
return false;
}
@ -394,9 +386,10 @@ public class WildcardStringParser {
if ((parsableString.mCharArray[0] == mInitialState.mChar) || isWildcardCharacter(mInitialState.mChar)) {
runnerState = mInitialState;
parsableString.mIndex = 0;
} else {
}
else {
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this) + "cannot enter first automaton state - rejection!");
out.println("cannot enter first automaton state - rejection!");
}
return false;
}
@ -412,20 +405,20 @@ public class WildcardStringParser {
out.println();
}
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this) + "parsing - index number " + i + ", active char: '"
out.println("parsing - index number " + i + ", active char: '"
+ parsableString.getActiveChar() + "' char string index: " + parsableString.mIndex
+ " number of chars since last free-range state: " + numberOfParsedCharactersRead_SinceLastFreePassState);
}
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this) + "parsing - state: " + runnerState.mAutomatonStateNumber + " '"
out.println("parsing - state: " + runnerState.mAutomatonStateNumber + " '"
+ runnerState.mChar + "' - no of free-pass chars read: " + numberOfFreePassCharactersRead_SinceLastFreePassState);
}
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this) + "parsing - hasPerformedFreeRangeMovement: " + hasPerformedFreeRangeMovement);
out.println("parsing - hasPerformedFreeRangeMovement: " + hasPerformedFreeRangeMovement);
}
if (runnerState.mNextState == null) {
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this) + "parsing - runnerState.mNextState == null");
out.println("parsing - runnerState.mNextState == null");
}
// If there are no subsequent state (final state) and the state represents '*' - acceptance!
@ -437,40 +430,39 @@ public class WildcardStringParser {
if (numberOfFreePassCharactersRead_SinceLastFreePassState > numberOfParsedCharactersRead_SinceLastFreePassState) {
if (mDebugging) {
out.println(
DebugUtil.getPrefixDebugMessage(this)
+ "no subsequent state (final state) and the state represents '*' - end of parsing string, but not enough characters read - rejection!");
"no subsequent state (final state) and the state represents '*' - end of parsing string, but not enough characters read - rejection!");
}
return false;
} else {
}
else {
if (mDebugging) {
out.println(
DebugUtil.getPrefixDebugMessage(this)
+ "no subsequent state (final state) and the state represents '*' - end of parsing string and enough characters read - acceptance!");
"no subsequent state (final state) and the state represents '*' - end of parsing string and enough characters read - acceptance!");
}
return true;
}
} else {
}
else {
if (numberOfFreePassCharactersRead_SinceLastFreePassState > numberOfParsedCharactersRead_SinceLastFreePassState) {
if (mDebugging) {
out.println(
DebugUtil.getPrefixDebugMessage(this)
+ "no subsequent state (final state) and the state represents '*' - not the end of parsing string and not enough characters read - read next character");
"no subsequent state (final state) and the state represents '*' - not the end of parsing string and not enough characters read - read next character");
}
parsableString.mIndex++;
numberOfParsedCharactersRead_SinceLastFreePassState++;
} else {
}
else {
if (mDebugging) {
out.println(
DebugUtil.getPrefixDebugMessage(this)
+ "no subsequent state (final state) and the state represents '*' - not the end of parsing string, but enough characters read - acceptance!");
"no subsequent state (final state) and the state represents '*' - not the end of parsing string, but enough characters read - acceptance!");
}
return true;
}
}
} else {
}
else {
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this)
+ "no subsequent state (final state) and the state represents '*' - no skipping performed - acceptance!");
out.println("no subsequent state (final state) and the state represents '*' - no skipping performed - acceptance!");
}
return true;
}
@ -484,24 +476,24 @@ public class WildcardStringParser {
&& (numberOfFreePassCharactersRead_SinceLastFreePassState > numberOfParsedCharactersRead_SinceLastFreePassState)) {
if (mDebugging) {
out.println(
DebugUtil.getPrefixDebugMessage(this)
+ "no subsequent state (final state) and skipping has been performed and end of parsing string, but not enough characters read - rejection!");
"no subsequent state (final state) and skipping has been performed and end of parsing string, but not enough characters read - rejection!");
}
return false;
}
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this)
+ "no subsequent state (final state) and the end of the string to test is reached - acceptance!");
out.println("no subsequent state (final state) and the end of the string to test is reached - acceptance!");
}
return true;
} else {
}
else {
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this) + "parsing - escaping process...");
out.println("parsing - escaping process...");
}
}
} else {
}
else {
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this) + "parsing - runnerState.mNextState != null");
out.println("parsing - runnerState.mNextState != null");
}
// Special Case:
@ -525,22 +517,23 @@ public class WildcardStringParser {
out.println();
}
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this) + "parsing - index number " + i + ", active char: '"
out.println("parsing - index number " + i + ", active char: '"
+ parsableString.getActiveChar() + "' char string index: " + parsableString.mIndex
+ " number of chars since last free-range state: " + numberOfParsedCharactersRead_SinceLastFreePassState);
}
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this) + "parsing - state: " + runnerState.mAutomatonStateNumber + " '"
out.println("parsing - state: " + runnerState.mAutomatonStateNumber + " '"
+ runnerState.mChar + "' - no of free-pass chars read: " + numberOfFreePassCharactersRead_SinceLastFreePassState);
}
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this) + "parsing - hasPerformedFreeRangeMovement: "
out.println("parsing - hasPerformedFreeRangeMovement: "
+ hasPerformedFreeRangeMovement);
}
if ((hasPerformedFreeRangeMovement)
&& (numberOfFreePassCharactersRead_SinceLastFreePassState >= numberOfParsedCharactersRead_SinceLastFreePassState)) {
return true;
} else {
}
else {
return false;
}
}
@ -573,18 +566,17 @@ public class WildcardStringParser {
runnerState = runnerState.mLastFreeRangeState;
parsableString.mIndex++;
numberOfParsedCharactersRead_SinceLastFreePassState++;
} else {
}
else {
if (mDebugging) {
out.println(
DebugUtil.getPrefixDebugMessage(this)
+ "the next state does not represent the same character as the next character in the string to test, and there are no last-free-range-state - rejection!");
out.println("the next state does not represent the same character as the next character in the string to test, and there are no last-free-range-state - rejection!");
}
return false;
}
}
}
if (mDebugging) {
out.println(DebugUtil.getPrefixDebugMessage(this) + "finished reading parsing string and not at any final state - rejection!");
out.println("finished reading parsing string and not at any final state - rejection!");
}
return false;
}
@ -596,23 +588,22 @@ public class WildcardStringParser {
/**
* Method toString
*
*
* @return
*
*/
public String toString() {
StringBuilder buffer = new StringBuilder();
if (!mInitialized) {
buffer.append(DebugUtil.getClassName(this));
buffer.append(getClass().getName());
buffer.append(": Not initialized properly!");
buffer.append("\n");
buffer.append("\n");
} else {
}
else {
WildcardStringParserState runnerState = mInitialState;
buffer.append(DebugUtil.getClassName(this));
buffer.append(getClass().getName());
buffer.append(": String mask ");
buffer.append(mStringMask);
buffer.append("\n");
@ -625,7 +616,8 @@ public class WildcardStringParser {
buffer.append(" (");
if (runnerState.mLastFreeRangeState != null) {
buffer.append(runnerState.mLastFreeRangeState.mAutomatonStateNumber);
} else {
}
else {
buffer.append("-");
}
buffer.append(")");
@ -646,11 +638,8 @@ public class WildcardStringParser {
/**
* Method equals
*
*
* @param pObject
*
* @return
*
*/
public boolean equals(Object pObject) {
@ -667,9 +656,7 @@ public class WildcardStringParser {
/**
* Method hashCode
*
*
* @return
*
*/
public int hashCode() {
return super.hashCode();
@ -684,11 +671,10 @@ public class WildcardStringParser {
}
// Just taking the lazy, easy and dangerous way out
protected void finalize() throws Throwable {}
protected void finalize() throws Throwable {
}
/**
* A simple holder class for an automaton state.
*/
/** A simple holder class for an automaton state. */
class WildcardStringParserState {
// Constants
@ -704,9 +690,7 @@ public class WildcardStringParser {
/**
* Constructor WildcardStringParserState
*
*
* @param pChar
*
*/
public WildcardStringParserState(final char pChar) {
this.mChar = pChar;
@ -716,9 +700,7 @@ public class WildcardStringParser {
// Debug
}
/**
* A simple holder class for a string to be parsed.
*/
/** A simple holder class for a string to be parsed. */
class ParsableString {
// Constants
@ -752,7 +734,7 @@ public class WildcardStringParser {
if ((mIndex > -1) && (mIndex < mCharArray.length)) {
return mCharArray[mIndex];
}
System.err.println(DebugUtil.ERROR + DebugUtil.getClassName(this) + ": trying to access character outside character array!");
System.err.println(getClass().getName() + ": trying to access character outside character array!");
return ' ';
}
@ -761,7 +743,7 @@ public class WildcardStringParser {
if ((mIndex > -1) && (mIndex + 1 < mCharArray.length)) {
return mCharArray[mIndex + 1];
}
System.err.println(DebugUtil.ERROR + DebugUtil.getClassName(this) + ": trying to access character outside character array!");
System.err.println(getClass().getName() + ": trying to access character outside character array!");
return ' ';
}
@ -786,9 +768,7 @@ public class WildcardStringParser {
/**
* Method toString
*
*
* @return
*
*/
public String toString() {
return new String(mCharArray);

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>twelvemonkeys-imageio-jmagick</artifactId>
<version>2.2-SNAPSHOT</version>
<version>2.2</version>
<name>TwelveMonkeys ImageIO JMagick Plugin</name>
<description>
<![CDATA[
@ -17,7 +17,7 @@
<parent>
<artifactId>twelvemonkeys-imageio</artifactId>
<groupId>com.twelvemonkeys</groupId>
<version>2.2-SNAPSHOT</version>
<version>2.2</version>
</parent>
<dependencies>

View File

@ -28,10 +28,13 @@
package com.twelvemonkeys.imageio.plugins.pict;
import com.twelvemonkeys.image.ConvolveTester;
import com.twelvemonkeys.image.BufferedImageIcon;
import com.twelvemonkeys.image.ImageUtil;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.awt.*;
import java.lang.reflect.InvocationTargetException;
/**
* QDTest
@ -125,6 +128,34 @@ public class QDTest {
context.closePicture();
}
ConvolveTester.showIt(image, "QuickDraw Test");
showIt(image, "QuickDraw Test");
}
public static void showIt(final BufferedImage pImage, final String pTitle) {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JFrame frame = new JFrame(pTitle);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationByPlatform(true);
JPanel pane = new JPanel(new BorderLayout());
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
BufferedImageIcon icon = new BufferedImageIcon(ImageUtil.accelerate(pImage, gc));
JScrollPane scroll = new JScrollPane(new JLabel(icon));
scroll.setBorder(null);
pane.add(scroll);
frame.setContentPane(pane);
frame.pack();
frame.setVisible(true);
}
});
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -29,7 +29,6 @@
package com.twelvemonkeys.servlet;
import com.twelvemonkeys.lang.StringUtil;
import com.twelvemonkeys.util.DebugUtil;
import com.twelvemonkeys.util.convert.ConversionException;
import com.twelvemonkeys.util.convert.Converter;
@ -45,6 +44,7 @@ import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
@ -154,7 +154,7 @@ public final class ServletUtil {
// public static T getParameter<T>(ServletRequest pReq, String pName,
// String pFormat, T pDefault) {
static Object getParameter(ServletRequest pReq, String pName, Class pType, String pFormat, Object pDefault) {
static <T> T getParameter(ServletRequest pReq, String pName, Class<T> pType, String pFormat, T pDefault) {
// Test if pDefault is either null or instance of pType
if (pDefault != null && !pType.isInstance(pDefault)) {
throw new IllegalArgumentException("default value not instance of " + pType + ": " + pDefault.getClass());
@ -166,7 +166,7 @@ public final class ServletUtil {
return pDefault;
}
try {
return Converter.getInstance().toObject(str, pType, pFormat);
return pType.cast(Converter.getInstance().toObject(str, pType, pFormat));
}
catch (ConversionException ce) {
return pDefault;
@ -949,14 +949,14 @@ public final class ServletUtil {
// recieved the request
buffer.append(indentation);
buffer.append("Last accessed time: ");
buffer.append(DebugUtil.getTimestamp(pHttpSession.getLastAccessedTime()));
buffer.append(new Date(pHttpSession.getLastAccessedTime()));
buffer.append("\n");
// Returns the time when this session was created, measured in
// milliseconds since midnight January 1, 1970 GMT
buffer.append(indentation);
buffer.append("Creation time: ");
buffer.append(DebugUtil.getTimestamp(pHttpSession.getCreationTime()));
buffer.append(new Date(pHttpSession.getCreationTime()));
buffer.append("\n");
// Returns true if the client does not yet know about the session