signature:
public class LdContextFactory { /** * Gets explicitly defined terms , e . g . on package , class or mixin .
 * @ param annotatedElement
 * to find terms
 * @ param name
 * of annotated element , i . e . class name or package name
 * @ return terms */
private Map < String , Object > getAnnotatedTerms ( AnnotatedElement annotatedElement , String name ) { } }

implementation:
final Terms annotatedTerms = findAnnotation ( annotatedElement , Terms . class ) ; final Term annotatedTerm = findAnnotation ( annotatedElement , Term . class ) ; if ( annotatedTerms != null && annotatedTerm != null ) { throw new IllegalStateException ( "found both @Terms and @Term in " + name + ", use either one or the other" ) ; } Map < String , Object > annotatedTermsMap = new LinkedHashMap < String , Object > ( ) ; if ( annotatedTerms != null ) { final Term [ ] terms = annotatedTerms . value ( ) ; for ( Term term : terms ) { collectTerms ( name , annotatedTermsMap , term ) ; } } else if ( annotatedTerm != null ) { // only one term
collectTerms ( name , annotatedTermsMap , annotatedTerm ) ; } return annotatedTermsMap ;


signature: public class EventController { @ RequestMapping ( method = RequestMethod . GET ) @ ResponseBody public ResponseEntity < Resources < Event > > findEvents ( @ RequestParam ( required = false ) String name ) { } }

implementation: List < Event > events = assembler . toResources ( eventBackend . getEvents ( ) ) ; List < Event > matches = new ArrayList < Event > ( ) ; for ( Event event : events ) { if ( name == null || event . workPerformed . getContent ( ) . name . equals ( name ) ) { addAffordances ( event ) ; matches . add ( event ) ; } } Resources < Event > eventResources = new Resources < Event > ( matches ) ; eventResources . add ( AffordanceBuilder . linkTo ( AffordanceBuilder . methodOn ( EventController . class ) . addEvent ( new Event ( null , new CreativeWork ( null ) , null , EventStatusType . EVENT_SCHEDULED ) ) ) . withSelfRel ( ) ) ; eventResources . add ( AffordanceBuilder . linkTo ( AffordanceBuilder . methodOn ( EventController . class ) . findEvents ( null ) ) . withRel ( "hydra:search" ) ) ; return new ResponseEntity < Resources < Event > > ( eventResources , HttpStatus . OK ) ;


signature:
public class PartialUriTemplateComponents { /** * Query consisting of expanded parameters and unexpanded parameters .
 * @ return query , may be empty */
public String getQuery ( ) { } }

implementation: StringBuilder query = new StringBuilder ( ) ; if ( queryTail . length ( ) > 0 ) { if ( queryHead . length ( ) == 0 ) { query . append ( "{?" ) . append ( queryTail ) . append ( "}" ) ; } else if ( queryHead . length ( ) > 0 ) { query . append ( queryHead ) . append ( "{&" ) . append ( queryTail ) . append ( "}" ) ; } } else { query . append ( queryHead ) ; } return query . toString ( ) ;


signature:
public class XhtmlWriter { /** * Appends form and squashes non - GET or POST to POST . If required , adds _ method field for handling by an
 * appropriate
 * filter such as Spring ' s HiddenHttpMethodFilter .
 * @ param affordance
 * to make into a form
 * @ param actionDescriptor
 * describing the form action
 * @ throws IOException
 * @ see
 * < a href = " http : / / docs . spring . io / spring / docs / 3.0 . x / javadoc - api / org / springframework / web / filter / HiddenHttpMethodFilter . html " > Spring
 * MVC HiddenHttpMethodFilter < / a > */
private void appendForm ( Affordance affordance , ActionDescriptor actionDescriptor ) throws IOException { } }

implementation:
String formName = actionDescriptor . getActionName ( ) ; RequestMethod httpMethod = RequestMethod . valueOf ( actionDescriptor . getHttpMethod ( ) ) ; // Link ' s expand method removes non - required variables from URL
String actionUrl = affordance . expand ( ) . getHref ( ) ; beginForm ( OptionalAttributes . attr ( "action" , actionUrl ) . and ( "method" , getHtmlConformingHttpMethod ( httpMethod ) ) . and ( "name" , formName ) ) ; write ( "<h4>" ) ; write ( "Form " + formName ) ; write ( "</h4>" ) ; writeHiddenHttpMethodField ( httpMethod ) ; // build the form
if ( actionDescriptor . hasRequestBody ( ) ) { // parameter bean
ActionInputParameter requestBody = actionDescriptor . getRequestBody ( ) ; Class < ? > parameterType = requestBody . getParameterType ( ) ; recurseBeanProperties ( parameterType , actionDescriptor , requestBody , requestBody . getValue ( ) , "" ) ; } else { // plain parameter list
Collection < String > requestParams = actionDescriptor . getRequestParamNames ( ) ; for ( String requestParamName : requestParams ) { ActionInputParameter actionInputParameter = actionDescriptor . getActionInputParameter ( requestParamName ) ; Object [ ] possibleValues = actionInputParameter . getPossibleValues ( actionDescriptor ) ; // TODO duplication with appendInputOrSelect
if ( possibleValues . length > 0 ) { if ( actionInputParameter . isArrayOrCollection ( ) ) { appendSelectMulti ( requestParamName , possibleValues , actionInputParameter ) ; } else { appendSelectOne ( requestParamName , possibleValues , actionInputParameter ) ; } } else { if ( actionInputParameter . isArrayOrCollection ( ) ) { // have as many inputs as there are call values , list of 5 nulls gives you five input fields
// TODO support for free list input instead , code on demand ?
Object [ ] callValues = actionInputParameter . getValues ( ) ; int items = callValues . length ; for ( int i = 0 ; i < items ; i ++ ) { Object value ; if ( i < callValues . length ) { value = callValues [ i ] ; } else { value = null ; } appendInput ( requestParamName , actionInputParameter , value , actionInputParameter . isReadOnly ( requestParamName ) ) ; // not readonly
} } else { String callValueFormatted = actionInputParameter . getValueFormatted ( ) ; appendInput ( requestParamName , actionInputParameter , callValueFormatted , actionInputParameter . isReadOnly ( requestParamName ) ) ; // not readonly
} } } } inputButton ( Type . SUBMIT , capitalize ( httpMethod . name ( ) . toLowerCase ( ) ) ) ; endForm ( ) ;


signature:
public class XhtmlWriter { /** * Classic submit or reset button .
 * @ param type
 * submit or reset
 * @ param value
 * caption on the button
 * @ throws IOException */
private void inputButton ( Type type , String value ) throws IOException { } }

implementation: write ( "<input type=\"" ) ; write ( type . toString ( ) ) ; write ( "\" " ) ; write ( "value" ) ; write ( "=" ) ; quote ( ) ; write ( value ) ; quote ( ) ; write ( "/>" ) ;


signature:
public class XhtmlWriter { /** * Renders input fields for bean properties of bean to add or update or patch .
 * @ param beanType
 * to render
 * @ param actionDescriptor
 * which describes the method
 * @ param actionInputParameter
 * which requires the bean
 * @ param currentCallValue
 * sample call value
 * @ throws IOException */
private void recurseBeanProperties ( Class < ? > beanType , ActionDescriptor actionDescriptor , ActionInputParameter actionInputParameter , Object currentCallValue , String parentParamName ) throws IOException { } }

implementation:
// TODO support Option provider by other method args ?
final BeanInfo beanInfo = getBeanInfo ( beanType ) ; final PropertyDescriptor [ ] propertyDescriptors = beanInfo . getPropertyDescriptors ( ) ; // TODO collection and map
// TODO : do not add two inputs for setter and ctor
// TODO almost duplicate of HtmlResourceMessageConverter . recursivelyCreateObject
if ( RequestMethod . POST == RequestMethod . valueOf ( actionDescriptor . getHttpMethod ( ) ) ) { try { Constructor [ ] constructors = beanType . getConstructors ( ) ; // find default ctor
Constructor constructor = PropertyUtils . findDefaultCtor ( constructors ) ; // find ctor with JsonCreator ann
if ( constructor == null ) { constructor = PropertyUtils . findJsonCreator ( constructors , JsonCreator . class ) ; } Assert . notNull ( constructor , "no default constructor or JsonCreator found for type " + beanType . getName ( ) ) ; int parameterCount = constructor . getParameterTypes ( ) . length ; if ( parameterCount > 0 ) { Annotation [ ] [ ] annotationsOnParameters = constructor . getParameterAnnotations ( ) ; Class [ ] parameters = constructor . getParameterTypes ( ) ; int paramIndex = 0 ; for ( Annotation [ ] annotationsOnParameter : annotationsOnParameters ) { for ( Annotation annotation : annotationsOnParameter ) { if ( JsonProperty . class == annotation . annotationType ( ) ) { JsonProperty jsonProperty = ( JsonProperty ) annotation ; // TODO use required attribute of JsonProperty
String paramName = jsonProperty . value ( ) ; Class parameterType = parameters [ paramIndex ] ; // TODO duplicate below for PropertyDescriptors and in appendForm
if ( DataType . isSingleValueType ( parameterType ) ) { if ( actionInputParameter . isIncluded ( paramName ) ) { Object propertyValue = PropertyUtils . getPropertyOrFieldValue ( currentCallValue , paramName ) ; ActionInputParameter constructorParamInputParameter = new SpringActionInputParameter ( new MethodParameter ( constructor , paramIndex ) , propertyValue ) ; final Object [ ] possibleValues = actionInputParameter . getPossibleValues ( constructor , paramIndex , actionDescriptor ) ; appendInputOrSelect ( actionInputParameter , parentParamName + paramName , constructorParamInputParameter , possibleValues ) ; } } else if ( DataType . isArrayOrCollection ( parameterType ) ) { Object [ ] callValues = actionInputParameter . getValues ( ) ; int items = callValues . length ; for ( int i = 0 ; i < items ; i ++ ) { Object value ; if ( i < callValues . length ) { value = callValues [ i ] ; } else { value = null ; } recurseBeanProperties ( actionInputParameter . getParameterType ( ) , actionDescriptor , actionInputParameter , value , parentParamName ) ; } } else { beginDiv ( ) ; write ( paramName + ":" ) ; Object propertyValue = PropertyUtils . getPropertyOrFieldValue ( currentCallValue , paramName ) ; recurseBeanProperties ( parameterType , actionDescriptor , actionInputParameter , propertyValue , paramName + "." ) ; endDiv ( ) ; } paramIndex ++ ; // increase for each @ JsonProperty
} } } Assert . isTrue ( parameters . length == paramIndex , "not all constructor arguments of @JsonCreator " + constructor . getName ( ) + " are annotated with @JsonProperty" ) ; } } catch ( Exception e ) { throw new RuntimeException ( "Failed to write input fields for constructor" , e ) ; } } else { // non - POST
// TODO non - writable properties and public fields : make sure the inputs are part of a form
// write input field for every setter
for ( PropertyDescriptor propertyDescriptor : propertyDescriptors ) { final Method writeMethod = propertyDescriptor . getWriteMethod ( ) ; if ( writeMethod == null ) { continue ; } final Class < ? > propertyType = propertyDescriptor . getPropertyType ( ) ; String propertyName = propertyDescriptor . getName ( ) ; if ( DataType . isSingleValueType ( propertyType ) ) { final Property property = new Property ( beanType , propertyDescriptor . getReadMethod ( ) , propertyDescriptor . getWriteMethod ( ) , propertyDescriptor . getName ( ) ) ; Object propertyValue = PropertyUtils . getPropertyOrFieldValue ( currentCallValue , propertyName ) ; MethodParameter methodParameter = new MethodParameter ( propertyDescriptor . getWriteMethod ( ) , 0 ) ; ActionInputParameter propertySetterInputParameter = new SpringActionInputParameter ( methodParameter , propertyValue ) ; final Object [ ] possibleValues = actionInputParameter . getPossibleValues ( propertyDescriptor . getWriteMethod ( ) , 0 , actionDescriptor ) ; appendInputOrSelect ( actionInputParameter , propertyName , propertySetterInputParameter , possibleValues ) ; } else if ( actionInputParameter . isArrayOrCollection ( ) ) { Object [ ] callValues = actionInputParameter . getValues ( ) ; int items = callValues . length ; for ( int i = 0 ; i < items ; i ++ ) { Object value ; if ( i < callValues . length ) { value = callValues [ i ] ; } else { value = null ; } recurseBeanProperties ( actionInputParameter . getParameterType ( ) , actionDescriptor , actionInputParameter , value , parentParamName ) ; } } else { beginDiv ( ) ; write ( propertyName + ":" ) ; Object propertyValue = PropertyUtils . getPropertyValue ( currentCallValue , propertyDescriptor ) ; recurseBeanProperties ( propertyType , actionDescriptor , actionInputParameter , propertyValue , parentParamName ) ; endDiv ( ) ; } } }


