signature:
public class Doubles { /** * Verifies that the actual value is not less than the expected .
 * @ param description the description of the < em > actual < / em > value .
 * @ param actual the < em > actual < / em > value .
 * @ param expected the < em > expected < / em > value . */
public void assertNotLessThan ( Description description , Double actual , double expected ) { } }

implementation: assertNotNull ( description , actual ) ; if ( isLessThan ( actual , expected ) ) { throw failures . failure ( description , shouldNotBeLessThan ( actual , expected ) ) ; }


signature:
public class Failures { /** * Creates a < code > { @ link AssertionError } < / code > using < code > { @ link ErrorMessageFactory } < / code > to create the detail message of the
 * < code > { @ link AssertionError } < / code > , prepending the value of < code > { @ link Description } < / code > to the
 * error message
 * @ param description contains information about the failed assertion .
 * @ param message knows how to create detail messages for { @ code AssertionError } s .
 * @ return the created < code > { @ link AssertionError } < / code > . */
public AssertionError failure ( Description description , ErrorMessageFactory message ) { } }

implementation: AssertionError assertionError = new AssertionError ( message . create ( description ) ) ; removeFestRelatedElementsFromStackTraceIfNeeded ( assertionError ) ; return assertionError ;


signature:
public class Failures { /** * Creates a < code > { @ link AssertionError } < / code > using the given { @ code String } as message .
 * It filters the AssertionError stack trace be default , to have full stack trace use
 * { @ link # setRemoveFestRelatedElementsFromStackTrace ( boolean ) } .
 * @ param message the message of the { @ code AssertionError } to create .
 * @ return the created < code > { @ link AssertionError } < / code > . */
public AssertionError failure ( String message ) { } }

implementation: AssertionError assertionError = new AssertionError ( message ) ; removeFestRelatedElementsFromStackTraceIfNeeded ( assertionError ) ; return assertionError ;


signature:
public class ShouldHaveAtIndex { /** * Creates a new < / code > { @ link ShouldHaveAtIndex } < / code > .
 * @ param < T > guarantees that the type of the actual value and the generic type of the { @ code Condition } are the same .
 * @ param actual the actual value in the failed assertion .
 * @ param condition the { @ code Condition } .
 * @ param index the index of the expected value .
 * @ param found the value in { @ code actual } stored under { @ code index } .
 * @ return the created { @ code ErrorMessageFactory } . */
public static < T > ErrorMessageFactory shouldHaveAtIndex ( List < T > actual , Matcher < ? super T > condition , Index index , T found ) { } }

implementation: return new ShouldHaveAtIndex ( actual , condition , index , found ) ;


signature:
public class ListAssert { /** * { @ inheritDoc } */
@ Override public ListAssert contains ( Object value , Index index ) { } }

implementation: lists . assertContains ( description , actual , value , index ) ; return this ;


signature:
public class ListAssert { /** * { @ inheritDoc } */
@ Override public ListAssert doesNotContain ( Object value , Index index ) { } }

implementation: lists . assertDoesNotContain ( description , actual , value , index ) ; return this ;


signature:
public class ElementsShouldHaveAtMost { /** * Creates a new < / code > { @ link ElementsShouldHaveAtMost } < / code > .
 * @ param actual the actual value in the failed assertion .
 * @ param times least time the condition should be verify .
 * @ param condition the { @ code Condition } .
 * @ return the created { @ code ErrorMessageFactory } . */
public static ErrorMessageFactory elementsShouldHaveAtMost ( Object actual , int times , Matcher < ? > condition ) { } }

implementation: return new ElementsShouldHaveAtMost ( actual , times , condition ) ;


signature:
public class ElementsShouldHave { /** * Creates a new < / code > { @ link ElementsShouldHave } < / code > .
 * @ param actual the actual value in the failed assertion .
 * @ param notSatisfies elements that not satisfies the condition
 * @ param condition the { @ code Condition } .
 * @ return the created { @ code ErrorMessageFactory } . */
public static ErrorMessageFactory elementsShouldHave ( Object actual , Object notSatisfies , Matcher < ? > condition ) { } }

implementation: return new ElementsShouldHave ( actual , notSatisfies , condition ) ;


signature:
public class ObjectArrays { /** * Verifies that the given array ends with the given sequence of objects , without any other objects between them .
 * Similar to < code > { @ link # assertContainsSequence ( Description , Object [ ] , Object [ ] ) } < / code > , but it also verifies that
 * the last element in the sequence is also the last element of the given array .
 * @ param description contains information about the assertion .
 * @ param actual the given array .
 * @ param sequence the sequence of objects to look for .
 * @ throws NullPointerException if the given argument is { @ code null } .
 * @ throws IllegalArgumentException if the given argument is an empty array .
 * @ throws AssertionError if the given array is { @ code null } .
 * @ throws AssertionError if the given array does not end with the given sequence of objects . */
public void assertEndsWith ( Description description , Object [ ] actual , Object [ ] sequence ) { } }

implementation: arrays . assertEndsWith ( description , actual , sequence ) ;


signature:
public class NotEqualErrorFactory { /** * Creates an { @ link AssertionError } indicating that an assertion that verifies that two objects are equal , failed .
 * If JUnit 4 is in the classpath , this method will instead create a { @ code org . junit . ComparisonFailure } that
 * highlights the difference ( s ) between the expected and actual objects .
 * @ param description the description of the failed assertion .
 * @ return the created { @ code AssertionError } . */
@ Override public AssertionError newAssertionError ( Description description ) { } }

implementation: AssertionError error = comparisonFailure ( description ) ; if ( error != null ) { return error ; } return Failures . instance ( ) . failure ( defaultErrorMessage ( description ) ) ;


signature:
public class StringAssert { /** * { @ inheritDoc } */
@ Override public @ Nonnull StringAssert hasSize ( int expected ) { } }

implementation: strings . assertHasSize ( description , actual , expected ) ; return this ;


signature:
public class StringAssert { /** * Verifies that the < em > actual < / em > { @ code String } is equal to the given one , ignoring case considerations .
 * @ param expected the given { @ code String } to compare the actual { @ code String } to .
 * @ return { @ code this } assertion object .
 * @ throws AssertionError if the < em > actual < / em > { @ code String } is not equal to the given one . */
public @ Nonnull StringAssert isEqualToIgnoringCase ( @ Nullable String expected ) { } }

implementation: strings . assertEqualsIgnoringCase ( description , actual , expected ) ; return this ;


signature:
public class StringAssert { /** * Verifies that the < em > actual < / em > { @ code String } contains the given sequence .
 * @ param sequence the sequence to look for .
 * @ return { @ code this } assertion object .
 * @ throws NullPointerException if the given sequence is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > { @ code String } is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > { @ code String } does not contain the given one . */
public @ Nonnull StringAssert contains ( @ Nonnull String sequence ) { } }

implementation: strings . assertContains ( description , actual , sequence ) ; return this ;


signature:
public class StringAssert { /** * Verifies that the < em > actual < / em > { @ code String } does not contain the given sequence .
 * @ param sequence the sequence to look for .
 * @ return { @ code this } assertion object .
 * @ throws NullPointerException if the given sequence is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > { @ code String } is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > { @ code String } contains the given one . */
public @ Nonnull StringAssert doesNotContain ( @ Nonnull String sequence ) { } }

implementation: strings . assertDoesNotContain ( description , actual , sequence ) ; return this ;


signature:
public class StringAssert { /** * Verifies that the < em > actual < / em > { @ code String } starts with the given prefix .
 * @ param prefix the given prefix .
 * @ return { @ code this } assertion object .
 * @ throws NullPointerException if the given prefix is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > { @ code String } is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > { @ code String } does not start with the given prefix . */
public @ Nonnull StringAssert startsWith ( @ Nonnull String prefix ) { } }

implementation: strings . assertStartsWith ( description , actual , prefix ) ; return this ;


signature:
public class StringAssert { /** * Verifies that the < em > actual < / em > { @ code String } ends with the given suffix .
 * @ param suffix the given suffix .
 * @ return { @ code this } assertion object .
 * @ throws NullPointerException if the given suffix is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > { @ code String } is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > { @ code String } does not end with the given suffix . */
public @ Nonnull StringAssert endsWith ( @ Nonnull String suffix ) { } }

implementation: strings . assertEndsWith ( description , actual , suffix ) ; return this ;


signature:
public class StringAssert { /** * Verifies that the < em > actual < / em > { @ code String } matches the given regular expression .
 * @ param regex the regular expression to which the < em > actual < / em > { @ code String } is to be matched .
 * @ return { @ code this } assertion object .
 * @ throws NullPointerException if the given pattern is { @ code null } .
 * @ throws PatternSyntaxException if the regular expression ' s syntax is invalid .
 * @ throws AssertionError if the < em > actual < / em > { @ code String } is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > { @ code String } does not match the given regular expression . */
public @ Nonnull StringAssert matches ( @ Nonnull String regex ) { } }

implementation: strings . assertMatches ( description , actual , regex ) ; return this ;


signature:
public class StringAssert { /** * Verifies that the < em > actual < / em > { @ code String } does not match the given regular expression .
 * @ param regex the regular expression to which the < em > actual < / em > { @ code String } is to be matched .
 * @ return { @ code this } assertion object .
 * @ throws NullPointerException if the given pattern is { @ code null } .
 * @ throws PatternSyntaxException if the regular expression ' s syntax is invalid .
 * @ throws AssertionError if the < em > actual < / em > { @ code String } matches the given regular expression . */
public @ Nonnull StringAssert doesNotMatch ( @ Nonnull String regex ) { } }

implementation: strings . assertDoesNotMatch ( description , actual , regex ) ; return this ;


signature:
public class StringAssert { /** * Verifies that the < em > actual < / em > { @ code String } matches the given regular expression .
 * @ param pattern the compiled representation of the regular expression to which the < em > actual < / em > { @ code String } is
 * to be matched .
 * @ return { @ code this } assertion object .
 * @ throws NullPointerException if the given pattern is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > { @ code String } is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > { @ code String } does not match the given regular expression . */
public @ Nonnull StringAssert matches ( @ Nonnull Pattern pattern ) { } }

implementation: strings . assertMatches ( description , actual , pattern ) ; return this ;


signature:
public class StringAssert { /** * Verifies that the < em > actual < / em > { @ code String } does not match the given regular expression .
 * @ param pattern the compiled representation of the regular expression to which the < em > actual < / em > { @ code String } is
 * to be matched .
 * @ return { @ code this } assertion object .
 * @ throws NullPointerException if the given pattern is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > { @ code String } does not match the given regular expression . */
public @ Nonnull StringAssert doesNotMatch ( @ Nonnull Pattern pattern ) { } }

implementation: strings . assertDoesNotMatch ( description , actual , pattern ) ; return this ;


signature:
public class ElementsShouldBeAtLeast { /** * Creates a new < / code > { @ link ElementsShouldBeAtLeast } < / code > .
 * @ param actual the actual value in the failed assertion .
 * @ param times least time the condition should be verify .
 * @ param condition the { @ code Condition } .
 * @ return the created { @ code ErrorMessageFactory } . */
public static ErrorMessageFactory elementsShouldBeAtLeast ( Object actual , int times , Matcher < ? > condition ) { } }

implementation: return new ElementsShouldBeAtLeast ( actual , times , condition ) ;


signature:
public class DoesNotHave { /** * Creates a new < / code > { @ link DoesNotHave } < / code > .
 * @ param condition the condition to inverse .
 * @ return The Not condition created . */
public static < T > DoesNotHave < T > doesNotHave ( Matcher < ? super T > condition ) { } }

