/** * Get the QueryType enum from it's search type. * * @param type The type of query. * * @return the enum QueryType if found otherwise empty. */ public static Optional<QueryType> fromType(String type) { for (QueryType queryType : values()) { if (queryType.type.equals(type)) { return Optional.of(queryType); } } return Optional.empty(); } }
SearchFilter.QueryType optionalQuery = SearchFilter.QueryType.fromType(searchType) .orElseThrow(() -> new IllegalArgumentException("Couldn't convert " + searchType + " to a QueryType."));