idx int64 0 41.2k | question stringlengths 83 4.15k | target stringlengths 5 715 |
|---|---|---|
11,700 | protected static String tryCommands ( String [ ] cmds ) { if ( cmds == null ) { return null ; } String output ; for ( int ii = 0 ; ii < cmds . length ; ii ++ ) { output = runCommand ( cmds [ ii ] ) ; if ( output != null ) { return output ; } } return null ; } | Takes a lists of commands and tries to run each one till one works . The idea being to be able to gracefully cope with not knowing where a command is installed on different installations . |
11,701 | protected static String runCommand ( String cmd ) { try { Process p = Runtime . getRuntime ( ) . exec ( cmd ) ; BufferedReader cin = new BufferedReader ( new InputStreamReader ( p . getInputStream ( ) ) ) ; StringBuilder buffer = new StringBuilder ( ) ; String line = "" ; while ( line != null ) { buffer . append ( line ) ; line = cin . readLine ( ) ; } cin . close ( ) ; return buffer . toString ( ) ; } catch ( IOException e ) { return null ; } } | Run the specified command and return the output as a string . |
11,702 | public static void copyRow ( XSSFSheet srcSheet , XSSFSheet destSheet , int parentSheetRow , int parentSheetColumn , XSSFRow srcRow , XSSFRow destRow , Map < Integer , CellStyle > styleMap ) { Set < CellRangeAddressWrapper > mergedRegions = new TreeSet < CellRangeAddressWrapper > ( ) ; destRow . setHeight ( srcRow . getHeight ( ) ) ; for ( int j = srcRow . getFirstCellNum ( ) ; j <= srcRow . getLastCellNum ( ) ; j ++ ) { XSSFCell oldCell = srcRow . getCell ( j ) ; if ( oldCell != null ) { XSSFCell newCell = destRow . createCell ( parentSheetColumn + j ) ; copyCell ( oldCell , newCell , styleMap ) ; CellRangeAddress mergedRegion = getMergedRegion ( srcSheet , srcRow . getRowNum ( ) , ( short ) oldCell . getColumnIndex ( ) ) ; if ( mergedRegion != null ) { CellRangeAddress newMergedRegion = new CellRangeAddress ( parentSheetRow + mergedRegion . getFirstRow ( ) , parentSheetRow + mergedRegion . getLastRow ( ) , parentSheetColumn + mergedRegion . getFirstColumn ( ) , parentSheetColumn + mergedRegion . getLastColumn ( ) ) ; CellRangeAddressWrapper wrapper = new CellRangeAddressWrapper ( newMergedRegion ) ; if ( isNewMergedRegion ( wrapper , mergedRegions ) ) { mergedRegions . add ( wrapper ) ; destSheet . addMergedRegion ( wrapper . range ) ; } } } } } | Copy a row from a sheet to another sheet |
11,703 | public static void copyCell ( XSSFCell oldCell , XSSFCell newCell , Map < Integer , CellStyle > styleMap ) { if ( styleMap != null ) { if ( oldCell . getSheet ( ) . getWorkbook ( ) == newCell . getSheet ( ) . getWorkbook ( ) ) { newCell . setCellStyle ( oldCell . getCellStyle ( ) ) ; } else { int stHashCode = oldCell . getCellStyle ( ) . hashCode ( ) ; CellStyle newCellStyle = styleMap . get ( stHashCode ) ; if ( newCellStyle == null ) { newCellStyle = newCell . getSheet ( ) . getWorkbook ( ) . createCellStyle ( ) ; newCellStyle . cloneStyleFrom ( oldCell . getCellStyle ( ) ) ; styleMap . put ( stHashCode , newCellStyle ) ; } newCell . setCellStyle ( newCellStyle ) ; } } switch ( oldCell . getCellType ( ) ) { case XSSFCell . CELL_TYPE_STRING : newCell . setCellValue ( oldCell . getStringCellValue ( ) ) ; break ; case XSSFCell . CELL_TYPE_NUMERIC : newCell . setCellValue ( oldCell . getNumericCellValue ( ) ) ; break ; case XSSFCell . CELL_TYPE_BLANK : newCell . setCellType ( XSSFCell . CELL_TYPE_BLANK ) ; break ; case XSSFCell . CELL_TYPE_BOOLEAN : newCell . setCellValue ( oldCell . getBooleanCellValue ( ) ) ; break ; case XSSFCell . CELL_TYPE_ERROR : newCell . setCellErrorValue ( oldCell . getErrorCellValue ( ) ) ; break ; case XSSFCell . CELL_TYPE_FORMULA : newCell . setCellFormula ( oldCell . getCellFormula ( ) ) ; break ; default : break ; } } | Copy a cell to another cell |
11,704 | public String connect ( String hostname , int port ) throws IOException , CDDBException { return connect ( hostname , port , CLIENT_NAME , CLIENT_VERSION ) ; } | Connects this CDDB instance to the CDDB server running on the supplied host using the specified port and default client name and version . |
11,705 | public String connect ( String hostname , int port , String clientName , String clientVersion ) throws IOException , CDDBException { String localhost = InetAddress . getLocalHost ( ) . getHostName ( ) ; String username = System . getProperty ( "user.name" ) ; if ( username == null ) { username = "anonymous" ; } InetAddress addr = InetAddress . getByName ( hostname ) ; _sock = new Socket ( addr , port ) ; _in = new BufferedReader ( new InputStreamReader ( _sock . getInputStream ( ) , ISO8859 ) ) ; _out = new PrintStream ( new BufferedOutputStream ( _sock . getOutputStream ( ) ) , false , ISO8859 ) ; _in . readLine ( ) ; Response rsp = request ( "proto 6" ) ; if ( rsp . code == 201 || rsp . code == 501 ) { _in = new BufferedReader ( new InputStreamReader ( _sock . getInputStream ( ) , UTF8 ) ) ; _out = new PrintStream ( new BufferedOutputStream ( _sock . getOutputStream ( ) ) , false , UTF8 ) ; } StringBuilder req = new StringBuilder ( "cddb hello " ) ; req . append ( username ) . append ( " " ) ; req . append ( localhost ) . append ( " " ) ; req . append ( clientName ) . append ( " " ) ; req . append ( clientVersion ) ; rsp = request ( req . toString ( ) ) ; if ( CDDBProtocol . codeFamily ( rsp . code ) != CDDBProtocol . OK && rsp . code != 402 ) { throw new CDDBException ( rsp . code , rsp . message ) ; } return rsp . message ; } | Connects this CDDB instance to the CDDB server running on the supplied host using the specified port . |
11,706 | public String [ ] lscat ( ) throws IOException , CDDBException { if ( _sock == null ) { throw new CDDBException ( 500 , "Not connected" ) ; } Response rsp = request ( "cddb lscat" ) ; if ( rsp . code != 210 ) { throw new CDDBException ( rsp . code , rsp . message ) ; } ArrayList < String > list = new ArrayList < String > ( ) ; String input ; while ( ! ( input = _in . readLine ( ) ) . equals ( CDDBProtocol . TERMINATOR ) ) { list . add ( input ) ; } String [ ] categories = new String [ list . size ( ) ] ; list . toArray ( categories ) ; return categories ; } | Fetches and returns the list of categories supported by the server . |
11,707 | public Entry [ ] query ( String discid , int [ ] frameOffsets , int length ) throws IOException , CDDBException { if ( _sock == null ) { throw new CDDBException ( 500 , "Not connected" ) ; } StringBuilder req = new StringBuilder ( "cddb query " ) ; req . append ( discid ) . append ( " " ) ; req . append ( frameOffsets . length ) . append ( " " ) ; for ( int frameOffset : frameOffsets ) { req . append ( frameOffset ) . append ( " " ) ; } req . append ( length ) ; Response rsp = request ( req . toString ( ) ) ; Entry [ ] entries = null ; if ( rsp . code == 200 ) { entries = new Entry [ 1 ] ; entries [ 0 ] = new Entry ( ) ; entries [ 0 ] . parse ( rsp . message ) ; } else if ( rsp . code == 211 ) { ArrayList < Entry > list = new ArrayList < Entry > ( ) ; String input = _in . readLine ( ) ; while ( input != null && ! input . equals ( CDDBProtocol . TERMINATOR ) ) { System . out . println ( "...: " + input ) ; Entry e = new Entry ( ) ; e . parse ( input ) ; list . add ( e ) ; input = _in . readLine ( ) ; } entries = new Entry [ list . size ( ) ] ; list . toArray ( entries ) ; } else if ( CDDBProtocol . codeFamily ( rsp . code ) != CDDBProtocol . OK ) { throw new CDDBException ( rsp . code , rsp . message ) ; } return entries ; } | Issues a query to the CDDB server using the supplied CD identifying information . |
11,708 | protected final void append ( ArrayList < String > list , int index , String value ) { while ( list . size ( ) <= index ) { list . add ( "" ) ; } list . set ( index , list . get ( index ) + value ) ; } | Appends the supplied string to the contents of the list at the supplied index . If the list has no contents at the supplied index the supplied value becomes the contents at that index . |
11,709 | protected Response request ( String req ) throws IOException { System . err . println ( "REQ:" + req ) ; _out . println ( req ) ; _out . flush ( ) ; String rspstr = _in . readLine ( ) ; if ( rspstr == null ) { throw new EOFException ( ) ; } System . err . println ( "RSP:" + rspstr ) ; Response rsp = new Response ( ) ; String codestr = rspstr ; int sidx = rspstr . indexOf ( " " ) ; if ( sidx != - 1 ) { codestr = rspstr . substring ( 0 , sidx ) ; rsp . message = rspstr . substring ( sidx + 1 ) ; } try { rsp . code = Integer . parseInt ( codestr ) ; } catch ( NumberFormatException nfe ) { rsp . code = 599 ; rsp . message = "Unparseable response" ; } return rsp ; } | Issues a request to the CDDB server and parses the response . |
11,710 | public final Cursor < T > select ( Connection conn , String condition ) { String query = "select " + listOfFields + " from " + name + " " + condition ; return new Cursor < T > ( this , conn , query ) ; } | Select records from database table according to search condition |
11,711 | public synchronized void insert ( Connection conn , T obj ) throws SQLException { StringBuilder sql = new StringBuilder ( "insert into " + name + " (" + listOfFields + ") values (?" ) ; for ( int i = 1 ; i < nColumns ; i ++ ) { sql . append ( ",?" ) ; } sql . append ( ")" ) ; PreparedStatement insertStmt = conn . prepareStatement ( sql . toString ( ) ) ; bindUpdateVariables ( insertStmt , obj , null ) ; insertStmt . executeUpdate ( ) ; insertStmt . close ( ) ; } | Insert new record in the table . Values of inserted record fields are taken from specified object . |
11,712 | public synchronized void insert ( Connection conn , T [ ] objects ) throws SQLException { StringBuilder sql = new StringBuilder ( "insert into " + name + " (" + listOfFields + ") values (?" ) ; for ( int i = 1 ; i < nColumns ; i ++ ) { sql . append ( ",?" ) ; } sql . append ( ")" ) ; PreparedStatement insertStmt = conn . prepareStatement ( sql . toString ( ) ) ; for ( int i = 0 ; i < objects . length ; i ++ ) { bindUpdateVariables ( insertStmt , objects [ i ] , null ) ; insertStmt . addBatch ( ) ; } insertStmt . executeBatch ( ) ; insertStmt . close ( ) ; } | Insert several new records in the table . Values of inserted records fields are taken from objects of specified array . |
11,713 | public synchronized int delete ( Connection conn , T obj ) throws SQLException { if ( primaryKeys == null ) { throw new IllegalStateException ( "No primary key for table " + name + "." ) ; } int nDeleted = 0 ; StringBuilder sql = new StringBuilder ( "delete from " + name + " where " + primaryKeys [ 0 ] + " = ?" ) ; for ( int i = 1 ; i < primaryKeys . length ; i ++ ) { sql . append ( " and " ) . append ( primaryKeys [ i ] ) . append ( " = ?" ) ; } PreparedStatement deleteStmt = conn . prepareStatement ( sql . toString ( ) ) ; for ( int i = 0 ; i < primaryKeys . length ; i ++ ) { fields [ primaryKeyIndices [ i ] ] . bindVariable ( deleteStmt , obj , i + 1 ) ; } nDeleted = deleteStmt . executeUpdate ( ) ; deleteStmt . close ( ) ; return nDeleted ; } | Delete record with specified value of primary key from the table . |
11,714 | public synchronized int delete ( Connection conn , T [ ] objects ) throws SQLException { if ( primaryKeys == null ) { throw new IllegalStateException ( "No primary key for table " + name + "." ) ; } int nDeleted = 0 ; StringBuilder sql = new StringBuilder ( "delete from " + name + " where " + primaryKeys [ 0 ] + " = ?" ) ; for ( int i = 1 ; i < primaryKeys . length ; i ++ ) { sql . append ( " and " ) . append ( primaryKeys [ i ] ) . append ( " = ?" ) ; } PreparedStatement deleteStmt = conn . prepareStatement ( sql . toString ( ) ) ; for ( int i = 0 ; i < objects . length ; i ++ ) { for ( int j = 0 ; j < primaryKeys . length ; j ++ ) { fields [ primaryKeyIndices [ j ] ] . bindVariable ( deleteStmt , objects [ i ] , j + 1 ) ; } deleteStmt . addBatch ( ) ; } int rc [ ] = deleteStmt . executeBatch ( ) ; for ( int k = 0 ; k < rc . length ; k ++ ) { nDeleted += rc [ k ] ; } deleteStmt . close ( ) ; return nDeleted ; } | Delete records with specified primary keys from the table . |
11,715 | public static boolean restrictQueryExecution ( String sql ) { String [ ] restrictions = { "delete" , "truncate" , "update" , "drop" , "alter" } ; if ( sql != null ) { sql = sql . toLowerCase ( ) ; for ( String restriction : restrictions ) { if ( sql . startsWith ( restriction ) ) { return true ; } String regex = "\\s+" + restriction + "\\s+" ; Pattern pattern = Pattern . compile ( regex ) ; Matcher matcher = pattern . matcher ( sql ) ; if ( matcher . find ( ) ) { return true ; } } } return false ; } | Restrict a query execution . Do not allow for database modifications . |
11,716 | public static boolean isValidProcedureCall ( String sql , Dialect dialect ) { if ( sql == null ) { return false ; } if ( dialect instanceof OracleDialect ) { return sql . split ( "\\?" ) . length == 2 ; } else { return true ; } } | See if the sql contains only one ? character |
11,717 | public static Expression compile ( String exp ) { if ( Miscellaneous . isEmpty ( exp ) || exp . equals ( "." ) ) { exp = "$" ; } Queue < String > queue = new LinkedList < String > ( ) ; List < String > tokens = parseTokens ( exp ) ; boolean isInBracket = false ; int numInBracket = 0 ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < tokens . size ( ) ; i ++ ) { String token = tokens . get ( i ) ; if ( token . equals ( "[" ) ) { if ( isInBracket ) { throw new IllegalArgumentException ( "Error parsing expression '" + exp + "': Nested [ found" ) ; } isInBracket = true ; numInBracket = 0 ; sb . append ( token ) ; } else if ( token . equals ( "]" ) ) { if ( ! isInBracket ) { throw new IllegalArgumentException ( "Error parsing expression '" + exp + "': Unbalanced ] found" ) ; } isInBracket = false ; sb . append ( token ) ; queue . add ( sb . toString ( ) ) ; sb = new StringBuilder ( ) ; } else { if ( isInBracket ) { if ( numInBracket > 0 ) { throw new IllegalArgumentException ( "Error parsing expression '" + exp + "': Multiple tokens found inside a bracket" ) ; } sb . append ( token ) ; numInBracket ++ ; } else { queue . add ( token ) ; } } if ( i == tokens . size ( ) - 1 ) { if ( isInBracket ) { throw new IllegalArgumentException ( "Error parsing expression '" + exp + "': Unbalanced [ found" ) ; } } } return new Expression ( queue , exp ) ; } | Compiles the expression . |
11,718 | public static void addDragSource ( DragSource source , JComponent comp , boolean autoremove ) { singleton . addSource ( source , comp , autoremove ) ; } | Add the specified component as a source of drags with the DragSource controller . |
11,719 | public static void addDropTarget ( DropTarget target , JComponent comp , boolean autoremove ) { singleton . addTarget ( target , comp , autoremove ) ; } | Add the specified component as a drop target . |
11,720 | protected void addSource ( DragSource source , JComponent comp , boolean autoremove ) { _draggers . put ( comp , source ) ; comp . addMouseListener ( _sourceListener ) ; comp . addMouseMotionListener ( _sourceListener ) ; if ( autoremove ) { comp . addAncestorListener ( _remover ) ; } } | Add a dragsource . |
11,721 | protected void removeSource ( JComponent comp ) { if ( _sourceComp == comp ) { clearComponentCursor ( ) ; _topComp . setCursor ( _topCursor ) ; reset ( ) ; } _draggers . remove ( comp ) ; comp . removeMouseListener ( _sourceListener ) ; comp . removeMouseMotionListener ( _sourceListener ) ; } | Remove a dragsource . |
11,722 | protected void addTarget ( DropTarget target , JComponent comp , boolean autoremove ) { _droppers . put ( comp , target ) ; addTargetListeners ( comp ) ; if ( autoremove ) { comp . addAncestorListener ( _remover ) ; } } | Add a droptarget . |
11,723 | protected void addTargetListeners ( Component comp ) { comp . addMouseListener ( _targetListener ) ; comp . addMouseMotionListener ( _targetListener ) ; if ( comp instanceof Container ) { Container cont = ( Container ) comp ; cont . addContainerListener ( _childListener ) ; for ( int ii = 0 , nn = cont . getComponentCount ( ) ; ii < nn ; ii ++ ) { addTargetListeners ( cont . getComponent ( ii ) ) ; } } } | Add the appropriate target listeners to this component and all its children . |
11,724 | protected void removeTargetListeners ( Component comp ) { comp . removeMouseListener ( _targetListener ) ; comp . removeMouseMotionListener ( _targetListener ) ; if ( comp instanceof Container ) { Container cont = ( Container ) comp ; cont . removeContainerListener ( _childListener ) ; for ( int ii = 0 , nn = cont . getComponentCount ( ) ; ii < nn ; ii ++ ) { removeTargetListeners ( cont . getComponent ( ii ) ) ; } } } | Remove the appropriate target listeners to this component and all its children . |
11,725 | protected void setComponentCursor ( Component comp ) { Cursor c = comp . getCursor ( ) ; if ( c != _curCursor ) { assertComponentCursorCleared ( ) ; _lastComp = comp ; _oldCursor = comp . isCursorSet ( ) ? c : null ; comp . setCursor ( _curCursor ) ; } } | Check to see if we need to do component - level cursor setting and take care of it if needed . |
11,726 | protected DropTarget findAppropriateTarget ( Component comp ) { DropTarget target ; while ( comp != null ) { target = ( comp == _sourceComp ) ? null : _droppers . get ( comp ) ; if ( ( target != null ) && comp . isEnabled ( ) && _source . checkDrop ( target ) && target . checkDrop ( _source , _data [ 0 ] ) ) { return target ; } comp = comp . getParent ( ) ; } return null ; } | Find the lowest accepting parental target to this component . |
11,727 | protected void checkAutoscroll ( MouseEvent exitEvent ) { Component comp = exitEvent . getComponent ( ) ; Point p = exitEvent . getPoint ( ) ; try { Point scr = comp . getLocationOnScreen ( ) ; p . translate ( scr . x , scr . y ) ; } catch ( IllegalComponentStateException icse ) { return ; } Component parent ; DropTarget target ; while ( true ) { target = _droppers . get ( comp ) ; if ( target instanceof AutoscrollingDropTarget ) { AutoscrollingDropTarget adt = ( AutoscrollingDropTarget ) target ; JComponent jc = ( JComponent ) comp ; Rectangle r = getRectOnScreen ( jc ) ; if ( ! r . contains ( p ) ) { _scrollComp = jc ; _scrollDim = adt . getAutoscrollBorders ( ) ; _scrollPoint = p ; _scrollTimer . start ( ) ; return ; } } parent = comp . getParent ( ) ; if ( parent == null ) { return ; } comp = parent ; } } | Check to see if we want to enter autoscrolling mode . |
11,728 | protected Rectangle getRectOnScreen ( JComponent comp ) { Rectangle r = comp . getVisibleRect ( ) ; Point p = comp . getLocationOnScreen ( ) ; r . translate ( p . x , p . y ) ; return r ; } | Find the rectangular area that is visible in screen coordinates for the given component . |
11,729 | protected void reset ( ) { _scrollTimer . stop ( ) ; _source = null ; _sourceComp = null ; _lastComp = null ; _lastTarget = null ; _data [ 0 ] = null ; _cursors [ 0 ] = null ; _cursors [ 1 ] = null ; _topComp = null ; _topCursor = null ; _curCursor = null ; _scrollComp = null ; _scrollDim = null ; _scrollPoint = null ; } | Reset dnd to a starting state . |
11,730 | public static Report loadConvertedReport ( InputStream is ) { XStream xstream = XStreamFactory . createXStream ( ) ; InputStreamReader reader = null ; try { reader = new InputStreamReader ( is , "UTF-8" ) ; return ( Report ) xstream . fromXML ( reader ) ; } catch ( Exception e ) { LOG . error ( e . getMessage ( ) , e ) ; e . printStackTrace ( ) ; return null ; } } | Create a report object from an input stream |
11,731 | public static Report loadConvertedReport ( String xml ) { XStream xstream = XStreamFactory . createXStream ( ) ; try { return ( Report ) xstream . fromXML ( xml ) ; } catch ( Exception e ) { LOG . error ( e . getMessage ( ) , e ) ; e . printStackTrace ( ) ; return null ; } } | Create a report object from xml |
11,732 | public static Report loadReport ( String xml ) throws LoadReportException { try { String convertedXml = ConverterChain . applyFromXml ( xml ) ; XStream xstream = XStreamFactory . createXStream ( ) ; return ( Report ) xstream . fromXML ( convertedXml ) ; } catch ( ConverterException ex ) { LOG . error ( ex . getMessage ( ) , ex ) ; throw new LoadReportException ( ex . getMessage ( ) , ex ) ; } } | Create a report object from xml Do a conversion if it is needed |
11,733 | public static Report loadReport ( InputStream is ) throws LoadReportException { try { String xml = readAsString ( is ) ; String convertedXml = ConverterChain . applyFromXml ( xml ) ; XStream xstream = XStreamFactory . createXStream ( ) ; return ( Report ) xstream . fromXML ( convertedXml ) ; } catch ( Exception ex ) { LOG . error ( ex . getMessage ( ) , ex ) ; throw new LoadReportException ( ex . getMessage ( ) , ex ) ; } } | Create a report object from an input stream Do a conversion if it is needed |
11,734 | public static void saveReport ( Report report , OutputStream out ) { XStream xstream = XStreamFactory . createXStream ( ) ; xstream . toXML ( report , out ) ; } | Write a report object to an output stream |
11,735 | public static void saveReport ( Report report , String path ) { FileOutputStream fos = null ; try { fos = new FileOutputStream ( path ) ; saveReport ( report , fos ) ; } catch ( Exception ex ) { LOG . error ( ex . getMessage ( ) , ex ) ; ex . printStackTrace ( ) ; } finally { if ( fos != null ) { try { fos . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } } | Write a report object to a file at specified path |
11,736 | public static void saveReport ( String xml , String path ) { FileOutputStream fos = null ; try { fos = new FileOutputStream ( path ) ; fos . write ( xml . getBytes ( "UTF-8" ) ) ; fos . flush ( ) ; } catch ( Exception ex ) { LOG . error ( ex . getMessage ( ) , ex ) ; ex . printStackTrace ( ) ; } finally { if ( fos != null ) { try { fos . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } } | Write a xml text to a file at specified path |
11,737 | public static String reportToXml ( Report report ) { XStream xstream = XStreamFactory . createXStream ( ) ; ByteArrayOutputStream bos = new ByteArrayOutputStream ( ) ; xstream . toXML ( report , bos ) ; return bos . toString ( ) ; } | Convert a report object to xml text |
11,738 | public static byte isValid ( String reportVersion ) { if ( isOlderUnsupportedVersion ( reportVersion ) ) { return REPORT_INVALID_OLDER ; } else if ( isNewerUnsupportedVersion ( reportVersion ) ) { return REPORT_INVALID_NEWER ; } else { return REPORT_VALID ; } } | Test if string version given as parameter is valid meaning is over 2 . 0 and no greater than current engine version |
11,739 | public static boolean isOlderUnsupportedVersion ( String version ) { return ( ( version == null ) || "" . equals ( version ) || version . startsWith ( "0" ) || version . startsWith ( "1" ) ) ; } | Return true if version string is less than 2 . 0 |
11,740 | public static boolean isNewerUnsupportedVersion ( String version ) { if ( ( version == null ) || "" . equals ( version ) ) { return true ; } String engineVersion = ReleaseInfoAdapter . getVersionNumber ( ) ; String [ ] ev = engineVersion . split ( "\\." ) ; String [ ] rv = version . split ( "\\." ) ; return ( ( Integer . parseInt ( ev [ 0 ] ) < Integer . parseInt ( rv [ 0 ] ) ) || ( ( Integer . parseInt ( ev [ 0 ] ) == Integer . parseInt ( rv [ 0 ] ) ) && ( Integer . parseInt ( ev [ 1 ] ) < Integer . parseInt ( rv [ 1 ] ) ) ) ) ; } | Return true if version string is newer than version of the report engine |
11,741 | public static int compareVersions ( String v1 , String v2 ) { String [ ] v1a = v1 . split ( "\\." ) ; String [ ] v2a = v2 . split ( "\\." ) ; Integer v1M = Integer . parseInt ( v1a [ 0 ] ) ; Integer v2M = Integer . parseInt ( v2a [ 0 ] ) ; if ( v1M < v2M ) { return - 1 ; } else if ( v1M > v2M ) { return 1 ; } else { Integer v1min = Integer . parseInt ( v1a [ 1 ] ) ; Integer v2min = Integer . parseInt ( v2a [ 1 ] ) ; if ( v1min < v2min ) { return - 1 ; } else if ( v1min > v2min ) { return 1 ; } else { return 0 ; } } } | Compare two report versions strings |
11,742 | public static String getVersion ( String reportFile ) { try { String text = readAsString ( reportFile ) ; return getVersionFromText ( text ) ; } catch ( IOException e ) { LOG . error ( e . getMessage ( ) , e ) ; return null ; } } | Get report version from report file |
11,743 | public static String getVersion ( InputStream is ) { try { String text = readAsString ( is ) ; return getVersionFromText ( text ) ; } catch ( IOException e ) { LOG . error ( e . getMessage ( ) , e ) ; return null ; } } | Get report version from input stream to read report file |
11,744 | public static String readAsString ( String reportPath ) throws IOException { StringBuffer fileData = new StringBuffer ( 1000 ) ; BufferedReader reader = new BufferedReader ( new FileReader ( reportPath ) ) ; char [ ] buf = new char [ 1024 ] ; int numRead = 0 ; while ( ( numRead = reader . read ( buf ) ) != - 1 ) { fileData . append ( buf , 0 , numRead ) ; } reader . close ( ) ; return fileData . toString ( ) ; } | Read a report file as string |
11,745 | public static String readAsString ( InputStream is ) throws IOException { try { return new Scanner ( is , "UTF-8" ) . useDelimiter ( "\\A" ) . next ( ) ; } catch ( java . util . NoSuchElementException e ) { return "" ; } } | Read data from input stream |
11,746 | public static String getFileName ( String filePath ) { if ( filePath == null ) { return filePath ; } int index = filePath . lastIndexOf ( File . separator ) ; if ( index == - 1 ) { return filePath ; } return filePath . substring ( index + 1 ) ; } | Get file name from a file path |
11,747 | public static List < String > getStaticImages ( Report report ) { List < String > images = new ArrayList < String > ( ) ; ReportLayout layout = report . getLayout ( ) ; List < Band > bands = layout . getBands ( ) ; for ( Band band : bands ) { for ( int i = 0 , rows = band . getRowCount ( ) ; i < rows ; i ++ ) { List < BandElement > list = band . getRow ( i ) ; for ( BandElement be : list ) { if ( ( be instanceof ImageBandElement ) && ! ( be instanceof ChartBandElement ) && ! ( be instanceof BarcodeBandElement ) ) { images . add ( ( ( ImageBandElement ) be ) . getImage ( ) ) ; } } } } if ( layout . getBackgroundImage ( ) != null ) { images . add ( layout . getBackgroundImage ( ) ) ; } return images ; } | Get static images used by report |
11,748 | public static String getSql ( Report report ) { String sql ; if ( report . getSql ( ) != null ) { sql = report . getSql ( ) ; } else { sql = report . getQuery ( ) . toString ( ) ; } return sql ; } | Get sql string from report object |
11,749 | public static List < ExpressionBean > getExpressions ( ReportLayout layout ) { List < ExpressionBean > expressions = new LinkedList < ExpressionBean > ( ) ; for ( Band band : layout . getBands ( ) ) { for ( int i = 0 , rows = band . getRowCount ( ) ; i < rows ; i ++ ) { List < BandElement > list = band . getRow ( i ) ; for ( BandElement be : list ) { if ( be instanceof ExpressionBandElement ) { if ( ! expressions . contains ( ( ExpressionBandElement ) be ) ) { expressions . add ( new ExpressionBean ( ( ExpressionBandElement ) be , band . getName ( ) ) ) ; } } } } } return expressions ; } | Get expression elements from report layout |
11,750 | public static List < String > getExpressionsNames ( ReportLayout layout ) { List < String > expressions = new LinkedList < String > ( ) ; for ( Band band : layout . getBands ( ) ) { for ( int i = 0 , rows = band . getRowCount ( ) ; i < rows ; i ++ ) { List < BandElement > list = band . getRow ( i ) ; for ( BandElement be : list ) { if ( be instanceof ExpressionBandElement ) { String expName = ( ( ExpressionBandElement ) be ) . getExpressionName ( ) ; if ( ! expressions . contains ( expName ) ) { expressions . add ( expName ) ; } } } } } return expressions ; } | Get expression names from report layout |
11,751 | public static String isValidSqlWithMessage ( Connection con , String sql , List < QueryParameter > parameters ) { try { QueryUtil qu = new QueryUtil ( con , DialectUtil . getDialect ( con ) ) ; Map < String , QueryParameter > params = new HashMap < String , QueryParameter > ( ) ; for ( QueryParameter qp : parameters ) { params . put ( qp . getName ( ) , qp ) ; } qu . getColumnNames ( sql , params ) ; } catch ( Exception ex ) { LOG . error ( ex . getMessage ( ) , ex ) ; return ex . getMessage ( ) ; } return null ; } | Test if sql with parameters is valid |
11,752 | public static List < Report > getSubreports ( Report report ) { List < Report > subreports = new ArrayList < Report > ( ) ; List < Band > bands = report . getLayout ( ) . getDocumentBands ( ) ; for ( Band band : bands ) { for ( int i = 0 , rows = band . getRowCount ( ) ; i < rows ; i ++ ) { List < BandElement > list = band . getRow ( i ) ; for ( int j = 0 , size = list . size ( ) ; j < size ; j ++ ) { BandElement be = list . get ( j ) ; if ( be instanceof ReportBandElement ) { subreports . add ( ( ( ReportBandElement ) be ) . getReport ( ) ) ; } } } } return subreports ; } | Get subreports for a report |
11,753 | public static List < Report > getDetailSubreports ( ReportLayout reportLayout ) { List < Report > subreports = new ArrayList < Report > ( ) ; Band band = reportLayout . getDetailBand ( ) ; for ( int i = 0 , rows = band . getRowCount ( ) ; i < rows ; i ++ ) { List < BandElement > list = band . getRow ( i ) ; for ( int j = 0 , size = list . size ( ) ; j < size ; j ++ ) { BandElement be = list . get ( j ) ; if ( be instanceof ReportBandElement ) { subreports . add ( ( ( ReportBandElement ) be ) . getReport ( ) ) ; } } } return subreports ; } | Get detail band subreports for a report layout |
11,754 | public static List < Chart > getDetailCharts ( ReportLayout reportLayout ) { List < Chart > charts = new ArrayList < Chart > ( ) ; Band band = reportLayout . getDetailBand ( ) ; for ( int i = 0 , rows = band . getRowCount ( ) ; i < rows ; i ++ ) { List < BandElement > list = band . getRow ( i ) ; for ( int j = 0 , size = list . size ( ) ; j < size ; j ++ ) { BandElement be = list . get ( j ) ; if ( be instanceof ChartBandElement ) { charts . add ( ( ( ChartBandElement ) be ) . getChart ( ) ) ; } } } return charts ; } | Get detail band charts for a report layout |
11,755 | private static ReportLayout getForReportLayout ( Connection con , ReportLayout layout , ParametersBean pBean ) throws Exception { ReportLayout convertedLayout = ObjectCloner . silenceDeepCopy ( layout ) ; List < Band > bands = convertedLayout . getDocumentBands ( ) ; for ( Band band : bands ) { for ( int i = 0 , rows = band . getRowCount ( ) ; i < rows ; i ++ ) { List < BandElement > list = band . getRow ( i ) ; for ( int j = 0 , size = list . size ( ) ; j < size ; j ++ ) { BandElement be = list . get ( j ) ; if ( be instanceof ForReportBandElement ) { String sql = ( ( ForReportBandElement ) be ) . getSql ( ) ; Report report = ( ( ForReportBandElement ) be ) . getReport ( ) ; if ( ( sql == null ) || sql . isEmpty ( ) ) { return convertedLayout ; } else { QueryUtil qu = new QueryUtil ( con , DialectUtil . getDialect ( con ) ) ; String columnName = qu . getColumnNames ( sql , pBean . getParams ( ) ) . get ( 0 ) ; List < IdName > values = qu . getValues ( sql , pBean . getParams ( ) , pBean . getParamValues ( ) ) ; int pos = j ; for ( int k = 0 ; k < values . size ( ) ; k ++ ) { IdName in = values . get ( k ) ; if ( k > 0 ) { band . insertColumn ( pos ) ; } Report newReport = ObjectCloner . silenceDeepCopy ( report ) ; ReportLayout subReportLayout = ReportUtil . getReportLayoutForHeaderFunctions ( newReport . getLayout ( ) ) ; newReport . setLayout ( subReportLayout ) ; newReport . setName ( report . getBaseName ( ) + "_" + ( k + 1 ) + ".report" ) ; newReport . getGeneratedParamValues ( ) . put ( columnName , in . getId ( ) ) ; band . setElementAt ( new ReportBandElement ( newReport ) , i , pos ) ; pos ++ ; } List < Integer > oldColumnsWidth = layout . getColumnsWidth ( ) ; List < Integer > newColumnWidth = new ArrayList < Integer > ( ) ; for ( int m = 0 ; m < j ; m ++ ) { newColumnWidth . add ( oldColumnsWidth . get ( m ) ) ; } for ( int m = 0 ; m < values . size ( ) ; m ++ ) { newColumnWidth . add ( oldColumnsWidth . get ( j ) ) ; } for ( int m = j + 1 ; m < size ; m ++ ) { newColumnWidth . add ( oldColumnsWidth . get ( m ) ) ; } convertedLayout . setColumnsWidth ( newColumnWidth ) ; return convertedLayout ; } } } } } return convertedLayout ; } | If a report layout contains a ForReportBandElement we must replace this element with more ReportBandElements This means inserting n - 1 new columns where n is the number of values return by sql inside ForReportBandElement |
11,756 | public static boolean foundFunctionInGroupHeader ( ReportLayout layout , String groupName ) { List < Band > groupHeaderBands = layout . getGroupHeaderBands ( ) ; for ( Band band : groupHeaderBands ) { if ( band . getName ( ) . equals ( ReportLayout . GROUP_HEADER_BAND_NAME_PREFIX + groupName ) ) { return foundFunctionInBand ( band ) ; } } return false ; } | Test to see if a function is found in group header band |
11,757 | public static boolean foundFunctionInAnyGroupHeader ( ReportLayout layout ) { List < Band > groupHeaderBands = layout . getGroupHeaderBands ( ) ; for ( Band band : groupHeaderBands ) { boolean found = foundFunctionInBand ( band ) ; if ( found ) { return true ; } } return false ; } | Test to see if a function is found in any group header band |
11,758 | public void addFieldParser ( String property , FieldParser parser ) { if ( _parsers == null ) { _parsers = new HashMap < String , FieldParser > ( ) ; } _parsers . put ( property , parser ) ; } | Adds a custom parser for the specified named field . |
11,759 | public static Field [ ] getFields ( Class < ? > clazz ) { ArrayList < Field > list = new ArrayList < Field > ( ) ; getFields ( clazz , list ) ; return list . toArray ( new Field [ list . size ( ) ] ) ; } | Get the fields contained in the class and its superclasses . |
11,760 | public static boolean compatibleClasses ( Class < ? > [ ] lhs , Class < ? > [ ] rhs ) { if ( lhs . length != rhs . length ) { return false ; } for ( int i = 0 ; i < lhs . length ; ++ i ) { if ( rhs [ i ] == null || rhs [ i ] . equals ( Void . TYPE ) ) { if ( lhs [ i ] . isPrimitive ( ) ) { return false ; } else { continue ; } } if ( ! lhs [ i ] . isAssignableFrom ( rhs [ i ] ) ) { Class < ? > lhsPrimEquiv = primitiveEquivalentOf ( lhs [ i ] ) ; Class < ? > rhsPrimEquiv = primitiveEquivalentOf ( rhs [ i ] ) ; if ( ! primitiveIsAssignableFrom ( lhsPrimEquiv , rhsPrimEquiv ) ) { return false ; } } } return true ; } | Tells whether instances of the classes in the rhs array could be used as parameters to a reflective method invocation whose parameter list has types denoted by the lhs array . |
11,761 | public static Method getAccessibleMethodFrom ( Class < ? > clazz , String methodName , Class < ? > [ ] parameterTypes ) { Class < ? > superclass = clazz . getSuperclass ( ) ; Method overriddenMethod = null ; if ( superclass != null && classIsAccessible ( superclass ) ) { try { overriddenMethod = superclass . getMethod ( methodName , parameterTypes ) ; } catch ( NoSuchMethodException nsme ) { } if ( overriddenMethod != null ) { return overriddenMethod ; } } Class < ? > [ ] interfaces = clazz . getInterfaces ( ) ; for ( int i = 0 ; i < interfaces . length ; ++ i ) { if ( classIsAccessible ( interfaces [ i ] ) ) { try { overriddenMethod = interfaces [ i ] . getMethod ( methodName , parameterTypes ) ; } catch ( NoSuchMethodException nsme ) { } if ( overriddenMethod != null ) { return overriddenMethod ; } } } if ( superclass != null ) { overriddenMethod = getAccessibleMethodFrom ( superclass , methodName , parameterTypes ) ; if ( overriddenMethod != null ) { return overriddenMethod ; } } for ( int i = 0 ; i < interfaces . length ; ++ i ) { overriddenMethod = getAccessibleMethodFrom ( interfaces [ i ] , methodName , parameterTypes ) ; if ( overriddenMethod != null ) { return overriddenMethod ; } } return null ; } | Searches for the method with the given name and formal parameter types that is in the nearest accessible class in the class hierarchy starting with clazz s superclass . The superclass and implemented interfaces of clazz are searched then their superclasses etc . until a method is found . Returns null if there is no such method . |
11,762 | public static boolean primitiveIsAssignableFrom ( Class < ? > lhs , Class < ? > rhs ) { if ( lhs == null || rhs == null ) { return false ; } if ( ! ( lhs . isPrimitive ( ) && rhs . isPrimitive ( ) ) ) { return false ; } if ( lhs . equals ( rhs ) ) { return true ; } Set < Class < ? > > wideningSet = _primitiveWideningsMap . get ( rhs ) ; if ( wideningSet == null ) { return false ; } return wideningSet . contains ( lhs ) ; } | Tells whether an instance of the primitive class represented by rhs can be assigned to an instance of the primitive class represented by lhs . |
11,763 | private void createStar ( ) { Point2D . Float point = start ; p = new GeneralPath ( GeneralPath . WIND_NON_ZERO ) ; p . moveTo ( point . x , point . y ) ; p . lineTo ( point . x + 3.0f , point . y - 1.5f ) ; point = ( Point2D . Float ) p . getCurrentPoint ( ) ; p . lineTo ( point . x + 1.5f , point . y - 3.0f ) ; point = ( Point2D . Float ) p . getCurrentPoint ( ) ; p . lineTo ( point . x + 1.5f , point . y + 3.0f ) ; point = ( Point2D . Float ) p . getCurrentPoint ( ) ; p . lineTo ( point . x + 3.0f , point . y + 1.5f ) ; point = ( Point2D . Float ) p . getCurrentPoint ( ) ; p . lineTo ( point . x - 3.0f , point . y + 1.5f ) ; point = ( Point2D . Float ) p . getCurrentPoint ( ) ; p . lineTo ( point . x - 1.5f , point . y + 3.0f ) ; point = ( Point2D . Float ) p . getCurrentPoint ( ) ; p . lineTo ( point . x - 1.5f , point . y - 3.0f ) ; p . closePath ( ) ; } | Create the path from start |
11,764 | Shape atLocation ( float x , float y ) { start . setLocation ( x , y ) ; p . reset ( ) ; createStar ( ) ; return p ; } | Modify the location of this star |
11,765 | public static int [ ] add ( int [ ] list , int startIdx , int value ) { if ( list == null ) { list = new int [ DEFAULT_LIST_SIZE ] ; } int llength = list . length ; int index = llength ; for ( int i = startIdx ; i < llength ; i ++ ) { if ( list [ i ] == 0 ) { index = i ; break ; } } if ( index >= list . length ) { list = accomodate ( list , index ) ; } list [ index ] = value ; return list ; } | Adds the specified value to the next empty slot in the specified list . Begins searching for empty slots at the specified index . This can be used to quickly add values to a list that preserves consecutivity by calling it with the size of the list as the first index to check . |
11,766 | public static int remove ( int [ ] list , int value ) { if ( list == null ) { return 0 ; } int llength = list . length ; for ( int i = 0 ; i < llength ; i ++ ) { int val = list [ i ] ; if ( val == value ) { System . arraycopy ( list , i + 1 , list , i , llength - ( i + 1 ) ) ; list [ llength - 1 ] = 0 ; return val ; } } return 0 ; } | Removes the first value that is equal to the supplied value . The values after the removed value will be slid down the array one spot to fill the place of the removed value . |
11,767 | public static int removeAt ( int [ ] list , int index ) { int llength = list . length ; if ( llength <= index ) { return 0 ; } int val = list [ index ] ; System . arraycopy ( list , index + 1 , list , index , llength - ( index + 1 ) ) ; list [ llength - 1 ] = 0 ; return val ; } | Removes the value at the specified index . The values after the removed value will be slid down the array one spot to fill the place of the removed value . If a null array is supplied or one that is not large enough to accomodate this index zero is returned . |
11,768 | public static int sum ( int [ ] list ) { int total = 0 , lsize = list . length ; for ( int ii = 0 ; ii < lsize ; ii ++ ) { total += list [ ii ] ; } return total ; } | Returns the total of all of the values in the list . |
11,769 | protected static int [ ] accomodate ( int [ ] list , int index ) { int size = list . length ; while ( size <= index ) { size = Math . max ( size * 2 , DEFAULT_LIST_SIZE ) ; } int [ ] newlist = new int [ size ] ; System . arraycopy ( list , 0 , newlist , 0 , list . length ) ; return newlist ; } | Creates a new list that will accomodate the specified index and copies the contents of the old list to the first . |
11,770 | public static Integer [ ] box ( int [ ] list ) { if ( list == null ) { return null ; } Integer [ ] boxed = new Integer [ list . length ] ; for ( int ii = 0 ; ii < list . length ; ii ++ ) { boxed [ ii ] = list [ ii ] ; } return boxed ; } | Covnerts an array of primitives to an array of objects . |
11,771 | public static List < Integer > asList ( int [ ] list ) { if ( list == null ) { return null ; } List < Integer > ilist = new ArrayList < Integer > ( list . length ) ; for ( int ii = 0 ; ii < list . length ; ii ++ ) { ilist . add ( list [ ii ] ) ; } return ilist ; } | Converts an array of primitives to a list of Integers . |
11,772 | public static void attachHandler ( String protocol , Class < ? extends URLStreamHandler > handlerClass ) { if ( _handlers == null ) { _handlers = new HashMap < String , Class < ? extends URLStreamHandler > > ( ) ; URL . setURLStreamHandlerFactory ( new AttachableURLFactory ( ) ) ; } _handlers . put ( protocol . toLowerCase ( ) , handlerClass ) ; } | Register a URL handler . |
11,773 | public URLStreamHandler createURLStreamHandler ( String protocol ) { Class < ? extends URLStreamHandler > handler = _handlers . get ( protocol . toLowerCase ( ) ) ; if ( handler != null ) { try { return handler . newInstance ( ) ; } catch ( Exception e ) { log . warning ( "Unable to instantiate URLStreamHandler" , "protocol" , protocol , "cause" , e ) ; } } return null ; } | documentation inherited from interface URLStreamHandlerFactory |
11,774 | public static < E extends Enum < E > & ByteEnum > E fromByte ( Class < E > eclass , byte code ) { for ( E value : eclass . getEnumConstants ( ) ) { if ( value . toByte ( ) == code ) { return value ; } } throw new IllegalArgumentException ( eclass + " has no value with code " + code ) ; } | Returns the enum value with the specified code in the supplied enum class . |
11,775 | public static < E extends Enum < E > & ByteEnum > int setToInt ( Set < E > set ) { int flags = 0 ; for ( E value : set ) { flags |= toIntFlag ( value ) ; } return flags ; } | Convert a Set of ByteEnums into an integer compactly representing the elements that are included . |
11,776 | public static < E extends Enum < E > & ByteEnum > EnumSet < E > intToSet ( Class < E > eclass , int flags ) { EnumSet < E > set = EnumSet . noneOf ( eclass ) ; for ( E value : eclass . getEnumConstants ( ) ) { if ( ( flags & toIntFlag ( value ) ) != 0 ) { set . add ( value ) ; } } return set ; } | Convert an int representation of ByteEnum flags into an EnumSet . |
11,777 | protected static void initLogger ( ) { Factory factory = createConfiguredFactory ( ) ; try { if ( factory == null && System . getProperty ( "log4j.configuration" ) != null ) { factory = ( Factory ) Class . forName ( "com.samskivert.util.Log4JLogger" ) . newInstance ( ) ; } } catch ( SecurityException se ) { } catch ( Throwable t ) { System . err . println ( "Unable to instantiate Log4JLogger: " + t ) ; } try { if ( factory == null && System . getProperty ( "log4j.configurationFile" ) != null ) { factory = ( Factory ) Class . forName ( "com.samskivert.util.Log4J2Logger" ) . newInstance ( ) ; } } catch ( SecurityException se ) { } catch ( Throwable t ) { System . err . println ( "Unable to instantiate Log4J2Logger: " + t ) ; } if ( factory == null ) { factory = new JDK14Logger ( ) ; } setFactory ( factory ) ; } | Called at static initialization time . Selects and initializes our logging backend . |
11,778 | protected Constraints getConstraints ( Component child ) { if ( _constraints != null ) { Constraints c = _constraints . get ( child ) ; if ( c != null ) { return c ; } } return DEFAULT_CONSTRAINTS ; } | Get the Constraints for the specified child component . |
11,779 | protected DimenInfo computeDimens ( Container parent , int type ) { int count = parent . getComponentCount ( ) ; DimenInfo info = new DimenInfo ( ) ; info . dimens = new Dimension [ count ] ; for ( int i = 0 ; i < count ; i ++ ) { Component child = parent . getComponent ( i ) ; if ( ! child . isVisible ( ) ) { continue ; } Dimension csize ; switch ( type ) { case MINIMUM : csize = child . getMinimumSize ( ) ; break ; case MAXIMUM : csize = child . getMaximumSize ( ) ; break ; default : csize = child . getPreferredSize ( ) ; break ; } info . count ++ ; info . totwid += csize . width ; info . tothei += csize . height ; if ( csize . width > info . maxwid ) { info . maxwid = csize . width ; } if ( csize . height > info . maxhei ) { info . maxhei = csize . height ; } Constraints c = getConstraints ( child ) ; if ( c . isFixed ( ) ) { info . fixwid += csize . width ; info . fixhei += csize . height ; info . numfix ++ ; } else { info . totweight += c . getWeight ( ) ; if ( csize . width > info . maxfreewid ) { info . maxfreewid = csize . width ; } if ( csize . height > info . maxfreehei ) { info . maxfreehei = csize . height ; } } info . dimens [ i ] = csize ; } return info ; } | Computes dimensions of the children widgets that are useful for the group layout managers . |
11,780 | protected void checkCreate ( ) { if ( _creator != null && isShowing ( ) ) { setLayout ( new BorderLayout ( ) ) ; add ( _creator . createContent ( ) , BorderLayout . CENTER ) ; _creator = null ; } } | Check to see if we should now create the content . |
11,781 | public void invokeTask ( Component parent , String retryMessage ) throws Exception { while ( true ) { try { invoke ( ) ; return ; } catch ( Exception e ) { Object [ ] options = new Object [ ] { "Retry operation" , "Abort operation" } ; int rv = JOptionPane . showOptionDialog ( parent , retryMessage + "\n\n" + e . getMessage ( ) , "Operation failure" , JOptionPane . YES_NO_OPTION , JOptionPane . WARNING_MESSAGE , null , options , options [ 1 ] ) ; if ( rv == 1 ) { throw e ; } } } } | Invokes the supplied task and catches any thrown exceptions . In the event of an exception the provided message is displayed to the user and the are allowed to retry the task or allow it to fail . |
11,782 | public void update ( ) { osName = System . getProperty ( "os.name" ) ; osVersion = System . getProperty ( "os.version" ) ; osArch = System . getProperty ( "os.arch" ) ; javaVersion = System . getProperty ( "java.version" ) ; javaVendor = System . getProperty ( "java.vendor" ) ; Runtime rtime = Runtime . getRuntime ( ) ; freeMemory = rtime . freeMemory ( ) / 1024 ; totalMemory = rtime . totalMemory ( ) / 1024 ; usedMemory = totalMemory - freeMemory ; maxMemory = rtime . maxMemory ( ) / 1024 ; isHeadless = GraphicsEnvironment . isHeadless ( ) ; if ( ! isHeadless ) { try { GraphicsEnvironment env = GraphicsEnvironment . getLocalGraphicsEnvironment ( ) ; GraphicsDevice gd = env . getDefaultScreenDevice ( ) ; DisplayMode mode = gd . getDisplayMode ( ) ; bitDepth = mode . getBitDepth ( ) ; refreshRate = mode . getRefreshRate ( ) / 1024 ; isFullScreen = ( gd . getFullScreenWindow ( ) != null ) ; displayWidth = mode . getWidth ( ) ; displayHeight = mode . getHeight ( ) ; } catch ( Throwable t ) { isHeadless = true ; } } } | Updates the system info record s statistics to reflect the current state of the JVM . |
11,783 | public void add ( T element ) { DependencyNode < T > node = new DependencyNode < T > ( element ) ; _nodes . put ( element , node ) ; _orphans . add ( element ) ; } | Adds an element with no initial dependencies from the graph . |
11,784 | public void remove ( T element ) { DependencyNode < T > node = _nodes . remove ( element ) ; _orphans . remove ( element ) ; for ( DependencyNode < T > parent : node . parents ) { parent . children . remove ( node ) ; } for ( DependencyNode < T > child : node . children ) { child . parents . remove ( node ) ; if ( child . parents . isEmpty ( ) ) { _orphans . add ( child . content ) ; } } } | Removes an element and its dependencies from the graph . |
11,785 | public void addDependency ( T dependant , T dependee ) { _orphans . remove ( dependant ) ; DependencyNode < T > dependantNode = _nodes . get ( dependant ) ; if ( dependantNode == null ) { throw new IllegalArgumentException ( "Unknown dependant? " + dependant ) ; } DependencyNode < T > dependeeNode = _nodes . get ( dependee ) ; if ( dependeeNode == null ) { throw new IllegalArgumentException ( "Unknown dependee? " + dependee ) ; } if ( dependee == dependant || dependsOn ( dependee , dependant ) ) { throw new IllegalArgumentException ( "Refusing to create circular dependency." ) ; } dependantNode . parents . add ( dependeeNode ) ; dependeeNode . children . add ( dependantNode ) ; } | Records a new dependency of the dependant upon the dependee . |
11,786 | public boolean dependsOn ( T elem1 , T elem2 ) { DependencyNode < T > node1 = _nodes . get ( elem1 ) ; DependencyNode < T > node2 = _nodes . get ( elem2 ) ; List < DependencyNode < T > > nodesToCheck = new ArrayList < DependencyNode < T > > ( ) ; List < DependencyNode < T > > nodesAlreadyChecked = new ArrayList < DependencyNode < T > > ( ) ; nodesToCheck . addAll ( node1 . parents ) ; while ( ! nodesToCheck . isEmpty ( ) ) { DependencyNode < T > checkNode = nodesToCheck . remove ( nodesToCheck . size ( ) - 1 ) ; if ( nodesAlreadyChecked . contains ( checkNode ) ) { continue ; } else if ( checkNode == node2 ) { return true ; } else { nodesAlreadyChecked . add ( checkNode ) ; nodesToCheck . addAll ( checkNode . parents ) ; } } return false ; } | Returns whether elem1 is designated to depend on elem2 . |
11,787 | public ObserverList < T > toObserverList ( ) { ObserverList < T > list = ObserverList . newSafeInOrder ( ) ; while ( ! isEmpty ( ) ) { list . add ( removeAvailableElement ( ) ) ; } return list ; } | Flattens this graph into an observer list in dependencys order . Empties the graph in the process . |
11,788 | public void remove ( String name ) { String oldValue = getValue ( name , ( String ) null ) ; _prefs . remove ( name ) ; _propsup . firePropertyChange ( name , oldValue , null ) ; } | Remove any set value for the specified preference . |
11,789 | public static String restrictHTML ( String src , boolean allowFormatting , boolean allowImages , boolean allowLinks ) { ArrayList < String > allow = new ArrayList < String > ( ) ; if ( allowFormatting ) { allow . add ( "<b>" ) ; allow . add ( "</b>" ) ; allow . add ( "<i>" ) ; allow . add ( "</i>" ) ; allow . add ( "<u>" ) ; allow . add ( "</u>" ) ; allow . add ( "<font [^\"<>!-]*(\"[^\"<>!-]*\"[^\"<>!-]*)*>" ) ; allow . add ( "</font>" ) ; allow . add ( "<br>" ) ; allow . add ( "</br>" ) ; allow . add ( "<br/>" ) ; allow . add ( "<p>" ) ; allow . add ( "</p>" ) ; allow . add ( "<hr>" ) ; allow . add ( "</hr>" ) ; allow . add ( "<hr/>" ) ; } if ( allowImages ) { allow . add ( "<img [^\"<>!-]*(\"[^\"<>!-]*\"[^\"<>!-]*)*>" ) ; allow . add ( "</img>" ) ; } if ( allowLinks ) { allow . add ( "<a href=[^\"<>!-]*(\"[^\"<>!-]*\"[^\"<>!-]*)*>" ) ; allow . add ( "</a>" ) ; } return restrictHTML ( src , allow . toArray ( new String [ allow . size ( ) ] ) ) ; } | Restrict HTML except for the specified tags . |
11,790 | public static String restrictHTML ( String src , String [ ] regexes ) { if ( StringUtil . isBlank ( src ) ) { return src ; } ArrayList < String > list = new ArrayList < String > ( ) ; list . add ( src ) ; for ( String regexe : regexes ) { Pattern p = Pattern . compile ( regexe , Pattern . CASE_INSENSITIVE ) ; for ( int jj = 0 ; jj < list . size ( ) ; jj += 2 ) { String piece = list . get ( jj ) ; Matcher m = p . matcher ( piece ) ; if ( m . find ( ) ) { list . set ( jj , piece . substring ( 0 , m . start ( ) ) ) ; list . add ( jj + 1 , piece . substring ( m . start ( ) , m . end ( ) ) ) ; list . add ( jj + 2 , piece . substring ( m . end ( ) ) ) ; } } } StringBuilder buf = new StringBuilder ( ) ; for ( int jj = 0 , nn = list . size ( ) ; jj < nn ; jj ++ ) { String s = list . get ( jj ) ; if ( jj % 2 == 0 ) { s = s . replace ( "<" , "<" ) ; s = s . replace ( ">" , ">" ) ; } buf . append ( s ) ; } return buf . toString ( ) ; } | Restrict HTML from the specified string except for the specified regular expressions . |
11,791 | public void requestFailed ( Exception cause ) { Object [ ] args = _args != null ? ArrayUtil . append ( _args , cause ) : new Object [ ] { cause } ; if ( _slogger != null ) { _slogger . warning ( _errorText , args ) ; } else if ( _jlogger != null ) { _jlogger . log ( Level . WARNING , Logger . format ( _errorText , args ) , cause ) ; } else { System . err . println ( Logger . format ( _errorText , args ) ) ; } } | from interface ResultListener |
11,792 | public static int compare ( Date d1 , Date d2 ) { Calendar c1 = Calendar . getInstance ( ) ; c1 . setTime ( d1 ) ; Calendar c2 = Calendar . getInstance ( ) ; c2 . setTime ( d2 ) ; if ( c1 . get ( Calendar . YEAR ) == c2 . get ( Calendar . YEAR ) ) { if ( c1 . get ( Calendar . MONTH ) == c2 . get ( Calendar . MONTH ) ) { return c1 . get ( Calendar . DAY_OF_MONTH ) - c2 . get ( Calendar . DAY_OF_MONTH ) ; } return c1 . get ( Calendar . MONTH ) - c2 . get ( Calendar . MONTH ) ; } return c1 . get ( Calendar . YEAR ) - c2 . get ( Calendar . YEAR ) ; } | Compares two dates taking into consideration only the year month and day |
11,793 | public static int getYear ( Date date ) { Calendar c = Calendar . getInstance ( ) ; c . setTime ( date ) ; return c . get ( Calendar . YEAR ) ; } | Get the year of the date |
11,794 | public static int getMonth ( Date date ) { Calendar c = Calendar . getInstance ( ) ; c . setTime ( date ) ; return c . get ( Calendar . MONTH ) ; } | Get the month of the date |
11,795 | public static int getDayOfYear ( Date date ) { Calendar c = Calendar . getInstance ( ) ; c . setTime ( date ) ; return c . get ( Calendar . DAY_OF_YEAR ) ; } | Get the day of year of the date |
11,796 | public static int getDayOfMonth ( Date date ) { Calendar c = Calendar . getInstance ( ) ; c . setTime ( date ) ; return c . get ( Calendar . DAY_OF_MONTH ) ; } | Get the day of month of the date |
11,797 | public static int getDayOfWeek ( Date date ) { Calendar c = Calendar . getInstance ( ) ; c . setTime ( date ) ; return c . get ( Calendar . DAY_OF_WEEK ) ; } | Get the day of week of the date |
11,798 | public static int getHour ( Date date ) { Calendar c = Calendar . getInstance ( ) ; c . setTime ( date ) ; return c . get ( Calendar . HOUR_OF_DAY ) ; } | Get the hour of the date |
11,799 | public static int getMinute ( Date date ) { Calendar c = Calendar . getInstance ( ) ; c . setTime ( date ) ; return c . get ( Calendar . MINUTE ) ; } | Get the minute of the date |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.