signature:
public class SymbolKeyTraverser { /** * { @ inheritDoc } */
public Iterator < Operator < Term > > traverse ( Functor functor , boolean reverse ) { } }

implementation:
/* log . fine ( " Traversing functor " + functor . toString ( interner , true , false ) ) ; */
Queue < Operator < Term > > queue = ( ! reverse ) ? new StackQueue < Operator < Term > > ( ) : new LinkedList < Operator < Term > > ( ) ; Term [ ] arguments = functor . getArguments ( ) ; // For a top - level functor clear top - level flag , so that child functors are not taken as top - level .
if ( arguments != null ) { for ( int i = 0 ; i < arguments . length ; i ++ ) { Term argument = arguments [ i ] ; // When navigating onto a variable , the variable is scoped within a clause , and may appear many times
// within it . Therefore it always uses its unique id relative to the root symbol table for the
// clause as its contextual position . Other terms use their position path and are relative to the
// the current positions symbol table .
SymbolTable < Integer , String , Object > contextSymbolTable ; if ( argument . isVar ( ) ) { contextSymbolTable = clauseScopedSymbolTable . enterScope ( CLAUSE_FREEVAR_INDEX ) ; /* log . fine ( " Enter freevar scope " ) ; */
argument . setReversable ( new ContextOperator ( contextSymbolTable , createTermOperator ( argument , i , functor ) ) ) ; argument . setTermTraverser ( this ) ; queue . offer ( argument ) ; /* log . fine ( " Created : " +
 ( " var argument operator on " + argument . toString ( interner , true , false ) ) ) ; */
} else { contextSymbolTable = null ; argument . setReversable ( new ContextOperator ( contextSymbolTable , i , createTermOperator ( argument , i , functor ) ) ) ; argument . setTermTraverser ( this ) ; queue . offer ( argument ) ; /* log . fine ( " Created : " +
 ( " argument operator " + i + " on " + argument . toString ( interner , true , false ) ) ) ; */
} } } return queue . iterator ( ) ;


signature:
public class SymbolKeyTraverser { /** * { @ inheritDoc }
 * < p / > Assigns symbol keys to non - variable terms , based on the positional path to the term within its containing
 * clause . */
public void visit ( Term term ) { } }

implementation: if ( isEnteringContext ( ) ) { SymbolKey key = currentSymbolTable . getSymbolKey ( currentPosition ) ; term . setSymbolKey ( key ) ; } if ( delegate != null ) { delegate . visit ( term ) ; }


signature:
public class SymbolKeyTraverser { /** * { @ inheritDoc }
 * < p / > Assigns symbol keys to variables , based on the variables id . */
public void visit ( Variable variable ) { } }

implementation:
if ( isEnteringContext ( ) ) { SymbolKey key = currentSymbolTable . getSymbolKey ( variable . getId ( ) ) ; variable . setSymbolKey ( key ) ; /* log . fine ( variable . toString ( interner , true , false ) + " assigned " + key ) ; */
} else if ( isLeavingContext ( ) ) { variable . setTermTraverser ( null ) ; } if ( delegate != null ) { delegate . visit ( variable ) ; }


signature:
public class SymbolKeyTraverser { /** * { @ inheritDoc } */
public void visit ( Predicate predicate ) { } }

implementation: if ( isEnteringContext ( ) ) { super . visit ( predicate ) ; } else if ( isLeavingContext ( ) ) { predicate . setTermTraverser ( null ) ; } if ( delegate != null ) { delegate . visit ( predicate ) ; }


signature:
public class SymbolKeyTraverser { /** * { @ inheritDoc } */
public void visit ( Clause clause ) { } }

implementation: if ( isEnteringContext ( ) ) { super . visit ( clause ) ; } else if ( isLeavingContext ( ) ) { clause . setTermTraverser ( null ) ; } if ( delegate != null ) { delegate . visit ( clause ) ; }


signature:
public class SymbolKeyTraverser { /** * { @ inheritDoc } */
public void visit ( Functor functor ) { } }

implementation:
if ( isEnteringContext ( ) ) { SymbolKey key = currentSymbolTable . getSymbolKey ( currentPosition ) ; functor . setSymbolKey ( key ) ; /* log . fine ( functor . toString ( interner , true , false ) + " assigned " + key ) ; */
} else if ( isLeavingContext ( ) ) { functor . setTermTraverser ( null ) ; } if ( delegate != null ) { delegate . visit ( functor ) ; }


signature:
public class SymbolKeyTraverser { /** * { @ inheritDoc } */
public void visit ( IntegerType literal ) { } }

implementation: if ( isEnteringContext ( ) ) { SymbolKey key = currentSymbolTable . getSymbolKey ( currentPosition ) ; literal . setSymbolKey ( key ) ; } else if ( isLeavingContext ( ) ) { literal . setTermTraverser ( null ) ; } if ( delegate != null ) { delegate . visit ( literal ) ; }


signature:
public class DistributedList { /** * Returns a distriubuted iterator that can provide elements of the list on demand over a remote connection .
 * @ return A { @ link com . thesett . common . util . distributed . DistributedIterator } that provides the elements of the list
 * on demand instead of all at once . */
public Iterator iterator ( ) { } }

implementation:
try { DistributedIteratorImpl di ; di = new DistributedIteratorImpl ( super . iterator ( ) ) ; return new ClientIterator ( di ) ; } catch ( RemoteException e ) { // Rethrow the RemoteException as a RuntimeException so as not to conflict with the interface of ArrayList
throw new IllegalStateException ( "There was a RemoteExcpetion." , e ) ; }


signature:
public class BitHackUtils { /** * Calcalates the log base 2 of an integer . This code is tuned to uniformly distributed output values , longer
 * numbers are slightly favoured .
 * @ param value The value to calculate for .
 * @ return Log base 2 of the input value . */
public static int intLogBase2 ( int value ) { } }

implementation: int temp1 ; int temp2 = value >> 16 ; if ( temp2 > 0 ) { temp1 = temp2 >> 8 ; return ( temp1 > 0 ) ? ( 24 + LOG_TABLE_256 [ temp1 ] ) : ( 16 + LOG_TABLE_256 [ temp2 ] ) ; } else { temp1 = value >> 8 ; return ( temp1 > 0 ) ? ( 8 + LOG_TABLE_256 [ temp1 ] ) : LOG_TABLE_256 [ value ] ; }


signature:
public class BitHackUtils { /** * Calcalates the log base 2 of an integer . This code is tuned to uniformly distributed input values , longer numbers
 * are favoured .
 * @ param value The value to calculate for .
 * @ return Log base 2 of the input value . */
public static int intLogBase2v2 ( int value ) { } }

implementation: int temp ; if ( ( temp = value >> 24 ) > 0 ) { return 24 + LOG_TABLE_256 [ temp ] ; } else if ( ( temp = value >> 16 ) > 0 ) { return 16 + LOG_TABLE_256 [ temp ] ; } else if ( ( temp = value >> 8 ) > 0 ) { return 8 + LOG_TABLE_256 [ temp ] ; } else { return LOG_TABLE_256 [ value ] ; }


signature:
public class BitHackUtils { /** * Calcalates the log base 2 of an integer in O ( log ( N ) ) steps ; shorter numbers are favoured .
 * @ param value The value to calculate for .
 * @ return Log base 2 of the input value . */
public static int intLogBase2v3 ( int value ) { } }

implementation: int result = 0 ; if ( ( value & LOG2_V3_BRANCH_VALUES [ 4 ] ) > 0 ) { value >>= LOG2_V3_SHIFT_VALUES [ 4 ] ; result |= LOG2_V3_SHIFT_VALUES [ 4 ] ; } if ( ( value & LOG2_V3_BRANCH_VALUES [ 3 ] ) > 0 ) { value >>= LOG2_V3_SHIFT_VALUES [ 3 ] ; result |= LOG2_V3_SHIFT_VALUES [ 3 ] ; } if ( ( value & LOG2_V3_BRANCH_VALUES [ 2 ] ) > 0 ) { value >>= LOG2_V3_SHIFT_VALUES [ 2 ] ; result |= LOG2_V3_SHIFT_VALUES [ 2 ] ; } if ( ( value & LOG2_V3_BRANCH_VALUES [ 1 ] ) > 0 ) { value >>= LOG2_V3_SHIFT_VALUES [ 1 ] ; result |= LOG2_V3_SHIFT_VALUES [ 1 ] ; } if ( ( value & LOG2_V3_BRANCH_VALUES [ 0 ] ) > 0 ) { value >>= LOG2_V3_SHIFT_VALUES [ 0 ] ; result |= LOG2_V3_SHIFT_VALUES [ 0 ] ; } return result ;


signature:
public class BitHackUtils { /** * Calcalates the log base 10 of an integer . This produces results faster for longer numbers .
 * @ param value The value to calculate for .
 * @ return Log base 10 of the input value . */
public static int intLogBase10v2 ( int value ) { } }


signature:
public class BitHackUtils { /** * Calcalates the log base 10 of an integer . This produces results faster for shorter numbers .
 * @ param value The value to calculate for .
 * @ return Log base 10 of the input value . */
public static int intLogBase10v3 ( int value ) { } }


signature:
public class BitHackUtils { /** * Calcalates the log base 10 of an integer . This method favours shorter numbers .
 * @ param value The value to calculate for .
 * @ return Log base 10 of the input value . */
public static int intLogBase10 ( long value ) { } }


signature:
public class BitHackUtils { /** * Calcalates the log base 10 of an integer . This method favours longer numbers , or evenly distributed input .
 * @ param value The value to calculate for .
 * @ return Log base 10 of the input value . */
public static int intLogBase10v2 ( long value ) { } }


signature:
public class BitHackUtils { /** * Calculates the number of ASCII characters that will be needed to represent a specifed signed 32 - bit integer .
 * @ param value The value to get the character count for .
 * @ return The number of ASCII character need to represent an signed 32 - bit integer . */
public static int getCharacterCountInt32 ( int value ) { } }

implementation: if ( value >= 0 ) { return getCharacterCountUInt32 ( value ) ; } else if ( value == Integer . MIN_VALUE ) { return getCharacterCountUInt32 ( Integer . MAX_VALUE ) + 1 ; } else { return getCharacterCountUInt32 ( - value ) + 1 ; }


signature:
public class BitHackUtils { /** * Calculates the number of ASCII characters that will be needed to represent a specifed signed 64 - bit integer .
 * @ param value The value to get the character count for .
 * @ return The number of ASCII character need to represent an signed 64 - bit integer . */
public static int getCharacterCountInt64 ( long value ) { } }

implementation: if ( value >= 0 ) { return getCharacterCountUInt64 ( value ) ; } else if ( value == Long . MIN_VALUE ) { return getCharacterCountUInt64 ( Long . MAX_VALUE ) + 1 ; } else { return getCharacterCountUInt64 ( - value ) + 1 ; }


signature:
public class BitHackUtils { /** * Calculates the number of ASCII characters that will be needed to represent a specified signed decimal number .
 * @ param integerValue The integer component of the decimal number .
 * @ param scale The scale component of the decimal number .
 * @ return The number of ASCII character need to represent a signed decimal number . */
public static int getCharacterCountDecimal ( long integerValue , int scale ) { } }

