idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
135,000
protected void fireActionPerformed ( ) { Object [ ] listeners = listenerList . getListenerList ( ) ; for ( int i = listeners . length - 2 ; i >= 0 ; i -= 2 ) { if ( listeners [ i ] == ActionListener . class ) { if ( _actionEvent == null ) { _actionEvent = new ActionEvent ( this , ActionEvent . ACTION_PERFORMED , _actio...
Notifies our listeners when the selection changed .
135,001
protected void addButtons ( int start , int count ) { Object selobj = _model . getSelectedItem ( ) ; for ( int i = start ; i < count ; i ++ ) { Object elem = _model . getElementAt ( i ) ; if ( selobj == elem ) { _selectedIndex = i ; } JLabel ibut = null ; if ( elem instanceof Image ) { ibut = new JLabel ( new ImageIcon...
Adds buttons for the specified range of model elements .
135,002
protected void removeButtons ( int start , int count ) { while ( count -- > 0 ) { remove ( start ) ; } if ( _selectedIndex >= start ) { if ( start + count > _selectedIndex ) { _selectedIndex = - 1 ; } else { _selectedIndex -= count ; } } }
Removes the buttons in the specified interval .
135,003
protected void updateSelection ( int selidx ) { if ( selidx == _selectedIndex ) { return ; } if ( _selectedIndex != - 1 ) { JLabel but = ( JLabel ) getComponent ( _selectedIndex ) ; but . setBorder ( DESELECTED_BORDER ) ; } _selectedIndex = selidx ; if ( _selectedIndex != - 1 ) { JLabel but = ( JLabel ) getComponent ( ...
Sets the selection to the specified index and updates the buttons to reflect the change . This does not update the model .
135,004
protected void layout ( Graphics2D gfx , int iconPadding , int extraPadding ) { int sqwid , sqhei ; if ( _icon == null ) { sqwid = sqhei = 0 ; } else { sqwid = _icon . getIconWidth ( ) ; sqhei = _icon . getIconHeight ( ) ; _label . setTargetHeight ( sqhei ) ; } _label . layout ( gfx ) ; Dimension lsize = _label . getSi...
Lays out the label sausage . It is assumed that the desired label font is already set in the label .
135,005
protected void paint ( Graphics2D gfx , int x , int y , Color background , Object cliData ) { Object oalias = SwingUtil . activateAntiAliasing ( gfx ) ; gfx . setColor ( background ) ; drawBase ( gfx , x , y ) ; drawIcon ( gfx , x , y , cliData ) ; drawLabel ( gfx , x , y ) ; drawBorder ( gfx , x , y ) ; drawExtras ( g...
Paints the label sausage .
135,006
protected void drawBase ( Graphics2D gfx , int x , int y ) { gfx . fillRoundRect ( x , y , _size . width - 1 , _size . height - 1 , _dia , _dia ) ; }
Draws the base sausage within which all the other decorations are added .
135,007
protected void drawIcon ( Graphics2D gfx , int x , int y , Object cliData ) { if ( _icon != null ) { _icon . paintIcon ( null , gfx , x + _xoff , y + _yoff ) ; } }
Draws the icon if applicable .
135,008
protected void drawLabel ( Graphics2D gfx , int x , int y ) { _label . render ( gfx , x + _lxoff , y + _lyoff ) ; }
Draws the label .
135,009
protected void drawBorder ( Graphics2D gfx , int x , int y ) { gfx . setColor ( Color . black ) ; gfx . drawRoundRect ( x , y , _size . width - 1 , _size . height - 1 , _dia , _dia ) ; }
Draws the black outer border .
135,010
public static String getFullColumnClassName ( String className ) { if ( className . startsWith ( "java." ) ) { return className ; } if ( "String" . equals ( className ) ) { return "java.lang.String" ; } else if ( "Int" . equals ( className ) ) { return "java.lang.Integer" ; } else if ( "Double" . equals ( className ) )...
CsvJdbc driver className is not a full java class name
135,011
public static void centerWindow ( Window window ) { Rectangle bounds ; try { bounds = GraphicsEnvironment . getLocalGraphicsEnvironment ( ) . getDefaultScreenDevice ( ) . getDefaultConfiguration ( ) . getBounds ( ) ; } catch ( Throwable t ) { Toolkit tk = window . getToolkit ( ) ; Dimension ss = tk . getScreenSize ( ) ...
Center the given window within the screen boundaries .
135,012
public static void drawStringCentered ( Graphics g , String str , int x , int y , int width , int height ) { FontMetrics fm = g . getFontMetrics ( g . getFont ( ) ) ; int xpos = x + ( ( width - fm . stringWidth ( str ) ) / 2 ) ; int ypos = y + ( ( height + fm . getAscent ( ) ) / 2 ) ; g . drawString ( str , xpos , ypos...
Draw a string centered within a rectangle . The string is drawn using the graphics context s current font and color .
135,013
public static Point fitRectInRect ( Rectangle rect , Rectangle bounds ) { return new Point ( Math . min ( bounds . x + bounds . width - rect . width , Math . max ( rect . x , bounds . x ) ) , Math . min ( bounds . y + bounds . height - rect . height , Math . max ( rect . y , bounds . y ) ) ) ; }
Returns the most reasonable position for the specified rectangle to be placed at so as to maximize its containment by the specified bounding rectangle while still placing it as near its original coordinates as possible .
135,014
public static boolean positionRect ( Rectangle r , Rectangle bounds , Collection < ? extends Shape > avoidShapes ) { Point origPos = r . getLocation ( ) ; Comparator < Point > comp = createPointComparator ( origPos ) ; SortableArrayList < Point > possibles = new SortableArrayList < Point > ( ) ; possibles . add ( fitRe...
Position the specified rectangle as closely as possible to its current position but make sure it is within the specified bounds and that it does not overlap any of the Shapes contained in the avoid list .
135,015
public static < P extends Point2D > Comparator < P > createPointComparator ( final P origin ) { return new Comparator < P > ( ) { public int compare ( P p1 , P p2 ) { double dist1 = origin . distance ( p1 ) ; double dist2 = origin . distance ( p2 ) ; return ( dist1 > dist2 ) ? 1 : ( ( dist1 < dist2 ) ? - 1 : 0 ) ; } } ...
Create a comparator that compares against the distance from the specified point .
135,016
public static void applyToHierarchy ( Component comp , ComponentOp op ) { applyToHierarchy ( comp , Integer . MAX_VALUE , op ) ; }
Apply the specified ComponentOp to the supplied component and then all its descendants .
135,017
public static void applyToHierarchy ( Component comp , int depth , ComponentOp op ) { if ( comp == null ) { return ; } op . apply ( comp ) ; if ( comp instanceof Container && -- depth >= 0 ) { Container c = ( Container ) comp ; int ccount = c . getComponentCount ( ) ; for ( int ii = 0 ; ii < ccount ; ii ++ ) { applyToH...
Apply the specified ComponentOp to the supplied component and then all its descendants up to the specified maximum depth .
135,018
public static Object activateAntiAliasing ( Graphics2D gfx ) { RenderingHints ohints = gfx . getRenderingHints ( ) , nhints = new RenderingHints ( null ) ; nhints . add ( ohints ) ; nhints . put ( RenderingHints . KEY_ANTIALIASING , RenderingHints . VALUE_ANTIALIAS_ON ) ; nhints . put ( RenderingHints . KEY_TEXT_ANTIAL...
Activates anti - aliasing in the supplied graphics context on both text and 2D drawing primitives .
135,019
public static void restoreAntiAliasing ( Graphics2D gfx , Object rock ) { if ( rock != null ) { gfx . setRenderingHints ( ( RenderingHints ) rock ) ; } }
Restores anti - aliasing in the supplied graphics context to its original setting .
135,020
public static void sizeToContents ( JTable table ) { TableModel model = table . getModel ( ) ; TableColumn column = null ; Component comp = null ; int ccount = table . getColumnModel ( ) . getColumnCount ( ) , rcount = model . getRowCount ( ) , cellHeight = 0 ; for ( int cc = 0 ; cc < ccount ; cc ++ ) { int headerWidth...
Adjusts the widths and heights of the cells of the supplied table to fit their contents .
135,021
public static Cursor createImageCursor ( Image img , Point hotspot ) { Toolkit tk = Toolkit . getDefaultToolkit ( ) ; int w = img . getWidth ( null ) ; int h = img . getHeight ( null ) ; Dimension d = tk . getBestCursorSize ( w , h ) ; if ( ( ( w < d . width ) && ( h <= d . height ) ) || ( ( w <= d . width ) && ( h < d...
Create a custom cursor out of the specified image with the specified hotspot .
135,022
public static void addDebugBorders ( JPanel panel ) { Color bcolor = new Color ( _rando . nextInt ( 256 ) , _rando . nextInt ( 256 ) , _rando . nextInt ( 256 ) ) ; panel . setBorder ( BorderFactory . createLineBorder ( bcolor ) ) ; for ( int ii = 0 ; ii < panel . getComponentCount ( ) ; ii ++ ) { Object child = panel ....
Adds a one pixel border of random color to this and all panels contained in this panel s child hierarchy .
135,023
public static void setFrameIcons ( Frame frame , List < ? extends Image > icons ) { try { Method m = frame . getClass ( ) . getMethod ( "setIconImages" , List . class ) ; m . invoke ( frame , icons ) ; return ; } catch ( SecurityException e ) { } catch ( NoSuchMethodException e ) { } catch ( Exception e ) { log . warni...
Sets the frame s icons . Unfortunately the ability to pass multiple icons so the OS can choose the most size - appropriate one was added in 1 . 6 ; before that you can only set one icon .
135,024
public static JComponent createAdjustEditor ( ) { VGroupLayout layout = new VGroupLayout ( VGroupLayout . NONE , VGroupLayout . STRETCH , 3 , VGroupLayout . TOP ) ; layout . setOffAxisJustification ( VGroupLayout . LEFT ) ; JTabbedPane editor = new EditorPane ( ) ; Font font = editor . getFont ( ) ; Font smaller = font...
Creates a Swing user interface that can be used to adjust all registered runtime adjustments .
135,025
public Object get ( Object array , int index ) { return ( array == null ) ? null : Array . get ( array , index ) ; }
Returns the object in the array at index . Wrapped as an object if it is a primitive .
135,026
public static String httpPost ( final URL url , final String submission , int timeout , final Map < String , String > requestProps ) throws IOException , ServiceWaiter . TimeoutException { final ServiceWaiter < String > waiter = new ServiceWaiter < String > ( ( timeout < 0 ) ? ServiceWaiter . NO_TIMEOUT : timeout ) ; T...
Return the results of a form post . Note that the http request takes place on another thread but this thread blocks until the results are returned or it times out .
135,027
protected String [ ] inferCaller ( ) { String self = getClass ( ) . getName ( ) ; StackTraceElement [ ] stack = ( new Throwable ( ) ) . getStackTrace ( ) ; int ii = 0 ; for ( ; ii < stack . length ; ii ++ ) { if ( self . equals ( stack [ ii ] . getClassName ( ) ) ) { break ; } } System . err . println ( "Found self at ...
Infers the caller of a Logger method from the current stack trace . This can be used by wrappers to provide the correct calling class and method information to their underlying log implementation .
135,028
public boolean isSourceModified ( Resource resource ) { SiteKey skey = new SiteKey ( resource . getName ( ) ) ; if ( skey . siteId == SiteIdentifier . DEFAULT_SITE_ID ) { return false ; } else { try { return ( resource . getLastModified ( ) < _loader . getLastModified ( skey . siteId ) ) ; } catch ( IOException ioe ) {...
Things won t ever be modified when loaded from the servlet context because they came from the webapp . war file and if that is reloaded everything will be thrown away and started afresh .
135,029
public Series setType ( SeriesType type ) { if ( type != null ) { this . type = type . name ( ) . toLowerCase ( ) ; } else { this . type = null ; } return this ; }
The type of series
135,030
private void populateDependentParameters ( Report nextReport , QueryParameter parameter ) { Map < String , QueryParameter > childParams = ParameterUtil . getChildDependentParameters ( nextReport , parameter ) ; for ( QueryParameter childParam : childParams . values ( ) ) { if ( ! parameters . contains ( childParam ) ) ...
and set their values too
135,031
public static boolean equalsText ( String s1 , String s2 ) { if ( s1 == null ) { if ( s2 != null ) { return false ; } } else { if ( s2 == null ) { return false ; } } if ( ( s1 != null ) && ( s2 != null ) ) { s1 = s1 . replaceAll ( "\\s" , "" ) . toLowerCase ( ) ; s2 = s2 . replaceAll ( "\\s" , "" ) . toLowerCase ( ) ; ...
functional compare for two strings as ignore - case text
135,032
private static boolean isImage ( String hexString ) { boolean isImage = false ; if ( hexString . startsWith ( "89504e470d0a1a0a" ) ) { isImage = true ; } else if ( hexString . startsWith ( "474946383761" ) || hexString . startsWith ( "474946383961" ) ) { isImage = true ; } else if ( hexString . startsWith ( "ffd8ffe0" ...
JPEGs start with FF D8 FF E0 xx xx 4A 46 49 46 00
135,033
public void layout ( Graphics2D gfx , Font font ) { _label . setFont ( font ) ; layout ( gfx , BORDER_THICKNESS ) ; openBounds . width = _size . width ; openBounds . height = _size . height ; closedBounds . height = closedBounds . width = _size . height ; }
Computes the dimensions of this label based on the specified font and in the specified graphics context .
135,034
protected void drawBase ( Graphics2D gfx , int x , int y ) { if ( _active ) { super . drawBase ( gfx , x , y ) ; } else { gfx . fillOval ( x , y , closedBounds . width - 1 , closedBounds . height - 1 ) ; } }
Draw the base circle or sausage within which all the other decorations are added .
135,035
protected void paint ( Graphics2D gfx , int x , int y , RadialMenu menu ) { paint ( gfx , x , y , UIManager . getColor ( "RadialLabelSausage.background" ) , menu ) ; }
Paints the radial label sausage .
135,036
public static int nextPowerOfTwo ( int value ) { return ( int ) Math . pow ( 2 , Math . ceil ( Math . log ( value ) / Math . log ( 2 ) ) ) ; }
Rounds the specified value up to the next nearest power of two .
135,037
public static Object [ ] add ( Object [ ] list , int startIdx , Object element ) { requireNotNull ( element ) ; if ( list == null ) { list = new Object [ DEFAULT_LIST_SIZE ] ; } int llength = list . length ; int index = llength ; for ( int i = startIdx ; i < llength ; i ++ ) { if ( list [ i ] == null ) { index = i ; br...
Adds the specified element 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 elements to a list that preserves consecutivity by calling it with the size of the list as the first index to check .
135,038
public static Object [ ] insert ( Object [ ] list , int index , Object element ) { requireNotNull ( element ) ; if ( list == null ) { list = new Object [ DEFAULT_LIST_SIZE ] ; } int size = list . length ; if ( list [ size - 1 ] != null ) { list = accomodate ( list , size ) ; } else { size -- ; } System . arraycopy ( li...
Inserts the supplied element at the specified position in the array shifting the remaining elements down . The array will be expanded if necessary .
135,039
public static int indexOfNull ( Object [ ] list ) { if ( list != null ) { for ( int ii = 0 , nn = list . length ; ii < nn ; ii ++ ) { if ( list [ ii ] == null ) { return ii ; } } } return - 1 ; }
Returns the lowest index in the array that contains null or - 1 if there is no room to add elements without expanding the array .
135,040
public static Object remove ( Object [ ] list , int index ) { if ( list == null ) { return null ; } int llength = list . length ; if ( llength <= index || index < 0 ) { return null ; } Object elem = list [ index ] ; System . arraycopy ( list , index + 1 , list , index , llength - ( index + 1 ) ) ; list [ llength - 1 ] ...
Removes the element at the specified index . The elements after the removed element will be slid down the array one spot to fill the place of the removed element . If a null array is supplied or one that is not large enough to accomodate this index null is returned .
135,041
public static int size ( Object [ ] list ) { if ( list == null ) { return 0 ; } int llength = list . length ; for ( int ii = 0 ; ii < llength ; ii ++ ) { if ( list [ ii ] == null ) { return ii ; } } return llength ; }
Returns the number of elements prior to the first null in the supplied list .
135,042
public static int getSize ( Object [ ] list ) { int size = 0 ; for ( int ii = 0 , nn = ( list == null ) ? 0 : list . length ; ii < nn ; ii ++ ) { if ( list [ ii ] != null ) { size ++ ; } } return size ; }
Returns the number of non - null elements in the supplied list .
135,043
public static void main ( String [ ] args ) { Object [ ] list = null ; String foo = "foo" ; String bar = "bar" ; list = ListUtil . add ( list , foo ) ; System . out . println ( "add(foo): " + StringUtil . toString ( list ) ) ; list = ListUtil . add ( list , bar ) ; System . out . println ( "add(bar): " + StringUtil . t...
Run some tests .
135,044
public int getOrElse ( int key , int defval ) { Record rec = locateRecord ( key ) ; return ( rec == null ) ? defval : rec . value ; }
Returns the value mapped to the specified key or the supplied default value if there is no mapping .
135,045
public int removeOrElse ( int key , int defval ) { _modCount ++ ; int removed = removeImpl ( key , defval ) ; checkShrink ( ) ; return removed ; }
Removes the value mapped for the specified key .
135,046
public void clear ( ) { _modCount ++ ; for ( int i = 0 ; i < _buckets . length ; i ++ ) { _buckets [ i ] = null ; } _size = 0 ; }
Clears all mappings .
135,047
public void ensureCapacity ( int minCapacity ) { int size = _buckets . length ; while ( minCapacity > ( int ) ( size * _loadFactor ) ) { size *= 2 ; } if ( size != _buckets . length ) { resizeBuckets ( size ) ; } }
Ensure that the hash can comfortably hold the specified number of elements . Calling this method is not necessary but can improve performance if done prior to adding many elements .
135,048
protected Record locateRecord ( int key ) { int index = Math . abs ( key ) % _buckets . length ; for ( Record rec = _buckets [ index ] ; rec != null ; rec = rec . next ) { if ( rec . key == key ) { return rec ; } } return null ; }
Internal method to locate the record for the specified key .
135,049
protected int removeImpl ( int key , int defval ) { int index = Math . abs ( key ) % _buckets . length ; Record prev = null ; for ( Record rec = _buckets [ index ] ; rec != null ; rec = rec . next ) { if ( rec . key == key ) { if ( prev == null ) { _buckets [ index ] = rec . next ; } else { prev . next = rec . next ; }...
Internal method for removing a mapping .
135,050
protected void checkShrink ( ) { if ( ( _buckets . length > DEFAULT_BUCKETS ) && ( _size < ( int ) ( _buckets . length * _loadFactor * .125 ) ) ) { resizeBuckets ( Math . max ( DEFAULT_BUCKETS , _buckets . length >> 1 ) ) ; } }
Check to see if we want to shrink the table .
135,051
public Set < IntIntEntry > entrySet ( ) { return new AbstractSet < IntIntEntry > ( ) { public int size ( ) { return _size ; } public Iterator < IntIntEntry > iterator ( ) { return new IntEntryIterator ( ) ; } } ; }
Get a set of all the entries in this map .
135,052
public void addComponent ( BaseComponent comp ) { if ( comp instanceof InitComponent ) { if ( _initers == null ) { throw new IllegalStateException ( "Too late to register InitComponent." ) ; } _initers . add ( ( InitComponent ) comp ) ; } if ( comp instanceof ShutdownComponent ) { if ( _downers == null ) { throw new Il...
Registers a component with the lifecycle . This should be done during dependency resolution by injecting the Lifecycle into your constructor and calling this method there .
135,053
public void removeComponent ( BaseComponent comp ) { if ( _initers != null && comp instanceof InitComponent ) { _initers . remove ( ( InitComponent ) comp ) ; } if ( _downers != null && comp instanceof ShutdownComponent ) { _downers . remove ( ( ShutdownComponent ) comp ) ; } }
Removes a component from the lifecycle . This is generally not used .
135,054
public void addInitConstraint ( InitComponent lhs , Constraint constraint , InitComponent rhs ) { if ( lhs == null || rhs == null ) { throw new IllegalArgumentException ( "Cannot add constraint about null component." ) ; } InitComponent before = ( constraint == Constraint . RUNS_BEFORE ) ? lhs : rhs ; InitComponent aft...
Adds a constraint that a certain component must be initialized before another .
135,055
public void addShutdownConstraint ( ShutdownComponent lhs , Constraint constraint , ShutdownComponent rhs ) { if ( lhs == null || rhs == null ) { throw new IllegalArgumentException ( "Cannot add constraint about null component." ) ; } ShutdownComponent before = ( constraint == Constraint . RUNS_BEFORE ) ? lhs : rhs ; S...
Adds a constraint that a certain component must be shutdown before another .
135,056
public void init ( ) { if ( _initers == null ) { log . warning ( "Refusing repeat init() request." ) ; return ; } ObserverList < InitComponent > list = _initers . toObserverList ( ) ; _initers = null ; list . apply ( new ObserverList . ObserverOp < InitComponent > ( ) { public boolean apply ( InitComponent comp ) { log...
Initializes all components immediately on the caller s thread .
135,057
public void shutdown ( ) { if ( _downers == null ) { log . warning ( "Refusing repeat shutdown() request." ) ; return ; } ObserverList < ShutdownComponent > list = _downers . toObserverList ( ) ; _downers = null ; list . apply ( new ObserverList . ObserverOp < ShutdownComponent > ( ) { public boolean apply ( ShutdownCo...
Shuts down all components immediately on the caller s thread .
135,058
protected Record < V > getImpl ( int key ) { for ( Record < V > rec = _buckets [ keyToIndex ( key ) ] ; rec != null ; rec = rec . next ) { if ( rec . key == key ) { return rec ; } } return null ; }
Locate the record with the specified key .
135,059
protected Record < V > removeImpl ( int key , boolean checkShrink ) { int index = keyToIndex ( key ) ; for ( Record < V > prev = null , rec = _buckets [ index ] ; rec != null ; rec = rec . next ) { if ( rec . key == key ) { if ( prev == null ) { _buckets [ index ] = rec . next ; } else { prev . next = rec . next ; } _s...
Remove an element with optional checking to see if we should shrink . When this is called from our iterator checkShrink == false to avoid booching the buckets .
135,060
protected final int keyToIndex ( int key ) { key += ~ ( key << 9 ) ; key ^= ( key >>> 14 ) ; key += ( key << 4 ) ; key ^= ( key >>> 10 ) ; return key & ( _buckets . length - 1 ) ; }
Turn the specified key into an index .
135,061
public IntSet intKeySet ( ) { if ( _keySet == null ) { _keySet = new AbstractIntSet ( ) { public Interator interator ( ) { return new AbstractInterator ( ) { public boolean hasNext ( ) { return i . hasNext ( ) ; } public int nextInt ( ) { return i . next ( ) . getIntKey ( ) ; } public void remove ( ) { i . remove ( ) ;...
documentation inherited from interface IntMap
135,062
public static String rehostLocation ( HttpServletRequest req , String servername ) { StringBuffer buf = req . getRequestURL ( ) ; String csname = req . getServerName ( ) ; int csidx = buf . indexOf ( csname ) ; if ( csidx != - 1 ) { buf . delete ( csidx , csidx + csname . length ( ) ) ; buf . insert ( csidx , servernam...
Recreates the URL used to make the supplied request replacing the server part of the URL with the supplied server name .
135,063
public static String getServletURL ( HttpServletRequest req , String path ) { StringBuffer buf = req . getRequestURL ( ) ; String sname = req . getServletPath ( ) ; buf . delete ( buf . length ( ) - sname . length ( ) , buf . length ( ) ) ; if ( ! path . startsWith ( "/" ) ) { buf . append ( "/" ) ; } buf . append ( pa...
Prepends the server port and servlet context path to the supplied path resulting in a fully - formed URL for requesting a servlet .
135,064
public void insertDatum ( Object element , int row ) { _data . add ( row , element ) ; _model . fireTableRowsInserted ( row , row ) ; }
Insert the specified element at the specified row .
135,065
public void updateDatum ( Object element , int row ) { _data . set ( row , element ) ; _model . fireTableRowsUpdated ( row , row ) ; }
Change the value of the specified row .
135,066
public void removeDatum ( Object element ) { int dex = _data . indexOf ( element ) ; if ( dex != - 1 ) { removeDatum ( dex ) ; } }
Remove the specified element from the set of data .
135,067
public String getErrorMessage ( ) { String msg = getMessage ( ) ; return String . valueOf ( _errorCode ) . equals ( msg ) ? null : msg ; }
Returns the textual error message supplied with this exception or null if only an error code was supplied .
135,068
public static String [ ] getCanonicalPathElements ( File file ) throws IOException { file = file . getCanonicalFile ( ) ; if ( ! file . isDirectory ( ) ) { file = file . getParentFile ( ) ; } return file . getPath ( ) . split ( File . separator ) ; }
Gets the individual path elements building up the canonical path to the given file .
135,069
public static String computeRelativePath ( File file , File relativeTo ) throws IOException { String [ ] realDirs = getCanonicalPathElements ( file ) ; String [ ] relativeToDirs = getCanonicalPathElements ( relativeTo ) ; int common = 0 ; for ( ; common < realDirs . length && common < relativeToDirs . length ; common +...
Computes a relative path between to Files
135,070
public static int getRunPriority ( ) { String s = System . getProperty ( RUN_PRIORITY_PROPERTY ) ; int priority = Thread . NORM_PRIORITY ; if ( s != null ) { try { priority = Integer . parseInt ( s ) ; } catch ( NumberFormatException ex ) { } } return priority ; }
Get priority for running next reports queries and exporters
135,071
public static int getRecordsYield ( ) { String s = System . getProperty ( RECORDS_YIELD_PROPERTY ) ; int records = Integer . MAX_VALUE ; if ( s != null ) { try { records = Integer . parseInt ( s ) ; } catch ( NumberFormatException ex ) { } } return records ; }
Get number of query records after the exporter waits a little to degrevate the processor
135,072
public static int getMillisYield ( ) { String s = System . getProperty ( MILLIS_YIELD_PROPERTY ) ; int millis = DEFAULT_MILLIS_YIELD ; if ( s != null ) { try { millis = Integer . parseInt ( s ) ; } catch ( NumberFormatException ex ) { } } return millis ; }
Get number of milliseconds the exporter will wait after RECORDS_YIELD are exported
135,073
public static void createSummaryInformation ( String filePath , String title ) { if ( filePath == null ) { return ; } try { File poiFilesystem = new File ( filePath ) ; InputStream is = new FileInputStream ( poiFilesystem ) ; POIFSFileSystem poifs = new POIFSFileSystem ( is ) ; is . close ( ) ; DirectoryEntry dir = poi...
is called also on the server
135,074
public ClassLoader getSiteClassLoader ( int siteId ) throws IOException { synchronized ( getLock ( siteId ) ) { ClassLoader loader = _loaders . get ( siteId ) ; if ( loader == null ) { final SiteResourceBundle bundle = getBundle ( siteId ) ; if ( bundle == null ) { return null ; } loader = AccessController . doPrivileg...
Returns a class loader that loads resources from the site - specific jar file for the specified site . If no site - specific jar file exists for the specified site null will be returned .
135,075
protected Object getLock ( int siteId ) { Object lock = null ; synchronized ( _locks ) { lock = _locks . get ( siteId ) ; if ( lock == null ) { _locks . put ( siteId , lock = new Object ( ) ) ; } } return lock ; }
We synchronize on a per - site basis but we use a separate lock object for each site so that the process of loading a bundle for the first time does not require blocking access to resources from other sites .
135,076
protected SiteResourceBundle getBundle ( int siteId ) throws IOException { SiteResourceBundle bundle = _bundles . get ( siteId ) ; if ( bundle == null ) { String ident = _siteIdent . getSiteString ( siteId ) ; File file = new File ( _jarPath , ident + JAR_EXTENSION ) ; bundle = new SiteResourceBundle ( file ) ; _bundle...
Obtains the site - specific jar file for the specified site . This should only be called when the lock for this site is held .
135,077
public static Interval create ( RunQueue runQueue , final Runnable onExpired ) { return new Interval ( runQueue ) { public void expired ( ) { onExpired . run ( ) ; } public String toString ( ) { return onExpired . toString ( ) ; } } ; }
Creates an interval that executes the supplied runnable on the specified RunQueue when it expires .
135,078
public final void cancel ( ) { IntervalTask task = _task ; if ( task != null ) { _task = null ; task . cancel ( ) ; } }
Cancel the current schedule and ensure that any expirations that are queued up but have not yet run do not run .
135,079
public static void deliverMail ( String recipient , String sender , String subject , String body ) throws IOException { deliverMail ( new String [ ] { recipient } , sender , subject , body ) ; }
Delivers the supplied mail message using the machine s local mail SMTP server which must be listening on port 25 .
135,080
public static void deliverMail ( String [ ] recipients , String sender , String subject , String body , String [ ] headers , String [ ] values ) throws IOException { if ( recipients == null || recipients . length < 1 ) { throw new IOException ( "Must specify one or more recipients." ) ; } try { MimeMessage message = cr...
Delivers the supplied mail with the specified additional headers .
135,081
public static void deliverMail ( String [ ] recipients , String sender , String subject , MimeMessage message ) throws IOException { checkCreateSession ( ) ; try { message . setFrom ( new InternetAddress ( sender ) ) ; for ( String recipient : recipients ) { message . addRecipient ( Message . RecipientType . TO , new I...
Delivers an already - formed message to the specified recipients . This message can be any mime type including multipart .
135,082
protected static void checkCreateSession ( ) { if ( _defaultSession == null ) { Properties props = System . getProperties ( ) ; if ( props . getProperty ( "mail.smtp.host" ) == null ) { props . put ( "mail.smtp.host" , "localhost" ) ; } _defaultSession = Session . getDefaultInstance ( props , null ) ; } }
Create our default session if not already created .
135,083
public Template getTemplate ( String path , String encoding ) throws Exception { Object siteId = get ( "__siteid__" ) ; if ( siteId != null ) { path = siteId + ":" + path ; } if ( encoding == null ) { return RuntimeSingleton . getRuntimeServices ( ) . getTemplate ( path ) ; } else { return RuntimeSingleton . getRuntime...
Fetches a Velocity template that can be used for later formatting . The template is read with the specified encoding or the default encoding if encoding is null .
135,084
public void putAllParameters ( ) { Enumeration < ? > e = _req . getParameterNames ( ) ; while ( e . hasMoreElements ( ) ) { String param = ( String ) e . nextElement ( ) ; put ( param , _req . getParameter ( param ) ) ; } }
Don t use this method . It is terribly unsafe and was written by a lazy engineer .
135,085
public String encodeAllParameters ( ) { StringBuilder buf = new StringBuilder ( ) ; Enumeration < ? > e = _req . getParameterNames ( ) ; while ( e . hasMoreElements ( ) ) { if ( buf . length ( ) > 0 ) { buf . append ( '&' ) ; } String param = ( String ) e . nextElement ( ) ; buf . append ( StringUtil . encode ( param )...
Encodes all the request params so they can be slapped onto a different URL which is useful when doing redirects .
135,086
public static DatabaseLiaison getLiaison ( String url ) { if ( url == null ) throw new NullPointerException ( "URL must not be null" ) ; DatabaseLiaison liaison = _mappings . get ( url ) ; if ( liaison == null ) { for ( DatabaseLiaison candidate : _liaisons ) { if ( candidate . matchesURL ( url ) ) { liaison = candidat...
Fetch the appropriate database liaison for the supplied URL which should be the same string that would be used to configure a connection to the database .
135,087
private XSSFCellStyle updateSubreportBandElementStyle ( XSSFCellStyle cellStyle , BandElement bandElement , Object value , int gridRow , int gridColumn , int colSpan ) { if ( subreportCellStyle == null ) { return cellStyle ; } if ( gridColumn == 0 ) { cellStyle . setBorderLeft ( subreportCellStyle . getBorderLeft ( ) )...
If a border style is set on a ReportBandElement we must apply it to all subreport cells
135,088
public V get ( K key ) { V value = null ; SoftReference < V > ref = _map . get ( key ) ; if ( ref != null ) { value = ref . get ( ) ; if ( value == null ) { _map . remove ( key ) ; } } return value ; }
Looks up and returns the value associated with the supplied key .
135,089
public V remove ( K key ) { SoftReference < V > ref = _map . remove ( key ) ; return ( ref == null ) ? null : ref . get ( ) ; }
Removes the specified key from the map . Returns the value to which the key was previously mapped or null .
135,090
public static SiteIdentifier single ( final int siteId , final String siteString ) { return new SiteIdentifier ( ) { public int identifySite ( HttpServletRequest req ) { return siteId ; } public String getSiteString ( int siteId ) { return siteString ; } public int getSiteId ( String siteString ) { return siteId ; } pu...
Returns a site identifier that returns the specified site always .
135,091
public static String generateRandomKey ( Random rand , int length ) { int numKeyChars = KEY_CHARS . length ( ) ; StringBuilder buf = new StringBuilder ( ) ; for ( int ii = 0 ; ii < length ; ii ++ ) { buf . append ( KEY_CHARS . charAt ( rand . nextInt ( numKeyChars ) ) ) ; } return buf . toString ( ) ; }
Return a key of the given length that contains random numbers .
135,092
public static boolean verifyLuhn ( String key ) { if ( StringUtil . isBlank ( key ) || key . matches ( ".*\\D.*" ) || key . matches ( "^[0]+$" ) ) { return false ; } return ( getLuhnRemainder ( key ) == 0 ) ; }
Verify the key with the Luhn check . If the key is all zeros then the luhn check is true but that is almost never what you want so explicitly check for zero and return false if it is .
135,093
public static int getLuhnRemainder ( String key ) { int len = key . length ( ) ; int sum = 0 ; for ( int multSeq = len % 2 , ii = 0 ; ii < len ; ii ++ ) { int c = key . charAt ( ii ) - '0' ; if ( ii % 2 == multSeq ) { c *= 2 ; } sum += ( c / 10 ) + ( c % 10 ) ; } return sum % 10 ; }
Return the luhn remainder for the given key .
135,094
public static void configureDefaultHandler ( Formatter formatter ) { Logger logger = LogManager . getLogManager ( ) . getLogger ( "" ) ; for ( Handler handler : logger . getHandlers ( ) ) { handler . setFormatter ( formatter ) ; } }
Configures the default logging handler to use an instance of the specified formatter when formatting messages .
135,095
public static void reverse ( byte [ ] values , int offset , int length ) { int aidx = offset ; int bidx = offset + length - 1 ; while ( bidx > aidx ) { byte value = values [ aidx ] ; values [ aidx ] = values [ bidx ] ; values [ bidx ] = value ; aidx ++ ; bidx -- ; } }
Reverses a subset of elements within the specified array .
135,096
public static void shuffle ( Object [ ] values , Random rnd ) { shuffle ( values , 0 , values . length , rnd ) ; }
Shuffles the elements in the given array into a random sequence .
135,097
public static byte [ ] insert ( byte [ ] values , byte value , int index ) { byte [ ] nvalues = new byte [ values . length + 1 ] ; if ( index > 0 ) { System . arraycopy ( values , 0 , nvalues , 0 , index ) ; } nvalues [ index ] = value ; if ( index < values . length ) { System . arraycopy ( values , index , nvalues , i...
Creates a new array one larger than the supplied array and with the specified value inserted into the specified slot .
135,098
public static < T extends Object > T [ ] insert ( T [ ] values , T value , int index ) { @ SuppressWarnings ( "unchecked" ) T [ ] nvalues = ( T [ ] ) Array . newInstance ( values . getClass ( ) . getComponentType ( ) , values . length + 1 ) ; if ( index > 0 ) { System . arraycopy ( values , 0 , nvalues , 0 , index ) ; ...
Creates a new array one larger than the supplied array and with the specified value inserted into the specified slot . The type of the values array will be preserved .
135,099
public static < T extends Object > T [ ] append ( T [ ] values , T value ) { return insert ( values , value , values . length ) ; }
Creates a new array one larger than the supplied array and with the specified value inserted into the last slot . The type of the values array will be preserved .