idx int64 0 165k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
17,400 | public static void uploadFile ( Session session , String localFile , String remoteFile ) throws Exception { boolean ptimestamp = true ; String command = "scp " + ( ptimestamp ? "-p" : "" ) + " -t " + remoteFile ; Channel channel = session . openChannel ( "exec" ) ; ( ( ChannelExec ) channel ) . setCommand ( command ) ; OutputStream out = channel . getOutputStream ( ) ; InputStream in = channel . getInputStream ( ) ; channel . connect ( ) ; if ( checkAck ( in ) != 0 ) { throw new RuntimeException ( ) ; } File _lfile = new File ( localFile ) ; if ( ptimestamp ) { command = "T " + ( _lfile . lastModified ( ) / 1000 ) + " 0" ; command += ( " " + ( _lfile . lastModified ( ) / 1000 ) + " 0\n" ) ; out . write ( command . getBytes ( ) ) ; out . flush ( ) ; if ( checkAck ( in ) != 0 ) { throw new RuntimeException ( ) ; } } long filesize = _lfile . length ( ) ; command = "C0644 " + filesize + " " ; if ( localFile . lastIndexOf ( '/' ) > 0 ) { command += localFile . substring ( localFile . lastIndexOf ( '/' ) + 1 ) ; } else { command += localFile ; } command += "\n" ; out . write ( command . getBytes ( ) ) ; out . flush ( ) ; if ( checkAck ( in ) != 0 ) { throw new RuntimeException ( ) ; } FileInputStream fis = new FileInputStream ( localFile ) ; byte [ ] buf = new byte [ 1024 ] ; while ( true ) { int len = fis . read ( buf , 0 , buf . length ) ; if ( len <= 0 ) break ; out . write ( buf , 0 , len ) ; } fis . close ( ) ; fis = null ; buf [ 0 ] = 0 ; out . write ( buf , 0 , 1 ) ; out . flush ( ) ; if ( checkAck ( in ) != 0 ) { throw new RuntimeException ( ) ; } out . close ( ) ; channel . disconnect ( ) ; } | Upload a file to the remote host via scp . |
17,401 | public int readObjectHeaderV15 ( int [ ] data , int offset ) throws Exception { int bitPos = offset ; Integer mode = ( Integer ) DwgUtil . getBits ( data , 2 , bitPos ) ; bitPos = bitPos + 2 ; setMode ( mode . intValue ( ) ) ; Vector v = DwgUtil . getBitLong ( data , bitPos ) ; bitPos = ( ( Integer ) v . get ( 0 ) ) . intValue ( ) ; int rnum = ( ( Integer ) v . get ( 1 ) ) . intValue ( ) ; setNumReactors ( rnum ) ; v = DwgUtil . testBit ( data , bitPos ) ; bitPos = ( ( Integer ) v . get ( 0 ) ) . intValue ( ) ; boolean nolinks = ( ( Boolean ) v . get ( 1 ) ) . booleanValue ( ) ; setNoLinks ( nolinks ) ; v = DwgUtil . getBitShort ( data , bitPos ) ; bitPos = ( ( Integer ) v . get ( 0 ) ) . intValue ( ) ; int color = ( ( Integer ) v . get ( 1 ) ) . intValue ( ) ; setColor ( color ) ; v = DwgUtil . getBitDouble ( data , bitPos ) ; bitPos = ( ( Integer ) v . get ( 0 ) ) . intValue ( ) ; float ltscale = ( ( Double ) v . get ( 1 ) ) . floatValue ( ) ; Integer ltflag = ( Integer ) DwgUtil . getBits ( data , 2 , bitPos ) ; bitPos = bitPos + 2 ; Integer psflag = ( Integer ) DwgUtil . getBits ( data , 2 , bitPos ) ; bitPos = bitPos + 2 ; v = DwgUtil . getBitShort ( data , bitPos ) ; bitPos = ( ( Integer ) v . get ( 0 ) ) . intValue ( ) ; int invis = ( ( Integer ) v . get ( 1 ) ) . intValue ( ) ; v = DwgUtil . getRawChar ( data , bitPos ) ; bitPos = ( ( Integer ) v . get ( 0 ) ) . intValue ( ) ; int weight = ( ( Integer ) v . get ( 1 ) ) . intValue ( ) ; return bitPos ; } | Reads the header of an object in a DWG file Version 15 |
17,402 | public List validateSLD ( InputSource xml ) { URL schemaURL = SLDValidator . class . getResource ( "/schemas/sld/StyledLayerDescriptor.xsd" ) ; return ResponseUtils . validate ( xml , schemaURL , false , entityResolver ) ; } | validate a . sld against the schema |
17,403 | public static void pipeMagnitude ( double [ ] magnitude , double [ ] whereDrain , IHMProgressMonitor pm ) { int count = 0 ; int length = magnitude . length ; for ( int i = 0 ; i < length ; i ++ ) { count = 0 ; magnitude [ i ] ++ ; int k = i ; while ( whereDrain [ k ] != Constants . OUT_INDEX_PIPE && count < length ) { k = ( int ) whereDrain [ k ] ; magnitude [ k ] ++ ; count ++ ; } if ( count > length ) { pm . errorMessage ( msg . message ( "trentoP.error.pipe" ) ) ; throw new IllegalArgumentException ( msg . message ( "trentoP.error.pipe" ) ) ; } } } | Calculate the magnitudo of the several drainage area . |
17,404 | public static boolean verifyProjectType ( SimpleFeatureType schema , IHMProgressMonitor pm ) { String searchedField = PipesTrentoP . ID . getAttributeName ( ) ; verifyFeatureKey ( findAttributeName ( schema , searchedField ) , searchedField , pm ) ; searchedField = PipesTrentoP . DRAIN_AREA . getAttributeName ( ) ; verifyFeatureKey ( findAttributeName ( schema , searchedField ) , searchedField , pm ) ; searchedField = PipesTrentoP . INITIAL_ELEVATION . getAttributeName ( ) ; verifyFeatureKey ( findAttributeName ( schema , searchedField ) , searchedField , pm ) ; searchedField = PipesTrentoP . FINAL_ELEVATION . getAttributeName ( ) ; verifyFeatureKey ( findAttributeName ( schema , searchedField ) , searchedField , pm ) ; searchedField = PipesTrentoP . RUNOFF_COEFFICIENT . getAttributeName ( ) ; verifyFeatureKey ( findAttributeName ( schema , searchedField ) , searchedField , pm ) ; searchedField = PipesTrentoP . KS . getAttributeName ( ) ; verifyFeatureKey ( findAttributeName ( schema , searchedField ) , searchedField , pm ) ; searchedField = PipesTrentoP . MINIMUM_PIPE_SLOPE . getAttributeName ( ) ; verifyFeatureKey ( findAttributeName ( schema , searchedField ) , searchedField , pm ) ; searchedField = PipesTrentoP . AVERAGE_RESIDENCE_TIME . getAttributeName ( ) ; verifyFeatureKey ( findAttributeName ( schema , searchedField ) , searchedField , pm ) ; searchedField = PipesTrentoP . PIPE_SECTION_TYPE . getAttributeName ( ) ; verifyFeatureKey ( findAttributeName ( schema , searchedField ) , searchedField , pm ) ; searchedField = PipesTrentoP . AVERAGE_SLOPE . getAttributeName ( ) ; verifyFeatureKey ( findAttributeName ( schema , searchedField ) , searchedField , pm ) ; searchedField = PipesTrentoP . PER_AREA . getAttributeName ( ) ; String attributeName = findAttributeName ( schema , searchedField ) ; if ( attributeName != null ) { return true ; } return false ; } | Verify the schema . |
17,405 | private static void verifyFeatureKey ( String key , String searchedField , IHMProgressMonitor pm ) { if ( key == null ) { if ( pm != null ) { pm . errorMessage ( msg . message ( "trentoP.error.featureKey" ) + searchedField ) ; } throw new IllegalArgumentException ( msg . message ( "trentoP.error.featureKey" ) + searchedField ) ; } } | Verify if there is a key of a FeatureCollections . |
17,406 | public static ValidationMessage < Origin > message ( LineReader lineReader , Severity severity , String messageKey , Object ... params ) { return message ( lineReader . getCurrentLineNumber ( ) , severity , messageKey , params ) ; } | Creates a validation message . |
17,407 | public static void setCDSTranslationReport ( ExtendedResult < CdsFeatureTranslationCheck . TranslationReportInfo > cdsCheckResult ) { try { CdsFeatureTranslationCheck . TranslationReportInfo translationInfo = cdsCheckResult . getExtension ( ) ; StringWriter translationReportWriter = new StringWriter ( ) ; TranslationResult translationResult = translationInfo . getTranslationResult ( ) ; CdsFeature cdsFeature = translationInfo . getCdsFeature ( ) ; if ( translationResult != null && cdsFeature != null ) { String providedTranslation = cdsFeature . getTranslation ( ) ; new TranslationResultWriter ( translationResult , providedTranslation ) . write ( translationReportWriter ) ; String translationReport = translationReportWriter . toString ( ) ; StringWriter reportString = new StringWriter ( ) ; reportString . append ( "The results of the automatic translation are shown below.\n\n" ) ; CompoundLocation < Location > compoundLocation = translationInfo . getCdsFeature ( ) . getLocations ( ) ; reportString . append ( "Feature location : " ) ; reportString . append ( FeatureLocationWriter . renderCompoundLocation ( compoundLocation ) ) . append ( "\n" ) ; reportString . append ( "Base count : " ) . append ( Integer . toString ( translationResult . getBaseCount ( ) ) ) . append ( "\n" ) ; reportString . append ( "Translation length : " ) . append ( Integer . toString ( translationResult . getTranslation ( ) . length ( ) ) ) . append ( "\n\n" ) ; reportString . append ( "Translation table info : " ) ; TranslationTable translationTable = translationInfo . getTranslationTable ( ) ; String translationTableName = "NOT SET" ; String translationTableNumber = "NOT SET" ; if ( translationTable != null ) { translationTableName = translationTable . getName ( ) ; translationTableNumber = Integer . toString ( translationTable . getNumber ( ) ) ; } reportString . append ( "Table name - \"" ) . append ( translationTableName ) . append ( "\" " ) ; reportString . append ( "Table number - \"" ) . append ( translationTableNumber ) . append ( "\"\n\n" ) ; if ( translationReport != null && ! translationReport . isEmpty ( ) ) { reportString . append ( "The amino acid codes immediately below the dna triplets is the actual " + "translation based on the information you provided." ) ; List < Qualifier > providedtranslations = translationInfo . getCdsFeature ( ) . getQualifiers ( Qualifier . TRANSLATION_QUALIFIER_NAME ) ; if ( ! providedtranslations . isEmpty ( ) ) { reportString . append ( "\nThe second row of amino acid codes is the translation you provided in the CDS " + "feature. These translations should match." ) ; } reportString . append ( "\n\n" ) ; reportString . append ( translationReport ) ; } else { reportString . append ( "No translation made\n\n" ) ; } cdsCheckResult . setReportMessage ( reportString . toString ( ) ) ; for ( ValidationMessage message : cdsCheckResult . getMessages ( ) ) { message . setReportMessage ( reportString . toString ( ) ) ; } } } catch ( IOException e ) { e . printStackTrace ( ) ; } } | Takes all the messages in a CdsFeatureTranslationCheck ExtendedResult ValidationResult object and writes a report for the CDS translation . Uses extra information from the ExtendedResult . Have put this here as it uses Writers from the FF package and the embl - api - core package does not have access to these . |
17,408 | public void writeTemplateSpreadsheetDownloadFile ( List < TemplateTokenInfo > tokenNames , TemplateVariablesSet variablesSet , String filePath ) throws TemplateException { prepareWriter ( filePath ) ; writeDownloadSpreadsheetHeader ( tokenNames ) ; for ( int i = 1 ; i < variablesSet . getEntryCount ( ) + 1 ; i ++ ) { TemplateVariables entryVariables = variablesSet . getEntryValues ( i ) ; writeSpreadsheetVariableRow ( tokenNames , i , entryVariables ) ; } flushAndCloseWriter ( ) ; } | Writes the download file for variables for spreadsheet import |
17,409 | public void writeLargeTemplateSpreadsheetDownloadFile ( List < TemplateTokenInfo > tokenNames , int entryCount , TemplateVariables constants , String filePath ) throws TemplateException { prepareWriter ( filePath ) ; writeDownloadSpreadsheetHeader ( tokenNames ) ; for ( int i = 1 ; i < entryCount + 1 ; i ++ ) { writeSpreadsheetVariableRow ( tokenNames , i , constants ) ; } flushAndCloseWriter ( ) ; } | Used to write spreadsheets where entry number exceeds the MEGABULK size . Does not use the variables map stored in the database just writes constants . |
17,410 | public void writeDownloadSpreadsheetHeader ( List < TemplateTokenInfo > variableTokenNames ) { StringBuilder headerBuilder = new StringBuilder ( ) ; headerBuilder . append ( UPLOAD_COMMENTS ) ; headerBuilder . append ( "\n" ) ; for ( TemplateTokenInfo tokenInfo : variableTokenNames ) { if ( tokenInfo . getName ( ) . equals ( TemplateProcessorConstants . COMMENTS_TOKEN ) ) { headerBuilder . append ( "#The field '" + tokenInfo . getDisplayName ( ) + "' allows return characters. To add return characters add '<br>'; e.g. line1<br>line2" ) ; headerBuilder . append ( "\n" ) ; } } headerBuilder . append ( HEADER_TOKEN ) ; headerBuilder . append ( UPLOAD_DELIMITER ) ; for ( TemplateTokenInfo variable : variableTokenNames ) { headerBuilder . append ( variable . getDisplayName ( ) ) ; headerBuilder . append ( UPLOAD_DELIMITER ) ; } String headerLine = headerBuilder . toString ( ) ; headerLine = headerLine . substring ( 0 , headerLine . length ( ) - 1 ) ; this . lineWriter . println ( headerLine ) ; } | writes the header for the example download spreadsheet |
17,411 | public void process ( ) throws Exception { if ( ! concatOr ( outTca == null , doReset ) ) { return ; } checkNull ( inPit , inFlow ) ; HashMap < String , Double > regionMap = CoverageUtilities . getRegionParamsFromGridCoverage ( inPit ) ; cols = regionMap . get ( CoverageUtilities . COLS ) . intValue ( ) ; rows = regionMap . get ( CoverageUtilities . ROWS ) . intValue ( ) ; xRes = regionMap . get ( CoverageUtilities . XRES ) ; yRes = regionMap . get ( CoverageUtilities . YRES ) ; RenderedImage pitfillerRI = inPit . getRenderedImage ( ) ; WritableRaster pitWR = CoverageUtilities . renderedImage2WritableRaster ( pitfillerRI , false ) ; RenderedImage flowRI = inFlow . getRenderedImage ( ) ; WritableRaster flowWR = CoverageUtilities . renderedImage2WritableRaster ( flowRI , true ) ; WritableRaster tca3dWR = CoverageUtilities . createWritableRaster ( cols , rows , null , null , doubleNovalue ) ; tca3dWR = area3d ( pitWR , flowWR , tca3dWR ) ; outTca = CoverageUtilities . buildCoverage ( "tca3d" , tca3dWR , regionMap , inPit . getCoordinateReferenceSystem ( ) ) ; } | Calculates total contributing areas |
17,412 | public void readDwgSeqendV15 ( int [ ] data , int offset ) throws Exception { int bitPos = offset ; bitPos = readObjectHeaderV15 ( data , bitPos ) ; bitPos = readObjectTailV15 ( data , bitPos ) ; } | Read a Seqend in the DWG format Version 15 |
17,413 | public boolean isDownStreamOf ( PfafstetterNumber pfafstetterNumber ) { int lastDot = pfafstetterNumberString . lastIndexOf ( '.' ) ; String pre = pfafstetterNumberString . substring ( 0 , lastDot + 1 ) ; String lastNum = pfafstetterNumberString . substring ( lastDot + 1 , pfafstetterNumberString . length ( ) ) ; int lastNumInt = Integer . parseInt ( lastNum ) ; if ( lastNumInt % 2 == 0 ) { return false ; } else { String pfaff = pfafstetterNumber . toString ( ) ; if ( pfaff . startsWith ( pre ) ) { String lastPart = pfaff . substring ( lastDot + 1 , pfaff . length ( ) ) ; String lastPartParent = StringUtilities . REGEX_PATTER_DOT . split ( lastPart ) [ 0 ] ; if ( Integer . parseInt ( lastPartParent ) >= lastNumInt ) { return true ; } } } return false ; } | Checks if the actual pfafstetter object is downstream or not of the passed argument |
17,414 | public synchronized static boolean areConnectedUpstream ( PfafstetterNumber p1 , PfafstetterNumber p2 ) { List < Integer > p1OrdersList = p1 . getOrdersList ( ) ; List < Integer > p2OrdersList = p2 . getOrdersList ( ) ; int levelDiff = p1OrdersList . size ( ) - p2OrdersList . size ( ) ; if ( levelDiff == 0 ) { if ( p1 . toStringUpToLastLevel ( ) . equals ( p2 . toStringUpToLastLevel ( ) ) ) { int p1Last = p1OrdersList . get ( p1OrdersList . size ( ) - 1 ) ; int p2Last = p2OrdersList . get ( p2OrdersList . size ( ) - 1 ) ; if ( p2Last == p1Last + 1 || p2Last == p1Last + 2 ) { return p1Last % 2 != 0 ; } } } else if ( levelDiff == - 1 ) { if ( p2 . toString ( ) . startsWith ( p1 . toStringUpToLastLevel ( ) ) ) { int p2Last = p2OrdersList . get ( p2OrdersList . size ( ) - 1 ) ; if ( p2Last != 1 ) { return false ; } int p1Last = p1OrdersList . get ( p1OrdersList . size ( ) - 1 ) ; int p2LastMinus1 = p2OrdersList . get ( p2OrdersList . size ( ) - 2 ) ; if ( p2LastMinus1 == p1Last + 1 || p2Last == p1Last + 2 ) { return p1Last % 2 != 0 ; } } } return false ; } | Checks if two pfafstetter are connected upstream i . e . p1 is more downstream than p2 |
17,415 | private Number setFeatureField ( SimpleFeature pipe , String key ) { Number field = ( ( Number ) pipe . getAttribute ( key ) ) ; if ( field == null ) { pm . errorMessage ( msg . message ( "trentoP.error.number" ) + key ) ; throw new IllegalArgumentException ( msg . message ( "trentoP.error.number" ) + key ) ; } return field ; } | Check if there is the field in a SimpleFeature and if it s a Number . |
17,416 | public void designPipe ( double [ ] [ ] diameters , double tau , double g , double maxd , double c , StringBuilder strWarnings ) { switch ( this . pipeSectionType ) { case 1 : designCircularPipe ( diameters , tau , g , maxd , strWarnings ) ; break ; case 2 : designRectangularPipe ( tau , g , maxd , c , strWarnings ) ; break ; case 3 : designTrapeziumPipe ( tau , g , maxd , c , strWarnings ) ; break ; default : designCircularPipe ( diameters , tau , g , maxd , strWarnings ) ; break ; } } | Calculate the dimension of the pipes . |
17,417 | private void designCircularPipe ( double [ ] [ ] diameters , double tau , double g , double maxd , StringBuilder strWarnings ) { double newtheta ; double naturalslope ; double D ; double [ ] dD = new double [ 1 ] ; double ms ; newtheta = getDiameter ( diameters , tau , g , dD , maxd , strWarnings ) ; naturalslope = METER2CM * ( getInitialElevation ( ) - getFinalElevation ( ) ) / getLenght ( ) ; ms = getMinimumPipeSlope ( ) ; if ( naturalslope < 0 ) { strWarnings . append ( msg . message ( "trentoP.warning.slope" ) + id ) ; } if ( naturalslope < ms ) { naturalslope = ms ; } if ( naturalslope > pipeSlope ) { pipeSlope = ( naturalslope ) ; newtheta = getDiameterI ( diameters , naturalslope , g , dD , maxd , strWarnings ) ; } D = diameter ; meanSpeed = ( ( 8 * discharge ) / ( CUBICMETER2LITER * D * D * ( newtheta - sin ( newtheta ) ) / METER2CMSQUARED ) ) ; depthInitialPipe = ( getInitialElevation ( ) - minimumDepth - ( D + 2 * dD [ 0 ] ) / METER2CM ) ; depthFinalPipe = ( depthInitialPipe - getLenght ( ) * pipeSlope / METER2CM ) ; initialFreesurface = depthInitialPipe + emptyDegree * D / METER2CM + dD [ 0 ] / METER2CM ; finalFreesurface = depthFinalPipe + emptyDegree * D / METER2CM + dD [ 0 ] / METER2CM ; } | Dimensiona la tubazione . |
17,418 | private double getDiameter ( double [ ] [ ] diameters , double tau , double g , double [ ] dD , double maxd , StringBuilder strWarnings ) { double B ; double thta ; double oldD ; double D = 0 ; double known ; double newtheta ; double newrh ; B = ( discharge * sqrt ( WSPECIFICWEIGHT / tau ) ) / ( CUBICMETER2LITER * getKs ( ) ) ; thta = 2 * acos ( 1 - 2 * g ) ; oldD = TWO_TWENTYOVERTHIRTEEN * pow ( B , SIXOVERTHIRTEEN ) / ( pow ( ( 1 - sin ( thta ) / thta ) , ONEOVERTHIRTEEN ) * pow ( thta - sin ( thta ) , SIXOVERTHIRTEEN ) ) ; if ( oldD < diameters [ diameters . length - 1 ] [ 0 ] ) { int j = 0 ; for ( j = 0 ; j < diameters . length ; j ++ ) { D = diameters [ j ] [ 0 ] ; if ( D >= oldD ) break ; } if ( D < maxd ) { D = maxd ; } diameter = ( D ) ; dD [ 0 ] = diameters [ j ] [ 1 ] ; known = ( B * TWO_TENOVERTHREE ) / pow ( D / METER2CM , THIRTHEENOVERSIX ) ; newtheta = Utility . thisBisection ( thta , known , ONEOVERSIX , minG , accuracy , jMax , pm , strWarnings ) ; if ( newtheta > thta ) { strWarnings . append ( msg . message ( "trentoP.warning.bisection" ) + id ) ; } } else { D = oldD ; diameter = D ; newtheta = thta ; } emptyDegree = 0.5 * ( 1 - cos ( newtheta / 2 ) ) ; newrh = 0.25 * D * ( 1 - sin ( newtheta ) / newtheta ) ; pipeSlope = ( tau / ( WSPECIFICWEIGHT * newrh ) * METER2CMSQUARED ) ; return newtheta ; } | Dimensiona il tubo imponendo uno sforzo tangenziale al fondo . |
17,419 | private void designTrapeziumPipe ( double tau , double g , double maxd , double c , StringBuilder strWarnings ) { double base ; double naturalSlope ; double D ; double ms ; base = getHeight2 ( tau , g , maxd , c ) ; ms = getMinimumPipeSlope ( ) ; naturalSlope = METER2CM * ( initialElevation - finalElevation ) / lenght ; if ( naturalSlope < 0 ) { strWarnings . append ( msg . message ( "trentoP.warning.slope" ) + id ) ; } if ( naturalSlope < ms ) { naturalSlope = ms ; } if ( naturalSlope > pipeSlope ) { pipeSlope = naturalSlope ; base = getHeight2I ( naturalSlope , g , maxd , c ) ; } D = diameter ; meanSpeed = ( discharge / CUBICMETER2LITER ) / ( emptyDegree * D * base / METER2CMSQUARED ) ; depthInitialPipe = getInitialElevation ( ) - diameter / METER2CM ; depthFinalPipe = depthInitialPipe - getLenght ( ) * pipeSlope / METER2CM ; initialFreesurface = depthInitialPipe + emptyDegree * D / METER2CM ; finalFreesurface = depthFinalPipe + emptyDegree * D / METER2CM ; } | Chiama altre subroutine per dimensionare una sezione di tipo 3 ossia trapezioidale . |
17,420 | public double verifyEmptyDegree ( StringBuilder strWarnings , double q ) { double B ; double thta ; double known ; double newtheta = 0 ; B = ( q * sqrt ( WSPECIFICWEIGHT / 2.8 ) ) / ( CUBICMETER2LITER * getKs ( ) ) ; thta = 2 * acos ( 1 - 2 * 0.8 ) ; known = ( B * TWO_TENOVERTHREE ) / pow ( diameterToVerify / METER2CM , THIRTHEENOVERSIX ) ; newtheta = Utility . thisBisection ( thta , known , ONEOVERSIX , minG , accuracy , jMax , pm , strWarnings ) ; emptyDegree = 0.5 * ( 1 - cos ( newtheta / 2 ) ) ; return newtheta ; } | Verify if the empty degree is greather than the 0 . 8 . |
17,421 | public static void addGpsLogDataPoint ( Connection connection , OmsGeopaparazziProject3To4Converter . GpsPoint point , long gpslogId ) throws Exception { Date timestamp = ETimeUtilities . INSTANCE . TIME_FORMATTER_LOCAL . parse ( point . utctime ) ; String insertSQL = "INSERT INTO " + TableDescriptions . TABLE_GPSLOG_DATA + "(" + TableDescriptions . GpsLogsDataTableFields . COLUMN_ID . getFieldName ( ) + ", " + TableDescriptions . GpsLogsDataTableFields . COLUMN_LOGID . getFieldName ( ) + ", " + TableDescriptions . GpsLogsDataTableFields . COLUMN_DATA_LON . getFieldName ( ) + ", " + TableDescriptions . GpsLogsDataTableFields . COLUMN_DATA_LAT . getFieldName ( ) + ", " + TableDescriptions . GpsLogsDataTableFields . COLUMN_DATA_ALTIM . getFieldName ( ) + ", " + TableDescriptions . GpsLogsDataTableFields . COLUMN_DATA_TS . getFieldName ( ) + ") VALUES" + "(?,?,?,?,?,?)" ; try ( PreparedStatement writeStatement = connection . prepareStatement ( insertSQL ) ) { writeStatement . setLong ( 1 , point . id ) ; writeStatement . setLong ( 2 , gpslogId ) ; writeStatement . setDouble ( 3 , point . lon ) ; writeStatement . setDouble ( 4 , point . lat ) ; writeStatement . setDouble ( 5 , point . altim ) ; writeStatement . setLong ( 6 , timestamp . getTime ( ) ) ; writeStatement . executeUpdate ( ) ; } } | Adds a new XY entry to the gps table . |
17,422 | public static List < GpsLog > getLogsList ( IHMConnection connection ) throws Exception { List < GpsLog > logsList = new ArrayList < > ( ) ; String sql = "select " + GpsLogsTableFields . COLUMN_ID . getFieldName ( ) + "," + GpsLogsTableFields . COLUMN_LOG_STARTTS . getFieldName ( ) + "," + GpsLogsTableFields . COLUMN_LOG_ENDTS . getFieldName ( ) + "," + GpsLogsTableFields . COLUMN_LOG_TEXT . getFieldName ( ) + " from " + TABLE_GPSLOGS ; try ( IHMStatement statement = connection . createStatement ( ) ; IHMResultSet rs = statement . executeQuery ( sql ) ; ) { statement . setQueryTimeout ( 30 ) ; while ( rs . next ( ) ) { long id = rs . getLong ( 1 ) ; long startDateTimeString = rs . getLong ( 2 ) ; long endDateTimeString = rs . getLong ( 3 ) ; String text = rs . getString ( 4 ) ; GpsLog log = new GpsLog ( ) ; log . id = id ; log . startTime = startDateTimeString ; log . endTime = endDateTimeString ; log . text = text ; logsList . add ( log ) ; } } return logsList ; } | Get the list of available logs . |
17,423 | public static void collectDataForLog ( IHMConnection connection , GpsLog log ) throws Exception { long logId = log . id ; String query = "select " + GpsLogsDataTableFields . COLUMN_DATA_LAT . getFieldName ( ) + "," + GpsLogsDataTableFields . COLUMN_DATA_LON . getFieldName ( ) + "," + GpsLogsDataTableFields . COLUMN_DATA_ALTIM . getFieldName ( ) + "," + GpsLogsDataTableFields . COLUMN_DATA_TS . getFieldName ( ) + " from " + TABLE_GPSLOG_DATA + " where " + GpsLogsDataTableFields . COLUMN_LOGID . getFieldName ( ) + " = " + logId + " order by " + GpsLogsDataTableFields . COLUMN_DATA_TS . getFieldName ( ) ; try ( IHMStatement newStatement = connection . createStatement ( ) ; IHMResultSet result = newStatement . executeQuery ( query ) ; ) { newStatement . setQueryTimeout ( 30 ) ; while ( result . next ( ) ) { double lat = result . getDouble ( 1 ) ; double lon = result . getDouble ( 2 ) ; double altim = result . getDouble ( 3 ) ; long ts = result . getLong ( 4 ) ; GpsPoint gPoint = new GpsPoint ( ) ; gPoint . lon = lon ; gPoint . lat = lat ; gPoint . altim = altim ; gPoint . utctime = ts ; log . points . add ( gPoint ) ; } } } | Gather gps points data for a supplied log . |
17,424 | public static SshTunnelHandler openTunnel ( String remoteHost , String remoteSshUser , String remoteSshPwd , int localPort , int remotePort ) throws JSchException { int port = 22 ; JSch jsch = new JSch ( ) ; Session tunnelingSession = jsch . getSession ( remoteSshUser , remoteHost , port ) ; tunnelingSession . setPassword ( remoteSshPwd ) ; HMUserInfo lui = new HMUserInfo ( "" ) ; tunnelingSession . setUserInfo ( lui ) ; tunnelingSession . setConfig ( "StrictHostKeyChecking" , "no" ) ; tunnelingSession . setPortForwardingL ( localPort , "localhost" , remotePort ) ; tunnelingSession . connect ( ) ; tunnelingSession . openChannel ( "direct-tcpip" ) ; return new SshTunnelHandler ( tunnelingSession ) ; } | Open a tunnel to the remote host . |
17,425 | public static Vector getRawLong ( int [ ] data , int offset ) { Vector v = new Vector ( ) ; int val = 0 ; v . add ( new Integer ( offset + 32 ) ) ; v . add ( new Integer ( val ) ) ; return v ; } | Read a long value from a group of unsigned bytes |
17,426 | public static Vector getTextString ( int [ ] data , int offset ) throws Exception { int bitPos = offset ; int newBitPos = ( ( Integer ) DwgUtil . getBitShort ( data , bitPos ) . get ( 0 ) ) . intValue ( ) ; int len = ( ( Integer ) DwgUtil . getBitShort ( data , bitPos ) . get ( 1 ) ) . intValue ( ) ; bitPos = newBitPos ; int bitLen = len * 8 ; Object cosa = DwgUtil . getBits ( data , bitLen , bitPos ) ; String string ; if ( cosa instanceof byte [ ] ) { string = new String ( ( byte [ ] ) cosa ) ; } } | Read a String from a group of unsigned bytes |
17,427 | public Iterator < Compound > toRootOrder ( final Compound c ) { return new Iterator < Compound > ( ) { Compound curr ; TreeNode n = node ( c ) ; Compound parent = c ; public boolean hasNext ( ) { return ! n . isRoot ( ) ; } public Compound next ( ) { if ( hasNext ( ) ) { curr = parent ; parent = n . parent ; n = node ( n . parent ) ; return curr ; } else { throw new NoSuchElementException ( ) ; } } public void remove ( ) { throw new UnsupportedOperationException ( ) ; } } ; } | Returns all compounds from the Compound argument to the root of the tree following the path . |
17,428 | public void println ( String value ) { print ( value ) ; out . println ( ) ; out . flush ( ) ; newLine = true ; } | Print the string as the last value on the line . The value will be quoted if needed . |
17,429 | public void println ( String [ ] values ) { for ( int i = 0 ; i < values . length ; i ++ ) { print ( values [ i ] ) ; } out . println ( ) ; out . flush ( ) ; newLine = true ; } | Print a single line of comma separated values . The values will be quoted if needed . Quotes and newLine characters will be escaped . |
17,430 | public void printlnComment ( String comment ) { if ( this . strategy . isCommentingDisabled ( ) ) { return ; } if ( ! newLine ) { out . println ( ) ; } out . print ( this . strategy . getCommentStart ( ) ) ; out . print ( ' ' ) ; for ( int i = 0 ; i < comment . length ( ) ; i ++ ) { char c = comment . charAt ( i ) ; switch ( c ) { case '\r' : if ( i + 1 < comment . length ( ) && comment . charAt ( i + 1 ) == '\n' ) { i ++ ; } case '\n' : out . println ( ) ; out . print ( this . strategy . getCommentStart ( ) ) ; out . print ( ' ' ) ; break ; default : out . print ( c ) ; break ; } } out . println ( ) ; out . flush ( ) ; newLine = true ; } | Put a comment among the comma separated values . Comments will always begin on a new line and occupy a least one full line . The character specified to star comments and a space will be inserted at the beginning of each new line in the comment . |
17,431 | public void print ( String value ) { boolean quote = false ; if ( value . length ( ) > 0 ) { char c = value . charAt ( 0 ) ; if ( newLine && ( c < '0' || ( c > '9' && c < 'A' ) || ( c > 'Z' && c < 'a' ) || ( c > 'z' ) ) ) { quote = true ; } if ( c == ' ' || c == '\f' || c == '\t' ) { quote = true ; } for ( int i = 0 ; i < value . length ( ) ; i ++ ) { c = value . charAt ( i ) ; if ( c == '"' || c == this . strategy . getDelimiter ( ) || c == '\n' || c == '\r' ) { quote = true ; c = value . charAt ( value . length ( ) - 1 ) ; break ; } } if ( c == ' ' || c == '\f' || c == '\t' ) { quote = true ; } } else if ( newLine ) { quote = true ; } if ( newLine ) { newLine = false ; } else { out . print ( this . strategy . getDelimiter ( ) ) ; } if ( quote ) { out . print ( escapeAndQuote ( value ) ) ; } else { out . print ( value ) ; } out . flush ( ) ; } | Print the string as the next value on the line . The value will be quoted if needed . |
17,432 | private String escapeAndQuote ( String value ) { int count = 2 ; for ( int i = 0 ; i < value . length ( ) ; i ++ ) { switch ( value . charAt ( i ) ) { case '\"' : case '\n' : case '\r' : case '\\' : count ++ ; break ; default : break ; } } StringBuffer sb = new StringBuffer ( value . length ( ) + count ) ; sb . append ( strategy . getEncapsulator ( ) ) ; for ( int i = 0 ; i < value . length ( ) ; i ++ ) { char c = value . charAt ( i ) ; if ( c == strategy . getEncapsulator ( ) ) { sb . append ( '\\' ) . append ( c ) ; continue ; } switch ( c ) { case '\n' : sb . append ( "\\n" ) ; break ; case '\r' : sb . append ( "\\r" ) ; break ; case '\\' : sb . append ( "\\\\" ) ; break ; default : sb . append ( c ) ; } } sb . append ( strategy . getEncapsulator ( ) ) ; return sb . toString ( ) ; } | Enclose the value in quotes and escape the quote and comma characters that are inside . |
17,433 | public static double calculateSlope ( GridNode node , double flowValue ) { double value = doubleNovalue ; if ( ! isNovalue ( flowValue ) ) { int flowDir = ( int ) flowValue ; if ( flowDir != 10 ) { Direction direction = Direction . forFlow ( flowDir ) ; double distance = direction . getDistance ( node . xRes , node . yRes ) ; double currentElevation = node . elevation ; double nextElevation = node . getElevationAt ( direction ) ; value = ( currentElevation - nextElevation ) / distance ; } } return value ; } | Calculates the slope of a given flowdirection value in currentCol and currentRow . |
17,434 | public static String [ ] getAvailablePortNames ( ) { SerialPort [ ] ports = SerialPort . getCommPorts ( ) ; String [ ] portNames = new String [ ports . length ] ; for ( int i = 0 ; i < portNames . length ; i ++ ) { String systemPortName = ports [ i ] . getSystemPortName ( ) ; portNames [ i ] = systemPortName ; } return portNames ; } | Getter for the available serial ports . |
17,435 | public static boolean isThisAGpsPort ( String port ) throws Exception { SerialPort comPort = SerialPort . getCommPort ( port ) ; comPort . openPort ( ) ; comPort . setComPortTimeouts ( SerialPort . TIMEOUT_READ_SEMI_BLOCKING , 100 , 0 ) ; int waitTries = 0 ; int parseTries = 0 ; while ( true && waitTries ++ < 10 && parseTries < 2 ) { while ( comPort . bytesAvailable ( ) == 0 ) Thread . sleep ( 500 ) ; byte [ ] readBuffer = new byte [ comPort . bytesAvailable ( ) ] ; int numRead = comPort . readBytes ( readBuffer , readBuffer . length ) ; if ( numRead > 0 ) { String data = new String ( readBuffer ) ; String [ ] split = data . split ( "\n" ) ; for ( String line : split ) { if ( SentenceValidator . isSentence ( line ) ) { return true ; } } parseTries ++ ; } } return false ; } | Makes a blocking check to find out if the given port supplies GPS data . |
17,436 | public InvertibleMatrix inverse ( ) throws MatrixException { InvertibleMatrix inverse = new InvertibleMatrix ( nRows ) ; IdentityMatrix identity = new IdentityMatrix ( nRows ) ; for ( int c = 0 ; c < nCols ; ++ c ) { ColumnVector col = solve ( identity . getColumn ( c ) , true ) ; inverse . setColumn ( col , c ) ; } return inverse ; } | Compute the inverse of this matrix . |
17,437 | public double determinant ( ) throws MatrixException { decompose ( ) ; double determinant = ( ( exchangeCount & 1 ) == 0 ) ? 1 : - 1 ; for ( int i = 0 ; i < nRows ; ++ i ) { int pi = permutation [ i ] ; determinant *= LU . at ( pi , i ) ; } return determinant ; } | Compute the determinant . |
17,438 | public double norm ( ) { double sum = 0 ; for ( int r = 0 ; r < nRows ; ++ r ) { for ( int c = 0 ; c < nCols ; ++ c ) { double v = values [ r ] [ c ] ; sum += v * v ; } } return ( double ) Math . sqrt ( sum ) ; } | Compute the Euclidean norm of this matrix . |
17,439 | private static boolean isleap ( double gpsTime ) { boolean isLeap = false ; double [ ] leaps = getleaps ( ) ; for ( int i = 0 ; i < leaps . length ; i += 1 ) { if ( gpsTime == leaps [ i ] ) { isLeap = true ; break ; } } return isLeap ; } | Test to see if a GPS second is a leap second |
17,440 | private static int countleaps ( double gpsTime , boolean accum_leaps ) { int i , nleaps ; double [ ] leaps = getleaps ( ) ; nleaps = 0 ; if ( accum_leaps ) { for ( i = 0 ; i < leaps . length ; i += 1 ) { if ( gpsTime + i >= leaps [ i ] ) { nleaps += 1 ; } } } else { for ( i = 0 ; i < leaps . length ; i += 1 ) { if ( gpsTime >= leaps [ i ] ) { nleaps += 1 ; } } } return nleaps ; } | Count number of leap seconds that have passed |
17,441 | private static boolean isunixtimeleap ( double unixTime ) { double gpsTime = unixTime - 315964800 ; gpsTime += countleaps ( gpsTime , true ) - 1 ; return isleap ( gpsTime ) ; } | Test to see if a unixtime second is a leap second |
17,442 | public static EGpsWeekDays gpsWeekTime2WeekDay ( double gpsWeekTime ) { int seconds = ( int ) gpsWeekTime ; EGpsWeekDays day4Seconds = EGpsWeekDays . getDay4Seconds ( seconds ) ; return day4Seconds ; } | Convert GPS Week Time to the day of the week . |
17,443 | public static String gpsWeekTime2ISO8601 ( double gpsWeekTime ) { DateTime gps2unix = gpsWeekTime2DateTime ( gpsWeekTime ) ; return gps2unix . toString ( ISO8601Formatter ) ; } | Convert GPS Time to ISO8601 time string . |
17,444 | private void updateComponents ( ) { updatingComponents = true ; Font font = getFont ( ) ; fontList . setSelectedValue ( font . getName ( ) , true ) ; sizeList . setSelectedValue ( font . getSize ( ) , true ) ; boldCheckBox . setSelected ( font . isBold ( ) ) ; italicCheckBox . setSelected ( font . isItalic ( ) ) ; if ( previewText == null ) { previewLabel . setText ( font . getName ( ) ) ; } Font oldValue = previewLabel . getFont ( ) ; previewLabel . setFont ( font ) ; firePropertyChange ( "font" , oldValue , font ) ; updatingComponents = false ; } | Updates the font in the preview component according to the selected values . |
17,445 | public void setSelectionModel ( FontSelectionModel newModel ) { FontSelectionModel oldModel = selectionModel ; selectionModel = newModel ; oldModel . removeChangeListener ( labelUpdater ) ; newModel . addChangeListener ( labelUpdater ) ; firePropertyChange ( "selectionModel" , oldModel , newModel ) ; } | Set the model containing the selected font . |
17,446 | protected void fireChangeListeners ( ) { ChangeEvent ev = new ChangeEvent ( this ) ; Object [ ] l = listeners . getListeners ( ChangeListener . class ) ; for ( Object listener : l ) { ( ( ChangeListener ) listener ) . stateChanged ( ev ) ; } } | Fires the listeners registered with this model . |
17,447 | public void process ( ) throws Exception { if ( ! concatOr ( outPit == null , doReset ) ) { return ; } checkNull ( inElev ) ; HashMap < String , Double > regionMap = CoverageUtilities . getRegionParamsFromGridCoverage ( inElev ) ; nCols = regionMap . get ( CoverageUtilities . COLS ) . intValue ( ) ; nRows = regionMap . get ( CoverageUtilities . ROWS ) . intValue ( ) ; xRes = regionMap . get ( CoverageUtilities . XRES ) ; yRes = regionMap . get ( CoverageUtilities . YRES ) ; elevationIter = CoverageUtilities . getRandomIterator ( inElev ) ; WritableRaster pitRaster = CoverageUtilities . createWritableRaster ( nCols , nRows , null , null , null ) ; pitIter = CoverageUtilities . getWritableRandomIterator ( pitRaster ) ; for ( int i = 0 ; i < nRows ; i ++ ) { if ( pm . isCanceled ( ) ) { return ; } for ( int j = 0 ; j < nCols ; j ++ ) { double value = elevationIter . getSampleDouble ( j , i , 0 ) ; if ( ! isNovalue ( value ) ) { pitIter . setSample ( j , i , 0 , value ) ; } else { pitIter . setSample ( j , i , 0 , PITNOVALUE ) ; } } } flood ( ) ; if ( pm . isCanceled ( ) ) { return ; } for ( int i = 0 ; i < nRows ; i ++ ) { if ( pm . isCanceled ( ) ) { return ; } for ( int j = 0 ; j < nCols ; j ++ ) { if ( dir [ j ] [ i ] == 0 ) { return ; } double value = pitIter . getSampleDouble ( j , i , 0 ) ; if ( value == PITNOVALUE || isNovalue ( value ) ) { pitIter . setSample ( j , i , 0 , doubleNovalue ) ; } } } pitIter . done ( ) ; outPit = CoverageUtilities . buildCoverage ( "pitfiller" , pitRaster , regionMap , inElev . getCoordinateReferenceSystem ( ) ) ; } | The pitfiller algorithm . |
17,448 | private void flood ( ) throws Exception { pitsStackSize = ( int ) ( nCols * nRows * 0.1 ) ; pstack = pitsStackSize ; dn = new int [ pitsStackSize ] ; currentPitRows = new int [ pitsStackSize ] ; currentPitCols = new int [ pitsStackSize ] ; ipool = new int [ pstack ] ; jpool = new int [ pstack ] ; firstCol = 0 ; firstRow = 0 ; lastCol = nCols ; lastRow = nRows ; setdf ( ) ; } | Takes the elevation matrix and calculate a matrix with pits filled using the flooding algorithm . |
17,449 | private void addPitToStack ( int row , int col ) { currentPitsCount = currentPitsCount + 1 ; if ( currentPitsCount >= pitsStackSize ) { pitsStackSize = ( int ) ( pitsStackSize + nCols * nRows * .1 ) + 2 ; currentPitRows = realloc ( currentPitRows , pitsStackSize ) ; currentPitCols = realloc ( currentPitCols , pitsStackSize ) ; dn = realloc ( dn , pitsStackSize ) ; } currentPitRows [ currentPitsCount ] = row ; currentPitCols [ currentPitsCount ] = col ; } | Adds a pit position to the stack . |
17,450 | private int resolveFlats ( int pitsCount ) { int stillPitsCount ; currentPitsCount = pitsCount ; do { if ( pm . isCanceled ( ) ) { return - 1 ; } pitsCount = currentPitsCount ; currentPitsCount = 0 ; for ( int ip = 1 ; ip <= pitsCount ; ip ++ ) { dn [ ip ] = 0 ; } for ( int k = 1 ; k <= 8 ; k ++ ) { for ( int pitIndex = 1 ; pitIndex <= pitsCount ; pitIndex ++ ) { double elevDelta = pitIter . getSampleDouble ( currentPitCols [ pitIndex ] , currentPitRows [ pitIndex ] , 0 ) - pitIter . getSampleDouble ( currentPitCols [ pitIndex ] + DIR_WITHFLOW_EXITING_INVERTED [ k ] [ 0 ] , currentPitRows [ pitIndex ] + DIR_WITHFLOW_EXITING_INVERTED [ k ] [ 1 ] , 0 ) ; if ( ( elevDelta >= 0. ) && ( ( dir [ currentPitCols [ pitIndex ] + DIR_WITHFLOW_EXITING_INVERTED [ k ] [ 0 ] ] [ currentPitRows [ pitIndex ] + DIR_WITHFLOW_EXITING_INVERTED [ k ] [ 1 ] ] != 0 ) && ( dn [ pitIndex ] == 0 ) ) ) dn [ pitIndex ] = k ; } } stillPitsCount = 1 ; for ( int pitIndex = 1 ; pitIndex <= pitsCount ; pitIndex ++ ) { if ( dn [ pitIndex ] > 0 ) { dir [ currentPitCols [ pitIndex ] ] [ currentPitRows [ pitIndex ] ] = dn [ pitIndex ] ; } else { currentPitsCount ++ ; currentPitRows [ currentPitsCount ] = currentPitRows [ pitIndex ] ; currentPitCols [ currentPitsCount ] = currentPitCols [ pitIndex ] ; if ( pitIter . getSampleDouble ( currentPitCols [ currentPitsCount ] , currentPitRows [ currentPitsCount ] , 0 ) < pitIter . getSampleDouble ( currentPitCols [ stillPitsCount ] , currentPitRows [ stillPitsCount ] , 0 ) ) stillPitsCount = currentPitsCount ; } } } while ( currentPitsCount < pitsCount ) ; return stillPitsCount ; } | Try to find a drainage direction for undefinite cell . |
17,451 | private int pool ( int row , int col , int prevNPool ) { int in ; int jn ; int npool = prevNPool ; if ( apool [ col ] [ row ] <= 0 ) { if ( dir [ col ] [ row ] != - 1 ) { apool [ col ] [ row ] = pooln ; npool = npool + 1 ; if ( npool >= pstack ) { if ( pstack < nCols * nRows ) { pstack = ( int ) ( pstack + nCols * nRows * .1 ) ; if ( pstack > nCols * nRows ) { } ipool = realloc ( ipool , pstack ) ; jpool = realloc ( jpool , pstack ) ; } } ipool [ npool ] = row ; jpool [ npool ] = col ; for ( int k = 1 ; k <= 8 ; k ++ ) { in = row + DIR_WITHFLOW_EXITING_INVERTED [ k ] [ 1 ] ; jn = col + DIR_WITHFLOW_EXITING_INVERTED [ k ] [ 0 ] ; if ( ( ( dir [ jn ] [ in ] > 0 ) && ( ( dir [ jn ] [ in ] - k == 4 ) || ( dir [ jn ] [ in ] - k == - 4 ) ) ) || ( ( dir [ jn ] [ in ] == 0 ) && ( pitIter . getSampleDouble ( jn , in , 0 ) >= pitIter . getSampleDouble ( col , row , 0 ) ) ) ) { npool = pool ( in , jn , npool ) ; } } } } return npool ; } | function to compute pool recursively and at the same time determine the minimum elevation of the edge . |
17,452 | private void setDirection ( double pitValue , int row , int col , int [ ] [ ] dir , double [ ] fact ) { dir [ col ] [ row ] = 0 ; double smax = 0.0 ; for ( int k = 1 ; k <= 8 ; k ++ ) { int cn = col + DIR_WITHFLOW_EXITING_INVERTED [ k ] [ 0 ] ; int rn = row + DIR_WITHFLOW_EXITING_INVERTED [ k ] [ 1 ] ; double pitN = pitIter . getSampleDouble ( cn , rn , 0 ) ; if ( isNovalue ( pitN ) ) { dir [ col ] [ row ] = - 1 ; break ; } if ( dir [ col ] [ row ] != - 1 ) { double slope = fact [ k ] * ( pitValue - pitN ) ; if ( slope > smax ) { smax = slope ; dir [ col ] [ row ] = k ; } } } } | Calculate the drainage direction with the D8 method . |
17,453 | private double [ ] calculateDirectionFactor ( double dx , double dy ) { double [ ] fact = new double [ 9 ] ; for ( int k = 1 ; k <= 8 ; k ++ ) { fact [ k ] = 1.0 / ( Math . sqrt ( DIR_WITHFLOW_EXITING_INVERTED [ k ] [ 0 ] * dy * DIR_WITHFLOW_EXITING_INVERTED [ k ] [ 0 ] * dy + DIR_WITHFLOW_EXITING_INVERTED [ k ] [ 1 ] * DIR_WITHFLOW_EXITING_INVERTED [ k ] [ 1 ] * dx * dx ) ) ; } return fact ; } | Calculate the drainage direction factor . |
17,454 | private boolean assignFlowDirection ( GridNode current , GridNode diagonal , GridNode node1 , GridNode node2 ) { double diagonalSlope = abs ( current . getSlopeTo ( diagonal ) ) ; if ( node1 != null ) { double tmpSlope = abs ( diagonal . getSlopeTo ( node1 ) ) ; if ( diagonalSlope < tmpSlope ) { return false ; } } if ( node2 != null ) { double tmpSlope = abs ( diagonal . getSlopeTo ( node2 ) ) ; if ( diagonalSlope < tmpSlope ) { return false ; } } return true ; } | Checks if the path from the current to the first node is steeper than to the others . |
17,455 | private boolean nodeOk ( GridNode node ) { return node != null && ! assignedFlowsMap . isMarked ( node . col , node . row ) ; } | Checks if the node is ok . |
17,456 | public void run ( ) throws Exception { if ( ranges == null ) { throw new ModelsIllegalargumentException ( "No ranges have been defined for the parameter space." , this ) ; } createSwarm ( ) ; double [ ] previous = null ; while ( iterationStep <= maxIterations ) { updateSwarm ( ) ; if ( printStep ( ) ) { System . out . println ( prefix + " - ITER: " + iterationStep + " global best: " + globalBest + " - for positions: " + Arrays . toString ( globalBestLocations ) ) ; } if ( function . hasConverged ( globalBest , globalBestLocations , previous ) ) { break ; } previous = globalBestLocations . clone ( ) ; } } | Run the particle swarm engine . |
17,457 | public static boolean parametersInRange ( double [ ] parameters , double [ ] ... ranges ) { for ( int i = 0 ; i < ranges . length ; i ++ ) { if ( ! NumericsUtilities . isBetween ( parameters [ i ] , ranges [ i ] ) ) { return false ; } } return true ; } | Checks if the parameters are in the ranges . |
17,458 | public static < T > T convert ( Object from , Class < ? extends T > to , Params arg ) { if ( from == null ) { throw new NullPointerException ( "from" ) ; } if ( to == null ) { throw new NullPointerException ( "to" ) ; } if ( from . getClass ( ) == String . class && to . isArray ( ) ) { return new ArrayConverter ( ( String ) from ) . getArrayForType ( to ) ; } @ SuppressWarnings ( "unchecked" ) Converter < Object , T > c = co . get ( key ( from . getClass ( ) , to ) ) ; if ( c == null ) { c = lookupConversionService ( from . getClass ( ) , to ) ; if ( c == null ) { throw new ComponentException ( "No Converter: " + from + " (" + from . getClass ( ) + ") -> " + to ) ; } co . put ( key ( from . getClass ( ) , to ) , c ) ; } Object param = null ; if ( arg != null ) { param = arg . get ( from . getClass ( ) , to ) ; } return ( T ) c . convert ( from , param ) ; } | Convert a String value into an object of a certain type |
17,459 | @ SuppressWarnings ( "unchecked" ) private static < T > Converter < Object , T > lookupConversionService ( Class from , Class to ) { for ( ConversionProvider converter : convServices ) { Converter c = converter . getConverter ( from , to ) ; if ( c != null ) { return c ; } } return null ; } | Lookup a conversion service |
17,460 | private static Class getArrayBaseType ( Class array ) { while ( array . isArray ( ) ) { array = array . getComponentType ( ) ; } return array ; } | Get the array base type |
17,461 | private static Date parse ( String date ) { for ( int i = 0 ; i < fmt . length ; i ++ ) { try { SimpleDateFormat df = new SimpleDateFormat ( fmt [ i ] ) ; return df . parse ( date ) ; } catch ( ParseException E ) { } } throw new IllegalArgumentException ( date ) ; } | parse the date using the formats above . This is thread safe . |
17,462 | public void fixRowsAndCols ( ) { rows = ( int ) Math . round ( ( n - s ) / ns_res ) ; if ( rows < 1 ) rows = 1 ; cols = ( int ) Math . round ( ( e - w ) / we_res ) ; if ( cols < 1 ) cols = 1 ; } | calculate rows and cols from the region and its resolution . Round if required . |
17,463 | public static Point2D . Double snapToNextHigherInActiveRegionResolution ( double x , double y , Window activeWindow ) { double minx = activeWindow . getRectangle ( ) . getBounds2D ( ) . getMinX ( ) ; double ewres = activeWindow . getWEResolution ( ) ; double xsnap = minx + ( Math . ceil ( ( x - minx ) / ewres ) * ewres ) ; double miny = activeWindow . getRectangle ( ) . getBounds2D ( ) . getMinY ( ) ; double nsres = activeWindow . getNSResolution ( ) ; double ysnap = miny + ( Math . ceil ( ( y - miny ) / nsres ) * nsres ) ; return new Point2D . Double ( xsnap , ysnap ) ; } | Moves the point given by X and Y to be on the grid of the active region . |
17,464 | public static Window getActiveWindowFromMapset ( String mapsetPath ) { File windFile = new File ( mapsetPath + File . separator + GrassLegacyConstans . WIND ) ; if ( ! windFile . exists ( ) ) { return null ; } return new Window ( windFile . getAbsolutePath ( ) ) ; } | Get the active region window from the mapset |
17,465 | public static void writeActiveWindowToMapset ( String mapsetPath , Window window ) throws IOException { writeWindowFile ( mapsetPath + File . separator + GrassLegacyConstans . WIND , window ) ; } | Write active region window to the mapset |
17,466 | public static void writeDefaultWindowToLocation ( String locationPath , Window window ) throws IOException { writeWindowFile ( locationPath + File . separator + GrassLegacyConstans . PERMANENT_MAPSET + File . separator + GrassLegacyConstans . DEFAULT_WIND , window ) ; } | Write default region window to the PERMANENT mapset |
17,467 | public static Window adaptActiveRegionToEnvelope ( Envelope bounds , Window activeRegion ) { Point2D eastNorth = Window . snapToNextHigherInActiveRegionResolution ( bounds . getMaxX ( ) , bounds . getMaxY ( ) , activeRegion ) ; Point2D westsouth = Window . snapToNextHigherInActiveRegionResolution ( bounds . getMinX ( ) - activeRegion . getWEResolution ( ) , bounds . getMinY ( ) - activeRegion . getNSResolution ( ) , activeRegion ) ; Window tmp = new Window ( westsouth . getX ( ) , eastNorth . getX ( ) , westsouth . getY ( ) , eastNorth . getY ( ) , activeRegion . getWEResolution ( ) , activeRegion . getNSResolution ( ) ) ; return tmp ; } | Takes an envelope and an active region and creates a new region to match the bounds of the envelope but the resolutions of the active region . This is important if the region has to match some feature layer . The bounds are assured to contain completely the envelope . |
17,468 | public double [ ] cceua ( double s [ ] [ ] , double sf [ ] , double bl [ ] , double bu [ ] ) { int nps = s . length ; int nopt = s [ 0 ] . length ; int n = nps ; int m = nopt ; double alpha = 1.0 ; double beta = 0.5 ; double sb [ ] = new double [ nopt ] ; double sw [ ] = new double [ nopt ] ; double fb = sf [ 0 ] ; double fw = sf [ n - 1 ] ; for ( int i = 0 ; i < nopt ; i ++ ) { sb [ i ] = s [ 0 ] [ i ] ; sw [ i ] = s [ n - 1 ] [ i ] ; } double ce [ ] = new double [ nopt ] ; for ( int i = 0 ; i < nopt ; i ++ ) { ce [ i ] = 0 ; for ( int j = 0 ; j < n - 1 ; j ++ ) { ce [ i ] += s [ j ] [ i ] ; } ce [ i ] /= ( n - 1 ) ; } double snew [ ] = new double [ nopt ] ; for ( int i = 0 ; i < nopt ; i ++ ) { snew [ i ] = ce [ i ] + alpha * ( ce [ i ] - sw [ i ] ) ; } int ibound = 0 ; for ( int i = 0 ; i < nopt ; i ++ ) { if ( ( snew [ i ] - bl [ i ] ) < 0 ) { ibound = 1 ; } if ( ( bu [ i ] - snew [ i ] ) < 0 ) { ibound = 2 ; } } if ( ibound >= 1 ) { snew = randomSampler ( ) ; } double fnew = funct ( snew ) ; if ( fnew > fw ) { for ( int i = 0 ; i < nopt ; i ++ ) { snew [ i ] = sw [ i ] + beta * ( ce [ i ] - sw [ i ] ) ; } fnew = funct ( snew ) ; } if ( fnew > fw ) { snew = randomSampler ( ) ; fnew = funct ( snew ) ; } double result [ ] = new double [ nopt + 1 ] ; for ( int i = 0 ; i < nopt ; i ++ ) { result [ i ] = snew [ i ] ; } result [ nopt ] = fnew ; return result ; } | bu upper bound |
17,469 | public static boolean deleteFileOrDirOnExit ( File filehandle ) { if ( filehandle . isDirectory ( ) ) { String [ ] children = filehandle . list ( ) ; for ( int i = 0 ; i < children . length ; i ++ ) { boolean success = deleteFileOrDir ( new File ( filehandle , children [ i ] ) ) ; if ( ! success ) { return false ; } } } filehandle . deleteOnExit ( ) ; return true ; } | Delete file or folder recursively on exit of the program |
17,470 | public static String readInputStreamToString ( InputStream inputStream ) { try { List < Byte > bytesList = new ArrayList < Byte > ( ) ; byte b = 0 ; while ( ( b = ( byte ) inputStream . read ( ) ) != - 1 ) { bytesList . add ( b ) ; } inputStream . close ( ) ; byte [ ] bArray = new byte [ bytesList . size ( ) ] ; for ( int i = 0 ; i < bArray . length ; i ++ ) { bArray [ i ] = bytesList . get ( i ) ; } String file = new String ( bArray ) ; return file ; } catch ( IOException e ) { e . printStackTrace ( ) ; return null ; } } | Read from an inoutstream and convert the readed stuff to a String . Usefull for text files that are available as streams . |
17,471 | public static String hexDigest ( String algorithm , File [ ] files ) { try { MessageDigest md = MessageDigest . getInstance ( algorithm ) ; byte [ ] buf = new byte [ 4096 ] ; for ( File f : files ) { FileInputStream in = new FileInputStream ( f ) ; int nread = in . read ( buf ) ; while ( nread > 0 ) { md . update ( buf , 0 , nread ) ; nread = in . read ( buf ) ; } in . close ( ) ; } return toHex ( md . digest ( buf ) ) ; } catch ( Exception ex ) { ex . printStackTrace ( System . out ) ; } return "<error>" ; } | Creates a hex encoded sha - 256 hash of all files . |
17,472 | public static boolean hasLevel ( ASpatialDb db , int levelNum ) throws Exception { String tablename = TABLENAME + levelNum ; return db . hasTable ( tablename ) ; } | Checks if the given level table exists . |
17,473 | public static List < LasLevel > getLasLevels ( ASpatialDb db , int levelNum , Envelope envelope ) throws Exception { String tableName = TABLENAME + levelNum ; List < LasLevel > lasLevels = new ArrayList < > ( ) ; String sql = "SELECT " + COLUMN_GEOM + "," + COLUMN_ID + "," + COLUMN_SOURCE_ID + "," + COLUMN_AVG_ELEV + "," + COLUMN_MIN_ELEV + "," + COLUMN_MAX_ELEV + "," + COLUMN_AVG_INTENSITY + "," + COLUMN_MIN_INTENSITY + "," + COLUMN_MAX_INTENSITY ; sql += " FROM " + tableName ; if ( envelope != null ) { double x1 = envelope . getMinX ( ) ; double y1 = envelope . getMinY ( ) ; double x2 = envelope . getMaxX ( ) ; double y2 = envelope . getMaxY ( ) ; sql += " WHERE " + db . getSpatialindexBBoxWherePiece ( tableName , null , x1 , y1 , x2 , y2 ) ; } String _sql = sql ; IGeometryParser gp = db . getType ( ) . getGeometryParser ( ) ; return db . execOnConnection ( conn -> { try ( IHMStatement stmt = conn . createStatement ( ) ; IHMResultSet rs = stmt . executeQuery ( _sql ) ) { while ( rs . next ( ) ) { LasLevel lasLevel = new LasLevel ( ) ; lasLevel . level = levelNum ; int i = 1 ; Geometry geometry = gp . fromResultSet ( rs , i ++ ) ; if ( geometry instanceof Polygon ) { Polygon polygon = ( Polygon ) geometry ; lasLevel . polygon = polygon ; lasLevel . id = rs . getLong ( i ++ ) ; lasLevel . sourceId = rs . getLong ( i ++ ) ; lasLevel . avgElev = rs . getDouble ( i ++ ) ; lasLevel . minElev = rs . getDouble ( i ++ ) ; lasLevel . maxElev = rs . getDouble ( i ++ ) ; lasLevel . avgIntensity = rs . getShort ( i ++ ) ; lasLevel . minIntensity = rs . getShort ( i ++ ) ; lasLevel . maxIntensity = rs . getShort ( i ++ ) ; lasLevels . add ( lasLevel ) ; } } return lasLevels ; } } ) ; } | Query the las level table . |
17,474 | public static void handle ( File srcFile , AnnotationHandler ah ) throws Exception { FileInputStream fis = new FileInputStream ( srcFile ) ; FileChannel fc = fis . getChannel ( ) ; ByteBuffer bb = fc . map ( FileChannel . MapMode . READ_ONLY , 0 , fc . size ( ) ) ; CharsetDecoder cd = Charset . forName ( "8859_1" ) . newDecoder ( ) ; CharBuffer cb = cd . decode ( bb ) ; ah . start ( cb . toString ( ) ) ; handle ( cb . toString ( ) , ah ) ; ah . done ( ) ; fis . close ( ) ; } | Handle a file with an annotation handler . |
17,475 | public static void handle ( String s , AnnotationHandler ah ) { Map < String , Map < String , String > > l = new LinkedHashMap < String , Map < String , String > > ( ) ; Matcher m = annPattern . matcher ( s ) ; while ( m . find ( ) ) { String rest = s . substring ( m . end ( 0 ) ) . trim ( ) ; String srcLine = null ; if ( rest . indexOf ( '\n' ) > - 1 ) { srcLine = rest . substring ( 0 , rest . indexOf ( '\n' ) ) ; } else { srcLine = rest ; } Map < String , String > val = new LinkedHashMap < String , String > ( ) ; String annArgs = m . group ( 3 ) ; if ( annArgs == null ) { } else if ( annArgs . indexOf ( '=' ) > - 1 ) { StringTokenizer t = new StringTokenizer ( annArgs , "," ) ; while ( t . hasMoreTokens ( ) ) { String arg = t . nextToken ( ) ; String key = arg . substring ( 0 , arg . indexOf ( '=' ) ) ; String value = arg . substring ( arg . indexOf ( '=' ) + 1 ) ; val . put ( key . trim ( ) , value . trim ( ) ) ; } } else { val . put ( AnnotationHandler . VALUE , annArgs ) ; } l . put ( m . group ( 1 ) , val ) ; if ( ! annTestPattern . matcher ( srcLine ) . find ( ) ) { ah . handle ( l , srcLine ) ; ah . log ( " Ann -> " + l ) ; ah . log ( " Src -> " + srcLine ) ; l = new LinkedHashMap < String , Map < String , String > > ( ) ; } } } | Handle a string with an annotation handler |
17,476 | public static void createPropertiesTable ( ASpatialDb database ) throws Exception { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "CREATE TABLE " ) ; sb . append ( PROPERTIESTABLE ) ; sb . append ( " (" ) ; sb . append ( ID ) ; sb . append ( " INTEGER PRIMARY KEY AUTOINCREMENT, " ) ; sb . append ( NAME ) . append ( " TEXT, " ) ; sb . append ( SIZE ) . append ( " REAL, " ) ; sb . append ( FILLCOLOR ) . append ( " TEXT, " ) ; sb . append ( STROKECOLOR ) . append ( " TEXT, " ) ; sb . append ( FILLALPHA ) . append ( " REAL, " ) ; sb . append ( STROKEALPHA ) . append ( " REAL, " ) ; sb . append ( SHAPE ) . append ( " TEXT, " ) ; sb . append ( WIDTH ) . append ( " REAL, " ) ; sb . append ( LABELSIZE ) . append ( " REAL, " ) ; sb . append ( LABELFIELD ) . append ( " TEXT, " ) ; sb . append ( LABELVISIBLE ) . append ( " INTEGER, " ) ; sb . append ( ENABLED ) . append ( " INTEGER, " ) ; sb . append ( ORDER ) . append ( " INTEGER," ) ; sb . append ( DASH ) . append ( " TEXT," ) ; sb . append ( MINZOOM ) . append ( " INTEGER," ) ; sb . append ( MAXZOOM ) . append ( " INTEGER," ) ; sb . append ( DECIMATION ) . append ( " REAL," ) ; sb . append ( THEME ) . append ( " TEXT" ) ; sb . append ( " );" ) ; String query = sb . toString ( ) ; database . executeInsertUpdateDeleteSql ( query ) ; } | Create the properties table . |
17,477 | public static Style createDefaultPropertiesForTable ( ASpatialDb database , String spatialTableUniqueName , String spatialTableLabelField ) throws Exception { StringBuilder sbIn = new StringBuilder ( ) ; sbIn . append ( "insert into " ) . append ( PROPERTIESTABLE ) ; sbIn . append ( " ( " ) ; sbIn . append ( NAME ) . append ( " , " ) ; sbIn . append ( SIZE ) . append ( " , " ) ; sbIn . append ( FILLCOLOR ) . append ( " , " ) ; sbIn . append ( STROKECOLOR ) . append ( " , " ) ; sbIn . append ( FILLALPHA ) . append ( " , " ) ; sbIn . append ( STROKEALPHA ) . append ( " , " ) ; sbIn . append ( SHAPE ) . append ( " , " ) ; sbIn . append ( WIDTH ) . append ( " , " ) ; sbIn . append ( LABELSIZE ) . append ( " , " ) ; sbIn . append ( LABELFIELD ) . append ( " , " ) ; sbIn . append ( LABELVISIBLE ) . append ( " , " ) ; sbIn . append ( ENABLED ) . append ( " , " ) ; sbIn . append ( ORDER ) . append ( " , " ) ; sbIn . append ( DASH ) . append ( " ," ) ; sbIn . append ( MINZOOM ) . append ( " ," ) ; sbIn . append ( MAXZOOM ) . append ( " ," ) ; sbIn . append ( DECIMATION ) ; sbIn . append ( " ) " ) ; sbIn . append ( " values " ) ; sbIn . append ( " ( " ) ; Style style = new Style ( ) ; style . name = spatialTableUniqueName ; style . labelfield = spatialTableLabelField ; if ( spatialTableLabelField != null && spatialTableLabelField . trim ( ) . length ( ) > 0 ) { style . labelvisible = 1 ; } sbIn . append ( style . insertValuesString ( ) ) ; sbIn . append ( " );" ) ; if ( database != null ) { String insertQuery = sbIn . toString ( ) ; database . executeInsertUpdateDeleteSql ( insertQuery ) ; } return style ; } | Create a default properties table for a spatial table . |
17,478 | public static void updateStyle ( ASpatialDb database , Style style ) throws Exception { StringBuilder sbIn = new StringBuilder ( ) ; sbIn . append ( "update " ) . append ( PROPERTIESTABLE ) ; sbIn . append ( " set " ) ; sbIn . append ( SIZE ) . append ( "=?," ) ; sbIn . append ( FILLCOLOR ) . append ( "=?," ) ; sbIn . append ( STROKECOLOR ) . append ( "=?," ) ; sbIn . append ( FILLALPHA ) . append ( "=?," ) ; sbIn . append ( STROKEALPHA ) . append ( "=?," ) ; sbIn . append ( SHAPE ) . append ( "=?," ) ; sbIn . append ( WIDTH ) . append ( "=?," ) ; sbIn . append ( LABELSIZE ) . append ( "=?," ) ; sbIn . append ( LABELFIELD ) . append ( "=?," ) ; sbIn . append ( LABELVISIBLE ) . append ( "=?," ) ; sbIn . append ( ENABLED ) . append ( "=?," ) ; sbIn . append ( ORDER ) . append ( "=?," ) ; sbIn . append ( DASH ) . append ( "=?," ) ; sbIn . append ( MINZOOM ) . append ( "=?," ) ; sbIn . append ( MAXZOOM ) . append ( "=?," ) ; sbIn . append ( DECIMATION ) . append ( "=?," ) ; sbIn . append ( THEME ) . append ( "=?" ) ; sbIn . append ( " where " ) ; sbIn . append ( NAME ) ; sbIn . append ( "='" ) ; sbIn . append ( style . name ) ; sbIn . append ( "';" ) ; Object [ ] objects = { style . size , style . fillcolor , style . strokecolor , style . fillalpha , style . strokealpha , style . shape , style . width , style . labelsize , style . labelfield , style . labelvisible , style . enabled , style . order , style . dashPattern , style . minZoom , style . maxZoom , style . decimationFactor , style . getTheme ( ) } ; String updateQuery = sbIn . toString ( ) ; database . executeInsertUpdateDeletePreparedSql ( updateQuery , objects ) ; } | Update a style definition . |
17,479 | private ArrayList < ArrayList < String > > parseString ( String text ) { ArrayList < ArrayList < String > > result = new ArrayList < ArrayList < String > > ( ) ; StringTokenizer linetoken = new StringTokenizer ( text , "\n" ) ; StringTokenizer token ; String current ; while ( linetoken . hasMoreTokens ( ) ) { current = linetoken . nextToken ( ) ; if ( current . contains ( "," ) ) { token = new StringTokenizer ( current , "," ) ; } else { token = new StringTokenizer ( current ) ; } ArrayList < String > line = new ArrayList < String > ( ) ; while ( token . hasMoreTokens ( ) ) { line . add ( token . nextToken ( ) ) ; } result . add ( line ) ; } return result ; } | turns the clipboard into a list of tokens each array list is a line each string in the list is a token in the line |
17,480 | private void addContents ( String text ) { int firstColSelected = table . getSelectedColumn ( ) ; int firstRowSelected = table . getSelectedRow ( ) ; int temp = firstColSelected ; if ( firstColSelected == - 1 || firstRowSelected == - 1 ) { return ; } ArrayList < ArrayList < String > > clipboard = parseString ( text ) ; for ( int i = 0 ; i < clipboard . size ( ) ; i ++ ) { for ( int j = 0 ; j < clipboard . get ( i ) . size ( ) ; j ++ ) { try { table . getModel ( ) . setValueAt ( clipboard . get ( i ) . get ( j ) , firstRowSelected , temp ++ ) ; } catch ( Exception e ) { } } temp = firstColSelected ; firstRowSelected ++ ; } } | this adds the text to the jtable |
17,481 | public void pasteClipboard ( ) { Transferable t = Toolkit . getDefaultToolkit ( ) . getSystemClipboard ( ) . getContents ( null ) ; try { if ( t != null && t . isDataFlavorSupported ( DataFlavor . stringFlavor ) ) { addContents ( ( String ) t . getTransferData ( DataFlavor . stringFlavor ) ) ; table . repaint ( ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } } | this is the function that adds the clipboard contents to the table |
17,482 | public String getControlType ( Object control ) { if ( control == null || ! ( control instanceof ScreenAnnotation ) ) return null ; if ( showPanControls && controlPan . equals ( control ) ) return AVKey . VIEW_PAN ; else if ( showLookControls && controlLook . equals ( control ) ) return AVKey . VIEW_LOOK ; else if ( showHeadingControls && controlHeadingLeft . equals ( control ) ) return AVKey . VIEW_HEADING_LEFT ; else if ( showHeadingControls && controlHeadingRight . equals ( control ) ) return AVKey . VIEW_HEADING_RIGHT ; else if ( showZoomControls && controlZoomIn . equals ( control ) ) return AVKey . VIEW_ZOOM_IN ; else if ( showZoomControls && controlZoomOut . equals ( control ) ) return AVKey . VIEW_ZOOM_OUT ; else if ( showPitchControls && controlPitchUp . equals ( control ) ) return AVKey . VIEW_PITCH_UP ; else if ( showPitchControls && controlPitchDown . equals ( control ) ) return AVKey . VIEW_PITCH_DOWN ; else if ( showFovControls && controlFovNarrow . equals ( control ) ) return AVKey . VIEW_FOV_NARROW ; else if ( showFovControls && controlFovWide . equals ( control ) ) return AVKey . VIEW_FOV_WIDE ; else if ( showVeControls && controlVeUp . equals ( control ) ) return AVKey . VERTICAL_EXAGGERATION_UP ; else if ( showVeControls && controlVeDown . equals ( control ) ) return AVKey . VERTICAL_EXAGGERATION_DOWN ; return null ; } | Get the control type associated with the given object or null if unknown . |
17,483 | public void highlight ( Object control ) { if ( this . currentControl == control ) return ; if ( this . currentControl != null ) { this . currentControl . getAttributes ( ) . setImageOpacity ( - 1 ) ; this . currentControl = null ; } if ( control != null && control instanceof ScreenAnnotation ) { this . currentControl = ( ScreenAnnotation ) control ; this . currentControl . getAttributes ( ) . setImageOpacity ( 1 ) ; } } | Specifies the control to highlight . Any currently highlighted control is un - highlighted . |
17,484 | protected Object getImageSource ( String control ) { if ( control . equals ( AVKey . VIEW_PAN ) ) return IMAGE_PAN ; else if ( control . equals ( AVKey . VIEW_LOOK ) ) return IMAGE_LOOK ; else if ( control . equals ( AVKey . VIEW_HEADING_LEFT ) ) return IMAGE_HEADING_LEFT ; else if ( control . equals ( AVKey . VIEW_HEADING_RIGHT ) ) return IMAGE_HEADING_RIGHT ; else if ( control . equals ( AVKey . VIEW_ZOOM_IN ) ) return IMAGE_ZOOM_IN ; else if ( control . equals ( AVKey . VIEW_ZOOM_OUT ) ) return IMAGE_ZOOM_OUT ; else if ( control . equals ( AVKey . VIEW_PITCH_UP ) ) return IMAGE_PITCH_UP ; else if ( control . equals ( AVKey . VIEW_PITCH_DOWN ) ) return IMAGE_PITCH_DOWN ; else if ( control . equals ( AVKey . VIEW_FOV_WIDE ) ) return IMAGE_FOV_WIDE ; else if ( control . equals ( AVKey . VIEW_FOV_NARROW ) ) return IMAGE_FOV_NARROW ; else if ( control . equals ( AVKey . VERTICAL_EXAGGERATION_UP ) ) return IMAGE_VE_UP ; else if ( control . equals ( AVKey . VERTICAL_EXAGGERATION_DOWN ) ) return IMAGE_VE_DOWN ; return null ; } | Get a control image source . |
17,485 | protected Point computeLocation ( Rectangle viewport , Rectangle controls ) { double x ; double y ; if ( this . locationCenter != null ) { x = this . locationCenter . x - controls . width / 2 ; y = this . locationCenter . y - controls . height / 2 ; } else if ( this . position . equals ( AVKey . NORTHEAST ) ) { x = viewport . getWidth ( ) - controls . width - this . borderWidth ; y = viewport . getHeight ( ) - controls . height - this . borderWidth ; } else if ( this . position . equals ( AVKey . SOUTHEAST ) ) { x = viewport . getWidth ( ) - controls . width - this . borderWidth ; y = 0d + this . borderWidth ; } else if ( this . position . equals ( AVKey . NORTHWEST ) ) { x = 0d + this . borderWidth ; y = viewport . getHeight ( ) - controls . height - this . borderWidth ; } else if ( this . position . equals ( AVKey . SOUTHWEST ) ) { x = 0d + this . borderWidth ; y = 0d + this . borderWidth ; } else { x = viewport . getWidth ( ) - controls . width - this . borderWidth ; y = viewport . getHeight ( ) - controls . height - this . borderWidth ; } if ( this . locationOffset != null ) { x += this . locationOffset . x ; y += this . locationOffset . y ; } return new Point ( ( int ) x , ( int ) y ) ; } | Compute the screen location of the controls overall rectangle bottom right corner according to either the location center if not null or the screen position . |
17,486 | public static ValidationMessage < Origin > error ( String messageKey , Object ... params ) { return ValidationMessage . message ( Severity . ERROR , messageKey , params ) ; } | Creates a ValidationMessage - severity ERROR |
17,487 | public static ValidationMessage < Origin > warning ( String messageKey , Object ... params ) { return ValidationMessage . message ( Severity . WARNING , messageKey , params ) ; } | Creates a ValidationMessage - severity WARNING |
17,488 | public static ValidationMessage < Origin > info ( String messageKey , Object ... params ) { return ValidationMessage . message ( Severity . INFO , messageKey , params ) ; } | Creates a ValidationMessage - severity INFO |
17,489 | public void writeMessage ( Writer writer , String targetOrigin ) throws IOException { writeMessage ( writer , messageFormatter , targetOrigin ) ; } | Writes the message with an additional target origin . |
17,490 | protected void set ( double values [ ] ) { this . nRows = values . length ; this . nCols = 1 ; this . values = new double [ nRows ] [ 1 ] ; for ( int r = 0 ; r < nRows ; ++ r ) { this . values [ r ] [ 0 ] = values [ r ] ; } } | Set this column vector from an array of values . |
17,491 | public List < String > getAttributesNames ( ) { SimpleFeatureType featureType = feature . getFeatureType ( ) ; List < AttributeDescriptor > attributeDescriptors = featureType . getAttributeDescriptors ( ) ; List < String > attributeNames = new ArrayList < String > ( ) ; for ( AttributeDescriptor attributeDescriptor : attributeDescriptors ) { String name = attributeDescriptor . getLocalName ( ) ; attributeNames . add ( name ) ; } return attributeNames ; } | Getter for the list of attribute names . |
17,492 | @ SuppressWarnings ( "unchecked" ) public < T > T getAttribute ( String attrName , Class < T > adaptee ) { if ( attrName == null ) { return null ; } if ( adaptee == null ) { adaptee = ( Class < T > ) String . class ; } Object attribute = feature . getAttribute ( attrName ) ; if ( attribute == null ) { return null ; } if ( attribute instanceof Number ) { Number num = ( Number ) attribute ; if ( adaptee . isAssignableFrom ( Double . class ) ) { return adaptee . cast ( num . doubleValue ( ) ) ; } else if ( adaptee . isAssignableFrom ( Float . class ) ) { return adaptee . cast ( num . floatValue ( ) ) ; } else if ( adaptee . isAssignableFrom ( Integer . class ) ) { return adaptee . cast ( num . intValue ( ) ) ; } else if ( adaptee . isAssignableFrom ( Long . class ) ) { return adaptee . cast ( num . longValue ( ) ) ; } else if ( adaptee . isAssignableFrom ( String . class ) ) { return adaptee . cast ( num . toString ( ) ) ; } else { throw new IllegalArgumentException ( ) ; } } else if ( attribute instanceof String ) { if ( adaptee . isAssignableFrom ( Double . class ) ) { try { Double parsed = Double . parseDouble ( ( String ) attribute ) ; return adaptee . cast ( parsed ) ; } catch ( Exception e ) { return null ; } } else if ( adaptee . isAssignableFrom ( Float . class ) ) { try { Float parsed = Float . parseFloat ( ( String ) attribute ) ; return adaptee . cast ( parsed ) ; } catch ( Exception e ) { return null ; } } else if ( adaptee . isAssignableFrom ( Integer . class ) ) { try { Integer parsed = Integer . parseInt ( ( String ) attribute ) ; return adaptee . cast ( parsed ) ; } catch ( Exception e ) { return null ; } } else if ( adaptee . isAssignableFrom ( String . class ) ) { return adaptee . cast ( attribute ) ; } else { throw new IllegalArgumentException ( ) ; } } else if ( attribute instanceof Geometry ) { return null ; } else { throw new IllegalArgumentException ( "Can't adapt attribute of type: " + attribute . getClass ( ) . getCanonicalName ( ) ) ; } } | Gets an attribute from the feature table adapting to the supplied class . |
17,493 | public boolean intersects ( Geometry geometry , boolean usePrepared ) { if ( ! getEnvelope ( ) . intersects ( geometry . getEnvelopeInternal ( ) ) ) { return false ; } if ( usePrepared ) { if ( preparedGeometry == null ) { preparedGeometry = PreparedGeometryFactory . prepare ( getGeometry ( ) ) ; } return preparedGeometry . intersects ( geometry ) ; } else { return getGeometry ( ) . intersects ( geometry ) ; } } | Check for intersection . |
17,494 | public boolean covers ( Geometry geometry , boolean usePrepared ) { if ( ! getEnvelope ( ) . covers ( geometry . getEnvelopeInternal ( ) ) ) { return false ; } if ( usePrepared ) { if ( preparedGeometry == null ) { preparedGeometry = PreparedGeometryFactory . prepare ( getGeometry ( ) ) ; } return preparedGeometry . covers ( geometry ) ; } else { return getGeometry ( ) . covers ( geometry ) ; } } | Check for cover . |
17,495 | private double calcAerodynamic ( double displacement , double roughness , double Zref , double windSpeed , double snowWaterEquivalent ) { double ra = 0.0 ; double d_Lower ; double K2 ; double Z0_Lower ; double tmp_wind ; tmp_wind = windSpeed ; K2 = VON_K * VON_K ; if ( displacement > Zref ) Zref = displacement + Zref + roughness ; Z0_Lower = roughness ; d_Lower = displacement ; if ( snowWaterEquivalent > 0 ) { windSpeed = Math . log ( ( 2. + Z0_SNOW ) / Z0_SNOW ) / Math . log ( Zref / Z0_SNOW ) ; ra = Math . log ( ( 2. + Z0_SNOW ) / Z0_SNOW ) * Math . log ( Zref / Z0_SNOW ) / K2 ; } else { windSpeed = Math . log ( ( 2. + Z0_Lower ) / Z0_Lower ) / Math . log ( ( Zref - d_Lower ) / Z0_Lower ) ; ra = Math . log ( ( 2. + ( 1.0 / 0.63 - 1.0 ) * d_Lower ) / Z0_Lower ) * Math . log ( ( 2. + ( 1.0 / 0.63 - 1.0 ) * d_Lower ) / ( 0.1 * Z0_Lower ) ) / K2 ; } if ( tmp_wind > 0. ) { windSpeed *= tmp_wind ; ra /= tmp_wind ; } else { windSpeed *= tmp_wind ; ra = HUGE_RESIST ; pm . message ( "Aerodinamic resistance is set to the maximum value!" ) ; } return ra ; } | Calculates the aerodynamic resistance for the vegetation layer . |
17,496 | public static LinkedHashMap < String , List < String > > getTablesSorted ( List < String > allTableNames , boolean doSort ) { LinkedHashMap < String , List < String > > tablesMap = new LinkedHashMap < > ( ) ; tablesMap . put ( USERDATA , new ArrayList < String > ( ) ) ; tablesMap . put ( STYLE , new ArrayList < String > ( ) ) ; tablesMap . put ( METADATA , new ArrayList < String > ( ) ) ; tablesMap . put ( INTERNALDATA , new ArrayList < String > ( ) ) ; tablesMap . put ( SPATIALINDEX , new ArrayList < String > ( ) ) ; for ( String tableName : allTableNames ) { tableName = tableName . toLowerCase ( ) ; if ( spatialindexTables . contains ( tableName ) || tableName . startsWith ( startsWithIndexTables ) ) { List < String > list = tablesMap . get ( SPATIALINDEX ) ; list . add ( tableName ) ; continue ; } if ( tableName . startsWith ( startsWithStyleTables ) ) { List < String > list = tablesMap . get ( STYLE ) ; list . add ( tableName ) ; continue ; } if ( metadataTables . contains ( tableName ) ) { List < String > list = tablesMap . get ( METADATA ) ; list . add ( tableName ) ; continue ; } if ( internalDataTables . contains ( tableName ) ) { List < String > list = tablesMap . get ( INTERNALDATA ) ; list . add ( tableName ) ; continue ; } List < String > list = tablesMap . get ( USERDATA ) ; list . add ( tableName ) ; } if ( doSort ) { for ( List < String > values : tablesMap . values ( ) ) { Collections . sort ( values ) ; } } return tablesMap ; } | Sorts all supplied table names by type . |
17,497 | public static void createTables ( Connection connection ) throws IOException , SQLException { StringBuilder sB = new StringBuilder ( ) ; sB . append ( "CREATE TABLE " ) ; sB . append ( TABLE_BOOKMARKS ) ; sB . append ( " (" ) ; sB . append ( COLUMN_ID ) ; sB . append ( " INTEGER PRIMARY KEY, " ) ; sB . append ( COLUMN_LON ) . append ( " REAL NOT NULL, " ) ; sB . append ( COLUMN_LAT ) . append ( " REAL NOT NULL," ) ; sB . append ( COLUMN_ZOOM ) . append ( " REAL NOT NULL," ) ; sB . append ( COLUMN_NORTHBOUND ) . append ( " REAL NOT NULL," ) ; sB . append ( COLUMN_SOUTHBOUND ) . append ( " REAL NOT NULL," ) ; sB . append ( COLUMN_WESTBOUND ) . append ( " REAL NOT NULL," ) ; sB . append ( COLUMN_EASTBOUND ) . append ( " REAL NOT NULL," ) ; sB . append ( COLUMN_TEXT ) . append ( " TEXT NOT NULL " ) ; sB . append ( ");" ) ; String CREATE_TABLE_BOOKMARKS = sB . toString ( ) ; sB = new StringBuilder ( ) ; sB . append ( "CREATE INDEX bookmarks_x_by_y_idx ON " ) ; sB . append ( TABLE_BOOKMARKS ) ; sB . append ( " ( " ) ; sB . append ( COLUMN_LON ) ; sB . append ( ", " ) ; sB . append ( COLUMN_LAT ) ; sB . append ( " );" ) ; String CREATE_INDEX_BOOKMARKS_X_BY_Y = sB . toString ( ) ; try ( Statement statement = connection . createStatement ( ) ) { statement . setQueryTimeout ( 30 ) ; statement . executeUpdate ( CREATE_TABLE_BOOKMARKS ) ; statement . executeUpdate ( CREATE_INDEX_BOOKMARKS_X_BY_Y ) ; } catch ( Exception e ) { throw new IOException ( e . getLocalizedMessage ( ) ) ; } } | Create bookmarks tables . |
17,498 | public static String checkCompatibilityIssues ( String sql ) { sql = sql . replaceAll ( "LONG PRIMARY KEY AUTOINCREMENT" , "INTEGER PRIMARY KEY AUTOINCREMENT" ) ; sql = sql . replaceAll ( "AUTO_INCREMENT" , "AUTOINCREMENT" ) ; return sql ; } | Check for compatibility issues with other databases . |
17,499 | void mapOut ( String out , Object comp , String comp_out ) { if ( comp == ca . getComponent ( ) ) { throw new ComponentException ( "cannot connect 'Out' with itself for " + out ) ; } ComponentAccess ac_dest = lookup ( comp ) ; FieldAccess destAccess = ( FieldAccess ) ac_dest . output ( comp_out ) ; FieldAccess srcAccess = ( FieldAccess ) ca . output ( out ) ; checkFA ( destAccess , comp , comp_out ) ; checkFA ( srcAccess , ca . getComponent ( ) , out ) ; FieldContent data = srcAccess . getData ( ) ; data . tagLeaf ( ) ; data . tagOut ( ) ; destAccess . setData ( data ) ; dataSet . add ( data ) ; if ( log . isLoggable ( Level . CONFIG ) ) { log . log ( Level . CONFIG , String . format ( "@Out(%s) -> @Out(%s)" , srcAccess , destAccess ) ) ; } } | Map two output fields . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.