You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by mb...@apache.org on 2017/04/13 15:16:07 UTC
[07/34] ant git commit: java 5-8
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java b/src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java
index a4a288b..8fefe86 100644
--- a/src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java
+++ b/src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java
@@ -45,6 +45,7 @@ public abstract class AbstractScriptComponent extends ProjectComponent {
* Set the project.
* @param project the owner of this component.
*/
+ @Override
public void setProject(Project project) {
super.setProject(project);
helper.setProjectComponent(this);
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/ScriptCondition.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/ScriptCondition.java b/src/main/org/apache/tools/ant/types/optional/ScriptCondition.java
index fac02bf..76b2337 100644
--- a/src/main/org/apache/tools/ant/types/optional/ScriptCondition.java
+++ b/src/main/org/apache/tools/ant/types/optional/ScriptCondition.java
@@ -41,6 +41,7 @@ public class ScriptCondition extends AbstractScriptComponent implements Conditio
* @throws org.apache.tools.ant.BuildException
* if an error occurs
*/
+ @Override
public boolean eval() throws BuildException {
initScriptRunner();
executeScript("ant_condition");
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/ScriptFilter.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/ScriptFilter.java b/src/main/org/apache/tools/ant/types/optional/ScriptFilter.java
index 3b0f1a1..a990fd0 100644
--- a/src/main/org/apache/tools/ant/types/optional/ScriptFilter.java
+++ b/src/main/org/apache/tools/ant/types/optional/ScriptFilter.java
@@ -53,6 +53,7 @@ public class ScriptFilter extends TokenFilter.ChainableReaderFilter {
* Set the project.
* @param project the owner of this component.
*/
+ @Override
public void setProject(Project project) {
super.setProject(project);
helper.setProjectComponent(this);
@@ -105,6 +106,7 @@ public class ScriptFilter extends TokenFilter.ChainableReaderFilter {
* @param token the token to be filtered
* @return the filtered token
*/
+ @Override
public String filter(String token) {
init();
setToken(token);
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/ScriptMapper.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/ScriptMapper.java b/src/main/org/apache/tools/ant/types/optional/ScriptMapper.java
index 38dab0b..6fa4b58 100644
--- a/src/main/org/apache/tools/ant/types/optional/ScriptMapper.java
+++ b/src/main/org/apache/tools/ant/types/optional/ScriptMapper.java
@@ -35,8 +35,8 @@ public class ScriptMapper extends AbstractScriptComponent implements FileNameMap
*
* @param from a string.
*/
+ @Override
public void setFrom(String from) {
-
}
/**
@@ -44,15 +44,15 @@ public class ScriptMapper extends AbstractScriptComponent implements FileNameMap
*
* @param to a string.
*/
+ @Override
public void setTo(String to) {
-
}
/**
* Reset the list of files
*/
public void clear() {
- files = new ArrayList<String>(1);
+ files = new ArrayList<>(1);
}
/**
@@ -77,15 +77,15 @@ public class ScriptMapper extends AbstractScriptComponent implements FileNameMap
* null if it does not.
*/
+ @Override
public String[] mapFileName(String sourceFileName) {
initScriptRunner();
getRunner().addBean("source", sourceFileName);
clear();
executeScript("ant_mapper");
- if (files.size() == 0) {
+ if (files.isEmpty()) {
return null;
- } else {
- return files.toArray(new String[files.size()]);
}
+ return files.toArray(new String[files.size()]);
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java b/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java
index 9225840..e5e11a5 100644
--- a/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java
+++ b/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java
@@ -59,6 +59,7 @@ public class ScriptSelector extends BaseSelector {
* Set the project.
* @param project the owner of this component.
*/
+ @Override
public void setProject(Project project) {
super.setProject(project);
helper.setProjectComponent(this);
@@ -166,6 +167,7 @@ public class ScriptSelector extends BaseSelector {
*
* @return whether the file should be selected or not
*/
+ @Override
public boolean isSelected(File basedir, String filename, File file) {
init();
setSelected(true);
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java b/src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java
index f2fe69b..f966646 100644
--- a/src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java
+++ b/src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java
@@ -41,12 +41,12 @@ public class ClassfileSet extends FileSet {
* classes which must be included in the fileset and which are the
* starting point for the dependency search.
*/
- private List<String> rootClasses = new ArrayList<String>();
+ private List<String> rootClasses = new ArrayList<>();
/**
* The list of filesets which contain root classes.
*/
- private List<FileSet> rootFileSets = new ArrayList<FileSet>();
+ private List<FileSet> rootFileSets = new ArrayList<>();
/**
* Inner class used to contain info about root classes.
@@ -81,6 +81,16 @@ public class ClassfileSet extends FileSet {
}
/**
+ * Create a ClassfileSet from another ClassfileSet.
+ *
+ * @param s the other classfileset.
+ */
+ protected ClassfileSet(ClassfileSet s) {
+ super(s);
+ rootClasses.addAll(s.rootClasses);
+ }
+
+ /**
* Add a fileset to which contains a collection of root classes used to
* drive the search from classes.
*
@@ -93,16 +103,6 @@ public class ClassfileSet extends FileSet {
}
/**
- * Create a ClassfileSet from another ClassfileSet.
- *
- * @param s the other classfileset.
- */
- protected ClassfileSet(ClassfileSet s) {
- super(s);
- rootClasses.addAll(s.rootClasses);
- }
-
- /**
* Set the root class attribute.
*
* @param rootClass the name of the root class.
@@ -118,6 +118,7 @@ public class ClassfileSet extends FileSet {
*
* @return a dependency scanner.
*/
+ @Override
public DirectoryScanner getDirectoryScanner(Project p) {
if (isReference()) {
return getRef(p).getDirectoryScanner(p);
@@ -125,7 +126,7 @@ public class ClassfileSet extends FileSet {
dieOnCircularReference(p);
DirectoryScanner parentScanner = super.getDirectoryScanner(p);
DependScanner scanner = new DependScanner(parentScanner);
- final Vector<String> allRootClasses = new Vector<String>(rootClasses);
+ final Vector<String> allRootClasses = new Vector<>(rootClasses);
for (FileSet additionalRootSet : rootFileSets) {
DirectoryScanner additionalScanner
= additionalRootSet.getDirectoryScanner(p);
@@ -160,11 +161,13 @@ public class ClassfileSet extends FileSet {
*
* @return a clone of the class file set.
*/
- public Object clone() {
+ @Override
+ public ClassfileSet clone() {
return new ClassfileSet(isReference()
? (ClassfileSet) (getRef(getProject())) : this);
}
+ @Override
protected synchronized void dieOnCircularReference(Stack<Object> stk, Project p) {
if (isChecked()) {
return;
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/depend/DependScanner.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/depend/DependScanner.java b/src/main/org/apache/tools/ant/types/optional/depend/DependScanner.java
index bb3cf54..5ea51c7 100644
--- a/src/main/org/apache/tools/ant/types/optional/depend/DependScanner.java
+++ b/src/main/org/apache/tools/ant/types/optional/depend/DependScanner.java
@@ -19,8 +19,10 @@ package org.apache.tools.ant.types.optional.depend;
import java.io.File;
import java.util.Enumeration;
-import java.util.Hashtable;
+import java.util.Set;
import java.util.Vector;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
@@ -48,7 +50,7 @@ public class DependScanner extends DirectoryScanner {
*/
private Vector<String> included;
- private Vector<File> additionalBaseDirs = new Vector<File>();
+ private Vector<File> additionalBaseDirs = new Vector<>();
/**
* The parent scanner which gives the basic set of files. Only files which
@@ -82,15 +84,13 @@ public class DependScanner extends DirectoryScanner {
*
* @return the names of the files.
*/
+ @Override
public String[] getIncludedFiles() {
- String[] files = new String[getIncludedFilesCount()];
- for (int i = 0; i < files.length; i++) {
- files[i] = (String) included.elementAt(i);
- }
- return files;
+ return included.toArray(new String[getIncludedFilesCount()]);
}
/** {@inheritDoc}. */
+ @Override
public synchronized int getIncludedFilesCount() {
if (included == null) {
throw new IllegalStateException();
@@ -103,12 +103,14 @@ public class DependScanner extends DirectoryScanner {
*
* @exception IllegalStateException when basedir was set incorrectly.
*/
+ @Override
public synchronized void scan() throws IllegalStateException {
- included = new Vector<String>();
+ included = new Vector<>();
String analyzerClassName = DEFAULT_ANALYZER_CLASS;
- DependencyAnalyzer analyzer = null;
+ DependencyAnalyzer analyzer;
try {
- Class<? extends DependencyAnalyzer> analyzerClass = Class.forName(analyzerClassName)
+ Class<? extends DependencyAnalyzer> analyzerClass =
+ Class.forName(analyzerClassName)
.asSubclass(DependencyAnalyzer.class);
analyzer = analyzerClass.newInstance();
} catch (Exception e) {
@@ -116,28 +118,22 @@ public class DependScanner extends DirectoryScanner {
+ analyzerClassName, e);
}
analyzer.addClassPath(new Path(null, basedir.getPath()));
- for (Enumeration<File> e = additionalBaseDirs.elements(); e.hasMoreElements();) {
- File additionalBaseDir = e.nextElement();
- analyzer.addClassPath(new Path(null, additionalBaseDir.getPath()));
- }
+ additionalBaseDirs.stream().map(File::getPath)
+ .map(p -> new Path(null, p)).forEach(analyzer::addClassPath);
- for (Enumeration<String> e = rootClasses.elements(); e.hasMoreElements();) {
- String rootClass = e.nextElement();
- analyzer.addRootClass(rootClass);
- }
- Enumeration<String> e = analyzer.getClassDependencies();
+ rootClasses.forEach(analyzer::addRootClass);
- String[] parentFiles = parentScanner.getIncludedFiles();
- Hashtable<String, String> parentSet = new Hashtable<String, String>();
- for (int i = 0; i < parentFiles.length; ++i) {
- parentSet.put(parentFiles[i], parentFiles[i]);
- }
+ Set<String> parentSet = Stream.of(parentScanner.getIncludedFiles())
+ .collect(Collectors.toSet());
+
+ Enumeration<String> e = analyzer.getClassDependencies();
+
while (e.hasMoreElements()) {
- String classname = (String) e.nextElement();
- String filename = classname.replace('.', File.separatorChar);
- filename = filename + ".class";
+ String classname = e.nextElement();
+ String filename =
+ classname.replace('.', File.separatorChar) + ".class";
File depFile = new File(basedir, filename);
- if (depFile.exists() && parentSet.containsKey(filename)) {
+ if (depFile.exists() && parentSet.contains(filename)) {
// This is included
included.addElement(filename);
}
@@ -147,6 +143,7 @@ public class DependScanner extends DirectoryScanner {
/**
* @see DirectoryScanner#addDefaultExcludes
*/
+ @Override
public void addDefaultExcludes() {
}
@@ -154,6 +151,7 @@ public class DependScanner extends DirectoryScanner {
* @see DirectoryScanner#getExcludedDirectories
*/
/** {@inheritDoc}. */
+ @Override
public String[] getExcludedDirectories() {
return null;
}
@@ -162,6 +160,7 @@ public class DependScanner extends DirectoryScanner {
* @see DirectoryScanner#getExcludedFiles
*/
/** {@inheritDoc}. */
+ @Override
public String[] getExcludedFiles() {
return null;
}
@@ -170,6 +169,7 @@ public class DependScanner extends DirectoryScanner {
* @see DirectoryScanner#getIncludedDirectories
*/
/** {@inheritDoc}. */
+ @Override
public String[] getIncludedDirectories() {
return new String[0];
}
@@ -178,6 +178,7 @@ public class DependScanner extends DirectoryScanner {
* @see DirectoryScanner#getIncludedDirsCount
*/
/** {@inheritDoc}. */
+ @Override
public int getIncludedDirsCount() {
return 0;
}
@@ -186,6 +187,7 @@ public class DependScanner extends DirectoryScanner {
* @see DirectoryScanner#getNotIncludedDirectories
*/
/** {@inheritDoc}. */
+ @Override
public String[] getNotIncludedDirectories() {
return null;
}
@@ -194,6 +196,7 @@ public class DependScanner extends DirectoryScanner {
* @see DirectoryScanner#getNotIncludedFiles
*/
/** {@inheritDoc}. */
+ @Override
public String[] getNotIncludedFiles() {
return null;
}
@@ -202,6 +205,7 @@ public class DependScanner extends DirectoryScanner {
* @see DirectoryScanner#setExcludes
*/
/** {@inheritDoc}. */
+ @Override
public void setExcludes(String[] excludes) {
}
@@ -209,6 +213,7 @@ public class DependScanner extends DirectoryScanner {
* @see DirectoryScanner#setIncludes
*/
/** {@inheritDoc}. */
+ @Override
public void setIncludes(String[] includes) {
}
@@ -216,6 +221,7 @@ public class DependScanner extends DirectoryScanner {
* @see DirectoryScanner#setCaseSensitive
*/
/** {@inheritDoc}. */
+ @Override
public void setCaseSensitive(boolean isCaseSensitive) {
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/image/Arc.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/image/Arc.java b/src/main/org/apache/tools/ant/types/optional/image/Arc.java
index 3d8b29b..a1d4709 100644
--- a/src/main/org/apache/tools/ant/types/optional/image/Arc.java
+++ b/src/main/org/apache/tools/ant/types/optional/image/Arc.java
@@ -74,23 +74,24 @@ public class Arc extends BasicShape implements DrawOperation {
* @todo refactor using an EnumeratedAttribute
*/
public void setType(String strType) {
- if (strType.equalsIgnoreCase("open")) {
+ if ("open".equalsIgnoreCase(strType)) {
type = Arc2D.OPEN;
- } else if (strType.equalsIgnoreCase("pie")) {
+ } else if ("pie".equalsIgnoreCase(strType)) {
type = Arc2D.PIE;
- } else if (strType.equalsIgnoreCase("chord")) {
+ } else if ("chord".equalsIgnoreCase(strType)) {
type = Arc2D.CHORD;
}
}
/** {@inheritDoc}. */
+ @Override
public PlanarImage executeDrawOperation() {
BufferedImage bi = new BufferedImage(width + (stroke_width * 2),
height + (stroke_width * 2), BufferedImage.TYPE_4BYTE_ABGR_PRE);
- Graphics2D graphics = (Graphics2D) bi.getGraphics();
+ Graphics2D graphics = bi.createGraphics();
- if (!stroke.equals("transparent")) {
+ if (!"transparent".equalsIgnoreCase(stroke)) {
BasicStroke bStroke = new BasicStroke(stroke_width);
graphics.setColor(ColorMapper.getColorByName(stroke));
graphics.setStroke(bStroke);
@@ -98,24 +99,21 @@ public class Arc extends BasicShape implements DrawOperation {
height, start, stop, type));
}
- if (!fill.equals("transparent")) {
+ if (!"transparent".equalsIgnoreCase(fill)) {
graphics.setColor(ColorMapper.getColorByName(fill));
graphics.fill(new Arc2D.Double(stroke_width, stroke_width,
width, height, start, stop, type));
}
-
- final int size = instructions.size();
- for (int i = 0; i < size; i++) {
- ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
+ for (ImageOperation instr : instructions) {
if (instr instanceof DrawOperation) {
PlanarImage img = ((DrawOperation) instr).executeDrawOperation();
graphics.drawImage(img.getAsBufferedImage(), null, 0, 0);
} else if (instr instanceof TransformOperation) {
- graphics = (Graphics2D) bi.getGraphics();
PlanarImage image = ((TransformOperation) instr)
.executeTransformOperation(PlanarImage.wrapRenderedImage(bi));
bi = image.getAsBufferedImage();
+ graphics = bi.createGraphics();
}
}
return PlanarImage.wrapRenderedImage(bi);
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/image/ColorMapper.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/image/ColorMapper.java b/src/main/org/apache/tools/ant/types/optional/image/ColorMapper.java
index 88e2871..14470fd 100644
--- a/src/main/org/apache/tools/ant/types/optional/image/ColorMapper.java
+++ b/src/main/org/apache/tools/ant/types/optional/image/ColorMapper.java
@@ -24,9 +24,6 @@ import java.awt.Color;
* @see org.apache.tools.ant.taskdefs.optional.image.Image
*/
public final class ColorMapper {
- /** private constructor for Utility class */
- private ColorMapper() {
- }
/** black string */
public static final String COLOR_BLACK = "black";
@@ -69,34 +66,42 @@ public final class ColorMapper {
* @todo refactor to use an EnumeratedAttribute (maybe?)
*/
public static Color getColorByName(String colorName) {
- if (colorName.equalsIgnoreCase(COLOR_BLACK)) {
- return Color.black;
- } else if (colorName.equalsIgnoreCase(COLOR_BLUE)) {
+ switch (colorName.toLowerCase()) {
+ case COLOR_BLUE:
return Color.blue;
- } else if (colorName.equalsIgnoreCase(COLOR_CYAN)) {
+ case COLOR_CYAN:
return Color.cyan;
- } else if (colorName.equalsIgnoreCase(COLOR_DARKGRAY) || colorName.equalsIgnoreCase(COLOR_DARKGREY)) {
+ case COLOR_DARKGRAY:
+ case COLOR_DARKGREY:
return Color.darkGray;
- } else if (colorName.equalsIgnoreCase(COLOR_GRAY) || colorName.equalsIgnoreCase(COLOR_GREY)) {
+ case COLOR_GRAY:
+ case COLOR_GREY:
return Color.gray;
- } else if (colorName.equalsIgnoreCase(COLOR_LIGHTGRAY) || colorName.equalsIgnoreCase(COLOR_LIGHTGREY)) {
+ case COLOR_LIGHTGRAY:
+ case COLOR_LIGHTGREY:
return Color.lightGray;
- } else if (colorName.equalsIgnoreCase(COLOR_GREEN)) {
+ case COLOR_GREEN:
return Color.green;
- } else if (colorName.equalsIgnoreCase(COLOR_MAGENTA)) {
+ case COLOR_MAGENTA:
return Color.magenta;
- } else if (colorName.equalsIgnoreCase(COLOR_ORANGE)) {
+ case COLOR_ORANGE:
return Color.orange;
- } else if (colorName.equalsIgnoreCase(COLOR_PINK)) {
+ case COLOR_PINK:
return Color.pink;
- } else if (colorName.equalsIgnoreCase(COLOR_RED)) {
+ case COLOR_RED:
return Color.red;
- } else if (colorName.equalsIgnoreCase(COLOR_WHITE)) {
+ case COLOR_WHITE:
return Color.white;
- } else if (colorName.equalsIgnoreCase(COLOR_YELLOW)) {
+ case COLOR_YELLOW:
return Color.yellow;
+ case COLOR_BLACK:
+ default:
+ return Color.black;
}
- return Color.black;
+ }
+
+ /** private constructor for Utility class */
+ private ColorMapper() {
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/image/Draw.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/image/Draw.java b/src/main/org/apache/tools/ant/types/optional/image/Draw.java
index 2f097d5..b2cfab9 100644
--- a/src/main/org/apache/tools/ant/types/optional/image/Draw.java
+++ b/src/main/org/apache/tools/ant/types/optional/image/Draw.java
@@ -49,11 +49,13 @@ public class Draw extends TransformOperation {
}
/** {@inheritDoc}. */
+ @Override
public void addRectangle(Rectangle rect) {
instructions.add(rect);
}
/** {@inheritDoc}. */
+ @Override
public void addText(Text text) {
instructions.add(text);
}
@@ -75,13 +77,12 @@ public class Draw extends TransformOperation {
}
/** {@inheritDoc}. */
+ @Override
public PlanarImage executeTransformOperation(PlanarImage image) {
BufferedImage bi = image.getAsBufferedImage();
- Graphics2D graphics = (Graphics2D) bi.getGraphics();
+ Graphics2D graphics = bi.createGraphics();
- final int size = instructions.size();
- for (int i = 0; i < size; i++) {
- ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
+ for (ImageOperation instr : instructions) {
if (instr instanceof DrawOperation) {
PlanarImage op = ((DrawOperation) instr).executeDrawOperation();
log("\tDrawing to x=" + xloc + " y=" + yloc);
@@ -92,11 +93,8 @@ public class Draw extends TransformOperation {
BufferedImage child = op.getAsBufferedImage();
log("\tDrawing to x=" + xloc + " y=" + yloc);
graphics.drawImage(child, null, xloc, yloc);
- PlanarImage.wrapRenderedImage(bi);
}
}
- image = PlanarImage.wrapRenderedImage(bi);
-
- return image;
+ return PlanarImage.wrapRenderedImage(bi);
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/image/Ellipse.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/image/Ellipse.java b/src/main/org/apache/tools/ant/types/optional/image/Ellipse.java
index 9924d90..46a3b8b 100644
--- a/src/main/org/apache/tools/ant/types/optional/image/Ellipse.java
+++ b/src/main/org/apache/tools/ant/types/optional/image/Ellipse.java
@@ -51,35 +51,33 @@ public class Ellipse extends BasicShape implements DrawOperation {
}
/** {@inheritDoc}. */
+ @Override
public PlanarImage executeDrawOperation() {
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE);
- Graphics2D graphics = (Graphics2D) bi.getGraphics();
+ Graphics2D graphics = bi.createGraphics();
- if (!stroke.equals("transparent")) {
+ if (!"transparent".equalsIgnoreCase(stroke)) {
BasicStroke bStroke = new BasicStroke(stroke_width);
graphics.setColor(ColorMapper.getColorByName(stroke));
graphics.setStroke(bStroke);
graphics.draw(new Ellipse2D.Double(0, 0, width, height));
}
- if (!fill.equals("transparent")) {
+ if (!"transparent".equalsIgnoreCase(fill)) {
graphics.setColor(ColorMapper.getColorByName(fill));
graphics.fill(new Ellipse2D.Double(0, 0, width, height));
}
-
- final int size = instructions.size();
- for (int i = 0; i < size; i++) {
- ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
+ for (ImageOperation instr : instructions) {
if (instr instanceof DrawOperation) {
PlanarImage img = ((DrawOperation) instr).executeDrawOperation();
graphics.drawImage(img.getAsBufferedImage(), null, 0, 0);
} else if (instr instanceof TransformOperation) {
- graphics = (Graphics2D) bi.getGraphics();
PlanarImage image = ((TransformOperation) instr)
.executeTransformOperation(PlanarImage.wrapRenderedImage(bi));
bi = image.getAsBufferedImage();
+ graphics = bi.createGraphics();
}
}
return PlanarImage.wrapRenderedImage(bi);
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/image/ImageOperation.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/image/ImageOperation.java b/src/main/org/apache/tools/ant/types/optional/image/ImageOperation.java
index d72fe04..7ff6af8 100644
--- a/src/main/org/apache/tools/ant/types/optional/image/ImageOperation.java
+++ b/src/main/org/apache/tools/ant/types/optional/image/ImageOperation.java
@@ -27,7 +27,7 @@ import org.apache.tools.ant.types.DataType;
*/
public abstract class ImageOperation extends DataType {
// CheckStyle:VisibilityModifier OFF - bc
- protected Vector<ImageOperation> instructions = new Vector<ImageOperation>();
+ protected Vector<ImageOperation> instructions = new Vector<>();
// CheckStyle:VisibilityModifier ON
/**
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/image/Rectangle.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/image/Rectangle.java b/src/main/org/apache/tools/ant/types/optional/image/Rectangle.java
index e2d5bb1..b15272f 100644
--- a/src/main/org/apache/tools/ant/types/optional/image/Rectangle.java
+++ b/src/main/org/apache/tools/ant/types/optional/image/Rectangle.java
@@ -68,41 +68,39 @@ public class Rectangle extends BasicShape implements DrawOperation {
}
/** {@inheritDoc}. */
+ @Override
public PlanarImage executeDrawOperation() {
log("\tCreating Rectangle w=" + width + " h=" + height + " arcw="
+ arcwidth + " arch=" + archeight);
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE);
- Graphics2D graphics = (Graphics2D) bi.getGraphics();
+ Graphics2D graphics = bi.createGraphics();
- if (!stroke.equals("transparent")) {
+ if (!"transparent".equalsIgnoreCase(stroke)) {
BasicStroke bStroke = new BasicStroke(stroke_width);
graphics.setColor(ColorMapper.getColorByName(stroke));
graphics.setStroke(bStroke);
- if ((arcwidth != 0) || (archeight != 0)) {
- graphics.drawRoundRect(0, 0, width, height, arcwidth, archeight);
- } else {
+ if (arcwidth == 0 && archeight == 0) {
graphics.drawRect(0, 0, width, height);
+ } else {
+ graphics.drawRoundRect(0, 0, width, height, arcwidth, archeight);
}
}
- if (!fill.equals("transparent")) {
+ if (!"transparent".equalsIgnoreCase(fill)) {
graphics.setColor(ColorMapper.getColorByName(fill));
- if ((arcwidth != 0) || (archeight != 0)) {
+ if (arcwidth == 0 && archeight == 0) {
+ graphics.fillRect(stroke_width, stroke_width,
+ width - (stroke_width * 2), height - (stroke_width * 2));
+ } else {
graphics.fillRoundRect(stroke_width, stroke_width,
width - (stroke_width * 2), height - (stroke_width * 2),
arcwidth, archeight);
- } else {
- graphics.fillRect(stroke_width, stroke_width,
- width - (stroke_width * 2), height - (stroke_width * 2));
}
}
-
- final int size = instructions.size();
- for (int i = 0; i < size; i++) {
- ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
+ for (ImageOperation instr : instructions) {
if (instr instanceof DrawOperation) {
PlanarImage img = ((DrawOperation) instr).executeDrawOperation();
graphics.drawImage(img.getAsBufferedImage(), null, 0, 0);
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/image/Rotate.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/image/Rotate.java b/src/main/org/apache/tools/ant/types/optional/image/Rotate.java
index 3013bde..0904ba2 100644
--- a/src/main/org/apache/tools/ant/types/optional/image/Rotate.java
+++ b/src/main/org/apache/tools/ant/types/optional/image/Rotate.java
@@ -67,24 +67,21 @@ public class Rotate extends TransformOperation implements DrawOperation {
* @param image The image to perform the transformation on.
* @return the transformed image.
*/
+ @Override
public PlanarImage executeTransformOperation(PlanarImage image) {
- BufferedImage bi = null;
- final int size = instructions.size();
- for (int i = 0; i < size; i++) {
- ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
+ for (ImageOperation instr : instructions) {
if (instr instanceof DrawOperation) {
// If this TransformOperation has DrawOperation children
// then Rotate the first child and return.
System.out.println("Execing Draws");
PlanarImage op = ((DrawOperation) instr).executeDrawOperation();
- image = performRotate(op);
- return image;
- } else if (instr instanceof TransformOperation) {
- bi = image.getAsBufferedImage();
+ return performRotate(op);
+ }
+ if (instr instanceof TransformOperation) {
+ BufferedImage bi = image.getAsBufferedImage();
System.out.println("Execing Transforms");
image = ((TransformOperation) instr)
.executeTransformOperation(PlanarImage.wrapRenderedImage(bi));
- bi = image.getAsBufferedImage();
}
}
System.out.println("Execing as TransformOperation");
@@ -100,16 +97,14 @@ public class Rotate extends TransformOperation implements DrawOperation {
* ONE image.
* @return the image.
*/
+ @Override
public PlanarImage executeDrawOperation() {
- final int size = instructions.size();
- for (int i = 0; i < size; i++) {
- ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
+ for (ImageOperation instr : instructions) {
if (instr instanceof DrawOperation) {
// If this TransformOperation has DrawOperation children
// then Rotate the first child and return.
PlanarImage op = ((DrawOperation) instr).executeDrawOperation();
- op = performRotate(op);
- return op;
+ return performRotate(op);
}
}
return null;
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/image/Scale.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/image/Scale.java b/src/main/org/apache/tools/ant/types/optional/image/Scale.java
index 532694d..156e47f 100644
--- a/src/main/org/apache/tools/ant/types/optional/image/Scale.java
+++ b/src/main/org/apache/tools/ant/types/optional/image/Scale.java
@@ -41,8 +41,9 @@ public class Scale extends TransformOperation implements DrawOperation {
/** Enumerated class for proportions attribute. */
public static class ProportionsAttribute extends EnumeratedAttribute {
/** {@inheritDoc}. */
+ @Override
public String[] getValues() {
- return new String[] {"ignore", "width", "height", "cover", "fit"};
+ return new String[] { "ignore", "width", "height", "cover", "fit" };
}
}
@@ -76,16 +77,14 @@ public class Scale extends TransformOperation implements DrawOperation {
* @return the value converted from the width string.
*/
public float getWidth() {
- float width = 0.0F;
int percIndex = widthStr.indexOf('%');
if (percIndex > 0) {
- width = Float.parseFloat(widthStr.substring(0, percIndex));
xPercent = true;
+ float width = Float.parseFloat(widthStr.substring(0, percIndex));
return width / HUNDRED;
- } else {
- xPercent = false;
- return Float.parseFloat(widthStr);
}
+ xPercent = false;
+ return Float.parseFloat(widthStr);
}
/**
@@ -95,13 +94,12 @@ public class Scale extends TransformOperation implements DrawOperation {
public float getHeight() {
int percIndex = heightStr.indexOf('%');
if (percIndex > 0) {
- float height = Float.parseFloat(heightStr.substring(0, percIndex));
yPercent = true;
+ float height = Float.parseFloat(heightStr.substring(0, percIndex));
return height / HUNDRED;
- } else {
- yPercent = false;
- return Float.parseFloat(heightStr);
}
+ yPercent = false;
+ return Float.parseFloat(heightStr);
}
/**
@@ -116,10 +114,10 @@ public class Scale extends TransformOperation implements DrawOperation {
float yFl = getHeight();
if (!xPercent) {
- xFl = (xFl / image.getWidth());
+ xFl = xFl / image.getWidth();
}
if (!yPercent) {
- yFl = (yFl / image.getHeight());
+ yFl = yFl / image.getHeight();
}
if ("width".equals(proportions)) {
@@ -134,8 +132,8 @@ public class Scale extends TransformOperation implements DrawOperation {
xFl = yFl;
}
- pb.add(new Float(xFl));
- pb.add(new Float(yFl));
+ pb.add(Float.valueOf(xFl));
+ pb.add(Float.valueOf(yFl));
log("\tScaling to " + (xFl * HUNDRED) + "% x "
+ (yFl * HUNDRED) + "%");
@@ -145,18 +143,16 @@ public class Scale extends TransformOperation implements DrawOperation {
/** {@inheritDoc}. */
+ @Override
public PlanarImage executeTransformOperation(PlanarImage image) {
- BufferedImage bi = null;
- final int size = instructions.size();
- for (int i = 0; i < size; i++) {
- ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
+ for (ImageOperation instr : instructions) {
if (instr instanceof DrawOperation) {
return performScale(image);
- } else if (instr instanceof TransformOperation) {
- bi = image.getAsBufferedImage();
+ }
+ if (instr instanceof TransformOperation) {
+ BufferedImage bi = image.getAsBufferedImage();
image = ((TransformOperation) instr)
.executeTransformOperation(PlanarImage.wrapRenderedImage(bi));
- bi = image.getAsBufferedImage();
}
}
return performScale(image);
@@ -164,10 +160,9 @@ public class Scale extends TransformOperation implements DrawOperation {
/** {@inheritDoc}. */
+ @Override
public PlanarImage executeDrawOperation() {
- final int size = instructions.size();
- for (int i = 0; i < size; i++) {
- ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
+ for (ImageOperation instr : instructions) {
if (instr instanceof DrawOperation) {
PlanarImage image = null;
// If this TransformOperation has DrawOperation children
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/image/Text.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/image/Text.java b/src/main/org/apache/tools/ant/types/optional/image/Text.java
index 869fbac..d862459 100644
--- a/src/main/org/apache/tools/ant/types/optional/image/Text.java
+++ b/src/main/org/apache/tools/ant/types/optional/image/Text.java
@@ -92,6 +92,7 @@ public class Text extends ImageOperation implements DrawOperation {
* Draw the text.
* @return the resultant image.
*/
+ @Override
public PlanarImage executeDrawOperation() {
log("\tCreating Text \"" + strText + "\"");
@@ -100,19 +101,18 @@ public class Text extends ImageOperation implements DrawOperation {
int height = 1;
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE);
- Graphics2D graphics = (Graphics2D) bi.getGraphics();
+ Graphics2D graphics = bi.createGraphics();
graphics.setRenderingHint(
RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(
RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
- Font f = new Font(font, Font.PLAIN, point);
+ Font f = createFont();
FontMetrics fmetrics = graphics.getFontMetrics(f);
height = fmetrics.getMaxAscent() + fmetrics.getMaxDescent();
width = fmetrics.stringWidth(strText);
-
bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE);
- graphics = (Graphics2D) bi.getGraphics();
+ graphics = bi.createGraphics();
graphics.setRenderingHint(
RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
@@ -122,7 +122,17 @@ public class Text extends ImageOperation implements DrawOperation {
graphics.setFont(f);
graphics.setColor(couloir);
graphics.drawString(strText, 0, height - fmetrics.getMaxDescent());
- PlanarImage image = PlanarImage.wrapRenderedImage(bi);
- return image;
+ return PlanarImage.wrapRenderedImage(bi);
+ }
+
+ private Font createFont() {
+ int style = Font.PLAIN;
+ if (bold) {
+ style |= Font.BOLD;
+ }
+ if (italic) {
+ style |= Font.ITALIC;
+ }
+ return new Font(font, style, point);
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/image/TransformOperation.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/image/TransformOperation.java b/src/main/org/apache/tools/ant/types/optional/image/TransformOperation.java
index 896e5d1..3429ba7 100644
--- a/src/main/org/apache/tools/ant/types/optional/image/TransformOperation.java
+++ b/src/main/org/apache/tools/ant/types/optional/image/TransformOperation.java
@@ -32,6 +32,7 @@ public abstract class TransformOperation extends ImageOperation {
public abstract PlanarImage executeTransformOperation(PlanarImage img);
/** {@inheritDoc}. */
+ @Override
public void addRectangle(Rectangle instr) {
instructions.add(instr);
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/optional/xz/XzResource.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/xz/XzResource.java b/src/main/org/apache/tools/ant/types/optional/xz/XzResource.java
index dfd02e7..8f2908e 100644
--- a/src/main/org/apache/tools/ant/types/optional/xz/XzResource.java
+++ b/src/main/org/apache/tools/ant/types/optional/xz/XzResource.java
@@ -20,6 +20,8 @@ package org.apache.tools.ant.types.optional.xz;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+
+import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.resources.CompressedResource;
import org.tukaani.xz.LZMA2Options;
import org.tukaani.xz.XZInputStream;
@@ -43,7 +45,7 @@ public class XzResource extends CompressedResource {
* Constructor with another resource to wrap.
* @param other the resource to wrap.
*/
- public XzResource(org.apache.tools.ant.types.ResourceCollection other) {
+ public XzResource(ResourceCollection other) {
super(other);
}
@@ -53,6 +55,7 @@ public class XzResource extends CompressedResource {
* @return the wrapped stream.
* @throws IOException if there is a problem.
*/
+ @Override
protected InputStream wrapStream(InputStream in) throws IOException {
return new XZInputStream(in);
}
@@ -63,7 +66,8 @@ public class XzResource extends CompressedResource {
* @return the wrapped stream.
* @throws IOException if there is a problem.
*/
- protected OutputStream wrapStream(OutputStream out) throws IOException {
+ @Override
+ protected OutputStream wrapStream(OutputStream out) throws IOException {
return new XZOutputStream(out, new LZMA2Options());
}
@@ -71,6 +75,7 @@ public class XzResource extends CompressedResource {
* Get the name of the compression method.
* @return the string "XZ".
*/
+ @Override
protected String getCompressionName() {
return "XZ";
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/resolver/ApacheCatalog.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resolver/ApacheCatalog.java b/src/main/org/apache/tools/ant/types/resolver/ApacheCatalog.java
index cbf3f3f..6097b83 100644
--- a/src/main/org/apache/tools/ant/types/resolver/ApacheCatalog.java
+++ b/src/main/org/apache/tools/ant/types/resolver/ApacheCatalog.java
@@ -54,6 +54,7 @@ public class ApacheCatalog extends Catalog {
* will be a total of two ApacheCatalog instances, and so on.</p>
* @return the catalog.
*/
+ @Override
protected Catalog newCatalog() {
final ApacheCatalog cat = (ApacheCatalog) super.newCatalog();
cat.setResolver(resolver);
@@ -85,6 +86,7 @@ public class ApacheCatalog extends Catalog {
*
* @param entry The CatalogEntry to process.
*/
+ @Override
public void addEntry(final CatalogEntry entry) {
final int type = entry.getEntryType();
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/resolver/ApacheCatalogResolver.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resolver/ApacheCatalogResolver.java b/src/main/org/apache/tools/ant/types/resolver/ApacheCatalogResolver.java
index 2312d3d..1a7b44c 100644
--- a/src/main/org/apache/tools/ant/types/resolver/ApacheCatalogResolver.java
+++ b/src/main/org/apache/tools/ant/types/resolver/ApacheCatalogResolver.java
@@ -19,7 +19,6 @@
package org.apache.tools.ant.types.resolver;
import java.io.IOException;
-import java.net.MalformedURLException;
import java.net.URL;
import org.apache.tools.ant.BuildException;
@@ -104,7 +103,7 @@ public class ApacheCatalogResolver extends CatalogResolver {
final Catalog catalog = getCatalog();
if (!(catalog instanceof ApacheCatalog)) {
- throw new BuildException("Wrong catalog type found: " + catalog.getClass().getName());
+ throw new BuildException("Wrong catalog type found: %s", catalog.getClass().getName());
}
final ApacheCatalog apacheCatalog = (ApacheCatalog) catalog;
@@ -113,9 +112,7 @@ public class ApacheCatalogResolver extends CatalogResolver {
try {
apacheCatalog.parseCatalog(file);
- } catch (final MalformedURLException ex) {
- throw new BuildException(ex);
- } catch (final IOException ex) {
+ } catch (IOException ex) {
throw new BuildException(ex);
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java b/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java
index 417da9a..d37e5ee 100644
--- a/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java
+++ b/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java
@@ -151,14 +151,10 @@ public abstract class AbstractClasspathResource extends Resource {
return ((Resource) getCheckedRef()).isExists();
}
dieOnCircularReference();
- InputStream is = null;
- try {
- is = getInputStream();
+ try (InputStream is = getInputStream()) {
return is != null;
} catch (IOException ex) {
return false;
- } finally {
- FileUtils.close(is);
}
}
@@ -177,18 +173,21 @@ public abstract class AbstractClasspathResource extends Resource {
return !classLoader.needsCleanup()
? openInputStream(classLoader.getLoader())
: new FilterInputStream(openInputStream(classLoader.getLoader())) {
- public void close() throws IOException {
- FileUtils.close(in);
- classLoader.cleanup();
- }
- protected void finalize() throws Throwable {
- try {
- close();
- } finally {
- super.finalize();
- }
+ @Override
+ public void close() throws IOException {
+ FileUtils.close(in);
+ classLoader.cleanup();
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ try {
+ close();
+ } finally {
+ super.finalize();
}
- };
+ }
+ };
}
/**
@@ -198,10 +197,10 @@ public abstract class AbstractClasspathResource extends Resource {
*/
protected ClassLoaderWithFlag getClassLoader() {
ClassLoader cl = null;
- boolean clNeedsCleanup = false;
if (loader != null) {
cl = (ClassLoader) loader.getReferencedObject();
}
+ boolean clNeedsCleanup = false;
if (cl == null) {
if (getClasspath() != null) {
Path p = getClasspath().concatSystemClasspath("ignore");
@@ -254,8 +253,15 @@ public abstract class AbstractClasspathResource extends Resource {
loader = l;
cleanup = needsCleanup && l instanceof AntClassLoader;
}
- public ClassLoader getLoader() { return loader; }
- public boolean needsCleanup() { return cleanup; }
+
+ public ClassLoader getLoader() {
+ return loader;
+ }
+
+ public boolean needsCleanup() {
+ return cleanup;
+ }
+
public void cleanup() {
if (cleanup) {
((AntClassLoader) loader).cleanup();
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/resources/AbstractResourceCollectionWrapper.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/AbstractResourceCollectionWrapper.java b/src/main/org/apache/tools/ant/types/resources/AbstractResourceCollectionWrapper.java
index 5e4c3a3..b73d99c 100644
--- a/src/main/org/apache/tools/ant/types/resources/AbstractResourceCollectionWrapper.java
+++ b/src/main/org/apache/tools/ant/types/resources/AbstractResourceCollectionWrapper.java
@@ -20,6 +20,7 @@ package org.apache.tools.ant.types.resources;
import java.io.File;
import java.util.Iterator;
import java.util.Stack;
+import java.util.stream.Collectors;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
@@ -85,6 +86,7 @@ public abstract class AbstractResourceCollectionWrapper
* Fulfill the ResourceCollection contract.
* @return an Iterator of Resources.
*/
+ @Override
public final synchronized Iterator<Resource> iterator() {
if (isReference()) {
return ((AbstractResourceCollectionWrapper) getCheckedRef()).iterator();
@@ -107,6 +109,7 @@ public abstract class AbstractResourceCollectionWrapper
* Fulfill the ResourceCollection contract.
* @return number of elements as int.
*/
+ @Override
public synchronized int size() {
if (isReference()) {
return ((AbstractResourceCollectionWrapper) getCheckedRef()).size();
@@ -182,24 +185,19 @@ public abstract class AbstractResourceCollectionWrapper
}
/**
- * Format this BaseResourceCollectionWrapper as a String.
+ * Format this AbstractResourceCollectionWrapper as a String.
* @return a descriptive <code>String</code>.
*/
+ @Override
public synchronized String toString() {
if (isReference()) {
return getCheckedRef().toString();
}
- if (getSize() == 0) {
+ if (isEmpty()) {
return "";
}
- StringBuilder sb = new StringBuilder();
- for (Resource resource : this) {
- if (sb.length() > 0) {
- sb.append(File.pathSeparatorChar);
- }
- sb.append(resource);
- }
- return sb.toString();
+ return stream().map(Object::toString)
+ .collect(Collectors.joining(File.pathSeparator));
}
private BuildException oneNested() {
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/resources/AllButFirst.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/AllButFirst.java b/src/main/org/apache/tools/ant/types/resources/AllButFirst.java
index ffa665f..f6bcf49 100644
--- a/src/main/org/apache/tools/ant/types/resources/AllButFirst.java
+++ b/src/main/org/apache/tools/ant/types/resources/AllButFirst.java
@@ -17,10 +17,8 @@
*/
package org.apache.tools.ant.types.resources;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
+import java.util.stream.Collectors;
import org.apache.tools.ant.types.Resource;
@@ -36,25 +34,15 @@ public class AllButFirst extends SizeLimitCollection {
* Take all elements except for the first <code>count</code> elements.
* @return a Collection of Resources.
*/
+ @Override
protected Collection<Resource> getCollection() {
- int ct = getValidCount();
- Iterator<Resource> iter = getResourceCollection().iterator();
- List<Resource> al = new ArrayList<Resource>();
- for (int i = 0; i < ct && iter.hasNext(); i++) {
- // discard
- iter.next();
- }
- while (iter.hasNext()) {
- al.add(iter.next());
- }
- return al;
+ return getResourceCollection().stream().skip(getValidCount())
+ .collect(Collectors.toList());
}
@Override
public synchronized int size() {
- int sz = getResourceCollection().size();
- int ct = getValidCount();
- return sz > ct ? sz - ct : 0;
+ return (int) getResourceCollection().stream().skip(getValidCount()).count();
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/resources/AllButLast.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/AllButLast.java b/src/main/org/apache/tools/ant/types/resources/AllButLast.java
index a1e6a98..03f665e 100644
--- a/src/main/org/apache/tools/ant/types/resources/AllButLast.java
+++ b/src/main/org/apache/tools/ant/types/resources/AllButLast.java
@@ -18,10 +18,11 @@
package org.apache.tools.ant.types.resources;
import java.util.Collection;
-import java.util.List;
+import java.util.Collections;
+import java.util.stream.Collectors;
import org.apache.tools.ant.types.Resource;
-import org.apache.tools.ant.util.CollectionUtils;
+import org.apache.tools.ant.types.ResourceCollection;
/**
* ResourceCollection that contains all resources of another
@@ -35,19 +36,20 @@ public class AllButLast extends SizeLimitCollection {
* Take all elements except for the last <code>count</code> elements.
* @return a Collection of Resources.
*/
+ @Override
protected Collection<Resource> getCollection() {
int ct = getValidCount();
- List<Resource> result =
- (List<Resource>) CollectionUtils.asCollection(getResourceCollection()
- .iterator());
- return result.subList(0, result.size() - ct);
+ ResourceCollection nested = getResourceCollection();
+ if (ct > nested.size()) {
+ return Collections.emptyList();
+ }
+ return nested.stream().limit((long) nested.size() - ct)
+ .collect(Collectors.toList());
}
@Override
public synchronized int size() {
- int sz = getResourceCollection().size();
- int ct = getValidCount();
- return sz > ct ? sz - ct : 0;
+ return Math.max(getResourceCollection().size() - getValidCount(), 0);
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/resources/ArchiveResource.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/ArchiveResource.java b/src/main/org/apache/tools/ant/types/resources/ArchiveResource.java
index 09ce032..9fe16ab 100644
--- a/src/main/org/apache/tools/ant/types/resources/ArchiveResource.java
+++ b/src/main/org/apache/tools/ant/types/resources/ArchiveResource.java
@@ -103,12 +103,12 @@ public abstract class ArchiveResource extends Resource {
public void addConfigured(ResourceCollection a) {
checkChildrenAllowed();
if (archive != null) {
- throw new BuildException("you must not specify more than one"
- + " archive");
+ throw new BuildException(
+ "you must not specify more than one archive");
}
if (a.size() != 1) {
- throw new BuildException("only single argument resource collections"
- + " are supported as archives");
+ throw new BuildException(
+ "only single argument resource collections are supported as archives");
}
archive = a.iterator().next();
}
@@ -118,17 +118,17 @@ public abstract class ArchiveResource extends Resource {
* @return the archive as a Resource.
*/
public Resource getArchive() {
- return isReference()
- ? ((ArchiveResource) getCheckedRef()).getArchive() : archive;
+ return isReference() ? getCheckedRef().getArchive() : archive;
}
/**
* Get the last modified date of this Resource.
* @return the last modification date.
*/
+ @Override
public long getLastModified() {
if (isReference()) {
- return ((Resource) getCheckedRef()).getLastModified();
+ return getCheckedRef().getLastModified();
}
checkEntry();
return super.getLastModified();
@@ -138,9 +138,10 @@ public abstract class ArchiveResource extends Resource {
* Get the size of this Resource.
* @return the long size of this Resource.
*/
+ @Override
public long getSize() {
if (isReference()) {
- return ((Resource) getCheckedRef()).getSize();
+ return getCheckedRef().getSize();
}
checkEntry();
return super.getSize();
@@ -150,9 +151,10 @@ public abstract class ArchiveResource extends Resource {
* Learn whether this Resource represents a directory.
* @return boolean flag indicating whether the entry is a directory.
*/
+ @Override
public boolean isDirectory() {
if (isReference()) {
- return ((Resource) getCheckedRef()).isDirectory();
+ return getCheckedRef().isDirectory();
}
checkEntry();
return super.isDirectory();
@@ -162,9 +164,10 @@ public abstract class ArchiveResource extends Resource {
* Find out whether this Resource represents an existing Resource.
* @return boolean existence flag.
*/
+ @Override
public boolean isExists() {
if (isReference()) {
- return ((Resource) getCheckedRef()).isExists();
+ return getCheckedRef().isExists();
}
checkEntry();
return super.isExists();
@@ -176,7 +179,7 @@ public abstract class ArchiveResource extends Resource {
*/
public int getMode() {
if (isReference()) {
- return ((ArchiveResource) getCheckedRef()).getMode();
+ return getCheckedRef().getMode();
}
checkEntry();
return mode;
@@ -186,6 +189,7 @@ public abstract class ArchiveResource extends Resource {
* Overrides the super version.
* @param r the Reference to set.
*/
+ @Override
public void setRefid(Reference r) {
if (archive != null || modeSet) {
throw tooManyAttributes();
@@ -199,6 +203,7 @@ public abstract class ArchiveResource extends Resource {
* @return a negative integer, zero, or a positive integer as this Resource
* is less than, equal to, or greater than the specified Resource.
*/
+ @Override
public int compareTo(Resource another) {
return this.equals(another) ? 0 : super.compareTo(another);
}
@@ -209,6 +214,7 @@ public abstract class ArchiveResource extends Resource {
* @return true if another is a Resource representing
* the same entry in the same archive.
*/
+ @Override
public boolean equals(Object another) {
if (this == another) {
return true;
@@ -216,7 +222,7 @@ public abstract class ArchiveResource extends Resource {
if (isReference()) {
return getCheckedRef().equals(another);
}
- if (another == null || another.getClass() != getClass()) {
+ if (another == null || !another.getClass().equals(getClass())) {
return false;
}
ArchiveResource r = (ArchiveResource) another;
@@ -228,6 +234,7 @@ public abstract class ArchiveResource extends Resource {
* Get the hash code for this Resource.
* @return hash code as int.
*/
+ @Override
public int hashCode() {
return super.hashCode()
* (getArchive() == null ? NULL_ARCHIVE : getArchive().hashCode());
@@ -237,6 +244,7 @@ public abstract class ArchiveResource extends Resource {
* Format this Resource as a String.
* @return String representatation of this Resource.
*/
+ @Override
public String toString() {
return isReference() ? getCheckedRef().toString()
: getArchive().toString() + ':' + getName();
@@ -260,10 +268,10 @@ public abstract class ArchiveResource extends Resource {
throw new BuildException("archive attribute not set");
}
if (!r.isExists()) {
- throw new BuildException(r.toString() + " does not exist.");
+ throw new BuildException("%s does not exist.", r);
}
if (r.isDirectory()) {
- throw new BuildException(r + " denotes a directory.");
+ throw new BuildException("%s denotes a directory.", r);
}
fetchEntry();
haveEntry = true;
@@ -277,6 +285,7 @@ public abstract class ArchiveResource extends Resource {
/**
* {@inheritDoc}
*/
+ @Override
protected synchronized void dieOnCircularReference(Stack<Object> stk, Project p) {
if (isChecked()) {
return;
@@ -290,4 +299,9 @@ public abstract class ArchiveResource extends Resource {
setChecked(true);
}
}
+
+ @Override
+ protected ArchiveResource getCheckedRef() {
+ return (ArchiveResource) super.getCheckedRef();
+ }
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/resources/Archives.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/Archives.java b/src/main/org/apache/tools/ant/types/resources/Archives.java
index 4b0d51c..f47676f 100644
--- a/src/main/org/apache/tools/ant/types/resources/Archives.java
+++ b/src/main/org/apache/tools/ant/types/resources/Archives.java
@@ -21,6 +21,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
+import java.util.stream.Stream;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
@@ -31,7 +32,6 @@ import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.TarFileSet;
import org.apache.tools.ant.types.ZipFileSet;
-import org.apache.tools.ant.util.CollectionUtils;
/**
* A resource collection that treats all nested resources as archives
@@ -72,16 +72,13 @@ public class Archives extends DataType
/**
* Sums the sizes of nested archives.
*/
+ @Override
public int size() {
if (isReference()) {
- return ((Archives) getCheckedRef()).size();
+ return getCheckedRef().size();
}
dieOnCircularReference();
- int total = 0;
- for (final Iterator<ArchiveFileSet> i = grabArchives(); i.hasNext();) {
- total += i.next().size();
- }
- return total;
+ return streamArchives().mapToInt(ArchiveFileSet::size).sum();
}
/**
@@ -89,15 +86,11 @@ public class Archives extends DataType
*/
public Iterator<Resource> iterator() {
if (isReference()) {
- return ((Archives) getCheckedRef()).iterator();
+ return getCheckedRef().iterator();
}
dieOnCircularReference();
- final List<Resource> l = new LinkedList<Resource>();
- for (final Iterator<ArchiveFileSet> i = grabArchives(); i.hasNext();) {
- l.addAll(CollectionUtils
- .asCollection(i.next().iterator()));
- }
- return l.iterator();
+ return streamArchives().flatMap(ResourceCollection::stream)
+ .map(Resource.class::cast).iterator();
}
/**
@@ -105,9 +98,10 @@ public class Archives extends DataType
*/
public boolean isFilesystemOnly() {
if (isReference()) {
- return ((Archives) getCheckedRef()).isFilesystemOnly();
+ return getCheckedRef().isFilesystemOnly();
}
dieOnCircularReference();
+ // TODO check each archive in turn?
return false;
}
@@ -117,8 +111,8 @@ public class Archives extends DataType
*/
@Override
public void setRefid(final Reference r) {
- if (zips.getResourceCollections().size() > 0
- || tars.getResourceCollections().size() > 0) {
+ if (!(zips.getResourceCollections().isEmpty()
+ && tars.getResourceCollections().isEmpty())) {
throw tooManyAttributes();
}
super.setRefid(r);
@@ -130,7 +124,7 @@ public class Archives extends DataType
* @return a cloned instance.
*/
@Override
- public Object clone() {
+ public Archives clone() {
try {
final Archives a = (Archives) super.clone();
a.zips = (Union) zips.clone();
@@ -148,14 +142,20 @@ public class Archives extends DataType
* and returns an iterator over the collected archives.
*/
protected Iterator<ArchiveFileSet> grabArchives() {
- final List<ArchiveFileSet> l = new LinkedList<ArchiveFileSet>();
+ return streamArchives().iterator();
+ }
+
+ // TODO this is a pretty expensive operation and so the result
+ // should be cached.
+ private Stream<ArchiveFileSet> streamArchives() {
+ final List<ArchiveFileSet> l = new LinkedList<>();
for (final Resource r : zips) {
l.add(configureArchive(new ZipFileSet(), r));
}
for (final Resource r : tars) {
l.add(configureArchive(new TarFileSet(), r));
}
- return l.iterator();
+ return l.stream();
}
/**
@@ -190,5 +190,10 @@ public class Archives extends DataType
setChecked(true);
}
}
+
+ @Override
+ protected Archives getCheckedRef() {
+ return (Archives) super.getCheckedRef();
+ }
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/resources/BCFileSet.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/BCFileSet.java b/src/main/org/apache/tools/ant/types/resources/BCFileSet.java
index aa99a4a..6d8aaf8 100644
--- a/src/main/org/apache/tools/ant/types/resources/BCFileSet.java
+++ b/src/main/org/apache/tools/ant/types/resources/BCFileSet.java
@@ -47,6 +47,7 @@ public class BCFileSet extends FileSet {
* @return an Iterator of Resources.
* @since Ant 1.7
*/
+ @Override
public Iterator<Resource> iterator() {
if (isReference()) {
return ((FileSet) getRef(getProject())).iterator();
@@ -62,6 +63,7 @@ public class BCFileSet extends FileSet {
* @return number of elements as int.
* @since Ant 1.7
*/
+ @Override
public int size() {
if (isReference()) {
return ((FileSet) getRef(getProject())).size();
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/resources/BZip2Resource.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/BZip2Resource.java b/src/main/org/apache/tools/ant/types/resources/BZip2Resource.java
index 0c2dd4b..787407b 100644
--- a/src/main/org/apache/tools/ant/types/resources/BZip2Resource.java
+++ b/src/main/org/apache/tools/ant/types/resources/BZip2Resource.java
@@ -53,6 +53,7 @@ public class BZip2Resource extends CompressedResource {
* @return the wrapped stream.
* @throws IOException if there is a problem.
*/
+ @Override
protected InputStream wrapStream(InputStream in) throws IOException {
for (int i = 0; i < MAGIC.length; i++) {
if (in.read() != MAGIC[i]) {
@@ -68,6 +69,7 @@ public class BZip2Resource extends CompressedResource {
* @return the wrapped stream.
* @throws IOException if there is a problem.
*/
+ @Override
protected OutputStream wrapStream(OutputStream out) throws IOException {
for (int i = 0; i < MAGIC.length; i++) {
out.write(MAGIC[i]);
@@ -79,6 +81,7 @@ public class BZip2Resource extends CompressedResource {
* Get the name of the compression method.
* @return the string "Bzip2".
*/
+ @Override
protected String getCompressionName() {
return "Bzip2";
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java b/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java
index 281fa0f..e394ba9 100644
--- a/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java
+++ b/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java
@@ -24,6 +24,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
+import java.util.stream.Collectors;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
@@ -37,7 +38,7 @@ import org.apache.tools.ant.types.ResourceCollection;
*/
public abstract class BaseResourceCollectionContainer
extends DataType implements ResourceCollection, Cloneable {
- private List<ResourceCollection> rc = new ArrayList<ResourceCollection>();
+ private List<ResourceCollection> rc = new ArrayList<>();
private Collection<Resource> coll = null;
private boolean cache = true;
@@ -45,7 +46,6 @@ public abstract class BaseResourceCollectionContainer
* Create a new BaseResourceCollectionContainer.
*/
public BaseResourceCollectionContainer() {
- // TODO Auto-generated constructor stub
}
/**
@@ -120,9 +120,7 @@ public abstract class BaseResourceCollectionContainer
throw noChildrenAllowed();
}
try {
- for (ResourceCollection resourceCollection : c) {
- add(resourceCollection);
- }
+ c.forEach(this::add);
} catch (ClassCastException e) {
throw new BuildException(e);
}
@@ -134,9 +132,10 @@ public abstract class BaseResourceCollectionContainer
* are added to this container while the Iterator is in use.
* @return a "fail-fast" Iterator.
*/
+ @Override
public final synchronized Iterator<Resource> iterator() {
if (isReference()) {
- return ((BaseResourceCollectionContainer) getCheckedRef()).iterator();
+ return getCheckedRef().iterator();
}
dieOnCircularReference();
return new FailFast(this, cacheCollection().iterator());
@@ -146,9 +145,11 @@ public abstract class BaseResourceCollectionContainer
* Fulfill the ResourceCollection contract.
* @return number of elements as int.
*/
+ @Override
public synchronized int size() {
if (isReference()) {
- return getCheckedRef(BaseResourceCollectionContainer.class, getDataTypeName()).size();
+ return getCheckedRef(BaseResourceCollectionContainer.class,
+ getDataTypeName()).size();
}
dieOnCircularReference();
return cacheCollection().size();
@@ -158,27 +159,20 @@ public abstract class BaseResourceCollectionContainer
* Fulfill the ResourceCollection contract.
* @return whether this is a filesystem-only resource collection.
*/
+ @Override
public synchronized boolean isFilesystemOnly() {
if (isReference()) {
- return ((BaseResourceCollectionContainer) getCheckedRef()).isFilesystemOnly();
+ return getCheckedRef().isFilesystemOnly();
}
dieOnCircularReference();
//first the easy way, if all children are filesystem-only, return true:
- boolean goEarly = true;
- for (Iterator<ResourceCollection> i = rc.iterator(); goEarly && i.hasNext();) {
- goEarly = i.next().isFilesystemOnly();
- }
- if (goEarly) {
+ if (rc.stream().allMatch(ResourceCollection::isFilesystemOnly)) {
return true;
}
/* now check each Resource in case the child only
lets through files from any children IT may have: */
- for (Resource r : cacheCollection()) {
- if (r.as(FileProvider.class) == null) {
- return false;
- }
- }
- return true;
+ return cacheCollection().stream()
+ .allMatch(r -> r.asOptional(FileProvider.class).isPresent());
}
/**
@@ -225,11 +219,12 @@ public abstract class BaseResourceCollectionContainer
* collections is shallowly cloned.
* @return a cloned instance.
*/
- public Object clone() {
+ @Override
+ public BaseResourceCollectionContainer clone() {
try {
BaseResourceCollectionContainer c
= (BaseResourceCollectionContainer) super.clone();
- c.rc = new ArrayList<ResourceCollection>(rc);
+ c.rc = new ArrayList<>(rc);
c.coll = null;
return c;
} catch (CloneNotSupportedException e) {
@@ -241,21 +236,21 @@ public abstract class BaseResourceCollectionContainer
* Format this BaseResourceCollectionContainer as a String.
* @return a descriptive <code>String</code>.
*/
+ @Override
public synchronized String toString() {
if (isReference()) {
return getCheckedRef().toString();
}
- if (cacheCollection().size() == 0) {
+ if (cacheCollection().isEmpty()) {
return "";
}
- StringBuilder sb = new StringBuilder();
- for (Resource resource : coll) {
- if (sb.length() > 0) {
- sb.append(File.pathSeparatorChar);
- }
- sb.append(resource);
- }
- return sb.toString();
+ return coll.stream().map(Object::toString)
+ .collect(Collectors.joining(File.pathSeparator));
+ }
+
+ @Override
+ protected BaseResourceCollectionContainer getCheckedRef() {
+ return (BaseResourceCollectionContainer) super.getCheckedRef();
}
private synchronized Collection<Resource> cacheCollection() {
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionWrapper.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionWrapper.java b/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionWrapper.java
index 78ba95e..0bec29f 100644
--- a/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionWrapper.java
+++ b/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionWrapper.java
@@ -32,10 +32,12 @@ public abstract class BaseResourceCollectionWrapper
private Collection<Resource> coll = null;
+ @Override
protected Iterator<Resource> createIterator() {
return cacheCollection().iterator();
}
+ @Override
protected int getSize() {
return cacheCollection().size();
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/resources/CompressedResource.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/CompressedResource.java b/src/main/org/apache/tools/ant/types/resources/CompressedResource.java
index 2c72c26..d77c16c 100644
--- a/src/main/org/apache/tools/ant/types/resources/CompressedResource.java
+++ b/src/main/org/apache/tools/ant/types/resources/CompressedResource.java
@@ -47,6 +47,7 @@ public abstract class CompressedResource extends ContentTransformingResource {
* @return this Resource formatted as a String.
* @since Ant 1.7
*/
+ @Override
public String toString() {
return getCompressionName() + " compressed " + super.toString();
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/resources/ContentTransformingResource.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/ContentTransformingResource.java b/src/main/org/apache/tools/ant/types/resources/ContentTransformingResource.java
index 79445bf..2a00872 100644
--- a/src/main/org/apache/tools/ant/types/resources/ContentTransformingResource.java
+++ b/src/main/org/apache/tools/ant/types/resources/ContentTransformingResource.java
@@ -23,7 +23,6 @@ import java.io.OutputStream;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.ResourceCollection;
-import org.apache.tools.ant.util.FileUtils;
/**
* A resource that transforms the content of another resource.
@@ -58,9 +57,7 @@ public abstract class ContentTransformingResource extends ResourceDecorator {
@Override
public long getSize() {
if (isExists()) {
- InputStream in = null;
- try {
- in = getInputStream();
+ try (InputStream in = getInputStream()) {
final byte[] buf = new byte[BUFFER_SIZE];
int size = 0;
int readNow;
@@ -69,14 +66,11 @@ public abstract class ContentTransformingResource extends ResourceDecorator {
}
return size;
} catch (final IOException ex) {
- throw new BuildException("caught exception while reading "
- + getName(), ex);
- } finally {
- FileUtils.close(in);
+ throw new BuildException(
+ "caught exception while reading " + getName(), ex);
}
- } else {
- return 0;
}
+ return 0;
}
/**
@@ -120,24 +114,16 @@ public abstract class ContentTransformingResource extends ResourceDecorator {
public <T> T as(final Class<T> clazz) {
if (Appendable.class.isAssignableFrom(clazz)) {
if (isAppendSupported()) {
- final Appendable a =
- getResource().as(Appendable.class);
+ final Appendable a = getResource().as(Appendable.class);
if (a != null) {
- return clazz.cast(new Appendable() {
- public OutputStream getAppendOutputStream()
- throws IOException {
- OutputStream out = a.getAppendOutputStream();
- if (out != null) {
- out = wrapStream(out);
- }
- return out;
- }
+ return clazz.cast((Appendable) () -> {
+ OutputStream out = a.getAppendOutputStream();
+ return out == null ? null : wrapStream(out);
});
}
}
return null;
}
-
return FileProvider.class.isAssignableFrom(clazz)
? null : getResource().as(clazz);
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/resources/Difference.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/Difference.java b/src/main/org/apache/tools/ant/types/resources/Difference.java
index 3f3c983..920f9bc 100644
--- a/src/main/org/apache/tools/ant/types/resources/Difference.java
+++ b/src/main/org/apache/tools/ant/types/resources/Difference.java
@@ -38,16 +38,17 @@ public class Difference extends BaseResourceCollectionContainer {
* Calculate the difference of the nested ResourceCollections.
* @return a Collection of Resources.
*/
+ @Override
protected Collection<Resource> getCollection() {
List<ResourceCollection> rcs = getResourceCollections();
int size = rcs.size();
if (size < 2) {
- throw new BuildException("The difference of " + size
- + " resource collection" + ((size == 1) ? "" : "s")
- + " is undefined.");
+ throw new BuildException(
+ "The difference of %d resource %s is undefined.", size,
+ size == 1 ? "collection" : "collections");
}
- Set<Resource> hs = new HashSet<Resource>();
- List<Resource> al = new ArrayList<Resource>();
+ Set<Resource> hs = new HashSet<>();
+ List<Resource> al = new ArrayList<>();
for (ResourceCollection rc : rcs) {
for (Resource r : rc) {
if (hs.add(r)) {
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/resources/FailFast.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/FailFast.java b/src/main/org/apache/tools/ant/types/resources/FailFast.java
index dc962bb..f8da1b9 100644
--- a/src/main/org/apache/tools/ant/types/resources/FailFast.java
+++ b/src/main/org/apache/tools/ant/types/resources/FailFast.java
@@ -32,7 +32,7 @@ import org.apache.tools.ant.types.Resource;
* @since Ant 1.7
*/
/*package-private*/ class FailFast implements Iterator<Resource> {
- private static final WeakHashMap<Object, Set<FailFast>> MAP = new WeakHashMap<Object, Set<FailFast>>();
+ private static final WeakHashMap<Object, Set<FailFast>> MAP = new WeakHashMap<>();
/**
* Invalidate any in-use Iterators from the specified Object.
@@ -46,12 +46,7 @@ import org.apache.tools.ant.types.Resource;
}
private static synchronized void add(FailFast f) {
- Set<FailFast> s = MAP.get(f.parent);
- if (s == null) {
- s = new HashSet<FailFast>();
- MAP.put(f.parent, s);
- }
- s.add(f);
+ MAP.computeIfAbsent(f.parent, k -> new HashSet<>()).add(f);
}
private static synchronized void remove(FailFast f) {
@@ -95,6 +90,7 @@ import org.apache.tools.ant.types.Resource;
* Fulfill the Iterator contract.
* @return true if there are more elements.
*/
+ @Override
public boolean hasNext() {
if (wrapped == null) {
return false;
@@ -108,6 +104,7 @@ import org.apache.tools.ant.types.Resource;
* @return the next element.
* @throws NoSuchElementException if no more elements.
*/
+ @Override
public Resource next() {
if (wrapped == null || !wrapped.hasNext()) {
throw new NoSuchElementException();
@@ -127,6 +124,7 @@ import org.apache.tools.ant.types.Resource;
* Fulfill the Iterator contract.
* @throws UnsupportedOperationException always.
*/
+ @Override
public void remove() {
throw new UnsupportedOperationException();
}