implementation:
boolean isNeg = integerValue < 0 ; // Work out how many digits will be needed for the number , adding space for the minus sign , the decimal
// point and leading zeros if needed .
int totalDigits = BitHackUtils . getCharacterCountInt64 ( integerValue ) ; int totalLength = totalDigits ; if ( isNeg ) { totalDigits -- ; // Minus sign already accounted for .
} if ( scale > 0 ) { totalLength ++ ; // For the decimal point .
if ( scale >= totalDigits ) { // For the leading zeros ( + 1 for the zero before decimal point ) .
totalLength += ( scale - totalDigits ) + 1 ; } } else { // Add a zero for each negative point in scale
totalLength -= scale ; } return totalLength ;


signature:
public class SwingColorFactory { /** * { @ inheritDoc } */
public Fader < Color > createFader ( Color startColor , Color endColor ) { } }

implementation: return new FaderImpl ( startColor , endColor ) ;


signature:
public class CellBackgroundColorDelta { /** * { @ inheritDoc }
 * < p / > Applies color changes to the background of a row . */
public void changeColor ( C color ) { } }

implementation: AttributeSet aset = new AttributeSet ( ) ; aset . put ( AttributeSet . BACKGROUND_COLOR , color ) ; grid . insertAttribute ( aset , col , row ) ;


signature:
public class FirstStepBuiltIn { /** * { @ inheritDoc } */
public boolean proofStep ( ResolutionState state ) { } }

implementation:
Clause query = state . getCurrentClause ( ) ; // The query goals are placed onto the goal stack backwards so that their insertion order is reversed for an
// intuitive left - to - right evaluation order .
for ( int i = query . getBody ( ) . length - 1 ; i >= 0 ; i -- ) { BuiltInFunctor newGoal = state . getBuiltInTransform ( ) . apply ( query . getBody ( ) [ i ] ) ; state . getGoalStack ( ) . offer ( newGoal ) ; } return true ;


signature:
public class WAMCompiledQuery { /** * Sets a compiled head functor to this clause .
 * @ param head The head of this clause .
 * @ param instructions A list of instructions to add to the head . */
public void setHead ( Functor head , SizeableList < WAMInstruction > instructions ) { } }

implementation: this . head = head ; addInstructions ( instructions ) ;


signature:
public class WAMCompiledQuery { /** * Emmits the binary byte code for the clause into a machine , writing into the specified byte array . The state of
 * this clause is changed to ' Linked ' to indicate that it has been linked into a binary machine .
 * @ param buffer The code buffer to write to .
 * @ param machine The binary machine to resolve call - points against , and to record as being linked into .
 * @ param callPoint The call point within the machine , at which the code is to be stored .
 * @ throws LinkageException If required symbols to link to cannot be found in the binary machine . */
public void emmitCode ( ByteBuffer buffer , WAMMachine machine , WAMCallPoint callPoint ) throws LinkageException { } }

implementation:
// Ensure that the size of the instruction listing does not exceed max int ( highly unlikely ) .
if ( sizeof ( ) > Integer . MAX_VALUE ) { throw new IllegalStateException ( "The instruction listing size exceeds Integer.MAX_VALUE." ) ; } // Used to keep track of the size of the emitted code , in bytes , as it is written .
int length = 0 ; // Insert the compiled code into the byte code machine ' s code area .
for ( WAMInstruction instruction : instructions ) { instruction . emmitCode ( buffer , machine ) ; length += instruction . sizeof ( ) ; } // Keep record of the machine that the code is hosted in , and the call point of the functor within the machine .
this . machine = machine ; this . callPoint = callPoint ; // Record the fact that the code is now linked into a machine .
this . status = LinkStatus . Linked ;


signature:
public class WorkFlowController { /** * Listens for events from back , next , finish and cancel inputs . If the event is finish the { @ link # saveWork } method
 * is triggered . If the event is cancel the { @ link # discardWork } method is called . If the event is back or next then
 * the { @ link # prevPage } or { @ link # nextPage } methods are called .
 * @ param event The work flow action event . */
public void actionPerformed ( ActionEvent event ) { } }

implementation:
/* log . fine ( " void actionPerformed ( ActionEvent ) : called " ) ; */
/* log . fine ( " Action is " + event . getActionCommand ( ) ) ; */
// Check which action event was performed
String action = event . getActionCommand ( ) ; // Check if the finish button was pressed
if ( "Finish" . equals ( action ) ) { // Save the work in progress
saveWorkFlow ( ) ; } // Check if the cancel button was pressed
if ( "Cancel" . equals ( action ) ) { // Discard the work in progress
discardWorkFlow ( ) ; } // Check if the next page button was pressed
if ( "Next |>" . equals ( action ) ) { // Notify implementing class of transition to the next page
nextPage ( ) ; } // Check if the prev page button was pressed
if ( "<| Prev" . equals ( action ) ) { // Notify implementing class of transition to the previous page
prevPage ( ) ; }


signature:
public class WorkFlowController { /** * Sets the order in which the saveWork or dicardWork methods of the individual screens encountered in a work flow
 * are called . On of the constants { @ link # FORWARD _ ORDERING } or { @ link # REVERSE _ ORDERING } should be passed as the
 * value to this method to specify which ordering to use .
 * @ param order The commit ordering to use . */
public void setCommitOrder ( String order ) { } }

implementation:
// Check that the specified order matches one of the ordering constants
if ( ! order . equals ( FORWARD_ORDERING ) && ! order . equals ( REVERSE_ORDERING ) ) { return ; } // Check that the new ordering is different from the existing one so that some work needs to be done to change
// it
if ( order . equals ( FORWARD_ORDERING ) && ( accessedScreens instanceof LifoStack ) ) { // Copy the screens into a forward ordered stack
accessedScreens = new FifoStack ( accessedScreens ) ; } else if ( order . equals ( REVERSE_ORDERING ) && ( accessedScreens instanceof LifoStack ) ) { // Copy the screens into a reverse ordered stack
accessedScreens = new LifoStack ( accessedScreens ) ; }


signature:
public class WorkFlowController { /** * Method called when the finish button is pressed . It works through all the screens in the order in which they were
 * accessed ( or reverse order , depending on the order set by the { @ link # setCommitOrder } method ) . Any screens that
 * are in the NOT _ SAVED state will have their { @ link WorkFlowScreenPanel # saveWork } method called . After this step is
 * complete the { @ link # saveWork } for the work flow controller is called . */
protected void saveWorkFlow ( ) { } }

implementation:
/* log . fine ( " void saveWorkFlow ( ) : called " ) ; */
// Cycle through all the accessed screens in the work flow
while ( ! accessedScreens . isEmpty ( ) ) { WorkFlowScreenPanel nextScreen = ( WorkFlowScreenPanel ) accessedScreens . pop ( ) ; // Check if the screen has unsaved state and call its save work method if so
if ( nextScreen . getState ( ) . getState ( ) . equals ( WorkFlowScreenState . NOT_SAVED ) ) { nextScreen . saveWork ( ) ; } } // Call the save work method for the entire work flow controller to finalize the work flow
saveWork ( ) ;


signature:
public class WorkFlowController { /** * Method called when the cancel button is pressed . It works through all the screens in the order in which they were
 * accessed ( or reverse order , depending on the order set by the { @ link # setCommitOrder } method ) . Any screens that
 * are in the NOT _ SAVED state will have their { @ link WorkFlowScreenPanel # discardWork } method called . After this step
 * is complete the { @ link # discardWork } for the work flow controller is called . */
protected void discardWorkFlow ( ) { } }

implementation:
/* log . fine ( " void discardWorkFlow ( ) : called " ) ; */
// Cycle through all the accessed screens in the work flow
while ( ! accessedScreens . isEmpty ( ) ) { WorkFlowScreenPanel nextScreen = ( WorkFlowScreenPanel ) accessedScreens . pop ( ) ; // Check if the screen has unsaved state and call its discard work method if so
if ( nextScreen . getState ( ) . getState ( ) . equals ( WorkFlowScreenState . NOT_SAVED ) ) { nextScreen . discardWork ( ) ; } } // Call the discard work method for the entire work flow controller to finalize the work flow
discardWork ( ) ;


signature:
public class WorkFlowController { /** * This is a helper method that controller implementations may find useful for moving to a new screen . It places the
 * screen into the panel that this controller was built with , replacing any existing screen , changes the underlying
 * state to reflect the change to a new current screen and calls the new screens initialize method .
 * @ param screen The new work flow screen to be displayed . */
protected void setCurrentScreen ( WorkFlowScreenPanel screen ) { } }

implementation:
// Remove any existing screen from the panel
panel . removeAll ( ) ; // Place the new screen into the panel
panel . add ( screen ) ; // Check if the screen is not already in the stack of accessed screens . It may be if this is the second time
// the screen is visited foir example if the back button is used .
if ( ! accessedScreens . contains ( screen ) ) { // Add the screen to the stack of accessed screens
accessedScreens . push ( screen ) ; } // Update the work flow state to reflect the change to a new screen state
state . setCurrentScreenState ( screen . getState ( ) ) ; // Keep track of the current screen in a local member variable
currentScreen = screen ; // Initialize the new screen
screen . initialize ( ) ; // Force the panel to redraw
panel . validate ( ) ;


signature:
public class UnaryPredicateConjunction { /** * Evaluates a logical predicate .
 * @ param t The object to test for predicate membership .
 * @ return < tt > true < / tt > if the object is a member of the predicate , < tt > false < / tt > otherwise . */
public boolean evaluate ( T t ) { } }

implementation:
// Start by assuming that the candidate will be a member of the predicate .
boolean passed = true ; // Loop through all predicates and fail if any one of them does .
for ( UnaryPredicate < T > predicate : chain ) { if ( ! predicate . evaluate ( t ) ) { passed = false ; break ; } } return passed ;


signature:
public class ContextualProperties { /** * Looks up a property value relative to the environment , callers class and method . The default environment will be
 * checked for a matching property if defaults are being used . In order to work out the callers class and method
 * this method throws an exception and then searches one level up its stack frames .
 * @ param key The property key .
 * @ return The value of this property searching from the most specific definition ( environment , class , method , key )
 * to the most general ( key only ) , unless use of default environments is turned off in which case the most
 * general proeprty searched is ( environment , key ) . */
public String getProperty ( String key ) { } }

implementation:
// Try to get the callers class name and method name by examing the stack .
String className = null ; String methodName = null ; // Java 1.4 onwards only .
/* try
 throw new Exception ( ) ;
 catch ( Exception e )
 StackTraceElement [ ] stack = e . getStackTrace ( ) ;
 / / Check that the stack trace contains at least two elements , one for this method and one for the caller .
 if ( stack . length > = 2)
 className = stack [ 1 ] . getClassName ( ) ;
 methodName = stack [ 1 ] . getMethodName ( ) ; */
// Java 1.5 onwards only .
StackTraceElement [ ] stack = Thread . currentThread ( ) . getStackTrace ( ) ; // Check that the stack trace contains at least two elements , one for this method and one for the caller .
if ( stack . length >= 2 ) { className = stack [ 1 ] . getClassName ( ) ; methodName = stack [ 1 ] . getMethodName ( ) ; } // Java 1.3 and before ? Not sure , some horrible thing that parses the text spat out by printStackTrace ?
return getProperty ( className , methodName , key ) ;