signature:
public class XhtmlWriter { /** * Appends simple input or select , depending on availability of possible values .
 * @ param parentInputParameter
 * the parent during bean recursion
 * @ param paramName
 * of the child input parameter
 * @ param childInputParameter
 * the current input to be rendered
 * @ param possibleValues
 * suitable for childInputParameter
 * @ throws IOException */
private void appendInputOrSelect ( ActionInputParameter parentInputParameter , String paramName , ActionInputParameter childInputParameter , Object [ ] possibleValues ) throws IOException { } }

implementation:
if ( possibleValues . length > 0 ) { if ( childInputParameter . isArrayOrCollection ( ) ) { // TODO multiple formatted callvalues
appendSelectMulti ( paramName , possibleValues , childInputParameter ) ; } else { appendSelectOne ( paramName , possibleValues , childInputParameter ) ; } } else { appendInput ( paramName , childInputParameter , childInputParameter . getValue ( ) , parentInputParameter . isReadOnly ( paramName ) ) ; }


signature:
public class AffordanceBuilder { /** * Creates a new { @ link AffordanceBuilder } with a base of the mapping annotated to the given controller class . The
 * additional parameters are used to fill up potentially available path variables in the class scope request
 * mapping .
 * @ param controller
 * the class to discover the annotation on , must not be { @ literal null } .
 * @ param parameters
 * additional parameters to bind to the URI template declared in the annotation , must not be { @ literal
 * null } .
 * @ return builder */
public static AffordanceBuilder linkTo ( Class < ? > controller , Object ... parameters ) { } }

implementation: return FACTORY . linkTo ( controller , parameters ) ;


signature:
public class AffordanceBuilder { /** * Creates a new { @ link AffordanceBuilder } with a base of the mapping annotated to the given controller class . The
 * additional parameters are used to fill up potentially available path variables in the class scop request
 * mapping .
 * @ param controller
 * the class to discover the annotation on , must not be { @ literal null } .
 * @ param parameters
 * additional parameters to bind to the URI template declared in the annotation , must not be { @ literal
 * null } .
 * @ return */
public static AffordanceBuilder linkTo ( Class < ? > controller , Map < String , ? > parameters ) { } }


signature:
public class AffordanceBuilder { /** * Builds affordance with one or multiple rels which must have been defined previously using { @ link # rel ( String ) } or
 * { @ link # reverseRel ( String , String ) } . < p > The motivation for multiple rels is this statement in the web linking
 * rfc - 5988 : & quot ; Note that link - values can convey multiple links between the same target and context IRIs ; for
 * example : < / p >
 * < pre >
 * Link : & lt ; http : / / example . org / & gt ;
 * rel = " start http : / / example . net / relation / other "
 * < / pre >
 * Here , the link to ' http : / / example . org / ' has the registered relation type ' start ' and the extension relation type
 * ' http : / / example . net / relation / other ' . & quot ;
 * @ return affordance
 * @ see < a href = " https : / / tools . ietf . org / html / rfc5988 # section - 5.5 " > Web Linking Examples < / a > */
public Affordance build ( ) { } }

implementation: Assert . state ( ! ( rels . isEmpty ( ) && reverseRels . isEmpty ( ) ) , "no rels or reverse rels found, call rel() or rev() before building the affordance" ) ; final Affordance affordance ; affordance = new Affordance ( new PartialUriTemplate ( this . toString ( ) ) , actionDescriptors , rels . toArray ( new String [ rels . size ( ) ] ) ) ; for ( Map . Entry < String , List < String > > linkParamEntry : linkParams . entrySet ( ) ) { final List < String > values = linkParamEntry . getValue ( ) ; for ( String value : values ) { affordance . addLinkParam ( linkParamEntry . getKey ( ) , value ) ; } } for ( String reverseRel : reverseRels ) { affordance . addRev ( reverseRel ) ; } affordance . setCollectionHolder ( collectionHolder ) ; return affordance ;


signature:
public class AffordanceBuilder { /** * Allows to define one or more reverse link relations ( a " rev " in terms of rfc - 5988 ) , where the resource that has
 * the affordance will be considered the object in a subject - predicate - object statement . < p > E . g . if you had a rel
 * < code > ex : parent < / code > which connects a child to its father , you could also use ex : parent on the father to point
 * to the child by reverting the direction of ex : parent . This is mainly useful when you have no other way to
 * express
 * in your context that the direction of a relationship is inverted . < / p >
 * @ param rev
 * to be used as reverse relationship
 * @ param revertedRel
 * to be used in contexts which have no notion of reverse relationships . E . g . for a reverse rel
 * < code > ex : parent < / code > you can use a made - up rel name < code > ex : child < / code > which will be used as rel
 * when rendering HAL .
 * @ return builder */
public AffordanceBuilder reverseRel ( String rev , String revertedRel ) { } }

implementation: this . rels . add ( revertedRel ) ; this . reverseRels . add ( rev ) ; return this ;


signature:
public class AffordanceBuilder { /** * Allows to define one or more reverse link relations ( a " rev " in terms of rfc - 5988 ) to collections in cases where
 * the resource that has the affordance is not the object in a subject - predicate - object statement about each
 * collection item . See { @ link # rel ( TypedResource , String ) } for explanation .
 * @ param rev
 * to be used as reverse relationship
 * @ param revertedRel
 * to be used in contexts which have no notion of reverse relationships , e . g . HAL
 * @ param object
 * describing the object
 * @ return builder */
public AffordanceBuilder reverseRel ( String rev , String revertedRel , TypedResource object ) { } }

implementation: this . collectionHolder = object ; this . rels . add ( 0 , revertedRel ) ; this . reverseRels . add ( rev ) ; return this ;


signature:
public class AffordanceBuilder { /** * Allows to define one or more link relations for affordances that point to collections in cases where the
 * resource
 * that has the affordance is not the subject in a subject - predicate - object statement about each collection item .
 * E . g . a product might have a loose relationship to ordered items where it can be POSTed , but the ordered items do
 * not belong to the product , but to an order . You can express that by saying :
 * < pre >
 * TypedResource order = new TypedResource ( " http : / / schema . org / Order " ) ; / / holds the ordered items
 * Resource & lt ; Product & gt ; product = new Resource & lt ; & gt ; ( ) ; / / has a loose relationship to ordered items
 * product . add ( linkTo ( methodOn ( OrderController . class ) . postOrderedItem ( )
 * . rel ( order , " orderedItem " ) ) ; / / order has ordered items , not product has ordered items
 * < / pre >
 * If the order doesn ' t exist yet , it cannot be identified . In that case you may pass null to express that
 * @ param rel
 * to be used as link relation
 * @ param subject
 * describing the subject
 * @ return builder */
public AffordanceBuilder rel ( TypedResource subject , String rel ) { } }

implementation: this . collectionHolder = subject ; this . rels . add ( rel ) ; return this ;


signature:
public class AffordanceBuilder { /** * Allows to define link header params ( not UriTemplate variables ) .
 * @ param name
 * of the link header param
 * @ param value
 * of the link header param
 * @ return builder */
public AffordanceBuilder withLinkParam ( String name , String value ) { } }

implementation: this . linkParams . add ( name , value ) ; return this ;


signature:
public class AffordanceBuilder { /** * Returns a { @ link UriComponentsBuilder } obtained from the current servlet mapping with scheme tweaked in case the
 * request contains an { @ code X - Forwarded - Ssl } header , which is not ( yet ) supported by the underlying
 * { @ link UriComponentsBuilder } . If no { @ link RequestContextHolder } exists ( you ' re outside a Spring Web call ) , fall
 * back to relative URIs .
 * @ return */
static UriComponentsBuilder getBuilder ( ) { } }

implementation:
if ( RequestContextHolder . getRequestAttributes ( ) == null ) { return UriComponentsBuilder . fromPath ( "/" ) ; } HttpServletRequest request = getCurrentRequest ( ) ; UriComponentsBuilder builder = ServletUriComponentsBuilder . fromServletMapping ( request ) ; // special case handling for X - Forwarded - Ssl :
// apply it , but only if X - Forwarded - Proto is unset .
String forwardedSsl = request . getHeader ( "X-Forwarded-Ssl" ) ; ForwardedHeader forwarded = ForwardedHeader . of ( request . getHeader ( ForwardedHeader . NAME ) ) ; String proto = hasText ( forwarded . getProto ( ) ) ? forwarded . getProto ( ) : request . getHeader ( "X-Forwarded-Proto" ) ; if ( ! hasText ( proto ) && hasText ( forwardedSsl ) && forwardedSsl . equalsIgnoreCase ( "on" ) ) { builder . scheme ( "https" ) ; } return builder ;


signature:
public class AffordanceBuilder { /** * Copy of { @ link ServletUriComponentsBuilder # getCurrentRequest ( ) } until SPR - 10110 gets fixed .
 * @ return request */
private static HttpServletRequest getCurrentRequest ( ) { } }

implementation: RequestAttributes requestAttributes = RequestContextHolder . getRequestAttributes ( ) ; Assert . state ( requestAttributes != null , "Could not find current request via RequestContextHolder" ) ; Assert . isInstanceOf ( ServletRequestAttributes . class , requestAttributes ) ; HttpServletRequest servletRequest = ( ( ServletRequestAttributes ) requestAttributes ) . getRequest ( ) ; Assert . state ( servletRequest != null , "Could not find current HttpServletRequest" ) ; return servletRequest ;


signature:
public class AffordanceBuilder { /** * Adds actionDescriptors of the given AffordanceBuilder to this affordanceBuilder .
 * @ param affordanceBuilder
 * whose action descriptors should be added to this one
 * @ return builder */
public AffordanceBuilder and ( AffordanceBuilder affordanceBuilder ) { } }

implementation: for ( ActionDescriptor actionDescriptor : affordanceBuilder . actionDescriptors ) { this . actionDescriptors . add ( actionDescriptor ) ; } return this ;


signature:
public class PartialUriTemplate { /** * Returns the template as uri components , without variable expansion .
 * @ return components of the Uri */
public PartialUriTemplateComponents asComponents ( ) { } }

implementation: return getUriTemplateComponents ( Collections . < String , Object > emptyMap ( ) , Collections . < String > emptyList ( ) ) ;


signature:
public class PartialUriTemplate { /** * Expands the template using given parameters
 * @ param parameters
 * for expansion in the order of appearance in the template , must not be empty
 * @ return expanded template */
public PartialUriTemplateComponents expand ( Object ... parameters ) { } }

implementation: List < String > variableNames = getVariableNames ( ) ; Map < String , Object > parameterMap = new LinkedHashMap < String , Object > ( ) ; int i = 0 ; for ( String variableName : variableNames ) { if ( i < parameters . length ) { parameterMap . put ( variableName , parameters [ i ++ ] ) ; } else { break ; } } return getUriTemplateComponents ( parameterMap , Collections . < String > emptyList ( ) ) ;


signature:
public class PartialUriTemplate { /** * Expands the template using given parameters
 * @ param parameters
 * for expansion , must not be empty
 * @ return expanded template */
public PartialUriTemplateComponents expand ( Map < String , ? > parameters ) { } }

implementation: return getUriTemplateComponents ( parameters , Collections . < String > emptyList ( ) ) ;


signature:
public class PartialUriTemplate { /** * Applies parameters to template variables .
 * @ param parameters
 * to apply to variables
 * @ param requiredArgs
 * if not empty , retains given requiredArgs
 * @ return uri components */
private PartialUriTemplateComponents getUriTemplateComponents ( Map < String , ? > parameters , List < String > requiredArgs ) { } }

