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; 020 021import java.io.Serializable; 022 023/** 024 * Representation of a property (field) diff. 025 * 026 * @author <a href="mailto:[email protected]">Antoine Taillefer</a> 027 * @since 5.6 028 */ 029public class PropertyDiff implements Serializable { 030 031 private static final long serialVersionUID = -8458912212588012911L; 032 033 protected String propertyType; 034 035 protected DifferenceType differenceType = DifferenceType.different; 036 037 /** 038 * Checks if is simple type. 039 * 040 * @return true, if is simple type 041 */ 042 public boolean isSimpleType() { 043 return PropertyType.isSimpleType(propertyType); 044 } 045 046 /** 047 * Checks if is list type. 048 * 049 * @return true, if is list type 050 */ 051 public boolean isListType() { 052 return PropertyType.isListType(propertyType); 053 } 054 055 /** 056 * Checks if is scalar list type. 057 * 058 * @return true, if is scalar list type 059 */ 060 public boolean isScalarListType() { 061 return PropertyType.isScalarListType(propertyType); 062 } 063 064 /** 065 * Checks if is complex list type. 066 * 067 * @return true, if is complex list type 068 */ 069 public boolean isComplexListType() { 070 return PropertyType.isComplexListType(propertyType); 071 } 072 073 /** 074 * Checks if is content list type. 075 * 076 * @return true, if is content list type 077 */ 078 public boolean isContentListType(String propertyType) { 079 return PropertyType.isContentListType(propertyType); 080 } 081 082 /** 083 * Checks if is complex type. 084 * 085 * @return true, if is complex type 086 */ 087 public boolean isComplexType() { 088 return PropertyType.isComplexType(propertyType); 089 } 090 091 /** 092 * Checks if is content type. 093 * 094 * @return true, if is content type 095 */ 096 public boolean isContentType() { 097 return PropertyType.isContentType(propertyType); 098 } 099 100 public String getPropertyType() { 101 return propertyType; 102 } 103 104 public void setPropertyType(String propertyType) { 105 this.propertyType = propertyType; 106 } 107 108 public DifferenceType getDifferenceType() { 109 return differenceType; 110 } 111 112 public void setDifferenceType(DifferenceType differenceType) { 113 this.differenceType = differenceType; 114 } 115 116 @Override 117 public boolean equals(Object other) { 118 119 if (this == other) { 120 return true; 121 } 122 if (other == null || !(other instanceof PropertyDiff)) { 123 return false; 124 } 125 String otherPropertyType = ((PropertyDiff) other).getPropertyType(); 126 DifferenceType otherDifferenceType = ((PropertyDiff) other).getDifferenceType(); 127 return differenceType.equals(otherDifferenceType) 128 && ((propertyType == null && otherPropertyType == null) || (propertyType != null 129 && otherPropertyType != null && propertyType.equals(otherPropertyType))); 130 } 131 132 @Override 133 public String toString() { 134 135 StringBuilder sb = new StringBuilder(); 136 sb.append(" ("); 137 sb.append(propertyType); 138 sb.append(", "); 139 sb.append(differenceType.name()); 140 sb.append(")"); 141 return sb.toString(); 142 } 143}