idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
17,200 | public static boolean deleteDeletedValueQualifiers ( Feature feature , ArrayList < Qualifier > deleteQualifierList ) { boolean deleted = false ; for ( Qualifier qual : deleteQualifierList ) { feature . removeQualifier ( qual ) ; deleted = true ; } return deleted ; } | deletes the qualifiers which have DELETED value | 60 | 10 |
17,201 | public static boolean deleteDuplicatedQualfiier ( Feature feature , String qualifierName ) { ArrayList < Qualifier > qualifiers = ( ArrayList < Qualifier > ) feature . getQualifiers ( qualifierName ) ; Set < String > qualifierValueSet = new HashSet < String > ( ) ; for ( Qualifier qual : qualifiers ) { if ( qual . getValue ( ) != null ) { if ( ! qualifierValueSet . add ( qual . getValue ( ) ) ) { feature . removeQualifier ( qual ) ; return true ; } } } return false ; } | Delete duplicated qualfiier . | 120 | 8 |
17,202 | public ImageIcon getImage ( String key ) { ImageIcon image = imageMap . get ( key ) ; if ( image == null ) { image = createImage ( key ) ; imageMap . put ( key , image ) ; } return image ; } | Get an image for a certain key . | 52 | 8 |
17,203 | public static Style getStyleFromFile ( File file ) { Style style = null ; try { String name = file . getName ( ) ; if ( ! name . endsWith ( "sld" ) ) { String nameWithoutExtention = FileUtilities . getNameWithoutExtention ( file ) ; File sldFile = new File ( file . getParentFile ( ) , nameWithoutExtention + ".sld" ) ; if ( sldFile . exists ( ) ) { file = sldFile ; } else { // no style file here return null ; } } SLDHandler h = new SLDHandler ( ) ; StyledLayerDescriptor sld = h . parse ( file , null , null , null ) ; // SLDParser stylereader = new SLDParser(sf, file); // StyledLayerDescriptor sld = stylereader.parseSLD(); style = getDefaultStyle ( sld ) ; return style ; } catch ( Exception e ) { e . printStackTrace ( ) ; return null ; } } | Get the style from an sld file . | 221 | 9 |
17,204 | private static void genericizeftStyles ( List < FeatureTypeStyle > ftStyles ) { for ( FeatureTypeStyle featureTypeStyle : ftStyles ) { featureTypeStyle . featureTypeNames ( ) . clear ( ) ; featureTypeStyle . featureTypeNames ( ) . add ( new NameImpl ( GENERIC_FEATURE_TYPENAME ) ) ; } } | Converts the type name of all FeatureTypeStyles to Feature so that the all apply to any feature type . This is admittedly dangerous but is extremely useful because it means that the style can be used with any feature type . | 80 | 45 |
17,205 | public static Color colorWithoutAlpha ( Color color ) { return new Color ( color . getRed ( ) , color . getGreen ( ) , color . getBlue ( ) ) ; } | REmoves the alpha channel from a color . | 38 | 10 |
17,206 | public static Color colorWithAlpha ( Color color , int alpha ) { return new Color ( color . getRed ( ) , color . getGreen ( ) , color . getBlue ( ) , alpha ) ; } | Creates a color with the given alpha . | 43 | 9 |
17,207 | public Map < String , TemplateTokenInfo > getTokensAsMap ( ) { HashMap < String , TemplateTokenInfo > tokens = new HashMap < String , TemplateTokenInfo > ( ) ; for ( TemplateTokenInfo tokenInfo : tokenInfos ) tokens . put ( tokenInfo . getName ( ) , tokenInfo ) ; return Collections . unmodifiableMap ( tokens ) ; } | returns a map keyed with the token name | 80 | 10 |
17,208 | public < T > T getTile4TileCoordinate ( final int tx , final int ty , int zoom , Class < T > adaptee ) throws IOException { //System.out.println("https://tile.openstreetmap.org/" + zoom + "/" + tx + "/" + ty + ".png"); Tile tile = new Tile ( tx , ty , ( byte ) zoom , tileSize ) ; RendererJob mapGeneratorJob = new RendererJob ( tile , mapDataStore , renderTheme , displayModel , scaleFactor , false , false ) ; TileBitmap tb = renderer . executeJob ( mapGeneratorJob ) ; if ( ! ( tileCache instanceof InMemoryTileCache ) ) { tileCache . put ( mapGeneratorJob , tb ) ; } if ( tb instanceof AwtTileBitmap ) { AwtTileBitmap bmp = ( AwtTileBitmap ) tb ; if ( bmp != null ) { BufferedImage bitmap = AwtGraphicFactory . getBitmap ( bmp ) ; if ( adaptee . isAssignableFrom ( BufferedImage . class ) ) { return adaptee . cast ( bitmap ) ; } else if ( adaptee . isAssignableFrom ( byte [ ] . class ) ) { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; ImageIO . write ( bitmap , "png" , baos ) ; baos . flush ( ) ; byte [ ] imageInByte = baos . toByteArray ( ) ; baos . close ( ) ; return adaptee . cast ( imageInByte ) ; } } } throw new RuntimeException ( "Can't handle tilebitmap of type -> " + tb . getClass ( ) ) ; } | Get tile data for a given tile schema coordinate . | 378 | 10 |
17,209 | public void ENopen ( String input , String report , String outputBin ) throws EpanetException { int errcode = epanet . ENopen ( input , report , outputBin ) ; checkError ( errcode ) ; } | Opens the Toolkit to analyze a particular distribution system . | 52 | 12 |
17,210 | public void ENsaveinpfile ( String fileName ) throws EpanetException { int err = epanet . ENsaveinpfile ( fileName ) ; checkError ( err ) ; } | Writes all current network input data to a file using the format of an EPANET input file . | 42 | 21 |
17,211 | public void ENsavehydfile ( String filePath ) throws EpanetException { int err = epanet . ENsavehydfile ( filePath ) ; checkError ( err ) ; } | Saves the current contents of the binary hydraulics file to a file . | 40 | 16 |
17,212 | public int ENgetcount ( Components countcode ) throws EpanetException { int [ ] count = new int [ 1 ] ; int error = epanet . ENgetcount ( countcode . getCode ( ) , count ) ; checkError ( error ) ; return count [ 0 ] ; } | Retrieves the number of network components of a specified type . | 62 | 13 |
17,213 | public float ENgetoption ( OptionParameterCodes optionCode ) throws EpanetException { float [ ] optionValue = new float [ 1 ] ; int error = epanet . ENgetoption ( optionCode . getCode ( ) , optionValue ) ; checkError ( error ) ; return optionValue [ 0 ] ; } | Retrieves the value of a particular analysis option . | 68 | 11 |
17,214 | public long ENgettimeparam ( TimeParameterCodes timeParameterCode ) throws EpanetException { long [ ] timeValue = new long [ 1 ] ; int error = epanet . ENgettimeparam ( timeParameterCode . getCode ( ) , timeValue ) ; checkError ( error ) ; return timeValue [ 0 ] ; } | Retrieves the value of a specific analysis time parameter . | 72 | 12 |
17,215 | public int ENgetpatternindex ( String id ) throws EpanetException { int [ ] index = new int [ 1 ] ; int error = epanet . ENgetpatternindex ( id , index ) ; checkError ( error ) ; return index [ 0 ] ; } | Retrieves the index of a particular time pattern . | 57 | 11 |
17,216 | public float ENgetpatternvalue ( int index , int period ) throws EpanetException { float [ ] value = new float [ 1 ] ; int errcode = epanet . ENgetpatternvalue ( index , period , value ) ; checkError ( errcode ) ; return value [ 0 ] ; } | Retrieves the multiplier factor for a specific time period in a time pattern . | 66 | 16 |
17,217 | public int ENgetnodeindex ( String id ) throws EpanetException { int [ ] index = new int [ 1 ] ; int error = epanet . ENgetnodeindex ( id , index ) ; checkError ( error ) ; return index [ 0 ] ; } | Retrieves the index of a node with a specified ID . | 57 | 13 |
17,218 | public NodeTypes ENgetnodetype ( int index ) throws EpanetException { int [ ] typecode = new int [ 1 ] ; int error = epanet . ENgetnodetype ( index , typecode ) ; checkError ( error ) ; NodeTypes type = NodeTypes . forCode ( typecode [ 0 ] ) ; return type ; } | Retrieves the node - type code for a specific node . | 78 | 13 |
17,219 | public int ENgetlinkindex ( String id ) throws EpanetException { int [ ] index = new int [ 1 ] ; int error = epanet . ENgetlinkindex ( id , index ) ; checkError ( error ) ; return index [ 0 ] ; } | Retrieves the index of a link with a specified ID . | 57 | 13 |
17,220 | public String ENgetlinkid ( int index ) throws EpanetException { ByteBuffer bb = ByteBuffer . allocate ( 64 ) ; int errcode = epanet . ENgetlinkid ( index , bb ) ; checkError ( errcode ) ; String label ; label = byteBuffer2String ( bb ) ; return label ; } | Retrieves the ID label of a link with a specified index . | 75 | 14 |
17,221 | public LinkTypes ENgetlinktype ( int index ) throws EpanetException { int [ ] typecode = new int [ 1 ] ; int error = epanet . ENgetlinktype ( index , typecode ) ; checkError ( error ) ; LinkTypes type = LinkTypes . forCode ( typecode [ 0 ] ) ; return type ; } | Retrieves the link - type code for a specific link . | 74 | 13 |
17,222 | public int [ ] ENgetlinknodes ( int index ) throws EpanetException { int [ ] from = new int [ 1 ] ; int [ ] to = new int [ 1 ] ; int error = epanet . ENgetlinknodes ( index , from , to ) ; checkError ( error ) ; return new int [ ] { from [ 0 ] , to [ 0 ] } ; } | Retrieves the indexes of the end nodes of a specified link . | 85 | 14 |
17,223 | public float [ ] ENgetlinkvalue ( int index , LinkParameters param ) throws EpanetException { float [ ] value = new float [ 2 ] ; int errcode = epanet . ENgetlinkvalue ( index , param . getCode ( ) , value ) ; checkError ( errcode ) ; return value ; } | Retrieves the value of a specific link parameter . | 71 | 11 |
17,224 | public int ENgetversion ( ) throws EpanetException { int [ ] version = new int [ 0 ] ; int errcode = epanet . ENgetversion ( version ) ; checkError ( errcode ) ; return version [ 0 ] ; } | Get the version of OmsEpanet . | 55 | 10 |
17,225 | public void ENsetnodevalue ( int index , NodeParameters nodeParameter , float value ) throws EpanetException { int errcode = epanet . ENsetnodevalue ( index , nodeParameter . getCode ( ) , value ) ; checkError ( errcode ) ; } | Sets the value of a parameter for a specific node . | 60 | 12 |
17,226 | public void ENsetlinkvalue ( int index , LinkParameters linkParameter , float value ) throws EpanetException { int errcode = epanet . ENsetnodevalue ( index , linkParameter . getCode ( ) , value ) ; checkError ( errcode ) ; } | Sets the value of a parameter for a specific link . | 60 | 12 |
17,227 | public void ENaddpattern ( String id ) throws EpanetException { int errcode = epanet . ENaddpattern ( id ) ; checkError ( errcode ) ; } | Adds a new time pattern to the network . | 40 | 9 |
17,228 | public void ENsettimeparam ( TimeParameterCodes code , Long timevalue ) throws EpanetException { int errcode = epanet . ENsettimeparam ( code . getCode ( ) , timevalue ) ; checkError ( errcode ) ; } | Sets the value of a time parameter . | 57 | 9 |
17,229 | public void ENsetoption ( OptionParameterCodes optionCode , float value ) throws EpanetException { int errcode = epanet . ENsetoption ( optionCode . getCode ( ) , value ) ; checkError ( errcode ) ; } | Sets the value of a particular analysis option . | 55 | 10 |
17,230 | public static ValidationException error ( String messageKey , Object ... params ) { return new ValidationException ( ValidationMessage . error ( messageKey , params ) ) ; } | Creates a ValidationException which contains a ValidationMessage error . | 36 | 14 |
17,231 | public static ValidationException warning ( String messageKey , Object ... params ) { return new ValidationException ( ValidationMessage . warning ( messageKey , params ) ) ; } | Creates a ValidationException which contains a ValidationMessage warning . | 36 | 14 |
17,232 | public static ValidationException info ( String messageKey , Object ... params ) { return new ValidationException ( ValidationMessage . info ( messageKey , params ) ) ; } | Creates a ValidationException which contains a ValidationMessage info . | 36 | 14 |
17,233 | protected void writeFeatureLocation ( Writer writer ) throws IOException { new FeatureLocationWriter ( entry , feature , wrapType , featureHeader , qualifierHeader ) . write ( writer ) ; } | overridden in HTMLFeatureWriter | 38 | 6 |
17,234 | public void beginElement ( String elementName ) throws IOException { addElementName ( elementName ) ; indent ( ) ; writer . write ( "<" ) ; writer . write ( elementName ) ; } | Writes <elementName . | 42 | 6 |
17,235 | public void openElement ( String elementName ) throws IOException { assert ( elementNames . size ( ) > 0 ) ; assert ( elementNames . get ( elementNames . size ( ) - 1 ) . equals ( elementName ) ) ; writer . write ( ">" ) ; if ( indent || noTextElement ) { writer . write ( "\n" ) ; } } | Writes > \ n . | 77 | 6 |
17,236 | @ Override public void setData ( FieldContent data ) { // allow setting in field once only. // cannot have multiple sources for one @In ! if ( this . data != null ) { throw new ComponentException ( "Attempt to set @In field twice: " + comp + "." + field . getName ( ) ) ; } this . data = data ; } | called in in access | 77 | 4 |
17,237 | double qobs ( int dummy , double [ ] xt ) { int x = ( int ) ( xt [ 0 ] ) ; double p = Math . random ( ) ; double [ ] distr = accumP [ x ] ; int i , left = 0 , right = distr . length - 1 ; // Find and return least i s.t. p <= distr[i] while ( left <= right ) { // Here distr[left-1] <= p <= distr[right+1] i = ( left + right ) / 2 ; if ( p < distr [ i ] ) { right = i - 1 ; } else if ( distr [ i ] < p ) { left = i + 1 ; } else { return i ; } } // Now p <= distr[left] return left ; } | An efficient version of qobs using binary search in accumP | 175 | 12 |
17,238 | public static byte [ ] hexToBytes ( String hex ) { int byteLen = hex . length ( ) / 2 ; byte [ ] bytes = new byte [ byteLen ] ; for ( int i = 0 ; i < hex . length ( ) / 2 ; i ++ ) { int i2 = 2 * i ; if ( i2 + 1 > hex . length ( ) ) throw new IllegalArgumentException ( "Hex string has odd length" ) ; int nib1 = hexToInt ( hex . charAt ( i2 ) ) ; int nib0 = hexToInt ( hex . charAt ( i2 + 1 ) ) ; byte b = ( byte ) ( ( nib1 << 4 ) + ( byte ) nib0 ) ; bytes [ i ] = b ; } return bytes ; } | Converts a hexadecimal string to a byte array . The hexadecimal digit symbols are case - insensitive . | 167 | 25 |
17,239 | private Geometry setSRID ( Geometry g , int SRID ) { if ( SRID != 0 ) g . setSRID ( SRID ) ; return g ; } | Sets the SRID if it was specified in the WKB | 37 | 13 |
17,240 | private void readCoordinate ( ) throws IOException { for ( int i = 0 ; i < inputDimension ; i ++ ) { if ( i <= 1 ) { ordValues [ i ] = precisionModel . makePrecise ( dis . readDouble ( ) ) ; } else { ordValues [ i ] = dis . readDouble ( ) ; } } } | Reads a coordinate value with the specified dimensionality . Makes the X and Y ordinates precise according to the precision model in use . | 75 | 27 |
17,241 | public static void connectElements ( List < IHillSlope > elements ) { Collections . sort ( elements , elements . get ( 0 ) ) ; for ( int i = 0 ; i < elements . size ( ) ; i ++ ) { IHillSlope elem = elements . get ( i ) ; for ( int j = i + 1 ; j < elements . size ( ) ; j ++ ) { IHillSlope tmp = elements . get ( j ) ; elem . addConnectedDownstreamElementWithCheck ( tmp ) ; } } } | Connect the various elements in a chain of tributary basins and nets | 116 | 15 |
17,242 | public static final String bytesToHex ( byte [ ] bs , int off , int length ) { StringBuffer sb = new StringBuffer ( length * 2 ) ; bytesToHexAppend ( bs , off , length , sb ) ; return sb . toString ( ) ; } | Converts a byte array into a string of upper case hex chars . | 64 | 14 |
17,243 | public Vector getPoints ( double inc ) { Vector arc = new Vector ( ) ; double angulo ; int iempieza = ( int ) empieza + 1 ; int iacaba = ( int ) acaba ; if ( empieza <= acaba ) { addNode ( arc , empieza ) ; for ( angulo = iempieza ; angulo <= iacaba ; angulo += inc ) { addNode ( arc , angulo ) ; } addNode ( arc , acaba ) ; } else { addNode ( arc , empieza ) ; for ( angulo = iempieza ; angulo <= 360 ; angulo += inc ) { addNode ( arc , angulo ) ; } for ( angulo = 1 ; angulo <= iacaba ; angulo += inc ) { addNode ( arc , angulo ) ; } addNode ( arc , angulo ) ; } Point2D aux = ( Point2D ) arc . get ( arc . size ( ) - 1 ) ; double aux1 = Math . abs ( aux . getX ( ) - coord2 . getX ( ) ) ; double aux2 = Math . abs ( aux . getY ( ) - coord2 . getY ( ) ) ; return arc ; } | This method calculates an arc in a Gis geometry model . This arc is represented in this model by a Vector of Point2D . The distance between points in the arc is given as an argument | 268 | 39 |
17,244 | public Vector getCentralPoint ( ) { Vector arc = new Vector ( ) ; if ( empieza <= acaba ) { addNode ( arc , ( empieza + acaba ) / 2.0 ) ; } else { addNode ( arc , empieza ) ; double alfa = 360 - empieza ; double beta = acaba ; double an = alfa + beta ; double mid = an / 2.0 ; if ( mid <= alfa ) { addNode ( arc , empieza + mid ) ; } else { addNode ( arc , mid - alfa ) ; } } return arc ; } | Method that allows to obtain a set of points located in the central zone of this arc object | 131 | 18 |
17,245 | public static List < FileStoreDataSet > getDataSets ( File cacheRoot ) { if ( cacheRoot == null ) { String message = Logging . getMessage ( "nullValue.FileStorePathIsNull" ) ; Logging . logger ( ) . severe ( message ) ; throw new IllegalArgumentException ( message ) ; } ArrayList < FileStoreDataSet > datasets = new ArrayList < FileStoreDataSet > ( ) ; File [ ] cacheDirs = FileStoreDataSet . listDirs ( cacheRoot ) ; for ( File cacheDir : cacheDirs ) { if ( cacheDir . getName ( ) . equals ( "license" ) ) continue ; File [ ] subDirs = FileStoreDataSet . listDirs ( cacheDir ) ; if ( subDirs . length == 0 ) { datasets . add ( new FileStoreDataSet ( cacheDir , cacheRoot . getPath ( ) ) ) ; } else { // If the directory should be treated as a single dataset, add just one entry to the list. if ( isSingleDataSet ( subDirs ) ) { datasets . add ( new FileStoreDataSet ( cacheDir , cacheRoot . getPath ( ) ) ) ; } // Otherwise add each subdirectory as a separate data set. else { for ( File sd : subDirs ) { FileStoreDataSet ds = new FileStoreDataSet ( sd , cacheRoot . getPath ( ) ) ; datasets . add ( ds ) ; } } } } return datasets ; } | Find all of the data set directories in a cache root . | 321 | 12 |
17,246 | protected static File [ ] listDirs ( File parent ) { return parent . listFiles ( new FileFilter ( ) { public boolean accept ( File file ) { return file . isDirectory ( ) ; } } ) ; } | List all of the sub - directories in a parent directory . | 46 | 12 |
17,247 | protected static boolean isNumeric ( String s ) { for ( char c : s . toCharArray ( ) ) { if ( ! Character . isDigit ( c ) ) return false ; } return true ; } | Determines if a string contains only digits . | 45 | 10 |
17,248 | public static void createModulesOverview ( ) { Map < String , List < ClassField > > hmModules = HortonMachine . getInstance ( ) . moduleName2Fields ; Map < String , List < ClassField > > jggModules = JGrassGears . getInstance ( ) . moduleName2Fields ; Map < String , Class < ? > > hmModulesClasses = HortonMachine . getInstance ( ) . moduleName2Class ; Map < String , Class < ? > > jggModulesClasses = JGrassGears . getInstance ( ) . moduleName2Class ; Set < String > hmNames = hmModules . keySet ( ) ; String [ ] hmNamesArray = ( String [ ] ) hmNames . toArray ( new String [ hmNames . size ( ) ] ) ; Set < String > jggNames = jggModules . keySet ( ) ; String [ ] jggNamesArray = ( String [ ] ) jggNames . toArray ( new String [ jggNames . size ( ) ] ) ; Arrays . sort ( hmNamesArray ) ; Arrays . sort ( jggNamesArray ) ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( "#summary An overview of the modules implemented in the HortonMachine\n\n" ) ; sb . append ( "<wiki:toc max_depth=\"4\" />\n\n" ) ; sb . append ( "= HortonMachine Modules Overview =\n" ) ; sb . append ( "== !HortonMachine Modules ==\n" ) ; String status = "CERTIFIED" ; sb . append ( "=== Release ready ==\n" ) ; dumpModules ( hmModules , hmModulesClasses , hmNamesArray , sb , status ) ; status = "TESTED" ; sb . append ( "=== Tested but not for upcoming release ==\n" ) ; dumpModules ( hmModules , hmModulesClasses , hmNamesArray , sb , status ) ; status = "DRAFT" ; sb . append ( "=== Module that are not passing the QA rules yet ==\n" ) ; dumpModules ( hmModules , hmModulesClasses , hmNamesArray , sb , status ) ; sb . append ( "\n<BR/><BR/><BR/>\n\n" ) ; sb . append ( "== Gears Modules ==\n" ) ; status = "CERTIFIED" ; sb . append ( "=== Release ready ==\n" ) ; dumpModules ( jggModules , jggModulesClasses , jggNamesArray , sb , status ) ; status = "TESTED" ; sb . append ( "=== Tested but not for upcoming release ==\n" ) ; dumpModules ( jggModules , jggModulesClasses , jggNamesArray , sb , status ) ; status = "DRAFT" ; sb . append ( "=== Module that are not passing the QA rules yet ==\n" ) ; dumpModules ( jggModules , jggModulesClasses , jggNamesArray , sb , status ) ; System . out . println ( sb . toString ( ) ) ; } | Creates an overview of all the OMS modules for the wiki site . | 732 | 15 |
17,249 | public static Server startTcpServerMode ( String port , boolean doSSL , String tcpPassword , boolean ifExists , String baseDir ) throws SQLException { List < String > params = new ArrayList <> ( ) ; params . add ( "-tcpAllowOthers" ) ; params . add ( "-tcpPort" ) ; if ( port == null ) { port = "9123" ; } params . add ( port ) ; if ( doSSL ) { params . add ( "-tcpSSL" ) ; } if ( tcpPassword != null ) { params . add ( "-tcpPassword" ) ; params . add ( tcpPassword ) ; } if ( ifExists ) { params . add ( "-ifExists" ) ; } if ( baseDir != null ) { params . add ( "-baseDir" ) ; params . add ( baseDir ) ; } Server server = Server . createTcpServer ( params . toArray ( new String [ 0 ] ) ) . start ( ) ; return server ; } | Start the server mode . | 217 | 5 |
17,250 | public static Server startWebServerMode ( String port , boolean doSSL , boolean ifExists , String baseDir ) throws SQLException { List < String > params = new ArrayList <> ( ) ; params . add ( "-webAllowOthers" ) ; if ( port != null ) { params . add ( "-webPort" ) ; params . add ( port ) ; } if ( doSSL ) { params . add ( "-webSSL" ) ; } if ( ifExists ) { params . add ( "-ifExists" ) ; } if ( baseDir != null ) { params . add ( "-baseDir" ) ; params . add ( baseDir ) ; } Server server = Server . createWebServer ( params . toArray ( new String [ 0 ] ) ) . start ( ) ; return server ; } | Start the web server mode . | 173 | 6 |
17,251 | public static String createTableFromShp ( ASpatialDb db , File shapeFile , String newTableName , boolean avoidSpatialIndex ) throws Exception { FileDataStore store = FileDataStoreFinder . getDataStore ( shapeFile ) ; SimpleFeatureSource featureSource = store . getFeatureSource ( ) ; SimpleFeatureType schema = featureSource . getSchema ( ) ; if ( newTableName == null ) { newTableName = FileUtilities . getNameWithoutExtention ( shapeFile ) ; } return createTableFromSchema ( db , schema , newTableName , avoidSpatialIndex ) ; } | Create a spatial table using a shapefile as schema . | 130 | 11 |
17,252 | public static boolean importShapefile ( ASpatialDb db , File shapeFile , String tableName , int limit , IHMProgressMonitor pm ) throws Exception { FileDataStore store = FileDataStoreFinder . getDataStore ( shapeFile ) ; SimpleFeatureSource featureSource = store . getFeatureSource ( ) ; SimpleFeatureCollection features = featureSource . getFeatures ( ) ; return importFeatureCollection ( db , features , tableName , limit , pm ) ; } | Import a shapefile into a table . | 97 | 8 |
17,253 | private void writeExif ( ) throws IOException { IIOMetadata metadata = jpegReader . getImageMetadata ( 0 ) ; // names says which exif tree to get - 0 for jpeg 1 for the default String [ ] names = metadata . getMetadataFormatNames ( ) ; IIOMetadataNode root = ( IIOMetadataNode ) metadata . getAsTree ( names [ 0 ] ) ; // exif is on the app1 node called unknown NodeList nList = root . getElementsByTagName ( "unknown" ) ; IIOMetadataNode app1EXIFNode = ( IIOMetadataNode ) nList . item ( 0 ) ; ArrayList < IIOMetadata > md = readExif ( app1EXIFNode ) ; IIOMetadata exifMetadata = md . get ( 0 ) ; // insert the gps data into the exif exifMetadata = insertGPSCoords ( exifMetadata ) ; // create a new exif node IIOMetadataNode app1NodeNew = createNewExifNode ( exifMetadata , null , null ) ; // copy the user data accross app1EXIFNode . setUserObject ( app1NodeNew . getUserObject ( ) ) ; // write to a new image file FileImageOutputStream out1 = new FileImageOutputStream ( new File ( "GPS_" + imageFile . getName ( ) ) ) ; jpegWriter . setOutput ( out1 ) ; metadata . setFromTree ( names [ 0 ] , root ) ; IIOImage image = new IIOImage ( jpegReader . readAsRenderedImage ( 0 , jpegReader . getDefaultReadParam ( ) ) , null , metadata ) ; // write out the new image jpegWriter . write ( jpegReader . getStreamMetadata ( ) , image , jpegWriter . getDefaultWriteParam ( ) ) ; } | Main method to write the gps data to the exif | 411 | 12 |
17,254 | private ArrayList < IIOMetadata > readExif ( IIOMetadataNode app1EXIFNode ) { // Set up input skipping EXIF ID 6-byte sequence. byte [ ] app1Params = ( byte [ ] ) app1EXIFNode . getUserObject ( ) ; MemoryCacheImageInputStream app1EXIFInput = new MemoryCacheImageInputStream ( new ByteArrayInputStream ( app1Params , 6 , app1Params . length - 6 ) ) ; // only the tiff reader knows how to interpret the exif metadata ImageReader tiffReader = null ; Iterator < ImageReader > readers = ImageIO . getImageReadersByFormatName ( "tiff" ) ; while ( readers . hasNext ( ) ) { tiffReader = ( ImageReader ) readers . next ( ) ; if ( tiffReader . getClass ( ) . getName ( ) . startsWith ( "com.sun.media" ) ) { // Break on finding the core provider. break ; } } if ( tiffReader == null ) { throw new RuntimeException ( "Cannot find core TIFF reader!" ) ; } ArrayList < IIOMetadata > out = new ArrayList < IIOMetadata > ( 1 ) ; tiffReader . setInput ( app1EXIFInput ) ; IIOMetadata tiffMetadata = null ; try { tiffMetadata = tiffReader . getImageMetadata ( 0 ) ; // IIOMetadata meta = tiffReader.getImageMetadata(0); TIFFImageReadParam rParam = ( TIFFImageReadParam ) tiffReader . getDefaultReadParam ( ) ; rParam . setTIFFDecompressor ( null ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } ; tiffReader . dispose ( ) ; out . add ( 0 , tiffMetadata ) ; return out ; } | Private method - Reads the exif metadata for an image | 410 | 12 |
17,255 | private IIOMetadataNode createNewExifNode ( IIOMetadata tiffMetadata , IIOMetadata thumbMeta , BufferedImage thumbnail ) { IIOMetadataNode app1Node = null ; ImageWriter tiffWriter = null ; try { Iterator < ImageWriter > writers = ImageIO . getImageWritersByFormatName ( "tiff" ) ; while ( writers . hasNext ( ) ) { tiffWriter = writers . next ( ) ; if ( tiffWriter . getClass ( ) . getName ( ) . startsWith ( "com.sun.media" ) ) { // Break on finding the core provider. break ; } } if ( tiffWriter == null ) { System . out . println ( "Cannot find core TIFF writer!" ) ; System . exit ( 0 ) ; } ImageWriteParam writeParam = tiffWriter . getDefaultWriteParam ( ) ; writeParam . setCompressionMode ( ImageWriteParam . MODE_EXPLICIT ) ; writeParam . setCompressionType ( "EXIF JPEG" ) ; ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; MemoryCacheImageOutputStream app1EXIFOutput = new MemoryCacheImageOutputStream ( baos ) ; tiffWriter . setOutput ( app1EXIFOutput ) ; // escribir tiffWriter . prepareWriteEmpty ( jpegReader . getStreamMetadata ( ) , new ImageTypeSpecifier ( image ) , image . getWidth ( ) , image . getHeight ( ) , tiffMetadata , null , writeParam ) ; tiffWriter . endWriteEmpty ( ) ; // Flush data into byte stream. app1EXIFOutput . flush ( ) ; // Create APP1 parameter array. byte [ ] app1Parameters = new byte [ 6 + baos . size ( ) ] ; // Add EXIF APP1 ID bytes. app1Parameters [ 0 ] = ( byte ) ' ' ; app1Parameters [ 1 ] = ( byte ) ' ' ; app1Parameters [ 2 ] = ( byte ) ' ' ; app1Parameters [ 3 ] = ( byte ) ' ' ; app1Parameters [ 4 ] = app1Parameters [ 5 ] = ( byte ) 0 ; // Append TIFF stream to APP1 parameters. System . arraycopy ( baos . toByteArray ( ) , 0 , app1Parameters , 6 , baos . size ( ) ) ; // Create the APP1 EXIF node to be added to native JPEG image metadata. app1Node = new IIOMetadataNode ( "unknown" ) ; app1Node . setAttribute ( "MarkerTag" , ( new Integer ( 0xE1 ) ) . toString ( ) ) ; app1Node . setUserObject ( app1Parameters ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } finally { if ( tiffWriter != null ) tiffWriter . dispose ( ) ; } return app1Node ; } | Private method - creates a copy of the metadata that can be written to | 630 | 14 |
17,256 | private long [ ] [ ] getLatitude ( String lat ) { float secs = Float . parseFloat ( "0" + lat . substring ( 4 ) ) * 60.f ; long nom = ( long ) ( secs * 1000 ) ; long [ ] [ ] latl = new long [ ] [ ] { { Long . parseLong ( lat . substring ( 0 , 2 ) ) , 1 } , { Long . parseLong ( lat . substring ( 2 , 4 ) ) , 1 } , { nom , 1000 } } ; return latl ; } | assumes the the format is HHMM . MMMM | 120 | 12 |
17,257 | private long [ ] [ ] getLongitude ( String longi ) { float secs = Float . parseFloat ( "0" + longi . substring ( 5 ) ) * 60.f ; long nom = ( long ) ( secs * 1000 ) ; long [ ] [ ] longl = new long [ ] [ ] { { Long . parseLong ( longi . substring ( 0 , 3 ) ) , 1 } , { Long . parseLong ( longi . substring ( 3 , 5 ) ) , 1 } , { nom , 1000 } } ; return longl ; } | assumes the the format is HHHMM . MMMM | 124 | 13 |
17,258 | private long [ ] [ ] getTime ( String time ) { long [ ] [ ] timel = new long [ ] [ ] { { Long . parseLong ( time . substring ( 0 , 2 ) ) , 1 } , { Long . parseLong ( time . substring ( 2 , 4 ) ) , 1 } , { Long . parseLong ( time . substring ( 4 ) ) , 1 } } ; return timel ; } | Convert a time to exif format . | 92 | 9 |
17,259 | private String [ ] getDate ( String date ) { String dateStr = "20" + date . substring ( 4 ) + ":" + date . substring ( 2 , 4 ) + ":" + date . substring ( 0 , 2 ) ; String [ ] dateArray = new String [ 11 ] ; for ( int i = 0 ; i < dateStr . length ( ) ; i ++ ) dateArray [ i ] = dateStr . substring ( i , i + 1 ) ; dateArray [ 10 ] = "" ; return dateArray ; } | Convert a date to exif date . | 116 | 9 |
17,260 | void clear ( ) { count = 0 ; m0 = 0.0 ; clusters . space . setToOrigin ( m1 ) ; clusters . space . setToOrigin ( m2 ) ; var = 0.0 ; key = null ; } | Completely clears this cluster . All points and their associated mass is removed along with any key that was assigned to the cluster | 51 | 24 |
17,261 | void set ( final double m , final Object pt ) { if ( m == 0.0 ) { if ( count != 0 ) { clusters . space . setToOrigin ( m1 ) ; clusters . space . setToOrigin ( m2 ) ; } } else { clusters . space . setToScaled ( m1 , m , pt ) ; clusters . space . setToScaledSqr ( m2 , m , pt ) ; } count = 1 ; m0 = m ; var = 0.0 ; } | Sets this cluster equal to a single point . | 110 | 10 |
17,262 | void add ( final double m , final Object pt ) { if ( count == 0 ) { set ( m , pt ) ; } else { count += 1 ; if ( m != 0.0 ) { m0 += m ; clusters . space . addScaled ( m1 , m , pt ) ; clusters . space . addScaledSqr ( m2 , m , pt ) ; update ( ) ; } } } | Adds a point to the cluster . | 89 | 7 |
17,263 | void set ( GvmCluster < S , K > cluster ) { if ( cluster == this ) throw new IllegalArgumentException ( "cannot set cluster to itself" ) ; m0 = cluster . m0 ; clusters . space . setTo ( m1 , cluster . m1 ) ; clusters . space . setTo ( m2 , cluster . m2 ) ; var = cluster . var ; } | Sets this cluster equal to the specified cluster | 85 | 9 |
17,264 | void add ( GvmCluster < S , K > cluster ) { if ( cluster == this ) throw new IllegalArgumentException ( ) ; if ( cluster . count == 0 ) return ; //nothing to do if ( count == 0 ) { set ( cluster ) ; } else { count += cluster . count ; //TODO accelerate add m0 += cluster . m0 ; clusters . space . add ( m1 , cluster . m1 ) ; clusters . space . add ( m2 , cluster . m2 ) ; update ( ) ; } } | Adds the specified cluster to this cluster . | 115 | 8 |
17,265 | public static synchronized String char2DOS437 ( StringBuffer stringbuffer , int i , char c ) { if ( unicode2DOS437 == null ) { unicode2DOS437 = new char [ 0x10000 ] ; for ( int j = 0 ; j < 256 ; j ++ ) { char c1 ; if ( ( c1 = unicode [ 2 ] [ j ] ) != ' ' ) unicode2DOS437 [ c1 ] = ( char ) j ; } } if ( i != 2 ) { StringBuffer stringbuffer1 = new StringBuffer ( stringbuffer . length ( ) ) ; for ( int k = 0 ; k < stringbuffer . length ( ) ; k ++ ) { char c2 = unicode2DOS437 [ stringbuffer . charAt ( k ) ] ; stringbuffer1 . append ( c2 == 0 ? c : c2 ) ; } return new String ( stringbuffer1 ) ; } else { return new String ( stringbuffer ) ; } } | Char to DOS437 converter | 206 | 5 |
17,266 | public static void callAnnotated ( Object o , Class < ? extends Annotation > ann , boolean lazy ) { try { getMethodOfInterest ( o , ann ) . invoke ( o ) ; } catch ( IllegalAccessException ex ) { throw new RuntimeException ( ex ) ; } catch ( InvocationTargetException ex ) { throw new RuntimeException ( ex . getCause ( ) ) ; } catch ( IllegalArgumentException ex ) { if ( ! lazy ) { throw new RuntimeException ( ex . getMessage ( ) ) ; } } } | Call an method by Annotation . | 113 | 7 |
17,267 | public static Class infoClass ( Class cmp ) { Class info = null ; try { info = Class . forName ( cmp . getName ( ) + "CompInfo" ) ; } catch ( ClassNotFoundException E ) { // there is no info class, info = cmp ; } return info ; } | Get the info class for a component object | 66 | 8 |
17,268 | public static boolean adjustOutputPath ( File outputDir , Object comp , Logger log ) { boolean adjusted = false ; ComponentAccess cp = new ComponentAccess ( comp ) ; for ( Access in : cp . inputs ( ) ) { String fieldName = in . getField ( ) . getName ( ) ; Class fieldType = in . getField ( ) . getType ( ) ; if ( fieldType == File . class ) { Role role = in . getField ( ) . getAnnotation ( Role . class ) ; if ( role != null && Annotations . plays ( role , Role . OUTPUT ) ) { try { File f = ( File ) in . getField ( ) . get ( comp ) ; if ( f != null && ! f . isAbsolute ( ) ) { f = new File ( outputDir , f . getName ( ) ) ; in . setFieldValue ( f ) ; adjusted = true ; if ( log . isLoggable ( Level . CONFIG ) ) { log . config ( "Adjusting output for '" + fieldName + "' to " + f ) ; } } } catch ( Exception ex ) { throw new ComponentException ( "Failed adjusting output path for '" + fieldName ) ; } } } } return adjusted ; } | Adjust the output path . | 265 | 5 |
17,269 | public static Properties createDefault ( Object comp ) { Properties p = new Properties ( ) ; ComponentAccess ca = new ComponentAccess ( comp ) ; // over all input slots. for ( Access in : ca . inputs ( ) ) { try { String name = in . getField ( ) . getName ( ) ; Object o = in . getField ( ) . get ( comp ) ; if ( o != null ) { String value = o . toString ( ) ; p . put ( name , value ) ; } } catch ( Exception ex ) { throw new ComponentException ( "Failed access to field: " + in . getField ( ) . getName ( ) ) ; } } return p ; } | Create a default parameter set | 146 | 5 |
17,270 | public static GridCoverage2D cut ( GridCoverage2D raster , GridCoverage2D mask ) throws Exception { OmsCutOut cutDrain = new OmsCutOut ( ) ; cutDrain . inRaster = raster ; cutDrain . inMask = mask ; cutDrain . process ( ) ; return cutDrain . outRaster ; } | Cut a raster on a mask using the default parameters . | 81 | 12 |
17,271 | private void addMessage ( ValidationMessage < Origin > message ) { if ( message == null ) { return ; } if ( null != defaultOrigin ) { message . addOrigin ( defaultOrigin ) ; } this . messages . add ( message ) ; } | Adds a validation message to the result . | 52 | 8 |
17,272 | public int count ( Severity severity ) { int result = 0 ; if ( severity == null ) { return result ; } for ( ValidationMessage < Origin > message : messages ) { if ( severity . equals ( message . getSeverity ( ) ) ) { result ++ ; } } return result ; } | Counts validation messages by its severity . | 64 | 8 |
17,273 | public void removeMessage ( String messageId ) { Collection < ValidationMessage < Origin >> toRemove = new ArrayList < ValidationMessage < Origin > > ( ) ; for ( ValidationMessage < Origin > message : messages ) { if ( messageId . equals ( message . getMessageKey ( ) ) ) { toRemove . add ( message ) ; } } messages . removeAll ( toRemove ) ; } | removes all messages with a specified message id | 85 | 9 |
17,274 | public int compareTo ( Object o ) { BoundablePair nd = ( BoundablePair ) o ; if ( distance < nd . distance ) return - 1 ; if ( distance > nd . distance ) return 1 ; return 0 ; } | Compares two pairs based on their minimum distances | 53 | 9 |
17,275 | double b ( int i , double t ) { switch ( i ) { case - 2 : return ( ( ( - t + 3 ) * t - 3 ) * t + 1 ) / 6 ; case - 1 : return ( ( ( 3 * t - 6 ) * t ) * t + 4 ) / 6 ; case 0 : return ( ( ( - 3 * t + 3 ) * t + 3 ) * t + 1 ) / 6 ; case 1 : return ( t * t * t ) / 6 ; } return 0 ; // we only get here if an invalid i is specified } | the basis function for a cubic B spline | 123 | 9 |
17,276 | private Coordinate p ( int i , double t ) { double px = 0 ; double py = 0 ; for ( int j = - 2 ; j <= 1 ; j ++ ) { Coordinate coordinate = pts . get ( i + j ) ; px += b ( j , t ) * coordinate . x ; py += b ( j , t ) * coordinate . y ; } return new Coordinate ( px , py ) ; } | evaluate a point on the B spline | 92 | 8 |
17,277 | public static void oddEvenSort ( List < Double > listToBeSorted , List < Double > listThatFollowsTheSort ) { for ( int i = 0 ; i < listToBeSorted . size ( ) / 2 ; i ++ ) { for ( int j = 0 ; j + 1 < listToBeSorted . size ( ) ; j += 2 ) if ( listToBeSorted . get ( j ) > listToBeSorted . get ( j + 1 ) ) { double tmpa = listToBeSorted . get ( j ) ; listToBeSorted . set ( j , listToBeSorted . get ( j + 1 ) ) ; listToBeSorted . set ( j + 1 , tmpa ) ; if ( listThatFollowsTheSort != null ) { double tmpb = listThatFollowsTheSort . get ( j ) ; listThatFollowsTheSort . set ( j , listThatFollowsTheSort . get ( j + 1 ) ) ; listThatFollowsTheSort . set ( j + 1 , tmpb ) ; } } for ( int j = 1 ; j + 1 < listToBeSorted . size ( ) ; j += 2 ) if ( listToBeSorted . get ( j ) > listToBeSorted . get ( j + 1 ) ) { double tmpa = listToBeSorted . get ( j ) ; listToBeSorted . set ( j , listToBeSorted . get ( j + 1 ) ) ; listToBeSorted . set ( j + 1 , tmpa ) ; if ( listThatFollowsTheSort != null ) { double tmpb = listThatFollowsTheSort . get ( j ) ; listThatFollowsTheSort . set ( j , listThatFollowsTheSort . get ( j + 1 ) ) ; listThatFollowsTheSort . set ( j + 1 , tmpb ) ; } } } } | Sorts two lists regarding to the sort of the first | 416 | 11 |
17,278 | protected double simpson ( ) { double s = 0f ; double st = 0f ; double ost = 0f ; double os = 0f ; for ( int i = 1 ; i < maxsteps ; i ++ ) { st = trapezoid ( i ) ; s = ( 4f * st - ost ) / 3f ; if ( i > 5 ) { if ( Math . abs ( s - os ) < accuracy * Math . abs ( os ) || ( s == 0f && os == 0f ) ) { return s ; } } os = s ; ost = st ; } return 0d ; } | Calculate the integral with the simpson method of the equation implemented in the method equation | 129 | 18 |
17,279 | protected double trapezoid ( int n ) { double x = 0 ; double tnm = 0 ; double sum = 0 ; double del = 0 ; int it = 0 ; int j = 0 ; if ( n == 1 ) { strapezoid = 0.5f * ( upperlimit - lowerlimit ) * ( equation ( lowerlimit ) + equation ( upperlimit ) ) ; } else { /* * for (it = 1, j = 1; j < n - 1; j++) { it <<= 1; } */ it = ( int ) Math . pow ( 2.0 , n - 1 ) ; tnm = ( double ) it ; del = ( upperlimit - lowerlimit ) / tnm ; x = lowerlimit + 0.5f * del ; for ( sum = 0f , j = 1 ; j <= it ; j ++ , x += del ) { if ( x >= upperlimit ) { System . out . println ( "hoi" ) ; } sum += equation ( x ) ; } strapezoid = ( double ) ( 0.5f * ( strapezoid + ( upperlimit - lowerlimit ) * sum / tnm ) ) ; } return strapezoid ; } | Calculate the integral with the trapezoidal algorithm of the equation implemented in the method equation | 253 | 19 |
17,280 | public static double [ ] tileLatLonBounds ( int tx , int ty , int zoom , int tileSize ) { double [ ] bounds = tileBounds3857 ( tx , ty , zoom , tileSize ) ; double [ ] mins = metersToLatLon ( bounds [ 0 ] , bounds [ 1 ] ) ; double [ ] maxs = metersToLatLon ( bounds [ 2 ] , bounds [ 3 ] ) ; return new double [ ] { mins [ 1 ] , maxs [ 0 ] , maxs [ 1 ] , mins [ 0 ] } ; } | Get lat - long bounds from tile index . | 122 | 9 |
17,281 | public static double metersYToLatitude ( double y ) { return Math . toDegrees ( Math . atan ( Math . sinh ( y / EQUATORIALRADIUS ) ) ) ; } | Convert a meter measure to a latitude | 45 | 8 |
17,282 | public void addGeometryXYColumnAndIndex ( String tableName , String geomColName , String geomType , String epsg , boolean avoidIndex ) throws Exception { String epsgStr = "4326" ; if ( epsg != null ) { epsgStr = epsg ; } String geomTypeStr = "LINESTRING" ; if ( geomType != null ) { geomTypeStr = geomType ; } if ( geomColName == null ) { geomColName = ASpatialDb . DEFAULT_GEOM_FIELD_NAME ; } String _geomColName = geomColName ; String _epsgStr = epsgStr ; String _geomTypeStr = geomTypeStr ; pgDb . execOnConnection ( connection -> { try ( IHMStatement stmt = connection . createStatement ( ) ) { String sql = sqlTemplates . addGeometryColumn ( tableName , _geomColName , _epsgStr , _geomTypeStr , "2" ) ; stmt . execute ( sql ) ; if ( ! avoidIndex ) { sql = sqlTemplates . createSpatialIndex ( tableName , _geomColName ) ; stmt . execute ( sql ) ; } } return null ; } ) ; } | Adds a geometry column to a table . | 281 | 8 |
17,283 | public BufferedImage getTile ( int x , int y , int z ) throws Exception { try ( PreparedStatement statement = connection . prepareStatement ( SELECTQUERY ) ) { statement . setInt ( 1 , z ) ; statement . setInt ( 2 , x ) ; statement . setInt ( 3 , y ) ; ResultSet resultSet = statement . executeQuery ( ) ; if ( resultSet . next ( ) ) { byte [ ] imageBytes = resultSet . getBytes ( 1 ) ; boolean orig = ImageIO . getUseCache ( ) ; ImageIO . setUseCache ( false ) ; InputStream in = new ByteArrayInputStream ( imageBytes ) ; BufferedImage bufferedImage = ImageIO . read ( in ) ; ImageIO . setUseCache ( orig ) ; return bufferedImage ; } } return null ; } | Get a Tile image from the database . | 176 | 8 |
17,284 | public static BufferedImage readGridcoverageImageForTile ( AbstractGridCoverage2DReader reader , int x , int y , int zoom , CoordinateReferenceSystem resampleCrs ) throws IOException { double north = tile2lat ( y , zoom ) ; double south = tile2lat ( y + 1 , zoom ) ; double west = tile2lon ( x , zoom ) ; double east = tile2lon ( x + 1 , zoom ) ; Coordinate ll = new Coordinate ( west , south ) ; Coordinate ur = new Coordinate ( east , north ) ; try { CoordinateReferenceSystem sourceCRS = DefaultGeographicCRS . WGS84 ; MathTransform transform = CRS . findMathTransform ( sourceCRS , resampleCrs ) ; ll = JTS . transform ( ll , null , transform ) ; ur = JTS . transform ( ur , null , transform ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } BufferedImage image = ImageUtilities . imageFromReader ( reader , TILESIZE , TILESIZE , ll . x , ur . x , ll . y , ur . y , resampleCrs ) ; return image ; } | Read the image of a tile from a generic geotools coverage reader . | 259 | 15 |
17,285 | public int [ ] convertToArray ( ) { int [ ] p = new int [ size ] ; for ( int j = 0 ; j < height ; ++ j ) { for ( int i = 0 ; i < width ; ++ i ) { p [ ( j * width ) + i ] = pixels [ i ] [ j ] ; } } return p ; } | Converts the 2D array into a 1D array of pixel values . | 76 | 15 |
17,286 | public void generatePixels ( HashSet < Point > pix ) { // Reset all pixels to background for ( int j = 0 ; j < height ; ++ j ) { for ( int i = 0 ; i < width ; ++ i ) { pixels [ i ] [ j ] = BACKGROUND ; } } convertToPixels ( pix ) ; } | Generates a new 2D array of pixels from a hash set of foreground pixels . | 74 | 17 |
17,287 | public void convertToPixels ( HashSet < Point > pix ) { Iterator < Point > it = pix . iterator ( ) ; while ( it . hasNext ( ) ) { Point p = it . next ( ) ; pixels [ p . x ] [ p . y ] = FOREGROUND ; } } | Adds the pixels from a hash set to the 2D array of pixels . | 67 | 15 |
17,288 | public void generateForegroundEdge ( ) { foregroundEdgePixels . clear ( ) ; Point p ; for ( int n = 0 ; n < height ; ++ n ) { for ( int m = 0 ; m < width ; ++ m ) { if ( pixels [ m ] [ n ] == FOREGROUND ) { p = new Point ( m , n ) ; for ( int j = - 1 ; j < 2 ; ++ j ) { for ( int i = - 1 ; i < 2 ; ++ i ) { if ( ( p . x + i >= 0 ) && ( p . x + i < width ) && ( p . y + j >= 0 ) && ( p . y + j < height ) ) { if ( ( pixels [ p . x + i ] [ p . y + j ] == BACKGROUND ) && ( ! foregroundEdgePixels . contains ( p ) ) ) { foregroundEdgePixels . add ( p ) ; } } } } } } } } | Generates the foreground edge hash set from the 2D array of pixels . | 206 | 15 |
17,289 | public void generateBackgroundEdgeFromForegroundEdge ( ) { backgroundEdgePixels . clear ( ) ; Point p , p2 ; Iterator < Point > it = foregroundEdgePixels . iterator ( ) ; while ( it . hasNext ( ) ) { p = new Point ( it . next ( ) ) ; for ( int j = - 1 ; j < 2 ; ++ j ) { for ( int i = - 1 ; i < 2 ; ++ i ) { if ( ( p . x + i >= 0 ) && ( p . x + i < width ) && ( p . y + j >= 0 ) && ( p . y + j < height ) ) { p2 = new Point ( p . x + i , p . y + j ) ; if ( pixels [ p2 . x ] [ p2 . y ] == BACKGROUND ) { backgroundEdgePixels . add ( p2 ) ; } } } } } } | Generates the background edge hash set from the foreground edge hash set and the 2D array of pixels . | 196 | 21 |
17,290 | public String nextValue ( ) throws IOException { Token tkn = nextToken ( ) ; String ret = null ; switch ( tkn . type ) { case TT_TOKEN : case TT_EORECORD : ret = tkn . content . toString ( ) ; break ; case TT_EOF : ret = null ; break ; case TT_INVALID : default : // error no token available (or error) throw new IOException ( "(line " + getLineNumber ( ) + ") invalid parse sequence" ) ; /// unreachable: break; } return ret ; } | Parses the CSV according to the given strategy and returns the next csv - value as string . | 124 | 21 |
17,291 | public String [ ] getLine ( ) throws IOException { String [ ] ret = EMPTY_STRING_ARRAY ; record . clear ( ) ; while ( true ) { reusableToken . reset ( ) ; nextToken ( reusableToken ) ; switch ( reusableToken . type ) { case TT_TOKEN : record . add ( reusableToken . content . toString ( ) ) ; break ; case TT_EORECORD : record . add ( reusableToken . content . toString ( ) ) ; break ; case TT_EOF : if ( reusableToken . isReady ) { record . add ( reusableToken . content . toString ( ) ) ; } else { ret = null ; } break ; case TT_INVALID : default : // error: throw IOException throw new IOException ( "(line " + getLineNumber ( ) + ") invalid parse sequence" ) ; // unreachable: break; } if ( reusableToken . type != TT_TOKEN ) { break ; } } if ( ! record . isEmpty ( ) ) { ret = ( String [ ] ) record . toArray ( new String [ record . size ( ) ] ) ; } return ret ; } | Parses from the current point in the stream til the end of the current line . | 248 | 18 |
17,292 | Token nextToken ( Token tkn ) throws IOException { wsBuf . clear ( ) ; // resuse // get the last read char (required for empty line detection) int lastChar = in . readAgain ( ) ; // read the next char and set eol /* note: unfourtunately isEndOfLine may consumes a character silently. * this has no effect outside of the method. so a simple workaround * is to call 'readAgain' on the stream... * uh: might using objects instead of base-types (jdk1.5 autoboxing!) */ int c = in . read ( ) ; boolean eol = isEndOfLine ( c ) ; c = in . readAgain ( ) ; // empty line detection: eol AND (last char was EOL or beginning) while ( strategy . getIgnoreEmptyLines ( ) && eol && ( lastChar == ' ' || lastChar == ExtendedBufferedReader . UNDEFINED ) && ! isEndOfFile ( lastChar ) ) { // go on char ahead ... lastChar = c ; c = in . read ( ) ; eol = isEndOfLine ( c ) ; c = in . readAgain ( ) ; // reached end of file without any content (empty line at the end) if ( isEndOfFile ( c ) ) { tkn . type = TT_EOF ; return tkn ; } } // did we reached eof during the last iteration already ? TT_EOF if ( isEndOfFile ( lastChar ) || ( lastChar != strategy . getDelimiter ( ) && isEndOfFile ( c ) ) ) { tkn . type = TT_EOF ; return tkn ; } // important: make sure a new char gets consumed in each iteration while ( ! tkn . isReady ) { // ignore whitespaces at beginning of a token while ( isWhitespace ( c ) && ! eol ) { wsBuf . append ( ( char ) c ) ; c = in . read ( ) ; eol = isEndOfLine ( c ) ; } // ok, start of token reached: comment, encapsulated, or token if ( c == strategy . getCommentStart ( ) ) { // ignore everything till end of line and continue (incr linecount) in . readLine ( ) ; tkn = nextToken ( tkn . reset ( ) ) ; } else if ( c == strategy . getDelimiter ( ) ) { // empty token return TT_TOKEN("") tkn . type = TT_TOKEN ; tkn . isReady = true ; } else if ( eol ) { // empty token return TT_EORECORD("") //noop: tkn.content.append(""); tkn . type = TT_EORECORD ; tkn . isReady = true ; } else if ( c == strategy . getEncapsulator ( ) ) { // consume encapsulated token encapsulatedTokenLexer ( tkn , c ) ; } else if ( isEndOfFile ( c ) ) { // end of file return TT_EOF() //noop: tkn.content.append(""); tkn . type = TT_EOF ; tkn . isReady = true ; } else { // next token must be a simple token // add removed blanks when not ignoring whitespace chars... if ( ! strategy . getIgnoreLeadingWhitespaces ( ) ) { tkn . content . append ( wsBuf ) ; } simpleTokenLexer ( tkn , c ) ; } } return tkn ; } | Returns the next token . | 762 | 5 |
17,293 | private Token simpleTokenLexer ( Token tkn , int c ) throws IOException { for ( ; ; ) { if ( isEndOfLine ( c ) ) { // end of record tkn . type = TT_EORECORD ; tkn . isReady = true ; break ; } else if ( isEndOfFile ( c ) ) { // end of file tkn . type = TT_EOF ; tkn . isReady = true ; break ; } else if ( c == strategy . getDelimiter ( ) ) { // end of token tkn . type = TT_TOKEN ; tkn . isReady = true ; break ; } else if ( c == ' ' && strategy . getUnicodeEscapeInterpretation ( ) && in . lookAhead ( ) == ' ' ) { // interpret unicode escaped chars (like \u0070 -> p) tkn . content . append ( ( char ) unicodeEscapeLexer ( c ) ) ; } else if ( c == strategy . getEscape ( ) ) { tkn . content . append ( ( char ) readEscape ( c ) ) ; } else { tkn . content . append ( ( char ) c ) ; } c = in . read ( ) ; } if ( strategy . getIgnoreTrailingWhitespaces ( ) ) { tkn . content . trimTrailingWhitespace ( ) ; } return tkn ; } | A simple token lexer | 304 | 5 |
17,294 | private Token encapsulatedTokenLexer ( Token tkn , int c ) throws IOException { // save current line int startLineNumber = getLineNumber ( ) ; // ignore the given delimiter // assert c == delimiter; for ( ; ; ) { c = in . read ( ) ; if ( c == ' ' && strategy . getUnicodeEscapeInterpretation ( ) && in . lookAhead ( ) == ' ' ) { tkn . content . append ( ( char ) unicodeEscapeLexer ( c ) ) ; } else if ( c == strategy . getEscape ( ) ) { tkn . content . append ( ( char ) readEscape ( c ) ) ; } else if ( c == strategy . getEncapsulator ( ) ) { if ( in . lookAhead ( ) == strategy . getEncapsulator ( ) ) { // double or escaped encapsulator -> add single encapsulator to token c = in . read ( ) ; tkn . content . append ( ( char ) c ) ; } else { // token finish mark (encapsulator) reached: ignore whitespace till delimiter for ( ; ; ) { c = in . read ( ) ; if ( c == strategy . getDelimiter ( ) ) { tkn . type = TT_TOKEN ; tkn . isReady = true ; return tkn ; } else if ( isEndOfFile ( c ) ) { tkn . type = TT_EOF ; tkn . isReady = true ; return tkn ; } else if ( isEndOfLine ( c ) ) { // ok eo token reached tkn . type = TT_EORECORD ; tkn . isReady = true ; return tkn ; } else if ( ! isWhitespace ( c ) ) { // error invalid char between token and next delimiter throw new IOException ( "(line " + getLineNumber ( ) + ") invalid char between encapsulated token end delimiter" ) ; } } } } else if ( isEndOfFile ( c ) ) { // error condition (end of file before end of token) throw new IOException ( "(startline " + startLineNumber + ")" + "eof reached before encapsulated token finished" ) ; } else { // consume character tkn . content . append ( ( char ) c ) ; } } } | An encapsulated token lexer | 498 | 6 |
17,295 | protected int unicodeEscapeLexer ( int c ) throws IOException { int ret = 0 ; // ignore 'u' (assume c==\ now) and read 4 hex digits c = in . read ( ) ; code . clear ( ) ; try { for ( int i = 0 ; i < 4 ; i ++ ) { c = in . read ( ) ; if ( isEndOfFile ( c ) || isEndOfLine ( c ) ) { throw new NumberFormatException ( "number too short" ) ; } code . append ( ( char ) c ) ; } ret = Integer . parseInt ( code . toString ( ) , 16 ) ; } catch ( NumberFormatException e ) { throw new IOException ( "(line " + getLineNumber ( ) + ") Wrong unicode escape sequence found '" + code . toString ( ) + "'" + e . toString ( ) ) ; } return ret ; } | Decodes Unicode escapes . | 197 | 5 |
17,296 | private boolean isEndOfLine ( int c ) throws IOException { // check if we have \r\n... if ( c == ' ' ) { if ( in . lookAhead ( ) == ' ' ) { // note: does not change c outside of this method !! c = in . read ( ) ; } } return ( c == ' ' ) ; } | Greedy - accepts \ n and \ r \ n This checker consumes silently the second control - character ... | 77 | 22 |
17,297 | private WritableRaster skyviewfactor ( WritableRaster pitWR , double res ) { /* * evalutating the normal vector (in the center of the square compound * of 4 pixel. */ normalVectorWR = normalVector ( pitWR , res ) ; WritableRaster skyviewFactorWR = CoverageUtilities . createWritableRaster ( cols , rows , null , pitWR . getSampleModel ( ) , 0.0 ) ; pm . beginTask ( msg . message ( "skyview.calculating" ) , 35 ) ; for ( int i = 0 ; i < 360 - 10 ; i = i + 10 ) { azimuth = Math . toRadians ( i * 1.0 ) ; WritableRaster skyViewWR = CoverageUtilities . createWritableRaster ( cols , rows , null , pitWR . getSampleModel ( ) , Math . toRadians ( maxSlope ) ) ; for ( int j = ( int ) maxSlope ; j >= 0 ; j -- ) { elevation = Math . toRadians ( j * 1.0 ) ; double [ ] sunVector = calcSunVector ( ) ; double [ ] inverseSunVector = calcInverseSunVector ( sunVector ) ; double [ ] normalSunVector = calcNormalSunVector ( sunVector ) ; calculateFactor ( rows , cols , sunVector , inverseSunVector , normalSunVector , pitWR , skyViewWR , res ) ; } for ( int t = normalVectorWR . getMinY ( ) ; t < normalVectorWR . getMinY ( ) + normalVectorWR . getHeight ( ) ; t ++ ) { for ( int k = normalVectorWR . getMinX ( ) ; k < normalVectorWR . getMinX ( ) + normalVectorWR . getWidth ( ) ; k ++ ) { double tmp = skyViewWR . getSampleDouble ( k , t , 0 ) ; skyViewWR . setSample ( k , t , 0 , Math . cos ( tmp ) * Math . cos ( tmp ) * 10.0 / 360.0 ) ; } } for ( int q = 0 ; q < skyviewFactorWR . getWidth ( ) ; q ++ ) { for ( int k = 0 ; k < skyviewFactorWR . getHeight ( ) ; k ++ ) { double tmp = skyviewFactorWR . getSampleDouble ( q , k , 0 ) ; skyviewFactorWR . setSample ( q , k , 0 , tmp + skyViewWR . getSampleDouble ( q , k , 0 ) ) ; } } pm . worked ( 1 ) ; } pm . done ( ) ; return skyviewFactorWR ; } | Calculate the skyview factor . | 566 | 8 |
17,298 | protected WritableRaster shadow ( int x , int y , WritableRaster tmpWR , WritableRaster pitWR , double res , double [ ] normalSunVector , double [ ] inverseSunVector , double [ ] sunVector ) { int n = 0 ; double zcompare = - Double . MAX_VALUE ; double dx = ( inverseSunVector [ 0 ] * n ) ; double dy = ( inverseSunVector [ 1 ] * n ) ; int nCols = tmpWR . getWidth ( ) ; int nRows = tmpWR . getHeight ( ) ; int idx = ( int ) ( x + dx ) ; int jdy = ( int ) ( y + dy ) ; double vectorToOrigin [ ] = new double [ 3 ] ; while ( idx >= 0 && idx <= nCols - 1 && jdy >= 0 && jdy <= nRows - 1 ) { vectorToOrigin [ 0 ] = dx * res ; vectorToOrigin [ 1 ] = dy * res ; vectorToOrigin [ 2 ] = pitWR . getSampleDouble ( idx , jdy , 0 ) ; double zprojection = scalarProduct ( vectorToOrigin , normalSunVector ) ; double nGrad [ ] = normalVectorWR . getPixel ( idx , jdy , new double [ 3 ] ) ; double cosinc = scalarProduct ( sunVector , nGrad ) ; double elevRad = elevation ; if ( ( cosinc >= 0 ) && ( zprojection > zcompare ) ) { tmpWR . setSample ( idx , jdy , 0 , elevRad ) ; zcompare = zprojection ; } n = n + 1 ; dy = ( inverseSunVector [ 1 ] * n ) ; dx = ( inverseSunVector [ 0 ] * n ) ; idx = ( int ) Math . round ( x + dx ) ; jdy = ( int ) Math . round ( y + dy ) ; } return tmpWR ; } | Calculate the angle . | 417 | 6 |
17,299 | public boolean connectIfPossible ( MonitoringPoint monitoringPoint ) { // check if the other point has this as related id if ( ID == monitoringPoint . getRelatedID ( ) ) { pfafRelatedMonitoringPointsTable . put ( monitoringPoint . getPfatstetterNumber ( ) . toString ( ) , monitoringPoint ) ; return true ; } return false ; } | Tries to connect another monitoringpoint if that one has a related id equal to that of this object . That way it would be possible to add more than one point as related . | 78 | 36 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.