implementation:
Assert . notNull ( parameters , "Parameters must not be null!" ) ; final StringBuilder baseUrl = new StringBuilder ( urlComponents . get ( 0 ) ) ; final StringBuilder queryHead = new StringBuilder ( ) ; final StringBuilder queryTail = new StringBuilder ( ) ; final StringBuilder fragmentIdentifier = new StringBuilder ( ) ; for ( int i = 1 ; i < urlComponents . size ( ) ; i ++ ) { final String part = urlComponents . get ( i ) ; final List < Integer > variablesInPart = variableIndices . get ( i ) ; if ( variablesInPart . isEmpty ( ) ) { if ( part . startsWith ( "?" ) || part . startsWith ( "&" ) ) { queryHead . append ( part ) ; } else if ( part . startsWith ( "#" ) ) { fragmentIdentifier . append ( part ) ; } else { baseUrl . append ( part ) ; } } else { for ( Integer variableInPart : variablesInPart ) { final TemplateVariable variable = variables . get ( variableInPart ) ; final Object value = parameters . get ( variable . getName ( ) ) ; if ( value == null ) { switch ( variable . getType ( ) ) { case REQUEST_PARAM : case REQUEST_PARAM_CONTINUED : if ( requiredArgs . isEmpty ( ) || requiredArgs . contains ( variable . getName ( ) ) ) { // query vars without value always go last ( query tail )
if ( queryTail . length ( ) > 0 ) { queryTail . append ( ',' ) ; } queryTail . append ( variable . getName ( ) ) ; } break ; case FRAGMENT : fragmentIdentifier . append ( variable . toString ( ) ) ; break ; case PATH_VARIABLE : if ( queryHead . length ( ) != 0 ) { // level 1 variable in query
queryHead . append ( variable . toString ( ) ) ; } else { baseUrl . append ( variable . toString ( ) ) ; } break ; case SEGMENT : baseUrl . append ( variable . toString ( ) ) ; } } else { switch ( variable . getType ( ) ) { case REQUEST_PARAM : case REQUEST_PARAM_CONTINUED : if ( queryHead . length ( ) == 0 ) { queryHead . append ( '?' ) ; } else { queryHead . append ( '&' ) ; } queryHead . append ( variable . getName ( ) ) . append ( '=' ) . append ( urlEncode ( value . toString ( ) ) ) ; break ; case SEGMENT : baseUrl . append ( '/' ) ; // fall through
case PATH_VARIABLE : if ( queryHead . length ( ) != 0 ) { // level 1 variable in query
queryHead . append ( urlEncode ( value . toString ( ) ) ) ; } else { baseUrl . append ( urlEncode ( value . toString ( ) ) ) ; } break ; case FRAGMENT : fragmentIdentifier . append ( '#' ) ; fragmentIdentifier . append ( urlEncode ( value . toString ( ) ) ) ; break ; } } } } } return new PartialUriTemplateComponents ( baseUrl . toString ( ) , queryHead . toString ( ) , queryTail . toString ( ) , fragmentIdentifier . toString ( ) , variableNames ) ;


signature:
public class PartialUriTemplate { /** * Strips all variables which are not required by any of the given action descriptors . If no action descriptors are
 * given , nothing will be stripped .
 * @ param actionDescriptors
 * to decide which variables are optional , may be empty
 * @ return partial uri template components without optional variables , if actionDescriptors was not empty */
public PartialUriTemplateComponents stripOptionalVariables ( List < ActionDescriptor > actionDescriptors ) { } }

implementation: return getUriTemplateComponents ( Collections . < String , Object > emptyMap ( ) , getRequiredArgNames ( actionDescriptors ) ) ;


signature:
public class AbstractUberNode { /** * Gets first child of this uber node having the given name attribute .
 * @ param name
 * to look up
 * @ return found child or null */
public UberNode getFirstByName ( String name ) { } }

implementation:
// TODO consider less naive impl
UberNode ret = null ; for ( UberNode node : data ) { if ( name . equals ( node . getName ( ) ) ) { ret = node ; break ; } } return ret ;


signature:
public class AbstractUberNode { /** * Gets first child of this uber node having the given rel attribute .
 * @ param rel
 * to look up
 * @ return found child or null */
public UberNode getFirstByRel ( String rel ) { } }

implementation:
// TODO consider less naive impl
for ( UberNode node : data ) { List < String > myRels = node . getRel ( ) ; if ( myRels != null ) { for ( String myRel : myRels ) { if ( rel . equals ( myRel ) ) { return node ; } } } } return null ;


signature:
public class AbstractUberNode { /** * Allows iterating over children of this uber node which have a data attribute . */
@ Override public Iterator < UberNode > iterator ( ) { } }

implementation: return new Iterator < UberNode > ( ) { int index = 0 ; @ Override public void remove ( ) { throw new UnsupportedOperationException ( "removing from uber node is not supported" ) ; } @ Override public UberNode next ( ) { index = findNextChildWithData ( ) ; return data . get ( index ++ ) ; } @ Override public boolean hasNext ( ) { return findNextChildWithData ( ) != - 1 ; } private int findNextChildWithData ( ) { for ( int i = index ; i < data . size ( ) ; i ++ ) { if ( ! data . get ( i ) . getData ( ) . isEmpty ( ) ) { return i ; } } return - 1 ; } } ;


signature:
public class PersistentHashSet { /** * Works around some type inference limitations of Java 8. */
public static < E > MutableHashSet < E > emptyMutable ( Equator < E > eq ) { } }

implementation: return empty ( eq ) . mutable ( ) ;


signature:
public class PersistentHashSet { /** * Returns a new PersistentHashSet of the values . The vararg version of this method is
 * { @ link org . organicdesign . fp . StaticImports # set ( Object . . . ) } If the input contains duplicate
 * elements , later values overwrite earlier ones .
 * @ param elements The items to put into a vector .
 * @ return a new PersistentHashSet of the given elements . */
public static < E > PersistentHashSet < E > of ( Iterable < E > elements ) { } }

implementation: PersistentHashSet < E > empty = empty ( ) ; MutableSet < E > ret = empty . mutable ( ) ; for ( E e : elements ) { ret . put ( e ) ; } return ( PersistentHashSet < E > ) ret . immutable ( ) ;


signature:
public class PersistentHashMap { /** * Works around some type inference limitations of Java 8. */
public static < K , V > MutableHashMap < K , V > emptyMutable ( ) { } }

implementation: return PersistentHashMap . < K , V > empty ( ) . mutable ( ) ;


signature:
public class PersistentHashMap { /** * Works around some type inference limitations of Java 8. */
public static < K , V > MutableHashMap < K , V > emptyMutable ( Equator < K > e ) { } }

implementation: return PersistentHashMap . < K , V > empty ( e ) . mutable ( ) ;


signature:
public class PersistentHashMap { /** * Returns a new PersistentHashMap of the given keys and their paired values , skipping any null
 * Entries . */
@ SuppressWarnings ( "WeakerAccess" ) public static < K , V > PersistentHashMap < K , V > ofEq ( Equator < K > eq , Iterable < Map . Entry < K , V > > es ) { } }

implementation: if ( es == null ) { return empty ( eq ) ; } MutableHashMap < K , V > map = emptyMutable ( eq ) ; for ( Map . Entry < K , V > entry : es ) { if ( entry != null ) { map . assoc ( entry . getKey ( ) , entry . getValue ( ) ) ; } } return map . immutable ( ) ;


signature:
public class PersistentHashMap { /** * Returns a new PersistentHashMap of the given keys and their paired values . There is also a
 * varargs version of this method : { @ link org . organicdesign . fp . StaticImports # map ( Map . Entry . . . ) } . Use
 * the { @ link org . organicdesign . fp . StaticImports # tup ( Object , Object ) } method to define key / value
 * pairs briefly and easily .
 * @ param kvPairs Key / value pairs ( to go into the map ) . In the case of a duplicate key , later
 * values in the input list overwrite the earlier ones . The resulting map can contain zero or one
 * null key and any number of null values . Null k / v pairs will be silently ignored .
 * @ return a new PersistentHashMap of the given key / value pairs */
public static < K , V > PersistentHashMap < K , V > of ( Iterable < Map . Entry < K , V > > kvPairs ) { } }

implementation: if ( kvPairs == null ) { return empty ( ) ; } PersistentHashMap < K , V > m = empty ( ) ; MutableHashMap < K , V > map = m . mutable ( ) ; for ( Map . Entry < K , V > entry : kvPairs ) { if ( entry != null ) { map . assoc ( entry . getKey ( ) , entry . getValue ( ) ) ; } } return map . immutable ( ) ;


signature:
public class PersistentHashMap { /** * public static void main ( String [ ] args ) {
 * try
 * ArrayList words = new ArrayList ( ) ;
 * Scanner s = new Scanner ( new File ( args [ 0 ] ) ) ;
 * s . useDelimiter ( Pattern . compile ( " \ \ W " ) ) ;
 * while ( s . hasNext ( ) )
 * String word = s . next ( ) ;
 * words . add ( word ) ;
 * System . out . println ( " words : " + words . size ( ) ) ;
 * ImMap map = PersistentHashMap . EMPTY ;
 * ImMap map = new PersistentHashMap ( ) ;
 * Map ht = new Hashtable ( ) ;
 * Map ht = new HashMap ( ) ;
 * Random rand ;
 * System . out . println ( " Building map " ) ;
 * long startTime = System . nanoTime ( ) ;
 * for ( Object word5 : words )
 * map = map . assoc ( word5 , word5 ) ;
 * rand = new Random ( 42 ) ;
 * ImMap snapshotMap = map ;
 * for ( int i = 0 ; i < words . size ( ) / 200 ; i + + )
 * map = map . without ( words . get ( rand . nextInt ( words . size ( ) / 2 ) ) ) ;
 * long estimatedTime = System . nanoTime ( ) - startTime ;
 * System . out . println ( " size = " + map . size ( ) + " , time : " + estimatedTime / 100000 ) ;
 * System . out . println ( " Building ht " ) ;
 * startTime = System . nanoTime ( ) ;
 * for ( Object word1 : words )
 * ht . put ( word1 , word1 ) ;
 * rand = new Random ( 42 ) ;
 * for ( int i = 0 ; i < words . size ( ) / 200 ; i + + )
 * ht . remove ( words . get ( rand . nextInt ( words . size ( ) / 2 ) ) ) ;
 * estimatedTime = System . nanoTime ( ) - startTime ;
 * System . out . println ( " size = " + ht . size ( ) + " , time : " + estimatedTime / 100000 ) ;
 * System . out . println ( " map lookup " ) ;
 * startTime = System . nanoTime ( ) ;
 * int c = 0;
 * for ( Object word2 : words )
 * if ( ! map . contains ( word2 ) )
 * estimatedTime = System . nanoTime ( ) - startTime ;
 * System . out . println ( " notfound = " + c + " , time : " + estimatedTime / 100000 ) ;
 * System . out . println ( " ht lookup " ) ;
 * startTime = System . nanoTime ( ) ;
 * c = 0;
 * for ( Object word3 : words )
 * if ( ! ht . containsKey ( word3 ) )
 * estimatedTime = System . nanoTime ( ) - startTime ;
 * System . out . println ( " notfound = " + c + " , time : " + estimatedTime / 100000 ) ;
 * System . out . println ( " snapshotMap lookup " ) ;
 * startTime = System . nanoTime ( ) ;
 * c = 0;
 * for ( Object word4 : words )
 * if ( ! snapshotMap . contains ( word4 ) )
 * estimatedTime = System . nanoTime ( ) - startTime ;
 * System . out . println ( " notfound = " + c + " , time : " + estimatedTime / 100000 ) ;
 * catch ( FileNotFoundException e )
 * e . printStackTrace ( ) ; */
private static < K , V > INode < K , V > [ ] cloneAndSet ( INode < K , V > [ ] array , int i , INode < K , V > a ) { } }

implementation: INode < K , V > [ ] clone = array . clone ( ) ; clone [ i ] = a ; return clone ;


signature: public class FunctionUtils { public static String ordinal ( final int origI ) { } }

implementation: final int i = ( origI < 0 ) ? - origI : origI ; final int modTen = i % 10 ; if ( ( modTen < 4 ) && ( modTen > 0 ) ) { int modHundred = i % 100 ; if ( ( modHundred < 21 ) && ( modHundred > 3 ) ) { return Integer . toString ( origI ) + "th" ; } switch ( modTen ) { case 1 : return Integer . toString ( origI ) + "st" ; case 2 : return Integer . toString ( origI ) + "nd" ; case 3 : return Integer . toString ( origI ) + "rd" ; } } return Integer . toString ( origI ) + "th" ;


signature:
public class PersistentTreeMap { /** * Returns a new PersistentTreeMap of the given comparable keys and their paired values , skipping
 * any null Entries . */
public static < K extends Comparable < K > , V > PersistentTreeMap < K , V > of ( Iterable < Map . Entry < K , V > > es ) { } }

implementation: if ( es == null ) { return empty ( ) ; } PersistentTreeMap < K , V > map = new PersistentTreeMap < > ( Equator . defaultComparator ( ) , null , 0 ) ; for ( Map . Entry < K , V > entry : es ) { if ( entry != null ) { map = map . assoc ( entry . getKey ( ) , entry . getValue ( ) ) ; } } return map ;


