signature:
public class SSLServerSocketAppenderBase { /** * { @ inheritDoc } */
@ Override public void start ( ) { } }

implementation: try { SSLContext sslContext = getSsl ( ) . createContext ( this ) ; SSLParametersConfiguration parameters = getSsl ( ) . getParameters ( ) ; parameters . setContext ( getContext ( ) ) ; socketFactory = new ConfigurableSSLServerSocketFactory ( parameters , sslContext . getServerSocketFactory ( ) ) ; super . start ( ) ; } catch ( Exception ex ) { addError ( ex . getMessage ( ) , ex ) ; }


signature:
public class OnPrintStreamStatusListenerBase { /** * Print status messages retrospectively */
private void retrospectivePrint ( ) { } }

implementation: if ( context == null ) return ; long now = System . currentTimeMillis ( ) ; StatusManager sm = context . getStatusManager ( ) ; List < Status > statusList = sm . getCopyOfStatusList ( ) ; for ( Status status : statusList ) { long timestampOfStatusMesage = status . getDate ( ) ; if ( isElapsedTimeLongerThanThreshold ( now , timestampOfStatusMesage ) ) { print ( status ) ; } }


signature:
public class SyslogAppenderBase { /** * Returns the integer value corresponding to the named syslog facility .
 * @ param facilityStr the syslog facility name
 * @ return the syslog facility code
 * @ throws IllegalArgumentException
 * if the facility string is not recognized */
static public int facilityStringToint ( String facilityStr ) { } }

implementation: if ( "KERN" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_KERN ; } else if ( "USER" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_USER ; } else if ( "MAIL" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_MAIL ; } else if ( "DAEMON" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_DAEMON ; } else if ( "AUTH" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_AUTH ; } else if ( "SYSLOG" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_SYSLOG ; } else if ( "LPR" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_LPR ; } else if ( "NEWS" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_NEWS ; } else if ( "UUCP" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_UUCP ; } else if ( "CRON" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_CRON ; } else if ( "AUTHPRIV" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_AUTHPRIV ; } else if ( "FTP" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_FTP ; } else if ( "NTP" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_NTP ; } else if ( "AUDIT" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_AUDIT ; } else if ( "ALERT" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_ALERT ; } else if ( "CLOCK" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_CLOCK ; } else if ( "LOCAL0" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_LOCAL0 ; } else if ( "LOCAL1" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_LOCAL1 ; } else if ( "LOCAL2" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_LOCAL2 ; } else if ( "LOCAL3" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_LOCAL3 ; } else if ( "LOCAL4" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_LOCAL4 ; } else if ( "LOCAL5" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_LOCAL5 ; } else if ( "LOCAL6" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_LOCAL6 ; } else if ( "LOCAL7" . equalsIgnoreCase ( facilityStr ) ) { return SyslogConstants . LOG_LOCAL7 ; } else { throw new IllegalArgumentException ( facilityStr + " is not a valid syslog facility string" ) ; }


signature:
public class SyslogAppenderBase { /** * The < b > Facility < / b > option must be set one of the strings KERN , USER , MAIL ,
 * DAEMON , AUTH , SYSLOG , LPR , NEWS , UUCP , CRON , AUTHPRIV , FTP , NTP , AUDIT ,
 * ALERT , CLOCK , LOCAL0 , LOCAL1 , LOCAL2 , LOCAL3 , LOCAL4 , LOCAL5 , LOCAL6,
 * LOCAL7 . Case is not important .
 * See { @ link SyslogConstants } and RFC 3164 for more information about the
 * < b > Facility < / b > option .
 * @ param facilityStr the name of the desired facility */
public void setFacility ( String facilityStr ) { } }

implementation: if ( facilityStr != null ) { facilityStr = facilityStr . trim ( ) ; } this . facilityStr = facilityStr ;


signature:
public class NodeToStringTransformer { /** * Determine if a node has already been visited already by checking the cycleDetectionStack
 * for it ' s existence . This method is used - - rather than Stack . contains ( ) - - because
 * we want to ignore the Node ' s ' next ' attribute when comparing for equality . */
private boolean haveVisitedNodeAlready ( Node node , Stack < Node > cycleDetectionStack ) { } }

implementation: for ( Node cycleNode : cycleDetectionStack ) { if ( equalNodes ( node , cycleNode ) ) { return true ; } } return false ;


signature:
public class SQLiteAppender { /** * Gets a file object from a file path to a SQLite database
 * @ param filename absolute path to database file
 * @ return the file object if a valid file found ; otherwise , null */
public File getDatabaseFile ( String filename ) { } }

implementation: File dbFile = null ; if ( filename != null && filename . trim ( ) . length ( ) > 0 ) { dbFile = new File ( filename ) ; } if ( dbFile == null || dbFile . isDirectory ( ) ) { dbFile = new File ( new AndroidContextUtil ( ) . getDatabasePath ( "logback.db" ) ) ; } return dbFile ;


signature:
public class SQLiteAppender { /** * ( non - Javadoc )
 * @ see ch . qos . logback . core . UnsynchronizedAppenderBase # start ( ) */
@ Override public void start ( ) { } }

implementation: this . started = false ; File dbfile = getDatabaseFile ( this . filename ) ; if ( dbfile == null ) { addError ( "Cannot determine database filename" ) ; return ; } boolean dbOpened = false ; try { dbfile . getParentFile ( ) . mkdirs ( ) ; addInfo ( "db path: " + dbfile . getAbsolutePath ( ) ) ; this . db = SQLiteDatabase . openOrCreateDatabase ( dbfile . getPath ( ) , null ) ; dbOpened = true ; } catch ( SQLiteException e ) { addError ( "Cannot open database" , e ) ; } if ( dbOpened ) { if ( dbNameResolver == null ) { dbNameResolver = new DefaultDBNameResolver ( ) ; } insertExceptionSQL = SQLBuilder . buildInsertExceptionSQL ( dbNameResolver ) ; insertPropertiesSQL = SQLBuilder . buildInsertPropertiesSQL ( dbNameResolver ) ; insertSQL = SQLBuilder . buildInsertSQL ( dbNameResolver ) ; try { this . db . execSQL ( SQLBuilder . buildCreateLoggingEventTableSQL ( dbNameResolver ) ) ; this . db . execSQL ( SQLBuilder . buildCreatePropertyTableSQL ( dbNameResolver ) ) ; this . db . execSQL ( SQLBuilder . buildCreateExceptionTableSQL ( dbNameResolver ) ) ; clearExpiredLogs ( this . db ) ; super . start ( ) ; this . started = true ; } catch ( SQLiteException e ) { addError ( "Cannot create database tables" , e ) ; } }


signature:
public class SQLiteAppender { /** * Removes expired logs from the database
 * @ param db */
private void clearExpiredLogs ( SQLiteDatabase db ) { } }

implementation: if ( lastCheckExpired ( this . maxHistory , this . lastCleanupTime ) ) { this . lastCleanupTime = this . clock . currentTimeMillis ( ) ; this . getLogCleaner ( ) . performLogCleanup ( db , this . maxHistory ) ; }


signature:
public class SQLiteAppender { /** * Determines whether it ' s time to clear expired logs
 * @ param expiry max time duration between checks
 * @ param lastCleanupTime timestamp ( ms ) of last cleanup
 * @ return true if last check has expired */
private boolean lastCheckExpired ( Duration expiry , long lastCleanupTime ) { } }

implementation: boolean isExpired = false ; if ( expiry != null && expiry . getMilliseconds ( ) > 0 ) { final long now = this . clock . currentTimeMillis ( ) ; final long timeDiff = now - lastCleanupTime ; isExpired = ( lastCleanupTime <= 0 ) || ( timeDiff >= expiry . getMilliseconds ( ) ) ; } return isExpired ;


signature:
public class SQLiteAppender { /** * Gets the { @ code SQLiteLogCleaner } in use . Creates default if needed . */
public SQLiteLogCleaner getLogCleaner ( ) { } }

implementation: if ( this . logCleaner == null ) { final Clock thisClock = this . clock ; this . logCleaner = new SQLiteLogCleaner ( ) { public void performLogCleanup ( SQLiteDatabase db , Duration expiry ) { final long expiryMs = thisClock . currentTimeMillis ( ) - expiry . getMilliseconds ( ) ; final String deleteExpiredLogsSQL = SQLBuilder . buildDeleteExpiredLogsSQL ( dbNameResolver , expiryMs ) ; db . execSQL ( deleteExpiredLogsSQL ) ; } } ; } return this . logCleaner ;


signature:
public class SQLiteAppender { /** * ( non - Javadoc )
 * @ see ch . qos . logback . core . UnsynchronizedAppenderBase # append ( java . lang . Object ) */
@ Override public void append ( ILoggingEvent eventObject ) { } }

implementation: if ( isStarted ( ) ) { try { clearExpiredLogs ( db ) ; SQLiteStatement stmt = db . compileStatement ( insertSQL ) ; try { db . beginTransaction ( ) ; long eventId = subAppend ( eventObject , stmt ) ; if ( eventId != - 1 ) { secondarySubAppend ( eventObject , eventId ) ; db . setTransactionSuccessful ( ) ; } } finally { if ( db . inTransaction ( ) ) { db . endTransaction ( ) ; } stmt . close ( ) ; } } catch ( Throwable e ) { addError ( "Cannot append event" , e ) ; } }


signature:
public class SQLiteAppender { /** * Inserts the main details of a log event into the database
 * @ param event the event to insert
 * @ param insertStatement the SQLite statement used to insert the event
 * @ return the row ID of the newly inserted event ; - 1 if the insertion failed
 * @ throws SQLException */
private long subAppend ( ILoggingEvent event , SQLiteStatement insertStatement ) throws SQLException { } }

implementation:
bindLoggingEvent ( insertStatement , event ) ; bindLoggingEventArguments ( insertStatement , event . getArgumentArray ( ) ) ; // This is expensive . . . should we do it every time ?
bindCallerData ( insertStatement , event . getCallerData ( ) ) ; long insertId = - 1 ; try { insertId = insertStatement . executeInsert ( ) ; } catch ( SQLiteException e ) { addWarn ( "Failed to insert loggingEvent" , e ) ; } return insertId ;


signature:
public class SQLiteAppender { /** * Updates an existing row of an event with the secondary details of the event .
 * This includes MDC properties and any exception information .
 * @ param event the event containing the details to insert
 * @ param eventId the row ID of the event to modify
 * @ throws SQLException */
private void secondarySubAppend ( ILoggingEvent event , long eventId ) throws SQLException { } }

implementation: Map < String , String > mergedMap = mergePropertyMaps ( event ) ; insertProperties ( mergedMap , eventId ) ; if ( event . getThrowableProxy ( ) != null ) { insertThrowable ( event . getThrowableProxy ( ) , eventId ) ; }


