001/* 002 * JGrapes Event Driven Framework 003 * Copyright (C) 2017-2022 Michael N. Lipp 004 * 005 * This program is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU Affero General Public License as published by 007 * the Free Software Foundation; either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, but 011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License 013 * for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License along 016 * with this program; if not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.jgrapes.webconsole.base; 020 021import java.beans.ConstructorProperties; 022 023/** 024 * Defines a web console component base model following the 025 * JavaBean conventions. Conlet models should follow these 026 * conventions because many template engines rely on them. 027 * Besides, following these conventions often simplifies 028 * serialization to portable formats. 029 * 030 * This base class defines `conletId` as only property. 031 * Additionally, it overrides {@link #hashCode()} and 032 * {@link #equals(Object)} using the `conletId` as single 033 * criterion. 034 */ 035public class ConletBaseModel { 036 037 protected String conletId; 038 039 /** 040 * Creates a new model with the given type and id. 041 * 042 * @param conletId the web console component id 043 */ 044 @ConstructorProperties({ "conletId" }) 045 public ConletBaseModel(String conletId) { 046 this.conletId = conletId; 047 } 048 049 /** 050 * Returns the web console component id. 051 * 052 * @return the web console component id 053 */ 054 public String getConletId() { 055 return conletId; 056 } 057 058 /** 059 * Hash code. 060 * 061 * @return the int 062 */ 063 /* 064 * (non-Javadoc) 065 * 066 * @see java.lang.Object#hashCode() 067 */ 068 @Override 069 public int hashCode() { 070 final int prime = 31; 071 int result = 1; 072 result = prime * result 073 + ((conletId == null) ? 0 : conletId.hashCode()); 074 return result; 075 } 076 077 /** 078 * Two objects are equal if they have equal web console component ids. 079 * 080 * @param obj the other object 081 * @return the result 082 */ 083 @Override 084 public boolean equals(Object obj) { 085 if (this == obj) { 086 return true; 087 } 088 if (obj == null) { 089 return false; 090 } 091 if (getClass() != obj.getClass()) { 092 return false; 093 } 094 ConletBaseModel other = (ConletBaseModel) obj; 095 if (conletId == null) { 096 if (other.conletId != null) { 097 return false; 098 } 099 } else if (!conletId.equals(other.conletId)) { 100 return false; 101 } 102 return true; 103 } 104}