signature:
public class ContextualProperties { /** * Looks up a property value relative to the environment , base class and modifier . The default environment will be
 * checked for a matching property if defaults are being used .
 * @ param base An object of the class to retrieve properties relative to .
 * @ param modifier The modifier ( which may stand for a method of the class ) .
 * @ param key The property key .
 * @ return The value of this property searching from the most specific definition ( environment , class , modifier ,
 * key ) to the most general ( key only ) , unless use of default environments is turned off in which case the
 * most general property searched is ( environment , key ) . */
public String getProperty ( Object base , String modifier , String key ) { } }

implementation: return getProperty ( base . getClass ( ) . getName ( ) , modifier , key ) ;


signature:
public class ContextualProperties { /** * Looks up a property value relative to the environment , base class and modifier . The default environment will be
 * checked for a matching property if defaults are being used .
 * @ param base The name of the class to retrieve properties relative to .
 * @ param modifier The modifier ( which may stand for a method of the class ) .
 * @ param key The property key .
 * @ return The value of this property searching from the most specific definition ( environment , class , modifier ,
 * key ) to the most general ( key only ) , unless use of default environments is turned off in which case the
 * most general property searched is ( environment , key ) . */
public String getProperty ( String base , String modifier , String key ) { } }

implementation:
String result = null ; // Loop over the key orderings , from the most specific to the most general , until a matching value is found .
for ( Iterator i = getKeyIterator ( base , modifier , key ) ; i . hasNext ( ) ; ) { String nextKey = ( String ) i . next ( ) ; result = super . getProperty ( nextKey ) ; if ( result != null ) { break ; } } return result ;


signature:
public class ContextualProperties { /** * Looks up an array property value relative to the environment , callers class and method . The default environment
 * will be checked for a matching array property if defaults are being used . In order to work out the callers class
 * and method this method throws an exception and then searches one level up its stack frames .
 * @ param key The property key .
 * @ return The array value of this indexed property searching from the most specific definition ( environment , class ,
 * method , key ) to the most general ( key only ) , unless use of default environments is turned off in which
 * case the most general proeprty searched is ( environment , key ) . */
public String [ ] getProperties ( String key ) { } }

implementation:
// Try to get the callers class name and method name by throwing an exception an searching the stack frames .
String className = null ; String methodName = null ; /* Java 1.4 onwards only .
 try {
 throw new Exception ( ) ;
 } catch ( Exception e ) {
 StackTraceElement [ ] stack = e . getStackTrace ( ) ;
 / / Check that the stack trace contains at least two elements , one for this method and one for the caller .
 if ( stack . length > = 2 ) {
 className = stack [ 1 ] . getClassName ( ) ;
 methodName = stack [ 1 ] . getMethodName ( ) ; */
return getProperties ( className , methodName , key ) ;


signature:
public class ContextualProperties { /** * Looks up an array property value relative to the environment , base class and modifier . The default environment
 * will be checked for a matching array property if defaults are being used .
 * @ param base An object of the class to retrieve properties relative to .
 * @ param modifier The modifier ( which may stand for a method of the class ) .
 * @ param key The property key .
 * @ return The array value of this indexed property searching from the most specific definition ( environment , class ,
 * modifier , key ) to the most general ( key only ) , unless use of default environments is turned off in which
 * case the most general proeprty searched is ( environment , key ) . */
public String [ ] getProperties ( Object base , String modifier , String key ) { } }

implementation: return getProperties ( base . getClass ( ) . getName ( ) , modifier , key ) ;


signature:
public class ContextualProperties { /** * Looks up an array property value relative to the environment , base class and modifier . The default environment
 * will be checked for a matching array property if defaults are being used .
 * @ param base The name of the class to retrieve properties relative to .
 * @ param modifier The modifier ( which may stand for a method of the class ) .
 * @ param key The property key .
 * @ return The array value of this indexed property searching from the most specific definition ( environment , class ,
 * modifier , key ) to the most general ( key only ) , unless use of default environments is turned off in which
 * case the most general property searched is ( environment , key ) . */
public String [ ] getProperties ( String base , String modifier , String key ) { } }

implementation:
String [ ] result = null ; // Loop over the key orderings , from the most specific to the most general , until a matching value is found .
for ( Iterator i = getKeyIterator ( base , modifier , key ) ; i . hasNext ( ) ; ) { String nextKey = ( String ) i . next ( ) ; Collection arrayList = ( ArrayList ) arrayProperties . get ( nextKey ) ; if ( arrayList != null ) { result = ( String [ ] ) arrayList . toArray ( new String [ ] { } ) ; break ; } } return result ;


signature:
public class ContextualProperties { /** * For a given environment , base , modifier and key and setting of the use of default environments feature this
 * generates an iterator that walks over the order in which to try and access properties .
 * < p > See the { @ link # ORDER } constant for an explanation of how the key ordering is generated .
 * @ param base The name of the class to retrieve properties relative to .
 * @ param modifier The modifier ( which may stand for a method of the class ) .
 * @ param key The property key .
 * @ return An Iterator over String keys defining the order in which properties should be accessed . */
protected Iterator getKeyIterator ( final String base , final String modifier , final String key ) { } }

implementation:
return new Iterator ( ) { // The key ordering count always begins at the start of the ORDER array .
private int i ; public boolean hasNext ( ) { return ( useDefaults ? ( ( i < ORDER . length ) && ( ORDER [ i ] > ENVIRONMENT_DEFAULTS_CUTOFF ) ) : ( i < ORDER . length ) ) ; } public Object next ( ) { // Check that there is a next element and return null if not .
if ( ! hasNext ( ) ) { return null ; } // Get the next ordering count .
int o = ORDER [ i ] ; // Do bit matching on the count to choose which elements to include in the key .
String result = ( ( ( o & E ) != 0 ) ? ( environment + "." ) : "" ) + ( ( ( o & B ) != 0 ) ? ( base + "." ) : "" ) + ( ( ( o & M ) != 0 ) ? ( modifier + "." ) : "" ) + key ; // Increment the iterator to get the next key on the next call .
i ++ ; return result ; } public void remove ( ) { // This method is not supported .
throw new UnsupportedOperationException ( "remove() is not supported on this key order iterator as " + "the ordering cannot be changed" ) ; } } ;


signature:
public class ContextualProperties { /** * Scans all the properties in the parent Properties object and creates arrays for any array property definitions .
 * < p > Array properties are defined with indexes . For example :
 * < p > < code > property . 1 = one < br / >
 * property . 2 = two < br / >
 * property . 3 = three < br / >
 * < / code >
 * < p > Note that these properties will be stored as the ' empty string ' or " " property array .
 * < p > < code > . 1 = one < br / >
 * 2 = two < br / >
 * < / code > */
protected void createArrayProperties ( ) { } }

implementation:
// Scan through all defined properties .
for ( Object o : keySet ( ) ) { String key = ( String ) o ; String value = super . getProperty ( key ) ; // Split the property key into everything before the last ' . ' and after it .
int lastDotIndex = key . lastIndexOf ( '.' ) ; String keyEnding = key . substring ( lastDotIndex + 1 , key . length ( ) ) ; String keyStart = key . substring ( 0 , ( lastDotIndex == - 1 ) ? 0 : lastDotIndex ) ; // Check if the property key ends in an integer , in which case it is an array property .
int index = 0 ; try { index = Integer . parseInt ( keyEnding ) ; } catch ( NumberFormatException e ) { // The ending is not an integer so its not an array .
// Exception can be ignored as it means this property is not an array .
e = null ; continue ; } // Check if an array property already exists for this base name and create one if not .
ArrayList propArray = ( ArrayList ) arrayProperties . get ( keyStart ) ; if ( propArray == null ) { propArray = new ArrayList ( ) ; arrayProperties . put ( keyStart , propArray ) ; } // Add the new property value to the array property for the index .
propArray . set ( index , value ) ; }


signature:
public class LojixTermBuilder { /** * { @ inheritDoc } */
public Term build ( ) { } }

implementation: Term result ; if ( ! isCompound ( ) ) { result = getFunctor ( ) ; } else { if ( getFunctor ( ) . isAtom ( ) ) { List < Term > args = getArgs ( ) ; int arity = args . size ( ) ; Functor functor = ( Functor ) getFunctor ( ) ; int name = interner . internFunctorName ( interner . getFunctorName ( functor . getName ( ) ) , arity ) ; result = new Functor ( name , args . toArray ( new Term [ arity ] ) ) ; } else { throw new IllegalStateException ( "Invalid functor type." ) ; } } return result ;


signature:
public class BaseThrottle { /** * Specifies the throttling rate in operations per second . This must be called with with a value , the inverse of
 * which is a measurement in nano seconds , such that the number of nano seconds do not overflow a long integer . The
 * value must also be larger than zero .
 * @ param hertz The throttling rate in cycles per second . */
public void setRate ( float hertz ) { } }

implementation:
// Check that the argument is above zero .
if ( hertz <= 0.0f ) { throw new IllegalArgumentException ( "The throttle rate must be above zero." ) ; } // Calculate the cycle time .
cycleTimeNanos = ( long ) ( 1000000000f / hertz ) ; // Reset the first pass flag .
firstCall = false ; firstCheckCall = false ;


signature:
public class BaseThrottle { /** * This method can only be called at the rate set by the { @ link # setRate } method , if it is called faster than this
 * it will inject short pauses to restrict the call rate to that rate .
 * @ throws InterruptedException If interrupted whilst performing a blocking wait on the throttle . */
public void throttle ( ) throws InterruptedException { } }

implementation:
// Don ' t introduce any pause on the first call .
if ( ! firstCall ) { // Check if there is any time left in the cycle since the last throttle call to this method and introduce a
// short pause to fill that time if there is .
long remainingTimeNanos = timeToThrottleNanos ( ) ; while ( remainingTimeNanos > 0 ) { long milliPause = remainingTimeNanos / 1000000 ; int nanoPause = ( int ) ( remainingTimeNanos % 1000000 ) ; Thread . sleep ( milliPause , nanoPause ) ; remainingTimeNanos = timeToThrottleNanos ( ) ; } } else { firstCall = false ; }


signature:
public class BaseThrottle { /** * Checks but does not enforce the throttle rate . When this method is called , it checks if a length of time greater
 * than that equal to the inverse of the throttling rate has passed since it was last called and returned < tt >
 * true < / tt > . If the length of time still to elapse to the next throttle allow point is zero or less , this method
 * will return a negative value , if there is still time to pass until the throttle allow point , this method will
 * return a positive value indicating the amount of time still to pass . A thread can wait for that period of time
 * before rechecking the throttle condition .
 * @ return The length of time since or still to elaps to the next throttle allow point . A negative value indicates
 * that the throttle time has passed and a positive time indicates that there is still time to pass before
 * it is reached . The units are in nanoseconds . */
public long timeToThrottleNanos ( ) { } }

implementation: long now = System . nanoTime ( ) ; long remainingNanos = ( cycleTimeNanos + lastCheckTimeNanos ) - now ; if ( ( remainingNanos <= 0 ) ) { firstCheckCall = false ; lastCheckTimeNanos = now ; return remainingNanos ; } else if ( firstCheckCall ) { firstCheckCall = false ; lastCheckTimeNanos = now ; return 0 ; } else { return remainingNanos ; }


signature:
public class MapBackedState { /** * { @ inheritDoc } */
public void setProperty ( String name , Object value ) { } }

implementation:
// Set the type of the new property in the state type mapping .
componentType . addPropertyType ( name , TypeHelper . getTypeFromObject ( value ) ) ; // Add the new property to the property map .
properties . put ( name , value ) ;