signature:
public class SQLiteAppender { /** * Binds the main details of a log event to a SQLite statement ' s parameters
 * @ param stmt the SQLite statement to modify
 * @ param event the event containing the details to bind
 * @ throws SQLException */
private void bindLoggingEvent ( SQLiteStatement stmt , ILoggingEvent event ) throws SQLException { } }

implementation: stmt . bindLong ( TIMESTMP_INDEX , event . getTimeStamp ( ) ) ; stmt . bindString ( FORMATTED_MESSAGE_INDEX , event . getFormattedMessage ( ) ) ; stmt . bindString ( LOGGER_NAME_INDEX , event . getLoggerName ( ) ) ; stmt . bindString ( LEVEL_STRING_INDEX , event . getLevel ( ) . toString ( ) ) ; stmt . bindString ( THREAD_NAME_INDEX , event . getThreadName ( ) ) ; stmt . bindLong ( REFERENCE_FLAG_INDEX , computeReferenceMask ( event ) ) ;


signature:
public class SQLiteAppender { /** * Binds a logging event ' s arguments ( e . g . , < code > logger . debug ( " x = { } y = { } " , arg1 , arg2 ) < / code > )
 * to a SQLite statement ' s parameters
 * @ param stmt the SQLite statement to modify
 * @ param argArray the argument array to bind
 * @ throws SQLException */
private void bindLoggingEventArguments ( SQLiteStatement stmt , Object [ ] argArray ) throws SQLException { } }

implementation:
int arrayLen = argArray != null ? argArray . length : 0 ; for ( int i = 0 ; i < arrayLen && i < 4 ; i ++ ) { stmt . bindString ( ARG0_INDEX + i , asStringTruncatedTo254 ( argArray [ i ] ) ) ; } // / / set remaining columns to " "
// for ( int i = arrayLen ; i < 4 ; i + + ) {
// stmt . bindString ( ARG0 _ INDEX + i , " " ) ;


signature:
public class SQLiteAppender { /** * Gets the first 254 characters of an object ' s string representation . This is
 * used to truncate a logging event ' s argument binding if necessary .
 * @ param o the object
 * @ return up to 254 characters of the object ' s string representation ; or empty
 * string if the object string is itself null */
private String asStringTruncatedTo254 ( Object o ) { } }

implementation: String s = null ; if ( o != null ) { s = o . toString ( ) ; } if ( s != null && s . length ( ) > 254 ) { s = s . substring ( 0 , 254 ) ; } return s == null ? "" : s ;


signature:
public class SQLiteAppender { /** * Computes the reference mask for a logging event , including
 * flags to indicate whether MDC properties or exception info
 * is available for the event .
 * @ param event the logging event to evaluate
 * @ return the 16 - bit reference mask */
private static short computeReferenceMask ( ILoggingEvent event ) { } }

implementation: short mask = 0 ; int mdcPropSize = 0 ; if ( event . getMDCPropertyMap ( ) != null ) { mdcPropSize = event . getMDCPropertyMap ( ) . keySet ( ) . size ( ) ; } int contextPropSize = 0 ; if ( event . getLoggerContextVO ( ) . getPropertyMap ( ) != null ) { contextPropSize = event . getLoggerContextVO ( ) . getPropertyMap ( ) . size ( ) ; } if ( mdcPropSize > 0 || contextPropSize > 0 ) { mask = PROPERTIES_EXIST ; } if ( event . getThrowableProxy ( ) != null ) { mask |= EXCEPTION_EXISTS ; } return mask ;


signature:
public class SQLiteAppender { /** * Merges a log event ' s properties with the properties of the logger context .
 * The context properties are first in the map , and then the event ' s properties
 * are appended .
 * @ param event the logging event to evaluate
 * @ return the merged properties map */
private Map < String , String > mergePropertyMaps ( ILoggingEvent event ) { } }

implementation:
Map < String , String > mergedMap = new HashMap < String , String > ( ) ; // we add the context properties first , then the event properties , since
// we consider that event - specific properties should have priority over
// context - wide properties .
Map < String , String > loggerContextMap = event . getLoggerContextVO ( ) . getPropertyMap ( ) ; if ( loggerContextMap != null ) { mergedMap . putAll ( loggerContextMap ) ; } Map < String , String > mdcMap = event . getMDCPropertyMap ( ) ; if ( mdcMap != null ) { mergedMap . putAll ( mdcMap ) ; } return mergedMap ;


signature:
public class SQLiteAppender { /** * Updates an existing row with property details ( context properties and event ' s properties ) .
 * @ param mergedMap the properties of the context plus the event ' s properties
 * @ param eventId the row ID of the event
 * @ throws SQLException */
private void insertProperties ( Map < String , String > mergedMap , long eventId ) throws SQLException { } }

implementation: if ( mergedMap . size ( ) > 0 ) { SQLiteStatement stmt = db . compileStatement ( insertPropertiesSQL ) ; try { for ( Entry < String , String > entry : mergedMap . entrySet ( ) ) { stmt . bindLong ( 1 , eventId ) ; stmt . bindString ( 2 , entry . getKey ( ) ) ; stmt . bindString ( 3 , entry . getValue ( ) ) ; stmt . executeInsert ( ) ; } } finally { stmt . close ( ) ; } }


signature:
public class SQLiteAppender { /** * Binds the calling function ' s details ( filename , line , etc . ) to a SQLite statement ' s arguments
 * @ param stmt the SQLite statement to modify
 * @ param callerDataArray the caller ' s stack trace
 * @ throws SQLException */
private void bindCallerData ( SQLiteStatement stmt , StackTraceElement [ ] callerDataArray ) throws SQLException { } }

implementation: if ( callerDataArray != null && callerDataArray . length > 0 ) { StackTraceElement callerData = callerDataArray [ 0 ] ; if ( callerData != null ) { bindString ( stmt , CALLER_FILENAME_INDEX , callerData . getFileName ( ) ) ; bindString ( stmt , CALLER_CLASS_INDEX , callerData . getClassName ( ) ) ; bindString ( stmt , CALLER_METHOD_INDEX , callerData . getMethodName ( ) ) ; bindString ( stmt , CALLER_LINE_INDEX , Integer . toString ( callerData . getLineNumber ( ) ) ) ; } }


signature:
public class SQLiteAppender { /** * Inserts an exception into the logging _ exceptions table
 * @ param stmt
 * @ param txt
 * @ param i
 * @ param eventId */
private void insertException ( SQLiteStatement stmt , String txt , short i , long eventId ) throws SQLException { } }

implementation: stmt . bindLong ( 1 , eventId ) ; stmt . bindLong ( 2 , i ) ; stmt . bindString ( 3 , txt ) ; stmt . executeInsert ( ) ;


signature:
public class ElementSelector { /** * Returns the number of " prefix " components that this pattern has in common
 * with the pattern p passed as parameter . By " prefix " components we mean the
 * components at the beginning of the pattern .
 * @ param p element path
 * @ return the number of " prefix " components in common with p */
public int getPrefixMatchLength ( ElementPath p ) { } }

implementation:
if ( p == null ) { return 0 ; } int lSize = this . partList . size ( ) ; int rSize = p . partList . size ( ) ; // no match possible for empty sets
if ( ( lSize == 0 ) || ( rSize == 0 ) ) { return 0 ; } int minLen = ( lSize <= rSize ) ? lSize : rSize ; int match = 0 ; for ( int i = 0 ; i < minLen ; i ++ ) { String l = this . partList . get ( i ) ; String r = p . partList . get ( i ) ; if ( equalityCheck ( l , r ) ) { match ++ ; } else { break ; } } return match ;


signature:
public class StatusBase { /** * different status objects lying on the same cycle */
public synchronized int getEffectiveLevel ( ) { } }

implementation: int result = level ; int effLevel ; Iterator it = iterator ( ) ; Status s ; while ( it . hasNext ( ) ) { s = ( Status ) it . next ( ) ; effLevel = s . getEffectiveLevel ( ) ; if ( effLevel > result ) { result = effLevel ; } } return result ;


signature:
public class PropertySetter { /** * Uses JavaBeans { @ link Introspector } to computer setters of object to be
 * configured . */
protected void introspect ( ) { } }

implementation: try { propertyDescriptors = Introspector . getPropertyDescriptors ( this . objClass ) ; methodDescriptors = Introspector . getMethodDescriptors ( this . objClass ) ; } catch ( IntrospectionException ex ) { addError ( "Failed to introspect " + obj + ": " + ex . getMessage ( ) ) ; propertyDescriptors = new PropertyDescriptor [ 0 ] ; methodDescriptors = new MethodDescriptor [ 0 ] ; }


signature:
public class PropertySetter { /** * Set a property on this PropertySetter ' s Object . If successful , this method
 * will invoke a setter method on the underlying Object . The setter is the one
 * for the specified property name and the value is determined partly from the
 * setter argument type and partly from the value specified in the call to
 * this method .
 * If the setter expects a String no conversion is necessary . If it expects an
 * int , then an attempt is made to convert ' value ' to an int using new
 * Integer ( value ) . If the setter expects a boolean , the conversion is by new
 * Boolean ( value ) .
 * @ param name
 * name of the property
 * @ param value
 * String value of the property */
public void setProperty ( String name , String value ) { } }

implementation: if ( value == null ) { return ; } name = Introspector . decapitalize ( name ) ; PropertyDescriptor prop = getPropertyDescriptor ( name ) ; if ( prop == null ) { addWarn ( "No such property [" + name + "] in " + objClass . getName ( ) + "." ) ; } else { try { setProperty ( prop , name , value ) ; } catch ( PropertySetterException ex ) { addWarn ( "Failed to set property [" + name + "] to value \"" + value + "\". " , ex ) ; } }


signature:
public class PropertySetter { /** * Set the named property given a { @ link PropertyDescriptor } .
 * @ param prop
 * A PropertyDescriptor describing the characteristics of the
 * property to set .
 * @ param name
 * The named of the property to set .
 * @ param value
 * The value of the property .
 * @ throws PropertySetterException
 * No setter for property ; setter ' s argument list is not equal to 1 ; parameter conversion failure */
public void setProperty ( PropertyDescriptor prop , String name , String value ) throws PropertySetterException { } }

implementation: Method setter = prop . getWriteMethod ( ) ; if ( setter == null ) { throw new PropertySetterException ( "No setter for property [" + name + "]." ) ; } Class < ? > [ ] paramTypes = setter . getParameterTypes ( ) ; if ( paramTypes . length != 1 ) { throw new PropertySetterException ( "#params for setter != 1" ) ; } Object arg ; try { arg = StringToObjectConverter . convertArg ( this , value , paramTypes [ 0 ] ) ; } catch ( Throwable t ) { throw new PropertySetterException ( "Conversion to type [" + paramTypes [ 0 ] + "] failed. " , t ) ; } if ( arg == null ) { throw new PropertySetterException ( "Conversion to type [" + paramTypes [ 0 ] + "] failed." ) ; } try { setter . invoke ( obj , arg ) ; } catch ( Exception ex ) { throw new PropertySetterException ( ex ) ; }