signature:
public class PersistentTreeMap { /** * Returns a new PersistentTreeMap of the specified comparator and the given key / value pairs .
 * @ param comp A comparator ( on the keys ) that defines the sort order inside the new map . This
 * becomes a permanent part of the map and all sub - maps or appended maps derived from it . If you
 * want to use a null key , make sure the comparator treats nulls correctly in all circumstances !
 * @ param kvPairs Key / value pairs ( to go into the map ) . In the case of a duplicate key , later
 * values in the input list overwrite the earlier ones . The resulting map can contain zero or
 * one null key ( if your comparator knows how to sort nulls ) and any number of null values . Null
 * k / v pairs will be silently ignored .
 * @ return a new PersistentTreeMap of the specified comparator and the given key / value pairs */
public static < K , V > PersistentTreeMap < K , V > ofComp ( Comparator < ? super K > comp , Iterable < Map . Entry < K , V > > kvPairs ) { } }

implementation: if ( kvPairs == null ) { return new PersistentTreeMap < > ( comp , null , 0 ) ; } PersistentTreeMap < K , V > map = new PersistentTreeMap < > ( comp , null , 0 ) ; for ( Map . Entry < K , V > entry : kvPairs ) { if ( entry != null ) { map = map . assoc ( entry . getKey ( ) , entry . getValue ( ) ) ; } } return map ;


signature:
public class PersistentTreeMap { /** * Be extremely careful with this because it uses the default comparator , which only works for
 * items that implement Comparable ( have a " natural ordering " ) . An attempt to use it with other
 * items will blow up at runtime . Either a withComparator ( ) method will be added , or this will
 * be removed . */
@ SuppressWarnings ( "unchecked" ) public static < K extends Comparable < K > , V > PersistentTreeMap < K , V > empty ( ) { } }

implementation: return ( PersistentTreeMap < K , V > ) EMPTY ;


signature:
public class PersistentTreeMap { /** * Returns a new empty PersistentTreeMap that will use the specified comparator . */
public static < K , V > PersistentTreeMap < K , V > empty ( Comparator < ? super K > c ) { } }

implementation: return new PersistentTreeMap < > ( c , null , 0 ) ;


signature:
public class PersistentTreeMap { /** * Returns a view of the mappings contained in this map . The set should actually contain
 * UnmodMap . UnEntry items , but that return signature is illegal in Java , so you ' ll just have to
 * remember . */
@ Override public ImSortedSet < Entry < K , V > > entrySet ( ) { } }

implementation:
// This is the pretty way to do it .
return this . fold ( PersistentTreeSet . ofComp ( new KeyComparator < > ( comp ) ) , PersistentTreeSet :: put ) ;


signature:
public class PersistentTreeMap { /** * { @ inheritDoc } */
@ Override public ImSortedMap < K , V > subMap ( K fromKey , K toKey ) { } }

implementation:
int diff = comp . compare ( fromKey , toKey ) ; if ( diff > 0 ) { throw new IllegalArgumentException ( "fromKey is greater than toKey" ) ; } UnEntry < K , V > last = last ( ) ; K lastKey = last . getKey ( ) ; int compFromKeyLastKey = comp . compare ( fromKey , lastKey ) ; // If no intersect , return empty . We aren ' t checking the toKey vs . the firstKey ( ) because
// that ' s a single pass through the iterator loop which is probably as cheap as checking
// here .
if ( ( diff == 0 ) || ( compFromKeyLastKey > 0 ) ) { return new PersistentTreeMap < > ( comp , null , 0 ) ; } // If map is entirely contained , just return it .
if ( ( comp . compare ( fromKey , firstKey ( ) ) <= 0 ) && ( comp . compare ( toKey , lastKey ) > 0 ) ) { return this ; } // Don ' t iterate through entire map for only the last item .
if ( compFromKeyLastKey == 0 ) { return ofComp ( comp , Collections . singletonList ( last ) ) ; } ImSortedMap < K , V > ret = new PersistentTreeMap < > ( comp , null , 0 ) ; UnmodIterator < UnEntry < K , V > > iter = this . iterator ( ) ; while ( iter . hasNext ( ) ) { UnEntry < K , V > next = iter . next ( ) ; K key = next . getKey ( ) ; if ( comp . compare ( toKey , key ) <= 0 ) { break ; } if ( comp . compare ( fromKey , key ) > 0 ) { continue ; } ret = ret . assoc ( key , next . getValue ( ) ) ; } return ret ;


signature:
public class PersistentTreeMap { /** * { @ inheritDoc } */
@ Override public Option < UnEntry < K , V > > head ( ) { } }

implementation: Node < K , V > t = tree ; if ( t != null ) { while ( t . left ( ) != null ) { t = t . left ( ) ; } } return Option . some ( t ) ;


signature:
public class PersistentTreeMap { /** * Returns the comparator used to order the keys in this map , or null if it uses
 * Fn2 . DEFAULT _ COMPARATOR ( for compatibility with java . util . SortedMap ) . */
@ Override public Comparator < ? super K > comparator ( ) { } }

implementation: return ( comp == Equator . Comp . DEFAULT ) ? null : comp ;


signature:
public class PersistentTreeMap { /** * { @ inheritDoc } */
@ Override public PersistentTreeMap < K , V > assoc ( K key , V val ) { } }

implementation:
Box < Node < K , V > > found = new Box < > ( null ) ; Node < K , V > t = add ( tree , key , val , found ) ; // null = = already contains key
if ( t == null ) { Node < K , V > foundNode = found . val ; // note only get same collection on identity of val , not equals ( )
if ( foundNode . getValue ( ) == val ) { return this ; } return new PersistentTreeMap < > ( comp , replace ( tree , key , val ) , size ) ; } return new PersistentTreeMap < > ( comp , t . blacken ( ) , size + 1 ) ;


signature:
public class PersistentTreeMap { /** * { @ inheritDoc } */
@ Override public PersistentTreeMap < K , V > without ( K key ) { } }

implementation:
Box < Node < K , V > > found = new Box < > ( null ) ; Node < K , V > t = remove ( tree , key , found ) ; if ( t == null ) { // null = = doesn ' t contain key
if ( found . val == null ) { return this ; } // empty
return new PersistentTreeMap < > ( comp , null , 0 ) ; } return new PersistentTreeMap < > ( comp , t . blacken ( ) , size - 1 ) ;


signature:
public class PersistentTreeMap { /** * Returns the last key in this map or throws a NoSuchElementException if the map is empty . */
@ Override public K lastKey ( ) { } }

implementation: UnEntry < K , V > max = last ( ) ; if ( max == null ) { throw new NoSuchElementException ( "this map is empty" ) ; } return max . getKey ( ) ;


signature:
public class PersistentTreeMap { /** * Returns the last key / value pair in this map , or null if the map is empty . */
public UnEntry < K , V > last ( ) { } }

implementation: Node < K , V > t = tree ; if ( t != null ) { while ( t . right ( ) != null ) t = t . right ( ) ; } return t ;


signature:
public class PersistentTreeMap { /** * Returns an Option of the key / value pair matching the given key , or Option . none ( ) if the key is
 * not found . */
@ Override public Option < UnmodMap . UnEntry < K , V > > entry ( K key ) { } }

implementation: Node < K , V > t = tree ; while ( t != null ) { int c = comp . compare ( key , t . getKey ( ) ) ; if ( c == 0 ) return Option . some ( t ) ; else if ( c < 0 ) t = t . left ( ) ; else t = t . right ( ) ; } return Option . none ( ) ; // t ; / / t is always null


signature: public class PersistentTreeMap { private Node < K , V > add ( Node < K , V > t , K key , V val , Box < Node < K , V > > found ) { } }

implementation:
if ( t == null ) { // if ( val = = null )
// return new Red < > ( key ) ;
return new Red < > ( key , val ) ; } int c = comp . compare ( key , t . getKey ( ) ) ; if ( c == 0 ) { found . val = t ; return null ; } Node < K , V > ins = add ( c < 0 ? t . left ( ) : t . right ( ) , key , val , found ) ; if ( ins == null ) // found below
return null ; if ( c < 0 ) return t . addLeft ( ins ) ; return t . addRight ( ins ) ;


signature:
public class PersistentTreeMap { /** * Node < K , V > concat ( Node < K1 , V1 > left , Node < K2 , V2 > right ) { */
@ SuppressWarnings ( "unchecked" ) private static < K , V > Node < K , V > append ( Node < ? extends K , ? extends V > left , Node < ? extends K , ? extends V > right ) { } }

implementation:
if ( left == null ) return ( Node < K , V > ) right ; else if ( right == null ) return ( Node < K , V > ) left ; else if ( left instanceof PersistentTreeMap . Red ) { if ( right instanceof PersistentTreeMap . Red ) { Node < K , V > app = append ( left . right ( ) , right . left ( ) ) ; if ( app instanceof PersistentTreeMap . Red ) return red ( app . getKey ( ) , app . getValue ( ) , red ( left . getKey ( ) , left . getValue ( ) , left . left ( ) , app . left ( ) ) , red ( right . getKey ( ) , right . getValue ( ) , app . right ( ) , right . right ( ) ) ) ; else return red ( left . getKey ( ) , left . getValue ( ) , left . left ( ) , red ( right . getKey ( ) , right . getValue ( ) , app , right . right ( ) ) ) ; } else return red ( left . getKey ( ) , left . getValue ( ) , left . left ( ) , append ( left . right ( ) , right ) ) ; } else if ( right instanceof PersistentTreeMap . Red ) return red ( right . getKey ( ) , right . getValue ( ) , append ( left , right . left ( ) ) , right . right ( ) ) ; else // black / black
{ Node < K , V > app = append ( left . right ( ) , right . left ( ) ) ; if ( app instanceof PersistentTreeMap . Red ) return red ( app . getKey ( ) , app . getValue ( ) , black ( left . getKey ( ) , left . getValue ( ) , left . left ( ) , app . left ( ) ) , black ( right . getKey ( ) , right . getValue ( ) , app . right ( ) , right . right ( ) ) ) ; else return balanceLeftDel ( left . getKey ( ) , left . getValue ( ) , left . left ( ) , black ( right . getKey ( ) , right . getValue ( ) , app , right . right ( ) ) ) ; }


signature:
public class Xform { /** * Static factory methods */
public static < T > Xform < T > of ( Iterable < ? extends T > list ) { } }

implementation: if ( list == null ) { return empty ( ) ; } return new SourceProviderIterableDesc < > ( list ) ;


signature:
public class Xform { /** * than lazily evaluated and cached linked - list , Sequence model . */
@ SuppressWarnings ( "unchecked" ) private static < H > H _fold ( Iterable source , Operation [ ] ops , int opIdx , H ident , Fn2 reducer ) { } }

implementation:
Object ret = ident ; // This is a label - the first one I have used in Java in years , or maybe ever .
// I ' m assuming this is fast , but will have to test to confirm it .
sourceLoop : for ( Object o : source ) { for ( int j = opIdx ; j < ops . length ; j ++ ) { Operation op = ops [ j ] ; if ( ( op . filter != null ) && ! op . filter . apply ( o ) ) { // stop processing this source item and go to the next one .
continue sourceLoop ; } if ( op . map != null ) { o = op . map . apply ( o ) ; // This is how map can handle takeWhile , take , and other termination marker
// roles . Remember , the fewer functions we have to check for , the faster this
// will execute .
if ( o == TERMINATE ) { return ( H ) ret ; } } else if ( op . flatMap != null ) { ret = _fold ( op . flatMap . apply ( o ) , ops , j + 1 , ( H ) ret , reducer ) ; // stop processing this source item and go to the next one .
continue sourceLoop ; } // if ( ( op . terminate ! = null ) & & op . terminate . apply ( o ) ) {
// return ( G ) ret ;
} // Here , the item made it through all the operations . Combine it with the result .
ret = reducer . apply ( ret , o ) ; } return ( H ) ret ;


signature: public class Xform { @ Override public Xform < A > concat ( Iterable < ? extends A > list ) { } }

implementation: if ( list == null ) { throw new IllegalArgumentException ( "Can't concat a null iterable" ) ; } return new AppendIterDesc < > ( this , new SourceProviderIterableDesc < > ( list ) ) ;


signature: public class Xform { @ Override public Xform < A > precat ( Iterable < ? extends A > list ) { } }

implementation: if ( list == null ) { throw new IllegalArgumentException ( "Can't precat a null iterable" ) ; } return new AppendIterDesc < > ( of ( list ) , this ) ;


signature:
public class Xform { /** * The number of items to drop from the beginning of the output . */
@ Override public Xform < A > dropWhile ( Fn1 < ? super A , Boolean > predicate ) { } }

implementation: if ( predicate == null ) { throw new IllegalArgumentException ( "Can't dropWhile without a function." ) ; } return new DropWhileDesc < > ( this , predicate ) ;


signature:
public class Xform { /** * Provides a way to collect the results of the transformation . */
@ Override public < B > B fold ( B ident , Fn2 < ? super B , ? super A , B > reducer ) { } }

implementation:
if ( reducer == null ) { throw new IllegalArgumentException ( "Can't fold with a null reduction function." ) ; } // Construct an optimized array of OpRuns ( mutable operations for this run )
RunList runList = toRunList ( ) ; return _fold ( runList , runList . opArray ( ) , 0 , ident , reducer ) ;


signature:
public class Xform { /** * Thit implementation should be correct , but could be slow in the case where previous operations
 * are slow and the terminateWhen operation is fast and terminates early . It actually renders
 * items to a mutable List , then runs through the list performing the requested reduction ,
 * checking for early termination on the result . If you can to a takeWhile ( ) or take ( ) earlier
 * in the transform chain instead of doing it here , always do that . If you really need early
 * termination based on the * result * of a fold , and the operations are expensive or the input
 * is huge , try using a View instead . If you don ' t care about those things , then this method is
 * perfect for you .
 * { @ inheritDoc } */
@ Override public < G , B > Or < G , B > foldUntil ( G accum , Fn2 < ? super G , ? super A , B > terminator , Fn2 < ? super G , ? super A , G > reducer ) { } }

implementation:
if ( terminator == null ) { return Or . good ( fold ( accum , reducer ) ) ; } if ( reducer == null ) { throw new IllegalArgumentException ( "Can't fold with a null reduction function." ) ; } // Yes , this is a cheap plastic imitation of what you ' d hope for if you really need this
// method . The trouble is that when I implemented it correctly in _ fold , I found
// it was going to be incredibly difficult , or more likely impossible to implement
// when the previous operation was flatMap , since you don ' t have the right result type to
// check against when you recurse in to the flat mapping function , and if you check the
// return from the recursion , it may have too many elements already .
// In XformTest . java , there ' s something marked " Early termination test " that illustrates
// this exact problem .
List < A > as = this . toMutableList ( ) ; for ( A a : as ) { B term = terminator . apply ( accum , a ) ; if ( term != null ) { return Or . bad ( term ) ; } accum = reducer . apply ( accum , a ) ; } return Or . good ( accum ) ;


signature:
public class PersistentTreeSet { /** * Returns a new PersistentTreeSet of the given comparator . Always use this instead of starting
 * with empty ( ) because there is no way to assign a comparator to an existing set . */
public static < T > PersistentTreeSet < T > ofComp ( Comparator < ? super T > comp ) { } }

implementation: return new PersistentTreeSet < > ( PersistentTreeMap . empty ( comp ) ) ;


signature:
public class PersistentTreeSet { /** * Returns a new PersistentTreeSet of the given comparator and items .
 * @ param comp A comparator that defines the sort order of elements in the new set . This
 * becomes part of the set ( it ' s not for pre - sorting ) .
 * @ param elements items to go into the set . In the case of a duplicate element , later
 * values in the input list overwrite the earlier ones .
 * @ return a new PersistentTreeSet of the specified comparator and the given elements */
public static < T > PersistentTreeSet < T > ofComp ( Comparator < ? super T > comp , Iterable < T > elements ) { } }

implementation: PersistentTreeSet < T > ret = new PersistentTreeSet < > ( PersistentTreeMap . empty ( comp ) ) ; if ( elements == null ) { return ret ; } for ( T element : elements ) { ret = ret . put ( element ) ; } return ret ;


signature:
public class PersistentTreeSet { /** * Returns a new PersistentTreeSet of the given comparable items . */
public static < T extends Comparable < T > > PersistentTreeSet < T > of ( Iterable < T > items ) { } }

implementation:
// empty ( ) uses default comparator
if ( items == null ) { return empty ( ) ; } PersistentTreeSet < T > ret = empty ( ) ; for ( T item : items ) { ret = ret . put ( item ) ; } return ret ;


signature:
public class PersistentTreeSet { /** * { @ inheritDoc } */
@ Override public PersistentTreeSet < E > without ( E key ) { } }

implementation: return ( impl . containsKey ( key ) ) ? new PersistentTreeSet < > ( impl . without ( key ) ) : this ;


signature:
public class PersistentTreeSet { /** * { @ inheritDoc } */
@ Override public UnmodSortedIterator < E > iterator ( ) { } }

implementation: return new UnmodSortedIterator < E > ( ) { UnmodSortedIterator < ? extends UnmodMap . UnEntry < E , ? > > iter = impl . iterator ( ) ; @ Override public boolean hasNext ( ) { return iter . hasNext ( ) ; } @ Override public E next ( ) { UnmodMap . UnEntry < E , ? > e = iter . next ( ) ; return e == null ? null : e . getKey ( ) ; } } ;


signature:
public class PersistentTreeSet { /** * { @ inheritDoc } */
@ Override public Option < E > head ( ) { } }

implementation: return size ( ) > 0 ? Option . some ( impl . firstKey ( ) ) : Option . none ( ) ;


signature:
public class PersistentTreeSet { /** * { @ inheritDoc } */
@ Override public PersistentTreeSet < E > put ( E e ) { } }

implementation: return ( impl . containsKey ( e ) ) ? this : new PersistentTreeSet < > ( impl . assoc ( e , null ) ) ;


signature:
public class PersistentTreeSet { /** * { @ inheritDoc } */
@ Override public ImSortedSet < E > subSet ( E fromElement , E toElement ) { } }

implementation: return PersistentTreeSet . ofMap ( impl . subMap ( fromElement , toElement ) ) ;


signature:
public class PersistentTreeSet { /** * { @ inheritDoc } */
@ Override public ImSortedSet < E > tailSet ( E fromElement ) { } }

implementation: return PersistentTreeSet . ofMap ( impl . tailMap ( fromElement ) ) ;


signature:
public class None { /** * { @ inheritDoc } */
@ Override public < U > U match ( Fn1 < T , U > has , Fn0 < U > hasNot ) { } }

implementation: return hasNot . get ( ) ;


signature:
public class Tuple2 { /** * Public static factory method */
public static < A , B > Tuple2 < A , B > of ( A a , B b ) { } }

implementation: return new Tuple2 < > ( a , b ) ;


signature:
public class Tuple2 { /** * Map . Entry factory method */
public static < K , V > Tuple2 < K , V > of ( Map . Entry < K , V > entry ) { } }

implementation:
// Protect against multiple - instantiation
if ( entry instanceof Tuple2 ) { return ( Tuple2 < K , V > ) entry ; } return new Tuple2 < > ( entry . getKey ( ) , entry . getValue ( ) ) ;


signature:
public class RrbTree { /** * Returns a new RrbTree minus the given item ( all items to the right are shifted left one )
 * This is O ( log n ) . */
public RrbTree < E > without ( int index ) { } }

implementation: if ( ( index > 0 ) && ( index < size ( ) - 1 ) ) { Tuple2 < ? extends RrbTree < E > , ? extends RrbTree < E > > s1 = split ( index ) ; Tuple2 < ? extends RrbTree < E > , ? extends RrbTree < E > > s2 = s1 . _2 ( ) . split ( 1 ) ; return s1 . _1 ( ) . join ( s2 . _2 ( ) ) ; } else if ( index == 0 ) { return split ( 1 ) . _2 ( ) ; } else if ( index == size ( ) - 1 ) { return split ( size ( ) - 1 ) . _1 ( ) ; } else { throw new IndexOutOfBoundsException ( "Failed test: 0 <= index < size" ) ; }


signature:
public class RrbTree { /** * Helper function to avoid type warnings . */
@ SuppressWarnings ( "unchecked" ) private static < T > Node < T > [ ] genericNodeArray ( int size ) { } }

implementation: return ( Node < T > [ ] ) new Node < ? > [ size ] ;


signature:
public class RrbTree { /** * = = = = = Debugging and pretty - printing = = = = = */
private static StringBuilder showSubNodes ( StringBuilder sB , Object [ ] items , int nextIndent ) { } }

implementation:
boolean isFirst = true ; for ( Object n : items ) { if ( isFirst ) { isFirst = false ; } else { // sB . append ( " " ) ;
if ( items [ 0 ] instanceof Leaf ) { sB . append ( " " ) ; } else { sB . append ( "\n" ) . append ( indentSpace ( nextIndent ) ) ; } } sB . append ( ( ( Node ) n ) . indentedStr ( nextIndent ) ) ; } return sB ;


signature:
public class OneOf3 { /** * If sel is managed correctly , it ensures that the cast is accurate . */
@ SuppressWarnings ( "unchecked" ) public < R > R match ( Fn1 < A , R > fa , Fn1 < B , R > fb , Fn1 < C , R > fc ) { } }

implementation: if ( sel == 0 ) { return fa . apply ( ( A ) item ) ; } else if ( sel == 1 ) { return fb . apply ( ( B ) item ) ; } else { return fc . apply ( ( C ) item ) ; }


signature: public class RangeOfInt { public static RangeOfInt of ( Number s , Number e ) { } }

implementation: if ( ( s == null ) || ( e == null ) ) { throw new IllegalArgumentException ( "Nulls not allowed" ) ; } if ( e . longValue ( ) < s . longValue ( ) ) { throw new IllegalArgumentException ( "end of range must be >= start of range" ) ; } return new RangeOfInt ( s . intValue ( ) , e . intValue ( ) ) ;


signature:
public class RangeOfInt { /** * Though this overrides List . contains ( Object o ) , it is effectively a convenience method for
 * calling contains ( int i ) . Therefore , it only accepts Integers , Longs , BigIntegers , and
 * Strings that parse as signed decimal Integers . It does not accept Numbers since they can ' t
 * easily be checked for truncation and floating - point might not round properly with respect to
 * bounds , or might not make sense if you are using your range to define a set of integers .
 * Handles truncation ( returns false ) for the types it accepts . Throws exceptions for types it
 * does not accept .
 * Thanks for all the help from codereview . stackexchange :
 * http : / / codereview . stackexchange . com / questions / 100846 / rounding - and - truncation - in - intrange - containsobject - o
 * @ param o an Integer , Long , BigInteger , or String that parses as a signed decimal Integer .
 * @ return true if the number is within the bounds of this range ( high end is exclusive ) . False
 * otherwise .
 * @ throws IllegalArgumentException if the argument is not an Integer , Long , BigInteger , or
 * String .
 * @ throws NumberFormatException if a String argument cannot be parsed using Integer . valueOf ( ) . */
@ SuppressWarnings ( "deprecation" ) @ Override public boolean contains ( Object o ) { } }

implementation:
// Only accept classes where we can convert to an integer while preventing
// overflow / underflow . If there were a way to reliably test for overflow / underflow in
// Numbers , we could accept them too , but with the rounding errors of floats and doubles
// that ' s impractical .
if ( o instanceof Integer ) { return contains ( ( ( Integer ) o ) . intValue ( ) ) ; } else if ( o instanceof Long ) { long l = ( Long ) o ; return ( l <= ( ( long ) Integer . MAX_VALUE ) ) && ( l >= ( ( long ) Integer . MIN_VALUE ) ) && contains ( ( int ) l ) ; } else if ( o instanceof BigInteger ) { try { // Throws an exception if it ' s more than 32 bits .
return contains ( ( ( BigInteger ) o ) . intValueExact ( ) ) ; } catch ( ArithmeticException ignore ) { return false ; } } else if ( o instanceof String ) { return contains ( Integer . valueOf ( ( String ) o ) ) ; } else { throw new IllegalArgumentException ( "Don't know how to convert to a primitive int" + " without risking accidental truncation.  Pass an" + " Integer, Long, BigInteger, or String that parses" + " within Integer bounds instead." ) ; }


signature:
public class RangeOfInt { /** * Unlike most implementations of List , this method has excellent O ( 1 ) performance !
 * { @ inheritDoc } */
@ Override public int indexOf ( Object o ) { } }

implementation: if ( o instanceof Number ) { int i = ( ( Number ) o ) . intValue ( ) ; if ( ( i >= start ) && ( i < end ) ) { return i - start ; } } return - 1 ;


signature:
public class RangeOfInt { /** * { @ inheritDoc }
 * Iterates from start of range ( inclusive ) up - to , but excluding , the end of the range .
 * I ' m not sure this is a good idea , but Python , Clojure , Scala , and just about everything in
 * Java expects similar behavior . */
@ Override public UnmodListIterator < Integer > listIterator ( final int startIdx ) { } }

