Skip to content

Instantly share code, notes, and snippets.

View naturalwarren's full-sized avatar
🎯
Focusing

Warren Smith naturalwarren

🎯
Focusing
View GitHub Profile
@naturalwarren
naturalwarren / UsingRave.java
Last active April 2, 2017 21:54
Demonstrates how to use RAVE
View UsingRave.java
public class UsingRave {
public static void main(String[] args) {
MyModel myModel = new MyModel(“Validate me please!”);
try {
Rave.getInstance().validate(myModel);
} catch (RaveException e) {
// This response didn't pass RAVE validation, throw an exception.
throw new RuntimeException(e);
}
}
@naturalwarren
naturalwarren / ExampleModel.java
Created May 26, 2017 17:02
An example model with RAVE validation.
View ExampleModel.java
@Validated(factory = RaveValidatorFactory.class)
public class MyModel {
@NonNull private String someString;
public MyModel(@NonNull String someString) {
this.someString = someString;
}
@NonNull
@naturalwarren
naturalwarren / UsingRave.java
Created May 26, 2017 17:03
Example usage of RAVE.
View UsingRave.java
public class UsingRave {
public static void main(String[] args) {
MyModel myModel = new MyModel(“Validate me please!”);
Rave.validate(myModel);
}
}
@naturalwarren
naturalwarren / RaveValidatorFactory.java
Created May 26, 2017 17:03
Example usage of RAVE.
View RaveValidatorFactory.java
/**
* A factory class capable of creating a validator whose implementation generated at annotation processing time.
*/
public final class RaveValidatorFactory implements ValidatorFactory {
@NonNull
@Override
public BaseValidator generateValidator() {
return new RaveValidatorFactory_Generated_Validator();
}
View RaveValidatorFactory_Generated_Validator.java
public final class RaveValidatorFactory_Generated_Validator extends BaseValidator {
RaveValidatorFactory_Generated_Validator() {
addSupportedClass(MyModel.class);
registerSelf();
}
@Override
protected void validateAs(@NonNull Object object, @NonNull Class<?> clazz, @NonNull ExclusionStrategy exclusionStrategy) throws InvalidModelException {
if (!clazz.isInstance(object)) {
throw new IllegalArgumentException(object.getClass().getCanonicalName() + "is not of type" + clazz.getCanonicalName());
@naturalwarren
naturalwarren / Rider.java
Last active May 26, 2017 20:42
Rider Model with Nullness Annotations
View Rider.java
public class Rider {
@NonNull private String firstName;
@NonNull private String lastName;
public Rider(@NonNull String firstname, @NonNull String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
View build.gradle
apply plugin: ‘com.android.application’
dependencies {
implementation deps.support.appcompat
implementation deps.retrofit.core
implementation deps.retrofit.adapter.rxjava2
implementation deps.retrofit.converter.moshi
}
View dependencies.gradle
def versions = [ retrofit: ‘2.4.0', support: '27.1.1']
def retrofit = [
adapter: [ rxjava2: "com.squareup.retrofit2:adapter-rxjava2:${versions.retrofit}" ],
converter: [ moshi: "com.squareup.retrofit2:converter-moshi:${versions.retrofit}" ],
core: "com.squareup.retrofit2:retrofit:${versions.retrofit}"
]
def support = [
appcompat: "com.android.support:appcompat-v7:${versions.support}",
View securities.json
{
"securities":{
"security":[
{
"symbol":"PHYS",
"exchange":"Q",
"type":"stock",
"description":"Sprott Physical Gold Trust ETV"
}
]
View Enveloped.kt
/**
* Indicates an endpoint wraps a response in a JSON Object.
* When deserializing the response we should only return
* what's inside the outer most object.
*/
@Retention(RUNTIME)
@JsonQualifier
@Target(FUNCTION, CLASS)
internal annotation class Enveloped