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

org.bson.codecs.ValueCodecProvider Maven / Gradle / Ivy

Go to download

The MongoDB Java Driver uber-artifact, containing mongodb-driver, mongodb-driver-core, and bson

The newest version!
/*
 * Copyright 2008-present MongoDB, Inc.
 *
 * 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.
 */

package org.bson.codecs;

import org.bson.codecs.configuration.CodecProvider;
import org.bson.codecs.configuration.CodecRegistry;

import java.util.HashMap;
import java.util.Map;

/**
 * A Codec provider for dynamically-typed value classes.  Other providers are needed for containers for maps and arrays.  It provides the
 * following codecs:
 *
 * 
    *
  • {@link org.bson.codecs.BinaryCodec}
  • *
  • {@link org.bson.codecs.BooleanCodec}
  • *
  • {@link org.bson.codecs.DateCodec}
  • *
  • {@link org.bson.codecs.DoubleCodec}
  • *
  • {@link org.bson.codecs.IntegerCodec}
  • *
  • {@link org.bson.codecs.LongCodec}
  • *
  • {@link org.bson.codecs.Decimal128Codec}
  • *
  • {@link org.bson.codecs.MinKeyCodec}
  • *
  • {@link org.bson.codecs.MaxKeyCodec}
  • *
  • {@link org.bson.codecs.CodeCodec}
  • *
  • {@link org.bson.codecs.ObjectIdCodec}
  • *
  • {@link org.bson.codecs.CharacterCodec}
  • *
  • {@link org.bson.codecs.StringCodec}
  • *
  • {@link org.bson.codecs.SymbolCodec}
  • *
  • {@link org.bson.codecs.UuidCodec}
  • *
  • {@link org.bson.codecs.ByteCodec}
  • *
  • {@link org.bson.codecs.ShortCodec}
  • *
  • {@link org.bson.codecs.ByteArrayCodec}
  • *
  • {@link org.bson.codecs.FloatCodec}
  • *
  • {@link org.bson.codecs.AtomicBooleanCodec}
  • *
  • {@link org.bson.codecs.AtomicIntegerCodec}
  • *
  • {@link org.bson.codecs.AtomicLongCodec}
  • *
* * @since 3.0 */ public class ValueCodecProvider implements CodecProvider { private final Map, Codec> codecs = new HashMap, Codec>(); /** * A provider of Codecs for simple value types. */ public ValueCodecProvider() { addCodecs(); } @Override @SuppressWarnings("unchecked") public Codec get(final Class clazz, final CodecRegistry registry) { return (Codec) codecs.get(clazz); } private void addCodecs() { addCodec(new BinaryCodec()); addCodec(new BooleanCodec()); addCodec(new DateCodec()); addCodec(new DoubleCodec()); addCodec(new IntegerCodec()); addCodec(new LongCodec()); addCodec(new MinKeyCodec()); addCodec(new MaxKeyCodec()); addCodec(new CodeCodec()); addCodec(new Decimal128Codec()); addCodec(new BigDecimalCodec()); addCodec(new ObjectIdCodec()); addCodec(new CharacterCodec()); addCodec(new StringCodec()); addCodec(new SymbolCodec()); addCodec(new OverridableUuidRepresentationUuidCodec()); addCodec(new ByteCodec()); addCodec(new PatternCodec()); addCodec(new ShortCodec()); addCodec(new ByteArrayCodec()); addCodec(new FloatCodec()); addCodec(new AtomicBooleanCodec()); addCodec(new AtomicIntegerCodec()); addCodec(new AtomicLongCodec()); } private void addCodec(final Codec codec) { codecs.put(codec.getEncoderClass(), codec); } @Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } return true; } @Override public int hashCode() { return 0; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy