/** * Access a {@link ParseFile} value. This function will not perform a network request. Unless the * {@link ParseFile} has been downloaded (e.g. by calling {@link ParseFile#getData()}), * {@link ParseFile#isDataAvailable()} will return {@code false}. * * @param key The key to access the value for. * @return {@code null} if there is no such key or if it is not a {@link ParseFile}. */ @Nullable public ParseFile getParseFile(@NonNull String key) { Object value = get(key); if (!(value instanceof ParseFile)) { return null; } return (ParseFile) value; }
return object.getUpdatedAt(); default: return object.get(key);
assertEquals(dateLong, object.getState().updatedAt()); assertEquals(objectJSON.getString("objectId"), object.getObjectId()); assertEquals(objectJSON.getString("sessionToken"), object.get("sessionToken")); assertEquals(objectJSON.getString("key"), object.getString("key")); assertEquals(dateLong, objectAgain.getState().updatedAt()); assertEquals(objectAgainJSON.getString("objectId"), objectAgain.getObjectId()); assertEquals(objectAgainJSON.getString("sessionToken"), objectAgain.get("sessionToken")); assertEquals(objectAgainJSON.getString("keyAgain"), objectAgain.getString("keyAgain"));
assertEquals(newObject.getString("string"), object.getString("string")); assertEquals(newObject.getDate("date"), object.getDate("date")); assertEquals(newObject.get("null"), object.get("null")); assertEquals(newObject.getList("collection"), object.getList("collection")); assertEquals(newObject.getParseObject("pointer").getClassName(), other.getClassName());
@Override public void done(List<ParseObject> objects, ParseException e) { if ( e == null){ if(objects.size() > 0){ listViewContent.clear(); usernames.clear(); latitudes.clear(); longitudes.clear(); for (ParseObject object : objects){ Double distanceInMiles = userLocation.distanceInMilesTo((ParseGeoPoint) object.get("requesterLocation")); Double distaneOneDP = (double) Math.round(distanceInMiles *10) / 10; listViewContent.add(String.valueOf(distaneOneDP)+ " miles"); usernames.add(object.getString("requesterUsername")); latitudes.add(object.getParseGeoPoint("requesterLocation").getLatitude()); longitudes.add(object.getParseGeoPoint("requesterLocation").getLongitude()); } arrayAdapter.notifyDataSetChanged(); } } } });
/** * Access a {@code ParseObject} value. This function will not perform a network request. Unless the * {@code ParseObject} has been downloaded (e.g. by a {@link ParseQuery#include(String)} or by calling * {@link #fetchIfNeeded()} or {@link #fetch()}), {@link #isDataAvailable()} will return * {@code false}. * * @param key The key to access the value for. * @return {@code null} if there is no such key or if it is not a {@code ParseObject}. */ @Nullable public ParseObject getParseObject(@NonNull String key) { Object value = get(key); if (!(value instanceof ParseObject)) { return null; } return (ParseObject) value; }
/** * Access a {@link ParseUser} value. This function will not perform a network request. Unless the * {@code ParseObject} has been downloaded (e.g. by a {@link ParseQuery#include(String)} or by calling * {@link #fetchIfNeeded()} or {@link #fetch()}), {@link #isDataAvailable()} will return * {@code false}. * * @param key The key to access the value for. * @return {@code null} if there is no such key or if the value is not a {@link ParseUser}. */ @Nullable public ParseUser getParseUser(@NonNull String key) { Object value = get(key); if (!(value instanceof ParseUser)) { return null; } return (ParseUser) value; }
void performRemove(String key) { synchronized (mutex) { Object object = get(key); if (object != null) { performOperation(key, ParseDeleteOperation.getInstance()); } } }
@Test public void testGetAvailableIfKeyAvailable() { ParseObject.State state = mock(ParseObject.State.class); when(state.className()).thenReturn("TestObject"); when(state.isComplete()).thenReturn(false); when(state.availableKeys()).thenReturn(new HashSet<>(Collections.singletonList("foo"))); ParseObject object = ParseObject.from(state); object.get("foo"); }
@Test(expected = IllegalStateException.class) public void testGetUnavailable() { ParseObject.State state = mock(ParseObject.State.class); when(state.className()).thenReturn("TestObject"); when(state.isComplete()).thenReturn(false); ParseObject object = ParseObject.from(state); object.get("foo"); }
ParseObject object = (ParseObject) root; for (String key : object.keySet()) { traverseInternal(object.get(key), true, seen);
@Test public void testFetchIncludesCollection() throws ParseException { OfflineStore store = mock(OfflineStore.class); when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class))) .thenReturn(Task.<ParseObject>forResult(null)); ParseSQLiteDatabase db = mock(ParseSQLiteDatabase.class); ParseQuery.State<ParseObject> query = new ParseQuery.State.Builder<>("TestObject") .include("foo") .build(); ParseObject object = mock(ParseObject.class); ParseObject unfetchedObject = mock(ParseObject.class); Collection<ParseObject> objects = new ArrayList<>(); objects.add(unfetchedObject); when(object.get("foo")).thenReturn(objects); ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, db)); verify(store).fetchLocallyAsync(object, db); verify(store).fetchLocallyAsync(unfetchedObject, db); verifyNoMoreInteractions(store); }
@Test public void testFetchIncludesMap() throws ParseException { OfflineStore store = mock(OfflineStore.class); when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class))) .thenReturn(Task.<ParseObject>forResult(null)); ParseSQLiteDatabase db = mock(ParseSQLiteDatabase.class); ParseQuery.State<ParseObject> query = new ParseQuery.State.Builder<>("TestObject") .include("foo.bar") .build(); ParseObject object = mock(ParseObject.class); ParseObject unfetchedObject = mock(ParseObject.class); Map<String, ParseObject> objects = new HashMap<>(); objects.put("bar", unfetchedObject); when(object.get("foo")).thenReturn(objects); ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, db)); verify(store).fetchLocallyAsync(object, db); verify(store).fetchLocallyAsync(unfetchedObject, db); verifyNoMoreInteractions(store); }
@Test public void testFetchIncludesJSONArray() throws ParseException { OfflineStore store = mock(OfflineStore.class); when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class))) .thenReturn(Task.<ParseObject>forResult(null)); ParseSQLiteDatabase db = mock(ParseSQLiteDatabase.class); ParseQuery.State<ParseObject> query = new ParseQuery.State.Builder<>("TestObject") .include("foo") .build(); ParseObject object = mock(ParseObject.class); ParseObject unfetchedObject = mock(ParseObject.class); JSONArray objects = new JSONArray(); objects.put(unfetchedObject); when(object.get("foo")).thenReturn(objects); ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, db)); verify(store).fetchLocallyAsync(object, db); verify(store).fetchLocallyAsync(unfetchedObject, db); verifyNoMoreInteractions(store); }
@Test public void testFetchIncludesJSONObject() throws Exception { OfflineStore store = mock(OfflineStore.class); when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class))) .thenReturn(Task.<ParseObject>forResult(null)); ParseSQLiteDatabase db = mock(ParseSQLiteDatabase.class); ParseQuery.State<ParseObject> query = new ParseQuery.State.Builder<>("TestObject") .include("foo.bar") .build(); ParseObject object = mock(ParseObject.class); ParseObject unfetchedObject = mock(ParseObject.class); JSONObject objects = new JSONObject(); objects.put("bar", unfetchedObject); when(object.get("foo")).thenReturn(objects); ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, db)); verify(store).fetchLocallyAsync(object, db); verify(store).fetchLocallyAsync(unfetchedObject, db); verifyNoMoreInteractions(store); }
object.put("name", "grantland"); object.revert("foo"); assertNull(object.get("foo")); assertEquals("grantland", object.get("name")); object.revert("foo"); assertFalse(object.isDirty()); assertEquals("bar", object.get("foo")); object.put("name", "grantland"); object.revert("foo"); assertEquals("bar", object.get("foo")); assertEquals("grantland", object.get("name")); tasks.add(object.saveInBackground()); object.revert("foo"); assertEquals("baz", object.get("foo")); assertEquals("nlutsenko", object.get("name")); object.put("name", "grantland"); object.revert("foo"); assertEquals("baz", object.get("foo")); assertEquals("grantland", object.get("name"));
object.put("name", "grantland"); object.revert(); assertNull(object.get("foo")); assertNull(object.get("name")); object.revert(); assertFalse(object.isDirty()); assertEquals("bar", object.get("foo")); object.revert(); assertFalse(object.isDirty()); assertEquals("bar", object.get("foo")); assertFalse(object.isDataAvailable("name")); object.revert(); assertFalse(object.isDirty()); assertEquals("baz", object.get("foo")); assertEquals("nlutsenko", object.get("name")); object.revert(); assertFalse(object.isDirty()); assertEquals("baz", object.get("foo")); assertEquals("nlutsenko", object.get("name"));