thiagolocatelli / parse4j

Java Library to deal with Parse (parse.com) REST API
http://thiagolocatelli.github.io/parse4j
143 stars 117 forks source link

Multiple Combined "OR" Queries - Not Available #84

Open SeloSlav opened 7 years ago

SeloSlav commented 7 years ago

I'm trying to build a combined ParseQuery like the one shown here: http://stackoverflow.com/questions/28892973/multiple-combined-or-queries-using-android-parse

Unfortunately, it doesn't seem the .or() method is provided in Parse4J.

I tried building my own class to include it:

import org.parse4j.ParseObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

public class ParseQuery<T extends ParseObject> {

    private static Logger LOGGER = LoggerFactory.getLogger(ParseQuery.class);

    /**
     * Constructs a query that is the {@code or} of the given queries.
     *
     * @param queries
     *          The list of {@code ParseQuery}s to 'or' together
     * @return A {@code ParseQuery} that is the 'or' of the passed in queries
     */
    public static <T extends ParseObject> ParseQuery<T> or(List<ParseQuery<T>> queries) {
        if (queries.isEmpty()) {
            throw new IllegalArgumentException("Can't take an or of an empty list of queries");
        }

        List<State.Builder<T>> builders = new ArrayList<>();
        for (ParseQuery<T> query : queries) {
            builders.add(query.getBuilder());
        }
        return new ParseQuery<>(State.Builder.or(builders));
    }

}

Does anybody know which class "State" happens to be? I found this code in the ParsePlatform Android SDK: https://github.com/thiagolocatelli/parse4j/blob/master/src/main/java/org/parse4j/ParseQuery.java

Any ideas?