implementation: return new DoesNotHave < T > ( condition ) ;


signature:
public class ByteArrays { /** * Verifies that the given array does not contain the given value at the given index .
 * @ param description contains information about the assertion .
 * @ param actual the given array .
 * @ param value the value to look for .
 * @ param index the index where the value should be stored in the given array .
 * @ throws AssertionError if the given array is { @ code null } .
 * @ throws NullPointerException if the given { @ code Index } is { @ code null } .
 * @ throws AssertionError if the given array contains the given value at the given index . */
public void assertDoesNotContain ( Description description , byte [ ] actual , byte value , Index index ) { } }

implementation: arrays . assertDoesNotContain ( description , actual , value , index ) ;


signature:
public class ByteArrays { /** * Asserts that the given array contains only the given values and nothing else , in any order .
 * @ param description contains information about the assertion .
 * @ param actual the given array .
 * @ param values the values that are expected to be in the given array .
 * @ throws NullPointerException if the array of values is { @ code null } .
 * @ throws IllegalArgumentException if the array of values is empty .
 * @ throws AssertionError if the given array is { @ code null } .
 * @ throws AssertionError if the given array does not contain the given values or if the given array contains values
 * that are not in the given array . */
public void assertContainsOnly ( Description description , byte [ ] actual , byte [ ] values ) { } }

implementation: arrays . assertContainsOnly ( description , actual , values ) ;


signature:
public class ByteArrays { /** * Verifies that the given array contains the given sequence of values , without any other values between them .
 * @ param description contains information about the assertion .
 * @ param actual the given array .
 * @ param sequence the sequence of values to look for .
 * @ throws AssertionError if the given array is { @ code null } .
 * @ throws NullPointerException if the given sequence is { @ code null } .
 * @ throws IllegalArgumentException if the given sequence is empty .
 * @ throws AssertionError if the given array does not contain the given sequence of values . */
public void assertContainsSequence ( Description description , byte [ ] actual , byte [ ] sequence ) { } }

implementation: arrays . assertContainsSequence ( description , actual , sequence ) ;


signature:
public class Objects { /** * Asserts that the < em > actual < / em > object is not { @ code null } .
 * @ param description the description of the < em > actual < / em > object .
 * @ param actual the < em > actual < / em > object .
 * @ throws AssertionError if the < em > actual < / em > object is { @ code null } . */
public void assertNotNull ( Description description , Object actual ) { } }

implementation: if ( actual == null ) { throw failures . failure ( description , shouldNotBeNull ( ) ) ; }


signature:
public class Objects { /** * Asserts that two objects are equal .
 * @ param description the description of the < em > actual < / em > object .
 * @ param actual the < em > actual < / em > object .
 * @ param expected the < em > expected < / em > object .
 * @ throws AssertionError if { @ code actual } is not equal to { @ code expected } . This method will throw a
 * { @ code org . junit . ComparisonFailure } instead if JUnit is in the classpath and the given objects are not
 * equal . */
public void assertEqual ( Description description , Object actual , Object expected ) { } }

implementation: if ( ! areEqual ( actual , expected ) ) { throw shouldBeEqual ( actual , expected ) . newAssertionError ( description ) ; }


signature:
public class Objects { /** * Asserts that two objects are not equal .
 * @ param description the description of the < em > actual < / em > object .
 * @ param actual the < em > actual < / em > object .
 * @ param other the object to compare { @ code actual } to .
 * @ throws AssertionError if { @ code actual } is equal to { @ code other } . */
public void assertNotEqual ( Description description , Object actual , Object other ) { } }

implementation: if ( areEqual ( actual , other ) ) { throw failures . failure ( description , shouldNotBeEqual ( actual , other ) ) ; }


signature:
public class Objects { /** * Asserts that two objects refer to the same instance .
 * @ param description the description of the < em > actual < / em > object .
 * @ param actual the < em > actual < / em > object .
 * @ param expected the < em > expected < / em > object .
 * @ throws AssertionError if the given objects do not refer to the same instance . */
public void assertSame ( Description description , Object actual , Object expected ) { } }

implementation: if ( actual != expected ) { String format = "expected:<%s> and actual:<%s> should refer to the same instance" ; throw failures . failure ( description , new BasicErrorMessageFactory ( format , expected , actual ) ) ; }


signature:
public class Objects { /** * Asserts that two objects do not refer to the same instance .
 * @ param description the description of the < em > actual < / em > object .
 * @ param actual the < em > actual < / em > object .
 * @ param other the object to compare { @ code actual } to .
 * @ throws AssertionError if the given objects refer to the same instance . */
public void assertNotSame ( Description description , Object actual , Object other ) { } }

implementation: if ( actual == other ) { String format = "expected not same:<%s>" ; throw failures . failure ( description , new BasicErrorMessageFactory ( format , actual ) ) ; }


signature:
public class Objects { /** * Asserts that the < em > actual < / em > object is an instance of the given type .
 * @ param description the description of the < em > actual < / em > object .
 * @ param actual the < em > actual < / em > object .
 * @ param type the type to check the < em > actual < / em > object against .
 * @ throws NullPointerException if the given type is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > object is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > object is not an instance of the given type . */
public void assertIsInstanceOf ( Description description , Object actual , Class < ? > type ) { } }

implementation: checkNotNull ( type ) ; assertNotNull ( description , actual ) ; if ( ! type . isInstance ( actual ) ) { String format = "expecting <%s> to be an instance of:<%s> but was instance of:<%s>" ; throw failures . failure ( description , new BasicErrorMessageFactory ( format , actual , type , actual . getClass ( ) ) ) ; }


signature:
public class Objects { /** * Asserts that the < em > actual < / em > object is not an instance of the given type .
 * @ param description the description of the < em > actual < / em > object .
 * @ param actual the < em > actual < / em > object .
 * @ param type the type to check the < em > actual < / em > object against .
 * @ throws NullPointerException if the given type is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > object is an instance of the given type . */
public void assertIsNotInstanceOf ( Description description , Object actual , Class < ? > type ) { } }

implementation: checkNotNull ( type ) ; if ( type . isInstance ( actual ) ) { String format = "expecting <%s> not to be an instance of:<%s>" ; throw failures . failure ( description , new BasicErrorMessageFactory ( format , actual , type ) ) ; }


signature:
public class Objects { /** * Verifies that the < em > actual < / em > object is an instance of any of the given types .
 * @ param description the description of the < em > actual < / em > object .
 * @ param actual the < em > actual < / em > object .
 * @ param types the types to check the < em > actual < / em > object against .
 * @ throws NullPointerException if the given array is { @ code null } .
 * @ throws IllegalArgumentException if the given array is empty .
 * @ throws NullPointerException if the given array has { @ code null } elements .
 * @ throws AssertionError if the < em > actual < / em > object is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > object is not an instance of any of the given types . */
public void assertIsInstanceOfAny ( Description description , Object actual , Class < ? > [ ] types ) { } }

implementation: checkNotNullOrEmpty ( types ) ; assertNotNull ( description , actual ) ; if ( ! isInstanceOfAny ( actual , types ) ) { String format = "expecting <%s> to be an instance of any of:<%s> but was instance of:<%s>" ; throw failures . failure ( description , new BasicErrorMessageFactory ( format , actual , types , actual . getClass ( ) ) ) ; }


signature:
public class Objects { /** * Verifies that the < em > actual < / em > object is not an instance of any of the given types .
 * @ param description the description of the < em > actual < / em > object .
 * @ param actual the < em > actual < / em > object .
 * @ param types the types to check the < em > actual < / em > object against .
 * @ throws NullPointerException if the given array is { @ code null } .
 * @ throws IllegalArgumentException if the given array is empty .
 * @ throws NullPointerException if the given array has { @ code null } elements .
 * @ throws AssertionError if the < em > actual < / em > object is an instance of any of the given types . */
public void assertIsNotInstanceOfAny ( Description description , Object actual , Class < ? > [ ] types ) { } }

implementation: checkNotNullOrEmpty ( types ) ; if ( isInstanceOfAny ( actual , types ) ) { String format = "expecting <%s> not to be an instance of any of:<%s>" ; throw failures . failure ( description , new BasicErrorMessageFactory ( format , actual , types ) ) ; }


signature:
public class ElementsShouldBeExactly { /** * Creates a new < / code > { @ link ElementsShouldBeExactly } < / code > .
 * @ param actual the actual value in the failed assertion .
 * @ param times exactly times the condition should be verify .
 * @ param condition the { @ code Condition } .
 * @ return the created { @ code ErrorMessageFactory } . */
public static ErrorMessageFactory elementsShouldBeExactly ( Object actual , int times , Matcher < ? > condition ) { } }

implementation: return new ElementsShouldBeExactly ( actual , times , condition ) ;


signature:
public class CharArrays { /** * Asserts that the given array does not contain the given values .
 * @ param description contains information about the assertion .
 * @ param actual the given array .
 * @ param values the values that are expected not to be in the given array .
 * @ throws NullPointerException if the array of values is { @ code null } .
 * @ throws IllegalArgumentException if the array of values is empty .
 * @ throws AssertionError if the given array is { @ code null } .
 * @ throws AssertionError if the given array contains any of given values . */
public void assertDoesNotContain ( Description description , char [ ] actual , char [ ] values ) { } }

implementation: arrays . assertDoesNotContain ( description , actual , values ) ;


signature:
public class CharArrays { /** * Verifies that the given array starts with the given sequence of values , without any other values between them .
 * Similar to < code > { @ link # assertContainsSequence ( Description , char [ ] , char [ ] ) } < / code > , but it also verifies that the
 * first element in the sequence is also the first element of the given array .
 * @ param description contains information about the assertion .
 * @ param actual the given array .
 * @ param sequence the sequence of values to look for .
 * @ throws NullPointerException if the given argument is { @ code null } .
 * @ throws IllegalArgumentException if the given argument is an empty array .
 * @ throws AssertionError if the given array is { @ code null } .
 * @ throws AssertionError if the given array does not start with the given sequence of values . */
public void assertStartsWith ( Description description , char [ ] actual , char [ ] sequence ) { } }

implementation: arrays . assertStartsWith ( description , actual , sequence ) ;


signature:
public class CharArrays { /** * Verifies that the actual is sorted into ascending order according to the natural ordering of its elements .
 * Empty arrays are considered sorted .
 * @ param description contains the information about the assertion .
 * @ param actual the given array .
 * @ throws AssertionError if the { @ code actual } is { @ code null } . */
public void assertIsSorted ( Description description , char [ ] actual ) { } }

implementation: if ( actual == null ) { throw failures . failure ( "The actual is null" ) ; } if ( actual . length == 0 ) { return ; } for ( int i = 0 ; i < actual . length - 1 ; i ++ ) { if ( actual [ i ] > actual [ i + 1 ] ) { throw failures . failure ( description , shouldBeSorted ( i , actual ) ) ; } }


signature:
public class Fail { /** * Throws an { @ link AssertionError } with the given message and with the { @ link Throwable } that caused the failure .
 * @ param failureMessage the description of the failed assertion . It can be { @ code null } .
 * @ param realCause cause of the error .
 * @ throws AssertionError with the given message and with the { @ link Throwable } that caused the failure . */
public static void fail ( String failureMessage , Throwable realCause ) { } }

