diff --git a/CodenameOne/src/com/codename1/ads/InnerActive.java b/CodenameOne/src/com/codename1/ads/InnerActive.java index 2b65a5d467..5607ca82e9 100644 --- a/CodenameOne/src/com/codename1/ads/InnerActive.java +++ b/CodenameOne/src/com/codename1/ads/InnerActive.java @@ -37,7 +37,7 @@ * * @author Chen */ -public class InnerActive extends AdsService{ +public class InnerActive extends AdsService{ // PMD Fix: UnusedPrivateField removed obsolete field private final String REQUEST_URL = "http://m2m1.inner-active.com/simpleM2M/clientRequestHtmlAd"; @@ -51,9 +51,6 @@ public class InnerActive extends AdsService{ //UDID/IMEI private String hid; - //client Id - private String cid; - private boolean banner = true; private static boolean testAds = true; diff --git a/CodenameOne/src/com/codename1/background/BackgroundFetch.java b/CodenameOne/src/com/codename1/background/BackgroundFetch.java index a989294b80..e6a52784d3 100644 --- a/CodenameOne/src/com/codename1/background/BackgroundFetch.java +++ b/CodenameOne/src/com/codename1/background/BackgroundFetch.java @@ -68,6 +68,6 @@ public interface BackgroundFetch { * @see com.codename1.ui.Display.getPreferredBackgroundFetchInterval() * @see com.codename1.ui.Display.isBackgroundFetchSupported() */ - public void performBackgroundFetch(long deadline, Callback onComplete); + void performBackgroundFetch(long deadline, Callback onComplete); // PMD Fix: UnnecessaryModifier removed } diff --git a/CodenameOne/src/com/codename1/capture/VideoCaptureConstraints.java b/CodenameOne/src/com/codename1/capture/VideoCaptureConstraints.java index 1cb3ab4d4e..42b6c0cb1c 100644 --- a/CodenameOne/src/com/codename1/capture/VideoCaptureConstraints.java +++ b/CodenameOne/src/com/codename1/capture/VideoCaptureConstraints.java @@ -101,8 +101,8 @@ public class VideoCaptureConstraints { * to transfer the "preferred" constraints to corresponding "actual" constraints * based on what the platform supports. */ - public static interface Compiler { - public VideoCaptureConstraints compile(VideoCaptureConstraints cnst); + public interface Compiler { // PMD Fix: UnnecessaryModifier removed implicit static + VideoCaptureConstraints compile(VideoCaptureConstraints cnst); // PMD Fix: UnnecessaryModifier removed redundant public } /** diff --git a/CodenameOne/src/com/codename1/charts/ChartComponent.java b/CodenameOne/src/com/codename1/charts/ChartComponent.java index e20388314b..e48a864f7b 100644 --- a/CodenameOne/src/com/codename1/charts/ChartComponent.java +++ b/CodenameOne/src/com/codename1/charts/ChartComponent.java @@ -536,29 +536,21 @@ public void pointerDragged(int[] x, int[] y) { } double[] zoomLimits = xyChart.getRenderer().getZoomLimits(); - if (zoomLimits != null && zoomLimits[0] != 0) { - if (maxX - minX < zoomLimits[0]) { - maxX = xyChart.getRenderer().getXAxisMax(); - minX = xyChart.getRenderer().getXAxisMin(); - } + if (zoomLimits != null && zoomLimits[0] != 0 && maxX - minX < zoomLimits[0]) { // PMD Fix: CollapsibleIfStatements + maxX = xyChart.getRenderer().getXAxisMax(); + minX = xyChart.getRenderer().getXAxisMin(); } - if (zoomLimits != null && zoomLimits[1] != 0) { - if (maxX - minX > zoomLimits[1]) { - maxX = xyChart.getRenderer().getXAxisMax(); - minX = xyChart.getRenderer().getXAxisMin(); - } + if (zoomLimits != null && zoomLimits[1] != 0 && maxX - minX > zoomLimits[1]) { // PMD Fix: CollapsibleIfStatements + maxX = xyChart.getRenderer().getXAxisMax(); + minX = xyChart.getRenderer().getXAxisMin(); } - if (zoomLimits != null && zoomLimits[2] != 0) { - if (maxY - minY < zoomLimits[2]) { - maxY = xyChart.getRenderer().getYAxisMax(); - minY = xyChart.getRenderer().getYAxisMin(); - } + if (zoomLimits != null && zoomLimits[2] != 0 && maxY - minY < zoomLimits[2]) { // PMD Fix: CollapsibleIfStatements + maxY = xyChart.getRenderer().getYAxisMax(); + minY = xyChart.getRenderer().getYAxisMin(); } - if (zoomLimits != null && zoomLimits[3] != 0) { - if (maxY - minY > zoomLimits[3]) { - maxY = xyChart.getRenderer().getYAxisMax(); - minY = xyChart.getRenderer().getYAxisMin(); - } + if (zoomLimits != null && zoomLimits[3] != 0 && maxY - minY > zoomLimits[3]) { // PMD Fix: CollapsibleIfStatements + maxY = xyChart.getRenderer().getYAxisMax(); + minY = xyChart.getRenderer().getYAxisMin(); } if (!xyChart.getRenderer().isZoomXEnabled()) { @@ -894,7 +886,7 @@ private void zoomTransition(double minX, double maxX, double minY, double maxY, } private interface IZoomTransition { - public void start(); + void start(); } private class ZoomTransition implements Animation, IZoomTransition { diff --git a/CodenameOne/src/com/codename1/charts/compat/GradientDrawable.java b/CodenameOne/src/com/codename1/charts/compat/GradientDrawable.java index 165d2b5f6c..f39fcc2299 100644 --- a/CodenameOne/src/com/codename1/charts/compat/GradientDrawable.java +++ b/CodenameOne/src/com/codename1/charts/compat/GradientDrawable.java @@ -39,7 +39,7 @@ public GradientDrawable(Orientation orientation, int[] colors) { this.colors = colors; } - public static enum Orientation { + public enum Orientation { // PMD Fix: UnnecessaryModifier removed redundant static BL_TR, BOTTOM_TOP, BR_TL, diff --git a/CodenameOne/src/com/codename1/charts/compat/Paint.java b/CodenameOne/src/com/codename1/charts/compat/Paint.java index 4300ca902d..6985bb387b 100644 --- a/CodenameOne/src/com/codename1/charts/compat/Paint.java +++ b/CodenameOne/src/com/codename1/charts/compat/Paint.java @@ -34,11 +34,10 @@ * @author shannah * @deprecated */ -public class Paint { +public class Paint { // PMD Fix: UnusedPrivateField removed redundant antiAlias flag static Graphics g; - private boolean antiAlias; private Font typeface = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL); private int strokeCap = Cap.BUTT; private int strokeJoin = Join.BEVEL; @@ -154,7 +153,7 @@ public float measureText(char[] chars, int start, int count){ public void setAntiAlias(boolean antialiasing) { - this.antiAlias = antialiasing; + // No-op for compatibility. } public Font getTypeface() { @@ -209,7 +208,7 @@ public void setStrokeWidth(float i) { - public static enum Style { + public enum Style { // PMD Fix: UnnecessaryModifier removed redundant static FILL, FILL_AND_STROKE, STROKE diff --git a/CodenameOne/src/com/codename1/charts/models/XYSeries.java b/CodenameOne/src/com/codename1/charts/models/XYSeries.java index b3deecbc86..8ee1b52375 100644 --- a/CodenameOne/src/com/codename1/charts/models/XYSeries.java +++ b/CodenameOne/src/com/codename1/charts/models/XYSeries.java @@ -84,15 +84,14 @@ private void initRange() { mMaxX = MathHelper.NULL_VALUE; mMinY = MathHelper.NULL_VALUE; mMaxY = MathHelper.NULL_VALUE; - int length = getItemCount(); + int length = getItemCount(); // PMD Fix: UnusedLocalVariable removed redundant loop index for (int k = 0; k < length; k++) { double x = getX(k); double y = getY(k); updateRange(x, y); } - int i=0; - } + } /** * Updates the range on both axes. diff --git a/CodenameOne/src/com/codename1/charts/renderers/BasicStroke.java b/CodenameOne/src/com/codename1/charts/renderers/BasicStroke.java index 906f55b627..e4a4f064cf 100644 --- a/CodenameOne/src/com/codename1/charts/renderers/BasicStroke.java +++ b/CodenameOne/src/com/codename1/charts/renderers/BasicStroke.java @@ -51,12 +51,13 @@ public class BasicStroke { * @param intervals the path effect intervals * @param phase the path effect phase */ - public BasicStroke(int cap, int join, float miter, float[] intervals, float phase) { - mCap = cap; - mJoin = join; - mMiter = miter; - mIntervals = intervals; - } + public BasicStroke(int cap, int join, float miter, float[] intervals, float phase) { + mCap = cap; + mJoin = join; + mMiter = miter; + mIntervals = intervals; + mPhase = phase; // PMD Fix: UnusedFormalParameter store constructor argument + } /** * Returns the stroke cap. diff --git a/CodenameOne/src/com/codename1/charts/renderers/DefaultRenderer.java b/CodenameOne/src/com/codename1/charts/renderers/DefaultRenderer.java index 54be110dd0..7a0fdfd471 100644 --- a/CodenameOne/src/com/codename1/charts/renderers/DefaultRenderer.java +++ b/CodenameOne/src/com/codename1/charts/renderers/DefaultRenderer.java @@ -23,7 +23,7 @@ /** * An abstract renderer to be extended by the multiple series classes. */ -public class DefaultRenderer { +public class DefaultRenderer { // PMD Fix: UnusedPrivateField removed unused text font constant /** The chart title. */ private String mChartTitle = ""; /** The chart title text size. */ @@ -34,8 +34,6 @@ public class DefaultRenderer { public static final int BACKGROUND_COLOR = 0x0; /** The default color for text. */ public static final int TEXT_COLOR = 0xEAEAEA; - /** A text font for regular text, like the chart labels. */ - private static final Font REGULAR_TEXT_FONT = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL); /** The typeface name for the texts. */ private int mTextTypefaceName = Font.FACE_SYSTEM; /** The typeface style for the texts. */ diff --git a/CodenameOne/src/com/codename1/charts/renderers/XYMultipleSeriesRenderer.java b/CodenameOne/src/com/codename1/charts/renderers/XYMultipleSeriesRenderer.java index 6dace70358..3f69ef2296 100644 --- a/CodenameOne/src/com/codename1/charts/renderers/XYMultipleSeriesRenderer.java +++ b/CodenameOne/src/com/codename1/charts/renderers/XYMultipleSeriesRenderer.java @@ -121,9 +121,9 @@ public enum Orientation { /** The rotate angle. */ private int mAngle = 0; - private Orientation(int angle) { - mAngle = angle; - } + Orientation(int angle) { // PMD Fix: UnnecessaryModifier removed implicit private keyword + mAngle = angle; + } /** * Return the orientation rotate angle. diff --git a/CodenameOne/src/com/codename1/charts/renderers/XYSeriesRenderer.java b/CodenameOne/src/com/codename1/charts/renderers/XYSeriesRenderer.java index 8ff74d1d6d..a92d32923d 100644 --- a/CodenameOne/src/com/codename1/charts/renderers/XYSeriesRenderer.java +++ b/CodenameOne/src/com/codename1/charts/renderers/XYSeriesRenderer.java @@ -29,7 +29,7 @@ /** * A renderer for the XY type series. */ -public class XYSeriesRenderer extends SimpleSeriesRenderer { +public class XYSeriesRenderer extends SimpleSeriesRenderer { // PMD Fix: UnnecessarySemicolon cleaned extra delimiter /** If the chart points should be filled. */ private boolean mFillPoints = false; /** If the chart should be filled outside its line. */ @@ -61,9 +61,9 @@ public class XYSeriesRenderer extends SimpleSeriesRenderer { * A descriptor for the line fill behavior. */ public static class FillOutsideLine { - public enum Type { - NONE, BOUNDS_ALL, BOUNDS_BELOW, BOUNDS_ABOVE, BELOW, ABOVE - }; + public enum Type { + NONE, BOUNDS_ALL, BOUNDS_BELOW, BOUNDS_ABOVE, BELOW, ABOVE + } /** The fill type. */ private final Type mType; diff --git a/CodenameOne/src/com/codename1/charts/transitions/XYSeriesTransition.java b/CodenameOne/src/com/codename1/charts/transitions/XYSeriesTransition.java index 96f8ce44a1..759281c0fd 100644 --- a/CodenameOne/src/com/codename1/charts/transitions/XYSeriesTransition.java +++ b/CodenameOne/src/com/codename1/charts/transitions/XYSeriesTransition.java @@ -118,13 +118,11 @@ protected void cleanup() { */ protected void update(int progress) { double dProgress = (double)progress; - int len = endVals.getItemCount(); + int len = endVals.getItemCount(); // PMD Fix: UnusedLocalVariable removed unused endindex for (int i=0; i getLabels(final double start, final double end, // this way, we avoid a label value like 0.4000000000000000001 instead // of 0.4 z = FORMAT.parseDouble(FORMAT.format(z)); - } catch (ParseException e) { - // do nothing here - } + } catch (ParseException e) { // PMD Fix: EmptyCatchBlock log exception + Log.e(e); + } labels.add(z); } return labels; diff --git a/CodenameOne/src/com/codename1/charts/views/CombinedXYChart.java b/CodenameOne/src/com/codename1/charts/views/CombinedXYChart.java index b87e8ea6f3..78d205be0f 100644 --- a/CodenameOne/src/com/codename1/charts/views/CombinedXYChart.java +++ b/CodenameOne/src/com/codename1/charts/views/CombinedXYChart.java @@ -24,7 +24,8 @@ import com.codename1.charts.renderers.SimpleSeriesRenderer; import com.codename1.charts.renderers.XYMultipleSeriesRenderer; import com.codename1.charts.renderers.XYMultipleSeriesRenderer.Orientation; -import com.codename1.charts.renderers.XYSeriesRenderer; +import com.codename1.charts.renderers.XYSeriesRenderer; +import com.codename1.io.Log; @@ -59,9 +60,9 @@ public CombinedXYChart(XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer for (int i = 0; i < length; i++) { try { mCharts[i] = getXYChart(chartDefinitions[i].getType()); - } catch (Exception e) { - // ignore - } + } catch (Exception e) { // PMD Fix: EmptyCatchBlock log exception + Log.e(e); + } if (mCharts[i] == null) { throw new IllegalArgumentException("Unknown chart type " + chartDefinitions[i].getType()); } else { diff --git a/CodenameOne/src/com/codename1/charts/views/PointStyle.java b/CodenameOne/src/com/codename1/charts/views/PointStyle.java index c4d556f37c..8981d48c2c 100644 --- a/CodenameOne/src/com/codename1/charts/views/PointStyle.java +++ b/CodenameOne/src/com/codename1/charts/views/PointStyle.java @@ -30,7 +30,7 @@ public enum PointStyle { * * @param name the name */ - private PointStyle(String name) { + PointStyle(String name) { // PMD Fix: UnnecessaryModifier removed implicit private mName = name; } diff --git a/CodenameOne/src/com/codename1/charts/views/RadarChart.java b/CodenameOne/src/com/codename1/charts/views/RadarChart.java index 776aee35be..1d8a8e5253 100644 --- a/CodenameOne/src/com/codename1/charts/views/RadarChart.java +++ b/CodenameOne/src/com/codename1/charts/views/RadarChart.java @@ -105,11 +105,12 @@ public void draw(Canvas canvas, int x, int y, int width, int height, Paint paint paint.setColor(ColorUtil.GRAY); float thisRad = (float) Math.toRadians(90 - currentAngle); float nextRad = (float) Math.toRadians(90 - (currentAngle + angle)); - for (float level = 0; level <= 1f; level += decCoef) { - float thisX = (float) (centerX - Math.sin(thisRad) * radius * level); - float thisY = (float) (centerY - Math.cos(thisRad) * radius * level); - float nextX = (float) (centerX - Math.sin(nextRad) * radius * level); - float nextY = (float) (centerY - Math.cos(nextRad) * radius * level); + for (double level = 0; level <= 1d; level += decCoef) { // PMD Fix: DontUseFloatTypeForLoopIndices switched to double + float levelFactor = (float) level; + float thisX = (float) (centerX - Math.sin(thisRad) * radius * levelFactor); + float thisY = (float) (centerY - Math.cos(thisRad) * radius * levelFactor); + float nextX = (float) (centerX - Math.sin(nextRad) * radius * levelFactor); + float nextY = (float) (centerY - Math.cos(nextRad) * radius * levelFactor); canvas.drawLine(thisX, thisY, nextX, nextY, paint); } canvas.drawLine(centerX, centerY, centerX - (float) Math.sin(thisRad) * radius, centerY - (float) Math.cos(thisRad) * radius, paint); diff --git a/CodenameOne/src/com/codename1/charts/views/TimeChart.java b/CodenameOne/src/com/codename1/charts/views/TimeChart.java index fc3547d91e..2b934f26f3 100644 --- a/CodenameOne/src/com/codename1/charts/views/TimeChart.java +++ b/CodenameOne/src/com/codename1/charts/views/TimeChart.java @@ -17,15 +17,16 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import com.codename1.charts.compat.Canvas; -import com.codename1.charts.compat.Paint; - -import com.codename1.charts.models.XYMultipleSeriesDataset; -import com.codename1.charts.models.XYSeries; -import com.codename1.charts.renderers.XYMultipleSeriesRenderer; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import com.codename1.charts.compat.Canvas; +import com.codename1.charts.compat.Paint; + +import com.codename1.charts.models.XYMultipleSeriesDataset; +import com.codename1.charts.models.XYSeries; +import com.codename1.charts.renderers.XYMultipleSeriesRenderer; +import com.codename1.io.Log; import java.util.Calendar; import java.util.TimeZone; @@ -143,12 +144,12 @@ protected void drawXLabels(List xLabels, Double[] xTextLabelLocations, C private DateFormat getDateFormat(double start, double end) { if (mDateFormat != null) { SimpleDateFormat format = null; - try { - format = new SimpleDateFormat(mDateFormat); - return format; - } catch (Exception e) { - // do nothing here - } + try { + format = new SimpleDateFormat(mDateFormat); + return format; + } catch (Exception e) { // PMD Fix: EmptyCatchBlock log exception + Log.e(e); + } } DateFormat format = SimpleDateFormat.getDateInstance(SimpleDateFormat.MEDIUM); double diff = end - start; diff --git a/CodenameOne/src/com/codename1/charts/views/XYChart.java b/CodenameOne/src/com/codename1/charts/views/XYChart.java index 9c2e462556..44c19e7119 100644 --- a/CodenameOne/src/com/codename1/charts/views/XYChart.java +++ b/CodenameOne/src/com/codename1/charts/views/XYChart.java @@ -623,35 +623,30 @@ protected void drawChartValuesText(Canvas canvas, XYSeries series, XYSeriesRende float previousPointX = points.get(0); float previousPointY = points.get(1); for (int k = 0; k < points.size(); k += 2) { - if (k == 2) { // decide whether to display first two points' values or - // not - if (Math.abs(points.get(2) - points.get(0)) > renderer.getDisplayChartValuesDistance() - || Math.abs(points.get(3) - points.get(1)) > renderer.getDisplayChartValuesDistance()) { - // first point - drawText(canvas, getLabel(renderer.getChartValuesFormat(), series.getY(startIndex)), - points.get(0), points.get(1) - renderer.getChartValuesSpacing(), paint, 0); - // second point - drawText(canvas, - getLabel(renderer.getChartValuesFormat(), series.getY(startIndex + 1)), - points.get(2), points.get(3) - renderer.getChartValuesSpacing(), paint, 0); - - previousPointX = points.get(2); - previousPointY = points.get(3); - } - } else if (k > 2) { - // compare current point's position with the previous point's, if they - // are not too close, display - if (Math.abs(points.get(k) - previousPointX) > renderer.getDisplayChartValuesDistance() - || Math.abs(points.get(k + 1) - previousPointY) > renderer - .getDisplayChartValuesDistance()) { - drawText(canvas, - getLabel(renderer.getChartValuesFormat(), series.getY(startIndex + k / 2)), - points.get(k), points.get(k + 1) - renderer.getChartValuesSpacing(), paint, 0); - previousPointX = points.get(k); - previousPointY = points.get(k + 1); - } - } - } + if (k == 2 && (Math.abs(points.get(2) - points.get(0)) > renderer.getDisplayChartValuesDistance() + || Math.abs(points.get(3) - points.get(1)) > renderer.getDisplayChartValuesDistance())) { // PMD Fix: CollapsibleIfStatements combined nested checks + // first point + drawText(canvas, getLabel(renderer.getChartValuesFormat(), series.getY(startIndex)), + points.get(0), points.get(1) - renderer.getChartValuesSpacing(), paint, 0); + // second point + drawText(canvas, + getLabel(renderer.getChartValuesFormat(), series.getY(startIndex + 1)), + points.get(2), points.get(3) - renderer.getChartValuesSpacing(), paint, 0); + + previousPointX = points.get(2); + previousPointY = points.get(3); + } else if (k > 2 && (Math.abs(points.get(k) - previousPointX) > renderer.getDisplayChartValuesDistance() + || Math.abs(points.get(k + 1) - previousPointY) > renderer + .getDisplayChartValuesDistance())) { // PMD Fix: CollapsibleIfStatements merged nested checks + // compare current point's position with the previous point's, if they + // are not too close, display + drawText(canvas, + getLabel(renderer.getChartValuesFormat(), series.getY(startIndex + k / 2)), + points.get(k), points.get(k + 1) - renderer.getChartValuesSpacing(), paint, 0); + previousPointX = points.get(k); + previousPointY = points.get(k + 1); + } + } } else { // if only one point, display it for (int k = 0; k < points.size(); k += 2) { drawText(canvas, diff --git a/CodenameOne/src/com/codename1/cloud/BindTarget.java b/CodenameOne/src/com/codename1/cloud/BindTarget.java index 8b1ac2735c..47ff2673fa 100644 --- a/CodenameOne/src/com/codename1/cloud/BindTarget.java +++ b/CodenameOne/src/com/codename1/cloud/BindTarget.java @@ -39,5 +39,5 @@ public interface BindTarget { * @param oldValue the old value of the property * @param newValue the new value for the property */ - public void propertyChanged(Component source, String propertyName, Object oldValue, Object newValue); + void propertyChanged(Component source, String propertyName, Object oldValue, Object newValue); // PMD Fix: UnnecessaryModifier removed } diff --git a/CodenameOne/src/com/codename1/cloud/CloudImageProperty.java b/CodenameOne/src/com/codename1/cloud/CloudImageProperty.java index 8cd3cd9e52..bb4f1fdb96 100644 --- a/CodenameOne/src/com/codename1/cloud/CloudImageProperty.java +++ b/CodenameOne/src/com/codename1/cloud/CloudImageProperty.java @@ -42,7 +42,7 @@ * @author Shai Almog * @deprecated the cloud storage API is no longer supported, we recommend switching to a solution such as parse4cn1 */ -public class CloudImageProperty implements CustomProperty { +public class CloudImageProperty implements CustomProperty { // PMD Fix: UnnecessarySemicolon removed stray delimiter private static CacheMap cloudImageCache; private String idProperty; private EncodedImage placeholderImage; @@ -85,7 +85,7 @@ public Object propertyValue(CloudObject obj, String propertyName) { ConnectionRequest cr = new ConnectionRequest() { private EncodedImage e; protected void readResponse(InputStream input) throws IOException { - e = EncodedImage.create(input);; + e = EncodedImage.create(input); if(e.getWidth() != placeholderImage.getWidth() || e.getHeight() != placeholderImage.getHeight()) { ImageIO io = ImageIO.getImageIO(); if(io != null) { diff --git a/CodenameOne/src/com/codename1/cloud/CloudObject.java b/CodenameOne/src/com/codename1/cloud/CloudObject.java index fd36382256..971c4fa8d0 100644 --- a/CodenameOne/src/com/codename1/cloud/CloudObject.java +++ b/CodenameOne/src/com/codename1/cloud/CloudObject.java @@ -378,7 +378,7 @@ public void setLong(String key, long value) { throw new RuntimeException("Read only object, you are not the owner"); } status = STATUS_MODIFIED; - values.put(key, new Long(value)); + values.put(key, Long.valueOf(value)); // PMD Fix: PrimitiveWrapperInstantiation avoid constructor } /** @@ -403,7 +403,7 @@ public void setLong(String key, Long value) { public Long getLong(String key) { Object o = getObject(key); if(o instanceof Integer) { - return new Long(((Integer)o).intValue()); + return Long.valueOf(((Integer)o).intValue()); // PMD Fix: PrimitiveWrapperInstantiation avoid constructor } return (Long)o; } @@ -419,7 +419,7 @@ public void setInteger(String key, int value) { throw new RuntimeException("Read only object, you are not the owner"); } status = STATUS_MODIFIED; - values.put(key, new Integer(value)); + values.put(key, Integer.valueOf(value)); // PMD Fix: PrimitiveWrapperInstantiation avoid constructor } /** @@ -444,7 +444,7 @@ public void setInteger(String key, Integer value) { public Integer getInteger(String key) { Object o = getObject(key); if(o instanceof Long) { - return new Integer((int)((Long)o).longValue()); + return Integer.valueOf((int)((Long)o).longValue()); // PMD Fix: PrimitiveWrapperInstantiation avoid constructor } return (Integer)o; } @@ -460,7 +460,7 @@ public void setDouble(String key, double value) { throw new RuntimeException("Read only object, you are not the owner"); } status = STATUS_MODIFIED; - values.put(key, new Double(value)); + values.put(key, Double.valueOf(value)); // PMD Fix: PrimitiveWrapperInstantiation avoid constructor } /** @@ -497,7 +497,7 @@ public void setFloat(String key, float value) { throw new RuntimeException("Read only object, you are not the owner"); } status = STATUS_MODIFIED; - values.put(key, new Float(value)); + values.put(key, Float.valueOf(value)); // PMD Fix: PrimitiveWrapperInstantiation avoid constructor } /** @@ -522,7 +522,7 @@ public void setFloat(String key, Float value) { public Float getFloat(String key) { Object o = getObject(key); if(o instanceof Double) { - return new Float(((Double)o).floatValue()); + return Float.valueOf(((Double)o).floatValue()); // PMD Fix: PrimitiveWrapperInstantiation avoid constructor } return (Float)o; } @@ -538,7 +538,7 @@ public void setBoolean(String key, boolean value) { throw new RuntimeException("Read only object, you are not the owner"); } status = STATUS_MODIFIED; - values.put(key, new Boolean(value)); + values.put(key, Boolean.valueOf(value)); // PMD Fix: PrimitiveWrapperInstantiation avoid constructor } /** @@ -760,7 +760,7 @@ public void propertyChanged(Component source, String propertyName, Object oldVal */ public void unbindProperty(Component cmp, String propertyName) { BindTarget t = (BindTarget)cmp.getClientProperty("CN1Bind" + propertyName); - cmp.unbindProperty(propertyName, t);; + cmp.unbindProperty(propertyName, t); } /** diff --git a/CodenameOne/src/com/codename1/cloud/CloudResponse.java b/CodenameOne/src/com/codename1/cloud/CloudResponse.java index b940c49118..8b5301624f 100644 --- a/CodenameOne/src/com/codename1/cloud/CloudResponse.java +++ b/CodenameOne/src/com/codename1/cloud/CloudResponse.java @@ -35,12 +35,12 @@ public interface CloudResponse { * * @param returnValue the return value of the metho */ - public void onSuccess(T returnValue); + void onSuccess(T returnValue); // PMD Fix: UnnecessaryModifier removed /** * Invoked if there was a server error * * @param err the exception containing the error details */ - public void onError(CloudException err); + void onError(CloudException err); // PMD Fix: UnnecessaryModifier removed } diff --git a/CodenameOne/src/com/codename1/cloud/CloudStorage.java b/CodenameOne/src/com/codename1/cloud/CloudStorage.java index d66cd74076..dbf0708c58 100644 --- a/CodenameOne/src/com/codename1/cloud/CloudStorage.java +++ b/CodenameOne/src/com/codename1/cloud/CloudStorage.java @@ -36,7 +36,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.Hashtable; -import java.util.Vector; /** * The cloud storage class allows developers to use the Codename One cloud @@ -55,7 +54,7 @@ * * @author Shai Almog */ -public class CloudStorage { +public class CloudStorage { // PMD Fix: UnusedPrivateField removed pendingRefreshes cache /** * Return code for methods in this class indicating a successful operation */ @@ -146,8 +145,6 @@ public synchronized void delete(CloudObject cl) { public void refresh(CloudObject[] objects, CloudResponse response) { } - private Vector pendingRefreshes; - /** * Adds the given object to a set of refresh operations in which we don't * really care if the operation is successful diff --git a/CodenameOne/src/com/codename1/cloud/CustomProperty.java b/CodenameOne/src/com/codename1/cloud/CustomProperty.java index a551c012d8..30c9057a48 100644 --- a/CodenameOne/src/com/codename1/cloud/CustomProperty.java +++ b/CodenameOne/src/com/codename1/cloud/CustomProperty.java @@ -40,5 +40,5 @@ public interface CustomProperty { * @param propertyName the name of the property * @return the property value */ - public Object propertyValue(CloudObject obj, String propertyName); + Object propertyValue(CloudObject obj, String propertyName); // PMD Fix: UnnecessaryModifier removed } diff --git a/CodenameOne/src/com/codename1/codescan/ScanResult.java b/CodenameOne/src/com/codename1/codescan/ScanResult.java index d203c00a7d..616816e233 100644 --- a/CodenameOne/src/com/codename1/codescan/ScanResult.java +++ b/CodenameOne/src/com/codename1/codescan/ScanResult.java @@ -39,12 +39,12 @@ public interface ScanResult { * @param formatName the format of the scan * @param rawBytes the bytes of data */ - public void scanCompleted(String contents, String formatName, byte[] rawBytes); + void scanCompleted(String contents, String formatName, byte[] rawBytes); // PMD Fix: UnnecessaryModifier removed /** * Invoked if the user canceled the scan */ - public void scanCanceled(); + void scanCanceled(); // PMD Fix: UnnecessaryModifier removed /** * Invoked if an error occurred during the scanning process @@ -52,5 +52,5 @@ public interface ScanResult { * @param errorCode code * @param message descriptive message */ - public void scanError(int errorCode, String message); + void scanError(int errorCode, String message); // PMD Fix: UnnecessaryModifier removed } diff --git a/CodenameOne/src/com/codename1/components/Ads.java b/CodenameOne/src/com/codename1/components/Ads.java index d703e707af..72fdc70819 100644 --- a/CodenameOne/src/com/codename1/components/Ads.java +++ b/CodenameOne/src/com/codename1/components/Ads.java @@ -524,7 +524,7 @@ public Object getPropertyValue(String name) { return getAppID(); } if (name.equals("updateDuration")) { - return new Integer(getUpdateDuration()); + return Integer.valueOf(getUpdateDuration()); // PMD Fix: PrimitiveWrapperInstantiation avoid constructor } if (name.equals("age")) { return getAge(); diff --git a/CodenameOne/src/com/codename1/components/AudioRecorderComponent.java b/CodenameOne/src/com/codename1/components/AudioRecorderComponent.java index c4b8d80dd8..40a3391555 100644 --- a/CodenameOne/src/com/codename1/components/AudioRecorderComponent.java +++ b/CodenameOne/src/com/codename1/components/AudioRecorderComponent.java @@ -80,7 +80,7 @@ public class AudioRecorderComponent extends Container implements ActionSource { /** * Enum for tracking the recorder state. */ - public static enum RecorderState { + public enum RecorderState { // PMD Fix: UnnecessaryModifier removed redundant static /** * The recorder is initializing. */ diff --git a/CodenameOne/src/com/codename1/components/ButtonList.java b/CodenameOne/src/com/codename1/components/ButtonList.java index 65d4e5478e..0b2705401c 100644 --- a/CodenameOne/src/com/codename1/components/ButtonList.java +++ b/CodenameOne/src/com/codename1/components/ButtonList.java @@ -105,9 +105,9 @@ public abstract class ButtonList extends Container implements DataChangedListene * @param The type used for the view. For RadioList T would be RadioButton. For CheckBoxList, T would be CheckBox. For SwitchList it's different because * the Switch uses a wrapper component. */ - public static interface Decorator { - public void decorate(M modelItem, V viewItem); - public void undecorate(V viewItem); + public interface Decorator { // PMD Fix: UnnecessaryModifier removed redundant static + void decorate(M modelItem, V viewItem); // PMD Fix: UnnecessaryModifier removed redundant public + void undecorate(V viewItem); // PMD Fix: UnnecessaryModifier removed redundant public } diff --git a/CodenameOne/src/com/codename1/components/ImageViewer.java b/CodenameOne/src/com/codename1/components/ImageViewer.java index 709c9c143d..f660a82404 100644 --- a/CodenameOne/src/com/codename1/components/ImageViewer.java +++ b/CodenameOne/src/com/codename1/components/ImageViewer.java @@ -232,33 +232,29 @@ public void initComponent() { } private void eagerLock() { - if(eagerLock) { - if(swipeableImages != null && swipeableImages.getSize() > 1) { - Image left = getImageLeft(); - if(swipePlaceholder != null) { - left.asyncLock(swipePlaceholder); + if(eagerLock && swipeableImages != null && swipeableImages.getSize() > 1) { + Image left = getImageLeft(); + if (swipePlaceholder != null) { // PMD Fix: CollapsibleIfStatements consolidate placeholder check + left.asyncLock(swipePlaceholder); + } else { + left.lock(); + } + if(swipeableImages.getSize() > 2) { + Image right = getImageRight(); + if (swipePlaceholder != null) { // PMD Fix: CollapsibleIfStatements consolidate placeholder check + right.asyncLock(swipePlaceholder); } else { - left.lock(); - } - if(swipeableImages.getSize() > 2) { - Image right = getImageRight(); - if(swipePlaceholder != null) { - right.asyncLock(swipePlaceholder); - } else { - right.lock(); - } + right.lock(); } } - } + } } - + private void eagerUnlock() { - if(eagerLock) { - if(swipeableImages != null && swipeableImages.getSize() > 1) { - getImageLeft().unlock(); - getImageRight().unlock(); - } - } + if(eagerLock && swipeableImages != null && swipeableImages.getSize() > 1) { + getImageLeft().unlock(); + getImageRight().unlock(); + } } /** diff --git a/CodenameOne/src/com/codename1/components/InfiniteProgress.java b/CodenameOne/src/com/codename1/components/InfiniteProgress.java index cb08414c48..478b8cc0c5 100644 --- a/CodenameOne/src/com/codename1/components/InfiniteProgress.java +++ b/CodenameOne/src/com/codename1/components/InfiniteProgress.java @@ -227,10 +227,8 @@ public boolean animate() { * @since 7.0 */ public boolean animate(boolean force) { - if (!force) { - if (!isVisible() || Display.getInstance().getCurrent() != this.getComponentForm()) { - return false; - } + if (!force && (!isVisible() || Display.getInstance().getCurrent() != this.getComponentForm())) { // PMD Fix: CollapsibleIfStatements merged visibility checks + return false; } // reduce repaint thrushing of the UI from the infinite progress boolean val = super.animate() || tick % tickCount == 0; @@ -345,11 +343,11 @@ public void paint(Graphics g) { if(animation instanceof FontImage) { rotated = animation.rotate(v); } else { - Integer angle = new Integer(v); + Integer angle = Integer.valueOf(v); // PMD Fix: PrimitiveWrapperInstantiation avoid constructor rotated = cache.get(angle); if(rotated == null) { rotated = animation.rotate(v); - cache.put(v, rotated); + cache.put(angle, rotated); } } g.drawImage(rotated, getX() + s.getPaddingLeftNoRTL(), getY() + s.getPaddingTop()); diff --git a/CodenameOne/src/com/codename1/components/InteractionDialog.java b/CodenameOne/src/com/codename1/components/InteractionDialog.java index ee29150c04..1eee6d8a15 100644 --- a/CodenameOne/src/com/codename1/components/InteractionDialog.java +++ b/CodenameOne/src/com/codename1/components/InteractionDialog.java @@ -637,11 +637,9 @@ public void showPopupDialog(Component c) { * This is ignored if there isn't enough space */ public void showPopupDialog(Component c, boolean bias) { - Form f = c== null ? null : c.getComponentForm(); - if (f != null) { - if (!formMode && !f.getContentPane().contains(c)) { - setFormMode(true); - } + Form f = c == null ? null : c.getComponentForm(); // PMD Fix: BrokenNullCheck + if (f != null && !formMode && !f.getContentPane().contains(c)) { + setFormMode(true); } disposed = false; getUnselectedStyle().setOpacity(255); @@ -689,16 +687,15 @@ public void showPopupDialog(Rectangle rect, boolean bias) { getContentPane().setUIID("PopupContentPane"); } - Component contentPane = getContentPane(); Label title = getTitleComponent(); UIManager manager = getUIManager(); - + String dialogTitle = title.getText(); // hide the title if no text is there to allow the styles of the dialog title to disappear, we need this code here since otherwise the // preferred size logic of the dialog won't work with large title borders - if((dialogTitle != null || dialogTitle.length() == 0) && manager.isThemeConstant("hideEmptyTitleBool", true)) { + if((dialogTitle == null || dialogTitle.length() == 0) && manager.isThemeConstant("hideEmptyTitleBool", true)) { boolean b = getTitle().length() > 0; titleArea.setVisible(b); getTitleComponent().setVisible(b); @@ -712,9 +709,8 @@ public void showPopupDialog(Rectangle rect, boolean bias) { // allows a text area to recalculate its preferred size if embedded within a dialog revalidate(); - Style contentPaneStyle = getStyle(); + Style contentPaneStyle = getStyle(); // PMD Fix: UnusedLocalVariable removed redundant contentPane reference - boolean restoreArrow = false; if(manager.isThemeConstant(getUIID()+ "ArrowBool", false)) { Image t = manager.getThemeImageConstant(getUIID() + "ArrowTopImage"); Image b = manager.getThemeImageConstant(getUIID() + "ArrowBottomImage"); @@ -723,8 +719,7 @@ public void showPopupDialog(Rectangle rect, boolean bias) { Border border = contentPaneStyle.getBorder(); if(border != null) { border.setImageBorderSpecialTile(t, b, l, r, rect); - restoreArrow = true; - } + } } else { Border border = contentPaneStyle.getBorder(); if(border != null) { diff --git a/CodenameOne/src/com/codename1/components/MediaPlayer.java b/CodenameOne/src/com/codename1/components/MediaPlayer.java index 3f13b2caba..5481e7949b 100644 --- a/CodenameOne/src/com/codename1/components/MediaPlayer.java +++ b/CodenameOne/src/com/codename1/components/MediaPlayer.java @@ -171,7 +171,7 @@ public void showControls() { animateLayoutFade(300, 0); } } - if (video != null && usesNativeVideoControls()) { + if (video != null && usesNativeVideoControls()) { // PMD Fix: CollapsibleIfStatements merged nested native control check video.setVariable(Media.VARIABLE_NATIVE_CONTRLOLS_EMBEDDED, true); } } @@ -190,7 +190,7 @@ public void hideControls() { animateLayoutFade(300, 0); } } - if (video != null && usesNativeVideoControls()) { + if (video != null && usesNativeVideoControls()) { // PMD Fix: CollapsibleIfStatements merged nested native control check video.setVariable(Media.VARIABLE_NATIVE_CONTRLOLS_EMBEDDED, false); } } @@ -256,10 +256,8 @@ public void run() { if(dur > 0) { float pos = video.getTime(); int offset = (int)(pos / dur * 100.0f); - if(offset > -1 && offset < 101) { - if (progress != null) { - progress.setProgress(offset); - } + if(offset > -1 && offset < 101 && progress != null) { + progress.setProgress(offset); } } } @@ -437,12 +435,10 @@ private void initUI() { progress.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { float dur = video.getDuration(); - if(dur > 0) { - if (progress != null) { - float pos = progress.getProgress(evt); - int t = (int)(pos / 100.0f * dur); - video.setTime(t); - } + if(dur > 0 && progress != null) { + float pos = progress.getProgress(evt); + int t = (int)(pos / 100.0f * dur); + video.setTime(t); } } }); @@ -491,7 +487,7 @@ public void actionPerformed(AsyncMedia.MediaStateChangeEvent evt) { private void updateIconAndText() { - if (video != null && video.isPlaying()) { + if (video != null && video.isPlaying()) { // PMD Fix: CollapsibleIfStatements merged null/playing checks if (getPauseIcon() != null) { this.setIcon(getPauseIcon()); } else { @@ -532,32 +528,30 @@ protected void deinitialize() { }else{ play.setText("play"); } - if(autoplay) { - if(video != null && !video.isPlaying()){ - if (getPauseIcon() != null) { - play.setIcon(getPauseIcon()); - } else { - play.setText("pause"); - } - Timer t = new Timer(); - t.schedule(new TimerTask() { - public void run() { - if (isInitialized()) { - Display.getInstance().callSerially(new Runnable() { - public void run() { - if (video != null && !video.isPlaying() && isInitialized()) { - video.play(); - checkProgressSlider(); - } + if(autoplay && video != null && !video.isPlaying()) { + if (getPauseIcon() != null) { + play.setIcon(getPauseIcon()); + } else { + play.setText("pause"); + } + Timer t = new Timer(); + t.schedule(new TimerTask() { + public void run() { + if (isInitialized()) { + Display.getInstance().callSerially(new Runnable() { + public void run() { + if (video != null && !video.isPlaying() && isInitialized()) { + video.play(); + checkProgressSlider(); } - }); - } + } + }); } - - }, 300l); - - //video.play(); - } + } + + }, 300l); + + //video.play(); } play.addActionListener(new ActionListener() { diff --git a/CodenameOne/src/com/codename1/components/RSSReader.java b/CodenameOne/src/com/codename1/components/RSSReader.java index ba19d88215..712e21ebd0 100644 --- a/CodenameOne/src/com/codename1/components/RSSReader.java +++ b/CodenameOne/src/com/codename1/components/RSSReader.java @@ -338,7 +338,7 @@ public Class[] getPropertyTypes() { */ public Object getPropertyValue(String name) { if(name.equals("limit")) { - return new Integer(limit); + return Integer.valueOf(limit); // PMD Fix: PrimitiveWrapperInstantiation avoid constructor } if(name.equals("url")) { return url; diff --git a/CodenameOne/src/com/codename1/components/SplitPane.java b/CodenameOne/src/com/codename1/components/SplitPane.java index 1c54ed0276..4e99ed1e1c 100644 --- a/CodenameOne/src/com/codename1/components/SplitPane.java +++ b/CodenameOne/src/com/codename1/components/SplitPane.java @@ -42,6 +42,7 @@ import com.codename1.ui.layouts.LayeredLayout.LayeredLayoutConstraint.Inset; import com.codename1.ui.plaf.Border; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; /** @@ -685,8 +686,9 @@ public void setBottom(Component cmp) { * @return */ public Component getBottomOrRightComponent() { - for (Component c : bottomOrRight) { - return c; + Iterator iterator = bottomOrRight.iterator(); // PMD Fix: AvoidBranchingStatementAsLastInLoop + if (iterator.hasNext()) { + return iterator.next(); } return null; } @@ -712,8 +714,9 @@ public Component getRight() { * @return */ public Component getTopOrLeftComponent() { - for (Component c : topOrLeft) { - return c; + Iterator iterator = topOrLeft.iterator(); // PMD Fix: AvoidBranchingStatementAsLastInLoop + if (iterator.hasNext()) { + return iterator.next(); } return null; } diff --git a/CodenameOne/src/com/codename1/io/JSONSanitizer.java b/CodenameOne/src/com/codename1/io/JSONSanitizer.java index 742e8c1f50..5e9f250c53 100644 --- a/CodenameOne/src/com/codename1/io/JSONSanitizer.java +++ b/CodenameOne/src/com/codename1/io/JSONSanitizer.java @@ -378,15 +378,9 @@ void sanitize() { // Look for a run of '.', [0-9], [a-zA-Z_$], [+-] which subsumes // all the above without including any JSON special characters // outside keyword and number. - int runEnd; - for (runEnd = i; runEnd < n; ++runEnd) { - char tch = jsonish.charAt(runEnd); - if (('a' <= tch && tch <= 'z') || ('0' <= tch && tch <= '9') - || tch == '+' || tch == '-' || tch == '.' - || ('A' <= tch && tch <= 'Z') || tch == '_' || tch == '$') { - continue; - } - break; + int runEnd = i; + while (runEnd < n && isIdentifierCharacter(jsonish.charAt(runEnd))) { + runEnd++; } if (runEnd == i) { @@ -403,10 +397,8 @@ void sanitize() { if (!(isNumber || isKeyword)) { // We're going to have to quote the output. Further expand to // include more of an unquoted token in a string. - for (; runEnd < n; ++runEnd) { - if (isJsonSpecialChar(runEnd)) { - break; - } + while (runEnd < n && !isJsonSpecialChar(runEnd)) { + runEnd++; } if (runEnd < n && jsonish.charAt(runEnd) == '"') { ++runEnd; @@ -486,7 +478,7 @@ void sanitize() { } // Insert brackets to close unclosed content. - while (bracketDepth != 0) { + while (bracketDepth != 0) { // PMD Fix: AvoidBranchingStatementAsLastInLoop sanitizedJson.append(isMap[--bracketDepth] ? '}' : ']'); } } @@ -1127,6 +1119,12 @@ private boolean isHexAt(int i) { return 'a' <= ch && ch <= 'f'; } + private static boolean isIdentifierCharacter(char tch) { + return ('a' <= tch && tch <= 'z') || ('0' <= tch && tch <= '9') + || tch == '+' || tch == '-' || tch == '.' + || ('A' <= tch && tch <= 'Z') || tch == '_' || tch == '$'; + } + private boolean isJsonSpecialChar(int i) { char ch = jsonish.charAt(i); if (ch <= ' ') { return true; } diff --git a/CodenameOne/src/com/codename1/ui/ComponentSelector.java b/CodenameOne/src/com/codename1/ui/ComponentSelector.java index 6b23370aa8..27d48ecfe2 100644 --- a/CodenameOne/src/com/codename1/ui/ComponentSelector.java +++ b/CodenameOne/src/com/codename1/ui/ComponentSelector.java @@ -891,8 +891,9 @@ public ComponentSelector fadeInAndWait(final int duration) { * @see Component#isVisible() */ public boolean isVisible() { - for (Component c : this) { - return c.isVisible(); + Iterator iterator = iterator(); // PMD Fix: AvoidBranchingStatementAsLastInLoop + if (iterator.hasNext()) { + return iterator.next().isVisible(); } return false; } @@ -903,8 +904,9 @@ public boolean isVisible() { * @see Component#isHidden() */ public boolean isHidden() { - for (Component c : this) { - return c.isHidden(); + Iterator iterator = iterator(); // PMD Fix: AvoidBranchingStatementAsLastInLoop + if (iterator.hasNext()) { + return iterator.next().isHidden(); } return false; } @@ -2006,8 +2008,9 @@ public ComponentSelector addAll(Collection c, boolean chain * @return The first component in this set. */ public Component asComponent() { - for (Component c : this) { - return c; + Iterator iterator = iterator(); // PMD Fix: AvoidBranchingStatementAsLastInLoop + if (iterator.hasNext()) { + return iterator.next(); } return null; } @@ -2232,8 +2235,9 @@ public ComponentSelector putClientProperty(String key, Object value) { * @return The value of the client property. */ public Object getClientProperty(String key) { - for (Component c : this) { - return c.getClientProperty(key); + Iterator iterator = iterator(); // PMD Fix: AvoidBranchingStatementAsLastInLoop + if (iterator.hasNext()) { + return iterator.next().getClientProperty(key); } return null; } @@ -2794,9 +2798,9 @@ public ComponentSelector setUnselectedStyle(Style style) { * @return */ public ComponentSelector requestFocus() { - for (Component c : this) { - c.requestFocus(); - return this; + Iterator iterator = iterator(); // PMD Fix: AvoidBranchingStatementAsLastInLoop + if (iterator.hasNext()) { + iterator.next().requestFocus(); } return this; } @@ -2941,8 +2945,9 @@ public ComponentSelector setIgnorePointerEvents(boolean ignore) { } public boolean isIgnorePointerEvents() { - for (Component c : this) { - return c.isIgnorePointerEvents(); + Iterator iterator = iterator(); // PMD Fix: AvoidBranchingStatementAsLastInLoop + if (iterator.hasNext()) { + return iterator.next().isIgnorePointerEvents(); } return false; } diff --git a/CodenameOne/src/com/codename1/ui/Display.java b/CodenameOne/src/com/codename1/ui/Display.java index 346ec200b5..9bc3de9c61 100644 --- a/CodenameOne/src/com/codename1/ui/Display.java +++ b/CodenameOne/src/com/codename1/ui/Display.java @@ -1177,20 +1177,16 @@ void mainEDTLoop() { try { // when there is no current form the EDT is useful only // for features such as call serially - while(impl.getCurrentForm() == null) { + while (impl.getCurrentForm() == null) { // PMD Fix: AvoidBranchingStatementAsLastInLoop synchronized(lock){ - breakOut2: - if(shouldEDTSleep()) { - while(pendingIdleSerialCalls.size() > 0) { + if(!pendingIdleSerialCalls.isEmpty()) { Runnable r = pendingIdleSerialCalls.get(0); pendingIdleSerialCalls.remove(0); callSerially(r); - - break breakOut2; + } else { + lock.wait(); } - - lock.wait(); } // paint transition or intro animations and don't do anything else if such @@ -1216,23 +1212,21 @@ void mainEDTLoop() { } } - while(codenameOneRunning) { + while (codenameOneRunning) { // PMD Fix: AvoidBranchingStatementAsLastInLoop try { // wait indefinetly Lock surrounds the should method to prevent serial calls from // getting "lost" synchronized(lock){ - breakOut1: - if(shouldEDTSleep()) { - while(pendingIdleSerialCalls.size() > 0) { + if(!pendingIdleSerialCalls.isEmpty()) { Runnable r = pendingIdleSerialCalls.get(0); pendingIdleSerialCalls.remove(0); callSerially(r); - break breakOut1; + } else { + impl.edtIdle(true); + lock.wait(); + impl.edtIdle(false); } - impl.edtIdle(true); - lock.wait(); - impl.edtIdle(false); } } diff --git a/CodenameOne/src/com/codename1/ui/geom/GeneralPath.java b/CodenameOne/src/com/codename1/ui/geom/GeneralPath.java index 266a2b553b..8c5cda3ec0 100644 --- a/CodenameOne/src/com/codename1/ui/geom/GeneralPath.java +++ b/CodenameOne/src/com/codename1/ui/geom/GeneralPath.java @@ -2872,7 +2872,8 @@ static int crossBound(double bound[], int bc, double py1, double py2) { // Check Y coordinate int up = 0; int down = 0; - for(int i = 2; i < bc; i += 4) { + boolean intersects = false; + for (int i = 2; i < bc; i += 4) { // PMD Fix: AvoidBranchingStatementAsLastInLoop if (bound[i] < py1) { up++; continue; @@ -2881,6 +2882,11 @@ static int crossBound(double bound[], int bc, double py1, double py2) { down++; continue; } + intersects = true; + break; + } + + if (intersects) { return CROSSING; } @@ -2893,13 +2899,19 @@ static int crossBound(double bound[], int bc, double py1, double py2) { // bc >= 2 sortBound(bound, bc); boolean sign = bound[2] > py2; - for(int i = 6; i < bc; i += 4) { + boolean crossing = false; + for (int i = 6; i < bc; i += 4) { // PMD Fix: AvoidBranchingStatementAsLastInLoop boolean sign2 = bound[i] > py2; if (sign != sign2 && bound[i + 1] != bound[i - 3]) { - return CROSSING; + crossing = true; + sign = sign2; + break; } sign = sign2; } + if (crossing) { + return CROSSING; + } } return UNKNOWN; }