001/* 002 * Copyright 2018 Anyware Services 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 */ 016package org.ametys.cms.content.compare; 017 018import java.util.ArrayList; 019import java.util.List; 020 021import org.ametys.cms.repository.Content; 022import org.ametys.runtime.model.View; 023 024/** 025 * Result of a comparison between 2 contents 026 */ 027public class ContentComparatorResult 028{ 029 private Content _content1; 030 private Content _content2; 031 private String _viewName; 032 private View _view; 033 034 private boolean _areEquals; 035 private List<ContentComparatorChange> _changes; 036 037 /** 038 * Create a new result from 2 contents 039 * @param content1 1st content 040 * @param content2 2nd content 041 */ 042 public ContentComparatorResult(Content content1, Content content2) 043 { 044 this(content1, content2, null, null); 045 } 046 047 /** 048 * Create a new result from 2 contents and the name of a metadataSet 049 * @param content1 1st content 050 * @param content2 2nd content 051 * @param viewName name of the {@link View} 052 * @param view {@link View} 053 */ 054 public ContentComparatorResult(Content content1, Content content2, String viewName, View view) 055 { 056 this._content1 = content1; 057 this._content2 = content2; 058 this._viewName = viewName; 059 this._view = view; 060 if (content1 != null && content2 != null) 061 { 062 this._areEquals = true; 063 } 064 else 065 { 066 this._areEquals = false; 067 } 068 this._changes = new ArrayList<>(); 069 } 070 071 /** 072 * are the contents equals ? 073 * @return true if equals 074 */ 075 public boolean areEquals() 076 { 077 return this._areEquals; 078 } 079 080 /** 081 * If contents are not equals, a list of {@link ContentComparatorChange} is generated 082 * @return list of {@link ContentComparatorChange} 083 */ 084 public List<ContentComparatorChange> getChanges() 085 { 086 return this._changes; 087 } 088 089 /** 090 * get the 1st content of the comparison 091 * @return 1st content 092 */ 093 public Content getContent1() 094 { 095 return this._content1; 096 } 097 098 /** 099 * get the 1st content of the comparison 100 * @return 2nd content 101 */ 102 public Content getContent2() 103 { 104 return this._content2; 105 } 106 107 /** 108 * get the name of the {@link View} 109 * @return View's name (can be null) 110 */ 111 public String getViewName() 112 { 113 return this._viewName; 114 } 115 116 /** 117 * get the {@link View} (generated from the view name, of from all attributes) 118 * @return {@link View} 119 */ 120 public View getView() 121 { 122 return this._view; 123 } 124 125 /** 126 * add a change to the list 127 * @param change a new change 128 */ 129 protected void addChange(ContentComparatorChange change) 130 { 131 this._changes.add(change); 132 setNotEquals(); 133 } 134 135 /** 136 * declare that the 2 contents are not equals 137 */ 138 protected void setNotEquals() 139 { 140 this._areEquals = false; 141 } 142 143 @Override 144 public String toString() 145 { 146 return "ContentComparatorResult [content1=" + _content1 + ", content2=" + _content2 + ", viewName=" + _viewName + ", view=" + _view + ", areEquals=" + _areEquals 147 + ", changes=" + _changes + "]"; 148 } 149 150 151}