idx int64 0 165k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
17,500 | void mapIn ( String in , Object comp , String comp_in ) { if ( comp == ca . getComponent ( ) ) { throw new ComponentException ( "cannot connect 'In' with itself for " + in ) ; } ComponentAccess ac_dest = lookup ( comp ) ; FieldAccess destAccess = ( FieldAccess ) ac_dest . input ( comp_in ) ; checkFA ( destAccess , comp , comp_in ) ; FieldAccess srcAccess = ( FieldAccess ) ca . input ( in ) ; checkFA ( srcAccess , ca . getComponent ( ) , in ) ; FieldContent data = srcAccess . getData ( ) ; data . tagLeaf ( ) ; data . tagIn ( ) ; destAccess . setData ( data ) ; dataSet . add ( data ) ; if ( log . isLoggable ( Level . CONFIG ) ) { log . config ( String . format ( "@In(%s) -> @In(%s)" , srcAccess , destAccess ) ) ; } } | Map two input fields . |
17,501 | void mapInVal ( Object val , Object to , String to_in ) { if ( val == null ) { throw new ComponentException ( "Null value for " + name ( to , to_in ) ) ; } if ( to == ca . getComponent ( ) ) { throw new ComponentException ( "field and component ar ethe same for mapping :" + to_in ) ; } ComponentAccess ca_to = lookup ( to ) ; Access to_access = ca_to . input ( to_in ) ; checkFA ( to_access , to , to_in ) ; ca_to . setInput ( to_in , new FieldValueAccess ( to_access , val ) ) ; if ( log . isLoggable ( Level . CONFIG ) ) { log . config ( String . format ( "Value(%s) -> @In(%s)" , val . toString ( ) , to_access . toString ( ) ) ) ; } } | Directly map a value to a input field . |
17,502 | void mapInField ( Object from , String from_field , Object to , String to_in ) { if ( to == ca . getComponent ( ) ) { throw new ComponentException ( "wrong connect:" + from_field ) ; } ComponentAccess ca_to = lookup ( to ) ; Access to_access = ca_to . input ( to_in ) ; checkFA ( to_access , to , to_in ) ; try { FieldContent . FA f = new FieldContent . FA ( from , from_field ) ; ca_to . setInput ( to_in , new FieldObjectAccess ( to_access , f , ens ) ) ; if ( log . isLoggable ( Level . CONFIG ) ) { log . config ( String . format ( "Field(%s) -> @In(%s)" , f . toString ( ) , to_access . toString ( ) ) ) ; } } catch ( Exception E ) { throw new ComponentException ( "No such field '" + from . getClass ( ) . getCanonicalName ( ) + "." + from_field + "'" ) ; } } | Map an input field . |
17,503 | void mapOutField ( Object from , String from_out , Object to , String to_field ) { if ( from == ca . getComponent ( ) ) { throw new ComponentException ( "wrong connect:" + to_field ) ; } ComponentAccess ca_from = lookup ( from ) ; Access from_access = ca_from . output ( from_out ) ; checkFA ( from_access , from , from_out ) ; try { FieldContent . FA f = new FieldContent . FA ( to , to_field ) ; ca_from . setOutput ( from_out , new FieldObjectAccess ( from_access , f , ens ) ) ; if ( log . isLoggable ( Level . CONFIG ) ) { log . config ( String . format ( "@Out(%s) -> field(%s)" , from_access , f . toString ( ) ) ) ; } } catch ( Exception E ) { throw new ComponentException ( "No such field '" + to . getClass ( ) . getCanonicalName ( ) + "." + to_field + "'" ) ; } } | Map a object to an output field . |
17,504 | void connect ( Object from , String from_out , Object to , String to_in ) { if ( from == to ) { throw new ComponentException ( "src == dest." ) ; } if ( to_in == null || from_out == null ) { throw new ComponentException ( "Some field arguments are null" ) ; } ComponentAccess ca_from = lookup ( from ) ; ComponentAccess ca_to = lookup ( to ) ; Access from_access = ca_from . output ( from_out ) ; checkFA ( from_access , from , from_out ) ; Access to_access = ca_to . input ( to_in ) ; checkFA ( to_access , to , to_in ) ; if ( ! canConnect ( from_access , to_access ) ) { throw new ComponentException ( "Type/Access mismatch, Cannot connect: " + from + '.' + to_in + " -> " + to + '.' + from_out ) ; } FieldContent data = from_access . getData ( ) ; data . tagIn ( ) ; data . tagOut ( ) ; dataSet . add ( data ) ; to_access . setData ( data ) ; if ( checkCircular ) { validator . addConnection ( from , to ) ; validator . checkCircular ( ) ; } if ( log . isLoggable ( Level . CONFIG ) ) { log . config ( String . format ( "@Out(%s) -> @In(%s)" , from_access . toString ( ) , to_access . toString ( ) ) ) ; } } | Connect out to in |
17,505 | void feedback ( Object from , String from_out , Object to , String to_in ) { if ( from == to ) { throw new ComponentException ( "src == dest." ) ; } if ( to_in == null || from_out == null ) { throw new ComponentException ( "Some field arguments are null" ) ; } ComponentAccess ca_from = lookup ( from ) ; ComponentAccess ca_to = lookup ( to ) ; Access from_access = ca_from . output ( from_out ) ; checkFA ( from_access , from , from_out ) ; Access to_access = ca_to . input ( to_in ) ; checkFA ( to_access , to , to_in ) ; if ( ! canConnect ( from_access , to_access ) ) { throw new ComponentException ( "Type/Access mismatch, Cannot connect: " + from + '.' + to_in + " -> " + to + '.' + from_out ) ; } FieldContent data = from_access . getData ( ) ; data . tagIn ( ) ; data . tagOut ( ) ; to_access . setData ( data ) ; ca_from . setOutput ( from_out , new AsyncFieldAccess ( from_access ) ) ; ca_to . setInput ( to_in , new AsyncFieldAccess ( to_access ) ) ; if ( checkCircular ) { } if ( log . isLoggable ( Level . CONFIG ) ) { log . config ( String . format ( "feedback @Out(%s) -> @In(%s)" , from_access . toString ( ) , to_access . toString ( ) ) ) ; } } | Feedback connect out to in |
17,506 | void callAnnotated ( Class < ? extends Annotation > ann , boolean lazy ) { for ( ComponentAccess p : oMap . values ( ) ) { p . callAnnotatedMethod ( ann , lazy ) ; } } | Call an annotated method . |
17,507 | public double addPoint ( double x , double y ) { pts . add ( new Coordinate ( x , y ) ) ; return selection = pts . size ( ) - 1 ; } | add a control point return index of new control point |
17,508 | public void setPoint ( double x , double y ) { if ( selection >= 0 ) { Coordinate coordinate = new Coordinate ( x , y ) ; pts . set ( selection , coordinate ) ; } } | set selected control point |
17,509 | public static Object sim ( String file , String ll , String cmd ) throws Exception { String f = CLI . readFile ( file ) ; Object o = CLI . createSim ( f , false , ll ) ; return CLI . invoke ( o , cmd ) ; } | Executes a simulation . |
17,510 | public static void groovy ( String file , String ll , String cmd ) throws Exception { String f = CLI . readFile ( file ) ; Object o = CLI . createSim ( f , true , ll ) ; } | Executed plain groovy . |
17,511 | public static String readFile ( String name ) throws IOException { StringBuilder b = new StringBuilder ( ) ; BufferedReader r = new BufferedReader ( new FileReader ( name ) ) ; String line ; while ( ( line = r . readLine ( ) ) != null ) { b . append ( line ) . append ( '\n' ) ; } r . close ( ) ; return b . toString ( ) ; } | Read a file and provide its content as String . |
17,512 | public static Object createSim ( String script , boolean groovy , String ll ) throws Exception { setOMSProperties ( ) ; Level . parse ( ll ) ; String prefix = groovy ? "" : "import static oms3.SimConst.*\n" + "def __sb__ = new oms3.SimBuilder(logging:'" + ll + "')\n" + "__sb__." ; ClassLoader parent = Thread . currentThread ( ) . getContextClassLoader ( ) ; Binding b = new Binding ( ) ; b . setVariable ( "oms_version" , System . getProperty ( "oms.version" ) ) ; b . setVariable ( "oms_home" , System . getProperty ( "oms.home" ) ) ; b . setVariable ( "oms_prj" , System . getProperty ( "oms.prj" ) ) ; GroovyShell shell = new GroovyShell ( new GroovyClassLoader ( parent ) , b ) ; return shell . evaluate ( prefix + script ) ; } | Create a simulation object . |
17,513 | private Object getPropertyTypeValue ( Class propertyType , Object value ) { if ( propertyType . equals ( String . class ) ) { return value . toString ( ) ; } else if ( propertyType . equals ( Boolean . class ) || propertyType . equals ( Boolean . TYPE ) ) { Boolean arg = null ; if ( value instanceof Boolean ) { arg = ( Boolean ) value ; } else { arg = Boolean . parseBoolean ( value . toString ( ) ) ; } return arg ; } else if ( propertyType . equals ( Short . class ) || propertyType . equals ( Short . TYPE ) ) { Short arg = null ; if ( value instanceof Short ) { arg = ( Short ) value ; } else { arg = Short . parseShort ( value . toString ( ) ) ; } return arg ; } else if ( propertyType . equals ( Integer . class ) || propertyType . equals ( Integer . TYPE ) ) { Integer arg = null ; if ( value instanceof Integer ) { arg = ( Integer ) value ; } else { arg = Integer . parseInt ( value . toString ( ) ) ; } return arg ; } else if ( propertyType . equals ( Long . class ) || propertyType . equals ( Long . TYPE ) ) { Long arg = null ; if ( value instanceof Long ) { arg = ( Long ) value ; } else { arg = Long . parseLong ( value . toString ( ) ) ; } return arg ; } else if ( propertyType . equals ( Float . class ) || propertyType . equals ( Float . TYPE ) ) { Float arg = null ; if ( value instanceof Float ) { arg = ( Float ) value ; } else { arg = Float . parseFloat ( value . toString ( ) ) ; } return arg ; } else if ( propertyType . equals ( Double . class ) || propertyType . equals ( Double . TYPE ) ) { Double arg = null ; if ( value instanceof Double ) { arg = ( Double ) value ; } else { arg = Double . parseDouble ( value . toString ( ) ) ; } return arg ; } else { return value ; } } | converts ths incoming value to an object for the property type . |
17,514 | public static < T , K , V > Map < K , V > toMap ( Stream < T > stream , Function < T , K > keySupplier , Function < T , V > valueSupplier ) { return stream . collect ( Collectors . toMap ( keySupplier , valueSupplier ) ) ; } | Collect stream to map . |
17,515 | public static < T , K , R > Map < R , List < T > > toMapGroupBy ( Stream < T > stream , Function < T , R > groupingFunction ) { return stream . collect ( Collectors . groupingBy ( groupingFunction ) ) ; } | Collect a map by grouping based on the object s field . |
17,516 | public static < T > Map < Boolean , List < T > > toMapPartition ( Stream < T > stream , Predicate < T > predicate ) { return stream . collect ( Collectors . partitioningBy ( predicate ) ) ; } | Split a stream into a map with true and false . |
17,517 | public static < T > T findAny ( Stream < T > stream , Predicate < T > predicate ) { Optional < T > element = stream . filter ( predicate ) . findAny ( ) ; return element . orElse ( null ) ; } | Find an element in the stream . |
17,518 | public void createSpatialTable ( String tableName , int tableSrid , String geometryFieldData , String [ ] fieldData ) throws Exception { createSpatialTable ( tableName , tableSrid , geometryFieldData , fieldData , null , false ) ; } | Creates a spatial table with default values for foreign keys and index . |
17,519 | public void createSpatialIndex ( String tableName , String geomColumnName ) throws Exception { if ( geomColumnName == null ) { geomColumnName = "the_geom" ; } String realColumnName = getProperColumnNameCase ( tableName , geomColumnName ) ; String realTableName = getProperTableNameCase ( tableName ) ; String sql = "CREATE SPATIAL INDEX ON " + realTableName + "(" + realColumnName + ");" ; execOnConnection ( connection -> { try ( IHMStatement stmt = connection . createStatement ( ) ) { stmt . execute ( sql . toString ( ) ) ; } return null ; } ) ; } | Create a spatial index . |
17,520 | public void insertGeometry ( String tableName , Geometry geometry , String epsg ) throws Exception { String epsgStr = "4326" ; if ( epsg == null ) { epsgStr = epsg ; } GeometryColumn gc = getGeometryColumnsForTable ( tableName ) ; String sql = "INSERT INTO " + tableName + " (" + gc . geometryColumnName + ") VALUES (ST_GeomFromText(?, " + epsgStr + "))" ; execOnConnection ( connection -> { try ( IHMPreparedStatement pStmt = connection . prepareStatement ( sql ) ) { pStmt . setString ( 1 , geometry . toText ( ) ) ; pStmt . executeUpdate ( ) ; } return null ; } ) ; } | Insert a geometry into a table . |
17,521 | public boolean isTableSpatial ( String tableName ) throws Exception { GeometryColumn geometryColumns = getGeometryColumnsForTable ( tableName ) ; return geometryColumns != null ; } | Checks if a table is spatial . |
17,522 | public List < Geometry > getGeometriesIn ( String tableName , Envelope envelope , String ... prePostWhere ) throws Exception { List < Geometry > geoms = new ArrayList < Geometry > ( ) ; List < String > wheres = new ArrayList < > ( ) ; String pre = "" ; String post = "" ; String where = "" ; if ( prePostWhere != null && prePostWhere . length == 3 ) { if ( prePostWhere [ 0 ] != null ) pre = prePostWhere [ 0 ] ; if ( prePostWhere [ 1 ] != null ) post = prePostWhere [ 1 ] ; if ( prePostWhere [ 2 ] != null ) { where = prePostWhere [ 2 ] ; wheres . add ( where ) ; } } GeometryColumn gCol = getGeometryColumnsForTable ( tableName ) ; String sql = "SELECT " + pre + gCol . geometryColumnName + post + " FROM " + tableName ; if ( envelope != null ) { double x1 = envelope . getMinX ( ) ; double y1 = envelope . getMinY ( ) ; double x2 = envelope . getMaxX ( ) ; double y2 = envelope . getMaxY ( ) ; wheres . add ( getSpatialindexBBoxWherePiece ( tableName , null , x1 , y1 , x2 , y2 ) ) ; } if ( wheres . size ( ) > 0 ) { sql += " WHERE " + DbsUtilities . joinBySeparator ( wheres , " AND " ) ; } String _sql = sql ; IGeometryParser geometryParser = getType ( ) . getGeometryParser ( ) ; return execOnConnection ( connection -> { try ( IHMStatement stmt = connection . createStatement ( ) ; IHMResultSet rs = stmt . executeQuery ( _sql ) ) { while ( rs . next ( ) ) { Geometry geometry = geometryParser . fromResultSet ( rs , 1 ) ; geoms . add ( geometry ) ; } return geoms ; } } ) ; } | Get the geometries of a table inside a given envelope . |
17,523 | public List < Geometry > getGeometriesIn ( String tableName , Geometry intersectionGeometry , String ... prePostWhere ) throws Exception { List < Geometry > geoms = new ArrayList < Geometry > ( ) ; List < String > wheres = new ArrayList < > ( ) ; String pre = "" ; String post = "" ; String where = "" ; if ( prePostWhere != null && prePostWhere . length == 3 ) { if ( prePostWhere [ 0 ] != null ) pre = prePostWhere [ 0 ] ; if ( prePostWhere [ 1 ] != null ) post = prePostWhere [ 1 ] ; if ( prePostWhere [ 2 ] != null ) { where = prePostWhere [ 2 ] ; wheres . add ( where ) ; } } GeometryColumn gCol = getGeometryColumnsForTable ( tableName ) ; String sql = "SELECT " + pre + gCol . geometryColumnName + post + " FROM " + tableName ; if ( intersectionGeometry != null ) { intersectionGeometry . setSRID ( gCol . srid ) ; wheres . add ( getSpatialindexGeometryWherePiece ( tableName , null , intersectionGeometry ) ) ; } if ( wheres . size ( ) > 0 ) { sql += " WHERE " + DbsUtilities . joinBySeparator ( wheres , " AND " ) ; } IGeometryParser geometryParser = getType ( ) . getGeometryParser ( ) ; String _sql = sql ; return execOnConnection ( connection -> { try ( IHMStatement stmt = connection . createStatement ( ) ; IHMResultSet rs = stmt . executeQuery ( _sql ) ) { while ( rs . next ( ) ) { Geometry geometry = geometryParser . fromResultSet ( rs , 1 ) ; geoms . add ( geometry ) ; } return geoms ; } } ) ; } | Get the geometries of a table intersecting a given geometry . |
17,524 | public static boolean fEq ( float a , float b , float epsilon ) { if ( isNaN ( a ) && isNaN ( b ) ) { return true ; } float diffAbs = abs ( a - b ) ; return a == b ? true : diffAbs < epsilon ? true : diffAbs / Math . max ( abs ( a ) , abs ( b ) ) < epsilon ; } | Returns true if two floats are considered equal based on an supplied epsilon . |
17,525 | public static double logGamma ( double x ) { double ret ; if ( Double . isNaN ( x ) || ( x <= 0.0 ) ) { ret = Double . NaN ; } else { double g = 607.0 / 128.0 ; double sum = 0.0 ; for ( int i = LANCZOS . length - 1 ; i > 0 ; -- i ) { sum = sum + ( LANCZOS [ i ] / ( x + i ) ) ; } sum = sum + LANCZOS [ 0 ] ; double tmp = x + g + .5 ; ret = ( ( x + .5 ) * log ( tmp ) ) - tmp + HALF_LOG_2_PI + log ( sum / x ) ; } return ret ; } | Gamma function ported from the apache math package . |
17,526 | public static List < int [ ] > getNegativeRanges ( double [ ] x ) { int firstNegative = - 1 ; int lastNegative = - 1 ; List < int [ ] > rangeList = new ArrayList < int [ ] > ( ) ; for ( int i = 0 ; i < x . length ; i ++ ) { double xValue = x [ i ] ; if ( firstNegative == - 1 && xValue < 0 ) { firstNegative = i ; } else if ( firstNegative != - 1 && lastNegative == - 1 && xValue > 0 ) { lastNegative = i - 1 ; } if ( i == x . length - 1 && firstNegative != - 1 && lastNegative == - 1 ) { lastNegative = i ; } if ( firstNegative != - 1 && lastNegative != - 1 ) { rangeList . add ( new int [ ] { firstNegative , lastNegative } ) ; firstNegative = - 1 ; lastNegative = - 1 ; } } return rangeList ; } | Get the range index for which x is negative . |
17,527 | public static double [ ] range2Bins ( double min , double max , int binsNum ) { double delta = ( max - min ) / binsNum ; double [ ] bins = new double [ binsNum + 1 ] ; int count = 0 ; double running = min ; for ( int i = 0 ; i < binsNum ; i ++ ) { bins [ count ] = running ; running = running + delta ; count ++ ; } bins [ binsNum ] = max ; return bins ; } | Creates an array of equal bin from a range and the number of bins . |
17,528 | public static double [ ] range2Bins ( double min , double max , double step , boolean doLastEqual ) { double intervalsDouble = ( max - min ) / step ; int intervals = ( int ) intervalsDouble ; double rest = intervalsDouble - intervals ; if ( rest > D_TOLERANCE ) { intervals ++ ; } double [ ] bins = new double [ intervals + 1 ] ; int count = 0 ; double running = min ; for ( int i = 0 ; i < intervals ; i ++ ) { bins [ count ] = running ; running = running + step ; count ++ ; } if ( doLastEqual ) { bins [ intervals ] = running ; } else { bins [ intervals ] = max ; } return bins ; } | Creates an array of bins from a range and a step to use . |
17,529 | private void verifyInput ( ) { if ( inData == null || inStations == null ) { throw new NullPointerException ( msg . message ( "kriging.stationproblem" ) ) ; } if ( pMode < 0 || pMode > 1 ) { throw new IllegalArgumentException ( msg . message ( "kriging.defaultMode" ) ) ; } if ( defaultVariogramMode != 0 && defaultVariogramMode != 1 ) { throw new IllegalArgumentException ( msg . message ( "kriging.variogramMode" ) ) ; } if ( defaultVariogramMode == 0 ) { if ( pVariance == 0 || pIntegralscale [ 0 ] == 0 || pIntegralscale [ 1 ] == 0 || pIntegralscale [ 2 ] == 0 ) { pm . errorMessage ( msg . message ( "kriging.noParam" ) ) ; pm . errorMessage ( "varianza " + pVariance ) ; pm . errorMessage ( "Integral scale x " + pIntegralscale [ 0 ] ) ; pm . errorMessage ( "Integral scale y " + pIntegralscale [ 1 ] ) ; pm . errorMessage ( "Integral scale z " + pIntegralscale [ 2 ] ) ; } } if ( defaultVariogramMode == 1 ) { if ( pNug == 0 || pS == 0 || pA == 0 ) { pm . errorMessage ( msg . message ( "kriging.noParam" ) ) ; pm . errorMessage ( "Nugget " + pNug ) ; pm . errorMessage ( "Sill " + pS ) ; pm . errorMessage ( "Range " + pA ) ; } } if ( ( pMode == 0 ) && inInterpolate == null ) { throw new ModelsIllegalargumentException ( msg . message ( "kriging.noPoint" ) , this , pm ) ; } if ( pMode == 1 && inInterpolationGrid == null ) { throw new ModelsIllegalargumentException ( "The gridded interpolation needs a gridgeometry in input." , this , pm ) ; } } | Verify the input of the model . |
17,530 | private LinkedHashMap < Integer , Coordinate > getCoordinate ( int nStaz , SimpleFeatureCollection collection , String idField ) throws Exception { LinkedHashMap < Integer , Coordinate > id2CoordinatesMap = new LinkedHashMap < Integer , Coordinate > ( ) ; FeatureIterator < SimpleFeature > iterator = collection . features ( ) ; Coordinate coordinate = null ; try { while ( iterator . hasNext ( ) ) { SimpleFeature feature = iterator . next ( ) ; int name = ( ( Number ) feature . getAttribute ( idField ) ) . intValue ( ) ; coordinate = ( ( Geometry ) feature . getDefaultGeometry ( ) ) . getCentroid ( ) . getCoordinate ( ) ; double z = 0 ; if ( fPointZ != null ) { try { z = ( ( Number ) feature . getAttribute ( fPointZ ) ) . doubleValue ( ) ; } catch ( NullPointerException e ) { pm . errorMessage ( msg . message ( "kriging.noPointZ" ) ) ; throw new Exception ( msg . message ( "kriging.noPointZ" ) ) ; } } coordinate . z = z ; id2CoordinatesMap . put ( name , coordinate ) ; } } finally { iterator . close ( ) ; } return id2CoordinatesMap ; } | Extract the coordinate of a FeatureCollection in a HashMap with an ID as a key . |
17,531 | private double variogram ( double c0 , double a , double sill , double rx , double ry , double rz ) { if ( isNovalue ( rz ) ) { rz = 0 ; } double value = 0 ; double h2 = Math . sqrt ( rx * rx + rz * rz + ry * ry ) ; if ( pSemivariogramType == 0 ) { value = c0 + sill * ( 1 - Math . exp ( - ( h2 * h2 ) / ( a * a ) ) ) ; } if ( pSemivariogramType == 1 ) { value = c0 + sill * ( 1 - Math . exp ( - ( h2 ) / ( a ) ) ) ; } return value ; } | The gaussian variogram |
17,532 | public static void figureOutConnect ( PrintStream w , Object ... comps ) { List < ComponentAccess > l = new ArrayList < ComponentAccess > ( ) ; for ( Object c : comps ) { l . add ( new ComponentAccess ( c ) ) ; } for ( ComponentAccess cp_out : l ) { w . println ( "// connect " + objName ( cp_out ) ) ; for ( Access fout : cp_out . outputs ( ) ) { String s = " out2in(" + objName ( cp_out ) + ", \"" + fout . getField ( ) . getName ( ) + "\"" ; for ( ComponentAccess cp_in : l ) { if ( cp_in == cp_out ) { continue ; } for ( Access fin : cp_in . inputs ( ) ) { if ( fout . getField ( ) . getName ( ) . equals ( fin . getField ( ) . getName ( ) ) ) { s = s + ", " + objName ( cp_in ) ; } } } w . println ( s + ");" ) ; } w . println ( ) ; } } | Figure out connectivity and generate Java statements . |
17,533 | public static List < Class < ? > > getComponentClasses ( URL jar ) throws IOException { JarInputStream jarFile = new JarInputStream ( jar . openStream ( ) ) ; URLClassLoader cl = new URLClassLoader ( new URL [ ] { jar } , Thread . currentThread ( ) . getContextClassLoader ( ) ) ; List < Class < ? > > idx = new ArrayList < Class < ? > > ( ) ; JarEntry jarEntry = jarFile . getNextJarEntry ( ) ; while ( jarEntry != null ) { String classname = jarEntry . getName ( ) ; if ( classname . endsWith ( ".class" ) ) { classname = classname . substring ( 0 , classname . indexOf ( ".class" ) ) . replace ( '/' , '.' ) ; try { Class < ? > c = Class . forName ( classname , false , cl ) ; for ( Method method : c . getMethods ( ) ) { if ( ( method . getAnnotation ( Execute . class ) ) != null ) { idx . add ( c ) ; break ; } } } catch ( ClassNotFoundException ex ) { ex . printStackTrace ( ) ; } } jarEntry = jarFile . getNextJarEntry ( ) ; } jarFile . close ( ) ; return idx ; } | Get all components from a jar file |
17,534 | public static URL getDocumentation ( Class < ? > comp , Locale loc ) { Documentation doc = ( Documentation ) comp . getAnnotation ( Documentation . class ) ; if ( doc != null ) { String v = doc . value ( ) ; try { URL url = new URL ( v ) ; return url ; } catch ( MalformedURLException E ) { String name = v . substring ( 0 , v . lastIndexOf ( '.' ) ) ; String ext = v . substring ( v . lastIndexOf ( '.' ) ) ; String lang = loc . getLanguage ( ) ; URL f = comp . getResource ( name + "_" + lang + ext ) ; if ( f != null ) { return f ; } f = comp . getResource ( v ) ; if ( f != null ) { return f ; } } } return null ; } | Get the documentation as URL reference ; |
17,535 | public static String getDescription ( Class < ? > comp , Locale loc ) { Description descr = ( Description ) comp . getAnnotation ( Description . class ) ; if ( descr != null ) { String lang = loc . getLanguage ( ) ; Method [ ] m = descr . getClass ( ) . getMethods ( ) ; for ( Method method : m ) { if ( method . getName ( ) . equals ( lang ) ) { try { String d = ( String ) method . invoke ( descr , ( Object [ ] ) null ) ; if ( d != null && ! d . isEmpty ( ) ) { return d ; } } catch ( Exception ex ) { ex . printStackTrace ( ) ; } } } return descr . value ( ) ; } return null ; } | Get the Component Description |
17,536 | public static Object [ ] stringListToArray ( List < String > list ) { Object [ ] params = null ; if ( list != null ) { params = list . toArray ( new String [ list . size ( ) ] ) ; } return params ; } | Converts list of strings to an array . |
17,537 | public static boolean notMatches ( String value , String prefix , String middle , String postfix ) { return ! matches ( value , prefix , middle , postfix ) ; } | Check whether value NOT matches the pattern build with prefix middle part and post - fixer . |
17,538 | public static boolean matches ( String value , String prefix , String middle , String postfix ) { String pattern = prefix + middle + postfix ; boolean result = value . matches ( pattern ) ; return result ; } | Check whether value matches the pattern build with prefix middle part and post - fixer . |
17,539 | public static boolean matchesWithoutPrefixes ( String value1 , String prefix1 , String value2 , String prefix2 ) { if ( ! value1 . startsWith ( prefix1 ) ) { return false ; } value1 = value1 . substring ( prefix1 . length ( ) ) ; if ( ! value2 . startsWith ( prefix2 ) ) { return false ; } value2 = value2 . substring ( prefix2 . length ( ) ) ; return value1 . equals ( value2 ) ; } | It removes prefixes from values and compare remaining parts . |
17,540 | public static ValidationMessage shiftReferenceLocation ( Entry entry , long newSequenceLength ) { Collection < Reference > references = entry . getReferences ( ) ; for ( Reference reference : references ) { for ( Location rlocation : reference . getLocations ( ) . getLocations ( ) ) { { rlocation . setEndPosition ( newSequenceLength ) ; if ( rlocation . getBeginPosition ( ) . equals ( rlocation . getEndPosition ( ) ) ) { return ValidationMessage . message ( Severity . WARNING , UTILS_6 , rlocation . getBeginPosition ( ) , rlocation . getEndPosition ( ) ) ; } } } } return null ; } | Reference Location shifting |
17,541 | @ SuppressWarnings ( "nls" ) public void dumpChart ( File chartFile , boolean autoRange , boolean withLegend , int imageWidth , int imageHeight ) throws IOException { JFreeChart chart = ChartFactory . createXYLineChart ( title , xLabel , yLabel , collection , PlotOrientation . VERTICAL , withLegend , false , false ) ; XYPlot plot = ( XYPlot ) chart . getPlot ( ) ; NumberAxis yAxis = ( NumberAxis ) plot . getRangeAxis ( ) ; yAxis . setStandardTickUnits ( NumberAxis . createStandardTickUnits ( ) ) ; if ( autoRange ) { double delta = ( max - min ) * 0.1 ; yAxis . setRange ( min - delta , max + delta ) ; } if ( ! chartFile . getName ( ) . endsWith ( ".png" ) ) { chartFile = FileUtilities . substituteExtention ( chartFile , "png" ) ; } if ( imageWidth == - 1 ) { imageWidth = IMAGEWIDTH ; } if ( imageHeight == - 1 ) { imageHeight = IMAGEHEIGHT ; } BufferedImage bufferedImage = chart . createBufferedImage ( imageWidth , imageHeight ) ; ImageIO . write ( bufferedImage , "png" , chartFile ) ; } | Creates the chart image and dumps it to file . |
17,542 | public RuleWrapper getFirstRule ( ) { if ( featureTypeStylesWrapperList . size ( ) > 0 ) { FeatureTypeStyleWrapper featureTypeStyleWrapper = featureTypeStylesWrapperList . get ( 0 ) ; List < RuleWrapper > rulesWrapperList = featureTypeStyleWrapper . getRulesWrapperList ( ) ; if ( rulesWrapperList . size ( ) > 0 ) { RuleWrapper ruleWrapper = rulesWrapperList . get ( 0 ) ; return ruleWrapper ; } } return null ; } | Facility to get the first rule if available . |
17,543 | public boolean isSimpleType ( ) { if ( fieldType . equals ( Double . class . getCanonicalName ( ) ) || fieldType . equals ( Float . class . getCanonicalName ( ) ) || fieldType . equals ( Integer . class . getCanonicalName ( ) ) || fieldType . equals ( double . class . getCanonicalName ( ) ) || fieldType . equals ( float . class . getCanonicalName ( ) ) || fieldType . equals ( int . class . getCanonicalName ( ) ) || fieldType . equals ( Boolean . class . getCanonicalName ( ) ) || fieldType . equals ( boolean . class . getCanonicalName ( ) ) || fieldType . equals ( String . class . getCanonicalName ( ) ) ) { return true ; } return false ; } | Checks if this field is a simple type . |
17,544 | private Long [ ] checkLocation ( Location location ) { Long [ ] positions = new Long [ 2 ] ; if ( location . isComplement ( ) ) { positions [ 0 ] = location . getEndPosition ( ) ; positions [ 1 ] = location . getBeginPosition ( ) ; } else { positions [ 0 ] = location . getBeginPosition ( ) ; positions [ 1 ] = location . getEndPosition ( ) ; } return positions ; } | Checks and swaps positions if in wrong order . |
17,545 | public String getSequence ( Long beginPosition , Long endPosition ) { if ( beginPosition == null || endPosition == null || ( beginPosition > endPosition ) || beginPosition < 1 || endPosition > getLength ( ) ) { return null ; } int length = ( int ) ( endPosition . longValue ( ) - beginPosition . longValue ( ) ) + 1 ; int offset = beginPosition . intValue ( ) - 1 ; String subSequence = null ; try { subSequence = ByteBufferUtils . string ( getSequenceBuffer ( ) , offset , length ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; return subSequence ; } return subSequence ; } | Overridden so we can create appropriate sized buffer before making string . |
17,546 | String convertCase ( String str ) { if ( str == null ) { return null ; } return sensitive ? str : str . toLowerCase ( ) ; } | Converts the case of the input String to a standard format . Subsequent operations can then use standard String methods . |
17,547 | private void set ( Matrix m ) { this . nRows = 1 ; this . nCols = m . nCols ; this . values = m . values ; } | Set this row vector from a matrix . Only the first row is used . |
17,548 | public RowVector getRow ( int r ) throws MatrixException { if ( ( r < 0 ) || ( r >= nRows ) ) { throw new MatrixException ( MatrixException . INVALID_INDEX ) ; } RowVector rv = new RowVector ( nCols ) ; for ( int c = 0 ; c < nCols ; ++ c ) { rv . values [ 0 ] [ c ] = this . values [ r ] [ c ] ; } return rv ; } | Get a row of this matrix . |
17,549 | public ColumnVector getColumn ( int c ) throws MatrixException { if ( ( c < 0 ) || ( c >= nCols ) ) { throw new MatrixException ( MatrixException . INVALID_INDEX ) ; } ColumnVector cv = new ColumnVector ( nRows ) ; for ( int r = 0 ; r < nRows ; ++ r ) { cv . values [ r ] [ 0 ] = this . values [ r ] [ c ] ; } return cv ; } | Get a column of this matrix . |
17,550 | protected void set ( double values [ ] [ ] ) { this . nRows = values . length ; this . nCols = values [ 0 ] . length ; this . values = values ; for ( int r = 1 ; r < nRows ; ++ r ) { nCols = Math . min ( nCols , values [ r ] . length ) ; } } | Set this matrix from a 2 - d array of values . If the rows do not have the same length then the matrix column count is the length of the shortest row . |
17,551 | public void setRow ( RowVector rv , int r ) throws MatrixException { if ( ( r < 0 ) || ( r >= nRows ) ) { throw new MatrixException ( MatrixException . INVALID_INDEX ) ; } if ( nCols != rv . nCols ) { throw new MatrixException ( MatrixException . INVALID_DIMENSIONS ) ; } for ( int c = 0 ; c < nCols ; ++ c ) { this . values [ r ] [ c ] = rv . values [ 0 ] [ c ] ; } } | Set a row of this matrix from a row vector . |
17,552 | public void setColumn ( ColumnVector cv , int c ) throws MatrixException { if ( ( c < 0 ) || ( c >= nCols ) ) { throw new MatrixException ( MatrixException . INVALID_INDEX ) ; } if ( nRows != cv . nRows ) { throw new MatrixException ( MatrixException . INVALID_DIMENSIONS ) ; } for ( int r = 0 ; r < nRows ; ++ r ) { this . values [ r ] [ c ] = cv . values [ r ] [ 0 ] ; } } | Set a column of this matrix from a column vector . |
17,553 | public Matrix transpose ( ) { double tv [ ] [ ] = new double [ nCols ] [ nRows ] ; for ( int r = 0 ; r < nRows ; ++ r ) { for ( int c = 0 ; c < nCols ; ++ c ) { tv [ c ] [ r ] = values [ r ] [ c ] ; } } return new Matrix ( tv ) ; } | Return the transpose of this matrix . |
17,554 | public Matrix add ( Matrix m ) throws MatrixException { if ( ( nRows != m . nRows ) && ( nCols != m . nCols ) ) { throw new MatrixException ( MatrixException . INVALID_DIMENSIONS ) ; } double sv [ ] [ ] = new double [ nRows ] [ nCols ] ; for ( int r = 0 ; r < nRows ; ++ r ) { for ( int c = 0 ; c < nCols ; ++ c ) { sv [ r ] [ c ] = values [ r ] [ c ] + m . values [ r ] [ c ] ; } } return new Matrix ( sv ) ; } | Add another matrix to this matrix . |
17,555 | public Matrix subtract ( Matrix m ) throws MatrixException { if ( ( nRows != m . nRows ) && ( nCols != m . nCols ) ) { throw new MatrixException ( MatrixException . INVALID_DIMENSIONS ) ; } double dv [ ] [ ] = new double [ nRows ] [ nCols ] ; for ( int r = 0 ; r < nRows ; ++ r ) { for ( int c = 0 ; c < nCols ; ++ c ) { dv [ r ] [ c ] = values [ r ] [ c ] - m . values [ r ] [ c ] ; } } return new Matrix ( dv ) ; } | Subtract another matrix from this matrix . |
17,556 | public Matrix multiply ( double k ) { double pv [ ] [ ] = new double [ nRows ] [ nCols ] ; for ( int r = 0 ; r < nRows ; ++ r ) { for ( int c = 0 ; c < nCols ; ++ c ) { pv [ r ] [ c ] = k * values [ r ] [ c ] ; } } return new Matrix ( pv ) ; } | Multiply this matrix by a constant . |
17,557 | public Matrix multiply ( Matrix m ) throws MatrixException { if ( nCols != m . nRows ) { throw new MatrixException ( MatrixException . INVALID_DIMENSIONS ) ; } double pv [ ] [ ] = new double [ nRows ] [ m . nCols ] ; for ( int r = 0 ; r < nRows ; ++ r ) { for ( int c = 0 ; c < m . nCols ; ++ c ) { double dot = 0 ; for ( int k = 0 ; k < nCols ; ++ k ) { dot += values [ r ] [ k ] * m . values [ k ] [ c ] ; } pv [ r ] [ c ] = dot ; } } return new Matrix ( pv ) ; } | Multiply this matrix by another matrix . |
17,558 | public static void printInfo ( String filePath ) throws Exception { LasInfo lasInfo = new LasInfo ( ) ; lasInfo . inLas = filePath ; lasInfo . process ( ) ; } | Utility method to run info . |
17,559 | private double internalPipeVerify ( int k , double [ ] cDelays , double [ ] [ ] net , double [ ] [ ] timeDischarge , double [ ] [ ] timeFillDegree , int tp ) { int num ; double localdelay , olddelay , qMax , B , known , theta , u ; double [ ] [ ] qPartial ; qPartial = new double [ timeDischarge . length ] [ timeDischarge [ 0 ] . length ] ; calculateDelays ( k , cDelays , net ) ; localdelay = 1 ; double accuracy = networkPipes [ 0 ] . getAccuracy ( ) ; int jMax = networkPipes [ 0 ] . getjMax ( ) ; double minG = networkPipes [ 0 ] . getMinG ( ) ; double maxtheta = networkPipes [ 0 ] . getMaxTheta ( ) ; double tolerance = networkPipes [ 0 ] . getTolerance ( ) ; int count = 0 ; do { olddelay = localdelay ; qMax = 0 ; for ( int i = 0 ; i < net . length ; i ++ ) { net [ i ] [ 2 ] += localdelay ; } ; for ( int j = 0 ; j < net . length ; ++ j ) { num = ( int ) net [ j ] [ 0 ] ; getHydrograph ( num , qPartial , olddelay , net [ j ] [ 2 ] , tp ) ; } getHydrograph ( k , qPartial , olddelay , 0 , tp ) ; qMax = ModelsEngine . sumDoublematrixColumns ( k , qPartial , timeDischarge , 0 , qPartial [ 0 ] . length - 1 , pm ) ; if ( qMax <= 1 ) qMax = 1 ; for ( int i = 0 ; i < net . length ; i ++ ) { net [ i ] [ 2 ] -= localdelay ; } calculateFillDegree ( k , timeDischarge , timeFillDegree ) ; B = qMax / ( CUBICMETER2LITER * networkPipes [ k ] . getKs ( ) * sqrt ( networkPipes [ k ] . verifyPipeSlope / METER2CM ) ) ; known = ( B * TWO_THIRTEENOVERTHREE ) / pow ( networkPipes [ k ] . diameterToVerify / METER2CM , EIGHTOVERTHREE ) ; theta = Utility . thisBisection ( maxtheta , known , TWOOVERTHREE , minG , accuracy , jMax , pm , strBuilder ) ; u = qMax * 80 / ( pow ( networkPipes [ k ] . diameterToVerify , 2 ) * ( theta - sin ( theta ) ) ) ; localdelay = networkPipes [ k ] . getLenght ( ) / ( celerityfactor1 * u * MINUTE2SEC ) ; count ++ ; if ( count > MAX_NUMBER_ITERATION ) { infiniteLoop = true ; throw new ArithmeticException ( ) ; } } while ( abs ( localdelay - olddelay ) / olddelay >= tolerance ) ; cDelays [ k ] = localdelay ; return qMax ; } | verify of the no - head pipes . |
17,560 | private void calculateDelays ( int k , double [ ] cDelays , double [ ] [ ] net ) { double t ; int ind , r = 1 ; for ( int j = 0 ; j < net . length ; ++ j ) { t = 0 ; r = 1 ; ind = ( int ) net [ j ] [ 0 ] ; while ( networkPipes [ ind ] . getIndexPipeWhereDrain ( ) != k ) { ind = networkPipes [ ind ] . getIndexPipeWhereDrain ( ) ; t += cDelays [ ind ] ; r ++ ; } if ( r > networkPipes . length ) { pm . errorMessage ( msg . message ( "trentoP.error.incorrectmatrix" ) ) ; throw new ArithmeticException ( msg . message ( "trentoP.error.incorrectmatrix" ) ) ; } net [ j ] [ 2 ] = t ; } } | Calcola il ritardo della tubazione k . |
17,561 | private double getHydrograph ( int k , double [ ] [ ] Qpartial , double localdelay , double delay , int tp ) { double Qmax = 0 ; double tmin = rainData [ 0 ] [ 0 ] ; int j = 0 ; double t = tmin ; double Q ; double rain ; int maxRain = 0 ; if ( tMax == tpMaxCalibration ) { maxRain = rainData . length ; } else { maxRain = tp / dt ; } double tMaxApproximate = ModelsEngine . approximate2Multiple ( tMax , dt ) ; for ( t = tmin , j = 0 ; t <= tMaxApproximate ; t += dt , ++ j ) { Q = 0 ; for ( int i = 0 ; i <= maxRain - 1 ; ++ i ) { rain = rainData [ i ] [ 1 ] * networkPipes [ k ] . getDrainArea ( ) * networkPipes [ k ] . getRunoffCoefficient ( ) * HAOVERH_TO_METEROVERS ; if ( t <= i * dt ) { Q += 0 ; } else if ( t <= ( i + 1 ) * dt ) { Q += rain * pFunction ( k , t - i * dt , localdelay , delay ) ; } else { Q += rain * ( pFunction ( k , t - i * dt , localdelay , delay ) - pFunction ( k , t - ( i + 1 ) * dt , localdelay , delay ) ) ; } } Qpartial [ j ] [ k ] = Q ; if ( Q >= Qmax ) { Qmax = Q ; } } return Qmax ; } | Restituisce l idrogramma . |
17,562 | public void geoSewer ( ) throws Exception { if ( ! foundMaxrainTime ) { evaluateDischarge ( lastTimeDischarge , lastTimeFillDegree , tpMaxCalibration ) ; } else { int minTime = ( int ) ModelsEngine . approximate2Multiple ( INITIAL_TIME , dt ) ; double qMax = 0 ; for ( int i = minTime ; i < tpMaxCalibration ; i = i + dt ) { tpMax = i ; double [ ] [ ] timeDischarge = createMatrix ( ) ; double [ ] [ ] timeFillDegree = createMatrix ( ) ; double q = evaluateDischarge ( timeDischarge , timeFillDegree , i ) ; if ( q > qMax ) { qMax = q ; lastTimeDischarge = timeDischarge ; lastTimeFillDegree = timeFillDegree ; } else if ( q < qMax ) { break ; } if ( isFill ) { break ; } } } getNetData ( ) ; } | Estimate the discharge for each time and for each pipes . |
17,563 | private double scanNetwork ( int k , int l , double [ ] one , double [ ] [ ] net ) { int ind ; double t ; double length ; double totalarea = 0 ; int r = 0 ; int i = 0 ; for ( int j = 0 ; j < k ; j ++ ) { t = 0 ; i = ( int ) one [ j ] ; ind = i ; length = networkPipes [ ind ] . getLenght ( ) ; while ( networkPipes [ ind ] . getIdPipeWhereDrain ( ) != OUT_ID_PIPE ) { ind = networkPipes [ ind ] . getIndexPipeWhereDrain ( ) ; if ( ind == l ) { net [ r ] [ 0 ] = i ; net [ r ] [ 1 ] = length + networkPipes [ l ] . getLenght ( ) ; net [ r ] [ 2 ] = t ; totalarea += networkPipes [ i ] . getDrainArea ( ) ; r ++ ; break ; } } if ( r > net . length ) break ; } totalarea += networkPipes [ l ] . getDrainArea ( ) ; return totalarea ; } | Compila la mantrice net con tutte i dati del sottobacino con chiusura nel tratto che si sta analizzando e restituisce la sua superfice |
17,564 | public void readDwgBlockV15 ( int [ ] data , int offset ) throws Exception { int bitPos = offset ; bitPos = readObjectHeaderV15 ( data , bitPos ) ; Vector v = DwgUtil . getTextString ( data , bitPos ) ; bitPos = ( ( Integer ) v . get ( 0 ) ) . intValue ( ) ; String text = ( String ) v . get ( 1 ) ; name = text ; bitPos = readObjectTailV15 ( data , bitPos ) ; } | Read a Block in the DWG format Version 15 |
17,565 | public void setRepeatTimerDelay ( int delay ) { if ( delay <= 0 ) { String message = Logging . getMessage ( "generic.ArgumentOutOfRange" , delay ) ; Logging . logger ( ) . severe ( message ) ; throw new IllegalArgumentException ( message ) ; } this . repeatTimer . setDelay ( delay ) ; } | Set the repeat timer delay in milliseconds . |
17,566 | public void setPitchIncrement ( double value ) { if ( value < 0 ) { String message = Logging . getMessage ( "generic.ArgumentOutOfRange" , value ) ; Logging . logger ( ) . severe ( message ) ; throw new IllegalArgumentException ( message ) ; } this . pitchStep = value ; } | Set the pitch increment value in decimal degrees . Doubling this value will double the pitch change speed . Must be positive . Default value is 1 degree . |
17,567 | public void setFovIncrement ( double value ) { if ( value < 1 ) { String message = Logging . getMessage ( "generic.ArgumentOutOfRange" , value ) ; Logging . logger ( ) . severe ( message ) ; throw new IllegalArgumentException ( message ) ; } this . fovStep = value ; } | Set the field of view increment factor . At each iteration the current field of view will be multiplied or divided by this value . Must be greater then or equal to one . Default value is 1 . 05 . |
17,568 | public void setVeIncrement ( double value ) { if ( value < 0 ) { String message = Logging . getMessage ( "generic.ArgumentOutOfRange" , value ) ; Logging . logger ( ) . severe ( message ) ; throw new IllegalArgumentException ( message ) ; } this . veStep = value ; } | Set the vertical exaggeration increment . At each iteration the current vertical exaggeration will be increased or decreased by this amount . Must be greater than or equal to zero . Default value is 0 . 1 . |
17,569 | protected Vec4 computeSurfacePoint ( OrbitView view , Angle heading , Angle pitch ) { Globe globe = wwd . getModel ( ) . getGlobe ( ) ; Matrix transform = globe . computeSurfaceOrientationAtPosition ( view . getCenterPosition ( ) ) ; transform = transform . multiply ( Matrix . fromRotationZ ( heading . multiply ( - 1 ) ) ) ; transform = transform . multiply ( Matrix . fromRotationX ( Angle . NEG90 . add ( pitch ) ) ) ; Vec4 forward = Vec4 . UNIT_Y . transformBy4 ( transform ) ; Intersection [ ] intersections = wwd . getSceneController ( ) . getTerrain ( ) . intersect ( new Line ( view . getEyePoint ( ) , forward ) ) ; return ( intersections != null && intersections . length != 0 ) ? intersections [ 0 ] . getIntersectionPoint ( ) : null ; } | Find out where on the terrain surface the eye would be looking at with the given heading and pitch angles . |
17,570 | public static void enableProxy ( String url , String port , String user , String pwd , String nonProxyHosts ) { _url = url ; _port = port ; _user = user ; _pwd = pwd ; System . setProperty ( "http.proxyHost" , url ) ; System . setProperty ( "https.proxyHost" , url ) ; if ( port != null && port . trim ( ) . length ( ) != 0 ) { System . setProperty ( "http.proxyPort" , port ) ; System . setProperty ( "https.proxyPort" , port ) ; } if ( user != null && pwd != null && user . trim ( ) . length ( ) != 0 && pwd . trim ( ) . length ( ) != 0 ) { System . setProperty ( "http.proxyUserName" , user ) ; System . setProperty ( "https.proxyUserName" , user ) ; System . setProperty ( "http.proxyUser" , user ) ; System . setProperty ( "https.proxyUser" , user ) ; System . setProperty ( "http.proxyPassword" , pwd ) ; System . setProperty ( "https.proxyPassword" , pwd ) ; Authenticator . setDefault ( new ProxyAuthenticator ( user , pwd ) ) ; } if ( nonProxyHosts != null ) { System . setProperty ( "http.nonProxyHosts" , nonProxyHosts ) ; } hasProxy = true ; } | Enable the proxy usage based on the url user and pwd . |
17,571 | public static void disableProxy ( ) { System . clearProperty ( "http.proxyHost" ) ; System . clearProperty ( "http.proxyPort" ) ; System . clearProperty ( "http.proxyUserName" ) ; System . clearProperty ( "http.proxyUser" ) ; System . clearProperty ( "http.proxyPassword" ) ; System . clearProperty ( "https.proxyHost" ) ; System . clearProperty ( "https.proxyPort" ) ; System . clearProperty ( "https.proxyUserName" ) ; System . clearProperty ( "https.proxyUser" ) ; System . clearProperty ( "https.proxyPassword" ) ; _url = null ; _port = null ; _user = null ; _pwd = null ; hasProxy = false ; } | Disable the proxy usage . |
17,572 | public static String loadNativeLibrary ( String nativeLibPath , String libName ) { try { String name = "las_c" ; if ( libName == null ) libName = name ; if ( nativeLibPath != null ) { NativeLibrary . addSearchPath ( libName , nativeLibPath ) ; } WRAPPER = ( LiblasJNALibrary ) Native . loadLibrary ( libName , LiblasJNALibrary . class ) ; } catch ( UnsatisfiedLinkError e ) { return e . getLocalizedMessage ( ) ; } return null ; } | Loads the native libs creating the native wrapper . |
17,573 | public static void createTables ( Connection connection ) throws Exception { StringBuilder sB = new StringBuilder ( ) ; sB . append ( "CREATE TABLE " ) ; sB . append ( TABLE_LOG ) ; sB . append ( " (" ) ; sB . append ( COLUMN_ID ) ; sB . append ( " INTEGER PRIMARY KEY AUTOINCREMENT, " ) ; sB . append ( COLUMN_DATAORA ) . append ( " INTEGER NOT NULL, " ) ; sB . append ( COLUMN_LOGMSG ) . append ( " TEXT " ) ; sB . append ( ");" ) ; String CREATE_TABLE = sB . toString ( ) ; sB = new StringBuilder ( ) ; sB . append ( "CREATE INDEX " + TABLE_LOG + "_" + COLUMN_ID + " ON " ) ; sB . append ( TABLE_LOG ) ; sB . append ( " ( " ) ; sB . append ( COLUMN_ID ) ; sB . append ( " );" ) ; String CREATE_INDEX = sB . toString ( ) ; sB = new StringBuilder ( ) ; sB . append ( "CREATE INDEX " + TABLE_LOG + "_" + COLUMN_DATAORA + " ON " ) ; sB . append ( TABLE_LOG ) ; sB . append ( " ( " ) ; sB . append ( COLUMN_DATAORA ) ; sB . append ( " );" ) ; String CREATE_INDEX_DATE = sB . toString ( ) ; try ( Statement statement = connection . createStatement ( ) ) { statement . setQueryTimeout ( 30 ) ; statement . executeUpdate ( CREATE_TABLE ) ; statement . executeUpdate ( CREATE_INDEX ) ; statement . executeUpdate ( CREATE_INDEX_DATE ) ; } catch ( Exception e ) { throw new IOException ( e . getLocalizedMessage ( ) ) ; } } | Create the default log table . |
17,574 | public static String convert ( long x , int n , String d ) { if ( x == 0 ) { return "0" ; } String r = "" ; int m = 1 << n ; m -- ; while ( x != 0 ) { r = d . charAt ( ( int ) ( x & m ) ) + r ; x = x >>> n ; } return r ; } | Converts number to string |
17,575 | public static String sprintf ( String s , Object [ ] params ) { if ( ( s == null ) || ( params == null ) ) { return s ; } StringBuffer result = new StringBuffer ( "" ) ; String [ ] ss = split ( s ) ; int p = 0 ; for ( int i = 0 ; i < ss . length ; i ++ ) { char c = ss [ i ] . charAt ( 0 ) ; String t = ss [ i ] . substring ( 1 ) ; if ( c == '+' ) { result . append ( t ) ; } else { Object param = params [ p ] ; if ( param instanceof Integer ) { result . append ( new Format ( t ) . form ( ( Integer ) param ) ) ; } else if ( param instanceof Long ) { result . append ( new Format ( t ) . form ( ( Long ) param ) ) ; } else if ( param instanceof Character ) { result . append ( new Format ( t ) . form ( ( Character ) param ) ) ; } else if ( param instanceof Double ) { result . append ( new Format ( t ) . form ( ( Double ) param ) ) ; } else if ( param instanceof Double ) { result . append ( new Format ( t ) . form ( new Float ( ( Double ) param ) ) ) ; } else { result . append ( new Format ( t ) . form ( param . toString ( ) ) ) ; } p ++ ; } } return result . toString ( ) ; } | Sprintf multiple strings . |
17,576 | public void setLowerAndUpperBounds ( double lower , double upper ) { if ( data == null ) { return ; } this . originalLowerBound = lower ; this . originalUpperBound = upper ; if ( originalLowerBound < min ) { offset = Math . abs ( originalLowerBound ) + 10 ; } else { offset = Math . abs ( min ) + 10 ; } if ( calibrationType == MEAN ) { lowerBound = ( originalLowerBound + offset ) * ( mean + offset ) / ( min + offset ) - offset ; upperBound = ( originalUpperBound + offset ) * ( mean + offset ) / ( max + offset ) - offset ; } else { lowerBound = originalLowerBound ; upperBound = originalUpperBound ; } hasBounds = true ; setDeviation ( ) ; } | Set the lower and upper bounds and the actual bounds are determined . |
17,577 | private boolean checkLocations ( long length , CompoundLocation < Location > locations ) { for ( Location location : locations . getLocations ( ) ) { if ( location instanceof RemoteLocation ) continue ; if ( location . getIntBeginPosition ( ) == null || location . getIntBeginPosition ( ) < 0 ) { return false ; } if ( location . getIntEndPosition ( ) == null || location . getIntEndPosition ( ) > length ) { return false ; } } return true ; } | Checks that the locations are within the sequence length |
17,578 | public static SimpleFeatureSource readFeatureSource ( String path ) throws Exception { File shapeFile = new File ( path ) ; FileDataStore store = FileDataStoreFinder . getDataStore ( shapeFile ) ; SimpleFeatureSource featureSource = store . getFeatureSource ( ) ; return featureSource ; } | Get the feature source from a file . |
17,579 | public static GEOMTYPE getGeometryType ( SimpleFeatureCollection featureCollection ) { GeometryDescriptor geometryDescriptor = featureCollection . getSchema ( ) . getGeometryDescriptor ( ) ; if ( EGeometryType . isPolygon ( geometryDescriptor ) ) { return GEOMTYPE . POLYGON ; } else if ( EGeometryType . isLine ( geometryDescriptor ) ) { return GEOMTYPE . LINE ; } else if ( EGeometryType . isPoint ( geometryDescriptor ) ) { return GEOMTYPE . POINT ; } else { return GEOMTYPE . UNKNOWN ; } } | Get the geometry type from a featurecollection . |
17,580 | public static void insertBeforeCompass ( WorldWindow wwd , Layer layer ) { int compassPosition = 0 ; LayerList layers = wwd . getModel ( ) . getLayers ( ) ; for ( Layer l : layers ) { if ( l instanceof CompassLayer ) compassPosition = layers . indexOf ( l ) ; } layers . add ( compassPosition , layer ) ; } | Insert a layer before the compass layer . |
17,581 | public void readDwgVertex2DV15 ( int [ ] data , int offset ) throws Exception { int bitPos = offset ; bitPos = readObjectHeaderV15 ( data , bitPos ) ; Vector v = DwgUtil . getRawChar ( data , bitPos ) ; bitPos = ( ( Integer ) v . get ( 0 ) ) . intValue ( ) ; int flags = ( ( Integer ) v . get ( 1 ) ) . intValue ( ) ; this . flags = flags ; v = DwgUtil . getBitDouble ( data , bitPos ) ; bitPos = ( ( Integer ) v . get ( 0 ) ) . intValue ( ) ; double x = ( ( Double ) v . get ( 1 ) ) . doubleValue ( ) ; v = DwgUtil . getBitDouble ( data , bitPos ) ; bitPos = ( ( Integer ) v . get ( 0 ) ) . intValue ( ) ; double y = ( ( Double ) v . get ( 1 ) ) . doubleValue ( ) ; v = DwgUtil . getBitDouble ( data , bitPos ) ; bitPos = ( ( Integer ) v . get ( 0 ) ) . intValue ( ) ; double z = ( ( Double ) v . get ( 1 ) ) . doubleValue ( ) ; double [ ] coord = new double [ ] { x , y , z } ; point = new double [ ] { x , y , z } ; v = DwgUtil . getBitDouble ( data , bitPos ) ; bitPos = ( ( Integer ) v . get ( 0 ) ) . intValue ( ) ; double sw = ( ( Double ) v . get ( 1 ) ) . doubleValue ( ) ; double ew = 0.0 ; if ( sw < 0.0 ) { ew = Math . abs ( sw ) ; sw = ew ; } else { v = DwgUtil . getBitDouble ( data , bitPos ) ; bitPos = ( ( Integer ) v . get ( 0 ) ) . intValue ( ) ; ew = ( ( Double ) v . get ( 1 ) ) . doubleValue ( ) ; } initWidth = sw ; endWidth = ew ; v = DwgUtil . getBitDouble ( data , bitPos ) ; bitPos = ( ( Integer ) v . get ( 0 ) ) . intValue ( ) ; double bulge = ( ( Double ) v . get ( 1 ) ) . doubleValue ( ) ; this . bulge = bulge ; v = DwgUtil . getBitDouble ( data , bitPos ) ; bitPos = ( ( Integer ) v . get ( 0 ) ) . intValue ( ) ; double tandir = ( ( Double ) v . get ( 1 ) ) . doubleValue ( ) ; tangentDir = tandir ; bitPos = readObjectTailV15 ( data , bitPos ) ; } | Read a Vertex2D in the DWG format Version 15 |
17,582 | public static double runoffCoefficientError ( double [ ] obs , double [ ] sim , double [ ] precip ) { sameArrayLen ( sim , obs , precip ) ; double mean_pred = Stats . mean ( sim ) ; double mean_val = Stats . mean ( obs ) ; double mean_ppt = Stats . mean ( precip ) ; double error = Math . abs ( ( mean_pred / mean_ppt ) - ( mean_val / mean_ppt ) ) ; return Math . sqrt ( error ) ; } | Runoff coefficient error ROCE |
17,583 | public double [ ] update ( double w , double c1 , double rand1 , double c2 , double rand2 , double [ ] globalBest ) { for ( int i = 0 ; i < locations . length ; i ++ ) { particleVelocities [ i ] = w * particleVelocities [ i ] + c1 * rand1 * ( particleLocalBests [ i ] - locations [ i ] ) + c2 * rand2 * ( globalBest [ i ] - locations [ i ] ) ; double tmpLocation = locations [ i ] + particleVelocities [ i ] ; tmpLocations [ i ] = tmpLocation ; } if ( ! PSEngine . parametersInRange ( tmpLocations , ranges ) ) { for ( int i = 0 ; i < tmpLocations . length ; i ++ ) { double min = ranges [ i ] [ 0 ] ; double max = ranges [ i ] [ 1 ] ; if ( tmpLocations [ i ] > max ) { double tmp = max - ( tmpLocations [ i ] - max ) ; if ( tmp < min ) { tmp = max ; } locations [ i ] = tmp ; } else if ( tmpLocations [ i ] < min ) { double tmp = min + ( min - tmpLocations [ i ] ) ; if ( tmp > max ) { tmp = min ; } locations [ i ] = tmp ; } else { locations [ i ] = tmpLocations [ i ] ; } } return null ; } else { for ( int i = 0 ; i < locations . length ; i ++ ) { locations [ i ] = tmpLocations [ i ] ; } return locations ; } } | Particle swarming formula to update positions . |
17,584 | public void setParticleLocalBeststoCurrent ( ) { for ( int i = 0 ; i < locations . length ; i ++ ) { particleLocalBests [ i ] = locations [ i ] ; } } | Setter to set the current positions to be the local best positions . |
17,585 | public static File getLastFile ( ) { Preferences preferences = Preferences . userRoot ( ) . node ( GuiBridgeHandler . PREFS_NODE_NAME ) ; String userHome = System . getProperty ( "user.home" ) ; String lastPath = preferences . get ( LAST_PATH , userHome ) ; File file = new File ( lastPath ) ; if ( ! file . exists ( ) ) { return new File ( userHome ) ; } return file ; } | Handle the last set path preference . |
17,586 | public static void setLastPath ( String lastPath ) { File file = new File ( lastPath ) ; if ( ! file . isDirectory ( ) ) { lastPath = file . getParentFile ( ) . getAbsolutePath ( ) ; } Preferences preferences = Preferences . userRoot ( ) . node ( GuiBridgeHandler . PREFS_NODE_NAME ) ; preferences . put ( LAST_PATH , lastPath ) ; } | Save the passed path as last path available . |
17,587 | public static void setPreference ( String preferenceKey , String value ) { if ( preferencesDb != null ) { preferencesDb . setPreference ( preferenceKey , value ) ; return ; } Preferences preferences = Preferences . userRoot ( ) . node ( GuiBridgeHandler . PREFS_NODE_NAME ) ; if ( value != null ) { preferences . put ( preferenceKey , value ) ; } else { preferences . remove ( preferenceKey ) ; } } | Set a preference . |
17,588 | @ SuppressWarnings ( { "unchecked" , "rawtypes" } ) public static String [ ] showMultiInputDialog ( Component parentComponent , String title , String [ ] labels , String [ ] defaultValues , HashMap < String , String [ ] > fields2ValuesMap ) { Component [ ] valuesFields = new Component [ labels . length ] ; JPanel panel = new JPanel ( ) ; panel . setBorder ( BorderFactory . createEmptyBorder ( 10 , 10 , 10 , 10 ) ) ; String input [ ] = new String [ labels . length ] ; panel . setLayout ( new GridLayout ( labels . length , 2 , 5 , 5 ) ) ; for ( int i = 0 ; i < labels . length ; i ++ ) { panel . add ( new JLabel ( labels [ i ] ) ) ; boolean doneCombo = false ; if ( fields2ValuesMap != null ) { String [ ] values = fields2ValuesMap . get ( labels [ i ] ) ; if ( values != null ) { JComboBox < String > valuesCombo = new JComboBox < > ( values ) ; valuesFields [ i ] = valuesCombo ; panel . add ( valuesCombo ) ; if ( defaultValues != null ) { valuesCombo . setSelectedItem ( defaultValues [ i ] ) ; } doneCombo = true ; } } if ( ! doneCombo ) { valuesFields [ i ] = new JTextField ( ) ; panel . add ( valuesFields [ i ] ) ; if ( defaultValues != null ) { ( ( JTextField ) valuesFields [ i ] ) . setText ( defaultValues [ i ] ) ; } } } JScrollPane scrollPane = new JScrollPane ( panel ) ; scrollPane . setPreferredSize ( new Dimension ( 550 , 300 ) ) ; int result = JOptionPane . showConfirmDialog ( parentComponent , scrollPane , title , JOptionPane . OK_CANCEL_OPTION ) ; if ( result != JOptionPane . OK_OPTION ) { return null ; } for ( int i = 0 ; i < labels . length ; i ++ ) { if ( valuesFields [ i ] instanceof JTextField ) { JTextField textField = ( JTextField ) valuesFields [ i ] ; input [ i ] = textField . getText ( ) ; } if ( valuesFields [ i ] instanceof JComboBox ) { JComboBox < String > combo = ( JComboBox ) valuesFields [ i ] ; input [ i ] = combo . getSelectedItem ( ) . toString ( ) ; } } return input ; } | Create a simple multi input pane that returns what the use inserts . |
17,589 | public static void colorButton ( JButton button , Color color , Integer size ) { if ( size == null ) size = 15 ; BufferedImage bi = new BufferedImage ( size , size , BufferedImage . TYPE_INT_RGB ) ; Graphics2D gr = ( Graphics2D ) bi . getGraphics ( ) ; gr . setColor ( color ) ; gr . fillRect ( 0 , 0 , size , size ) ; gr . dispose ( ) ; button . setIcon ( new ImageIcon ( bi ) ) ; } | Create an image to make a color picker button . |
17,590 | public static void setFileBrowsingOnWidgets ( JTextField pathTextField , JButton browseButton , String [ ] allowedExtensions , Runnable postRunnable ) { FileFilter filter = null ; if ( allowedExtensions != null ) { filter = new FileFilter ( ) { public String getDescription ( ) { return Arrays . toString ( allowedExtensions ) ; } public boolean accept ( File f ) { if ( f . isDirectory ( ) ) { return true ; } String name = f . getName ( ) ; for ( String ext : allowedExtensions ) { if ( name . toLowerCase ( ) . endsWith ( ext . toLowerCase ( ) ) ) { return true ; } } return false ; } } ; } FileFilter _filter = filter ; browseButton . addActionListener ( e -> { File lastFile = GuiUtilities . getLastFile ( ) ; File [ ] res = showOpenFilesDialog ( browseButton , "Select file" , false , lastFile , _filter ) ; if ( res != null && res . length == 1 ) { String absolutePath = res [ 0 ] . getAbsolutePath ( ) ; pathTextField . setText ( absolutePath ) ; setLastPath ( absolutePath ) ; if ( postRunnable != null ) { postRunnable . run ( ) ; } } } ) ; } | Adds to a textfield and button the necessary to browse for a file . |
17,591 | public static void setFolderBrowsingOnWidgets ( JTextField pathTextField , JButton browseButton ) { browseButton . addActionListener ( e -> { File lastFile = GuiUtilities . getLastFile ( ) ; File [ ] res = showOpenFolderDialog ( browseButton , "Select folder" , false , lastFile ) ; if ( res != null && res . length == 1 ) { String absolutePath = res [ 0 ] . getAbsolutePath ( ) ; pathTextField . setText ( absolutePath ) ; setLastPath ( absolutePath ) ; } } ) ; } | Adds to a textfield and button the necessary to browse for a folder . |
17,592 | private static double [ ] calculateParameters ( final double [ ] [ ] elevationValues ) { int rows = elevationValues . length ; int cols = elevationValues [ 0 ] . length ; int pointsNum = rows * cols ; final double [ ] [ ] xyMatrix = new double [ pointsNum ] [ 6 ] ; final double [ ] valueArray = new double [ pointsNum ] ; int index = 0 ; for ( int y = 0 ; y < rows ; y ++ ) { for ( int x = 0 ; x < cols ; x ++ ) { xyMatrix [ index ] [ 0 ] = x * x ; xyMatrix [ index ] [ 1 ] = y * y ; xyMatrix [ index ] [ 2 ] = x * y ; xyMatrix [ index ] [ 3 ] = x ; xyMatrix [ index ] [ 4 ] = y ; xyMatrix [ index ] [ 5 ] = 1 ; valueArray [ index ] = elevationValues [ y ] [ x ] ; index ++ ; } } RealMatrix A = MatrixUtils . createRealMatrix ( xyMatrix ) ; RealVector z = MatrixUtils . createRealVector ( valueArray ) ; DecompositionSolver solver = new RRQRDecomposition ( A ) . getSolver ( ) ; RealVector solution = solver . solve ( z ) ; final double [ ] parameters = solution . toArray ( ) ; return parameters ; } | Calculates the parameters of a bivariate quadratic equation . |
17,593 | public Object column ( int col ) throws jsqlite . Exception { switch ( column_type ( col ) ) { case Constants . SQLITE_INTEGER : return new Long ( column_long ( col ) ) ; case Constants . SQLITE_FLOAT : return new Double ( column_double ( col ) ) ; case Constants . SQLITE_BLOB : return column_bytes ( col ) ; case Constants . SQLITE3_TEXT : return column_string ( col ) ; } return null ; } | Retrieve column data as object from exec ed SQLite3 statement . |
17,594 | protected void processGrid ( int cols , int rows , boolean ignoreBorder , Calculator calculator ) throws Exception { ExecutionPlanner planner = createDefaultPlanner ( ) ; planner . setNumberOfTasks ( rows * cols ) ; int startC = 0 ; int startR = 0 ; int endC = cols ; int endR = rows ; if ( ignoreBorder ) { startC = 1 ; startR = 1 ; endC = cols - 1 ; endR = rows - 1 ; } for ( int r = startR ; r < endR ; r ++ ) { for ( int c = startC ; c < endC ; c ++ ) { int _c = c , _r = r ; planner . submit ( ( ) -> { if ( ! pm . isCanceled ( ) ) { calculator . calculate ( _c , _r ) ; } } ) ; } } planner . join ( ) ; } | Loops through all rows and cols of the given grid . |
17,595 | public int compare ( SimpleFeature f1 , SimpleFeature f2 ) { int linkid1 = ( Integer ) f1 . getAttribute ( LINKID ) ; int linkid2 = ( Integer ) f2 . getAttribute ( LINKID ) ; if ( linkid1 < linkid2 ) { return - 1 ; } else if ( linkid1 > linkid2 ) { return 1 ; } else { return 0 ; } } | establish the position of each net point respect to the others |
17,596 | public static Color colorFromRbgString ( String rbgString ) { String [ ] split = rbgString . split ( "," ) ; if ( split . length < 3 || split . length > 4 ) { throw new IllegalArgumentException ( "Color string has to be of type r,g,b." ) ; } int r = ( int ) Double . parseDouble ( split [ 0 ] . trim ( ) ) ; int g = ( int ) Double . parseDouble ( split [ 1 ] . trim ( ) ) ; int b = ( int ) Double . parseDouble ( split [ 2 ] . trim ( ) ) ; Color c = null ; if ( split . length == 4 ) { int a = ( int ) Double . parseDouble ( split [ 3 ] . trim ( ) ) ; c = new Color ( r , g , b , a ) ; } else { c = new Color ( r , g , b ) ; } return c ; } | Converts a color string . |
17,597 | public static Color fromHex ( String hex ) { if ( hex . startsWith ( "#" ) ) { hex = hex . substring ( 1 ) ; } int length = hex . length ( ) ; int total = 6 ; if ( length < total ) { String token = hex ; int tokenLength = token . length ( ) ; for ( int i = 0 ; i < total ; i = i + tokenLength ) { hex += token ; } } int index = 0 ; String r = hex . substring ( index , index + 2 ) ; String g = hex . substring ( index + 2 , index + 4 ) ; String b = hex . substring ( index + 4 , index + total ) ; return new Color ( Integer . valueOf ( r , 16 ) , Integer . valueOf ( g , 16 ) , Integer . valueOf ( b , 16 ) ) ; } | Convert hex color to Color . |
17,598 | public int getFlowAt ( Direction direction ) { switch ( direction ) { case E : return eFlow ; case W : return wFlow ; case N : return nFlow ; case S : return sFlow ; case EN : return enFlow ; case NW : return nwFlow ; case WS : return wsFlow ; case SE : return seFlow ; default : throw new IllegalArgumentException ( ) ; } } | Get the value of the flow in one of the surrounding direction . |
17,599 | public FlowNode goDownstream ( ) { if ( isValid ) { Direction direction = Direction . forFlow ( flow ) ; if ( direction != null ) { FlowNode nextNode = new FlowNode ( gridIter , cols , rows , col + direction . col , row + direction . row ) ; if ( nextNode . isValid ) { return nextNode ; } } } return null ; } | Get the next downstream node . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.