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