signature:
public class BacktrackingAlgorithm { /** * { @ inheritDoc } */
public SearchNode < O , T > search ( QueueSearchState < O , T > initSearch , Collection < T > startStates , int maxSteps , int searchSteps ) throws SearchNotExhaustiveException { } }

implementation:
// Initialize the queue with the start states set up in search nodes if this has not already been done .
// This will only be done on the first call to this method , as enqueueStartStates sets a flag when it is
// done . Subsequent searches continue from where the previous search left off . Have to call reset on
// the search method to really start the search again from the start states .
Queue < SearchNode < O , T > > queue = initSearch . enqueueStartStates ( startStates ) ; // Get the goal predicate configured as part of the enqueueing start states process .
UnaryPredicate goalPredicate = initSearch . getGoalPredicate ( ) ; // Backtrack the most recent goal state , if one has been established .
if ( mostRecentGoalNode != null ) { backtrack ( mostRecentGoalNode ) ; // Clear the most recent goal , now that it has been backtracked if required .
mostRecentGoalNode = null ; } // Keep running until the queue becomes empty or a goal state is found .
while ( ! queue . isEmpty ( ) ) { // Extract or peek at the head element from the queue .
SearchNode headNode = queue . remove ( ) ; // Apply the current nodes operator to establish its shared state .
Reversable reversableState = ( ReTraversable ) headNode . getState ( ) ; reversableState . applyOperator ( ) ; // Expand the successors into the queue whether the current node is a goal state or not .
// This prepares the queue for subsequent searches , ensuring that goal states do not block
// subsequent goal states that exist beyond them .
headNode . unexaminedSuccessorCount = headNode . expandSuccessors ( queue , reverseEnqueue ) ; // As the head node is about to be goal tested , reduce the unexamined successor count of its predecessor .
if ( headNode . getParent ( ) != null ) { headNode . getParent ( ) . unexaminedSuccessorCount -- ; } // Check if the current node is a goal state .
if ( goalPredicate . evaluate ( headNode . getState ( ) ) ) { // Remember this goal node so that subsequent searches remember to backtrack over it .
mostRecentGoalNode = headNode ; return headNode ; } // Backtrack over all fully exhausted nodes from the current position , as required .
backtrack ( headNode ) ; // Check if there is a maximum number of steps limit and increase the step count and check the limit if so .
if ( maxSteps > 0 ) { searchSteps ++ ; // Update the search state with the number of steps taken so far .
initSearch . setStepsTaken ( searchSteps ) ; if ( searchSteps >= maxSteps ) { // The maximum number of steps has been reached , however if the queue is now empty then the search
// has just completed within the maximum . Check if the queue is empty and return null if so .
if ( queue . isEmpty ( ) ) { return null ; } // Quit without a solution as the max number of steps has been reached but because there are still
// more states in the queue then raise a search failure exception .
else { throw new SearchNotExhaustiveException ( "Maximum number of steps reached." , null ) ; } } } } // No goal state was found so return null
return null ;


signature:
public class BacktrackingAlgorithm { /** * Back - tracks from the specified node , moving succesively upwards through the chain of parent nodes , until a node
 * is encountered that has unexamined successors . This method implements the backtracking searches reverse
 * direction . By checking for the presence of unexamined successors , this method only backtracks where necessary .
 * @ param checkNode The search node to start back - tracking from . */
protected void backtrack ( SearchNode checkNode ) { } }

implementation: while ( ( checkNode != null ) && ( checkNode . unexaminedSuccessorCount == 0 ) ) { Reversable undoState = ( ReTraversable ) checkNode . getState ( ) ; undoState . undoOperator ( ) ; checkNode = checkNode . getParent ( ) ; }


signature:
public class WAMResolvingMachine { /** * { @ inheritDoc } */
public void emmitCode ( WAMCompiledPredicate predicate ) throws LinkageException { } }

implementation:
// Keep track of the offset into which the code was loaded .
int entryPoint = codeBuffer . position ( ) ; int length = ( int ) predicate . sizeof ( ) ; // If the code is for a program clause , store the programs entry point in the call table .
WAMCallPoint callPoint = setCodeAddress ( predicate . getName ( ) , entryPoint , length ) ; // Emmit code for the clause into this machine .
predicate . emmitCode ( codeBuffer , this , callPoint ) ; // Notify the native machine of the addition of new code .
codeAdded ( codeBuffer , entryPoint , length ) ; // Notify any attached DPI monitor of the addition of new code .
if ( monitor != null ) { monitor . onCodeUpdate ( this , entryPoint , length ) ; }


signature:
public class WAMResolvingMachine { /** * { @ inheritDoc } */
public void emmitCode ( WAMCompiledQuery query ) throws LinkageException { } }

implementation:
// Keep track of the offset into which the code was loaded .
int entryPoint = codeBuffer . position ( ) ; int length = ( int ) query . sizeof ( ) ; // If the code is for a program clause , store the programs entry point in the call table .
WAMCallPoint callPoint = new WAMCallPoint ( entryPoint , length , - 1 ) ; // Emmit code for the clause into this machine .
query . emmitCode ( codeBuffer , this , callPoint ) ; // Notify the native machine of the addition of new code .
codeAdded ( codeBuffer , entryPoint , length ) ; // Notify any attached DPI monitor of the addition of new code .
if ( monitor != null ) { monitor . onCodeUpdate ( this , entryPoint , length ) ; }


signature:
public class WAMResolvingMachine { /** * Extracts the raw byte code from the machine for a given call table entry .
 * @ param callPoint The call table entry giving the location and length of the code .
 * @ return The byte code at the specified location . */
public byte [ ] retrieveCode ( WAMCallPoint callPoint ) { } }

implementation: byte [ ] result = new byte [ callPoint . length ] ; codeBuffer . get ( result , callPoint . entryPoint , callPoint . length ) ; return result ;


signature:
public class WAMResolvingMachine { /** * { @ inheritDoc } */
public ByteBuffer getCodeBuffer ( int start , int length ) { } }

implementation:
// Take a read only slice onto an appropriate section of the code buffer .
ByteBuffer readOnlyBuffer = codeBuffer . asReadOnlyBuffer ( ) ; readOnlyBuffer . position ( start ) ; readOnlyBuffer . limit ( start + length ) ; return readOnlyBuffer ;


signature:
public class WAMResolvingMachine { /** * Runs a query , and for every non - anonymous variable in the query , decodes its binding value from the heap and
 * returns it in a set of variable bindings .
 * @ param query The query to execute .
 * @ return A set of variable bindings resulting from the query . */
protected Set < Variable > executeAndExtractBindings ( WAMCompiledQuery query ) { } }

implementation:
// Execute the query and program . The starting point for the execution is the first functor in the query
// body , this will follow on to the subsequent functors and make calls to functors in the compiled programs .
boolean success = execute ( query . getCallPoint ( ) ) ; // Used to collect the results in .
Set < Variable > results = null ; // Collect the results only if the resolution was successfull .
if ( success ) { results = new HashSet < Variable > ( ) ; // The same variable context is used accross all of the results , for common use of variables in the
// results .
Map < Integer , Variable > varContext = new HashMap < Integer , Variable > ( ) ; // For each of the free variables in the query , extract its value from the location on the heap pointed to
// by the register that holds the variable .
/* log . fine ( " query . getVarNames ( ) . size ( ) = " + query . getVarNames ( ) . size ( ) ) ; */
for ( byte reg : query . getVarNames ( ) . keySet ( ) ) { int varName = query . getVarNames ( ) . get ( reg ) ; if ( query . getNonAnonymousFreeVariables ( ) . contains ( varName ) ) { int addr = derefStack ( reg ) ; Term term = decodeHeap ( addr , varContext ) ; results . add ( new Variable ( varName , term , false ) ) ; } } } return results ;


signature:
public class WAMResolvingMachine { /** * Decodes a term from the raw byte representation on the machines heap , into an abstract syntax tree .
 * @ param start The start offset of the term on the heap .
 * @ param variableContext The variable context for the decoded variables . This may be shared amongst all variables
 * decoded for a particular unifcation .
 * @ return The term decoded from its heap representation . */
protected Term decodeHeap ( int start , Map < Integer , Variable > variableContext ) { } }

implementation:
/* log . fine ( " private Term decodeHeap ( int start = " + start + " , Map < Integer , Variable > variableContext = " +
 variableContext + " ) : called " ) ; */
// Used to hold the decoded argument in .
Term result = null ; // Dereference the initial heap pointer .
int addr = deref ( start ) ; byte tag = getDerefTag ( ) ; int val = getDerefVal ( ) ; /* log . fine ( " addr = " + addr ) ; */
/* log . fine ( " tag = " + tag ) ; */
/* log . fine ( " val = " + val ) ; */
switch ( tag ) { case REF : { // Check if a variable for the address has already been created in this context , and use it if so .
Variable var = variableContext . get ( val ) ; if ( var == null ) { var = new Variable ( varNameId . decrementAndGet ( ) , null , false ) ; variableContext . put ( val , var ) ; } result = var ; break ; } case STR : { // Decode f / n from the STR data .
int fn = getHeap ( val ) ; int f = fn & 0x00ffffff ; /* log . fine ( " fn = " + fn ) ; */
/* log . fine ( " f = " + f ) ; */
// Look up and initialize this functor name from the symbol table .
FunctorName functorName = getDeinternedFunctorName ( f ) ; // Fill in this functors name and arity and allocate storage space for its arguments .
int arity = functorName . getArity ( ) ; Term [ ] arguments = new Term [ arity ] ; // Loop over all of the functors arguments , recursively decoding them .
for ( int i = 0 ; i < arity ; i ++ ) { arguments [ i ] = decodeHeap ( val + 1 + i , variableContext ) ; } // Create a new functor to hold the decoded data .
result = new Functor ( f , arguments ) ; break ; } case WAMInstruction . CON : { // Decode f / n from the CON data .
int f = val & 0x3fffffff ; /* log . fine ( " f = " + f ) ; */
// Create a new functor to hold the decoded data .
result = new Functor ( f , null ) ; break ; } case WAMInstruction . LIS : { FunctorName functorName = new FunctorName ( "cons" , 2 ) ; int f = internFunctorName ( functorName ) ; // Fill in this functors name and arity and allocate storage space for its arguments .
int arity = functorName . getArity ( ) ; Term [ ] arguments = new Term [ arity ] ; // Loop over all of the functors arguments , recursively decoding them .
for ( int i = 0 ; i < arity ; i ++ ) { arguments [ i ] = decodeHeap ( val + i , variableContext ) ; } // Create a new functor to hold the decoded data .
result = new Functor ( f , arguments ) ; break ; } default : throw new IllegalStateException ( "Encountered unknown tag type on the heap." ) ; } return result ;


signature:
public class DirectMemento { /** * Captures an objects state in this memento . */
public void capture ( ) { } }

implementation:
// Get the class of the object to build a memento for .
Class cls = ob . getClass ( ) ; // Iterate through the classes whole inheritence chain .
while ( ! cls . equals ( Object . class ) ) { // Get the classes fields .
Field [ ] attrs = cls . getDeclaredFields ( ) ; // Build a new map to put the fields in for the current class .
HashMap map = new HashMap ( ) ; // Cache the field values by the class name .
values . put ( cls , map ) ; // Loop over all the fields in the current class .
for ( Field attr : attrs ) { // Make the field accessible ( it may be protected or private ) .
attr . setAccessible ( true ) ; // Check that the field should be captured .
if ( shouldBeSaved ( attr ) ) { // Use a try block as access to the field may fail , although this should not happen because
// even private , protected and package fields have been made accessible .
try { // Cache the field by its name .
map . put ( attr . getName ( ) , attr . get ( ob ) ) ; } catch ( IllegalAccessException e ) { // The field could not be accessed but all fields have been made accessible so this should
// not happen .
throw new IllegalStateException ( "Field '" + attr . getName ( ) + "' could not be accessed but the 'setAccessible(true)' method was invoked on it." , e ) ; } } } // Get the superclass for the next step of the iteration over the whole inheritence chain .
cls = cls . getSuperclass ( ) ; }


