idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
14,900
public static ZipEntry getClassZipEntryFromZipInClassPath ( String className ) throws IOException { String fileName = StringSupport . replaceAll ( className , "." , "/" ) ; fileName += ".class" ; Collection < String > jars = StringSupport . split ( System . getProperty ( "java.class.path" ) , ";:" , false ) ; for ( String jarFileName : jars ) { if ( jarFileName . endsWith ( ".jar" ) || jarFileName . endsWith ( ".zip" ) ) { ZipEntry entry = getZipEntryFromZip ( fileName , jarFileName ) ; if ( entry != null ) { return entry ; } } } return null ; }
Tries to retrieve a class as ZipEntry from all jars mentioned in system property java . class . path
14,901
public static File createFile ( String filename ) throws IOException { File file = new File ( filename ) ; if ( ! file . exists ( ) ) { if ( file . getParent ( ) != null ) { File path = new File ( file . getParent ( ) ) ; path . mkdirs ( ) ; } file . createNewFile ( ) ; } return file ; }
Creates a file . The file and the directory structure is created physically if it does not exist already .
14,902
public static void deleteContentsInDirectoryTree ( File root , String includeMask ) { Collection < File > files = getContentsInDirectoryTree ( root , includeMask , true , true ) ; for ( File file : files ) { if ( file . exists ( ) ) { if ( file . isDirectory ( ) ) { emptyDirectory ( file . getAbsolutePath ( ) ) ; } file . delete ( ) ; } } }
Deletes from a directory all files and subdirectories targeted by a given mask . The method will recurse into subdirectories .
14,903
public static String convertToUnixStylePath ( String path ) { String retval = StringSupport . replaceAll ( path , "\\" , "/" ) ; retval = StringSupport . replaceAll ( retval , new String [ ] { "///" , "//" } , new String [ ] { "/" , "/" } ) ; return retval ; }
Converts backslashes into forward slashes .
14,904
protected Element loadDocument ( String ctx_str , String loc_str , EntityResolver resolver ) { try { final URL ctx = new URL ( ctx_str ) ; final URL doc = new URL ( ctx , loc_str ) ; final SAXReader rdr = new SAXReader ( ) ; if ( resolver != null ) { rdr . setEntityResolver ( resolver ) ; } final Element rslt = rdr . read ( doc ) . getRootElement ( ) ; rslt . normalize ( ) ; return rslt ; } catch ( Throwable t ) { String msg = "Unable to read the specified document:" + "\n\tCONTEXT=" + ctx_str + "\n\tLOCATION=" + loc_str ; throw new RuntimeException ( msg , t ) ; } }
Loads a DOM4J document from the specified contact and location and returns the root Element
14,905
public Object getBookmark ( int iHandleType ) { Map < String , Object > properties = this . getProperties ( ) ; Object bookmark = properties . get ( BOOKMARK ) ; if ( iHandleType == DBConstants . BOOKMARK_HANDLE ) return bookmark ; if ( iHandleType == DBConstants . FULL_OBJECT_HANDLE ) { String strDatabaseName = ( String ) properties . get ( DB_NAME ) ; String strTableName = ( String ) properties . get ( TABLE_NAME ) ; String strSource = m_strSourceType + BaseTable . HANDLE_SEPARATOR + strDatabaseName + BaseTable . HANDLE_SEPARATOR + strTableName ; strSource += BaseTable . HANDLE_SEPARATOR + bookmark . toString ( ) ; return strSource ; } return null ; }
Get the bookmark .
14,906
public boolean isRecordMatch ( Record record ) { Map < String , Object > properties = this . getProperties ( ) ; String strTableName = ( String ) properties . get ( TABLE_NAME ) ; if ( record != null ) if ( record . getTableNames ( false ) . equals ( strTableName ) ) return true ; return false ; }
Should this record get this message?
14,907
public boolean isMatchHint ( String strKeyArea , Object objKeyData ) { if ( m_mapHints != null ) if ( objKeyData . equals ( m_mapHints . get ( strKeyArea ) ) ) return true ; return false ; }
Does this key area hint match my hint?
14,908
public static Process runCommand ( List < String > toRun ) throws OSHelperException { Process proc ; ProcessBuilder procBuilder = new ProcessBuilder ( ) ; procBuilder . command ( toRun ) ; try { proc = procBuilder . start ( ) ; } catch ( IOException ex ) { throw new OSHelperException ( "Received an IOException when running command:\n" + toRun + "\n" + ex . getMessage ( ) , ex ) ; } return proc ; }
Runs a new OS process
14,909
public static int procWait ( Process process ) throws OSHelperException { try { return process . waitFor ( ) ; } catch ( InterruptedException ex ) { throw new OSHelperException ( "Received an InterruptedException when waiting for an external process to terminate." , ex ) ; } }
Waits for a specified process to terminate
14,910
public static byte [ ] readFile ( String fileName ) throws OSHelperException { File file = new File ( fileName ) ; if ( ! file . exists ( ) ) { throw new OSHelperException ( "File " + fileName + " does not exist" ) ; } if ( ! file . canRead ( ) ) { throw new OSHelperException ( "File " + fileName + " is not readable" ) ; } if ( ! file . isFile ( ) ) { throw new OSHelperException ( "File " + fileName + " is not a normal file" ) ; } RandomAccessFile raFile = null ; try { raFile = new RandomAccessFile ( fileName , "r" ) ; } catch ( FileNotFoundException ex ) { throw new OSHelperException ( "File " + fileName + " not found" ) ; } long fileLengthLong ; try { fileLengthLong = raFile . length ( ) ; } catch ( IOException ex ) { throw new OSHelperException ( ex ) ; } if ( fileLengthLong > Integer . MAX_VALUE ) { throw new OSHelperException ( "File length exceeds " + Integer . MAX_VALUE + " bytes: " + fileLengthLong ) ; } int fileLengthInt = ( int ) fileLengthLong ; byte [ ] bytes = new byte [ fileLengthInt ] ; try { raFile . read ( bytes ) ; } catch ( IOException ex ) { throw new OSHelperException ( ex ) ; } finally { try { raFile . close ( ) ; } catch ( IOException ex ) { throw new OSHelperException ( ex ) ; } } return bytes ; }
Read a file to a byte array
14,911
public static void writeFile ( byte [ ] bytes , String targetFileName ) throws OSHelperException { FileOutputStream fos ; try { fos = new FileOutputStream ( targetFileName ) ; } catch ( FileNotFoundException ex ) { throw new OSHelperException ( "Received a FileNotFoundException when trying to open target file " + targetFileName + "." , ex ) ; } try { fos . write ( bytes ) ; } catch ( IOException ex ) { throw new OSHelperException ( "Received an IOException when trying to write to target file " + targetFileName + "." , ex ) ; } finally { try { fos . close ( ) ; } catch ( IOException ex ) { throw new OSHelperException ( "Received an IOException when trying to close FileOutputStream for target file " + targetFileName + "." , ex ) ; } } }
Write a file
14,912
public static ProcessReturn sendEmail_Unix ( String target , String topic , String text ) throws OSHelperException { topic = topic . replaceAll ( "\"" , "\\\"" ) ; String emailCommandAsString = "mail -s \"" + topic + "\" -S sendcharsets=utf-8 " + target ; List < String > emailCommandAsList = OSHelper . constructCommandAsList_Unix_sh ( emailCommandAsString ) ; Process process = OSHelper . runCommand ( emailCommandAsList ) ; OutputStream processStdin = process . getOutputStream ( ) ; try { processStdin . write ( text . getBytes ( ) ) ; } catch ( IOException ex ) { throw new OSHelperException ( ex ) ; } try { processStdin . close ( ) ; } catch ( IOException ex ) { throw new OSHelperException ( ex ) ; } ProcessReturn processReturn = OSHelper . procWaitWithProcessReturn ( process , 10000 ) ; return processReturn ; }
Send a simple email
14,913
public static List < String > constructCommandAsList_Unix_sh ( String command ) { List < String > commandAsList = new ArrayList < String > ( ) ; commandAsList . add ( "sh" ) ; commandAsList . add ( "-c" ) ; commandAsList . add ( command ) ; return commandAsList ; }
Helper method to construct a UNIX - like - OS - compatible command that is using the SH shell syntax .
14,914
public static List < String > constructCommandAsList_Windows_cmd ( String command ) { List < String > commandAsList = new ArrayList < String > ( ) ; commandAsList . add ( "cmd" ) ; commandAsList . add ( "/c" ) ; commandAsList . add ( command ) ; return commandAsList ; }
Helper method to construct a Windows - compatible command that is using the CMD shell syntax .
14,915
public void appendField ( final String key , final String value ) { if ( builder . length ( ) > 0 ) { builder . append ( "&" ) ; } try { builder . append ( key ) . append ( "=" ) . append ( URLEncoder . encode ( value , "UTF-8" ) ) ; } catch ( UnsupportedEncodingException e ) { throw new AssertionError ( "UTF-8 encoding should always be available." ) ; } }
Append a field to the form .
14,916
public static < E > void shuffle ( E [ ] array ) { int swapPlace = - 1 ; for ( int i = 0 ; i < array . length ; i ++ ) { swapPlace = ( int ) ( Math . random ( ) * ( array . length - 1 ) ) ; TrivialSwap . swap ( array , i , swapPlace ) ; } }
Randomly shuffle the elements in an array
14,917
public static < E > void shuffle ( List < E > list ) { int swapPlace = - 1 ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { swapPlace = ( int ) ( Math . random ( ) * ( list . size ( ) - 1 ) ) ; TrivialSwap . swap ( list , i , swapPlace ) ; } }
Randomly shuffle the elements in a list
14,918
public static void shuffle ( int [ ] intArray ) { int swapPlace = - 1 ; for ( int i = 0 ; i < intArray . length ; i ++ ) { swapPlace = ( int ) ( Math . random ( ) * ( intArray . length - 1 ) ) ; XORSwap . swap ( intArray , i , swapPlace ) ; } }
Randomly shuffle an int array
14,919
public static void shuffle ( float [ ] floatArray ) { int swapPlace = - 1 ; for ( int i = 0 ; i < floatArray . length ; i ++ ) { swapPlace = ( int ) ( Math . random ( ) * ( floatArray . length - 1 ) ) ; TrivialSwap . swap ( floatArray , i , swapPlace ) ; } }
Randomly shuffle an float array
14,920
public static void shuffle ( byte [ ] byteArray ) { int swapPlace = - 1 ; for ( int i = 0 ; i < byteArray . length ; i ++ ) { swapPlace = ( int ) ( Math . random ( ) * ( byteArray . length - 1 ) ) ; XORSwap . swap ( byteArray , i , swapPlace ) ; } }
Randomly shuffle an byte array
14,921
public static void shuffle ( short [ ] shortArray ) { int swapPlace = - 1 ; for ( int i = 0 ; i < shortArray . length ; i ++ ) { swapPlace = ( int ) ( Math . random ( ) * ( shortArray . length - 1 ) ) ; XORSwap . swap ( shortArray , i , swapPlace ) ; } }
Randomly shuffle an short array
14,922
public static void shuffle ( long [ ] longArray ) { int swapPlace = - 1 ; for ( int i = 0 ; i < longArray . length ; i ++ ) { swapPlace = ( int ) ( Math . random ( ) * ( longArray . length - 1 ) ) ; XORSwap . swap ( longArray , i , swapPlace ) ; } }
Randomly shuffle an long array
14,923
public static void shuffle ( double [ ] doubleArray ) { int swapPlace = - 1 ; for ( int i = 0 ; i < doubleArray . length ; i ++ ) { swapPlace = ( int ) ( Math . random ( ) * ( doubleArray . length - 1 ) ) ; TrivialSwap . swap ( doubleArray , i , swapPlace ) ; } }
Randomly shuffle a double array
14,924
public static void shuffle ( char [ ] charArray ) { int swapPlace = - 1 ; for ( int i = 0 ; i < charArray . length ; i ++ ) { swapPlace = ( int ) ( Math . random ( ) * ( charArray . length - 1 ) ) ; XORSwap . swap ( charArray , i , swapPlace ) ; } }
Randomly shuffle a char array
14,925
public void destroy ( ) { log . debug ( "Close Hibernate session factory and releases caches and database connections." ) ; SessionFactory sessionFactory = getSessionFactory ( ) ; if ( sessionFactory != null ) { sessionFactory . close ( ) ; } }
Destroy Hibernate session factory and releases database resources .
14,926
public void addObserver ( PropertySetter observer , String ... properties ) { try { semaphore . acquire ( ) ; } catch ( InterruptedException ex ) { throw new IllegalArgumentException ( ex ) ; } try { addObserver ( observer ) ; for ( String p : properties ) { observers . addObserver ( p , observer ) ; } } finally { semaphore . release ( ) ; } }
Adds a PropertySetter observer for properties .
14,927
public int fieldChanged ( boolean bDisplayOption , int iMoveMode ) { if ( m_gridScreen != null ) m_gridScreen . reSelectRecords ( ) ; if ( m_sPopupBox != null ) m_sPopupBox . reSelectRecords ( ) ; return DBConstants . NORMAL_RETURN ; }
The Field has Changed . Reselect the grid screen .
14,928
public Point eval ( double t , AbstractPoint p ) { if ( t < 0 || t > 1 ) { throw new IllegalArgumentException ( "t=" + t + " not in [0,1]" ) ; } p . set ( 0 , 0 ) ; double c0 = Math . pow ( 1 - t , 3 ) ; double c1 = 3 * Math . pow ( 1 - t , 2 ) * t ; double c2 = 3 * ( 1 - t ) * t * t ; double c3 = t * t * t ; p . add ( c0 * P [ start ] . getX ( ) , c0 * P [ start ] . getY ( ) ) ; p . add ( c1 * P [ start + 1 ] . getX ( ) , c1 * P [ start + 1 ] . getY ( ) ) ; p . add ( c2 * P [ start + 2 ] . getX ( ) , c2 * P [ start + 2 ] . getY ( ) ) ; p . add ( c3 * P [ start + 3 ] . getX ( ) , c3 * P [ start + 3 ] . getY ( ) ) ; return p ; }
Evaluates point in Bezier Curve . Returned Point is the same as given in parameter p .
14,929
public void curveStart ( ) { double d0 = AbstractPoint . angle ( P [ start ] , P [ start + 3 ] ) ; double d1 = AbstractPoint . angle ( P [ start + 3 ] , P [ start ] ) ; double d2 = AbstractPoint . angle ( P [ start + 3 ] , P [ start + 2 ] ) ; double a1 = d1 - d2 ; double a2 = d0 + a1 ; double di = AbstractPoint . distance ( P [ start + 3 ] , P [ start + 2 ] ) ; P [ start + 1 ] = AbstractPoint . move ( P [ start ] , a2 , di ) ; }
Experimental! makes the start curve like the end
14,930
public static PluginLoader withPluginDirectory ( Path pluginsDirectory ) throws PluginException { if ( pluginsDirectory == null ) { throw new PluginException ( "Plugins directory can't be null" ) ; } return new PluginLoader ( pluginsDirectory ) ; }
Define the directory to search for plugins
14,931
public PluginLoader withExtensionPoints ( Class ... extensionPoints ) { this . extensionPoints . addAll ( Stream . of ( extensionPoints ) . distinct ( ) . collect ( Collectors . < Class > toList ( ) ) ) ; return this ; }
Define extension points to be considered by this loader
14,932
public String pending ( boolean silent ) { if ( modified && ! warned ) { if ( silent || ! PromptDialog . confirm ( TX_PROMPT ) ) { return "Vital entry in progress." ; } } return null ; }
Called when a patient context change has been requested .
14,933
public String getString ( ) { String string = super . getString ( ) ; int iIndent = ( int ) m_convIndent . getValue ( ) ; string = gstrSpaces . substring ( 0 , iIndent * m_iIndentAmount ) + string ; return string ; }
GetString Method .
14,934
public static < T > Consumer < T > writeValue ( final Position . Writable < ? super T > pos ) { return pos :: setValue ; }
Get a UnaryProcedure callback for writing a position value .
14,935
public static void empty ( String parameter , String name ) { if ( parameter == null || ! parameter . isEmpty ( ) ) { throw new IllegalArgumentException ( name + " is null or not empty." ) ; } }
Test if string parameter is strictly empty that is not null but empty .
14,936
public static void notEmpty ( String parameter , String name ) throws IllegalArgumentException { if ( parameter != null && parameter . isEmpty ( ) ) { throw new IllegalArgumentException ( name + " is empty." ) ; } }
Test if string parameter is strict not empty . If parameter to test is null this test method does not rise exception .
14,937
public static void notNullOrEmpty ( String parameter , String name ) throws IllegalArgumentException { if ( parameter == null || parameter . isEmpty ( ) ) { throw new IllegalArgumentException ( name + " is null or empty." ) ; } }
Test if string parameter is not null or empty .
14,938
public static void notNullOrEmpty ( File parameter , String name ) throws IllegalArgumentException { if ( parameter == null || parameter . getPath ( ) . isEmpty ( ) ) { throw new IllegalArgumentException ( name + " path is null or empty." ) ; } }
Test if file parameter is not null and has not empty path .
14,939
public static void notNullOrEmpty ( Object [ ] parameter , String name ) throws IllegalArgumentException { if ( parameter == null || parameter . length == 0 ) { throw new IllegalArgumentException ( name + " parameter is empty." ) ; } }
Test if array parameter is not null or empty .
14,940
public static void size ( Collection < ? > parameter , int size , String name ) throws IllegalArgumentException { if ( parameter . size ( ) != size ) { throw new IllegalArgumentException ( String . format ( "%s size is not %d." , name , size ) ) ; } }
Test if given collection size has a specified value .
14,941
public static void size ( Map < ? , ? > parameter , int size , String name ) throws IllegalArgumentException { if ( parameter . size ( ) != size ) { throw new IllegalArgumentException ( String . format ( "%s size is not %d." , name , size ) ) ; } }
Test if given map size has a specified value .
14,942
public static void isFile ( File parameter , String name ) throws IllegalArgumentException { if ( parameter == null || ! parameter . exists ( ) || parameter . isDirectory ( ) ) { throw new IllegalArgumentException ( String . format ( "%s |%s| is missing or is a directory." , name , parameter . getAbsolutePath ( ) ) ) ; } }
Check if file parameter is an existing ordinary file not a directory . This validator throws illegal argument if given file does not exist or is not an ordinary file .
14,943
public static void range ( double parameter , double lowEndpoint , double highEndpoint , String name ) throws IllegalArgumentException { if ( lowEndpoint > parameter || parameter > highEndpoint ) { throw new IllegalArgumentException ( String . format ( "%s parameter is not in range [%d, %d]." , name , lowEndpoint , highEndpoint ) ) ; } }
Test if numeric parameter is in a given range . Parameter is considered in range if is greater or equal with lower endpoint and smaller or equal higher endpoint .
14,944
public static void EQ ( long parameter , long expected , String name ) throws IllegalArgumentException { if ( parameter != expected ) { throw new IllegalArgumentException ( String . format ( "%s is not %d." , name , expected ) ) ; } }
Test if numeric parameter has expected value .
14,945
public static void GT ( long parameter , long value , String name ) throws IllegalArgumentException { if ( parameter <= value ) { throw new IllegalArgumentException ( String . format ( "%s is not greater than %d." , name , value ) ) ; } }
Test if numeric parameter is strictly greater than given threshold value .
14,946
public static void GT ( char parameter , char expected , String name ) throws IllegalArgumentException { if ( parameter <= expected ) { throw new IllegalArgumentException ( String . format ( "%s is not greater than %c." , name , expected ) ) ; } }
Test if character parameter is strictly greater than given character value .
14,947
public static void GTE ( long parameter , long value , String name ) throws IllegalArgumentException { if ( parameter < value ) { throw new IllegalArgumentException ( String . format ( "%s is not greater than or equal %d." , name , value ) ) ; } }
Test if numeric parameter is greater than or equal to given threshold value .
14,948
public static void LT ( char parameter , char value , String name ) throws IllegalArgumentException { if ( parameter >= value ) { throw new IllegalArgumentException ( String . format ( "%s is not less than %c." , name , value ) ) ; } }
Test if character parameter is strictly less than given character value .
14,949
public static void LTE ( long parameter , long value , String name ) throws IllegalArgumentException { if ( parameter > value ) { throw new IllegalArgumentException ( String . format ( "%s is not less than or equal %d." , name , value ) ) ; } }
Test if numeric parameter is less than or equal to given threshold value .
14,950
public static void isKindOf ( Type parameter , Type typeToMatch , String name ) { if ( ! Types . isKindOf ( parameter , typeToMatch ) ) { throw new IllegalArgumentException ( Strings . format ( "%s is not %s." , name , typeToMatch ) ) ; } }
Test if parameter is of requested type and throw exception if not .
14,951
public void assign ( RPCParameters source ) { clear ( ) ; for ( RPCParameter param : source . params ) { params . add ( new RPCParameter ( param ) ) ; } }
Copies parameters from another list to this one .
14,952
public void put ( int index , RPCParameter param ) { expand ( index ) ; if ( index < params . size ( ) ) { params . set ( index , param ) ; } else { params . add ( param ) ; } }
Adds a parameter at the specified index .
14,953
public boolean inMap ( String name , Location location ) { MapArea map = maps . get ( name ) ; if ( map == null ) { throw new IllegalArgumentException ( name ) ; } return map . isInside ( location ) ; }
Returns true if location is inside named map .
14,954
public boolean inAnyMap ( Location location ) { return maps . values ( ) . stream ( ) . anyMatch ( ( org . vesalainen . ham . MapArea m ) -> m . isInside ( location ) ) ; }
Location is inside one of the maps .
14,955
public static int getFirstNonWhitespace ( String strText ) { if ( strText != null ) { for ( int i = 0 ; i < strText . length ( ) ; i ++ ) { if ( ! Character . isWhitespace ( strText . charAt ( i ) ) ) return i ; } } return - 1 ; }
Get the position of the first non - whitespace char .
14,956
public static byte [ ] sha3 ( byte [ ] input , int start , int length ) { Keccak256 digest = new Keccak256 ( ) ; digest . update ( input , start , length ) ; return digest . digest ( ) ; }
hashing chunk of the data
14,957
public static byte [ ] calcNewAddr ( byte [ ] addr , byte [ ] nonce ) { byte [ ] encSender = RLP . encodeElement ( addr ) ; byte [ ] encNonce = RLP . encodeBigInteger ( new BigInteger ( 1 , nonce ) ) ; return sha3omit12 ( RLP . encodeList ( encSender , encNonce ) ) ; }
The way to calculate new address
14,958
public static byte [ ] doubleDigest ( byte [ ] input , int offset , int length ) { synchronized ( sha256digest ) { sha256digest . reset ( ) ; sha256digest . update ( input , offset , length ) ; byte [ ] first = sha256digest . digest ( ) ; return sha256digest . digest ( first ) ; } }
Calculates the SHA - 256 hash of the given byte range and then hashes the resulting hash again . This is standard procedure in Bitcoin . The resulting hash is in big endian form .
14,959
public String getHtmlKeywords ( ) { Record recMenu = this . getMainRecord ( ) ; if ( recMenu . getField ( MenusModel . KEYWORDS ) . getLength ( ) > 0 ) return recMenu . getField ( MenusModel . KEYWORDS ) . toString ( ) ; else return super . getHtmlKeywords ( ) ; }
Get the Html keywords .
14,960
public String getHtmlMenudesc ( ) { Record recMenu = this . getMainRecord ( ) ; if ( recMenu . getField ( MenusModel . COMMENT ) . getLength ( ) > 0 ) return recMenu . getField ( MenusModel . COMMENT ) . toString ( ) ; else return super . getHtmlMenudesc ( ) ; }
Get the Html Description .
14,961
protected String [ ] fetchCommandParams ( CommandInterpreter interpreter ) { List < String > result = new ArrayList < String > ( ) ; String param ; while ( ( param = interpreter . nextArgument ( ) ) != null ) { result . add ( param ) ; } return result . toArray ( new String [ result . size ( ) ] ) ; }
Fetch command line arguments from source
14,962
public TimeSpan getTimeSpan ( Distance distance ) { return new TimeSpan ( ( long ) ( 1000 * distance . getMeters ( ) / value ) , TimeUnit . MILLISECONDS ) ; }
Returns the time span taken to move the distance
14,963
public Date getThere ( Date start , Distance distance ) { TimeSpan timeSpan = getTimeSpan ( distance ) ; return timeSpan . addDate ( start ) ; }
Returns the time we are there if we started at start
14,964
public static final Point mul ( double k , Point p ) { return new AbstractPoint ( k * p . getX ( ) , k * p . getY ( ) ) ; }
multiply p s x and y with k .
14,965
public static final Point add ( Point ... points ) { AbstractPoint res = new AbstractPoint ( ) ; for ( Point pp : points ) { res . x += pp . getX ( ) ; res . y += pp . getY ( ) ; } return res ; }
Sums points x values to x values and y values to y values
14,966
public static final double distance ( Point p1 , Point p2 ) { return Math . hypot ( p1 . getX ( ) - p2 . getX ( ) , p1 . getY ( ) - p2 . getY ( ) ) ; }
Calculates the distance between points
14,967
public static final Point move ( Point p , double radians , double distance ) { return new AbstractPoint ( p . getX ( ) + distance * Math . cos ( radians ) , p . getY ( ) + distance * Math . sin ( radians ) ) ; }
Creates a new Point distance from p to radians direction
14,968
public static final double [ ] toArray ( Point ... points ) { double [ ] res = new double [ 2 * points . length ] ; int idx = 0 ; for ( Point pp : points ) { res [ idx ++ ] = pp . getX ( ) ; res [ idx ++ ] = pp . getY ( ) ; } return res ; }
Creates an array for points p1 p2 ...
14,969
public static final Point [ ] midPoints ( int count , Point p1 , Point p2 ) { Point [ ] res = new Point [ count ] ; Point gap = AbstractPoint . subtract ( p2 , p1 ) ; Point leg = AbstractPoint . mul ( ( double ) ( 1 ) / ( double ) ( count + 1 ) , gap ) ; for ( int ii = 0 ; ii < count ; ii ++ ) { res [ ii ] = AbstractPoint . add ( p1 , AbstractPoint . mul ( ii + 1 , leg ) ) ; } return res ; }
Creates evenly spaced midpoints in a line between p1 and p2 Example if count = 1 it creates point in the midle of p1 and p2
14,970
public static final int searchX ( Point [ ] points , Point key ) { return Arrays . binarySearch ( points , key , xcomp ) ; }
Searches given key in array in x - order
14,971
public void initConstants ( ) { if ( NUMBERS != null ) return ; if ( ( ( BaseField ) this . getField ( ) ) . getRecord ( ) . getRecordOwner ( ) != null ) { org . jbundle . model . Task task = ( ( BaseField ) this . getField ( ) ) . getRecord ( ) . getRecordOwner ( ) . getTask ( ) ; ResourceBundle resources = ( ( BaseApplication ) task . getApplication ( ) ) . getResources ( ResourceConstants . AMOUNT_RESOURCE , true ) ; NUMBERS = new String [ 10 ] ; for ( int i = 0 ; i < 10 ; i ++ ) { NUMBERS [ i ] = resources . getString ( Integer . toString ( i ) ) ; } TEENS = new String [ 10 ] ; for ( int i = 10 ; i < 20 ; i ++ ) { TEENS [ i - 10 ] = resources . getString ( Integer . toString ( i ) ) ; } TENS = new String [ 10 ] ; for ( int i = 2 ; i < 10 ; i ++ ) { TENS [ i ] = resources . getString ( Integer . toString ( i * 10 ) ) ; } HUNDRED = resources . getString ( "100" ) ; THOUSAND = resources . getString ( "1000" ) ; MILLION = resources . getString ( "1000000" ) ; BILLION = resources . getString ( "1000000000" ) ; AND = resources . getString ( "&" ) ; } else { NUMBERS [ 0 ] = "Zero" ; NUMBERS [ 1 ] = "One" ; NUMBERS [ 2 ] = "Two" ; NUMBERS [ 3 ] = "Three" ; NUMBERS [ 4 ] = "Four" ; NUMBERS [ 5 ] = "Five" ; NUMBERS [ 6 ] = "Six" ; NUMBERS [ 7 ] = "Seven" ; NUMBERS [ 8 ] = "Eight" ; NUMBERS [ 9 ] = "Nine" ; TEENS [ 0 ] = "ten" ; TEENS [ 1 ] = "Eleven" ; TEENS [ 2 ] = "Twelve" ; TEENS [ 3 ] = "Thirteen" ; TEENS [ 4 ] = "Fourteen" ; TEENS [ 5 ] = "Fifteen" ; TEENS [ 6 ] = "Sixteen" ; TEENS [ 7 ] = "Seventeen" ; TEENS [ 8 ] = "Eighteen" ; TEENS [ 9 ] = "Nineteen" ; TENS [ 0 ] = Constants . BLANK ; TENS [ 1 ] = Constants . BLANK ; TENS [ 2 ] = "Twenty" ; TENS [ 3 ] = "Thirty" ; TENS [ 4 ] = "Forty" ; TENS [ 5 ] = "Fifty" ; TENS [ 6 ] = "Sixty" ; TENS [ 7 ] = "Seventy" ; TENS [ 8 ] = "Eighty" ; TENS [ 9 ] = "Ninety" ; HUNDRED = "Hundred" ; THOUSAND = "Thousand" ; MILLION = "Million" ; BILLION = "Billion" ; AND = "and" ; } }
Init the number constants .
14,972
public static String toBase58 ( byte [ ] b ) { if ( b . length == 0 ) { return "" ; } int lz = 0 ; while ( lz < b . length && b [ lz ] == 0 ) { ++ lz ; } StringBuilder s = new StringBuilder ( ) ; BigInteger n = new BigInteger ( 1 , b ) ; while ( n . compareTo ( BigInteger . ZERO ) > 0 ) { BigInteger [ ] r = n . divideAndRemainder ( BigInteger . valueOf ( 58 ) ) ; n = r [ 0 ] ; char digit = b58 [ r [ 1 ] . intValue ( ) ] ; s . append ( digit ) ; } while ( lz > 0 ) { -- lz ; s . append ( "1" ) ; } return s . reverse ( ) . toString ( ) ; }
convert a byte array to a human readable base58 string . Base58 is a Bitcoin specific encoding similar to widely used base64 but avoids using characters of similar shape such as 1 and l or O an 0
14,973
public static String toBase58WithChecksum ( byte [ ] b ) { byte [ ] cs = Hash . hash ( b ) ; byte [ ] extended = new byte [ b . length + 4 ] ; System . arraycopy ( b , 0 , extended , 0 , b . length ) ; System . arraycopy ( cs , 0 , extended , b . length , 4 ) ; return toBase58 ( extended ) ; }
Encode in base58 with an added checksum of four bytes .
14,974
public static byte [ ] reverse ( byte [ ] data ) { for ( int i = 0 , j = data . length - 1 ; i < data . length / 2 ; i ++ , j -- ) { data [ i ] ^= data [ j ] ; data [ j ] ^= data [ i ] ; data [ i ] ^= data [ j ] ; } return data ; }
reverse a byte array in place WARNING the parameter array is altered and returned .
14,975
public static byte [ ] fromHex ( String hex ) { try { return Hex . decodeHex ( hex . toCharArray ( ) ) ; } catch ( DecoderException e ) { return null ; } }
recreate a byte array from hexadecimal
14,976
public void open ( ) throws DBException { if ( m_pDatabase == null ) { PhysicalDatabaseParent pDBParent = null ; Environment env = ( Environment ) this . getDatabaseOwner ( ) . getEnvironment ( ) ; if ( env != null ) pDBParent = ( PhysicalDatabaseParent ) env . getPDatabaseParent ( mapDBParentProperties , true ) ; String databaseName = this . getDatabaseName ( true ) ; if ( databaseName . endsWith ( BaseDatabase . SHARED_SUFFIX ) ) databaseName = databaseName . substring ( 0 , databaseName . length ( ) - BaseDatabase . SHARED_SUFFIX . length ( ) ) ; else if ( databaseName . endsWith ( BaseDatabase . USER_SUFFIX ) ) databaseName = databaseName . substring ( 0 , databaseName . length ( ) - BaseDatabase . USER_SUFFIX . length ( ) ) ; char strPDatabaseType = this . getPDatabaseType ( ) ; m_pDatabase = pDBParent . getPDatabase ( databaseName , strPDatabaseType , false ) ; if ( m_pDatabase == null ) m_pDatabase = this . makePDatabase ( pDBParent , databaseName ) ; m_pDatabase . addPDatabaseOwner ( this ) ; } m_pDatabase . open ( ) ; super . open ( ) ; }
Open the database . If this is the first time a raw data database is created .
14,977
public int addPTableOwner ( ThinPhysicalTableOwner pTableOwner ) { if ( pTableOwner != null ) { m_lTimeLastUsed = System . currentTimeMillis ( ) ; m_setPTableOwners . add ( pTableOwner ) ; pTableOwner . setPTable ( this ) ; } return m_setPTableOwners . size ( ) ; }
Bump the use count . This doesn t have to be synchronized because getPTable in PDatabase is .
14,978
public synchronized int removePTableOwner ( ThinPhysicalTableOwner pTableOwner , boolean bFreeIfEmpty ) { if ( pTableOwner != null ) { m_setPTableOwners . remove ( pTableOwner ) ; pTableOwner . setPTable ( null ) ; } if ( m_setPTableOwners . size ( ) == 0 ) if ( bFreeIfEmpty ) { this . free ( ) ; return 0 ; } m_lTimeLastUsed = System . currentTimeMillis ( ) ; return m_setPTableOwners . size ( ) ; }
Free this table if it is no longer being used .
14,979
public synchronized void remove ( FieldTable table ) throws DBException { BaseBuffer bufferOld = ( BaseBuffer ) table . getDataSource ( ) ; for ( int iKeyArea = Constants . MAIN_KEY_AREA ; iKeyArea < table . getRecord ( ) . getKeyAreaCount ( ) + Constants . MAIN_KEY_AREA ; iKeyArea ++ ) { KeyAreaInfo keyArea = table . getRecord ( ) . getKeyArea ( iKeyArea ) ; keyArea . reverseKeyBuffer ( null , Constants . TEMP_KEY_AREA ) ; this . getPKeyArea ( iKeyArea ) . doRemove ( table , table . getRecord ( ) . getKeyArea ( iKeyArea ) , bufferOld ) ; } bufferOld . free ( ) ; table . setDataSource ( null ) ; }
Delete this record .
14,980
public synchronized BaseBuffer move ( int iRelPosition , FieldTable table ) throws DBException { int iKeyOrder = table . getRecord ( ) . getDefaultOrder ( ) ; if ( iKeyOrder == - 1 ) iKeyOrder = Constants . MAIN_KEY_AREA ; KeyAreaInfo keyArea = table . getRecord ( ) . getKeyArea ( iKeyOrder ) ; PKeyArea vKeyArea = this . getPKeyArea ( iKeyOrder ) ; BaseBuffer buffer = ( BaseBuffer ) table . getDataSource ( ) ; if ( ( iRelPosition != Constants . FIRST_RECORD ) && ( iRelPosition != Constants . LAST_RECORD ) ) if ( ! vKeyArea . atCurrent ( buffer ) ) { keyArea . reverseKeyBuffer ( null , Constants . TEMP_KEY_AREA ) ; if ( keyArea . getUniqueKeyCode ( ) != Constants . UNIQUE ) table . getRecord ( ) . getKeyArea ( Constants . MAIN_KEY_AREA ) . reverseKeyBuffer ( null , Constants . TEMP_KEY_AREA ) ; buffer = vKeyArea . doSeek ( "==" , table , keyArea ) ; } buffer = vKeyArea . doMove ( iRelPosition , table , keyArea ) ; this . saveCurrentKeys ( table , buffer , ( buffer == null ) ) ; return buffer ; }
Move the position of the record . See PKeyArea for the logic behind this method .
14,981
public void initKeyAreas ( FieldTable table ) throws DBException { if ( m_VKeyList == null ) { m_VKeyList = new Vector < PKeyArea > ( ) ; for ( int iKeyArea = Constants . MAIN_KEY_AREA ; iKeyArea <= table . getRecord ( ) . getKeyAreaCount ( ) + Constants . MAIN_KEY_AREA - 1 ; iKeyArea ++ ) { this . makePKeyArea ( table ) ; } } }
Set up the raw data key areas .
14,982
public void moveupFieldData ( FieldData fieldInfo ) { BaseField field ; String thisFieldStr ; int count = fieldInfo . getFieldCount ( ) + DBConstants . MAIN_FIELD ; for ( int i = DBConstants . MAIN_FIELD ; i < count ; i ++ ) { field = fieldInfo . getField ( i ) ; if ( field . getString ( ) . length ( ) == 0 ) { thisFieldStr = m_FieldData . getField ( i ) . getString ( ) ; if ( thisFieldStr . length ( ) != 0 ) field . setString ( thisFieldStr ) ; } } }
Move FieldData2 fields to empty FieldData fields .
14,983
public void start ( ) { Thread thread = new Thread ( new Runnable ( ) { public void run ( ) { try { onPreExecute ( ) ; Value value = execute ( ) ; onPostExecute ( value ) ; } catch ( Throwable throwable ) { onThrowable ( throwable ) ; } } } ) ; thread . start ( ) ; }
Start asynchronous task execution .
14,984
public static boolean after ( final Date point , final Date when ) { final Calendar pointCalendar = Calendar . getInstance ( ) ; pointCalendar . setTime ( point ) ; final Calendar whenCalendar = Calendar . getInstance ( ) ; whenCalendar . setTime ( when ) ; return pointCalendar . after ( whenCalendar ) ; }
Returns true if the given from Date is after the given when Date otherwise false .
14,985
public static int computeAge ( final Date birthday , final Date computeDate ) { final Age age = new Age ( birthday , computeDate ) ; return ( int ) age . calculateInYears ( ) ; }
Computes the Age from the birthday till the computeDate object .
14,986
public static Date computeEasternSunday ( final int year ) { final int easternSundayNumber = computeEasternSundayNumber ( year ) ; final int month = easternSundayNumber / 31 ; final int day = easternSundayNumber % 31 + 1 ; return CreateDateExtensions . newDate ( year , month - 1 , day ) ; }
Computes the eastern sunday for the given year . Year should be greater than 1583 .
14,987
public static int computeEasternSundayNumber ( final int year ) { final int i = year % 19 ; final int j = year / 100 ; final int k = year % 100 ; final int l = ( 19 * i + j - j / 4 - ( j - ( j + 8 ) / 25 + 1 ) / 3 + 15 ) % 30 ; final int m = ( 32 + 2 * ( j % 4 ) + 2 * ( k / 4 ) - l - k % 4 ) % 7 ; return ( l + m - 7 * ( ( i + 11 * l + 22 * m ) / 451 ) + 114 ) ; }
Computes the number from eastern sunday for the given year . Year should be greater the 1583 .
14,988
public static boolean isBetween ( final Date start , final Date end , final Date between ) { final long min = start . getTime ( ) ; final long max = end . getTime ( ) ; final long index = between . getTime ( ) ; return min <= index && index <= max ; }
Checks if the Date object between is between from the given to Date objects .
14,989
public static boolean isDateInThePast ( final Date date ) { boolean inPast = false ; final Calendar compare = Calendar . getInstance ( ) ; compare . setTime ( date ) ; final Calendar now = Calendar . getInstance ( ) ; now . setTime ( new Date ( System . currentTimeMillis ( ) ) ) ; inPast = now . after ( compare ) ; return inPast ; }
Checks if the given date object is in the past .
14,990
public static boolean isValidDate ( final String date , final String format , final boolean lenient ) { boolean isValid = true ; if ( date == null || format == null || format . length ( ) <= 0 ) { return false ; } try { final DateFormat df = new SimpleDateFormat ( format ) ; df . setLenient ( lenient ) ; df . parse ( date ) ; } catch ( final ParseException | IllegalArgumentException e ) { isValid = false ; } return isValid ; }
Checks if the Date is valid to convert .
14,991
public static Date substractDaysFromDate ( final Date date , final int substractDays ) { final Calendar dateOnCalendar = Calendar . getInstance ( ) ; dateOnCalendar . setTime ( date ) ; dateOnCalendar . add ( Calendar . DATE , substractDays * - 1 ) ; return dateOnCalendar . getTime ( ) ; }
Substract days to the given Date object and returns it .
14,992
public static Date substractMonthsFromDate ( final Date date , final int substractMonths ) { final Calendar dateOnCalendar = Calendar . getInstance ( ) ; dateOnCalendar . setTime ( date ) ; dateOnCalendar . add ( Calendar . MONTH , substractMonths * - 1 ) ; return dateOnCalendar . getTime ( ) ; }
Substract months to the given Date object and returns it .
14,993
public static Date substractYearsFromDate ( final Date date , final int substractYears ) { final Calendar dateOnCalendar = Calendar . getInstance ( ) ; dateOnCalendar . setTime ( date ) ; dateOnCalendar . add ( Calendar . YEAR , substractYears * - 1 ) ; return dateOnCalendar . getTime ( ) ; }
Substract years to the given Date object and returns it .
14,994
public static String appendSystemtimeToFilename ( final File fileToRename , final Date add2Name ) { final String format = "HHmmssSSS" ; String sysTime = null ; if ( null != add2Name ) { final DateFormat df = new SimpleDateFormat ( format ) ; sysTime = df . format ( add2Name ) ; } else { final DateFormat df = new SimpleDateFormat ( format ) ; sysTime = df . format ( new Date ( ) ) ; } final String fileName = fileToRename . getName ( ) ; final int ext_index = fileName . lastIndexOf ( "." ) ; final String ext = fileName . substring ( ext_index , fileName . length ( ) ) ; String newName = fileName . substring ( 0 , ext_index ) ; newName += "_" + sysTime + ext ; return newName ; }
Returns the filename from the given file with the systemtime .
14,995
public static List < File > changeAllFilenameSuffix ( final File file , final String oldSuffix , final String newSuffix ) throws IOException , FileDoesNotExistException , FileIsADirectoryException { return changeAllFilenameSuffix ( file , oldSuffix , newSuffix , false ) ; }
Changes all the Filenames with the new Suffix recursively .
14,996
public static List < File > changeAllFilenameSuffix ( final File file , final String oldSuffix , final String newSuffix , final boolean delete ) throws IOException , FileDoesNotExistException , FileIsADirectoryException { boolean success ; List < File > notDeletedFiles = null ; final String filePath = file . getAbsolutePath ( ) ; final String suffix [ ] = { oldSuffix } ; final List < File > files = FileSearchExtensions . findFiles ( filePath , suffix ) ; final int fileCount = files . size ( ) ; for ( int i = 0 ; i < fileCount ; i ++ ) { final File currentFile = files . get ( i ) ; success = RenameFileExtensions . changeFilenameSuffix ( currentFile , newSuffix , delete ) ; if ( ! success ) { if ( null != notDeletedFiles ) { notDeletedFiles . add ( currentFile ) ; } else { notDeletedFiles = new ArrayList < > ( ) ; notDeletedFiles . add ( currentFile ) ; } } } return notDeletedFiles ; }
Changes all the Filenames with the new Suffix recursively . If delete is true its deletes the existing file with the same name .
14,997
public static boolean forceToMoveFile ( final File srcFile , final File destinationFile ) throws IOException , FileIsADirectoryException { boolean moved = RenameFileExtensions . renameFile ( srcFile , destinationFile , true ) ; return moved ; }
Moves the given source file to the given destination file .
14,998
public static boolean moveFile ( final File srcFile , final File destDir ) throws IOException , FileIsADirectoryException { return RenameFileExtensions . renameFile ( srcFile , destDir , true ) ; }
Moves the given source file to the destination Directory .
14,999
public static File renameFileWithSystemtime ( final File fileToRename ) throws IOException , FileIsADirectoryException { final String newFilenameWithSystemtime = appendSystemtimeToFilename ( fileToRename ) ; final File fileWithNewName = new File ( fileToRename . getParent ( ) , newFilenameWithSystemtime ) ; renameFile ( fileToRename , fileWithNewName , true ) ; return fileWithNewName ; }
Renames the given file and add to the filename the systemtime .