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.DocumentDiff; 025import org.nuxeo.ecm.diff.model.SchemaDiff; 026 027/** 028 * Implementation of DocumentDiff using a HashMap. 029 * 030 * @author <a href="mailto:ataillefer@nuxeo.com">Antoine Taillefer</a> 031 */ 032public class DocumentDiffImpl implements DocumentDiff { 033 034 private static final long serialVersionUID = -5117078340766697371L; 035 036 /** 037 * Map holding the doc diff. 038 * <p> 039 * Keys are schema names. Values represent the differences between the fields of the schema. 040 */ 041 private Map<String, SchemaDiff> docDiff; 042 043 /** 044 * Instantiates a new document diff impl. 045 */ 046 public DocumentDiffImpl() { 047 docDiff = new HashMap<String, SchemaDiff>(); 048 } 049 050 public Map<String, SchemaDiff> getDocDiff() { 051 return docDiff; 052 } 053 054 public int getSchemaCount() { 055 return docDiff.size(); 056 } 057 058 public boolean isDocDiffEmpty() { 059 return getSchemaCount() == 0; 060 } 061 062 public List<String> getSchemaNames() { 063 return new ArrayList<String>(docDiff.keySet()); 064 } 065 066 public SchemaDiff getSchemaDiff(String schema) { 067 return docDiff.get(schema); 068 } 069 070 public SchemaDiff initSchemaDiff(String schema) { 071 SchemaDiff schemaDiff = new SchemaDiffImpl(); 072 docDiff.put(schema, schemaDiff); 073 return schemaDiff; 074 } 075 076}