implementation: AssertionError error = Failures . instance ( ) . failure ( failureMessage ) ; error . initCause ( realCause ) ; throw error ;


signature:
public class Fail { /** * Throws an { @ link AssertionError } with a message explaining that a { @ link Throwable } of given class was expected to
 * be thrown but had not been .
 * @ param throwableClass the Throwable class that was expected to be thrown .
 * @ throws AssertionError with a message explaining that a { @ link Throwable } of given class was expected to be thrown
 * but had not been . */
public static void failBecauseExceptionWasNotThrown ( Class < ? extends Throwable > throwableClass ) { } }

implementation: throw Failures . instance ( ) . failure ( format ( "Expected %s to be thrown" , throwableClass . getSimpleName ( ) ) ) ;


signature:
public class Files { /** * Asserts that the < em > actual < / em > { @ link File } represents an existing file or directory .
 * @ param description the description of the < em > actual < / em > { @ code File } .
 * @ param actual the < em > actual < / em > { @ code File } .
 * @ throws AssertionError if the < em > actual < / em > { @ code File } is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > { @ link File } represents a file or directory that does not exist . */
public void assertExists ( Description description , File actual ) { } }

implementation: assertNotNull ( description , actual ) ; if ( ! actual . exists ( ) ) { String format = "expecting resource in path:<%s> to exist" ; throw failures . failure ( description , new BasicErrorMessageFactory ( format , actual ) ) ; }


signature:
public class Files { /** * Asserts that the < em > actual < / em > { @ code File } represents an existing file .
 * @ param description the description of the < em > actual < / em > { @ code File } .
 * @ param actual the < em > actual < / em > { @ code File } .
 * @ throws AssertionError if the < em > actual < / em > { @ code File } is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > { @ code File } does not represent an existing file . */
public void assertIsFile ( Description description , File actual ) { } }

implementation: assertNotNull ( description , actual ) ; if ( ! actual . isFile ( ) ) { String format = "expecting path:<%s> to represent an existing file" ; throw failures . failure ( description , new BasicErrorMessageFactory ( format , actual ) ) ; }


signature:
public class Files { /** * Asserts that the < em > actual < / em > { @ code File } represents an existing directory .
 * @ param description the description of the < em > actual < / em > { @ code File } .
 * @ param actual the < em > actual < / em > { @ code File } .
 * @ throws AssertionError if the < em > actual < / em > { @ code File } is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > { @ code File } does not represent an existing directory . */
public void assertIsDirectory ( Description description , File actual ) { } }

implementation: assertNotNull ( description , actual ) ; if ( ! actual . isDirectory ( ) ) { String format = "expecting path:<%s> to represent an existing directory" ; throw failures . failure ( description , new BasicErrorMessageFactory ( format , actual ) ) ; }


signature:
public class Files { /** * Asserts that the given { @ code File } s represent existing files with equal content . It is assumed that the content of
 * the files is text .
 * @ param description the description of the < em > actual < / em > { @ code File } .
 * @ param actual the < em > actual < / em > { @ code File } .
 * @ param expected the < em > expected < / em > { @ code File } .
 * @ param charset the charset to use when reading the contents of the given { @ code File } s .
 * @ throws NullPointerException if the < em > expected < / em > { @ code File } is { @ code null } .
 * @ throws IllegalArgumentException if the < em > expected < / em > { @ code File } does not represent an existing file .
 * @ throws NullPointerException if the given charset is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > { @ code File } is { @ code null } .
 * @ throws AssertionError if the < em > actual < / em > { @ code File } does not represent an existing file .
 * @ throws IORuntimeException if an I / O error occurs .
 * @ throws AssertionError if the given files do not have equal content . */
public void assertEqualContent ( Description description , File actual , File expected , Charset charset ) { } }

implementation: checkIsFile ( expected ) ; checkNotNull ( charset ) ; assertIsFile ( description , actual ) ; try { String lineSeparator = System . getProperty ( "line.separator" ) ; FileDiffs diffs = comparator . compareContents ( actual , expected , charset ) ; if ( ! diffs . isEmpty ( ) ) { String format = "files expected:<%s> and actual:<%s> do not have equal content:" + lineSeparator + "%s" + lineSeparator + "using charset:<%s>" ; throw failures . failure ( description , new BasicErrorMessageFactory ( format , expected , actual , diffs , charset ) ) ; } } catch ( IOException e ) { String format = "Failed to compare contents of files:<%s> and:<%s> using charset:<%s>" ; throw new IORuntimeException ( String . format ( format , actual , expected , charset ) , e ) ; }


signature:
public class ElementsShouldHaveAtLeast { /** * Creates a new < / code > { @ link ElementsShouldHaveAtLeast } < / code > .
 * @ param actual the actual value in the failed assertion .
 * @ param times least time the condition should be verify .
 * @ param condition the { @ code Condition } .
 * @ return the created { @ code ErrorMessageFactory } . */
public static ErrorMessageFactory elementsShouldHaveAtLeast ( Object actual , int times , Matcher < ? > condition ) { } }

implementation: return new ElementsShouldHaveAtLeast ( actual , times , condition ) ;


signature:
public class AllOf { /** * Creates a new < code > { @ link AllOf } < / code >
 * @ param < T > the type of object the given condition accept .
 * @ param conditions the conditions to evaluate .
 * @ return the created { @ code AnyOf } .
 * @ throws NullPointerException if the given iterable is { @ code null } .
 * @ throws NullPointerException if any of the elements in the given iterable is { @ code null } . */
public static < T > Matcher < T > allOf ( Iterable < ? extends Matcher < ? super T > > conditions ) { } }

implementation: return new AllOf < T > ( conditions ) ;


signature:
public class ElementsShouldBe { /** * Creates a new < / code > { @ link ElementsShouldBe } < / code > .
 * @ param actual the actual value in the failed assertion .
 * @ param notSatisfies elements that not satisfies the condition
 * @ param condition the { @ code Condition } .
 * @ return the created { @ code ErrorMessageFactory } . */
public static ErrorMessageFactory elementsShouldBe ( Object actual , Object notSatisfies , Matcher < ? > condition ) { } }

implementation: return new ElementsShouldBe ( actual , notSatisfies , condition ) ;


signature:
public class ShouldContain { /** * Creates a new < / code > { @ link ShouldContain } < / code > .
 * @ param actual the actual value in the failed assertion .
 * @ param expected values expected to be in { @ code actual } .
 * @ param notFound the values in { @ code expected } not found in { @ code actual } .
 * @ return the created { @ code ErrorMessageFactory } . */
public static ErrorMessageFactory shouldContain ( Object actual , Object expected , Object notFound ) { } }

implementation: return new ShouldContain ( actual , expected , notFound ) ;


signature:
public class ElementsShouldBeAtMost { /** * Creates a new < / code > { @ link ElementsShouldBeAtMost } < / code > .
 * @ param actual the actual value in the failed assertion .
 * @ param times least time the condition should be verify .
 * @ param condition the { @ code Condition } .
 * @ return the created { @ code ErrorMessageFactory } . */
public static ErrorMessageFactory elementsShouldBeAtMost ( Object actual , int times , Matcher < ? > condition ) { } }

implementation: return new ElementsShouldBeAtMost ( actual , times , condition ) ;


signature:
public class ElementsShouldNotHaveAtLeast { /** * Creates a new < / code > { @ link ElementsShouldNotHaveAtLeast } < / code > .
 * @ param actual the actual value in the failed assertion .
 * @ param times least time the condition should be verify .
 * @ param condition the { @ code Condition } .
 * @ return the created { @ code ErrorMessageFactory } . */
public static ErrorMessageFactory elementsShouldNotHaveAtLeast ( Object actual , int times , Matcher < ? > condition ) { } }

implementation: return new ElementsShouldNotHaveAtLeast ( actual , times , condition ) ;


signature:
public class ShouldBeSorted { /** * Creates a new < code > { @ link ShouldBeSorted } < / code > .
 * @ param i the index of elements whose not naturally ordered with the next .
 * @ param group the actual group in the failed assertion ( either collection or an array ) .
 * @ return an instance of { @ code ErrorMessageFactory } . */
public static ErrorMessageFactory shouldBeSorted ( int i , Object group ) { } }

implementation: List < ? > groupAsList = groupAsList ( group ) ; return new ShouldBeSorted ( "group is not sorted because element %s:<%s> is not less or equal than element %s:<%s>.\n" + "group was:\n" + "<%s>" , i , groupAsList . get ( i ) , i + 1 , groupAsList . get ( i + 1 ) , groupAsList ) ;


signature:
public class ShouldBeSorted { /** * Convert the given group ( which is either an array or a Collection ) to a List .
 * @ param group the group to convert
 * @ return the corresponding List
 * @ throws IllegalArgumentException if group can ' t be converted to a List */
@ SuppressWarnings ( "unchecked" ) private static List < ? > groupAsList ( Object group ) { } }

implementation: if ( group . getClass ( ) . isArray ( ) ) { return wrap ( group ) ; } else if ( group instanceof Collection < ? > ) { List < Object > asList = new ArrayList < Object > ( ) ; asList . addAll ( ( ( Collection < Object > ) group ) ) ; return asList ; } throw new IllegalArgumentException ( "Parameter should be an array or a collection but was " + group ) ;


signature:
public class ArrayWrapperList { /** * Wraps a given array with a < code > { @ link ArrayWrapperList } < / code >
 * @ param array the array to wrap .
 * @ return the wrapped array or { @ code null } if the given array was already { @ code null } .
 * @ throws IllegalArgumentException if the { @ code array } is not an array . */
public static ArrayWrapperList wrap ( Object array ) { } }

implementation: if ( array == null ) { return null ; } if ( ! array . getClass ( ) . isArray ( ) ) { throw new IllegalArgumentException ( "The object to wrap should be an array" ) ; } return new ArrayWrapperList ( array ) ;


signature:
public class ArrayWrapperList { /** * { @ inheritDoc } */
@ Override public Object get ( int index ) { } }

implementation: checkIsInRange ( index ) ; return Array . get ( array , index ) ;


signature:
public class DoubleAssert { /** * { @ inheritDoc } */
@ Override public DoubleAssert isEqualTo ( Double expected , Offset < Double > offset ) { } }

implementation: doubles . assertEqual ( description , actual , expected , offset ) ; return this ;


signature:
public class DoubleAssert { /** * { @ inheritDoc } */
@ Override public DoubleAssert isNotEqualTo ( Double expected ) { } }

implementation: doubles . assertNotEqual ( description , actual , expected ) ; return this ;


signature:
public class ObjectArrayAssert { /** * { @ inheritDoc } */
@ Override @ Nonnull public ObjectArrayAssert hasSize ( int expectedSize ) { } }

implementation: arrays . assertHasSize ( description , actual , expectedSize ) ; return this ;


signature:
public class ObjectArrayAssert { /** * Verifies that the given array contains the given object at the given index .
 * @ param value the object to look for .
 * @ param index the index where the object should be stored in the given array .
 * @ return { @ code this } assertion object .
 * @ throws AssertionError if the given array is { @ code null } or empty .
 * @ throws NullPointerException if the given { @ code Index } is { @ code null } .
 * @ throws IndexOutOfBoundsException if the value of the given { @ code Index } is equal to or greater than the size of
 * the given array .
 * @ throws AssertionError if the given array does not contain the given object at the given index . */
public ObjectArrayAssert contains ( Object value , Index index ) { } }

implementation: arrays . assertContains ( description , actual , value , index ) ; return this ;


