Changeset View
Changeset View
Standalone View
Standalone View
java/server/src/main/java/org/softwareheritage/graph/Node.java
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | public static Node.Type fromInt(int intType) { | ||||
return REV; | return REV; | ||||
case 5: | case 5: | ||||
return SNP; | return SNP; | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
/** | /** | ||||
* Parses SWH node type from string. | * Converts string to corresponding SWH node type. | ||||
* | * | ||||
* @param strType node type represented as a string | * @param strType node type represented as a string | ||||
* @return the corresponding {@link Node.Type} value | * @return the corresponding {@link Node.Type} value | ||||
* @see org.softwareheritage.graph.Node.Type | * @see org.softwareheritage.graph.Node.Type | ||||
*/ | */ | ||||
public static Node.Type fromStr(String strType) { | public static Node.Type fromStr(String strType) { | ||||
if (!strType.matches("cnt|dir|ori|rel|rev|snp")) { | if (!strType.matches("cnt|dir|ori|rel|rev|snp")) { | ||||
throw new IllegalArgumentException("Unknown node type: " + strType); | throw new IllegalArgumentException("Unknown node type: " + strType); | ||||
} | } | ||||
return Node.Type.valueOf(strType.toUpperCase()); | return Node.Type.valueOf(strType.toUpperCase()); | ||||
} | } | ||||
/** | /** | ||||
* Parses SWH node type possible values from formatted string (TODO: link API doc). | * Parses SWH node type possible values from formatted string (see the <a | ||||
* href="https://docs.softwareheritage.org/devel/swh-graph/api.html#terminology">API | |||||
* syntax</a>). | |||||
* | * | ||||
* @param strFmtType node types represented as a formatted string (TODO: link API doc) | * @param strFmtType node types represented as a formatted string | ||||
* @return a list containing the {@link Node.Type} values | * @return a list containing the {@link Node.Type} values | ||||
* @see org.softwareheritage.graph.Node.Type | * @see org.softwareheritage.graph.Node.Type | ||||
*/ | */ | ||||
public static ArrayList<Node.Type> parse(String strFmtType) { | public static ArrayList<Node.Type> parse(String strFmtType) { | ||||
ArrayList<Node.Type> types = new ArrayList<>(); | ArrayList<Node.Type> types = new ArrayList<>(); | ||||
if (strFmtType.equals("*")) { | if (strFmtType.equals("*")) { | ||||
List<Node.Type> nodeTypes = Arrays.asList(Node.Type.values()); | List<Node.Type> nodeTypes = Arrays.asList(Node.Type.values()); | ||||
Show All 9 Lines |