signature:
public class DirectMemento { /** * Restores the values currently in this memento to the specified object .
 * @ param ob The object to which the values from this memento should be restored .
 * @ throws NoSuchFieldException If the object in question does not have a field for one of the memento values . */
public void restore ( Object ob ) throws NoSuchFieldException { } }

implementation:
/* log . fine ( " public void map ( Object ob ) : called " ) ; */
/* log . fine ( " class is " + ob . getClass ( ) ) ; */
// Iterate over the whole inheritence chain .
for ( Object key : values . keySet ( ) ) { // Get the next class from the cache .
Class cls = ( Class ) key ; // Get the cache of field values for the class .
Map vals = ( HashMap ) values . get ( cls ) ; // Loop over all fields in the class .
for ( Object o : vals . keySet ( ) ) { // Get the next field name .
String attr = ( String ) o ; // Get the next field value .
Object val = vals . get ( attr ) ; // Get a reference to the field in the object .
Field f = cls . getDeclaredField ( attr ) ; // Make the field accessible ( it may be protected , package or private ) .
f . setAccessible ( true ) ; // Use a try block as writing to the field may fail .
try { // Write to the field .
f . set ( ob , val ) ; } catch ( IllegalAccessException e ) { // The field could not be written to but all fields have been made accessible so this should
// not happen .
throw new IllegalStateException ( "Field '" + f . getName ( ) + "' could not be accessed but the 'setAccessible(true)' method was invoked on it." , e ) ; } } }


signature:
public class DirectMemento { /** * Gets the value of the named field of the specified class .
 * @ param cls The class in which the field to get is declared .
 * @ param attr The name of the field .
 * @ return The object value of the attribute . */
public Object get ( Class cls , String attr ) { } }

implementation:
HashMap map ; // See if the class exists in the cache .
if ( ! values . containsKey ( cls ) ) { // Class not in cache so return null .
return null ; } // Get the cache of field values for the class .
map = ( HashMap ) values . get ( cls ) ; // Extract the specified field from the cache .
return map . get ( attr ) ;


signature:
public class DirectMemento { /** * Places the specified value into the memento based on the field ' s declaring class and name .
 * @ param cls The class in which the field is declared .
 * @ param attr The name of the attribute .
 * @ param val The value to store into this memento . */
public void put ( Class cls , String attr , Object val ) { } }

implementation:
/* log . fine ( " public void put ( Class cls , String attr , Object val ) : called " ) ; */
/* log . fine ( " class name is " + cls . getName ( ) ) ; */
/* log . fine ( " attribute is " + attr ) ; */
/* log . fine ( " value to set is " + val ) ; */
HashMap map ; // Check that the cache for the class exists in the cache .
if ( values . containsKey ( cls ) ) { // Get the cache of field for the class .
map = ( HashMap ) values . get ( cls ) ; } else { // The class does not already exist in the cache to create a new cache for its fields .
map = new HashMap ( ) ; // Cache the new field cache against the class .
values . put ( cls , map ) ; } // Store the attribute in the field cache for the class .
map . put ( attr , val ) ;


signature:
public class DirectMemento { /** * Generates a list of all the fields of the object that this memento maps for a given class .
 * @ param cls The class to get all field names for .
 * @ return A collection of the field names or null if the specified class is not part of the objects class hierarchy
 * chain . */
public Collection getAllFieldNames ( Class cls ) { } }

implementation:
/* log . fine ( " public Collection getAllFieldNames ( Class cls ) : called " ) ; */
// See if the class exists in the cache
if ( ! values . containsKey ( cls ) ) { // Class not in cache so return null
return null ; } // Get the cache of fields for the class
Map map = ( HashMap ) values . get ( cls ) ; // Return all the keys from cache of fields
return map . keySet ( ) ;


signature:
public class PrologInterpreter { /** * Creates the interpreter and launches its top - level run loop .
 * @ param args The command line arguments . */
public static void main ( String [ ] args ) { } }

implementation:
try { VariableAndFunctorInterner interner = new VariableAndFunctorInternerImpl ( "Prolog_Variable_Namespace" , "Prolog_Functor_Namespace" ) ; PrologCompiler compiler = new PrologCompiler ( interner ) ; PrologResolver resolver = new PrologResolver ( interner ) ; Parser < Clause , Token > parser = new InteractiveParser ( interner ) ; PrologEngine engine = new PrologEngine ( parser , interner , compiler , resolver ) ; engine . reset ( ) ; ResolutionInterpreter < PrologCompiledClause , PrologCompiledClause > interpreter = new ResolutionInterpreter < PrologCompiledClause , PrologCompiledClause > ( engine ) ; interpreter . interpreterLoop ( ) ; } catch ( Exception e ) { /* log . log ( Level . SEVERE , e . getMessage ( ) , e ) ; */
e . printStackTrace ( new PrintStream ( System . err ) ) ; System . exit ( - 1 ) ; }


signature:
public class ProductionScriptGenMojo { /** * Implementation of the prod - script goal .
 * @ throws org . apache . maven . plugin . MojoExecutionException */
public void execute ( ) throws MojoExecutionException , MojoFailureException { } }

implementation:
// log . debug ( " public void execute ( ) throws MojoExecutionException : called " ) ;
// Turn each of the test runner command lines into a script .
for ( String commandName : commands . keySet ( ) ) { if ( prodScriptOutDirectory != null ) { writeUnixScript ( commandName , prodScriptOutDirectory ) ; writeWindowsScript ( commandName , prodScriptOutDirectory ) ; } }


signature:
public class ProductionScriptGenMojo { /** * { @ inheritDoc } */
protected String appendClasspath ( String commandLine , boolean unix ) { } }

implementation:
String pathSeperator ; String seperator ; String classpathDirPrefix ; if ( unix ) { pathSeperator = "/" ; seperator = ":" ; classpathDirPrefix = JAR_DIR_PREFIX_UNIX ; } else { pathSeperator = "\\" ; seperator = ";" ; classpathDirPrefix = JAR_DIR_PREFIX_WINDOWS ; } for ( Iterator i = classpathElements . iterator ( ) ; i . hasNext ( ) ; ) { String cpPath = ( String ) i . next ( ) ; int lastSlash = cpPath . lastIndexOf ( "/" ) ; int lastBackslash = cpPath . lastIndexOf ( "\\" ) ; int lastPathSeperator = ( lastSlash > lastBackslash ) ? lastSlash : lastBackslash ; if ( lastPathSeperator != - 1 ) { cpPath = cpPath . substring ( lastPathSeperator + 1 ) ; } // cpPath = cpPath . replace ( " / " , pathSeperator ) ;
if ( cpPath . endsWith ( ".jar" ) ) { commandLine += classpathDirPrefix + pathSeperator + cpPath + seperator ; } } commandLine += classpathDirPrefix + pathSeperator + outputJar + ".jar" ; return commandLine ;


signature:
public class IntIntOpenLinearTable { /** * { @ inheritDoc } */
public void setup ( ByteBuffer buffer , int t , int n ) { } }

implementation: this . buffer = buffer ; this . offset = t ; this . size = ( n >> 3 ) ; // Shift by 3 as key and value must be stored as a pair , making 8 bytes per entry .


signature:
public class IntIntOpenLinearTable { /** * { @ inheritDoc } */
public int get ( int key ) { } }

implementation: int addr = addr ( hash ( key ) ) ; while ( true ) { int tableKey = buffer . getInt ( addr ) ; if ( key == tableKey ) { return buffer . getInt ( addr + 4 ) ; } if ( tableKey == 0 ) { return 0 ; } addr += 8 ; }


signature:
public class IntIntOpenLinearTable { /** * { @ inheritDoc } */
public void put ( int key , int val ) { } }

implementation: int addr = addr ( hash ( key ) ) ; while ( true ) { int tableKey = buffer . getInt ( addr ) ; if ( key == tableKey ) { break ; } if ( tableKey == 0 ) { break ; } addr += 8 ; } buffer . putInt ( addr , key ) ; buffer . putInt ( addr + 4 , val ) ;


signature:
public class LockFreeNQueue { /** * Inserts the specified element onto the tail of this queue .
 * @ param o the element to add , may not be null .
 * @ return < tt > true < / tt > ( as per the general contract of < tt > Queue . offer < / tt > ) .
 * @ todo Compare and set possibly not needed after the succesfull tail join . Straight update looks like it should
 * work ? I may have missed something here . */
public boolean offer ( E o ) { } }

implementation:
/* log . fine ( " public boolean offer ( E o ) : called " ) ; */
/* log . fine ( " o = " + o ) ; */
// Ensure that the item to add is not null .
if ( o == null ) { throw new IllegalArgumentException ( "The 'o' parameter may not be null." ) ; } // Derive the integer priority of the element using the priority function , shift it into this queues range if
// necessary and adjust it to any offset caused by lowest priority not equal to zero .
int level = priorityToLevel ( p . apply ( o ) ) ; /* log . fine ( " offer level = " + level ) ; */
// Create a new node to hold the new data element .
Node < E > newNode = new DataNode < E > ( o , markers [ level + 1 ] ) ; // Add the element to the tail of the queue with matching level , looping until this can complete as an atomic
// operation .
while ( true ) { // Get tail and next ref . Would expect next ref to be null , but other thread may update it .
Node < E > t = markers [ level + 1 ] . getTail ( ) ; Node < E > s = t . getNext ( ) ; /* log . fine ( " t = " + t ) ; */
/* log . fine ( " s = " + s ) ; */
// Recheck the tail ref , to ensure other thread has not already moved it . This can potentially prevent
// a relatively expensive compare and set from failing later on , if another thread has already shited
// the tail .
if ( t == markers [ level + 1 ] . getTail ( ) ) { /* log . fine ( " t is still the tail . " ) ; */
// Check that the next element reference on the tail is the tail marker , to confirm that another thread
// has not updated it . Again , this may prevent a cas from failing later .
if ( s == markers [ level + 1 ] ) { /* log . fine ( " s is the tail marker . " ) ; */
// Try to join the new tail onto the old one .
if ( t . casNext ( s , newNode ) ) { // The tail join was succesfull , so now update the queues tail reference . No conflict should
// occurr here as the tail join was succesfull , so its just a question of updating the tail
// reference . A compare and set is still used because . . .
markers [ level + 1 ] . casTail ( t , newNode ) ; // Increment the queue size count .
count . incrementAndGet ( ) ; return true ; } } // Update the tail reference , other thread may also be doing the same .
else { // Why bother doing this at all ? I suppose , because another thread may be stalled and doing this
// will enable this one to keep running .
// Update the tail reference for the queue because another thread has already added a new tail
// but not yet managed to update the tail reference .
markers [ level + 1 ] . casTail ( t , s ) ; } } }


signature:
public class LockFreeNQueue { /** * Retrieves and removes the head of this queue , or null if this queue is empty .
 * < p / > This method will make a single pass down the queue , starting from the highest priority and working down to
 * the lowest . If it fails to extract an element from the queue on this single pass , it will return null . It is
 * possible that the queue contains transient data during this pass that this method does not manage to extract ,
 * because other threads managed to take the data , or because other threads inserted higher priority data once this
 * pass was already further down the queue .
 * @ return The head of this queue , or null if this queue is empty . */
public E poll ( ) { } }

