Skip to content

Commit 8ebf356

Browse files
committed
use BiMap over iterating of Map values to find key
1 parent 6d1fefd commit 8ebf356

File tree

1 file changed

+9
-7
lines changed
  • lightblue-ldap-metadata/src/main/java/com/redhat/lightblue/metadata/ldap/model

1 file changed

+9
-7
lines changed

lightblue-ldap-metadata/src/main/java/com/redhat/lightblue/metadata/ldap/model/LdapMetadata.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020

2121
import java.util.HashMap;
2222
import java.util.Map;
23-
import java.util.Map.Entry;
2423

24+
import com.google.common.collect.BiMap;
25+
import com.google.common.collect.HashBiMap;
2526
import com.redhat.lightblue.common.ldap.LdapFieldNameTranslator;
2627
import com.redhat.lightblue.util.Path;
2728

@@ -34,7 +35,7 @@
3435
*/
3536
public class LdapMetadata implements LdapFieldNameTranslator{
3637

37-
private final Map<Path, String> fieldsToAttributes = new HashMap<Path, String>();
38+
private final BiMap<Path, String> fieldsToAttributes = HashBiMap.create();
3839

3940
/**
4041
* Returns an immutable copy of the internal collection of {@link FieldAttributeMapping}s.
@@ -62,12 +63,13 @@ public String translateFieldName(Path path){
6263

6364
@Override
6465
public Path translateAttributeName(String attributeName){
65-
for(Entry<Path, String> f2a : fieldsToAttributes.entrySet()){
66-
if(f2a.getValue().equalsIgnoreCase(attributeName)){
67-
return f2a.getKey();
68-
}
66+
Path fieldPath = fieldsToAttributes.inverse().get(attributeName);
67+
68+
if(fieldPath == null){
69+
return new Path(attributeName);
6970
}
70-
return new Path(attributeName);
71+
72+
return fieldPath;
7173
}
7274

7375
/**

0 commit comments

Comments
 (0)