/** * Constructs a query using the given separator character and path. * * <p>As an example, {@code new DataQuery('/', "a/b/c")} and * {@code new DataQuery('.', "a.b.c")} represent the same path but are * constructed using different separators.</p> * * @param separator The separator * @param path The path * @return The newly constructed {@link DataQuery} */ public static DataQuery of(char separator, String path) { return new DataQuery(separator, path); }
/** * Constructs a query using the given parts. * * @param parts The parts * @return The newly constructed {@link DataQuery} */ public static DataQuery of(String... parts) { if (parts.length == 0) { return DataQuery.EMPTY; } return new DataQuery(parts); }
/** * Constructs a query using the given parts. * * @param parts The parts * @return The newly constructed {@link DataQuery} */ public static DataQuery of(List<String> parts) { if (parts.isEmpty()) { return DataQuery.EMPTY; } return new DataQuery(parts); }
/** * Gets the last entry of this {@link DataQuery}. If this query is * a single entry query or an empty query, it returns itself. * * @return The last entry as a data query, if not already last */ public DataQuery last() { if (this.parts.size() <= 1) { return this; } return new DataQuery(this.parts.get(this.parts.size() - 1)); }
/** * Returns a new query that is made up of this query's parts followed by the * given query. * * @param that The given query to follow this one * @return The constructed query */ public DataQuery then(String that) { ImmutableList.Builder<String> builder = new ImmutableList.Builder<>(); builder.addAll(this.parts); builder.add(that); return new DataQuery(builder.build()); }
/** * Returns a new query that is made up of this query's parts followed by the * given query's parts. * * @param that The given query to follow this one * @return The constructed query */ public DataQuery then(DataQuery that) { ImmutableList.Builder<String> builder = new ImmutableList.Builder<>(); builder.addAll(this.parts); builder.addAll(that.parts); return new DataQuery(builder.build()); }
/** * Returns a {@link DataQuery} where the last node is "popped" off. If this * query is already the top level query, then the {@link DataQuery#of()} is * returned. * * @return The next level query */ public DataQuery pop() { if (this.parts.size() <= 1) { return of(); } ImmutableList.Builder<String> builder = ImmutableList.builder(); for (int i = 0; i < this.parts.size() - 1; i++) { builder.add(this.parts.get(i)); } return new DataQuery(builder.build()); }
/** * Returns the parts of this query as individual queries. The returned list * is immutable. * * @return The constructed queries */ public List<DataQuery> getQueryParts() { if (this.queryParts == null) { ImmutableList.Builder<DataQuery> builder = ImmutableList.builder(); for (String part : getParts()) { builder.add(new DataQuery(part)); } this.queryParts = builder.build(); } return this.queryParts; }
/** * Returns a {@link DataQuery} where the first node is "popped" off. If this * query is already the top level query, then the {@link DataQuery#of()} is * returned. * * @return The next level query */ public DataQuery popFirst() { if (this.parts.size() <= 1) { return of(); } ImmutableList.Builder<String> builder = ImmutableList.builder(); for (int i = 1; i < this.parts.size(); i++) { builder.add(this.parts.get(i)); } return new DataQuery(builder.build()); }
/** * Constructs a query using the given parts. * * @param parts The parts * @return The newly constructed {@link DataQuery} */ public static DataQuery of(String... parts) { if (parts.length == 0) { return DataQuery.EMPTY; } return new DataQuery(parts); }
/** * Constructs a query using the given separator character and path. * * <p>As an example, {@code new DataQuery('/', "a/b/c")} and * {@code new DataQuery('.', "a.b.c")} represent the same path but are * constructed using different separators.</p> * * @param separator The separator * @param path The path * @return The newly constructed {@link DataQuery} */ public static DataQuery of(char separator, String path) { return new DataQuery(separator, path); }
/** * Constructs a query using the given parts. * * @param parts The parts * @return The newly constructed {@link DataQuery} */ public static DataQuery of(List<String> parts) { if (parts.isEmpty()) { return DataQuery.EMPTY; } return new DataQuery(parts); }
/** * Gets the last entry of this {@link DataQuery}. If this query is * a single entry query or an empty query, it returns itself. * * @return The last entry as a data query, if not already last */ public DataQuery last() { if (this.parts.size() <= 1) { return this; } return new DataQuery(this.parts.get(this.parts.size() - 1)); }
/** * Returns a new query that is made up of this query's parts followed by the * given query's parts. * * @param that The given query to follow this one * @return The constructed query */ public DataQuery then(DataQuery that) { ImmutableList.Builder<String> builder = new ImmutableList.Builder<>(); builder.addAll(this.parts); builder.addAll(that.parts); return new DataQuery(builder.build()); }
/** * Returns a new query that is made up of this query's parts followed by the * given query. * * @param that The given query to follow this one * @return The constructed query */ public DataQuery then(String that) { ImmutableList.Builder<String> builder = new ImmutableList.Builder<>(); builder.addAll(this.parts); builder.add(that); return new DataQuery(builder.build()); }
/** * Returns the parts of this query as individual queries. The returned list * is immutable. * * @return The constructed queries */ public List<DataQuery> getQueryParts() { if (this.queryParts == null) { ImmutableList.Builder<DataQuery> builder = ImmutableList.builder(); for (String part : getParts()) { builder.add(new DataQuery(part)); } this.queryParts = builder.build(); } return this.queryParts; }
/** * Returns a {@link DataQuery} where the first node is "popped" off. If this * query is already the top level query, then the {@link DataQuery#of()} is * returned. * * @return The next level query */ public DataQuery popFirst() { if (this.parts.size() <= 1) { return of(); } ImmutableList.Builder<String> builder = ImmutableList.builder(); for (int i = 1; i < this.parts.size(); i++) { builder.add(this.parts.get(i)); } return new DataQuery(builder.build()); }
/** * Returns a {@link DataQuery} where the last node is "popped" off. If this * query is already the top level query, then the {@link DataQuery#of()} is * returned. * * @return The next level query */ public DataQuery pop() { if (this.parts.size() <= 1) { return of(); } ImmutableList.Builder<String> builder = ImmutableList.builder(); for (int i = 0; i < this.parts.size() - 1; i++) { builder.add(this.parts.get(i)); } return new DataQuery(builder.build()); }