-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #537 from IBM/lee-master
issue #535 - Deduplicate the SearchParameter map
- Loading branch information
Showing
7 changed files
with
264 additions
and
490 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
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,65 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2019 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package com.ibm.fhir.search.parameters; | ||
|
||
import java.util.Collection; | ||
import java.util.LinkedHashMap; | ||
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() { | ||
// LinkedHashMaps to preserve insertion order | ||
codeMap = new LinkedHashMap<>(); | ||
urlMap = new LinkedHashMap<>(); | ||
} | ||
|
||
/** | ||
* @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.