signature:
public class PropertySetter { /** * Can the given clazz instantiable with certainty ?
 * @ param clazz
 * The class to test for instantiability
 * @ return true if clazz can be instantiated , and false otherwise . */
private boolean isUnequivocallyInstantiable ( Class < ? > clazz ) { } }

implementation:
if ( clazz . isInterface ( ) ) { return false ; } // checking for constructors would be more elegant , but in
// classes without any declared constructors , Class . getConstructor ( )
// returns null .
Object o ; try { o = clazz . getDeclaredConstructor ( ) . newInstance ( ) ; if ( o != null ) { return true ; } else { return false ; } } catch ( InstantiationException e ) { return false ; } catch ( IllegalAccessException e ) { return false ; } catch ( NoSuchMethodException e ) { return false ; } catch ( InvocationTargetException e ) { return false ; }


signature:
public class ResourceExistsPropertyDefiner { /** * Returns the string " true " if the { @ link # setResource ( String ) resource } specified by the
 * user is available on the class path , " false " otherwise .
 * @ return " true " | " false " depending on the availability of resource on the classpath */
public String getPropertyValue ( ) { } }

implementation: if ( OptionHelper . isEmpty ( resourceStr ) ) { addError ( "The \"resource\" property must be set." ) ; return null ; } URL resourceURL = Loader . getResourceBySelfClassLoader ( resourceStr ) ; return booleanAsStr ( resourceURL != null ) ;


signature:
public class CopyOnInheritThreadLocal { /** * Child threads should get a copy of the parent ' s hashmap . */
@ Override protected HashMap < String , String > childValue ( HashMap < String , String > parentValue ) { } }

implementation: if ( parentValue == null ) { return null ; } else { return new HashMap < String , String > ( parentValue ) ; }


signature:
public class Parser { /** * Eopt = E | ~ */
private Node Eopt ( ) throws ScanException { } }

implementation: Token next = peekAtCurentToken ( ) ; if ( next == null ) { return null ; } else { return E ( ) ; }


signature:
public class Parser { /** * T = LITERAL | ' $ { ' V ' } ' */
private Node T ( ) throws ScanException { } }

implementation: Token t = peekAtCurentToken ( ) ; switch ( t . type ) { case LITERAL : advanceTokenPointer ( ) ; return makeNewLiteralNode ( t . payload ) ; case CURLY_LEFT : advanceTokenPointer ( ) ; Node innerNode = C ( ) ; Token right = peekAtCurentToken ( ) ; expectCurlyRight ( right ) ; advanceTokenPointer ( ) ; Node curlyLeft = makeNewLiteralNode ( CoreConstants . LEFT_ACCOLADE ) ; curlyLeft . append ( innerNode ) ; curlyLeft . append ( makeNewLiteralNode ( CoreConstants . RIGHT_ACCOLADE ) ) ; return curlyLeft ; case START : advanceTokenPointer ( ) ; Node v = V ( ) ; Token w = peekAtCurentToken ( ) ; expectCurlyRight ( w ) ; advanceTokenPointer ( ) ; return v ; default : return null ; }


signature:
public class Parser { /** * V = E ( ' : = ' E | ~ ) */
private Node V ( ) throws ScanException { } }

implementation: Node e = E ( ) ; Node variable = new Node ( Node . Type . VARIABLE , e ) ; Token t = peekAtCurentToken ( ) ; if ( isDefaultToken ( t ) ) { advanceTokenPointer ( ) ; Node def = E ( ) ; variable . defaultPart = def ; } return variable ;


signature:
public class Parser { /** * C = E ( ' : = ' E | ~ ) */
private Node C ( ) throws ScanException { } }

implementation: Node e0 = E ( ) ; Token t = peekAtCurentToken ( ) ; if ( isDefaultToken ( t ) ) { advanceTokenPointer ( ) ; Node literal = makeNewLiteralNode ( CoreConstants . DEFAULT_VALUE_SEPARATOR ) ; e0 . append ( literal ) ; Node e1 = E ( ) ; e0 . append ( e1 ) ; } return e0 ;


signature:
public class IncludeAction { /** * Processes an include
 * @ param ic context
 * @ param url URL to file / resource being included */
@ Override protected void processInclude ( InterpretationContext ic , URL url ) throws JoranException { } }

implementation:
InputStream in = openURL ( url ) ; try { if ( in != null ) { // add URL to watch list in case the " scan " flag is true , in
// which case this URL is periodically checked for changes
ConfigurationWatchListUtil . addToWatchList ( getContext ( ) , url ) ; // parse the include
SaxEventRecorder recorder = createRecorder ( in , url ) ; recorder . setContext ( getContext ( ) ) ; recorder . recordEvents ( in ) ; // remove the leading / trailing tags ( < included > or < configuration > )
trimHeadAndTail ( recorder ) ; ic . getJoranInterpreter ( ) . getEventPlayer ( ) . addEventsDynamically ( recorder . getSaxEventList ( ) , this . eventOffset ) ; } } catch ( JoranException e ) { optionalWarning ( "Failed processing [" + url . toString ( ) + "]" , e ) ; } finally { close ( in ) ; }


signature:
public class IncludeAction { /** * Opens the given URL , logging any exceptions
 * @ param url URL of file / resource to open
 * @ return an input stream to the URL ; or { @ code null } if the URL could not be opened */
private InputStream openURL ( URL url ) { } }

implementation: try { return url . openStream ( ) ; } catch ( IOException e ) { optionalWarning ( "Failed to open [" + url . toString ( ) + "]" , e ) ; return null ; }


signature:
public class IncludeAction { /** * Removes the head tag and tail tag if they are named either
 * " included " or " configuration "
 * @ param recorder the SAX Event recorder containing the tags */
private void trimHeadAndTail ( SaxEventRecorder recorder ) { } }

implementation:
List < SaxEvent > saxEventList = recorder . getSaxEventList ( ) ; if ( saxEventList . size ( ) == 0 ) { return ; } boolean includedTagFound = false ; boolean configTagFound = false ; // find opening element
SaxEvent first = saxEventList . get ( 0 ) ; if ( first != null ) { String elemName = getEventName ( first ) ; includedTagFound = INCLUDED_TAG . equalsIgnoreCase ( elemName ) ; configTagFound = CONFIG_TAG . equalsIgnoreCase ( elemName ) ; } // if opening element found , remove it , and then remove the closing element
if ( includedTagFound || configTagFound ) { saxEventList . remove ( 0 ) ; final int listSize = saxEventList . size ( ) ; if ( listSize == 0 ) { return ; } final int lastIndex = listSize - 1 ; SaxEvent last = saxEventList . get ( lastIndex ) ; if ( last != null ) { String elemName = getEventName ( last ) ; if ( ( includedTagFound && INCLUDED_TAG . equalsIgnoreCase ( elemName ) ) || ( configTagFound && CONFIG_TAG . equalsIgnoreCase ( elemName ) ) ) { saxEventList . remove ( lastIndex ) ; } } }


signature:
public class IncludeAction { /** * Gets the event name of a { @ code SaxEvent }
 * @ param event SaxEvent to evaluate
 * @ return { @ code event . qName } is if it ' s not empty ; otherwise , { @ code event . localName } */
private String getEventName ( SaxEvent event ) { } }

implementation: return event . qName . length ( ) > 0 ? event . qName : event . localName ;


signature:
public class ServerSocketReceiver { /** * Starts the server . */
protected boolean shouldStart ( ) { } }

implementation: ServerSocket serverSocket = null ; try { serverSocket = getServerSocketFactory ( ) . createServerSocket ( getPort ( ) , getBacklog ( ) , getInetAddress ( ) ) ; ServerListener < RemoteAppenderClient > listener = createServerListener ( serverSocket ) ; runner = createServerRunner ( listener , getContext ( ) . getScheduledExecutorService ( ) ) ; runner . setContext ( getContext ( ) ) ; return true ; } catch ( Exception ex ) { addError ( "server startup error: " + ex , ex ) ; CloseUtil . closeQuietly ( serverSocket ) ; return false ; }


signature:
public class ServerSocketReceiver { /** * { @ inheritDoc } */
protected void onStop ( ) { } }

implementation: try { if ( runner == null ) return ; runner . stop ( ) ; } catch ( IOException ex ) { addError ( "server shutdown error: " + ex , ex ) ; }


signature:
public class AlgoliaException { /** * Test whether this error is transient .
 * @ return true if transient , false if fatal . */
public boolean isTransient ( ) { } }

implementation: Throwable cause = getCause ( ) ; if ( cause == null ) { return isServerError ( statusCode ) ; } else if ( cause instanceof AlgoliaException ) { return ( ( AlgoliaException ) cause ) . isTransient ( ) ; } else if ( cause instanceof IOException ) { return true ; } else { return false ; }


signature:
public class PlacesClient { /** * Set the default hosts for Algolia Places . */
private void setDefaultHosts ( ) { } }

implementation: List < String > fallbackHosts = Arrays . asList ( "places-1.algolianet.com" , "places-2.algolianet.com" , "places-3.algolianet.com" ) ; Collections . shuffle ( fallbackHosts ) ; List < String > hosts = new ArrayList < > ( fallbackHosts . size ( ) + 1 ) ; hosts . add ( "places-dsn.algolia.net" ) ; hosts . addAll ( fallbackHosts ) ; String [ ] hostsArray = hosts . toArray ( new String [ hosts . size ( ) ] ) ; setReadHosts ( hostsArray ) ; setWriteHosts ( hostsArray ) ;


signature:
public class PlacesClient { /** * Search for places .
 * @ param params Search parameters .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request searchAsync ( @ NonNull PlacesQuery params , @ NonNull CompletionHandler completionHandler ) { } }

implementation: final PlacesQuery paramsCopy = new PlacesQuery ( params ) ; return new AsyncTaskRequest ( completionHandler ) { @ Override protected @ NonNull JSONObject run ( ) throws AlgoliaException { return search ( paramsCopy ) ; } } . start ( ) ;


signature:
public class PlacesClient { /** * Search for places .
 * @ param params Search parameters . */
protected JSONObject search ( @ NonNull PlacesQuery params ) throws AlgoliaException { } }

implementation:
try { JSONObject body = new JSONObject ( ) . put ( "params" , params . build ( ) ) ; return postRequest ( "/1/places/query" , /* urlParameters : */
null , body . toString ( ) , true /* readOperation */
, /* requestOptions : */
null ) ; } catch ( JSONException e ) { throw new RuntimeException ( e ) ; // should never happen
}


signature:
public class PlacesClient { /** * Get a place by its objectID .
 * @ param objectID the record ' s identifier .
 * @ return the corresponding record .
 * @ throws AlgoliaException when the given objectID does not exist . */
public JSONObject getByObjectID ( @ NonNull String objectID ) throws AlgoliaException { } }

implementation:
return getRequest ( "/1/places/" + objectID , /* urlParameters : */
null , false , /* requestOptions : */
null ) ;


