Changeset 13950 in josm


Ignore:
Timestamp:
2018-06-18T01:51:26+02:00 (9 months ago)
Author:
Don-vip
Message:

use IPrimitive in SearchAction

Location:
trunk
Files:
2 edited

Legend:

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

    r13926 r13950  
    4545import org.openstreetmap.josm.actions.JosmAction;
    4646import org.openstreetmap.josm.actions.ParameterizedAction;
    47 import org.openstreetmap.josm.data.osm.DataSet;
    4847import org.openstreetmap.josm.data.osm.Filter;
    49 import org.openstreetmap.josm.data.osm.OsmPrimitive;
     48import org.openstreetmap.josm.data.osm.IPrimitive;
     49import org.openstreetmap.josm.data.osm.OsmData;
    5050import org.openstreetmap.josm.data.osm.search.PushbackTokenizer;
    5151import org.openstreetmap.josm.data.osm.search.SearchCompiler;
     
    626626     * @return The result of the search.
    627627     * @since 10457
    628      */
    629     public static Collection<OsmPrimitive> searchAndReturn(String search, SearchMode mode) {
     628     * @since 13950 (signature)
     629     */
     630    public static Collection<IPrimitive> searchAndReturn(String search, SearchMode mode) {
    630631        final SearchSetting searchSetting = new SearchSetting();
    631632        searchSetting.text = search;
     
    678679     * @since 10457
    679680     * @since 10600 (functional interface)
     681     * @since 13950 (signature)
    680682     */
    681683    @FunctionalInterface
     
    689691         * @param parent parent component
    690692         */
    691         void receiveSearchResult(DataSet ds, Collection<OsmPrimitive> result, int foundMatches, SearchSetting setting, Component parent);
     693        void receiveSearchResult(OsmData<?, ?, ?, ?> ds, Collection<IPrimitive> result,
     694                int foundMatches, SearchSetting setting, Component parent);
    692695    }
    693696
     
    698701
    699702        @Override
    700         public void receiveSearchResult(DataSet ds, Collection<OsmPrimitive> result, int foundMatches, SearchSetting setting, Component parent) {
     703        public void receiveSearchResult(OsmData<?, ?, ?, ?> ds, Collection<IPrimitive> result,
     704                int foundMatches, SearchSetting setting, Component parent) {
    701705            ds.setSelected(result);
    702706            MapFrame map = MainApplication.getMap();
     
    732736     */
    733737    private static final class CapturingSearchReceiver implements SearchReceiver {
    734         private Collection<OsmPrimitive> result;
     738        private Collection<IPrimitive> result;
    735739
    736740        @Override
    737         public void receiveSearchResult(DataSet ds, Collection<OsmPrimitive> result, int foundMatches,
     741        public void receiveSearchResult(OsmData<?, ?, ?, ?> ds, Collection<IPrimitive> result, int foundMatches,
    738742                SearchSetting setting, Component parent) {
    739743                    this.result = result;
     
    742746
    743747    static final class SearchTask extends PleaseWaitRunnable {
    744         private final DataSet ds;
     748        private final OsmData<?, ?, ?, ?> ds;
    745749        private final SearchSetting setting;
    746         private final Collection<OsmPrimitive> selection;
    747         private final Predicate<OsmPrimitive> predicate;
     750        private final Collection<IPrimitive> selection;
     751        private final Predicate<IPrimitive> predicate;
    748752        private boolean canceled;
    749753        private int foundMatches;
    750754        private final SearchReceiver resultReceiver;
    751755
    752         private SearchTask(DataSet ds, SearchSetting setting, Collection<OsmPrimitive> selection, Predicate<OsmPrimitive> predicate,
    753                 SearchReceiver resultReceiver) {
     756        private SearchTask(OsmData<?, ?, ?, ?> ds, SearchSetting setting, Collection<IPrimitive> selection,
     757                Predicate<IPrimitive> predicate, SearchReceiver resultReceiver) {
    754758            super(tr("Searching"));
    755759            this.ds = ds;
     
    761765
    762766        static SearchTask newSearchTask(SearchSetting setting, SearchReceiver resultReceiver) {
    763             final DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     767            final OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData();
    764768            if (ds == null) {
    765769                throw new IllegalStateException("No active dataset");
     
    775779         * @return A new search task.
    776780         */
    777         private static SearchTask newSearchTask(SearchSetting setting, final DataSet ds, SearchReceiver resultReceiver) {
    778             final Collection<OsmPrimitive> selection = new HashSet<>(ds.getAllSelected());
    779             return new SearchTask(ds, setting, selection, ds::isSelected, resultReceiver);
     781        private static SearchTask newSearchTask(SearchSetting setting, final OsmData<?, ?, ?, ?> ds, SearchReceiver resultReceiver) {
     782            final Collection<IPrimitive> selection = new HashSet<>(ds.getAllSelected());
     783            return new SearchTask(ds, setting, selection, IPrimitive::isSelected, resultReceiver);
    780784        }
    781785
     
    797801                }
    798802
    799                 Collection<OsmPrimitive> all;
     803                Collection<? extends IPrimitive> all;
    800804                if (setting.allElements) {
    801805                    all = ds.allPrimitives();
    802806                } else {
    803                     all = ds.getPrimitives(OsmPrimitive::isSelectable);
     807                    all = ds.getPrimitives(p -> p.isSelectable()); // Do not use method reference before Java 11!
    804808                }
    805809                final ProgressMonitor subMonitor = getProgressMonitor().createSubTaskMonitor(all.size(), false);
    806810                subMonitor.beginTask(trn("Searching in {0} object", "Searching in {0} objects", all.size(), all.size()));
    807811
    808                 for (OsmPrimitive osm : all) {
     812                for (IPrimitive osm : all) {
    809813                    if (canceled) {
    810814                        return;
  • trunk/test/unit/org/openstreetmap/josm/actions/JoinAreasActionTest.java

    r12728 r13950  
    2020import org.openstreetmap.josm.actions.search.SearchAction;
    2121import org.openstreetmap.josm.data.osm.DataSet;
     22import org.openstreetmap.josm.data.osm.IPrimitive;
    2223import org.openstreetmap.josm.data.osm.Node;
    2324import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    8586            for (String ref : new String[]{"A", "B", "C", "D", "E"}) {
    8687                System.out.print("Joining ways " + ref);
    87                 Collection<OsmPrimitive> found = SearchAction.searchAndReturn("type:way ref="+ref, SearchMode.replace);
     88                Collection<IPrimitive> found = SearchAction.searchAndReturn("type:way ref="+ref, SearchMode.replace);
    8889                assertEquals(2, found.size());
    8990
    9091                MainApplication.getMenu().joinAreas.join(Utils.filteredCollection(found, Way.class));
    9192
    92                 Collection<OsmPrimitive> found2 = SearchAction.searchAndReturn("type:way ref="+ref, SearchMode.replace);
     93                Collection<IPrimitive> found2 = SearchAction.searchAndReturn("type:way ref="+ref, SearchMode.replace);
    9394                assertEquals(1, found2.size());
    9495                System.out.println(" ==> OK");
Note: See TracChangeset for help on using the changeset viewer.