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