implementation:
if ( ( startIdx < 0 ) || ( startIdx > size ) ) { // To match ArrayList and other java . util . List expectations
throw new IndexOutOfBoundsException ( "Index: " + startIdx ) ; } return new UnmodListIterator < Integer > ( ) { int val = start + startIdx ; @ Override public boolean hasNext ( ) { return val < end ; } @ Override public Integer next ( ) { if ( val >= end ) { // To match ArrayList and other java . util . List expectations
throw new NoSuchElementException ( ) ; } Integer t = val ; val = val + 1 ; return t ; } @ Override public boolean hasPrevious ( ) { return val > start ; } @ Override public Integer previous ( ) { if ( val <= start ) { // To match ArrayList and other java . util . List expectations
throw new NoSuchElementException ( ) ; } val = val - 1 ; return val ; } @ Override public int nextIndex ( ) { return val - start ; } } ;


signature:
public class RangeOfInt { /** * { @ inheritDoc } */
@ Override public RangeOfInt subList ( int fromIndex , int toIndex ) { } }

implementation:
if ( ( fromIndex == 0 ) && ( toIndex == size ) ) { return this ; } // Note that this is an IllegalArgumentException , not IndexOutOfBoundsException in order to
// match ArrayList .
if ( fromIndex > toIndex ) { throw new IllegalArgumentException ( "fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")" ) ; } // The text of this matches ArrayList
if ( fromIndex < 0 ) { throw new IndexOutOfBoundsException ( "fromIndex = " + fromIndex ) ; } if ( toIndex > size ) { throw new IndexOutOfBoundsException ( "toIndex = " + toIndex ) ; } // Look very closely at the second parameter because the bounds checking is * different *
// from the get ( ) method . get ( toIndex ) can throw an exception if toIndex > = start + size .
// But since a range is exclusive of it ' s right - bound , we can create a new sub - range
// with a right bound index of size , as opposed to size minus 1 . I spent hours
// understanding this before fixing a bug with it . In the end , subList should do the same
// thing on a Range that it does on the equivalent ArrayList . I made tests for the same .
return RangeOfInt . of ( start + fromIndex , start + toIndex ) ;


signature:
public class RuntimeTypes { /** * Use this to prevent duplicate runtime types .
 * @ param cs an immutable vector of classes to register */
public static ImList < Class > registerClasses ( Class ... cs ) { } }

implementation:
if ( cs == null ) { throw new IllegalArgumentException ( "Can't register a null type array" ) ; } if ( cs . length == 0 ) { throw new IllegalArgumentException ( "Can't register a zero-length type array" ) ; } for ( Class c : cs ) { if ( c == null ) { throw new IllegalArgumentException ( "There shouldn't be any null types in this array!" ) ; } } ArrayHolder < Class > ah = new ArrayHolder < > ( cs ) ; ImList < Class > registeredTypes ; synchronized ( Lock . INSTANCE ) { registeredTypes = typeMap . get ( ah ) ; if ( registeredTypes == null ) { ImList < Class > vecCs = vec ( cs ) ; typeMap . put ( ah , vecCs ) ; registeredTypes = vecCs ; } } // We are returning the original array . If we returned our safe copy , it could be modified !
return registeredTypes ;


signature:
public class Tuple7 { /** * Public static factory method */
public static < A , B , C , D , E , F , G > Tuple7 < A , B , C , D , E , F , G > of ( A a , B b , C c , D d , E e , F f , G g ) { } }

implementation: return new Tuple7 < > ( a , b , c , d , e , f , g ) ;


signature:
public class PersistentVector { /** * Returns a new mutable vector . For some reason calling empty ( ) . mutable ( ) sometimes requires
 * an explicit type parameter in Java , so this convenience method works around that . */
@ SuppressWarnings ( "unchecked" ) public static < T > MutableVector < T > emptyMutable ( ) { } }

implementation: PersistentVector < T > e = empty ( ) ; return e . mutable ( ) ;


signature:
public class PersistentVector { /** * Public static factory method to create a vector from an Iterable . A varargs version of this
 * method is : { @ link org . organicdesign . fp . StaticImports # vec ( Object . . . ) } . */
static public < T > PersistentVector < T > ofIter ( Iterable < T > items ) { } }

implementation: MutableVector < T > ret = emptyMutable ( ) ; for ( T item : items ) { ret . append ( item ) ; } return ret . immutable ( ) ;


signature:
public class PersistentVector { /** * Returns the array ( of type E ) from the leaf node indicated by the given index . */
@ SuppressWarnings ( "unchecked" ) private E [ ] leafNodeArrayFor ( int i ) { } }

implementation:
// i is the index into this vector . Each 5 bits represent an index into an array . The
// highest 5 bits ( that are less than the shift value ) are the index into the top - level
// array . The lowest 5 bits index the the leaf . The guts of this method indexes into the
// array at each level , finally indexing into the leaf node .
if ( i >= 0 && i < size ) { if ( i >= tailoff ( ) ) { return tail ; } Node node = root ; for ( int level = shift ; level > 0 ; level -= NODE_LENGTH_POW_2 ) { node = ( Node ) node . array [ ( i >>> level ) & LOW_BITS ] ; } return ( E [ ] ) node . array ; } throw new IndexOutOfBoundsException ( ) ;


signature:
public class PersistentVector { /** * Returns the item specified by the given index . */
@ Override public E get ( int i ) { } }

implementation: E [ ] node = leafNodeArrayFor ( i ) ; return node [ i & LOW_BITS ] ;


signature:
public class PersistentVector { /** * { @ inheritDoc } */
@ SuppressWarnings ( "unchecked" ) @ Override public PersistentVector < E > replace ( int i , E val ) { } }

implementation: if ( i >= 0 && i < size ) { if ( i >= tailoff ( ) ) { Object [ ] newTail = new Object [ tail . length ] ; System . arraycopy ( tail , 0 , newTail , 0 , tail . length ) ; newTail [ i & LOW_BITS ] = val ; return new PersistentVector < > ( size , shift , root , ( E [ ] ) newTail ) ; } return new PersistentVector < > ( size , shift , doAssoc ( shift , root , i , val ) , tail ) ; } if ( i == size ) { return append ( val ) ; } throw new IndexOutOfBoundsException ( ) ;


signature:
public class PersistentVector { /** * Inserts a new item at the end of the Vecsicle .
 * @ param val the value to insert
 * @ return a new Vecsicle with the additional item . */
@ SuppressWarnings ( "unchecked" ) @ Override public PersistentVector < E > append ( E val ) { } }

implementation:
// room in tail ?
// if ( tail . length < MAX _ NODE _ LENGTH )
if ( size - tailoff ( ) < MAX_NODE_LENGTH ) { E [ ] newTail = ( E [ ] ) new Object [ tail . length + 1 ] ; System . arraycopy ( tail , 0 , newTail , 0 , tail . length ) ; newTail [ tail . length ] = val ; return new PersistentVector < > ( size + 1 , shift , root , newTail ) ; } // full tail , push into tree
Node newroot ; Node tailnode = new Node ( root . edit , tail ) ; int newshift = shift ; // overflow root ?
if ( ( size >>> NODE_LENGTH_POW_2 ) > ( 1 << shift ) ) { newroot = new Node ( root . edit ) ; newroot . array [ 0 ] = root ; newroot . array [ 1 ] = newPath ( root . edit , shift , tailnode ) ; newshift += NODE_LENGTH_POW_2 ; } else { newroot = pushTail ( shift , root , tailnode ) ; } return new PersistentVector < > ( size + 1 , newshift , newroot , ( E [ ] ) new Object [ ] { val } ) ;


signature:
public class PersistentVector { /** * Efficiently adds items to the end of this PersistentVector .
 * @ param items the values to insert
 * @ return a new PersistentVector with the additional items at the end . */
@ Override public PersistentVector < E > concat ( Iterable < ? extends E > items ) { } }

implementation: return ( PersistentVector < E > ) ImList . super . concat ( items ) ;


signature: public class PersistentVector { private static Node doAssoc ( int level , Node node , int i , Object val ) { } }

implementation: Node ret = new Node ( node . edit , node . array . clone ( ) ) ; if ( level == 0 ) { ret . array [ i & LOW_BITS ] = val ; } else { int subidx = ( i >>> level ) & LOW_BITS ; ret . array [ subidx ] = doAssoc ( level - NODE_LENGTH_POW_2 , ( Node ) node . array [ subidx ] , i , val ) ; } return ret ;


signature:
public class Tuple9 { /** * Public static factory method */
public static < A , B , C , D , E , F , G , H , I > Tuple9 < A , B , C , D , E , F , G , H , I > of ( A a , B b , C c , D d , E e , F f , G g , H h , I i ) { } }

implementation: return new Tuple9 < > ( a , b , c , d , e , f , g , h , i ) ;


signature:
public class StaticImports { /** * Returns a new PersistentHashMap of the given keys and their paired values . Use the
 * { @ link StaticImports # tup ( Object , Object ) } method to define those key / value pairs briefly and
 * easily . This data definition method is one of the few methods in this project that support
 * varargs .
 * @ param kvPairs Key / value pairs ( to go into the map ) . In the case of a duplicate key , later
 * values in the input list overwrite the earlier ones . The resulting map can contain zero or one
 * null key and any number of null values . Null k / v pairs will be silently ignored .
 * @ return a new PersistentHashMap of the given key / value pairs */
@ SafeVarargs public static < K , V > ImMap < K , V > map ( Map . Entry < K , V > ... kvPairs ) { } }

implementation: if ( ( kvPairs == null ) || ( kvPairs . length < 1 ) ) { return PersistentHashMap . empty ( ) ; } return PersistentHashMap . of ( Arrays . asList ( kvPairs ) ) ;


signature:
public class StaticImports { /** * Returns a new MutableMap of the given keys and their paired values . Use the
 * { @ link StaticImports # tup ( Object , Object ) } method to define those key / value pairs briefly and
 * easily . This data definition method is one of the few methods in this project that support
 * varargs .
 * @ param kvPairs Key / value pairs ( to go into the map ) . In the case of a duplicate key , later
 * values in the input list overwrite the earlier ones . The resulting map can contain zero or one
 * null key and any number of null values . Null k / v pairs will be silently ignored .
 * @ return a new MutableMap of the given key / value pairs */
@ SafeVarargs public static < K , V > MutableMap < K , V > mutableMap ( Map . Entry < K , V > ... kvPairs ) { } }

implementation: MutableMap < K , V > ret = PersistentHashMap . emptyMutable ( ) ; if ( kvPairs == null ) { return ret ; } for ( Map . Entry < K , V > me : kvPairs ) { ret . assoc ( me ) ; } return ret ;


signature:
public class StaticImports { /** * Returns a mutable RRB Tree { @ link MutableRrbt } of the given items .
 * The RRB Tree is a list - type data structure that supports random inserts , split , and join
 * ( the PersistentVector does not ) . The mutable RRB Tree append ( ) method is only about half
 * as fast as the PersistentVector method of the same name . If you build it entirely with random
 * inserts , then the RRB tree get ( ) method may be about 5x slower . Otherwise , performance
 * is about the same .
 * This data definition method is one of the few methods in this project that support varargs . */
@ SafeVarargs static public < T > MutableRrbt < T > mutableRrb ( T ... items ) { } }

implementation: if ( ( items == null ) || ( items . length < 1 ) ) { return RrbTree . emptyMutable ( ) ; } return RrbTree . < T > emptyMutable ( ) . concat ( Arrays . asList ( items ) ) ;


signature:
public class StaticImports { /** * Returns a new MutableSet of the values . This data definition method is one of the few
 * methods in this project that support varargs . If the input contains duplicate elements , later
 * values overwrite earlier ones . */
@ SafeVarargs public static < T > MutableSet < T > mutableSet ( T ... items ) { } }

implementation: MutableSet < T > ret = PersistentHashSet . emptyMutable ( ) ; if ( items == null ) { return ret ; } for ( T t : items ) { ret . put ( t ) ; } return ret ;


signature:
public class StaticImports { /** * Returns a MutableVector of the given items . This data definition method is one of the
 * few methods in this project that support varargs . */
@ SafeVarargs public static < T > MutableList < T > mutableVec ( T ... items ) { } }

implementation: MutableList < T > ret = PersistentVector . emptyMutable ( ) ; if ( items == null ) { return ret ; } for ( T t : items ) { ret . append ( t ) ; } return ret ;


signature:
public class StaticImports { /** * Returns a new immutable RRB Tree { @ link ImRrbt } of the given items . An RRB Tree
 * is an immutable list that supports random inserts , split , and join ( the PersistentVector does
 * not ) . If you build it entirely with random
 * inserts , then the RRB tree get ( ) method may be about 5x slower . Otherwise , performance
 * is about the same .
 * This data definition method is one of the few methods in this project that support varargs . */
@ SafeVarargs static public < T > ImRrbt < T > rrb ( T ... items ) { } }

implementation: if ( ( items == null ) || ( items . length < 1 ) ) { return RrbTree . empty ( ) ; } return mutableRrb ( items ) . immutable ( ) ;


signature:
public class StaticImports { /** * Returns a new PersistentHashSet of the values . This data definition method is one of the few
 * methods in this project that support varargs . If the input contains duplicate elements , later
 * values overwrite earlier ones . */
@ SafeVarargs public static < T > ImSet < T > set ( T ... items ) { } }

implementation: if ( ( items == null ) || ( items . length < 1 ) ) { return PersistentHashSet . empty ( ) ; } return PersistentHashSet . of ( Arrays . asList ( items ) ) ;


signature:
public class StaticImports { /** * Returns a new PersistentTreeMap of the specified comparator and the given key / value pairs . Use
 * the tup ( ) method to define those key / value pairs briefly and easily . The keys are sorted
 * according to the comparator you provide .
 * @ param comp A comparator ( on the keys ) that defines the sort order inside the new map . This
 * becomes a permanent part of the map and all sub - maps or appended maps derived from it . If you
 * want to use a null key , make sure the comparator treats nulls correctly in all circumstances !
 * @ param kvPairs Key / value pairs ( to go into the map ) . In the case of a duplicate key , later
 * values in the input list overwrite the earlier ones . The resulting map can contain zero or one
 * null key ( if your comparator knows how to sort nulls ) and any number of null values . Null k / v
 * pairs will be silently ignored .
 * @ return a new PersistentTreeMap of the specified comparator and the given key / value pairs */
public static < K , V > ImSortedMap < K , V > sortedMap ( Comparator < ? super K > comp , Iterable < Map . Entry < K , V > > kvPairs ) { } }

implementation: return PersistentTreeMap . ofComp ( comp , kvPairs ) ;


signature:
public class StaticImports { /** * Returns a new PersistentTreeSet of the given comparator and items .
 * @ param comp A comparator that defines the sort order of elements in the new set . This
 * becomes part of the set ( it ' s not for pre - sorting ) .
 * @ param elements items to go into the set . In the case of duplicates , later elements overwrite
 * earlier ones .
 * @ return a new PersistentTreeSet of the specified comparator and the given elements */
public static < T > ImSortedSet < T > sortedSet ( Comparator < ? super T > comp , Iterable < T > elements ) { } }

implementation: return Xform . of ( elements ) . toImSortedSet ( comp ) ;


signature:
public class StaticImports { /** * Returns a new PersistentTreeSet of the given comparable items . */
public static < T extends Comparable < T > > ImSortedSet < T > sortedSet ( Iterable < T > items ) { } }

implementation: return PersistentTreeSet . of ( items ) ;


signature:
public class StaticImports { /** * Returns a new PersistentVector of the given items . This data definition method is one of the
 * few methods in this project that support varargs . */
@ SafeVarargs static public < T > ImList < T > vec ( T ... items ) { } }

implementation: if ( ( items == null ) || ( items . length < 1 ) ) { return PersistentVector . empty ( ) ; } return mutableVec ( items ) . immutable ( ) ;


signature:
public class StaticImports { /** * If you need to wrap a regular Java array outside this project to perform
 * a transformation on it , this method is the most convenient , efficient way to do so . */
@ SafeVarargs public static < T > UnmodIterable < T > xformArray ( T ... items ) { } }

implementation: return Xform . of ( Arrays . asList ( items ) ) ;


signature:
public class StaticImports { /** * Wrap a String ( or CharSequence ) to perform a Character - by - Character transformation on it . */
public static UnmodIterable < Character > xformChars ( CharSequence seq ) { } }

implementation:
// noinspection Convert2Lambda
return new UnmodIterable < Character > ( ) { @ Override public UnmodIterator < Character > iterator ( ) { return new UnmodIterator < Character > ( ) { private int idx = 0 ; @ Override public boolean hasNext ( ) { return idx < seq . length ( ) ; } @ Override public Character next ( ) { int nextIdx = idx + 1 ; Character c = seq . charAt ( idx ) ; idx = nextIdx ; return c ; } } ; } } ;


signature:
public class IndentUtils { /** * Creates a new StringBuilder with the given number of spaces and returns it .
 * @ param len the number of spaces
 * @ return a { @ link StringBuilder } with the specificed number of initial spaces . */
public static StringBuilder indentSpace ( int len ) { } }

implementation: StringBuilder sB = new StringBuilder ( ) ; if ( len < 1 ) { return sB ; } while ( len > SPACES_LENGTH_MINUS_ONE ) { sB . append ( SPACES [ SPACES_LENGTH_MINUS_ONE ] ) ; len = len - SPACES_LENGTH_MINUS_ONE ; } return sB . append ( SPACES [ len ] ) ;


signature:
public class IndentUtils { /** * There is Arrays . toString , but this is intended to produce Cymling code some day . */
public static < T > String arrayString ( T [ ] items ) { } }

implementation: StringBuilder sB = new StringBuilder ( "A[" ) ; boolean isFirst = true ; for ( T item : items ) { if ( isFirst ) { isFirst = false ; } else { sB . append ( " " ) ; } if ( item instanceof String ) { sB . append ( "\"" ) . append ( item ) . append ( "\"" ) ; } else { sB . append ( item ) ; } } return sB . append ( "]" ) . toString ( ) ;


signature:
public class IndentUtils { /** * TODO : We need one of these for each type of primitive for pretty - printing without commas . */
public static String arrayString ( int [ ] items ) { } }

implementation: StringBuilder sB = new StringBuilder ( "i[" ) ; boolean isFirst = true ; for ( int item : items ) { if ( isFirst ) { isFirst = false ; } else { sB . append ( " " ) ; } sB . append ( item ) ; } return sB . append ( "]" ) . toString ( ) ;


signature:
public class LazyRef { /** * Construct a LazyRef from the given initialization function .
 * @ param producer a zero - argument function that produces the desired value when called .
 * @ return a LazyRef with the given producer . */
public static < T > LazyRef < T > of ( Fn0 < T > producer ) { } }

implementation: if ( producer == null ) { throw new IllegalArgumentException ( "The producer function cannot be null (the value it returns can)" ) ; } return new LazyRef < > ( producer ) ;


signature:
public class LazyRef { /** * This whole method is synchronized on the advice of Goetz2006 p . 347 */
public synchronized T applyEx ( ) { } }

implementation:
// Have we produced our value yet ?
if ( producer != null ) { // produce our value .
value = producer . apply ( ) ; // Delete the producer to 1 . mark the work done and 2 . free resources .
producer = null ; } // We ' re clear to return the lazily computed value .
return value ;


signature:
public class Cowry { /** * Helper function to avoid type warnings .
 * @ param elem the item to put in the array .
 * @ param tClass the class of the array .
 * @ return an array of the appropriate class containing the single element . */
@ SuppressWarnings ( "unchecked" ) public static < T > T [ ] singleElementArray ( T elem , Class < T > tClass ) { } }

implementation: if ( tClass == null ) { return ( T [ ] ) new Object [ ] { elem } ; } T [ ] newItems = ( T [ ] ) Array . newInstance ( tClass , 1 ) ; newItems [ 0 ] = elem ; return newItems ;


signature:
public class Cowry { /** * Returns a new array one longer than the given one , with the specified item inserted at the specified index .
 * @ param item The item to insert
 * @ param items The original array ( will not be modified )
 * @ param idx the index to insert the item at .
 * @ param tClass The runtime class to store in the new array ( or null for an Object array ) .
 * @ return A copy of the given array with the additional item at the appropriate index
 * ( will be one longer than the original array ) . */
public static < T > T [ ] insertIntoArrayAt ( T item , T [ ] items , int idx , Class < T > tClass ) { } }

implementation:
// Make an array that ' s one bigger . It ' s too bad that the JVM bothers to
// initialize this with nulls .
@ SuppressWarnings ( "unchecked" ) T [ ] newItems = ( T [ ] ) ( ( tClass == null ) ? new Object [ items . length + 1 ] : Array . newInstance ( tClass , items . length + 1 ) ) ; // If we aren ' t inserting at the first item , array - copy the items before the insert
// point .
if ( idx > 0 ) { System . arraycopy ( items , 0 , newItems , 0 , idx ) ; } // Insert the new item .
newItems [ idx ] = item ; // If we aren ' t inserting at the last item , array - copy the items after the insert
// point .
if ( idx < items . length ) { System . arraycopy ( items , idx , newItems , idx + 1 , items . length - idx ) ; } return newItems ;


signature:
public class Cowry { /** * Returns a new array containing the first n items of the given array .
 * @ param items the items to copy
 * @ param length the maximum length of the new array
 * @ param tClass the class of the items in the array ( null for Object )
 * @ return a copy of the original array with the given length */
public static < T > T [ ] arrayCopy ( T [ ] items , int length , Class < T > tClass ) { } }

implementation:
// Make an array of the appropriate size . It ' s too bad that the JVM bothers to
// initialize this with nulls .
@ SuppressWarnings ( "unchecked" ) T [ ] newItems = ( T [ ] ) ( ( tClass == null ) ? new Object [ length ] : Array . newInstance ( tClass , length ) ) ; // array - copy the items up to the new length .
if ( length > 0 ) { System . arraycopy ( items , 0 , newItems , 0 , items . length < length ? items . length : length ) ; } return newItems ;


signature:
public class Cowry { /** * Called splice , but handles precat ( idx = 0 ) and concat ( idx = origItems . length ) .
 * @ param insertedItems the items to insert
 * @ param origItems the original items .
 * @ param idx the index to insert new items at
 * @ param tClass the class of the resulting new array
 * @ return a new array with the new items inserted at the proper position of the old array . */
public static < A > A [ ] spliceIntoArrayAt ( A [ ] insertedItems , A [ ] origItems , int idx , Class < A > tClass ) { } }

implementation:
// Make an array that big enough . It ' s too bad that the JVM bothers to
// initialize this with nulls .
@ SuppressWarnings ( "unchecked" ) A [ ] newItems = tClass == null ? ( A [ ] ) new Object [ insertedItems . length + origItems . length ] : ( A [ ] ) Array . newInstance ( tClass , insertedItems . length + origItems . length ) ; // If we aren ' t inserting at the first item , array - copy the items before the insert
// point .
if ( idx > 0 ) { // src , srcPos , dest , destPos , length
System . arraycopy ( origItems , 0 , newItems , 0 , idx ) ; } // Insert the new items
// src , srcPos , dest , destPos , length
System . arraycopy ( insertedItems , 0 , newItems , idx , insertedItems . length ) ; // If we aren ' t inserting at the last item , array - copy the items after the insert
// point .
if ( idx < origItems . length ) { System . arraycopy ( origItems , idx , newItems , idx + insertedItems . length , origItems . length - idx ) ; } return newItems ;


signature: public class Cowry { public static < T > T [ ] replaceInArrayAt ( T replacedItem , T [ ] origItems , int idx , Class < T > tClass ) { } }

implementation:
// Make an array that big enough . It ' s too bad that the JVM bothers to
// initialize this with nulls .
@ SuppressWarnings ( "unchecked" ) T [ ] newItems = ( T [ ] ) ( ( tClass == null ) ? new Object [ origItems . length ] : Array . newInstance ( tClass , origItems . length ) ) ; System . arraycopy ( origItems , 0 , newItems , 0 , origItems . length ) ; newItems [ idx ] = replacedItem ; return newItems ;


signature:
public class Cowry { /** * Only call this if the array actually needs to be split ( 0 & lt ; splitPoint & lt ; orig . length ) .
 * @ param orig array to split
 * @ param splitIndex items less than this index go in the left , equal or greater in the right .
 * @ return a 2D array of leftItems then rightItems */
public static < T > Tuple2 < T [ ] , T [ ] > splitArray ( T [ ] orig , int splitIndex ) { } }

implementation:
// , Class < T > tClass ) {
// if ( splitIndex < 1 ) {
// throw new IllegalArgumentException ( " Called split when splitIndex < 1 " ) ;
// if ( splitIndex > orig . length - 1 ) {
// throw new IllegalArgumentException ( " Called split when splitIndex > orig . length - 1 " ) ;
// NOTE :
// I sort of suspect that generic 2D array creation where the two arrays are of a different
// length is not possible in Java , or if it is , it ' s not likely to be much faster than
// what we have here . I ' d just copy the Arrays . copyOf code everywhere this function is used
// if you want more speed .
// int rightLength = orig . length - splitIndex ;
// Class < T > tClass = ( Class < T > ) orig . getClass ( ) . getComponentType ( ) ;
// Tuple2 < T [ ] , T [ ] > split = Tuple2 . of ( ( T [ ] ) Array . newInstance ( tClass , splitIndex ) ,
// ( T [ ] ) Array . newInstance ( tClass , rightLength ) ) ;
// Tuple2 < T [ ] , T [ ] > split =
return Tuple2 . of ( Arrays . copyOf ( orig , splitIndex ) , Arrays . copyOfRange ( orig , splitIndex , orig . length ) ) ; // / / original array , offset , newArray , offset , length
// System . arraycopy ( orig , 0 , split . _ 1 ( ) , 0 , splitIndex ) ;
// System . arraycopy ( orig , splitIndex , split . _ 2 ( ) , 0 , rightLength ) ;
// return split ;


signature:
public class Cowry { /** * Only call this if the array actually needs to be split ( 0 & lt ; splitPoint & lt ; orig . length ) .
 * @ param orig array to split
 * @ param splitIndex items less than this index go in the left , equal or greater in the right .
 * @ return a 2D array of leftItems then rightItems */
public static int [ ] [ ] splitArray ( int [ ] orig , int splitIndex ) { } }

implementation:
// This function started an exact duplicate of the one above , but for ints .
// if ( splitIndex < 1 ) {
// throw new IllegalArgumentException ( " Called split when splitIndex < 1 " ) ;
// if ( splitIndex > orig . length - 1 ) {
// throw new IllegalArgumentException ( " Called split when splitIndex > orig . length - 1 " ) ;
int rightLength = orig . length - splitIndex ; int [ ] [ ] split = new int [ ] [ ] { new int [ splitIndex ] , new int [ rightLength ] } ; // original array , offset , newArray , offset , length
System . arraycopy ( orig , 0 , split [ 0 ] , 0 , splitIndex ) ; System . arraycopy ( orig , splitIndex , split [ 1 ] , 0 , rightLength ) ; return split ;


signature:
public class DeployableUnitDescriptorFactoryImpl { /** * ( non - Javadoc )
 * @ see org . mobicents . slee . core . component . du . DeployableUnitDescriptorFactory # parse ( java . io . InputStream ) */
public DeployableUnitDescriptorImpl parse ( InputStream inputStream ) throws DeploymentException { } }

implementation: Object jaxbPojo = buildJAXBPojo ( inputStream ) ; if ( jaxbPojo instanceof org . mobicents . slee . container . component . deployment . jaxb . slee11 . du . DeployableUnit ) { return new DeployableUnitDescriptorImpl ( ( org . mobicents . slee . container . component . deployment . jaxb . slee11 . du . DeployableUnit ) jaxbPojo ) ; } else if ( jaxbPojo instanceof org . mobicents . slee . container . component . deployment . jaxb . slee . du . DeployableUnit ) { return new DeployableUnitDescriptorImpl ( ( org . mobicents . slee . container . component . deployment . jaxb . slee . du . DeployableUnit ) jaxbPojo ) ; } else { throw new SLEEException ( "unexpected class of jaxb pojo built: " + ( jaxbPojo != null ? jaxbPojo . getClass ( ) : null ) ) ; }


signature:
public class SleeTransactionImpl { /** * Some operations require that the transaction be suspended
 * @ throws SystemException */
private void suspendIfAssoaciatedWithThread ( ) throws SystemException { } }

implementation:
// if there is a tx associated with this thread and it is this one
// then suspend it to dissociate the thread ( dumb feature ? ! ? ! of jboss ts )
final SleeTransaction currentThreadTransaction = transactionManager . getSleeTransaction ( ) ; if ( currentThreadTransaction != null && currentThreadTransaction . equals ( this ) ) { // lets use the real tx manager directly , to avoid any other procedures
transactionManager . getRealTransactionManager ( ) . suspend ( ) ; }


signature:
public class SleeTransactionImpl { /** * Verifies if the wrapped transaction is active and if dissociates it from
 * the thread if needed
 * @ throws IllegalStateException
 * @ throws SecurityException */
private void beforeAsyncOperation ( ) throws IllegalStateException , SecurityException { } }

implementation: try { int status = transaction . getStatus ( ) ; if ( asyncOperationInitiated . getAndSet ( true ) || ( status != Status . STATUS_ACTIVE && status != Status . STATUS_MARKED_ROLLBACK ) ) { throw new IllegalStateException ( "There is no active tx, tx is in state: " + status ) ; } suspendIfAssoaciatedWithThread ( ) ; } catch ( SystemException e ) { throw new IllegalStateException ( e ) ; }


signature:
public class SleeTransactionImpl { /** * ( non - Javadoc )
 * @ see javax . slee . transaction . SleeTransaction # asyncCommit ( javax . slee . transaction . CommitListener ) */
public void asyncCommit ( CommitListener commitListener ) throws IllegalStateException , SecurityException { } }

implementation: beforeAsyncOperation ( ) ; transactionManager . getExecutorService ( ) . submit ( new AsyncTransactionCommitRunnable ( commitListener , transaction ) ) ;


signature:
public class SleeTransactionImpl { /** * ( non - Javadoc )
 * @ see javax . slee . transaction . SleeTransaction # asyncRollback ( javax . slee . transaction . RollbackListener ) */
public void asyncRollback ( RollbackListener rollbackListener ) throws IllegalStateException , SecurityException { } }

implementation: beforeAsyncOperation ( ) ; transactionManager . getExecutorService ( ) . submit ( new AsyncTransactionRollbackRunnable ( rollbackListener , transaction ) ) ;


signature:
public class SleeTransactionImpl { /** * ( non - Javadoc )
 * @ see javax . slee . transaction . SleeTransaction # delistResource ( javax . transaction . xa . XAResource , int ) */
public boolean delistResource ( XAResource arg0 , int arg1 ) throws IllegalStateException , SystemException { } }

implementation: return transaction . delistResource ( arg0 , arg1 ) ;


signature:
public class SleeTransactionImpl { /** * ( non - Javadoc )
 * @ see javax . slee . transaction . SleeTransaction # enlistResource ( javax . transaction . xa . XAResource ) */
public boolean enlistResource ( XAResource arg0 ) throws IllegalStateException , RollbackException { } }

implementation:
try { return transaction . enlistResource ( arg0 ) ; } catch ( SystemException e ) { // this should be a bug in slee 1.1 api , the exceptions thrown
// should match jta transaction interface
throw new RuntimeException ( e ) ; }


signature:
public class SleeTransactionImpl { /** * ( non - Javadoc )
 * @ see javax . transaction . Transaction # commit ( ) */
public void commit ( ) throws RollbackException , HeuristicMixedException , HeuristicRollbackException , SecurityException , IllegalStateException , SystemException { } }

implementation: if ( asyncOperationInitiated . get ( ) ) { throw new IllegalStateException ( ) ; } try { transaction . commit ( ) ; } finally { suspendIfAssoaciatedWithThread ( ) ; }


signature:
public class ResourceAdaptorEntityState { /** * Get a < code > ResourceAdaptorEntityState < / code > object from an integer value .
 * @ param state the state as an integer .
 * @ return a < code > ResourceAdaptorEntityState < / code > object corresponding to < code > state < / code > .
 * @ throws IllegalArgumentException if < code > state < / code > is not a valid resource
 * adaptor entity state value . */
public static ResourceAdaptorEntityState fromInt ( int state ) throws IllegalArgumentException { } }

implementation: switch ( state ) { case ENTITY_INACTIVE : return INACTIVE ; case ENTITY_ACTIVE : return ACTIVE ; case ENTITY_STOPPING : return STOPPING ; default : throw new IllegalArgumentException ( "Invalid state: " + state ) ; }


signature:
public class DeployableUnitServiceComponentBuilder { /** * Builds a service component contained in the specified du jar file , with the specified and adds it to the specified deployable unit .
 * @ param serviceDescriptorFileName
 * @ param deployableUnitJar
 * @ param deployableUnit
 * @ param documentBuilder
 * @ throws DeploymentException */
public List < ServiceComponentImpl > buildComponents ( String serviceDescriptorFileName , JarFile deployableUnitJar ) throws DeploymentException { } }

implementation:
// make component jar entry
JarEntry componentDescriptor = deployableUnitJar . getJarEntry ( serviceDescriptorFileName ) ; InputStream componentDescriptorInputStream = null ; List < ServiceComponentImpl > result = new ArrayList < ServiceComponentImpl > ( ) ; try { componentDescriptorInputStream = deployableUnitJar . getInputStream ( componentDescriptor ) ; ServiceDescriptorFactoryImpl descriptorFactory = componentManagement . getComponentDescriptorFactory ( ) . getServiceDescriptorFactory ( ) ; for ( ServiceDescriptorImpl descriptor : descriptorFactory . parse ( componentDescriptorInputStream ) ) { result . add ( new ServiceComponentImpl ( descriptor ) ) ; } } catch ( IOException e ) { throw new DeploymentException ( "failed to parse service descriptor from " + componentDescriptor . getName ( ) , e ) ; } finally { if ( componentDescriptorInputStream != null ) { try { componentDescriptorInputStream . close ( ) ; } catch ( IOException e ) { logger . error ( "failed to close inputstream of descriptor for jar " + componentDescriptor . getName ( ) ) ; } } } return result ;


signature:
public class ConcreteClassGeneratorUtils { /** * Recursively walk a directory tree and return a List of all jars Files found ;
 * the List is sorted using File . compareTo .
 * @ param aStartingDir
 * is a valid directory , which can be read . */
static public List getJarsFileListing ( File aStartingDir ) throws FileNotFoundException { } }

implementation:
validateDirectory ( aStartingDir ) ; List result = new ArrayList ( ) ; File [ ] filesAndDirs = aStartingDir . listFiles ( new FileFilter ( ) { public boolean accept ( File pathname ) { if ( pathname . getName ( ) . endsWith ( ".jar" ) ) return true ; return false ; } } ) ; List filesDirs = Arrays . asList ( filesAndDirs ) ; Iterator filesIter = filesDirs . iterator ( ) ; File file = null ; while ( filesIter . hasNext ( ) ) { file = ( File ) filesIter . next ( ) ; result . add ( file ) ; // always add , even if directory
if ( ! file . isFile ( ) ) { // must be a directory
// recursive call !
List deeperList = getJarsFileListing ( file ) ; result . addAll ( deeperList ) ; } } Collections . sort ( result ) ; return result ;


signature:
public class ConcreteClassGeneratorUtils { /** * Directory is valid if it exists , does not represent a file , and can be read . */
static private void validateDirectory ( File aDirectory ) throws FileNotFoundException { } }

implementation: if ( aDirectory == null ) { throw new IllegalArgumentException ( "Directory should not be null." ) ; } if ( ! aDirectory . exists ( ) ) { throw new FileNotFoundException ( "Directory does not exist: " + aDirectory ) ; } if ( ! aDirectory . isDirectory ( ) ) { throw new IllegalArgumentException ( "Is not a directory: " + aDirectory ) ; } if ( ! aDirectory . canRead ( ) ) { throw new IllegalArgumentException ( "Directory cannot be read: " + aDirectory ) ; }


signature:
public class ConcreteClassGeneratorUtils { /** * Create the links with possible interfaces
 * @ param concreteClass
 * the concrete class to which to add the interface links
 * @ param interfaces
 * the interfaces the concrete class has to implement */
public static void createInterfaceLinks ( CtClass concreteClass , CtClass [ ] interfaces ) { } }

implementation: if ( interfaces != null ) concreteClass . setInterfaces ( interfaces ) ; else return ; for ( int i = 0 ; i < interfaces . length ; i ++ ) { logger . trace ( concreteClass . getName ( ) + " Implements link with " + interfaces [ i ] . getName ( ) + " interface created" ) ; }


signature:
public class ConcreteClassGeneratorUtils { /** * Create the inheritance link with the sbb absract class provided by the
 * sbb developer
 * @ param concreteClass
 * the concrete class to which to add the inheritance link
 * @ param superClass
 * the superClass to set */
public static void createInheritanceLink ( CtClass concreteClass , CtClass superClass ) { } }

implementation: if ( superClass == null ) return ; try { concreteClass . setSuperclass ( superClass ) ; logger . trace ( concreteClass . getName ( ) + " Inheritance link with " + superClass . getName ( ) + " class created" ) ; } catch ( CannotCompileException cce ) { cce . printStackTrace ( ) ; }