signature:
public class UMinus { /** * Evaluates the arithmetic operator on its numeric argument .
 * @ param firstNumber The first argument .
 * @ return The result of performing the arithmetic operator on its argument . */
protected NumericType evaluate ( NumericType firstNumber ) { } }

implementation:
// If the argument is a real number , then use real number arithmetic , otherwise use integer arithmetic .
if ( firstNumber . isInteger ( ) ) { return new IntLiteral ( - firstNumber . intValue ( ) ) ; } else { return new DoubleLiteral ( - firstNumber . doubleValue ( ) ) ; }


signature:
public class PropertyReaderBase { /** * This methods attempts to load the properties from a file or URL referenced by the system property with the same
 * name as the properties resource name , from a resource on the classpath with the same name as the properties
 * resource name or from a properties file name relative to the current working directory . It tries these methods
 * sequentially one after the other until one succeeds . */
protected void findProperties ( ) { } }

implementation:
/* log . fine ( " findProperties : called " ) ; */
// Try to load the properties from a file referenced by the system property matching
// the properties file name .
properties = getPropertiesUsingSystemProperty ( ) ; if ( properties != null ) { /* log . fine ( " loaded properties using the system property " ) ; */
// The properties were succesfully located and loaded
return ; } /* log . fine ( " failed to get properties from the system properties " ) ; */
// Try to load the properties from a resource on the classpath using the current
// class loader
properties = getPropertiesUsingClasspath ( ) ; if ( properties != null ) { /* log . fine ( " loaded properties from the class path " ) ; */
// The properties were succesfully located and loaded
return ; } /* log . fine ( " failed to get properties from the classpath " ) ; */
// Try to load the properties from a file relative to the current working directory
properties = getPropertiesUsingCWD ( ) ; if ( properties != null ) { /* log . fine ( " loaded properties from the current working directory " ) ; */
// The properties were succesfully located and loaded
return ; } /* log . fine ( " failed to get properties from the current working directory " ) ; */


signature:
public class PropertyReaderBase { /** * Tries to load the properties from the file or URL named by the system property with name mathching the properties
 * resource name .
 * @ return The properties found under the file name or URL or null if none can be found there . */
protected Properties getPropertiesUsingSystemProperty ( ) { } }

implementation:
/* log . fine ( " getPropertiesUsingSystemProperty : called " ) ; */
// Get the path to the file from the system properties
/* log . fine ( " getPropertiesResourceName ( ) = " + getPropertiesResourceName ( ) ) ; */
String path = System . getProperty ( getPropertiesResourceName ( ) ) ; /* log . fine ( " properties resource name = " + getPropertiesResourceName ( ) ) ; */
/* log . fine ( " path = " + path ) ; */
// Use PropertiesHelper to try to load the properties from the path
try { return PropertiesHelper . getProperties ( path ) ; } catch ( IOException e ) { /* log . fine ( " Could not load properties from path " + path ) ; */
// Failure of this method is noted , so exception is ignored .
e = null ; } return null ;


signature:
public class PropertyReaderBase { /** * Tries to load the properties from the classpath using the classloader for this class .
 * @ return The properties loaded from the resource name under the classpath or null if none can be found there . */
protected Properties getPropertiesUsingClasspath ( ) { } }

implementation:
/* log . fine ( " getPropertiesUsingClasspath : called " ) ; */
// Try to open the properties resource name as an input stream from the classpath
InputStream is = this . getClass ( ) . getClassLoader ( ) . getResourceAsStream ( getPropertiesResourceName ( ) ) ; // Use PropertiesHelper to try to load the properties from the input stream if one was succesfully created
if ( is != null ) { try { return PropertiesHelper . getProperties ( is ) ; } catch ( IOException e ) { /* log . fine ( " Could not load properties from classpath " ) ; */
// Failure of this method is noted , so exception is ignored .
e = null ; } } return null ;


signature:
public class PropertyReaderBase { /** * Tries to load the properties as a file or URL matching the properties resource name . File names will be taken
 * relative to the current working directory .
 * @ return The properties found from the resource name as a file in the current working directory or null if none
 * can be found there . */
protected Properties getPropertiesUsingCWD ( ) { } }

implementation:
/* log . fine ( " getPropertiesUsingCWD : called " ) ; */
// Use PropertiesHelper to try to load the properties from a file or URl
try { return PropertiesHelper . getProperties ( getPropertiesResourceName ( ) ) ; } catch ( IOException e ) { /* log . fine ( " Could not load properties from file or URL " + getPropertiesResourceName ( ) ) ; */
// Failure of this method is noted , so exception is ignored .
e = null ; } return null ;


signature:
public class BuiltInTransformVisitor { /** * Applies the built - in transform during a post - fix visit of a term .
 * @ param functor The functor to visit . */
protected void leaveFunctor ( Functor functor ) { } }

implementation:
int pos = traverser . getPosition ( ) ; if ( ! traverser . isInHead ( ) && ( pos >= 0 ) ) { Functor transformed = builtInTransform . apply ( functor ) ; if ( functor != transformed ) { /* log . fine ( " Transformed : " + functor + " to " + transformed . getClass ( ) ) ; */
BuiltInFunctor builtInFunctor = ( BuiltInFunctor ) transformed ; Term parentTerm = traverser . getParentContext ( ) . getTerm ( ) ; if ( parentTerm instanceof Clause ) { Clause parentClause = ( Clause ) parentTerm ; parentClause . getBody ( ) [ pos ] = builtInFunctor ; } else if ( parentTerm instanceof Functor ) { Functor parentFunctor = ( Functor ) parentTerm ; parentFunctor . getArguments ( ) [ pos ] = builtInFunctor ; } } }


signature:
public class Variable { /** * Gets the actual value of a term , which is either the term itself , or in the case of variables , the value that is
 * currently assigned to the variable . When the variable is free , the variable term itself is returned .
 * @ return The term itself , or the assigned value of this variable . */
public Term getValue ( ) { } }

implementation:
Term result = this ; Term assignment = this . substitution ; // If the variable is assigned , loops down the chain of assignments until no more can be found . Whatever term
// is found at the end of the chain of assignments is the value of this variable .
while ( assignment != null ) { result = assignment ; if ( ! assignment . isVar ( ) ) { break ; } else { assignment = ( ( Variable ) assignment ) . substitution ; } } return result ;


signature:
public class Variable { /** * Binds this variable to the specified value .
 * @ param term The value to bind this variable to . */
public void setSubstitution ( Term term ) { } }

implementation:
Term termToBindTo = term ; // When binding against a variable , always bind to its storage cell and not the variable itself .
if ( termToBindTo instanceof Variable ) { Variable variableToBindTo = ( Variable ) term ; termToBindTo = variableToBindTo . getStorageCell ( variableToBindTo ) ; } substitution = termToBindTo ;


signature:
public class Variable { /** * { @ inheritDoc } */
public void accept ( TermVisitor visitor ) { } }

implementation: if ( visitor instanceof VariableVisitor ) { ( ( VariableVisitor ) visitor ) . visit ( this ) ; } else { super . accept ( visitor ) ; }


signature:
public class Variable { /** * { @ inheritDoc } */
public Variable acceptTransformer ( TermTransformer transformer ) { } }

implementation: if ( transformer instanceof VariableTransformer ) { return ( ( VariableTransformer ) transformer ) . transform ( this ) ; } else { return ( Variable ) super . acceptTransformer ( transformer ) ; }


signature:
public class Variable { /** * Compares this term for structural equality with another . Two terms are structurally equal if they are the same
 * functor with the same arguments , or are the same unbound variable , or the bound values of the left or right
 * variable operands are structurally equal . Structural equality is a stronger equality than unification and unlike
 * unification it does not produce any variable bindings . Two unified terms will always be structurally equal .
 * @ param term The term to compare with this one for structural equality .
 * @ return < tt > true < / tt > if the two terms are structurally eqaul , < tt > false < / tt > otherwise . */
public boolean structuralEquals ( Term term ) { } }

implementation:
Term comparator = term . getValue ( ) ; Term value = getValue ( ) ; // Check if this is an unbound variable in which case the comparator must be the same variable .
if ( value == this ) { return this . equals ( comparator ) ; } else { return value . structuralEquals ( comparator ) ; }


signature:
public class ASCIIByteBufferString { /** * { @ inheritDoc } */
public CharSequence subSequence ( int start , int end ) { } }

implementation: return new ASCIIByteBufferString ( data , offset + start , end - start ) ;


signature:
public class ASCIIByteBufferString { /** * { @ inheritDoc }
 * < p / > Two ASCII strings are compared using a lexicographical ordering . */
public int compareTo ( ASCIIString comparator ) { } }