signature:
public class ObjectArrayAssert { /** * Verifies that the given array contains the given object at the given index .
 * @ param value the object to look for .
 * @ param index the index where the object should be stored in the given array .
 * @ return { @ code this } assertion object .
 * @ throws AssertionError if the given array is { @ code null } or empty .
 * @ throws NullPointerException if the given { @ code Index } is { @ code null } .
 * @ throws IndexOutOfBoundsException if the value of the given { @ code Index } is equal to or greater than the size of
 * the given array .
 * @ throws AssertionError if the given array does not contain the given object at the given index . */
public ObjectArrayAssert doesNotContain ( Object value , Index index ) { } }

implementation: arrays . assertDoesNotContain ( description , actual , value , index ) ; return this ;


signature:
public class ShouldContainOnly { /** * Creates a new < / code > { @ link ShouldContainOnly } < / code > .
 * @ param actual the actual value in the failed assertion .
 * @ param expected values expected to be contained in { @ code actual } .
 * @ param notFound values in { @ code expected } not found in { @ code actual } .
 * @ param notExpected values in { @ code actual } that were not in { @ code expected } .
 * @ return the created { @ code ErrorMessageFactory } . */
public static ErrorMessageFactory shouldContainOnly ( Object actual , Object expected , Object notFound , Object notExpected ) { } }

implementation: return new ShouldContainOnly ( actual , expected , notFound , notExpected ) ;


signature:
public class ShouldBeSubsetOf { /** * Creates a new < code > { @ link ShouldBeSubsetOf } < / code > .
 * @ param actual the actual set
 * @ param values the expected superset
 * @ param unexpected the elements found in the actual set , but not in the given values .
 * @ return the created { @ code ErrorMessageFactory } . */
public static ErrorMessageFactory shouldBeSubsetOf ( Object actual , Object values , Iterable < ? > unexpected ) { } }

implementation: return new ShouldBeSubsetOf ( actual , values , unexpected ) ;


signature:
public class Collections { /** * Asserts that the given { @ code Collection } contains { @ code null } .
 * @ param description contains information about the assertion .
 * @ param actual the given { @ code Collection } .
 * @ throws AssertionError if the given { @ code Collection } is { @ code null } .
 * @ throws AssertionError if the given { @ code Collection } does not contain null . */
public void assertContainsNull ( Description description , Collection < ? > actual ) { } }

implementation: assertNotNull ( description , actual ) ; if ( ! actual . contains ( null ) ) { throw failures . failure ( description , ShouldContainNull . shouldContainNull ( actual ) ) ; }


signature:
public class Collections { /** * Verifies that the given < code > { @ link Collection } < / code > contains the given sequence of objects , without any other
 * objects between them .
 * @ param description contains information about the assertion .
 * @ param actual the given { @ code Collection } .
 * @ param sequence the sequence of objects to look for .
 * @ throws AssertionError if the given { @ code Collection } is { @ code null } .
 * @ throws NullPointerException if the given sequence is { @ code null } .
 * @ throws IllegalArgumentException if the given sequence is empty .
 * @ throws AssertionError if the given { @ code Collection } does not contain the given sequence of objects . */
public void assertContainsSequence ( Description description , Collection < ? > actual , Object [ ] sequence ) { } }

implementation: checkIsNotNullAndNotEmpty ( sequence ) ; assertNotNull ( description , actual ) ; boolean firstAlreadyFound = false ; int i = 0 ; int sequenceSize = sequence . length ; for ( Object o : actual ) { if ( i >= sequenceSize ) { break ; } if ( ! firstAlreadyFound ) { if ( ! areEqual ( o , sequence [ i ] ) ) { continue ; } firstAlreadyFound = true ; i ++ ; continue ; } if ( areEqual ( o , sequence [ i ++ ] ) ) { continue ; } throw actualDoesNotContainSequence ( description , actual , sequence ) ; } if ( ! firstAlreadyFound || i < sequenceSize ) { throw actualDoesNotContainSequence ( description , actual , sequence ) ; }


signature:
public class Collections { /** * Asserts that the given { @ code Collection } does not contain the given values .
 * @ param description contains information about the assertion .
 * @ param actual the given { @ code Collection } .
 * @ param values the values that are expected not to be in the given { @ code Collection } .
 * @ throws NullPointerException if the array of values is { @ code null } .
 * @ throws IllegalArgumentException if the array of values is empty .
 * @ throws AssertionError if the given { @ code Collection } is { @ code null } .
 * @ throws AssertionError if the given { @ code Collection } contains any of given values . */
public void assertDoesNotContain ( Description description , Collection < ? > actual , Object [ ] values ) { } }

implementation: checkIsNotNullAndNotEmpty ( values ) ; assertNotNull ( description , actual ) ; Set < Object > found = new LinkedHashSet < Object > ( ) ; for ( Object o : values ) { if ( actual . contains ( o ) ) { found . add ( o ) ; } } if ( found . isEmpty ( ) ) { return ; } throw failures . failure ( description , shouldNotContain ( actual , values , found ) ) ;


signature:
public class Collections { /** * Asserts that the given { @ code Collection } does not have duplicate values .
 * @ param description contains information about the assertion .
 * @ param actual the given { @ code Collection } .
 * @ throws NullPointerException if the array of values is { @ code null } .
 * @ throws IllegalArgumentException if the array of values is empty .
 * @ throws AssertionError if the given { @ code Collection } is { @ code null } .
 * @ throws AssertionError if the given { @ code Collection } contains duplicate values . */
public void assertDoesNotHaveDuplicates ( Description description , Collection < ? > actual ) { } }

implementation: assertNotNull ( description , actual ) ; Collection < ? > duplicates = duplicatesFrom ( actual ) ; if ( duplicates . isEmpty ( ) ) { return ; } throw failures . failure ( description , shouldNotHaveDuplicates ( actual , duplicates ) ) ;


signature:
public class Offset { /** * Creates a new { @ link Offset } .
 * @ param value the value of the offset .
 * @ return the created { @ code Offset } .
 * @ throws NullPointerException if the given value is { @ code null } .
 * @ throws IllegalArgumentException if the given value is negative . */
public static Offset < Double > offset ( Double value ) { } }

implementation: checkNotNull ( value ) ; if ( value . doubleValue ( ) < 0d ) { throw valueNotPositive ( ) ; } return new Offset < Double > ( value ) ;


signature:
public class Offset { /** * Creates a new { @ link Offset } .
 * @ param value the value of the offset .
 * @ return the created { @ code Offset } .
 * @ throws NullPointerException if the given value is { @ code null } .
 * @ throws IllegalArgumentException if the given value is negative . */
public static Offset < Float > offset ( Float value ) { } }

implementation: checkNotNull ( value ) ; if ( value . floatValue ( ) < 0f ) { throw valueNotPositive ( ) ; } return new Offset < Float > ( value ) ;


signature:
public class Offset { /** * Creates a new { @ link Offset } .
 * @ param value the value of the offset .
 * @ return the created { @ code Offset } .
 * @ throws NullPointerException if the given value is { @ code null } .
 * @ throws IllegalArgumentException if the given value is negative . */
public static Offset < Integer > offset ( Integer value ) { } }

implementation: checkNotNull ( value ) ; if ( value . intValue ( ) < 0 ) { throw valueNotPositive ( ) ; } return new Offset < Integer > ( value ) ;


signature:
public class Assertive { /** * Precondition that clients are required to fulfill .
 * Violations are considered to be programming errors ,
 * on the clients part .
 * @ param < T > type of object to check
 * @ param o the object to check
 * @ param matcher the matcher that the given object must satisfy
 * @ return the validated object */
public static < T > T require ( T o , Matcher < ? > matcher ) { } }

implementation: getProvider ( ) . requirePolicy ( ) . check ( matcherContract ( o , matcher ) ) ; return o ;


signature:
public class Assertive { /** * Precondition that clients are required to fulfill .
 * Violations are considered to be programming errors ,
 * on the clients part .
 * @ param condition the condition to check
 * @ param msg message { @ link java . lang . String # format format string }
 * @ param values values passed into the msg format string */
public static void require ( boolean condition , String msg , Object ... values ) { } }

implementation: getProvider ( ) . requirePolicy ( ) . check ( booleanContract ( condition , describing ( msg , values ) ) ) ;


signature:
public class Assertive { /** * Postcondition that supplier are supposed to ensure .
 * Violations are considered to be programming errors ,
 * on the suppliers part .
 * @ param < T > type of object to check
 * @ param o the object to check
 * @ param matcher the matcher that the given object must satisfy
 * @ return the validated object */
public static < T > T ensure ( T o , Matcher < ? > matcher ) { } }

implementation: getProvider ( ) . ensurePolicy ( ) . check ( matcherContract ( o , matcher ) ) ; return o ;


signature:
public class Assertive { /** * Postcondition that supplier are supposed to ensure .
 * Violations are considered to be programming errors ,
 * on the suppliers part .
 * @ param condition the condition to check
 * @ param msg message { @ link java . lang . String # format format string }
 * @ param values values passed into the msg format string */
public static void ensure ( boolean condition , String msg , Object ... values ) { } }

implementation: getProvider ( ) . ensurePolicy ( ) . check ( booleanContract ( condition , describing ( msg , values ) ) ) ;


signature:
public class Assertive { /** * Unreachable code have been reached . This is
 * considered to be a programming error .
 * @ param msg message { @ link java . lang . String # format format string }
 * @ param values values passed into the msg format string */
public static void neverGetHere ( String msg , Object ... values ) { } }

implementation: getProvider ( ) . neverGetHerePolicy ( ) . neverGetHere ( NO_CAUSE , describing ( msg , values ) ) ;


signature:
public class Assertive { /** * Unexpected exception have been caught . This is considered
 * to be a programming error .
 * @ param t the throwable being unexpectedly caught .
 * @ param msg message { @ link java . lang . String # format format string }
 * @ param values values passed into the msg format string */
public static void neverGetHere ( Throwable t , String msg , Object ... values ) { } }

implementation: getProvider ( ) . neverGetHerePolicy ( ) . neverGetHere ( t , describing ( msg , values ) ) ;


signature:
public class Assertive { /** * Unreachable code have been reached . This is
 * considered to be a programming error .
 * @ param msg descriptive message
 * @ return an error */
public static Error neverGetHereError ( String msg ) { } }

implementation: getProvider ( ) . neverGetHerePolicy ( ) . neverGetHere ( NO_CAUSE , msg ) ; return DEFAULT_ERROR ;


signature:
public class Assertive { /** * Unreachable code have been reached . This is
 * considered to be a programming error .
 * @ param msg message { @ link java . lang . String # format format string }
 * @ param values values passed into the msg format string
 * @ return an error */
public static Error neverGetHereError ( String msg , Object ... values ) { } }

implementation: getProvider ( ) . neverGetHerePolicy ( ) . neverGetHere ( NO_CAUSE , describing ( msg , values ) ) ; return DEFAULT_ERROR ;


signature:
public class Assertive { /** * Unexpected exception have been caught . This is considered
 * to be a programming error .
 * @ param t the throwable being unexpectedly caught .
 * @ return an error */
public static Error neverGetHereError ( Throwable t ) { } }

implementation: getProvider ( ) . neverGetHerePolicy ( ) . neverGetHere ( t , NULL_MESSAGE ) ; return DEFAULT_ERROR ;


