Skip to content

Commit

Permalink
#98 toCollection()
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jul 13, 2020
1 parent 00c9b13 commit ac46bf5
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
18 changes: 14 additions & 4 deletions src/main/java/org/xembly/Arg.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ final class Arg {
* @throws XmlContentException If fails
*/
Arg(final String val) throws XmlContentException {
for (final char chr : val.toCharArray()) {
Arg.legal(chr);
}
this.value = val;
this.value = Arg.ifValid(val);
}

@Override
Expand Down Expand Up @@ -203,4 +200,17 @@ private static void range(final char chr, final int left, final int right)
}
}

/**
* Check it for validity and return.
* @param val The XML string
* @return Itself
* @throws XmlContentException If fails
*/
private static String ifValid(final String val) throws XmlContentException {
for (final char chr : val.toCharArray()) {
Arg.legal(chr);
}
return val;
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/xembly/CdataDirective.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.w3c.dom.Document;
import org.w3c.dom.Node;

/*
/**
* CDATA directive.
*
* <p>The class is immutable and thread-safe.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/xembly/CommentDirective.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.w3c.dom.Document;
import org.w3c.dom.Node;

/*
/**
* COMMENT directive.
*
* <p>The class is immutable and thread-safe.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/xembly/StrictDirective.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public Directive.Cursor exec(final Node dom,
throw new ImpossibleModificationException(
String.format(
"%d current nodes [%s] while strictly %d expected",
cursor.size(), this.names(cursor), this.number
cursor.size(), StrictDirective.names(cursor), this.number
)
);
}
Expand All @@ -95,7 +95,7 @@ public Directive.Cursor exec(final Node dom,
* @param nodes Collection of nodes
* @return Text presentation of them
*/
private String names(final Iterable<Node> nodes) {
private static String names(final Iterable<Node> nodes) {
final StringBuilder text = new StringBuilder(0);
for (final Node node : nodes) {
if (text.length() > 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/xembly/XpathDirective.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private static Collection<Node> traditional(final String query,
final Node dom, final Collection<Node> current)
throws ImpossibleModificationException {
final XPath xpath = XpathDirective.FACTORY.get().newXPath();
final Collection<Node> targets = new HashSet<Node>(0);
final Collection<Node> targets = new HashSet<>(0);
for (final Node node : XpathDirective.roots(dom, current)) {
final NodeList list;
try {
Expand Down Expand Up @@ -173,7 +173,7 @@ private static Iterable<Node> roots(final Node dom,
if (dom.getOwnerDocument() == null) {
roots = Collections.singletonList(dom);
} else {
roots = Collections.<Node>singletonList(
roots = Collections.singletonList(
dom.getOwnerDocument().getDocumentElement()
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/xembly/DirectivesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
/**
* Test case for {@link Directives}.
*/
@SuppressWarnings("PMD.TooManyMethods")
@SuppressWarnings({"PMD.TooManyMethods", "PMD.AvoidDuplicateLiterals"})
public final class DirectivesTest {

/**
Expand Down
7 changes: 2 additions & 5 deletions src/test/java/org/xembly/XemblerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,8 @@ public void concurrentInvocationWithNoExceptions() throws Exception {
"ADDIF 'blow';REMOVE;ADDIF 'blow';"
)
);
final int capacity = 10000;
final Collection<Callable<Node>> tasks =
new ArrayList<Callable<Node>>(
capacity
);
final int capacity = 10_000;
final Collection<Callable<Node>> tasks = new ArrayList<>(capacity);
for (int idx = 0; idx < capacity; ++idx) {
final Callable<Node> callable = XemblerTest.callable(
xembler, root
Expand Down

0 comments on commit ac46bf5

Please sign in to comment.