001/*
002 *  Copyright 2014 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016
017package org.ametys.cms.content.references;
018
019import java.util.HashMap;
020import java.util.List;
021import java.util.Map;
022
023/**
024 * Outgoing references.
025 * <p>
026 * They are simply a {@link Map} where keys are the reference types (String) and
027 * values are the reference values (List) with some convenient methods.
028 * </p>
029 */
030public class OutgoingReferences extends HashMap<String, List<String>>
031{
032    /** An unmodifiable empty map of outgoing references */
033    public static final OutgoingReferences EMPTY = new OutgoingReferences(); 
034    
035    /**
036     * Merge outgoing references with the current ones
037     * @param others The new references
038     */
039    public void merge(OutgoingReferences others)
040    {
041        if (others != null)
042        {
043            for (String type : others.keySet())
044            {
045                if (this.containsKey(type))
046                {
047                    this.get(type).addAll(others.get(type));
048                }
049                else
050                {
051                    this.put(type, others.get(type));
052                }
053            }
054        }
055    }
056}