signature:
public class Assertive { /** * Unexpected exception have been caught . This is considered
 * to be a programming error .
 * @ param t the throwable being unexpectedly caught .
 * @ param msg message { @ link java . lang . String # format format string }
 * @ param values values passed into the msg format string
 * @ return an error */
public static Error neverGetHereError ( Throwable t , String msg , Object ... values ) { } }

implementation: getProvider ( ) . neverGetHerePolicy ( ) . neverGetHere ( t , describing ( msg , values ) ) ; return DEFAULT_ERROR ;


signature:
public class ArgumentMatchers { /** * Wraps an existing matcher , decorating its description with the name specified . All other functions are
 * delegated to the decorated matcher , including its mismatch description .
 * Example :
 * < pre > named ( " theNameOfMyArgument " , notNullValue ( ) ) < / pre >
 * @ param < T >
 * the type of object to match
 * @ param name
 * the given name of the wrapped matcher
 * @ param matcher
 * the matcher to decorate with a name
 * @ return
 * the decorated matcher */
@ Factory public static < T > Matcher < T > named ( String name , Matcher < T > matcher ) { } }

implementation: return describedAs ( "%0 = %1" , matcher , name , matcher ) ;


signature:
public class ArgumentMatchers { /** * A matcher matching non - null and non - empty strings
 * Example :
 * < pre > assertThat ( " this is not an empty string " , notEmptyString ( ) ) < / pre >
 * @ return
 * matcher for a not empty string */
@ Factory public static Matcher < String > notEmptyString ( ) { } }

implementation: return new CustomTypeSafeMatcher < String > ( "not empty" ) { @ Override protected boolean matchesSafely ( String s ) { return ! s . isEmpty ( ) ; } } ;


signature:
public class Validation { /** * Validate the boolean expression that is supposed to be true .
 * If not , a recoverable exception will be thrown that the client
 * is supposed to catch and recover from .
 * @ param < X > type of exception to throw if validation fails
 * @ param condition the condition to validate . Supposed to be true .
 * @ param exceptionClass the class of recoverable exception to be thrown if validation fails .
 * @ throws X the recoverable exception , if validation fails */
public static < X extends Exception > void validate ( boolean condition , Class < X > exceptionClass ) throws X { } }

implementation: if ( ! condition ) { throw exception ( exceptionClass ) . newInstance ( null ) ; }


signature:
public class Validation { /** * Validate the boolean expression that is supposed to be true .
 * If not , a recoverable exception will be thrown that the client
 * is supposed to catch and recover from .
 * @ param < X > type of exception to throw if validation fails
 * @ param condition the condition to validate . Supposed to be true .
 * @ param factory the factory of recoverable exception to be thrown if validation fails .
 * @ throws X the recoverable exception , if validation fails */
public static < X extends Exception > void validate ( boolean condition , ExceptionFactory < X > factory ) throws X { } }

implementation: if ( ! condition ) { throw factory . newInstance ( null ) ; }


signature:
public class Validation { /** * Validate the given object that is supposed to satisfy the matcher .
 * If not , a recoverable exception will be thrown that the client
 * is supposed to catch and recover from .
 * @ param < T > type of object to validate
 * @ param < X > type of exception to throw if validation fails
 * @ param o the object to validate
 * @ param matcher the matcher that the object must satisfy
 * @ param exception the recoverable exception to be thrown if validation fails .
 * @ return the validated object , if valid
 * @ throws X the recoverable exception , if validation fails */
public static < T , X extends Exception > T validate ( T o , Matcher < ? > matcher , X exception ) throws X { } }

implementation: if ( ! matcher . matches ( o ) ) { throw exception ; } return o ;


signature:
public class Validation { /** * Validate the given object that is supposed to satisfy the matcher .
 * If not , a recoverable exception will be thrown that the client
 * is supposed to catch and recover from .
 * @ param < T > type of object to validate
 * @ param < X > type of exception to throw if validation fails
 * @ param o the object to validate
 * @ param matcher the matcher that the object must satisfy
 * @ param exceptionClass the class of recoverable exception to be thrown if validation fails .
 * @ return the validated object , if valid
 * @ throws X the recoverable exception , if validation fails */
public static < T , X extends Exception > T validate ( T o , Matcher < ? > matcher , Class < X > exceptionClass ) throws X { } }

implementation: if ( ! matcher . matches ( o ) ) { throw exception ( exceptionClass ) . newInstance ( describingMismatchOf ( o , matcher ) . toString ( ) ) ; } return o ;


signature:
public class Validation { /** * Validate the given object that is supposed to satisfy the matcher .
 * If not , a recoverable exception will be thrown that the client
 * is supposed to catch and recover from .
 * @ param < T > type of object to validate
 * @ param < X > type of exception to throw if validation fails
 * @ param o the object to validate
 * @ param matcher the matcher that the object must satisfy
 * @ param factory the factory of recoverable exception to be thrown if validation fails .
 * @ return the validated object , if valid
 * @ throws X the recoverable exception , if validation fails */
public static < T , X extends Exception > T validate ( T o , Matcher < ? > matcher , ExceptionFactory < X > factory ) throws X { } }

implementation: if ( ! matcher . matches ( o ) ) { throw factory . newInstance ( describingMismatchOf ( o , matcher ) . toString ( ) ) ; } return o ;


signature:
public class Resource { /** * TODO : support fancier resolutions */
public Resource resolve ( String path ) { } }

implementation:
// it might be an absolute path . . .
if ( path . startsWith ( "http:" ) || path . startsWith ( "https:" ) || path . startsWith ( "file:" ) ) { return new Resource ( path , query , headers ) ; } // strip prefix / if needed . . .
if ( path . startsWith ( "/" ) ) { path = path . substring ( 1 ) ; } return new Resource ( this . path + "/" + path , query , headers ) ;


signature:
public class DefaultCallbackFactory { /** * helper method to create the callback with all configurations wanted
 * @ param method
 * @ return */
@ Override public FilterawareRequestCallback createCallback ( Method method ) { } }

implementation: FilterawareRequestCallback callback = new DefaultFilterawareRequestCallback ( method ) ; for ( CallbackFilter filter : callbackFilters ) { callback . addFilter ( filter ) ; } return callback ;


signature: public class AbstractJsonEncoderDecoder { public static BigDecimal toBigDecimal ( JSONValue value ) { } }

implementation: JSONNumber number = value . isNumber ( ) ; if ( number != null ) { return new BigDecimal ( number . toString ( ) ) ; } JSONString string = value . isString ( ) ; if ( string != null ) { try { return new BigDecimal ( string . stringValue ( ) ) ; } catch ( NumberFormatException e ) { } } throw new DecodingException ( "Expected a json number, but was given: " + value ) ;


signature:
public class AbstractJsonEncoderDecoder { /** * TODO ( sbeutel ) : new map method to handle other key values than String */
public static < KeyType , ValueType > JSONValue toJSON ( Map < KeyType , ValueType > value , AbstractJsonEncoderDecoder < ? super KeyType > keyEncoder , AbstractJsonEncoderDecoder < ? super ValueType > valueEncoder , Style style ) { } }

implementation:
if ( value == null ) { return getNullType ( ) ; } switch ( style ) { case DEFAULT : case SIMPLE : { JSONObject rc = new JSONObject ( ) ; for ( Entry < KeyType , ValueType > t : value . entrySet ( ) ) { // TODO find a way to check only once
JSONValue k = keyEncoder . encode ( t . getKey ( ) ) ; if ( k . isString ( ) != null ) { rc . put ( k . isString ( ) . stringValue ( ) , valueEncoder . encode ( t . getValue ( ) ) ) ; } else { rc . put ( k . toString ( ) , valueEncoder . encode ( t . getValue ( ) ) ) ; } } return rc ; } case JETTISON_NATURAL : { JSONObject rc = new JSONObject ( ) ; JSONArray entries = new JSONArray ( ) ; int i = 0 ; for ( Entry < KeyType , ValueType > t : value . entrySet ( ) ) { JSONObject entry = new JSONObject ( ) ; // TODO find a way to check only once
JSONValue k = keyEncoder . encode ( t . getKey ( ) ) ; if ( k . isString ( ) != null ) { entry . put ( "key" , k ) ; } else { entry . put ( "key" , new JSONString ( k . toString ( ) ) ) ; } entry . put ( "value" , valueEncoder . encode ( t . getValue ( ) ) ) ; entries . set ( i ++ , entry ) ; } rc . put ( "entry" , entries ) ; return rc ; } default : throw new UnsupportedOperationException ( "The encoding style is not yet supported: " + style . name ( ) ) ; }


signature:
public class UI { /** * This is the entry point method . */
@ Override public void onModuleLoad ( ) { } }

implementation: Button button = new Button ( "Place Pizza Order" ) ; button . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { placeOrder ( ) ; } } ) ; RootPanel . get ( ) . add ( button ) ; button = new Button ( "Do Put" ) ; button . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { doPut ( ) ; } } ) ; RootPanel . get ( ) . add ( button ) ; button = new Button ( "Do A Search on Yahoo /w Jsonp" ) ; button . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { doJsonp ( ) ; } } ) ; RootPanel . get ( ) . add ( button ) ;


signature:
public class DefaultDispatcherFilter { /** * main filter method for a dispatcherfilter .
 * @ return continue filtering or not */
@ Override public boolean filter ( Method method , RequestBuilder builder ) { } }

implementation: if ( LogConfiguration . loggingIsEnabled ( ) ) { Logger . getLogger ( Dispatcher . class . getName ( ) ) . info ( "Sending http request: " + builder . getHTTPMethod ( ) + " " + builder . getUrl ( ) ) ; } builder . setCallback ( callbackFactory . createCallback ( method ) ) ; return true ;


signature:
public class CachingDispatcherFilter { /** * main filter method for a dispatcherfilter .
 * @ return continue filtering or not */
@ Override public boolean filter ( Method method , final RequestBuilder builder ) { } }

implementation:
CacheKey cacheKey = cacheKey ( builder ) ; if ( cacheKey != null ) { final Response cachedResponse = cacheStorage . getResultOrReturnNull ( cacheKey ) ; if ( cachedResponse != null ) { // case 1 : we got a result in cache = > return it . . .
if ( LogConfiguration . loggingIsEnabled ( ) ) { Logger . getLogger ( Dispatcher . class . getName ( ) ) . info ( "already got a cached response for: " + builder . getHTTPMethod ( ) + " " + builder . getUrl ( ) ) ; } // onResponseReceived can be time consuming and can manipulate the DOM
// deferring the command keeps the async behaviour of this method call
Scheduler . get ( ) . scheduleDeferred ( new ScheduledCommand ( ) { @ Override public void execute ( ) { builder . getCallback ( ) . onResponseReceived ( null , cachedResponse ) ; } } ) ; return false ; } RequestCallback callback = callbackFactory . createCallback ( method ) ; // case 2 : = > no cache in result = > queue it . . . .
if ( ! cacheStorage . hasCallback ( cacheKey ) ) { // case 2.1 = > first callback = > make a new one and execute . . .
cacheStorage . addCallback ( cacheKey , builder . getCallback ( ) ) ; if ( LogConfiguration . loggingIsEnabled ( ) ) { Logger . getLogger ( Dispatcher . class . getName ( ) ) . info ( "Sending *caching* http request: " + builder . getHTTPMethod ( ) + " " + builder . getUrl ( ) ) ; } // important part :
builder . setCallback ( callback ) ; return true ; } // case 2.2 = > a callback already in progress = > queue to get response when back
if ( LogConfiguration . loggingIsEnabled ( ) ) { Logger . getLogger ( Dispatcher . class . getName ( ) ) . info ( "request in progress, queue callback: " + builder . getHTTPMethod ( ) + " " + builder . getUrl ( ) ) ; } cacheStorage . addCallback ( cacheKey , callback ) ; return false ; } // non cachable case
if ( LogConfiguration . loggingIsEnabled ( ) ) { String content = builder . getRequestData ( ) ; Logger . getLogger ( Dispatcher . class . getName ( ) ) . info ( "Sending *non-caching* http request: " + builder . getHTTPMethod ( ) + " " + builder . getUrl ( ) + " (Content: `" + content + "´)" ) ; } // * add X - Request - Token to all non - caching calls ( ! = GET ) if we have some
// builder . setHeader ( " X - Testing " , " Bude " ) ;
builder . setCallback ( callbackFactory . createCallback ( method ) ) ; return true ; // continue filtering


