idx int64 0 41.2k | question stringlengths 83 4.15k | target stringlengths 5 715 |
|---|---|---|
1,800 | protected < T > Provider < T > findProvider ( Class < T > type , Annotation qualifier ) throws ProviderMissingException { String key = PokeHelper . makeProviderKey ( type , qualifier ) ; Component targetComponent = getRootComponent ( ) . componentLocator . get ( key ) ; Provider provider = null ; if ( targetComponent != null ) { provider = targetComponent . providers . get ( key ) ; } if ( provider == null ) { String msg = String . format ( "Provider(%s) cannot be found" , key ) ; throw new ProviderMissingException ( msg ) ; } else { return provider ; } } | Find the provider specified by the type and qualifier . It will look through the providers registered to this component and all its children components . |
1,801 | private void addNewKeyToComponent ( String key , Component component ) throws ProviderConflictException { Component root = getRootComponent ( ) ; if ( componentLocator . keySet ( ) . contains ( key ) ) { String msg = String . format ( "Type %s has already been registered " + "in this component(%s)." , key , getComponentId ( ) ) ; throw new ProviderConflictException ( msg ) ; } if ( root != this && root . componentLocator . keySet ( ) . contains ( key ) ) { String msg = String . format ( "\nClass type %s cannot be registered to component(%s)\nsince it's " + "already been registered in its root component(%s).\n\nYou can prepare a child " + "component and register providers to it first. Then attach the child component\nto the " + "component tree with allowOverridden flag set true" , key , getComponentId ( ) , getRootComponent ( ) . getComponentId ( ) ) ; throw new ProviderConflictException ( msg ) ; } root . componentLocator . put ( key , component ) ; } | Add key to the component locator of the component . This component and the the component tree root s component locator will both be updated . |
1,802 | public void release ( final Object target ) { if ( uiThreadRunner . isOnUiThread ( ) ) { try { graph . release ( target , Inject . class ) ; } catch ( ProviderMissingException e ) { throw new MvcGraphException ( e . getMessage ( ) , e ) ; } } else { uiThreadRunner . post ( new Runnable ( ) { public void run ( ) { try { graph . release ( target , Inject . class ) ; } catch ( ProviderMissingException e ) { throw new MvcGraphException ( e . getMessage ( ) , e ) ; } } } ) ; } } | Release cached instances held by fields of target object . References of instances of the instances will be decremented . Once the reference count of a contract type reaches 0 it will be removed from the instances . |
1,803 | private void go ( ) { if ( navigateEvent != null ) { navigationManager . postEvent2C ( navigateEvent ) ; if ( navigationManager . logger . isTraceEnabled ( ) ) { if ( navigateEvent instanceof NavigationManager . Event . OnLocationForward ) { NavigationManager . Event . OnLocationForward event = ( NavigationManager . Event . OnLocationForward ) navigateEvent ; String lastLocId = event . getLastValue ( ) == null ? null : event . getLastValue ( ) . getLocationId ( ) ; navigationManager . logger . trace ( "Nav Manager: Forward: {} -> {}" , lastLocId , event . getCurrentValue ( ) . getLocationId ( ) ) ; } } if ( navigateEvent instanceof NavigationManager . Event . OnLocationBack ) { if ( navigationManager . logger . isTraceEnabled ( ) ) { NavigationManager . Event . OnLocationBack event = ( NavigationManager . Event . OnLocationBack ) navigateEvent ; NavLocation lastLoc = event . getLastValue ( ) ; NavLocation currentLoc = event . getCurrentValue ( ) ; navigationManager . logger . trace ( "Nav Manager: Backward: {} -> {}" , lastLoc . getLocationId ( ) , currentLoc == null ? "null" : currentLoc . getLocationId ( ) ) ; } checkAppExit ( sender ) ; } } dumpHistory ( ) ; } | Sends out the navigation event to execute the navigation |
1,804 | void destroy ( ) { if ( onSettled != null ) { onSettled . run ( ) ; } if ( pendingReleaseInstances != null ) { for ( PendingReleaseInstance i : pendingReleaseInstances ) { try { Mvc . graph ( ) . dereference ( i . instance , i . type , i . qualifier ) ; } catch ( ProviderMissingException e ) { navigationManager . logger . warn ( "Failed to auto release {} after navigation settled" , i . type . getName ( ) ) ; } } } } | Internal use . Don t do it in your app . |
1,805 | private void checkAppExit ( Object sender ) { NavLocation curLocation = navigationManager . getModel ( ) . getCurrentLocation ( ) ; if ( curLocation == null ) { navigationManager . postEvent2C ( new NavigationManager . Event . OnAppExit ( sender ) ) ; } } | Check the app is exiting |
1,806 | private void dumpHistory ( ) { if ( navigationManager . dumpHistoryOnLocationChange ) { navigationManager . logger . trace ( "" ) ; navigationManager . logger . trace ( "Nav Controller: dump: begin -------------------------------------------- ) ; NavLocation curLoc = navigationManager . getModel ( ) . getCurrentLocation ( ) ; while ( curLoc != null ) { navigationManager . logger . trace ( "Nav Controller: dump: {}({})" , curLoc . getLocationId ( ) ) ; curLoc = curLoc . getPreviousLocation ( ) ; } navigationManager . logger . trace ( "Nav Controller: dump: end -------------------------------------------- ) ; navigationManager . logger . trace ( "" ) ; } } | Prints navigation history |
1,807 | void retain ( Object owner , Field field ) { retain ( ) ; Map < String , Integer > fields = owners . get ( owner ) ; if ( fields == null ) { fields = new HashMap < > ( ) ; owners . put ( owner , fields ) ; } Integer count = fields . get ( field . toGenericString ( ) ) ; if ( count == null ) { fields . put ( field . toGenericString ( ) , 1 ) ; } else { count ++ ; fields . put ( field . toGenericString ( ) , count ) ; } } | Retain an instance injected as a field of an object |
1,808 | void release ( Object owner , Field field ) { Map < String , Integer > fields = owners . get ( owner ) ; if ( fields != null ) { release ( ) ; Integer count = fields . get ( field . toGenericString ( ) ) ; if ( -- count > 0 ) { fields . put ( field . toGenericString ( ) , count ) ; } else { fields . remove ( field . toGenericString ( ) ) ; } } if ( fields != null && fields . isEmpty ( ) ) { owners . remove ( owner ) ; } } | Release an instance injected as a field of an object |
1,809 | public T getCachedInstance ( ) { ScopeCache cache = getScopeCache ( ) ; if ( cache != null ) { String key = PokeHelper . makeProviderKey ( type , qualifier ) ; Object instance = cache . findInstance ( key ) ; if ( instance != null ) { return ( T ) instance ; } } return null ; } | Get the cached instance of this provider when there is a instances associated with this provider and the instance is cached already . Note that the method will NOT increase reference count of this provider |
1,810 | void registerEventBuses ( ) { if ( ! eventsRegistered ) { Mvc . graph ( ) . inject ( this ) ; eventBusV . register ( androidComponent ) ; eventsRegistered = true ; logger . trace ( "+Event2V bus registered for view - '{}'." , androidComponent . getClass ( ) . getSimpleName ( ) ) ; } else { logger . trace ( "!Event2V bus already registered for view - '{}' and its controllers." , androidComponent . getClass ( ) . getSimpleName ( ) ) ; } } | Register event bus for views . |
1,811 | void unregisterEventBuses ( ) { if ( eventsRegistered ) { eventBusV . unregister ( androidComponent ) ; eventsRegistered = false ; logger . trace ( "-Event2V bus unregistered for view - '{}' and its controllers." , androidComponent . getClass ( ) . getSimpleName ( ) ) ; Mvc . graph ( ) . release ( this ) ; } else { logger . trace ( "!Event2V bus already unregistered for view - '{}'." , androidComponent . getClass ( ) . getSimpleName ( ) ) ; } } | Unregister event bus for views . |
1,812 | public void inject ( Object target , Class < ? extends Annotation > injectAnnotation ) throws ProvideException , ProviderMissingException , CircularDependenciesException { if ( monitors != null ) { int size = monitors . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { monitors . get ( i ) . onInject ( target ) ; } } doInject ( target , null , null , null , injectAnnotation ) ; visitedInjectNodes . clear ( ) ; revisitedNode = null ; visitedFields . clear ( ) ; } | Inject all fields annotated by the given injectAnnotation |
1,813 | private void recordVisitField ( Object object , Field objectField , Field field ) { Map < String , Set < String > > bag = visitedFields . get ( object ) ; if ( bag == null ) { bag = new HashMap < > ( ) ; visitedFields . put ( object , bag ) ; } Set < String > fields = bag . get ( objectField ) ; String objectFiledKey = objectField == null ? "" : objectField . toGenericString ( ) ; if ( fields == null ) { fields = new HashSet < > ( ) ; bag . put ( objectFiledKey , fields ) ; } fields . add ( field . toGenericString ( ) ) ; } | Records the field of a target object is visited |
1,814 | private boolean isFieldVisited ( Object object , Field objectField , Field field ) { Map < String , Set < String > > bag = visitedFields . get ( object ) ; if ( bag == null ) { return false ; } String objectFiledKey = objectField == null ? "" : objectField . toGenericString ( ) ; Set < String > fields = bag . get ( objectFiledKey ) ; return fields != null && fields . contains ( field ) ; } | Indicates whether the field of a target object is visited |
1,815 | private void throwCircularDependenciesException ( ) throws CircularDependenciesException { String msg = "Circular dependencies found. Check the circular graph below:\n" ; boolean firstNode = true ; String tab = " " ; for ( String visit : visitedInjectNodes ) { if ( ! firstNode ) { msg += tab + "->" ; tab += tab ; } msg += visit + "\n" ; firstNode = false ; } msg += tab . substring ( 2 ) + "->" + revisitedNode + "\n" ; throw new CircularDependenciesException ( msg ) ; } | Print readable circular graph |
1,816 | protected List < ImageDTO > extractImagesFromCursor ( Cursor cursor , int offset , int limit ) { List < ImageDTO > images = new ArrayList < > ( ) ; int count = 0 ; int begin = offset > 0 ? offset : 0 ; if ( cursor . moveToPosition ( begin ) ) { do { ImageDTO image = extractOneImageFromCurrentCursor ( cursor ) ; images . add ( image ) ; count ++ ; if ( limit > 0 && count > limit ) { break ; } } while ( cursor . moveToNext ( ) ) ; } cursor . close ( ) ; return images ; } | Extract a list of imageDTO from current cursor with the given offset and limit . |
1,817 | protected List < VideoDTO > extractVideosFromCursor ( Cursor cursor , int offset , int limit ) { List < VideoDTO > videos = new ArrayList < > ( ) ; int count = 0 ; int begin = offset > 0 ? offset : 0 ; if ( cursor . moveToPosition ( begin ) ) { do { VideoDTO video = extractOneVideoFromCursor ( cursor ) ; videos . add ( video ) ; count ++ ; if ( limit > 0 && count > limit ) { break ; } } while ( cursor . moveToNext ( ) ) ; } cursor . close ( ) ; return videos ; } | Extract a list of videoDTO from current cursor with the given offset and limit . |
1,818 | public static void setField ( Object obj , Field field , Object value ) { boolean accessible = field . isAccessible ( ) ; if ( ! accessible ) { field . setAccessible ( true ) ; } try { field . set ( obj , value ) ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } field . setAccessible ( accessible ) ; } | Sets value to the field of the given object . |
1,819 | public static Object getFieldValue ( Object obj , Field field ) { Object value = null ; boolean accessible = field . isAccessible ( ) ; if ( ! accessible ) { field . setAccessible ( true ) ; } try { value = field . get ( obj ) ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } field . setAccessible ( accessible ) ; return value ; } | Gets value of the field of the given object . |
1,820 | public PageSnapshot highlight ( WebElement element ) { try { highlight ( element , Color . red , 3 ) ; } catch ( RasterFormatException rfe ) { throw new ElementOutsideViewportException ( ELEMENT_OUT_OF_VIEWPORT_EX_MESSAGE , rfe ) ; } return this ; } | Highlights WebElement within the page with Color . red and line width 3 . |
1,821 | public PageSnapshot highlight ( WebElement element , Color color , int lineWidth ) { try { image = ImageProcessor . highlight ( image , new Coordinates ( element , devicePixelRatio ) , color , lineWidth ) ; } catch ( RasterFormatException rfe ) { throw new ElementOutsideViewportException ( ELEMENT_OUT_OF_VIEWPORT_EX_MESSAGE , rfe ) ; } return this ; } | Highlights WebElement within the page with provided color and line width . |
1,822 | public PageSnapshot blur ( WebElement element ) { try { image = ImageProcessor . blurArea ( image , new Coordinates ( element , devicePixelRatio ) ) ; } catch ( RasterFormatException rfe ) { throw new ElementOutsideViewportException ( ELEMENT_OUT_OF_VIEWPORT_EX_MESSAGE , rfe ) ; } return this ; } | Blur provided element within the page only . |
1,823 | public PageSnapshot monochrome ( WebElement element ) { try { image = ImageProcessor . monochromeArea ( image , new Coordinates ( element , devicePixelRatio ) ) ; } catch ( RasterFormatException rfe ) { throw new ElementOutsideViewportException ( ELEMENT_OUT_OF_VIEWPORT_EX_MESSAGE , rfe ) ; } return this ; } | Makes an element withing a page monochrome - applies gray - and - white filter . Original colors remain on the rest of the page . |
1,824 | public PageSnapshot blurExcept ( WebElement element ) { try { image = ImageProcessor . blurExceptArea ( image , new Coordinates ( element , devicePixelRatio ) ) ; } catch ( RasterFormatException rfe ) { throw new ElementOutsideViewportException ( ELEMENT_OUT_OF_VIEWPORT_EX_MESSAGE , rfe ) ; } return this ; } | Blurs all the page except the element provided . |
1,825 | public PageSnapshot cropAround ( WebElement element , int offsetX , int offsetY ) { try { image = ImageProcessor . cropAround ( image , new Coordinates ( element , devicePixelRatio ) , offsetX , offsetY ) ; } catch ( RasterFormatException rfe ) { throw new ElementOutsideViewportException ( ELEMENT_OUT_OF_VIEWPORT_EX_MESSAGE , rfe ) ; } return this ; } | Crop the image around specified element with offset . |
1,826 | public static boolean imagesAreEqualsWithDiff ( BufferedImage image1 , BufferedImage image2 , String pathFileName , double deviation ) { BufferedImage output = new BufferedImage ( image1 . getWidth ( ) , image1 . getHeight ( ) , BufferedImage . TYPE_INT_RGB ) ; int width1 = image1 . getWidth ( null ) ; int width2 = image2 . getWidth ( null ) ; int height1 = image1 . getHeight ( null ) ; int height2 = image2 . getHeight ( null ) ; if ( ( width1 != width2 ) || ( height1 != height2 ) ) { throw new UnableToCompareImagesException ( "Images dimensions mismatch: image1 - " + width1 + "x" + height1 + "; image2 - " + width2 + "x" + height2 ) ; } long diff = 0 ; long recordedDiff = 0 ; for ( int y = 0 ; y < height1 ; y ++ ) { for ( int x = 0 ; x < width1 ; x ++ ) { recordedDiff = diff ; int rgb1 = image1 . getRGB ( x , y ) ; int rgb2 = image2 . getRGB ( x , y ) ; int r1 = ( rgb1 >> 16 ) & 0xff ; int g1 = ( rgb1 >> 8 ) & 0xff ; int b1 = ( rgb1 ) & 0xff ; int r2 = ( rgb2 >> 16 ) & 0xff ; int g2 = ( rgb2 >> 8 ) & 0xff ; int b2 = ( rgb2 ) & 0xff ; diff += Math . abs ( r1 - r2 ) ; diff += Math . abs ( g1 - g2 ) ; diff += Math . abs ( b1 - b2 ) ; if ( diff > recordedDiff ) output . setRGB ( x , y , new Color ( 255 , 0 , 0 ) . getRGB ( ) & rgb1 ) ; else output . setRGB ( x , y , rgb1 ) ; } } int colourSpaceBytes = 3 ; double totalPixels = width1 * height1 * colourSpaceBytes ; pixelError = diff / totalPixels / 255.0 ; if ( pixelError > 0 ) FileUtil . writeImage ( output , "png" , new File ( pathFileName + ".png" ) ) ; return pixelError == 0 || pixelError <= deviation ; } | Extends the functionality of imagesAreEqualsWithDiff but creates a third BufferedImage and applies pixel manipulation to it . |
1,827 | public DrawerProfile setAvatar ( Context context , Bitmap avatar ) { mAvatar = new BitmapDrawable ( context . getResources ( ) , avatar ) ; notifyDataChanged ( ) ; return this ; } | Sets an avatar image to the drawer profile |
1,828 | public DrawerProfile setRoundedAvatar ( Context context , Bitmap image ) { return setAvatar ( new RoundedAvatarDrawable ( new BitmapDrawable ( context . getResources ( ) , image ) . getBitmap ( ) ) ) ; } | Sets a rounded avatar image to the drawer profile |
1,829 | public DrawerProfile setBackground ( Context context , Bitmap background ) { mBackground = new BitmapDrawable ( context . getResources ( ) , background ) ; notifyDataChanged ( ) ; return this ; } | Sets a background to the drawer profile |
1,830 | public DrawerItem setImageMode ( int imageMode ) { if ( imageMode != ICON && imageMode != AVATAR && imageMode != SMALL_AVATAR ) { throw new IllegalArgumentException ( "Image mode must be either ICON or AVATAR." ) ; } mImageMode = imageMode ; notifyDataChanged ( ) ; return this ; } | Sets an image mode to the drawer item |
1,831 | public DrawerItem setTextSecondary ( String textSecondary , int textMode ) { mTextSecondary = textSecondary ; setTextMode ( textMode ) ; notifyDataChanged ( ) ; return this ; } | Sets a secondary text with a given text mode to the drawer item |
1,832 | public DrawerItem setTextMode ( int textMode ) { if ( textMode != SINGLE_LINE && textMode != TWO_LINE && textMode != THREE_LINE ) { throw new IllegalArgumentException ( "Image mode must be either SINGLE_LINE, TWO_LINE or THREE_LINE." ) ; } mTextMode = textMode ; notifyDataChanged ( ) ; return this ; } | Sets a text mode to the drawer item |
1,833 | public DrawerView addProfile ( DrawerProfile profile ) { if ( profile . getId ( ) <= 0 ) { profile . setId ( System . nanoTime ( ) * 100 + Math . round ( Math . random ( ) * 100 ) ) ; } for ( DrawerProfile oldProfile : mProfileAdapter . getItems ( ) ) { if ( oldProfile . getId ( ) == profile . getId ( ) ) { mProfileAdapter . remove ( oldProfile ) ; break ; } } profile . attachTo ( this ) ; mProfileAdapter . add ( profile ) ; if ( mProfileAdapter . getCount ( ) == 1 ) { selectProfile ( profile ) ; } updateProfile ( ) ; return this ; } | Adds a profile to the drawer view |
1,834 | public DrawerProfile findProfileById ( long id ) { for ( DrawerProfile profile : mProfileAdapter . getItems ( ) ) { if ( profile . getId ( ) == id ) { return profile ; } } return null ; } | Gets a profile from the drawer view |
1,835 | public DrawerView clearProfiles ( ) { for ( DrawerProfile profile : mProfileAdapter . getItems ( ) ) { profile . detach ( ) ; } mProfileAdapter . clear ( ) ; updateProfile ( ) ; return this ; } | Removes all profiles from the drawer view |
1,836 | public DrawerView addItems ( List < DrawerItem > items ) { mAdapter . setNotifyOnChange ( false ) ; for ( DrawerItem item : items ) { if ( item . getId ( ) <= 0 ) { item . setId ( System . nanoTime ( ) * 100 + Math . round ( Math . random ( ) * 100 ) ) ; } for ( DrawerItem oldItem : mAdapter . getItems ( ) ) { if ( oldItem . getId ( ) == item . getId ( ) ) { mAdapter . remove ( oldItem ) ; break ; } } item . attachTo ( mAdapter ) ; mAdapter . add ( item ) ; } mAdapter . setNotifyOnChange ( true ) ; mAdapter . notifyDataSetChanged ( ) ; updateList ( ) ; return this ; } | Adds items to the drawer view |
1,837 | public DrawerView addItem ( DrawerItem item ) { if ( item . getId ( ) <= 0 ) { item . setId ( System . nanoTime ( ) * 100 + Math . round ( Math . random ( ) * 100 ) ) ; } for ( DrawerItem oldItem : mAdapter . getItems ( ) ) { if ( oldItem . getId ( ) == item . getId ( ) ) { mAdapter . remove ( oldItem ) ; break ; } } item . attachTo ( mAdapter ) ; mAdapter . add ( item ) ; updateList ( ) ; return this ; } | Adds an item to the drawer view |
1,838 | public DrawerItem findItemById ( long id ) { for ( DrawerItem item : mAdapter . getItems ( ) ) { if ( item . getId ( ) == id ) { return item ; } } return null ; } | Gets an item from the drawer view |
1,839 | public DrawerView selectItemById ( long id ) { mAdapterFixed . clearSelection ( ) ; int count = mAdapter . getCount ( ) ; for ( int i = 0 ; i < count ; i ++ ) { if ( mAdapter . getItem ( i ) . getId ( ) == id ) { mAdapter . select ( i ) ; return this ; } } return this ; } | Selects an item from the drawer view |
1,840 | public DrawerView clearItems ( ) { for ( DrawerItem item : mAdapter . getItems ( ) ) { item . detach ( ) ; } mAdapter . clear ( ) ; updateList ( ) ; return this ; } | Removes all items from the drawer view |
1,841 | public DrawerView addFixedItems ( List < DrawerItem > items ) { mAdapterFixed . setNotifyOnChange ( false ) ; for ( DrawerItem item : items ) { if ( item . getId ( ) <= 0 ) { item . setId ( System . nanoTime ( ) * 100 + Math . round ( Math . random ( ) * 100 ) ) ; } for ( DrawerItem oldItem : mAdapterFixed . getItems ( ) ) { if ( oldItem . getId ( ) == item . getId ( ) ) { mAdapterFixed . remove ( oldItem ) ; break ; } } item . attachTo ( mAdapterFixed ) ; mAdapterFixed . add ( item ) ; } mAdapterFixed . setNotifyOnChange ( true ) ; mAdapterFixed . notifyDataSetChanged ( ) ; updateFixedList ( ) ; return this ; } | Adds fixed items to the drawer view |
1,842 | public DrawerView addFixedItem ( DrawerItem item ) { if ( item . getId ( ) <= 0 ) { item . setId ( System . nanoTime ( ) * 100 + Math . round ( Math . random ( ) * 100 ) ) ; } for ( DrawerItem oldItem : mAdapterFixed . getItems ( ) ) { if ( oldItem . getId ( ) == item . getId ( ) ) { mAdapterFixed . remove ( oldItem ) ; break ; } } item . attachTo ( mAdapterFixed ) ; mAdapterFixed . add ( item ) ; updateFixedList ( ) ; return this ; } | Adds a fixed item to the drawer view |
1,843 | public DrawerItem findFixedItemById ( long id ) { for ( DrawerItem item : mAdapterFixed . getItems ( ) ) { if ( item . getId ( ) == id ) { return item ; } } return null ; } | Gets a fixed item from the drawer view |
1,844 | public DrawerView clearFixedItems ( ) { for ( DrawerItem item : mAdapterFixed . getItems ( ) ) { item . detach ( ) ; } mAdapterFixed . clear ( ) ; updateFixedList ( ) ; return this ; } | Removes all fixed items from the drawer view |
1,845 | public void setAdapter ( ListAdapter adapter ) { if ( mAdapter != null ) { mAdapter . unregisterDataSetObserver ( mDataObserver ) ; } mAdapter = adapter ; if ( mAdapter != null ) { mAdapter . registerDataSetObserver ( mDataObserver ) ; mAreAllItemsSelectable = mAdapter . areAllItemsEnabled ( ) ; } setupChildren ( ) ; } | Sets the data behind this LinearListView . |
1,846 | public void setEmptyView ( View emptyView ) { mEmptyView = emptyView ; final ListAdapter adapter = getAdapter ( ) ; final boolean empty = ( ( adapter == null ) || adapter . isEmpty ( ) ) ; updateEmptyStatus ( empty ) ; } | Sets the view to show if the adapter is empty |
1,847 | private void fillBuffer ( ) throws IOException { if ( ! endOfInput && ( lastCoderResult == null || lastCoderResult . isUnderflow ( ) ) ) { encoderIn . compact ( ) ; int position = encoderIn . position ( ) ; int c = reader . read ( encoderIn . array ( ) , position , encoderIn . remaining ( ) ) ; if ( c == - 1 ) { endOfInput = true ; } else { encoderIn . position ( position + c ) ; } encoderIn . flip ( ) ; } encoderOut . compact ( ) ; lastCoderResult = encoder . encode ( encoderIn , encoderOut , endOfInput ) ; encoderOut . flip ( ) ; } | Fills the internal char buffer from the reader . |
1,848 | public T header ( String name , String value ) { Collection < String > l = headers . get ( name ) ; if ( l == null ) { l = new ArrayList < String > ( ) ; } l . add ( value ) ; headers . put ( name , l ) ; return derived . cast ( this ) ; } | Add a header . |
1,849 | public T queryString ( String name , String value ) { List < String > l = queryString . get ( name ) ; if ( l == null ) { l = new ArrayList < String > ( ) ; } l . add ( value ) ; queryString . put ( name , l ) ; return derived . cast ( this ) ; } | Add a query param . |
1,850 | public static Link create ( final String text , final TextStyle ts , final NamedObject table ) { return new Link ( text , ts , '#' + table . getName ( ) ) ; } | Create a new styled Link to a table |
1,851 | public static Link create ( final String text , final NamedObject table ) { return new Link ( text , null , '#' + table . getName ( ) ) ; } | Create a new Link to a table |
1,852 | public static Link create ( final String text , final TextStyle ts , final String ref ) { return new Link ( text , ts , '#' + ref ) ; } | Create a new styled link to a given ref |
1,853 | public static Link create ( final String text , final String ref ) { return new Link ( text , null , '#' + ref ) ; } | Create a new link to a given ref |
1,854 | public static Link create ( final String text , final TextStyle ts , final File file ) { return new Link ( text , ts , file . toURI ( ) . toString ( ) ) ; } | Create a new styled link to a given file |
1,855 | public static Link create ( final String text , final File file ) { return new Link ( text , null , file . toURI ( ) . toString ( ) ) ; } | Create a new link to a given file |
1,856 | public static Link create ( final String text , final TextStyle ts , final URL url ) { return new Link ( text , ts , url . toString ( ) ) ; } | Create a new styled link to a given url |
1,857 | public static Link create ( final String text , final URL url ) { return new Link ( text , null , url . toString ( ) ) ; } | Create a new link to a given url |
1,858 | public TableCellStyleBuilder borderAll ( final Length size , final Color borderColor , final BorderAttribute . Style style ) { final BorderAttribute bs = new BorderAttribute ( size , borderColor , style ) ; this . bordersBuilder . all ( bs ) ; return this ; } | Add a border style for all the borders of this cell . |
1,859 | public TableCellStyleBuilder borderBottom ( final Length size , final Color borderColor , final BorderAttribute . Style style ) { final BorderAttribute bs = new BorderAttribute ( size , borderColor , style ) ; this . bordersBuilder . bottom ( bs ) ; return this ; } | Add a border style for the bottom border of this cell . |
1,860 | public TableCellStyleBuilder borderLeft ( final Length size , final Color borderColor , final BorderAttribute . Style style ) { final BorderAttribute bs = new BorderAttribute ( size , borderColor , style ) ; this . bordersBuilder . left ( bs ) ; return this ; } | Add a border style for the left border of this cell . |
1,861 | public TableCellStyleBuilder borderRight ( final Length size , final Color borderColor , final BorderAttribute . Style style ) { final BorderAttribute bs = new BorderAttribute ( size , borderColor , style ) ; this . bordersBuilder . right ( bs ) ; return this ; } | Add a border style for the right border of this cell . |
1,862 | public TableCellStyleBuilder borderTop ( final Length size , final Color borderColor , final BorderAttribute . Style style ) { final BorderAttribute bs = new BorderAttribute ( size , borderColor , style ) ; this . bordersBuilder . top ( bs ) ; return this ; } | Add a border style for the top border of this cell . |
1,863 | public boolean add ( final K key , final V value ) { final V curValue = this . valueByKey . get ( key ) ; if ( curValue == null ) { if ( this . mode == Mode . UPDATE ) return false ; } else { if ( this . mode == Mode . CREATE ) return false ; } if ( this . closed && ! this . valueByKey . containsKey ( key ) ) { throw new IllegalStateException ( "Container put(" + key + ", " + value + ")" ) ; } else if ( this . debug && ! this . valueByKey . containsKey ( key ) ) { Logger . getLogger ( "debug" ) . severe ( "Container put(" + key + ", " + value + ")" ) ; } this . valueByKey . put ( key , value ) ; return true ; } | If mode is update then the key must exist . If the mode is create then the key must not exist . Otherwise the key may exist . If the container is frozen no new key - value pair is accepted . |
1,864 | public void appendEAttribute ( final Appendable appendable , final CharSequence attrName , final String attrRawValue ) throws IOException { appendable . append ( ' ' ) . append ( attrName ) . append ( "=\"" ) . append ( this . escaper . escapeXMLAttribute ( attrRawValue ) ) . append ( '"' ) ; } | Append a space and new element to the appendable element the name of the element is attrName and the value is attrRawValue . The will be escaped if necessary |
1,865 | public void appendAttribute ( final Appendable appendable , final CharSequence attrName , final boolean attrValue ) throws IOException { this . appendAttribute ( appendable , attrName , Boolean . toString ( attrValue ) ) ; } | Append a new element to the appendable element the name of the element is attrName and the value is the boolean attrValue . |
1,866 | public void appendAttribute ( final Appendable appendable , final CharSequence attrName , final CharSequence attrValue ) throws IOException { appendable . append ( ' ' ) . append ( attrName ) . append ( "=\"" ) . append ( attrValue ) . append ( '"' ) ; } | Append a space then a new element to the appendable element the name of the element is attrName and the value is attrValue . The value won t be escaped . |
1,867 | public void appendTag ( final Appendable appendable , final CharSequence tagName , final String content ) throws IOException { appendable . append ( '<' ) . append ( tagName ) . append ( '>' ) . append ( this . escaper . escapeXMLContent ( content ) ) . append ( "</" ) . append ( tagName ) . append ( '>' ) ; } | Append a content inside a tag |
1,868 | public static OdsFactory create ( final Logger logger , final Locale locale ) { final PositionUtil positionUtil = new PositionUtil ( new EqualityUtil ( ) , new TableNameUtil ( ) ) ; final WriteUtil writeUtil = WriteUtil . create ( ) ; final XMLUtil xmlUtil = XMLUtil . create ( ) ; final DataStyles format = DataStylesBuilder . create ( locale ) . build ( ) ; return new OdsFactory ( logger , positionUtil , writeUtil , xmlUtil , format , true ) ; } | create an ods factory |
1,869 | private AnonymousOdsDocument createAnonymousDocument ( ) { final OdsElements odsElements = OdsElements . create ( this . positionUtil , this . xmlUtil , this . writeUtil , this . format , this . libreOfficeMode ) ; return AnonymousOdsDocument . create ( this . logger , this . xmlUtil , odsElements ) ; } | Create a new empty document for an anonymous writer . Use addTable to add tables . |
1,870 | private NamedOdsDocument createNamedDocument ( ) { final OdsElements odsElements = OdsElements . create ( this . positionUtil , this . xmlUtil , this . writeUtil , this . format , this . libreOfficeMode ) ; return NamedOdsDocument . create ( this . logger , this . xmlUtil , odsElements ) ; } | Create a new empty document for a normal writer . Use addTable to add tables . |
1,871 | public OdsFileWriterAdapter createWriterAdapter ( final File file ) throws IOException { final NamedOdsDocument document = this . createNamedDocument ( ) ; final ZipUTF8WriterBuilder zipUTF8Writer = ZipUTF8WriterImpl . builder ( ) . noWriterBuffer ( ) ; final OdsFileWriterAdapter writerAdapter = OdsFileWriterAdapter . create ( OdsFileDirectWriter . builder ( this . logger , document ) . openResult ( this . openFile ( file ) ) . zipBuilder ( zipUTF8Writer ) . build ( ) ) ; document . addObserver ( writerAdapter ) ; document . prepareFlush ( ) ; return writerAdapter ; } | Create an adapter for a writer . |
1,872 | public Position getPosition ( final String pos ) { final String s = pos . toUpperCase ( Locale . US ) ; final int len = s . length ( ) ; int status = 0 ; int row = 0 ; int col = 0 ; int n = 0 ; while ( n < len ) { final char c = s . charAt ( n ) ; switch ( status ) { case BEGIN_LETTER : case BEGIN_DIGIT : status ++ ; if ( c == '$' ) n ++ ; break ; case FIRST_LETTER : if ( 'A' <= c && c <= 'Z' ) { col = c - 'A' + 1 ; status = PositionUtil . OPT_SECOND_LETTER ; n ++ ; } else return null ; break ; case OPT_SECOND_LETTER : if ( 'A' <= c && c <= 'Z' ) { col = col * ALPHABET_SIZE + c - ORD_A + 1 ; n ++ ; } status = PositionUtil . BEGIN_DIGIT ; break ; case FIRST_DIGIT : if ( '0' <= c && c <= '9' ) { row = c - '0' ; status = PositionUtil . OPT_DIGIT ; n ++ ; } else return null ; break ; case OPT_DIGIT : if ( '0' <= c && c <= '9' ) { row = row * 10 + c - '0' ; n ++ ; } else return null ; break ; default : return null ; } } return new Position ( this . equalityUtil , this . tableNameUtil , row - 1 , col - 1 ) ; } | Convert a cell position string like B3 to the column number . |
1,873 | public static Color fromRGB ( final int red , final int green , final int blue ) { if ( ColorHelper . helper == null ) ColorHelper . helper = new ColorHelper ( ) ; return ColorHelper . helper . getFromRGB ( red , green , blue ) ; } | Create a color from RGB values |
1,874 | public Color getFromRGB ( final int red , final int green , final int blue ) { return this . getFromString ( "#" + this . toHexString ( red ) + this . toHexString ( green ) + this . toHexString ( blue ) ) ; } | Helper function to create any available color string from color values . |
1,875 | public static FractionStyleBuilder create ( final String name , final Locale locale ) { checker . checkStyleName ( name ) ; return new FractionStyleBuilder ( name , locale ) ; } | Create a new number style builder with the name name minimum integer digits is minIntDigits and decimal places is decPlaces . |
1,876 | public void appendXMLToTable ( final XMLUtil util , final Appendable appendable , final int count ) throws IOException { appendable . append ( "<table:table-column" ) ; util . appendEAttribute ( appendable , "table:style-name" , this . name ) ; if ( count > 1 ) util . appendAttribute ( appendable , "table:number-columns-repeated" , count ) ; if ( this . defaultCellStyle != null ) util . appendEAttribute ( appendable , "table:default-cell-style-name" , this . defaultCellStyle . getName ( ) ) ; appendable . append ( "/>" ) ; } | Append the XML to the table representation |
1,877 | public void addToContentStyles ( final StylesContainer stylesContainer ) { stylesContainer . addContentStyle ( this ) ; if ( this . defaultCellStyle != null ) { stylesContainer . addContentStyle ( this . defaultCellStyle ) ; } } | Add this style to a styles container |
1,878 | private void setDateTimeNow ( ) { final Date dt = new Date ( ) ; this . dateTime = MetaElement . DF_DATE . format ( dt ) + "T" + MetaElement . DF_TIME . format ( dt ) ; } | Store the date and time of the document creation in the MetaElement data . |
1,879 | synchronized public E get ( ) { if ( this . isClosed ( ) ) throw new NoSuchElementException ( ) ; while ( this . elements . isEmpty ( ) ) { try { this . wait ( ) ; } catch ( final InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; throw new RuntimeException ( e ) ; } } return this . elements . remove ( ) ; } | Get an element from the bus . Blocking method . |
1,880 | public static boolean openFile ( final File f ) { if ( desktop != null && f . exists ( ) && f . isFile ( ) ) { try { desktop . open ( f ) ; return true ; } catch ( final IOException e ) { Logger . getLogger ( FastOds . class . getName ( ) ) . log ( Level . SEVERE , "Can't open file " + f + " in appropriate application" , e ) ; } } return false ; } | Opens a file with the default application . |
1,881 | public void saveAs ( final File file ) throws IOException { try { final FileOutputStream out = new FileOutputStream ( file ) ; try { this . save ( out ) ; } finally { out . flush ( ) ; out . close ( ) ; } } catch ( final FileNotFoundException e ) { this . logger . log ( Level . SEVERE , "Can't open " + file , e ) ; throw new IOException ( e ) ; } catch ( final NullPointerException e ) { this . logger . log ( Level . SEVERE , "No file" , e ) ; throw new IOException ( e ) ; } } | Save the new file . |
1,882 | public void saveAs ( final String filename , final ZipUTF8WriterBuilder builder ) throws IOException { try { final FileOutputStream out = new FileOutputStream ( filename ) ; final ZipUTF8Writer writer = builder . build ( out ) ; try { this . save ( writer ) ; } finally { writer . close ( ) ; } } catch ( final FileNotFoundException e ) { this . logger . log ( Level . SEVERE , "Can't open " + filename , e ) ; throw new IOException ( e ) ; } } | Save the document to filename . |
1,883 | public F content ( final String string ) { this . curRegionBox . set ( Text . content ( string ) ) ; return ( F ) this ; } | Set the text content of the section |
1,884 | public static Footer simpleFooter ( final String text , final TextStyle ts ) { return new SimplePageSectionBuilder ( ) . text ( Text . styledContent ( text , ts ) ) . buildFooter ( ) ; } | Create a simple footer with a styled text |
1,885 | public static Header simpleHeader ( final String text , final TextStyle ts ) { return new SimplePageSectionBuilder ( ) . text ( Text . styledContent ( text , ts ) ) . buildHeader ( ) ; } | Create a simple header with a styled text |
1,886 | public BordersBuilder all ( final Length size , final Color color , final BorderAttribute . Style style ) { return this . all ( new BorderAttribute ( size , color , style ) ) ; } | Set all borders |
1,887 | public TableCellStyle addChildCellStyle ( final TableCellStyle style , final TableCell . Type type ) { final TableCellStyle newStyle ; final DataStyle dataStyle = this . format . getDataStyle ( type ) ; if ( dataStyle == null ) { newStyle = style ; } else { newStyle = this . stylesContainer . addChildCellStyle ( style , dataStyle ) ; } return newStyle ; } | Create an automatic style for this TableCellStyle and this type of cell . Do not produce any effect if the type is Type . STRING or Type . VOID . |
1,888 | public void flushRows ( final XMLUtil util , final ZipUTF8Writer writer , final SettingsElement settingsElement ) throws IOException { this . ensureContentBegin ( util , writer ) ; final int lastTableIndex = this . tables . size ( ) - 1 ; if ( lastTableIndex == - 1 ) return ; int tableIndex = this . flushPosition . getTableIndex ( ) ; Table table = this . tables . get ( tableIndex ) ; if ( tableIndex < lastTableIndex ) { table . flushRemainingRowsFrom ( util , writer , this . flushPosition . getLastRowIndex ( ) + 1 ) ; settingsElement . addTableConfig ( table . getConfigEntry ( ) ) ; tableIndex ++ ; while ( tableIndex < lastTableIndex ) { table = this . tables . get ( tableIndex ) ; table . appendXMLToContentEntry ( util , writer ) ; settingsElement . addTableConfig ( table . getConfigEntry ( ) ) ; tableIndex ++ ; } table = this . tables . get ( lastTableIndex ) ; table . flushAllAvailableRows ( util , writer ) ; } else { table . flushSomeAvailableRowsFrom ( util , writer , this . flushPosition . getLastRowIndex ( ) + 1 ) ; } this . flushPosition . set ( lastTableIndex , this . tables . get ( lastTableIndex ) . getLastRowNumber ( ) ) ; } | Flush the rows from the last position to the current position |
1,889 | public void flushTables ( final XMLUtil util , final ZipUTF8Writer writer ) throws IOException { this . ensureContentBegin ( util , writer ) ; final int lastTableIndex = this . tables . size ( ) - 1 ; if ( lastTableIndex < 0 ) return ; int tableIndex = this . flushPosition . getTableIndex ( ) ; Table table = this . tables . get ( tableIndex ) ; table . flushRemainingRowsFrom ( util , writer , this . flushPosition . getLastRowIndex ( ) + 1 ) ; tableIndex ++ ; while ( tableIndex <= lastTableIndex ) { table = this . tables . get ( tableIndex ) ; table . appendXMLToContentEntry ( util , writer ) ; tableIndex ++ ; } } | Flush the tables . |
1,890 | public void writePostamble ( final XMLUtil util , final ZipUTF8Writer writer ) throws IOException { if ( this . autofilters != null ) this . appendAutofilters ( writer , util ) ; writer . write ( "</office:spreadsheet>" ) ; writer . write ( "</office:body>" ) ; writer . write ( "</office:document-content>" ) ; writer . flush ( ) ; writer . closeEntry ( ) ; } | Write the postamble into the given writer . Used by the FinalizeFlusher and by standard write method |
1,891 | public void writePreamble ( final XMLUtil util , final ZipUTF8Writer writer ) throws IOException { writer . putNextEntry ( new ZipEntry ( "content.xml" ) ) ; writer . write ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ) ; writer . write ( "<office:document-content xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" " + "xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\" " + "xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\" " + "xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" " + "xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\" " + "xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\" " + "xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" " + "xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\" " + "xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\" " + "xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\" " + "xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\" " + "xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\" " + "xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\" xmlns:math=\"http://www" + ".w3.org/1998/Math/MathML\" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\" " + "xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\" " + "xmlns:ooo=\"http://openoffice.org/2004/office\" xmlns:ooow=\"http://openoffice" + ".org/2004/writer\" xmlns:oooc=\"http://openoffice.org/2004/calc\" xmlns:dom=\"http://www" + ".w3.org/2001/xml-events\" xmlns:xforms=\"http://www.w3.org/2002/xforms\" " + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www" + ".w3.org/2001/XMLSchema-instance\" office:version=\"1.1\">" ) ; writer . write ( "<office:scripts/>" ) ; this . stylesContainer . writeFontFaceDecls ( util , writer ) ; writer . write ( "<office:automatic-styles>" ) ; this . stylesContainer . writeHiddenDataStyles ( util , writer ) ; this . stylesContainer . writeContentAutomaticStyles ( util , writer ) ; writer . write ( "</office:automatic-styles>" ) ; writer . write ( "<office:body>" ) ; writer . write ( "<office:spreadsheet>" ) ; } | Write the preamble into the given writer . Used by the MetaAndStylesElementsFlusher and by standard write method |
1,892 | public TextBuilder parStyledContent ( final String text , final TextStyle ts ) { return this . par ( ) . styledSpan ( text , ts ) ; } | Create a new paragraph with a text content |
1,893 | public void addChildCellStyle ( final TableCellStyle style , final TableCell . Type type ) { this . odsElements . addChildCellStyle ( style , type ) ; } | Add a cell style for a given data type . Use only if you want to flush data before the end of the document construction . Do not produce any effect if the type is Type . STRING or Type . VOID |
1,894 | public static PreprocessedRowsFlusher create ( final XMLUtil xmlUtil , final List < TableRow > tableRows ) throws IOException { return new PreprocessedRowsFlusher ( xmlUtil , tableRows , new StringBuilder ( STRING_BUILDER_SIZE ) ) ; } | Create an new rows flusher |
1,895 | public static Text styledContent ( final String text , final TextStyle ts ) { return Text . builder ( ) . parStyledContent ( text , ts ) . build ( ) ; } | Create a simple Text object with a style |
1,896 | public synchronized void flushAdaptee ( ) throws IOException { OdsFlusher flusher = this . flushers . poll ( ) ; if ( flusher == null ) return ; while ( flusher != null ) { this . adaptee . update ( flusher ) ; if ( flusher . isEnd ( ) ) { this . stopped = true ; this . notifyAll ( ) ; return ; } flusher = this . flushers . poll ( ) ; } try { this . wait ( ) ; } catch ( final InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; throw new RuntimeException ( e ) ; } this . notifyAll ( ) ; } | Flushes all available flushers to the adaptee writer . The thread falls asleep if we reach the end of the queue without a FinalizeFlusher . |
1,897 | public synchronized void waitForData ( ) { while ( this . flushers . isEmpty ( ) && this . isNotStopped ( ) ) { try { this . wait ( ) ; } catch ( final InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; throw new RuntimeException ( e ) ; } } } | wait for the data |
1,898 | public String escapeTableName ( final String tableName ) { boolean toQuote = false ; int apostropheCount = 0 ; for ( int i = 0 ; i < tableName . length ( ) ; i ++ ) { final char c = tableName . charAt ( i ) ; if ( Character . isWhitespace ( c ) || c == '.' ) { toQuote = true ; } else if ( c == '\'' ) { toQuote = true ; apostropheCount += 1 ; } } final StringBuilder sb = new StringBuilder ( tableName . length ( ) + ( toQuote ? 2 : 0 ) + apostropheCount ) ; if ( toQuote ) { sb . append ( SINGLE_QUOTE ) ; } for ( int i = 0 ; i < tableName . length ( ) ; i ++ ) { final char c = tableName . charAt ( i ) ; sb . append ( c ) ; if ( c == '\'' ) { sb . append ( SINGLE_QUOTE ) ; } } if ( toQuote ) { sb . append ( SINGLE_QUOTE ) ; } return sb . toString ( ) ; } | 9 . 2 . 1 Referencing Table Cells |
1,899 | public TableCellStyle addChildCellStyle ( final TableCellStyle style , final DataStyle dataStyle ) { final ChildCellStyle childKey = new ChildCellStyle ( style , dataStyle ) ; TableCellStyle anonymousStyle = this . anonymousStyleByChildCellStyle . get ( childKey ) ; if ( anonymousStyle == null ) { this . addDataStyle ( dataStyle ) ; if ( ! style . hasParent ( ) ) { this . addContentFontFaceContainerStyle ( style ) ; } final String name = style . getRealName ( ) + "-_-" + dataStyle . getName ( ) ; final TableCellStyleBuilder anonymousStyleBuilder = TableCellStyle . builder ( name ) . parentCellStyle ( style ) . dataStyle ( dataStyle ) ; if ( dataStyle . isHidden ( ) ) { anonymousStyleBuilder . hidden ( ) ; } anonymousStyle = anonymousStyleBuilder . build ( ) ; this . addContentFontFaceContainerStyle ( anonymousStyle ) ; this . anonymousStyleByChildCellStyle . put ( childKey , anonymousStyle ) ; } return anonymousStyle ; } | Add a child style that mixes the cell style with a data style to the container |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.