All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.stormpath.sdk.phone.Phones Maven / Gradle / Ivy

Go to download

The Stormpath Java SDK API .jar provides a Java API that your code can use to make calls to the Stormpath API. This .jar is the only compile-time dependency within the Stormpath SDK project that your code should depend on. Implementations of this API (implementation .jars) should be runtime dependencies only.

The newest version!
/*
 * Copyright 2016 Stormpath, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.stormpath.sdk.phone;

import com.stormpath.sdk.lang.Classes;
import com.stormpath.sdk.query.Criterion;
import com.stormpath.sdk.query.DateExpressionFactory;
import com.stormpath.sdk.query.EqualsExpressionFactory;
import com.stormpath.sdk.query.StringExpressionFactory;

import java.lang.reflect.Constructor;

/**
 * Static utility/helper methods for working with {@link Phone} resources.  Most methods are
 * factory methods used for forming
 * Phone-specific fluent DSL queries. For example:
 * 
 * Phones.where(Phones.name().containsIgnoreCase("Foo"))
 *     .and(Phones.status().eq(PhoneStatus.ENABLED))
 *     .orderByName().descending()
 *     .withAccount()
 *     .offsetBy(50)
 *     .limitTo(25));
 * 
* or, if using static imports: *
 * import static com.stormpath.sdk.phone.Phones.*;
 *
 * ...
 *
 * where(name().containsIgnoreCase("Foo"))
 *     .and(status().eq(PhoneStatus.ENABLED))
 *     .orderByName().descending()
 *     .withAccount()
 *     .offsetBy(50)
 *     .limitTo(25));
 * 
* * @since 1.1.0 */ public final class Phones { private static final Class BUILDER_CLASS = Classes.forName("com.stormpath.sdk.impl.phone.DefaultCreatePhoneRequestBuilder"); //prevent instantiation private Phones() { } /** * Returns a new {@link PhoneOptions} instance, used to customize how one or more {@link Phone}s are retrieved. * * @return a new {@link PhoneOptions} instance, used to customize how one or more {@link Phone}s are retrieved. */ public static PhoneOptions options() { return (PhoneOptions) Classes.newInstance("com.stormpath.sdk.impl.phone.DefaultPhoneOptions"); } /** * Returns a new {@link PhoneCriteria} instance to use to formulate a Phone query. *

* Note that it is usually more common to use the {@link #where(com.stormpath.sdk.query.Criterion) where} method * instead of this one as the {@code where} method usually lends to better readability. For example: *

     * Phones.criteria().add(Phones.name().eqIgnoreCase("Foo"))...
     * 
* versus: *
     * Phones.where(Phones.name().eqIgnoreCase("Foo"))...
     * 
* or when using static imports: *
     * where(name().eqIgnoreCase("Foo"))...
     * 
* While all three statements are equivalent, the second and third examples are shorter and probably more readable. * * @return a new {@link PhoneCriteria} instance to use to formulate a Phone query. */ public static PhoneCriteria criteria() { return (PhoneCriteria) Classes.newInstance("com.stormpath.sdk.impl.phone.DefaultPhoneCriteria"); } /** * Creates a new {@link PhoneCriteria} instance using the specified {@code criterion} as the first query condition. * * @return a new {@link PhoneCriteria} instance using the specified {@code criterion} as the first query condition. */ public static PhoneCriteria where(Criterion criterion) { return criteria().add(criterion); } /** * Creates a new {@link StringExpressionFactory} instance reflecting the Phone {@link Phone#getName() name} * property, to be used to construct a name Criterion when building an {@link PhoneCriteria} query. For example: *
     * Phones.where(Phones.name().startsWithIgnoreCase("foo");
     * 
* The above example invokes the returned factory's startsWithIgnoreCase("foo") method. This * produces a name-specific {@link Criterion} which is added to the criteria query (via the * {@link #where(com.stormpath.sdk.query.Criterion) where} method). For example, the following code is equivalent: *
     * PhoneCriteria criteria = Phones.criteria();
     * StringExpressionFactory nameExpressionFactory = Phones.name();
     * Criterion nameStartsWithFoo = nameExpressionFactory.startsWithIgnoreCase("foo");
     * criteria.add(nameStartsWithFoo);
     * 
* The first code example is clearly more succinct and readable. * * @return a new {@link Phone#getName() name}-specific {@link StringExpressionFactory} instance, to be * used to construct a criterion when building an {@link PhoneCriteria} query. */ public static StringExpressionFactory name() { return newStringExpressionFactory("name"); } /** * Creates a new {@link StringExpressionFactory} instance reflecting the Phone {@link Phone#getNumber() number} * property, to be used to construct a number Criterion when building an {@link PhoneCriteria} query. For example: *
     * Phones.where(Phones.number().startsWithIgnoreCase("201");
     * 
* The above example invokes the returned factory's startsWithIgnoreCase("foo") method. This * produces a number-specific {@link Criterion} which is added to the criteria query (via the * {@link #where(com.stormpath.sdk.query.Criterion) where} method). For example, the following code is equivalent: *
     * PhoneCriteria criteria = Phones.criteria();
     * StringExpressionFactory numberExpressionFactory = Phones.number();
     * Criterion numberStartsWithFoo = numberExpressionFactory.startsWithIgnoreCase("foo");
     * criteria.add(nameStartsWithFoo);
     * 
* The first code example is clearly more succinct and readable. * * @return a new {@link Phone#getNumber() number}-specific {@link StringExpressionFactory} instance, to be * used to construct a criterion when building an {@link PhoneCriteria} query. */ public static StringExpressionFactory number() { return newStringExpressionFactory("number"); } /** * Creates a new {@link StringExpressionFactory} instance reflecting the Phone {@link Phone#getDescription() description} * property, to be used to construct a description Criterion when building an {@link PhoneCriteria} query. For example: *
     * Phones.where(Phones.description().startsWithIgnoreCase("This is a description");
     * 
* The above example invokes the returned factory's startsWithIgnoreCase("foo") method. This * produces a description-specific {@link Criterion} which is added to the criteria query (via the * {@link #where(com.stormpath.sdk.query.Criterion) where} method). For example, the following code is equivalent: *
     * PhoneCriteria criteria = Phones.criteria();
     * StringExpressionFactory descriptionExpressionFactory = Phones.description();
     * Criterion descriptionStartsWithFoo = descriptionExpressionFactory.startsWithIgnoreCase("foo");
     * criteria.add(descriptionStartsWithFoo);
     * 
* The first code example is clearly more succinct and readable. * * @return a new {@link Phone#getNumber() number}-specific {@link StringExpressionFactory} instance, to be * used to construct a criterion when building an {@link PhoneCriteria} query. */ public static StringExpressionFactory description() { return newStringExpressionFactory("description"); } /** * Creates a new {@link EqualsExpressionFactory} instance reflecting the Phone {@link Phone#getStatus() status} * property, to be used to construct a status Criterion when building an {@link PhoneCriteria} query. For example: *
     * Phones.where(Phones.status().eq(PhoneStatus.ENABLED);
     * 
* The above example invokes the returned factory's eq() method. This * produces a status-specific {@link Criterion} which is added to the criteria query (via the * {@link #where(com.stormpath.sdk.query.Criterion) where} method). For example, the following code is equivalent: *
     * PhoneCriteria criteria = Phones.criteria();
     * StringExpressionFactory statusExpressionFactory = Phones.status();
     * Criterion statusEqualsEnabled = statusExpressionFactory.eq(PhoneStatus.ENABLED);
     * criteria.add(statusEqualsEnabled);
     * 
* The first code example is clearly more succinct and readable. * * @return a new {@link Phone#getStatus() status}-specific {@link StringExpressionFactory} instance, to be * used to construct a criterion when building an {@link PhoneCriteria} query. */ public static EqualsExpressionFactory status() { return newEqualsExpressionFactory("status"); } /** * Creates a new {@link EqualsExpressionFactory} instance reflecting the Phone {@link Phone#getVerificationStatus() verificationStatus} * property, to be used to construct a status Criterion when building an {@link PhoneCriteria} query. For example: *
     * Phones.where(Phones.verificationStatus().eq(PhoneVerificationStatus.VERIFIED);
     * 
* The above example invokes the returned factory's eq() method. This * produces a verificationStatus-specific {@link Criterion} which is added to the criteria query (via the * {@link #where(com.stormpath.sdk.query.Criterion) where} method). For example, the following code is equivalent: *
     * PhoneCriteria criteria = Phones.criteria();
     * StringExpressionFactory statusExpressionFactory = Phones.verificationStatus();
     * Criterion verificationStatusEqualsEnabled = verificationStatusExpressionFactory.eq(PhoneVerificationStatus.VERIFIED);
     * criteria.add(verificationStatusEqualsEnabled);
     * 
* The first code example is clearly more succinct and readable. * * @return a new {@link Phone#getVerificationStatus() verificationStatus}-specific {@link StringExpressionFactory} instance, to be * used to construct a criterion when building an {@link PhoneCriteria} query. */ public static EqualsExpressionFactory verificationStatus() { return newEqualsExpressionFactory("verificationStatus"); } /** * Creates a new {@link DateExpressionFactory} instance reflecting the Phone {@link Phone#getCreatedAt() createdAt} * property, to be used to construct a createdAt Criterion when building an {@link PhoneCriteria} query. For example: *
     * Phones.where(Phones.createdAt().matches("[,2014-04-05T12:00:00]");
     * 
* The above example invokes the returned factory's matches("[,2014-04-05T12:00:00]")) method. This * produces a createdAt-specific {@link Criterion} which is added to the criteria query (via the * {@link #where(Criterion) where} method). *
     * For example, the following code is equivalent:
     * 
     * PhoneCriteria criteria = Phones.criteria();
     * DateExpressionFactory createdAt = Phones.createdAt();
     * Criterion createdAtMatches = createdAt.matches("[,2014-04-05T12:00:00]");
     * criteria.add(createdAtMatches);
     * 
* * @return a new {@link Phone#getCreatedAt() createdAt}-specific {@link DateExpressionFactory} instance, to be * used to construct a criterion when building an {@link PhoneCriteria} query. */ public static DateExpressionFactory createdAt(){ return newDateExpressionFactory("createdAt"); } /** * Creates a new {@link DateExpressionFactory} instance reflecting the Phone {@link Phone#getModifiedAt() modifiedAt} * property, to be used to construct a modifiedAt Criterion when building an {@link PhoneCriteria} query. For example: *
     * Phones.where(Phones.modifiedAt().matches("[,2014-04-05T12:00:00]");
     * 
* The above example invokes the returned factory's matches("[,2014-04-05T12:00:00]")) method. This * produces a modifiedAt-specific {@link Criterion} which is added to the criteria query (via the * {@link #where(Criterion) where} method). *
     * For example, the following code is equivalent:
     * 
     * PhoneCriteria criteria = Phones.criteria();
     * DateExpressionFactory createdAt = Phones.modifiedAt();
     * Criterion modifiedAtMatches = modifiedAt.matches("[,2014-04-05T12:00:00]");
     * criteria.add(modifiedAtMatches);
     * 
* * @return a new {@link Phone#getModifiedAt() modifiedAt}-specific {@link DateExpressionFactory} instance, to be * used to construct a criterion when building an {@link PhoneCriteria} query. * @since 1.0.RC4.6 */ public static DateExpressionFactory modifiedAt(){ return newDateExpressionFactory("modifiedAt"); } private static DateExpressionFactory newDateExpressionFactory(String propName) { final String FQCN = "com.stormpath.sdk.impl.query.DefaultDateExpressionFactory"; return (DateExpressionFactory) Classes.newInstance(FQCN, propName); } /** * Creates a new {@link com.stormpath.sdk.phone.CreatePhoneRequestBuilder createPhoneRequestBuilder} * instance reflecting the specified {@link com.stormpath.sdk.phone.Phone} instance. The builder can be used to customize any * creation request options as necessary. * * @param phone the phone to create a new record for within Stormpath * @return a new {@link com.stormpath.sdk.phone.CreatePhoneRequestBuilder createPhoneRequestBuilder} * instance reflecting the specified {@link com.stormpath.sdk.phone.Phone} instance. ** @see com.stormpath.sdk.account.Account#createPhone(CreatePhoneRequest) * * @since 1.1.0 */ public static CreatePhoneRequestBuilder newCreateRequestFor(Phone phone) { Constructor ctor = Classes.getConstructor(BUILDER_CLASS, Phone.class); return (CreatePhoneRequestBuilder) Classes.instantiate(ctor, phone); } private static StringExpressionFactory newStringExpressionFactory(String propName) { final String FQCN = "com.stormpath.sdk.impl.query.DefaultStringExpressionFactory"; return (StringExpressionFactory) Classes.newInstance(FQCN, propName); } private static EqualsExpressionFactory newEqualsExpressionFactory(String propName) { final String FQCN = "com.stormpath.sdk.impl.query.DefaultEqualsExpressionFactory"; return (EqualsExpressionFactory) Classes.newInstance(FQCN, propName); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy