All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arangodb.velocypack.internal.VPackKeyMapAdapters Maven / Gradle / Ivy

There is a newer version: 3.1.0
Show newest version
/*
 * DISCLAIMER
 *
 * Copyright 2016 ArangoDB GmbH, Cologne, Germany
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Copyright holder is ArangoDB GmbH, Cologne, Germany
 */

package com.arangodb.velocypack.internal;

import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;

import com.arangodb.velocypack.VPackKeyMapAdapter;

/**
 * @author Mark Vollmary
 *
 */
public class VPackKeyMapAdapters {

	private VPackKeyMapAdapters() {
		super();
	}

	public static VPackKeyMapAdapter> createEnumAdapter(final Type type) {
		return new VPackKeyMapAdapter>() {
			@Override
			public String serialize(final Enum key) {
				return key.name();
			}

			@SuppressWarnings({ "unchecked", "rawtypes" })
			@Override
			public Enum deserialize(final String key) {
				final Class enumType = (Class) type;
				return Enum.valueOf(enumType, key);
			}
		};
	}

	public static final VPackKeyMapAdapter STRING = new VPackKeyMapAdapter() {
		@Override
		public String serialize(final String key) {
			return key;
		}

		@Override
		public String deserialize(final String key) {
			return key;
		}
	};
	public static final VPackKeyMapAdapter BOOLEAN = new VPackKeyMapAdapter() {
		@Override
		public String serialize(final Boolean key) {
			return key.toString();
		}

		@Override
		public Boolean deserialize(final String key) {
			return Boolean.valueOf(key);
		}
	};
	public static final VPackKeyMapAdapter INTEGER = new VPackKeyMapAdapter() {
		@Override
		public String serialize(final Integer key) {
			return key.toString();
		}

		@Override
		public Integer deserialize(final String key) {
			return Integer.valueOf(key);
		}
	};
	public static final VPackKeyMapAdapter LONG = new VPackKeyMapAdapter() {
		@Override
		public String serialize(final Long key) {
			return key.toString();
		}

		@Override
		public Long deserialize(final String key) {
			return Long.valueOf(key);
		}
	};
	public static final VPackKeyMapAdapter SHORT = new VPackKeyMapAdapter() {
		@Override
		public String serialize(final Short key) {
			return key.toString();
		}

		@Override
		public Short deserialize(final String key) {
			return Short.valueOf(key);
		}
	};
	public static final VPackKeyMapAdapter DOUBLE = new VPackKeyMapAdapter() {
		@Override
		public String serialize(final Double key) {
			return key.toString();
		}

		@Override
		public Double deserialize(final String key) {
			return Double.valueOf(key);
		}
	};
	public static final VPackKeyMapAdapter FLOAT = new VPackKeyMapAdapter() {
		@Override
		public String serialize(final Float key) {
			return key.toString();
		}

		@Override
		public Float deserialize(final String key) {
			return Float.valueOf(key);
		}
	};
	public static final VPackKeyMapAdapter BIG_INTEGER = new VPackKeyMapAdapter() {
		@Override
		public String serialize(final BigInteger key) {
			return key.toString();
		}

		@Override
		public BigInteger deserialize(final String key) {
			return new BigInteger(key);
		}
	};
	public static final VPackKeyMapAdapter BIG_DECIMAL = new VPackKeyMapAdapter() {
		@Override
		public String serialize(final BigDecimal key) {
			return key.toString();
		}

		@Override
		public BigDecimal deserialize(final String key) {
			return new BigDecimal(key);
		}
	};
	public static final VPackKeyMapAdapter NUMBER = new VPackKeyMapAdapter() {
		@Override
		public String serialize(final Number key) {
			return key.toString();
		}

		@Override
		public Number deserialize(final String key) {
			return Double.valueOf(key);
		}
	};
	public static final VPackKeyMapAdapter CHARACTER = new VPackKeyMapAdapter() {
		@Override
		public String serialize(final Character key) {
			return key.toString();
		}

		@Override
		public Character deserialize(final String key) {
			return key.charAt(0);
		}
	};
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy