signature:
public class Animators { /** * Scale the Activity down to the rectangle . To see the Activity behind this one , you must
 * include the below attributes [ 1 ] in your Activity theme . You may further modify the animator ,
 * for example to fade out the Activity by decreasing its
 * { @ link ViewPropertyAnimator # alpha ( float ) alpha } and / or set an
 * { @ link ViewPropertyAnimator # withEndAction ( Runnable ) end action } that finishes the Activity .
 * When finishing the Activity in this way , you may wish to also call
 * { @ link Activity # overridePendingTransition ( int , int ) Activity . overridePendingTransition ( 0,
 * 0 ) } in order to prevent the system Activity close animation from running .
 * 1 . Activity theme attributes
 * { @ code < item name = " android : windowBackground " > @ android : color / transparent < / item > } < br / >
 * { @ code < item name = " android : windowIsTranslucent " > true < / item > }
 * @ see ActivityOptions # makeScaleUpAnimation ( View , int , int , int , int ) */
public static ViewPropertyAnimator makeScaleDownAnimation ( Activity a , Rect to ) { } }

implementation:
View view = a . getWindow ( ) . getDecorView ( ) ; Rect frame = Windows . getFrame ( a ) ; float sx = ( float ) to . width ( ) / view . getWidth ( ) ; float sy = ( float ) to . height ( ) / ( view . getHeight ( ) - frame . top ) ; // ignore status bar
view . setPivotX ( 0.0f ) ; view . setPivotY ( 0.0f ) ; return view . animate ( ) . translationX ( to . left ) . translationY ( to . top - frame . top * sy ) . scaleX ( sx ) . scaleY ( sy ) . withLayer ( ) ;


signature:
public class Content { /** * Get the number of rows at the URI .
 * @ return { @ link Integer # MIN _ VALUE } if the URI could not be queried
 * @ since 2.3.0 */
public static int getCount ( Context context , Uri uri ) { } }

implementation: String [ ] proj = { "COUNT(*)" } ; return Cursors . firstInt ( context . getContentResolver ( ) . query ( uri , proj , null , null , null ) ) ;


signature:
public class Content { /** * Request that a sync starts immediately .
 * @ see ContentResolver # requestSync ( Account , String , Bundle ) */
public static void requestSyncNow ( Account account , String authority , @ Nullable Bundle extras ) { } }

implementation: if ( extras == null ) { extras = new Bundle ( ) ; } extras . putBoolean ( SYNC_EXTRAS_MANUAL , true ) ; extras . putBoolean ( SYNC_EXTRAS_EXPEDITED , true ) ; ContentResolver . requestSync ( account , authority , extras ) ;


signature:
public class Addresses { /** * Get a single line address which uses the delimiter between the original lines . */
public static String concatAddressLines ( Address address , String delimiter ) { } }

implementation: StringBuilder s = new StringBuilder ( 256 ) ; for ( int i = 0 , max = address . getMaxAddressLineIndex ( ) ; i <= max ; i ++ ) { if ( i > 0 ) { s . append ( delimiter ) ; } s . append ( address . getAddressLine ( i ) ) ; } return s . toString ( ) ;


signature:
public class GoogleApiClients { /** * Register the listeners and then connect the client . */
public static GoogleApiClient connect ( GoogleApiClient client , ConnectedListener connected , OnConnectionFailedListener failed ) { } }

implementation: client . registerConnectionCallbacks ( new ConnectionListener ( connected ) ) ; client . registerConnectionFailedListener ( failed ) ; client . connect ( ) ; return client ;


signature:
public class Fragments { /** * Get the arguments for the Fragment . If the Fragment doesn ' t have arguments and it isn ' t
 * attached to an Activity , a new Bundle will be set as its arguments . Otherwise an empty ( and
 * immutable ) Bundle will be returned . */
public static Bundle arguments ( Fragment frag ) { } }

implementation:
Bundle args = frag . getArguments ( ) ; if ( args == null ) { if ( ! frag . isAdded ( ) ) { args = new Bundle ( ) ; try { frag . setArguments ( args ) ; } catch ( IllegalStateException e ) { // " attached " but not yet " added "
args = EMPTY ; } } else { args = EMPTY ; } } return args ;


signature:
public class Fragments { /** * Begin a transaction that uses the transition .
 * @ return null if the FragmentManager is null */
@ SuppressLint ( "CommitTransaction" ) private static FragmentTransaction transit ( FragmentManager fm , int transit ) { } }

implementation: return fm != null ? fm . beginTransaction ( ) . setTransition ( transit ) : null ;


signature:
public class Fragments { /** * Get the Fragment with the ID .
 * @ return null if the Fragment isn ' t found
 * @ since 4.0.0 */
@ Nullable public static < T extends Fragment > T findById ( Activity a , @ IdRes int id ) { } }

implementation: return findById ( a . getFragmentManager ( ) , id ) ;


signature:
public class Fragments { /** * Get the Fragment with the ID .
 * @ return null if the Fragment isn ' t found
 * @ since 4.0.0 */
@ Nullable public static < T extends Fragment > T findById ( Fragment frag , @ IdRes int id ) { } }

implementation: return findById ( frag . getFragmentManager ( ) , id ) ;


signature:
public class Fragments { /** * Get the Fragment with the ID .
 * @ return null if the Fragment isn ' t found
 * @ since 4.0.0 */
@ Nullable @ SuppressWarnings ( "unchecked" ) public static < T extends Fragment > T findById ( FragmentManager fm , @ IdRes int id ) { } }

implementation: return ( T ) fm . findFragmentById ( id ) ;


signature:
public class MutableForegroundColorSpan { /** * Get the result of applying the alpha to the color . */
@ Override public int getForegroundColor ( ) { } }

implementation: return Color . argb ( mAlpha , Color . red ( mColor ) , Color . green ( mColor ) , Color . blue ( mColor ) ) ;


signature:
public class Views { /** * Make the View visible if it isn ' t already . */
public static < T extends View > T visible ( @ Nullable T view ) { } }

implementation: return set ( view , VISIBLE ) ;


signature:
public class Views { /** * Make the View invisible if it isn ' t already . */
public static < T extends View > T invisible ( @ Nullable T view ) { } }

implementation: return set ( view , INVISIBLE ) ;


signature:
public class Views { /** * Make the View gone if it isn ' t already . */
public static < T extends View > T gone ( @ Nullable T view ) { } }

implementation: return set ( view , GONE ) ;


signature:
public class Views { /** * { @ link View # measure ( int , int ) Measure } the View in its parent . You can then call
 * { @ link View # getMeasuredWidth ( ) } and { @ link View # getMeasuredHeight ( ) } .
 * @ param view must have { @ link LayoutParams }
 * @ param parent must already be measured */
public static < T extends View > T measure ( T view , ViewGroup parent ) { } }

implementation: LayoutParams p = view . getLayoutParams ( ) ; int w = parent != null && p . width == MATCH_PARENT ? parent . getMeasuredWidth ( ) : p . width ; int h = parent != null && p . height == MATCH_PARENT ? parent . getMeasuredHeight ( ) : p . height ; return measure ( view , w , h ) ;


signature:
public class Views { /** * Inflate the ViewStub if the View is null . Otherwise just get the previously inflated View .
 * @ since 4.0.0 */
@ SuppressWarnings ( "unchecked" ) public static < T extends View > T inflate ( ViewStub stub , @ Nullable T view ) { } }

implementation: return view == null ? ( T ) stub . inflate ( ) : view ;


signature:
public class Views { /** * Set the listener on all of the Views .
 * @ since 4.0.0 */
public static void setOnClickListeners ( OnClickListener listener , View ... views ) { } }

implementation: for ( View view : views ) { view . setOnClickListener ( listener ) ; }


signature:
public class Log { /** * Send an ERROR log message and log the exception . */
public void e ( Object src , String msg , @ Nullable Throwable thrown ) { } }

implementation: maybeLog ( ERROR , src , msg , thrown ) ;


signature:
public class Log { /** * Send a WARN log message and log the exception . */
public void w ( Object src , String msg , @ Nullable Throwable thrown ) { } }

implementation: maybeLog ( WARN , src , msg , thrown ) ;


signature:
public class Log { /** * Send an INFO log message and log the exception . */
public void i ( Object src , String msg , @ Nullable Throwable thrown ) { } }

implementation: maybeLog ( INFO , src , msg , thrown ) ;


signature:
public class Log { /** * Send a DEBUG log message and log the exception . */
public void d ( Object src , String msg , @ Nullable Throwable thrown ) { } }

implementation: maybeLog ( DEBUG , src , msg , thrown ) ;


signature:
public class Log { /** * Send a VERBOSE log message and log the exception . */
public void v ( Object src , String msg , @ Nullable Throwable thrown ) { } }

implementation: maybeLog ( VERBOSE , src , msg , thrown ) ;


signature:
public class Log { /** * Get the name of the level .
 * @ param level one of the Android { @ link android . util . Log Log } constants */
public static String getLevelName ( int level ) { } }

implementation: switch ( level ) { case VERBOSE : return "VERBOSE" ; case DEBUG : return "DEBUG" ; case INFO : return "INFO" ; case WARN : return "WARN" ; case ERROR : return "ERROR" ; case ASSERT : return "ASSERT" ; default : return "?" ; }


signature:
public class MoreActivityOptions { /** * Scale the new Activity from the View to its full size .
 * @ see ActivityOptions # makeScaleUpAnimation ( View , int , int , int , int ) */
public static ActivityOptions makeScaleUpAnimation ( View source ) { } }

implementation: return ActivityOptions . makeScaleUpAnimation ( source , 0 , 0 , source . getWidth ( ) , source . getHeight ( ) ) ;


signature:
public class InputMethods { /** * Show the current input method for the focused View which can receive input . */
public static void show ( View view ) { } }

implementation: view . postDelayed ( ( ) -> Managers . inputMethod ( view . getContext ( ) ) . showSoftInput ( view , 0 ) , 300L ) ; // give InputMethodManager some time to recognise that the View is focused


signature:
public class InputMethods { /** * Hide the input method for the View ' s window . */
public static void hide ( View view ) { } }

implementation: Managers . inputMethod ( view . getContext ( ) ) . hideSoftInputFromWindow ( view . getWindowToken ( ) , 0 ) ;


signature:
public class Cursors { /** * True if the cursor has a row at the position .
 * @ since 4.0.0 */
public static boolean hasPosition ( Cursor cursor , int position ) { } }

implementation: return ! cursor . isClosed ( ) && position >= 0 && position < cursor . getCount ( ) ;


signature:
public class Cursors { /** * Get the number of rows in the cursor .
 * @ param close true to close the cursor or false to leave it open */
public static int count ( Cursor cursor , boolean close ) { } }

implementation: int count = cursor . getCount ( ) ; close ( cursor , close ) ; return count ;


signature:
public class Cursors { /** * Get the int value in the first row and column .
 * @ param close true to close the cursor or false to leave it open
 * @ return { @ link Integer # MIN _ VALUE } if the cursor is empty
 * @ since 2.5.0 */
public static int firstInt ( Cursor cursor , boolean close ) { } }

implementation: int i = cursor . moveToFirst ( ) ? cursor . getInt ( 0 ) : Integer . MIN_VALUE ; close ( cursor , close ) ; return i ;


signature:
public class Cursors { /** * Get the long value in the first row and column .
 * @ param close true to close the cursor or false to leave it open
 * @ return { @ link Long # MIN _ VALUE } if the cursor is empty */
public static long firstLong ( Cursor cursor , boolean close ) { } }

implementation: long l = cursor . moveToFirst ( ) ? cursor . getLong ( 0 ) : Long . MIN_VALUE ; close ( cursor , close ) ; return l ;


signature:
public class Cursors { /** * Get the String value in the first row and column .
 * @ param close true to close the cursor or false to leave it open
 * @ return null if the cursor is empty */
@ Nullable public static String firstString ( Cursor cursor , boolean close ) { } }

implementation: String s = cursor . moveToFirst ( ) ? cursor . getString ( 0 ) : null ; close ( cursor , close ) ; return s ;


signature:
public class Cursors { /** * Get all int values in the first column .
 * @ param close true to close the cursor or false to leave it open
 * @ since 2.5.0 */
public static int [ ] allInts ( Cursor cursor , boolean close ) { } }

implementation: int [ ] i = EMPTY_INT_ARRAY ; if ( cursor . moveToFirst ( ) ) { i = new int [ cursor . getCount ( ) ] ; do { i [ cursor . getPosition ( ) ] = cursor . getInt ( 0 ) ; } while ( cursor . moveToNext ( ) ) ; } close ( cursor , close ) ; return i ;


signature:
public class Cursors { /** * Get all long values in the first column .
 * @ param close true to close the cursor or false to leave it open */
public static long [ ] allLongs ( Cursor cursor , boolean close ) { } }

