Changeset 10599 in josm


Ignore:
Timestamp:
2016-07-23T02:08:50+02:00 (3 years ago)
Author:
Don-vip
Message:

see #11390 - sonar - squid:S1610 - Java 8: Abstract classes without fields should be converted to interfaces

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java

    r10552 r10599  
    318318     *
    319319     * @since 8954
    320      */
    321     public abstract static class Strategy {
     320     * @since 10599 (functional interface)
     321     */
     322    @FunctionalInterface
     323    public interface Strategy {
    322324
    323325        /**
     
    327329         * @return the way to keep
    328330         */
    329         public abstract Way determineWayToKeep(Iterable<Way> wayChunks);
     331        Way determineWayToKeep(Iterable<Way> wayChunks);
    330332
    331333        /**
     
    333335         * @return strategy which selects the way chunk with the highest node count to keep
    334336         */
    335         public static Strategy keepLongestChunk() {
    336             return new Strategy() {
    337                 @Override
    338                 public Way determineWayToKeep(Iterable<Way> wayChunks) {
     337        static Strategy keepLongestChunk() {
     338            return wayChunks -> {
    339339                    Way wayToKeep = null;
    340340                    for (Way i : wayChunks) {
     
    344344                    }
    345345                    return wayToKeep;
    346                 }
    347             };
     346                };
    348347        }
    349348
     
    352351         * @return strategy which selects the first way chunk
    353352         */
    354         public static Strategy keepFirstChunk() {
    355             return new Strategy() {
    356                 @Override
    357                 public Way determineWayToKeep(Iterable<Way> wayChunks) {
    358                     return wayChunks.iterator().next();
    359                 }
    360             };
     353        static Strategy keepFirstChunk() {
     354            return wayChunks -> wayChunks.iterator().next();
    361355        }
    362356    }
  • trunk/src/org/openstreetmap/josm/command/Command.java

    r10467 r10599  
    3737 *
    3838 * @author imi
     39 * @since 21 (creation)
     40 * @since 10599 (signature)
    3941 */
    40 public abstract class Command extends PseudoCommand {
     42public abstract class Command implements PseudoCommand {
    4143
    4244    private static final class CloneVisitor extends AbstractVisitor {
  • trunk/src/org/openstreetmap/josm/command/PseudoCommand.java

    r8447 r10599  
    1212 * as subcommand of real commands but it is just an empty shell and can not be
    1313 * executed or undone.
     14 * @since  3262 (creation)
     15 * @since 10599 (functional interface)
    1416 */
    15 public abstract class PseudoCommand {
     17public interface PseudoCommand {
    1618
    1719    /**
     
    1921     * @return description text representing this command
    2022     */
    21     public abstract String getDescriptionText();
     23    String getDescriptionText();
    2224
    2325    /**
     
    2527     * @return descriptive icon of this command
    2628     */
    27     public Icon getDescriptionIcon() {
     29    default Icon getDescriptionIcon() {
    2830        return null;
    2931    }
     
    3335     * @return primitives that take part in this command
    3436     */
    35     public abstract Collection<? extends OsmPrimitive> getParticipatingPrimitives();
     37    Collection<? extends OsmPrimitive> getParticipatingPrimitives();
    3638
    3739    /**
     
    4042     * @return the subcommands, null if there are no child commands
    4143     */
    42     public Collection<PseudoCommand> getChildren() {
     44    default Collection<PseudoCommand> getChildren() {
    4345        return null;
    4446    }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r10469 r10599  
    130130     * Represents a fix to a validation test. The fixing {@link Command} can be obtained by {@link #createCommand(OsmPrimitive, Selector)}.
    131131     */
    132     abstract static class FixCommand {
     132    @FunctionalInterface
     133    interface FixCommand {
    133134        /**
    134135         * Creates the fixing {@link Command} for the given primitive. The {@code matchingSelector} is used to evaluate placeholders
     
    138139         * @return fix command
    139140         */
    140         abstract Command createCommand(final OsmPrimitive p, final Selector matchingSelector);
    141 
    142         private static void checkObject(final Object obj) {
     141        Command createCommand(final OsmPrimitive p, final Selector matchingSelector);
     142
     143        static void checkObject(final Object obj) {
    143144            CheckParameterUtil.ensureThat(obj instanceof Expression || obj instanceof String,
    144145                    "instance of Exception or String expected, but got " + obj);
     
    152153         * @return result string
    153154         */
    154         private static String evaluateObject(final Object obj, final OsmPrimitive p, final Selector matchingSelector) {
     155        static String evaluateObject(final Object obj, final OsmPrimitive p, final Selector matchingSelector) {
    155156            final String s;
    156157            if (obj instanceof Expression) {
     
    173174            return new FixCommand() {
    174175                @Override
    175                 Command createCommand(OsmPrimitive p, Selector matchingSelector) {
     176                public Command createCommand(OsmPrimitive p, Selector matchingSelector) {
    176177                    final Tag tag = Tag.ofString(evaluateObject(obj, p, matchingSelector));
    177178                    return new ChangePropertyCommand(p, tag.getKey(), tag.getValue());
     
    194195            return new FixCommand() {
    195196                @Override
    196                 Command createCommand(OsmPrimitive p, Selector matchingSelector) {
     197                public Command createCommand(OsmPrimitive p, Selector matchingSelector) {
    197198                    final String key = evaluateObject(obj, p, matchingSelector);
    198199                    return new ChangePropertyCommand(p, key, "");
     
    215216            return new FixCommand() {
    216217                @Override
    217                 Command createCommand(OsmPrimitive p, Selector matchingSelector) {
     218                public Command createCommand(OsmPrimitive p, Selector matchingSelector) {
    218219                    return new ChangePropertyKeyCommand(p,
    219220                            TagCheck.insertArguments(matchingSelector, oldKey, p),
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java

    r10589 r10599  
    3030import org.openstreetmap.josm.tools.Utils;
    3131
    32 public abstract class Condition {
    33 
    34     public abstract boolean applies(Environment e);
    35 
    36     public static Condition createKeyValueCondition(String k, String v, Op op, Context context, boolean considerValAsKey) {
     32public interface Condition {
     33
     34    boolean applies(Environment e);
     35
     36    static Condition createKeyValueCondition(String k, String v, Op op, Context context, boolean considerValAsKey) {
    3737        switch (context) {
    3838        case PRIMITIVE:
     
    5757    }
    5858
    59     public static Condition createRegexpKeyRegexpValueCondition(String k, String v, Op op) {
     59    static Condition createRegexpKeyRegexpValueCondition(String k, String v, Op op) {
    6060        return new RegexpKeyValueRegexpCondition(k, v, op);
    6161    }
    6262
    63     public static Condition createKeyCondition(String k, boolean not, KeyMatchType matchType, Context context) {
     63    static Condition createKeyCondition(String k, boolean not, KeyMatchType matchType, Context context) {
    6464        switch (context) {
    6565        case PRIMITIVE:
     
    7777    }
    7878
    79     public static PseudoClassCondition createPseudoClassCondition(String id, boolean not, Context context) {
     79    static PseudoClassCondition createPseudoClassCondition(String id, boolean not, Context context) {
    8080        return PseudoClassCondition.createPseudoClassCondition(id, not, context);
    8181    }
    8282
    83     public static ClassCondition createClassCondition(String id, boolean not, Context context) {
     83    static ClassCondition createClassCondition(String id, boolean not, Context context) {
    8484        return new ClassCondition(id, not);
    8585    }
    8686
    87     public static ExpressionCondition createExpressionCondition(Expression e, Context context) {
     87    static ExpressionCondition createExpressionCondition(Expression e, Context context) {
    8888        return new ExpressionCondition(e);
    8989    }
     
    9292     * This is the operation that {@link KeyValueCondition} uses to match.
    9393     */
    94     public enum Op {
     94    enum Op {
    9595        /** The value equals the given reference. */
    9696        EQ,
     
    183183     * Context, where the condition applies.
    184184     */
    185     public enum Context {
     185    enum Context {
    186186        /**
    187187         * normal primitive selector, e.g. way[highway=residential]
     
    200200     * Extra class for performance reasons.
    201201     */
    202     public static class SimpleKeyValueCondition extends Condition {
     202    class SimpleKeyValueCondition implements Condition {
    203203        /**
    204204         * The key to search for.
     
    240240     *
    241241     */
    242     public static class KeyValueCondition extends Condition {
     242    class KeyValueCondition implements Condition {
    243243        /**
    244244         * The key to search for.
     
    288288    }
    289289
    290     public static class KeyValueRegexpCondition extends KeyValueCondition {
     290    class KeyValueRegexpCondition extends KeyValueCondition {
    291291
    292292        public final Pattern pattern;
     
    317317    }
    318318
    319     public static class RegexpKeyValueRegexpCondition extends KeyValueRegexpCondition {
     319    class RegexpKeyValueRegexpCondition extends KeyValueRegexpCondition {
    320320
    321321        public final Pattern keyPattern;
     
    337337    }
    338338
    339     public static class RoleCondition extends Condition {
     339    class RoleCondition implements Condition {
    340340        public final String role;
    341341        public final Op op;
     
    354354    }
    355355
    356     public static class IndexCondition extends Condition {
     356    class IndexCondition implements Condition {
    357357        public final String index;
    358358        public final Op op;
     
    377377     * This defines how {@link KeyCondition} matches a given key.
    378378     */
    379     public enum KeyMatchType {
     379    enum KeyMatchType {
    380380        /**
    381381         * The key needs to be equal to the given label.
     
    417417     * </pre>
    418418     */
    419     public static class KeyCondition extends Condition {
     419    class KeyCondition implements Condition {
    420420
    421421        /**
     
    499499    }
    500500
    501     public static class ClassCondition extends Condition {
     501    class ClassCondition implements Condition {
    502502
    503503        public final String id;
     
    524524     * are written in lower case with dashes between words.
    525525     */
    526     static class PseudoClasses {
     526    final class PseudoClasses {
     527
     528        private PseudoClasses() {
     529            // Hide default constructor for utilities classes
     530        }
    527531
    528532        /**
     
    687691    }
    688692
    689     public static class PseudoClassCondition extends Condition {
     693    class PseudoClassCondition implements Condition {
    690694
    691695        public final Method method;
     
    736740    }
    737741
    738     public static class OpenEndPseudoClassCondition extends PseudoClassCondition {
     742    class OpenEndPseudoClassCondition extends PseudoClassCondition {
    739743        public OpenEndPseudoClassCondition(boolean not) {
    740744            super(null, not);
     
    747751    }
    748752
    749     public static class ExpressionCondition extends Condition {
     753    class ExpressionCondition implements Condition {
    750754
    751755        private final Expression e;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/LabelCompositionStrategy.java

    r10300 r10599  
    3434 *   options <tt>mappaint.nameOrder</tt> and <tt>mappaint.nameComplementOrder</tt>.</li>
    3535 * </ul>
    36  *
     36 * @since  3987 (creation)
     37 * @since 10599 (functional interface)
    3738 */
    38 public abstract class LabelCompositionStrategy {
     39@FunctionalInterface
     40public interface LabelCompositionStrategy {
    3941
    4042    /**
     
    4648     * if no suitable value could be composed
    4749     */
    48     public abstract String compose(OsmPrimitive primitive);
    49 
    50     public static class StaticLabelCompositionStrategy extends LabelCompositionStrategy {
     50    String compose(OsmPrimitive primitive);
     51
     52    class StaticLabelCompositionStrategy implements LabelCompositionStrategy {
    5153        private final String defaultLabel;
    5254
     
    8385    }
    8486
    85     public static class TagLookupCompositionStrategy extends LabelCompositionStrategy {
     87    class TagLookupCompositionStrategy implements LabelCompositionStrategy {
    8688
    8789        private final String defaultLabelTag;
     
    127129    }
    128130
    129     public static class DeriveLabelFromNameTagsCompositionStrategy
    130         extends LabelCompositionStrategy implements PreferenceChangedListener {
     131    class DeriveLabelFromNameTagsCompositionStrategy implements LabelCompositionStrategy, PreferenceChangedListener {
    131132
    132133        /**
  • trunk/src/org/openstreetmap/josm/gui/util/RotationAngle.java

    r10228 r10599  
    1212
    1313/**
    14  * Determines how an icon is to be rotated depending on the primitive to displayed.
     14 * Determines how an icon is to be rotated depending on the primitive to be displayed.
     15 * @since  8199 (creation)
     16 * @since 10599 (functional interface)
    1517 */
    16 public abstract class RotationAngle {
     18@FunctionalInterface
     19public interface RotationAngle {
    1720
    1821    /**
    19      * Calculates the rotation angle depending on the primitive to displayed.
     22     * Calculates the rotation angle depending on the primitive to be displayed.
    2023     * @param p primitive
    2124     * @return rotation angle
    2225     */
    23     public abstract double getRotationAngle(OsmPrimitive p);
     26    double getRotationAngle(OsmPrimitive p);
    2427
    2528    /**
     
    2831     * @return rotation angle
    2932     */
    30     public static RotationAngle buildStaticRotation(final double angle) {
     33    static RotationAngle buildStaticRotation(final double angle) {
    3134        return new RotationAngle() {
    3235            @Override
     
    4750     * @return rotation angle
    4851     */
    49     public static RotationAngle buildStaticRotation(final String string) {
     52    static RotationAngle buildStaticRotation(final String string) {
    5053        try {
    5154            return buildStaticRotation(parseCardinalRotation(string));
     
    6366     * @return the angle in radians
    6467     */
    65     public static double parseCardinalRotation(final String cardinal) {
     68    static double parseCardinalRotation(final String cardinal) {
    6669        switch (cardinal.toLowerCase(Locale.ENGLISH)) {
    6770            case "n":
     
    98101     * @return rotation angle
    99102     */
    100     public static RotationAngle buildWayDirectionRotation() {
     103    static RotationAngle buildWayDirectionRotation() {
    101104        return new RotationAngle() {
    102105            @Override
  • trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java

    r10436 r10599  
    1515import org.openstreetmap.josm.JOSMFixture;
    1616import org.openstreetmap.josm.Main;
     17import org.openstreetmap.josm.actions.SplitWayAction.Strategy;
    1718import org.openstreetmap.josm.data.coor.EastNorth;
    1819import org.openstreetmap.josm.data.coor.LatLon;
     
    177178        dataSet.setSelected(Arrays.asList(w2, n3, n4, n5));
    178179
    179         final SplitWayAction.Strategy strategy = new SplitWayAction.Strategy() {
    180 
    181             @Override
    182             public Way determineWayToKeep(Iterable<Way> wayChunks) {
     180        final Strategy strategy = wayChunks -> {
    183181                final Iterator<Way> it = wayChunks.iterator();
    184182                for (int i = 0; i < indexOfWayToKeep; i++) {
     
    186184                }
    187185                return it.next();
    188             }
    189         };
     186            };
    190187        final SplitWayAction.SplitWayResult result = SplitWayAction.splitWay(
    191188                layer, w2, SplitWayAction.buildSplitChunks(w2, Arrays.asList(n3, n4, n5)), new ArrayList<OsmPrimitive>(), strategy);
Note: See TracChangeset for help on using the changeset viewer.