geotool源码&Hints提示类

Hints类,类似于对类的配置,我们来看一下代码的实现。

public class Hints extends RenderingHints {
    private static volatile Map<java.awt.RenderingHints.Key, Object> GLOBAL = new ConcurrentHashMap();
    private static AtomicBoolean needScan = new AtomicBoolean(true);
    public static final Hints.ClassKey CRS_AUTHORITY_FACTORY = new Hints.ClassKey("org.opengis.referencing.crs.CRSAuthorityFactory");
    public static final Hints.ClassKey CS_AUTHORITY_FACTORY = new Hints.ClassKey("org.opengis.referencing.cs.CSAuthorityFactory");
    public static final Hints.ClassKey DATUM_AUTHORITY_FACTORY = new Hints.ClassKey("org.opengis.referencing.datum.DatumAuthorityFactory");
    public static final Hints.ClassKey CRS_FACTORY = new Hints.ClassKey("org.opengis.referencing.crs.CRSFactory");
    public static final Hints.ClassKey CS_FACTORY = new Hints.ClassKey("org.opengis.referencing.cs.CSFactory");
    public static final Hints.ClassKey DATUM_FACTORY = new Hints.ClassKey("org.opengis.referencing.datum.DatumFactory");
    public static final Hints.ClassKey COORDINATE_OPERATION_FACTORY = new Hints.ClassKey("org.opengis.referencing.operation.CoordinateOperationFactory");
    public static final Hints.ClassKey COORDINATE_OPERATION_AUTHORITY_FACTORY = new Hints.ClassKey("org.opengis.referencing.operation.CoordinateOperationAuthorityFactory");
    public static final Hints.ClassKey MATH_TRANSFORM_FACTORY = new Hints.ClassKey("org.opengis.referencing.operation.MathTransformFactory");
    public static final Hints.Key DEFAULT_COORDINATE_REFERENCE_SYSTEM = new Hints.Key("org.opengis.referencing.crs.CoordinateReferenceSystem");
    public static final Hints.FileKey CRS_AUTHORITY_EXTRA_DIRECTORY = new Hints.FileKey(false);
    public static final Hints.Key EPSG_DATA_SOURCE = new Hints.DataSourceKey();
    public static final Hints.OptionKey DATUM_SHIFT_METHOD = new Hints.OptionKey(new String[]{"Molodenski", "Abridged_Molodenski", "Geocentric", "*"});
    public static final Hints.Key LENIENT_DATUM_SHIFT = new Hints.Key(Boolean.class);
    public static final Hints.Key FORCE_LONGITUDE_FIRST_AXIS_ORDER = new Hints.Key(Boolean.class);
    public static final Hints.Key FORCE_AXIS_ORDER_HONORING = new Hints.Key(String.class);
    public static final Hints.Key FORCE_STANDARD_AXIS_DIRECTIONS = new Hints.Key(Boolean.class);
    public static final Hints.Key FORCE_STANDARD_AXIS_UNITS = new Hints.Key(Boolean.class);
    public static final Hints.Key VERSION = new Hints.Key("org.geotools.util.Version");
    public static final Hints.Key ENTITY_RESOLVER = new Hints.Key(EntityResolver.class);
    public static final Hints.Key USE_PROVIDED_FID = new Hints.Key(Boolean.class);
    public static final Hints.Key PROVIDED_FID = new Hints.Key(String.class);
    public static final Hints.Key CRS = new Hints.Key("org.opengis.referencing.crs.CoordinateReferenceSystem");
    public static final Hints.Key PRECISION = new Hints.Key("org.opengis.geometry.Precision");
    public static final Hints.Key POSITION_FACTORY = new Hints.Key("org.opengis.geometry.PositionFactory");
    public static final Hints.Key GEOMETRY_FACTORY = new Hints.Key("org.opengis.geometry.coordinate.GeometryFactory");
    public static final Hints.Key LINEARIZATION_TOLERANCE = new Hints.Key(Double.class);
    public static final Hints.Key COMPLEX_FACTORY = new Hints.Key("org.opengis.geometry.complex.ComplexFactory");
    public static final Hints.Key AGGREGATE_FACTORY = new Hints.Key("org.opengis.geometry.aggregate.AggregateFactory");
    public static final Hints.Key PRIMITIVE_FACTORY = new Hints.Key("org.opengis.geometry.primitive.PrimitiveFactory");
    public static final Hints.Key GEOMETRY_VALIDATE = new Hints.Key(Boolean.class);
    public static final Hints.ClassKey JTS_GEOMETRY_FACTORY = new Hints.ClassKey("org.locationtech.jts.geom.GeometryFactory");
    public static final Hints.ClassKey JTS_COORDINATE_SEQUENCE_FACTORY = new Hints.ClassKey("org.locationtech.jts.geom.CoordinateSequenceFactory");
    public static final Hints.Key JTS_PRECISION_MODEL = new Hints.Key("org.locationtech.jts.geom.PrecisionModel");
    public static final Hints.Key JTS_SRID = new Hints.Key(Integer.class);
    public static Hints.ClassKey FEATURE_FACTORY = new Hints.ClassKey("org.opengis.feature.FeatureFactory");
    public static Hints.ClassKey FEATURE_TYPE_FACTORY = new Hints.ClassKey("org.opengis.feature.type.FeatureTypeFactory");
    public static final Hints.ClassKey FEATURE_LOCK_FACTORY = new Hints.ClassKey("org.geotools.data.FeatureLockFactory");
    public static final Hints.ClassKey FEATURE_COLLECTIONS = new Hints.ClassKey("org.geotools.feature.FeatureCollections");
    /** @deprecated */
    public static final Hints.Key FEATURE_TYPE_FACTORY_NAME = new Hints.Key(String.class);
    public static final Hints.Key FEATURE_DETACHED = new Hints.Key(Boolean.class);
    public static final Hints.Key FEATURE_2D = new Hints.Key(Boolean.class);
    public static final Hints.Key MAX_MEMORY_SORT = new Hints.Key(Integer.class);
    public static final Hints.Key GEOMETRY_DISTANCE = new Hints.Key(Double.class);
    public static final Hints.Key GEOMETRY_GENERALIZATION = new Hints.Key(Double.class);
    public static final Hints.Key GEOMETRY_SIMPLIFICATION = new Hints.Key(Double.class);
    public static final Hints.Key SCREENMAP = new Hints.ClassKey("org.geotools.renderer.ScreenMap");
    public static final Hints.Key COORDINATE_DIMENSION = new Hints.Key(Integer.class);
    public static final Hints.ClassKey STYLE_FACTORY = new Hints.ClassKey("org.geotools.styling.StyleFactory");
    public static final Hints.OptionKey COLOR_DEFINITION = new Hints.OptionKey(new String[]{"CSS"});
    public static final Hints.ClassKey ATTRIBUTE_TYPE_FACTORY = new Hints.ClassKey("org.geotools.feature.AttributeTypeFactory");
    public static final Hints.ClassKey FILTER_FACTORY = new Hints.ClassKey("org.opengis.filter.FilterFactory");
    public static final Hints.ClassKey VIRTUAL_TABLE_PARAMETERS = new Hints.ClassKey("java.util.Map");
    public static final Hints.Key MAX_ALLOWED_TILES = new Hints.Key(Integer.class);
    public static final Hints.Key MOSAIC_LOCATION_ATTRIBUTE = new Hints.Key(String.class);
    public static final Hints.Key USE_JAI_IMAGEREAD = new Hints.Key(Boolean.class);
    public static final Hints.Key OVERVIEW_POLICY = new Hints.Key("org.geotools.coverage.grid.io.OverviewPolicy");
    public static final Hints.Key DECIMATION_POLICY = new Hints.Key("org.geotools.coverage.grid.io.DecimationPolicy");
    public static final Hints.Key TILE_ENCODING = new Hints.Key(String.class);
    public static final Hints.Key JAI_INSTANCE = new Hints.Key("javax.media.jai.JAI");
    public static final Hints.Key SAMPLE_DIMENSION_TYPE = new Hints.Key("org.opengis.coverage.SampleDimensionType");
    public static final Hints.ClassKey GRID_COVERAGE_FACTORY = new Hints.ClassKey("org.geotools.coverage.grid.GridCoverageFactory");
    public static final Hints.ClassKey EXECUTOR_SERVICE = new Hints.ClassKey("java.util.concurrent.ExecutorService");
    public static final Hints.Key RESAMPLE_TOLERANCE = new Hints.Key(Double.class);
    public static final Hints.ClassKey REPOSITORY = new Hints.ClassKey("org.geotools.data.Repository");
    public static final Hints.Key RESOLVE = new Hints.Key("net.opengis.wfs20.ResolveValueType");
    public static final Hints.Key RESOLVE_TIMEOUT = new Hints.Key(Integer.class);
    public static final Hints.Key ASSOCIATION_TRAVERSAL_DEPTH = new Hints.Key(Integer.class);
    public static final Hints.Key ASSOCIATION_PROPERTY = new Hints.Key("org.opengis.filter.expression.PropertyName");
    public static final Hints.OptionKey CACHE_POLICY = new Hints.OptionKey(new String[]{"weak", "all", "fixed", "none", "default", "soft"});
    public static final Hints.IntegerKey CACHE_LIMIT = new Hints.IntegerKey(50);
    public static final Hints.IntegerKey AUTHORITY_MAX_ACTIVE = new Hints.IntegerKey(Runtime.getRuntime().availableProcessors() + 1);
    public static final Hints.IntegerKey AUTHORITY_MIN_IDLE = new Hints.IntegerKey(1);
    public static final Hints.IntegerKey AUTHORITY_MAX_IDLE = new Hints.IntegerKey(2);
    public static final Hints.IntegerKey AUTHORITY_MIN_EVICT_IDLETIME = new Hints.IntegerKey(120000);
    public static final Hints.IntegerKey AUTHORITY_SOFTMIN_EVICT_IDLETIME = new Hints.IntegerKey(10000);
    public static final Hints.IntegerKey AUTHORITY_TIME_BETWEEN_EVICTION_RUNS = new Hints.IntegerKey(5000);
    public static final Hints.DoubleKey COMPARISON_TOLERANCE = new Hints.DoubleKey(0.0D);
    public static final Hints.Key LOCAL_DATE_TIME_HANDLING = new Hints.Key(Boolean.class);
    public static final Hints.Key ENCODE_EWKT = new Hints.Key(Boolean.class);

