Skip to content

Commit

Permalink
issue #535 - Deduplicate the SearchParameter map
Browse files Browse the repository at this point in the history
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
lmsurpre committed Dec 23, 2019
1 parent 03ecee6 commit 202f3f4
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 471 deletions.
@@ -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();
}
}

0 comments on commit 202f3f4

Please sign in to comment.