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 * Antoine Taillefer 016 */ 017package org.nuxeo.ecm.diff.model.impl; 018 019import org.nuxeo.ecm.diff.model.DifferenceType; 020import org.nuxeo.ecm.diff.model.PropertyDiff; 021import org.nuxeo.ecm.diff.model.PropertyType; 022 023/** 024 * Implementation of {@link PropertyDiff} for a content property (blob). 025 * 026 * @author <a href="mailto:ataillefer@nuxeo.com">Antoine Taillefer</a> 027 * @since 5.6 028 */ 029public class ContentPropertyDiff extends PropertyDiff { 030 031 private static final long serialVersionUID = -1030336913574192065L; 032 033 protected ContentProperty leftContent; 034 035 protected ContentProperty rightContent; 036 037 /** 038 * Instantiates a new content property diff with the {@link PropertyType#CONTENT} property type. 039 * 040 * @param propertyType the property type 041 */ 042 public ContentPropertyDiff() { 043 this.propertyType = PropertyType.CONTENT; 044 } 045 046 /** 047 * Instantiates a new content property diff with a difference type. 048 * 049 * @param propertyType the property type 050 */ 051 public ContentPropertyDiff(DifferenceType differenceType) { 052 this(); 053 this.differenceType = differenceType; 054 } 055 056 /** 057 * Instantiates a new content property diff with the {@link PropertyType#CONTENT} property type, the 058 * {@link DifferenceType#different} difference type, a left content and right content. 059 * 060 * @param leftContent the left content 061 * @param rightContent the right content 062 */ 063 public ContentPropertyDiff(ContentProperty leftContent, ContentProperty rightContent) { 064 065 this(DifferenceType.different, leftContent, rightContent); 066 } 067 068 /** 069 * Instantiates a new content property diff with the {@link PropertyType#CONTENT} property type, a difference type, 070 * a left content and right content. 071 * 072 * @param differenceType the difference type 073 * @param leftContent the left content 074 * @param rightContent the right content 075 */ 076 public ContentPropertyDiff(DifferenceType differenceType, ContentProperty leftContent, ContentProperty rightContent) { 077 078 this(PropertyType.CONTENT, differenceType, leftContent, rightContent); 079 } 080 081 /** 082 * Instantiates a new content property diff with a property type, difference type, left content and right content. 083 * 084 * @param propertyType the property type 085 * @param differenceType the difference type 086 * @param leftContent the left content 087 * @param rightContent the right content 088 */ 089 public ContentPropertyDiff(String propertyType, DifferenceType differenceType, ContentProperty leftContent, 090 ContentProperty rightContent) { 091 092 this.propertyType = propertyType; 093 this.differenceType = differenceType; 094 this.leftContent = leftContent; 095 this.rightContent = rightContent; 096 } 097 098 @Override 099 public boolean equals(Object other) { 100 101 if (!super.equals(other)) { 102 return false; 103 } 104 if (this == other) { 105 return true; 106 } 107 if (!(other instanceof ContentPropertyDiff)) { 108 return false; 109 } 110 111 ContentProperty otherLeftContent = ((ContentPropertyDiff) other).getLeftContent(); 112 ContentProperty otherRightContent = ((ContentPropertyDiff) other).getRightContent(); 113 114 return (leftContent == null && otherLeftContent == null && rightContent == null && otherRightContent == null) 115 || (leftContent == null && otherLeftContent == null && rightContent != null && rightContent.equals(otherRightContent)) 116 || (rightContent == null && otherRightContent == null && leftContent != null && leftContent.equals(otherLeftContent)) 117 || (leftContent != null && rightContent != null && leftContent.equals(otherLeftContent) && rightContent.equals(otherRightContent)); 118 } 119 120 @Override 121 public String toString() { 122 123 StringBuilder sb = new StringBuilder(); 124 125 sb.append(leftContent); 126 sb.append(" --> "); 127 sb.append(rightContent); 128 sb.append(super.toString()); 129 130 return sb.toString(); 131 } 132 133 public ContentProperty getLeftContent() { 134 return leftContent; 135 } 136 137 public void setLeftContent(ContentProperty leftContent) { 138 this.leftContent = leftContent; 139 } 140 141 public ContentProperty getRightContent() { 142 return rightContent; 143 } 144 145 public void setRightContent(ContentProperty rightContent) { 146 this.rightContent = rightContent; 147 } 148}