implementation: int n = Math . min ( length , comparator . length ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { byte b1 = get ( i ) ; byte b2 = comparator . get ( i ) ; if ( b1 == b2 ) { continue ; } if ( b1 < b2 ) { return - 1 ; } return 1 ; } return length - comparator . length ( ) ;


signature:
public class ASCIIByteBufferString { /** * Computes and caches in the { @ link # stringValue } field , a representation of this string as a default Java String . */
private void computeStringValue ( ) { } }

implementation: char [ ] chars = new char [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { chars [ i ] = ( char ) data . get ( i + offset ) ; } stringValue = new String ( chars ) ;


signature:
public class ASCIIByteBufferString { /** * Computes and caches in the { @ link # hashCode } field , a hash code for this string . */
private void computeHashCode ( ) { } }

implementation: hashCode = 0 ; for ( int i = 0 ; i < length ; i ++ ) { hashCode = ( 31 * hashCode ) + data . get ( i + offset ) ; }


signature:
public class GreedySearch { /** * Creates the correct type of queue for this search . This search uses a priority queue ordered by heuristic value .
 * @ return An empty priority queue with heuristic ordering . */
public Queue < SearchNode < O , T > > createQueue ( ) { } }

implementation: return new PriorityQueue < SearchNode < O , T > > ( 11 , new GreedyComparator ( ) ) ;


signature:
public class SilentFailSocketAppender { /** * Drop the connection to the remote host and release the underlying connector thread if it has been created . */
public void cleanUp ( ) { } }

implementation:
if ( oos != null ) { try { oos . close ( ) ; } catch ( IOException e ) { LogLog . error ( "Could not close oos." , e ) ; } oos = null ; } if ( connector != null ) { // LogLog . debug ( " Interrupting the connector . " ) ;
connector . interrupted = true ; connector = null ; // allow gc
}


signature:
public class SilentFailSocketAppender { /** * Appends a logging event to the remote event reciever .
 * @ param event The logging event to send . */
public void append ( LoggingEvent event ) { } }

implementation:
if ( event == null ) { return ; } if ( address == null ) { errorHandler . error ( "No remote host is set for SocketAppender named \"" + this . name + "\"." ) ; return ; } if ( oos != null ) { try { if ( locationInfo ) { event . getLocationInformation ( ) ; } oos . writeObject ( event ) ; // LogLog . debug ( " = = = = = Flushing . " ) ;
oos . flush ( ) ; if ( ++ counter >= RESET_FREQUENCY ) { counter = 0 ; // Failing to reset the object output stream every now and
// then creates a serious memory leak .
// System . err . println ( " Doing oos . reset ( ) " ) ;
oos . reset ( ) ; } } catch ( IOException e ) { oos = null ; LogLog . warn ( "Detected problem with connection: " + e ) ; if ( reconnectionDelay > 0 ) { fireConnector ( ) ; } } }


signature:
public class SilentFailSocketAppender { /** * Connects to remote server at < code > address < / code > and < code > port < / code > .
 * @ param address The address to connect to .
 * @ param port The port to connect to . */
void connect ( InetAddress address , int port ) { } }

implementation:
if ( this . address == null ) { return ; } try { // First , close the previous connection if any .
cleanUp ( ) ; Socket socket = new Socket ( ) ; SocketAddress socketAddr = new InetSocketAddress ( address , port ) ; socket . connect ( socketAddr , 10 ) ; oos = new ObjectOutputStream ( socket . getOutputStream ( ) ) ; } catch ( IOException e ) { // Silently fail and do not retry later .
// Exception noted so can be ignored .
e = null ; /* * String msg = " Could not connect to remote log4j server at [ " + address . getHostName ( ) + " ] . " ;
 * if ( reconnectionDelay > 0 ) { msg + = " We will try again later . " ; fireConnector ( ) ; / / fire the connector
 * thread } LogLog . error ( msg , e ) ; */
}


signature:
public class SilentFailSocketAppender { /** * Starts a new connector thread to do ? */
void fireConnector ( ) { } }

implementation: if ( connector == null ) { LogLog . debug ( "Starting a new connector thread." ) ; connector = new Connector ( ) ; connector . setDaemon ( true ) ; connector . setPriority ( Thread . MIN_PRIORITY ) ; connector . start ( ) ; }


signature:
public class WAMCompiledTermsPrintingVisitor { /** * { @ inheritDoc } */
public void visit ( Predicate predicate ) { } }

implementation: for ( AllTermsVisitor printer : printers ) { printer . visit ( predicate ) ; } super . visit ( predicate ) ;


signature:
public class WAMCompiledTermsPrintingVisitor { /** * { @ inheritDoc } */
public void visit ( Clause clause ) { } }

implementation: for ( AllTermsVisitor printer : printers ) { printer . visit ( clause ) ; } super . visit ( clause ) ;


signature:
public class WAMCompiledTermsPrintingVisitor { /** * { @ inheritDoc } */
public void visit ( Functor functor ) { } }

implementation: for ( AllTermsVisitor printer : printers ) { printer . visit ( functor ) ; } super . visit ( functor ) ;


signature:
public class WAMCompiledTermsPrintingVisitor { /** * { @ inheritDoc } */
public void visit ( Variable variable ) { } }

implementation: for ( AllTermsVisitor printer : printers ) { printer . visit ( variable ) ; } super . visit ( variable ) ;


signature:
public class WAMCompiledTermsPrintingVisitor { /** * Sets up the stack of column printers . */
protected void initializePrinters ( ) { } }

implementation: int maxColumns = 0 ; printers . add ( new SourceClausePrinter ( interner , symbolTable , traverser , maxColumns ++ , printTable ) ) ; printers . add ( new PositionPrinter ( interner , symbolTable , traverser , maxColumns ++ , printTable ) ) ; printers . add ( new UnoptimizedLabelPrinter ( interner , symbolTable , traverser , maxColumns ++ , printTable ) ) ; printers . add ( new UnoptimizedByteCodePrinter ( interner , symbolTable , traverser , maxColumns ++ , printTable ) ) ; printers . add ( new LabelPrinter ( interner , symbolTable , traverser , maxColumns ++ , printTable ) ) ; printers . add ( new ByteCodePrinter ( interner , symbolTable , traverser , maxColumns ++ , printTable ) ) ;


signature:
public class WAMCompiledTermsPrintingVisitor { /** * Assembles the accumulated output in all rows and columns into a table . The table is appended onto { @ link # result } */
protected void printTable ( ) { } }

implementation: for ( int i = 0 ; i < printTable . getRowCount ( ) ; i ++ ) { for ( int j = 0 ; j < printTable . getColumnCount ( ) ; j ++ ) { String valueToPrint = printTable . get ( j , i ) ; valueToPrint = ( valueToPrint == null ) ? "" : valueToPrint ; result . append ( valueToPrint ) ; Integer maxColumnSize = printTable . getMaxColumnSize ( j ) ; int padding = ( ( maxColumnSize == null ) ? 0 : maxColumnSize ) - valueToPrint . length ( ) ; padding = ( padding < 0 ) ? 0 : padding ; for ( int s = 0 ; s < padding ; s ++ ) { result . append ( " " ) ; } result . append ( " % " ) ; } result . append ( "\n" ) ; }


signature: public class MicrodataDocumentTck { @ Test public void getItemsWhenItemReturnsItem ( ) throws MalformedURLException { } }

implementation:
server ( ) . enqueue ( new MockResponse ( ) . setBody ( "" + "
" + "" ) ) ; List < MicrodataItem > actual = newBrowser ( ) . get ( url ( server ( ) ) ) . getItems ( "http://x" ) ; assertThat ( "items" , actual , contains ( item ( "http://y" ) ) ) ;


signature: public class MicrodataDocumentTck { @ Test public void getLinkWhenAnchorReturnsLink ( ) throws MalformedURLException { } }

implementation: server ( ) . enqueue ( new MockResponse ( ) . setBody ( "" + "" + "" ) ) ; Link actual = newBrowser ( ) . get ( url ( server ( ) ) ) . getLink ( "x" ) ; assertThat ( "link" , actual , is ( link ( "x" , "http://y/" ) ) ) ;


signature: public class MicrodataDocumentTck { @ Test public void getFormReturnsForm ( ) { } }

implementation: server ( ) . enqueue ( new MockResponse ( ) . setBody ( "" + "<form name='x'/>" + "" ) ) ; Form actual = newBrowser ( ) . get ( url ( server ( ) ) ) . getForm ( "x" ) ; assertThat ( "form" , actual . getName ( ) , is ( "x" ) ) ;


signature: public class MicrodataDocumentTck { @ Test public void unwrapWithUnknownTypeThrowsException ( ) { } }

implementation: server ( ) . enqueue ( new MockResponse ( ) . setBody ( "<html><body/></html>" ) ) ; MicrodataDocument document = newBrowser ( ) . get ( url ( server ( ) ) ) ; thrown ( ) . expect ( IllegalArgumentException . class ) ; thrown ( ) . expectMessage ( "Cannot unwrap to: class java.lang.Void" ) ; document . unwrap ( Void . class ) ;


signature: public class FormTck { @ Test public void getControlReturnsControl ( ) { } }

implementation: server ( ) . enqueue ( new MockResponse ( ) . setBody ( "" + "<form name='f'>" + "<input type='text' name='x'/>" + "</form>" + "" ) ) ; Control actual = newBrowser ( ) . get ( url ( server ( ) ) ) . getForm ( "f" ) . getControl ( "x" ) ; assertThat ( "form control" , actual . getName ( ) , is ( "x" ) ) ;


signature: public class FormTck { @ Test public void getControlValueReturnsInitialValue ( ) { } }

implementation: server ( ) . enqueue ( new MockResponse ( ) . setBody ( "" + "<form name='f'>" + "<input type='text' name='x' value='y'/>" + "</form>" + "" ) ) ; String actual = newBrowser ( ) . get ( url ( server ( ) ) ) . getForm ( "f" ) . getControlValue ( "x" ) ; assertThat ( "form control value" , actual , is ( "y" ) ) ;


signature: public class FormTck { @ Test public void setControlValueSetsValue ( ) { } }

implementation: server ( ) . enqueue ( new MockResponse ( ) . setBody ( "" + "<form name='f'>" + "<input type='text' name='x' value='y'/>" + "</form>" + "" ) ) ; Form form = newBrowser ( ) . get ( url ( server ( ) ) ) . getForm ( "f" ) ; form . setControlValue ( "x" , "y" ) ; assertThat ( "form control value" , form . getControlValue ( "x" ) , is ( "y" ) ) ;


signature: public class FormTck { @ Test public void getControlGroupReturnsControlGroup ( ) { } }

implementation: server ( ) . enqueue ( new MockResponse ( ) . setBody ( "" + "<form name='f'>" + "<input type='text' name='x'/>" + "<input type='text' name='x'/>" + "</form>" + "" ) ) ; ControlGroup actual = newBrowser ( ) . get ( url ( server ( ) ) ) . getForm ( "f" ) . getControlGroup ( "x" ) ; assertThat ( "form control group" , actual . getName ( ) , is ( "x" ) ) ;


signature: public class FormTck { @ Test public void submitWhenSubmitInputSubmitsRequest ( ) throws InterruptedException { } }

implementation: server ( ) . enqueue ( new MockResponse ( ) . setBody ( "" + "<form name='f' action='/x'>" + "<input type='submit'/>" + "</form>" + "" ) ) ; server ( ) . enqueue ( new MockResponse ( ) ) ; newBrowser ( ) . get ( url ( server ( ) ) ) . getForm ( "f" ) . submit ( ) ; server ( ) . takeRequest ( ) ; assertThat ( "request" , takeRequest ( server ( ) ) . getPath ( ) , is ( "/x" ) ) ;


signature: public class FormTck { @ Test public void unwrapWithUnknownTypeThrowsException ( ) { } }

implementation: server ( ) . enqueue ( new MockResponse ( ) . setBody ( "" + "<form name='x'/>" + "" ) ) ; Form form = newBrowser ( ) . get ( url ( server ( ) ) ) . getForm ( "x" ) ; thrown ( ) . expect ( IllegalArgumentException . class ) ; thrown ( ) . expectMessage ( "Cannot unwrap to: class java.lang.Void" ) ; form . unwrap ( Void . class ) ;


signature:
public class SourceClausePrinter { /** * { @ inheritDoc } */
protected void enterFunctor ( Functor functor ) { } }

implementation: String showContextAs = interner . getFunctorName ( functor ) + ( functor . isAtom ( ) ? "" : "(" ) ; int delta = showContextAs . length ( ) ; addLineToRow ( indent + showContextAs ) ; nextRow ( ) ; indent = indenter . generateTraceIndent ( delta ) ;


signature:
public class SourceClausePrinter { /** * { @ inheritDoc } */
protected void leaveFunctor ( Functor functor ) { } }

implementation: String toAppend = indent ; boolean addData = false ; if ( functor . isCompound ( ) ) { toAppend += ")" ; addData = true ; } if ( ! traverser . isInHead ( ) && ! traverser . isLastBodyFunctor ( ) && traverser . isTopLevel ( ) ) { toAppend += "," ; addData = true ; } if ( traverser . isInHead ( ) && traverser . isTopLevel ( ) ) { toAppend += " :-" ; addData = true ; } if ( addData ) { addLineToRow ( toAppend ) ; nextRow ( ) ; } indent = indenter . generateTraceIndent ( - indenter . getLastDelta ( ) ) ;


signature:
public class SourceClausePrinter { /** * { @ inheritDoc } */
protected void enterVariable ( Variable variable ) { } }

implementation: String showContextAs = interner . getVariableName ( variable ) ; int delta = showContextAs . length ( ) ; addLineToRow ( indent + showContextAs ) ; nextRow ( ) ; indent = indenter . generateTraceIndent ( delta ) ;


signature: public class DefaultControlGroup { private static String getCheckedValue ( Control control ) { } }

implementation: if ( control instanceof CheckableControl ) { return ( ( CheckableControl ) control ) . getCheckedValue ( ) ; } return control . getValue ( ) ;


signature:
public class True { /** * { @ inheritDoc } */
public SizeableLinkedList < WAMInstruction > compileBodyCall ( Functor expression , boolean isFirstBody , boolean isLastBody , boolean chainRule , int permVarsRemaining ) { } }

implementation: SizeableLinkedList < WAMInstruction > result = new SizeableLinkedList < WAMInstruction > ( ) ; if ( isLastBody ) { if ( ! chainRule ) { result . add ( new WAMInstruction ( WAMInstruction . WAMInstructionSet . Deallocate ) ) ; } result . add ( new WAMInstruction ( WAMInstruction . WAMInstructionSet . Proceed ) ) ; } return result ;


signature:
public class GlobalWriteLockWithWriteBehindTxMethod { /** * When operating in transactional mode causes any changes since the last commit to be made visible to the search
 * method . */
public void commit ( ) { } }

implementation:
TxId txId = null ; // Check if in a higher transactional mode than none , otherwise commit does nothing .
if ( ! getIsolationLevel ( ) . equals ( IsolationLevel . None ) ) { // Extract the current transaction id .
txId = TxManager . getTxIdFromThread ( ) ; // Wait until the global write lock can be acquired by this transaction .
try { acquireGlobalWriteLock ( txId ) ; } catch ( InterruptedException e ) { // The commit was interrupted , so cannot succeed .
throw new IllegalStateException ( "Interrupted whilst commit is waiting for global write lock." , e ) ; } // Check that this transaction has made changes to be committed .
List < TxOperation > alterations = txWrites . get ( txId ) ; try { if ( alterations != null ) { // Loop through all the writes that the transaction wants to apply to the resource .
for ( TxOperation nextAlteration : alterations ) { // Apply the change and update the term resource .
nextAlteration . execute ( ) ; } // Clear the write behind cache for this transaction as its work has been completed .
txWrites . remove ( txId ) ; } } finally { // Release the global write lock .
releaseGlobalWriteLock ( ) ; } }


signature:
public class GlobalWriteLockWithWriteBehindTxMethod { /** * When operation in transactional mode causes any changes since the last commit to be dropped and never made
 * visible to the search method . */
public void rollback ( ) { } }

implementation:
TxId txId = null ; // Check if in a higher transactional mode than none , otherwise commit does nothing .
if ( ! getIsolationLevel ( ) . equals ( IsolationLevel . None ) ) { // Extract the current transaction id .
txId = TxManager . getTxIdFromThread ( ) ; // Check that this transaction has made changes to be rolled back .
List < TxOperation > alterations = txWrites . get ( txId ) ; if ( alterations != null ) { // Loop through all the writes that the transaction wants to apply to the resource .
for ( TxOperation nextAlteration : alterations ) { // Cancel the operation .
nextAlteration . cancel ( false ) ; } } // Discard all the changes that the transaction was going to make .
txWrites . remove ( txId ) ; }


signature:
public class GlobalWriteLockWithWriteBehindTxMethod { /** * Requests an operation that alters the transactional resource . This may be blocked until an appropriate lock can
 * be acquired , delayed until commit time , or actioned upon a copy of the data structure private to a transaction
 * branch .
 * < p / > This stores the requested operation for execution at commit time , unless running in non - transactional mode in
 * which case it is run immediately .
 * @ param op The write operation as a future . */
public void requestWriteOperation ( TxOperation op ) { } }

implementation:
// Check if in a higher transactional mode than none and capture the transaction id if so .
TxId txId = null ; if ( getIsolationLevel ( ) . compareTo ( IsolationLevel . None ) > 0 ) { // Extract the current transaction id .
txId = TxManager . getTxIdFromThread ( ) ; // Ensure that this resource is enlisted with the current session .
enlistWithSession ( ) ; } // For non - transactional isolation levels , apply the requested operation immediately .
if ( getIsolationLevel ( ) . equals ( IsolationLevel . None ) ) { op . execute ( ) ; } // Add the operation to the transaction write - behind cache for the transaction id , if using transactional
// isolation , to defer the operation untill commit time .
else { addCachedOperation ( txId , op ) ; }


signature:
public class GlobalWriteLockWithWriteBehindTxMethod { /** * Adds a transactional operation to the transactional write - behind cache for the specified transaction . If no cache
 * exists for the specified transaction id , a new one is created .
 * @ param txId The transaction id to store the operation against .
 * @ param cachedWriteOperation The operation to store . */
private void addCachedOperation ( TxId txId , TxOperation cachedWriteOperation ) { } }

implementation: List < TxOperation > writeCache = txWrites . get ( txId ) ; if ( writeCache == null ) { writeCache = new ArrayList < TxOperation > ( ) ; txWrites . put ( txId , writeCache ) ; } writeCache . add ( cachedWriteOperation ) ;


signature:
public class GlobalWriteLockWithWriteBehindTxMethod { /** * Waits until the global write lock can be acquired by the specified transaction .
 * @ param txId The transaction id to acquite the global write lock for .
 * @ throws InterruptedException If interrupted whilst waiting for the global write lock . */
private void acquireGlobalWriteLock ( TxId txId ) throws InterruptedException { } }

implementation:
// Get the global write lock to ensure only one thread at a time can execute this code .
globalLock . writeLock ( ) . lock ( ) ; // Use a try block so that the corresponding finally block guarantees release of the thread lock .
try { // Check that this transaction does not already own the lock .
if ( ! txId . equals ( globalWriteLockTxId ) ) { // Wait until the write lock becomes free .
while ( globalWriteLockTxId != null ) { globalWriteLockFree . await ( ) ; } // Assign the global write lock to this transaction .
globalWriteLockTxId = txId ; } } finally { // Ensure that the thread lock is released once assignment of the write lock to the transaction is complete .
globalLock . writeLock ( ) . unlock ( ) ; }


signature:
public class GlobalWriteLockWithWriteBehindTxMethod { /** * Releases the global write lock from being assigned to a transaction . */
private void releaseGlobalWriteLock ( ) { } }

implementation:
// Get the global write lock to ensure only one thread at a time can execute this code .
globalLock . writeLock ( ) . lock ( ) ; // Use a try block so that the corresponding finally block guarantees release of the thread lock .
try { // Release the global write lock , assigning it to no transaction .
globalWriteLockTxId = null ; // Signal that the write lock is now free .
globalWriteLockFree . signal ( ) ; } // Ensure that the thread lock is released once assignment of the write lock to the transaction is complete .
finally { globalLock . writeLock ( ) . unlock ( ) ; }


signature:
public class GlobalWriteLockWithWriteBehindTxMethod { /** * Enlists this transactional resource with the current session . If no session exists this will fail .
 * @ throws IllegalStateException If this resource is transactional and accessed outside of a transaction . */
private void enlistWithSession ( ) { } }

implementation:
TxSession session = TxSessionImpl . getCurrentSession ( ) ; // Ensure that this resource is being used within a session .
if ( session == null ) { throw new IllegalStateException ( "Cannot access transactional resource outside of a session." ) ; } // Ensure that this resource is enlisted with the session .
session . enlist ( this ) ;


signature:
public class NestedMediaQueries { /** * Locates nested MediaQueryNode inside RuleSetNode ,
 * separates RuleSetNode and MediaQueryNode
 * If MediaQueryNode has nested RuleSetNodes than to every
 * nested selectors will added selector of input RuleSetNode
 * If MediaQueryNode has other nodes except WhiteSpaceCollectionNode and
 * RuleSetNode than all of that will be wrapped with new RuleSetNode with
 * the same selectors as has input RuleSetNode */
@ Override public boolean enter ( RuleSetNode ruleSetNode ) { } }

implementation:
ScopeNode scopeNode = NodeTreeUtils . getFirstChild ( ruleSetNode , ScopeNode . class ) ; SelectorGroupNode selectorGroupNode = NodeTreeUtils . getFirstChild ( ruleSetNode , SelectorGroupNode . class ) ; if ( selectorGroupNode == null ) { return true ; } List < SelectorNode > selectorNodes = NodeTreeUtils . getChildren ( selectorGroupNode , SelectorNode . class ) ; if ( selectorNodes . size ( ) < 0 ) { return true ; } List < MediaQueryNode > mediaQueryNodes = NodeTreeUtils . getAndRemoveChildren ( scopeNode , MediaQueryNode . class ) ; for ( MediaQueryNode mediaQueryNode : mediaQueryNodes ) { ScopeNode mediaScopeNode = NodeTreeUtils . getFirstChild ( mediaQueryNode , ScopeNode . class ) ; List < RuleSetNode > nestedRuleSets = NodeTreeUtils . getAndRemoveChildren ( mediaScopeNode , RuleSetNode . class ) ; // if scope node for media query has anything more but whitespaces and rule sets than wrap it with rule set with the same selector group as outer rule set has
if ( mediaScopeNode . getChildren ( ) . size ( ) > NodeTreeUtils . getChildren ( mediaScopeNode , WhiteSpaceCollectionNode . class ) . size ( ) ) { RuleSetNode newRuleSetNode = new RuleSetNode ( ) ; ScopeNode newScopeNode = new ScopeNode ( ) ; newRuleSetNode . addChild ( selectorGroupNode . clone ( ) ) ; newRuleSetNode . addChild ( newScopeNode ) ; NodeTreeUtils . moveChildren ( mediaScopeNode , newScopeNode ) ; mediaScopeNode . clearChildren ( ) ; mediaScopeNode . addChild ( newRuleSetNode ) ; } // adding outer selectors to every nested selectors
for ( RuleSetNode nestedRuleSet : nestedRuleSets ) { List < SelectorGroupNode > nestedSelectorGroupNodes = NodeTreeUtils . getChildren ( nestedRuleSet , SelectorGroupNode . class ) ; for ( SelectorGroupNode nestedSelectorGroupNode : nestedSelectorGroupNodes ) { List < SelectorNode > nestedSelectorNodes = NodeTreeUtils . getAndRemoveChildren ( nestedSelectorGroupNode , SelectorNode . class ) ; NodeTreeUtils . getAndRemoveChildren ( nestedSelectorGroupNode , SpacingNode . class ) ; for ( SelectorNode selectorNode : selectorNodes ) { for ( SelectorNode nestedSelectorNode : nestedSelectorNodes ) { if ( nestedSelectorNode . getChildren ( ) . get ( 0 ) != null ) { if ( nestedSelectorNode . getChildren ( ) . get ( 0 ) instanceof SelectorSegmentNode ) { SelectorSegmentNode selectorSegmentNode = ( SelectorSegmentNode ) nestedSelectorNode . getChildren ( ) . get ( 0 ) ; selectorSegmentNode . setCombinator ( " " ) ; } } for ( int j = selectorNode . getChildren ( ) . size ( ) - 1 ; j >= 0 ; j -- ) { if ( selectorNode . getChildren ( ) . get ( j ) instanceof SelectorSegmentNode ) { SelectorSegmentNode selectorSegmentNode = ( SelectorSegmentNode ) selectorNode . getChildren ( ) . get ( j ) . clone ( ) ; nestedSelectorNode . addChild ( 0 , selectorSegmentNode ) ; } } nestedSelectorGroupNode . addChild ( nestedSelectorNode ) ; nestedSelectorGroupNode . addChild ( new SpacingNode ( " " ) ) ; } } } mediaScopeNode . addChild ( nestedRuleSet ) ; } if ( ruleSetNode . getParent ( ) != null ) { ruleSetNode . getParent ( ) . addChild ( new SpacingNode ( "\n" ) ) ; ruleSetNode . getParent ( ) . addChild ( mediaQueryNode ) ; } } return true ;


signature:
public class BatchSynchQueueBase { /** * Inserts the specified element into this queue , if possible . When using queues that may impose insertion
 * restrictions ( for example capacity bounds ) , method < tt > offer < / tt > is generally preferable to method
 * { @ link java . util . Collection # add } , which can fail to insert an element only by throwing an exception .
 * @ param e The element to insert , may not be null .
 * @ return < tt > true < / tt > if it was possible to add the element to this queue , else < tt > false < / tt >
 * @ throws IllegalArgumentException If the specified element is < tt > null < / tt > . */
public boolean offer ( E e ) { } }

implementation: if ( e == null ) { throw new IllegalArgumentException ( "The 'e' parameter may not be null." ) ; } ReentrantLock lock = this . lock ; lock . lock ( ) ; try { return insert ( e , false ) ; } finally { lock . unlock ( ) ; }


signature:
public class BatchSynchQueueBase { /** * Inserts the specified element into this queue , waiting if necessary up to the specified wait time for space to
 * become available .
 * @ param e The element to add , may not be null .
 * @ param timeout How long to wait before giving up , in units of < tt > unit < / tt >
 * @ param unit A < tt > TimeUnit < / tt > determining how to interpret the < tt > timeout < / tt > parameter .
 * @ return < tt > true < / tt > if successful , or < tt > false < / tt > if the specified waiting time elapses before space is
 * available .
 * @ throws InterruptedException If interrupted while waiting .
 * @ throws IllegalArgumentException If the specified element is < tt > null < / tt > . */
public boolean offer ( E e , long timeout , TimeUnit unit ) throws InterruptedException { } }

implementation:
if ( e == null ) { throw new IllegalArgumentException ( "The 'e' parameter may not be null." ) ; } ReentrantLock lock = this . lock ; lock . lockInterruptibly ( ) ; long nanos = unit . toNanos ( timeout ) ; try { do { if ( insert ( e , false ) ) { return true ; } try { nanos = notFull . awaitNanos ( nanos ) ; } catch ( InterruptedException ie ) { // Wake up another thread waiting on notFull , as the condition may be true , but this thread
// was interrupted so cannot make use of it .
notFull . signal ( ) ; throw ie ; } } while ( nanos > 0 ) ; return false ; } finally { lock . unlock ( ) ; }


signature:
public class BatchSynchQueueBase { /** * Retrieves and removes the head of this queue , or < tt > null < / tt > if this queue is empty .
 * @ return The head of this queue , or < tt > null < / tt > if this queue is empty . */
public E poll ( ) { } }

implementation: ReentrantLock lock = this . lock ; lock . lock ( ) ; try { if ( count == 0 ) { return null ; } return extract ( true , true ) . getElement ( ) ; } finally { lock . unlock ( ) ; }


signature:
public class BatchSynchQueueBase { /** * Retrieves and removes the head of this queue , waiting if necessary up to the specified wait time if no elements
 * are present on this queue .
 * @ param timeout How long to wait before giving up , in units of < tt > unit < / tt > .
 * @ param unit A < tt > TimeUnit < / tt > determining how to interpret the < tt > timeout < / tt > parameter .
 * @ return The head of this queue , or < tt > null < / tt > if the specified waiting time elapses before an element is
 * present .
 * @ throws InterruptedException If interrupted while waiting . */
public E poll ( long timeout , TimeUnit unit ) throws InterruptedException { } }

implementation:
ReentrantLock lock = this . lock ; lock . lockInterruptibly ( ) ; try { long nanos = unit . toNanos ( timeout ) ; do { if ( count != 0 ) { return extract ( true , true ) . getElement ( ) ; } try { nanos = notEmpty . awaitNanos ( nanos ) ; } catch ( InterruptedException ie ) { notEmpty . signal ( ) ; // propagate to non - interrupted thread
throw ie ; } } while ( nanos > 0 ) ; return null ; } finally { lock . unlock ( ) ; }


signature:
public class BatchSynchQueueBase { /** * Retrieves , but does not remove , the head of this queue , returning < tt > null < / tt > if this queue is empty .
 * @ return The head of this queue , or < tt > null < / tt > if this queue is empty . */
public E peek ( ) { } }

implementation: ReentrantLock lock = this . lock ; lock . lock ( ) ; try { return peekAtBufferHead ( ) ; } finally { lock . unlock ( ) ; }


signature:
public class BatchSynchQueueBase { /** * Adds the specified element to this queue , waiting if necessary for space to become available .
 * < p / > This method delegated to { @ link # tryPut } which can raise { @ link SynchException } s . If any are raised this
 * method silently ignores them . Use the { @ link # tryPut } method directly if you want to catch these exceptions .
 * @ param e The element to add .
 * @ throws InterruptedException If interrupted while waiting . */
public void put ( E e ) throws InterruptedException { } }

implementation:
try { tryPut ( e ) ; } catch ( SynchException ex ) { // This exception is deliberately ignored . See the method comment for information about this .
ex = null ; }


signature:
public class BatchSynchQueueBase { /** * Tries a synchronous put into the queue . If a consumer encounters an exception condition whilst processing the
 * data that is put , then this is returned to the caller wrapped inside a { @ link SynchException } .
 * @ param e The data element to put into the queue , may not be null .
 * @ throws InterruptedException If the thread is interrupted whilst waiting to write to the queue or whilst
 * waiting on its entry in the queue being consumed .
 * @ throws SynchException If a consumer encounters an error whilst processing the data element .
 * @ throws IllegalArgumentException If the specified element is < tt > null < / tt > . */
public void tryPut ( E e ) throws InterruptedException , SynchException { } }

implementation:
if ( e == null ) { throw new IllegalArgumentException ( "The 'e' parameter may not be null." ) ; } // final Queue < E > items = this . buffer ;
ReentrantLock lock = this . lock ; lock . lockInterruptibly ( ) ; try { while ( getBufferRemainingCapacity ( ) == 0 ) { // Release the lock and wait until the queue is not full .
notFull . await ( ) ; } } catch ( InterruptedException ie ) { notFull . signal ( ) ; // propagate to non - interrupted thread
throw ie ; } // There is room in the queue so insert must succeed . Insert into the queu , release the lock and block
// the producer until its data is taken .
insert ( e , true ) ;


signature:
public class BatchSynchQueueBase { /** * Retrieves and removes the head of this queue , waiting if no elements are present on this queue . Any producer that
 * has its data element taken by this call will be immediately unblocked . To keep the producer blocked whilst taking
 * just a single item , use the { @ link # drainTo ( java . util . Collection < SynchRecord < E > > , int , boolean ) } method . There
 * is no take method to do that because there is not usually any advantage in a synchronous hand off design that
 * consumes data one item at a time . It is normal to consume data in chunks to ammortize consumption latencies
 * accross many producers where possible .
 * @ return The head of this queue .
 * @ throws InterruptedException if interrupted while waiting . */
public E take ( ) throws InterruptedException { } }

implementation:
ReentrantLock lock = this . lock ; lock . lockInterruptibly ( ) ; try { try { while ( count == 0 ) { // Release the lock and wait until the queue becomes non - empty .
notEmpty . await ( ) ; } } catch ( InterruptedException ie ) { notEmpty . signal ( ) ; // propagate to non - interrupted thread
throw ie ; } // There is data in the queue so extraction must succeed . Notify any waiting threads that the queue is
// not full , and unblock the producer that owns the data item that is taken .
return extract ( true , true ) . getElement ( ) ; } finally { lock . unlock ( ) ; }


signature:
public class BatchSynchQueueBase { /** * Removes at most the given number of available elements from this queue and adds them into the given collection . A
 * failure encountered while attempting to < tt > add < / tt > elements to collection < tt > c < / tt > may result in elements
 * being in neither , either or both collections when the associated exception is thrown . Attempts to drain a queue
 * to itself result in < tt > IllegalArgumentException < / tt > . Further , the behavior of this operation is undefined if
 * the specified collection is modified while the operation is in progress .
 * @ param collection The collection to transfer elements into .
 * @ param maxElements The maximum number of elements to transfer . If this is - 1 then that is interpreted as meaning
 * all elements .
 * @ return The number of elements transferred .
 * @ throws IllegalArgumentException If collection is this queue or null . */
public int drainTo ( Collection < ? super E > collection , int maxElements ) { } }

implementation:
if ( collection == null ) { throw new IllegalArgumentException ( "The 'collection' parameter may not be null." ) ; } if ( collection == this ) { throw new IllegalArgumentException ( "The 'collection' parameter may not be this object." ) ; } // final Queue < E > items = this . buffer ;
ReentrantLock lock = this . lock ; lock . lock ( ) ; try { int n = 0 ; for ( int max = ( ( maxElements >= count ) || ( maxElements < 0 ) ) ? count : maxElements ; n < max ; n ++ ) { // Take items from the queue , do unblock the producers , but don ' t send not full signals yet .
collection . add ( extract ( true , false ) . getElement ( ) ) ; } if ( n > 0 ) { // count - = n ;
notFull . signalAll ( ) ; } return n ; } finally { lock . unlock ( ) ; }


signature:
public class BatchSynchQueueBase { /** * Takes all available data items from the queue or blocks until some become available . The returned items are
 * wrapped in a { @ link SynchRecord } which provides an interface to requeue them or send errors to their producers ,
 * where the producers are still blocked .
 * @ param c The collection to drain the data items into .
 * @ param unblock If set to < tt > true < / tt > the producers for the taken items will be immediately unblocked .
 * @ return A count of the number of elements that were drained from the queue . */
public SynchRef drainTo ( Collection < SynchRecord < E > > c , boolean unblock ) { } }

implementation: return drainTo ( c , - 1 , unblock ) ;


signature:
public class BatchSynchQueueBase { /** * Takes up to maxElements available data items from the queue or blocks until some become available . The returned
 * items are wrapped in a { @ link SynchRecord } which provides an interface to requeue them or send errors to their
 * producers , where the producers are still blocked .
 * @ param collection The collection to drain the data items into .
 * @ param maxElements The maximum number of elements to drain .
 * @ param unblock If set to < tt > true < / tt > the producers for the taken items will be immediately unblocked .
 * @ return A count of the number of elements that were drained from the queue .
 * @ throws IllegalArgumentException If collection is this queue or null . */
public SynchRef drainTo ( Collection < SynchRecord < E > > collection , int maxElements , boolean unblock ) { } }

implementation:
if ( collection == null ) { throw new IllegalArgumentException ( "The 'collection' parameter may not be null." ) ; } if ( collection == this ) { throw new IllegalArgumentException ( "The 'collection' parameter may not be this object." ) ; } // final Queue < E > items = this . buffer ;
ReentrantLock lock = this . lock ; lock . lock ( ) ; try { int n = 0 ; for ( int max = ( ( maxElements >= count ) || ( maxElements < 0 ) ) ? count : maxElements ; n < max ; n ++ ) { // Extract the next record from the queue , don ' t signal the not full condition yet and release
// producers depending on whether the caller wants to or not .
collection . add ( extract ( false , unblock ) ) ; } if ( n > 0 ) { // count - = n ;
notFull . signalAll ( ) ; } return new SynchRefImpl ( n , collection ) ; } finally { lock . unlock ( ) ; }


signature:
public class BatchSynchQueueBase { /** * Insert element into the queue , then possibly signal that the queue is not empty and block the producer on the
 * element until permission to procede is given .
 * < p / > If the producer is to be blocked then the lock must be released first , otherwise no other process will be
 * able to get access to the queue . Hence , unlock and block are always set together .
 * < p / > Call only when holding the global lock .
 * @ param element The element to insert in the queue .
 * @ param unlockAndBlock < tt > true < / tt > If the global queue lock should be released and the producer should be
 * blocked .
 * @ return < tt > true < / tt > if the operation succeeded , < tt > false < / tt > otherwise . If the result is < tt > true < / tt > this
 * method may not return straight away , but only after the producer is unblocked by having its data consumed
 * if the unlockAndBlock flag is set . In the false case the method will return straight away , no matter what
 * value the unlockAndBlock flag has , leaving the global lock on . */
protected boolean insert ( E element , boolean unlockAndBlock ) { } }

implementation:
// Create a new record for the data item .
SynchRecordImpl < E > record = new SynchRecordImpl < E > ( element ) ; boolean result = buffer . offer ( record ) ; if ( result ) { count ++ ; // Tell any waiting consumers that the queue is not empty .
notEmpty . signal ( ) ; if ( unlockAndBlock ) { // Allow other threads to read / write the queue .
lock . unlock ( ) ; // Wait until a consumer takes this data item .
record . waitForConsumer ( ) ; } return true ; } else { return false ; }


signature:
public class BatchSynchQueueBase { /** * Removes an element from the buffer , and optionally unblocks the producer of the element , if it is waiting , and
 * optionally signals that the { @ link # notFull } condition may now be true .
 * < p / > Warning : This method must only be called when holding the main { @ link # lock } .
 * @ param unblock < tt > true < / tt > if the elements producer should be released .
 * @ param signal < tt > trye < / tt > if the { @ link # notFull } condition should be signalled .
 * @ return The synch record for the extracted item . */
protected SynchRecordImpl < E > extract ( boolean unblock , boolean signal ) { } }

implementation: SynchRecordImpl < E > result = buffer . remove ( ) ; count -- ; if ( signal ) { notFull . signal ( ) ; } if ( unblock ) { result . releaseImmediately ( ) ; } return result ;


signature:
public class ClientIterator { /** * Fetches the next element from this iterator .
 * @ return The next element in the iterator . */
public Object next ( ) { } }

implementation: try { Object ob = source . next ( ) ; return ob ; } catch ( RemoteException e ) { throw new IllegalStateException ( e ) ; }


signature:
public class ParsedProperties { /** * Helper method for setting system properties to defaults when they are not already set .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public static boolean setSysPropertyIfNull ( String propname , boolean value ) { } }

implementation: return Boolean . parseBoolean ( setSysPropertyIfNull ( propname , Boolean . toString ( value ) ) ) ;


signature:
public class ParsedProperties { /** * Helper method for setting system properties to defaults when they are not already set .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public static short setSysPropertyIfNull ( String propname , short value ) { } }

implementation: return Short . parseShort ( setSysPropertyIfNull ( propname , Short . toString ( value ) ) ) ;


signature:
public class ParsedProperties { /** * Helper method for setting system properties to defaults when they are not already set .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public static int setSysPropertyIfNull ( String propname , int value ) { } }

implementation: return Integer . parseInt ( setSysPropertyIfNull ( propname , Integer . toString ( value ) ) ) ;


signature:
public class ParsedProperties { /** * Helper method for setting system properties to defaults when they are not already set .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public static long setSysPropertyIfNull ( String propname , long value ) { } }

implementation: return Long . parseLong ( setSysPropertyIfNull ( propname , Long . toString ( value ) ) ) ;


signature:
public class ParsedProperties { /** * Helper method for setting system properties to defaults when they are not already set .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public static float setSysPropertyIfNull ( String propname , float value ) { } }

implementation: return Float . parseFloat ( setSysPropertyIfNull ( propname , Float . toString ( value ) ) ) ;


signature:
public class ParsedProperties { /** * Helper method for setting system properties to defaults when they are not already set .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public static double setSysPropertyIfNull ( String propname , double value ) { } }

implementation: return Double . parseDouble ( setSysPropertyIfNull ( propname , Double . toString ( value ) ) ) ;


signature:
public class ParsedProperties { /** * Helper method for setting system properties to defaults when they are not already set .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the system property after this method call . */
public static String setSysPropertyIfNull ( String propname , String value ) { } }

implementation: String property = System . getProperty ( propname ) ; if ( property == null ) { System . setProperty ( propname , value ) ; return value ; } else { return property ; }


signature:
public class ParsedProperties { /** * Helper method for setting properties to defaults when they are not already set .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public boolean setPropertyIfNull ( String propname , boolean value ) { } }

implementation: return Boolean . parseBoolean ( setPropertyIfNull ( propname , Boolean . toString ( value ) ) ) ;


signature:
public class ParsedProperties { /** * Helper method for setting properties to defaults when they are not already set .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public short setPropertyIfNull ( String propname , short value ) { } }

implementation: return Short . parseShort ( setPropertyIfNull ( propname , Short . toString ( value ) ) ) ;


signature:
public class ParsedProperties { /** * Helper method for setting properties to defaults when they are not already set .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public int setPropertyIfNull ( String propname , int value ) { } }

implementation: return Integer . parseInt ( setPropertyIfNull ( propname , Integer . toString ( value ) ) ) ;


signature:
public class ParsedProperties { /** * Helper method for setting properties to defaults when they are not already set .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public long setPropertyIfNull ( String propname , long value ) { } }

implementation: return Long . parseLong ( setPropertyIfNull ( propname , Long . toString ( value ) ) ) ;


signature:
public class ParsedProperties { /** * Helper method for setting properties to defaults when they are not already set .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public float setPropertyIfNull ( String propname , float value ) { } }

implementation: return Float . parseFloat ( setPropertyIfNull ( propname , Float . toString ( value ) ) ) ;


signature:
public class ParsedProperties { /** * Helper method for setting properties to defaults when they are not already set .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public double setPropertyIfNull ( String propname , double value ) { } }

implementation: return Double . parseDouble ( setPropertyIfNull ( propname , Double . toString ( value ) ) ) ;


signature:
public class ParsedProperties { /** * Helper method for setting properties to defaults when they are not already set .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public String setPropertyIfNull ( String propname , String value ) { } }

implementation: String property = super . getProperty ( propname ) ; if ( property == null ) { super . setProperty ( propname , value ) ; return value ; } else { return property ; }


signature:
public class ParsedProperties { /** * Helper method for setting properties .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public boolean setProperty ( String propname , boolean value ) { } }

implementation: setProperty ( propname , Boolean . toString ( value ) ) ; return value ;


signature:
public class ParsedProperties { /** * Helper method for setting properties .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public short setProperty ( String propname , short value ) { } }

implementation: setProperty ( propname , Short . toString ( value ) ) ; return value ;


signature:
public class ParsedProperties { /** * Helper method for setting properties .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public int setProperty ( String propname , int value ) { } }

implementation: setProperty ( propname , Integer . toString ( value ) ) ; return value ;


signature:
public class ParsedProperties { /** * Helper method for setting properties .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public long setProperty ( String propname , long value ) { } }

implementation: setProperty ( propname , Long . toString ( value ) ) ; return value ;


signature:
public class ParsedProperties { /** * Helper method for setting properties .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public float setProperty ( String propname , float value ) { } }

implementation: setProperty ( propname , Float . toString ( value ) ) ; return value ;


signature:
public class ParsedProperties { /** * Helper method for setting properties .
 * @ param propname The name of the system property to set .
 * @ param value The value to set it to .
 * @ return The value of the property after this method call . */
public double setProperty ( String propname , double value ) { } }

implementation: setProperty ( propname , Double . toString ( value ) ) ; return value ;


signature:
public class ParsedProperties { /** * Parses a property as a boolean .
 * @ param propName The property .
 * @ return The property as a boolean , or false if it does not exist . */
public boolean getPropertyAsBoolean ( String propName ) { } }

implementation: String prop = getProperty ( propName ) ; return ( prop != null ) && Boolean . parseBoolean ( prop ) ;


signature:
public class ParsedProperties { /** * Parses a property as an integer .
 * @ param propName The property .
 * @ return The property as a integer , or null if it does not exist . */
public Integer getPropertyAsInteger ( String propName ) { } }

implementation: String prop = getProperty ( propName ) ; return ( prop != null ) ? Integer . valueOf ( prop ) : null ;


signature:
public class ParsedProperties { /** * Parses a property as a long .
 * @ param propName The property .
 * @ return The property as a long , or null if it does not exist . */
public Long getPropertyAsLong ( String propName ) { } }

implementation: String prop = getProperty ( propName ) ; return ( prop != null ) ? Long . valueOf ( prop ) : null ;


signature:
public class ScopeNode { /** * Creates a clone of this scope to be attached to the tree at the site of a mixin reference . If an ArgumentsNode is passed ,
 * each of its values override those defined by the mixin ' s parameters . */
public ScopeNode callMixin ( String name , ArgumentsNode arguments ) { } }

implementation:
List < ExpressionGroupNode > argumentList = ( arguments != null ) ? NodeTreeUtils . getChildren ( arguments , ExpressionGroupNode . class ) : Collections . < ExpressionGroupNode > emptyList ( ) ; if ( argumentList . size ( ) > _parameterDefinitions . size ( ) ) { throw new IllegalMixinArgumentException ( name , _parameterDefinitions . size ( ) ) ; } // Clone scope and filter out any white space
ScopeNode mixinScope = clone ( ) ; NodeTreeUtils . filterLineBreaks ( mixinScope ) ; // If arguments were passed , apply them
for ( int i = 0 ; i < argumentList . size ( ) ; i ++ ) { ExpressionGroupNode argument = argumentList . get ( i ) ; // Replace the value of the definition
VariableDefinitionNode parameter = mixinScope . _parameterDefinitions . get ( i ) ; parameter . clearChildren ( ) ; parameter . addChild ( argument ) ; } // Mark this scope ' s containing rule set as invisible since it has been used as a mixin
getParent ( ) . setVisible ( false ) ; return mixinScope ;


signature:
public class ScopeNode { /** * Recreate internal state before children are cloned . */
@ Override protected void cloneChildren ( InternalNode node ) { } }

implementation:
ScopeNode scope = ( ScopeNode ) node ; // Reset internal state
scope . _variableNameToValueMap = new HashMap < String , ExpressionGroupNode > ( ) ; scope . _selectorToRuleSetMap = new HashMap < String , RuleSetNode > ( ) ; scope . _parameterDefinitions = new ArrayList < VariableDefinitionNode > ( ) ; scope . _propertyNameToNodeMap = new HashMap < String , PropertyNode > ( ) ; scope . setAdditionVisitor ( ) ; super . cloneChildren ( node ) ;


signature: public class JsoupLink { private Connection getConnection ( ) { } }

implementation: URL href = getHref ( ) ; checkArgument ( href != null , "Invalid URL: " + element . attr ( "href" ) ) ; return Jsoup . connect ( href . toString ( ) ) . method ( Method . GET ) . cookies ( document . getCookies ( ) ) ;