Changeset 13809 in josm


Ignore:
Timestamp:
2018-05-21T20:31:36+02:00 (6 years ago)
Author:
Don-vip
Message:

define InterestingTags functions in IPrimitive

Location:
trunk/src/org/openstreetmap/josm
Files:
12 edited

Legend:

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

    r12641 r13809  
    1313import org.openstreetmap.josm.command.SequenceCommand;
    1414import org.openstreetmap.josm.data.APIDataSet;
     15import org.openstreetmap.josm.data.osm.AbstractPrimitive;
    1516import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1617import org.openstreetmap.josm.gui.MainApplication;
     
    2425    public boolean checkUpload(APIDataSet apiDataSet) {
    2526        List<OsmPrimitive> objectsToUpload = apiDataSet.getPrimitives();
    26         Collection<String> discardableKeys = new HashSet<>(OsmPrimitive.getDiscardableKeys());
     27        Collection<String> discardableKeys = new HashSet<>(AbstractPrimitive.getDiscardableKeys());
    2728
    2829        boolean needsChange = false;
  • trunk/src/org/openstreetmap/josm/corrector/ReverseWayTagCorrector.java

    r13158 r13809  
    1717import org.openstreetmap.josm.data.correction.RoleCorrection;
    1818import org.openstreetmap.josm.data.correction.TagCorrection;
     19import org.openstreetmap.josm.data.osm.AbstractPrimitive;
    1920import org.openstreetmap.josm.data.osm.Node;
    2021import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    5556    private static final Collection<Pattern> IGNORED_KEYS = new ArrayList<>();
    5657    static {
    57         for (String s : OsmPrimitive.getUninterestingKeys()) {
     58        for (String s : AbstractPrimitive.getUninterestingKeys()) {
    5859            IGNORED_KEYS.add(getPatternFor(s));
    5960        }
  • trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java

    r13804 r13809  
    99import java.util.Collections;
    1010import java.util.Date;
     11import java.util.HashMap;
    1112import java.util.HashSet;
     13import java.util.LinkedList;
     14import java.util.List;
    1215import java.util.Map;
    1316import java.util.Map.Entry;
     
    1619import java.util.concurrent.atomic.AtomicLong;
    1720
     21import org.openstreetmap.josm.spi.preferences.Config;
    1822import org.openstreetmap.josm.tools.LanguageInfo;
    1923import org.openstreetmap.josm.tools.Utils;
     
    742746        return getName();
    743747    }
     748
     749    /*-------------------------------------
     750     * WORK IN PROGRESS, UNINTERESTING KEYS
     751     *-------------------------------------*/
     752
     753    private static volatile Collection<String> workinprogress;
     754    private static volatile Collection<String> uninteresting;
     755    private static volatile Collection<String> discardable;
     756
     757    /**
     758     * Returns a list of "uninteresting" keys that do not make an object
     759     * "tagged".  Entries that end with ':' are causing a whole namespace to be considered
     760     * "uninteresting".  Only the first level namespace is considered.
     761     * Initialized by isUninterestingKey()
     762     * @return The list of uninteresting keys.
     763     */
     764    public static Collection<String> getUninterestingKeys() {
     765        if (uninteresting == null) {
     766            List<String> l = new LinkedList<>(Arrays.asList(
     767                "source", "source_ref", "source:", "comment",
     768                "watch", "watch:", "description", "attribution"));
     769            l.addAll(getDiscardableKeys());
     770            l.addAll(getWorkInProgressKeys());
     771            uninteresting = new HashSet<>(Config.getPref().getList("tags.uninteresting", l));
     772        }
     773        return uninteresting;
     774    }
     775
     776    /**
     777     * Returns a list of keys which have been deemed uninteresting to the point
     778     * that they can be silently removed from data which is being edited.
     779     * @return The list of discardable keys.
     780     */
     781    public static Collection<String> getDiscardableKeys() {
     782        if (discardable == null) {
     783            discardable = new HashSet<>(Config.getPref().getList("tags.discardable",
     784                    Arrays.asList(
     785                            "created_by",
     786                            "converted_by",
     787                            "geobase:datasetName",
     788                            "geobase:uuid",
     789                            "KSJ2:ADS",
     790                            "KSJ2:ARE",
     791                            "KSJ2:AdminArea",
     792                            "KSJ2:COP_label",
     793                            "KSJ2:DFD",
     794                            "KSJ2:INT",
     795                            "KSJ2:INT_label",
     796                            "KSJ2:LOC",
     797                            "KSJ2:LPN",
     798                            "KSJ2:OPC",
     799                            "KSJ2:PubFacAdmin",
     800                            "KSJ2:RAC",
     801                            "KSJ2:RAC_label",
     802                            "KSJ2:RIC",
     803                            "KSJ2:RIN",
     804                            "KSJ2:WSC",
     805                            "KSJ2:coordinate",
     806                            "KSJ2:curve_id",
     807                            "KSJ2:curve_type",
     808                            "KSJ2:filename",
     809                            "KSJ2:lake_id",
     810                            "KSJ2:lat",
     811                            "KSJ2:long",
     812                            "KSJ2:river_id",
     813                            "odbl",
     814                            "odbl:note",
     815                            "SK53_bulk:load",
     816                            "sub_sea:type",
     817                            "tiger:source",
     818                            "tiger:separated",
     819                            "tiger:tlid",
     820                            "tiger:upload_uuid",
     821                            "yh:LINE_NAME",
     822                            "yh:LINE_NUM",
     823                            "yh:STRUCTURE",
     824                            "yh:TOTYUMONO",
     825                            "yh:TYPE",
     826                            "yh:WIDTH",
     827                            "yh:WIDTH_RANK"
     828                        )));
     829        }
     830        return discardable;
     831    }
     832
     833    /**
     834     * Returns a list of "work in progress" keys that do not make an object
     835     * "tagged" but "annotated".
     836     * @return The list of work in progress keys.
     837     * @since 5754
     838     */
     839    public static Collection<String> getWorkInProgressKeys() {
     840        if (workinprogress == null) {
     841            workinprogress = new HashSet<>(Config.getPref().getList("tags.workinprogress",
     842                    Arrays.asList("note", "fixme", "FIXME")));
     843        }
     844        return workinprogress;
     845    }
     846
     847    /**
     848     * Determines if key is considered "uninteresting".
     849     * @param key The key to check
     850     * @return true if key is considered "uninteresting".
     851     */
     852    public static boolean isUninterestingKey(String key) {
     853        getUninterestingKeys();
     854        if (uninteresting.contains(key))
     855            return true;
     856        int pos = key.indexOf(':');
     857        if (pos > 0)
     858            return uninteresting.contains(key.substring(0, pos + 1));
     859        return false;
     860    }
     861
     862    @Override
     863    public Map<String, String> getInterestingTags() {
     864        Map<String, String> result = new HashMap<>();
     865        String[] keys = this.keys;
     866        if (keys != null) {
     867            for (int i = 0; i < keys.length; i += 2) {
     868                if (!isUninterestingKey(keys[i])) {
     869                    result.put(keys[i], keys[i + 1]);
     870                }
     871            }
     872        }
     873        return result;
     874    }
     875
     876    @Override
     877    public boolean hasSameInterestingTags(IPrimitive other) {
     878        return (!hasKeys() && !other.hasKeys())
     879                || getInterestingTags().equals(other.getInterestingTags());
     880    }
    744881}
  • trunk/src/org/openstreetmap/josm/data/osm/IPrimitive.java

    r13808 r13809  
    44import java.util.Date;
    55import java.util.List;
     6import java.util.Map;
    67
    78import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
     
    440441     * Returns the parent data set of this primitive.
    441442     * @return OsmData this primitive is part of.
     443     * @since 13807
    442444     */
    443445    OsmData<?, ?, ?, ?> getDataSet();
     446
     447    /**
     448     * Returns {@link #getKeys()} for which {@code key} does not fulfill uninteresting criteria.
     449     * @return A map of interesting tags
     450     * @since 13809
     451     */
     452    Map<String, String> getInterestingTags();
     453
     454    /**
     455     * Replies true if other isn't null and has the same interesting tags (key/value-pairs) as this.
     456     *
     457     * @param other the other object primitive
     458     * @return true if other isn't null and has the same interesting tags (key/value-pairs) as this.
     459     * @since 13809
     460     */
     461    boolean hasSameInterestingTags(IPrimitive other);
    444462}
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r13808 r13809  
    66import java.text.MessageFormat;
    77import java.util.ArrayList;
    8 import java.util.Arrays;
    98import java.util.Collection;
    109import java.util.Collections;
    1110import java.util.Date;
    12 import java.util.HashMap;
    1311import java.util.HashSet;
    1412import java.util.LinkedHashSet;
     
    608606    }
    609607
    610     /*---------------------------------------------------
    611      * WORK IN PROGRESS, UNINTERESTING AND DIRECTION KEYS
    612      *--------------------------------------------------*/
    613 
    614     private static volatile Collection<String> workinprogress;
    615     private static volatile Collection<String> uninteresting;
    616     private static volatile Collection<String> discardable;
    617 
    618     /**
    619      * Returns a list of "uninteresting" keys that do not make an object
    620      * "tagged".  Entries that end with ':' are causing a whole namespace to be considered
    621      * "uninteresting".  Only the first level namespace is considered.
    622      * Initialized by isUninterestingKey()
    623      * @return The list of uninteresting keys.
    624      */
    625     public static Collection<String> getUninterestingKeys() {
    626         if (uninteresting == null) {
    627             List<String> l = new LinkedList<>(Arrays.asList(
    628                 "source", "source_ref", "source:", "comment",
    629                 "watch", "watch:", "description", "attribution"));
    630             l.addAll(getDiscardableKeys());
    631             l.addAll(getWorkInProgressKeys());
    632             uninteresting = new HashSet<>(Config.getPref().getList("tags.uninteresting", l));
    633         }
    634         return uninteresting;
    635     }
    636 
    637     /**
    638      * Returns a list of keys which have been deemed uninteresting to the point
    639      * that they can be silently removed from data which is being edited.
    640      * @return The list of discardable keys.
    641      */
    642     public static Collection<String> getDiscardableKeys() {
    643         if (discardable == null) {
    644             discardable = new HashSet<>(Config.getPref().getList("tags.discardable",
    645                     Arrays.asList(
    646                             "created_by",
    647                             "converted_by",
    648                             "geobase:datasetName",
    649                             "geobase:uuid",
    650                             "KSJ2:ADS",
    651                             "KSJ2:ARE",
    652                             "KSJ2:AdminArea",
    653                             "KSJ2:COP_label",
    654                             "KSJ2:DFD",
    655                             "KSJ2:INT",
    656                             "KSJ2:INT_label",
    657                             "KSJ2:LOC",
    658                             "KSJ2:LPN",
    659                             "KSJ2:OPC",
    660                             "KSJ2:PubFacAdmin",
    661                             "KSJ2:RAC",
    662                             "KSJ2:RAC_label",
    663                             "KSJ2:RIC",
    664                             "KSJ2:RIN",
    665                             "KSJ2:WSC",
    666                             "KSJ2:coordinate",
    667                             "KSJ2:curve_id",
    668                             "KSJ2:curve_type",
    669                             "KSJ2:filename",
    670                             "KSJ2:lake_id",
    671                             "KSJ2:lat",
    672                             "KSJ2:long",
    673                             "KSJ2:river_id",
    674                             "odbl",
    675                             "odbl:note",
    676                             "SK53_bulk:load",
    677                             "sub_sea:type",
    678                             "tiger:source",
    679                             "tiger:separated",
    680                             "tiger:tlid",
    681                             "tiger:upload_uuid",
    682                             "yh:LINE_NAME",
    683                             "yh:LINE_NUM",
    684                             "yh:STRUCTURE",
    685                             "yh:TOTYUMONO",
    686                             "yh:TYPE",
    687                             "yh:WIDTH",
    688                             "yh:WIDTH_RANK"
    689                         )));
    690         }
    691         return discardable;
    692     }
    693 
    694     /**
    695      * Returns a list of "work in progress" keys that do not make an object
    696      * "tagged" but "annotated".
    697      * @return The list of work in progress keys.
    698      * @since 5754
    699      */
    700     public static Collection<String> getWorkInProgressKeys() {
    701         if (workinprogress == null) {
    702             workinprogress = new HashSet<>(Config.getPref().getList("tags.workinprogress",
    703                     Arrays.asList("note", "fixme", "FIXME")));
    704         }
    705         return workinprogress;
    706     }
    707 
    708     /**
    709      * Determines if key is considered "uninteresting".
    710      * @param key The key to check
    711      * @return true if key is considered "uninteresting".
    712      */
    713     public static boolean isUninterestingKey(String key) {
    714         getUninterestingKeys();
    715         if (uninteresting.contains(key))
    716             return true;
    717         int pos = key.indexOf(':');
    718         if (pos > 0)
    719             return uninteresting.contains(key.substring(0, pos + 1));
    720         return false;
    721     }
    722 
    723     /**
    724      * Returns {@link #getKeys()} for which {@code key} does not fulfill {@link #isUninterestingKey}.
    725      * @return A map of interesting tags
    726      */
    727     public Map<String, String> getInterestingTags() {
    728         Map<String, String> result = new HashMap<>();
    729         String[] keys = this.keys;
    730         if (keys != null) {
    731             for (int i = 0; i < keys.length; i += 2) {
    732                 if (!isUninterestingKey(keys[i])) {
    733                     result.put(keys[i], keys[i + 1]);
    734                 }
    735             }
    736         }
    737         return result;
    738     }
     608    /*---------------
     609     * DIRECTION KEYS
     610     *---------------*/
    739611
    740612    private static Match compileDirectionKeys(String prefName, String defaultValue) throws AssertionError {
     
    1097969
    1098970    /**
    1099      * Replies true if other isn't null and has the same interesting tags (key/value-pairs) as this.
    1100      *
    1101      * @param other the other object primitive
    1102      * @return true if other isn't null and has the same interesting tags (key/value-pairs) as this.
    1103      */
    1104     public boolean hasSameInterestingTags(OsmPrimitive other) {
    1105         return (keys == null && other.keys == null)
    1106                 || getInterestingTags().equals(other.getInterestingTags());
    1107     }
    1108 
    1109     /**
    1110971     * Replies true if this primitive and other are equal with respect to their semantic attributes.
    1111972     * <ol>
  • trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateRelation.java

    r13637 r13809  
    1818import org.openstreetmap.josm.command.SequenceCommand;
    1919import org.openstreetmap.josm.data.coor.LatLon;
     20import org.openstreetmap.josm.data.osm.AbstractPrimitive;
    2021import org.openstreetmap.josm.data.osm.Node;
    2122import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    181182
    182183    /** List of keys without useful information */
    183     private final Set<String> ignoreKeys = new HashSet<>(OsmPrimitive.getUninterestingKeys());
     184    private final Set<String> ignoreKeys = new HashSet<>(AbstractPrimitive.getUninterestingKeys());
    184185
    185186    /**
  • trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateWay.java

    r11627 r13809  
    1919import org.openstreetmap.josm.command.SequenceCommand;
    2020import org.openstreetmap.josm.data.coor.LatLon;
     21import org.openstreetmap.josm.data.osm.AbstractPrimitive;
    2122import org.openstreetmap.josm.data.osm.Node;
    2223import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    170171     */
    171172    public void removeUninterestingKeys(Map<String, String> wkeys) {
    172         for (String key : OsmPrimitive.getDiscardableKeys()) {
     173        for (String key : AbstractPrimitive.getDiscardableKeys()) {
    173174            wkeys.remove(key);
    174175        }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r13597 r13809  
    3030import org.openstreetmap.josm.command.Command;
    3131import org.openstreetmap.josm.command.SequenceCommand;
     32import org.openstreetmap.josm.data.osm.AbstractPrimitive;
    3233import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3334import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    289290        if (!presets.isEmpty()) {
    290291            additionalPresetsValueData = new MultiMap<>();
    291             for (String a : OsmPrimitive.getUninterestingKeys()) {
     292            for (String a : AbstractPrimitive.getUninterestingKeys()) {
    292293                additionalPresetsValueData.putVoid(a);
    293294            }
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolver.java

    r11772 r13809  
    77import org.openstreetmap.josm.command.ChangePropertyCommand;
    88import org.openstreetmap.josm.command.Command;
     9import org.openstreetmap.josm.data.osm.AbstractPrimitive;
    910import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1011import org.openstreetmap.josm.data.osm.TagCollection;
     
    4142            cmds.addAll(buildTagChangeCommand(targetPrimitive, allResolutions));
    4243        }
    43         for (String p : OsmPrimitive.getDiscardableKeys()) {
     44        for (String p : AbstractPrimitive.getDiscardableKeys()) {
    4445            if (targetPrimitive.get(p) != null) {
    4546                cmds.add(new ChangePropertyCommand(targetPrimitive, p, null));
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolutionUtil.java

    r13647 r13809  
    1717import org.openstreetmap.josm.data.StructUtils;
    1818import org.openstreetmap.josm.data.StructUtils.StructEntry;
     19import org.openstreetmap.josm.data.osm.AbstractPrimitive;
    1920import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2021import org.openstreetmap.josm.data.osm.Tag;
     
    101102        // remove irrelevant tags
    102103        //
    103         for (String key : OsmPrimitive.getDiscardableKeys()) {
     104        for (String key : AbstractPrimitive.getDiscardableKeys()) {
    104105            tc.removeByKey(key);
    105106        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesCellRenderer.java

    r12987 r13809  
    2121import javax.swing.table.TableCellRenderer;
    2222
    23 import org.openstreetmap.josm.data.osm.OsmPrimitive;
     23import org.openstreetmap.josm.data.osm.AbstractPrimitive;
    2424import org.openstreetmap.josm.data.preferences.BooleanProperty;
    2525import org.openstreetmap.josm.data.preferences.CachingProperty;
     
    5252    private static void setColors(Component c, String key, boolean isSelected) {
    5353
    54         if (OsmPrimitive.getDiscardableKeys().contains(key)) {
     54        if (AbstractPrimitive.getDiscardableKeys().contains(key)) {
    5555            c.setForeground((isSelected ? SELECTED_FG : NORMAL_FG).get());
    5656            c.setBackground((isSelected ? SELECTED_BG : NORMAL_BG).get());
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r13766 r13809  
    6060import org.openstreetmap.josm.command.Command;
    6161import org.openstreetmap.josm.data.SelectionChangedListener;
     62import org.openstreetmap.josm.data.osm.AbstractPrimitive;
    6263import org.openstreetmap.josm.data.osm.DataSet;
    6364import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
     
    580581            types.add(TaggingPresetType.forPrimitive(osm));
    581582            for (String key : osm.keySet()) {
    582                 if (displayDiscardableKeys || !OsmPrimitive.getDiscardableKeys().contains(key)) {
     583                if (displayDiscardableKeys || !AbstractPrimitive.getDiscardableKeys().contains(key)) {
    583584                    String value = osm.get(key);
    584585                    keyCount.put(key, keyCount.containsKey(key) ? keyCount.get(key) + 1 : 1);
Note: See TracChangeset for help on using the changeset viewer.