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.dao; 021 022import ca.uhn.fhir.jpa.model.entity.ResourceEncodingEnum; 023import com.google.common.hash.HashCode; 024import jakarta.annotation.Nullable; 025import org.hl7.fhir.instance.model.api.IBaseResource; 026 027import java.util.Arrays; 028import java.util.List; 029import java.util.Objects; 030import java.util.StringJoiner; 031 032/** 033 * POJO to contain the results of {@link ResourceHistoryCalculator#calculateResourceHistoryState(IBaseResource, ResourceEncodingEnum, List)} 034 */ 035public class ResourceHistoryState { 036 @Nullable 037 private final String myResourceText; 038 039 @Nullable 040 private final byte[] myResourceBinary; 041 042 private final ResourceEncodingEnum myEncoding; 043 private final HashCode myHashCode; 044 045 public ResourceHistoryState( 046 @Nullable String theResourceText, 047 @Nullable byte[] theResourceBinary, 048 ResourceEncodingEnum theEncoding, 049 HashCode theHashCode) { 050 myResourceText = theResourceText; 051 myResourceBinary = theResourceBinary; 052 myEncoding = theEncoding; 053 myHashCode = theHashCode; 054 } 055 056 @Nullable 057 public String getResourceText() { 058 return myResourceText; 059 } 060 061 @Nullable 062 public byte[] getResourceBinary() { 063 return myResourceBinary; 064 } 065 066 public ResourceEncodingEnum getEncoding() { 067 return myEncoding; 068 } 069 070 public HashCode getHashCode() { 071 return myHashCode; 072 } 073 074 @Override 075 public boolean equals(Object theO) { 076 if (this == theO) { 077 return true; 078 } 079 if (theO == null || getClass() != theO.getClass()) { 080 return false; 081 } 082 ResourceHistoryState that = (ResourceHistoryState) theO; 083 return Objects.equals(myResourceText, that.myResourceText) 084 && Arrays.equals(myResourceBinary, that.myResourceBinary) 085 && myEncoding == that.myEncoding 086 && Objects.equals(myHashCode, that.myHashCode); 087 } 088 089 @Override 090 public int hashCode() { 091 int result = Objects.hash(myResourceText, myEncoding, myHashCode); 092 result = 31 * result + Arrays.hashCode(myResourceBinary); 093 return result; 094 } 095 096 @Override 097 public String toString() { 098 return new StringJoiner(", ", ResourceHistoryState.class.getSimpleName() + "[", "]") 099 .add("myResourceText='" + myResourceText + "'") 100 .add("myResourceBinary=" + Arrays.toString(myResourceBinary)) 101 .add("myEncoding=" + myEncoding) 102 .add("myHashCode=" + myHashCode) 103 .toString(); 104 } 105}