001/*- 002 * #%L 003 * HAPI FHIR JPA Server 004 * %% 005 * Copyright (C) 2014 - 2024 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.jpa.search.builder.models; 021 022import com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn; 023import org.apache.commons.lang3.builder.EqualsBuilder; 024import org.apache.commons.lang3.builder.HashCodeBuilder; 025 026public class PredicateBuilderCacheKey { 027 private final DbColumn[] myDbColumn; 028 private final PredicateBuilderTypeEnum myType; 029 private final String myParamName; 030 private final int myHashCode; 031 032 public PredicateBuilderCacheKey(DbColumn[] theDbColumn, PredicateBuilderTypeEnum theType, String theParamName) { 033 myDbColumn = theDbColumn; 034 myType = theType; 035 myParamName = theParamName; 036 HashCodeBuilder hashBuilder = new HashCodeBuilder().append(myType).append(myParamName); 037 if (theDbColumn != null) { 038 for (DbColumn next : theDbColumn) { 039 hashBuilder.append(next); 040 } 041 } 042 myHashCode = hashBuilder.toHashCode(); 043 } 044 045 @Override 046 public boolean equals(Object theO) { 047 if (this == theO) { 048 return true; 049 } 050 051 if (theO == null || getClass() != theO.getClass()) { 052 return false; 053 } 054 055 PredicateBuilderCacheKey that = (PredicateBuilderCacheKey) theO; 056 057 return new EqualsBuilder() 058 .append(myDbColumn, that.myDbColumn) 059 .append(myType, that.myType) 060 .append(myParamName, that.myParamName) 061 .isEquals(); 062 } 063 064 @Override 065 public int hashCode() { 066 return myHashCode; 067 } 068}