<commit_before>package org.postgresql.codec {

    import org.postgresql.Oid;
    import flash.utils.Dictionary;

    import org.postgresql.CodecError;

    /**
     * The CodecFactory manages mappings between ActionScript Objects (of certain
     * Classes) and PostgreSQL column values (of certain oids). A Class can be mapped
     * to an oid registering an encoder, and an oid to a Class through a decoder.
     * Only a single mapping can exist for a given oid (or Class) at any given time.
     *
     * @see org.postgresql.Oid
     * @see Class
     */
    public class CodecFactory {

        private var _decoders:Dictionary;
        private var _encoders:Dictionary;

        /**
         * Constructor. No encoders or decoders are registered by default.
         */
        public function CodecFactory() {
            _decoders = new Dictionary();
            _encoders = new Dictionary();
        }

        /**
         * Register the given encoder to map values of the inType to the inOid. If
         * an encoder was previously registered for the same inType, it is silently
         * replaced.
         *
         * @param inType
         * @param inOid
         * @param encoder
         */
        public function registerEncoder(inType:Class, encoder:IPGTypeEncoder):void {
            _encoders[inType] = encoder;
        }

        /**
         * Register the given decoder to map values of the given outOid to the outType. If
         * a decoder was previously registered for the same outOid, it is silently replaced.
         *
         * @param outOid
         * @param outType
         * @param decoder
         */
        public function registerDecoder(outOid:int, decoder:IPGTypeDecoder):void {
            _decoders[outOid] = decoder;
        }

        /**
         * Return the decoder for the given oid
         * @param oid oid for which to find decoder
         * @return registered decoder
         * @throws org.postgresql.CodecError if no decoder has been registered for the given oid
         */
        public function getDecoder(oid:int):IPGTypeDecoder {
            if (oid in _decoders) {
                return _decoders[oid];
            } else {
                throw new CodecError("Could not find suitable decoder", CodecError.DECODE, null, oid);
            }
        }

        /**
         * Return the encoder for the given Class
         * @param value for which to find encoder
         * @return registered encoder
         * @throws org.postgresql.CodecError if no encoder is registered for the given Class
         */
        public function getEncoder(clazz:Class):IPGTypeEncoder {
            if (clazz in _encoders) {
                return _encoders[clazz];
            } else {
                throw new CodecError("Could not find suitable encoder", CodecError.ENCODE, null, Oid.UNSPECIFIED, clazz);
            }
        }

    }
}<commit_msg>Support for default decoders and encoders; doc cleanup.<commit_after>package org.postgresql.codec {

    import org.postgresql.Oid;
    import flash.utils.Dictionary;

    import org.postgresql.CodecError;

    /**
     * The CodecFactory manages mappings between ActionScript Objects (of certain
     * Classes) and PostgreSQL column values (of certain oids). A Class can be mapped
     * to an oid by registering an encoder, and an oid to a Class through a decoder.
     * Only a single mapping can exist for a given oid (or Class) at any given time.
     * <p/>
     * Default encoders and decoders can also be registered.
     * <p/>
     * No encoders or decoders are registered by default.
     *
     * @see org.postgresql.Oid
     * @see Class
     */
    public class CodecFactory {

        private var _decoders:Dictionary;
        private var _encoders:Dictionary;

        private var _defaultDecoder:IPGTypeDecoder;
        private var _defaultEncoder:IPGTypeEncoder;

        /**
         * @private
         */
        public function CodecFactory() {
            _decoders = new Dictionary();
            _encoders = new Dictionary();
        }

        /**
         * Register the given encoder to map values of the inType to an oid. If
         * an encoder was previously registered for the same inType, it is silently
         * replaced.
         *
         * @param inType Class for which to register mapping
         * @param encoder encoder instance to use for given class
         */
        public function registerEncoder(inType:Class, encoder:IPGTypeEncoder):void {
            if (!encoder) {
                throw new ArgumentError("Encoder must not be null");
            }
            if (!inType) {
                throw new ArgumentError("Class to be mapped must not be null");
            }
            _encoders[inType] = encoder;
        }

        /**
         * Register a encoder to map values when no other encoder is suitable. If
         * a previous default encoder was specified, it is silently replaced.
         *
         * @param encoder encoder instance for default encoding
         */
        public function registerDefaultEncoder(encoder:IPGTypeEncoder):void {
            if (!encoder) {
                throw new ArgumentError("Encoder must not be null");
            }
            _defaultEncoder = encoder;
        }

        /**
         * Register the given decoder to map values of the given outOid to an ActionScript type. If
         * a decoder was previously registered for the same outOid, it is silently replaced.
         *
         * @param outOid oid for which to register mapping
         * @param decoder decoder instance to use for given oid
         */
        public function registerDecoder(outOid:int, decoder:IPGTypeDecoder):void {
            if (!decoder) {
                throw new ArgumentError("Decoder must not be null");
            }
            _decoders[outOid] = decoder;
        }

        /**
         * Register a decoder to map values when no other decoder is suitable. If
         * a previous default decoder was specified, it is silently replaced.
         *
         * @param decoder decoder instance to use for default decoding
         */
        public function registerDefaultDecoder(decoder:IPGTypeDecoder):void {
            if (!decoder) {
                throw new ArgumentError("Decoder must not be null");
            }
            _defaultDecoder = decoder;
        }

        /**
         * Return the decoder for the given oid
         *
         * @param oid oid for which to find decoder
         * @return registered decoder
         * @throws org.postgresql.CodecError if no decoder has been registered for the given oid
         */
        public function getDecoder(oid:int):IPGTypeDecoder {
            if (oid in _decoders) {
                return _decoders[oid];
            } else if (_defaultDecoder) {
                return _defaultDecoder;
            } else {
                throw new CodecError("Could not find suitable decoder", CodecError.DECODE, null, oid);
            }
        }

        /**
         * Return the encoder for the given Class
         *
         * @param value for which to find encoder
         * @return registered encoder
         * @throws org.postgresql.CodecError if no encoder is registered for the given Class
         */
        public function getEncoder(clazz:Class):IPGTypeEncoder {
            if (clazz in _encoders) {
                return _encoders[clazz];
            } else if (_defaultEncoder) {
                return _defaultEncoder;
            } else {
                throw new CodecError("Could not find suitable encoder", CodecError.ENCODE, null, Oid.UNSPECIFIED, clazz);
            }
        }

    }
}
{'fraction_non_alphanumeric': 0.06851274050962039, 'fraction_numerical': 0.0, 'mean_word_length': 1.845044378698225, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7484489', 'n_tokens_mistral': 2022, 'n_tokens_neox': 1914, 'n_words': 717}