signature:
public class MirroredIndex { /** * Add a data selection query to this index .
 * NOTE : All queries are implicitly browse queries ( and not search queries ) .
 * @ param query The data selection query to add . */
public void addDataSelectionQuery ( @ NonNull DataSelectionQuery query ) { } }

implementation: mirrorSettings . addQuery ( query ) ; mirrorSettings . setQueriesModificationDate ( new Date ( ) ) ; saveMirrorSettings ( ) ;


signature:
public class MirroredIndex { /** * Replace all data selection queries associated to this index .
 * @ param queries The new data selection queries . ( May be empty , although this will actually empty your mirror ! ) */
public void setDataSelectionQueries ( @ NonNull DataSelectionQuery ... queries ) { } }

implementation: DataSelectionQuery [ ] oldQueries = mirrorSettings . getQueries ( ) ; if ( ! Arrays . equals ( oldQueries , queries ) ) { mirrorSettings . setQueries ( queries ) ; mirrorSettings . setQueriesModificationDate ( new Date ( ) ) ; saveMirrorSettings ( ) ; }


signature:
public class MirroredIndex { /** * Set the delay after which data is considered to be obsolete .
 * @ param duration The delay between syncs , expressed in < code > unit < / code > .
 * @ param unit The unit in which < code > duration < / code > is expressed . */
public void setDelayBetweenSyncs ( long duration , @ NonNull TimeUnit unit ) { } }

implementation: this . setDelayBetweenSyncs ( TimeUnit . MILLISECONDS . convert ( duration , unit ) ) ;


signature:
public class MirroredIndex { /** * Lazy instantiate the local index . */
private synchronized void ensureLocalIndex ( ) { } }

implementation: if ( localIndex == null ) { localIndex = new LocalIndex ( getClient ( ) . getRootDataDir ( ) . getAbsolutePath ( ) , getClient ( ) . getApplicationID ( ) , getRawIndexName ( ) ) ; }


signature: public class MirroredIndex { private void saveMirrorSettings ( ) { } }

implementation: File dataDir = getDataDir ( ) ; if ( ! dataDir . exists ( ) ) { dataDir . mkdirs ( ) ; } mirrorSettings . save ( getSettingsFile ( ) ) ;


signature:
public class MirroredIndex { /** * Launch a sync .
 * If a sync is already running , this call is ignored . Otherwise , the sync is enqueued and runs in the background .
 * NOTE : All index syncs are sequential : no two syncs can run at the same time .
 * @ throws IllegalStateException If no data selection queries were set . */
public void sync ( ) { } }

implementation: if ( getDataSelectionQueries ( ) . length == 0 ) { throw new IllegalStateException ( "Cannot sync with empty data selection queries" ) ; } synchronized ( this ) { if ( syncing ) return ; syncing = true ; } getClient ( ) . localBuildExecutorService . submit ( new Runnable ( ) { @ Override public void run ( ) { _sync ( ) ; } } ) ;


signature:
public class MirroredIndex { /** * Launch a sync only if the data is obsolete .
 * The data is obsolete if the last successful sync is older than the delay between syncs , or if the data selection
 * queries have been changed in the meantime .
 * @ throws IllegalStateException If no data selection queries were set . */
public void syncIfNeeded ( ) { } }

implementation: long currentDate = System . currentTimeMillis ( ) ; if ( currentDate - mirrorSettings . getLastSyncDate ( ) . getTime ( ) > delayBetweenSyncs || mirrorSettings . getQueriesModificationDate ( ) . compareTo ( mirrorSettings . getLastSyncDate ( ) ) > 0 ) { sync ( ) ; }


signature:
public class MirroredIndex { /** * Refresh the local mirror .
 * WARNING : Should be called from a background thread . */
private void _sync ( ) { } }

implementation:
if ( ! mirrored ) throw new IllegalArgumentException ( "Mirroring not activated on this index" ) ; // Reset statistics .
stats = new SyncStats ( ) ; long startTime = System . currentTimeMillis ( ) ; // Notify listeners .
getClient ( ) . completionExecutor . execute ( new Runnable ( ) { @ Override public void run ( ) { fireSyncDidStart ( ) ; } } ) ; try { // Create temporary directory .
tmpDir = new File ( getClient ( ) . getTempDir ( ) , UUID . randomUUID ( ) . toString ( ) ) ; tmpDir . mkdirs ( ) ; // NOTE : We are doing everything sequentially , because this is a background job : we care more about
// resource consumption than about how long it will take .
// Fetch settings .
{ JSONObject settingsJSON = this . getSettings ( 1 , /* requestOptions : */
null ) ; settingsFile = new File ( tmpDir , "settings.json" ) ; String data = settingsJSON . toString ( ) ; Writer writer = new OutputStreamWriter ( new FileOutputStream ( settingsFile ) , "UTF-8" ) ; writer . write ( data ) ; writer . close ( ) ; } // Perform data selection queries .
objectFiles = new ArrayList < > ( ) ; final DataSelectionQuery [ ] queries = mirrorSettings . getQueries ( ) ; for ( DataSelectionQuery query : queries ) { String cursor = null ; int retrievedObjects = 0 ; do { // Make next request .
JSONObject objectsJSON = cursor == null ? this . browse ( query . query , /* requestOptions : */
null ) : this . browseFrom ( cursor , /* requestOptions : */
null ) ; // Write result to file .
int objectFileNo = objectFiles . size ( ) ; File file = new File ( tmpDir , String . format ( "%d.json" , objectFileNo ) ) ; objectFiles . add ( file ) ; String data = objectsJSON . toString ( ) ; Writer writer = new OutputStreamWriter ( new FileOutputStream ( file ) , "UTF-8" ) ; writer . write ( data ) ; writer . close ( ) ; cursor = objectsJSON . optString ( "cursor" , null ) ; JSONArray hits = objectsJSON . optJSONArray ( "hits" ) ; if ( hits == null ) { // Something went wrong :
// Report the error , and just abort this batch and proceed with the next query .
Log . e ( this . getClass ( ) . getName ( ) , "No hits in result for query: " + query . query ) ; break ; } retrievedObjects += hits . length ( ) ; } while ( retrievedObjects < query . maxObjects && cursor != null ) ; stats . objectCount += retrievedObjects ; } // Update statistics .
long afterFetchTime = System . currentTimeMillis ( ) ; stats . fetchTime = afterFetchTime - startTime ; stats . fileCount = objectFiles . size ( ) ; // Build the index .
_buildOffline ( settingsFile , objectFiles . toArray ( new File [ objectFiles . size ( ) ] ) ) ; // Update statistics .
long afterBuildTime = System . currentTimeMillis ( ) ; stats . buildTime = afterBuildTime - afterFetchTime ; stats . totalTime = afterBuildTime - startTime ; // Remember the last sync date .
mirrorSettings . setLastSyncDate ( new Date ( ) ) ; saveMirrorSettings ( ) ; // Log statistics .
Log . d ( this . getClass ( ) . getName ( ) , "Sync stats: " + stats ) ; } catch ( Exception e ) { Log . e ( this . getClass ( ) . getName ( ) , "Sync failed" , e ) ; error = e ; } finally { // Clean up .
if ( tmpDir != null ) { FileUtils . deleteRecursive ( tmpDir ) ; tmpDir = null ; } settingsFile = null ; objectFiles = null ; // Mark sync as finished .
synchronized ( this ) { syncing = false ; } // Notify listeners .
getClient ( ) . completionExecutor . execute ( new Runnable ( ) { @ Override public void run ( ) { fireSyncDidFinish ( ) ; } } ) ; }


signature:
public class MirroredIndex { /** * Search the online API , falling back to the local mirror if enabled in case of error .
 * @ param query Search query .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
@ Override public Request searchAsync ( @ NonNull Query query , @ Nullable RequestOptions requestOptions , @ NonNull CompletionHandler completionHandler ) { } }

implementation:
// A non - mirrored index behaves exactly as an online index .
if ( ! mirrored ) { return super . searchAsync ( query , requestOptions , completionHandler ) ; } // A mirrored index launches a mixed offline / online request .
else { final Query queryCopy = new Query ( query ) ; return new OnlineOfflineSearchRequest ( queryCopy , requestOptions , completionHandler ) . start ( ) ; }


signature:
public class MirroredIndex { /** * Search the online API .
 * @ param query Search query .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request searchOnlineAsync ( @ NonNull Query query , @ NonNull final CompletionHandler completionHandler ) { } }

implementation:
return searchOnlineAsync ( query , /* requestOptions : */
null , completionHandler ) ;


signature:
public class MirroredIndex { /** * Search the online API .
 * @ param query Search query .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request searchOnlineAsync ( @ NonNull Query query , @ Nullable final RequestOptions requestOptions , @ NonNull final CompletionHandler completionHandler ) { } }

implementation: final Query queryCopy = new Query ( query ) ; return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return searchOnline ( queryCopy , requestOptions ) ; } } . start ( ) ;


signature: public class MirroredIndex { @ Override public Request multipleQueriesAsync ( @ NonNull Collection < Query > queries , final Client . MultipleQueriesStrategy strategy , @ Nullable RequestOptions requestOptions , @ NonNull CompletionHandler completionHandler ) { } }

implementation:
// A non - mirrored index behaves exactly as an online index .
if ( ! mirrored ) { return super . multipleQueriesAsync ( queries , strategy , completionHandler ) ; } // A mirrored index launches a mixed offline / online request .
else { final List < Query > queriesCopy = new ArrayList < > ( queries . size ( ) ) ; for ( Query query : queries ) { queriesCopy . add ( new Query ( query ) ) ; } return new OnlineOfflineMultipleQueriesRequest ( queriesCopy , strategy , requestOptions , completionHandler ) . start ( ) ; }


signature:
public class MirroredIndex { /** * Run multiple queries on this index , explicitly targeting the online API .
 * @ param queries Queries to run .
 * @ param strategy Strategy to use .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request multipleQueriesOnlineAsync ( @ NonNull List < Query > queries , final Client . MultipleQueriesStrategy strategy , final @ NonNull CompletionHandler completionHandler ) { } }

implementation:
return multipleQueriesAsync ( queries , /* requestOptions : */
null , completionHandler ) ;


signature:
public class MirroredIndex { /** * Run multiple queries on this index , explicitly targeting the online API .
 * @ param queries Queries to run .
 * @ param strategy Strategy to use .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request multipleQueriesOnlineAsync ( @ NonNull List < Query > queries , final Client . MultipleQueriesStrategy strategy , @ Nullable final RequestOptions requestOptions , final @ NonNull CompletionHandler completionHandler ) { } }

implementation: final List < Query > queriesCopy = new ArrayList < > ( queries . size ( ) ) ; for ( Query query : queries ) { queriesCopy . add ( new Query ( query ) ) ; } return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return multipleQueriesOnline ( queriesCopy , strategy == null ? null : strategy . toString ( ) , requestOptions ) ; } } . start ( ) ;


signature:
public class MirroredIndex { /** * Run multiple queries on this index , explicitly targeting the offline mirror .
 * @ param queries Queries to run .
 * @ param strategy Strategy to use .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request .
 * @ throws IllegalStateException if mirroring is not activated on this index . */
public Request multipleQueriesOfflineAsync ( final @ NonNull List < Query > queries , final Client . MultipleQueriesStrategy strategy , @ NonNull CompletionHandler completionHandler ) { } }