    public Hints() {
        super((Map)null);
    }

    public Hints(java.awt.RenderingHints.Key key, Object value) {
        super((Map)null);
        super.put(key, value);
    }

    public Hints(java.awt.RenderingHints.Key key1, Object value1, java.awt.RenderingHints.Key key2, Object value2) {
        this(key1, value1);
        super.put(key2, value2);
    }

    /** @deprecated */
    @Deprecated
    public Hints(java.awt.RenderingHints.Key key1, Object value1, Object[] pairs) {
        this(key1, value1);
        this.fromPairs(pairs);
    }

    public Hints(java.awt.RenderingHints.Key key1, Object value1, java.awt.RenderingHints.Key key2, Object value2, Object... pairs) {
        this(key1, value1, key2, value2);
        this.fromPairs(pairs);
    }

    private void fromPairs(Object[] pairs) throws IllegalArgumentException {
        if ((pairs.length & 1) != 0) {
            throw new IllegalArgumentException(Errors.format(149, pairs.length));
        } else {
            for(int i = 0; i < pairs.length; i += 2) {
                super.put(pairs[i], pairs[i + 1]);
            }

        }
    }

    public Hints(Map<? extends java.awt.RenderingHints.Key, ?> hints) {
        super(stripNonKeys(hints));
    }