implementation:
/* log . fine ( " public E poll ( ) : called " ) ; */
// This is used to keep track of the level of the list that is found to have data in it .
int currentLevel = 0 ; while ( true ) { // This is used to locate the marker head of a list that contains data .
Marker < E > h = null ; // This is used to locate the potential data node of a list with data in it . Another thread may already
// have taken this data .
Node < E > first = null ; // Second data item , may also be tail marker , first data item of next list , or null at end of last list .
Node < E > second = null ; // Loop down any empty lists at the front of the queue until a list with data in it is found .
for ( ; currentLevel < n ; currentLevel ++ ) { h = markers [ currentLevel ] ; first = h . getNext ( ) ; second = first . getNext ( ) ; // Check if the list at the current level is not empty and should be tried for data .
if ( ! h . isEmpty ( markers [ currentLevel + 1 ] ) ) { break ; } // Check if the current level is empty and is the last level , in which case return null .
else if ( currentLevel == ( n - 1 ) ) { // log . info ( " returning null from level loop . " ) ;
return null ; } // Else if the current level is empty loop to the next one to see if it has data .
} /* log . fine ( " current poll level = " + currentLevel ) ; */
// This is used to locate the tail of the list that has been found with data in it .
Node < E > t = markers [ currentLevel + 1 ] . getTail ( ) ; // Check that the first data item has not yet been taken . Another thread may already have taken it ,
// in which case performing a relatively expensive cas on the head will fail . If first is still intact
// then second will be intact too .
if ( first == h . getNext ( ) ) { // Check if the queue has become empty .
if ( h . isEmpty ( markers [ currentLevel + 1 ] ) ) { // Another thread has managed to take data from the queue , leaving it empty .
// First won ' t be null . It may point to tail though . . .
if ( first == null ) { // Don ' t want to return here , want to try the next list . The list loop has a return null
// once it gets to the end to take care of that .
// log . info ( " returning null as first = = null " ) ;
return null ; } else { // Not sure yet why castail here ? Does this repair a broken tail ref left after the last item
// was taken ?
markers [ currentLevel + 1 ] . casTail ( t , first ) ; } } // The queue contains data , so try to move its head marker reference from the first data item , onto the
// second item ( which may be data , or the tail marker ) . If this succeeds , then the first data node
// has been atomically extracted from the head of the queue .
else if ( h . casNext ( first , second ) ) { // h Does not refer to an empty queue , so first must be a data node .
DataNode < E > firstDataNode = ( ( DataNode < E > ) first ) ; E item = firstDataNode . getItem ( ) ; // Even though the empty test did not indicate that the list was empty , it may contain null
// data items , because the remove method doesn ' t extract nodes on a remove . These need to be skipped
// over . Could they be removed here ?
if ( item != null ) { firstDataNode . setItem ( null ) ; /* log . fine ( " returing item = " + item ) ; */
// Decrement the queue size count .
count . decrementAndGet ( ) ; return item ; } // else skip over deleted item , continue trying at this level . Go back an retry starting from same
// level . List at this level may now be empty , or may get the next item from it .
// else skip over marker element . just make markers return null for item to skip them ? No , because
// need to advance currentLevel and get head and tail markers for the next level . but then , next
// level advance will occur when this level is retried and found to be empty won ' t it ?
} } }


signature:
public class UniformCostSearch { /** * Creates the correct type of search nodes for this search . This search uses ordinary search nodes .
 * @ param state The search space state to create a search node for .
 * @ return The state encapsulated in an ordinary search node . */
public SearchNode < O , T > createSearchNode ( T state ) { } }

implementation: return new SearchNode < O , T > ( state ) ;


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

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


signature:
public class RegisterMonitorController { /** * { @ inheritDoc }
 * < p / > Creates the register monitor component and hooks it up to the register set . */
public void open ( ) { } }

implementation:
// Build a text grid panel in the left position .
grid = componentFactory . createTextGrid ( ) ; grid . insertVerticalSeparator ( 3 , 10 ) ; mainWindow . showLeftPane ( componentFactory . createTextGridPanel ( grid ) ) ; // Build a table model on the text grid , and construct a register monitor on the table .
table = grid . createTable ( 0 , 0 , 20 , 20 ) ; monitor = new RegisterSetMonitor ( table ) ; // Attach a listener for updates to the register table .
table . addTextTableListener ( new TableUpdateHandler ( ) ) ; grid . addTextGridSelectionListener ( new SelectionHandler ( ) ) ;


signature:
public class TermWalkers { /** * Provides a simple depth first walk over a term .
 * @ param visitor The visitor to apply to each term .
 * @ return A simple depth first walk over a term . */
public static TermWalker simpleWalker ( TermVisitor visitor ) { } }

implementation: DepthFirstBacktrackingSearch < Term , Term > search = new DepthFirstBacktrackingSearch < Term , Term > ( ) ; return new TermWalker ( search , new DefaultTraverser ( ) , visitor ) ;


signature:
public class TermWalkers { /** * Provides a depth first walk over a term , visiting only when a goal predicate matches .
 * @ param unaryPredicate The goal predicate .
 * @ param visitor The visitor to apply to each term .
 * @ return A depth first walk over a term , visiting only when a goal predicate matches . */
public static TermWalker goalWalker ( UnaryPredicate < Term > unaryPredicate , TermVisitor visitor ) { } }

implementation: TermWalker walker = simpleWalker ( visitor ) ; walker . setGoalPredicate ( unaryPredicate ) ; return walker ;


signature:
public class TermWalkers { /** * Provides a positional depth first walk over a term .
 * @ param visitor The visitor to apply to each term , and to notify of positional context changes .
 * @ return A positional depth first walk over a term . */
public static TermWalker positionalWalker ( PositionalTermVisitor visitor ) { } }

implementation: PositionalTermTraverser positionalTraverser = new PositionalTermTraverserImpl ( ) ; positionalTraverser . setContextChangeVisitor ( visitor ) ; visitor . setPositionalTraverser ( positionalTraverser ) ; return new TermWalker ( new DepthFirstBacktrackingSearch < Term , Term > ( ) , positionalTraverser , visitor ) ;


signature:
public class TermWalkers { /** * Provides a positional depth first walk over a term , visiting only when a goal predicate matches .
 * @ param unaryPredicate The goal predicate .
 * @ param visitor The visitor to apply to each term .
 * @ return A positional depth first walk over a term , visiting only when a goal predicate matches . */
public static TermWalker positionalGoalWalker ( UnaryPredicate < Term > unaryPredicate , PositionalTermVisitor visitor ) { } }

implementation: TermWalker walker = positionalWalker ( visitor ) ; walker . setGoalPredicate ( unaryPredicate ) ; return walker ;


signature:
public class TermWalkers { /** * Provides a positional postfix walk over a term .
 * @ param visitor The visitor to apply to each term , and to notify of positional context changes .
 * @ return A positional postfix first walk over a term . */
public static TermWalker positionalPostfixWalker ( PositionalTermVisitor visitor ) { } }

implementation: PositionalTermTraverser positionalTraverser = new PositionalTermTraverserImpl ( ) ; positionalTraverser . setContextChangeVisitor ( visitor ) ; visitor . setPositionalTraverser ( positionalTraverser ) ; return new TermWalker ( new PostFixSearch < Term , Term > ( ) , positionalTraverser , visitor ) ;


signature:
public class PrologResolver { /** * { @ inheritDoc } */
public void addToDomain ( PrologCompiledClause term ) { } }

implementation: List < PrologCompiledClause > predicate = domain . get ( term . getHead ( ) . getName ( ) ) ; if ( predicate == null ) { predicate = new LinkedList < PrologCompiledClause > ( ) ; domain . put ( term . getHead ( ) . getName ( ) , predicate ) ; } predicate . add ( term ) ;


signature:
public class PrologResolver { /** * { @ inheritDoc } */
public void setQuery ( PrologCompiledClause query ) { } }

implementation:
// Reset the search in order to initialize it .
resolutionSearch . reset ( ) ; // Keep a reference to the current query .
currentQuery = query ; // Create the starting point for the resolution , consisting of the queries to resolve as the intial goal stack ,
// and an empty list of bindings .
goalStack = new StackQueue < BuiltInFunctor > ( ) ; // Create a fresh list to hold the results of the resolution in .
bindings = new StackQueue < Variable > ( ) ; // Create the initial state of the proof search .
ResolutionState initialState = new ResolutionStateImpl ( query ) ; addStartState ( initialState ) ; // If printing execution traces , ensure the execution indenter starts from zero .
/* if ( TRACE )
 indenter . reset ( ) ; */


signature:
public class PrologResolver { /** * { @ inheritDoc } */
public Set < Variable > resolve ( ) { } }

implementation:
// Find all free variables in the query .
Set < Variable > freeVars = TermUtils . findFreeNonAnonymousVariables ( currentQuery ) ; // Used to collect the results in .
Set < Variable > results = null ; // Search for the next available solution .
SearchNode solution ; try { solution = findGoalPath ( ) ; } catch ( SearchNotExhaustiveException e ) { // The search may fail if the maximum number of search steps is reached . This limit is not turned on by
// default . If this happens , null is returned , indicating that no solution was found .
// Exception ignored as empty search results are noted and dealt with by returning null .
e = null ; solution = null ; results = null ; } // Check that a solution was found and return the variable bindings from it if so . Only the variable bindings
// that were free and non - anonymous in the original query are returned .
if ( solution != null ) { results = new HashSet < Variable > ( freeVars ) ; } return results ;


signature:
public class PrologResolver { /** * { @ inheritDoc }
 * < p / > This also resets the entire knowledge base of this resolver , so that it is empty . */
public void reset ( ) { } }

implementation:
// Empty the knowledge base and clear the current query .
domain = new HashMap < Integer , List < PrologCompiledClause > > ( ) ; currentQuery = null ; // Reset the underlying search .
resolutionSearch . reset ( ) ; // If printing execution traces , ensure the execution indenter starts from zero .
/* if ( TRACE )
 indenter . reset ( ) ; */


signature:
public class PrologResolver { /** * { @ inheritDoc } */
public ResolutionState search ( ) throws SearchNotExhaustiveException { } }

implementation: SearchNode < ResolutionState , ResolutionState > path = findGoalPath ( ) ; if ( path != null ) { return path . getState ( ) ; } else { return null ; }


signature:
public class PrologResolver { /** * { @ inheritDoc } */
public Iterator < Set < Variable > > iterator ( ) { } }

implementation:
// Find all free variables in the query .
final Set < Variable > freeVars = TermUtils . findFreeNonAnonymousVariables ( currentQuery ) ; Function < ResolutionState , Set < Variable > > listFunction = new Function < ResolutionState , Set < Variable > > ( ) { public Set < Variable > apply ( ResolutionState state ) { return freeVars ; } } ; return new Filterator < ResolutionState , Set < Variable > > ( Searches . allSolutions ( this ) , listFunction ) ;


signature:
public class PropertiesHelper { /** * Get properties from an input stream .
 * @ param is The input stream .
 * @ return The properties loaded from the input stream .
 * @ throws IOException If the is an I / O error reading from the stream . */
public static Properties getProperties ( InputStream is ) throws IOException { } }

implementation:
/* log . fine ( " getProperties ( InputStream ) : called " ) ; */
// Create properties object laoded from input stream
Properties properties = new Properties ( ) ; properties . load ( is ) ; return properties ;


signature:
public class PropertiesHelper { /** * Get properties from a file .
 * @ param file The file .
 * @ return The properties loaded from the file .
 * @ throws IOException If there is an I / O error reading from the file . */
public static Properties getProperties ( File file ) throws IOException { } }

implementation:
/* log . fine ( " getProperties ( File ) : called " ) ; */
// Open the file as an input stream
InputStream is = new FileInputStream ( file ) ; // Create properties object loaded from the stream
Properties properties = getProperties ( is ) ; // Close the file
is . close ( ) ; return properties ;


signature:
public class PropertiesHelper { /** * Get properties from a url .
 * @ param url The URL .
 * @ return The properties loaded from the url .
 * @ throws IOException If there is an I / O error reading from the URL . */
public static Properties getProperties ( URL url ) throws IOException { } }

implementation:
/* log . fine ( " getProperties ( URL ) : called " ) ; */
// Open the URL as an input stream
InputStream is = url . openStream ( ) ; // Create properties object loaded from the stream
Properties properties = getProperties ( is ) ; // Close the url
is . close ( ) ; return properties ;


