idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
8,100
public Object createInstanceQuietly ( ) { try { return clazz . newInstance ( ) ; } catch ( InstantiationException e ) { log . finest ( e ) ; return null ; } catch ( IllegalAccessException e ) { log . finest ( e ) ; return null ; } }
Constructs an instance of the wrapped class ignoring any errors .
8,101
public boolean overlaps ( Span other ) { return other != null && this . start ( ) < other . end ( ) && this . end ( ) > other . start ( ) ; }
Returns true if the bounds of other text are connected with the bounds of this text .
8,102
public boolean encloses ( Span other ) { return other != null && other . start ( ) >= this . start ( ) && other . end ( ) < this . end ( ) ; }
Returns true if the bounds of the other text do not extend outside the bounds of this text .
8,103
public Options collectFrom ( Class type ) { final Options opts = new Options ( ) ; collectOptions ( type , opts ) ; return opts ; }
Collects all Options for a given type . The collector traverses the type hierarchy and resolves Option groups .
8,104
static String [ ] decode ( String filename ) { int i = filename . indexOf ( "+" ) ; if ( i == - 1 ) return new String [ ] { decodePart ( filename ) , null , null } ; int j = filename . lastIndexOf ( "+" ) ; return new String [ ] { decodePart ( filename . substring ( 0 , i ) ) , decodePart ( filename . substring ( i + 1 , j ) ) , decodePart ( filename . substring ( j + 1 ) ) } ; }
reverses the encoding
8,105
public static double sum ( double [ ] vector ) { double total = 0.0 ; for ( int i = 0 ; i < vector . length ; i ++ ) { total += vector [ i ] ; } return total ; }
Returns the sum of the vector .
8,106
public static double sumOfAbsolutes ( double [ ] vector ) { double total = 0.0 ; for ( int i = 0 ; i < vector . length ; i ++ ) { total += Math . abs ( vector [ i ] ) ; } return total ; }
Returns the sum of the absolute values in the vector .
8,107
public static double median ( double [ ] vector ) { final double [ ] sorted = vector . clone ( ) ; Arrays . sort ( sorted ) ; if ( vector . length % 2 == 1 ) { return sorted [ vector . length / 2 ] ; } return ( sorted [ vector . length / 2 - 1 ] + sorted [ vector . length / 2 ] ) / 2 ; }
Returns the median of the vector .
8,108
public static double [ ] sequence ( double start , double end , int length ) { double [ ] retval = new double [ length ] ; double step = ( end - start ) / ( length == 1 ? 1 : length - 1 ) ; for ( int i = 0 ; i < length ; i ++ ) { retval [ i ] = start + ( i * step ) ; } return retval ; }
Generates a sequence of specified length from specified start to specified end .
8,109
public static int [ ] getOrder ( double [ ] values , boolean descending ) { return DMatrixUtils . getOrder ( values , IntStream . range ( 0 , values . length ) . toArray ( ) , descending ) ; }
Get the order of the elements in descending or ascending order .
8,110
public static int [ ] getOrder ( int [ ] values , int [ ] indices , boolean descending ) { Integer [ ] opIndices = ArrayUtils . toObject ( indices ) ; Arrays . sort ( opIndices , new Comparator < Integer > ( ) { public int compare ( Integer o1 , Integer o2 ) { if ( descending ) { return Double . compare ( values [ o2 ] , values [ o1 ] ) ; } else { return Double . compare ( values [ o1 ] , values [ o2 ] ) ; } } } ) ; return ArrayUtils . toPrimitive ( opIndices ) ; }
Get the order of the specified elements in descending or ascending order .
8,111
public static BigDecimal roundDownTo ( double value , double steps ) { final BigDecimal bValue = BigDecimal . valueOf ( value ) ; final BigDecimal bSteps = BigDecimal . valueOf ( steps ) ; if ( Objects . equals ( bSteps , BigDecimal . ZERO ) ) { return bValue ; } else { return bValue . divide ( bSteps , 0 , RoundingMode . FLOOR ) . multiply ( bSteps ) ; } }
Returns the DOWN rounded value of the given value for the given steps .
8,112
public static BigDecimal roundUpTo ( double value , double steps ) { final BigDecimal bValue = BigDecimal . valueOf ( value ) ; final BigDecimal bSteps = BigDecimal . valueOf ( steps ) ; if ( Objects . equals ( bSteps , BigDecimal . ZERO ) ) { return bValue ; } else { return bValue . divide ( bSteps , 0 , RoundingMode . CEILING ) . multiply ( bSteps ) ; } }
Returns the UP rounded value of the given value for the given steps .
8,113
public static BigDecimal roundToClosest ( double value , double steps ) { final BigDecimal down = DMatrixUtils . roundDownTo ( value , steps ) ; final BigDecimal up = DMatrixUtils . roundUpTo ( value , steps ) ; final BigDecimal orig = new BigDecimal ( String . valueOf ( value ) ) ; if ( orig . subtract ( down ) . abs ( ) . compareTo ( orig . subtract ( up ) . abs ( ) ) < 0 ) { return down ; } return up ; }
Returns the closest rounded value of the given value for the given steps .
8,114
public static double [ ] [ ] matrixFromRange ( double [ ] lower , double [ ] upper , int rows ) { final int cols = lower . length ; final double [ ] [ ] matrix = new double [ rows ] [ cols ] ; for ( int col = 0 ; col < cols ; col ++ ) { final double [ ] sequence = DMatrixUtils . sequence ( lower [ col ] , upper [ col ] , rows ) ; for ( int row = 0 ; row < sequence . length ; row ++ ) { matrix [ row ] [ col ] = sequence [ row ] ; } } return matrix ; }
Creates a matrix from the provided range for columns with the given number of rows .
8,115
public static double [ ] cumsum ( double [ ] vector ) { final double [ ] retval = new double [ vector . length ] ; retval [ 0 ] = vector [ 0 ] ; for ( int i = 1 ; i < retval . length ; i ++ ) { retval [ i ] = vector [ i ] + retval [ i - 1 ] ; } return retval ; }
Computes the cumulative sums of a given vector .
8,116
public static int [ ] shuffleIndices ( int length , RandomGenerator randomGenerator ) { final int [ ] indices = IntStream . range ( 0 , length ) . toArray ( ) ; MathArrays . shuffle ( indices , randomGenerator ) ; return indices ; }
Consumes the length of an array and returns its shuffled indices .
8,117
public static double [ ] applyIndices ( double [ ] vector , int [ ] indices ) { final double [ ] retval = new double [ indices . length ] ; for ( int i = 0 ; i < retval . length ; i ++ ) { retval [ i ] = vector [ indices [ i ] ] ; } return retval ; }
Consumes an array and desired respective indices in an array and return a new array with values from the desired indices .
8,118
public static double [ ] pairwiseMin ( double [ ] vector1 , double [ ] vector2 ) { final double [ ] retval = new double [ vector1 . length ] ; for ( int i = 0 ; i < retval . length ; i ++ ) { retval [ i ] = Math . min ( vector1 [ i ] , vector2 [ i ] ) ; } return retval ; }
Computes a vector as the min of respective pairs from two arrays .
8,119
public static double [ ] pairwiseMax ( double [ ] vector1 , double [ ] vector2 ) { final double [ ] retval = new double [ vector1 . length ] ; for ( int i = 0 ; i < retval . length ; i ++ ) { retval [ i ] = Math . max ( vector1 [ i ] , vector2 [ i ] ) ; } return retval ; }
Computes a vector as the max of respective pairs from two arrays .
8,120
public TableFactor observe ( int variable , final int value ) { return marginalize ( variable , 0 , ( marginalizedVariableValue , assignment ) -> { if ( marginalizedVariableValue == value ) { return ( old , n ) -> { assert ! Double . isNaN ( n ) ; return n ; } ; } else { return ( old , n ) -> { assert ! Double . isNaN ( old ) ; return old ; } ; } } ) ; }
Remove a variable by observing it at a certain value return a new factor without that variable .
8,121
public double [ ] [ ] getMaxedMarginals ( ) { double [ ] [ ] maxValues = new double [ neighborIndices . length ] [ ] ; for ( int i = 0 ; i < neighborIndices . length ; i ++ ) { maxValues [ i ] = new double [ getDimensions ( ) [ i ] ] ; for ( int j = 0 ; j < maxValues [ i ] . length ; j ++ ) maxValues [ i ] [ j ] = Double . NEGATIVE_INFINITY ; } Iterator < int [ ] > fastPassByReferenceIterator = fastPassByReferenceIterator ( ) ; int [ ] assignment = fastPassByReferenceIterator . next ( ) ; while ( true ) { double v = getAssignmentLogValue ( assignment ) ; for ( int i = 0 ; i < neighborIndices . length ; i ++ ) { if ( maxValues [ i ] [ assignment [ i ] ] < v ) maxValues [ i ] [ assignment [ i ] ] = v ; } if ( fastPassByReferenceIterator . hasNext ( ) ) { fastPassByReferenceIterator . next ( ) ; } else break ; } for ( int i = 0 ; i < neighborIndices . length ; i ++ ) { normalizeLogArr ( maxValues [ i ] ) ; } return maxValues ; }
Convenience function to max out all but one variable and return the marginal array .
8,122
public TableFactor maxOut ( int variable ) { return marginalize ( variable , Double . NEGATIVE_INFINITY , ( marginalizedVariableValue , assignment ) -> Math :: max ) ; }
Marginalize out a variable by taking the max value .
8,123
public int [ ] getBestAssignment ( ) { double maxValue = Double . NEGATIVE_INFINITY ; for ( int i = 0 ; i < values . length ; i ++ ) if ( values [ i ] > maxValue ) { maxValue = values [ i ] ; } Iterator < int [ ] > fastPassByReferenceIterator = fastPassByReferenceIterator ( ) ; do { int [ ] assignment = fastPassByReferenceIterator . next ( ) ; double v = getAssignmentLogValue ( assignment ) ; if ( v == maxValue ) return assignment ; } while ( fastPassByReferenceIterator . hasNext ( ) ) ; throw new IllegalStateException ( "This is unreachable." ) ; }
Returns the highest value assignment to this TableFactor
8,124
public double valueSum ( ) { double max = 0.0 ; for ( int [ ] assignment : this ) { double v = getAssignmentLogValue ( assignment ) ; if ( v > max ) { max = v ; } } double sumExp = 0.0 ; for ( int [ ] assignment : this ) { double assigmentLogValue = getAssignmentLogValue ( assignment ) ; assert ! Double . isNaN ( assigmentLogValue ) ; sumExp += Math . exp ( getAssignmentLogValue ( assignment ) - max ) ; } assert ! Double . isNaN ( sumExp ) ; assert ! Double . isNaN ( max ) ; return sumExp * Math . exp ( max ) ; }
This is useful for calculating the partition function and is exposed here because when implemented internally we can do a much more numerically stable summation .
8,125
private TableFactor marginalize ( int variable , double startingValue , BiFunction < Integer , int [ ] , BiFunction < Double , Double , Double > > curriedFoldr ) { assert ( getDimensions ( ) . length > 1 ) ; List < Integer > resultDomain = new ArrayList < > ( ) ; for ( int n : neighborIndices ) { if ( n != variable ) { resultDomain . add ( n ) ; } } int [ ] resultNeighborIndices = new int [ resultDomain . size ( ) ] ; int [ ] resultDimensions = new int [ resultNeighborIndices . length ] ; for ( int i = 0 ; i < resultDomain . size ( ) ; i ++ ) { int var = resultDomain . get ( i ) ; resultNeighborIndices [ i ] = var ; resultDimensions [ i ] = getVariableSize ( var ) ; } TableFactor result = new TableFactor ( resultNeighborIndices , resultDimensions ) ; int [ ] mapping = new int [ neighborIndices . length ] ; for ( int i = 0 ; i < neighborIndices . length ; i ++ ) { mapping [ i ] = resultDomain . indexOf ( neighborIndices [ i ] ) ; } for ( int [ ] assignment : result ) { result . setAssignmentLogValue ( assignment , startingValue ) ; } int [ ] resultAssignment = new int [ result . neighborIndices . length ] ; int marginalizedVariableValue = 0 ; Iterator < int [ ] > fastPassByReferenceIterator = fastPassByReferenceIterator ( ) ; int [ ] assignment = fastPassByReferenceIterator . next ( ) ; while ( true ) { for ( int i = 0 ; i < assignment . length ; i ++ ) { if ( mapping [ i ] != - 1 ) resultAssignment [ mapping [ i ] ] = assignment [ i ] ; else marginalizedVariableValue = assignment [ i ] ; } double value = curriedFoldr . apply ( marginalizedVariableValue , resultAssignment ) . apply ( result . getAssignmentLogValue ( resultAssignment ) , getAssignmentLogValue ( assignment ) ) ; assert ( ! Double . isNaN ( value ) ) ; result . setAssignmentLogValue ( resultAssignment , value ) ; if ( fastPassByReferenceIterator . hasNext ( ) ) fastPassByReferenceIterator . next ( ) ; else break ; } return result ; }
Marginalizes out a variable by applying an associative join operation for each possible assignment to the marginalized variable .
8,126
private int getVariableSize ( int variable ) { for ( int i = 0 ; i < neighborIndices . length ; i ++ ) { if ( neighborIndices [ i ] == variable ) return getDimensions ( ) [ i ] ; } return 0 ; }
Address a variable by index to get it s size . Basically just a convenience function .
8,127
private void normalizeLogArr ( double [ ] arr ) { double max = Double . NEGATIVE_INFINITY ; for ( double d : arr ) { if ( d > max ) max = d ; } double expSum = 0.0 ; for ( double d : arr ) { expSum += Math . exp ( d - max ) ; } double logSumExp = max + Math . log ( expSum ) ; if ( Double . isInfinite ( logSumExp ) ) { for ( int i = 0 ; i < arr . length ; i ++ ) { arr [ i ] = 1.0 / arr . length ; } } else { for ( int i = 0 ; i < arr . length ; i ++ ) { arr [ i ] = Math . exp ( arr [ i ] - logSumExp ) ; } } }
Super basic in - place array normalization
8,128
public synchronized int add ( final Message msg ) { final int nextKey = this . getNextPosition ( ) ; this . store . put ( nextKey , msg ) ; MessageStore . LOGGER . info ( "Message #{} stored on position #{}" , msg . getUniqueId ( ) , nextKey ) ; this . nextMessagePosition . incrementAndGet ( ) ; if ( this . store . size ( ) > this . messageLimit ) { this . store . remove ( this . store . firstKey ( ) ) ; } return nextKey ; }
Add message to the storage .
8,129
public Collection < Message > getAll ( ) { final int firstMessagePosition = this . getFirstPosition ( ) ; if ( firstMessagePosition < MessageStore . INITIAL_MESSAGE_POSITION ) { return Collections . unmodifiableList ( Collections . emptyList ( ) ) ; } return this . getFrom ( firstMessagePosition ) ; }
Return all messages currently present .
8,130
public synchronized List < Message > getFromRange ( final int startPosition , final int endPosition ) { final int firstMessageId = this . getFirstPosition ( ) ; if ( ( startPosition < MessageStore . INITIAL_MESSAGE_POSITION ) || ( endPosition < MessageStore . INITIAL_MESSAGE_POSITION ) ) { throw new IllegalArgumentException ( "Message position cannot be negative." ) ; } else if ( ( firstMessageId >= MessageStore . INITIAL_MESSAGE_POSITION ) && ( startPosition < firstMessageId ) ) { throw new IllegalArgumentException ( "Message at position " + startPosition + " had already been discarded. First available message position is " + firstMessageId + "." ) ; } else if ( endPosition <= startPosition ) { throw new IllegalArgumentException ( "Ending position must be larger than starting message position." ) ; } else if ( endPosition > this . getNextPosition ( ) ) { throw new IllegalArgumentException ( "Range end cannot be greater than the next message position." ) ; } return Collections . unmodifiableList ( new LinkedList < > ( this . store . subMap ( startPosition , endPosition ) . values ( ) ) ) ; }
Return all messages on positions in the given range .
8,131
public String fixPathInfo ( String path ) { if ( path == null ) return null ; if ( path . startsWith ( "/" ) ) path = path . substring ( 1 ) ; if ( baseURL == null ) if ( properties != null ) if ( this . getProperty ( BASE_PATH ) != null ) path = this . getProperty ( BASE_PATH ) + path ; return path ; }
Get the file path from the request .
8,132
public static String getPackagePath ( final Class < ? > clasz ) { checkNotNull ( "clasz" , clasz ) ; return clasz . getPackage ( ) . getName ( ) . replace ( '.' , '/' ) ; }
Returns the package path of a class .
8,133
public static URL getResource ( final Class < ? > clasz , final String name ) { checkNotNull ( "clasz" , clasz ) ; checkNotNull ( "name" , name ) ; final String nameAndPath = SLASH + getPackagePath ( clasz ) + SLASH + name ; return clasz . getResource ( nameAndPath ) ; }
Get the path to a resource located in the same package as a given class .
8,134
public static void addToClasspath ( final File file , final ClassLoader classLoader ) { checkNotNull ( "file" , file ) ; try { addToClasspath ( file . toURI ( ) . toURL ( ) , classLoader ) ; } catch ( final MalformedURLException e ) { throw new RuntimeException ( e ) ; } }
Adds a file to the classpath .
8,135
public static void addToClasspath ( final String url , final ClassLoader classLoader ) { checkNotNull ( "url" , url ) ; try { addToClasspath ( new URL ( url ) , classLoader ) ; } catch ( final MalformedURLException e ) { throw new RuntimeException ( e ) ; } }
Adds an URL to the classpath .
8,136
public static boolean containsURL ( final URL [ ] urls , final URL url ) { checkNotNull ( "urls" , urls ) ; checkNotNull ( "url" , url ) ; for ( int i = 0 ; i < urls . length ; i ++ ) { final URL element = urls [ i ] ; final String elementStr = element . toExternalForm ( ) ; final String urlStr = url . toExternalForm ( ) ; if ( elementStr . equals ( urlStr ) ) { return true ; } } return false ; }
Checks if the array or URLs contains the given URL .
8,137
public static String createHash ( final File file , final String algorithm ) { checkNotNull ( "file" , file ) ; checkNotNull ( "algorithm" , algorithm ) ; try { try ( final FileInputStream in = new FileInputStream ( file ) ) { return createHash ( in , algorithm ) ; } } catch ( final IOException ex ) { throw new RuntimeException ( ex ) ; } }
Creates a HEX encoded hash from a file .
8,138
public static String createHash ( final InputStream inputStream , final String algorithm ) { checkNotNull ( "inputStream" , inputStream ) ; checkNotNull ( "algorithm" , algorithm ) ; try { final MessageDigest messageDigest = MessageDigest . getInstance ( algorithm ) ; try ( final BufferedInputStream in = new BufferedInputStream ( inputStream ) ) { final byte [ ] buf = new byte [ 1024 ] ; int count = 0 ; while ( ( count = in . read ( buf ) ) > - 1 ) { messageDigest . update ( buf , 0 , count ) ; } } return encodeHex ( messageDigest . digest ( ) ) ; } catch ( final NoSuchAlgorithmException | IOException ex ) { throw new RuntimeException ( ex ) ; } }
Creates a HEX encoded hash from a stream .
8,139
private static Cipher createCipher ( final String algorithm , final int mode , final char [ ] password , final byte [ ] salt , final int count ) throws GeneralSecurityException { final SecretKeyFactory keyFactory = SecretKeyFactory . getInstance ( algorithm ) ; final PBEKeySpec keySpec = new PBEKeySpec ( password ) ; final SecretKey key = keyFactory . generateSecret ( keySpec ) ; final Cipher cipher = Cipher . getInstance ( algorithm ) ; final PBEParameterSpec params = new PBEParameterSpec ( salt , count ) ; cipher . init ( mode , key , params ) ; return cipher ; }
Creates a cipher for encryption or decryption .
8,140
public static byte [ ] encryptPasswordBased ( final String algorithm , final byte [ ] data , final char [ ] password , final byte [ ] salt , final int count ) { checkNotNull ( "algorithm" , algorithm ) ; checkNotNull ( "data" , data ) ; checkNotNull ( "password" , password ) ; checkNotNull ( "salt" , salt ) ; try { final Cipher cipher = createCipher ( algorithm , Cipher . ENCRYPT_MODE , password , salt , count ) ; return cipher . doFinal ( data ) ; } catch ( final Exception ex ) { throw new RuntimeException ( "Error encrypting the password!" , ex ) ; } }
Encrypts some data based on a password .
8,141
public static byte [ ] decryptPasswordBased ( final String algorithm , final byte [ ] encryptedData , final char [ ] password , final byte [ ] salt , final int count ) { checkNotNull ( "algorithm" , algorithm ) ; checkNotNull ( "encryptedData" , encryptedData ) ; checkNotNull ( "password" , password ) ; checkNotNull ( "salt" , salt ) ; try { final Cipher cipher = createCipher ( algorithm , Cipher . DECRYPT_MODE , password , salt , count ) ; return cipher . doFinal ( encryptedData ) ; } catch ( final Exception ex ) { throw new RuntimeException ( "Error decrypting the password!" , ex ) ; } }
Decrypts some data based on a password .
8,142
public static URL createUrl ( final URL baseUrl , final String path , final String filename ) { checkNotNull ( "baseUrl" , baseUrl ) ; checkNotNull ( "filename" , filename ) ; try { String baseUrlStr = baseUrl . toString ( ) ; if ( ! baseUrlStr . endsWith ( SLASH ) ) { baseUrlStr = baseUrlStr + SLASH ; } final String pathStr ; if ( ( path == null ) || ( path . length ( ) == 0 ) ) { pathStr = "" ; } else { if ( path . endsWith ( SLASH ) ) { pathStr = path ; } else { pathStr = path + SLASH ; } } return new URL ( baseUrlStr + pathStr + filename ) ; } catch ( final IOException ex ) { throw new RuntimeException ( ex ) ; } }
Creates an URL based on a directory a relative path and a filename .
8,143
public static boolean fileInsideDirectory ( final File dir , final File file ) { checkNotNull ( "dir" , dir ) ; checkNotNull ( "file" , file ) ; final String dirPath = getCanonicalPath ( dir ) ; final String filePath = getCanonicalPath ( file ) ; return filePath . startsWith ( dirPath ) ; }
Checks if a given file is inside the given directory .
8,144
public static void addToClasspath ( final URL url , final ClassLoader classLoader ) { checkNotNull ( "url" , url ) ; checkNotNull ( "classLoader" , classLoader ) ; if ( ! ( classLoader instanceof URLClassLoader ) ) { throw new IllegalArgumentException ( "Cannot add '" + url + "' to classloader because it's not an URL classloader" ) ; } final URLClassLoader urlClassLoader = ( URLClassLoader ) classLoader ; if ( ! containsURL ( urlClassLoader . getURLs ( ) , url ) ) { try { final Method addURL = URLClassLoader . class . getDeclaredMethod ( "addURL" , new Class [ ] { URL . class } ) ; addURL . setAccessible ( true ) ; addURL . invoke ( urlClassLoader , new Object [ ] { url } ) ; } catch ( final NoSuchMethodException e ) { throw new RuntimeException ( e ) ; } catch ( final IllegalArgumentException e ) { throw new RuntimeException ( e ) ; } catch ( final IllegalAccessException e ) { throw new RuntimeException ( e ) ; } catch ( final InvocationTargetException e ) { throw new RuntimeException ( e ) ; } } }
Adds an URL to the class path .
8,145
public static Object invoke ( final Object obj , final String methodName , final Class < ? > [ ] argTypes , final Object [ ] args ) throws InvokeMethodFailedException { checkNotNull ( "obj" , obj ) ; checkNotNull ( "methodName" , methodName ) ; final Class < ? > [ ] argTypesIntern ; final Object [ ] argsIntern ; if ( argTypes == null ) { argTypesIntern = new Class [ ] { } ; if ( args != null ) { throw new IllegalArgumentException ( "The argument 'argTypes' is null but " + "'args' containes values!" ) ; } argsIntern = new Object [ ] { } ; } else { argTypesIntern = argTypes ; if ( args == null ) { throw new IllegalArgumentException ( "The argument 'argTypes' contains classes " + "but 'args' is null!" ) ; } argsIntern = args ; } checkSameLength ( argTypesIntern , argsIntern ) ; String returnType = null ; try { final Method method = obj . getClass ( ) . getMethod ( methodName , argTypesIntern ) ; if ( method . getReturnType ( ) == null ) { returnType = "void" ; } else { returnType = method . getReturnType ( ) . getName ( ) ; } return method . invoke ( obj , argsIntern ) ; } catch ( final SecurityException ex ) { throw new InvokeMethodFailedException ( "Security problem with '" + getMethodSignature ( returnType , methodName , argTypesIntern ) + "'! [" + obj . getClass ( ) . getName ( ) + "]" , ex ) ; } catch ( final NoSuchMethodException ex ) { throw new InvokeMethodFailedException ( "Method '" + getMethodSignature ( returnType , methodName , argTypesIntern ) + "' not found! [" + obj . getClass ( ) . getName ( ) + "]" , ex ) ; } catch ( final IllegalArgumentException ex ) { throw new InvokeMethodFailedException ( "Argument problem with '" + getMethodSignature ( returnType , methodName , argTypesIntern ) + "'! [" + obj . getClass ( ) . getName ( ) + "]" , ex ) ; } catch ( final IllegalAccessException ex ) { throw new InvokeMethodFailedException ( "Access problem with '" + getMethodSignature ( returnType , methodName , argTypesIntern ) + "'! [" + obj . getClass ( ) . getName ( ) + "]" , ex ) ; } catch ( final InvocationTargetException ex ) { throw new InvokeMethodFailedException ( "Got an exception when calling '" + getMethodSignature ( returnType , methodName , argTypesIntern ) + "'! [" + obj . getClass ( ) . getName ( ) + "]" , ex ) ; } }
Calls a method with reflection and maps all errors into one exception .
8,146
public static String replaceVars ( final String str , final Map < String , String > vars ) { if ( ( str == null ) || ( str . length ( ) == 0 ) || ( vars == null ) || ( vars . size ( ) == 0 ) ) { return str ; } final StringBuilder sb = new StringBuilder ( ) ; int end = - 1 ; int from = 0 ; int start = - 1 ; while ( ( start = str . indexOf ( "${" , from ) ) > - 1 ) { sb . append ( str . substring ( end + 1 , start ) ) ; end = str . indexOf ( '}' , start + 1 ) ; if ( end == - 1 ) { sb . append ( str . substring ( start ) ) ; from = str . length ( ) ; } else { final String key = str . substring ( start + 2 , end ) ; final String value = ( String ) vars . get ( key ) ; if ( value == null ) { sb . append ( "${" ) ; sb . append ( key ) ; sb . append ( "}" ) ; } else { sb . append ( value ) ; } from = end + 1 ; } } sb . append ( str . substring ( from ) ) ; return sb . toString ( ) ; }
Replaces all variables inside a string with values from a map .
8,147
private static void zipFile ( final File srcFile , final String destPath , final ZipOutputStream out ) throws IOException { final byte [ ] buf = new byte [ 1024 ] ; try ( final InputStream in = new BufferedInputStream ( new FileInputStream ( srcFile ) ) ) { final ZipEntry zipEntry = new ZipEntry ( concatPathAndFilename ( destPath , srcFile . getName ( ) , File . separator ) ) ; zipEntry . setTime ( srcFile . lastModified ( ) ) ; out . putNextEntry ( zipEntry ) ; int len ; while ( ( len = in . read ( buf ) ) > 0 ) { out . write ( buf , 0 , len ) ; } out . closeEntry ( ) ; } }
Adds a file to a ZIP output stream .
8,148
private static File [ ] listFiles ( final File srcDir , final FileFilter filter ) { final File [ ] files ; if ( filter == null ) { files = srcDir . listFiles ( ) ; } else { files = srcDir . listFiles ( filter ) ; } return files ; }
List all files for a directory .
8,149
private static void zipDir ( final File srcDir , final FileFilter filter , final String destPath , final ZipOutputStream out ) throws IOException { final File [ ] files = listFiles ( srcDir , filter ) ; for ( int i = 0 ; i < files . length ; i ++ ) { if ( files [ i ] . isDirectory ( ) ) { zipDir ( files [ i ] , filter , concatPathAndFilename ( destPath , files [ i ] . getName ( ) , File . separator ) , out ) ; } else { zipFile ( files [ i ] , destPath , out ) ; } } }
Add a directory to a ZIP output stream .
8,150
public static void zipDir ( final File srcDir , final FileFilter filter , final String destPath , final File destFile ) throws IOException { Utils4J . checkNotNull ( "srcDir" , srcDir ) ; Utils4J . checkValidDir ( srcDir ) ; Utils4J . checkNotNull ( "destFile" , destFile ) ; try ( final ZipOutputStream out = new ZipOutputStream ( new BufferedOutputStream ( new FileOutputStream ( destFile ) ) ) ) { zipDir ( srcDir , filter , destPath , out ) ; } }
Creates a ZIP file and adds all files in a directory and all it s sub directories to the archive . Only entries are added that comply to the file filter .
8,151
public static void zipDir ( final File srcDir , final String destPath , final File destFile ) throws IOException { zipDir ( srcDir , null , destPath , destFile ) ; }
Creates a ZIP file and adds all files in a directory and all it s sub directories to the archive .
8,152
public static String readAsString ( final URL url , final String encoding , final int bufSize ) { try ( final Reader reader = new InputStreamReader ( url . openStream ( ) , encoding ) ) { final StringBuilder sb = new StringBuilder ( ) ; final char [ ] cbuf = new char [ bufSize ] ; int count ; while ( ( count = reader . read ( cbuf ) ) > - 1 ) { sb . append ( String . valueOf ( cbuf , 0 , count ) ) ; } return sb . toString ( ) ; } catch ( final IOException ex ) { throw new RuntimeException ( ex ) ; } }
Reads a given URL and returns the content as String .
8,153
public static String replaceCrLfTab ( final String str ) { if ( str == null ) { return null ; } final int len = str . length ( ) ; final StringBuilder sb = new StringBuilder ( ) ; int i = 0 ; while ( i < len ) { final char ch = str . charAt ( i ++ ) ; if ( ch == '\\' ) { if ( i < len ) { final char next = str . charAt ( i ) ; final Character replacement = SPECIAL_CHAR_REPLACEMENT_MAP . get ( next ) ; if ( replacement != null ) { sb . append ( replacement ) ; i ++ ; } else { sb . append ( ch ) ; } } else { sb . append ( ch ) ; } } else { sb . append ( ch ) ; } } return sb . toString ( ) ; }
Replaces the strings \ r \ n and \ t with carriage return new line and tab character .
8,154
public static boolean expectedCause ( final Exception actualException , final Collection < Class < ? extends Exception > > expectedExceptions ) { checkNotNull ( "actualException" , actualException ) ; if ( expectedExceptions == null || expectedExceptions . size ( ) == 0 ) { return true ; } final Throwable cause = actualException . getCause ( ) ; if ( ! ( cause instanceof Exception ) ) { return false ; } return expectedException ( ( Exception ) cause , expectedExceptions ) ; }
Verifies if the cause of an exception is of a given type .
8,155
public static boolean expectedException ( final Exception actualException , final Collection < Class < ? extends Exception > > expectedExceptions ) { checkNotNull ( "actualException" , actualException ) ; if ( expectedExceptions == null || expectedExceptions . size ( ) == 0 ) { return true ; } for ( final Class < ? extends Exception > expectedException : expectedExceptions ) { if ( expectedException . isAssignableFrom ( actualException . getClass ( ) ) ) { return true ; } } return false ; }
Verifies if an exception is of a given type .
8,156
public static boolean jreFile ( final File file ) { final String javaHome = System . getProperty ( "java.home" ) ; try { return file . getCanonicalPath ( ) . startsWith ( javaHome ) && file . isFile ( ) ; } catch ( final IOException ex ) { throw new RuntimeException ( "Error reading canonical path for: " + file , ex ) ; } }
Determines if the file is a file from the Java runtime and exists .
8,157
public static List < File > classpathFiles ( final Predicate < File > predicate ) { return pathsFiles ( System . getProperty ( "java.class.path" ) , predicate ) ; }
Returns a list of files from the classpath .
8,158
public static List < File > pathsFiles ( final String paths , final Predicate < File > predicate ) { final List < File > files = new ArrayList < File > ( ) ; for ( final String filePathAndName : paths . split ( File . pathSeparator ) ) { final File file = new File ( filePathAndName ) ; if ( file . isDirectory ( ) ) { try ( final Stream < Path > stream = Files . walk ( file . toPath ( ) , Integer . MAX_VALUE ) ) { stream . map ( f -> f . toFile ( ) ) . filter ( predicate ) . forEach ( files :: add ) ; } catch ( final IOException ex ) { throw new RuntimeException ( "Error walking path: " + file , ex ) ; } } else { if ( predicate . test ( file ) ) { files . add ( file ) ; } } } return files ; }
Returns a list of files from all given paths .
8,159
private static void inlineSvgNodes ( final Document doc , final String basePath ) { try { if ( doc == null ) return ; final String fixedBasePath = basePath == null ? "" : basePath ; final List < Node > nodes = XMLUtilities . getChildNodes ( doc . getDocumentElement ( ) , "object" ) ; for ( final Node node : nodes ) { final NamedNodeMap attributes = node . getAttributes ( ) ; final Node typeAttribute = attributes . getNamedItem ( "type" ) ; final Node dataAttribute = attributes . getNamedItem ( "data" ) ; if ( typeAttribute != null && typeAttribute . getTextContent ( ) . equals ( "image/svg+xml" ) && dataAttribute != null ) { final String data = dataAttribute . getTextContent ( ) ; final File dataFile = new File ( fixedBasePath + "/" + data ) ; if ( dataFile . exists ( ) ) { final String fileString = FileUtilities . readFileContents ( dataFile ) ; final Document svgDoc = XMLUtilities . convertStringToDocument ( fileString ) ; if ( svgDoc != null ) { final Element svgDocElement = svgDoc . getDocumentElement ( ) ; if ( svgDocElement != null && svgDocElement . getNodeName ( ) . equals ( "svg" ) ) { final Node parent = node . getParentNode ( ) ; if ( parent != null ) { final Node importedNode = doc . importNode ( svgDocElement , true ) ; parent . replaceChild ( importedNode , node ) ; } } } } } } } catch ( final Exception ex ) { LOG . error ( "Unable to convert external SVG image to DOM Document" , ex ) ; } }
Finds any reference to an external SVG image and replaces the node with the SVG inline data .
8,160
private static void inlineCssNodes ( final Document doc , final String basePath ) { if ( doc == null ) return ; final String fixedBasePath = basePath == null ? "" : basePath ; final List < Node > nodes = XMLUtilities . getChildNodes ( doc . getDocumentElement ( ) , "link" ) ; for ( final Node node : nodes ) { final NamedNodeMap attributes = node . getAttributes ( ) ; final Node relAttribute = attributes . getNamedItem ( "rel" ) ; final Node hrefAttribute = attributes . getNamedItem ( "href" ) ; final Node mediaAttribute = attributes . getNamedItem ( "media" ) ; if ( relAttribute != null && relAttribute . getTextContent ( ) . equals ( "stylesheet" ) && hrefAttribute != null ) { final String href = hrefAttribute . getTextContent ( ) ; final File hrefFile = new File ( fixedBasePath + "/" + href ) ; if ( hrefFile . exists ( ) ) { String cssBasePath = "" ; int end = href . lastIndexOf ( "/" ) ; if ( end == - 1 ) end = href . lastIndexOf ( "\\" ) ; if ( end != - 1 ) cssBasePath = href . substring ( 0 , end ) ; final String fileString = inlineCssImports ( FileUtilities . readFileContents ( hrefFile ) , basePath + "/" + cssBasePath ) ; final Node parent = node . getParentNode ( ) ; if ( parent != null ) { final Element newNode = doc . createElement ( "style" ) ; newNode . setAttribute ( "type" , "text/css" ) ; if ( mediaAttribute != null ) newNode . setAttribute ( "media" , mediaAttribute . getTextContent ( ) ) ; newNode . setTextContent ( fileString ) ; parent . replaceChild ( newNode , node ) ; } } } } }
Finds any reference to an external CSS scripts and replaces the node with inline CSS data .
8,161
private static String inlineCssImports ( final String css , final String basePath ) { String retValue = css ; int start ; while ( ( start = retValue . indexOf ( CSS_IMPORT_START ) ) != - 1 ) { int end = retValue . indexOf ( CSS_IMPORT_END , start ) ; if ( end != - 1 ) { final String filePath = retValue . substring ( start + CSS_IMPORT_START . length ( ) , end ) ; final String fileData = FileUtilities . readFileContents ( new File ( basePath + "/" + filePath ) ) ; retValue = retValue . replace ( CSS_IMPORT_START + filePath + CSS_IMPORT_END , fileData ) ; } } return retValue ; }
Finds any reference to an external CSS scripts that themselves have been referenced in a CSS script using an import statement and replaces the node with inline CSS data .
8,162
private static void inlineImgNodes ( final Document doc , final String basePath ) { if ( doc == null ) return ; final String fixedBasePath = basePath == null ? "" : basePath ; final List < Node > imageNodes = XMLUtilities . getChildNodes ( doc . getDocumentElement ( ) , "img" ) ; for ( final Node node : imageNodes ) { final NamedNodeMap attributes = node . getAttributes ( ) ; final Node srcAttribute = attributes . getNamedItem ( "src" ) ; if ( srcAttribute != null ) { final String src = srcAttribute . getTextContent ( ) ; final File srcFile = new File ( fixedBasePath + "/" + src ) ; if ( srcFile . exists ( ) ) { final byte [ ] srcFileByteArray = FileUtilities . readFileContentsAsByteArray ( srcFile ) ; if ( srcFileByteArray != null ) { final int extensionStringLocation = src . lastIndexOf ( "." ) ; if ( extensionStringLocation != - 1 && extensionStringLocation != src . length ( ) - 1 ) { final String extension = src . substring ( extensionStringLocation + 1 ) ; final byte [ ] srcFileEncodedByteArray = Base64 . encodeBase64 ( srcFileByteArray ) ; final String srcFileEncodedString = new String ( srcFileEncodedByteArray ) ; final Node parent = node . getParentNode ( ) ; if ( parent != null ) { final Element newImgNode = doc . createElement ( "img" ) ; newImgNode . setAttribute ( "src" , "data:image/" + extension + ";base64," + srcFileEncodedString ) ; parent . replaceChild ( newImgNode , node ) ; } } } } } } }
Finds any reference to an external images and replaces them with inline base64 data
8,163
public static int dfs ( int j , int k , int [ ] Pinv , int [ ] Llen , int Llen_offset , int [ ] Lip , int Lip_offset , int [ ] Stack , int [ ] Flag , int [ ] Lpend , int top , double [ ] LU , double [ ] Lik , int Lik_offset , int [ ] plength , int [ ] Ap_pos ) { int i , pos , jnew , head , l_length ; double [ ] Li ; l_length = plength [ 0 ] ; head = 0 ; Stack [ 0 ] = j ; ASSERT ( Flag [ j ] != k ) ; while ( head >= 0 ) { j = Stack [ head ] ; jnew = Pinv [ j ] ; ASSERT ( jnew >= 0 && jnew < k ) ; if ( Flag [ j ] != k ) { Flag [ j ] = k ; PRINTF ( "[ start dfs at %d : new %d\n" , j , jnew ) ; Ap_pos [ head ] = ( Lpend [ jnew ] == EMPTY ) ? Llen [ Llen_offset + jnew ] : Lpend [ jnew ] ; } Li = LU ; int Li_offset = Lip [ Lip_offset + jnew ] ; for ( pos = -- Ap_pos [ head ] ; pos >= 0 ; -- pos ) { i = ( int ) Li [ Li_offset + pos ] ; if ( Flag [ i ] != k ) { if ( Pinv [ i ] >= 0 ) { Ap_pos [ head ] = pos ; Stack [ ++ head ] = i ; break ; } else { Flag [ i ] = k ; Lik [ Lik_offset + l_length ] = i ; l_length ++ ; } } } if ( pos == - 1 ) { head -- ; Stack [ -- top ] = j ; PRINTF ( " end dfs at %d ] head : %d\n" , j , head ) ; } } plength [ 0 ] = l_length ; return ( top ) ; }
Does a depth - first - search starting at node j .
8,164
public static int lsolve_symbolic ( int n , int k , int [ ] Ap , int [ ] Ai , int [ ] Q , int [ ] Pinv , int [ ] Stack , int [ ] Flag , int [ ] Lpend , int [ ] Ap_pos , double [ ] LU , int lup , int [ ] Llen , int Llen_offset , int [ ] Lip , int Lip_offset , int k1 , int [ ] PSinv ) { double [ ] Lik ; int i , p , pend , oldcol , kglobal , top ; int [ ] l_length ; top = n ; l_length = new int [ ] { 0 } ; Lik = LU ; int Lik_offset = lup ; kglobal = k + k1 ; oldcol = Q [ kglobal ] ; pend = Ap [ oldcol + 1 ] ; for ( p = Ap [ oldcol ] ; p < pend ; p ++ ) { i = PSinv [ Ai [ p ] ] - k1 ; if ( i < 0 ) continue ; PRINTF ( "\n ===== DFS at node %d in b, inew: %d\n" , i , Pinv [ i ] ) ; if ( Flag [ i ] != k ) { if ( Pinv [ i ] >= 0 ) { top = dfs ( i , k , Pinv , Llen , Llen_offset , Lip , Lip_offset , Stack , Flag , Lpend , top , LU , Lik , Lik_offset , l_length , Ap_pos ) ; } else { Flag [ i ] = k ; Lik [ Lik_offset + l_length [ 0 ] ] = i ; l_length [ 0 ] ++ ; } } } Llen [ Llen_offset + k ] = l_length [ 0 ] ; return ( top ) ; }
Finds the pattern of x for the solution of Lx = b .
8,165
public static void construct_column ( int k , int [ ] Ap , int [ ] Ai , double [ ] Ax , int [ ] Q , double [ ] X , int k1 , int [ ] PSinv , double [ ] Rs , int scale , int [ ] Offp , int [ ] Offi , double [ ] Offx ) { double aik ; int i , p , pend , oldcol , kglobal , poff , oldrow ; kglobal = k + k1 ; poff = Offp [ kglobal ] ; oldcol = Q [ kglobal ] ; pend = Ap [ oldcol + 1 ] ; if ( scale <= 0 ) { for ( p = Ap [ oldcol ] ; p < pend ; p ++ ) { oldrow = Ai [ p ] ; i = PSinv [ oldrow ] - k1 ; aik = Ax [ p ] ; if ( i < 0 ) { Offi [ poff ] = oldrow ; Offx [ poff ] = aik ; poff ++ ; } else { X [ i ] = aik ; } } } else { for ( p = Ap [ oldcol ] ; p < pend ; p ++ ) { oldrow = Ai [ p ] ; i = PSinv [ oldrow ] - k1 ; aik = Ax [ p ] ; aik = SCALE_DIV ( aik , Rs [ oldrow ] ) ; if ( i < 0 ) { Offi [ poff ] = oldrow ; Offx [ poff ] = aik ; poff ++ ; } else { X [ i ] = aik ; } } } Offp [ kglobal + 1 ] = poff ; }
Construct the kth column of A and the off - diagonal part if requested . Scatter the numerical values into the workspace X and construct the corresponding column of the off - diagonal matrix .
8,166
public static String getFileExtension ( final String fileName ) { if ( fileName == null ) return null ; final int lastPeriodIndex = fileName . lastIndexOf ( "." ) ; if ( lastPeriodIndex != - 1 && lastPeriodIndex < fileName . length ( ) - 1 ) { final String extension = fileName . substring ( lastPeriodIndex + 1 ) ; return extension ; } return null ; }
Gets the extension for a file .
8,167
public static void openFile ( final File file ) throws IOException { if ( ! file . isFile ( ) ) throw new IOException ( "Passed file is not a file." ) ; if ( ! Desktop . isDesktopSupported ( ) ) { throw new IllegalStateException ( "Desktop is not supported" ) ; } final Desktop desktop = Desktop . getDesktop ( ) ; if ( ! desktop . isSupported ( Desktop . Action . OPEN ) ) { throw new IllegalStateException ( "Desktop doesn't support the open action" ) ; } desktop . open ( file ) ; }
Opens a file using the OS default program for the file type using the Java Desktop API .
8,168
public static void saveFile ( final File file , final String contents , final String encoding ) throws IOException { saveFile ( file , contents . getBytes ( encoding ) ) ; }
Save the data represented as a String to a file
8,169
public static void saveFile ( final File file , byte [ ] fileContents ) throws IOException { if ( file . isDirectory ( ) ) { throw new IOException ( "Unable to save file contents as a directory." ) ; } final FileOutputStream fos = new FileOutputStream ( file ) ; fos . write ( fileContents ) ; fos . flush ( ) ; fos . close ( ) ; }
Save the data represented as a byte array to a file
8,170
public static int klu_defaults ( KLU_common Common ) { if ( Common == null ) { return ( FALSE ) ; } Common . tol = 0.001 ; Common . memgrow = 1.2 ; Common . initmem_amd = 1.2 ; Common . initmem = 10 ; Common . btf = TRUE ; Common . maxwork = 0 ; Common . ordering = 0 ; Common . scale = 2 ; Common . halt_if_singular = TRUE ; Common . user_order = null ; Common . user_data = null ; Common . status = KLU_OK ; Common . nrealloc = 0 ; Common . structural_rank = EMPTY ; Common . numerical_rank = EMPTY ; Common . noffdiag = EMPTY ; Common . flops = EMPTY ; Common . rcond = EMPTY ; Common . condest = EMPTY ; Common . rgrowth = EMPTY ; Common . work = 0 ; Common . memusage = 0 ; Common . mempeak = 0 ; return ( TRUE ) ; }
Sets default parameters for KLU .
8,171
@ SuppressWarnings ( "unchecked" ) public final Parser < Object > getParser ( ) { if ( parser != null ) { return parser ; } LOG . info ( "Creating parser: {}" , className ) ; if ( className == null ) { throw new IllegalStateException ( "Class name was not set: " + getName ( ) ) ; } if ( context == null ) { throw new IllegalStateException ( "Context class loader was not set: " + getName ( ) + " / " + className ) ; } final Object obj = Utils4J . createInstance ( className , context . getClassLoader ( ) ) ; if ( ! ( obj instanceof Parser < ? > ) ) { throw new IllegalStateException ( "Expected class to be of type '" + Parser . class . getName ( ) + "', but was: " + className ) ; } parser = ( Parser < Object > ) obj ; parser . initialize ( context , this ) ; return parser ; }
Returns an existing parser instance or creates a new one if it s the first call to this method .
8,172
public final void addInterface ( final Class < ? > intf ) { if ( intf == null ) { throw new IllegalArgumentException ( "The argument 'intf' cannot be null!" ) ; } if ( ! intf . isInterface ( ) ) { throw new IllegalArgumentException ( "The argument 'intf' [" + intf . getName ( ) + "] is not an interface!" ) ; } interfaces . add ( intf ) ; }
Adds a new interface that has this method .
8,173
private boolean gavExists ( ) { return groupId != null && ! "" . equals ( groupId ) && artifactId != null && ! "" . equals ( artifactId ) && version != null && ! "" . equals ( version ) ; }
Determines if the GAV coordinates are specified .
8,174
private void installJar ( final File installableFile ) throws MojoExecutionException { try { Artifact artifact = new DefaultArtifact ( groupId , artifactId , version , null , "jar" , null , new DefaultArtifactHandler ( "jar" ) ) ; install ( installableFile , artifact , localRepository ) ; File artifactFile = new File ( localRepository . getBasedir ( ) , localRepository . pathOf ( artifact ) ) ; installAdditional ( artifactFile , ".sha1" , CeylonUtil . calculateChecksum ( artifactFile ) , false ) ; if ( model != null ) { String deps = calculateDependencies ( new MavenProject ( model ) ) ; if ( ! "" . equals ( deps ) ) { installAdditional ( artifactFile , "module.properties" , deps , false ) ; installAdditional ( artifactFile , ".module" , deps , true ) ; } } } catch ( Exception e ) { throw new MojoExecutionException ( e . getMessage ( ) , e ) ; } }
Does the actual installation of the jar file .
8,175
private void processModel ( final Model readModel ) { this . model = readModel ; Parent parent = readModel . getParent ( ) ; if ( this . groupId == null ) { this . groupId = readModel . getGroupId ( ) ; if ( this . groupId == null && parent != null ) { this . groupId = parent . getGroupId ( ) ; } } if ( this . artifactId == null ) { this . artifactId = readModel . getArtifactId ( ) ; } if ( this . version == null ) { this . version = readModel . getVersion ( ) ; if ( this . version == null && parent != null ) { this . version = parent . getVersion ( ) ; } } if ( this . packaging == null ) { this . packaging = readModel . getPackaging ( ) ; } }
Populates missing mojo parameters from the specified POM .
8,176
private Model readModel ( final InputStream pomStream ) throws MojoExecutionException { Reader reader = null ; try { reader = ReaderFactory . newXmlReader ( pomStream ) ; return new MavenXpp3Reader ( ) . read ( reader ) ; } catch ( FileNotFoundException e ) { throw new MojoExecutionException ( "File not found " + pomFile , e ) ; } catch ( IOException e ) { throw new MojoExecutionException ( "Error reading POM " + pomFile , e ) ; } catch ( XmlPullParserException e ) { throw new MojoExecutionException ( "Error parsing POM " + pomFile , e ) ; } finally { IOUtil . close ( reader ) ; } }
Parses a POM .
8,177
protected void initAttributes ( TypedArray attrArray ) { mCircleXRadius = attrArray . getDimension ( R . styleable . CircularSeekBar_circle_x_radius , DEFAULT_CIRCLE_X_RADIUS * DPTOPX_SCALE ) ; mCircleYRadius = attrArray . getDimension ( R . styleable . CircularSeekBar_circle_y_radius , DEFAULT_CIRCLE_Y_RADIUS * DPTOPX_SCALE ) ; mPointerRadius = attrArray . getDimension ( R . styleable . CircularSeekBar_pointer_radius , DEFAULT_POINTER_RADIUS * DPTOPX_SCALE ) ; mPointerHaloWidth = attrArray . getDimension ( R . styleable . CircularSeekBar_pointer_halo_width , DEFAULT_POINTER_HALO_WIDTH * DPTOPX_SCALE ) ; mPointerHaloBorderWidth = attrArray . getDimension ( R . styleable . CircularSeekBar_pointer_halo_border_width , DEFAULT_POINTER_HALO_BORDER_WIDTH * DPTOPX_SCALE ) ; mCircleStrokeWidth = attrArray . getDimension ( R . styleable . CircularSeekBar_circle_stroke_width , DEFAULT_CIRCLE_STROKE_WIDTH * DPTOPX_SCALE ) ; mPointerColor = attrArray . getColor ( R . styleable . CircularSeekBar_pointer_color , DEFAULT_POINTER_COLOR ) ; mPointerHaloColor = attrArray . getColor ( R . styleable . CircularSeekBar_pointer_halo_color , DEFAULT_POINTER_HALO_COLOR ) ; mPointerHaloColorOnTouch = attrArray . getColor ( R . styleable . CircularSeekBar_pointer_halo_color_ontouch , DEFAULT_POINTER_HALO_COLOR_ONTOUCH ) ; mCircleColor = attrArray . getColor ( R . styleable . CircularSeekBar_circle_color , DEFAULT_CIRCLE_COLOR ) ; mCircleProgressColor = attrArray . getColor ( R . styleable . CircularSeekBar_circle_progress_color , DEFAULT_CIRCLE_PROGRESS_COLOR ) ; mCircleFillColor = attrArray . getColor ( R . styleable . CircularSeekBar_circle_fill , DEFAULT_CIRCLE_FILL_COLOR ) ; mPointerAlpha = Color . alpha ( mPointerHaloColor ) ; mPointerAlphaOnTouch = attrArray . getInt ( R . styleable . CircularSeekBar_pointer_alpha_ontouch , DEFAULT_POINTER_ALPHA_ONTOUCH ) ; if ( mPointerAlphaOnTouch > 255 || mPointerAlphaOnTouch < 0 ) { mPointerAlphaOnTouch = DEFAULT_POINTER_ALPHA_ONTOUCH ; } mMax = attrArray . getInt ( R . styleable . CircularSeekBar_maxValue , DEFAULT_MAX ) ; mProgress = attrArray . getInt ( R . styleable . CircularSeekBar_progressValue , DEFAULT_PROGRESS ) ; mCustomRadii = attrArray . getBoolean ( R . styleable . CircularSeekBar_use_custom_radii , DEFAULT_USE_CUSTOM_RADII ) ; mMaintainEqualCircle = attrArray . getBoolean ( R . styleable . CircularSeekBar_maintain_equal_circle , DEFAULT_MAINTAIN_EQUAL_CIRCLE ) ; mMoveOutsideCircle = attrArray . getBoolean ( R . styleable . CircularSeekBar_move_outside_circle , DEFAULT_MOVE_OUTSIDE_CIRCLE ) ; lockEnabled = attrArray . getBoolean ( R . styleable . CircularSeekBar_lock_enabled , DEFAULT_LOCK_ENABLED ) ; mStartAngle = ( ( 360f + ( attrArray . getFloat ( ( R . styleable . CircularSeekBar_start_angle ) , DEFAULT_START_ANGLE ) % 360f ) ) % 360f ) ; mEndAngle = ( ( 360f + ( attrArray . getFloat ( ( R . styleable . CircularSeekBar_end_angle ) , DEFAULT_END_ANGLE ) % 360f ) ) % 360f ) ; if ( mStartAngle == mEndAngle ) { mEndAngle = mEndAngle - .1f ; } }
Initialize the CircularSeekBar with the attributes from the XML style . Uses the defaults defined at the top of this file when an attribute is not specified by the user .
8,178
public void setProgress ( int progress ) { if ( mProgress != progress ) { mProgress = progress ; if ( mOnCircularSeekBarChangeListener != null ) { mOnCircularSeekBarChangeListener . onProgressChanged ( this , progress , false ) ; } recalculateAll ( ) ; invalidate ( ) ; } }
Set the progress of the CircularSeekBar . If the progress is the same then any listener will not receive a onProgressChanged event .
8,179
public void setPointerAlpha ( int alpha ) { if ( alpha >= 0 && alpha <= 255 ) { mPointerAlpha = alpha ; mPointerHaloPaint . setAlpha ( mPointerAlpha ) ; invalidate ( ) ; } }
Sets the pointer alpha .
8,180
public void setMax ( int max ) { if ( ! ( max <= 0 ) ) { if ( max <= mProgress ) { mProgress = 0 ; if ( mOnCircularSeekBarChangeListener != null ) { mOnCircularSeekBarChangeListener . onProgressChanged ( this , mProgress , false ) ; } } mMax = max ; recalculateAll ( ) ; invalidate ( ) ; } }
Set the max of the CircularSeekBar . If the new max is less than the current progress then the progress will be set to zero . If the progress is changed as a result then any listener will receive a onProgressChanged event .
8,181
public List < Link > collectLinks ( String rel ) { return collectResources ( Link . class , HalResourceType . LINKS , rel ) ; }
recursively collects links within this resource and all embedded resources
8,182
public List < HalResource > collectEmbedded ( String rel ) { return collectResources ( HalResource . class , HalResourceType . EMBEDDED , rel ) ; }
recursively collects embedded resources of a specific rel
8,183
public HalResource setEmbedded ( String relation , HalResource resource ) { if ( resource == null ) { return this ; } return addResources ( HalResourceType . EMBEDDED , relation , false , new HalResource [ ] { resource } ) ; }
Embed resource for the given relation . Overwrites existing one .
8,184
public HalResource removeLink ( String relation , int index ) { return removeResource ( HalResourceType . LINKS , relation , index ) ; }
Removes one link for the given relation and index .
8,185
public HalResource removeLinkWithHref ( String relation , String href ) { List < Link > links = getLinks ( relation ) ; for ( int i = 0 ; i < links . size ( ) ; i ++ ) { if ( href . equals ( links . get ( i ) . getHref ( ) ) ) { return removeLink ( relation , i ) ; } } return this ; }
Remove the link with the given relation and href
8,186
public HalResource removeEmbedded ( String relation , int index ) { return removeResource ( HalResourceType . EMBEDDED , relation , index ) ; }
Removes one embedded resource for the given relation and index .
8,187
public HalResource renameEmbedded ( String relToRename , String newRel ) { List < HalResource > resources = getEmbedded ( relToRename ) ; return removeEmbedded ( relToRename ) . addEmbedded ( newRel , resources ) ; }
Changes the rel of embedded resources
8,188
public HalResource addState ( ObjectNode state ) { state . fields ( ) . forEachRemaining ( entry -> model . set ( entry . getKey ( ) , entry . getValue ( ) ) ) ; return this ; }
Adds state to the resource .
8,189
public static Service read ( Bundle bundle ) { String resourcePath = DOCS_CLASSPATH_PREFIX + "/" + SERVICE_DOC_FILE ; URL bundleResource = bundle . getResource ( resourcePath ) ; if ( bundleResource == null ) { return null ; } try ( InputStream is = bundleResource . openStream ( ) ) { return new ServiceJson ( ) . read ( is ) ; } catch ( Throwable ex ) { log . error ( "Unable to parse JSON file " + resourcePath + " from bundle " + bundle . getSymbolicName ( ) ) ; return null ; } }
Reads service model from bundle classpath .
8,190
public void setTabText ( int index , String text ) { TextView tv = ( TextView ) mTabTitleViews . get ( index ) ; if ( tv != null ) { tv . setText ( text ) ; } }
Set the text on the specified tab s TextView .
8,191
public final void addGenerator ( final GeneratorConfig generator ) { Contract . requireArgNotNull ( "generator" , generator ) ; if ( list == null ) { list = new ArrayList < > ( ) ; } list . add ( generator ) ; }
Adds a generator to the list . If the list does not exist it s created .
8,192
public final GeneratorConfig findByName ( final String generatorName ) throws GeneratorNotFoundException { Contract . requireArgNotEmpty ( "generatorName" , generatorName ) ; final int idx = list . indexOf ( new GeneratorConfig ( generatorName , "dummy" , "dummy" ) ) ; if ( idx < 0 ) { throw new GeneratorNotFoundException ( generatorName ) ; } return list . get ( idx ) ; }
Returns a generator by it s name .
8,193
public final SgClass get ( final String className ) { if ( className == null ) { throw new IllegalArgumentException ( "The argument 'className' cannot be null!" ) ; } return cache . get ( className ) ; }
Returns a class from the internal cache .
8,194
public final void put ( final SgClass clasz ) { if ( clasz == null ) { throw new IllegalArgumentException ( "The argument 'clasz' cannot be null!" ) ; } cache . put ( clasz . getName ( ) , clasz ) ; }
Adds a class to the internal cache .
8,195
public static OkHttpClient createOkHttpClient ( ) { OkHttpClient okHttpClient = new OkHttpClient ( ) ; okHttpClient . setConnectTimeout ( 15 * 1000 , TimeUnit . MILLISECONDS ) ; okHttpClient . setReadTimeout ( 20 * 1000 , TimeUnit . MILLISECONDS ) ; return okHttpClient ; }
Create an OkHttpClient with sensible timeouts for mobile connections .
8,196
public static DownloadProperties forGalaxyDist ( final File destination , String revision ) { return new DownloadProperties ( GALAXY_DIST_REPOSITORY_URL , BRANCH_STABLE , revision , destination ) ; }
Builds a new DownloadProperties for downloading Galaxy from galaxy - dist .
8,197
public static DownloadProperties forGalaxyCentral ( final File destination , String revision ) { return new DownloadProperties ( GALAXY_CENTRAL_REPOSITORY_URL , BRANCH_DEFAULT , revision , destination ) ; }
Builds a new DownloadProperties for downloading Galaxy from galaxy - central .
8,198
public static DownloadProperties forStableAtRevision ( final File destination , String revision ) { return new DownloadProperties ( GALAXY_CENTRAL_REPOSITORY_URL , BRANCH_STABLE , revision , destination ) ; }
Builds a new DownloadProperties for downloading Galaxy at the given revision .
8,199
public static DownloadProperties forRelease ( final String release , final File destination ) { return new DownloadProperties ( new WgetGithubDownloader ( release ) , destination ) ; }
Builds a new DownloadProperties for downloading a specific Galaxy release .