    public Hints(RenderingHints hints) {
        super(stripNonKeys(hints));
    }

    static Map<java.awt.RenderingHints.Key, Object> stripNonKeys(Map<?, ?> hints) {
        if (hints == null) {
            return null;
        } else {
            Map<java.awt.RenderingHints.Key, Object> filtered = hints;
            Iterator it = hints.keySet().iterator();

            while(it.hasNext()) {
                Object key = it.next();
                if (!(key instanceof java.awt.RenderingHints.Key)) {
                    if (filtered == hints) {
                        filtered = new HashMap((Map)filtered);
                    }

                    ((Map)filtered).remove(key);
                }
            }

            return (Map)filtered;
        }
    }

    public Hints clone() {
        return (Hints)super.clone();
    }

    public static void scanSystemProperties() {
        needScan.set(true);
    }

    private static boolean ensureSystemDefaultLoaded() {
        if (needScan.get()) {
            Map<java.awt.RenderingHints.Key, Object> newGlobal = new ConcurrentHashMap(GLOBAL);
            boolean modified = GeoTools.scanForSystemHints(newGlobal);
            GLOBAL = newGlobal;
            needScan.set(false);
            return modified;
        } else {
            return false;
        }
    }

    static Hints getDefaults(boolean strict) {
        boolean changed = ensureSystemDefaultLoaded();
        Object hints;
        if (strict) {
            hints = new StrictHints(GLOBAL);
        } else {
            hints = new Hints(GLOBAL);
        }

        if (changed) {
            GeoTools.fireConfigurationChanged();
        }

        return (Hints)hints;
    }