signature:
public class PropertiesHelper { /** * Get properties from a path name . The path name may refer to either a file or a URL .
 * @ param pathname The path name .
 * @ return The properties loaded from the file or URL .
 * @ throws IOException If there is an I / O error reading from the URL or file named by the path . */
public static Properties getProperties ( String pathname ) throws IOException { } }

implementation:
/* log . fine ( " getProperties ( String ) : called " ) ; */
// Check that the path is not null
if ( pathname == null ) { return null ; } // Check if the path is a URL
if ( isURL ( pathname ) ) { // The path is a URL
return getProperties ( new URL ( pathname ) ) ; } else { // Assume the path is a file name
return getProperties ( new File ( pathname ) ) ; }


signature:
public class PropertiesHelper { /** * Trims whitespace from property values . This method returns a new set of properties the same as the properties
 * specified as an argument but with any white space removed by the { @ link java . lang . String # trim } method .
 * @ param properties The properties to trim whitespace from .
 * @ return The white space trimmed properties . */
public static Properties trim ( Properties properties ) { } }

implementation:
Properties trimmedProperties = new Properties ( ) ; // Loop over all the properties
for ( Object o : properties . keySet ( ) ) { String next = ( String ) o ; String nextValue = properties . getProperty ( next ) ; // Trim the value if it is not null
if ( nextValue != null ) { nextValue . trim ( ) ; } // Store the trimmed value in the trimmed properties
trimmedProperties . setProperty ( next , nextValue ) ; } return trimmedProperties ;


signature:
public class PropertiesHelper { /** * Helper method . Guesses whether a string is a URL or not . A String is considered to be a url if it begins with
 * http : , ftp : , or uucp : .
 * @ param name The string to test for being a URL .
 * @ return True if the string is a URL and false if not . */
private static boolean isURL ( String name ) { } }

implementation: return ( name . toLowerCase ( ) . startsWith ( "http:" ) || name . toLowerCase ( ) . startsWith ( "ftp:" ) || name . toLowerCase ( ) . startsWith ( "uucp:" ) ) ;


signature:
public class JTextGrid { /** * { @ inheritDoc }
 * < p / > Renders the text grid model . */
protected void paintComponent ( Graphics g ) { } }

implementation:
Graphics2D graphics2D = ( Graphics2D ) g . create ( ) ; Rectangle clipRect = ( Rectangle ) g . getClip ( ) ; // Work out the area to be painted in grid coordinates against the clipping rectangle .
int startCol = xToCol ( clipRect . x ) ; int startRow = yToRow ( clipRect . y ) ; int cols = xToCol ( clipRect . x + clipRect . width ) ; int rows = yToRow ( clipRect . y + clipRect . height ) ; graphics2D . setFont ( getFont ( ) ) ; graphics2D . setColor ( getBackground ( ) ) ; graphics2D . fillRect ( clipRect . x , clipRect . y , clipRect . width , clipRect . height ) ; initializeFontMetrics ( ) ; if ( useAntiAliasing ) { graphics2D . setRenderingHint ( RenderingHints . KEY_ANTIALIASING , RenderingHints . VALUE_ANTIALIAS_ON ) ; graphics2D . setRenderingHint ( RenderingHints . KEY_RENDERING , RenderingHints . VALUE_RENDER_QUALITY ) ; } SortedMap < Integer , Integer > hSeps = model . getHorizontalSeparators ( ) ; int hSepOffset = 0 ; for ( int row = 0 ; row <= rows ; row ++ ) { Integer hNextSep = null ; if ( ! hSeps . isEmpty ( ) ) { hNextSep = hSeps . firstKey ( ) ; } if ( ( hNextSep != null ) && ( hNextSep == row ) ) { hSepOffset += hSeps . get ( hNextSep ) ; hSeps . remove ( hNextSep ) ; } SortedMap < Integer , Integer > vSeps = model . getVerticalSeparators ( ) ; int vSepOffset = 0 ; for ( int col = 0 ; col <= cols ; col ++ ) { Integer vNextSep = null ; if ( ! vSeps . isEmpty ( ) ) { vNextSep = vSeps . firstKey ( ) ; } if ( ( vNextSep != null ) && ( vNextSep == col ) ) { int vSepWidth = vSeps . get ( vNextSep ) ; vSepOffset += vSepWidth ; vSeps . remove ( vNextSep ) ; // If adding a vertical separator row attributes should be rendered within it to fill the space
// left by the separator .
AttributeSet attributes = model . getRowAttribute ( row ) ; Color bgColor = ( attributes != null ) ? ( Color ) attributes . get ( AttributeSet . BACKGROUND_COLOR ) : null ; bgColor = ( bgColor == null ) ? getBackground ( ) : bgColor ; graphics2D . setColor ( bgColor ) ; graphics2D . fillRect ( colToX ( col ) + vSepOffset - vSepWidth , rowToY ( row ) + hSepOffset , colToX ( col ) + vSepOffset , charHeight ) ; } // Only render if within the clip rectangle
if ( ( col >= startCol ) && ( row >= startRow ) ) { char character = model . getCharAt ( col , row ) ; AttributeSet attributes = model . getAttributeAt ( col , row ) ; Color bgColor = ( attributes != null ) ? ( Color ) attributes . get ( AttributeSet . BACKGROUND_COLOR ) : null ; bgColor = ( bgColor == null ) ? getBackground ( ) : bgColor ; graphics2D . setColor ( bgColor ) ; graphics2D . fillRect ( colToX ( col ) + vSepOffset , rowToY ( row ) + hSepOffset , charWidth , charHeight ) ; graphics2D . setColor ( getForeground ( ) ) ; graphics2D . drawString ( Character . toString ( character ) , colToX ( col ) + vSepOffset , ( rowToY ( ( row + 1 ) ) ) - descent + hSepOffset ) ; } } } graphics2D . dispose ( ) ;


signature:
public class JTextGrid { /** * Computes the rendered dimensions of the text grid model , on screen . Used for sizing this component .
 * @ return The on - screen dimensions of the rendered text grid model . */
protected Dimension computeGridSize ( ) { } }

implementation: int cols = model . getWidth ( ) ; int rows = model . getHeight ( ) ; int horizSeparatorSize = 0 ; for ( int size : model . getHorizontalSeparators ( ) . values ( ) ) { horizSeparatorSize += size ; } int vertSeparatorSize = 0 ; for ( int size : model . getVerticalSeparators ( ) . values ( ) ) { vertSeparatorSize += size ; } return new Dimension ( vertSeparatorSize + colToX ( cols ) , horizSeparatorSize + rowToY ( rows ) ) ;


signature:
public class JTextGrid { /** * Sets up metrics relating to the size of the font used to display the text grid . This only needs to be done once
 * but this method can be called many times as it is guarded by an initialization flag to prevent these being
 * calculated many times . */
private void initializeFontMetrics ( ) { } }

implementation: if ( ! fontMetricsInitialized ) { FontMetrics fontMetrics = getFontMetrics ( getFont ( ) ) ; charWidth = fontMetrics . charWidth ( ' ' ) ; charHeight = fontMetrics . getHeight ( ) ; descent = fontMetrics . getDescent ( ) ; fontMetricsInitialized = true ; }


signature:
public class BaseState { /** * Adds a property changed listener to be notified of changes to the application state .
 * @ param l The listener . */
public void addPropertyChangeListener ( PropertyChangeListener l ) { } }

implementation:
// Check if the listneres list has been initialized
if ( listeners == null ) { // Listeneres list not intialized so create a new list
listeners = new ArrayList ( ) ; } synchronized ( listeners ) { // Add the new listener to the list
listeners . add ( l ) ; }


signature:
public class BaseState { /** * Adds a property changed listener to be notified of changes to the named property .
 * @ param l The listener /
 * @ param p The property ( ignored , notifies of changes to any properties ) . */
public void addPropertyChangeListener ( String p , PropertyChangeListener l ) { } }

implementation:
// Check if the listeneres list has been initialized
if ( listeners == null ) { // Listeneres list not initialized so create a new list
listeners = new ArrayList ( ) ; } synchronized ( listeners ) { // Add the new listener to the list
listeners . add ( l ) ; }


signature:
public class BaseState { /** * Removes the specified property change listener from the list of active listeners .
 * @ param p Ignored . In future will be used to name the specific property to remove the listener for .
 * @ param l The property change listener to remove . */
public void removePropertyChangeListener ( String p , PropertyChangeListener l ) { } }

implementation: if ( listeners == null ) { return ; } synchronized ( listeners ) { listeners . remove ( l ) ; }


signature:
public class BaseState { /** * Notifies all property change listeners of the given PropertyChangeEvent .
 * @ param evt The property change event to pass to all listeners . */
protected void firePropertyChange ( PropertyChangeEvent evt ) { } }

implementation:
/* log . fine ( " firePropertyChange : called " ) ; */
// Take a copy of the event as a final variable so that it can be used in an inner class
final PropertyChangeEvent finalEvent = evt ; Iterator it ; // Check if the list of listeners is empty
if ( listeners == null ) { // There are no listeners so simply return without doing anything
return ; } // synchronize on the list of listeners to prevent comodification
synchronized ( listeners ) { // Cycle through all listeners and notify them
it = listeners . iterator ( ) ; while ( it . hasNext ( ) ) { // Get the next listener from the list
final PropertyChangeListener l = ( PropertyChangeListener ) it . next ( ) ; // Notify the listener of the property change event
Runnable r = new Runnable ( ) { public void run ( ) { // Fire a property change event
l . propertyChange ( finalEvent ) ; } } ; // Run the property change event in the Swing event queue
SwingUtilities . invokeLater ( r ) ; } }


signature:
public class DoubleRangeType { /** * Creates a new double range type with the specified name , if it does not already exist .
 * @ param name The name of the double range type to create .
 * @ param min The minimum value that an instance of the type can take .
 * @ param max The maximum value that an instance of teh type can take .
 * @ return A new double range type .
 * @ throws IllegalArgumentException If min is not less than or equal to max , or the named type already exists . */
public static Type createInstance ( String name , double min , double max ) { } }

implementation:
// Ensure that min is less than or equal to max .
if ( min > max ) { throw new IllegalArgumentException ( "'min' must be less than or equal to 'max'." ) ; } synchronized ( DOUBLE_RANGE_TYPES ) { // Add the newly created type to the map of all types .
DoubleRangeType newType = new DoubleRangeType ( name , min , max ) ; // Ensure that the named type does not already exist , unless it has an identical definition already , in which
// case the old definition can be re - used and the new one discarded .
DoubleRangeType oldType = DOUBLE_RANGE_TYPES . get ( name ) ; if ( ( oldType != null ) && ! oldType . equals ( newType ) ) { throw new IllegalArgumentException ( "The type '" + name + "' already exists and cannot be redefined." ) ; } else if ( ( oldType != null ) && oldType . equals ( newType ) ) { return oldType ; } else { DOUBLE_RANGE_TYPES . put ( name , newType ) ; return newType ; } }


signature:
public class Conjunction { /** * { @ inheritDoc } */
public SizeableLinkedList < WAMInstruction > compileBodyArguments ( Functor functor , boolean isFirstBody , FunctorName clauseName , int bodyNumber ) { } }

implementation:
SizeableLinkedList < WAMInstruction > result = new SizeableLinkedList < WAMInstruction > ( ) ; SizeableLinkedList < WAMInstruction > instructions ; Term [ ] expressions = functor . getArguments ( ) ; for ( int i = 0 ; i < expressions . length ; i ++ ) { Functor expression = ( Functor ) expressions [ i ] ; Integer permVarsRemaining = ( Integer ) defaultBuiltIn . getSymbolTable ( ) . get ( expression . getSymbolKey ( ) , SYMKEY_PERM_VARS_REMAINING ) ; // Select a non - default built - in implementation to compile the functor with , if it is a built - in .
BuiltIn builtIn ; if ( expression instanceof BuiltIn ) { builtIn = ( BuiltIn ) expression ; } else { builtIn = defaultBuiltIn ; } // The ' isFirstBody ' parameter is only set to true , when this is the first functor of a rule .
instructions = builtIn . compileBodyArguments ( expression , false , clauseName , bodyNumber ) ; result . addAll ( instructions ) ; // Call the body . The number of permanent variables remaining is specified for environment trimming .
instructions = builtIn . compileBodyCall ( expression , false , false , false , 0 /* permVarsRemaining */
) ; result . addAll ( instructions ) ; } return result ;


