ParseRESTQueryCommand extends ParseRESTCommand { static <T extends ParseObject> Map<String, String> encode( ParseQuery.State<T> state, boolean count) { ParseEncoder encoder = PointerEncoder.get(); HashMap<String, String> parameters = new HashMap<>(); List<String> order = state.order(); if (!order.isEmpty()) { parameters.put(KEY_ORDER, ParseTextUtils.join(",", order)); } ParseQuery.QueryConstraints conditions = state.constraints(); if (!conditions.isEmpty()) { JSONObject encodedConditions = (JSONObject) encoder.encode(conditions); parameters.put(KEY_WHERE, encodedConditions.toString()); } Set<String> selectedKeys = state.selectedKeys(); if (selectedKeys != null) { parameters.put(KEY_KEYS, ParseTextUtils.join(",", selectedKeys)); } Set<String> includeds = state.includes(); if (!includeds.isEmpty()) { parameters.put(KEY_INCLUDE, ParseTextUtils.join(",", includeds)); } int limit = state.limit(); if (limit >= 0) { parameters.put(KEY_LIMIT, Integer.toString(limit)); } if (count) { parameters.put(KEY_COUNT, Integer.toString(1)); } else { int skip = state.skip(); if (skip > 0) { parameters.put(KEY_SKIP, Integer.toString(skip)); } } Map<String, Object> extraOptions = state.extraOptions(); for (Map.Entry<String, Object> entry : extraOptions.entrySet()) { Object encodedExtraOptions = encoder.encode(entry.getValue()); parameters.put(entry.getKey(), encodedExtraOptions.toString()); } if (state.isTracingEnabled()) { parameters.put(KEY_TRACE, Integer.toString(1)); } return parameters; } private  ParseRESTQueryCommand(
            String httpPath,
            ParseHttpRequest.Method httpMethod,
            Map<String, ?> parameters,
            String sessionToken); static ParseRESTQueryCommand findCommand(
            ParseQuery.State<T> state, String sessionToken); static ParseRESTQueryCommand countCommand(
            ParseQuery.State<T> state, String sessionToken);  }
@Test public void testEncodeWithNoCount() throws Exception { ParseQuery.State<ParseObject> state = new ParseQuery.State.Builder<>("TestObject") .orderByAscending("orderKey") .addCondition("inKey", "$in", Arrays.asList("inValue", "inValueAgain")) .selectKeys(Collections.singletonList("selectedKey, selectedKeyAgain")) .include("includeKey") .setLimit(5) .setSkip(6) .redirectClassNameForKey("extraKey") .setTracingEnabled(true) .build(); Map<String, String> encoded = ParseRESTQueryCommand.encode(state, false); assertEquals("orderKey", encoded.get(ParseRESTQueryCommand.KEY_ORDER)); JSONObject conditionJson = new JSONObject(encoded.get(ParseRESTQueryCommand.KEY_WHERE)); JSONArray conditionWhereJsonArray = new JSONArray() .put("inValue") .put("inValueAgain"); assertEquals( conditionWhereJsonArray, conditionJson.getJSONObject("inKey").getJSONArray("$in"), JSONCompareMode.NON_EXTENSIBLE); assertTrue(encoded.get(ParseRESTQueryCommand.KEY_KEYS).contains("selectedKey")); assertTrue(encoded.get(ParseRESTQueryCommand.KEY_KEYS).contains("selectedKeyAgain")); assertEquals("includeKey", encoded.get(ParseRESTQueryCommand.KEY_INCLUDE)); assertEquals("5", encoded.get(ParseRESTQueryCommand.KEY_LIMIT)); assertEquals("6", encoded.get(ParseRESTQueryCommand.KEY_SKIP)); assertEquals("extraKey", encoded.get("redirectClassNameForKey")); assertEquals("1", encoded.get(ParseRESTQueryCommand.KEY_TRACE)); }
@Test public void testEncodeWithCount() { ParseQuery.State<ParseObject> state = new ParseQuery.State.Builder<>("TestObject") .setSkip(6) .setLimit(3) .build(); Map<String, String> encoded = ParseRESTQueryCommand.encode(state, true); assertTrue(encoded.containsKey(ParseRESTQueryCommand.KEY_LIMIT)); assertFalse(encoded.containsKey(ParseRESTQueryCommand.KEY_SKIP)); assertEquals("1", encoded.get(ParseRESTQueryCommand.KEY_COUNT)); }