implementation: long [ ] l = EMPTY_LONG_ARRAY ; if ( cursor . moveToFirst ( ) ) { l = new long [ cursor . getCount ( ) ] ; do { l [ cursor . getPosition ( ) ] = cursor . getLong ( 0 ) ; } while ( cursor . moveToNext ( ) ) ; } close ( cursor , close ) ; return l ;


signature:
public class Cursors { /** * Get all String values in the first column .
 * @ param close true to close the cursor or false to leave it open */
public static String [ ] allStrings ( Cursor cursor , boolean close ) { } }

implementation: String [ ] s = EMPTY_STRING_ARRAY ; if ( cursor . moveToFirst ( ) ) { s = new String [ cursor . getCount ( ) ] ; do { s [ cursor . getPosition ( ) ] = cursor . getString ( 0 ) ; } while ( cursor . moveToNext ( ) ) ; } close ( cursor , close ) ; return s ;


signature:
public class BindingAdapter { /** * Update the contents of the binding to reflect the item at the position . Any payload info can
 * be used to run an efficient partial update . */
public void onBind ( B binding , int position , List < Object > payloads ) { } }

implementation: onBind ( binding , position ) ;


signature:
public class BindingAdapters { /** * Set a placeholder before loading an image , optionally resizing and transforming it . All
 * attributes are optional .
 * @ param transform can be " circle " */
@ BindingAdapter ( value = { } }

implementation:
"sprockets_placeholder" , "sprockets_load" , "sprockets_resize" , "sprockets_transform" } , requireAll = false ) public static void load ( ImageView view , Drawable placeholder , Uri load , boolean resize , String transform ) { RequestCreator req = Picasso . with ( view . getContext ( ) ) . load ( load ) . placeholder ( placeholder ) ; if ( resize ) { req . fit ( ) . centerCrop ( ) ; // view width / height isn ' t available yet
} if ( TextUtils . equals ( transform , "circle" ) ) { req . transform ( Transformations . circle ( ) ) ; } req . into ( view ) ;


signature:
public class LayoutManagers { /** * Get the orientation of the RecyclerView ' s LayoutManager .
 * @ return - 1 if the RecyclerView doesn ' t have a LayoutManager
 * @ see RecyclerView # VERTICAL
 * @ see RecyclerView # HORIZONTAL */
public static int getOrientation ( RecyclerView view ) { } }

implementation: LayoutManager layout = view . getLayoutManager ( ) ; if ( layout instanceof LinearLayoutManager ) { return ( ( LinearLayoutManager ) layout ) . getOrientation ( ) ; } else if ( layout instanceof StaggeredGridLayoutManager ) { return ( ( StaggeredGridLayoutManager ) layout ) . getOrientation ( ) ; } return - 1 ;


signature:
public class LayoutManagers { /** * Get the number of spans laid out by the RecyclerView ' s LayoutManager .
 * @ return 0 if the RecyclerView doesn ' t have a LayoutManager */
public static int getSpanCount ( RecyclerView view ) { } }

implementation:
LayoutManager layout = view . getLayoutManager ( ) ; if ( layout != null ) { if ( layout instanceof GridLayoutManager ) { return ( ( GridLayoutManager ) layout ) . getSpanCount ( ) ; } else if ( layout instanceof StaggeredGridLayoutManager ) { return ( ( StaggeredGridLayoutManager ) layout ) . getSpanCount ( ) ; } return 1 ; // assuming LinearLayoutManager
} return 0 ;


signature:
public class LayoutManagers { /** * If the RecyclerView uses a { @ link GridLayoutManager } , get its SpanSizeLookup . Otherwise get a
 * { @ link DefaultSpanSizeLookup DefaultSpanSizeLookup } . */
public static SpanSizeLookup getSpanSizeLookup ( RecyclerView view ) { } }

implementation: LayoutManager layout = view . getLayoutManager ( ) ; if ( layout instanceof GridLayoutManager ) { return ( ( GridLayoutManager ) layout ) . getSpanSizeLookup ( ) ; } if ( sDefSpanSizeLookup == null ) { sDefSpanSizeLookup = new DefaultSpanSizeLookup ( ) ; } return sDefSpanSizeLookup ;


signature:
public class SearchViews { /** * Override the default background with a theme version . */
public static SearchView setBackground ( SearchView view , @ DrawableRes int drawableId ) { } }

implementation: int id = view . getResources ( ) . getIdentifier ( "android:id/search_plate" , null , null ) ; if ( id > 0 ) { View search = view . findViewById ( id ) ; if ( search != null ) { search . setBackgroundResource ( drawableId ) ; } } return view ;


signature:
public class Layouts { /** * Add the rule to the View ' s RelativeLayout params and request a layout of the View . */
public static RelativeLayout . LayoutParams addRule ( View view , int verb , int anchor ) { } }

implementation: RelativeLayout . LayoutParams params = getParams ( view ) ; params . addRule ( verb , anchor ) ; view . requestLayout ( ) ; return params ;


signature:
public class CursorWrapperLoader { /** * / * Runs on a worker thread */
@ Override public D loadInBackground ( ) { } }

implementation:
synchronized ( this ) { if ( isLoadInBackgroundCanceled ( ) ) { throw new OperationCanceledException ( ) ; } mCancellationSignal = new CancellationSignal ( ) ; } try { Cursor cursor = getContext ( ) . getContentResolver ( ) . query ( mUri , mProjection , mSelection , mSelectionArgs , mSortOrder , mCancellationSignal ) ; if ( cursor != null ) { try { // Ensure the cursor window is filled .
cursor . getCount ( ) ; cursor . registerContentObserver ( mObserver ) ; } catch ( RuntimeException ex ) { cursor . close ( ) ; throw ex ; } return wrap ( cursor ) ; } return null ; } finally { synchronized ( this ) { mCancellationSignal = null ; } }


signature:
public class CursorAdapter { /** * Use the cursor for the items . */
public CursorAdapter < VH > setCursor ( @ Nullable Cursor cursor ) { } }

implementation: if ( cursor != mCursor ) { mCursor = cursor == null || cursor instanceof EasyCursor ? ( EasyCursor ) cursor : new EasyCursor ( cursor ) ; notifyDataSetChanged ( ) ; } return this ;


signature:
public class Drawables { /** * Tint the Drawable with the color specified by the attribute in the Context ' s theme .
 * @ return null if the drawable does not exist
 * @ since 4.0.0 */
@ Nullable public static Drawable tint ( Context context , @ DrawableRes int drawableId , @ AttrRes int attrId ) { } }

implementation: Drawable d = context . getDrawable ( drawableId ) ; if ( d != null ) { d . setTint ( Themes . getColor ( context , attrId ) ) ; } return d ;


signature:
public class Drawables { /** * Set the Drawable ' s size and tint to be the same as the text .
 * @ return null if the drawable does not exist
 * @ since 4.0.0 */
@ Nullable public static Drawable matchText ( Context context , @ DrawableRes int drawableId , TextView text ) { } }

implementation: Drawable d = context . getDrawable ( drawableId ) ; if ( d != null ) { int size = Math . round ( text . getTextSize ( ) ) ; d . setBounds ( 0 , 0 , size , size ) ; d . setTint ( text . getCurrentTextColor ( ) ) ; } return d ;


signature:
public class Drawables { /** * Get a colored oval .
 * @ since 2.2.0 */
public static ShapeDrawable oval ( @ ColorInt int color ) { } }

implementation: if ( sOval == null ) { sOval = new OvalShape ( ) ; } ShapeDrawable d = new ShapeDrawable ( sOval ) ; d . setIntrinsicWidth ( - 1 ) ; d . setIntrinsicHeight ( - 1 ) ; d . getPaint ( ) . setColor ( color ) ; return d ;


signature:
public class Windows { /** * Get the { @ link View # getWindowVisibleDisplayFrame ( Rect ) visible area } of the Activity ' s
 * Window . The height of screen decorations above the Window can be found in { @ link Rect # top } . */
public static Rect getFrame ( Activity a ) { } }

implementation: Rect frame = new Rect ( ) ; a . getWindow ( ) . getDecorView ( ) . getWindowVisibleDisplayFrame ( frame ) ; return frame ;


signature:
public class ReadCursor { /** * True if this method has been previously called for the current row . False if the cursor is
 * before the first row or after the last row . */
public boolean wasRead ( ) { } }

implementation: int pos = getPosition ( ) ; if ( pos < 0 || pos >= mRead . length ) { return false ; } boolean read = mRead [ pos ] ; if ( ! read ) { mRead [ pos ] = true ; } return read ;


signature:
public class NavigationDrawerActivity { /** * Connect the DrawerLayout to the ActionBar . Should be called in
 * { @ link # onCreate ( Bundle ) onCreate } . Must be called before
 * { @ link Activity # onPostCreate ( Bundle ) onPostCreate } executes . */
public NavigationDrawerActivity setDrawerLayout ( DrawerLayout drawer ) { } }

implementation:
mDrawer = drawer ; if ( mDrawer . getFitsSystemWindows ( ) ) { // let it draw the status bar
getWindow ( ) . setStatusBarColor ( TRANSPARENT ) ; } return this ;


signature:
public class Loopers { /** * Get this thread ' s Looper , if it ' s a Looper thread . Otherwise get the main thread Looper . */
public static Looper mineOrMain ( ) { } }

implementation: Looper looper = Looper . myLooper ( ) ; return looper != null ? looper : Looper . getMainLooper ( ) ;


signature:
public class SparseArrays { /** * Get the values of the SparseArray . */
@ SuppressWarnings ( "unchecked" ) public static < E > List < E > values ( SparseArray < E > array ) { } }

implementation: return ( List < E > ) values ( array , null , null , null , null ) ;


signature:
public class SparseArrays { /** * Get the values of the LongSparseArray . */
@ SuppressWarnings ( "unchecked" ) public static < E > List < E > values ( LongSparseArray < E > array ) { } }

implementation: return ( List < E > ) values ( null , null , null , null , array ) ;


signature:
public class TranslateImagePageChangeListener { /** * Check if the pager has a new adapter and switch to it if it does . */
private void checkAdapter ( ) { } }

implementation: PagerAdapter adapter = mPager . getAdapter ( ) ; if ( mAdapter != adapter ) { if ( mAdapter != null ) { mAdapter . unregisterDataSetObserver ( mObserver ) ; } mAdapter = adapter ; if ( mAdapter != null ) { mAdapter . registerDataSetObserver ( mObserver ) ; } reset ( ) ; }


signature:
public class TranslateImagePageChangeListener { /** * Check if the ImageView has a new Drawable and calculate the new scaling if it does . */
private void checkDrawable ( ) { } }

implementation:
Drawable drawable = mView . getDrawable ( ) ; if ( mDrawable != drawable ) { /* get the latest View size and ensure that it ' s been measured */
mViewWidth = mView . getWidth ( ) ; mViewHeight = mView . getHeight ( ) ; if ( mViewWidth > 0 && mViewHeight > 0 ) { mDrawable = drawable ; // don ' t save until now so above is repeated until measured
if ( mDrawable != null ) { mDrawableWidth = mDrawable . getIntrinsicWidth ( ) ; mDrawableHeight = mDrawable . getIntrinsicHeight ( ) ; if ( mDrawableWidth > 0 && mDrawableHeight > 0 ) { // e . g . colors don ' t have size
float widthRatio = ( float ) mViewWidth / mDrawableWidth ; float heightRatio = ( float ) mViewHeight / mDrawableHeight ; mScale = widthRatio > heightRatio ? widthRatio : heightRatio ; } else { // nothing to scale , ensure matrix is skipped
mScale = 0.0f ; } } } else { // don ' t update matrix until View is measured
mScale = 0.0f ; } reset ( ) ; }


signature:
public class TranslateImagePageChangeListener { /** * Scale the image and translate it according to the pager position and offset . */
private void updateMatrix ( int position , float offset ) { } }

implementation:
if ( mDrawable != null && mScale > 0.0f ) { if ( mPageCount == - 1 && mAdapter != null ) { // cache page count and translation values
mPageCount = mAdapter . getCount ( ) ; if ( mPageCount > 1 ) { mPageX = ( mDrawableWidth * mScale - mViewWidth ) / ( mPageCount - 1 ) ; mPageY = ( mDrawableHeight * mScale - mViewHeight ) / ( mPageCount - 1 ) ; } } mMatrix . setTranslate ( - mPageX * position - mPageX * offset , - mPageY * position - mPageY * offset ) ; mMatrix . preScale ( mScale , mScale ) ; mView . setScaleType ( MATRIX ) ; mView . setImageMatrix ( mMatrix ) ; }


signature:
public class SQLiteContentProvider { /** * Update or delete records and get the number of rows affected . */
private int updDel ( int op , Uri uri , ContentValues vals , String sel , String [ ] args ) { } }

implementation:
/* get the IDs of records that will be affected */
Sql sql = elements ( op , uri , new String [ ] { "rowid" } , sel , args , null ) ; long [ ] ids = Cursors . allLongs ( sql . mResult ) ; /* update or delete the records and then notify about any changes */
SQLiteDatabase db = mHelper . getWritableDatabase ( ) ; int rows = op == UPDATE ? db . update ( sql . table ( ) , vals , sql . sel ( ) , sql . args ( ) ) : db . delete ( sql . table ( ) , ! TextUtils . isEmpty ( sql . sel ( ) ) ? sql . sel ( ) : "1" , sql . args ( ) ) ; if ( rows > 0 ) { for ( long id : ids ) { notifyChange ( ContentUris . withAppendedId ( sql . notifyUri ( ) , id ) , uri ) ; } } return rows ;


signature:
public class SQLiteContentProvider { /** * Notify observers of a change at notify URI . This will be a no - op if the original URI
 * specifies { @ link Content # NOTIFY _ CHANGE NOTIFY _ CHANGE } = false / 0 . The change will be synced
 * to the network if the { @ link Content # CALLER _ IS _ SYNCADAPTER caller is not a sync adapter } . */
@ SuppressWarnings ( "ConstantConditions" ) private void notifyChange ( Uri notify , Uri orig ) { } }

implementation: if ( orig . getBooleanQueryParameter ( NOTIFY_CHANGE , true ) ) { getContext ( ) . getContentResolver ( ) . notifyChange ( notify , null , ! orig . getBooleanQueryParameter ( CALLER_IS_SYNCADAPTER , false ) ) ; }


signature:
public class SQLiteContentProvider { /** * Get the updated SQL elements for the URI and , when not inserting , a cursor with the query
 * results . */
private Sql elements ( int op , Uri uri , String [ ] proj , String sel , String [ ] args , String order ) { } }

implementation:
MutableSql sql = translate ( uri ) ; if ( sql == null ) { sql = Sql . create ( ) ; } if ( sql . table ( ) == null ) { sql . table ( uri . getPathSegments ( ) . get ( 0 ) ) ; } if ( sql . notifyUri ( ) == null && op != SELECT ) { sql . notifyUri ( uri . buildUpon ( ) . path ( sql . table ( ) ) . clearQuery ( ) . fragment ( null ) . build ( ) ) ; } if ( op != INSERT ) { // run the query and return the cursor
String from = sql . join ( ) != null ? sql . table ( ) + ' ' + sql . join ( ) : sql . table ( ) ; if ( ( sql . sel ( ) == null || sql . args ( ) == null ) && uri . getPathSegments ( ) . size ( ) == 2 ) { try { // filter on ID if URI in / table / id format
long id = ContentUris . parseId ( uri ) ; if ( id > 0 ) { if ( sql . sel ( ) == null ) { sql . sel ( "rowid = ?" ) ; } if ( sql . args ( ) == null ) { sql . args ( String . valueOf ( id ) ) ; } } } catch ( NumberFormatException e ) { // last segment not a number
} } if ( sel != null ) { // append caller values
sql . sel ( DatabaseUtils . concatenateWhere ( sql . sel ( ) , sel ) ) ; } if ( args != null ) { sql . args ( DatabaseUtils . appendSelectionArgs ( sql . args ( ) , args ) ) ; } String groupBy = uri . getQueryParameter ( GROUP_BY ) ; if ( groupBy != null ) { // prefer caller ' s value
sql . groupBy ( groupBy ) ; } String having = uri . getQueryParameter ( HAVING ) ; if ( having != null ) { sql . having ( having ) ; } if ( order != null ) { sql . orderBy ( order ) ; } String limit = uri . getQueryParameter ( LIMIT ) ; if ( limit != null ) { sql . limit ( limit ) ; } sql . mResult = mHelper . getReadableDatabase ( ) . query ( from , proj , sql . sel ( ) , sql . args ( ) , sql . groupBy ( ) , sql . having ( ) , sql . orderBy ( ) , sql . limit ( ) ) ; } return sql ;


signature:
public class Bitmaps { /** * Get the number of bytes that would be used to store a bitmap with the size , in pixels , and
 * storage config . */
public static int getByteCount ( int width , int height , Config config ) { } }

implementation: int bytes = 0 ; switch ( config ) { case ALPHA_8 : bytes = 1 ; break ; case RGB_565 : bytes = 2 ; break ; case ARGB_4444 : bytes = 2 ; break ; case ARGB_8888 : bytes = 4 ; break ; } return width * height * bytes ;


signature:
public class Bitmaps { /** * If the bitmap is immutable , get a mutable copy of it . After a copy is created , the source
 * bitmap will be recycled . If the bitmap is already mutable , it will be returned .
 * @ return null if a copy could not be made */
@ Nullable public static Bitmap mutable ( Bitmap source ) { } }

implementation: if ( source . isMutable ( ) ) { return source ; } Config config = source . getConfig ( ) ; Bitmap bm = source . copy ( config != null ? config : ARGB_8888 , true ) ; if ( bm != null ) { source . recycle ( ) ; } return bm ;


signature:
public class Intents { /** * True if the Intent can be resolved to an Activity . */
public static boolean hasActivity ( Context context , Intent intent ) { } }

implementation: return context . getPackageManager ( ) . resolveActivity ( intent , MATCH_DEFAULT_ONLY ) != null ;


signature:
public class Intents { /** * Get an Activity Intent that launches an email app with the headers . Any null or empty
 * parameters are skipped . The subject and body will be encoded .
 * @ since 4.0.0 */
public static Intent mailto ( List < String > to , List < String > cc , List < String > bcc , String subject , String body ) { } }

implementation: return new Intent ( ACTION_SENDTO , Uris . mailto ( to , cc , bcc , subject , body ) ) ;


signature:
public class Intents { /** * Get an Activity Intent that launches a { @ link PlacePicker } . If the required version of
 * Google Play services is not available , an appropriate dialog will be shown and null will be
 * returned . You can listen for the dismissal of the dialog in
 * { @ link Activity # onActivityResult ( int , int , Intent ) onActivityResult } with requestCode
 * { @ code R . id . sprockets _ gmsError } .
 * @ since 4.0.0 */
@ Nullable public static Intent placePicker ( Activity a ) { } }

implementation: int errorCode ; try { return new PlacePicker . IntentBuilder ( ) . build ( a ) ; } catch ( GooglePlayServicesNotAvailableException e ) { errorCode = e . errorCode ; } catch ( GooglePlayServicesRepairableException e ) { errorCode = e . getConnectionStatusCode ( ) ; } GoogleApiAvailability . getInstance ( ) . showErrorDialogFragment ( a , errorCode , R . id . sprockets_gmsError ) ; return null ;


signature:
public class PanesActivity { /** * Use the default layout for the panes . */
public void setDefaultContentView ( ) { } }

implementation: setContentView ( R . layout . sprockets_panes , R . id . panes , R . id . pane1 , R . id . pane2 ) ;


signature:
public class PanesActivity { /** * Use your own layout for the panes .
 * @ param pagerId ViewPager in the single pane layout
 * @ param pane1Id first pane in the multi - pane layout
 * @ param pane2Id second pane in the multi - pane layout */
@ SuppressWarnings ( "ConstantConditions" ) public void setContentView ( @ LayoutRes int layoutId , @ IdRes int pagerId , @ IdRes int pane1Id , @ IdRes int pane2Id ) { } }

implementation:
setContentView ( layoutId ) ; Fragment pane1 = findFragmentByPane ( 1 ) ; Fragment pane2 = findFragmentByPane ( 2 ) ; ViewPager pager = ( ViewPager ) findViewById ( pagerId ) ; /* do we need to move the fragments between the single and multi - pane layouts ? */
FragmentManager fm = getFragmentManager ( ) ; FragmentTransaction ft = null ; if ( pane2 == null ) { pane2 = getFragment ( 2 ) ; } else if ( pane2 . getId ( ) != ( pager != null ? pagerId : pane2Id ) ) { ft = fm . beginTransaction ( ) . remove ( pane2 ) ; // remove in reverse to preserve indices
} if ( pane1 == null ) { pane1 = getFragment ( 1 ) ; } else if ( pane1 . getId ( ) != ( pager != null ? pagerId : pane1Id ) ) { if ( ft == null ) { ft = fm . beginTransaction ( ) ; } ft . remove ( pane1 ) ; } if ( ft != null ) { ft . commitAllowingStateLoss ( ) ; fm . executePendingTransactions ( ) ; // force removes so can add to a different container
} /* add the fragments to the panes */
if ( pager != null ) { pager . setAdapter ( new PanesAdapter ( pane1 , pane2 ) ) ; } else { ft = null ; if ( pane1 . getId ( ) != pane1Id ) { ft = Fragments . open ( this ) . add ( pane1Id , pane1 , PANE_1 ) ; } if ( pane2 . getId ( ) != pane2Id ) { if ( ft == null ) { ft = Fragments . open ( this ) ; } ft . add ( pane2Id , pane2 , PANE_2 ) ; } if ( ft != null ) { ft . commitAllowingStateLoss ( ) ; } }


signature:
public class PanesActivity { /** * Get the fragment that is displayed in the pane .
 * @ return null if a fragment hasn ' t been added to the pane yet */
@ Nullable @ SuppressWarnings ( "unchecked" ) public < T extends Fragment > T findFragmentByPane ( @ IntRange ( from = 1 , to = 2 ) int pane ) { } }

implementation: String tag = Elements . get ( sPanes , pane - 1 ) ; return tag != null ? ( T ) getFragmentManager ( ) . findFragmentByTag ( tag ) : null ;


signature:
public class SprocketsPreferenceFragment { /** * Display the preferences and log changes in analytics .
 * @ since 2.6.0 */
public static SprocketsPreferenceFragment newInstance ( @ XmlRes int prefs , boolean logChanges ) { } }

implementation: SprocketsPreferenceFragment frag = new SprocketsPreferenceFragment ( ) ; Bundle args = Fragments . arguments ( frag ) ; args . putInt ( PREFS , prefs ) ; args . putBoolean ( LOG_CHANGES , logChanges ) ; return frag ;


signature:
public class SprocketsPreferenceFragment { /** * Set the preference ' s value ( s ) as its summary . */
protected void setSummary ( Preference pref ) { } }

implementation:
SharedPreferences prefs = getPreferenceManager ( ) . getSharedPreferences ( ) ; if ( pref instanceof RingtonePreference ) { String val = prefs . getString ( pref . getKey ( ) , null ) ; if ( ! TextUtils . isEmpty ( val ) ) { Ringtone tone = RingtoneManager . getRingtone ( a , Uri . parse ( val ) ) ; if ( tone != null ) { pref . setSummary ( tone . getTitle ( a ) ) ; } } else { pref . setSummary ( R . string . none ) ; } } else if ( pref instanceof MultiSelectListPreference ) { Set < String > vals = prefs . getStringSet ( pref . getKey ( ) , null ) ; if ( vals != null ) { if ( ! vals . isEmpty ( ) ) { MultiSelectListPreference multi = ( MultiSelectListPreference ) pref ; ArrayIntList indexList = new ArrayIntList ( vals . size ( ) ) ; for ( String val : vals ) { // find selected entry indexes
int i = multi . findIndexOfValue ( val ) ; if ( i >= 0 ) { indexList . add ( i ) ; } } int [ ] indexes = indexList . toArray ( ) ; Arrays . sort ( indexes ) ; // to display in same order as dialog
pref . setSummary ( TextUtils . join ( getString ( R . string . delimiter ) , Elements . slice ( multi . getEntries ( ) , indexes ) ) ) ; } else { pref . setSummary ( R . string . none ) ; } } } else if ( pref instanceof EditTextPreference ) { pref . setSummary ( prefs . getString ( pref . getKey ( ) , null ) ) ; } else if ( pref . getClass ( ) . equals ( Preference . class ) ) { String val = prefs . getString ( pref . getKey ( ) , null ) ; if ( ! TextUtils . isEmpty ( val ) ) { // don ' t clear existing summary
pref . setSummary ( val ) ; } }


signature:
public class Bundles { /** * Get a Bundle of the key and value . */
public static Bundle of ( String key , int value ) { } }

implementation: Bundle b = new Bundle ( 1 ) ; b . putInt ( key , value ) ; return b ;


signature:
public class Bundles { /** * Get a Bundle of the keys and values . */
public static Bundle of ( String key1 , int value1 , String key2 , int value2 ) { } }

implementation: Bundle b = new Bundle ( 2 ) ; b . putInt ( key1 , value1 ) ; b . putInt ( key2 , value2 ) ; return b ;


signature:
public class Bundles { /** * Get a Bundle of the key and value . */
public static Bundle of ( String key , long value ) { } }

implementation: Bundle b = new Bundle ( 1 ) ; b . putLong ( key , value ) ; return b ;


signature:
public class Bundles { /** * Get a Bundle of the key and value . */
public static Bundle of ( String key , float value ) { } }

implementation: Bundle b = new Bundle ( 1 ) ; b . putFloat ( key , value ) ; return b ;


signature:
public class Bundles { /** * Get a Bundle of the key and value . */
public static Bundle of ( String key , String value ) { } }

implementation: Bundle b = new Bundle ( 1 ) ; b . putString ( key , value ) ; return b ;


signature:
public class ContentService { /** * Get an Intent to insert or update rows of the content .
 * @ param action must be { @ link Intent # ACTION _ INSERT ACTION _ INSERT } or
 * { @ link Intent # ACTION _ EDIT ACTION _ EDIT }
 * @ since 4.0.0 */
public static Intent newIntent ( Context context , String action , Uri data , ContentValues values ) { } }

implementation: return newIntent ( context , action , data , values , null , null ) ;


signature:
public class ContentService { /** * Get an Intent to update the selected rows of the content .
 * @ since 4.0.0 */
public static Intent newUpdateIntent ( Context context , Uri data , ContentValues values , String selection , String [ ] selectionArgs ) { } }

implementation: return newIntent ( context , ACTION_EDIT , data , values , selection , selectionArgs ) ;


signature:
public class ContentService { /** * Get an Intent to delete rows of the content .
 * @ since 4.0.0 */
public static Intent newDeleteIntent ( Context context , Uri data ) { } }

implementation: return newIntent ( context , ACTION_DELETE , data , null , null , null ) ;


signature:
public class ContentService { /** * Get an Intent to delete the selected rows of the content .
 * @ since 4.0.0 */
public static Intent newDeleteIntent ( Context context , Uri data , String selection , String [ ] selectionArgs ) { } }

implementation: return newIntent ( context , ACTION_DELETE , data , null , selection , selectionArgs ) ;


signature:
public class Themes { /** * Get the color specified by the attribute in the Context ' s theme .
 * @ since 4.0.0 */
public static int getColor ( Context context , @ AttrRes int attrId ) { } }

implementation: int color = 0 ; TypedArray a = context . obtainStyledAttributes ( new int [ ] { attrId } ) ; try { color = a . getColor ( 0 , 0 ) ; } catch ( UnsupportedOperationException e ) { error ( "color" , attrId , e ) ; } a . recycle ( ) ; return color ;


signature:
public class Themes { /** * Get the Drawable specified by the attribute in the Context ' s theme .
 * @ return null if the drawable does not exist
 * @ since 4.0.0 */
@ Nullable public static Drawable getDrawable ( Context context , @ AttrRes int attrId ) { } }

implementation: Drawable d = null ; TypedArray a = context . obtainStyledAttributes ( new int [ ] { attrId } ) ; try { d = a . getDrawable ( 0 ) ; } catch ( UnsupportedOperationException e ) { error ( "drawable" , attrId , e ) ; } a . recycle ( ) ; return d ;


signature:
public class Themes { /** * Get the ActionBar height in the Context ' s theme . */
public static int getActionBarSize ( Context context ) { } }

implementation: TypedArray a = context . obtainStyledAttributes ( sActionBarSize ) ; int size = a . getDimensionPixelSize ( 0 , 0 ) ; a . recycle ( ) ; return size ;


signature:
public class Themes { /** * Get the ActionBar background in the Context ' s theme .
 * @ return null if a background is not defined */
@ Nullable public static Drawable getActionBarBackground ( Context context ) { } }

implementation: int [ ] attrs = { android . R . attr . actionBarStyle } ; TypedArray a = context . obtainStyledAttributes ( attrs ) ; int id = a . getResourceId ( 0 , 0 ) ; a . recycle ( ) ; if ( id > 0 ) { attrs [ 0 ] = android . R . attr . background ; a = context . obtainStyledAttributes ( id , attrs ) ; Drawable background = a . getDrawable ( 0 ) ; a . recycle ( ) ; return background ; } return null ;


signature:
public class Network { /** * True if a data network is connected . */
public static boolean isConnected ( Context context ) { } }

implementation: NetworkInfo info = Managers . connectivity ( context ) . getActiveNetworkInfo ( ) ; return info != null && info . isConnected ( ) ;


signature:
public class DiffMatchPatch { /** * Reduce the number of edits by eliminating semantically trivial equalities .
 * @ param diffs LinkedList of Diff objects . */
public void diff_cleanupSemantic ( LinkedList < Diff > diffs ) { } }

implementation:
if ( diffs . isEmpty ( ) ) { return ; } boolean changes = false ; Stack < Diff > equalities = new Stack < Diff > ( ) ; // Stack of qualities .
String lastequality = null ; // Always equal to equalities . lastElement ( ) . text
ListIterator < Diff > pointer = diffs . listIterator ( ) ; // Number of characters that changed prior to the equality .
int length_insertions1 = 0 ; int length_deletions1 = 0 ; // Number of characters that changed after the equality .
int length_insertions2 = 0 ; int length_deletions2 = 0 ; Diff thisDiff = pointer . next ( ) ; while ( thisDiff != null ) { if ( thisDiff . operation == Operation . EQUAL ) { // Equality found .
equalities . push ( thisDiff ) ; length_insertions1 = length_insertions2 ; length_deletions1 = length_deletions2 ; length_insertions2 = 0 ; length_deletions2 = 0 ; lastequality = thisDiff . text ; } else { // An insertion or deletion .
if ( thisDiff . operation == Operation . INSERT ) { length_insertions2 += thisDiff . text . length ( ) ; } else { length_deletions2 += thisDiff . text . length ( ) ; } // Eliminate an equality that is smaller or equal to the edits on both
// sides of it .
if ( lastequality != null && ( lastequality . length ( ) <= Math . max ( length_insertions1 , length_deletions1 ) ) && ( lastequality . length ( ) <= Math . max ( length_insertions2 , length_deletions2 ) ) ) { // System . out . println ( " Splitting : ' " + lastequality + " ' " ) ;
// Walk back to offending equality .
while ( thisDiff != equalities . lastElement ( ) ) { thisDiff = pointer . previous ( ) ; } pointer . next ( ) ; // Replace equality with a delete .
pointer . set ( new Diff ( Operation . DELETE , lastequality ) ) ; // Insert a corresponding an insert .
pointer . add ( new Diff ( Operation . INSERT , lastequality ) ) ; equalities . pop ( ) ; // Throw away the equality we just deleted .
if ( ! equalities . empty ( ) ) { // Throw away the previous equality ( it needs to be reevaluated ) .
equalities . pop ( ) ; } if ( equalities . empty ( ) ) { // There are no previous equalities , walk back to the start .
while ( pointer . hasPrevious ( ) ) { pointer . previous ( ) ; } } else { // There is a safe equality we can fall back to .
thisDiff = equalities . lastElement ( ) ; while ( thisDiff != pointer . previous ( ) ) { // Intentionally empty loop .
} } length_insertions1 = 0 ; // Reset the counters .
length_insertions2 = 0 ; length_deletions1 = 0 ; length_deletions2 = 0 ; lastequality = null ; changes = true ; } } thisDiff = pointer . hasNext ( ) ? pointer . next ( ) : null ; } // Normalize the diff .
if ( changes ) { diff_cleanupMerge ( diffs ) ; } diff_cleanupSemanticLossless ( diffs ) ; // Find any overlaps between deletions and insertions .
// e . g : < del > abcxxx < / del > < ins > xxxdef < / ins >
// - > < del > abc < / del > xxx < ins > def < / ins >
// e . g : < del > xxxabc < / del > < ins > defxxx < / ins >
// - > < ins > def < / ins > xxx < del > abc < / del >
// Only extract an overlap if it is as big as the edit ahead or behind it .
pointer = diffs . listIterator ( ) ; Diff prevDiff = null ; thisDiff = null ; if ( pointer . hasNext ( ) ) { prevDiff = pointer . next ( ) ; if ( pointer . hasNext ( ) ) { thisDiff = pointer . next ( ) ; } } while ( thisDiff != null ) { if ( prevDiff . operation == Operation . DELETE && thisDiff . operation == Operation . INSERT ) { String deletion = prevDiff . text ; String insertion = thisDiff . text ; int overlap_length1 = this . diff_commonOverlap ( deletion , insertion ) ; int overlap_length2 = this . diff_commonOverlap ( insertion , deletion ) ; if ( overlap_length1 >= overlap_length2 ) { if ( overlap_length1 >= deletion . length ( ) / 2.0 || overlap_length1 >= insertion . length ( ) / 2.0 ) { // Overlap found . Insert an equality and trim the surrounding edits .
pointer . previous ( ) ; pointer . add ( new Diff ( Operation . EQUAL , insertion . substring ( 0 , overlap_length1 ) ) ) ; prevDiff . text = deletion . substring ( 0 , deletion . length ( ) - overlap_length1 ) ; thisDiff . text = insertion . substring ( overlap_length1 ) ; // pointer . add inserts the element before the cursor , so there is
// no need to step past the new element .
} } else { if ( overlap_length2 >= deletion . length ( ) / 2.0 || overlap_length2 >= insertion . length ( ) / 2.0 ) { // Reverse overlap found .
// Insert an equality and swap and trim the surrounding edits .
pointer . previous ( ) ; pointer . add ( new Diff ( Operation . EQUAL , deletion . substring ( 0 , overlap_length2 ) ) ) ; prevDiff . operation = Operation . INSERT ; prevDiff . text = insertion . substring ( 0 , insertion . length ( ) - overlap_length2 ) ; thisDiff . operation = Operation . DELETE ; thisDiff . text = deletion . substring ( overlap_length2 ) ; // pointer . add inserts the element before the cursor , so there is
// no need to step past the new element .
} } thisDiff = pointer . hasNext ( ) ? pointer . next ( ) : null ; } prevDiff = thisDiff ; thisDiff = pointer . hasNext ( ) ? pointer . next ( ) : null ; }


signature:
public class DiffMatchPatch { /** * Look for single edits surrounded on both sides by equalities
 * which can be shifted sideways to align the edit to a word boundary .
 * e . g : The c < ins > at c < / ins > ame . - > The < ins > cat < / ins > came .
 * @ param diffs LinkedList of Diff objects . */
public void diff_cleanupSemanticLossless ( LinkedList < Diff > diffs ) { } }

implementation:
String equality1 , edit , equality2 ; String commonString ; int commonOffset ; int score , bestScore ; String bestEquality1 , bestEdit , bestEquality2 ; // Create a new iterator at the start .
ListIterator < Diff > pointer = diffs . listIterator ( ) ; Diff prevDiff = pointer . hasNext ( ) ? pointer . next ( ) : null ; Diff thisDiff = pointer . hasNext ( ) ? pointer . next ( ) : null ; Diff nextDiff = pointer . hasNext ( ) ? pointer . next ( ) : null ; // Intentionally ignore the first and last element ( don ' t need checking ) .
while ( nextDiff != null ) { if ( prevDiff . operation == Operation . EQUAL && nextDiff . operation == Operation . EQUAL ) { // This is a single edit surrounded by equalities .
equality1 = prevDiff . text ; edit = thisDiff . text ; equality2 = nextDiff . text ; // First , shift the edit as far left as possible .
commonOffset = diff_commonSuffix ( equality1 , edit ) ; if ( commonOffset != 0 ) { commonString = edit . substring ( edit . length ( ) - commonOffset ) ; equality1 = equality1 . substring ( 0 , equality1 . length ( ) - commonOffset ) ; edit = commonString + edit . substring ( 0 , edit . length ( ) - commonOffset ) ; equality2 = commonString + equality2 ; } // Second , step character by character right , looking for the best fit .
bestEquality1 = equality1 ; bestEdit = edit ; bestEquality2 = equality2 ; bestScore = diff_cleanupSemanticScore ( equality1 , edit ) + diff_cleanupSemanticScore ( edit , equality2 ) ; while ( edit . length ( ) != 0 && equality2 . length ( ) != 0 && edit . charAt ( 0 ) == equality2 . charAt ( 0 ) ) { equality1 += edit . charAt ( 0 ) ; edit = edit . substring ( 1 ) + equality2 . charAt ( 0 ) ; equality2 = equality2 . substring ( 1 ) ; score = diff_cleanupSemanticScore ( equality1 , edit ) + diff_cleanupSemanticScore ( edit , equality2 ) ; // The > = encourages trailing rather than leading whitespace on edits .
if ( score >= bestScore ) { bestScore = score ; bestEquality1 = equality1 ; bestEdit = edit ; bestEquality2 = equality2 ; } } if ( ! prevDiff . text . equals ( bestEquality1 ) ) { // We have an improvement , save it back to the diff .
if ( bestEquality1 . length ( ) != 0 ) { prevDiff . text = bestEquality1 ; } else { pointer . previous ( ) ; // Walk past nextDiff .
pointer . previous ( ) ; // Walk past thisDiff .
pointer . previous ( ) ; // Walk past prevDiff .
pointer . remove ( ) ; // Delete prevDiff .
pointer . next ( ) ; // Walk past thisDiff .
pointer . next ( ) ; // Walk past nextDiff .
} thisDiff . text = bestEdit ; if ( bestEquality2 . length ( ) != 0 ) { nextDiff . text = bestEquality2 ; } else { pointer . remove ( ) ; // Delete nextDiff .
nextDiff = thisDiff ; thisDiff = prevDiff ; } } } prevDiff = thisDiff ; thisDiff = nextDiff ; nextDiff = pointer . hasNext ( ) ? pointer . next ( ) : null ; }


signature:
public class DiffMatchPatch { /** * Given two strings , compute a score representing whether the internal
 * boundary falls on logical boundaries .
 * Scores range from 6 ( best ) to 0 ( worst ) .
 * @ param one First string .
 * @ param two Second string .
 * @ return The score . */
private int diff_cleanupSemanticScore ( String one , String two ) { } }

implementation:
if ( one . length ( ) == 0 || two . length ( ) == 0 ) { // Edges are the best .
return 6 ; } // Each port of this function behaves slightly differently due to
// subtle differences in each language ' s definition of things like
// ' whitespace ' . Since this function ' s purpose is largely cosmetic ,
// the choice has been made to use each language ' s native features
// rather than force total conformity .
char char1 = one . charAt ( one . length ( ) - 1 ) ; char char2 = two . charAt ( 0 ) ; boolean nonAlphaNumeric1 = ! Character . isLetterOrDigit ( char1 ) ; boolean nonAlphaNumeric2 = ! Character . isLetterOrDigit ( char2 ) ; boolean whitespace1 = nonAlphaNumeric1 && Character . isWhitespace ( char1 ) ; boolean whitespace2 = nonAlphaNumeric2 && Character . isWhitespace ( char2 ) ; boolean lineBreak1 = whitespace1 && Character . getType ( char1 ) == Character . CONTROL ; boolean lineBreak2 = whitespace2 && Character . getType ( char2 ) == Character . CONTROL ; boolean blankLine1 = lineBreak1 && BLANKLINEEND . matcher ( one ) . find ( ) ; boolean blankLine2 = lineBreak2 && BLANKLINESTART . matcher ( two ) . find ( ) ; if ( blankLine1 || blankLine2 ) { // Five points for blank lines .
return 5 ; } else if ( lineBreak1 || lineBreak2 ) { // Four points for line breaks .
return 4 ; } else if ( nonAlphaNumeric1 && ! whitespace1 && whitespace2 ) { // Three points for end of sentences .
return 3 ; } else if ( whitespace1 || whitespace2 ) { // Two points for whitespace .
return 2 ; } else if ( nonAlphaNumeric1 || nonAlphaNumeric2 ) { // One point for non - alphanumeric .
return 1 ; } return 0 ;


signature:
public class DiffMatchPatch { /** * Reduce the number of edits by eliminating operationally trivial equalities .
 * @ param diffs LinkedList of Diff objects . */
public void diff_cleanupEfficiency ( LinkedList < Diff > diffs ) { } }

implementation:
if ( diffs . isEmpty ( ) ) { return ; } boolean changes = false ; Stack < Diff > equalities = new Stack < Diff > ( ) ; // Stack of equalities .
String lastequality = null ; // Always equal to equalities . lastElement ( ) . text
ListIterator < Diff > pointer = diffs . listIterator ( ) ; // Is there an insertion operation before the last equality .
boolean pre_ins = false ; // Is there a deletion operation before the last equality .
boolean pre_del = false ; // Is there an insertion operation after the last equality .
boolean post_ins = false ; // Is there a deletion operation after the last equality .
boolean post_del = false ; Diff thisDiff = pointer . next ( ) ; Diff safeDiff = thisDiff ; // The last Diff that is known to be unsplitable .
while ( thisDiff != null ) { if ( thisDiff . operation == Operation . EQUAL ) { // Equality found .
if ( thisDiff . text . length ( ) < Diff_EditCost && ( post_ins || post_del ) ) { // Candidate found .
equalities . push ( thisDiff ) ; pre_ins = post_ins ; pre_del = post_del ; lastequality = thisDiff . text ; } else { // Not a candidate , and can never become one .
equalities . clear ( ) ; lastequality = null ; safeDiff = thisDiff ; } post_ins = post_del = false ; } else { // An insertion or deletion .
if ( thisDiff . operation == Operation . DELETE ) { post_del = true ; } else { post_ins = true ; } /* * Five types to be split :
 * < ins > A < / ins > < del > B < / del > XY < ins > C < / ins > < del > D < / del >
 * < ins > A < / ins > X < ins > C < / ins > < del > D < / del >
 * < ins > A < / ins > < del > B < / del > X < ins > C < / ins >
 * < ins > A < / del > X < ins > C < / ins > < del > D < / del >
 * < ins > A < / ins > < del > B < / del > X < del > C < / del > */
if ( lastequality != null && ( ( pre_ins && pre_del && post_ins && post_del ) || ( ( lastequality . length ( ) < Diff_EditCost / 2 ) && ( ( pre_ins ? 1 : 0 ) + ( pre_del ? 1 : 0 ) + ( post_ins ? 1 : 0 ) + ( post_del ? 1 : 0 ) ) == 3 ) ) ) { // System . out . println ( " Splitting : ' " + lastequality + " ' " ) ;
// Walk back to offending equality .
while ( thisDiff != equalities . lastElement ( ) ) { thisDiff = pointer . previous ( ) ; } pointer . next ( ) ; // Replace equality with a delete .
pointer . set ( new Diff ( Operation . DELETE , lastequality ) ) ; // Insert a corresponding an insert .
pointer . add ( thisDiff = new Diff ( Operation . INSERT , lastequality ) ) ; equalities . pop ( ) ; // Throw away the equality we just deleted .
lastequality = null ; if ( pre_ins && pre_del ) { // No changes made which could affect previous entry , keep going .
post_ins = post_del = true ; equalities . clear ( ) ; safeDiff = thisDiff ; } else { if ( ! equalities . empty ( ) ) { // Throw away the previous equality ( it needs to be reevaluated ) .
equalities . pop ( ) ; } if ( equalities . empty ( ) ) { // There are no previous questionable equalities ,
// walk back to the last known safe diff .
thisDiff = safeDiff ; } else { // There is an equality we can fall back to .
thisDiff = equalities . lastElement ( ) ; } while ( thisDiff != pointer . previous ( ) ) { // Intentionally empty loop .
} post_ins = post_del = false ; } changes = true ; } } thisDiff = pointer . hasNext ( ) ? pointer . next ( ) : null ; } if ( changes ) { diff_cleanupMerge ( diffs ) ; }


signature:
public class DiffMatchPatch { /** * Locate the best instance of ' pattern ' in ' text ' near ' loc ' using the
 * Bitap algorithm . Returns - 1 if no match found .
 * @ param text The text to search .
 * @ param pattern The pattern to search for .
 * @ param loc The location to search around .
 * @ return Best match index or - 1. */
protected int match_bitap ( String text , String pattern , int loc ) { } }

implementation:
assert ( Match_MaxBits == 0 || pattern . length ( ) <= Match_MaxBits ) : "Pattern too long for this application." ; // Initialise the alphabet .
Map < Character , Integer > s = match_alphabet ( pattern ) ; // Highest score beyond which we give up .
double score_threshold = Match_Threshold ; // Is there a nearby exact match ? ( speedup )
int best_loc = text . indexOf ( pattern , loc ) ; if ( best_loc != - 1 ) { score_threshold = Math . min ( match_bitapScore ( 0 , best_loc , loc , pattern ) , score_threshold ) ; // What about in the other direction ? ( speedup )
best_loc = text . lastIndexOf ( pattern , loc + pattern . length ( ) ) ; if ( best_loc != - 1 ) { score_threshold = Math . min ( match_bitapScore ( 0 , best_loc , loc , pattern ) , score_threshold ) ; } } // Initialise the bit arrays .
int matchmask = 1 << ( pattern . length ( ) - 1 ) ; best_loc = - 1 ; int bin_min , bin_mid ; int bin_max = pattern . length ( ) + text . length ( ) ; // Empty initialization added to appease Java compiler .
int [ ] last_rd = new int [ 0 ] ; for ( int d = 0 ; d < pattern . length ( ) ; d ++ ) { // Scan for the best match ; each iteration allows for one more error .
// Run a binary search to determine how far from ' loc ' we can stray at
// this error level .
bin_min = 0 ; bin_mid = bin_max ; while ( bin_min < bin_mid ) { if ( match_bitapScore ( d , loc + bin_mid , loc , pattern ) <= score_threshold ) { bin_min = bin_mid ; } else { bin_max = bin_mid ; } bin_mid = ( bin_max - bin_min ) / 2 + bin_min ; } // Use the result from this iteration as the maximum for the next .
bin_max = bin_mid ; int start = Math . max ( 1 , loc - bin_mid + 1 ) ; int finish = Math . min ( loc + bin_mid , text . length ( ) ) + pattern . length ( ) ; int [ ] rd = new int [ finish + 2 ] ; rd [ finish + 1 ] = ( 1 << d ) - 1 ; for ( int j = finish ; j >= start ; j -- ) { int charMatch ; if ( text . length ( ) <= j - 1 || ! s . containsKey ( text . charAt ( j - 1 ) ) ) { // Out of range .
charMatch = 0 ; } else { charMatch = s . get ( text . charAt ( j - 1 ) ) ; } if ( d == 0 ) { // First pass : exact match .
rd [ j ] = ( ( rd [ j + 1 ] << 1 ) | 1 ) & charMatch ; } else { // Subsequent passes : fuzzy match .
rd [ j ] = ( ( ( rd [ j + 1 ] << 1 ) | 1 ) & charMatch ) | ( ( ( last_rd [ j + 1 ] | last_rd [ j ] ) << 1 ) | 1 ) | last_rd [ j + 1 ] ; } if ( ( rd [ j ] & matchmask ) != 0 ) { double score = match_bitapScore ( d , j - 1 , loc , pattern ) ; // This match will almost certainly be better than any existing
// match . But check anyway .
if ( score <= score_threshold ) { // Told you so .
score_threshold = score ; best_loc = j - 1 ; if ( best_loc > loc ) { // When passing loc , don ' t exceed our current distance from loc .
start = Math . max ( 1 , 2 * loc - best_loc ) ; } else { // Already passed loc , downhill from here on in .
break ; } } } } if ( match_bitapScore ( d + 1 , loc , loc , pattern ) > score_threshold ) { // No hope for a ( better ) match at greater error levels .
break ; } last_rd = rd ; } return best_loc ;


signature:
public class DiffMatchPatch { /** * Compute a list of patches to turn text1 into text2.
 * text2 is not provided , diffs are the delta between text1 and text2.
 * @ param text1 Old text .
 * @ param diffs Array of Diff objects for text1 to text2.
 * @ return LinkedList of Patch objects . */
public LinkedList < Patch > patch_make ( String text1 , LinkedList < Diff > diffs ) { } }

implementation:
if ( text1 == null || diffs == null ) { throw new IllegalArgumentException ( "Null inputs. (patch_make)" ) ; } LinkedList < Patch > patches = new LinkedList < Patch > ( ) ; if ( diffs . isEmpty ( ) ) { return patches ; // Get rid of the null case .
} Patch patch = new Patch ( ) ; int char_count1 = 0 ; // Number of characters into the text1 string .
int char_count2 = 0 ; // Number of characters into the text2 string .
// Start with text1 ( prepatch _ text ) and apply the diffs until we arrive at
// text2 ( postpatch _ text ) . We recreate the patches one by one to determine
// context info .
String prepatch_text = text1 ; String postpatch_text = text1 ; for ( Diff aDiff : diffs ) { if ( patch . diffs . isEmpty ( ) && aDiff . operation != Operation . EQUAL ) { // A new patch starts here .
patch . start1 = char_count1 ; patch . start2 = char_count2 ; } switch ( aDiff . operation ) { case INSERT : patch . diffs . add ( aDiff ) ; patch . length2 += aDiff . text . length ( ) ; postpatch_text = postpatch_text . substring ( 0 , char_count2 ) + aDiff . text + postpatch_text . substring ( char_count2 ) ; break ; case DELETE : patch . length1 += aDiff . text . length ( ) ; patch . diffs . add ( aDiff ) ; postpatch_text = postpatch_text . substring ( 0 , char_count2 ) + postpatch_text . substring ( char_count2 + aDiff . text . length ( ) ) ; break ; case EQUAL : if ( aDiff . text . length ( ) <= 2 * Patch_Margin && ! patch . diffs . isEmpty ( ) && aDiff != diffs . getLast ( ) ) { // Small equality inside a patch .
patch . diffs . add ( aDiff ) ; patch . length1 += aDiff . text . length ( ) ; patch . length2 += aDiff . text . length ( ) ; } if ( aDiff . text . length ( ) >= 2 * Patch_Margin ) { // Time for a new patch .
if ( ! patch . diffs . isEmpty ( ) ) { patch_addContext ( patch , prepatch_text ) ; patches . add ( patch ) ; patch = new Patch ( ) ; // Unlike Unidiff , our patch lists have a rolling context .
// http : / / code . google . com / p / google - diff - match - patch / wiki / Unidiff
// Update prepatch text & pos to reflect the application of the
// just completed patch .
prepatch_text = postpatch_text ; char_count1 = char_count2 ; } } break ; } // Update the current character count .
if ( aDiff . operation != Operation . INSERT ) { char_count1 += aDiff . text . length ( ) ; } if ( aDiff . operation != Operation . DELETE ) { char_count2 += aDiff . text . length ( ) ; } } // Pick up the leftover patch if not empty .
if ( ! patch . diffs . isEmpty ( ) ) { patch_addContext ( patch , prepatch_text ) ; patches . add ( patch ) ; } return patches ;


signature:
public class DiffMatchPatch { /** * Parse a textual representation of patches and return a List of Patch
 * objects .
 * @ param textline Text representation of patches .
 * @ return List of Patch objects .
 * @ throws IllegalArgumentException If invalid input . */
public List < Patch > patch_fromText ( String textline ) throws IllegalArgumentException { } }

implementation:
List < Patch > patches = new LinkedList < Patch > ( ) ; if ( textline . length ( ) == 0 ) { return patches ; } List < String > textList = Arrays . asList ( textline . split ( "\n" ) ) ; LinkedList < String > text = new LinkedList < String > ( textList ) ; Patch patch ; Pattern patchHeader = Pattern . compile ( "^@@ -(\\d+),?(\\d*) \\+(\\d+),?(\\d*) @@$" ) ; Matcher m ; char sign ; String line ; while ( ! text . isEmpty ( ) ) { m = patchHeader . matcher ( text . getFirst ( ) ) ; if ( ! m . matches ( ) ) { throw new IllegalArgumentException ( "Invalid patch string: " + text . getFirst ( ) ) ; } patch = new Patch ( ) ; patches . add ( patch ) ; patch . start1 = Integer . parseInt ( m . group ( 1 ) ) ; if ( m . group ( 2 ) . length ( ) == 0 ) { patch . start1 -- ; patch . length1 = 1 ; } else if ( m . group ( 2 ) . equals ( "0" ) ) { patch . length1 = 0 ; } else { patch . start1 -- ; patch . length1 = Integer . parseInt ( m . group ( 2 ) ) ; } patch . start2 = Integer . parseInt ( m . group ( 3 ) ) ; if ( m . group ( 4 ) . length ( ) == 0 ) { patch . start2 -- ; patch . length2 = 1 ; } else if ( m . group ( 4 ) . equals ( "0" ) ) { patch . length2 = 0 ; } else { patch . start2 -- ; patch . length2 = Integer . parseInt ( m . group ( 4 ) ) ; } text . removeFirst ( ) ; while ( ! text . isEmpty ( ) ) { try { sign = text . getFirst ( ) . charAt ( 0 ) ; } catch ( IndexOutOfBoundsException e ) { // Blank line ? Whatever .
text . removeFirst ( ) ; continue ; } line = text . getFirst ( ) . substring ( 1 ) ; line = line . replace ( "+" , "%2B" ) ; // decode would change all " + " to " "
try { line = URLDecoder . decode ( line , "UTF-8" ) ; } catch ( UnsupportedEncodingException e ) { // Not likely on modern system .
throw new Error ( "This system does not support UTF-8." , e ) ; } catch ( IllegalArgumentException e ) { // Malformed URI sequence .
throw new IllegalArgumentException ( "Illegal escape in patch_fromText: " + line , e ) ; } if ( sign == '-' ) { // Deletion .
patch . diffs . add ( new Diff ( Operation . DELETE , line ) ) ; } else if ( sign == '+' ) { // Insertion .
patch . diffs . add ( new Diff ( Operation . INSERT , line ) ) ; } else if ( sign == ' ' ) { // Minor equality .
patch . diffs . add ( new Diff ( Operation . EQUAL , line ) ) ; } else if ( sign == '@' ) { // Start of next patch .
break ; } else { // WTF ?
throw new IllegalArgumentException ( "Invalid patch mode '" + sign + "' in: " + line ) ; } text . removeFirst ( ) ; } } return patches ;


signature:
public class LeftProjection { /** * If this projection contains a { @ link Left } then a new { @ link Left } is returned containing the value from the original { @ link Right } mapped via the
 * provided function , else the contained Either is returned as is .
 * @ param < T >
 * The type to return as the new { @ link Left }
 * @ param function
 * The function
 * @ return Mapped Either
 * @ since 1.1 */
@ SuppressWarnings ( "unchecked" ) public < T > Either < T , R > map ( Function < L , T > function ) { } }

implementation: return either . isLeft ( ) ? Left ( function . apply ( get ( ) ) ) : ( Either < T , R > ) either ;


signature:
public class PromiseImpl { /** * ( non - Javadoc )
 * @ see javascalautils . concurrent . Promise # tryComplete ( javascalautils . Try ) */
@ Override public boolean tryComplete ( Try < T > result ) { } }

implementation: Validator . requireNonNull ( result , "Must provide a valid result" ) ; return tryComplete ( future -> future . complete ( result ) ) ;


signature:
public class PromiseImpl { /** * ( non - Javadoc )
 * @ see javascalautils . concurrent . Promise # tryCompleteWith ( javascalautils . concurrent . Future ) */
@ Override public boolean tryCompleteWith ( Future < T > result ) { } }

implementation: return tryComplete ( future -> result . onComplete ( response -> future . complete ( response ) ) ) ;


signature:
public class PromiseImpl { /** * Internal try complete method that takes a consumer to apply the Future this Promise holds . < br >
 * Performs a check if this Promise already has been fulfilled or not .
 * @ param c The consumer
 * @ return true if completed , false if already completed */
private boolean tryComplete ( Consumer < FutureImpl < T > > c ) { } }

implementation:
if ( completed . compareAndSet ( false , true ) ) { // This Try is only here to manage any unforeseen exception raised by the Future event listener
// See issue # 41
Try ( ( ) -> c . accept ( future ) ) ; return true ; } return false ;


signature:
public class Validator { /** * Checks that the specified object reference is not { @ code null } and throws a customized { @ link IllegalArgumentException } if it is . < br >
 * Essentially this is very much the same as { @ link Objects # requireNonNull ( Object , String ) } but throws an { @ link IllegalArgumentException } as opposed to the
 * { @ link NullPointerException } the SDK class throws .
 * @ param < T >
 * The type of the object
 * @ param obj
 * The object to be validated
 * @ param message
 * detail message to be used in the event that a { @ code IllegalArgumentException } is thrown
 * @ return The provided object in case it was non - null
 * @ throws IllegalArgumentException
 * If the provided object was < code > null < / code >
 * @ since 1.3 */
public static < T > T requireNonNull ( T obj , String message ) { } }

implementation: if ( obj == null ) { throw new IllegalArgumentException ( message ) ; } return obj ;


signature:
public class None { /** * Always returns < code > this < / code > . < br >
 * I . e . the function is never used as { @ link None } represents nothing / no value .
 * @ since 1.0 */
@ SuppressWarnings ( "unchecked" ) public < R > Option < R > map ( ThrowableFunction1 < T , R > function ) { } }

implementation: return ( Option < R > ) this ;


signature:
public class None { /** * Always returns < code > this < / code > . < br >
 * I . e . the function is never used as { @ link None } represents nothing / no value .
 * @ since 1.2
 * @ since 1.0 */
@ Override public < R > Option < R > flatMap ( ThrowableFunction1 < T , Option < R > > function ) { } }

implementation:
// uses the Map method as it anyways produces the same result
return map ( null ) ;


signature:
public class None { /** * Returns a { @ link Right } containing the value from the provided supplier .
 * @ since 1.4
 * @ since 1.0 */
@ Override public < R > Either < T , R > toLeft ( Supplier < R > right ) { } }

implementation: return Right ( right . get ( ) ) ;


signature:
public class None { /** * Returns a { @ link Left } containing the value from the provided supplier .
 * @ since 1.4
 * @ since 1.0 */
@ Override public < L > Either < L , T > toRight ( Supplier < L > left ) { } }

implementation: return Left ( left . get ( ) ) ;


signature:
public class FutureCompanion { /** * Allows for easy creation of asynchronous computations that will be executed in the future . < br >
 * The purpose is to allow the user to invoke a side - effecting function that may succeed / fail but has now return type . < br >
 * E . g . deleting something from a database may not have an interesting return type . One is only interested of the outcome , { @ link Success } / { @ link Failure } . < br >
 * The method relays the execution to { @ link Future # apply ( ThrowableFunction0 ) } . < br >
 * Best used in conjunction with statically importing this method .
 * < blockquote >
 * < pre >
 * import static javascalautils . concurrent . FutureCompanion . Future ;
 * Future & lt ; Unit & gt ; t = Future ( ( ) - & gt ; {
 * database . delete ( someId ) ;
 * < / pre >
 * < / blockquote >
 * @ param function
 * The function to render either the value < i > T < / i > or raise an exception .
 * @ return The future that will hold either { @ link Unit } or an exception .
 * @ since 1.9
 * @ see Future # apply ( ThrowableFunction0) */
public static Future < Unit > Future ( VoidFunction0 function ) { } }

implementation: return Future ( ( ) -> { function . apply ( ) ; return Unit . Instance ; } ) ;


signature:
public class FutureCompanion { /** * Allows for easy creation of asynchronous computations that will be executed in the future . < br >
 * The purpose is to allow the user to invoke a side - effecting function that may succeed / fail but has now return type . < br >
 * E . g . deleting something from a database may not have an interesting return type . One is only interested of the outcome , { @ link Success } / { @ link Failure } . < br >
 * The method relays the execution to { @ link Future # apply ( ThrowableFunction0 ) } . < br >
 * Best used in conjunction with statically importing this method .
 * < blockquote >
 * < pre >
 * import static javascalautils . concurrent . FutureCompanion . Future ;
 * Future & lt ; Unit & gt ; t = Future ( ( ) - & gt ; {
 * database . delete ( someId ) ;
 * } , someExecutor ) ;
 * < / pre >
 * < / blockquote >
 * @ param function
 * The function to render either the value < i > T < / i > or raise an exception .
 * @ param executor
 * The executor to use to compute / execute the Future holding the provided function
 * @ return The future that will hold either { @ link Unit } or an exception .
 * @ since 1.9
 * @ see Future # apply ( ThrowableFunction0) */
public static Future < Unit > Future ( VoidFunction0 function , Executor executor ) { } }

implementation: return Future ( ( ) -> { function . apply ( ) ; return Unit . Instance ; } , executor ) ;


signature:
public class FutureCompanion { /** * Allows for easy creation of asynchronous computations that will be executed in the future . < br >
 * The method relays the execution to { @ link Future # apply ( ThrowableFunction0 ) } . < br >
 * Best used in conjunction with statically importing this method .
 * < blockquote >
 * < pre >
 * import static javascalautils . concurrent . FutureCompanion . Future ;
 * Future & lt ; Integer & gt ; resultSuccess = Future ( ( ) - & gt ; 9 / 3 ) ; / / The Future will at some point contain : Success ( 3)
 * Future & lt ; Integer & gt ; resultFailure = Future ( ( ) - & gt ; 9 / 0 ) ; / / The Future will at some point contain : Failure ( ArithmeticException )
 * < / pre >
 * < / blockquote >
 * @ param < T >
 * The type for the Future
 * @ param function
 * The function to render either the value < i > T < / i > or raise an exception .
 * @ return The future that will hold the result provided by the function
 * @ since 1.3
 * @ see Future # apply ( ThrowableFunction0) */
public static < T > Future < T > Future ( ThrowableFunction0 < T > function ) { } }

implementation: return Future . apply ( function ) ;


signature:
public class FutureCompanion { /** * Allows for easy creation of asynchronous computations that will be executed in the future . < br >
 * The method relays the execution to { @ link Future # apply ( ThrowableFunction0 ) } . < br >
 * Best used in conjunction with statically importing this method .
 * < blockquote >
 * < pre >
 * import static javascalautils . concurrent . FutureCompanion . Future ;
 * Future & lt ; Integer & gt ; resultSuccess = Future ( ( ) - & gt ; 9 / 3 , someExecutor ) ; / / The Future will at some point contain : Success ( 3)
 * Future & lt ; Integer & gt ; resultFailure = Future ( ( ) - & gt ; 9 / 0 , someExecutor ) ; / / The Future will at some point contain : Failure ( ArithmeticException )
 * < / pre >
 * < / blockquote >
 * @ param < T >
 * The type for the Future
 * @ param function
 * The function to render either the value < i > T < / i > or raise an exception .
 * @ param executor
 * The executor to use to compute / execute the Future holding the provided function
 * @ return The future that will hold the result provided by the function
 * @ since 1.4
 * @ see Future # apply ( ThrowableFunction0 , Executor ) */
public static < T > Future < T > Future ( ThrowableFunction0 < T > function , Executor executor ) { } }

implementation: return Future . apply ( function , executor ) ;


signature:
public class FutureCompanion { /** * Allows for converting a blocking JDK { @ link java . util . concurrent . Future Future } into a non - blocking future . < br >
 * This will use the default executor to wait / block on the provided future .
 * @ param < T >
 * The type for the Future
 * @ param future
 * The blocking future
 * @ return The future that will hold the result provided by the future
 * @ since 1.5 */
public static < T > Future < T > Future ( java . util . concurrent . Future < T > future ) { } }

implementation: return Future . apply ( ( ) -> future . get ( ) ) ;


signature:
public class Executors { /** * Creates an executor that uses the { @ link java . util . concurrent . Executors # newCachedThreadPool ( ThreadFactory ) } .
 * @ param threadFactory
 * The thread factory to use .
 * @ return An instance of this Executor
 * @ since 1.2 */
public static Executor createCachedThreadPoolExecutor ( ThreadFactory threadFactory ) { } }

implementation: return create ( java . util . concurrent . Executors . newCachedThreadPool ( threadFactory ) ) ;


signature:
public class Executors { /** * Creates an executor that uses the { @ link java . util . concurrent . Executors # newFixedThreadPool ( int , ThreadFactory ) }
 * @ param threads
 * The amount of threads to allow in the thread pool
 * @ param threadFactory
 * The thread factory to use .
 * @ return An instance of this Executor
 * @ since 1.2 */
public static Executor createFixedThreadPoolExecutor ( int threads , ThreadFactory threadFactory ) { } }

implementation: return create ( java . util . concurrent . Executors . newFixedThreadPool ( threads , threadFactory ) ) ;


signature:
public class Executors { /** * Creates the default { @ link Executor } instance . < br >
 * Either by getting the provider class from the system property or using the default .
 * @ return The created executor */
private static Executor createDefaultExecutor ( ) { } }

implementation: Try < Executor > t = ReflectionUtil . newInstance ( System . getProperty ( "javascalautils.concurrent.executorprovider" ) ) ; return t . getOrElse ( ( ) -> createCachedThreadPoolExecutor ( new NamedSequenceThreadFactory ( "Executors-Default" ) ) ) ;


signature:
public class FutureImpl { /** * ( non - Javadoc )
 * @ see javascalautils . concurrent . Future # onFailure ( java . util . function . Consumer ) */
@ Override public void onFailure ( Consumer < Throwable > consumer ) { } }

implementation:
Validator . requireNonNull ( consumer , "Null is not a valid consumer" ) ; // register a complete handler and ignore any Success responses
onComplete ( result -> { // transform Failure to a Success with the Throwable
// should it be a Success it will be transformed into a Failure and forEach will do nothing
result . failed ( ) . forEach ( consumer ) ; } ) ;


signature:
public class FutureImpl { /** * ( non - Javadoc )
 * @ see javascalautils . concurrent . Future # onSuccess ( java . util . function . Consumer ) */
@ Override public void onSuccess ( Consumer < T > consumer ) { } }

implementation:
Validator . requireNonNull ( consumer , "Null is not a valid consumer" ) ; // register a complete handler and ignore any Failure responses
onComplete ( result -> { // should it be a Failure the forEach will do nothing
result . forEach ( consumer ) ; } ) ;


signature:
public class FutureImpl { /** * ( non - Javadoc )
 * @ see javascalautils . concurrent . Future # onComplete ( java . util . function . Consumer ) */
@ Override public void onComplete ( Consumer < Try < T > > c ) { } }

implementation:
Validator . requireNonNull ( c , "Null is not a valid consumer" ) ; eventHandlers . add ( new EventHandler ( c ) ) ; // invoke all new handlers in case this Future is already completed
notifyHandlers ( ) ;


signature:
public class FutureImpl { /** * ( non - Javadoc )
 * @ see javascalautils . concurrent . Future # map ( java . util . function . Function ) */
@ Override public < R > Future < R > map ( ThrowableFunction1 < T , R > function ) { } }

implementation:
// the onFailure function just passed the error as - is without transformation
return transform ( function , t -> t ) ;


signature:
public class FutureImpl { /** * ( non - Javadoc )
 * @ see javascalautils . concurrent . Future # flatMap ( java . util . function . Function ) */
@ Override public < R > Future < R > flatMap ( ThrowableFunction1 < T , Future < R > > function ) { } }

implementation:
Validator . requireNonNull ( function , "Null is not a valid function" ) ; // Create new future expected to hold the value of the mapped type
FutureImpl < R > future = new FutureImpl < > ( ) ; // install success handler that will map the result before applying it
onSuccess ( value -> { // use the provided function to create a mapped future
// it might actually fail due to the provided function throws an exception , hence we wrap it with a Try
Try < Future < R > > mapped = Try ( ( ) -> function . apply ( value ) ) ; // add a recover function to the Try that fails this future with the error , else we complete this Future with the mapped Future
mapped . recover ( t -> Future . failed ( t ) ) . forEach ( f -> f . onComplete ( v -> future . complete ( v ) ) ) ; } ) ; // install failure handler that just passes the failure / result through
onFailure ( t -> future . failure ( t ) ) ; return future ;


signature:
public class FutureImpl { /** * ( non - Javadoc )
 * @ see javascalautils . concurrent . Future # filter ( java . util . function . Predicate ) */
@ Override public Future < T > filter ( Predicate < T > predicate ) { } }

implementation:
Validator . requireNonNull ( predicate , "Null is not a valid predicate" ) ; // Create new future expected to hold the value of the mapped type
FutureImpl < T > future = new FutureImpl < > ( ) ; // install success handler that will filter the result before applying it
onSuccess ( value -> { if ( predicate . test ( value ) ) { future . success ( value ) ; } else { future . failure ( new NoSuchElementException ( "The predicate failed on value [" + value + "]" ) ) ; } } ) ; // install failure handler that just passes the result through
onFailure ( t -> future . failure ( t ) ) ; return future ;


signature:
public class FutureImpl { /** * ( non - Javadoc )
 * @ see javascalautils . concurrent . Future # transform ( java . util . function . Function , java . util . function . Function ) */
@ Override public < R > Future < R > transform ( ThrowableFunction1 < T , R > onSuccess , ThrowableFunction1 < Throwable , Throwable > onFailure ) { } }

implementation:
Validator . requireNonNull ( onSuccess , "Null is not a valid function" ) ; Validator . requireNonNull ( onFailure , "Null is not a valid function" ) ; // Create new future expected to hold the value of the mapped type
FutureImpl < R > future = new FutureImpl < > ( ) ; // install success handler that will map the result before applying it
onSuccess ( value -> future . complete ( Try ( ( ) -> onSuccess . apply ( value ) ) ) ) ; // install failure handler that will map the error before applying it
onFailure ( t -> Try ( ( ) -> onFailure . apply ( t ) ) . recover ( ex -> ex ) . forEach ( ex -> future . failure ( ex ) ) ) ; return future ;


signature:
public class FutureImpl { /** * ( non - Javadoc )
 * @ see javascalautils . concurrent . Future # recover ( java . util . function . Function ) */
@ Override public Future < T > recover ( ThrowableFunction1 < Throwable , T > recoverFunction ) { } }

implementation:
Validator . requireNonNull ( recoverFunction , "Null is not a valid function" ) ; // Create new future expected to hold the value of the mapped type
FutureImpl < T > future = new FutureImpl < > ( ) ; // installs a handler that will automatically recover the result / Try should it be needed
onComplete ( t -> future . complete ( t . recover ( recoverFunction ) ) ) ; return future ;


signature:
public class FutureImpl { /** * ( non - Javadoc )
 * @ see javascalautils . concurrent . Future # result ( long , java . util . concurrent . TimeUnit ) */
@ Override public T result ( long duration , TimeUnit timeUnit ) throws Throwable , TimeoutException { } }

implementation:
// The response is now set to Some
// return the value of the response ( Try ) , should it be a Failure the exception is raised
return ready ( duration , timeUnit ) . response . get ( ) . get ( ) ;


signature:
public class FutureImpl { /** * / * ( non - Javadoc )
 * @ see javascalautils . concurrent . Future # ready ( long , java . util . concurrent . TimeUnit ) */
@ Override public FutureImpl < T > ready ( long duration , TimeUnit timeUnit ) throws TimeoutException , InterruptedException { } }

implementation:
Validator . requireNonNull ( timeUnit , "Null is not a valid time unit" ) ; CountDownLatch latch = new CountDownLatch ( 1 ) ; // install a handler that releases the count down latch when notified with a result .
// the actual result / response is of no interest as we anyways have access to it internally in this class / instance .
onComplete ( t -> latch . countDown ( ) ) ; // block for either the time to pass or the Future gets completed
if ( ! latch . await ( duration , timeUnit ) ) { throw new TimeoutException ( "Timeout waiting [" + duration + "] [" + timeUnit + "] for Future to complete" ) ; } // The future is now complete , return ourselves
return this ;


signature:
public class FutureImpl { /** * Completes this Future with a result . < br >
 * Invoked by the Promise owning this instance .
 * @ param result The result to complete with
 * @ return Returns itself */
Future < T > complete ( Try < T > result ) { } }

implementation:
// save the result
this . response = Some ( result ) ; // notify all potential handlers
notifyHandlers ( ) ; return this ;


signature:
public class FutureImpl { /** * Invoke all handlers with the value of this Future . < br >
 * The response may or may not exist at this point . < br >
 * A filter is applied to make sure we only notify handlers that have not been notified before . */
private < R > void notifyHandlers ( ) { } }

implementation:
// the response may or may not exist at this point
response . forEach ( t -> eventHandlers . stream ( ) . forEach ( h -> h . notify ( t ) ) ) ;


signature:
public class Some { /** * Returns an { @ link Option } containing the value of applying the given function to the current value .
 * @ since 1.0 */
@ Override public < R > Option < R > map ( ThrowableFunction1 < T , R > f ) { } }

implementation: return flatMap ( v -> Option . apply ( f . apply ( v ) ) ) ;


signature:
public class Some { /** * Returns an Option consisting of the result of applying the given function to the current value .
 * @ since 1.2 */
@ Override public < R > Option < R > flatMap ( ThrowableFunction1 < T , Option < R > > function ) { } }

implementation: try { return function . apply ( value ) ; } catch ( Throwable ex ) { throw new BrokenFunctionException ( "Caught exception while applying function" , ex ) ; }


signature:
public class Some { /** * Returns a { @ link Left } containing the value of this instance .
 * @ since 1.4 */
@ Override public < R > Either < T , R > toLeft ( Supplier < R > right ) { } }

implementation: return Left ( value ) ;


signature:
public class Some { /** * Returns a { @ link Right } containing the value of this instance .
 * @ since 1.4 */
@ Override public < L > Either < L , T > toRight ( Supplier < L > left ) { } }

implementation: return Right ( value ) ;


signature:
public class NamedSequenceThreadFactory { /** * Creates a new thread using the provided name and sequence counter . < br >
 * E . g . < i > threadName - nnn < / i >
 * @ since 1.2 */
@ Override public Thread newThread ( Runnable runnable ) { } }

implementation: return new Thread ( runnable , threadName + "-" + counter . getAndIncrement ( ) ) ;


signature:
public class RightProjection { /** * Returns the value if this is a { @ link Right } else the value provided by the supplier .
 * @ param supplier
 * The supplier
 * @ return The value
 * @ since 1.1 */
@ Override public R getOrElse ( Supplier < R > supplier ) { } }

implementation: return either . fold ( v -> supplier . get ( ) , v -> v ) ;


signature:
public class RightProjection { /** * Returns a { @ link Some } wrapping the { @ link Either } if it ' s a { @ link Right } and the value of the { @ link Right } matches the predicate , else { @ link None } .
 * @ param predicate
 * The predicate to apply
 * @ return The resulting Option of the filter operation
 * @ since 1.1 */
public Option < Either < L , R > > filter ( Predicate < R > predicate ) { } }

implementation: return Option . apply ( exists ( predicate ) ? either : null ) ;


signature:
public class RightProjection { /** * If this projection contains a { @ link Right } then a new { @ link Right } is returned containing the value from the original { @ link Right } mapped via the
 * provided function , else the contained Either is returned as is .
 * @ param < T >
 * The type to return as the new { @ link Right }
 * @ param function
 * The function
 * @ return Mapped Either
 * @ since 1.1 */
@ SuppressWarnings ( "unchecked" ) public < T > Either < L , T > map ( Function < R , T > function ) { } }

implementation: return either . isRight ( ) ? Right ( function . apply ( get ( ) ) ) : ( Either < L , T > ) either ;


signature:
public class Failure { /** * Always returns the value provided by the supplier . < br >
 * As per definition this is a failure without any data to return .
 * @ since 1.0 */
@ Override public Try < T > orElse ( Supplier < Try < T > > supplier ) { } }

implementation: return supplier . get ( ) ;


signature:
public class Failure { /** * Always returns < i > this < / i > . < br >
 * As per definition this is a failure without any data to map .
 * @ since 1.0 */
@ SuppressWarnings ( "unchecked" ) @ Override public < R > Try < R > map ( ThrowableFunction1 < T , R > function ) { } }

implementation: return ( Try < R > ) this ;


signature:
public class Failure { /** * Applies the provided function to the Throwable of this { @ link Failure } and returns a { @ link Success } with the result .
 * @ since 1.4 */
@ Override public Try < T > recover ( ThrowableFunction1 < Throwable , T > function ) { } }

implementation: return recoverWith ( t -> Success ( function . apply ( t ) ) ) ;


signature:
public class Failure { /** * Applies the provided function to the Throwable of this { @ link Failure } and returns the result .
 * @ since 1.4 */
@ Override public Try < T > recoverWith ( ThrowableFunction1 < Throwable , Try < T > > function ) { } }

implementation: try { return function . apply ( throwable ) ; } catch ( Throwable t ) { return new Failure < > ( t ) ; }


signature:
public class TryCompanion { /** * Creates an instance of { @ link Try } with a { @ link Unit } return type . < br >
 * The purpose is to allow the user to invoke a side - effecting function that may succeed / fail but has now return type . < br >
 * E . g . deleting something from a database may not have an interesting return type . One is only interested of the outcome , { @ link Success } / { @ link Failure } .
 * Best used in conjunction with statically importing this method .
 * < blockquote >
 * < pre >
 * import static javascalautils . TryCompanion . Try ;
 * Try & lt ; Unit & gt ; t = Try ( ( ) - & gt ; {
 * database . delete ( someId ) ;
 * < / pre >
 * < / blockquote >
 * @ param function
 * The function to render either the value < i > T < / i > or raise an exception .
 * @ return The resulting Try instance wrapping either { @ link Unit } or an exception
 * @ since 1.9 */
public static Try < Unit > Try ( VoidFunction0 function ) { } }

implementation: return Try . apply ( ( ) -> { function . apply ( ) ; return Unit . Instance ; } ) ;


signature:
public class TryCompanion { /** * Creates an instance of { @ link Try } wrapping the result of the provided function . < br >
 * Best used in conjunction with statically importing this method .
 * < blockquote >
 * < pre >
 * import static javascalautils . TryCompanion . Try ;
 * Try & lt ; Integer & gt ; t = Try ( ( ) - & gt ; 9 / 3 ) ;
 * < / pre >
 * < / blockquote >
 * @ param < T >
 * The type for the Try
 * @ param function
 * The function to render either the value < i > T < / i > or raise an exception .
 * @ return The resulting Try instance wrapping what the function resulted in
 * @ see Try # apply ( ThrowableFunction0)
 * @ since 1.3 */
public static < T > Try < T > Try ( ThrowableFunction0 < T > function ) { } }

implementation: return Try . apply ( function ) ;


signature:
public class ReflectionUtil { /** * Attempts to create an instance of the provided class . < br >
 * This expects the class to be public and have a public ( default ) constructor with no arguments .
 * @ param < T >
 * The expected to be returned by this method
 * @ param className
 * The name of the class
 * @ return The result , either { @ link Success Success ( T ) } with the instance or { @ link Failure Failure ( Throwable ) } in case of failure
 * @ since 1.4 */
@ SuppressWarnings ( "unchecked" ) static < T > Try < T > newInstance ( String className ) { } }

implementation: return Try ( ( ) -> ( T ) Class . forName ( className ) . newInstance ( ) ) ;


signature:
public class ExecutorImpl { /** * ( non - Javadoc )
 * @ see com . ericsson . concurrent . Executor # execute ( com . ericsson . concurrent . Executable ) */
@ Override public < T > Future < T > execute ( final Executable < T > executable ) { } }

implementation:
final Promise < T > promise = Promise ( ) ; return execute ( promise , ( ) -> { try { executable . execute ( promise ) ; // if the implementation didn ' t respond to the Promise we mark it as a failure .
if ( ! promise . isCompleted ( ) ) { promise . failure ( new IllegalStateException ( "No response was provided by the Promise" ) ) ; } } catch ( Exception ex ) { promise . failure ( ex ) ; } } ) ;


signature:
public class ExecutorImpl { /** * ( non - Javadoc )
 * @ see com . ericsson . concurrent . Executor # execute ( java . util . concurrent . Callable ) */
@ Override public < T > Future < T > execute ( final Callable < T > callable ) { } }

implementation: final Promise < T > promise = Promise ( ) ; return execute ( promise , ( ) -> { try { promise . success ( callable . call ( ) ) ; } catch ( Exception ex ) { promise . failure ( ex ) ; } } ) ;


signature:
public class ExecutorImpl { /** * ( non - Javadoc )
 * @ see com . ericsson . concurrent . Executor # executeAll ( com . ericsson . concurrent . Executable < T > [ ] ) */
@ Override public < T > List < Future < T > > executeAll ( @ SuppressWarnings ( "unchecked" ) Executable < T > ... executables ) { } }

implementation: List < Future < T > > responses = new ArrayList < > ( ) ; for ( Executable < T > executable : executables ) { responses . add ( execute ( executable ) ) ; } return responses ;


signature:
public class ExecutorImpl { /** * ( non - Javadoc )
 * @ see com . ericsson . concurrent . Executor # executeAll ( java . util . concurrent . Callable < T > [ ] ) */
@ Override public < T > List < Future < T > > executeAll ( @ SuppressWarnings ( "unchecked" ) Callable < T > ... callables ) { } }

implementation: List < Future < T > > responses = new ArrayList < > ( ) ; for ( Callable < T > callable : callables ) { responses . add ( execute ( callable ) ) ; } return responses ;


signature:
public class ExecutorImpl { /** * Executes the provided { @ link Runnable } on the internal executor . < br >
 * Any issues related to the internal executor are reported to the provided { @ link Promise }
 * @ param promise
 * The promise to fulfill once the work is finished
 * @ param runnable
 * The runnable to execute in the executor
 * @ return The Future holding the response - to - be */
private < T > Future < T > execute ( Promise < T > promise , Runnable runnable ) { } }

implementation:
try { executor . execute ( runnable ) ; } catch ( RejectedExecutionException ex ) { // could be rejected due to resource starvation , report a failure
promise . failure ( ex ) ; } return promise . future ( ) ;


signature:
public class Success { /** * Applies the value to the function and returns the { @ link Try } representing the mapped value .
 * @ since 1.0 */
@ Override public < R > Try < R > map ( ThrowableFunction1 < T , R > function ) { } }

implementation: return Try ( ( ) -> function . apply ( value ) ) ;


signature:
public class Success { /** * Applies the value to the function and returns the { @ link Try } generated by the function .
 * @ since 1.2 */
@ Override public < R > Try < R > flatMap ( ThrowableFunction1 < T , Try < R > > function ) { } }

implementation: try { return function . apply ( value ) ; } catch ( Throwable t ) { return new Failure < > ( t ) ; }


signature:
public class Success { /** * Applies the predicate to the value of this instance , if it matches < i > this < / i > is returned else a { @ link Failure } .
 * @ since 1.4 */
@ Override public Try < T > filter ( Predicate < T > predicate ) { } }

implementation: return predicate . test ( value ) ? this : new Failure < > ( new NoSuchElementException ( "Predicate did not match value, now empty result" ) ) ;


signature:
public class Right { /** * Applies the provided < code > func _ right < / code > to the wrapped value and returns the result .
 * @ since 1.1 */
@ Override public < T > T fold ( Function < L , T > func_left , Function < R , T > func_right ) { } }

implementation: return func_right . apply ( value ) ;


signature:
public class AbstractTraceeErrorLoggingHandler { /** * Converts a SOAPMessage instance to string representation . */
String convertSoapMessageAsString ( SOAPMessage soapMessage ) { } }

implementation: if ( soapMessage == null ) { return "null" ; } try { ByteArrayOutputStream os = new ByteArrayOutputStream ( ) ; soapMessage . writeTo ( os ) ; return new String ( os . toByteArray ( ) , determineMessageEncoding ( soapMessage ) ) ; } catch ( Exception e ) { logger . error ( "Couldn't create string representation of soapMessage: " + soapMessage . toString ( ) ) ; return "ERROR" ; }


signature:
public class MethodAnnotationPair { /** * Determines if a method should be processed . This will either be if no
 * { @ link io . tracee . contextlogger . contextprovider . api . TraceeContextProviderMethod } annotation
 * is present or if an empty property name is defined in the annotation or if passed profileSettings are null
 * or if the property name is disabled in the { @ link io . tracee . contextlogger . profile . ProfileSettings } .
 * @ param profileSettings The profile sttings object which should be used to check against .
 * @ return true if the result of the method should be processed , otherwise false . */
public boolean shouldBeProcessed ( final ProfileSettings profileSettings ) { } }

implementation: if ( profileSettings != null ) { String propertyName = GetterUtilities . getFullQualifiedFieldName ( baseType , method ) ; Boolean shouldBeProcessed = profileSettings . getPropertyValue ( propertyName ) ; if ( shouldBeProcessed == null ) { propertyName = baseType . getCanonicalName ( ) + "." + method . getName ( ) ; shouldBeProcessed = profileSettings . getPropertyValue ( propertyName ) ; } if ( shouldBeProcessed == null && annotation != null ) { shouldBeProcessed = annotation . enabledPerDefault ( ) ; } if ( shouldBeProcessed != null ) { return shouldBeProcessed ; } } return true ;


signature:
public class IsTraceeContextProviderPredicate { /** * Checks whether the passed instance type is annotated with the { @ link io . tracee . contextlogger . contextprovider . api . TraceeContextProvider } annotation .
 * @ param instance the instance to check
 * @ return true , if the passed instance ' s type is annotated with the { @ link io . tracee . contextlogger . contextprovider . api . TraceeContextProvider } annotation ,
 * otherwise false */
protected boolean hasTraceeContextProviderAnnotation ( final Object instance ) { } }

implementation: if ( instance == null ) { return false ; } TraceeContextProvider annotation = TraceeContextLogAnnotationUtilities . getAnnotationFromType ( instance ) ; return annotation != null ;


signature:
public class IsTraceeContextProviderPredicate { /** * Checks whether the passed instance extends the { @ link ImplicitContextData } or
 * { @ link io . tracee . contextlogger . contextprovider . api . WrappedContextData } types .
 * @ param instance the instance to check
 * @ return true , if the passed instance ' s type extends the ImplicitContextData or WrappedContextData class */
protected boolean isExtendingTraceeContextProvider ( final Object instance ) { } }

implementation: if ( instance == null ) { return false ; } return ImplicitContextData . class . isAssignableFrom ( instance . getClass ( ) ) || WrappedContextData . class . isAssignableFrom ( instance . getClass ( ) ) ;


signature:
public class ListUtilities { /** * Checks if passed instance is of type { @ link java . util . List } and contains elements of the passed type .
 * Warning : Only the first element of the list will be checked
 * @ param instance
 * @ param type
 * @ return */
public static boolean isListOfType ( Object instance , Class type ) { } }

implementation:
if ( instance == null || type == null ) { return false ; } if ( List . class . isAssignableFrom ( instance . getClass ( ) ) ) { // check whether the list is empty or the first instance is of passed type
List list = ( List ) instance ; boolean isEmpty = list . size ( ) == 0 ; for ( Object element : list ) { if ( element != null && ! type . isAssignableFrom ( element . getClass ( ) ) ) { return false ; } } return true ; } return false ;