001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements. See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache license, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License. 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     */
017    package org.apache.logging.log4j.core.appender.db.nosql.couch;
018    
019    import java.util.ArrayList;
020    import java.util.Arrays;
021    import java.util.HashMap;
022    import java.util.Map;
023    
024    import org.apache.logging.log4j.core.appender.db.nosql.NoSQLObject;
025    
026    /**
027     * The Apache CouchDB implementation of {@link NoSQLObject}.
028     */
029    public final class CouchDBObject implements NoSQLObject<Map<String, Object>> {
030        private final Map<String, Object> map;
031    
032        public CouchDBObject() {
033            this.map = new HashMap<String, Object>();
034        }
035    
036        @Override
037        public void set(final String field, final Object value) {
038            this.map.put(field, value);
039        }
040    
041        @Override
042        public void set(final String field, final NoSQLObject<Map<String, Object>> value) {
043            this.map.put(field, value.unwrap());
044        }
045    
046        @Override
047        public void set(final String field, final Object[] values) {
048            this.map.put(field, Arrays.asList(values));
049        }
050    
051        @Override
052        public void set(final String field, final NoSQLObject<Map<String, Object>>[] values) {
053            final ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
054            for (final NoSQLObject<Map<String, Object>> value : values) {
055                list.add(value.unwrap());
056            }
057            this.map.put(field, list);
058        }
059    
060        @Override
061        public Map<String, Object> unwrap() {
062            return this.map;
063        }
064    }