001/*
002 * Configurate
003 * Copyright (C) zml and Configurate contributors
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.spongepowered.configurate.serialize;
018
019import java.net.URL;
020import java.util.UUID;
021import java.util.regex.Pattern;
022
023/**
024 * Scalar value serializers available
025 *
026 * <p>Each of these serializers can be used through a configuration node, or
027 * directly with a value.
028 *
029 * @since 4.0.0
030 */
031public final class Scalars {
032
033    private Scalars() {}
034
035    /**
036     * Serializer for {@code boolean} values.
037     *
038     * <p>Case-insensitive true values are: {@code true}, {@code t},
039     * {@code yes}, {@code y}, and {@code 1}.</p>
040     *
041     * <p>Case-insensitive false values are: {@code false}, {@code f},
042     * {@code no}, {@code n}, and {@code 0}</p>
043     *
044     * @since 4.0.0
045     */
046    public static final ScalarSerializer<Boolean> BOOLEAN = new BooleanSerializer();
047
048    /**
049     * Serializer for {@link String} values.
050     *
051     * <p>Values that are not already strings are converted
052     * using {@link Object#toString()}.</p>
053     *
054     * @since 4.0.0
055     */
056    public static final ScalarSerializer<String> STRING = new StringSerializer();
057
058    /**
059     * Serializer for {@code char} values.
060     *
061     * <p>A character can be converted from a 1-long {@link String}, or
062     * a number.</p>
063     *
064     * @since 4.0.0
065     */
066    public static final ScalarSerializer<Character> CHAR = new CharSerializer();
067
068    /**
069     * Serializer for values in {@code enum} classes.
070     *
071     * <p>Value lookup is case-insensitive and ignores underscores.</p>
072     *
073     * @since 4.0.0
074     */
075    public static final ScalarSerializer<Enum<?>> ENUM = new EnumValueSerializer();
076
077    /**
078     * Serializer for {@link Pattern} values.
079     *
080     * <p>Patterns will be compiled with default options.</p>
081     *
082     * @since 4.0.0
083     */
084    public static final ScalarSerializer<Pattern> PATTERN = new PatternSerializer();
085
086    /**
087     * Serializer for {@link java.net.URI} values.
088     *
089     * @since 4.0.0
090     */
091    public static final ScalarSerializer<java.net.URI> URI = new UriSerializer();
092
093    /**
094     * Serializer for {@link URL} values.
095     *
096     * @since 4.0.0
097     */
098    public static final ScalarSerializer<URL> URL = new UrlSerializer();
099
100    /**
101     * Serializer for {@link UUID} values.
102     *
103     * <p>UUIDs will be accept in RFC format, and RFC format without
104     * dashes (Mojang style).</p>
105     *
106     * @since 4.0.0
107     */
108    public static final ScalarSerializer<UUID> UUID = new UuidSerializer();
109
110    /**
111     * Serializer for {@link Byte} values.
112     *
113     * @since 4.0.0
114     */
115    public static final ScalarSerializer<Byte> BYTE = NumericSerializers.BYTE;
116
117    /**
118     * Serializer for {@link Short} values.
119     *
120     * @since 4.0.0
121     */
122    public static final ScalarSerializer<Short> SHORT = NumericSerializers.SHORT;
123
124    /**
125     * Serializer for {@link Integer} values.
126     *
127     * @since 4.0.0
128     */
129    public static final ScalarSerializer<Integer> INTEGER = NumericSerializers.INTEGER;
130
131    /**
132     * Serializer for {@link Long} values.
133     *
134     * @since 4.0.0
135     */
136    public static final ScalarSerializer<Long> LONG = NumericSerializers.LONG;
137
138    /**
139     * Serializer for {@link Float} values.
140     *
141     * @since 4.0.0
142     */
143    public static final ScalarSerializer<Float> FLOAT = NumericSerializers.FLOAT;
144
145    /**
146     * Serializer for {@link Double} values.
147     *
148     * @since 4.0.0
149     */
150    public static final ScalarSerializer<Double> DOUBLE = NumericSerializers.DOUBLE;
151
152}