Skip to content

Commit

Permalink
Merge pull request #537 from IBM/lee-master
Browse files Browse the repository at this point in the history
issue #535 - Deduplicate the SearchParameter map
  • Loading branch information
lmsurpre authored Dec 24, 2019
2 parents 8154257 + e35ee27 commit 5d33c3f
Show file tree
Hide file tree
Showing 7 changed files with 264 additions and 490 deletions.
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();
}
}
Loading

0 comments on commit 5d33c3f

Please sign in to comment.