001package ca.cdr.api.fhir.tokenization; 002 003import jakarta.annotation.Nonnull; 004import org.apache.commons.lang3.Validate; 005 006import java.util.IdentityHashMap; 007import java.util.Map; 008 009/** 010 * This class is used to return de-tokenization results by the {@link ITokenizationProvider} 011 */ 012public class DetokenizationResults { 013 014 private final Map<DetokenizationRequest, String> myResults = new IdentityHashMap<>(); 015 016 /** 017 * For each request in the {@link DetokenizationRequests}, this method should be called 018 * exactly once to provide the corresponding de-tokenized string. 019 */ 020 public void addResult(@Nonnull DetokenizationRequest theRequest, @Nonnull String theResult) { 021 Validate.notNull(theRequest, "The request must not be null"); 022 Validate.notBlank(theResult, "The result must not be null or empty"); 023 Validate.isTrue(!myResults.containsKey(theRequest), "Can not add multiple results for the same request"); 024 myResults.put(theRequest, theResult); 025 } 026 027 public String getResult(DetokenizationRequest theRequest) { 028 return myResults.get(theRequest); 029 } 030}