[Minor] code cleanup

This commit is contained in:
Robert von Burg 2014-09-14 12:19:49 +02:00
parent 75199bc6b7
commit 3fbf73fd15
13 changed files with 394 additions and 408 deletions

View File

@ -15,7 +15,6 @@
*/
package ch.eitchnet.xmlpers.api;
public interface ParserFactory<T> {
public DomParser<T> getDomParser();

View File

@ -15,7 +15,6 @@
*/
package ch.eitchnet.xmlpers.api;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*

View File

@ -48,11 +48,11 @@ public class LockableObject {
if (!this.lock.tryLock(tryLockTime, TimeUnit.MILLISECONDS)) {
String msg = "Failed to acquire lock after {0} for {1}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, StringHelper.formatMillisecondsDuration(tryLockTime), this.toString());
msg = MessageFormat.format(msg, StringHelper.formatMillisecondsDuration(tryLockTime), toString());
throw new XmlPersistenceException(msg);
}
if (logger.isDebugEnabled())
logger.debug("locked " + this.toString()); //$NON-NLS-1$
logger.debug("locked " + toString()); //$NON-NLS-1$
} catch (InterruptedException e) {
throw new XmlPersistenceException("Thread interrupted: " + e.getMessage(), e); //$NON-NLS-1$
}
@ -64,6 +64,6 @@ public class LockableObject {
public void unlock() {
this.lock.unlock();
if (logger.isDebugEnabled())
logger.debug("unlocking " + this.toString()); //$NON-NLS-1$
logger.debug("unlocking " + toString()); //$NON-NLS-1$
}
}

View File

@ -1,8 +1,7 @@
package javanet.staxutils;
/**
* Characters that represent line breaks and indentation. These are represented
* as String-valued JavaBean properties.
* Characters that represent line breaks and indentation. These are represented as String-valued JavaBean properties.
*/
@SuppressWarnings("nls")
public interface Indentation {
@ -11,8 +10,8 @@ public interface Indentation {
public static final String DEFAULT_INDENT = " ";
/**
* Set the characters used for one level of indentation. The default is
* {@link #DEFAULT_INDENT}. "\t" is a popular alternative.
* Set the characters used for one level of indentation. The default is {@link #DEFAULT_INDENT}. "\t" is a popular
* alternative.
*/
void setIndent(String indent);
@ -26,10 +25,8 @@ public interface Indentation {
public static final String NORMAL_END_OF_LINE = "\n";
/**
* Set the characters that introduce a new line. The default is
* {@link #NORMAL_END_OF_LINE}.
* {@link IndentingXMLStreamWriter#getLineSeparator}() is a popular
* alternative.
* Set the characters that introduce a new line. The default is {@link #NORMAL_END_OF_LINE}.
* {@link IndentingXMLStreamWriter#getLineSeparator}() is a popular alternative.
*/
public void setNewLine(String newLine);

View File

@ -37,9 +37,8 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
/**
* A filter that indents an XML stream. To apply it, construct a filter that
* contains another {@link XMLStreamWriter}, which you pass to the constructor.
* Then call methods of the filter instead of the contained stream. For example:
* A filter that indents an XML stream. To apply it, construct a filter that contains another {@link XMLStreamWriter},
* which you pass to the constructor. Then call methods of the filter instead of the contained stream. For example:
*
* <pre>
* {@link XMLStreamWriter} stream = ...
@ -49,22 +48,19 @@ import javax.xml.stream.XMLStreamWriter;
* </pre>
*
* <p>
* The filter inserts characters to format the document as an outline, with
* nested elements indented. Basically, it inserts a line break and whitespace
* before:
* The filter inserts characters to format the document as an outline, with nested elements indented. Basically, it
* inserts a line break and whitespace before:
* <ul>
* <li>each DTD, processing instruction or comment that's not preceded by data</li>
* <li>each starting tag that's not preceded by data</li>
* <li>each ending tag that's preceded by nested elements but not data</li>
* </ul>
* This works well with 'data-oriented' XML, wherein each element contains
* either data or nested elements but not both. It can work badly with other
* styles of XML. For example, the data in a 'mixed content' document are apt to
* be polluted with indentation characters.
* This works well with 'data-oriented' XML, wherein each element contains either data or nested elements but not both.
* It can work badly with other styles of XML. For example, the data in a 'mixed content' document are apt to be
* polluted with indentation characters.
* <p>
* Indentation can be adjusted by setting the newLine and indent properties. But
* set them to whitespace only, for best results. Non-whitespace is apt to cause
* problems, for example when this class attempts to insert newLine before the
* Indentation can be adjusted by setting the newLine and indent properties. But set them to whitespace only, for best
* results. Non-whitespace is apt to cause problems, for example when this class attempts to insert newLine before the
* root element.
*
* @author <a href="mailto:jk2006@engineer.com">John Kristian</a>
@ -125,8 +121,7 @@ public class IndentingXMLStreamWriter extends StreamWriterDelegate implements In
}
/**
* @return System.getProperty("line.separator"); or
* {@link #NORMAL_END_OF_LINE} if that fails.
* @return System.getProperty("line.separator"); or {@link #NORMAL_END_OF_LINE} if that fails.
*/
public static String getLineSeparator() {
try {
@ -206,8 +201,7 @@ public class IndentingXMLStreamWriter extends StreamWriterDelegate implements In
}
@Override
public void writeEmptyElement(String prefix, String localName, String namespaceURI)
throws XMLStreamException {
public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
beforeMarkup();
this.out.writeEmptyElement(prefix, localName, namespaceURI);
afterMarkup();
@ -228,8 +222,7 @@ public class IndentingXMLStreamWriter extends StreamWriterDelegate implements In
}
@Override
public void writeStartElement(String prefix, String localName, String namespaceURI)
throws XMLStreamException {
public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
beforeStartElement();
this.out.writeStartElement(prefix, localName, namespaceURI);
afterStartElement();
@ -364,8 +357,7 @@ public class IndentingXMLStreamWriter extends StreamWriterDelegate implements In
}
while (prefixLength > this.linePrefix.length) {
// make linePrefix longer:
char[] newPrefix = new char[newLineLength
+ ((this.linePrefix.length - newLineLength) * 2)];
char[] newPrefix = new char[newLineLength + ((this.linePrefix.length - newLineLength) * 2)];
System.arraycopy(this.linePrefix, 0, newPrefix, 0, this.linePrefix.length);
System.arraycopy(this.linePrefix, newLineLength, newPrefix, this.linePrefix.length,
this.linePrefix.length - newLineLength);

View File

@ -36,9 +36,8 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
/**
* Abstract class for writing filtered XML streams. This class provides methods
* that merely delegate to the contained stream. Subclasses should override some
* of these methods, and may also provide additional methods and fields.
* Abstract class for writing filtered XML streams. This class provides methods that merely delegate to the contained
* stream. Subclasses should override some of these methods, and may also provide additional methods and fields.
*
* @author <a href="mailto:jk2006@engineer.com">John Kristian</a>
*/
@ -116,8 +115,7 @@ public abstract class StreamWriterDelegate implements XMLStreamWriter {
}
@Override
public void writeEmptyElement(String prefix, String localName, String namespaceURI)
throws XMLStreamException {
public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
this.out.writeEmptyElement(prefix, localName, namespaceURI);
}
@ -132,8 +130,7 @@ public abstract class StreamWriterDelegate implements XMLStreamWriter {
}
@Override
public void writeStartElement(String prefix, String localName, String namespaceURI)
throws XMLStreamException {
public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
this.out.writeStartElement(prefix, localName, namespaceURI);
}
@ -163,8 +160,7 @@ public abstract class StreamWriterDelegate implements XMLStreamWriter {
}
@Override
public void writeAttribute(String namespaceURI, String localName, String value)
throws XMLStreamException {
public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException {
this.out.writeAttribute(namespaceURI, localName, value);
}

View File

@ -60,7 +60,7 @@ public class LockingTest extends AbstractPersistenceTest {
properties.setProperty(PersistenceConstants.PROP_LOCK_TIME_MILLIS, Long.toString(500L));
setup(properties);
this.waitForWorkersTime = LockableObject.getLockTime() + this.getWaitForWorkersTime() + 300L;
this.waitForWorkersTime = LockableObject.getLockTime() + getWaitForWorkersTime() + 300L;
}
@Test
@ -128,10 +128,10 @@ public class LockingTest extends AbstractPersistenceTest {
private int runWorkers(List<? extends AbstractWorker> workers) throws InterruptedException {
this.setRun(true);
setRun(true);
for (AbstractWorker worker : workers) {
worker.join(this.getWaitForWorkersTime() + 2000L);
worker.join(getWaitForWorkersTime() + 2000L);
}
int nrOfSuccess = 0;
@ -169,7 +169,7 @@ public class LockingTest extends AbstractPersistenceTest {
public void run() {
logger.info("Waiting for ok to work..."); //$NON-NLS-1$
while (!LockingTest.this.isRun()) {
while (!isRun()) {
try {
Thread.sleep(10L);
} catch (InterruptedException e) {

View File

@ -47,8 +47,8 @@ import org.xml.sax.helpers.DefaultHandler;
import ch.eitchnet.utils.exceptions.XmlException;
import ch.eitchnet.utils.helper.XmlHelper;
import ch.eitchnet.xmlpers.test.model.ModelBuilder;
import ch.eitchnet.xmlpers.test.model.MyParameter;
import ch.eitchnet.xmlpers.test.model.MyModel;
import ch.eitchnet.xmlpers.test.model.MyParameter;
/**
* @author Robert von Burg <eitch@eitchnet.ch>

View File

@ -23,8 +23,8 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ch.eitchnet.xmlpers.api.DomParser;
import ch.eitchnet.xmlpers.test.model.MyParameter;
import ch.eitchnet.xmlpers.test.model.MyModel;
import ch.eitchnet.xmlpers.test.model.MyParameter;
import ch.eitchnet.xmlpers.util.DomUtil;
public class MyModelDomParser implements DomParser<MyModel> {

View File

@ -23,8 +23,8 @@ import org.xml.sax.helpers.DefaultHandler;
import ch.eitchnet.xmlpers.api.SaxParser;
import ch.eitchnet.xmlpers.api.XmlPersistenceStreamWriter;
import ch.eitchnet.xmlpers.test.model.MyParameter;
import ch.eitchnet.xmlpers.test.model.MyModel;
import ch.eitchnet.xmlpers.test.model.MyParameter;
class MyModelSaxParser extends DefaultHandler implements SaxParser<MyModel> {

View File

@ -73,7 +73,8 @@ public class MyModel {
}
/**
* @param id the id to set
* @param id
* the id to set
*/
public void setId(String id) {
this.id = id;
@ -87,7 +88,8 @@ public class MyModel {
}
/**
* @param name the name to set
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
@ -101,7 +103,8 @@ public class MyModel {
}
/**
* @param type the type to set
* @param type
* the type to set
*/
public void setType(String type) {
this.type = type;