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 */
016package org.ametys.cms.contenttype.indexing;
017
018import java.util.Collection;
019import java.util.Collections;
020import java.util.LinkedHashMap;
021import java.util.List;
022import java.util.Map;
023import java.util.Set;
024
025import org.ametys.cms.contenttype.ContentType;
026
027/**
028 * Indexing model for a {@link ContentType} 
029 */
030public class IndexingModel
031{
032    private Map<String, IndexingField> _fields;
033    
034    /** The indexing field references. */
035    private Map<String, Map<String, List<String>>> _fieldReferences;
036    
037    /**
038     * Build an empty indexing model.
039     */
040    public IndexingModel ()
041    {
042        _fields = new LinkedHashMap<>();
043    }
044    
045    /**
046     * Add a indexing field
047     * @param field The field to add
048     */
049    public void addIndexingField (IndexingField field)
050    {
051        _fields.put(field.getName(), field);
052    }
053
054    /**
055     * Get the indexing fields
056     * @return the indexing fields
057     */
058    public Collection<IndexingField> getFields()
059    {
060        return Collections.unmodifiableCollection(_fields.values());
061    }
062    
063    /**
064     * Get the indexing fields' names
065     * @return the indexing fields name
066     */
067    public Set<String> getFieldNames ()
068    {
069        return Collections.unmodifiableSet(_fields.keySet());
070    }
071    
072    /**
073     * Get the indexing field by its name
074     * @param fieldName The field name
075     * @return The indexing field or null if not found
076     */
077    public IndexingField getField(String fieldName)
078    {
079        return _fields.get(fieldName);
080    }
081
082    /**
083     * Get the indexing field references.
084     * @return the indexing field references
085     */
086    public Map<String, Map<String, List<String>>> getReferences()
087    {
088        return Collections.unmodifiableMap(_fieldReferences);
089    }
090    
091    /**
092     * Set the indexing field references.
093     * @param references the indexing field references to set
094     */
095    public void setReferences(Map<String, Map<String, List<String>>> references)
096    {
097        _fieldReferences = references;
098    }
099    
100}