implementation: if ( ! mirrored ) { throw new IllegalStateException ( "Offline requests are only available when the index is mirrored" ) ; } final List < Query > queriesCopy = new ArrayList < > ( queries . size ( ) ) ; for ( Query query : queries ) { queriesCopy . add ( new Query ( query ) ) ; } return getClient ( ) . new AsyncTaskRequest ( completionHandler , getClient ( ) . localSearchExecutorService ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return _multipleQueriesOffline ( queriesCopy , strategy == null ? null : strategy . toString ( ) ) ; } } . start ( ) ;


signature:
public class MirroredIndex { /** * Run multiple queries on this index , explicitly targeting the online API . */
private JSONObject multipleQueriesOnline ( @ NonNull List < Query > queries , String strategy , @ Nullable RequestOptions requestOptions ) throws AlgoliaException { } }

implementation: try { JSONObject content = super . multipleQueries ( queries , strategy , requestOptions ) ; content . put ( JSON_KEY_ORIGIN , JSON_VALUE_ORIGIN_REMOTE ) ; return content ; } catch ( JSONException e ) { throw new AlgoliaException ( "Failed to patch JSON result" ) ; }


signature:
public class MirroredIndex { /** * Run multiple queries on this index , explicitly targeting the offline mirror . */
private JSONObject _multipleQueriesOffline ( @ NonNull List < Query > queries , String strategy ) throws AlgoliaException { } }

implementation: if ( ! mirrored ) { throw new IllegalStateException ( "Cannot run offline search on a non-mirrored index" ) ; } return new MultipleQueryEmulator ( this . getRawIndexName ( ) ) { @ Override protected JSONObject singleQuery ( @ NonNull Query query ) throws AlgoliaException { return _searchOffline ( query ) ; } } . multipleQueries ( queries , strategy ) ;


signature:
public class MirroredIndex { /** * Browse the local mirror ( initial call ) .
 * Same semantics as { @ link Index # browseAsync } .
 * @ param query Browse query . Same restrictions as the online API .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request .
 * @ throws IllegalStateException if mirroring is not activated on this index . */
public Request browseMirrorAsync ( @ NonNull Query query , @ NonNull CompletionHandler completionHandler ) { } }

implementation: if ( ! mirrored ) { throw new IllegalStateException ( "Mirroring not activated on this index" ) ; } final Query queryCopy = new Query ( query ) ; return getClient ( ) . new AsyncTaskRequest ( completionHandler , getClient ( ) . localSearchExecutorService ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return _browseMirror ( queryCopy ) ; } } . start ( ) ;


signature:
public class MirroredIndex { /** * Browse the local mirror ( subsequent calls ) .
 * Same semantics as { @ link Index # browseFromAsync } .
 * @ param cursor Cursor to browse from .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request .
 * @ throws IllegalStateException if mirroring is not activated on this index . */
public Request browseMirrorFromAsync ( @ NonNull String cursor , @ NonNull CompletionHandler completionHandler ) { } }

implementation: if ( ! mirrored ) { throw new IllegalStateException ( "Mirroring not activated on this index" ) ; } final Query query = new Query ( ) . set ( "cursor" , cursor ) ; return getClient ( ) . new AsyncTaskRequest ( completionHandler , getClient ( ) . localSearchExecutorService ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return _browseMirror ( query ) ; } } . start ( ) ;


signature:
public class MirroredIndex { /** * Get an individual object from the online API , falling back to the local mirror in case of error ( when enabled ) .
 * @ param objectID Identifier of the object to retrieve .
 * @ param attributesToRetrieve Attributes to retrieve . If ` null ` or if at least one item is ` * ` , all retrievable
 * attributes will be retrieved .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
@ Override public Request getObjectAsync ( final @ NonNull String objectID , final @ Nullable Collection < String > attributesToRetrieve , @ Nullable RequestOptions requestOptions , @ NonNull CompletionHandler completionHandler ) { } }

implementation: if ( ! mirrored ) { return super . getObjectAsync ( objectID , attributesToRetrieve , requestOptions , completionHandler ) ; } else { return new OnlineOfflineGetObjectRequest ( objectID , new ArrayList ( attributesToRetrieve ) , requestOptions , completionHandler ) . start ( ) ; }


signature:
public class MirroredIndex { /** * Get an individual object , explicitly targeting the online API , not the offline mirror .
 * @ param objectID Identifier of the object to retrieve .
 * @ param attributesToRetrieve Attributes to retrieve . If ` null ` or if at least one item is ` * ` , all retrievable
 * attributes will be retrieved .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request getObjectOnlineAsync ( @ NonNull final String objectID , final @ Nullable List < String > attributesToRetrieve , @ NonNull final CompletionHandler completionHandler ) { } }

implementation:
return getObjectOnlineAsync ( objectID , attributesToRetrieve , /* requestOptions : */
null , completionHandler ) ;


signature:
public class MirroredIndex { /** * Get an individual object , explicitly targeting the online API , not the offline mirror .
 * @ param objectID Identifier of the object to retrieve .
 * @ param attributesToRetrieve Attributes to retrieve . If ` null ` or if at least one item is ` * ` , all retrievable
 * attributes will be retrieved .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request getObjectOnlineAsync ( @ NonNull final String objectID , final @ Nullable List < String > attributesToRetrieve , @ Nullable RequestOptions requestOptions , @ NonNull final CompletionHandler completionHandler ) { } }

implementation:
// TODO : Cannot perform origin tagging because it could conflict with the object ' s attributes
return super . getObjectAsync ( objectID , attributesToRetrieve , requestOptions , completionHandler ) ;


signature:
public class MirroredIndex { /** * Get an individual object , explicitly targeting the online API , not the offline mirror .
 * @ param objectID Identifier of the object to retrieve .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request getObjectOnlineAsync ( @ NonNull final String objectID , @ NonNull final CompletionHandler completionHandler ) { } }

implementation:
return getObjectOnlineAsync ( objectID , /* attributesToRetrieve : */
null , /* requestOptions : */
null , completionHandler ) ;


signature:
public class MirroredIndex { /** * Get an individual object , explicitly targeting the offline mirror , not the online API .
 * @ param objectID Identifier of the object to retrieve .
 * @ param attributesToRetrieve Attributes to retrieve . If ` null ` or if at least one item is ` * ` , all retrievable
 * attributes will be retrieved .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request .
 * @ throws IllegalStateException if mirroring is not activated on this index . */
public Request getObjectOfflineAsync ( @ NonNull final String objectID , final @ Nullable List < String > attributesToRetrieve , @ NonNull CompletionHandler completionHandler ) { } }

implementation: if ( ! mirrored ) { throw new IllegalStateException ( "Mirroring not activated on this index" ) ; } return getClient ( ) . new AsyncTaskRequest ( completionHandler , getClient ( ) . localSearchExecutorService ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return _getObjectOffline ( objectID , attributesToRetrieve ) ; } } . start ( ) ;


signature:
public class MirroredIndex { /** * Get an individual object , explicitly targeting the offline mirror , not the online API .
 * @ param objectID Identifier of the object to retrieve .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request .
 * @ throws IllegalStateException if mirroring is not activated on this index . */
public Request getObjectOfflineAsync ( @ NonNull final String objectID , @ NonNull final CompletionHandler completionHandler ) { } }

implementation: return getObjectOfflineAsync ( objectID , null , completionHandler ) ;


signature:
public class MirroredIndex { /** * Get individual objects from the online API , falling back to the local mirror in case of error ( when enabled ) .
 * @ param objectIDs Identifiers of objects to retrieve .
 * @ param attributesToRetrieve Attributes to retrieve . If ` null ` or if at least one item is ` * ` , all retrievable
 * attributes will be retrieved .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
@ Override public Request getObjectsAsync ( final @ NonNull Collection < String > objectIDs , final @ Nullable Collection < String > attributesToRetrieve , @ Nullable RequestOptions requestOptions , @ NonNull CompletionHandler completionHandler ) { } }

implementation: if ( ! mirrored ) { return super . getObjectsAsync ( objectIDs , attributesToRetrieve , requestOptions , completionHandler ) ; } else { return new OnlineOfflineGetObjectsRequest ( new ArrayList ( objectIDs ) , new ArrayList ( attributesToRetrieve ) , requestOptions , completionHandler ) . start ( ) ; }


signature:
public class MirroredIndex { /** * Get individual objects , explicitly targeting the online API , not the offline mirror .
 * @ param objectIDs Identifiers of objects to retrieve .
 * @ param attributesToRetrieve Attributes to retrieve . If ` null ` or if at least one item is ` * ` , all retrievable
 * attributes will be retrieved .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request getObjectsOnlineAsync ( @ NonNull final List < String > objectIDs , final @ Nullable List < String > attributesToRetrieve , @ NonNull final CompletionHandler completionHandler ) { } }

implementation:
return getObjectsOnlineAsync ( objectIDs , attributesToRetrieve , /* requestOptions : */
null , completionHandler ) ;


signature:
public class MirroredIndex { /** * Get individual objects , explicitly targeting the online API , not the offline mirror .
 * @ param objectIDs Identifiers of objects to retrieve .
 * @ param attributesToRetrieve Attributes to retrieve . If ` null ` or if at least one item is ` * ` , all retrievable
 * attributes will be retrieved .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request getObjectsOnlineAsync ( @ NonNull final List < String > objectIDs , final @ Nullable List < String > attributesToRetrieve , @ Nullable final RequestOptions requestOptions , @ NonNull final CompletionHandler completionHandler ) { } }

implementation: return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return getObjectsOnline ( objectIDs , attributesToRetrieve , requestOptions ) ; } } . start ( ) ;


signature:
public class MirroredIndex { /** * Get individual objects , explicitly targeting the online API , not the offline mirror .
 * @ param objectIDs Identifiers of objects to retrieve .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request getObjectsOnlineAsync ( @ NonNull final List < String > objectIDs , @ NonNull final CompletionHandler completionHandler ) { } }

implementation:
return getObjectsOnlineAsync ( objectIDs , /* attributesToRetrieve : */
null , /* requestOptions : */
null , completionHandler ) ;


signature:
public class MirroredIndex { /** * Get individual objects , explicitly targeting the offline mirror , not the online API .
 * @ param objectIDs Identifiers of objects to retrieve .
 * @ param attributesToRetrieve Attributes to retrieve . If ` null ` or if at least one item is ` * ` , all retrievable
 * attributes will be retrieved .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request .
 * @ throws IllegalStateException if mirroring is not activated on this index . */
public Request getObjectsOfflineAsync ( @ NonNull final List < String > objectIDs , final @ Nullable List < String > attributesToRetrieve , @ NonNull CompletionHandler completionHandler ) { } }

