idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
8,600 | static void render ( List < AbstractConfigValue > stack , StringBuilder sb , int indent , boolean atRoot , String atKey , ConfigRenderOptions options ) { boolean commentMerge = options . getComments ( ) ; if ( commentMerge ) { sb . append ( "# unresolved merge of " + stack . size ( ) + " values follows (\n" ) ; if ( atKey == null ) { indent ( sb , indent , options ) ; sb . append ( "# this unresolved merge will not be parseable because it's at the root of the object\n" ) ; indent ( sb , indent , options ) ; sb . append ( "# the HOCON format has no way to list multiple root objects in a single file\n" ) ; } } List < AbstractConfigValue > reversed = new ArrayList < AbstractConfigValue > ( ) ; reversed . addAll ( stack ) ; Collections . reverse ( reversed ) ; int i = 0 ; for ( AbstractConfigValue v : reversed ) { if ( commentMerge ) { indent ( sb , indent , options ) ; if ( atKey != null ) { sb . append ( "# unmerged value " + i + " for key " + ConfigImplUtil . renderJsonString ( atKey ) + " from " ) ; } else { sb . append ( "# unmerged value " + i + " from " ) ; } i += 1 ; sb . append ( v . origin ( ) . description ( ) ) ; sb . append ( "\n" ) ; for ( String comment : v . origin ( ) . comments ( ) ) { indent ( sb , indent , options ) ; sb . append ( "# " ) ; sb . append ( comment ) ; sb . append ( "\n" ) ; } } indent ( sb , indent , options ) ; if ( atKey != null ) { sb . append ( ConfigImplUtil . renderJsonString ( atKey ) ) ; if ( options . getFormatted ( ) ) sb . append ( " : " ) ; else sb . append ( ":" ) ; } v . render ( sb , indent , atRoot , options ) ; sb . append ( "," ) ; if ( options . getFormatted ( ) ) sb . append ( '\n' ) ; } sb . setLength ( sb . length ( ) - 1 ) ; if ( options . getFormatted ( ) ) { sb . setLength ( sb . length ( ) - 1 ) ; sb . append ( "\n" ) ; } if ( commentMerge ) { indent ( sb , indent , options ) ; sb . append ( "# ) end of unresolved merge\n" ) ; } } | static method also used by ConfigDelayedMergeObject . |
8,601 | static ConfigException . NotResolved improveNotResolved ( Path what , ConfigException . NotResolved original ) { String newMessage = what . render ( ) + " has not been resolved, you need to call Config#resolve()," + " see API docs for Config#resolve()" ; if ( newMessage . equals ( original . getMessage ( ) ) ) return original ; else return new ConfigException . NotResolved ( newMessage , original ) ; } | further down on the stack . |
8,602 | public ConfigRenderOptions setFormatted ( boolean value ) { if ( value == formatted ) return this ; else return new ConfigRenderOptions ( originComments , comments , value , json ) ; } | Returns options with formatting toggled . Formatting means indentation and whitespace enabling formatting makes things prettier but larger . |
8,603 | private AbstractConfigObject rootMustBeObj ( Container value ) { if ( value instanceof AbstractConfigObject ) { return ( AbstractConfigObject ) value ; } else { return SimpleConfigObject . empty ( ) ; } } | object with nothing in it instead . |
8,604 | static private ResultWithPath findInObject ( AbstractConfigObject obj , ResolveContext context , Path path ) throws NotPossibleToResolve { if ( ConfigImpl . traceSubstitutionsEnabled ( ) ) ConfigImpl . trace ( "*** finding '" + path + "' in " + obj ) ; Path restriction = context . restrictToChild ( ) ; ResolveResult < ? extends AbstractConfigValue > partiallyResolved = context . restrict ( path ) . resolve ( obj , new ResolveSource ( obj ) ) ; ResolveContext newContext = partiallyResolved . context . restrict ( restriction ) ; if ( partiallyResolved . value instanceof AbstractConfigObject ) { ValueWithPath pair = findInObject ( ( AbstractConfigObject ) partiallyResolved . value , path ) ; return new ResultWithPath ( ResolveResult . make ( newContext , pair . value ) , pair . pathFromRoot ) ; } else { throw new ConfigException . BugOrBroken ( "resolved object to non-object " + obj + " to " + partiallyResolved ) ; } } | the ValueWithPath instance itself should not be . |
8,605 | private static Node < Container > replace ( Node < Container > list , Container old , AbstractConfigValue replacement ) { Container child = list . head ( ) ; if ( child != old ) throw new ConfigException . BugOrBroken ( "Can only replace() the top node we're resolving; had " + child + " on top and tried to replace " + old + " overall list was " + list ) ; Container parent = list . tail ( ) == null ? null : list . tail ( ) . head ( ) ; if ( replacement == null || ! ( replacement instanceof Container ) ) { if ( parent == null ) { return null ; } else { AbstractConfigValue newParent = parent . replaceChild ( ( AbstractConfigValue ) old , null ) ; return replace ( list . tail ( ) , parent , newParent ) ; } } else { if ( parent == null ) { return new Node < Container > ( ( Container ) replacement ) ; } else { AbstractConfigValue newParent = parent . replaceChild ( ( AbstractConfigValue ) old , replacement ) ; Node < Container > newTail = replace ( list . tail ( ) , parent , newParent ) ; if ( newTail != null ) return newTail . prepend ( ( Container ) replacement ) ; else return new Node < Container > ( ( Container ) replacement ) ; } } } | returns null if the replacement results in deleting all the nodes . |
8,606 | ResolveSource replaceWithinCurrentParent ( AbstractConfigValue old , AbstractConfigValue replacement ) { if ( ConfigImpl . traceSubstitutionsEnabled ( ) ) ConfigImpl . trace ( "replaceWithinCurrentParent old " + old + "@" + System . identityHashCode ( old ) + " replacement " + replacement + "@" + System . identityHashCode ( old ) + " in " + this ) ; if ( old == replacement ) { return this ; } else if ( pathFromRoot != null ) { Container parent = pathFromRoot . head ( ) ; AbstractConfigValue newParent = parent . replaceChild ( old , replacement ) ; return replaceCurrentParent ( parent , ( newParent instanceof Container ) ? ( Container ) newParent : null ) ; } else { if ( old == root && replacement instanceof Container ) { return new ResolveSource ( rootMustBeObj ( ( Container ) replacement ) ) ; } else { throw new ConfigException . BugOrBroken ( "replace in parent not possible " + old + " with " + replacement + " in " + this ) ; } } } | replacement may be null to delete |
8,607 | static Iterator < Token > tokenize ( ConfigOrigin origin , Reader input , ConfigSyntax flavor ) { return new TokenIterator ( origin , input , flavor != ConfigSyntax . JSON ) ; } | Tokenizes a Reader . Does not close the reader ; you have to arrange to do that after you re done with the returned iterator . |
8,608 | private static SimpleConfigOrigin mergeThree ( SimpleConfigOrigin a , SimpleConfigOrigin b , SimpleConfigOrigin c ) { if ( similarity ( a , b ) >= similarity ( b , c ) ) { return mergeTwo ( mergeTwo ( a , b ) , c ) ; } else { return mergeTwo ( a , mergeTwo ( b , c ) ) ; } } | better consolidated . |
8,609 | static Map < SerializedField , Object > fieldsDelta ( Map < SerializedField , Object > base , Map < SerializedField , Object > child ) { Map < SerializedField , Object > m = new EnumMap < SerializedField , Object > ( child ) ; for ( Map . Entry < SerializedField , Object > baseEntry : base . entrySet ( ) ) { SerializedField f = baseEntry . getKey ( ) ; if ( m . containsKey ( f ) && ConfigImplUtil . equalsHandlingNull ( baseEntry . getValue ( ) , m . get ( f ) ) ) { m . remove ( f ) ; } else if ( ! m . containsKey ( f ) ) { switch ( f ) { case ORIGIN_DESCRIPTION : throw new ConfigException . BugOrBroken ( "origin missing description field? " + child ) ; case ORIGIN_LINE_NUMBER : m . put ( SerializedField . ORIGIN_LINE_NUMBER , - 1 ) ; break ; case ORIGIN_END_LINE_NUMBER : m . put ( SerializedField . ORIGIN_END_LINE_NUMBER , - 1 ) ; break ; case ORIGIN_TYPE : throw new ConfigException . BugOrBroken ( "should always be an ORIGIN_TYPE field" ) ; case ORIGIN_URL : m . put ( SerializedField . ORIGIN_NULL_URL , "" ) ; break ; case ORIGIN_RESOURCE : m . put ( SerializedField . ORIGIN_NULL_RESOURCE , "" ) ; break ; case ORIGIN_COMMENTS : m . put ( SerializedField . ORIGIN_NULL_COMMENTS , "" ) ; break ; case ORIGIN_NULL_URL : case ORIGIN_NULL_RESOURCE : case ORIGIN_NULL_COMMENTS : throw new ConfigException . BugOrBroken ( "computing delta, base object should not contain " + f + " " + base ) ; case END_MARKER : case ROOT_VALUE : case ROOT_WAS_CONFIG : case UNKNOWN : case VALUE_DATA : case VALUE_ORIGIN : throw new ConfigException . BugOrBroken ( "should not appear here: " + f ) ; } } else { } } return m ; } | filename with every single value . |
8,610 | public DrawerBuilder withDrawerWidthDp ( int drawerWidthDp ) { if ( mActivity == null ) { throw new RuntimeException ( "please pass an activity first to use this call" ) ; } this . mDrawerWidth = Utils . convertDpToPx ( mActivity , drawerWidthDp ) ; return this ; } | Set the DrawerBuilder width with a dp value |
8,611 | private void addMenuItems ( Menu mMenu , boolean subMenu ) { int groupId = R . id . material_drawer_menu_default_group ; for ( int i = 0 ; i < mMenu . size ( ) ; i ++ ) { MenuItem mMenuItem = mMenu . getItem ( i ) ; IDrawerItem iDrawerItem ; if ( ! subMenu && mMenuItem . getGroupId ( ) != groupId && mMenuItem . getGroupId ( ) != 0 ) { groupId = mMenuItem . getGroupId ( ) ; iDrawerItem = new DividerDrawerItem ( ) ; getItemAdapter ( ) . add ( iDrawerItem ) ; } if ( mMenuItem . hasSubMenu ( ) ) { iDrawerItem = new PrimaryDrawerItem ( ) . withName ( mMenuItem . getTitle ( ) . toString ( ) ) . withIcon ( mMenuItem . getIcon ( ) ) . withIdentifier ( mMenuItem . getItemId ( ) ) . withEnabled ( mMenuItem . isEnabled ( ) ) . withSelectable ( false ) ; getItemAdapter ( ) . add ( iDrawerItem ) ; addMenuItems ( mMenuItem . getSubMenu ( ) , true ) ; } else if ( mMenuItem . getGroupId ( ) != 0 || subMenu ) { iDrawerItem = new SecondaryDrawerItem ( ) . withName ( mMenuItem . getTitle ( ) . toString ( ) ) . withIcon ( mMenuItem . getIcon ( ) ) . withIdentifier ( mMenuItem . getItemId ( ) ) . withEnabled ( mMenuItem . isEnabled ( ) ) ; getItemAdapter ( ) . add ( iDrawerItem ) ; } else { iDrawerItem = new PrimaryDrawerItem ( ) . withName ( mMenuItem . getTitle ( ) . toString ( ) ) . withIcon ( mMenuItem . getIcon ( ) ) . withIdentifier ( mMenuItem . getItemId ( ) ) . withEnabled ( mMenuItem . isEnabled ( ) ) ; getItemAdapter ( ) . add ( iDrawerItem ) ; } } } | helper method to init the drawerItems from a menu |
8,612 | private void handleShowOnLaunch ( ) { if ( mActivity != null && mDrawerLayout != null ) { if ( mShowDrawerOnFirstLaunch || mShowDrawerUntilDraggedOpened ) { final SharedPreferences preferences = mSharedPreferences != null ? mSharedPreferences : PreferenceManager . getDefaultSharedPreferences ( mActivity ) ; if ( mShowDrawerOnFirstLaunch && ! preferences . getBoolean ( Drawer . PREF_USER_LEARNED_DRAWER , false ) ) { mDrawerLayout . openDrawer ( mSliderLayout ) ; SharedPreferences . Editor editor = preferences . edit ( ) ; editor . putBoolean ( Drawer . PREF_USER_LEARNED_DRAWER , true ) ; editor . apply ( ) ; } else if ( mShowDrawerUntilDraggedOpened && ! preferences . getBoolean ( Drawer . PREF_USER_OPENED_DRAWER_BY_DRAGGING , false ) ) { mDrawerLayout . openDrawer ( mSliderLayout ) ; mDrawerLayout . addDrawerListener ( new DrawerLayout . SimpleDrawerListener ( ) { boolean hasBeenDragged = false ; public void onDrawerStateChanged ( int newState ) { if ( newState == DrawerLayout . STATE_DRAGGING ) { hasBeenDragged = true ; } else if ( newState == DrawerLayout . STATE_IDLE ) { if ( hasBeenDragged && mDrawerLayout . isDrawerOpen ( mDrawerGravity ) ) { SharedPreferences . Editor editor = preferences . edit ( ) ; editor . putBoolean ( Drawer . PREF_USER_OPENED_DRAWER_BY_DRAGGING , true ) ; editor . apply ( ) ; } else { hasBeenDragged = false ; } } } } ) ; } } } } | helper method to handle when the drawer should be shown on launch |
8,613 | public Drawer buildView ( ) { mSliderLayout = ( ScrimInsetsRelativeLayout ) mActivity . getLayoutInflater ( ) . inflate ( R . layout . material_drawer_slider , mDrawerLayout , false ) ; mSliderLayout . setBackgroundColor ( UIUtils . getThemeColorFromAttrOrRes ( mActivity , R . attr . material_drawer_background , R . color . material_drawer_background ) ) ; DrawerLayout . LayoutParams params = ( DrawerLayout . LayoutParams ) mSliderLayout . getLayoutParams ( ) ; if ( params != null ) { params . gravity = mDrawerGravity ; params = DrawerUtils . processDrawerLayoutParams ( this , params ) ; mSliderLayout . setLayoutParams ( params ) ; } createContent ( ) ; Drawer result = new Drawer ( this ) ; if ( mAccountHeader != null ) { mAccountHeader . setDrawer ( result ) ; } if ( mSavedInstance != null && mSavedInstance . getBoolean ( Drawer . BUNDLE_DRAWER_CONTENT_SWITCHED , false ) ) { mAccountHeader . toggleSelectionList ( mActivity ) ; } handleShowOnLaunch ( ) ; if ( ! mAppended && mGenerateMiniDrawer ) { mMiniDrawer = new MiniDrawer ( ) . withDrawer ( result ) . withAccountHeader ( mAccountHeader ) ; } mActivity = null ; return result ; } | build the drawers content only . This will still return a Result object but only with the content set . No inflating of a DrawerLayout . |
8,614 | protected void closeDrawerDelayed ( ) { if ( mCloseOnClick && mDrawerLayout != null ) { if ( mDelayOnDrawerClose > - 1 ) { new Handler ( ) . postDelayed ( new Runnable ( ) { public void run ( ) { mDrawerLayout . closeDrawers ( ) ; if ( mScrollToTopAfterClick ) { mRecyclerView . smoothScrollToPosition ( 0 ) ; } } } , mDelayOnDrawerClose ) ; } else { mDrawerLayout . closeDrawers ( ) ; } } } | helper method to close the drawer delayed |
8,615 | protected void resetStickyFooterSelection ( ) { if ( mStickyFooterView instanceof LinearLayout ) { for ( int i = 0 ; i < ( mStickyFooterView ) . getChildCount ( ) ; i ++ ) { ( mStickyFooterView ) . getChildAt ( i ) . setActivated ( false ) ; ( mStickyFooterView ) . getChildAt ( i ) . setSelected ( false ) ; } } } | simple helper method to reset the selection of the sticky footer |
8,616 | public void setActiveProfile ( IProfile profile , boolean fireOnProfileChanged ) { final boolean isCurrentSelectedProfile = mAccountHeaderBuilder . switchProfiles ( profile ) ; if ( mAccountHeaderBuilder . mDrawer != null && isSelectionListShown ( ) ) { mAccountHeaderBuilder . mDrawer . setSelection ( profile . getIdentifier ( ) , false ) ; } if ( fireOnProfileChanged && mAccountHeaderBuilder . mOnAccountHeaderListener != null ) { mAccountHeaderBuilder . mOnAccountHeaderListener . onProfileChanged ( null , profile , isCurrentSelectedProfile ) ; } } | Selects the given profile and sets it to the new active profile |
8,617 | public void setActiveProfile ( long identifier , boolean fireOnProfileChanged ) { if ( mAccountHeaderBuilder . mProfiles != null ) { for ( IProfile profile : mAccountHeaderBuilder . mProfiles ) { if ( profile != null ) { if ( profile . getIdentifier ( ) == identifier ) { setActiveProfile ( profile , fireOnProfileChanged ) ; return ; } } } } } | Selects a profile by its identifier |
8,618 | public void removeProfile ( int position ) { if ( mAccountHeaderBuilder . mProfiles != null && mAccountHeaderBuilder . mProfiles . size ( ) > position ) { mAccountHeaderBuilder . mProfiles . remove ( position ) ; } mAccountHeaderBuilder . updateHeaderAndList ( ) ; } | remove a profile from the given position |
8,619 | public void removeProfileByIdentifier ( long identifier ) { int found = getPositionByIdentifier ( identifier ) ; if ( found > - 1 ) { mAccountHeaderBuilder . mProfiles . remove ( found ) ; } mAccountHeaderBuilder . updateHeaderAndList ( ) ; } | remove the profile with the given identifier |
8,620 | private int getPositionByIdentifier ( long identifier ) { int found = - 1 ; if ( mAccountHeaderBuilder . mProfiles != null && identifier != - 1 ) { for ( int i = 0 ; i < mAccountHeaderBuilder . mProfiles . size ( ) ; i ++ ) { if ( mAccountHeaderBuilder . mProfiles . get ( i ) != null ) { if ( mAccountHeaderBuilder . mProfiles . get ( i ) . getIdentifier ( ) == identifier ) { found = i ; break ; } } } } return found ; } | gets the position of a profile by it s identifier |
8,621 | public void setSelectorColor ( int selectorColor ) { this . mSelectorColor = selectorColor ; this . mSelectorFilter = new PorterDuffColorFilter ( Color . argb ( mSelectorAlpha , Color . red ( mSelectorColor ) , Color . green ( mSelectorColor ) , Color . blue ( mSelectorColor ) ) , PorterDuff . Mode . SRC_ATOP ) ; this . invalidate ( ) ; } | Sets the color of the selector to be draw over the CircularImageView . Be sure to provide some opacity . |
8,622 | public IDrawerItem generateMiniDrawerItem ( IDrawerItem drawerItem ) { if ( drawerItem instanceof SecondaryDrawerItem ) { return mIncludeSecondaryDrawerItems ? new MiniDrawerItem ( ( SecondaryDrawerItem ) drawerItem ) . withEnableSelectedBackground ( mEnableSelectedMiniDrawerItemBackground ) . withSelectedBackgroundAnimated ( false ) : null ; } else if ( drawerItem instanceof PrimaryDrawerItem ) { return new MiniDrawerItem ( ( PrimaryDrawerItem ) drawerItem ) . withEnableSelectedBackground ( mEnableSelectedMiniDrawerItemBackground ) . withSelectedBackgroundAnimated ( false ) ; } else if ( drawerItem instanceof ProfileDrawerItem ) { MiniProfileDrawerItem mpdi = new MiniProfileDrawerItem ( ( ProfileDrawerItem ) drawerItem ) ; mpdi . withEnabled ( mEnableProfileClick ) ; return mpdi ; } return null ; } | generates a MiniDrawerItem from a IDrawerItem |
8,623 | public View build ( Context ctx ) { mContainer = new LinearLayout ( ctx ) ; if ( mInnerShadow ) { if ( ! mInRTL ) { mContainer . setBackgroundResource ( R . drawable . material_drawer_shadow_left ) ; } else { mContainer . setBackgroundResource ( R . drawable . material_drawer_shadow_right ) ; } } mRecyclerView = new RecyclerView ( ctx ) ; mContainer . addView ( mRecyclerView , ViewGroup . LayoutParams . MATCH_PARENT , ViewGroup . LayoutParams . MATCH_PARENT ) ; mRecyclerView . setItemAnimator ( new DefaultItemAnimator ( ) ) ; mRecyclerView . setFadingEdgeLength ( 0 ) ; mRecyclerView . setClipToPadding ( false ) ; mRecyclerView . setLayoutManager ( new LinearLayoutManager ( ctx ) ) ; mItemAdapter = new ItemAdapter < > ( ) ; mAdapter = FastAdapter . with ( mItemAdapter ) ; mAdapter . withSelectable ( true ) ; mAdapter . withAllowDeselection ( false ) ; mRecyclerView . setAdapter ( mAdapter ) ; if ( mDrawer != null && mDrawer . mDrawerBuilder != null && ( mDrawer . mDrawerBuilder . mFullscreen || mDrawer . mDrawerBuilder . mTranslucentStatusBar ) ) { mRecyclerView . setPadding ( mRecyclerView . getPaddingLeft ( ) , UIUtils . getStatusBarHeight ( ctx ) , mRecyclerView . getPaddingRight ( ) , mRecyclerView . getPaddingBottom ( ) ) ; } if ( mDrawer != null && mDrawer . mDrawerBuilder != null && ( mDrawer . mDrawerBuilder . mFullscreen || mDrawer . mDrawerBuilder . mTranslucentNavigationBar ) && ctx . getResources ( ) . getConfiguration ( ) . orientation == Configuration . ORIENTATION_PORTRAIT ) { mRecyclerView . setPadding ( mRecyclerView . getPaddingLeft ( ) , mRecyclerView . getPaddingTop ( ) , mRecyclerView . getPaddingRight ( ) , UIUtils . getNavigationBarHeight ( ctx ) ) ; } createItems ( ) ; return mContainer ; } | build the MiniDrawer |
8,624 | public void onProfileClick ( ) { if ( mCrossFader != null ) { if ( mCrossFader . isCrossfaded ( ) ) { mCrossFader . crossfade ( ) ; } } if ( mAccountHeader != null ) { IProfile profile = mAccountHeader . getActiveProfile ( ) ; if ( profile instanceof IDrawerItem ) { mItemAdapter . set ( 0 , generateMiniDrawerItem ( ( IDrawerItem ) profile ) ) ; } } } | call this method to trigger the onProfileClick on the MiniDrawer |
8,625 | public boolean onItemClick ( IDrawerItem selectedDrawerItem ) { if ( selectedDrawerItem . isSelectable ( ) ) { if ( mCrossFader != null ) { if ( mCrossFader . isCrossfaded ( ) ) { mCrossFader . crossfade ( ) ; } } setSelection ( selectedDrawerItem . getIdentifier ( ) ) ; return false ; } else { return true ; } } | call this method to trigger the onItemClick on the MiniDrawer |
8,626 | public void setSelection ( long identifier ) { if ( identifier == - 1 ) { mAdapter . deselect ( ) ; } int count = mAdapter . getItemCount ( ) ; for ( int i = 0 ; i < count ; i ++ ) { IDrawerItem item = mAdapter . getItem ( i ) ; if ( item . getIdentifier ( ) == identifier && ! item . isSelected ( ) ) { mAdapter . deselect ( ) ; mAdapter . select ( i ) ; } } } | set the selection of the MiniDrawer |
8,627 | public void createItems ( ) { mItemAdapter . clear ( ) ; int profileOffset = 0 ; if ( mAccountHeader != null && mAccountHeader . getAccountHeaderBuilder ( ) . mProfileImagesVisible ) { IProfile profile = mAccountHeader . getActiveProfile ( ) ; if ( profile instanceof IDrawerItem ) { mItemAdapter . add ( generateMiniDrawerItem ( ( IDrawerItem ) profile ) ) ; profileOffset = 1 ; } } int select = - 1 ; if ( mDrawer != null ) { if ( getDrawerItems ( ) != null ) { int length = getDrawerItems ( ) . size ( ) ; int position = 0 ; for ( int i = 0 ; i < length ; i ++ ) { IDrawerItem miniDrawerItem = generateMiniDrawerItem ( getDrawerItems ( ) . get ( i ) ) ; if ( miniDrawerItem != null ) { if ( miniDrawerItem . isSelected ( ) ) { select = position ; } mItemAdapter . add ( miniDrawerItem ) ; position = position + 1 ; } } if ( select >= 0 ) { mAdapter . select ( select + profileOffset ) ; } } } if ( mOnMiniDrawerItemOnClickListener != null ) { mAdapter . withOnClickListener ( mOnMiniDrawerItemOnClickListener ) ; } else { mAdapter . withOnClickListener ( new OnClickListener < IDrawerItem > ( ) { public boolean onClick ( View v , IAdapter < IDrawerItem > adapter , final IDrawerItem item , final int position ) { int type = getMiniDrawerType ( item ) ; if ( mOnMiniDrawerItemClickListener != null && mOnMiniDrawerItemClickListener . onItemClick ( v , position , item , type ) ) { return false ; } if ( type == ITEM ) { if ( item . isSelectable ( ) ) { if ( mAccountHeader != null && mAccountHeader . isSelectionListShown ( ) ) { mAccountHeader . toggleSelectionList ( v . getContext ( ) ) ; } IDrawerItem drawerItem = mDrawer . getDrawerItem ( item . getIdentifier ( ) ) ; if ( drawerItem != null && ! drawerItem . isSelected ( ) ) { mDrawer . setSelection ( item , true ) ; } } else if ( mDrawer . getOnDrawerItemClickListener ( ) != null ) { mDrawer . getOnDrawerItemClickListener ( ) . onItemClick ( v , position , DrawerUtils . getDrawerItem ( getDrawerItems ( ) , item . getIdentifier ( ) ) ) ; } } else if ( type == PROFILE ) { if ( mAccountHeader != null && ! mAccountHeader . isSelectionListShown ( ) ) { mAccountHeader . toggleSelectionList ( v . getContext ( ) ) ; } if ( mCrossFader != null ) { mCrossFader . crossfade ( ) ; } } return false ; } } ) ; } mAdapter . withOnLongClickListener ( mOnMiniDrawerItemLongClickListener ) ; mRecyclerView . scrollToPosition ( 0 ) ; } | creates the items for the MiniDrawer |
8,628 | private List < IDrawerItem > getDrawerItems ( ) { return mDrawer . getOriginalDrawerItems ( ) != null ? mDrawer . getOriginalDrawerItems ( ) : mDrawer . getDrawerItems ( ) ; } | returns always the original drawerItems and not the switched content |
8,629 | private void setHeaderHeight ( int height ) { if ( mAccountHeaderContainer != null ) { ViewGroup . LayoutParams params = mAccountHeaderContainer . getLayoutParams ( ) ; if ( params != null ) { params . height = height ; mAccountHeaderContainer . setLayoutParams ( params ) ; } View accountHeader = mAccountHeaderContainer . findViewById ( R . id . material_drawer_account_header ) ; if ( accountHeader != null ) { params = accountHeader . getLayoutParams ( ) ; if ( params != null ) { params . height = height ; accountHeader . setLayoutParams ( params ) ; } } View accountHeaderBackground = mAccountHeaderContainer . findViewById ( R . id . material_drawer_account_header_background ) ; if ( accountHeaderBackground != null ) { params = accountHeaderBackground . getLayoutParams ( ) ; params . height = height ; accountHeaderBackground . setLayoutParams ( params ) ; } } } | helper method to set the height for the header! |
8,630 | private void handleSelectionView ( IProfile profile , boolean on ) { if ( on ) { if ( Build . VERSION . SDK_INT >= 23 ) { mAccountHeaderContainer . setForeground ( AppCompatResources . getDrawable ( mAccountHeaderContainer . getContext ( ) , mAccountHeaderTextSectionBackgroundResource ) ) ; } else { } mAccountHeaderContainer . setOnClickListener ( onSelectionClickListener ) ; mAccountHeaderContainer . setTag ( R . id . material_drawer_profile_header , profile ) ; } else { if ( Build . VERSION . SDK_INT >= 23 ) { mAccountHeaderContainer . setForeground ( null ) ; } else { } mAccountHeaderContainer . setOnClickListener ( null ) ; } } | a small helper to handle the selectionView |
8,631 | protected boolean switchProfiles ( IProfile newSelection ) { if ( newSelection == null ) { return false ; } if ( mCurrentProfile == newSelection ) { return true ; } if ( mAlternativeProfileHeaderSwitching ) { int prevSelection = - 1 ; if ( mProfileFirst == newSelection ) { prevSelection = 1 ; } else if ( mProfileSecond == newSelection ) { prevSelection = 2 ; } else if ( mProfileThird == newSelection ) { prevSelection = 3 ; } IProfile tmp = mCurrentProfile ; mCurrentProfile = newSelection ; if ( prevSelection == 1 ) { mProfileFirst = tmp ; } else if ( prevSelection == 2 ) { mProfileSecond = tmp ; } else if ( prevSelection == 3 ) { mProfileThird = tmp ; } } else { if ( mProfiles != null ) { ArrayList < IProfile > previousActiveProfiles = new ArrayList < > ( Arrays . asList ( mCurrentProfile , mProfileFirst , mProfileSecond , mProfileThird ) ) ; if ( previousActiveProfiles . contains ( newSelection ) ) { int position = - 1 ; for ( int i = 0 ; i < 4 ; i ++ ) { if ( previousActiveProfiles . get ( i ) == newSelection ) { position = i ; break ; } } if ( position != - 1 ) { previousActiveProfiles . remove ( position ) ; previousActiveProfiles . add ( 0 , newSelection ) ; mCurrentProfile = previousActiveProfiles . get ( 0 ) ; mProfileFirst = previousActiveProfiles . get ( 1 ) ; mProfileSecond = previousActiveProfiles . get ( 2 ) ; mProfileThird = previousActiveProfiles . get ( 3 ) ; } } else { mProfileThird = mProfileSecond ; mProfileSecond = mProfileFirst ; mProfileFirst = mCurrentProfile ; mCurrentProfile = newSelection ; } } } if ( mOnlySmallProfileImagesVisible ) { mProfileThird = mProfileSecond ; mProfileSecond = mProfileFirst ; mProfileFirst = mCurrentProfile ; } buildProfiles ( ) ; return false ; } | helper method to switch the profiles |
8,632 | private void setImageOrPlaceholder ( ImageView iv , ImageHolder imageHolder ) { DrawerImageLoader . getInstance ( ) . cancelImage ( iv ) ; iv . setImageDrawable ( DrawerImageLoader . getInstance ( ) . getImageLoader ( ) . placeholder ( iv . getContext ( ) , DrawerImageLoader . Tags . PROFILE . name ( ) ) ) ; ImageHolder . applyTo ( imageHolder , iv , DrawerImageLoader . Tags . PROFILE . name ( ) ) ; } | small helper method to set an profile image or a placeholder |
8,633 | private void onProfileImageClick ( View v , boolean current ) { IProfile profile = ( IProfile ) v . getTag ( R . id . material_drawer_profile_header ) ; boolean consumed = false ; if ( mOnAccountHeaderProfileImageListener != null ) { consumed = mOnAccountHeaderProfileImageListener . onProfileImageClick ( v , profile , current ) ; } if ( ! consumed ) { onProfileClick ( v , current ) ; } } | calls the mOnAccountHEaderProfileImageListener and continues with the actions afterwards |
8,634 | protected int getCurrentSelection ( ) { if ( mCurrentProfile != null && mProfiles != null ) { int i = 0 ; for ( IProfile profile : mProfiles ) { if ( profile == mCurrentProfile ) { return i ; } i ++ ; } } return - 1 ; } | get the current selection |
8,635 | protected void toggleSelectionList ( Context ctx ) { if ( mDrawer != null ) { if ( mDrawer . switchedDrawerContent ( ) ) { resetDrawerContent ( ctx ) ; mSelectionListShown = false ; } else { buildDrawerSelectionList ( ) ; mAccountSwitcherArrow . clearAnimation ( ) ; ViewCompat . animate ( mAccountSwitcherArrow ) . rotation ( 180 ) . start ( ) ; mSelectionListShown = true ; } } } | helper method to toggle the collection |
8,636 | protected void buildDrawerSelectionList ( ) { int selectedPosition = - 1 ; int position = 0 ; ArrayList < IDrawerItem > profileDrawerItems = new ArrayList < > ( ) ; if ( mProfiles != null ) { for ( IProfile profile : mProfiles ) { if ( profile == mCurrentProfile ) { if ( mCurrentHiddenInList ) { continue ; } else { selectedPosition = mDrawer . mDrawerBuilder . getItemAdapter ( ) . getGlobalPosition ( position ) ; } } if ( profile instanceof IDrawerItem ) { ( ( IDrawerItem ) profile ) . withSetSelected ( false ) ; profileDrawerItems . add ( ( IDrawerItem ) profile ) ; } position = position + 1 ; } } mDrawer . switchDrawerContent ( onDrawerItemClickListener , onDrawerItemLongClickListener , profileDrawerItems , selectedPosition ) ; } | helper method to build and set the drawer selection list |
8,637 | private void resetDrawerContent ( Context ctx ) { if ( mDrawer != null ) { mDrawer . resetDrawerContent ( ) ; } mAccountSwitcherArrow . clearAnimation ( ) ; ViewCompat . animate ( mAccountSwitcherArrow ) . rotation ( 0 ) . start ( ) ; } | helper method to reset the drawer content |
8,638 | public boolean isDrawerOpen ( ) { if ( mDrawerBuilder . mDrawerLayout != null && mDrawerBuilder . mSliderLayout != null ) { return mDrawerBuilder . mDrawerLayout . isDrawerOpen ( mDrawerBuilder . mDrawerGravity ) ; } return false ; } | Get the current state of the drawer . True if the drawer is currently open . |
8,639 | public MiniDrawer getMiniDrawer ( ) { if ( mDrawerBuilder . mMiniDrawer == null ) { mDrawerBuilder . mMiniDrawer = new MiniDrawer ( ) . withDrawer ( this ) . withAccountHeader ( mDrawerBuilder . mAccountHeader ) ; } return mDrawerBuilder . mMiniDrawer ; } | gets the already generated MiniDrawer or creates a new one |
8,640 | public FrameLayout getContent ( ) { if ( mContentView == null && this . mDrawerBuilder . mDrawerLayout != null ) { mContentView = ( FrameLayout ) this . mDrawerBuilder . mDrawerLayout . findViewById ( R . id . content_layout ) ; } return mContentView ; } | get the container frameLayout of the current drawer |
8,641 | public void setGravity ( int gravity ) { DrawerLayout . LayoutParams params = ( DrawerLayout . LayoutParams ) getSlider ( ) . getLayoutParams ( ) ; params . gravity = gravity ; getSlider ( ) . setLayoutParams ( params ) ; mDrawerBuilder . mDrawerGravity = gravity ; } | sets the gravity for this drawer . |
8,642 | public IDrawerItem getDrawerItem ( long identifier ) { Pair < IDrawerItem , Integer > res = getAdapter ( ) . getItemById ( identifier ) ; if ( res != null ) { return res . first ; } else { return null ; } } | returns the DrawerItem by the given identifier |
8,643 | public int getCurrentSelectedPosition ( ) { return mDrawerBuilder . mAdapter . getSelections ( ) . size ( ) == 0 ? - 1 : mDrawerBuilder . mAdapter . getSelections ( ) . iterator ( ) . next ( ) ; } | get the current position of the selected drawer element |
8,644 | public long getCurrentSelection ( ) { IDrawerItem drawerItem = mDrawerBuilder . getDrawerItem ( getCurrentSelectedPosition ( ) ) ; if ( drawerItem != null ) { return drawerItem . getIdentifier ( ) ; } return - 1 ; } | get the current selected item identifier |
8,645 | public void updateBadge ( long identifier , StringHolder badge ) { IDrawerItem drawerItem = getDrawerItem ( identifier ) ; if ( drawerItem instanceof Badgeable ) { Badgeable badgeable = ( Badgeable ) drawerItem ; badgeable . withBadge ( badge ) ; updateItem ( ( IDrawerItem ) badgeable ) ; } } | update the badge for a specific drawerItem identified by its id |
8,646 | public void removeItemByPosition ( int position ) { if ( mDrawerBuilder . checkDrawerItem ( position , false ) ) { mDrawerBuilder . getItemAdapter ( ) . remove ( position ) ; } } | Remove a drawerItem at a specific position |
8,647 | public void removeStickyFooterItemAtPosition ( int position ) { if ( mDrawerBuilder . mStickyDrawerItems != null && mDrawerBuilder . mStickyDrawerItems . size ( ) > position ) { mDrawerBuilder . mStickyDrawerItems . remove ( position ) ; } DrawerUtils . rebuildStickyFooterView ( mDrawerBuilder ) ; } | Remove a footerDrawerItem at a specific position |
8,648 | public void removeAllStickyFooterItems ( ) { if ( mDrawerBuilder . mStickyDrawerItems != null ) { mDrawerBuilder . mStickyDrawerItems . clear ( ) ; } if ( mDrawerBuilder . mStickyFooterView != null ) { mDrawerBuilder . mStickyFooterView . setVisibility ( View . GONE ) ; } } | Removes all footerItems from drawer |
8,649 | public void resetDrawerContent ( ) { if ( switchedDrawerContent ( ) ) { setOnDrawerItemClickListener ( originalOnDrawerItemClickListener ) ; setOnDrawerItemLongClickListener ( originalOnDrawerItemLongClickListener ) ; setItems ( originalDrawerItems , true ) ; getAdapter ( ) . withSavedInstanceState ( originalDrawerState ) ; originalOnDrawerItemClickListener = null ; originalOnDrawerItemLongClickListener = null ; originalDrawerItems = null ; originalDrawerState = null ; mDrawerBuilder . mRecyclerView . smoothScrollToPosition ( 0 ) ; if ( getStickyFooter ( ) != null ) { getStickyFooter ( ) . setVisibility ( View . VISIBLE ) ; } if ( getStickyFooterShadow ( ) != null ) { getStickyFooterShadow ( ) . setVisibility ( View . VISIBLE ) ; } if ( mDrawerBuilder . mAccountHeader != null && mDrawerBuilder . mAccountHeader . mAccountHeaderBuilder != null ) { mDrawerBuilder . mAccountHeader . mAccountHeaderBuilder . mSelectionListShown = false ; } } } | helper method to reset to the original drawerContent |
8,650 | public static ColorStateList getTextColorStateList ( int text_color , int selected_text_color ) { return new ColorStateList ( new int [ ] [ ] { new int [ ] { android . R . attr . state_selected } , new int [ ] { } } , new int [ ] { selected_text_color , text_color } ) ; } | helper to create a colorStateList for the text |
8,651 | public static StateListDrawable getIconStateList ( Drawable icon , Drawable selectedIcon ) { StateListDrawable iconStateListDrawable = new StateListDrawable ( ) ; iconStateListDrawable . addState ( new int [ ] { android . R . attr . state_selected } , selectedIcon ) ; iconStateListDrawable . addState ( new int [ ] { } , icon ) ; return iconStateListDrawable ; } | helper to create a stateListDrawable for the icon |
8,652 | public static StateListDrawable getDrawerItemBackground ( int selected_color ) { ColorDrawable clrActive = new ColorDrawable ( selected_color ) ; StateListDrawable states = new StateListDrawable ( ) ; states . addState ( new int [ ] { android . R . attr . state_selected } , clrActive ) ; return states ; } | helper to create a StateListDrawable for the drawer item background |
8,653 | public static int getOptimalDrawerWidth ( Context context ) { int possibleMinDrawerWidth = UIUtils . getScreenWidth ( context ) - UIUtils . getActionBarHeight ( context ) ; int maxDrawerWidth = context . getResources ( ) . getDimensionPixelSize ( R . dimen . material_drawer_width ) ; return Math . min ( possibleMinDrawerWidth , maxDrawerWidth ) ; } | helper to calculate the optimal drawer width |
8,654 | public static Drawable getPlaceHolder ( Context ctx ) { return new IconicsDrawable ( ctx , MaterialDrawerFont . Icon . mdf_person ) . colorRes ( R . color . accent ) . backgroundColorRes ( R . color . primary ) . sizeDp ( 56 ) . paddingDp ( 16 ) ; } | helper method to get a person placeHolder drawable |
8,655 | public static void setDrawerVerticalPadding ( View v ) { int verticalPadding = v . getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . material_drawer_vertical_padding ) ; v . setPadding ( verticalPadding , 0 , verticalPadding , 0 ) ; } | helper to set the vertical padding to the DrawerItems this is required because on API Level 17 the padding is ignored which is set via the XML |
8,656 | public static void setDrawerVerticalPadding ( View v , int level ) { int verticalPadding = v . getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . material_drawer_vertical_padding ) ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . JELLY_BEAN_MR1 ) { v . setPaddingRelative ( verticalPadding * level , 0 , verticalPadding , 0 ) ; } else { v . setPadding ( verticalPadding * level , 0 , verticalPadding , 0 ) ; } } | helper to set the vertical padding including the extra padding for deeper item hirachy level to the DrawerItems this is required because on API Level 17 the padding is ignored which is set via the XML |
8,657 | public static boolean isSystemBarOnBottom ( Context ctx ) { WindowManager wm = ( WindowManager ) ctx . getSystemService ( Context . WINDOW_SERVICE ) ; DisplayMetrics metrics = new DisplayMetrics ( ) ; wm . getDefaultDisplay ( ) . getMetrics ( metrics ) ; Configuration cfg = ctx . getResources ( ) . getConfiguration ( ) ; boolean canMove = ( metrics . widthPixels != metrics . heightPixels && cfg . smallestScreenWidthDp < 600 ) ; return ( ! canMove || metrics . widthPixels < metrics . heightPixels ) ; } | helper to check if the system bar is on the bottom of the screen |
8,658 | public void onPostBindView ( IDrawerItem drawerItem , View view ) { if ( mOnPostBindViewListener != null ) { mOnPostBindViewListener . onBindView ( drawerItem , view ) ; } } | is called after bindView to allow some post creation setps |
8,659 | public VH getViewHolder ( ViewGroup parent ) { return getViewHolder ( LayoutInflater . from ( parent . getContext ( ) ) . inflate ( getLayoutRes ( ) , parent , false ) ) ; } | This method returns the ViewHolder for our item using the provided View . |
8,660 | protected int getColor ( Context ctx ) { int color ; if ( this . isEnabled ( ) ) { color = ColorHolder . color ( getTextColor ( ) , ctx , R . attr . material_drawer_secondary_text , R . color . material_drawer_secondary_text ) ; } else { color = ColorHolder . color ( getDisabledTextColor ( ) , ctx , R . attr . material_drawer_hint_text , R . color . material_drawer_hint_text ) ; } return color ; } | helper method to decide for the correct color OVERWRITE to get the correct secondary color |
8,661 | public static void onFooterDrawerItemClick ( DrawerBuilder drawer , IDrawerItem drawerItem , View v , Boolean fireOnClick ) { boolean checkable = ! ( drawerItem != null && drawerItem instanceof Selectable && ! drawerItem . isSelectable ( ) ) ; if ( checkable ) { drawer . resetStickyFooterSelection ( ) ; v . setActivated ( true ) ; v . setSelected ( true ) ; drawer . getAdapter ( ) . deselect ( ) ; if ( drawer . mStickyFooterView != null && drawer . mStickyFooterView instanceof LinearLayout ) { LinearLayout footer = ( LinearLayout ) drawer . mStickyFooterView ; for ( int i = 0 ; i < footer . getChildCount ( ) ; i ++ ) { if ( footer . getChildAt ( i ) == v ) { drawer . mCurrentStickyFooterSelection = i ; break ; } } } } if ( fireOnClick != null ) { boolean consumed = false ; if ( fireOnClick ) { if ( drawerItem instanceof AbstractDrawerItem && ( ( AbstractDrawerItem ) drawerItem ) . getOnDrawerItemClickListener ( ) != null ) { consumed = ( ( AbstractDrawerItem ) drawerItem ) . getOnDrawerItemClickListener ( ) . onItemClick ( v , - 1 , drawerItem ) ; } if ( drawer . mOnDrawerItemClickListener != null ) { consumed = drawer . mOnDrawerItemClickListener . onItemClick ( v , - 1 , drawerItem ) ; } } if ( ! consumed ) { drawer . closeDrawerDelayed ( ) ; } } } | helper method to handle the onClick of the footer |
8,662 | public static void setStickyFooterSelection ( DrawerBuilder drawer , int position , Boolean fireOnClick ) { if ( position > - 1 ) { if ( drawer . mStickyFooterView != null && drawer . mStickyFooterView instanceof LinearLayout ) { LinearLayout footer = ( LinearLayout ) drawer . mStickyFooterView ; if ( drawer . mStickyFooterDivider ) { position = position + 1 ; } if ( footer . getChildCount ( ) > position && position >= 0 ) { IDrawerItem drawerItem = ( IDrawerItem ) footer . getChildAt ( position ) . getTag ( R . id . material_drawer_item ) ; onFooterDrawerItemClick ( drawer , drawerItem , footer . getChildAt ( position ) , fireOnClick ) ; } } } } | helper method to set the selection of the footer |
8,663 | public static int getPositionByIdentifier ( DrawerBuilder drawer , long identifier ) { if ( identifier != - 1 ) { for ( int i = 0 ; i < drawer . getAdapter ( ) . getItemCount ( ) ; i ++ ) { if ( drawer . getAdapter ( ) . getItem ( i ) . getIdentifier ( ) == identifier ) { return i ; } } } return - 1 ; } | calculates the position of an drawerItem . searching by it s identifier |
8,664 | public static IDrawerItem getDrawerItem ( List < IDrawerItem > drawerItems , long identifier ) { if ( identifier != - 1 ) { for ( IDrawerItem drawerItem : drawerItems ) { if ( drawerItem . getIdentifier ( ) == identifier ) { return drawerItem ; } } } return null ; } | gets the drawerItem with the specific identifier from a drawerItem list |
8,665 | public static IDrawerItem getDrawerItem ( List < IDrawerItem > drawerItems , Object tag ) { if ( tag != null ) { for ( IDrawerItem drawerItem : drawerItems ) { if ( tag . equals ( drawerItem . getTag ( ) ) ) { return drawerItem ; } } } return null ; } | gets the drawerItem by a defined tag from a drawerItem list |
8,666 | public static int getStickyFooterPositionByIdentifier ( DrawerBuilder drawer , long identifier ) { if ( identifier != - 1 ) { if ( drawer . mStickyFooterView != null && drawer . mStickyFooterView instanceof LinearLayout ) { LinearLayout footer = ( LinearLayout ) drawer . mStickyFooterView ; int shadowOffset = 0 ; for ( int i = 0 ; i < footer . getChildCount ( ) ; i ++ ) { Object o = footer . getChildAt ( i ) . getTag ( R . id . material_drawer_item ) ; if ( o == null && drawer . mStickyFooterDivider ) { shadowOffset = shadowOffset + 1 ; } if ( o != null && o instanceof IDrawerItem && ( ( IDrawerItem ) o ) . getIdentifier ( ) == identifier ) { return i - shadowOffset ; } } } } return - 1 ; } | calculates the position of an drawerItem inside the footer . searching by it s identifier |
8,667 | public static void rebuildStickyFooterView ( final DrawerBuilder drawer ) { if ( drawer . mSliderLayout != null ) { if ( drawer . mStickyFooterView != null ) { drawer . mStickyFooterView . removeAllViews ( ) ; if ( drawer . mStickyFooterDivider ) { addStickyFooterDivider ( drawer . mStickyFooterView . getContext ( ) , drawer . mStickyFooterView ) ; } DrawerUtils . fillStickyDrawerItemFooter ( drawer , drawer . mStickyFooterView , new View . OnClickListener ( ) { public void onClick ( View v ) { IDrawerItem drawerItem = ( IDrawerItem ) v . getTag ( R . id . material_drawer_item ) ; com . mikepenz . materialdrawer . DrawerUtils . onFooterDrawerItemClick ( drawer , drawerItem , v , true ) ; } } ) ; drawer . mStickyFooterView . setVisibility ( View . VISIBLE ) ; } else { DrawerUtils . handleFooterView ( drawer , new View . OnClickListener ( ) { public void onClick ( View v ) { IDrawerItem drawerItem = ( IDrawerItem ) v . getTag ( R . id . material_drawer_item ) ; DrawerUtils . onFooterDrawerItemClick ( drawer , drawerItem , v , true ) ; } } ) ; } setStickyFooterSelection ( drawer , drawer . mCurrentStickyFooterSelection , false ) ; } } | small helper to rebuild the FooterView |
8,668 | public static void handleFooterView ( DrawerBuilder drawer , View . OnClickListener onClickListener ) { Context ctx = drawer . mSliderLayout . getContext ( ) ; if ( drawer . mStickyDrawerItems != null && drawer . mStickyDrawerItems . size ( ) > 0 ) { drawer . mStickyFooterView = DrawerUtils . buildStickyDrawerItemFooter ( ctx , drawer , onClickListener ) ; } if ( drawer . mStickyFooterView != null ) { RelativeLayout . LayoutParams layoutParams = new RelativeLayout . LayoutParams ( RelativeLayout . LayoutParams . MATCH_PARENT , RelativeLayout . LayoutParams . WRAP_CONTENT ) ; layoutParams . addRule ( RelativeLayout . ALIGN_PARENT_BOTTOM , 1 ) ; drawer . mStickyFooterView . setId ( R . id . material_drawer_sticky_footer ) ; drawer . mSliderLayout . addView ( drawer . mStickyFooterView , layoutParams ) ; if ( ( drawer . mTranslucentNavigationBar || drawer . mFullscreen ) && Build . VERSION . SDK_INT >= 19 ) { drawer . mStickyFooterView . setPadding ( 0 , 0 , 0 , UIUtils . getNavigationBarHeight ( ctx ) ) ; } RelativeLayout . LayoutParams layoutParamsListView = ( RelativeLayout . LayoutParams ) drawer . mRecyclerView . getLayoutParams ( ) ; layoutParamsListView . addRule ( RelativeLayout . ABOVE , R . id . material_drawer_sticky_footer ) ; drawer . mRecyclerView . setLayoutParams ( layoutParamsListView ) ; if ( drawer . mStickyFooterShadow ) { drawer . mStickyFooterShadowView = new View ( ctx ) ; drawer . mStickyFooterShadowView . setBackgroundResource ( R . drawable . material_drawer_shadow_top ) ; drawer . mSliderLayout . addView ( drawer . mStickyFooterShadowView , RelativeLayout . LayoutParams . MATCH_PARENT , ctx . getResources ( ) . getDimensionPixelSize ( R . dimen . material_drawer_sticky_footer_elevation ) ) ; RelativeLayout . LayoutParams lps = ( RelativeLayout . LayoutParams ) drawer . mStickyFooterShadowView . getLayoutParams ( ) ; lps . addRule ( RelativeLayout . ABOVE , R . id . material_drawer_sticky_footer ) ; drawer . mStickyFooterShadowView . setLayoutParams ( lps ) ; } drawer . mRecyclerView . setPadding ( drawer . mRecyclerView . getPaddingLeft ( ) , drawer . mRecyclerView . getPaddingTop ( ) , drawer . mRecyclerView . getPaddingRight ( ) , ctx . getResources ( ) . getDimensionPixelSize ( R . dimen . material_drawer_padding ) ) ; } if ( drawer . mFooterView != null ) { if ( drawer . mRecyclerView == null ) { throw new RuntimeException ( "can't use a footerView without a recyclerView" ) ; } if ( drawer . mFooterDivider ) { drawer . getFooterAdapter ( ) . add ( new ContainerDrawerItem ( ) . withView ( drawer . mFooterView ) . withViewPosition ( ContainerDrawerItem . Position . BOTTOM ) ) ; } else { drawer . getFooterAdapter ( ) . add ( new ContainerDrawerItem ( ) . withView ( drawer . mFooterView ) . withViewPosition ( ContainerDrawerItem . Position . NONE ) ) ; } } } | helper method to handle the footerView |
8,669 | public static ViewGroup buildStickyDrawerItemFooter ( Context ctx , DrawerBuilder drawer , View . OnClickListener onClickListener ) { final LinearLayout linearLayout = new LinearLayout ( ctx ) ; linearLayout . setLayoutParams ( new LinearLayout . LayoutParams ( ViewGroup . LayoutParams . MATCH_PARENT , ViewGroup . LayoutParams . WRAP_CONTENT ) ) ; linearLayout . setOrientation ( LinearLayout . VERTICAL ) ; linearLayout . setBackgroundColor ( UIUtils . getThemeColorFromAttrOrRes ( ctx , R . attr . material_drawer_background , R . color . material_drawer_background ) ) ; if ( drawer . mStickyFooterDivider ) { addStickyFooterDivider ( ctx , linearLayout ) ; } fillStickyDrawerItemFooter ( drawer , linearLayout , onClickListener ) ; return linearLayout ; } | build the sticky footer item view |
8,670 | private static void addStickyFooterDivider ( Context ctx , ViewGroup footerView ) { LinearLayout divider = new LinearLayout ( ctx ) ; LinearLayout . LayoutParams dividerParams = new LinearLayout . LayoutParams ( ViewGroup . LayoutParams . MATCH_PARENT , ViewGroup . LayoutParams . WRAP_CONTENT ) ; divider . setMinimumHeight ( ( int ) UIUtils . convertDpToPixel ( 1 , ctx ) ) ; divider . setOrientation ( LinearLayout . VERTICAL ) ; divider . setBackgroundColor ( UIUtils . getThemeColorFromAttrOrRes ( ctx , R . attr . material_drawer_divider , R . color . material_drawer_divider ) ) ; footerView . addView ( divider , dividerParams ) ; } | adds the shadow to the stickyFooter |
8,671 | public static void fillStickyDrawerItemFooter ( DrawerBuilder drawer , ViewGroup container , View . OnClickListener onClickListener ) { for ( IDrawerItem drawerItem : drawer . mStickyDrawerItems ) { View view = drawerItem . generateView ( container . getContext ( ) , container ) ; view . setTag ( drawerItem ) ; if ( drawerItem . isEnabled ( ) ) { view . setOnClickListener ( onClickListener ) ; } container . addView ( view ) ; DrawerUIUtils . setDrawerVerticalPadding ( view ) ; } container . setPadding ( 0 , 0 , 0 , 0 ) ; } | helper method to fill the sticky footer with it s elements |
8,672 | public static DrawerLayout . LayoutParams processDrawerLayoutParams ( DrawerBuilder drawer , DrawerLayout . LayoutParams params ) { if ( params != null ) { if ( drawer . mDrawerGravity != null && ( drawer . mDrawerGravity == Gravity . RIGHT || drawer . mDrawerGravity == Gravity . END ) ) { params . rightMargin = 0 ; if ( Build . VERSION . SDK_INT >= 17 ) { params . setMarginEnd ( 0 ) ; } params . leftMargin = drawer . mActivity . getResources ( ) . getDimensionPixelSize ( R . dimen . material_drawer_margin ) ; if ( Build . VERSION . SDK_INT >= 17 ) { params . setMarginEnd ( drawer . mActivity . getResources ( ) . getDimensionPixelSize ( R . dimen . material_drawer_margin ) ) ; } } if ( drawer . mDrawerWidth > - 1 ) { params . width = drawer . mDrawerWidth ; } else { params . width = DrawerUIUtils . getOptimalDrawerWidth ( drawer . mActivity ) ; } } return params ; } | helper to extend the layoutParams of the drawer |
8,673 | public static void hideKeyboard ( Activity act ) { if ( act != null && act . getCurrentFocus ( ) != null ) { InputMethodManager inputMethodManager = ( InputMethodManager ) act . getSystemService ( Activity . INPUT_METHOD_SERVICE ) ; inputMethodManager . hideSoftInputFromWindow ( act . getCurrentFocus ( ) . getWindowToken ( ) , 0 ) ; } } | Helper to hide the keyboard |
8,674 | public static byte run ( String [ ] argv , ClassLoader classLoader ) { final Runtime runtime = Runtime . builder ( ) . withArgs ( argv ) . withClassLoader ( classLoader ) . build ( ) ; runtime . run ( ) ; return runtime . exitStatus ( ) ; } | Launches the Cucumber - JVM command line . |
8,675 | private < T > T pluginProxy ( final Class < T > type ) { Object proxy = Proxy . newProxyInstance ( classLoader , new Class < ? > [ ] { type } , new InvocationHandler ( ) { public Object invoke ( Object target , Method method , Object [ ] args ) throws Throwable { for ( Object plugin : getPlugins ( ) ) { if ( type . isInstance ( plugin ) ) { try { Utils . invoke ( plugin , method , 0 , args ) ; } catch ( Throwable t ) { if ( ! method . getName ( ) . equals ( "startOfScenarioLifeCycle" ) && ! method . getName ( ) . equals ( "endOfScenarioLifeCycle" ) ) { throw t ; } } } } return null ; } } ) ; return type . cast ( proxy ) ; } | Creates a dynamic proxy that multiplexes method invocations to all plugins of the same type . |
8,676 | public static BackportedJsonStringEncoder getInstance ( ) { SoftReference < BackportedJsonStringEncoder > ref = _threadEncoder . get ( ) ; BackportedJsonStringEncoder enc = ( ref == null ) ? null : ref . get ( ) ; if ( enc == null ) { enc = new BackportedJsonStringEncoder ( ) ; _threadEncoder . set ( new SoftReference < BackportedJsonStringEncoder > ( enc ) ) ; } return enc ; } | Factory method for getting an instance ; this is either recycled per - thread instance or a newly constructed one . |
8,677 | public char [ ] quoteAsString ( String input ) { TextBuffer textBuffer = _textBuffer ; if ( textBuffer == null ) { _textBuffer = textBuffer = new TextBuffer ( null ) ; } char [ ] outputBuffer = textBuffer . emptyAndGetCurrentSegment ( ) ; final int [ ] escCodes = sOutputEscapes128 ; final int escCodeCount = escCodes . length ; int inPtr = 0 ; final int inputLen = input . length ( ) ; int outPtr = 0 ; outer_loop : while ( inPtr < inputLen ) { tight_loop : while ( true ) { char c = input . charAt ( inPtr ) ; if ( c < escCodeCount && escCodes [ c ] != 0 ) { break tight_loop ; } if ( outPtr >= outputBuffer . length ) { outputBuffer = textBuffer . finishCurrentSegment ( ) ; outPtr = 0 ; } outputBuffer [ outPtr ++ ] = c ; if ( ++ inPtr >= inputLen ) { break outer_loop ; } } int escCode = escCodes [ input . charAt ( inPtr ++ ) ] ; int length = _appendSingleEscape ( escCode , _quoteBuffer ) ; if ( ( outPtr + length ) > outputBuffer . length ) { int first = outputBuffer . length - outPtr ; if ( first > 0 ) { System . arraycopy ( _quoteBuffer , 0 , outputBuffer , outPtr , first ) ; } outputBuffer = textBuffer . finishCurrentSegment ( ) ; int second = length - first ; System . arraycopy ( _quoteBuffer , first , outputBuffer , outPtr , second ) ; outPtr += second ; } else { System . arraycopy ( _quoteBuffer , 0 , outputBuffer , outPtr , length ) ; outPtr += length ; } } textBuffer . setCurrentLength ( outPtr ) ; return textBuffer . contentsAsArray ( ) ; } | Method that will quote text contents using JSON standard quoting and return results as a character array |
8,678 | private String authenticate ( Credentials credentials ) throws AuthenticationException { if ( ! ( credentials instanceof EsApiKeyCredentials ) ) { throw new AuthenticationException ( "Incorrect credentials type provided. Expected [" + EsApiKeyCredentials . class . getName ( ) + "] but got [" + credentials . getClass ( ) . getName ( ) + "]" ) ; } EsApiKeyCredentials esApiKeyCredentials = ( ( EsApiKeyCredentials ) credentials ) ; String authString = null ; if ( esApiKeyCredentials . getToken ( ) != null && StringUtils . hasText ( esApiKeyCredentials . getToken ( ) . getName ( ) ) ) { EsToken token = esApiKeyCredentials . getToken ( ) ; String keyComponents = token . getId ( ) + ":" + token . getApiKey ( ) ; byte [ ] base64Encoded = Base64 . encodeBase64 ( keyComponents . getBytes ( StringUtils . UTF_8 ) ) ; String tokenText = new String ( base64Encoded , StringUtils . UTF_8 ) ; authString = EsHadoopAuthPolicies . APIKEY + " " + tokenText ; } return authString ; } | Implementation method for authentication |
8,679 | private void assertCorrectJobId ( Settings settings ) { SettingsUtils . ensureJobTransportPoolingKey ( settings ) ; String requestingJobKey = SettingsUtils . getJobTransportPoolingKey ( settings ) ; if ( ! jobKey . equals ( requestingJobKey ) ) { throw new EsHadoopIllegalArgumentException ( "Settings object passed does not have the same job " + "pooling key property as when this pool was created. Job key requested was [" + requestingJobKey + "] but this pool services job [" + jobKey + "]. This could be a " + "different job incorrectly polluting the TransportPool. Bailing out..." ) ; } } | Checks to ensure that the caller is using a settings object with the same job id that this pool is responsible for . |
8,680 | private TransportPool getOrCreateTransportPool ( String hostInfo , Settings settings , SecureSettings secureSettings ) { TransportPool pool ; pool = hostPools . get ( hostInfo ) ; if ( pool == null ) { pool = new TransportPool ( jobKey , hostInfo , settings , secureSettings ) ; hostPools . put ( hostInfo , pool ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Creating new TransportPool for job [" + jobKey + "] for host [" + hostInfo + "]" ) ; } } return pool ; } | Gets the transport pool for the given host info or creates one if it is absent . |
8,681 | private Transport borrowFrom ( TransportPool pool , String hostInfo ) { if ( ! pool . getJobPoolingKey ( ) . equals ( jobKey ) ) { throw new EsHadoopIllegalArgumentException ( "PooledTransportFactory found a pool with a different owner than this job. " + "This could be a different job incorrectly polluting the TransportPool. Bailing out..." ) ; } try { return pool . borrowTransport ( ) ; } catch ( Exception ex ) { throw new EsHadoopException ( String . format ( "Could not get a Transport from the Transport Pool for host [%s]" , hostInfo ) , ex ) ; } } | Creates a Transport using the given TransportPool . |
8,682 | synchronized int cleanPools ( ) { int totalConnectionsRemaining = 0 ; List < String > hostsToRemove = new ArrayList < String > ( ) ; for ( Map . Entry < String , TransportPool > hostPool : hostPools . entrySet ( ) ) { String host = hostPool . getKey ( ) ; TransportPool pool = hostPool . getValue ( ) ; int connectionsRemaining = pool . removeOldConnections ( ) ; if ( connectionsRemaining == 0 ) { hostsToRemove . add ( host ) ; } else { totalConnectionsRemaining += connectionsRemaining ; } } for ( String hostToRemove : hostsToRemove ) { hostPools . remove ( hostToRemove ) ; } return totalConnectionsRemaining ; } | Iterates over the available host pools and asks each one to purge transports older than a certain age . |
8,683 | private void doExecute ( HttpMethod method ) throws IOException { long start = System . currentTimeMillis ( ) ; try { client . executeMethod ( method ) ; afterExecute ( method ) ; } finally { stats . netTotalTime += ( System . currentTimeMillis ( ) - start ) ; closeAuthSchemeQuietly ( method ) ; } } | Actually perform the request |
8,684 | private void afterExecute ( HttpMethod method ) throws IOException { AuthState hostAuthState = method . getHostAuthState ( ) ; if ( hostAuthState . isPreemptive ( ) || hostAuthState . isAuthAttempted ( ) ) { AuthScheme authScheme = hostAuthState . getAuthScheme ( ) ; if ( authScheme instanceof SpnegoAuthScheme && settings . getNetworkSpnegoAuthMutual ( ) ) { SpnegoAuthScheme spnegoAuthScheme = ( ( SpnegoAuthScheme ) authScheme ) ; Map challenges = AuthChallengeParser . parseChallenges ( method . getResponseHeaders ( WWW_AUTHENTICATE ) ) ; String id = spnegoAuthScheme . getSchemeName ( ) ; String challenge = ( String ) challenges . get ( id . toLowerCase ( ) ) ; if ( challenge == null ) { throw new IOException ( id + " authorization challenge expected, but not found" ) ; } spnegoAuthScheme . ensureMutualAuth ( challenge ) ; } } } | Close any authentication resources that we may still have open and perform any after - response duties that we need to perform . |
8,685 | private void closeAuthSchemeQuietly ( HttpMethod method ) { AuthScheme scheme = method . getHostAuthState ( ) . getAuthScheme ( ) ; if ( scheme instanceof Closeable ) { try { ( ( Closeable ) scheme ) . close ( ) ; } catch ( IOException e ) { log . error ( "Could not close [" + scheme . getSchemeName ( ) + "] auth scheme" , e ) ; } } } | Close the underlying authscheme if it is a Closeable object . |
8,686 | static List [ ] findTypos ( Collection < String > fields , Mapping mapping ) { Set < String > keys = mapping . flatten ( ) . keySet ( ) ; List < String > missing = new ArrayList < String > ( fields . size ( ) ) ; for ( String field : fields ) { if ( ! keys . contains ( field ) && ! isBuiltIn ( field ) ) { missing . add ( field ) ; } } if ( missing . isEmpty ( ) ) { return null ; } Map < String , String > unwrapped = new LinkedHashMap < String , String > ( ) ; for ( String key : keys ) { int match = key . lastIndexOf ( "." ) ; if ( match > 0 ) { String leafField = key . substring ( match + 1 ) ; if ( ! unwrapped . containsKey ( leafField ) ) { unwrapped . put ( leafField , key ) ; } } unwrapped . put ( key , key ) ; } List < String > typos = new ArrayList < String > ( ) ; Set < String > similar = unwrapped . keySet ( ) ; for ( String string : missing ) { List < String > matches = StringUtils . findSimiliar ( string , similar ) ; for ( String match : matches ) { typos . add ( unwrapped . get ( match ) ) ; } } return new List [ ] { missing , typos } ; } | return a tuple for proper messages |
8,687 | public static String joinParentField ( Settings settings ) { if ( StringUtils . hasText ( settings . getMappingJoin ( ) ) ) { return settings . getMappingJoin ( ) . concat ( ".parent" ) ; } return null ; } | If es . mapping . join is set this returns the field name for the join field s parent sub - field . |
8,688 | protected JsonDeserializer < Object > _findRootDeserializer ( DeserializationConfig cfg , JavaType valueType ) throws JsonMappingException { if ( valueType == null ) { throw new JsonMappingException ( "No value type configured for ObjectReader" ) ; } JsonDeserializer < Object > deser = _rootDeserializers . get ( valueType ) ; if ( deser != null ) { return deser ; } deser = _provider . findTypedValueDeserializer ( cfg , valueType ) ; if ( deser == null ) { throw new JsonMappingException ( "Can not find a deserializer for type " + valueType ) ; } _rootDeserializers . put ( valueType , deser ) ; return deser ; } | Method called to locate deserializer for the passed root - level value . |
8,689 | static Collection < String > columnToAlias ( Settings settings ) { FieldAlias fa = alias ( settings ) ; List < String > columnNames = StringUtils . tokenize ( settings . getProperty ( HiveConstants . COLUMNS ) , "," ) ; for ( String vc : HiveConstants . VIRTUAL_COLUMNS ) { columnNames . remove ( vc ) ; } for ( int i = 0 ; i < columnNames . size ( ) ; i ++ ) { String original = columnNames . get ( i ) ; String alias = fa . toES ( original ) ; if ( alias != null ) { columnNames . set ( i , alias ) ; } } return columnNames ; } | Renders the full collection of field names needed from ES by combining the names of the hive table fields with the user provided name mappings . |
8,690 | static String discoverJsonFieldName ( Settings settings , FieldAlias alias ) { Set < String > virtualColumnsToBeRemoved = new HashSet < String > ( HiveConstants . VIRTUAL_COLUMNS . length ) ; Collections . addAll ( virtualColumnsToBeRemoved , HiveConstants . VIRTUAL_COLUMNS ) ; List < String > columnNames = StringUtils . tokenize ( settings . getProperty ( HiveConstants . COLUMNS ) , "," ) ; Iterator < String > nameIter = columnNames . iterator ( ) ; List < String > columnTypes = StringUtils . tokenize ( settings . getProperty ( HiveConstants . COLUMNS_TYPES ) , ":" ) ; Iterator < String > typeIter = columnTypes . iterator ( ) ; String candidateField = null ; while ( nameIter . hasNext ( ) && candidateField == null ) { String columnName = nameIter . next ( ) ; String type = typeIter . next ( ) ; if ( "string" . equalsIgnoreCase ( type ) && ! virtualColumnsToBeRemoved . contains ( columnName ) ) { candidateField = columnName ; } } Assert . hasText ( candidateField , "Could not identify a field to insert JSON data into " + "from the given fields : {" + columnNames + "} of types {" + columnTypes + "}" ) ; candidateField = alias . toES ( candidateField ) ; return candidateField ; } | Selects an appropriate field from the given Hive table schema to insert JSON data into if the feature is enabled |
8,691 | private static EsToken obtainEsToken ( final RestClient client , User user ) { KerberosPrincipal principal = user . getKerberosPrincipal ( ) ; if ( user . isProxyUser ( ) ) { principal = user . getRealUserProvider ( ) . getUser ( ) . getKerberosPrincipal ( ) ; } Assert . isTrue ( principal != null , "Kerberos credentials are missing on current user" ) ; return user . doAs ( new PrivilegedExceptionAction < EsToken > ( ) { public EsToken run ( ) { return client . createNewApiToken ( newKeyName ( ) ) ; } } ) ; } | Obtain the given user s authentication token from Elasticsearch by performing the getAuthToken operation as the given user thus ensuring the subject s private credentials available on the thread s access control context for the life of the operation . |
8,692 | public static Token < EsTokenIdentifier > obtainToken ( RestClient client , User user ) { EsToken esToken = obtainEsToken ( client , user ) ; return EsTokenIdentifier . createTokenFrom ( esToken ) ; } | Obtain and return an authentication token for the current user . |
8,693 | public static void obtainAndCache ( RestClient client , User user ) throws IOException { EsToken token = obtainEsToken ( client , user ) ; if ( token == null ) { throw new IOException ( "No token returned for user " + user . getKerberosPrincipal ( ) . getName ( ) ) ; } if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Obtained token " + EsTokenIdentifier . KIND_NAME + " for user " + user . getKerberosPrincipal ( ) . getName ( ) ) ; } user . addEsToken ( token ) ; } | Obtain an authentication token for the given user and add it to the user s credentials . |
8,694 | public static void obtainTokenForJob ( final RestClient client , User user , Job job ) { Token < EsTokenIdentifier > token = obtainToken ( client , user ) ; if ( token == null ) { throw new EsHadoopException ( "No token returned for user " + user . getKerberosPrincipal ( ) . getName ( ) ) ; } Text clusterName = token . getService ( ) ; if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Obtained token " + EsTokenIdentifier . KIND_NAME . toString ( ) + " for user " + user . getKerberosPrincipal ( ) . getName ( ) + " on cluster " + clusterName . toString ( ) ) ; } job . getCredentials ( ) . addToken ( clusterName , token ) ; } | Obtain an authentication token on behalf of the given user and add it to the credentials for the given map reduce job . This version always obtains a fresh authentication token instead of checking for existing ones on the current user . |
8,695 | public static void addTokenForJob ( final RestClient client , ClusterName clusterName , User user , Job job ) { Token < EsTokenIdentifier > token = getAuthToken ( clusterName , user ) ; if ( token == null ) { token = obtainToken ( client , user ) ; } job . getCredentials ( ) . addToken ( token . getService ( ) , token ) ; } | Retrieves an authentication token from the given user obtaining a new token if necessary and adds it to the credentials for the given map reduce job . |
8,696 | private static Token < EsTokenIdentifier > getAuthToken ( ClusterName clusterName , User user ) { EsToken esToken = getEsAuthToken ( clusterName , user ) ; if ( esToken == null ) { return null ; } else { return EsTokenIdentifier . createTokenFrom ( esToken ) ; } } | Get the authentication token of the user for the provided cluster name in its Hadoop Token form . |
8,697 | private static EsToken getEsAuthToken ( ClusterName clusterName , User user ) { return user . getEsToken ( clusterName . getName ( ) ) ; } | Get the authentication token of the user for the provided cluster name in its ES - Hadoop specific form . |
8,698 | public static ClusterInfo discoverClusterInfo ( Settings settings , Log log ) { ClusterName remoteClusterName = null ; EsMajorVersion remoteVersion = null ; String clusterName = settings . getProperty ( InternalConfigurationOptions . INTERNAL_ES_CLUSTER_NAME ) ; String clusterUUID = settings . getProperty ( InternalConfigurationOptions . INTERNAL_ES_CLUSTER_UUID ) ; String version = settings . getProperty ( InternalConfigurationOptions . INTERNAL_ES_VERSION ) ; if ( StringUtils . hasText ( clusterName ) && StringUtils . hasText ( version ) ) { if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "Elasticsearch cluster [NAME:%s][UUID:%s][VERSION:%s] already present in configuration; skipping discovery" , clusterName , clusterUUID , version ) ) ; } remoteClusterName = new ClusterName ( clusterName , clusterUUID ) ; remoteVersion = EsMajorVersion . parse ( version ) ; return new ClusterInfo ( remoteClusterName , remoteVersion ) ; } RestClient bootstrap = new RestClient ( settings ) ; try { ClusterInfo mainInfo = bootstrap . mainInfo ( ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "Discovered Elasticsearch cluster [%s/%s], version [%s]" , mainInfo . getClusterName ( ) . getName ( ) , mainInfo . getClusterName ( ) . getUUID ( ) , mainInfo . getMajorVersion ( ) ) ) ; } settings . setInternalClusterInfo ( mainInfo ) ; return mainInfo ; } catch ( EsHadoopException ex ) { throw new EsHadoopIllegalArgumentException ( String . format ( "Cannot detect ES version - " + "typically this happens if the network/Elasticsearch cluster is not accessible or when targeting " + "a WAN/Cloud instance without the proper setting '%s'" , ConfigurationOptions . ES_NODES_WAN_ONLY ) , ex ) ; } finally { bootstrap . close ( ) ; } } | Retrieves the Elasticsearch cluster name and version from the settings or if they should be missing creates a bootstrap client and obtains their values . |
8,699 | private void lazyInitWriting ( ) { if ( ! writeInitialized ) { this . writeInitialized = true ; this . bulkProcessor = new BulkProcessor ( client , resources . getResourceWrite ( ) , settings ) ; this . trivialBytesRef = new BytesRef ( ) ; this . bulkEntryWriter = new BulkEntryWriter ( settings , BulkCommands . create ( settings , metaExtractor , client . clusterInfo . getMajorVersion ( ) ) ) ; } } | postpone writing initialization since we can do only reading so there s no need to allocate buffers |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.