Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #535 - Deduplicate the SearchParameter map
Previously, the parameter maps built by ParametersUtil had each SearchParameter listed twice...once by "code" and once by "url". This pull request introduces a new ParametersMap object that encapsulates two separate maps and presents it as a single object. Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
- Loading branch information
Showing
5 changed files
with
230 additions
and
471 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
fhir-search/src/main/java/com/ibm/fhir/search/parameters/ParametersMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2019 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package com.ibm.fhir.search.parameters; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.ibm.fhir.model.resource.SearchParameter; | ||
|
||
/** | ||
* A object for storing multiple on a common list of SearchParameter | ||
*/ | ||
public class ParametersMap { | ||
private final Map<String, SearchParameter> codeMap; | ||
private final Map<String, SearchParameter> urlMap; | ||
|
||
/** | ||
* Construct a ParametersMap from a Bunlde of SearchParameter | ||
*/ | ||
public ParametersMap() { | ||
codeMap = new HashMap<>(); | ||
urlMap = new HashMap<>(); | ||
} | ||
|
||
/** | ||
* @implSpec package-private to prevent insertion from outside the package | ||
*/ | ||
void insert(String code, String url, SearchParameter parameter) { | ||
codeMap.put(code, parameter); | ||
urlMap.put(url, parameter); | ||
} | ||
|
||
/** | ||
* @implSpec package-private to prevent insertion from outside the package | ||
*/ | ||
void insertAll(ParametersMap map) { | ||
codeMap.putAll(map.codeMap); | ||
urlMap.putAll(map.urlMap); | ||
} | ||
|
||
public SearchParameter lookupByCode(String searchParameterCode) { | ||
return codeMap.get(searchParameterCode); | ||
} | ||
|
||
public SearchParameter lookupByUrl(String searchParameterUrl) { | ||
return urlMap.get(searchParameterUrl); | ||
} | ||
|
||
public Collection<SearchParameter> values() { | ||
return codeMap.values(); | ||
} | ||
|
||
public boolean isEmpty() { | ||
return codeMap.isEmpty(); | ||
} | ||
|
||
public int size() { | ||
return codeMap.size(); | ||
} | ||
} |
Oops, something went wrong.