signature:
public class JsonEncoderDecoderClassCreator { /** * This method does NOT return the subtypes of the given class , but all the subtypes associated with the
 * { @ link JsonSubTypes } annotation , even if this annotation is assigned to
 * a parent class or an interface . */
private Collection < Type > findJsonSubTypes ( JClassType clazz ) { } }

implementation: return findJsonSubTypes ( clazz , new HashSet < JsonSubTypes . Type > ( ) ) ;


signature:
public class JsonEncoderDecoderClassCreator { /** * Get the middle part of the method name in compliance with the naming convention in the JavaBeans API
 * specification .
 * @ param fieldName
 * @ return */
static String getMiddleNameForPrefixingAsAccessorMutatorJavaBeansSpecCompliance ( String fieldName ) { } }

implementation: if ( fieldName . length ( ) > 1 && Character . isUpperCase ( fieldName . charAt ( 1 ) ) ) { return fieldName ; } return fieldName . substring ( 0 , 1 ) . toUpperCase ( ) + fieldName . substring ( 1 ) ;


signature:
public class JsonEncoderDecoderClassCreator { /** * checks whether a getter or setter exists on the specified type or any of
 * its super classes excluding Object . respects JsonIgnore accordingly .
 * @ param type
 * @ param field
 * @ param fieldName
 * @ param isSetter
 * @ return */
private boolean exists ( JClassType type , JField field , String fieldName , boolean isSetter ) { } }

implementation:
if ( field instanceof DummyJField ) { return true ; } JType [ ] args ; if ( isSetter ) { args = new JType [ ] { field . getType ( ) } ; } else { args = new JType [ ] { } ; } JMethod m = type . findMethod ( fieldName , args ) ; if ( null != m ) { if ( isIgnored ( m ) ) { return false ; } if ( isSetter ) { return true ; } JClassType returnType = m . getReturnType ( ) . isClassOrInterface ( ) ; JClassType fieldType = field . getType ( ) . isClassOrInterface ( ) ; if ( returnType == null || fieldType == null ) { // at least one is a primitive type
return m . getReturnType ( ) . equals ( field . getType ( ) ) ; } // both are non - primitives
return returnType . isAssignableFrom ( fieldType ) ; } try { JType objectType = find ( Object . class , getLogger ( ) , context ) ; JClassType superType = type . getSuperclass ( ) ; if ( ! objectType . equals ( superType ) ) { return exists ( superType , field , fieldName , isSetter ) ; } } catch ( UnableToCompleteException e ) { // do nothing
} return false ;


signature:
public class JsonEncoderDecoderClassCreator { /** * Get { @ link JsonProperty } from getter or setter . Annotation from setter is preferred to getter .
 * @ param getter
 * @ param setter
 * @ return */
private JsonProperty getJsonPropertyFromGetterSetter ( JMethod getter , JMethod setter ) { } }

implementation: JsonProperty setterProp = getAnnotation ( setter , JsonProperty . class ) ; return ( null != setterProp ) ? setterProp : getAnnotation ( getter , JsonProperty . class ) ;


signature:
public class JsonEncoderDecoderClassCreator { /** * Inspects the supplied type and all super classes up to but excluding
 * Object and returns a list of all fields found in these classes .
 * @ param type
 * @ return */
private List < JField > getFields ( JClassType type ) { } }

implementation:
List < JField > allFields = getFields ( new ArrayList < JField > ( ) , type ) ; Map < String , JMethod > getters = new HashMap < String , JMethod > ( ) ; Map < String , JMethod > setters = new HashMap < String , JMethod > ( ) ; JType booleanType = null ; try { booleanType = find ( Boolean . class , getLogger ( ) , context ) ; } catch ( UnableToCompleteException e ) { // do nothing
} for ( JMethod m : type . getInheritableMethods ( ) ) { if ( m . getName ( ) . startsWith ( "set" ) && m . getParameterTypes ( ) . length == 1 && m . getReturnType ( ) == JPrimitiveType . VOID && ! isIgnored ( m ) ) { setters . put ( m . getName ( ) . substring ( "set" . length ( ) ) , m ) ; } else if ( m . getName ( ) . startsWith ( "get" ) && m . getParameterTypes ( ) . length == 0 && m . getReturnType ( ) != JPrimitiveType . VOID && ! isIgnored ( m ) ) { getters . put ( m . getName ( ) . substring ( "get" . length ( ) ) , m ) ; } else if ( m . getName ( ) . startsWith ( "is" ) && m . getParameterTypes ( ) . length == 0 && ( m . getReturnType ( ) == JPrimitiveType . BOOLEAN || m . getReturnType ( ) . equals ( booleanType ) ) && ! isIgnored ( m ) ) { getters . put ( m . getName ( ) . substring ( "is" . length ( ) ) , m ) ; } else if ( m . getName ( ) . startsWith ( "has" ) && m . getParameterTypes ( ) . length == 0 && ( m . getReturnType ( ) == JPrimitiveType . BOOLEAN || m . getReturnType ( ) . equals ( booleanType ) ) && ! isIgnored ( m ) ) { getters . put ( m . getName ( ) . substring ( "has" . length ( ) ) , m ) ; } } for ( Map . Entry < String , JMethod > entry : getters . entrySet ( ) ) { JMethod getter = entry . getValue ( ) ; JMethod setter = setters . get ( entry . getKey ( ) ) ; if ( null != setter && setter . getParameterTypes ( ) [ 0 ] . equals ( getter . getReturnType ( ) ) ) { String name = entry . getKey ( ) . substring ( 0 , 1 ) . toLowerCase ( ) + entry . getKey ( ) . substring ( 1 ) ; JField f = null ; for ( JField field : allFields ) { if ( field . getName ( ) . equals ( name ) ) { f = field ; break ; } } if ( f != null && isJsonIgnored ( f ) ) { continue ; } JsonProperty propName = getJsonPropertyFromGetterSetter ( getter , setter ) ; // if have a field and an annotation from the getter / setter then use that annotation
if ( f != null ) { if ( propName != null && ! f . getName ( ) . equals ( propName . value ( ) ) ) { allFields . remove ( f ) ; DummyJField dummy = new DummyJField ( name , getter . getReturnType ( ) , getter ) ; dummy . setAnnotation ( propName ) ; allFields . add ( dummy ) ; } } else { DummyJField dummy = new DummyJField ( name , getter . getReturnType ( ) , getter ) ; if ( getter . isAnnotationPresent ( JsonProperty . class ) ) { dummy . setAnnotation ( getAnnotation ( getter , JsonProperty . class ) ) ; } allFields . add ( dummy ) ; } } } // remove fields annotated with JsonIgnore
for ( Iterator < JField > iter = allFields . iterator ( ) ; iter . hasNext ( ) ; ) { JField field = iter . next ( ) ; if ( isJsonIgnored ( field ) ) { iter . remove ( ) ; } } return allFields ;


signature:
public class JsonEncoderDecoderClassCreator { /** * Returns a list of all fields ( non { @ code transient } and not annotated with { @ link XmlTransient } ) in the
 * supplied type and all super classes .
 * @ param allFields
 * @ param type
 * @ return */
private List < JField > getFields ( List < JField > allFields , JClassType type ) { } }

implementation:
JField [ ] fields = type . getFields ( ) ; for ( JField field : fields ) { if ( ! field . isTransient ( ) && ! isXmlTransient ( field ) ) { allFields . add ( field ) ; } } try { JType objectType = find ( Object . class , getLogger ( ) , context ) ; if ( ! objectType . equals ( type ) ) { JClassType superType = type . getSuperclass ( ) ; return getFields ( allFields , superType ) ; } } catch ( UnableToCompleteException e ) { // do nothing
} return allFields ;


implementation: Button button = new Button ( "Get Greeting" ) ; button . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { getGreeting ( ) ; } } ) ; RootPanel . get ( ) . add ( button ) ; RootPanel . get ( ) . add ( new Label ( "Name:" ) ) ; final TextBox nameInput = new TextBox ( ) ; RootPanel . get ( ) . add ( nameInput ) ; Button customButton = new Button ( "Get Custom Greeting" ) ; customButton . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { getCustomGreeting ( nameInput . getValue ( ) ) ; } } ) ; RootPanel . get ( ) . add ( customButton ) ;


signature:
public class GwtJacksonEncoderDecoderInstanceLocator { /** * / * ( non - Javadoc )
 * @ see org . fusesource . restygwt . rebind . EncoderDecoderLocator # encodeExpression ( com . google . gwt . core . ext . typeinfo
 * . JType , java . lang . String , org . fusesource . restygwt . client . Json . Style ) */
@ Override public String encodeExpression ( JType type , String expression , Style style ) throws UnableToCompleteException { } }

implementation: return encodeDecodeExpression ( type , expression , "encode" ) ;


signature:
public class BindingDefaults { /** * access all annotationresolvers that are registered
 * @ return a copy of all AnnotationResolvers */
public static List < AnnotationResolver > getAnnotationResolvers ( GeneratorContext context , TreeLogger logger ) { } }

implementation:
// do this only the first time call
if ( null == _annotationResolversRequested ) { // call additional AnnotationResolvers if there are some configured
try { for ( String className : context . getPropertyOracle ( ) . getConfigurationProperty ( "org.fusesource.restygwt.annotationresolver" ) . getValues ( ) ) { logger . log ( TreeLogger . INFO , "classname to resolve: " + className ) ; Class < ? > clazz ; try { clazz = Class . forName ( className ) ; } catch ( ClassNotFoundException e ) { throw new RuntimeException ( "could not resolve class " + className + " " + e . getMessage ( ) ) ; } if ( null != clazz ) { try { logger . log ( TreeLogger . INFO , "add annotationresolver: " + clazz . getName ( ) ) ; addAnnotationResolver ( ( AnnotationResolver ) clazz . newInstance ( ) ) ; } catch ( InstantiationException e ) { throw new RuntimeException ( "could not instanciate class " + className + " " + e . getMessage ( ) ) ; } catch ( IllegalAccessException e ) { throw new RuntimeException ( "could not access class " + className + " " + e . getMessage ( ) ) ; } } else { throw new RuntimeException ( "could not create instance for classname " + className ) ; } } } catch ( BadPropertyValueException ignored ) { /* * ignored since there is no
 * < set - configuration - property name = " org . fusesource . restygwt . annotationresolver "
 * value = " org . fusesource . restygwt . rebind . ModelChangeAnnotationResolver " / > */
logger . log ( TreeLogger . DEBUG , "no additional annotationresolvers found" ) ; } } // return a copy
List < AnnotationResolver > ret = new ArrayList < AnnotationResolver > ( ) ; ret . addAll ( annotationResolvers ) ; return _annotationResolversRequested = ret ;


