mirror of
https://github.com/LBRYFoundation/lbry-database-java.git
synced 2025-08-23 09:27:22 +00:00
33 lines
No EOL
816 B
Java
33 lines
No EOL
816 B
Java
package com.lbry.database.util;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Map;
|
|
|
|
public class MapHelper{
|
|
|
|
public static <V> byte[] getKey(Map<byte[],V> map,byte[] key){
|
|
for(Map.Entry<byte[],V> entry : map.entrySet()){
|
|
if(Arrays.equals(entry.getKey(),key)){
|
|
return entry.getKey();
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static <V> V getValue(Map<byte[],V> map,byte[] key){
|
|
byte[] savedKey = MapHelper.getKey(map,key);
|
|
if(savedKey!=null){
|
|
return map.get(savedKey);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static <V> V remove(Map<byte[],V> map,byte[] key){
|
|
byte[] savedKey = MapHelper.getKey(map,key);
|
|
if(savedKey!=null){
|
|
return map.remove(savedKey);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
} |