signature:
public class FaderImpl { /** * { @ inheritDoc } */
public void actionPerformed ( ActionEvent e ) { } }

implementation: String groupName = e . getActionCommand ( ) ; FadeState fadeState = timers . get ( groupName ) ; if ( fadeState . interpolator . hasNext ( ) ) { Color color = fadeState . interpolator . next ( ) ; fadeState . target . changeColor ( color ) ; fadeState . timer . setInitialDelay ( 0 ) ; fadeState . timer . restart ( ) ; }


signature:
public class FaderImpl { /** * Requests a color fade against the specified target , under a group name .
 * @ param target The color delta target .
 * @ param groupName The group name for the fade . See class level comment for { @ link FaderImpl } for an explanation of
 * how the group name is used . */
public void doFade ( ColorDelta target , String groupName ) { } }

implementation:
FadeState fadeState = timers . get ( groupName ) ; // Set up the color interpolator .
Iterator < Color > interpolator = new ColorInterpolator ( startColor , endColor , 8 ) . iterator ( ) ; if ( fadeState == null ) { // Create a new fade state for the target group , and a timer to run it .
Timer timer = new Timer ( 20 , this ) ; fadeState = new FadeState ( timer , target , interpolator ) ; timers . put ( groupName , fadeState ) ; } else { // Kill any previous fade and replace the target with the new one .
fadeState . timer . stop ( ) ; fadeState . target = target ; fadeState . interpolator = interpolator ; } // Iterate to the initial color .
Color firstColor = fadeState . interpolator . next ( ) ; fadeState . target . changeColor ( firstColor ) ; // Kick off the fade timer .
fadeState . timer . setActionCommand ( groupName ) ; fadeState . timer . setInitialDelay ( 400 ) ; fadeState . timer . start ( ) ;


signature: public class MockWebServerMatchers { private static CombinableMatcher < RecordedRequest > recordedRequest ( String expectedMethod , String expectedPath ) { } }

implementation: return Matchers . < RecordedRequest > both ( hasProperty ( "method" , is ( expectedMethod ) ) ) . and ( hasProperty ( "path" , is ( expectedPath ) ) ) ;


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

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


signature:
public class SwingMainWindow { /** * { @ inheritDoc } */
public void showMainWindow ( ) { } }

implementation: frame = new JFrame ( ) ; frame . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE ) ; frame . setMinimumSize ( new Dimension ( 800 , 600 ) ) ; frame . setPreferredSize ( new Dimension ( 1000 , 800 ) ) ; layout = new DesktopAppLayout ( ) ; frame . getContentPane ( ) . setLayout ( layout ) ; frame . setVisible ( true ) ; JRootPane rootPane = frame . getRootPane ( ) ; rootPane . getInputMap ( ) . put ( KeyStroke . getKeyStroke ( "SPACE" ) , "pressed" ) ;


signature:
public class SwingMainWindow { /** * { @ inheritDoc } */
public void showCentrePane ( JComponent component ) { } }

implementation: frame . getContentPane ( ) . add ( component , DesktopAppLayout . CENTER ) ; frame . pack ( ) ; centreComponent = component ;


signature:
public class SwingMainWindow { /** * { @ inheritDoc } */
public void showConsole ( JComponent component ) { } }

implementation: showHorizontalBar ( ) ; frame . getContentPane ( ) . add ( component , DesktopAppLayout . CONSOLE ) ; frame . pack ( ) ; consoleComponent = component ;


signature:
public class SwingMainWindow { /** * { @ inheritDoc } */
public void showLeftPane ( JComponent component ) { } }

implementation: showLeftBar ( ) ; frame . getContentPane ( ) . add ( component , DesktopAppLayout . LEFT_PANE ) ; frame . pack ( ) ; leftComponent = component ;


signature:
public class SwingMainWindow { /** * { @ inheritDoc } */
public void showRightPane ( JComponent component ) { } }

implementation: showRightBar ( ) ; frame . getContentPane ( ) . add ( component , DesktopAppLayout . RIGHT_PANE ) ; frame . pack ( ) ; rightComponent = component ;


signature:
public class SwingMainWindow { /** * { @ inheritDoc } */
public void setKeyShortcut ( KeyStroke keyCombination , String actionName , Runnable action ) { } }

implementation: frame . getRootPane ( ) . getInputMap ( JComponent . WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ) . put ( keyCombination , actionName ) ; frame . getRootPane ( ) . getActionMap ( ) . put ( actionName , new RunnableAction ( action ) ) ;


signature:
public class SwingMainWindow { /** * Creates a horizontal grip - able bar for adjusting the console height . */
private void showHorizontalBar ( ) { } }

implementation:
// Left vertical bar .
Component bar = factory . createGripPanel ( layout . getConsoleHeightResizer ( ) , false ) ; frame . getContentPane ( ) . add ( bar , DesktopAppLayout . STATUS_BAR ) ;


signature:
public class SwingMainWindow { /** * Creates a vertical grip - able bar for adjusting the left panel width . */
private void showLeftBar ( ) { } }

implementation:
// Left vertical bar .
Component bar = factory . createGripPanel ( layout . getLeftPaneWidthResizer ( ) , true ) ; frame . getContentPane ( ) . add ( bar , DesktopAppLayout . LEFT_VERTICAL_BAR ) ;


signature:
public class SwingMainWindow { /** * Creates a vertical grip - able bar for adjusting the right panel width . */
private void showRightBar ( ) { } }

implementation:
// Right vertical bar .
Component bar = factory . createGripPanel ( layout . getRightPaneWidthResizer ( ) , true ) ; frame . getContentPane ( ) . add ( bar , DesktopAppLayout . RIGHT_VERTICAL_BAR ) ;


signature: public class JsoupMicrodataDocument { public List < MicrodataItem > getItems ( String type ) { } }

implementation: Elements elements = document . select ( byItemType ( newUrl ( type ) ) ) ; return Lists . transform ( elements , new Function < Element , MicrodataItem > ( ) { public MicrodataItem apply ( Element element ) { return new JsoupMicrodataItem ( JsoupMicrodataDocument . this , element ) ; } } ) ;


signature: public class JsoupMicrodataDocument { public List < Link > getLinks ( String rel ) { } }

implementation: Elements elements = document . select ( byLink ( rel ) ) ; return Lists . transform ( elements , new Function < Element , Link > ( ) { public Link apply ( Element element ) { return new JsoupLink ( JsoupMicrodataDocument . this , element ) ; } } ) ;


signature: public class JsoupMicrodataDocument { public < T > T unwrap ( Class < T > type ) { } }

implementation: checkArgument ( Document . class . equals ( type ) , "Cannot unwrap to: %s" , type ) ; return type . cast ( document ) ;


signature: public class JsoupMicrodataDocument { private static Document sanitize ( Document document ) { } }

implementation: for ( FormElement form : document . getAllElements ( ) . forms ( ) ) { sanitizeRadioControls ( form ) ; } return document ;


signature:
public class JsoupMicrodataDocument { /** * Ensures that radio controls are mutually exclusive within control groups . */
private static void sanitizeRadioControls ( FormElement form ) { } }

implementation:
Map < String , Element > controlsByName = new HashMap < String , Element > ( ) ; for ( Element control : form . elements ( ) ) { // cannot use Element . select since Element . hashCode collapses like elements
if ( "radio" . equals ( control . attr ( "type" ) ) && control . hasAttr ( "checked" ) ) { String name = control . attr ( "name" ) ; if ( controlsByName . containsKey ( name ) ) { controlsByName . get ( name ) . attr ( "checked" , false ) ; } controlsByName . put ( name , control ) ; } }


signature:
public class BaseUnaryCondition { /** * Wait for the predicate to become true on the specified object .
 * @ param t The object to test for predicate membership .
 * @ throws InterruptedException If interrupted whilst waiting . */
public void await ( T t ) throws InterruptedException { } }

implementation:
synchronized ( monitor ) { long waitNanos = evaluateWithWaitTimeNanos ( t ) ; // Loop forever until all conditions pass or the thread is interrupted .
while ( waitNanos > 0 ) { // If some conditions failed , then wait for the shortest wait time , or until the thread is woken up by
// a signal , before re - evaluating conditions .
long milliPause = waitNanos / 1000000 ; int nanoPause = ( int ) ( waitNanos % 1000000 ) ; monitor . wait ( milliPause , nanoPause ) ; waitNanos = evaluateWithWaitTimeNanos ( t ) ; } }


signature:
public class BaseUnaryCondition { /** * Wait for up to a timeout limit for the predicate to become true on the specified object .
 * @ param t The object to test for predicate membership .
 * @ param timeout The amount of time to wait .
 * @ param unit The units of time used .
 * @ return < tt > true < / tt > if the predicate became true before the timeout expired , < tt > false < / tt > otherwise .
 * @ throws InterruptedException If interrupted whilst waiting . */
public boolean await ( T t , long timeout , TimeUnit unit ) throws InterruptedException { } }

implementation:
synchronized ( monitor ) { // Holds the absolute time when the timeout expires .
long expiryTimeNanos = System . nanoTime ( ) + unit . toNanos ( timeout ) ; // Used to hold the estimated wait time until the condition may pass .
long waitNanos = evaluateWithWaitTimeNanos ( t ) ; // Loop forever until all conditions pass , the timeout expires , or the thread is interrupted .
while ( waitNanos > 0 ) { // Check how much time remains until the timeout expires .
long remainingTimeNanos = expiryTimeNanos - System . nanoTime ( ) ; // Check if the timeout has expired .
if ( remainingTimeNanos <= 0 ) { return false ; } // If some conditions failed , then wait for the shortest of the wait time or the remaining time until the
// timout expires , or until the thread is woken up by a signal , before re - evaluating conditions .
long timeToPauseNanos = ( waitNanos < remainingTimeNanos ) ? waitNanos : remainingTimeNanos ; long milliPause = timeToPauseNanos / 1000000 ; int nanoPause = ( int ) ( timeToPauseNanos % 1000000 ) ; monitor . wait ( milliPause , nanoPause ) ; // Re - evelaute the condition and obtain a new estimate of how long until it may pass .
waitNanos = evaluateWithWaitTimeNanos ( t ) ; } } // All conditions have passed when the above loop terminates .
return true ;


signature:
public class ScriptGenMojo { /** * Implementation of the script goal .
 * @ throws MojoExecutionException */
public void execute ( ) throws MojoExecutionException , MojoFailureException { } }

implementation:
// log . debug ( " public void execute ( ) throws MojoExecutionException : called " ) ;
// Turn each of the test runner command lines into a script .
for ( String commandName : commands . keySet ( ) ) { if ( scriptOutDirectory != null ) { writeUnixScript ( commandName , scriptOutDirectory ) ; writeWindowsScript ( commandName , scriptOutDirectory ) ; } }


signature:
public class ScriptGenMojo { /** * Appends the classpath onto the command line .
 * @ param commandLine The command line to append to .
 * @ param unix < tt > true < / tt > to use unix paths , < tt > false < / tt > to use windows .
 * @ return The appended to command line . */
protected String appendClasspath ( String commandLine , boolean unix ) { } }