signature:
public class Method { /** * sets the expected response status code . If the response status code does not match
 * any of the values specified then the request is considered to have failed . Defaults to accepting
 * 200,201,204 . If set to - 1 then any status code is considered a success . */
public Method expect ( int ... statuses ) { } }

implementation: if ( statuses . length == 1 && statuses [ 0 ] < 0 ) { anyStatus = true ; } else { anyStatus = false ; expectedStatuses . clear ( ) ; for ( int status : statuses ) { expectedStatuses . add ( status ) ; } } return this ;


signature:
public class Method { /** * Local file - system ( file : / / ) does not return any status codes .
 * Therefore - if we read from the file - system we accept all codes .
 * This is for instance relevant when developing a PhoneGap application with
 * restyGwt . */
public boolean isExpected ( int status ) { } }

implementation: String baseUrl = GWT . getHostPageBaseURL ( ) ; String requestUrl = builder . getUrl ( ) ; if ( FileSystemHelper . isRequestGoingToFileSystem ( baseUrl , requestUrl ) ) { return true ; } else if ( anyStatus ) { return true ; } else { return expectedStatuses . contains ( status ) ; }


signature:
public class BaseSourceCreator { /** * Lets have class name less than 200 to allow new generators safelly to add more sufixes there if needed */
private String reduceName ( String newClassName , String suffix ) { } }

implementation:
if ( newClassName . length ( ) < MAX_FILE_NAME_LENGTH ) { return newClassName ; } // String sufx = " _ Gen _ GwtJackEncDec _ " ;
// Lets first try to reduce the package name of the parametrized types
// according to parametersName2ClassName parametrized types
// Lets find if there are parametrized types
String noSufix = newClassName . substring ( 0 , newClassName . length ( ) - suffix . length ( ) ) ; if ( newClassName . indexOf ( "__" ) > 0 ) { // has generic
String primaryName = noSufix . substring ( 0 , noSufix . indexOf ( "__" ) ) ; String genericPart = noSufix . substring ( noSufix . indexOf ( "__" ) + 2 ) ; StringBuilder stringBuilder = new StringBuilder ( ) ; String [ ] eachGeneric = genericPart . split ( "__" ) ; for ( String genericType : eachGeneric ) { stringBuilder . append ( "__" ) ; stringBuilder . append ( reduceType ( genericType ) ) ; } String finalName = primaryName + stringBuilder . toString ( ) + suffix ; if ( finalName . length ( ) > MAX_FILE_NAME_LENGTH ) { // File name is still too long wrapping it out aggressively
String baseName = primaryName + stringBuilder . toString ( ) ; int firstPosition = baseName . indexOf ( "__" ) ; int lastPosition = baseName . lastIndexOf ( "__" ) ; String middle = baseName . substring ( firstPosition , lastPosition ) ; finalName = baseName . substring ( 0 , firstPosition ) + middle . subSequence ( 0 , 4 ) + "_" + ( middle . length ( ) - 5 ) + "_" + middle . substring ( middle . length ( ) - 9 ) + baseName . substring ( lastPosition ) + suffix ; return finalName ; } return finalName ; } // If there is no generic type lets give an error and force the client to reduce className
return newClassName ;


signature:
public class BaseSourceCreator { /** * Some packages are protected such that any type we generate in that package can ' t subsequently be loaded
 * because of a { @ link SecurityException } , for example < code > java . < / code > and < code > javax . < / code > packages .
 * To workaround this issue we add a prefix onto such packages so that the generated code can be loaded
 * later . The prefix added is < code > open . < / code >
 * @ param name
 * @ return */
private String getOpenPackageName ( String name ) { } }

implementation: if ( name . startsWith ( "java." ) || name . startsWith ( "javax." ) ) { name = "open." + name ; } return name ;


signature:
public class BaseSourceCreator { /** * Returns the boolean value of the property or the default value . */
protected static boolean getBooleanProperty ( TreeLogger logger , PropertyOracle propertyOracle , String propertyName , boolean defaultValue ) { } }

implementation:
try { SelectionProperty prop = propertyOracle . getSelectionProperty ( logger , propertyName ) ; String propVal = prop . getCurrentValue ( ) ; return Boolean . parseBoolean ( propVal ) ; } catch ( BadPropertyValueException e ) { // return the default value
} return defaultValue ;


signature:
public class Defaults { /** * Sets the format used when encoding and decoding Dates . If the date
 * format is set to { @ code null } , dates will be encoded and decoded as
 * timestamps ( the number of milliseconds since the Unix epoch ,
 * 1970-01-01 ) .
 * @ param dateFormat the date format string
 * @ see com . google . gwt . i18n . shared . DateTimeFormat DateTimeFormat */
public static void setDateFormat ( String dateFormat ) { } }

implementation: Defaults . dateFormat = dateFormat ; dateFormatHasTimeZone = false ; if ( dateFormat != null ) { for ( int i = 0 ; i < dateFormat . length ( ) ; i ++ ) { char ch = dateFormat . charAt ( i ) ; if ( ch == 'Z' || ch == 'z' || ch == 'V' || ch == 'v' ) { dateFormatHasTimeZone = true ; break ; } } }


signature:
public class RestServiceClassCreator { /** * Returns the rest method .
 * Iterates over the annotations and look for an annotation that is annotated with HttpMethod .
 * @ param method
 * @ return the rest method .
 * @ throws UnableToCompleteException
 * < ul >
 * < li > If more than one annotation that is annotated with HttpMethod is present , < / li >
 * < li > an invalid jax - rs method annotation is found or < / li >
 * < li > no annotation was found and the method name does not match a valid jax - rs method < / li >
 * < / ul >
 * Valid means it is in the set { @ link # REST _ METHODS } */
String getRestMethod ( JMethod method ) throws UnableToCompleteException { } }

implementation:
String restMethod = null ; Annotation [ ] annotations = method . getAnnotations ( ) ; for ( Annotation annotation : annotations ) { HttpMethod httpMethod = annotation . annotationType ( ) . getAnnotation ( HttpMethod . class ) ; // Check is HttpMethod
if ( null != httpMethod ) { if ( null != restMethod ) { // Error , see description of HttpMethod
getLogger ( ) . log ( ERROR , "Invalid method. It is an error for a method to be annotated with more than one annotation " + "that is annotated with HttpMethod: " + method . getReadableDeclaration ( ) ) ; throw new UnableToCompleteException ( ) ; } restMethod = httpMethod . value ( ) ; } } if ( null != restMethod ) { // Allow custom methods later ?
restMethod = restMethod . toLowerCase ( ) ; if ( ! REST_METHODS . contains ( restMethod ) ) { getLogger ( ) . log ( ERROR , "Invalid rest method. It must have a javax rs method annotation: " + method . getReadableDeclaration ( ) ) ; throw new UnableToCompleteException ( ) ; } } else if ( null != getAnnotation ( method , JSONP . class ) ) { restMethod = METHOD_JSONP ; } else { restMethod = method . getName ( ) ; if ( ! REST_METHODS . contains ( restMethod ) ) { getLogger ( ) . log ( ERROR , "Invalid rest method. It must either have a lower case rest method name or have a javax rs method" + " annotation: " + method . getReadableDeclaration ( ) ) ; throw new UnableToCompleteException ( ) ; } } return restMethod ;


