001/*
002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and others.
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 * Contributors:
017 *     ataillefer
018 */
019package org.nuxeo.ecm.diff.model.impl;
020
021import java.util.ArrayList;
022import java.util.HashMap;
023import java.util.List;
024import java.util.Map;
025
026import org.nuxeo.ecm.diff.model.PropertyDiff;
027import org.nuxeo.ecm.diff.model.SchemaDiff;
028
029/**
030 * Implementation of SchemaDiff using a HashMap.
031 * 
032 * @author <a href="mailto:ataillefer@nuxeo.com">Antoine Taillefer</a>
033 */
034public class SchemaDiffImpl implements SchemaDiff {
035
036    private static final long serialVersionUID = -5117078340766697371L;
037
038    /**
039     * Map holding the schema diff.
040     * <p>
041     * Keys are field names. Values represent the difference between the left doc and the right doc for the given field.
042     */
043    private Map<String, PropertyDiff> schemaDiff;
044
045    /**
046     * Instantiates a new schema diff impl.
047     */
048    public SchemaDiffImpl() {
049        schemaDiff = new HashMap<String, PropertyDiff>();
050    }
051
052    public Map<String, PropertyDiff> getSchemaDiff() {
053        return schemaDiff;
054    }
055
056    public int getFieldCount() {
057        return schemaDiff.size();
058    }
059
060    public List<String> getFieldNames() {
061        return new ArrayList<String>(schemaDiff.keySet());
062    }
063
064    public PropertyDiff getFieldDiff(String field) {
065        return schemaDiff.get(field);
066    }
067
068    public PropertyDiff putFieldDiff(String field, PropertyDiff fieldDiff) {
069        return schemaDiff.put(field, fieldDiff);
070    }
071
072}