matchcollector.java

来自「openmap java写的开源数字地图程序. 用applet实现,可以像g」· Java 代码 · 共 86 行

JAVA
86
字号
/** *  */package com.bbn.openmap.geo;import java.util.ArrayList;import java.util.Collection;import java.util.HashSet;import java.util.Iterator;public interface MatchCollector {    /**     * collect an indication that the query object a (or some part of     * it) matches object b in some way, presumably by intersection.     *      * @param a     * @param b     */    void collect(Object a, Object b);    /** @return an iterator over the previously collected elements * */    Iterator iterator();    /**     * A MatchCollector that collects a list of pairs of the matching     * objects     */    public static class PairArrayMatchCollector implements MatchCollector {        protected final ArrayList result = new ArrayList();        public void collect(Object a, Object b) {            result.add(new MatchCollector.Pair(a, b));        }        public Iterator iterator() {            return result.iterator();        }    }    public static class Pair {        private Object a;        private Object b;        public Pair(Object a, Object b) {            this.a = a;            this.b = b;        }        public Object getA() {            return a;        }        public Object getB() {            return b;        }    }    public static class SetMatchCollector implements MatchCollector {        protected final HashSet result = new HashSet();        public void collect(Object a, Object b) {            result.add(b);        }        public Iterator iterator() {            return result.iterator();        }    }    public static class CollectionMatchCollector implements MatchCollector {        protected final Collection c;        public CollectionMatchCollector(Collection c) {            this.c = c;        }        public void collect(Object a, Object b) {            c.add(b);        }        public Iterator iterator() {            return c.iterator();        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?