All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gov.nasa.pds.registry.common.connection.es.GetAltIdsParser Maven / Gradle / Ivy

The newest version!
package gov.nasa.pds.registry.common.connection.es;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

class GetAltIdsParser implements SearchResponseParser.Callback
{
    private Map> map;
    
    
    GetAltIdsParser()
    {
        map = new TreeMap<>();
    }

    
    public Map> getIdMap()
    {
        return map;
    }
    
    
    @Override
    public void onRecord(String id, Object rec)
    {
        if(rec instanceof Map)
        {
            Object obj = ((Map)rec).get("alternate_ids");
            if(obj == null) return;
            
            // Multiple values
            if(obj instanceof List)
            {
                Set altIds = new TreeSet<>();
                for(Object item: (List)obj)
                {
                    altIds.add(item.toString());
                }
                
                map.put(id, altIds);
            }
            // Single value
            else if(obj instanceof String)
            {
                Set altIds = new TreeSet<>();
                altIds.add((String)obj);
                map.put(id, altIds);
            }
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy