gov.nasa.pds.registry.common.util.LidVidUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of registry-common Show documentation
Show all versions of registry-common Show documentation
Common code used by Harvest and Registry Manager.
package gov.nasa.pds.registry.common.util;
import java.util.Collection;
import java.util.Set;
import java.util.TreeSet;
/**
* Helper methods to work with product IDs (LIDs and LIDVIDs).
*
* @author karpenko
*/
public class LidVidUtils
{
/**
* Convert lidvids to lids. Discard vid (version) information.
* @param lidvids Collection of LidVids
* @return Collection of Lids
*/
public static Set lidvidToLid(Collection lidvids)
{
if(isEmpty(lidvids)) return null;
Set lids = new TreeSet<>();
for(String lidvid: lidvids)
{
String lid = lidvidToLid(lidvid);
lids.add(lid);
}
return lids;
}
/**
* Convert lidvid to lid. Discard vid (version) information.
* @param lidvid LidVid
* @return Lid
*/
public static String lidvidToLid(String lidvid)
{
if(lidvid == null) return null;
int idx = lidvid.indexOf("::");
if(idx < 0) return null;
return lidvid.substring(0, idx);
}
/**
* Add all values from a collection to the set.
* @param set Target set
* @param col A collection
* @return Target set
*/
public static Set add(Set set, Collection col)
{
if(isEmpty(col)) return set;
if(set == null) set = new TreeSet<>();
set.addAll(col);
return set;
}
private static boolean isEmpty(Collection col)
{
return col == null || col.isEmpty();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy