idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
24,200
private BigDecimal parseNumber ( final NumberBuffer buffer ) { BigDecimal sum = BigDecimal . ZERO ; BigDecimal result = parseLargePair ( buffer ) ; if ( result == null ) { return null ; } while ( result != null ) { sum = sum . add ( result ) ; result = parseLargePair ( buffer ) ; } return sum ; }
Parses a Japanese number
80
6
24,201
public boolean isNumeralPunctuation ( final String input ) { for ( int i = 0 ; i < input . length ( ) ; i ++ ) { if ( ! isNumeralPunctuation ( input . charAt ( i ) ) ) { return false ; } } return true ; }
Numeral punctuation predicate
62
5
24,202
public void adaptHeightToChildren ( ) { DividableGridAdapter adapter = ( DividableGridAdapter ) getAdapter ( ) ; if ( adapter != null ) { int height = getPaddingTop ( ) + getPaddingBottom ( ) ; for ( int i = 0 ; i < adapter . getCount ( ) ; i += adapter . getColumnCount ( ) ) { AbstractItem item = adapter . getItem ( i ) ; if ( item instanceof Divider ) { height += getResources ( ) . getDimensionPixelSize ( TextUtils . isEmpty ( item . getTitle ( ) ) ? R . dimen . bottom_sheet_divider_height : R . dimen . bottom_sheet_divider_title_height ) ; } else { height += getResources ( ) . getDimensionPixelSize ( adapter . getStyle ( ) == BottomSheet . Style . GRID ? R . dimen . bottom_sheet_grid_item_size : R . dimen . bottom_sheet_list_item_height ) ; } } ViewGroup . LayoutParams params = getLayoutParams ( ) ; params . height = height ; setLayoutParams ( params ) ; requestLayout ( ) ; } }
Adapts the height of the grid view to the height of its children .
260
15
24,203
private List < AbstractItem > getRawItems ( ) { if ( rawItems == null ) { rawItems = new ArrayList <> ( ) ; for ( int i = 0 ; i < items . size ( ) ; i ++ ) { AbstractItem item = items . get ( i ) ; if ( item instanceof Divider && columnCount > 1 ) { for ( int j = 0 ; j < rawItems . size ( ) % columnCount ; j ++ ) { rawItems . add ( null ) ; } rawItems . add ( item ) ; for ( int j = 0 ; j < columnCount - 1 ; j ++ ) { rawItems . add ( new Divider ( ) ) ; } } else { rawItems . add ( item ) ; } } } return rawItems ; }
Returns a list which contains the items of the adapter including placeholders .
165
14
24,204
private View inflateItemView ( @ Nullable final ViewGroup parent ) { LayoutInflater layoutInflater = LayoutInflater . from ( context ) ; View view = layoutInflater . inflate ( style == Style . GRID ? R . layout . grid_item : R . layout . list_item , parent , false ) ; ItemViewHolder viewHolder = new ItemViewHolder ( ) ; viewHolder . iconImageView = view . findViewById ( android . R . id . icon ) ; viewHolder . titleTextView = view . findViewById ( android . R . id . title ) ; view . setTag ( viewHolder ) ; return view ; }
Inflates the view which is used to visualize an item .
150
13
24,205
@ SuppressWarnings ( "PrimitiveArrayArgumentToVariableArgMethod" ) private void visualizeItem ( @ NonNull final Item item , @ NonNull final ItemViewHolder viewHolder ) { viewHolder . iconImageView . setVisibility ( iconCount > 0 ? View . VISIBLE : View . GONE ) ; viewHolder . iconImageView . setEnabled ( item . isEnabled ( ) ) ; if ( item . getIcon ( ) != null && item . getIcon ( ) instanceof StateListDrawable ) { StateListDrawable stateListDrawable = ( StateListDrawable ) item . getIcon ( ) ; try { int [ ] currentState = viewHolder . iconImageView . getDrawableState ( ) ; Method getStateDrawableIndex = StateListDrawable . class . getMethod ( "getStateDrawableIndex" , int [ ] . class ) ; Method getStateDrawable = StateListDrawable . class . getMethod ( "getStateDrawable" , int . class ) ; int index = ( int ) getStateDrawableIndex . invoke ( stateListDrawable , currentState ) ; Drawable drawable = ( Drawable ) getStateDrawable . invoke ( stateListDrawable , index ) ; viewHolder . iconImageView . setImageDrawable ( drawable ) ; } catch ( Exception e ) { viewHolder . iconImageView . setImageDrawable ( item . getIcon ( ) ) ; } } else { viewHolder . iconImageView . setImageDrawable ( item . getIcon ( ) ) ; } viewHolder . titleTextView . setText ( item . getTitle ( ) ) ; viewHolder . titleTextView . setEnabled ( item . isEnabled ( ) ) ; if ( getItemColor ( ) != - 1 ) { viewHolder . titleTextView . setTextColor ( getItemColor ( ) ) ; } }
Visualizes a specific item .
407
6
24,206
private View inflateDividerView ( @ Nullable final ViewGroup parent , @ NonNull final Divider divider , final int position ) { LayoutInflater layoutInflater = LayoutInflater . from ( context ) ; View view = layoutInflater . inflate ( R . layout . divider , parent , false ) ; DividerViewHolder viewHolder = new DividerViewHolder ( ) ; viewHolder . leftDivider = view . findViewById ( R . id . left_divider ) ; viewHolder . rightDivider = view . findViewById ( R . id . right_divider ) ; viewHolder . titleTextView = view . findViewById ( android . R . id . title ) ; view . setTag ( viewHolder ) ; if ( ! TextUtils . isEmpty ( divider . getTitle ( ) ) || ( position % columnCount > 0 && ! TextUtils . isEmpty ( getRawItems ( ) . get ( position - ( position % columnCount ) ) . getTitle ( ) ) ) ) { view . getLayoutParams ( ) . height = context . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_divider_title_height ) ; } return view ; }
Inflates the view which is used to visualize a divider .
278
14
24,207
private void visualizeDivider ( @ NonNull final Divider divider , @ NonNull final DividerViewHolder viewHolder ) { if ( ! TextUtils . isEmpty ( divider . getTitle ( ) ) ) { viewHolder . titleTextView . setText ( divider . getTitle ( ) ) ; viewHolder . titleTextView . setVisibility ( View . VISIBLE ) ; viewHolder . leftDivider . setVisibility ( View . VISIBLE ) ; } else { viewHolder . titleTextView . setVisibility ( View . GONE ) ; viewHolder . leftDivider . setVisibility ( View . GONE ) ; } if ( dividerColor != - 1 ) { viewHolder . titleTextView . setTextColor ( dividerColor ) ; viewHolder . leftDivider . setBackgroundColor ( dividerColor ) ; viewHolder . rightDivider . setBackgroundColor ( dividerColor ) ; } }
Visualizes a specific divider .
207
7
24,208
public final void setStyle ( @ NonNull final Style style ) { Condition . INSTANCE . ensureNotNull ( style , "The style may not be null" ) ; this . style = style ; this . rawItems = null ; notifyDataSetChanged ( ) ; }
Sets the style which should be used to display the adapter s items .
56
15
24,209
public final void setWidth ( final int width ) { if ( style == Style . LIST_COLUMNS && ( getDeviceType ( context ) == DeviceType . TABLET || getOrientation ( context ) == Orientation . LANDSCAPE ) ) { columnCount = 2 ; } else if ( style == Style . GRID ) { int padding = context . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_grid_item_horizontal_padding ) ; int itemSize = context . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_grid_item_size ) ; columnCount = ( ( getDeviceType ( context ) != DeviceType . TABLET && context . getResources ( ) . getConfiguration ( ) . orientation == Configuration . ORIENTATION_PORTRAIT ? context . getResources ( ) . getDisplayMetrics ( ) . widthPixels : width ) - 2 * padding ) / itemSize ; } else { columnCount = 1 ; } rawItems = null ; notifyDataSetChanged ( ) ; }
Sets the width of the bottom sheet the items which are displayed by the adapter belong to .
233
19
24,210
public final void add ( @ NonNull final AbstractItem item ) { Condition . INSTANCE . ensureNotNull ( item , "The item may not be null" ) ; items . add ( item ) ; if ( item instanceof Item && ( ( Item ) item ) . getIcon ( ) != null ) { iconCount ++ ; } else if ( item instanceof Divider ) { dividerCount ++ ; } rawItems = null ; notifyOnDataSetChanged ( ) ; }
Adds a new item to the adapter .
99
8
24,211
public final void set ( final int index , @ NonNull final AbstractItem item ) { Condition . INSTANCE . ensureNotNull ( item , "The item may not be null" ) ; AbstractItem replacedItem = items . set ( index , item ) ; if ( replacedItem instanceof Item && ( ( Item ) replacedItem ) . getIcon ( ) != null ) { iconCount -- ; } else if ( replacedItem instanceof Divider ) { dividerCount -- ; } if ( item instanceof Item && ( ( Item ) item ) . getIcon ( ) != null ) { iconCount ++ ; } else if ( item instanceof Divider ) { dividerCount ++ ; } rawItems = null ; notifyOnDataSetChanged ( ) ; }
Replaces the item with at a specific index
156
9
24,212
public final void remove ( final int index ) { AbstractItem removedItem = items . remove ( index ) ; if ( removedItem instanceof Item && ( ( Item ) removedItem ) . getIcon ( ) != null ) { iconCount -- ; } else if ( removedItem instanceof Divider ) { dividerCount -- ; } rawItems = null ; notifyOnDataSetChanged ( ) ; }
Removes the item at a specific index .
82
9
24,213
public final void clear ( ) { items . clear ( ) ; iconCount = 0 ; dividerCount = 0 ; if ( rawItems != null ) { rawItems . clear ( ) ; } notifyOnDataSetChanged ( ) ; }
Removes all items from the adapter .
49
8
24,214
public final boolean isItemEnabled ( final int index ) { AbstractItem item = items . get ( index ) ; return item instanceof Item && ( ( Item ) item ) . isEnabled ( ) ; }
Returns whether the item at a specific index is enabled or not .
41
13
24,215
public final void setItemEnabled ( final int index , final boolean enabled ) { AbstractItem item = items . get ( index ) ; if ( item instanceof Item ) { ( ( Item ) item ) . setEnabled ( enabled ) ; rawItems = null ; notifyOnDataSetChanged ( ) ; } }
Sets whether the item at a specific index should be enabled or not .
63
15
24,216
public final void setTitle ( @ NonNull final Context context , @ StringRes final int resourceId ) { setTitle ( context . getText ( resourceId ) ) ; }
Sets the divider s title .
36
8
24,217
private boolean isScrollUpEvent ( final float x , final float y , @ NonNull final ViewGroup viewGroup ) { int location [ ] = new int [ 2 ] ; viewGroup . getLocationOnScreen ( location ) ; if ( x >= location [ 0 ] && x <= location [ 0 ] + viewGroup . getWidth ( ) && y >= location [ 1 ] && y <= location [ 1 ] + viewGroup . getHeight ( ) ) { for ( int i = 0 ; i < viewGroup . getChildCount ( ) ; i ++ ) { View view = viewGroup . getChildAt ( i ) ; if ( view . canScrollVertically ( - 1 ) ) { return true ; } else if ( view instanceof ViewGroup ) { return isScrollUpEvent ( x , y , ( ViewGroup ) view ) ; } } } return false ; }
Returns whether a touch event at a specific position targets a view which can be scrolled up .
181
19
24,218
private boolean handleDrag ( ) { if ( ! isAnimationRunning ( ) ) { if ( dragHelper . hasThresholdBeenReached ( ) ) { int margin = Math . round ( isMaximized ( ) ? dragHelper . getDragDistance ( ) : initialMargin + dragHelper . getDragDistance ( ) ) ; margin = Math . max ( Math . max ( margin , minMargin ) , 0 ) ; setTopMargin ( margin ) ; } return true ; } return false ; }
Handles when a drag gesture is performed by the user .
107
12
24,219
private void handleRelease ( ) { float speed = Math . max ( dragHelper . getDragSpeed ( ) , animationSpeed ) ; if ( getTopMargin ( ) > initialMargin || ( dragHelper . getDragSpeed ( ) > animationSpeed && dragHelper . getDragDistance ( ) > 0 ) || ( getDeviceType ( getContext ( ) ) == DeviceType . TABLET && isMaximized ( ) && getTopMargin ( ) > minMargin ) ) { animateHideView ( parentHeight - getTopMargin ( ) , speed , new DecelerateInterpolator ( ) , true ) ; } else { animateShowView ( - ( getTopMargin ( ) - minMargin ) , speed , new DecelerateInterpolator ( ) ) ; } }
Handles when a drag gesture has been ended by the user .
167
13
24,220
private void setTopMargin ( final int margin ) { FrameLayout . LayoutParams layoutParams = ( FrameLayout . LayoutParams ) getLayoutParams ( ) ; layoutParams . topMargin = margin ; setLayoutParams ( layoutParams ) ; }
Set the top margin of the view .
58
8
24,221
private void animateShowView ( final int diff , final float animationSpeed , @ NonNull final Interpolator interpolator ) { animateView ( diff , animationSpeed , createAnimationListener ( true , false ) , interpolator ) ; }
Animates the view to become show .
48
8
24,222
private void animateHideView ( final int diff , final float animationSpeed , @ NonNull final Interpolator interpolator , final boolean cancel ) { animateView ( diff , animationSpeed , createAnimationListener ( false , cancel ) , interpolator ) ; }
Animates the view to become hidden .
52
8
24,223
private void animateView ( final int diff , final float animationSpeed , @ NonNull final AnimationListener animationListener , @ NonNull final Interpolator interpolator ) { if ( ! isDragging ( ) && ! isAnimationRunning ( ) ) { long duration = calculateAnimationDuration ( diff , animationSpeed ) ; Animation animation = new DraggableViewAnimation ( this , diff , duration , animationListener ) ; animation . setInterpolator ( interpolator ) ; startAnimation ( animation ) ; } }
Animates the view to become shown or hidden .
103
10
24,224
private AnimationListener createAnimationListener ( final boolean show , final boolean cancel ) { return new AnimationListener ( ) { @ Override public void onAnimationStart ( final Animation animation ) { } @ Override public void onAnimationEnd ( final Animation animation ) { clearAnimation ( ) ; maximized = show ; if ( maximized ) { notifyOnMaximized ( ) ; } else { notifyOnHidden ( cancel ) ; } } @ Override public void onAnimationRepeat ( final Animation animation ) { } } ; }
Creates and returns a listener which allows to handle the end of an animation which has been used to show or hide the view .
106
26
24,225
public final void setIcon ( @ NonNull final Context context , @ DrawableRes final int resourceId ) { setIcon ( ContextCompat . getDrawable ( context , resourceId ) ) ; }
Sets the item s icon .
41
7
24,226
public final void setTitle ( @ NonNull final Context context , @ StringRes final int resourceId ) { Condition . INSTANCE . ensureNotNull ( context , "The context may not be null" ) ; setTitle ( context . getText ( resourceId ) ) ; }
Sets the title of the item .
57
8
24,227
private void initialize ( ) { width = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . default_width ) ; maximize = false ; adapter = new DividableGridAdapter ( getContext ( ) , Style . LIST , width ) ; super . setOnShowListener ( createOnShowListener ( ) ) ; }
Initializes the bottom sheet .
75
6
24,228
private WindowManager . LayoutParams createLayoutParams ( ) { WindowManager . LayoutParams layoutParams = getWindow ( ) . getAttributes ( ) ; layoutParams . width = ViewGroup . LayoutParams . MATCH_PARENT ; layoutParams . height = ViewGroup . LayoutParams . MATCH_PARENT ; return layoutParams ; }
Creates and returns the layout params which should be used to show the bottom sheet .
78
17
24,229
private FrameLayout . LayoutParams createRootViewLayoutParams ( ) { FrameLayout . LayoutParams layoutParams = new FrameLayout . LayoutParams ( FrameLayout . LayoutParams . MATCH_PARENT , FrameLayout . LayoutParams . MATCH_PARENT ) ; layoutParams . gravity = Gravity . BOTTOM | Gravity . CENTER_HORIZONTAL ; return layoutParams ; }
Creates and returns the layout params which should be used to show the bottom sheet s root view .
90
20
24,230
private void inflateRootView ( ) { ViewGroup contentView = findViewById ( android . R . id . content ) ; contentView . removeAllViews ( ) ; LayoutInflater layoutInflater = LayoutInflater . from ( getContext ( ) ) ; rootView = ( DraggableView ) layoutInflater . inflate ( R . layout . bottom_sheet , contentView , false ) ; rootView . setCallback ( this ) ; contentView . addView ( rootView , createRootViewLayoutParams ( ) ) ; }
Initializes the bottom sheet s root view .
119
9
24,231
private void inflateTitleView ( ) { titleContainer = rootView . findViewById ( R . id . title_container ) ; titleContainer . removeAllViews ( ) ; if ( customTitleView != null ) { titleContainer . addView ( customTitleView ) ; } else if ( customTitleViewId != - 1 ) { LayoutInflater layoutInflater = LayoutInflater . from ( getContext ( ) ) ; View view = layoutInflater . inflate ( customTitleViewId , titleContainer , false ) ; titleContainer . addView ( view ) ; } else { LayoutInflater layoutInflater = LayoutInflater . from ( getContext ( ) ) ; View view = layoutInflater . inflate ( R . layout . bottom_sheet_title , titleContainer , false ) ; titleContainer . addView ( view ) ; } if ( getStyle ( ) == Style . LIST ) { int padding = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_list_item_horizontal_padding ) ; titleContainer . setPadding ( padding , 0 , padding , 0 ) ; } else { int padding = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_grid_item_horizontal_padding ) ; titleContainer . setPadding ( padding , 0 , padding , 0 ) ; } View titleView = titleContainer . findViewById ( android . R . id . title ) ; titleTextView = titleView instanceof TextView ? ( TextView ) titleView : null ; }
Inflates the layout which is used to show the bottom sheet s title . The layout may either be the default one or a custom view if one has been set before .
351
35
24,232
private void inflateContentView ( ) { contentContainer = rootView . findViewById ( R . id . content_container ) ; contentContainer . removeAllViews ( ) ; if ( customView != null ) { contentContainer . setVisibility ( View . VISIBLE ) ; contentContainer . addView ( customView ) ; } else if ( customViewId != - 1 ) { contentContainer . setVisibility ( View . VISIBLE ) ; LayoutInflater layoutInflater = LayoutInflater . from ( getContext ( ) ) ; View view = layoutInflater . inflate ( customViewId , contentContainer , false ) ; contentContainer . addView ( view ) ; } else { LayoutInflater layoutInflater = LayoutInflater . from ( getContext ( ) ) ; View view = layoutInflater . inflate ( R . layout . bottom_sheet_grid_view , contentContainer , false ) ; contentContainer . addView ( view ) ; } showGridView ( ) ; }
Inflates the layout which is used to show the bottom sheet s content . The layout may either be the default one or a custom view if one has been set before .
217
35
24,233
private void showGridView ( ) { gridView = contentContainer . findViewById ( R . id . bottom_sheet_grid_view ) ; if ( gridView != null ) { contentContainer . setVisibility ( View . VISIBLE ) ; if ( getStyle ( ) == Style . GRID ) { int horizontalPadding = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_grid_item_horizontal_padding ) ; int paddingBottom = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_grid_padding_bottom ) ; gridView . setPadding ( horizontalPadding , 0 , horizontalPadding , paddingBottom ) ; gridView . setNumColumns ( GridView . AUTO_FIT ) ; gridView . setColumnWidth ( getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_grid_item_size ) ) ; } else { int paddingBottom = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_list_padding_bottom ) ; gridView . setPadding ( 0 , 0 , 0 , paddingBottom ) ; gridView . setNumColumns ( getStyle ( ) == Style . LIST_COLUMNS && ( getDeviceType ( getContext ( ) ) == DisplayUtil . DeviceType . TABLET || getOrientation ( getContext ( ) ) == DisplayUtil . Orientation . LANDSCAPE ) ? 2 : 1 ) ; } gridView . setOnItemClickListener ( createItemClickListener ( ) ) ; gridView . setOnItemLongClickListener ( createItemLongClickListener ( ) ) ; gridView . setAdapter ( adapter ) ; } }
Shows the grid view which is used to show the bottom sheet s items .
395
16
24,234
private void adaptRootView ( ) { if ( rootView != null ) { if ( getStyle ( ) == Style . LIST ) { int paddingTop = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_list_padding_top ) ; rootView . setPadding ( 0 , paddingTop , 0 , 0 ) ; } else { int paddingTop = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_grid_padding_top ) ; rootView . setPadding ( 0 , paddingTop , 0 , 0 ) ; } } }
Adapts the root view .
140
6
24,235
private void adaptIcon ( ) { if ( titleTextView != null ) { titleTextView . setCompoundDrawablesWithIntrinsicBounds ( icon , null , null , null ) ; } adaptTitleContainerVisibility ( ) ; }
Adapts the bottom sheet s icon .
52
8
24,236
private void adaptTitleContainerVisibility ( ) { if ( titleContainer != null ) { if ( customTitleView == null && customTitleViewId == - 1 ) { titleContainer . setVisibility ( ! TextUtils . isEmpty ( title ) || icon != null ? View . VISIBLE : View . GONE ) ; } else { titleContainer . setVisibility ( View . VISIBLE ) ; } } }
Adapts the visibility of the layout which is used to show the bottom sheet s title .
87
18
24,237
private void adaptWidth ( ) { adapter . setWidth ( width ) ; if ( rootView != null ) { rootView . setWidth ( width ) ; rootView . requestLayout ( ) ; } }
Adapts the width of the bottom sheet .
42
9
24,238
@ TargetApi ( VERSION_CODES . FROYO ) private OnShowListener createOnShowListener ( ) { return new OnShowListener ( ) { @ Override public void onShow ( final DialogInterface dialog ) { if ( onShowListener != null ) { onShowListener . onShow ( dialog ) ; } if ( maximize ) { maximize = false ; rootView . maximize ( new DecelerateInterpolator ( ) ) ; } } } ; }
Creates and returns a listener which allows to immediately maximize the bottom sheet after it has been shown .
100
20
24,239
private View . OnTouchListener createCancelOnTouchListener ( ) { return new View . OnTouchListener ( ) { @ Override public boolean onTouch ( final View v , final MotionEvent event ) { if ( cancelable && canceledOnTouchOutside ) { cancel ( ) ; v . performClick ( ) ; return true ; } return false ; } } ; }
Creates and returns a listener which allows to cancel the bottom sheet when the decor view is touched .
76
20
24,240
private OnItemClickListener createItemClickListener ( ) { return new OnItemClickListener ( ) { @ Override public void onItemClick ( final AdapterView < ? > parent , final View view , final int position , final long id ) { if ( itemClickListener != null && ! rootView . isDragging ( ) && ! rootView . isAnimationRunning ( ) ) { int index = position ; if ( adapter . containsDividers ( ) ) { for ( int i = position ; i >= 0 ; i -- ) { if ( adapter . getItem ( i ) == null || ( adapter . getItem ( i ) instanceof Divider && i % adapter . getColumnCount ( ) > 0 ) ) { index -- ; } } } itemClickListener . onItemClick ( parent , view , index , getId ( position ) ) ; } dismiss ( ) ; } } ; }
Creates and returns a listener which allows to observe when the items of a bottom sheet have been clicked .
187
21
24,241
private OnItemLongClickListener createItemLongClickListener ( ) { return new OnItemLongClickListener ( ) { @ Override public boolean onItemLongClick ( final AdapterView < ? > parent , final View view , final int position , final long id ) { if ( ! rootView . isDragging ( ) && ! rootView . isAnimationRunning ( ) && itemLongClickListener != null ) { int index = position ; if ( adapter . containsDividers ( ) ) { for ( int i = position ; i >= 0 ; i -- ) { if ( adapter . getItem ( i ) == null || ( adapter . getItem ( i ) instanceof Divider && i % adapter . getColumnCount ( ) > 0 ) ) { index -- ; } } } return itemLongClickListener . onItemLongClick ( parent , view , index , getId ( position ) ) ; } return false ; } } ; }
Creates and returns a listener which allows to observe when the items of a bottom sheet have been long - clicked .
194
23
24,242
private OnItemClickListener createIntentClickListener ( @ NonNull final Activity activity , @ NonNull final Intent intent , @ NonNull final List < ResolveInfo > resolveInfos ) { return new OnItemClickListener ( ) { @ Override public void onItemClick ( final AdapterView < ? > parent , final View view , final int position , final long id ) { ActivityInfo activityInfo = resolveInfos . get ( position ) . activityInfo ; ComponentName componentName = new ComponentName ( activityInfo . applicationInfo . packageName , activityInfo . name ) ; intent . setFlags ( Intent . FLAG_ACTIVITY_NEW_TASK | Intent . FLAG_ACTIVITY_RESET_TASK_IF_NEEDED ) ; intent . setComponent ( componentName ) ; activity . startActivity ( intent ) ; dismiss ( ) ; } } ; }
Creates and returns a listener which allows to start an app when an item of the bottom sheet has been clicked .
188
23
24,243
public final GridView getGridView ( ) { return ( gridView != null && gridView . getVisibility ( ) == View . VISIBLE ) ? gridView : null ; }
Returns the grid view which is contained by the bottom sheet .
38
12
24,244
public final void setIcon ( @ DrawableRes final int resourceId ) { this . icon = ContextCompat . getDrawable ( getContext ( ) , resourceId ) ; this . iconBitmap = null ; this . iconId = resourceId ; this . iconAttributeId = - 1 ; adaptIcon ( ) ; }
Sets the icon of the bottom sheet .
67
9
24,245
public final void setIconAttribute ( @ AttrRes final int attributeId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( new int [ ] { attributeId } ) ; this . icon = typedArray . getDrawable ( 0 ) ; this . iconBitmap = null ; this . iconId = - 1 ; this . iconAttributeId = attributeId ; adaptIcon ( ) ; }
Set the icon of the bottom sheet .
93
8
24,246
public final void setBackgroundColor ( @ ColorInt final int color ) { this . background = new ColorDrawable ( color ) ; this . backgroundBitmap = null ; this . backgroundId = - 1 ; this . backgroundColor = color ; adaptBackground ( ) ; }
Sets the background color of the bottom sheet .
56
10
24,247
public final void setDragSensitivity ( final float dragSensitivity ) { Condition . INSTANCE . ensureAtLeast ( dragSensitivity , 0 , "The drag sensitivity must be at least 0" ) ; Condition . INSTANCE . ensureAtMaximum ( dragSensitivity , 1 , "The drag sensitivity must be at maximum 1" ) ; this . dragSensitivity = dragSensitivity ; adaptDragSensitivity ( ) ; }
Sets the sensitivity which specifies the distance after which dragging has an effect on the bottom sheet in relation to an internal value range .
88
26
24,248
public final void setDimAmount ( final float dimAmount ) { Condition . INSTANCE . ensureAtLeast ( dimAmount , 0 , "The dim amount must be at least 0" ) ; Condition . INSTANCE . ensureAtMaximum ( dimAmount , 1 , "The dim amount must be at maximum 1" ) ; this . dimAmount = dimAmount ; getWindow ( ) . getAttributes ( ) . dimAmount = dimAmount ; }
Sets the dim amount which should be used to darken the area outside the bottom sheet .
91
19
24,249
public final int indexOf ( final int id ) { Condition . INSTANCE . ensureAtLeast ( id , 0 , "The id must be at least 0" ) ; for ( int i = 0 ; i < getItemCount ( ) ; i ++ ) { AbstractItem item = adapter . getItem ( i ) ; if ( item . getId ( ) == id ) { return i ; } } return - 1 ; }
Returns the index of the item which corresponds to a specific id .
89
13
24,250
public final void setIntent ( @ NonNull final Activity activity , @ NonNull final Intent intent ) { Condition . INSTANCE . ensureNotNull ( activity , "The activity may not be null" ) ; Condition . INSTANCE . ensureNotNull ( intent , "The intent may not be null" ) ; removeAllItems ( ) ; PackageManager packageManager = activity . getPackageManager ( ) ; List < ResolveInfo > resolveInfos = packageManager . queryIntentActivities ( intent , 0 ) ; for ( int i = 0 ; i < resolveInfos . size ( ) ; i ++ ) { ResolveInfo resolveInfo = resolveInfos . get ( i ) ; addItem ( i , resolveInfo . loadLabel ( packageManager ) , resolveInfo . loadIcon ( packageManager ) ) ; } setOnItemClickListener ( createIntentClickListener ( activity , ( Intent ) intent . clone ( ) , resolveInfos ) ) ; }
Adds the apps which are able to handle a specific intent as items to the bottom sheet . This causes all previously added items to be removed . When an item is clicked the corresponding app is started .
200
39
24,251
@ TargetApi ( VERSION_CODES . FROYO ) public final void maximize ( ) { if ( ! isMaximized ( ) ) { if ( ! isShowing ( ) ) { maximize = true ; show ( ) ; } else { rootView . maximize ( new AccelerateDecelerateInterpolator ( ) ) ; } } }
Maximizes the bottom sheet .
76
7
24,252
public final void setStyle ( @ NonNull final Style style ) { Condition . INSTANCE . ensureNotNull ( style , "The style may not be null" ) ; adapter . setStyle ( style ) ; adaptRootView ( ) ; adaptTitleView ( ) ; adaptContentView ( ) ; adaptGridViewHeight ( ) ; }
Sets the style which should be used to display the bottom sheet s items .
69
16
24,253
private void initializeBottomSheet ( ) { BottomSheet . Builder builder = createBottomSheetBuilder ( ) ; addItems ( builder ) ; bottomSheet = builder . create ( ) ; }
Initializes the regular bottom sheet containing list items .
41
10
24,254
private void initializeCustomBottomSheet ( ) { BottomSheet . Builder builder = createBottomSheetBuilder ( ) ; builder . setView ( R . layout . custom_view ) ; customBottomSheet = builder . create ( ) ; }
Initializes the bottom sheet containing a custom view .
51
10
24,255
private void initializeIntentBottomSheet ( ) { BottomSheet . Builder builder = createBottomSheetBuilder ( ) ; Intent intent = new Intent ( ) ; intent . setAction ( Intent . ACTION_SEND ) ; intent . putExtra ( Intent . EXTRA_TEXT , "This is my text to send." ) ; intent . setType ( "text/plain" ) ; builder . setIntent ( getActivity ( ) , intent ) ; intentBottomSheet = builder . create ( ) ; }
Initializes the bottom sheet containing possible receivers for an intent .
107
12
24,256
private void initializeShowBottomSheetPreference ( ) { Preference showBottomSheetPreference = findPreference ( getString ( R . string . show_bottom_sheet_preference_key ) ) ; showBottomSheetPreference . setOnPreferenceClickListener ( new OnPreferenceClickListener ( ) { @ Override public boolean onPreferenceClick ( final Preference preference ) { initializeBottomSheet ( ) ; bottomSheet . show ( ) ; return true ; } } ) ; }
Initializes the preference which allows to show a bottom sheet .
107
12
24,257
private void initializeShowCustomBottomSheetPreference ( ) { Preference showCustomBottomSheetPreference = findPreference ( getString ( R . string . show_custom_bottom_sheet_preference_key ) ) ; showCustomBottomSheetPreference . setOnPreferenceClickListener ( new OnPreferenceClickListener ( ) { @ Override public boolean onPreferenceClick ( final Preference preference ) { initializeCustomBottomSheet ( ) ; customBottomSheet . show ( ) ; return true ; } } ) ; }
Initializes the preference which allows to show a bottom sheet with custom content .
114
15
24,258
private void initializeShowIntentBottmSheetPreference ( ) { Preference showIntentBottomSheetPreference = findPreference ( getString ( R . string . show_intent_bottom_sheet_preference_key ) ) ; showIntentBottomSheetPreference . setOnPreferenceClickListener ( new OnPreferenceClickListener ( ) { @ Override public boolean onPreferenceClick ( Preference preference ) { initializeIntentBottomSheet ( ) ; intentBottomSheet . show ( ) ; return true ; } } ) ; }
Initializes the preference which allows to display the applications which are suited for handling an intent .
118
18
24,259
private BottomSheet . Builder createBottomSheetBuilder ( ) { BottomSheet . Builder builder = new BottomSheet . Builder ( getActivity ( ) ) ; builder . setStyle ( getStyle ( ) ) ; if ( shouldTitleBeShown ( ) ) { builder . setTitle ( getBottomSheetTitle ( ) ) ; } if ( shouldIconBeShown ( ) ) { builder . setIcon ( android . R . drawable . ic_dialog_alert ) ; } return builder ; }
Creates and returns a builder which allows to create bottom sheets depending on the app s settings .
107
19
24,260
private void addItems ( @ NonNull final BottomSheet . Builder builder ) { int dividerCount = getDividerCount ( ) ; boolean showDividerTitle = shouldDividerTitleBeShown ( ) ; int itemCount = getItemCount ( ) ; boolean showIcon = shouldItemIconsBeShown ( ) ; boolean disableItems = shouldItemsBeDisabled ( ) ; int index = 0 ; for ( int i = 0 ; i < dividerCount + 1 ; i ++ ) { if ( i > 0 ) { builder . addDivider ( showDividerTitle ? getString ( R . string . divider_title , i ) : null ) ; index ++ ; } for ( int j = 0 ; j < itemCount ; j ++ ) { String title = getString ( R . string . item_title , i * itemCount + j + 1 ) ; Drawable icon ; if ( isDarkThemeSet ( ) ) { icon = showIcon ? ContextCompat . getDrawable ( getActivity ( ) , getStyle ( ) == Style . GRID ? R . drawable . grid_item_dark : R . drawable . list_item_dark ) : null ; } else { icon = showIcon ? ContextCompat . getDrawable ( getActivity ( ) , getStyle ( ) == Style . GRID ? R . drawable . grid_item : R . drawable . list_item ) : null ; } builder . addItem ( i * dividerCount + j , title , icon ) ; if ( disableItems ) { builder . setItemEnabled ( index , false ) ; } index ++ ; } } builder . setOnItemClickListener ( createItemClickListener ( ) ) ; }
Adds items depending on the app s settings to a builder which allows to create a bottom sheet .
361
19
24,261
private Style getStyle ( ) { SharedPreferences sharedPreferences = PreferenceManager . getDefaultSharedPreferences ( getActivity ( ) ) ; String key = getString ( R . string . bottom_sheet_style_preference_key ) ; String defaultValue = getString ( R . string . bottom_sheet_style_preference_default_value ) ; String style = sharedPreferences . getString ( key , defaultValue ) ; switch ( style ) { case "list" : return Style . LIST ; case "list_columns" : return Style . LIST_COLUMNS ; default : return Style . GRID ; } }
Returns the style which should be used to create bottom sheets depending on the app s settings .
136
18
24,262
private boolean shouldTitleBeShown ( ) { SharedPreferences sharedPreferences = PreferenceManager . getDefaultSharedPreferences ( getActivity ( ) ) ; String key = getString ( R . string . show_bottom_sheet_title_preference_key ) ; boolean defaultValue = getResources ( ) . getBoolean ( R . bool . show_bottom_sheet_title_preference_default_value ) ; return sharedPreferences . getBoolean ( key , defaultValue ) ; }
Returns whether the title of bottom sheets should be shown depending on the app s settings or not .
107
19
24,263
private String getBottomSheetTitle ( ) { SharedPreferences sharedPreferences = PreferenceManager . getDefaultSharedPreferences ( getActivity ( ) ) ; String key = getString ( R . string . bottom_sheet_title_preference_key ) ; String defaultValue = getString ( R . string . bottom_sheet_title_preference_default_value ) ; return sharedPreferences . getString ( key , defaultValue ) ; }
Returns the title of bottom sheets depending on the app s settings .
96
13
24,264
private boolean shouldIconBeShown ( ) { SharedPreferences sharedPreferences = PreferenceManager . getDefaultSharedPreferences ( getActivity ( ) ) ; String key = getString ( R . string . show_bottom_sheet_icon_preference_key ) ; boolean defaultValue = getResources ( ) . getBoolean ( R . bool . show_bottom_sheet_icon_preference_default_value ) ; return sharedPreferences . getBoolean ( key , defaultValue ) ; }
Returns whether the icon of bottom sheets should be shown depending on the app s settings or not .
107
19
24,265
private int getDividerCount ( ) { SharedPreferences sharedPreferences = PreferenceManager . getDefaultSharedPreferences ( getActivity ( ) ) ; String key = getString ( R . string . divider_count_preference_key ) ; String defaultValue = getString ( R . string . divider_count_preference_default_value ) ; return Integer . valueOf ( sharedPreferences . getString ( key , defaultValue ) ) ; }
Returns the number of dividers which should be shown depending on the app s settings .
99
17
24,266
private boolean shouldDividerTitleBeShown ( ) { SharedPreferences sharedPreferences = PreferenceManager . getDefaultSharedPreferences ( getActivity ( ) ) ; String key = getString ( R . string . show_divider_title_preference_key ) ; boolean defaultValue = getResources ( ) . getBoolean ( R . bool . show_divider_title_preference_default_value ) ; return sharedPreferences . getBoolean ( key , defaultValue ) ; }
Returns whether the title of dividers should be shown depending on the app s settings or not .
107
19
24,267
private int getItemCount ( ) { SharedPreferences sharedPreferences = PreferenceManager . getDefaultSharedPreferences ( getActivity ( ) ) ; String key = getString ( R . string . item_count_preference_key ) ; String defaultValue = getString ( R . string . item_count_preference_default_value ) ; return Integer . valueOf ( sharedPreferences . getString ( key , defaultValue ) ) ; }
Returns the number of items which should be shown per divider depending on the app s settings .
96
19
24,268
private boolean shouldItemIconsBeShown ( ) { SharedPreferences sharedPreferences = PreferenceManager . getDefaultSharedPreferences ( getActivity ( ) ) ; String key = getString ( R . string . show_item_icons_preference_key ) ; boolean defaultValue = getResources ( ) . getBoolean ( R . bool . show_item_icons_preference_default_value ) ; return sharedPreferences . getBoolean ( key , defaultValue ) ; }
Returns whether icons should be shown next to items depending on the app s settings or not .
105
18
24,269
private boolean shouldItemsBeDisabled ( ) { SharedPreferences sharedPreferences = PreferenceManager . getDefaultSharedPreferences ( getActivity ( ) ) ; String key = getString ( R . string . disable_items_preference_key ) ; boolean defaultValue = getResources ( ) . getBoolean ( R . bool . disable_items_preference_default_value ) ; return sharedPreferences . getBoolean ( key , defaultValue ) ; }
Returns whether items should be disabled depending on the app s settings or not .
99
15
24,270
private boolean isDarkThemeSet ( ) { SharedPreferences sharedPreferences = PreferenceManager . getDefaultSharedPreferences ( getActivity ( ) ) ; String key = getString ( R . string . theme_preference_key ) ; String defaultValue = getString ( R . string . theme_preference_default_value ) ; return Integer . valueOf ( sharedPreferences . getString ( key , defaultValue ) ) != 0 ; }
Returns whether the app uses the dark theme or not .
95
11
24,271
public Map < String , String > detectVariableValues ( TokenList tokenList ) { Map < String , String > variables = new HashMap < String , String > ( ) ; boolean thisContainsVariables = containsVariables ( ) ; boolean thatContainsVariables = tokenList . containsVariables ( ) ; // If both lists contain variables, we get into trouble. if ( thisContainsVariables && thatContainsVariables ) { throw new VariableValueDetectionException ( "Cannot detect variable values if both token lists contain variables." ) ; } // If both lists don't contain variables, no variables can be detected and we can return the empty map. if ( ! thisContainsVariables && ! thatContainsVariables ) { return variables ; } ListIterator < Token > iteratorWithVariables = ( thisContainsVariables ? this : tokenList ) . listIterator ( ) ; ListIterator < Token > iteratorWithoutVariables = ( thisContainsVariables ? tokenList : this ) . listIterator ( ) ; // We now know that {@code iteratorWithVariables} contains at least one variable. We iterate over both lists // simultaneously and if {@code possibleVariableToken} is a {@link VariableToken}, we know that // {@code literalToken} contains the value for this variable. while ( iteratorWithVariables . hasNext ( ) && iteratorWithoutVariables . hasNext ( ) ) { Token possibleVariableToken = iteratorWithVariables . next ( ) ; Token literalToken = iteratorWithoutVariables . next ( ) ; if ( possibleVariableToken instanceof VariableToken ) { variables . put ( possibleVariableToken . getText ( ) , literalToken . getText ( ) ) ; } } return variables ; }
Detects variable values using another token list .
365
9
24,272
private boolean tokenTypesMatch ( Token token1 , Token token2 , Class < ? extends Token > tokenType ) { return tokenType . isAssignableFrom ( token1 . getClass ( ) ) && tokenType . isAssignableFrom ( token2 . getClass ( ) ) ; }
Checks whether both tokens have the specified type .
62
10
24,273
private boolean tokenTextsDoNotMatch ( Token token1 , Token token2 ) { return ! token1 . getText ( ) . equals ( token2 . getText ( ) ) ; }
Checks whether both tokens have the same texts .
40
10
24,274
@ SuppressWarnings ( "WeakerAccess" ) public static void setStatementResolver ( StatementResolver statementResolver ) { if ( statementResolver == null ) { throw new NullPointerException ( "The statement resolver must not be null." ) ; } StatementResolverHolder . STATEMENT_RESOLVER . set ( statementResolver ) ; }
Sets the statement resolver for the current thread .
79
11
24,275
public static WebElement findElementOrFail ( WebDriver webDriver , By element ) { try { return webDriver . findElement ( element ) ; } catch ( NoSuchElementException e ) { fail ( String . format ( "Element %s should exist but it does not." , element . toString ( ) ) , e ) ; } /** * Never reached since {@link de.codecentric.zucchini.bdd.util.Assert#fail(String)} fail()} throws * {@link java.lang.AssertionError}. */ return null ; }
Tries to find a specific element and fails if the element could not be found .
122
17
24,276
@ Override public void go ( ) { logger . info ( "Typing \"{}\"..." , ( Object ) keys ) ; new Actions ( getWebDriver ( ) ) . sendKeys ( Keys . ENTER ) ; }
Types the keys .
47
4
24,277
protected void failOnInvalidContext ( ExecutionContext executionContext ) { for ( Fact fact : executionContext . getFacts ( ) ) { failOnInvalidFact ( fact ) ; } for ( Step step : executionContext . getSteps ( ) ) { failOnInvalidStep ( step ) ; } for ( Result result : executionContext . getResults ( ) ) { failOnInvalidResult ( result ) ; } }
This method validates the execution context .
85
8
24,278
@ Override public void expect ( ) { try { webResult . setWebDriver ( getWebDriver ( ) ) ; webResult . expect ( ) ; fail ( "Result should fail but it did not." ) ; } catch ( Exception e ) { logger . debug ( "Negated failure:" , e ) ; } catch ( AssertionError e ) { logger . debug ( "Negated failure:" , e ) ; } }
Expects that the specified web result fails .
90
9
24,279
private void findTokens ( ) { mergedTokens = new TokenList ( ) ; variable = null ; state = TokenizerState . START ; index = - 1 ; while ( index < rawTokens . length ) { switch ( state ) { case START : next ( TokenizerState . OUTSIDE_VARIABLE_CONTEXT ) ; break ; case OUTSIDE_VARIABLE_CONTEXT : handleTokenOutsideOfVariableContext ( ) ; break ; case INSIDE_VARIABLE_CONTEXT : handleTokenInsideOfVariableContext ( ) ; break ; default : break ; } } }
Finds tokens within the split statement name .
126
9
24,280
@ Override public void go ( ) { logger . info ( "Waiting {} seconds..." , sleepTime ) ; try { Thread . sleep ( sleepTime ) ; } catch ( InterruptedException e ) { throw new ExecutionException ( "Thread could not sleep." , e ) ; } }
Waits for the specified sleep time .
60
8
24,281
@ Override public void go ( ) { logger . info ( "Typing \"{}\" into {}..." , keys , element ) ; findElementOrFail ( getWebDriver ( ) , element ) . sendKeys ( keys ) ; }
Types into the element .
50
5
24,282
@ Override public void go ( ) { logger . info ( "Waiting {} seconds for {}..." , timeout , element ) ; WebDriverWait waiting = new WebDriverWait ( getWebDriver ( ) , timeout ) ; try { waiting . until ( ExpectedConditions . presenceOfElementLocated ( element ) ) ; } catch ( NullPointerException e ) { fail ( String . format ( "Element %s did not appear within %d seconds." , element , timeout ) , e ) ; } }
Waits for the element .
105
6
24,283
@ Override public void expect ( ) { assertTrue ( String . format ( "Page should contain \"%s\" but it does not." , text ) , getWebDriver ( ) . getPageSource ( ) . contains ( text ) ) ; }
Expects that the specified text is present .
52
9
24,284
public SelectStep value ( String value ) { return new SelectStep ( element , value , SelectStep . OptionSelectorType . VALUE ) ; }
Selects an option by its value .
31
8
24,285
public SelectStep text ( String text ) { return new SelectStep ( element , text , SelectStep . OptionSelectorType . TEXT ) ; }
Selects an option by its text .
30
8
24,286
@ SuppressWarnings ( { "resource" } ) @ RequestMapping ( value = { "/api.js" , "/api-debug.js" , "/api-debug-doc.js" } , method = RequestMethod . GET ) public void api ( @ RequestParam ( value = "apiNs" , required = false ) String apiNs , @ RequestParam ( value = "actionNs" , required = false ) String actionNs , @ RequestParam ( value = "remotingApiVar" , required = false ) String remotingApiVar , @ RequestParam ( value = "pollingUrlsVar" , required = false ) String pollingUrlsVar , @ RequestParam ( value = "group" , required = false ) String group , @ RequestParam ( value = "fullRouterUrl" , required = false ) Boolean fullRouterUrl , @ RequestParam ( value = "format" , required = false ) String format , @ RequestParam ( value = "baseRouterUrl" , required = false ) String baseRouterUrl , HttpServletRequest request , HttpServletResponse response ) throws IOException { if ( format == null ) { response . setContentType ( this . configurationService . getConfiguration ( ) . getJsContentType ( ) ) ; response . setCharacterEncoding ( ExtDirectSpringUtil . UTF8_CHARSET . name ( ) ) ; String apiString = buildAndCacheApiString ( apiNs , actionNs , remotingApiVar , pollingUrlsVar , group , fullRouterUrl , baseRouterUrl , request ) ; byte [ ] outputBytes = apiString . getBytes ( ExtDirectSpringUtil . UTF8_CHARSET ) ; response . setContentLength ( outputBytes . length ) ; ServletOutputStream outputStream = response . getOutputStream ( ) ; outputStream . write ( outputBytes ) ; outputStream . flush ( ) ; } else { response . setContentType ( RouterController . APPLICATION_JSON . toString ( ) ) ; response . setCharacterEncoding ( RouterController . APPLICATION_JSON . getCharset ( ) . name ( ) ) ; String requestUrlString = request . getRequestURL ( ) . toString ( ) ; boolean debug = requestUrlString . contains ( "api-debug.js" ) ; String routerUrl = requestUrlString . replaceFirst ( "api[^/]*?\\.js" , "router" ) ; String apiString = buildApiJson ( apiNs , actionNs , remotingApiVar , routerUrl , group , debug ) ; byte [ ] outputBytes = apiString . getBytes ( ExtDirectSpringUtil . UTF8_CHARSET ) ; response . setContentLength ( outputBytes . length ) ; ServletOutputStream outputStream = response . getOutputStream ( ) ; outputStream . write ( outputBytes ) ; outputStream . flush ( ) ; } }
Method that handles api . js and api - debug . js calls . Generates a javascript with the necessary code for Ext Direct .
627
26
24,287
public void addError ( String field , String error ) { Assert . notNull ( field , "field must not be null" ) ; Assert . notNull ( error , "field must not be null" ) ; addErrors ( field , Collections . singletonList ( error ) ) ; addResultProperty ( SUCCESS_PROPERTY , Boolean . FALSE ) ; }
Adds one error message to a specific field . Does not overwrite already existing errors .
80
16
24,288
@ SuppressWarnings ( "unchecked" ) public void addErrors ( String field , List < String > errors ) { Assert . notNull ( field , "field must not be null" ) ; Assert . notNull ( errors , "field must not be null" ) ; // do not overwrite existing errors Map < String , List < String > > errorMap = ( Map < String , List < String > > ) this . result . get ( ERRORS_PROPERTY ) ; if ( errorMap == null ) { errorMap = new HashMap <> ( ) ; addResultProperty ( ERRORS_PROPERTY , errorMap ) ; } List < String > fieldErrors = errorMap . get ( field ) ; if ( fieldErrors == null ) { fieldErrors = new ArrayList <> ( ) ; errorMap . put ( field , fieldErrors ) ; } fieldErrors . addAll ( errors ) ; addResultProperty ( SUCCESS_PROPERTY , Boolean . FALSE ) ; }
Adds multiple error messages to a specific field . Does not overwrite already existing errors .
218
16
24,289
@ SuppressWarnings ( "unchecked" ) public < T extends Filter > T getFirstFilterForField ( String field ) { for ( Filter filter : this . filters ) { if ( filter . getField ( ) . equals ( field ) ) { return ( T ) filter ; } } return null ; }
Returns the first filter for the field .
66
8
24,290
public List < Filter > getAllFiltersForField ( String field ) { List < Filter > foundFilters = new ArrayList <> ( ) ; for ( Filter filter : this . filters ) { if ( filter . getField ( ) . equals ( field ) ) { foundFilters . add ( filter ) ; } } return Collections . unmodifiableList ( foundFilters ) ; }
Returns all filters for a field
82
6
24,291
public ExtDirectResponseBuilder addResultProperty ( String key , Object value ) { this . result . put ( key , value ) ; return this ; }
Add additional property to the response .
31
7
24,292
public static boolean isMultipart ( HttpServletRequest request ) { if ( ! "post" . equals ( request . getMethod ( ) . toLowerCase ( ) ) ) { return false ; } String contentType = request . getContentType ( ) ; return contentType != null && contentType . toLowerCase ( ) . startsWith ( "multipart/" ) ; }
Checks if the request is a multipart request
82
10
24,293
public static Object invoke ( ApplicationContext context , String beanName , MethodInfo methodInfo , final Object [ ] params ) throws IllegalArgumentException , IllegalAccessException , InvocationTargetException { Object bean = context . getBean ( beanName ) ; Method handlerMethod = methodInfo . getMethod ( ) ; ReflectionUtils . makeAccessible ( handlerMethod ) ; Object result = handlerMethod . invoke ( bean , params ) ; if ( result != null && result instanceof Optional ) { return ( ( Optional < ? > ) result ) . orElse ( null ) ; } return result ; }
Invokes a method on a Spring managed bean .
124
10
24,294
public static void addCacheHeaders ( HttpServletResponse response , String etag , Integer month ) { Assert . notNull ( etag , "ETag must not be null" ) ; long seconds ; if ( month != null ) { seconds = month * secondsInAMonth ; } else { seconds = 6L * secondsInAMonth ; } response . setDateHeader ( "Expires" , System . currentTimeMillis ( ) + seconds * 1000L ) ; response . setHeader ( "ETag" , etag ) ; response . setHeader ( "Cache-Control" , "public, max-age=" + seconds ) ; }
Adds Expires ETag and Cache - Control response headers .
140
12
24,295
public static String generateApiString ( ApplicationContext ctx , String remotingVarName , String pollingApiVarName ) throws JsonProcessingException { RemotingApi remotingApi = new RemotingApi ( ctx . getBean ( ConfigurationService . class ) . getConfiguration ( ) . getProviderType ( ) , "router" , null ) ; for ( Map . Entry < MethodInfoCache . Key , MethodInfo > entry : ctx . getBean ( MethodInfoCache . class ) ) { MethodInfo methodInfo = entry . getValue ( ) ; if ( methodInfo . getAction ( ) != null ) { remotingApi . addAction ( entry . getKey ( ) . getBeanName ( ) , methodInfo . getAction ( ) ) ; } else if ( methodInfo . getPollingProvider ( ) != null ) { remotingApi . addPollingProvider ( methodInfo . getPollingProvider ( ) ) ; } } remotingApi . sort ( ) ; StringBuilder extDirectConfig = new StringBuilder ( 100 ) ; extDirectConfig . append ( "var " ) . append ( remotingVarName ) . append ( " = " ) ; extDirectConfig . append ( new ObjectMapper ( ) . writer ( ) . withDefaultPrettyPrinter ( ) . writeValueAsString ( remotingApi ) ) ; extDirectConfig . append ( ";" ) ; List < PollingProvider > pollingProviders = remotingApi . getPollingProviders ( ) ; if ( ! pollingProviders . isEmpty ( ) ) { extDirectConfig . append ( "\n\nvar " ) . append ( pollingApiVarName ) . append ( " = {\n" ) ; for ( int i = 0 ; i < pollingProviders . size ( ) ; i ++ ) { extDirectConfig . append ( " \"" ) ; extDirectConfig . append ( pollingProviders . get ( i ) . getEvent ( ) ) ; extDirectConfig . append ( "\" : \"poll/" ) ; extDirectConfig . append ( pollingProviders . get ( i ) . getBeanName ( ) ) ; extDirectConfig . append ( "/" ) ; extDirectConfig . append ( pollingProviders . get ( i ) . getMethod ( ) ) ; extDirectConfig . append ( "/" ) ; extDirectConfig . append ( pollingProviders . get ( i ) . getEvent ( ) ) ; extDirectConfig . append ( "\"" ) ; if ( i < pollingProviders . size ( ) - 1 ) { extDirectConfig . append ( ",\n" ) ; } } extDirectConfig . append ( "\n};" ) ; } return extDirectConfig . toString ( ) ; }
Returns the api configuration as a String
587
7
24,296
public String writeValueAsString ( Object obj , boolean indent ) { try { if ( indent ) { return this . mapper . writer ( ) . withDefaultPrettyPrinter ( ) . writeValueAsString ( obj ) ; } return this . mapper . writeValueAsString ( obj ) ; } catch ( Exception e ) { LogFactory . getLog ( JsonHandler . class ) . info ( "serialize object to json" , e ) ; return null ; } }
Converts an object into a JSON string . In case of an exceptions returns null and logs the exception .
100
21
24,297
public Object readValue ( InputStream is , Class < Object > clazz ) { try { return this . mapper . readValue ( is , clazz ) ; } catch ( Exception e ) { LogFactory . getLog ( JsonHandler . class ) . info ( "deserialize json to object" , e ) ; return null ; } }
Converts a JSON string into an object . The input is read from an InputStream . In case of an exception returns null and logs the exception .
73
30
24,298
public static Method findMethodWithAnnotation ( Method method , Class < ? extends Annotation > annotation ) { if ( method . isAnnotationPresent ( annotation ) ) { return method ; } Class < ? > cl = method . getDeclaringClass ( ) ; while ( cl != null && cl != Object . class ) { try { Method equivalentMethod = cl . getDeclaredMethod ( method . getName ( ) , method . getParameterTypes ( ) ) ; if ( equivalentMethod . isAnnotationPresent ( annotation ) ) { return equivalentMethod ; } } catch ( NoSuchMethodException e ) { // do nothing here } cl = cl . getSuperclass ( ) ; } return null ; }
Find a method that is annotated with a specific annotation . Starts with the method and goes up to the superclasses of the class .
145
27
24,299
public void put ( String beanName , Class < ? > clazz , Method method , ApplicationContext context ) { MethodInfo info = new MethodInfo ( clazz , context , beanName , method ) ; this . cache . put ( new Key ( beanName , method . getName ( ) ) , info ) ; }
Put a method into the MethodCache .
66
8