idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
27,300
public static boolean isHaveAttribute ( AttributeSet attrs , String attribute ) { return attrs . getAttributeValue ( Ui . androidStyleNameSpace , attribute ) != null ; }
Check the AttributeSet values have a attribute String on user set the attribute resource . Form android styles namespace
27,301
protected int setPaintAlpha ( Paint paint , int alpha ) { final int prevAlpha = paint . getAlpha ( ) ; paint . setAlpha ( Ui . modulateAlpha ( prevAlpha , alpha ) ) ; return prevAlpha ; }
Set the draw paint alpha by modulateAlpha
27,302
public static Reflector with ( String name , ClassLoader classLoader ) throws ReflectException { return with ( getClassForName ( name , classLoader ) ) ; }
Create a Reflector by class name form ClassLoader
27,303
public Reflector set ( String name , Object value ) throws ReflectException { try { Field field = field0 ( name ) ; field . setAccessible ( true ) ; field . set ( obj , unwrap ( value ) ) ; return this ; } catch ( Exception e ) { throw new ReflectException ( e ) ; } }
Set the target field value
27,304
@ SuppressWarnings ( "RedundantTypeArguments" ) public < T > T get ( String name ) throws ReflectException { return field ( name ) . < T > get ( ) ; }
Get the target field value
27,305
public Reflector create ( Object ... args ) throws ReflectException { Class < ? > [ ] types = getTypes ( args ) ; try { Constructor < ? > constructor = type ( ) . getDeclaredConstructor ( types ) ; return with ( constructor , args ) ; } catch ( NoSuchMethodException e ) { for ( Constructor < ? > constructor : type ( ) . getDeclaredConstructors ( ) ) { if ( match ( constructor . getParameterTypes ( ) , types ) ) { return with ( constructor , args ) ; } } throw new ReflectException ( e ) ; } }
We can create class by args structural parameters
27,306
@ SuppressLint ( "DefaultLocale" ) private static String toLowerCaseFirstOne ( String string ) { int length = string . length ( ) ; if ( length == 0 || Character . isLowerCase ( string . charAt ( 0 ) ) ) { return string ; } else if ( length == 1 ) { return string . toLowerCase ( ) ; } else { return ( new StringBuilder ( ) ) . append ( Character . toLowerCase ( string . charAt ( 0 ) ) ) . append ( string . substring ( 1 ) ) . toString ( ) ; } }
Change string first char to lower case
27,307
public static < T > Class < ? > [ ] getClasses ( Type [ ] types ) { if ( types == null ) return null ; if ( types . length == 0 ) return new Class < ? > [ 0 ] ; Class < ? > [ ] classes = new Class [ types . length ] ; for ( int i = 0 ; i < types . length ; i ++ ) { classes [ i ] = getClass ( types [ i ] ) ; } return classes ; }
Get the underlying class array for a type array or null if the type is a variable type .
27,308
public void handleMessage ( Message msg ) { if ( msg . what == ASYNC ) { mAsyncDispatcher . dispatch ( ) ; } else if ( msg . what == SYNC ) { mSyncDispatcher . dispatch ( ) ; } else super . handleMessage ( msg ) ; }
Run in main thread
27,309
public void setBackgroundColorRes ( int colorRes ) { ColorStateList colorStateList = UiCompat . getColorStateList ( getResources ( ) , colorRes ) ; if ( colorStateList == null ) setBackgroundColor ( 0 ) ; else setBackgroundColor ( colorStateList . getDefaultColor ( ) ) ; }
Set the background color by resource id
27,310
protected void setLoadingDrawable ( LoadingDrawable drawable ) { if ( drawable == null ) { throw new NullPointerException ( "LoadingDrawable is null, You can only set the STYLE_CIRCLE and STYLE_LINE parameters." ) ; } else { drawable . setCallback ( this ) ; mLoadingDrawable = drawable ; invalidate ( ) ; requestLayout ( ) ; } }
In this we set LoadingDrawable really
27,311
public void setBorder ( int flag , int size , int color ) { if ( mBorder != flag || mBorderSize != size || mBorderColor != color ) { mBorder = flag ; mBorderSize = size ; mBorderColor = color ; if ( flag <= 0 ) { mBorderDrawable = null ; } else { RectF borderRect ; if ( ( flag & BORDER_ALL ) == BORDER_ALL ) borderRect = new RectF ( size , size , size , size ) ; else { int l = 0 , t = 0 , r = 0 , b = 0 ; if ( ( flag & BORDER_LEFT ) == BORDER_LEFT ) l = size ; if ( ( flag & BORDER_RIGHT ) == BORDER_RIGHT ) r = size ; if ( ( flag & BORDER_TOP ) == BORDER_TOP ) t = size ; if ( ( flag & BORDER_BOTTOM ) == BORDER_BOTTOM ) b = size ; borderRect = new RectF ( l , t , r , b ) ; } if ( mBorderDrawable == null ) { ShapeDrawable drawable = new ShapeDrawable ( new BorderShape ( borderRect ) ) ; Paint paint = drawable . getPaint ( ) ; paint . setColor ( color ) ; drawable . setCallback ( this ) ; mBorderDrawable = drawable ; } else { ShapeDrawable drawable = ( ShapeDrawable ) mBorderDrawable ; Paint paint = drawable . getPaint ( ) ; paint . setColor ( color ) ; BorderShape shape = ( BorderShape ) drawable . getShape ( ) ; shape . setBorder ( borderRect ) ; } } invalidate ( ) ; } }
Set the border You can init border size color and decision that direction contains border
27,312
private static void destroyService ( ) { Thread thread = DESTROY_THREAD ; if ( thread == null ) { thread = new Thread ( ) { public void run ( ) { try { Thread . sleep ( 5000 ) ; dispose ( ) ; } catch ( InterruptedException e ) { } DESTROY_THREAD = null ; } } ; thread . setDaemon ( true ) ; DESTROY_THREAD = thread ; thread . start ( ) ; } }
Destroy Service After 5 seconds run
27,313
private static void cancelDestroyService ( ) { Thread thread = DESTROY_THREAD ; if ( thread != null ) { DESTROY_THREAD = null ; thread . interrupt ( ) ; } }
Cancel Destroy Service
27,314
private static void bindService ( ) { synchronized ( Command . class ) { if ( ! IS_BIND ) { Context context = Cmd . getContext ( ) ; if ( context == null ) { throw new NullPointerException ( "Context not should null. Please call Cmd.init(Context)" ) ; } else { context . bindService ( new Intent ( context , CommandService . class ) , I_CONN , Context . BIND_AUTO_CREATE ) ; IS_BIND = true ; } } } }
Start bind Service
27,315
private static String commandRun ( Command command ) { if ( I_COMMAND == null ) { synchronized ( I_LOCK ) { if ( I_COMMAND == null ) { try { I_LOCK . wait ( ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } } } } cancelDestroyService ( ) ; int count = 5 ; Exception error = null ; while ( count > 0 ) { if ( command . isCancel ) { if ( command . mListener != null ) command . mListener . onCancel ( ) ; break ; } try { command . mResult = I_COMMAND . command ( command . mId , command . mTimeout , command . mParameters ) ; if ( command . mListener != null ) command . mListener . onCompleted ( command . mResult ) ; break ; } catch ( Exception e ) { error = e ; count -- ; try { Thread . sleep ( 3000 ) ; } catch ( InterruptedException e1 ) { e1 . printStackTrace ( ) ; } } } if ( count <= 0 && command . mListener != null ) { command . mListener . onError ( error ) ; } if ( I_COMMAND != null ) { try { if ( I_COMMAND . getTaskCount ( ) <= 0 ) destroyService ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } return command . mResult ; }
Run do Command
27,316
public static void dispose ( ) { synchronized ( Command . class ) { if ( IS_BIND ) { Context context = Cmd . getContext ( ) ; if ( context != null ) { try { context . unbindService ( I_CONN ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } I_COMMAND = null ; IS_BIND = false ; } } }
Dispose unbindService stopService
27,317
private int computeFlags ( int curFlags ) { curFlags &= ~ ( WindowManager . LayoutParams . FLAG_IGNORE_CHEEK_PRESSES | WindowManager . LayoutParams . FLAG_NOT_FOCUSABLE | WindowManager . LayoutParams . FLAG_NOT_TOUCHABLE | WindowManager . LayoutParams . FLAG_WATCH_OUTSIDE_TOUCH | WindowManager . LayoutParams . FLAG_LAYOUT_NO_LIMITS | WindowManager . LayoutParams . FLAG_ALT_FOCUSABLE_IM ) ; curFlags |= WindowManager . LayoutParams . FLAG_IGNORE_CHEEK_PRESSES ; curFlags |= WindowManager . LayoutParams . FLAG_NOT_FOCUSABLE ; curFlags |= WindowManager . LayoutParams . FLAG_NOT_TOUCHABLE ; curFlags |= WindowManager . LayoutParams . FLAG_LAYOUT_NO_LIMITS ; return curFlags ; }
I m NOT completely sure how all this bitwise things work ...
27,318
public void setProgress ( float progress ) { if ( progress < 0 ) mProgress = 0 ; else if ( mProgress > 1 ) mProgress = 1 ; else mProgress = progress ; stop ( ) ; onProgressChange ( mProgress ) ; invalidateSelf ( ) ; }
Set the draw progress The progress include 0~1 float On changed stop animation draw
27,319
public void setTrackColor ( ColorStateList stateList ) { mTrackStateList = stateList ; mTrackColor = mTrackStateList . getDefaultColor ( ) ; if ( mAlpha < 255 ) { mCurTrackColor = Ui . modulateColorAlpha ( mTrackColor , mAlpha ) ; } else { mCurTrackColor = mTrackColor ; } }
Set the Track ColorStateList
27,320
public void setScrubberColor ( ColorStateList stateList ) { mScrubberStateList = stateList ; mScrubberColor = mScrubberStateList . getDefaultColor ( ) ; if ( mAlpha < 255 ) { mCurScrubberColor = Ui . modulateColorAlpha ( mScrubberColor , mAlpha ) ; } else { mCurScrubberColor = mScrubberColor ; } }
Set the Scrubber ColorStateList
27,321
public void setThumbColor ( ColorStateList stateList ) { mThumbStateList = stateList ; mThumbColor = mThumbStateList . getDefaultColor ( ) ; if ( mAlpha < 255 ) { mCurThumbColor = Ui . modulateColorAlpha ( mThumbColor , mAlpha ) ; } else { mCurThumbColor = mThumbColor ; } }
Set the Thumb ColorStateList
27,322
protected boolean changeColor ( int color ) { boolean bFlag = mColor != color ; if ( bFlag ) { mColor = color ; onColorChange ( color ) ; invalidateSelf ( ) ; } return bFlag ; }
Set CurrentColor value
27,323
public static Result onBackground ( Action action ) { final HandlerPoster poster = getBackgroundPoster ( ) ; if ( Looper . myLooper ( ) == poster . getLooper ( ) ) { action . call ( ) ; return new ActionAsyncTask ( action , true ) ; } ActionAsyncTask task = new ActionAsyncTask ( action ) ; poster . async ( task ) ; return task ; }
Asynchronously The current thread asynchronous run relative to the sub thread not blocking the current thread
27,324
public static Result onUiAsync ( Action action ) { if ( Looper . myLooper ( ) == Looper . getMainLooper ( ) ) { action . call ( ) ; return new ActionAsyncTask ( action , true ) ; } ActionAsyncTask task = new ActionAsyncTask ( action ) ; getUiPoster ( ) . async ( task ) ; return task ; }
Asynchronously The current thread asynchronous run relative to the main thread not blocking the current thread
27,325
public static void onUiSync ( Action action ) { if ( Looper . myLooper ( ) == Looper . getMainLooper ( ) ) { action . call ( ) ; return ; } ActionSyncTask poster = new ActionSyncTask ( action ) ; getUiPoster ( ) . sync ( poster ) ; poster . waitRun ( ) ; }
Synchronously The current thread relative thread synchronization operation blocking the current thread thread for the main thread to complete
27,326
void onComplete ( TraceRouteThread trace , boolean isError , boolean isArrived , TraceRouteContainer routeContainer ) { if ( threads != null ) { synchronized ( mLock ) { try { threads . remove ( trace ) ; } catch ( NullPointerException e ) { e . printStackTrace ( ) ; } } } if ( ! isDone ) { if ( isError ) this . errorCount ++ ; this . isArrived = isArrived ; if ( routeContainers != null && routeContainer != null ) routeContainers . add ( routeContainer ) ; } if ( countDownLatch != null && countDownLatch . getCount ( ) > 0 ) countDownLatch . countDown ( ) ; }
Will the run thread is complete should call this method
27,327
private static List < String > parseFontFamily ( String val ) { List < String > fonts = null ; TextScanner scan = new TextScanner ( val ) ; while ( true ) { String item = scan . nextQuotedString ( ) ; if ( item == null ) item = scan . nextTokenWithWhitespace ( ',' ) ; if ( item == null ) break ; if ( fonts == null ) fonts = new ArrayList < > ( ) ; fonts . add ( item ) ; scan . skipCommaWhitespace ( ) ; if ( scan . empty ( ) ) break ; } return fonts ; }
Parse a font family list
27,328
private static Length parseFontSize ( String val ) { try { Length size = FontSizeKeywords . get ( val ) ; if ( size == null ) size = parseLength ( val ) ; return size ; } catch ( SVGParseException e ) { return null ; } }
Parse a font size keyword or numerical value
27,329
private static Style . FontStyle parseFontStyle ( String val ) { switch ( val ) { case "italic" : return Style . FontStyle . Italic ; case "normal" : return Style . FontStyle . Normal ; case "oblique" : return Style . FontStyle . Oblique ; default : return null ; } }
Parse a font style keyword
27,330
private static Style . FillRule parseFillRule ( String val ) { if ( "nonzero" . equals ( val ) ) return Style . FillRule . NonZero ; if ( "evenodd" . equals ( val ) ) return Style . FillRule . EvenOdd ; return null ; }
Parse fill rule
27,331
private static Style . LineCap parseStrokeLineCap ( String val ) { if ( "butt" . equals ( val ) ) return Style . LineCap . Butt ; if ( "round" . equals ( val ) ) return Style . LineCap . Round ; if ( "square" . equals ( val ) ) return Style . LineCap . Square ; return null ; }
Parse stroke - linecap
27,332
private static Style . LineJoin parseStrokeLineJoin ( String val ) { if ( "miter" . equals ( val ) ) return Style . LineJoin . Miter ; if ( "round" . equals ( val ) ) return Style . LineJoin . Round ; if ( "bevel" . equals ( val ) ) return Style . LineJoin . Bevel ; return null ; }
Parse stroke - linejoin
27,333
private static Length [ ] parseStrokeDashArray ( String val ) { TextScanner scan = new TextScanner ( val ) ; scan . skipWhitespace ( ) ; if ( scan . empty ( ) ) return null ; Length dash = scan . nextLength ( ) ; if ( dash == null ) return null ; if ( dash . isNegative ( ) ) return null ; float sum = dash . floatValue ( ) ; List < Length > dashes = new ArrayList < > ( ) ; dashes . add ( dash ) ; while ( ! scan . empty ( ) ) { scan . skipCommaWhitespace ( ) ; dash = scan . nextLength ( ) ; if ( dash == null ) return null ; if ( dash . isNegative ( ) ) return null ; dashes . add ( dash ) ; sum += dash . floatValue ( ) ; } if ( sum == 0f ) return null ; return dashes . toArray ( new Length [ dashes . size ( ) ] ) ; }
Parse stroke - dasharray
27,334
private static VectorEffect parseVectorEffect ( String val ) { switch ( val ) { case NONE : return Style . VectorEffect . None ; case "non-scaling-stroke" : return Style . VectorEffect . NonScalingStroke ; default : return null ; } }
Parse a vector effect keyword
27,335
private static RenderQuality parseRenderQuality ( String val ) { switch ( val ) { case "auto" : return RenderQuality . auto ; case "optimizeQuality" : return RenderQuality . optimizeQuality ; case "optimizeSpeed" : return RenderQuality . optimizeSpeed ; default : return null ; } }
Parse a rendering quality property
27,336
private static Set < String > parseSystemLanguage ( String val ) { TextScanner scan = new TextScanner ( val ) ; HashSet < String > result = new HashSet < > ( ) ; while ( ! scan . empty ( ) ) { String language = scan . nextToken ( ) ; int hyphenPos = language . indexOf ( '-' ) ; if ( hyphenPos != - 1 ) { language = language . substring ( 0 , hyphenPos ) ; } language = new Locale ( language , "" , "" ) . getLanguage ( ) ; result . add ( language ) ; scan . skipWhitespace ( ) ; } return result ; }
must be supported if we are to render this element
27,337
public void setSVG ( SVG svg , String css ) { if ( svg == null ) throw new IllegalArgumentException ( "Null value passed to setSVG()" ) ; this . svg = svg ; this . renderOptions . css ( css ) ; doRender ( ) ; }
Directly set the SVG and the CSS .
27,338
@ SuppressWarnings ( { "WeakerAccess" , "unused" } ) public static SVG getFromAsset ( AssetManager assetManager , String filename ) throws SVGParseException , IOException { SVGParser parser = new SVGParser ( ) ; InputStream is = assetManager . open ( filename ) ; try { return parser . parse ( is , enableInternalEntities ) ; } finally { try { is . close ( ) ; } catch ( IOException e ) { } } }
Read and parse an SVG from the assets folder .
27,339
@ SuppressWarnings ( { "WeakerAccess" , "unused" } ) public RectF getDocumentViewBox ( ) { if ( this . rootElement == null ) throw new IllegalArgumentException ( "SVG document is empty" ) ; if ( this . rootElement . viewBox == null ) return null ; return this . rootElement . viewBox . toRectF ( ) ; }
Returns the viewBox attribute of the current SVG document .
27,340
public Typeface resolveFont ( String fontFamily , int fontWeight , String fontStyle ) { Log . i ( TAG , "resolveFont(" + fontFamily + "," + fontWeight + "," + fontStyle + ")" ) ; try { return Typeface . createFromAsset ( assetManager , fontFamily + ".ttf" ) ; } catch ( RuntimeException ignored ) { } try { return Typeface . createFromAsset ( assetManager , fontFamily + ".otf" ) ; } catch ( RuntimeException e ) { return null ; } }
Attempt to find the specified font in the assets folder and return a Typeface object . For the font name Foo first the file Foo . ttf will be tried and if that fails Foo . otf .
27,341
public String resolveCSSStyleSheet ( String url ) { Log . i ( TAG , "resolveCSSStyleSheet(" + url + ")" ) ; return getAssetAsString ( url ) ; }
Attempt to find the specified stylesheet file in the assets folder and return its string contents .
27,342
private void render ( SVG . Svg obj ) { Box viewPort = makeViewPort ( obj . x , obj . y , obj . width , obj . height ) ; render ( obj , viewPort , obj . viewBox , obj . preserveAspectRatio ) ; }
Renderers for each element type
27,343
private Box makeViewPort ( Length x , Length y , Length width , Length height ) { float _x = ( x != null ) ? x . floatValueX ( this ) : 0f ; float _y = ( y != null ) ? y . floatValueY ( this ) : 0f ; Box viewPortUser = getCurrentViewPortInUserUnits ( ) ; float _w = ( width != null ) ? width . floatValueX ( this ) : viewPortUser . width ; float _h = ( height != null ) ? height . floatValueY ( this ) : viewPortUser . height ; return new Box ( _x , _y , _w , _h ) ; }
Derive the viewport from the x y width and height attributes of an object
27,344
private void checkForClipPath_OldStyle ( SvgElement obj , Box boundingBox ) { SvgObject ref = obj . document . resolveIRI ( state . style . clipPath ) ; if ( ref == null ) { error ( "ClipPath reference '%s' not found" , state . style . clipPath ) ; return ; } ClipPath clipPath = ( ClipPath ) ref ; if ( clipPath . children . isEmpty ( ) ) { canvas . clipRect ( 0 , 0 , 0 , 0 ) ; return ; } boolean userUnits = ( clipPath . clipPathUnitsAreUser == null || clipPath . clipPathUnitsAreUser ) ; if ( ( obj instanceof SVG . Group ) && ! userUnits ) { warn ( "<clipPath clipPathUnits=\"objectBoundingBox\"> is not supported when referenced from container elements (like %s)" , obj . getNodeName ( ) ) ; return ; } clipStatePush ( ) ; if ( ! userUnits ) { Matrix m = new Matrix ( ) ; m . preTranslate ( boundingBox . minX , boundingBox . minY ) ; m . preScale ( boundingBox . width , boundingBox . height ) ; canvas . concat ( m ) ; } if ( clipPath . transform != null ) { canvas . concat ( clipPath . transform ) ; } state = findInheritFromAncestorState ( clipPath ) ; checkForClipPath ( clipPath ) ; Path combinedPath = new Path ( ) ; for ( SvgObject child : clipPath . children ) { addObjectToClip ( child , true , combinedPath , new Matrix ( ) ) ; } canvas . clipPath ( combinedPath ) ; clipStatePop ( ) ; }
Pre - KitKat . Kept for backwards compatibility .
27,345
private void clipStatePush ( ) { CanvasLegacy . save ( canvas , CanvasLegacy . MATRIX_SAVE_FLAG ) ; stateStack . push ( state ) ; state = new RendererState ( state ) ; }
destroy the clip region we are trying to build .
27,346
public RenderOptions css ( String css ) { CSSParser parser = new CSSParser ( CSSParser . Source . RenderOptions ) ; this . css = parser . parse ( css ) ; return this ; }
Specifies some additional CSS rules that will be applied during render in addition to any specified in the file itself .
27,347
public void setChromeColor ( int color ) { if ( chromeColor != color ) { viewBorderPaint . setColor ( color ) ; chromeColor = color ; invalidate ( ) ; } }
Set the view border chrome color .
27,348
public void setChromeShadowColor ( int color ) { if ( chromeShadowColor != color ) { viewBorderPaint . setShadowLayer ( 1 , - 1 , 1 , color ) ; chromeShadowColor = color ; invalidate ( ) ; } }
Set the view border chrome shadow color .
27,349
public void writeToStream ( final String format , final OutputStream outputStream ) { try { LOGGER . debug ( "Writing WordCloud image data to output stream" ) ; ImageIO . write ( bufferedImage , format , outputStream ) ; LOGGER . debug ( "Done writing WordCloud image data to output stream" ) ; } catch ( final IOException e ) { LOGGER . error ( e . getMessage ( ) , e ) ; throw new KumoException ( "Could not write wordcloud to outputstream due to an IOException" , e ) ; } }
Write wordcloud image data to stream in the given format
27,350
protected void drawForegroundToBackground ( ) { if ( backgroundColor == null ) { return ; } final BufferedImage backgroundBufferedImage = new BufferedImage ( dimension . width , dimension . height , this . bufferedImage . getType ( ) ) ; final Graphics graphics = backgroundBufferedImage . getGraphics ( ) ; graphics . setColor ( backgroundColor ) ; graphics . fillRect ( 0 , 0 , dimension . width , dimension . height ) ; graphics . drawImage ( bufferedImage , 0 , 0 , null ) ; final Graphics graphics2 = bufferedImage . getGraphics ( ) ; graphics2 . drawImage ( backgroundBufferedImage , 0 , 0 , null ) ; }
create background then draw current word cloud on top of it . Doing it this way preserves the transparency of the this . bufferedImage s pixels for a more flexible pixel perfect collision
27,351
static int computeRadius ( final Dimension dimension , final Point start ) { final int maxDistanceX = Math . max ( start . x , dimension . width - start . x ) + 1 ; final int maxDistanceY = Math . max ( start . y , dimension . height - start . y ) + 1 ; return ( int ) Math . ceil ( Math . sqrt ( maxDistanceX * maxDistanceX + maxDistanceY * maxDistanceY ) ) ; }
compute the maximum radius for the placing spiral
27,352
protected boolean place ( final Word word , final Point start ) { final Graphics graphics = this . bufferedImage . getGraphics ( ) ; final int maxRadius = computeRadius ( dimension , start ) ; final Point position = word . getPosition ( ) ; for ( int r = 0 ; r < maxRadius ; r += 2 ) { for ( int x = Math . max ( - start . x , - r ) ; x <= Math . min ( r , dimension . width - start . x - 1 ) ; x ++ ) { position . x = start . x + x ; final int offset = ( int ) Math . sqrt ( r * r - x * x ) ; position . y = start . y + offset ; if ( position . y >= 0 && position . y < dimension . height && canPlace ( word ) ) { collisionRaster . mask ( word . getCollisionRaster ( ) , position ) ; graphics . drawImage ( word . getBufferedImage ( ) , position . x , position . y , null ) ; return true ; } position . y = start . y - offset ; if ( offset != 0 && position . y >= 0 && position . y < dimension . height && canPlace ( word ) ) { collisionRaster . mask ( word . getCollisionRaster ( ) , position ) ; graphics . drawImage ( word . getBufferedImage ( ) , position . x , position . y , null ) ; return true ; } } } return false ; }
try to place in center build out in a spiral trying to place words for N steps
27,353
private static List < Color > createLinearGradient ( final Color color1 , final Color color2 , final int gradientSteps ) { final List < Color > colors = new ArrayList < > ( gradientSteps + 1 ) ; colors . add ( color1 ) ; for ( int i = 1 ; i < gradientSteps ; i ++ ) { float ratio = ( float ) i / ( float ) gradientSteps ; final float red = color2 . getRed ( ) * ratio + color1 . getRed ( ) * ( 1 - ratio ) ; final float green = color2 . getGreen ( ) * ratio + color1 . getGreen ( ) * ( 1 - ratio ) ; final float blue = color2 . getBlue ( ) * ratio + color1 . getBlue ( ) * ( 1 - ratio ) ; colors . add ( new Color ( Math . round ( red ) , Math . round ( green ) , Math . round ( blue ) ) ) ; } colors . add ( color2 ) ; return colors ; }
Creates a linear Gradient between two colors
27,354
public void writeToFile ( final String outputFileName , final boolean blockThread , final boolean shutdownExecutor ) { if ( blockThread ) { waitForFuturesToBlockCurrentThread ( ) ; } super . writeToFile ( outputFileName ) ; if ( shutdownExecutor ) { this . shutdown ( ) ; } }
Writes the wordcloud to an imagefile .
27,355
private void initSyntaxRule ( ) throws SQLException { String identifierQuoteString = meta . getIdentifierQuoteString ( ) ; if ( identifierQuoteString . length ( ) > 1 ) { sqlLine . error ( "Identifier quote string is '" + identifierQuoteString + "'; quote strings longer than 1 char are not supported" ) ; identifierQuoteString = null ; } final String productName = meta . getDatabaseProductName ( ) ; final Set < String > keywords = Stream . of ( meta . getSQLKeywords ( ) . split ( "," ) ) . collect ( Collectors . toSet ( ) ) ; dialect = DialectImpl . create ( keywords , identifierQuoteString , productName , meta . storesUpperCaseIdentifiers ( ) ) ; }
Initializes a syntax rule for a given database connection .
27,356
boolean connect ( ) throws SQLException { try { if ( driver != null && driver . length ( ) != 0 ) { Class . forName ( driver ) ; } } catch ( ClassNotFoundException cnfe ) { return sqlLine . error ( cnfe ) ; } boolean foundDriver = false ; Driver theDriver = null ; try { theDriver = DriverManager . getDriver ( url ) ; foundDriver = theDriver != null ; } catch ( Exception e ) { } if ( ! foundDriver ) { sqlLine . output ( sqlLine . loc ( "autoloading-known-drivers" , url ) ) ; sqlLine . registerKnownDrivers ( ) ; theDriver = DriverManager . getDriver ( url ) ; } try { close ( ) ; } catch ( Exception e ) { return sqlLine . error ( e ) ; } connection = theDriver . connect ( url , info ) ; meta = ( DatabaseMetaData ) Proxy . newProxyInstance ( DatabaseMetaData . class . getClassLoader ( ) , new Class [ ] { DatabaseMetaData . class } , new DatabaseMetaDataHandler ( connection . getMetaData ( ) ) ) ; try { sqlLine . debug ( sqlLine . loc ( "connected" , meta . getDatabaseProductName ( ) , meta . getDatabaseProductVersion ( ) ) ) ; } catch ( Exception e ) { sqlLine . handleException ( e ) ; } try { sqlLine . debug ( sqlLine . loc ( "driver" , meta . getDriverName ( ) , meta . getDriverVersion ( ) ) ) ; } catch ( Exception e ) { sqlLine . handleException ( e ) ; } try { connection . setAutoCommit ( sqlLine . getOpts ( ) . getAutoCommit ( ) ) ; sqlLine . autocommitStatus ( connection ) ; } catch ( Exception e ) { sqlLine . handleException ( e ) ; } try { sqlLine . getCommands ( ) . isolation ( "isolation: " + sqlLine . getOpts ( ) . getIsolation ( ) , new DispatchCallback ( ) ) ; initSyntaxRule ( ) ; } catch ( Exception e ) { sqlLine . handleException ( e ) ; } sqlLine . showWarnings ( ) ; return true ; }
Connection to the specified data source .
27,357
public Map < String , OutputFormat > getOutputFormats ( SqlLine sqlLine ) { final Map < String , OutputFormat > outputFormats = new HashMap < > ( ) ; outputFormats . put ( "vertical" , new VerticalOutputFormat ( sqlLine ) ) ; outputFormats . put ( "table" , new TableOutputFormat ( sqlLine ) ) ; outputFormats . put ( "csv" , new SeparatedValuesOutputFormat ( sqlLine , "," ) ) ; outputFormats . put ( "tsv" , new SeparatedValuesOutputFormat ( sqlLine , "\t" ) ) ; XmlAttributeOutputFormat xmlAttrs = new XmlAttributeOutputFormat ( sqlLine ) ; outputFormats . put ( "xmlattr" , xmlAttrs ) ; outputFormats . put ( "xmlattrs" , xmlAttrs ) ; outputFormats . put ( "xmlelements" , new XmlElementOutputFormat ( sqlLine ) ) ; outputFormats . put ( "json" , new JsonOutputFormat ( sqlLine ) ) ; return Collections . unmodifiableMap ( outputFormats ) ; }
Override this method to modify known output formats implementations .
27,358
private List < Object > buildMetadataArgs ( String line , String paramName , String [ ] defaultValues ) { final List < Object > list = new ArrayList < > ( ) ; final String [ ] [ ] ret = sqlLine . splitCompound ( line ) ; String [ ] compound ; if ( ret == null || ret . length != 2 ) { if ( defaultValues [ defaultValues . length - 1 ] == null ) { throw new IllegalArgumentException ( sqlLine . loc ( "arg-usage" , ret == null || ret . length == 0 ? "" : ret [ 0 ] [ 0 ] , paramName ) ) ; } compound = new String [ 0 ] ; } else { compound = ret [ 1 ] ; } if ( compound . length <= defaultValues . length ) { list . addAll ( Arrays . asList ( defaultValues ) . subList ( 0 , defaultValues . length - compound . length ) ) ; list . addAll ( Arrays . asList ( compound ) ) ; } else { list . addAll ( Arrays . asList ( compound ) . subList ( 0 , defaultValues . length ) ) ; } return list ; }
Constructs a list of string parameters for a metadata call .
27,359
public void closeall ( String line , DispatchCallback callback ) { close ( null , callback ) ; if ( callback . isSuccess ( ) ) { while ( callback . isSuccess ( ) ) { close ( null , callback ) ; } callback . setToSuccess ( ) ; } callback . setToFailure ( ) ; }
Closes all connections .
27,360
public void close ( String line , DispatchCallback callback ) { if ( sqlLine . getRecordOutputFile ( ) != null ) { stopRecording ( line , callback ) ; } DatabaseConnection databaseConnection = sqlLine . getDatabaseConnection ( ) ; if ( databaseConnection == null ) { callback . setToFailure ( ) ; return ; } try { Connection connection = databaseConnection . getConnection ( ) ; if ( connection != null && ! connection . isClosed ( ) ) { sqlLine . info ( sqlLine . loc ( "closing" , connection . getClass ( ) . getName ( ) ) ) ; connection . close ( ) ; } else { sqlLine . info ( sqlLine . loc ( "already-closed" ) ) ; } } catch ( Exception e ) { callback . setToFailure ( ) ; sqlLine . error ( e ) ; return ; } sqlLine . getDatabaseConnections ( ) . remove ( ) ; callback . setToSuccess ( ) ; }
Closes the current connection . Closes the current file writer .
27,361
public void properties ( String line , DispatchCallback callback ) throws Exception { String example = "" ; example += "Usage: properties <properties file>" + SqlLine . getSeparator ( ) ; String [ ] parts = sqlLine . split ( line ) ; if ( parts . length < 2 ) { callback . setToFailure ( ) ; sqlLine . error ( example ) ; return ; } int successes = 0 ; for ( int i = 1 ; i < parts . length ; i ++ ) { Properties props = new Properties ( ) ; props . load ( new FileInputStream ( parts [ i ] ) ) ; connect ( props , callback ) ; if ( callback . isSuccess ( ) ) { successes ++ ; String nickname = getProperty ( props , "nickname" , "ConnectionNickname" ) ; if ( nickname != null ) { sqlLine . getDatabaseConnection ( ) . setNickname ( nickname ) ; } } } if ( successes != parts . length - 1 ) { callback . setToFailure ( ) ; } else { callback . setToSuccess ( ) ; } }
Connects to the database defined in the specified properties file .
27,362
public void list ( String line , DispatchCallback callback ) { int index = 0 ; DatabaseConnections databaseConnections = sqlLine . getDatabaseConnections ( ) ; sqlLine . info ( sqlLine . loc ( "active-connections" , databaseConnections . size ( ) ) ) ; for ( DatabaseConnection databaseConnection : databaseConnections ) { boolean closed ; try { closed = databaseConnection . connection . isClosed ( ) ; } catch ( Exception e ) { closed = true ; } sqlLine . output ( sqlLine . getColorBuffer ( ) . pad ( " #" + index ++ + "" , 5 ) . pad ( closed ? sqlLine . loc ( "closed" ) : sqlLine . loc ( "open" ) , 9 ) . pad ( databaseConnection . getNickname ( ) , 20 ) . append ( " " + databaseConnection . getUrl ( ) ) ) ; } callback . setToSuccess ( ) ; }
Lists the current connections .
27,363
public void script ( String line , DispatchCallback callback ) { if ( sqlLine . getScriptOutputFile ( ) == null ) { startScript ( line , callback ) ; } else { stopScript ( line , callback ) ; } }
Starts or stops saving a script to a file .
27,364
private void stopScript ( String line , DispatchCallback callback ) { try { sqlLine . getScriptOutputFile ( ) . close ( ) ; } catch ( Exception e ) { sqlLine . handleException ( e ) ; } sqlLine . output ( sqlLine . loc ( "script-closed" , sqlLine . getScriptOutputFile ( ) ) ) ; sqlLine . setScriptOutputFile ( null ) ; callback . setToSuccess ( ) ; }
Stop writing to the script file and close the script .
27,365
private void startScript ( String line , DispatchCallback callback ) { OutputFile outFile = sqlLine . getScriptOutputFile ( ) ; if ( outFile != null ) { callback . setToFailure ( ) ; sqlLine . error ( sqlLine . loc ( "script-already-running" , outFile ) ) ; return ; } String filename ; if ( line . length ( ) == "script" . length ( ) || ( filename = sqlLine . dequote ( line . substring ( "script" . length ( ) + 1 ) ) ) == null ) { sqlLine . error ( "Usage: script <file name>" ) ; callback . setToFailure ( ) ; return ; } try { outFile = new OutputFile ( expand ( filename ) ) ; sqlLine . setScriptOutputFile ( outFile ) ; sqlLine . output ( sqlLine . loc ( "script-started" , outFile ) ) ; callback . setToSuccess ( ) ; } catch ( Exception e ) { callback . setToFailure ( ) ; sqlLine . error ( e ) ; } }
Start writing to the specified script file .
27,366
public void run ( String line , DispatchCallback callback ) { String filename ; if ( line . length ( ) == "run" . length ( ) || ( filename = sqlLine . dequote ( line . substring ( "run" . length ( ) + 1 ) ) ) == null ) { sqlLine . error ( "Usage: run <file name>" ) ; callback . setToFailure ( ) ; return ; } List < String > cmds = new LinkedList < > ( ) ; try { final Parser parser = sqlLine . getLineReader ( ) . getParser ( ) ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( new FileInputStream ( expand ( filename ) ) , StandardCharsets . UTF_8 ) ) ) { final StringBuilder cmd = new StringBuilder ( ) ; boolean needsContinuation ; for ( ; ; ) { final String scriptLine = reader . readLine ( ) ; if ( scriptLine == null ) { break ; } cmd . append ( " \n" ) ; cmd . append ( scriptLine ) ; try { needsContinuation = false ; parser . parse ( cmd . toString ( ) , cmd . length ( ) , Parser . ParseContext . ACCEPT_LINE ) ; } catch ( EOFError e ) { needsContinuation = true ; } if ( ! needsContinuation && ! cmd . toString ( ) . trim ( ) . isEmpty ( ) ) { cmds . add ( maybeTrim ( cmd . toString ( ) ) ) ; cmd . setLength ( 0 ) ; } } if ( SqlLineParser . isSql ( sqlLine , cmd . toString ( ) , Parser . ParseContext . ACCEPT_LINE ) ) { cmd . append ( ";" ) ; cmds . add ( cmd . toString ( ) ) ; } } if ( sqlLine . runCommands ( cmds , callback ) == cmds . size ( ) ) { callback . setToSuccess ( ) ; } else { callback . setToFailure ( ) ; } } catch ( Exception e ) { callback . setToFailure ( ) ; sqlLine . error ( e ) ; } }
Runs a script from the specified file .
27,367
public static String expand ( String filename ) { if ( filename . startsWith ( "~" + File . separator ) ) { try { String home = System . getProperty ( "user.home" ) ; if ( home != null ) { return home + filename . substring ( 1 ) ; } } catch ( SecurityException e ) { } } return filename ; }
Expands ~ to the home directory .
27,368
public void record ( String line , DispatchCallback callback ) { if ( sqlLine . getRecordOutputFile ( ) == null ) { startRecording ( line , callback ) ; } else { stopRecording ( line , callback ) ; } }
Starts or stops saving all output to a file .
27,369
private void stopRecording ( String line , DispatchCallback callback ) { try { sqlLine . getRecordOutputFile ( ) . close ( ) ; } catch ( Exception e ) { sqlLine . handleException ( e ) ; } sqlLine . output ( sqlLine . loc ( "record-closed" , sqlLine . getRecordOutputFile ( ) ) ) ; sqlLine . setRecordOutputFile ( null ) ; callback . setToSuccess ( ) ; }
Stop writing output to the record file .
27,370
private void startRecording ( String line , DispatchCallback callback ) { OutputFile outputFile = sqlLine . getRecordOutputFile ( ) ; if ( outputFile != null ) { callback . setToFailure ( ) ; sqlLine . error ( sqlLine . loc ( "record-already-running" , outputFile ) ) ; return ; } String filename ; if ( line . length ( ) == "record" . length ( ) || ( filename = sqlLine . dequote ( line . substring ( "record" . length ( ) + 1 ) ) ) == null ) { sqlLine . error ( "Usage: record <file name>" ) ; callback . setToFailure ( ) ; return ; } try { outputFile = new OutputFile ( expand ( filename ) ) ; sqlLine . setRecordOutputFile ( outputFile ) ; sqlLine . output ( sqlLine . loc ( "record-started" , outputFile ) ) ; callback . setToSuccess ( ) ; } catch ( Exception e ) { callback . setToFailure ( ) ; sqlLine . error ( e ) ; } }
Start writing to the specified record file .
27,371
public static Status mainWithInputRedirection ( String [ ] args , InputStream inputStream ) throws IOException { return start ( args , inputStream , false ) ; }
Starts the program with redirected input .
27,372
void registerKnownDrivers ( ) { if ( appConfig . allowedDrivers == null ) { return ; } for ( String driverName : appConfig . allowedDrivers ) { try { Class . forName ( driverName ) ; } catch ( Throwable t ) { } } }
Walk through all the known drivers and try to register them .
27,373
boolean isComment ( String line , boolean trim ) { final String trimmedLine = trim ? line . trim ( ) : line ; for ( String comment : getDialect ( ) . getSqlLineOneLineComments ( ) ) { if ( trimmedLine . startsWith ( comment ) ) { return true ; } } return false ; }
Test whether a line is a comment .
27,374
public boolean error ( String msg ) { output ( getColorBuffer ( ) . red ( msg ) , true , errorStream ) ; return false ; }
Issue the specified error message
27,375
boolean assertAutoCommit ( ) { if ( ! assertConnection ( ) ) { return false ; } try { if ( getDatabaseConnection ( ) . connection . getAutoCommit ( ) ) { return error ( loc ( "autocommit-needs-off" ) ) ; } } catch ( Exception e ) { return error ( e ) ; } return true ; }
Ensure that autocommit is on for the current connection
27,376
boolean assertConnection ( ) { try { if ( getDatabaseConnection ( ) == null || getDatabaseConnection ( ) . connection == null ) { return error ( loc ( "no-current-connection" ) ) ; } if ( getDatabaseConnection ( ) . connection . isClosed ( ) ) { return error ( loc ( "connection-is-closed" ) ) ; } } catch ( SQLException sqle ) { return error ( loc ( "no-current-connection" ) ) ; } return true ; }
Assert that we have an active living connection . Print an error message if we do not .
27,377
void showWarnings ( ) { if ( getDatabaseConnection ( ) . connection == null ) { return ; } if ( ! getOpts ( ) . getShowWarnings ( ) ) { return ; } try { showWarnings ( getDatabaseConnection ( ) . connection . getWarnings ( ) ) ; } catch ( Exception e ) { handleException ( e ) ; } }
Print out any warnings that exist for the current connection .
27,378
String [ ] split ( String line , int assertLen , String usage ) { String [ ] ret = split ( line ) ; if ( ret . length != assertLen ) { error ( usage ) ; return null ; } return ret ; }
Split the line based on spaces asserting that the number of words is correct .
27,379
String wrap ( String toWrap , int len , int start ) { StringBuilder buff = new StringBuilder ( ) ; StringBuilder line = new StringBuilder ( ) ; char [ ] head = new char [ start ] ; Arrays . fill ( head , ' ' ) ; for ( StringTokenizer tok = new StringTokenizer ( toWrap , " " ) ; tok . hasMoreTokens ( ) ; ) { String next = tok . nextToken ( ) ; final int x = line . length ( ) ; line . append ( line . length ( ) == 0 ? "" : " " ) . append ( next ) ; if ( line . length ( ) > len ) { line . setLength ( x ) ; buff . append ( line ) . append ( SEPARATOR ) . append ( head ) ; line . setLength ( 0 ) ; line . append ( next ) ; } } buff . append ( line ) ; return buff . toString ( ) ; }
Wrap the specified string by breaking on space characters .
27,380
void progress ( int cur , int max ) { StringBuilder out = new StringBuilder ( ) ; if ( lastProgress != null ) { char [ ] back = new char [ lastProgress . length ( ) ] ; Arrays . fill ( back , '\b' ) ; out . append ( back ) ; } String progress = cur + "/" + ( max == - 1 ? "?" : "" + max ) + " " + ( max == - 1 ? "(??%)" : "(" + cur * 100 / ( max == 0 ? 1 : max ) + "%)" ) ; if ( cur >= max && max != - 1 ) { progress += " " + loc ( "done" ) + SEPARATOR ; lastProgress = null ; } else { lastProgress = progress ; } out . append ( progress ) ; getOutputStream ( ) . print ( out . toString ( ) ) ; getOutputStream ( ) . flush ( ) ; }
Output a progress indicator to the console .
27,381
String scanForDriver ( String url ) { try { Driver driver ; if ( ( driver = findRegisteredDriver ( url ) ) != null ) { return driver . getClass ( ) . getCanonicalName ( ) ; } scanDrivers ( ) ; if ( ( driver = findRegisteredDriver ( url ) ) != null ) { return driver . getClass ( ) . getCanonicalName ( ) ; } return null ; } catch ( Exception e ) { e . printStackTrace ( ) ; debug ( e . toString ( ) ) ; return null ; } }
Looks for a driver with a particular URL . Returns the name of the class if found null if not found .
27,382
< R > R withPrompting ( Supplier < R > action ) { if ( prompting ) { throw new IllegalArgumentException ( ) ; } prompting = true ; try { return action . get ( ) ; } finally { prompting = false ; } }
Enables prompting applies an action and disables prompting .
27,383
public boolean isDefault ( SqlLineProperty property ) { final String defaultValue = String . valueOf ( property . defaultValue ( ) ) ; final String currentValue = get ( property ) ; return String . valueOf ( ( Object ) null ) . equals ( currentValue ) || Objects . equals ( currentValue , defaultValue ) ; }
Returns whether the property is its default value .
27,384
ColorBuffer pad ( ColorBuffer str , int len ) { int n = str . getVisibleLength ( ) ; while ( n < len ) { str . append ( " " ) ; n ++ ; } return append ( str ) ; }
Pad the specified String with spaces to the indicated length
27,385
public ColorBuffer truncate ( int len ) { ColorBuffer cbuff = new ColorBuffer ( useColor ) ; ColorAttr lastAttr = null ; for ( Iterator < Object > i = parts . iterator ( ) ; cbuff . getVisibleLength ( ) < len && i . hasNext ( ) ; ) { Object next = i . next ( ) ; if ( next instanceof ColorAttr ) { lastAttr = ( ColorAttr ) next ; cbuff . append ( ( ColorAttr ) next ) ; continue ; } String val = next . toString ( ) ; if ( cbuff . getVisibleLength ( ) + val . length ( ) > len ) { int partLen = len - cbuff . getVisibleLength ( ) ; val = val . substring ( 0 , partLen ) ; } cbuff . append ( val ) ; } if ( lastAttr != null && lastAttr != ColorAttr . NORMAL ) { cbuff . append ( ColorAttr . NORMAL ) ; } return cbuff ; }
Truncate the ColorBuffer to the specified length and return the new ColorBuffer . Any open color tags will be closed .
27,386
private int getStartingPoint ( String buffer ) { for ( int i = 0 ; i < buffer . length ( ) ; i ++ ) { if ( ! Character . isWhitespace ( buffer . charAt ( i ) ) ) { return i ; } } return buffer . length ( ) ; }
Returns the index of the first non - whitespace character .
27,387
int handleNumbers ( String line , BitSet numberBitSet , int startingPoint ) { int end = startingPoint + 1 ; while ( end < line . length ( ) && Character . isDigit ( line . charAt ( end ) ) ) { end ++ ; } if ( end == line . length ( ) ) { if ( Character . isDigit ( line . charAt ( line . length ( ) - 1 ) ) ) { numberBitSet . set ( startingPoint , end ) ; } } else if ( Character . isWhitespace ( line . charAt ( end ) ) || line . charAt ( end ) == ';' || line . charAt ( end ) == ',' || line . charAt ( end ) == '=' || line . charAt ( end ) == '<' || line . charAt ( end ) == '>' || line . charAt ( end ) == '-' || line . charAt ( end ) == '+' || line . charAt ( end ) == '/' || line . charAt ( end ) == ')' || line . charAt ( end ) == '%' || line . charAt ( end ) == '*' || line . charAt ( end ) == '!' || line . charAt ( end ) == '^' || line . charAt ( end ) == '|' || line . charAt ( end ) == '&' || line . charAt ( end ) == ']' ) { numberBitSet . set ( startingPoint , end ) ; } startingPoint = end - 1 ; return startingPoint ; }
Marks numbers position based on input .
27,388
int handleComments ( String line , BitSet commentBitSet , int startingPoint , boolean isSql ) { Set < String > oneLineComments = isSql ? sqlLine . getDialect ( ) . getOneLineComments ( ) : sqlLine . getDialect ( ) . getSqlLineOneLineComments ( ) ; final char ch = line . charAt ( startingPoint ) ; if ( startingPoint + 1 < line . length ( ) && ch == '/' && line . charAt ( startingPoint + 1 ) == '*' ) { int end = line . indexOf ( "*/" , startingPoint ) ; end = end == - 1 ? line . length ( ) - 1 : end + 1 ; commentBitSet . set ( startingPoint , end + 1 ) ; startingPoint = end ; } else { for ( String oneLineComment : oneLineComments ) { if ( startingPoint <= line . length ( ) - oneLineComment . length ( ) && oneLineComment . regionMatches ( 0 , line , startingPoint , oneLineComment . length ( ) ) ) { int end = line . indexOf ( '\n' , startingPoint ) ; end = end == - 1 ? line . length ( ) - 1 : end ; commentBitSet . set ( startingPoint , end + 1 ) ; startingPoint = end ; } } } return startingPoint ; }
Marks commented string position based on input .
27,389
int handleSqlSingleQuotes ( String line , BitSet quoteBitSet , int startingPoint ) { int end ; int quoteCounter = 1 ; boolean quotationEnded = false ; do { end = line . indexOf ( '\'' , startingPoint + 1 ) ; if ( end > - 1 ) { quoteCounter ++ ; } if ( end == - 1 || end == line . length ( ) - 1 ) { quoteBitSet . set ( startingPoint , line . length ( ) ) ; quotationEnded = true ; } else if ( line . charAt ( end + 1 ) != '\'' && quoteCounter % 2 == 0 ) { quotationEnded = true ; } end = end == - 1 ? line . length ( ) - 1 : end ; quoteBitSet . set ( startingPoint , end + 1 ) ; startingPoint = end ; } while ( ! quotationEnded && end < line . length ( ) ) ; return startingPoint ; }
Marks single - quoted string position based on input .
27,390
public void post ( Object event ) { if ( event == null ) { throw new NullPointerException ( "Event to post must not be null." ) ; } enforcer . enforce ( this ) ; Set < Class < ? > > dispatchTypes = flattenHierarchy ( event . getClass ( ) ) ; boolean dispatched = false ; for ( Class < ? > eventType : dispatchTypes ) { Set < EventHandler > wrappers = getHandlersForEventType ( eventType ) ; if ( wrappers != null && ! wrappers . isEmpty ( ) ) { dispatched = true ; for ( EventHandler wrapper : wrappers ) { enqueueEvent ( event , wrapper ) ; } } } if ( ! dispatched && ! ( event instanceof DeadEvent ) ) { post ( new DeadEvent ( this , event ) ) ; } dispatchQueuedEvents ( ) ; }
Posts an event to all registered handlers . This method will return successfully after the event has been posted to all handlers and regardless of any exceptions thrown by handlers .
27,391
protected void dispatchQueuedEvents ( ) { if ( isDispatching . get ( ) ) { return ; } isDispatching . set ( true ) ; try { while ( true ) { EventWithHandler eventWithHandler = eventsToDispatch . get ( ) . poll ( ) ; if ( eventWithHandler == null ) { break ; } if ( eventWithHandler . handler . isValid ( ) ) { dispatch ( eventWithHandler . event , eventWithHandler . handler ) ; } } } finally { isDispatching . set ( false ) ; } }
Drain the queue of events to be dispatched . As the queue is being drained new events may be posted to the end of the queue .
27,392
public boolean goBack ( ) { if ( _entries . size ( ) > 0 && ( _entries . get ( 0 ) . getName ( ) . equals ( ".." ) ) ) { _list . performItemClick ( _list , 0 , 0 ) ; return true ; } return false ; }
attempts to move to the parent directory
27,393
public static int getListYScroll ( final ListView list ) { View child = list . getChildAt ( 0 ) ; return child == null ? - 1 : list . getFirstVisiblePosition ( ) * child . getHeight ( ) - child . getTop ( ) + list . getPaddingTop ( ) ; }
This only works assuming that all list items have the same height!
27,394
public static Event retrieve ( String id , RequestOptions options ) throws StripeException { return retrieve ( id , null , options ) ; }
Retrieves the details of an event . Supply the unique identifier of the event which you might have received in a webhook .
27,395
public static Customer retrieve ( String customer ) throws StripeException { return retrieve ( customer , ( Map < String , Object > ) null , ( RequestOptions ) null ) ; }
Retrieves the details of an existing customer . You need only supply the unique customer identifier that was returned upon customer creation .
27,396
public Discount deleteDiscount ( ) throws StripeException { return deleteDiscount ( ( Map < String , Object > ) null , ( RequestOptions ) null ) ; }
Removes the currently applied discount on a customer .
27,397
public JsonElement serialize ( ExpandableField < ? > src , Type typeOfSrc , JsonSerializationContext context ) { if ( src . isExpanded ( ) ) { return context . serialize ( src . getExpanded ( ) ) ; } else if ( src . getId ( ) != null ) { return new JsonPrimitive ( src . getId ( ) ) ; } else { return null ; } }
Serializes an expandable attribute into a JSON string .
27,398
public static TaxRate retrieve ( String taxRate ) throws StripeException { return retrieve ( taxRate , ( Map < String , Object > ) null , ( RequestOptions ) null ) ; }
Retrieves a tax rate with the given ID .
27,399
public static TaxRate create ( TaxRateCreateParams params , RequestOptions options ) throws StripeException { String url = String . format ( "%s%s" , Stripe . getApiBase ( ) , "/v1/tax_rates" ) ; return request ( ApiResource . RequestMethod . POST , url , params , TaxRate . class , options ) ; }
Creates a new tax rate .