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 * Antoine Taillefer 018 */ 019package org.nuxeo.ecm.diff.model.impl; 020 021import java.io.Serializable; 022 023import org.nuxeo.ecm.diff.model.DifferenceType; 024import org.nuxeo.ecm.diff.model.PropertyDiffDisplay; 025 026/** 027 * Default implementation of {@link PropertyDiffDisplay}. 028 * 029 * @author <a href="mailto:[email protected]">Antoine Taillefer</a> 030 * @since 5.6 031 */ 032public class PropertyDiffDisplayImpl implements PropertyDiffDisplay { 033 034 private static final long serialVersionUID = 875764424409126845L; 035 036 protected Serializable value; 037 038 protected DifferenceType differenceType; 039 040 protected String styleClass = DEFAULT_STYLE_CLASS; 041 042 public PropertyDiffDisplayImpl(Serializable value) { 043 this(value, DifferenceType.different); 044 } 045 046 public PropertyDiffDisplayImpl(Serializable value, DifferenceType differenceType) { 047 this(value, differenceType, null); 048 } 049 050 public PropertyDiffDisplayImpl(Serializable value, String styleClass) { 051 this(value, DifferenceType.different, styleClass); 052 } 053 054 public PropertyDiffDisplayImpl(Serializable value, DifferenceType differenceType, String styleClass) { 055 this.value = value; 056 this.differenceType = differenceType; 057 this.styleClass = styleClass; 058 } 059 060 public Serializable getValue() { 061 return value; 062 } 063 064 public void setValue(Serializable value) { 065 this.value = value; 066 } 067 068 public DifferenceType getDifferenceType() { 069 return differenceType; 070 } 071 072 public void setDifferenceType(DifferenceType differenceType) { 073 this.differenceType = differenceType; 074 } 075 076 public String getStyleClass() { 077 return styleClass; 078 } 079 080 public void setStyleClass(String styleClass) { 081 this.styleClass = styleClass; 082 } 083 084 @Override 085 public boolean equals(Object other) { 086 087 if (this == other) { 088 return true; 089 } 090 if (other == null || !(other instanceof PropertyDiffDisplay)) { 091 return false; 092 } 093 Serializable otherValue = ((PropertyDiffDisplay) other).getValue(); 094 Serializable otherStyleClass = ((PropertyDiffDisplay) other).getStyleClass(); 095 DifferenceType otherDifferenceType = ((PropertyDiffDisplay) other).getDifferenceType(); 096 if (value == null && otherValue == null && styleClass == null && otherStyleClass == null 097 && differenceType.equals(otherDifferenceType)) { 098 return true; 099 } 100 return differenceType.equals(otherDifferenceType) 101 && (value == null && otherValue == null && styleClass != null && styleClass.equals(otherStyleClass) 102 || styleClass == null && otherStyleClass == null && value != null && value.equals(otherValue) || value != null 103 && value.equals(otherValue) && styleClass != null && styleClass.equals(otherStyleClass)); 104 } 105 106 @Override 107 public String toString() { 108 StringBuilder sb = new StringBuilder(); 109 sb.append(value); 110 sb.append(" / "); 111 sb.append(differenceType.name()); 112 sb.append(" / "); 113 sb.append(styleClass); 114 return sb.toString(); 115 } 116}