001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * ataillefer 016 */ 017package org.nuxeo.ecm.diff.model.impl; 018 019import java.util.ArrayList; 020import java.util.HashMap; 021import java.util.List; 022import java.util.Map; 023 024import org.nuxeo.ecm.diff.model.PropertyDiff; 025import org.nuxeo.ecm.diff.model.SchemaDiff; 026 027/** 028 * Implementation of SchemaDiff using a HashMap. 029 * 030 * @author <a href="mailto:ataillefer@nuxeo.com">Antoine Taillefer</a> 031 */ 032public class SchemaDiffImpl implements SchemaDiff { 033 034 private static final long serialVersionUID = -5117078340766697371L; 035 036 /** 037 * Map holding the schema diff. 038 * <p> 039 * Keys are field names. Values represent the difference between the left doc and the right doc for the given field. 040 */ 041 private Map<String, PropertyDiff> schemaDiff; 042 043 /** 044 * Instantiates a new schema diff impl. 045 */ 046 public SchemaDiffImpl() { 047 schemaDiff = new HashMap<String, PropertyDiff>(); 048 } 049 050 public Map<String, PropertyDiff> getSchemaDiff() { 051 return schemaDiff; 052 } 053 054 public int getFieldCount() { 055 return schemaDiff.size(); 056 } 057 058 public List<String> getFieldNames() { 059 return new ArrayList<String>(schemaDiff.keySet()); 060 } 061 062 public PropertyDiff getFieldDiff(String field) { 063 return schemaDiff.get(field); 064 } 065 066 public PropertyDiff putFieldDiff(String field, PropertyDiff fieldDiff) { 067 return schemaDiff.put(field, fieldDiff); 068 } 069 070}