    static void putSystemDefault(RenderingHints hints) {
        ensureSystemDefaultLoaded();
        Map<java.awt.RenderingHints.Key, Object> map = toMap(hints);
        GLOBAL.putAll(map);
        GeoTools.fireConfigurationChanged();
    }

    private static Map<java.awt.RenderingHints.Key, Object> toMap(RenderingHints hints) {
        Map<java.awt.RenderingHints.Key, Object> result = new HashMap();
        Iterator var2 = hints.entrySet().iterator();

        while(var2.hasNext()) {
            Entry<Object, Object> entry = (Entry)var2.next();
            if (entry.getKey() instanceof java.awt.RenderingHints.Key) {
                result.put((java.awt.RenderingHints.Key)entry.getKey(), entry.getValue());
            }
        }

        return result;
    }

    public static Object getSystemDefault(java.awt.RenderingHints.Key key) {
        boolean changed = ensureSystemDefaultLoaded();
        Object value = GLOBAL.get(key);
        if (changed) {
            GeoTools.fireConfigurationChanged();
        }

        return value;
    }

    public static Object putSystemDefault(java.awt.RenderingHints.Key key, Object value) {
        boolean changed = ensureSystemDefaultLoaded();
        Object old = GLOBAL.put(key, value);
        if (changed || !Utilities.equals(value, old)) {
            GeoTools.fireConfigurationChanged();
        }

        return old;
    }

    public static Object removeSystemDefault(java.awt.RenderingHints.Key key) {
        boolean changed = ensureSystemDefaultLoaded();
        Object old = GLOBAL.remove(key);
        if (changed || old != null) {
            GeoTools.fireConfigurationChanged();
        }

        return old;
    }

    public String toString() {
        String lineSeparator = System.getProperty("line.separator", "\n");
        StringBuilder buffer = new StringBuilder("Hints:");
        buffer.append(lineSeparator).append(AbstractFactory.toString(this));
        Map<?, ?> extra = null;
        boolean changed = ensureSystemDefaultLoaded();
        if (!GLOBAL.isEmpty()) {
            extra = new HashMap(GLOBAL);
        }

        if (changed) {
            GeoTools.fireConfigurationChanged();
        }

        if (extra != null) {
            extra.keySet().removeAll(this.keySet());
            if (!extra.isEmpty()) {
                buffer.append("System defaults:").append(lineSeparator).append(AbstractFactory.toString(extra));
            }
        }

        return buffer.toString();
    }

