/** * Creates a new {@code ParseObject} based upon a subclass type. Note that the object will be * created based upon the {@link ParseClassName} of the given subclass type. For example, calling * create(ParseUser.class) may create an instance of a custom subclass of {@code ParseUser}. * * @param subclass The class of object to create. * @return A new {@code ParseObject} based upon the class name of the given subclass type. */ @SuppressWarnings("unchecked") public static <T extends ParseObject> T create(Class<T> subclass) { return (T) create(getSubclassingController().getClassName(subclass)); }
/* package for tests */ ParseUser lazyLogIn(String authType, Map<String, String> authData) { // Note: if authType != ParseAnonymousUtils.AUTH_TYPE the user is not "lazy". ParseUser user = ParseObject.create(ParseUser.class); synchronized (user.mutex) { user.setIsCurrentUser(true); user.putAuthData(authType, authData); } synchronized (mutex) { currentUserMatchesDisk = false; currentUser = user; } return user; } }
@Override public ParsePin then(Task<List<ParsePin>> task) { ParsePin pin = null; if (task.getResult() != null && task.getResult().size() > 0) { pin = task.getResult().get(0); } //TODO (grantland): What do we do if there are more than 1 result? if (pin == null) { pin = ParseObject.create(ParsePin.class); pin.setName(name); } return pin; } });
object = create(className); if (object.hasChanges()) { throw new IllegalStateException(
private static List<ParseObject> generateParseObjects( String key, Object[] values) { List<ParseObject> objects = new ArrayList<>(); int i = 0; for (Object value : values) { ParseObject object = ParseObject.create("TestObject"); object.put("id", i); if (value != null) { object.put(key, value); } objects.add(object); i++; } return objects; }
@Test public void testRegisteringSubclassesUsesMostDescendantSubclass() { try { // When we register a ParseUser subclass, we have to clear the cached currentParseUser, so // we need to register a mock ParseUserController here, otherwise Parse.getCacheDir() will // throw an exception in unit test environment. ParseCurrentUserController controller = mock(ParseCurrentUserController.class); ParseCorePlugins.getInstance().registerCurrentUserController(controller); assertEquals(ParseUser.class, ParseObject.create("_User").getClass()); ParseObject.registerSubclass(MyUser.class); assertEquals(MyUser.class, ParseObject.create("_User").getClass()); ParseObject.registerSubclass(ParseUser.class); assertEquals(MyUser.class, ParseObject.create("_User").getClass()); // This is expected to fail as MyUser2 and MyUser are not directly related. try { ParseObject.registerSubclass(MyUser2.class); fail(); } catch (IllegalArgumentException ex) { /* expected */ } assertEquals(MyUser.class, ParseObject.create("_User").getClass()); } finally { ParseObject.unregisterSubclass(ParseUser.class); ParseCorePlugins.getInstance().reset(); } }
showToast(R.string.com_parse_ui_no_name_toast); } else { ParseUser user = ParseObject.create(ParseUser.class);