implementation: String pathSeperator ; String seperator ; if ( unix ) { pathSeperator = "/" ; seperator = ":" ; } else { pathSeperator = "\\" ; seperator = ";" ; } for ( Iterator i = classpathElements . iterator ( ) ; i . hasNext ( ) ; ) { String cpPath = ( String ) i . next ( ) ; cpPath = cpPath . replace ( "/" , pathSeperator ) ; commandLine += cpPath + ( i . hasNext ( ) ? seperator : "" ) ; } return commandLine ;


signature:
public class DateRangeType { /** * Creates a new date range type with the specified name , if it does not already exist .
 * @ param name The name of the date range type to create .
 * @ param from The minimum value that an instance of the type can take .
 * @ param to The maximum value that an instance of teh type can take .
 * @ return A new date range type .
 * @ throws IllegalArgumentException If min is not less than or equal to max , or the named type already exists . */
public static Type createInstance ( String name , DateOnly from , DateOnly to ) { } }

implementation:
// Ensure that min is less than or equal to max .
if ( ( from != null ) && ( to != null ) && ( from . compareTo ( to ) > 0 ) ) { throw new IllegalArgumentException ( "'min' must be less than or equal to 'max'." ) ; } synchronized ( DATE_RANGE_TYPES ) { // Add the newly created type to the map of all types .
DateRangeType newType = new DateRangeType ( name , from , to ) ; // Ensure that the named type does not already exist , unless it has an identical definition already , in which
// case the old definition can be re - used and the new one discarded .
DateRangeType oldType = DATE_RANGE_TYPES . get ( name ) ; if ( ( oldType != null ) && ! oldType . equals ( newType ) ) { throw new IllegalArgumentException ( "The type '" + name + "' already exists and cannot be redefined." ) ; } else if ( ( oldType != null ) && oldType . equals ( newType ) ) { return oldType ; } else { DATE_RANGE_TYPES . put ( name , newType ) ; return newType ; } }


signature:
public class DateRangeType { /** * { @ inheritDoc } */
public void acceptVisitor ( TypeVisitor visitor ) { } }

implementation: if ( visitor instanceof DateRangeTypeVisitor ) { ( ( DateRangeTypeVisitor ) visitor ) . visit ( this ) ; } else { super . acceptVisitor ( visitor ) ; }


signature:
public class VariableBindingStackFrame { /** * Frees all variables held in this stack frame , and sets all the stack slots to < tt > null < / tt > . Note that as the
 * stack slots are < tt > null < / tt > the { @ link # getStorageCell ( StackVariable ) } method will not return valid storage
 * cells any more . This method should therefore only be used to clean up the stack frame when it is no longer
 * needed . */
public void free ( ) { } }

implementation: for ( int i = 0 ; i < bindings . length ; i ++ ) { if ( bindings [ i ] != null ) { bindings [ i ] . free ( ) ; bindings [ i ] = null ; } }


signature: public class SeleniumMicrodataItem { public List < Link > getLinks ( String rel ) { } }

implementation: List < WebElement > elements = element . findElements ( byLink ( rel ) ) ; return Lists . transform ( elements , new Function < WebElement , Link > ( ) { public Link apply ( WebElement element ) { return new SeleniumLink ( driver , element ) ; } } ) ;


signature:
public class ResolutionInterpreter { /** * Implements the top - level interpreter loop . This will parse and evaluate sentences until it encounters an CTRL - D
 * in query mode , at which point the interpreter will terminate .
 * @ throws SourceCodeException If malformed code is encountered .
 * @ throws IOException If an IO error is encountered whilst reading the source code . */
public void interpreterLoop ( ) throws IOException { } }

implementation:
// Display the welcome message .
printIntroduction ( ) ; // Initialize the JLine console .
consoleReader = initializeCommandLineReader ( ) ; // Used to buffer input , and only feed it to the parser when a PERIOD is encountered .
TokenBuffer tokenBuffer = new TokenBuffer ( ) ; // Used to hold the currently buffered lines of input , for the purpose of presenting this back to the user
// in the event of a syntax or other error in the input .
ArrayList < String > inputLines = new ArrayList < String > ( ) ; // Used to count the number of lines entered .
int lineNo = 0 ; while ( true ) { String line = null ; try { line = consoleReader . readLine ( mode . prompt ) ; inputLines . add ( line ) ; // JLine returns null if CTRL - D is pressed . Exit program mode back to query mode , or exit the
// interpreter completely from query mode .
if ( ( line == null ) && ( ( mode == Mode . Query ) || ( mode == Mode . QueryMultiLine ) ) ) { /* log . fine ( " CTRL - D in query mode , exiting . " ) ; */
System . out . println ( ) ; break ; } else if ( ( line == null ) && ( ( mode == Mode . Program ) || ( mode == Mode . ProgramMultiLine ) ) ) { /* log . fine ( " CTRL - D in program mode , returning to query mode . " ) ; */
System . out . println ( ) ; mode = Mode . Query ; continue ; } // Check the input to see if a system directive was input . This is only allowed in query mode , and is
// handled differently to normal queries .
if ( mode == Mode . Query ) { Source < Token > tokenSource = new OffsettingTokenSource ( TokenSource . getTokenSourceForString ( line ) , lineNo ) ; parser . setTokenSource ( tokenSource ) ; PrologParser . Directive directive = parser . peekAndConsumeDirective ( ) ; if ( directive != null ) { switch ( directive ) { case Trace : /* log . fine ( " Got trace directive . " ) ; */
break ; case Info : /* log . fine ( " Got info directive . " ) ; */
break ; case User : /* log . fine ( " Got user directive , entering program mode . " ) ; */
mode = Mode . Program ; break ; } inputLines . clear ( ) ; continue ; } } // For normal queries , the query functor ' ? - ' begins every statement , this is not passed back from
// JLine even though it is used as the command prompt .
if ( mode == Mode . Query ) { line = QUERY_PROMPT + line ; inputLines . set ( inputLines . size ( ) - 1 , line ) ; } // Buffer input tokens until EOL is reached , of the input is terminated with a PERIOD .
Source < Token > tokenSource = new OffsettingTokenSource ( TokenSource . getTokenSourceForString ( line ) , lineNo ) ; Token nextToken ; while ( true ) { nextToken = tokenSource . poll ( ) ; if ( nextToken == null ) { break ; } if ( nextToken . kind == PrologParserConstants . PERIOD ) { /* log . fine ( " Token was PERIOD . " ) ; */
mode = ( mode == Mode . QueryMultiLine ) ? Mode . Query : mode ; mode = ( mode == Mode . ProgramMultiLine ) ? Mode . Program : mode ; tokenBuffer . offer ( nextToken ) ; break ; } else if ( nextToken . kind == PrologParserConstants . EOF ) { /* log . fine ( " Token was EOF . " ) ; */
mode = ( mode == Mode . Query ) ? Mode . QueryMultiLine : mode ; mode = ( mode == Mode . Program ) ? Mode . ProgramMultiLine : mode ; lineNo ++ ; break ; } tokenBuffer . offer ( nextToken ) ; } // Evaluate the current token buffer , whenever the input is terminated with a PERIOD .
if ( ( nextToken != null ) && ( nextToken . kind == PrologParserConstants . PERIOD ) ) { parser . setTokenSource ( tokenBuffer ) ; // Parse the next clause .
Sentence < Clause > nextParsing = parser . parse ( ) ; /* log . fine ( nextParsing . toString ( ) ) ; */
evaluate ( nextParsing ) ; inputLines . clear ( ) ; } } catch ( SourceCodeException e ) { SourceCodePosition sourceCodePosition = e . getSourceCodePosition ( ) . asZeroOffsetPosition ( ) ; int startLine = sourceCodePosition . getStartLine ( ) ; int endLine = sourceCodePosition . getEndLine ( ) ; int startColumn = sourceCodePosition . getStartColumn ( ) ; int endColumn = sourceCodePosition . getEndColumn ( ) ; System . out . println ( "[(" + startLine + ", " + startColumn + "), (" + endLine + ", " + endColumn + ")]" ) ; for ( int i = 0 ; i < inputLines . size ( ) ; i ++ ) { String errorLine = inputLines . get ( i ) ; System . out . println ( errorLine ) ; // Check if the line has the error somewhere in it , and mark the part of it that contains the error .
int pos = 0 ; if ( i == startLine ) { for ( ; pos < startColumn ; pos ++ ) { System . out . print ( " " ) ; } } if ( i == endLine ) { for ( ; pos <= endColumn ; pos ++ ) { System . out . print ( "^" ) ; } System . out . println ( ) ; } if ( ( i > startLine ) && ( i < endLine ) ) { for ( ; pos < errorLine . length ( ) ; pos ++ ) { System . out . print ( "^" ) ; } System . out . println ( ) ; } } System . out . println ( ) ; System . out . println ( e . getMessage ( ) ) ; System . out . println ( ) ; inputLines . clear ( ) ; tokenBuffer . clear ( ) ; } }


signature:
public class ResolutionInterpreter { /** * Prints a welcome message . */
private void printIntroduction ( ) { } }

implementation: System . out . println ( "| LoJiX Prolog." ) ; System . out . println ( "| Copyright The Sett Ltd." ) ; System . out . println ( "| Licensed under the Apache License, Version 2.0." ) ; System . out . println ( "| //www.apache.org/licenses/LICENSE-2.0" ) ; System . out . println ( ) ;


signature:
public class ResolutionInterpreter { /** * Sets up the JLine console reader .
 * @ return A JLine console reader .
 * @ throws IOException If an IO error is encountered while reading the input . */
private ConsoleReader initializeCommandLineReader ( ) throws IOException { } }

implementation: ConsoleReader reader = new ConsoleReader ( ) ; reader . setBellEnabled ( false ) ; return reader ;


signature:
public class ResolutionInterpreter { /** * Evaluates a query against the resolver or adds a clause to the resolvers domain .
 * @ param sentence The clausal sentence to run as a query or as a clause to add to the domain .
 * @ throws SourceCodeException If the query or domain clause fails to compile or link into the resolver . */
private void evaluate ( Sentence < Clause > sentence ) throws SourceCodeException { } }

implementation:
Clause clause = sentence . getT ( ) ; if ( clause . isQuery ( ) ) { engine . endScope ( ) ; engine . compile ( sentence ) ; evaluateQuery ( ) ; } else { // Check if the program clause is new , or a continuation of the current predicate .
int name = clause . getHead ( ) . getName ( ) ; if ( ( currentPredicateName == null ) || ( currentPredicateName != name ) ) { engine . endScope ( ) ; currentPredicateName = name ; } addProgramClause ( sentence ) ; }


signature:
public class ResolutionInterpreter { /** * Evaluates a query . In the case of queries , the interner is used to recover textual names for the resulting
 * variable bindings . The user is queried through the parser to if more than one solution is required . */
private void evaluateQuery ( ) { } }

implementation:
/* log . fine ( " Read query from input . " ) ; */
// Create an iterator to generate all solutions on demand with . Iteration will stop if the request to
// the parser for the more ' ; ' token fails .
Iterator < Set < Variable > > i = engine . iterator ( ) ; if ( ! i . hasNext ( ) ) { System . out . println ( "false. " ) ; return ; } for ( ; i . hasNext ( ) ; ) { Set < Variable > solution = i . next ( ) ; if ( solution . isEmpty ( ) ) { System . out . print ( "true" ) ; } else { for ( Iterator < Variable > j = solution . iterator ( ) ; j . hasNext ( ) ; ) { Variable nextVar = j . next ( ) ; String varName = engine . getVariableName ( nextVar . getName ( ) ) ; System . out . print ( varName + " = " + nextVar . getValue ( ) . toString ( engine , true , false ) ) ; if ( j . hasNext ( ) ) { System . out . println ( ) ; } } } // Finish automatically if there are no more solutions .
if ( ! i . hasNext ( ) ) { System . out . println ( "." ) ; break ; } // Check if the user wants more solutions .
try { int key = consoleReader . readVirtualKey ( ) ; if ( key == SEMICOLON ) { System . out . println ( " ;" ) ; } else { System . out . println ( ) ; break ; } } catch ( IOException e ) { throw new IllegalStateException ( e ) ; } }