    static String nameOf(java.awt.RenderingHints.Key key) {
        if (key instanceof Hints.Key) {
            return key.toString();
        } else {
            int var1 = 0;

            while(true) {
                Class type;
                switch(var1++) {
                case 0:
                    type = RenderingHints.class;
                    break;
                case 1:
                    try {
                        type = Class.forName("javax.media.jai.JAI");
                        break;
                    } catch (ClassNotFoundException var4) {
                        ;
                    } catch (NoClassDefFoundError var5) {
                        ;
                    }
                    continue;
                default:
                    return key.toString();
                }

                String name = nameOf(type, key);
                if (name != null) {
                    return name;
                }
            }
        }
    }

    private static String nameOf(Class<?> type, java.awt.RenderingHints.Key key) {
        Field[] fields = type.getFields();

        for(int i = 0; i < fields.length; ++i) {
            Field f = fields[i];
            if (Modifier.isStatic(f.getModifiers())) {
                Object v;
                try {
                    v = f.get((Object)null);
                } catch (IllegalAccessException var7) {
                    continue;
                }

                if (v == key) {
                    return f.getName();
                }
            }
        }

        return null;
    }

    public static final class ConfigurationMetadataKey extends Hints.Key {
        private static Map<String, Hints.ConfigurationMetadataKey> map = new HashMap();

        private ConfigurationMetadataKey(String key) {
            super(key);
        }

        public static Hints.ConfigurationMetadataKey get(String key) {
            Hints.ConfigurationMetadataKey ret = (Hints.ConfigurationMetadataKey)map.get(key);
            if (ret == null) {
                Class var2 = Hints.ConfigurationMetadataKey.class;
                synchronized(Hints.ConfigurationMetadataKey.class) {
                    ret = (Hints.ConfigurationMetadataKey)map.get(key);
                    if (ret == null) {
                        ret = new Hints.ConfigurationMetadataKey(key);
                        map.put(key, ret);
                    }
                }
            }

            return ret;
        }

        public boolean isCompatibleValue(Object value) {
            return value != null;
        }
    }

    static final class DataSourceKey extends Hints.Key {
        public DataSourceKey() {
            super(DataSource.class);
        }

        public boolean isCompatibleValue(Object value) {
            return value instanceof DataSource || value instanceof String || value instanceof Name;
        }
    }

    public static final class OptionKey extends Hints.Key {
        private final Set<String> options;
        private final boolean wildcard;

        public OptionKey(String... alternatives) {
            super(String.class);
            Set<String> options = new TreeSet(Arrays.asList(alternatives));
            this.wildcard = options.remove("*");
            this.options = Collections.unmodifiableSet(options);
        }

        public Set<String> getOptions() {
            return this.options;
        }

        public boolean isCompatibleValue(Object value) {
            return this.wildcard ? value instanceof String : this.options.contains(value);
        }
    }

    public static final class DoubleKey extends Hints.Key {
        private final double number;

        public DoubleKey(double number) {
            super(Integer.class);
            this.number = number;
        }

        public double getDefault() {
            return this.number;
        }

        public double toValue(Hints hints) {
            if (hints != null) {
                Object value = hints.get(this);
                if (value instanceof Number) {
                    return ((Number)value).doubleValue();
                }

                if (value instanceof CharSequence) {
                    return Double.parseDouble(value.toString());
                }
            }

            return this.number;
        }

        public boolean isCompatibleValue(Object value) {
            if (!(value instanceof Float) && !(value instanceof Double)) {
                if (value instanceof String || value instanceof InternationalString) {
                    try {
                        Double.parseDouble(value.toString());
                    } catch (NumberFormatException var3) {
                        Logging.getLogger(Hints.DoubleKey.class).finer(var3.toString());
                    }
                }

                return false;
            } else {
                return true;
            }
        }
    }