signature:
public class RestServiceClassCreator { /** * TODO remove suppression */
@ SuppressWarnings ( { } }

implementation: "unchecked" , "rawtypes" } ) private List < AnnotationResolver > getAnnotationResolvers ( GeneratorContext context , TreeLogger logger ) { java . lang . reflect . Method m ; ArrayList args = new ArrayList ( ) ; ArrayList types = new ArrayList ( ) ; types . add ( GeneratorContext . class ) ; args . add ( context ) ; types . add ( TreeLogger . class ) ; args . add ( logger ) ; Object [ ] argValues = args . toArray ( ) ; Class [ ] argtypes = ( Class [ ] ) types . toArray ( new Class [ argValues . length ] ) ; try { m = BINDING_DEFAULTS . getMethod ( "getAnnotationResolvers" , argtypes ) ; } catch ( SecurityException e ) { throw new RuntimeException ( "could not call method `getAnnotationResolvers´ on " + BINDING_DEFAULTS , e ) ; } catch ( NoSuchMethodException e ) { throw new RuntimeException ( "could not resolve method `getAnnotationResolvers´ on " + BINDING_DEFAULTS , e ) ; } List < AnnotationResolver > l ; try { l = ( List < AnnotationResolver > ) m . invoke ( null , context , logger ) ; } catch ( IllegalArgumentException e ) { throw new RuntimeException ( "could not call method `getAnnotationResolvers´ on " + BINDING_DEFAULTS , e ) ; } catch ( IllegalAccessException e ) { throw new RuntimeException ( "could not call method `getAnnotationResolvers´ on " + BINDING_DEFAULTS , e ) ; } catch ( InvocationTargetException e ) { throw new RuntimeException ( "could not call method `getAnnotationResolvers´ on " + BINDING_DEFAULTS , e ) ; } return l ;


signature:
public class AnnotationUtils { /** * Get all annotations from superclasses and superinterfaces . < br >
 * < br >
 * Works like { @ link JClassType # findAnnotationInTypeHierarchy ( Class ) } but returns all annotations in the type
 * hierarchy .
 * @ author Ralf Sommer { @ literal < ralf . sommer . dev @ gmail . com > }
 * @ param classType
 * @ return annotations */
public static Annotation [ ] getAnnotationsInTypeHierarchy ( JClassType classType ) { } }

implementation:
Set < Annotation > resultAnnotations = new HashSet < Annotation > ( ) ; // Cache to avoid loops
Set < JClassType > alreadyCheckedTypes = new HashSet < JClassType > ( ) ; // Work queue
Queue < JClassType > typeQueue = new LinkedList < JClassType > ( ) ; for ( JClassType current = classType ; current != null ; current = typeQueue . poll ( ) ) { if ( ! alreadyCheckedTypes . add ( current ) ) { continue ; } // Get the annotations only from current , no inherited
Annotation [ ] annotations = current . getDeclaredAnnotations ( ) ; Collections . addAll ( resultAnnotations , annotations ) ; if ( current . getSuperclass ( ) != null ) { // Add the superclass to the queue
typeQueue . add ( current . getSuperclass ( ) ) ; } // Add the Superinterfaces to the queue
Collections . addAll ( typeQueue , current . getImplementedInterfaces ( ) ) ; } return resultAnnotations . toArray ( new Annotation [ resultAnnotations . size ( ) ] ) ;


signature:
public class RetryingCallbackFactory { /** * helper method to create the callback with all configurations wanted
 * @ param method
 * @ return */
@ Override public FilterawareRequestCallback createCallback ( Method method ) { } }

implementation: FilterawareRequestCallback retryingCallback = new RetryingFilterawareRequestCallback ( method , gracePeriodMillis , numberOfRetries ) ; for ( CallbackFilter filter : callbackFilters ) { retryingCallback . addFilter ( filter ) ; } return retryingCallback ;


signature:
public class CachingCallbackFilter { /** * the real filter method , called independent of the response code
 * TODO method . getResponse ( ) is not equal to response . unfortunately */
@ Override public RequestCallback filter ( Method method , Response response , RequestCallback callback ) { } }

implementation:
int code = response . getStatusCode ( ) ; final CacheKey ck = cacheKey ( method . builder ) ; final List < RequestCallback > removedCallbacks = cache . removeCallbacks ( ck ) ; if ( removedCallbacks != null ) { callback = new RequestCallback ( ) { @ Override public void onResponseReceived ( Request request , Response response ) { if ( GWT . isClient ( ) && LogConfiguration . loggingIsEnabled ( ) ) { Logger . getLogger ( CachingCallbackFilter . class . getName ( ) ) . finer ( "call " + removedCallbacks . size ( ) + " more queued callbacks for " + ck ) ; } // call all callbacks found in cache
for ( RequestCallback cb : removedCallbacks ) { cb . onResponseReceived ( request , response ) ; } } @ Override public void onError ( Request request , Throwable exception ) { if ( LogConfiguration . loggingIsEnabled ( ) ) { Logger . getLogger ( CachingCallbackFilter . class . getName ( ) ) . severe ( "cannot call " + ( removedCallbacks . size ( ) + 1 ) + " callbacks for " + ck + " due to error: " + exception . getMessage ( ) ) ; } if ( LogConfiguration . loggingIsEnabled ( ) ) { Logger . getLogger ( CachingCallbackFilter . class . getName ( ) ) . finer ( "call " + removedCallbacks . size ( ) + " more queued callbacks for " + ck ) ; } // and all the others , found in cache
for ( RequestCallback cb : removedCallbacks ) { cb . onError ( request , exception ) ; } } } ; } else { if ( GWT . isClient ( ) && LogConfiguration . loggingIsEnabled ( ) ) { Logger . getLogger ( CachingCallbackFilter . class . getName ( ) ) . finer ( "removed one or no " + "callback for cachekey " + ck ) ; } } if ( isCachingStatusCode ( code ) ) { cacheResult ( method , response ) ; return callback ; } if ( GWT . isClient ( ) && LogConfiguration . loggingIsEnabled ( ) ) { Logger . getLogger ( CachingCallbackFilter . class . getName ( ) ) . info ( "cannot cache due to invalid response code: " + code ) ; } return callback ;


signature:
public class CachingCallbackFilter { /** * when using the { @ link Domain } annotation on services , we are able to group responses
 * of a service to invalidate them later on more fine grained . this method resolves a
 * possible ` ` domain ` ` to allow grouping .
 * @ return array of names of cache domains */
protected String [ ] getCacheDomains ( Method method ) { } }

implementation: if ( null == method . getData ( ) . get ( Domain . CACHE_DOMAIN_KEY ) ) { return null ; } JSONValue jsonValue = JSONParser . parseStrict ( method . getData ( ) . get ( Domain . CACHE_DOMAIN_KEY ) ) ; if ( null == jsonValue ) { return null ; } JSONArray jsonArray = jsonValue . isArray ( ) ; if ( null != jsonArray ) { String [ ] dd = new String [ jsonArray . size ( ) ] ; for ( int i = 0 ; i < jsonArray . size ( ) ; ++ i ) { dd [ i ] = jsonArray . get ( i ) . isString ( ) . stringValue ( ) ; } return dd ; } return null ;


signature:
public class ModelChangeAnnotationResolver { /** * convert an array of classes to an array of strings to be usable in js context .
 * @ param classes
 * @ return */
@ SuppressWarnings ( "rawtypes" ) private String [ ] getAnnotationsAsStringArray ( Class [ ] classes ) { } }

implementation: if ( null == classes ) { return null ; } List < String > ret = new ArrayList < String > ( ) ; for ( Class c : classes ) { ret . add ( c . getName ( ) ) ; } return ret . toArray ( new String [ ret . size ( ) ] ) ;


signature:
public class AnnotationCopyUtil { /** * Returns the string representation of { @ code value } or { @ code null } , if the element should not be added .
 * @ param value
 * @ return */
private static String encodeAnnotationValue ( Object value ) { } }

implementation:
// Values of annotation elements must not be " null "
if ( null != value ) { if ( value instanceof String ) { return readStringValue ( value ) ; } else if ( value instanceof Number ) { return readNumberValue ( value ) ; } else if ( value . getClass ( ) . isArray ( ) ) { // workaround for ClassCastException : [ Ljava . lang . Object ; cannot be cast to [ I
// ignore empty arrays , because it becomes Object [ ]
if ( Array . getLength ( value ) > 0 ) { return readArrayValue ( value ) ; } return null ; } else if ( value instanceof Annotation ) { return getAnnotationAsString ( ( Annotation ) value ) ; } else if ( value instanceof Boolean ) { return readBooleanValue ( ( Boolean ) value ) ; } else if ( value instanceof Class ) { return readClassValue ( ( Class ) value ) ; } } throw new IllegalArgumentException ( "Unsupported value for encodeAnnotationValue: " + value ) ;


signature:
public class JsonpMethod { /** * helper method to make RestServiceClassCreator easier to maintain
 * @ param callback */
public Object send ( AsyncCallback < JavaScriptObject > callback ) { } }

implementation: return jsonpBuilder . requestObject ( resource . getUri ( ) , callback ) ;


signature:
public class TokenRequestHandler { /** * Handle a token request .
 * This method is an alias of the { @ link # handle ( MultivaluedMap , String ,
 * String [ ] ) handle ( ) } method which accepts 3 arguments .
 * @ param parameters
 * Request parameters of a token request .
 * @ param authorization
 * The value of { @ code Authorization } header in the token request .
 * A client application may embed its pair of client ID and client
 * secret in a token request using < a href =
 * " https : / / tools . ietf . org / html / rfc2617 # section - 2 " > Basic
 * Authentication < / a > .
 * @ return
 * A response that should be returned from the endpoint to the
 * client application .
 * @ throws WebApplicationException
 * An error occurred . */
public Response handle ( MultivaluedMap < String , String > parameters , String authorization ) throws WebApplicationException { } }

implementation: return handle ( parameters , authorization , null ) ;


signature:
public class TokenRequestHandler { /** * Process the parameters of the token request . */
private Response process ( MultivaluedMap < String , String > parameters , String clientId , String clientSecret , String [ ] clientCertificatePath ) { } }

implementation:
// Extra properties to associate with an access token .
Property [ ] properties = mSpi . getProperties ( ) ; String clientCertificate = null ; if ( clientCertificatePath != null && clientCertificatePath . length > 0 ) { // The first one is the client ' s certificate .
clientCertificate = clientCertificatePath [ 0 ] ; // if we have more in the path , pass them along separately without the first one
if ( clientCertificatePath . length > 1 ) { clientCertificatePath = Arrays . copyOfRange ( clientCertificatePath , 1 , clientCertificatePath . length ) ; } } // Call Authlete ' s / api / auth / token API .
TokenResponse response = getApiCaller ( ) . callToken ( parameters , clientId , clientSecret , properties , clientCertificate , clientCertificatePath ) ; // ' action ' in the response denotes the next action which
// this service implementation should take .
Action action = response . getAction ( ) ; // The content of the response to the client application .
String content = response . getResponseContent ( ) ; // Dispatch according to the action .
switch ( action ) { case INVALID_CLIENT : // 401 Unauthorized
return ResponseUtil . unauthorized ( content , CHALLENGE ) ; case INTERNAL_SERVER_ERROR : // 500 Internal Server Error
return ResponseUtil . internalServerError ( content ) ; case BAD_REQUEST : // 400 Bad Request
return ResponseUtil . badRequest ( content ) ; case PASSWORD : // Process the token request whose flow is " Resource Owner Password Credentials " .
return handlePassword ( response ) ; case OK : // 200 OK
return ResponseUtil . ok ( content ) ; default : // This never happens .
throw getApiCaller ( ) . unknownAction ( "/api/auth/token" , action ) ; }


signature:
public class TokenRequestHandler { /** * Process the token request whose flow is " Resource Owner Password Credentials " . */
private Response handlePassword ( TokenResponse response ) { } }

implementation:
// The credentials of the resource owner .
String username = response . getUsername ( ) ; String password = response . getPassword ( ) ; // Validate the credentials .
String subject = mSpi . authenticateUser ( username , password ) ; // Extra properties to associate with an access token .
Property [ ] properties = mSpi . getProperties ( ) ; // The ticket for Authlete ' s / api / auth / token / * API .
String ticket = response . getTicket ( ) ; if ( subject != null ) { // Issue an access token and optionally an ID token .
return getApiCaller ( ) . tokenIssue ( ticket , subject , properties ) ; } else { // The credentials are invalid . An access token is not issued .
throw getApiCaller ( ) . tokenFail ( ticket , Reason . INVALID_RESOURCE_OWNER_CREDENTIALS ) ; }


signature:
public class BackchannelAuthenticationRequestHandler { /** * Handle a backchannel authentication request to a backchannel authentication
 * endpoint of CIBA ( Client Initiated Backchannel Authentication ) .
 * @ param parameters
 * Request parameters of a backchannel authentication request .
 * @ param authorization
 * The value of { @ code Authorization } header in the backchannel authentication
 * request . A client application may embed its pair of client ID and
 * client secret in a backchannel authentication request using < a href =
 * " https : / / tools . ietf . org / html / rfc2617 # section - 2 " > Basic
 * Authentication < / a > .
 * @ param clientCertificatePath
 * The path of the client ' s certificate , each in PEM format . The first
 * item in the array is the client ' s certificate itself . May be { @ code null }
 * if the client did not send a certificate or path .
 * @ return
 * A response that should be returned from the endpoint to the
 * client application .
 * @ throws WebApplicationException
 * An error occurred . */
public Response handle ( MultivaluedMap < String , String > parameters , String authorization , String [ ] clientCertificatePath ) throws WebApplicationException { } }

implementation:
// Convert the value of Authorization header ( credentials of
// the client application ) , if any , into BasicCredentials .
BasicCredentials credentials = BasicCredentials . parse ( authorization ) ; // The credentials of the client application extracted from
// ' Authorization ' header . These may be null .
String clientId = credentials == null ? null : credentials . getUserId ( ) ; String clientSecret = credentials == null ? null : credentials . getPassword ( ) ; try { // Process the given parameters .
return process ( parameters , clientId , clientSecret , clientCertificatePath ) ; } catch ( WebApplicationException e ) { throw e ; } catch ( Throwable t ) { // Unexpected error .
throw unexpected ( "Unexpected error in BackchannelAuthenticationRequest" , t ) ; }


signature:
public class AuthorizationDecisionHandler { /** * Handle an end - user ' s decision on an authorization request .
 * @ param ticket
 * A ticket that was issued by Authlete ' s { @ code / api / auth / authorization } API .
 * @ param claimNames
 * Names of requested claims . Use the value of the { @ code claims }
 * parameter in a response from Authlete ' s { @ code / api / auth / authorization } API .
 * @ param claimLocales
 * Requested claim locales . Use the value of the { @ code claimsLocales }
 * parameter in a response from Authlete ' s { @ code / api / auth / authorization } API .
 * @ return
 * A response to the client application . Basically , the response
 * will trigger redirection to the client ' s redirection endpoint .
 * @ throws WebApplicationException
 * An error occurred . */
public Response handle ( String ticket , String [ ] claimNames , String [ ] claimLocales ) throws WebApplicationException { } }

implementation:
try { // Process the end - user ' s decision .
return process ( ticket , claimNames , claimLocales ) ; } catch ( WebApplicationException e ) { throw e ; } catch ( Throwable t ) { // Unexpected error .
throw unexpected ( "Unexpected error in AuthorizationDecisionHandler" , t ) ; }