implementation: if ( ! mirrored ) { throw new IllegalStateException ( "Mirroring not activated on this index" ) ; } return getClient ( ) . new AsyncTaskRequest ( completionHandler , getClient ( ) . localSearchExecutorService ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return _getObjectsOffline ( objectIDs , attributesToRetrieve ) ; } } . start ( ) ;


signature:
public class MirroredIndex { /** * Get individual objects , explicitly targeting the offline mirror , not the online API .
 * @ param objectIDs Identifiers of objects to retrieve .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request .
 * @ throws IllegalStateException if mirroring is not activated on this index . */
public Request getObjectsOfflineAsync ( @ NonNull final List < String > objectIDs , @ NonNull final CompletionHandler completionHandler ) { } }

implementation: return getObjectsOfflineAsync ( objectIDs , null , completionHandler ) ;


signature: public class MirroredIndex { @ Override public Request searchForFacetValuesAsync ( @ NonNull String facetName , @ NonNull String text , @ Nullable Query query , @ Nullable RequestOptions requestOptions , @ NonNull final CompletionHandler completionHandler ) { } }

implementation:
// A non - mirrored index behaves exactly as an online index .
if ( ! mirrored ) { return super . searchForFacetValuesAsync ( facetName , text , query , requestOptions , completionHandler ) ; } // A mirrored index launches a mixed offline / online request .
else { final Query queryCopy = query != null ? new Query ( query ) : null ; return new MixedFacetSearchRequest ( facetName , text , queryCopy , requestOptions , completionHandler ) . start ( ) ; }


signature:
public class MirroredIndex { /** * Search for facet values , explicitly targeting the online API , not the offline mirror .
 * Same parameters as { @ link Index # searchForFacetValues ( String , String , Query , CompletionHandler ) } . */
public Request searchForFacetValuesOnline ( @ NonNull String facetName , @ NonNull String text , @ Nullable Query query , @ NonNull final CompletionHandler completionHandler ) { } }

implementation:
return searchForFacetValuesOnline ( facetName , text , query , /* requestOptions : */
null , completionHandler ) ;


signature:
public class MirroredIndex { /** * Search for facet values , explicitly targeting the online API , not the offline mirror .
 * Same parameters as { @ link Index # searchForFacetValues ( String , String , Query , CompletionHandler ) } . */
public Request searchForFacetValuesOnline ( @ NonNull String facetName , @ NonNull String text , @ Nullable Query query , @ Nullable RequestOptions requestOptions , @ NonNull final CompletionHandler completionHandler ) { } }

implementation:
return super . searchForFacetValuesAsync ( facetName , text , query , requestOptions , new CompletionHandler ( ) { @ Override public void requestCompleted ( JSONObject content , AlgoliaException error ) { try { if ( content != null ) content . put ( JSON_KEY_ORIGIN , JSON_VALUE_ORIGIN_REMOTE ) ; } catch ( JSONException e ) { throw new RuntimeException ( e ) ; // should never happen
} completionHandler . requestCompleted ( content , error ) ; } } ) ;


signature:
public class MirroredIndex { /** * Search for facet values , explicitly targeting the offline mirror , not the online API . */
public Request searchForFacetValuesOffline ( final @ NonNull String facetName , final @ NonNull String text , @ Nullable Query query , @ NonNull final CompletionHandler completionHandler ) { } }

implementation: if ( ! mirrored ) { throw new IllegalStateException ( "Offline requests are only available when the index is mirrored" ) ; } final Query queryCopy = query != null ? new Query ( query ) : null ; return getClient ( ) . new AsyncTaskRequest ( completionHandler , getClient ( ) . localSearchExecutorService ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return _searchForFacetValuesOffline ( facetName , text , queryCopy ) ; } } . start ( ) ;


signature:
public class Index { /** * Searches inside this index ( asynchronously ) .
 * @ param query Search parameters . May be null to use an empty query .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request searchAsync ( @ Nullable Query query , @ Nullable final RequestOptions requestOptions , @ Nullable CompletionHandler completionHandler ) { } }

implementation: final Query queryCopy = query != null ? new Query ( query ) : new Query ( ) ; return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return search ( queryCopy , requestOptions ) ; } } . start ( ) ;


signature:
public class Index { /** * Searches inside this index ( synchronously ) .
 * @ param query Search parameters .
 * @ param requestOptions Request - specific options .
 * @ return Search results . */
public JSONObject searchSync ( @ Nullable Query query , @ Nullable RequestOptions requestOptions ) throws AlgoliaException { } }

implementation: return search ( query , requestOptions ) ;


signature:
public class Index { /** * Run multiple queries on this index with one API call .
 * A variant of { @ link Client # multipleQueriesAsync ( List , Client . MultipleQueriesStrategy , CompletionHandler ) }
 * where the targeted index is always the receiver .
 * @ param queries The queries to run .
 * @ param strategy The strategy to use .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request multipleQueriesAsync ( final @ NonNull Collection < Query > queries , final Client . MultipleQueriesStrategy strategy , @ Nullable CompletionHandler completionHandler ) { } }

implementation:
return multipleQueriesAsync ( queries , strategy , /* requestOptions : */
null , completionHandler ) ;


signature:
public class Index { /** * Searches inside this index synchronously .
 * @ param query Search parameters .
 * @ param requestOptions Request - specific options .
 * @ return Search results . */
protected byte [ ] searchSyncRaw ( @ NonNull Query query , @ Nullable RequestOptions requestOptions ) throws AlgoliaException { } }

implementation: return searchRaw ( query , requestOptions ) ;


signature:
public class Index { /** * Perform a search with disjunctive facets , generating as many queries as number of disjunctive facets ( helper ) .
 * @ param query The query .
 * @ param disjunctiveFacets List of disjunctive facets .
 * @ param refinements The current refinements , mapping facet names to a list of values .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
@ Override public Request searchDisjunctiveFacetingAsync ( @ NonNull Query query , @ NonNull final Collection < String > disjunctiveFacets , @ NonNull final Map < String , ? extends Collection < String > > refinements , @ Nullable final RequestOptions requestOptions , @ NonNull final CompletionHandler completionHandler ) { } }

implementation: return new DisjunctiveFaceting ( ) { @ Override protected Request multipleQueriesAsync ( @ NonNull Collection < Query > queries , @ Nullable CompletionHandler completionHandler ) { return Index . this . multipleQueriesAsync ( queries , null , requestOptions , completionHandler ) ; } } . searchDisjunctiveFacetingAsync ( query , disjunctiveFacets , refinements , completionHandler ) ;


signature:
public class Index { /** * Perform a search with disjunctive facets , generating as many queries as number of disjunctive facets ( helper ) .
 * @ param query The query .
 * @ param disjunctiveFacets List of disjunctive facets .
 * @ param refinements The current refinements , mapping facet names to a list of values .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request searchDisjunctiveFacetingAsync ( @ NonNull Query query , @ NonNull final Collection < String > disjunctiveFacets , @ NonNull final Map < String , ? extends Collection < String > > refinements , @ NonNull final CompletionHandler completionHandler ) { } }

implementation:
return searchDisjunctiveFacetingAsync ( query , disjunctiveFacets , refinements , /* requestOptions : */
null , completionHandler ) ;


signature:
public class Index { /** * Searches ( asynchronously ) for some text in a facet values .
 * @ param facetName The name of the facet to search . It must have been declared in the index ' s ` attributesForFaceting ` setting with the ` searchable ( ) ` modifier .
 * @ param text The text to search for in the facet ' s values .
 * @ param handler A Completion handler that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request searchForFacetValuesAsync ( @ NonNull String facetName , @ NonNull String text , @ NonNull final CompletionHandler handler ) throws AlgoliaException { } }

implementation:
return searchForFacetValuesAsync ( facetName , text , /* requestOptions : */
null , handler ) ;


signature:
public class Index { /** * Searches for some text in a facet values , optionally restricting the returned values to those contained in objects matching other ( regular ) search criteria .
 * @ param facetName The name of the facet to search . It must have been declared in the index ' s ` attributesForFaceting ` setting with the ` searchable ( ) ` modifier .
 * @ param facetText The text to search for in the facet ' s values .
 * @ param query An optional query to take extra search parameters into account . There parameters apply to index objects like in a regular search query . Only facet values contained in the matched objects will be returned
 * @ param handler A Completion handler that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request searchForFacetValuesAsync ( @ NonNull String facetName , @ NonNull String facetText , @ Nullable Query query , @ NonNull final CompletionHandler handler ) { } }

implementation:
return searchForFacetValuesAsync ( facetName , facetText , query , /* requestOptions : */
null , handler ) ;


signature:
public class Index { /** * Searches for some text in a facet values , optionally restricting the returned values to those contained in objects matching other ( regular ) search criteria .
 * @ param facetName The name of the facet to search . It must have been declared in the index ' s ` attributesForFaceting ` setting with the ` searchable ( ) ` modifier .
 * @ param facetText The text to search for in the facet ' s values .
 * @ param query An optional query to take extra search parameters into account . There parameters apply to index objects like in a regular search query . Only facet values contained in the matched objects will be returned
 * @ param requestOptions Request - specific options .
 * @ param handler A Completion handler that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
@ Override public Request searchForFacetValuesAsync ( @ NonNull String facetName , @ NonNull String facetText , @ Nullable Query query , @ Nullable final RequestOptions requestOptions , @ NonNull final CompletionHandler handler ) { } }

implementation:
try { final String path = "/1/indexes/" + getEncodedIndexName ( ) + "/facets/" + URLEncoder . encode ( facetName , "UTF-8" ) + "/query" ; final Query params = ( query != null ? new Query ( query ) : new Query ( ) ) ; params . set ( "facetQuery" , facetText ) ; final JSONObject requestBody = new JSONObject ( ) . put ( "params" , params . build ( ) ) ; final Client client = getClient ( ) ; return client . new AsyncTaskRequest ( handler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return client . postRequest ( path , /* urlParameters : */
null , requestBody . toString ( ) , true , requestOptions ) ; } } . start ( ) ; } catch ( UnsupportedEncodingException | JSONException e ) { throw new RuntimeException ( e ) ; // should never happen
}


signature:
public class Index { /** * Adds an object to this index ( asynchronously ) .
 * WARNING : For performance reasons , the arguments are not cloned . Since the method is executed in the background ,
 * you should not modify the object after it has been passed .
 * @ param object The object to add .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request addObjectAsync ( final @ NonNull JSONObject object , @ Nullable CompletionHandler completionHandler ) { } }

implementation:
return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return addObject ( object , /* requestOptions : */
null ) ; } } . start ( ) ;