signature:
public class TypeConverter { /** * Converts a boolean into a multi type data object .
 * @ param b The boolean to convert .
 * @ return A multi type data object holding all the types that the boolean can be converted into . */
public static MultiTypeData getMultiTypeData ( boolean b ) { } }

implementation:
// Convert the value to a String and return the set of types that that String can be converted to .
MultiTypeData result = getMultiTypeData ( Boolean . toString ( b ) ) ; result . nativeType = BOOLEAN ; return result ;


signature:
public class TypeConverter { /** * Converts a byte into a multi type data object .
 * @ param b The byte to convert .
 * @ return A multi type data object holding all the types that the byte can be converted into . */
public static MultiTypeData getMultiTypeData ( byte b ) { } }

implementation:
// Convert the value to a String and return the set of types that that String can be converted to .
MultiTypeData result = getMultiTypeData ( Byte . toString ( b ) ) ; result . nativeType = BYTE ; return result ;


signature:
public class TypeConverter { /** * Converts a char into a multi type data object .
 * @ param c The char to convert .
 * @ return A multi type data object holding all the types that the char can be converted into . */
public static MultiTypeData getMultiTypeData ( char c ) { } }

implementation:
// Convert the value to a String and return the set of types that that String can be converted to .
MultiTypeData result = getMultiTypeData ( Character . toString ( c ) ) ; result . nativeType = CHAR ; return result ;


signature:
public class TypeConverter { /** * Converts a short into a multi type data object .
 * @ param s The short to convert .
 * @ return A multi type data object holding all the types that the short can be converted into . */
public static MultiTypeData getMultiTypeData ( short s ) { } }

implementation:
// Convert the value to a String and return the set of types that that String can be converted to .
MultiTypeData result = getMultiTypeData ( Short . toString ( s ) ) ; result . nativeType = SHORT ; return result ;


signature:
public class TypeConverter { /** * Converts a int into a multi type data object .
 * @ param i The int to convert .
 * @ return A multi type data object holding all the types that the int can be converted into . */
public static MultiTypeData getMultiTypeData ( int i ) { } }

implementation:
// Convert the value to a String and return the set of types that that String can be converted to .
MultiTypeData result = getMultiTypeData ( Integer . toString ( i ) ) ; result . nativeType = INT ; return result ;


signature:
public class TypeConverter { /** * Converts a long into a multi type data object .
 * @ param l The long to convert .
 * @ return A multi type data object holding all the types that the long can be converted into . */
public static MultiTypeData getMultiTypeData ( long l ) { } }

implementation:
// Convert the value to a String and return the set of types that that String can be converted to .
MultiTypeData result = getMultiTypeData ( Long . toString ( l ) ) ; result . nativeType = LONG ; return result ;


signature:
public class TypeConverter { /** * Converts a float into a multi type data object .
 * @ param f The float to convert .
 * @ return A multi type data object holding all the types that the float can be converted into . */
public static MultiTypeData getMultiTypeData ( float f ) { } }

implementation:
// Convert the value to a String and return the set of types that that String can be converted to .
MultiTypeData result = getMultiTypeData ( Float . toString ( f ) ) ; result . nativeType = FLOAT ; return result ;


signature:
public class TypeConverter { /** * Converts a double into a multi type data object .
 * @ param d The double to convert .
 * @ return A multi type data object holding all the types that the double can be converted into . */
public static MultiTypeData getMultiTypeData ( double d ) { } }

implementation:
// Convert the value to a String and return the set of types that that String can be converted to .
MultiTypeData result = getMultiTypeData ( Double . toString ( d ) ) ; result . nativeType = DOUBLE ; return result ;


signature:
public class TypeConverter { /** * Converts a String into a multi type data object .
 * < p / > This method will return the native type as String . Methods that use this one to convert other types via
 * String should override this with the correct native type .
 * @ param s The String to convert .
 * @ return A multi type data object holding all the types that the String can be converted into . */
public static MultiTypeData getMultiTypeData ( String s ) { } }

implementation:
MultiTypeData result = new MultiTypeData ( ) ; // Start by assuming that the String can only be converted to a String .
result . typeFlags = STRING ; result . stringValue = s ; // Assume that the native type is String . It is up to methods that call this one to override this if this is
// not the case .
result . nativeType = STRING ; // Check if the string can be converted to a boolean .
if ( "true" . equals ( s ) ) { result . booleanValue = true ; result . typeFlags |= BOOLEAN ; } else if ( "false" . equals ( s ) ) { result . booleanValue = false ; result . typeFlags |= BOOLEAN ; } // Check if the string can be converted to an int .
try { result . intValue = Integer . parseInt ( s ) ; result . typeFlags |= INT ; } catch ( NumberFormatException e ) { // Exception noted so can be ignored .
e = null ; result . typeFlags &= ( Integer . MAX_VALUE - INT ) ; } // Check if the string can be converted to a byte .
try { result . byteValue = Byte . parseByte ( s ) ; result . typeFlags |= BYTE ; } catch ( NumberFormatException e ) { // Exception noted so can be ignored .
e = null ; result . typeFlags = ( Integer . MAX_VALUE - BYTE ) ; } // Check if the string can be converted to a char .
if ( s . length ( ) == 1 ) { result . charValue = s . charAt ( 0 ) ; result . typeFlags |= CHAR ; } // Check if the string can be converted to a short .
try { result . shortValue = Short . parseShort ( s ) ; result . typeFlags |= SHORT ; } catch ( NumberFormatException e ) { // Exception noted so can be ignored .
e = null ; result . typeFlags = ( Integer . MAX_VALUE - SHORT ) ; } // Check if the string can be converted to a long .
try { result . longValue = Long . parseLong ( s ) ; result . typeFlags |= LONG ; } catch ( NumberFormatException e ) { // Exception noted so can be ignored .
e = null ; result . typeFlags = ( Integer . MAX_VALUE - LONG ) ; } // Check if the string can be converted to a float .
try { result . floatValue = Float . parseFloat ( s ) ; result . typeFlags |= FLOAT ; } catch ( NumberFormatException e ) { // Exception noted so can be ignored .
e = null ; result . typeFlags = ( Integer . MAX_VALUE - FLOAT ) ; } // Check if the string can be converted to a double .
try { result . doubleValue = Double . parseDouble ( s ) ; result . typeFlags |= DOUBLE ; } catch ( NumberFormatException e ) { // Exception noted so can be ignored .
e = null ; result . typeFlags = ( Integer . MAX_VALUE - DOUBLE ) ; } // Assume the string can never be converted to an object .
return result ;


signature:
public class TypeConverter { /** * Converts a Object into a multi type data object .
 * @ param o The Object to convert .
 * @ return A multi type data object holding all the types that the Object can be converted into . */
public static MultiTypeData getMultiTypeData ( Object o ) { } }

implementation:
// Convert the value to a String and return the set of types that that String can be converted to .
MultiTypeData result = getMultiTypeData ( o . toString ( ) ) ; result . nativeType = OBJECT ; return result ;


signature:
public class TypeConverter { /** * Given a multi type data object and a class representing a type , this method attemps to return an object of that
 * class created from the multi type data . The exception to this rule is if the specified data type is a primtive
 * type , such as int . clas , then the returned object will be of the equivalent wrapper class type , Integer . class in
 * this case . This is because a primitive cannot be returned under an Object return type .
 * @ param d The multi type data object to convert .
 * @ param c The class to convert to .
 * @ return An object of the specified class which is the result of converting the multi type data object to that
 * class .
 * @ exception ClassCastException Is thrown if the multi type data object cannot be converted to the specified class . */
public static Object convert ( MultiTypeData d , Class c ) { } }

implementation:
// Check if it is an boolean convertion .
if ( ( ( d . typeFlags & BOOLEAN ) != 0 ) && ( Boolean . TYPE . equals ( c ) || Boolean . class . equals ( c ) ) ) { return d . booleanValue ; } // Check if it is an int convertion .
else if ( ( ( d . typeFlags & INT ) != 0 ) && ( Integer . TYPE . equals ( c ) || Integer . class . equals ( c ) ) ) { return d . intValue ; } // Check if it is an char convertion .
else if ( ( ( d . typeFlags & CHAR ) != 0 ) && ( Character . TYPE . equals ( c ) || Character . class . equals ( c ) ) ) { return d . charValue ; } // Check if it is an byte convertion .
else if ( ( ( d . typeFlags & BYTE ) != 0 ) && ( Byte . TYPE . equals ( c ) || Byte . class . equals ( c ) ) ) { return d . byteValue ; } // Check if it is an short convertion .
else if ( ( ( d . typeFlags & SHORT ) != 0 ) && ( Short . TYPE . equals ( c ) || Short . class . equals ( c ) ) ) { return d . shortValue ; } // Check if it is an long convertion .
else if ( ( ( d . typeFlags & LONG ) != 0 ) && ( Long . TYPE . equals ( c ) || Long . class . equals ( c ) ) ) { return d . longValue ; } // Check if it is an float convertion .
else if ( ( ( d . typeFlags & FLOAT ) != 0 ) && ( Float . TYPE . equals ( c ) || Float . class . equals ( c ) ) ) { return d . floatValue ; } // Check if it is an double convertion .
else if ( ( ( d . typeFlags & DOUBLE ) != 0 ) && ( Double . TYPE . equals ( c ) || Double . class . equals ( c ) ) ) { return d . doubleValue ; } // Check if it is a string convertion .
else if ( ( ( d . typeFlags & STRING ) != 0 ) && String . class . equals ( c ) ) { return d . stringValue ; } // Check if it is an object convertion and th object types match .
else if ( ( ( d . typeFlags & OBJECT ) != 0 ) && d . objectValue . getClass ( ) . equals ( c ) ) { return d . objectValue ; } // Throw a class cast exception if the multi data type cannot be converted to the specified class .
else { throw new ClassCastException ( "The multi data type, " + d + ", cannot be converted to the class, " + c + "." ) ; }


signature:
public class TypeConverter { /** * For a set of types this method selects the best type to convert a given multi type data object into . This method
 * can be usefull when deciding which of several setter methods on a bean is the best one to convert the multi type
 * data obejct into before calling the beans setter method .
 * < p / > This method tries first to match the native type of the multi type data and then tries the other types in
 * this order : Object , boolean , char , byte , short , int , long , float , double , String . The Object type is only matched
 * if the multi type data object has a native Object type and the class of that object exactly matches one of the
 * possible classes to convert to .
 * < p / > If the set of classes to convert to contains a primitive class type , such as int . class , and this is matched
 * the primitive class will be returned , int . class in this case . If the set of classes to convert to contains a
 * wrapper class , such as Integer . class , and this is matched then this will be returned . The primitive classes are
 * always matched first so if both the primitive and wrapper versions are in the set to be matched then the
 * primitive version will be returned .
 * @ param d The multi type data object to test for best convertion .
 * @ param types The possible set of classes to convert to .
 * @ return The best matching class or null if none can be matched . */
public static Class bestMatchingConversion ( MultiTypeData d , Collection < Class > types ) { } }

