必威体育Betway必威体育官网
当前位置:首页 > IT技术

geotool源码&Hints提示类

时间:2019-09-12 06:41:04来源:IT技术作者:seo实验室小编阅读:63次「手机版」
 

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;
        }
    }
}

相关阅读

分享到:

栏目导航

推荐阅读

热门阅读