    public static final class IntegerKey extends Hints.Key {
        private final int number;

        public IntegerKey(int number) {
            super(Integer.class);
            this.number = number;
        }

        public int getDefault() {
            return this.number;
        }

        public int toValue(Hints hints) {
            if (hints != null) {
                Object value = hints.get(this);
                if (value instanceof Number) {
                    return ((Number)value).intValue();
                }

                if (value instanceof CharSequence) {
                    return Integer.parseInt(value.toString());
                }
            }

            return this.number;
        }

        public boolean isCompatibleValue(Object value) {
            if (!(value instanceof Short) && !(value instanceof Integer)) {
                if (value instanceof String || value instanceof InternationalString) {
                    try {
                        Integer.parseInt(value.toString());
                    } catch (NumberFormatException var3) {
                        Logging.getLogger(Hints.IntegerKey.class).finer(var3.toString());
                    }
                }

                return false;
            } else {
                return true;
            }
        }
    }

    public static final class FileKey extends Hints.Key {
        private final boolean writable;

        public FileKey(boolean writable) {
            super(File.class);
            this.writable = writable;
        }

        public boolean isCompatibleValue(Object value) {
            File file;
            if (value instanceof File) {
                file = (File)value;
            } else {
                if (!(value instanceof String)) {
                    return false;
                }

                file = new File((String)value);
            }

            if (file.exists()) {
                return !this.writable || file.canWrite();
            } else {
                File parent = file.getParentFile();
                return parent != null && parent.canWrite();
            }
        }
    }

    public static final class ClassKey extends Hints.Key {
        public ClassKey(Class<?> classe) {
            super(classe);
        }

        ClassKey(String className) {
            super(className);
        }

        public boolean isCompatibleValue(Object value) {
            if (value == null) {
                return false;
            } else if (value instanceof Class[]) {
                Class<?>[] types = (Class[])((Class[])value);

                for(int i = 0; i < types.length; ++i) {
                    if (!this.isCompatibleValue(types[i])) {
                        return false;
                    }
                }

                return types.length != 0;
            } else if (value instanceof Class) {
                Class<?> type = (Class)value;
                Class<?> expected = this.getValueClass();
                if (expected.isAssignableFrom(type)) {
                    return true;
                } else {
                    if (expected.isInterface() && !type.isInterface()) {
                        int modifiers = type.getModifiers();
                        if (Modifier.isAbstract(modifiers) && !Modifier.isFinal(modifiers)) {
                            return true;
                        }
                    }

                    return false;
                }
            } else {
                return super.isCompatibleValue(value);
            }
        }
    }

    public static class Key extends java.awt.RenderingHints.Key {
        private static int count;
        private final String className;
        private transient Class<?> valueClass;

        public Key(Class<?> classe) {
            this(classe.getName());
            this.valueClass = classe;
        }

        Key(String className) {
            super(count());
            this.className = className;
        }

        private static synchronized int count() {
            return count++;
        }

        public Class<?> getValueClass() {
            if (this.valueClass == null) {
                try {
                    this.valueClass = Class.forName(this.className);
                } catch (ClassNotFoundException var2) {
                    Logging.unexpectedException(Hints.Key.class, "getValueClass", var2);
                    this.valueClass = Object.class;
                }
            }

            return this.valueClass;
        }

        public boolean isCompatibleValue(Object value) {
            return this.getValueClass().isInstance(value);
        }

        public String toString() {
            int var1 = 0;

            String name;
            do {
                Class type;
                switch(var1++) {
                case 0:
                    type = Hints.class;
                    break;
                case 1:
                    type = this.getValueClass();
                    break;
                default:
                    return super.toString();
                }

                name = Hints.nameOf(type, this);
            } while(name == null);

            return name;
        }
    }
}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yGIS

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值