implementation:
/* log . fine ( " public static Class bestMatchingConvertion ( MultiTypeData d , Set < Class > types ) : called " ) ; */
/* log . fine ( " d = " + d ) ; */
/* log . fine ( " types = " + types ) ; */
// Try to match the native type first before trying the convertions .
switch ( d . nativeType ) { case OBJECT : { // Check if the matching Object class can be found in the set of possible classes .
if ( types . contains ( d . objectValue . getClass ( ) ) ) { return d . objectValue . getClass ( ) ; } break ; } case BOOLEAN : { // Check if boolean is in the set of possible classes to match .
if ( types . contains ( boolean . class ) ) { return boolean . class ; } else if ( types . contains ( Boolean . class ) ) { return Boolean . class ; } break ; } case CHAR : { // Check if char is in the set of possible classes to match .
if ( types . contains ( char . class ) ) { return char . class ; } else if ( types . contains ( Character . class ) ) { return Character . class ; } break ; } case BYTE : { // Check if byte is in the set of possible classes to match .
if ( types . contains ( byte . class ) ) { return byte . class ; } else if ( types . contains ( Byte . class ) ) { return Byte . class ; } break ; } case SHORT : { // Check if short is in the set of possible classes to match .
if ( types . contains ( short . class ) ) { return short . class ; } else if ( types . contains ( Short . class ) ) { return Short . class ; } break ; } case INT : { // Check if int is in the set of possible classes to match .
if ( types . contains ( int . class ) ) { return int . class ; } else if ( types . contains ( Integer . class ) ) { return Integer . class ; } break ; } case LONG : { // Check if long is in the set of possible classes to match .
if ( types . contains ( long . class ) ) { return long . class ; } else if ( types . contains ( Long . class ) ) { return Long . class ; } break ; } case FLOAT : { // Check if float is in the set of possible classes to match .
if ( types . contains ( float . class ) ) { return float . class ; } else if ( types . contains ( Float . class ) ) { return Float . class ; } break ; } case DOUBLE : { // Check if double is in the set of possible classes to match .
if ( types . contains ( double . class ) ) { return double . class ; } else if ( types . contains ( Double . class ) ) { return Double . class ; } break ; } case STRING : { // Check if String is in the set of possible classes to match .
if ( types . contains ( String . class ) ) { return String . class ; } break ; } default : { throw new IllegalStateException ( "Unknown MultiTypeData type." ) ; } } // Check if the multi type can be converted to a boolean and boolean is in the set of possible convertions .
if ( ( ( d . typeFlags & BOOLEAN ) != 0 ) && types . contains ( boolean . class ) ) { return boolean . class ; } else if ( ( ( d . typeFlags & BOOLEAN ) != 0 ) && types . contains ( Boolean . class ) ) { return Boolean . class ; } // Check if the multi type can be converted to a byte and byte is in the set of possible convertions .
else if ( ( ( d . typeFlags & BYTE ) != 0 ) && types . contains ( byte . class ) ) { return byte . class ; } else if ( ( ( d . typeFlags & BYTE ) != 0 ) && types . contains ( Byte . class ) ) { return Byte . class ; } // Check if the multi type can be converted to a char and char is in the set of possible convertions .
else if ( ( ( d . typeFlags & CHAR ) != 0 ) && types . contains ( char . class ) ) { return char . class ; } else if ( ( ( d . typeFlags & CHAR ) != 0 ) && types . contains ( Character . class ) ) { return Character . class ; } // Check if the multi type can be converted to a short and short is in the set of possible convertions .
else if ( ( ( d . typeFlags & SHORT ) != 0 ) && types . contains ( short . class ) ) { return short . class ; } else if ( ( ( d . typeFlags & SHORT ) != 0 ) && types . contains ( Short . class ) ) { return Short . class ; } // Check if the multi type can be converted to a int and int is in the set of possible convertions .
else if ( ( ( d . typeFlags & INT ) != 0 ) && types . contains ( int . class ) ) { return int . class ; } else if ( ( ( d . typeFlags & INT ) != 0 ) && types . contains ( Integer . class ) ) { return Integer . class ; } // Check if the multi type can be converted to a long and long is in the set of possible convertions .
else if ( ( ( d . typeFlags & LONG ) != 0 ) && types . contains ( long . class ) ) { return long . class ; } else if ( ( ( d . typeFlags & LONG ) != 0 ) && types . contains ( Long . class ) ) { return Long . class ; } // Check if the multi type can be converted to a float and float is in the set of possible convertions .
else if ( ( ( d . typeFlags & FLOAT ) != 0 ) && types . contains ( float . class ) ) { return float . class ; } else if ( ( ( d . typeFlags & FLOAT ) != 0 ) && types . contains ( Float . class ) ) { return Float . class ; } // Check if the multi type can be converted to a double and double is in the set of possible convertions .
else if ( ( ( d . typeFlags & DOUBLE ) != 0 ) && types . contains ( double . class ) ) { return double . class ; } else if ( ( ( d . typeFlags & DOUBLE ) != 0 ) && types . contains ( Double . class ) ) { return Double . class ; } // Check if the multi type can be converted to a String and String is in the set of possible convertions .
else if ( ( ( d . typeFlags & STRING ) != 0 ) && types . contains ( String . class ) ) { return String . class ; } // No matching type convertion found so return null .
else { return null ; }


signature:
public class ScopeHelper { /** * Inserts an object into the scope .
 * @ param name The name of the variable to set .
 * @ param value The value to set . */
public void put ( String name , Object value ) { } }

implementation: pageContext . setAttribute ( name , value , scope ) ;


signature:
public class DimensionTable { /** * Checks is the specified dimension is equivalent . Equivalent means same
 * informations ( including type ) , same defaults , same links
 * @ param otherDim The { @ link DimensionTable } to compare for equivalence against
 * @ param errors An { @ link Error } collection that will be populated with any
 * additional { @ link Error } s
 * @ return true if equivalent false otherwise */
public boolean isEquivalent ( DimensionTable otherDim , Collection < Error > errors ) { } }

implementation: if ( this . informationNameToColumn . size ( ) != otherDim . informationNameToColumn . size ( ) ) { errors . add ( new Error ( "[" + this . getDimensionName ( ) + "-" + otherDim . getDimensionName ( ) + "] - Not the same number of informations." ) ) ; return false ; } for ( Entry < String , AbstractSqlColumn > entry : this . informationNameToColumn . entrySet ( ) ) { AbstractSqlColumn otherCol = otherDim . informationNameToColumn . get ( entry . getKey ( ) ) ; if ( otherCol == null ) { errors . add ( new Error ( "[" + this . getDimensionName ( ) + "-" + otherDim . getDimensionName ( ) + "] - Information named " + entry . getKey ( ) + " not found in " + otherDim . getDimensionName ( ) + "." ) ) ; return false ; } if ( ! otherCol . getBusinessName ( ) . equals ( entry . getValue ( ) . getBusinessName ( ) ) ) { errors . add ( new Error ( "[" + this . getDimensionName ( ) + "-" + otherDim . getDimensionName ( ) + "] - Information named " + entry . getKey ( ) + " have not the same name." ) ) ; return false ; } if ( otherCol . getColumnType ( ) != entry . getValue ( ) . getColumnType ( ) ) { errors . add ( new Error ( "[" + this . getDimensionName ( ) + "-" + otherDim . getDimensionName ( ) + "] - Information named " + entry . getKey ( ) + " are not the same type." ) ) ; return false ; } } if ( ! otherDim . getDefaultSearchColumn ( ) . getBusinessName ( ) . equals ( this . getDefaultSearchColumn ( ) . getBusinessName ( ) ) ) { errors . add ( new Error ( "[" + this . getDimensionName ( ) + "-" + otherDim . getDimensionName ( ) + "] - \"default search\" are not the same." ) ) ; return false ; } if ( ! otherDim . getDefaultGroupByColumn ( ) . getBusinessName ( ) . equals ( this . getDefaultGroupByColumn ( ) . getBusinessName ( ) ) ) { errors . add ( new Error ( "[" + this . getDimensionName ( ) + "-" + otherDim . getDimensionName ( ) + "] - \"default group by\" are not the same." ) ) ; return false ; } if ( ! otherDim . getLinkedTables ( ) . equals ( this . getLinkedTables ( ) ) ) { errors . add ( new Error ( "[" + this . getDimensionName ( ) + "-" + otherDim . getDimensionName ( ) + "] - Have not the same linked tables." ) ) ; return false ; } return true ;


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

implementation: String head = traverser . isInHead ( ) ? "/head" : "" ; String last = traverser . isLastBodyFunctor ( ) ? "/last" : "" ; String symKey = functor . getSymbolKey ( ) . toString ( ) ; if ( traverser . isTopLevel ( ) ) { addLineToRow ( "functor(" + symKey + ")" + head + last ) ; } else { addLineToRow ( "arg(" + symKey + ")" ) ; } nextRow ( ) ;


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

implementation: Integer allocation = ( Integer ) symbolTable . get ( variable . getSymbolKey ( ) , "allocation" ) ; String symKey = variable . getSymbolKey ( ) . toString ( ) ; String allocString = "" ; if ( allocation != null ) { int slot = ( allocation & ( 0xff ) ) ; int mode = allocation >> 8 ; allocString = ( ( mode == STACK_ADDR ) ? "Y" : "X" ) + slot ; } addLineToRow ( "arg/var(" + symKey + ") " + allocString ) ; nextRow ( ) ;


signature:
public class CircularArrayMap { /** * { @ inheritDoc }
 * @ throws ClassCastException If the key is not an Integer . */
public boolean containsKey ( Object objectKey ) { } }

implementation: int key = ( Integer ) objectKey ; return keyInRange ( key ) && ( data [ offset ( key ) ] != null ) ;


signature:
public class CircularArrayMap { /** * { @ inheritDoc }
 * @ throws ClassCastException If the key is not an Integer . */
public V get ( Object objectKey ) { } }

implementation: int key = ( Integer ) objectKey ; if ( keyInRange ( key ) ) { return ( V ) data [ offset ( key ) ] ; } return null ;


signature:
public class CircularArrayMap { /** * { @ inheritDoc } */
public V put ( Integer key , V value ) { } }

implementation:
if ( keyTooLarge ( key ) ) { expand ( key ) ; } int offset = offset ( key ) ; V oldValue = ( V ) data [ offset ] ; data [ offset ] = value ; // If the key is beyond the current end of the array , then move the end up .
if ( key >= end ) { end = key + 1 ; } // Increment the count only if a new value was inserted .
if ( oldValue == null ) { count ++ ; } return oldValue ;


signature:
public class CircularArrayMap { /** * Clears entries up to and including the specified key , from the map . This is a simple garbage collection operation
 * to clear consumed data from the circular buffer .
 * @ param key The key to clear up to . */
public void clearUpTo ( int key ) { } }

implementation:
if ( ( ( start <= key ) && ( key < ( end - 1 ) ) ) ) { // Loop from the start of the data , up to the key to clear up to , clearing all data encountered in - between .
int newStart ; for ( newStart = start ; ( newStart <= end ) && ( newStart <= key ) ; newStart ++ ) { int offset = offset ( newStart ) ; if ( data [ offset ] != null ) { data [ offset ] = null ; count -- ; } } // Continue on after the clear up to point , until the first non - null entry or end of array is encountered ,
// and make that the new start .
for ( ; newStart <= end ; newStart ++ ) { if ( data [ offset ( newStart ) ] != null ) { break ; } } start = newStart ; } else { // The key does not lie between the start and end markers , so clear the entire map up to the end
int newStart ; for ( newStart = start ; ( newStart <= end ) ; newStart ++ ) { int offset = offset ( newStart ) ; if ( data [ offset ] != null ) { data [ offset ] = null ; count -- ; } } start = newStart ; offset = - start ; }


signature:
public class CircularArrayMap { /** * { @ inheritDoc } */
public V remove ( Object objectKey ) { } }

implementation:
int key = ( Integer ) objectKey ; if ( keyInRange ( key ) ) { // Check if the key is the first element in the list , and walk forward to find the next non - empty element
// in order to advance the start to .
if ( key == start ) { int newStart = start + 1 ; while ( ( data [ offset ( newStart ) ] == null ) && ( newStart <= end ) ) { newStart ++ ; } start = newStart ; } int offset = offset ( key ) ; V result = ( V ) data [ offset ] ; data [ offset ] = null ; // Decrement the count only if a value was removed .
if ( result != null ) { count -- ; } return result ; } return null ;


signature:
public class CircularArrayMap { /** * { @ inheritDoc } */
public void clear ( ) { } }

implementation: data = new Object [ data . length ] ; length = data . length ; lowMark = - 1 ; start = 0 ; end = 0 ; count = 0 ; offset = 0 ;