signature:
public class Index { /** * Adds an object to this index , assigning it the specified object ID ( asynchronously ) .
 * If an object already exists with the same object ID , the existing object will be overwritten .
 * WARNING : For performance reasons , the arguments are not cloned . Since the method is executed in the background ,
 * you should not modify the object after it has been passed .
 * @ param object The object to add .
 * @ param objectID Identifier that you want to assign this object .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request addObjectAsync ( final @ NonNull JSONObject object , final @ NonNull String objectID , @ Nullable CompletionHandler completionHandler ) { } }

implementation:
return addObjectAsync ( object , objectID , /* requestOptions : */
null , completionHandler ) ;


signature:
public class Index { /** * Adds an object to this index , assigning it the specified object ID ( asynchronously ) .
 * If an object already exists with the same object ID , the existing object will be overwritten .
 * WARNING : For performance reasons , the arguments are not cloned . Since the method is executed in the background ,
 * you should not modify the object after it has been passed .
 * @ param object The object to add .
 * @ param objectID Identifier that you want to assign this object .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request addObjectAsync ( final @ NonNull JSONObject object , final @ NonNull String objectID , @ Nullable final RequestOptions requestOptions , @ Nullable CompletionHandler completionHandler ) { } }

implementation: return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return addObject ( object , objectID , requestOptions ) ; } } . start ( ) ;


signature:
public class Index { /** * Adds several objects to this index ( asynchronously ) .
 * @ param objects Objects to add .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request addObjectsAsync ( final @ NonNull JSONArray objects , @ Nullable CompletionHandler completionHandler ) { } }

implementation:
return addObjectsAsync ( objects , /* requestOptions : */
null , completionHandler ) ;


signature:
public class Index { /** * Update several objects ( asynchronously ) .
 * @ param objects Objects to update . Each object must contain an < code > objectID < / code > attribute .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request saveObjectsAsync ( final @ NonNull JSONArray objects , @ Nullable final RequestOptions requestOptions , @ Nullable CompletionHandler completionHandler ) { } }

implementation: return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return saveObjects ( objects , requestOptions ) ; } } . start ( ) ;


signature:
public class Index { /** * Partially update an object ( asynchronously ) .
 * * * Note : * * This method will create the object if it does not exist already . If you don ' t wish to , you can use
 * { @ link # partialUpdateObjectAsync ( JSONObject , String , boolean , CompletionHandler ) } and specify ` false ` for the
 * ` createIfNotExists ` argument .
 * @ param partialObject New value / operations for the object .
 * @ param objectID Identifier of object to be updated .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request partialUpdateObjectAsync ( final @ NonNull JSONObject partialObject , final @ NonNull String objectID , @ Nullable CompletionHandler completionHandler ) { } }

implementation:
return partialUpdateObjectAsync ( partialObject , objectID , /* createIfNotExists : */
true , /* requestOptions : */
null , completionHandler ) ;


signature:
public class Index { /** * Partially update an object ( asynchronously ) .
 * @ param partialObject New value / operations for the object .
 * @ param objectID Identifier of object to be updated .
 * @ param createIfNotExists Whether the object should be created if it does not exist already .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request partialUpdateObjectAsync ( final @ NonNull JSONObject partialObject , final @ NonNull String objectID , final boolean createIfNotExists , @ Nullable final RequestOptions requestOptions , @ Nullable CompletionHandler completionHandler ) { } }

implementation: return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return partialUpdateObject ( partialObject , objectID , createIfNotExists , requestOptions ) ; } } . start ( ) ;


signature:
public class Index { /** * Partially update several objects ( asynchronously ) .
 * * * Note : * * This method will create the objects if they do not exist already . If you don ' t wish to , you can use
 * { @ link # partialUpdateObjectsAsync ( JSONArray , boolean , CompletionHandler ) } and specify ` false ` for the
 * ` createIfNotExists ` argument .
 * @ param partialObjects New values / operations for the objects . Each object must contain an < code > objectID < / code >
 * attribute .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request partialUpdateObjectsAsync ( final @ NonNull JSONArray partialObjects , @ Nullable CompletionHandler completionHandler ) { } }

implementation:
return partialUpdateObjectsAsync ( partialObjects , /* createIfNotExists : */
true , /* requestOptions : */
null , completionHandler ) ;


signature:
public class Index { /** * Partially update several objects ( asynchronously ) .
 * @ param partialObjects New values / operations for the objects . Each object must contain an < code > objectID < / code >
 * attribute .
 * @ param createIfNotExists Whether objects should be created if they do not exist already .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request partialUpdateObjectsAsync ( final @ NonNull JSONArray partialObjects , final boolean createIfNotExists , @ Nullable final RequestOptions requestOptions , @ Nullable CompletionHandler completionHandler ) { } }

implementation: return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return partialUpdateObjects ( partialObjects , createIfNotExists , requestOptions ) ; } } . start ( ) ;


signature:
public class Index { /** * Gets an object from this index , optionally restricting the retrieved content ( asynchronously ) .
 * @ param objectID Identifier of the object to retrieve .
 * @ param attributesToRetrieve List of attributes to retrieve .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request getObjectAsync ( final @ NonNull String objectID , final Collection < String > attributesToRetrieve , @ Nullable CompletionHandler completionHandler ) { } }

implementation:
return getObjectAsync ( objectID , attributesToRetrieve , /* requestOptions : */
null , completionHandler ) ;


signature:
public class Index { /** * Gets an object from this index , optionally restricting the retrieved content ( asynchronously ) .
 * @ param objectID Identifier of the object to retrieve .
 * @ param attributesToRetrieve List of attributes to retrieve .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request getObjectAsync ( final @ NonNull String objectID , final Collection < String > attributesToRetrieve , @ Nullable final RequestOptions requestOptions , @ Nullable CompletionHandler completionHandler ) { } }

implementation: return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return getObject ( objectID , attributesToRetrieve , requestOptions ) ; } } . start ( ) ;


signature:
public class Index { /** * Gets several objects from this index ( asynchronously ) .
 * @ param objectIDs Identifiers of objects to retrieve .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request getObjectsAsync ( final @ NonNull Collection < String > objectIDs , @ Nullable CompletionHandler completionHandler ) { } }

implementation:
return getObjectsAsync ( objectIDs , /* attributesToRetrieve : */
null , /* requestOptions : */
null , completionHandler ) ;


signature:
public class Index { /** * Gets several objects from this index ( asynchronously ) , optionally restricting the retrieved content ( asynchronously ) .
 * @ param objectIDs Identifiers of objects to retrieve .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request getObjectsAsync ( final @ NonNull Collection < String > objectIDs , @ Nullable final RequestOptions requestOptions , @ Nullable CompletionHandler completionHandler ) { } }

implementation: return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return getObjects ( objectIDs , null , requestOptions ) ; } } . start ( ) ;


signature:
public class Index { /** * Wait until the publication of a task on the server ( helper ) .
 * All server tasks are asynchronous . This method helps you check that a task is published .
 * @ param taskID Identifier of the task ( as returned by the server ) .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request waitTaskAsync ( final @ NonNull String taskID , @ Nullable CompletionHandler completionHandler ) { } }

implementation: return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return waitTask ( taskID ) ; } } . start ( ) ;


signature:
public class Index { /** * Deletes an object from this index ( asynchronously ) .
 * @ param objectID Identifier of the object to delete .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request deleteObjectAsync ( final @ NonNull String objectID , @ Nullable CompletionHandler completionHandler ) { } }

implementation:
return deleteObjectAsync ( objectID , /* requestOptions : */
null , completionHandler ) ;


signature:
public class Index { /** * Deletes an object from this index ( asynchronously ) .
 * @ param objectID Identifier of the object to delete .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request deleteObjectAsync ( final @ NonNull String objectID , @ Nullable final RequestOptions requestOptions , @ Nullable CompletionHandler completionHandler ) { } }

implementation: return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return deleteObject ( objectID , requestOptions ) ; } } . start ( ) ;


signature:
public class Index { /** * Deletes several objects from this index ( asynchronously ) .
 * @ param objectIDs Identifiers of objects to delete .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request deleteObjectsAsync ( final @ NonNull Collection < String > objectIDs , @ Nullable CompletionHandler completionHandler ) { } }

implementation:
return deleteObjectsAsync ( objectIDs , /* requestOptions : */
null , completionHandler ) ;


signature:
public class Index { /** * Deletes several objects from this index ( asynchronously ) .
 * @ param objectIDs Identifiers of objects to delete .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request deleteObjectsAsync ( final @ NonNull Collection < String > objectIDs , @ Nullable final RequestOptions requestOptions , @ Nullable CompletionHandler completionHandler ) { } }

implementation: return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return deleteObjects ( objectIDs , requestOptions ) ; } } . start ( ) ;


signature:
public class Index { /** * Deletes all objects matching a query ( helper ) using browse and deleteObjects .
 * @ param query The query that objects to delete must match .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request .
 * @ deprecated use { @ link Index # deleteByAsync ( Query , CompletionHandler ) } instead . */
public Request deleteByQueryAsync ( @ NonNull Query query , @ Nullable CompletionHandler completionHandler ) { } }

implementation:
return deleteByQueryAsync ( query , /* requestOptions : */
null , completionHandler ) ;


signature:
public class Index { /** * Gets this index ' s settings ( asynchronously ) .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request getSettingsAsync ( @ Nullable final RequestOptions requestOptions , @ Nullable CompletionHandler completionHandler ) { } }

implementation: return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return getSettings ( 2 , requestOptions ) ; } } . start ( ) ;


signature:
public class Index { /** * Set this index ' s settings ( asynchronously ) .
 * Please refer to our < a href = " https : / / www . algolia . com / doc / android # index - settings " > API documentation < / a > for the
 * list of supported settings .
 * @ param settings New settings .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request setSettingsAsync ( final @ NonNull JSONObject settings , @ Nullable CompletionHandler completionHandler ) { } }

implementation:
return setSettingsAsync ( settings , /* forwardToReplicas : */
false , /* requestOptions : */
null , completionHandler ) ;


signature:
public class Index { /** * Set this index ' s settings ( asynchronously ) .
 * Please refer to our < a href = " https : / / www . algolia . com / doc / android # index - settings " > API documentation < / a > for the
 * list of supported settings .
 * @ param settings New settings .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request setSettingsAsync ( final @ NonNull JSONObject settings , final boolean forwardToReplicas , @ Nullable final RequestOptions requestOptions , @ Nullable CompletionHandler completionHandler ) { } }

implementation: return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return setSettings ( settings , forwardToReplicas , requestOptions ) ; } } . start ( ) ;


signature:
public class Index { /** * Browse the index from a cursor .
 * This method should be called after an initial call to ` browseAsync ( ) ` . It returns a cursor , unless the end of
 * the index has been reached .
 * @ param cursor The cursor of the next page to retrieve .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request browseFromAsync ( final @ NonNull String cursor , @ Nullable CompletionHandler completionHandler ) { } }

implementation:
return browseFromAsync ( cursor , /* requestOptions : */
null , completionHandler ) ;


signature:
public class Index { /** * Browse the index from a cursor .
 * This method should be called after an initial call to ` browseAsync ( ) ` . It returns a cursor , unless the end of
 * the index has been reached .
 * @ param cursor The cursor of the next page to retrieve .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request browseFromAsync ( final @ NonNull String cursor , @ Nullable final RequestOptions requestOptions , @ Nullable CompletionHandler completionHandler ) { } }

implementation: return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return browseFrom ( cursor , requestOptions ) ; } } . start ( ) ;


signature:
public class Index { /** * Clear this index .
 * @ param requestOptions Request - specific options .
 * @ param completionHandler The listener that will be notified of the request ' s outcome .
 * @ return A cancellable request . */
public Request clearIndexAsync ( @ Nullable final RequestOptions requestOptions , @ Nullable CompletionHandler completionHandler ) { } }

implementation: return getClient ( ) . new AsyncTaskRequest ( completionHandler ) { @ NonNull @ Override protected JSONObject run ( ) throws AlgoliaException { return clearIndex ( requestOptions ) ; } } . start ( ) ;


signature:
public class Index { /** * Adds an object in this index .
 * @ param obj the object to add .
 * @ param requestOptions Request - specific options .
 * @ throws AlgoliaException */
public JSONObject addObject ( JSONObject obj , @ Nullable RequestOptions requestOptions ) throws AlgoliaException { } }

implementation:
return client . postRequest ( "/1/indexes/" + encodedIndexName , /* urlParameters : */
null , obj . toString ( ) , false , requestOptions ) ;


signature:
public class Index { /** * Custom batch .
 * @ param actions the array of actions
 * @ param requestOptions Request - specific options .
 * @ throws AlgoliaException */
protected JSONObject batch ( JSONArray actions , @ Nullable RequestOptions requestOptions ) throws AlgoliaException { } }

implementation:
try { JSONObject content = new JSONObject ( ) ; content . put ( "requests" , actions ) ; return client . postRequest ( "/1/indexes/" + encodedIndexName + "/batch" , /* urlParameters : */
null , content . toString ( ) , false , requestOptions ) ; } catch ( JSONException e ) { throw new AlgoliaException ( e . getMessage ( ) ) ; }


signature:
public class Index { /** * Gets an object from this index .
 * @ param objectID the unique identifier of the object to retrieve
 * @ param requestOptions Request - specific options .
 * @ throws AlgoliaException */
public JSONObject getObject ( String objectID , @ Nullable RequestOptions requestOptions ) throws AlgoliaException { } }

implementation:
try { return client . getRequest ( "/1/indexes/" + encodedIndexName + "/" + URLEncoder . encode ( objectID , "UTF-8" ) , /* urlParameters : */
null , false , requestOptions ) ; } catch ( UnsupportedEncodingException e ) { throw new RuntimeException ( e ) ; }


signature:
public class Index { /** * Gets an object from this index .
 * @ param objectID the unique identifier of the object to retrieve
 * @ param attributesToRetrieve contains the list of attributes to retrieve .
 * @ param requestOptions Request - specific options .
 * @ throws AlgoliaException */
public JSONObject getObject ( String objectID , Collection < String > attributesToRetrieve , @ Nullable RequestOptions requestOptions ) throws AlgoliaException { } }

implementation: try { String path = "/1/indexes/" + encodedIndexName + "/" + URLEncoder . encode ( objectID , "UTF-8" ) ; Map < String , String > urlParameters = new HashMap < > ( ) ; if ( attributesToRetrieve != null ) { urlParameters . put ( "attributesToRetrieve" , AbstractQuery . buildCommaArray ( attributesToRetrieve . toArray ( new String [ attributesToRetrieve . size ( ) ] ) ) ) ; } return client . getRequest ( path , urlParameters , false , requestOptions ) ; } catch ( UnsupportedEncodingException e ) { throw new RuntimeException ( e ) ; }


signature:
public class Index { /** * Gets several objects from this index .
 * @ param objectIDs the array of unique identifier of objects to retrieve
 * @ throws AlgoliaException */
public JSONObject getObjects ( Collection < String > objectIDs ) throws AlgoliaException { } }

implementation:
return getObjects ( objectIDs , /* attributesToRetrieve : */
null , /* requestOptions : */
null ) ;


signature:
public class Index { /** * Gets several objects from this index .
 * @ param objectIDs the array of unique identifier of objects to retrieve
 * @ param attributesToRetrieve contains the list of attributes to retrieve .
 * @ param requestOptions Request - specific options .
 * @ throws AlgoliaException */
public JSONObject getObjects ( @ NonNull Collection < String > objectIDs , @ Nullable Collection < String > attributesToRetrieve , @ Nullable RequestOptions requestOptions ) throws AlgoliaException { } }

implementation:
try { JSONArray requests = new JSONArray ( ) ; for ( String id : objectIDs ) { JSONObject request = new JSONObject ( ) ; request . put ( "indexName" , this . rawIndexName ) ; request . put ( "objectID" , id ) ; if ( attributesToRetrieve != null ) { request . put ( "attributesToRetrieve" , new JSONArray ( attributesToRetrieve ) ) ; } requests . put ( request ) ; } JSONObject body = new JSONObject ( ) ; body . put ( "requests" , requests ) ; return client . postRequest ( "/1/indexes/*/objects" , /* urlParameters : */
null , body . toString ( ) , true , requestOptions ) ; } catch ( JSONException e ) { throw new AlgoliaException ( e . getMessage ( ) ) ; }


signature:
public class Index { /** * Update partially an object ( only update attributes passed in argument ) .
 * @ param partialObject the object attributes to override
 * @ param requestOptions Request - specific options .
 * @ throws AlgoliaException */
public JSONObject partialUpdateObject ( JSONObject partialObject , String objectID , Boolean createIfNotExists , @ Nullable RequestOptions requestOptions ) throws AlgoliaException { } }

implementation: try { String path = "/1/indexes/" + encodedIndexName + "/" + URLEncoder . encode ( objectID , "UTF-8" ) + "/partial" ; Map < String , String > urlParameters = new HashMap < > ( ) ; if ( createIfNotExists != null ) { urlParameters . put ( "createIfNotExists" , createIfNotExists . toString ( ) ) ; } return client . postRequest ( path , urlParameters , partialObject . toString ( ) , false , requestOptions ) ; } catch ( UnsupportedEncodingException e ) { throw new RuntimeException ( e ) ; }


signature:
public class Index { /** * Partially Override the content of several objects .
 * @ param inputArray the array of objects to update ( each object must contains an objectID attribute )
 * @ param requestOptions Request - specific options .
 * @ throws AlgoliaException */
public JSONObject partialUpdateObjects ( JSONArray inputArray , boolean createIfNotExists , @ Nullable RequestOptions requestOptions ) throws AlgoliaException { } }

implementation: try { final String action = createIfNotExists ? "partialUpdateObject" : "partialUpdateObjectNoCreate" ; JSONArray array = new JSONArray ( ) ; for ( int n = 0 ; n < inputArray . length ( ) ; n ++ ) { JSONObject obj = inputArray . getJSONObject ( n ) ; JSONObject operation = new JSONObject ( ) ; operation . put ( "action" , action ) ; operation . put ( "objectID" , obj . getString ( "objectID" ) ) ; operation . put ( "body" , obj ) ; array . put ( operation ) ; } return batch ( array , requestOptions ) ; } catch ( JSONException e ) { throw new AlgoliaException ( e . getMessage ( ) ) ; }


signature:
public class Index { /** * Override the content of object .
 * @ param object the object to save
 * @ param requestOptions Request - specific options .
 * @ throws AlgoliaException */
public JSONObject saveObject ( JSONObject object , String objectID , @ Nullable RequestOptions requestOptions ) throws AlgoliaException { } }

implementation:
try { return client . putRequest ( "/1/indexes/" + encodedIndexName + "/" + URLEncoder . encode ( objectID , "UTF-8" ) , /* urlParameters : */
null , object . toString ( ) , requestOptions ) ; } catch ( UnsupportedEncodingException e ) { throw new RuntimeException ( e ) ; }


signature:
public class Index { /** * Override the content of several objects .
 * @ param inputArray contains an array of objects to update ( each object must contains an objectID attribute )
 * @ param requestOptions Request - specific options .
 * @ throws AlgoliaException */
public JSONObject saveObjects ( JSONArray inputArray , @ Nullable RequestOptions requestOptions ) throws AlgoliaException { } }

implementation: try { JSONArray array = new JSONArray ( ) ; for ( int n = 0 ; n < inputArray . length ( ) ; n ++ ) { JSONObject obj = inputArray . getJSONObject ( n ) ; JSONObject action = new JSONObject ( ) ; action . put ( "action" , "updateObject" ) ; action . put ( "objectID" , obj . getString ( "objectID" ) ) ; action . put ( "body" , obj ) ; array . put ( action ) ; } return batch ( array , requestOptions ) ; } catch ( JSONException e ) { throw new AlgoliaException ( e . getMessage ( ) ) ; }


signature:
public class Index { /** * Deletes all objects matching a query using browse and deleteObjects .
 * @ param query the query string
 * @ param requestOptions Request - specific options .
 * @ throws AlgoliaException
 * @ deprecated use { @ link Index # deleteBy ( Query ) } instead . */
@ Deprecated public void deleteByQuery ( @ NonNull Query query , @ Nullable RequestOptions requestOptions ) throws AlgoliaException { } }

implementation:
try { boolean hasMore ; do { // Browse index for the next batch of objects .
// WARNING : Since deletion invalidates cursors , we always browse from the start .
List < String > objectIDs = new ArrayList < > ( 1000 ) ; JSONObject content = browse ( query , requestOptions ) ; JSONArray hits = content . getJSONArray ( "hits" ) ; for ( int i = 0 ; i < hits . length ( ) ; ++ i ) { JSONObject hit = hits . getJSONObject ( i ) ; objectIDs . add ( hit . getString ( "objectID" ) ) ; } hasMore = content . optString ( "cursor" , null ) != null ; // Delete objects .
JSONObject task = this . deleteObjects ( objectIDs , /* requestOptions : */
null ) ; this . waitTask ( task . getString ( "taskID" ) ) ; } while ( hasMore ) ; } catch ( JSONException e ) { throw new AlgoliaException ( e . getMessage ( ) ) ; }


signature:
public class Index { /** * Deletes all records matching the query .
 * @ param query the query string
 * @ throws AlgoliaException */
public JSONObject deleteBy ( @ NonNull Query query , RequestOptions requestOptions ) throws AlgoliaException { } }

implementation: try { return client . postRequest ( "/1/indexes/" + encodedIndexName + "/deleteByQuery" , query . getParameters ( ) , new JSONObject ( ) . put ( "params" , query . build ( ) ) . toString ( ) , false , requestOptions ) ; } catch ( JSONException e ) { e . printStackTrace ( ) ; return null ; }