idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
6,800
@ Pure public int lastIndexOf ( RoadSegment segment ) { int count = 0 ; int index ; int lastIndex = - 1 ; for ( final RoadPath p : this . paths ) { index = p . lastIndexOf ( segment ) ; if ( index >= 0 ) { lastIndex = count + index ; } count += p . size ( ) ; } return lastIndex ; }
Replies the index of the last occurrence . of the given road segment .
81
15
6,801
@ Pure public RoadSegment getRoadSegmentAt ( int index ) { if ( index >= 0 ) { int b = 0 ; for ( final RoadPath p : this . paths ) { final int e = b + p . size ( ) ; if ( index < e ) { return p . get ( index - b ) ; } b = e ; } } throw new IndexOutOfBoundsException ( ) ; }
Replies the road segment at the given index .
88
10
6,802
@ Pure public RoadPath getPathForRoadSegmentAt ( int index ) { if ( index >= 0 ) { int b = 0 ; for ( final RoadPath p : this . paths ) { final int e = b + p . size ( ) ; if ( index < e ) { return p ; } b = e ; } } throw new IndexOutOfBoundsException ( ) ; }
Replies the road path which is containing the road segment at the given index .
82
16
6,803
public RoadSegment removeRoadSegmentAt ( int index ) { if ( index >= 0 ) { int b = 0 ; for ( final RoadPath p : this . paths ) { int end = b + p . size ( ) ; if ( index < end ) { end = index - b ; return removeRoadSegmentAt ( p , end , null ) ; } b = end ; } } throw new IndexOutOfBoundsException ( ) ; }
Remove the road segment at the given index .
95
9
6,804
private RoadSegment removeRoadSegmentAt ( RoadPath path , int index , PathIterator iterator ) { final int pathIndex = this . paths . indexOf ( path ) ; assert pathIndex >= 0 && pathIndex < this . paths . size ( ) ; assert index >= 0 && index < path . size ( ) ; final RoadPath syncPath ; final RoadSegment sgmt ; if ( index == 0 || index == path . size ( ) - 1 ) { // Remove one of the bounds of the path. if cause // minimal insertion changes in the clustered road-path sgmt = path . remove ( index ) ; } else { // Split the path somewhere between the first and last positions sgmt = path . get ( index ) ; assert sgmt != null ; final RoadPath rest = path . splitAfter ( sgmt ) ; path . remove ( sgmt ) ; if ( rest != null && ! rest . isEmpty ( ) ) { // put back the rest of the segments this . paths . add ( pathIndex + 1 , rest ) ; } } -- this . segmentCount ; if ( path . isEmpty ( ) ) { this . paths . remove ( path ) ; if ( pathIndex > 0 ) { syncPath = this . paths . get ( pathIndex - 1 ) ; } else { syncPath = null ; } } else { syncPath = path ; } if ( iterator != null ) { iterator . reset ( syncPath ) ; } return sgmt ; }
Remove the road segment at the given index in the given path .
314
13
6,805
@ SuppressWarnings ( { "checkstyle:cyclomaticcomplexity" , "checkstyle:npathcomplexity" , "checkstyle:nestedifdepth" } ) public RoadPath addAndGetPath ( RoadPath end ) { RoadPath selectedPath = null ; if ( end != null && ! end . isEmpty ( ) ) { RoadConnection first = end . getFirstPoint ( ) ; RoadConnection last = end . getLastPoint ( ) ; assert first != null ; assert last != null ; first = first . getWrappedRoadConnection ( ) ; last = last . getWrappedRoadConnection ( ) ; assert first != null ; assert last != null ; if ( this . paths . isEmpty ( ) ) { this . paths . add ( end ) ; selectedPath = end ; } else { RoadPath connectToFirst = null ; RoadPath connectToLast = null ; final Iterator < RoadPath > pathIterator = this . paths . iterator ( ) ; RoadPath path ; while ( ( connectToFirst == null || connectToLast == null ) && pathIterator . hasNext ( ) ) { path = pathIterator . next ( ) ; if ( connectToFirst == null ) { if ( first . equals ( path . getFirstPoint ( ) ) ) { connectToFirst = path ; } else if ( first . equals ( path . getLastPoint ( ) ) ) { connectToFirst = path ; } } if ( connectToLast == null ) { if ( last . equals ( path . getFirstPoint ( ) ) ) { connectToLast = path ; } else if ( last . equals ( path . getLastPoint ( ) ) ) { connectToLast = path ; } } } if ( connectToFirst != null && connectToLast != null && ! connectToLast . equals ( connectToFirst ) ) { // a) Select the biggest path as reference // b) Remove the nonreference path that is connected to the new path // c) Add the components of the new path into the reference path // d) Reinject the components of the nonreference path. // -- // a) final RoadPath reference ; final RoadPath nonreference ; if ( connectToFirst . size ( ) > connectToLast . size ( ) ) { reference = connectToFirst ; nonreference = connectToLast ; } else { reference = connectToLast ; nonreference = connectToFirst ; } // b) if ( this . paths . remove ( nonreference ) ) { // c) if ( ! RoadPath . addPathToPath ( reference , end ) ) { // Reinject the remove elements. this . paths . add ( nonreference ) ; } else { // d) if ( ! RoadPath . addPathToPath ( reference , nonreference ) ) { // Reinject the remove elements. this . paths . add ( nonreference ) ; } else { selectedPath = reference ; } } } } else if ( connectToFirst != null ) { if ( RoadPath . addPathToPath ( connectToFirst , end ) ) { selectedPath = connectToFirst ; } } else if ( connectToLast != null ) { if ( RoadPath . addPathToPath ( connectToLast , end ) ) { selectedPath = connectToLast ; } } else if ( this . paths . add ( end ) ) { selectedPath = end ; } } if ( selectedPath != null ) { this . segmentCount += end . size ( ) ; } } return selectedPath ; }
Add the given road path into this cluster of road paths .
727
12
6,806
boolean setParentNodeReference ( N newParent , boolean fireEvent ) { final N oldParent = getParentNode ( ) ; if ( newParent == oldParent ) { return false ; } this . parent = ( newParent == null ) ? null : new WeakReference <> ( newParent ) ; if ( ! fireEvent ) { return true ; } firePropertyParentChanged ( oldParent , newParent ) ; if ( oldParent != null ) { oldParent . firePropertyParentChanged ( toN ( ) , oldParent , newParent ) ; } return false ; }
Set the reference to the parent node .
119
8
6,807
void firePropertyChildAdded ( TreeNodeAddedEvent event ) { if ( this . nodeListeners != null ) { for ( final TreeNodeListener listener : this . nodeListeners ) { if ( listener != null ) { listener . treeNodeChildAdded ( event ) ; } } } final N parentNode = getParentNode ( ) ; assert parentNode != this ; if ( parentNode != null ) { parentNode . firePropertyChildAdded ( event ) ; } }
Fire the event for the node child sets .
97
9
6,808
void firePropertyChildRemoved ( TreeNodeRemovedEvent event ) { if ( this . nodeListeners != null ) { for ( final TreeNodeListener listener : this . nodeListeners ) { if ( listener != null ) { listener . treeNodeChildRemoved ( event ) ; } } } final N parentNode = getParentNode ( ) ; if ( parentNode != null ) { parentNode . firePropertyChildRemoved ( event ) ; } }
Fire the event for the removed node child .
91
9
6,809
public static Function < Iterable < ? > , String > joinFunction ( final Joiner joiner ) { return new Function < Iterable < ? > , String > ( ) { @ Override public String apply ( final Iterable < ? > list ) { return joiner . join ( list ) ; } } ; }
Returns a Function which will join the string with the specified separator
66
13
6,810
public static Function < String , String > toLowerCaseFunction ( final Locale locale ) { return new Function < String , String > ( ) { @ Override public String apply ( final String s ) { return s . toLowerCase ( locale ) ; } @ Override public String toString ( ) { return "toLowercase(" + locale + ")" ; } } ; }
A Guava function for converting strings to lowercase .
79
11
6,811
public static UnicodeFriendlyString stripAccents ( final UnicodeFriendlyString input ) { // this nifty normalization courtesy of http://stackoverflow.com/questions/3322152/is-there-a-way-to-get-rid-of-accents-and-convert-a-whole-string-to-regular-lette return StringUtils . unicodeFriendly ( ACCENT_STRIPPER . matcher ( Normalizer . normalize ( input . utf16CodeUnits ( ) , Normalizer . Form . NFD ) ) // note this replaceAll is really deleteAll . replaceAll ( "" ) ) ; }
Removes all Unicode marks from a string . As a side effect applies NFD normalization .
140
19
6,812
public static int getKeyCode ( final char character ) throws IllegalAccessException , NoSuchFieldException { final String c = String . valueOf ( character ) . toUpperCase ( ) ; final String variableName = "VK_" + c ; final Class < KeyEvent > clazz = KeyEvent . class ; final Field field = clazz . getField ( variableName ) ; final int keyCode = field . getInt ( null ) ; return keyCode ; }
Gets the key code from the given char .
98
10
6,813
public static void typeCharacter ( final Robot robot , final char character ) throws IllegalAccessException , NoSuchFieldException { final boolean upperCase = Character . isUpperCase ( character ) ; final int keyCode = getKeyCode ( character ) ; if ( upperCase ) { robot . keyPress ( KeyEvent . VK_SHIFT ) ; } robot . keyPress ( keyCode ) ; robot . keyRelease ( keyCode ) ; if ( upperCase ) { robot . keyRelease ( KeyEvent . VK_SHIFT ) ; } }
Types the given char with the given robot .
112
9
6,814
public static void typeString ( final Robot robot , final String input ) throws NoSuchFieldException , IllegalAccessException { if ( input != null && ! input . isEmpty ( ) ) { for ( final char character : input . toCharArray ( ) ) { typeCharacter ( robot , character ) ; } } }
Type the given string with the given robot .
65
9
6,815
public < T extends MapLayer > Iterator < T > iterator ( Class < T > type ) { return new LayerReaderIterator <> ( type ) ; }
Replies an iterator on the layers of the given type and read from the input stream .
33
18
6,816
public final < T extends MapLayer > T read ( Class < T > type ) throws IOException { // Read the header if ( ! this . isHeaderRead ) { this . isHeaderRead = true ; readHeader ( ) ; if ( this . progression != null ) { this . progression . setProperties ( 0 , 0 , this . restToRead , false ) ; } } T selectedObject = null ; if ( this . restToRead > 0 ) { final ObjectInputStream oos = new ObjectInputStream ( this . input ) ; do { try { final Object readObject = oos . readObject ( ) ; -- this . restToRead ; if ( type . isInstance ( readObject ) ) { selectedObject = type . cast ( readObject ) ; } } catch ( ClassNotFoundException e ) { // } } while ( this . restToRead > 0 && selectedObject == null ) ; } if ( this . progression != null ) { if ( this . restToRead <= 0 ) { this . progression . end ( ) ; } else { this . progression . increment ( ) ; } } return selectedObject ; }
Read the next layer of the given type from the input .
238
12
6,817
@ SuppressWarnings ( { "resource" , "checkstyle:magicnumber" } ) protected void readHeader ( ) throws IOException { final ReadableByteChannel in = Channels . newChannel ( this . input ) ; final int limit = HEADER_KEY . getBytes ( ) . length + 2 ; final ByteBuffer hBuffer = ByteBuffer . allocate ( limit ) ; hBuffer . limit ( limit ) ; // Check the header final byte [ ] key = GISLayerIOConstants . HEADER_KEY . getBytes ( ) ; final int n = in . read ( hBuffer ) ; if ( n != limit ) { throw new IOException ( "Invalid file header" ) ; //$NON-NLS-1$ } for ( int i = 0 ; i < key . length ; ++ i ) { if ( hBuffer . get ( i ) != key [ i ] ) { throw new IOException ( "Invalid file header" ) ; //$NON-NLS-1$ } } // Check the format version final byte major = hBuffer . get ( key . length ) ; final byte minor = hBuffer . get ( key . length + 1 ) ; if ( major != GISLayerIOConstants . MAJOR_SPEC_NUMBER || minor != GISLayerIOConstants . MINOR_SPEC_NUMBER ) { throw new IOException ( "Invalid file format version." ) ; //$NON-NLS-1$ } // Read the number of objects inside the input stream final ByteBuffer sBuffer = ByteBuffer . allocate ( 4 ) ; sBuffer . limit ( 4 ) ; in . read ( sBuffer ) ; sBuffer . rewind ( ) ; this . restToRead = sBuffer . getInt ( ) ; }
Read the header of the file .
375
7
6,818
public LevelOfDetails getLevelOfDetails ( ) { if ( this . lod == null ) { final double meterSize = doc2fxSize ( 1 ) ; if ( meterSize <= LOW_DETAILLED_METER_SIZE ) { this . lod = LevelOfDetails . LOW ; } else if ( meterSize >= HIGH_DETAILLED_METER_SIZE ) { this . lod = LevelOfDetails . HIGH ; } else { this . lod = LevelOfDetails . NORMAL ; } } return this . lod ; }
Replies the current level of details .
113
8
6,819
@ SuppressWarnings ( { "checkstyle:magicnumber" , "static-method" } ) @ Pure public Color rgb ( int color ) { final int red = ( color & 0x00FF0000 ) >> 16 ; final int green = ( color & 0x0000FF00 ) >> 8 ; final int blue = color & 0x000000FF ; return Color . rgb ( red , green , blue ) ; }
Parse the given RGB color .
89
7
6,820
@ Pure public double doc2fxX ( double x ) { return this . centeringTransform . toCenterX ( x ) * this . scale . get ( ) + this . canvasWidth . get ( ) / 2. ; }
Transform a document x coordinate to its JavaFX equivalent .
48
11
6,821
@ Pure public double fx2docX ( double x ) { return this . centeringTransform . toGlobalX ( ( x - this . canvasWidth . get ( ) / 2. ) / this . scale . get ( ) ) ; }
Transform a JavaFX x coordinate to its document equivalent .
51
11
6,822
@ Pure public double doc2fxY ( double y ) { return this . centeringTransform . toCenterY ( y ) * this . scale . get ( ) + this . canvasHeight . get ( ) / 2. ; }
Transform a document y coordinate to its JavaFX equivalent .
48
11
6,823
@ Pure public double fx2docY ( double y ) { return this . centeringTransform . toGlobalY ( ( y - this . canvasHeight . get ( ) / 2. ) / this . scale . get ( ) ) ; }
Transform a JavaFX y coordinate to its document equivalent .
51
11
6,824
@ Pure public double doc2fxAngle ( double angle ) { final ZoomableCanvas < ? > canvas = getCanvas ( ) ; if ( canvas . isInvertedAxisX ( ) != canvas . isInvertedAxisY ( ) ) { return - angle ; } return angle ; }
Transform a document angle to its JavaFX equivalent .
64
10
6,825
@ Pure public double fx2docAngle ( double angle ) { final ZoomableCanvas < ? > canvas = getCanvas ( ) ; if ( canvas . isInvertedAxisX ( ) != canvas . isInvertedAxisY ( ) ) { return - angle ; } return angle ; }
Transform a JavaFX angle to its document equivalent .
65
10
6,826
public void restore ( ) { this . gc . restore ( ) ; if ( this . stateStack != null ) { if ( ! this . stateStack . isEmpty ( ) ) { final int [ ] data = this . stateStack . pop ( ) ; if ( this . stateStack . isEmpty ( ) ) { this . stateStack = null ; } this . bugdet = data [ 0 ] ; this . state = data [ 1 ] ; } else { this . stateStack = null ; } } }
Pops the state off of the stack setting the following attributes to their value at the time when that state was pushed onto the stack . If the stack is empty then nothing is changed .
107
37
6,827
public void fillRoundRect ( double x , double y , double width , double height , double arcWidth , double arcHeight ) { this . gc . fillRoundRect ( doc2fxX ( x ) , doc2fxY ( y ) , doc2fxSize ( width ) , doc2fxSize ( height ) , doc2fxSize ( arcWidth ) , doc2fxSize ( arcHeight ) ) ; }
Fills a rounded rectangle using the current fill paint .
88
11
6,828
public void strokeLine ( double x1 , double y1 , double x2 , double y2 ) { this . gc . strokeLine ( doc2fxX ( x1 ) , doc2fxY ( y1 ) , doc2fxX ( x2 ) , doc2fxY ( y2 ) ) ; }
Strokes a line using the current stroke paint .
68
11
6,829
@ SuppressWarnings ( { "static-method" , "checkstyle:magicnumber" } ) protected GISPolylineSet < RoadPolyline > createInternalDataStructure ( Rectangle2afp < ? , ? , ? , ? , ? , ? > originalBounds ) { /*return new MapPolylineGridSet<>(100, 100, originalBounds.getMinX(), originalBounds.getMinY(), originalBounds.getWidth(), originalBounds.getHeight());*/ return new MapPolylineTreeSet <> ( originalBounds . getMinX ( ) , originalBounds . getMinY ( ) , originalBounds . getWidth ( ) , originalBounds . getHeight ( ) ) ; }
Create the internal data structure .
158
6
6,830
@ SuppressWarnings ( "unchecked" ) @ Pure public Tree < RoadPolyline , ? > getInternalTree ( ) { if ( this . roadSegments instanceof GISTreeSet < ? , ? > ) { return ( ( GISTreeSet < RoadPolyline , ? > ) this . roadSegments ) . getTree ( ) ; } return null ; }
Replies the internal data - structure as tree .
81
10
6,831
@ Pure public LegalTrafficSide getLegalTrafficSide ( ) { final String side ; try { side = getAttributeAsString ( "LEGAL_TRAFFIC_SIDE" ) ; //$NON-NLS-1$ LegalTrafficSide sd ; try { sd = LegalTrafficSide . valueOf ( side ) ; } catch ( Throwable exception ) { sd = null ; } if ( sd != null ) { return sd ; } } catch ( Throwable exception ) { // } return RoadNetworkConstants . getPreferredLegalTrafficSide ( ) ; }
Replies the legal traffic side .
125
7
6,832
protected void fireSegmentChanged ( RoadSegment segment ) { if ( this . listeners != null && isEventFirable ( ) ) { for ( final RoadNetworkListener listener : this . listeners ) { listener . onRoadSegmentChanged ( this , segment ) ; } } }
Fire the change event .
58
5
6,833
@ Pure public Iterable < IntegerSegment > toSegmentIterable ( ) { return new Iterable < IntegerSegment > ( ) { @ Override public Iterator < IntegerSegment > iterator ( ) { return new SegmentIterator ( ) ; } } ; }
Returns an iterable object over the segments in this list in proper sequence .
57
15
6,834
public void set ( SortedSet < ? extends Number > collection ) { this . values = null ; this . size = 0 ; for ( final Number number : collection ) { final int e = number . intValue ( ) ; if ( ( this . values != null ) && ( e == this . values [ this . values . length - 1 ] + 1 ) ) { // Same group ++ this . values [ this . values . length - 1 ] ; ++ this . size ; } if ( ( this . values != null ) && ( e > this . values [ this . values . length - 1 ] + 1 ) ) { // Create a new group final int [ ] newTab = new int [ this . values . length + 2 ] ; System . arraycopy ( this . values , 0 , newTab , 0 , this . values . length ) ; newTab [ newTab . length - 2 ] = e ; newTab [ newTab . length - 1 ] = newTab [ newTab . length - 2 ] ; this . values = newTab ; ++ this . size ; } else if ( this . values == null ) { // Add the first group this . values = new int [ ] { e , e } ; this . size = 1 ; } } }
Set the content of this list from the specified collection .
263
11
6,835
@ Pure public SortedSet < Integer > toSortedSet ( ) { final SortedSet < Integer > theset = new TreeSet <> ( ) ; if ( this . values != null ) { for ( int idxStart = 0 ; idxStart < this . values . length - 1 ; idxStart += 2 ) { for ( int n = this . values [ idxStart ] ; n <= this . values [ idxStart + 1 ] ; ++ n ) { theset . add ( n ) ; } } } return theset ; }
Replies the complete list of stored integers .
118
9
6,836
protected String formatDateStr2 ( String str ) { // Initial Calendar object Calendar cal = Calendar . getInstance ( ) ; str = str . replaceAll ( "/" , "" ) ; try { // Set date with input value cal . set ( Integer . parseInt ( str . substring ( 0 , 4 ) ) , Integer . parseInt ( str . substring ( 4 , 6 ) ) - 1 , Integer . parseInt ( str . substring ( 6 ) ) ) ; // translatet to yyddd format return String . format ( "%1$02d%2$03d" , cal . get ( Calendar . YEAR ) % 100 , cal . get ( Calendar . DAY_OF_YEAR ) ) ; } catch ( Exception e ) { // if tranlate failed, then use default value for date //sbError.append("! Waring: There is a invalid date [").append(str).append("]\r\n"); return formatDateStr2 ( defValD ) ; } }
Translate data str from yyyymmdd to yyddd
214
14
6,837
protected static String formatDateStr ( String startDate , String strDays ) { // Initial Calendar object Calendar cal = Calendar . getInstance ( ) ; int days ; startDate = startDate . replaceAll ( "/" , "" ) ; try { days = Double . valueOf ( strDays ) . intValue ( ) ; // Set date with input value cal . set ( Integer . parseInt ( startDate . substring ( 0 , 4 ) ) , Integer . parseInt ( startDate . substring ( 4 , 6 ) ) - 1 , Integer . parseInt ( startDate . substring ( 6 ) ) ) ; cal . add ( Calendar . DATE , days ) ; // translatet to yyddd format return String . format ( "%1$02d%2$03d" , cal . get ( Calendar . YEAR ) % 100 , cal . get ( Calendar . DAY_OF_YEAR ) ) ; } catch ( Exception e ) { // if tranlate failed, then use default value for date // sbError.append("! Waring: There is a invalid date [").append(startDate).append("]\r\n"); return "-99" ; //formatDateStr(defValD); } }
Translate data str from yyyymmdd to yyddd plus days you want
260
18
6,838
protected String getExName ( Map result ) { String ret = getValueOr ( result , "exname" , "" ) ; if ( ret . matches ( "\\w+\\.\\w{2}[Xx]" ) ) { ret = ret . substring ( 0 , ret . length ( ) - 1 ) . replace ( "." , "" ) ; } // TODO need to be updated with a translate rule for other models' exname if ( ret . matches ( ".+(_+\\d+)+$" ) ) { ret = ret . replaceAll ( "(_+\\d+)+$" , "" ) ; } return ret ; }
Get experiment name without any extention content after first underscore
139
11
6,839
protected String getCrid ( Map result ) { HashMap mgnData = getObjectOr ( result , "management" , new HashMap ( ) ) ; ArrayList < HashMap > events = getObjectOr ( mgnData , "events" , new ArrayList ( ) ) ; String crid = null ; boolean isPlEventExist = false ; for ( HashMap event : events ) { if ( "planting" . equals ( event . get ( "event" ) ) ) { isPlEventExist = true ; if ( crid == null ) { crid = ( String ) event . get ( "crid" ) ; } else if ( ! crid . equals ( event . get ( "crid" ) ) ) { return "SQ" ; } } } if ( crid == null ) { crid = getValueOr ( result , "crid" , "XX" ) ; } if ( ! isPlEventExist && "XX" . equals ( crid ) ) { return "FA" ; } else { // DssatCRIDHelper crids = new DssatCRIDHelper(); return DssatCRIDHelper . get2BitCrid ( crid ) ; } }
Get crop id with 2 - bit format
261
8
6,840
protected synchronized String getFileName ( Map result , String fileType ) { String exname = getExName ( result ) ; String crid ; if ( getValueOr ( result , "seasonal_dome_applied" , "N" ) . equals ( "Y" ) ) { crid = "SN" ; } else { crid = getCrid ( result ) ; } if ( exname . length ( ) == 10 ) { if ( crid . equals ( "XX" ) || crid . equals ( "FA" ) ) { crid = exname . substring ( exname . length ( ) - 2 , exname . length ( ) ) ; } } String ret ; if ( exToFileMap . containsKey ( exname + "_" + crid ) ) { return exToFileMap . get ( exname + "_" + crid ) + fileType ; } else { ret = exname ; if ( ret . equals ( "" ) ) { ret = "TEMP0001" ; } else { try { if ( ret . endsWith ( crid ) ) { ret = ret . substring ( 0 , ret . length ( ) - crid . length ( ) ) ; } // If the exname is too long if ( ret . length ( ) > 8 ) { ret = ret . substring ( 0 , 8 ) ; } // If the exname do not follow the Dssat rule if ( ! ret . matches ( "[\\w ]{1,6}\\d{2}$" ) ) { if ( ret . length ( ) > 6 ) { ret = ret . substring ( 0 , 6 ) ; } ret += "01" ; } } catch ( Exception e ) { ret = "TEMP0001" ; } } // Special handling for batch if ( exname . matches ( ".+_\\d+_b\\S+(__\\d+)?$" ) ) { int idx = exname . lastIndexOf ( "_b" ) + 2 ; ret += "B" + exname . substring ( idx ) . replaceAll ( "__\\d+$" , "" ) ; } // Find a non-repeated file name int count ; while ( fileNameSet . contains ( ret + "." + crid ) ) { try { count = Integer . parseInt ( ret . substring ( ret . length ( ) - 2 , ret . length ( ) ) ) ; count ++ ; } catch ( Exception e ) { count = 1 ; } ret = ret . replaceAll ( "\\w{2}$" , String . format ( "%02d" , count ) ) ; } } exToFileMap . put ( exname + "_" + crid , ret + "." + crid ) ; fileNameSet . add ( ret + "." + crid ) ; return ret + "." + crid + fileType ; }
Generate output file name
618
5
6,841
protected void decompressData ( HashMap m ) { for ( Object key : m . keySet ( ) ) { if ( m . get ( key ) instanceof ArrayList ) { // iterate sub array nodes decompressData ( ( ArrayList ) m . get ( key ) ) ; } else if ( m . get ( key ) instanceof HashMap ) { // iterate sub data nodes decompressData ( ( HashMap ) m . get ( key ) ) ; } else { // ignore other type nodes } } }
decompress the data in a map object
109
9
6,842
protected void decompressData ( ArrayList arr ) { HashMap fstData = null ; // The first data record (Map type) HashMap cprData ; // The following data record which will be compressed for ( Object sub : arr ) { if ( sub instanceof ArrayList ) { // iterate sub array nodes decompressData ( ( ArrayList ) sub ) ; } else if ( sub instanceof HashMap ) { // iterate sub data nodes decompressData ( ( HashMap ) sub ) ; // Compress data for current array if ( fstData == null ) { // Get first data node fstData = ( HashMap ) sub ; } else { cprData = ( HashMap ) sub ; // The omitted data will be recovered to the following map; Only data item (String type) will be processed for ( Object key : fstData . keySet ( ) ) { if ( ! cprData . containsKey ( key ) ) { cprData . put ( key , fstData . get ( key ) ) ; } } } } else { } } }
decompress the data in an ArrayList object
227
10
6,843
protected String getPdate ( Map result ) { HashMap management = getObjectOr ( result , "management" , new HashMap ( ) ) ; ArrayList < HashMap > events = getObjectOr ( management , "events" , new ArrayList < HashMap > ( ) ) ; for ( HashMap event : events ) { if ( getValueOr ( event , "event" , "" ) . equals ( "planting" ) ) { return getValueOr ( event , "date" , "" ) ; } } return "" ; }
Get plating date from experiment management event
113
8
6,844
private boolean isContentTypeIn ( ZipInputStream stream ) throws IOException { boolean isContentType = false ; if ( this . innerFile != null ) { final String strInner = this . innerFile . toString ( ) ; InputStream dataStream = null ; ZipEntry zipEntry = stream . getNextEntry ( ) ; while ( zipEntry != null && dataStream == null ) { if ( strInner . equals ( zipEntry . getName ( ) ) ) { dataStream = stream ; } else { zipEntry = stream . getNextEntry ( ) ; } } if ( dataStream != null ) { isContentType = isContentType ( stream , zipEntry , dataStream ) ; } } else { isContentType = isContentType ( stream , null , null ) ; } return isContentType ; }
Replies if the given ZIP stream contains data of the expected type .
172
14
6,845
public void close ( ) throws IOException { this . accessors . clear ( ) ; if ( this . reader != null ) { this . reader . close ( ) ; this . reader = null ; } }
Close all opened accessors .
43
6
6,846
@ Pure protected DBaseFileReader getReader ( ) throws IOException { if ( this . reader == null ) { this . reader = new DBaseFileReader ( this . url . openStream ( ) ) ; this . reader . readDBFHeader ( ) ; this . reader . readDBFFields ( ) ; } return this . reader ; }
Replies the reader .
74
5
6,847
@ SuppressWarnings ( "resource" ) @ Pure public Collection < String > getAllAttributeNames ( int recordNumber ) { try { final DBaseFileReader dbReader = getReader ( ) ; synchronized ( dbReader ) { final List < DBaseFileField > fields = dbReader . getDBFFields ( ) ; if ( fields == null ) { return Collections . emptyList ( ) ; } final ArrayList < String > titles = new ArrayList <> ( fields . size ( ) ) ; for ( int i = 0 ; i < fields . size ( ) ; ++ i ) { titles . add ( fields . get ( i ) . getName ( ) ) ; } return titles ; } } catch ( IOException exception ) { return Collections . emptyList ( ) ; } }
Replies the names of all the attributes that corresponds to the specified record number .
166
16
6,848
@ SuppressWarnings ( "resource" ) @ Pure public int getAttributeCount ( ) { try { final DBaseFileReader dbReader = getReader ( ) ; synchronized ( dbReader ) { return dbReader . getDBFFieldCount ( ) ; } } catch ( IOException exception ) { return 0 ; } }
Replies the count of attributes .
68
7
6,849
@ SuppressWarnings ( "resource" ) @ Pure public Object getRawValue ( int recordNumber , String name , OutputParameter < AttributeType > type ) throws AttributeException { try { final DBaseFileReader dbReader = getReader ( ) ; synchronized ( dbReader ) { dbReader . seek ( recordNumber ) ; final DBaseFileRecord record = dbReader . readNextDBFRecord ( ) ; if ( record != null ) { final int column = dbReader . getDBFFieldIndex ( name ) ; if ( column >= 0 ) { final Object value = record . getFieldValue ( column ) ; final DBaseFieldType dbfType = dbReader . getDBFFieldType ( column ) ; type . set ( dbfType . toAttributeType ( ) ) ; return value ; } } throw new NoAttributeFoundException ( name ) ; } } catch ( IOException e ) { throw new AttributeException ( e ) ; } }
Replies the raw value that corresponds to the specified attribute name for the given record .
202
17
6,850
@ Pure public static int toLEInt ( int b1 , int b2 , int b3 , int b4 ) { return ( ( b4 & 0xFF ) << 24 ) + ( ( b3 & 0xFF ) << 16 ) + ( ( b2 & 0xFF ) << 8 ) + ( b1 & 0xFF ) ; }
Converting four bytes to a Little Endian integer .
76
11
6,851
@ Pure public static int toBEInt ( int b1 , int b2 , int b3 , int b4 ) { return ( ( b1 & 0xFF ) << 24 ) + ( ( b2 & 0xFF ) << 16 ) + ( ( b3 & 0xFF ) << 8 ) + ( b4 & 0xFF ) ; }
Converting four bytes to a Big Endian integer .
76
11
6,852
@ Pure public static long toLELong ( int b1 , int b2 , int b3 , int b4 , int b5 , int b6 , int b7 , int b8 ) { return ( ( b8 & 0xFF ) << 56 ) + ( ( b7 & 0xFF ) << 48 ) + ( ( b6 & 0xFF ) << 40 ) + ( ( b5 & 0xFF ) << 32 ) + ( ( b4 & 0xFF ) << 24 ) + ( ( b3 & 0xFF ) << 16 ) + ( ( b2 & 0xFF ) << 8 ) + ( b1 & 0xFF ) ; }
Converting eight bytes to a Little Endian integer .
144
11
6,853
@ Pure @ Inline ( value = "Double.longBitsToDouble(EndianNumbers.toLELong($1, $2, $3, $4, $5, $6, $7, $8))" , imported = { EndianNumbers . class } ) public static double toLEDouble ( int b1 , int b2 , int b3 , int b4 , int b5 , int b6 , int b7 , int b8 ) { return Double . longBitsToDouble ( toLELong ( b1 , b2 , b3 , b4 , b5 , b6 , b7 , b8 ) ) ; }
Converting eight bytes to a Little Endian double .
140
11
6,854
@ Pure @ Inline ( value = "Double.longBitsToDouble(EndianNumbers.toBELong($1, $2, $3, $4, $5, $6, $7, $8))" , imported = { EndianNumbers . class } ) public static double toBEDouble ( int b1 , int b2 , int b3 , int b4 , int b5 , int b6 , int b7 , int b8 ) { return Double . longBitsToDouble ( toBELong ( b1 , b2 , b3 , b4 , b5 , b6 , b7 , b8 ) ) ; }
Converting eight bytes to a Big Endian double .
143
11
6,855
@ Pure @ Inline ( value = "Float.intBitsToFloat(EndianNumbers.toLEInt($1, $2, $3, $4))" , imported = { EndianNumbers . class } ) public static float toLEFloat ( int b1 , int b2 , int b3 , int b4 ) { return Float . intBitsToFloat ( toLEInt ( b1 , b2 , b3 , b4 ) ) ; }
Converting four bytes to a Little Endian float .
100
11
6,856
@ Pure @ Inline ( value = "Float.intBitsToFloat(EndianNumbers.toBEInt($1, $2, $3, $4))" , imported = { EndianNumbers . class } ) public static float toBEFloat ( int b1 , int b2 , int b3 , int b4 ) { return Float . intBitsToFloat ( toBEInt ( b1 , b2 , b3 , b4 ) ) ; }
Converting four bytes to a Big Endian float .
100
11
6,857
@ Pure @ Inline ( value = "EndianNumbers.parseLEInt(Float.floatToIntBits($1))" , imported = { EndianNumbers . class } ) public static byte [ ] parseLEFloat ( float value ) { return parseLEInt ( Float . floatToIntBits ( value ) ) ; }
Converts a Java float to a Little Endian int on 4 bytes .
70
15
6,858
@ Pure public static byte [ ] parseLELong ( long value ) { return new byte [ ] { ( byte ) ( value & 0xFF ) , ( byte ) ( ( value >> 8 ) & 0xFF ) , ( byte ) ( ( value >> 16 ) & 0xFF ) , ( byte ) ( ( value >> 24 ) & 0xFF ) , ( byte ) ( ( value >> 32 ) & 0xFF ) , ( byte ) ( ( value >> 40 ) & 0xFF ) , ( byte ) ( ( value >> 48 ) & 0xFF ) , ( byte ) ( ( value >> 56 ) & 0xFF ) , } ; }
Converts a Java long to a Little Endian int on 8 bytes .
140
15
6,859
@ Pure @ Inline ( value = "EndianNumbers.parseLELong(Double.doubleToLongBits($1))" , imported = { EndianNumbers . class } ) public static byte [ ] parseLEDouble ( double value ) { return parseLELong ( Double . doubleToLongBits ( value ) ) ; }
Converts a Java double to a Little Endian int on 8 bytes .
70
15
6,860
@ Pure @ Inline ( value = "EndianNumbers.parseBEInt(Float.floatToIntBits($1))" , imported = { EndianNumbers . class } ) public static byte [ ] parseBEFloat ( float value ) { return parseBEInt ( Float . floatToIntBits ( value ) ) ; }
Converts a Java float to a Big Endian int on 4 bytes .
70
15
6,861
@ Pure public static byte [ ] parseBELong ( long value ) { return new byte [ ] { ( byte ) ( ( value >> 56 ) & 0xFF ) , ( byte ) ( ( value >> 48 ) & 0xFF ) , ( byte ) ( ( value >> 40 ) & 0xFF ) , ( byte ) ( ( value >> 32 ) & 0xFF ) , ( byte ) ( ( value >> 24 ) & 0xFF ) , ( byte ) ( ( value >> 16 ) & 0xFF ) , ( byte ) ( ( value >> 8 ) & 0xFF ) , ( byte ) ( value & 0xFF ) , } ; }
Converts a Java long to a Big Endian int on 8 bytes .
141
15
6,862
@ Pure @ Inline ( value = "EndianNumbers.parseBELong(Double.doubleToLongBits($1))" , imported = { EndianNumbers . class } ) public static byte [ ] parseBEDouble ( double value ) { return parseBELong ( Double . doubleToLongBits ( value ) ) ; }
Converts a Java double to a Big Endian int on 8 bytes .
73
15
6,863
@ SuppressWarnings ( { "unchecked" , "static-method" } ) @ Pure final < O > O unwrap ( O obj ) { O unwrapped = obj ; if ( obj instanceof TerminalConnection ) { unwrapped = ( O ) ( ( TerminalConnection ) obj ) . getWrappedRoadConnection ( ) ; } else if ( obj instanceof WrapSegment ) { unwrapped = ( O ) ( ( WrapSegment ) obj ) . getWrappedSegment ( ) ; } assert unwrapped != null ; return unwrapped ; }
Unwrap a connection .
123
5
6,864
@ Pure public UnitVectorProperty firstAxisProperty ( ) { if ( this . raxis == null ) { this . raxis = new UnitVectorProperty ( this , MathFXAttributeNames . FIRST_AXIS , getGeomFactory ( ) ) ; } return this . raxis ; }
Replies the property for the first rectangle axis .
61
10
6,865
@ Pure public ReadOnlyUnitVectorProperty secondAxisProperty ( ) { if ( this . saxis == null ) { this . saxis = new ReadOnlyUnitVectorWrapper ( this , MathFXAttributeNames . SECOND_AXIS , getGeomFactory ( ) ) ; this . saxis . bind ( Bindings . createObjectBinding ( ( ) -> { final Vector2dfx firstAxis = firstAxisProperty ( ) . get ( ) ; return firstAxis . toOrthogonalVector ( ) ; } , firstAxisProperty ( ) ) ) ; } return this . saxis . getReadOnlyProperty ( ) ; }
Replies the property for the second rectangle axis .
137
10
6,866
public static String showInfoDialog ( final Frame owner , final String message ) { InfomationDialog mdialog ; String ok = "OK" ; mdialog = new InfomationDialog ( owner , "Information message" , message , ok ) ; @ SuppressWarnings ( "unlikely-arg-type" ) final int index = mdialog . getVButtons ( ) . indexOf ( ok ) ; final Button button = mdialog . getVButtons ( ) . get ( index ) ; button . addActionListener ( mdialog ) ; mdialog . setVisible ( true ) ; return mdialog . getResult ( ) ; }
Statische Methode um ein Dialogfenster mit der angegebener Nachricht zu erzeugen .
143
28
6,867
@ Override protected HashMap readFile ( HashMap brMap ) throws IOException { HashMap ret = new HashMap ( ) ; HashMap metaData = new HashMap ( ) ; ArrayList < HashMap > culArr = readCultivarData ( brMap , metaData ) ; // compressData(sites); ArrayList < HashMap > expArr = new ArrayList ( ) ; HashMap tmp = new HashMap ( ) ; HashMap tmp2 = new HashMap ( ) ; tmp . put ( jsonKey , tmp2 ) ; tmp2 . put ( dataKey , culArr ) ; expArr . add ( tmp ) ; ret . put ( "experiments" , expArr ) ; return ret ; }
DSSAT Cultivar Data input method for only inputing Cultivar file
157
17
6,868
public static < LeftRightT > TypeConfusionInspector < LeftRightT > createOutputtingTo ( final String name , final Function < ? super LeftRightT , String > confusionLabeler , final Equivalence < LeftRightT > confusionEquivalence , final File outputDir ) { return new TypeConfusionInspector < LeftRightT > ( name , confusionLabeler , confusionEquivalence , outputDir ) ; }
Creates a new inspector . See class documentation for an explanation of the confusion labeler and confusion equivalence .
92
22
6,869
@ Pure public double distanceToEnd ( Point2D < ? , ? > point , double width ) { final Point2d firstPoint = getPointAt ( 0 ) ; final Point2d lastPoint = getPointAt ( - 1 ) ; double d1 = firstPoint . getDistance ( point ) ; double d2 = lastPoint . getDistance ( point ) ; d1 -= width ; if ( d1 < 0 ) { d1 = 0 ; } d2 -= width ; if ( d2 < 0 ) { d2 = 0 ; } return d1 < d2 ? d1 : d2 ; }
Replies the distance between the nearest end of this MapElement and the point .
129
16
6,870
@ Pure public final int getNearestEndIndex ( double x , double y , OutputParameter < Double > distance ) { final int count = getPointCount ( ) ; final Point2d firstPoint = getPointAt ( 0 ) ; final Point2d lastPoint = getPointAt ( count - 1 ) ; final double d1 = Point2D . getDistancePointPoint ( firstPoint . getX ( ) , firstPoint . getY ( ) , x , y ) ; final double d2 = Point2D . getDistancePointPoint ( lastPoint . getX ( ) , lastPoint . getY ( ) , x , y ) ; if ( d1 <= d2 ) { if ( distance != null ) { distance . set ( d1 ) ; } return 0 ; } if ( distance != null ) { distance . set ( d2 ) ; } return count - 1 ; }
Replies the index of the nearest end of line according to the specified point .
186
16
6,871
@ Pure public Point1d getNearestPosition ( Point2D < ? , ? > pos ) { Point2d pp = null ; final Vector2d v = new Vector2d ( ) ; double currentPosition = 0. ; double bestPosition = Double . NaN ; double bestDistance = Double . POSITIVE_INFINITY ; for ( final Point2d p : points ( ) ) { if ( pp != null ) { double position = Segment2afp . findsProjectedPointPointLine ( pos . getX ( ) , pos . getY ( ) , pp . getX ( ) , pp . getY ( ) , p . getX ( ) , p . getY ( ) ) ; if ( position < 0. ) { position = 0. ; } if ( position > 1. ) { position = 1. ; } v . sub ( p , pp ) ; final double t = v . getLength ( ) ; v . scale ( position ) ; final double dist = Point2D . getDistanceSquaredPointPoint ( pos . getX ( ) , pos . getY ( ) , pp . getX ( ) + v . getX ( ) , pp . getY ( ) + v . getY ( ) ) ; if ( dist < bestDistance ) { bestDistance = dist ; bestPosition = currentPosition + v . getLength ( ) ; } currentPosition += t ; } pp = p ; } if ( Double . isNaN ( bestPosition ) ) { return null ; } return new Point1d ( toSegment1D ( ) , bestPosition , 0. ) ; }
Return the nearest point 1 . 5D from a 2D position .
341
14
6,872
@ Pure public double getLength ( ) { if ( this . length < 0 ) { double segmentLength = 0 ; for ( final PointGroup group : groups ( ) ) { Point2d previousPts = null ; for ( final Point2d pts : group . points ( ) ) { if ( previousPts != null ) { segmentLength += previousPts . getDistance ( pts ) ; } previousPts = pts ; } } this . length = segmentLength ; } return this . length ; }
Replies the length of this polyline . The length is the distance between first point and the last point of the polyline .
105
26
6,873
@ Pure public Segment1D < ? , ? > getSubSegmentForDistance ( double distance ) { final double rd = distance < 0. ? 0. : distance ; double onGoingDistance = 0. ; for ( final PointGroup group : groups ( ) ) { Point2d previousPts = null ; for ( final Point2d pts : group . points ( ) ) { if ( previousPts != null ) { onGoingDistance += previousPts . getDistance ( pts ) ; if ( rd <= onGoingDistance ) { // The desired distance is on the current point pair return new DefaultSegment1d ( previousPts , pts ) ; } } previousPts = pts ; } } throw new IllegalArgumentException ( "distance must be lower or equal than getLength(); distance=" //$NON-NLS-1$ + Double . toString ( distance ) + "; length=" //$NON-NLS-1$ + Double . toString ( getLength ( ) ) ) ; }
Replies the subsegment which is corresponding to the given position .
217
14
6,874
@ Pure public final void toPath2D ( Path2d path ) { // loop on parts and build the path to draw boolean firstPoint ; for ( final PointGroup grp : groups ( ) ) { firstPoint = true ; for ( final Point2d pts : grp ) { final double x = pts . getX ( ) ; final double y = pts . getY ( ) ; if ( firstPoint ) { path . moveTo ( x , y ) ; firstPoint = false ; } else { path . lineTo ( x , y ) ; } } } }
Replies the Path2D that corresponds to this polyline .
120
13
6,875
public static boolean addPathToPath ( RoadPath inside , RoadPath elements ) { RoadConnection first = elements . getFirstPoint ( ) ; RoadConnection last = elements . getLastPoint ( ) ; assert first != null ; assert last != null ; first = first . getWrappedRoadConnection ( ) ; last = last . getWrappedRoadConnection ( ) ; assert first != null ; assert last != null ; if ( last . equals ( inside . getLastPoint ( ) ) || last . equals ( inside . getFirstPoint ( ) ) ) { for ( int i = elements . size ( ) - 1 ; i >= 0 ; -- i ) { if ( ! inside . add ( elements . get ( i ) ) ) { return false ; } } } else { for ( final RoadSegment segment : elements ) { if ( ! inside . add ( segment ) ) { return false ; } } } return true ; }
Add the elements stored inside a road path into a road path . This function takes care about the two ends to the path to insert into .
191
28
6,876
@ Pure public boolean isConnectableTo ( RoadPath path ) { assert path != null ; if ( path . isEmpty ( ) ) { return false ; } RoadConnection first1 = getFirstPoint ( ) ; RoadConnection last1 = getLastPoint ( ) ; first1 = first1 . getWrappedRoadConnection ( ) ; last1 = last1 . getWrappedRoadConnection ( ) ; RoadConnection first2 = path . getFirstPoint ( ) ; RoadConnection last2 = path . getLastPoint ( ) ; first2 = first2 . getWrappedRoadConnection ( ) ; last2 = last2 . getWrappedRoadConnection ( ) ; return first1 . equals ( first2 ) || first1 . equals ( last2 ) || last1 . equals ( first2 ) || last1 . equals ( last2 ) ; }
Replies if the given road path is connectable to this road path .
175
15
6,877
@ Pure public RoadConnection getFirstCrossRoad ( ) { for ( final RoadConnection pt : points ( ) ) { if ( pt . getConnectedSegmentCount ( ) > 2 ) { return pt ; } } return null ; }
Replies the first cross - road point in the path .
49
12
6,878
@ Pure public CrossRoad getFirstJunctionPoint ( ) { RoadConnection point = getFirstPoint ( ) ; double distance = 0 ; RoadSegment beforeSegment = null ; RoadSegment afterSegment = null ; int beforeSegmentIndex = - 1 ; int afterSegmentIndex = - 1 ; boolean found = false ; if ( point != null ) { int index = 0 ; for ( final RoadSegment sgmt : this ) { if ( found ) { afterSegment = sgmt ; afterSegmentIndex = index ; //stop now break ; } point = sgmt . getOtherSidePoint ( point ) ; beforeSegment = sgmt ; beforeSegmentIndex = index ; distance += sgmt . getLength ( ) ; final int count = point . getConnectedSegmentCount ( ) ; if ( count != 2 ) { found = true ; } ++ index ; } } if ( found ) { return new CrossRoad ( point , beforeSegment , beforeSegmentIndex , afterSegment , afterSegmentIndex , distance , distance ) ; } return null ; }
Replies the first cul - de - sac or cross - road point in the path .
232
18
6,879
public static String getFirstFreeBusLineName ( BusNetwork network ) { if ( network == null ) { return null ; } int nb = network . getBusLineCount ( ) ; String name ; do { ++ nb ; name = Locale . getString ( "NAME_TEMPLATE" , Integer . toString ( nb ) ) ; //$NON-NLS-1$ } while ( network . getBusLine ( name ) != null ) ; return name ; }
Replies a bus line name that was not exist in the specified network .
104
15
6,880
public boolean addBusItinerary ( BusItinerary busItinerary ) { if ( busItinerary == null ) { return false ; } if ( this . itineraries . indexOf ( busItinerary ) != - 1 ) { return false ; } if ( ! this . itineraries . add ( busItinerary ) ) { return false ; } final boolean isValidItinerary = busItinerary . isValidPrimitive ( ) ; busItinerary . setEventFirable ( isEventFirable ( ) ) ; busItinerary . setContainer ( this ) ; if ( isEventFirable ( ) ) { fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . ITINERARY_ADDED , busItinerary , this . itineraries . size ( ) - 1 , "shape" , //$NON-NLS-1$ null , null ) ) ; if ( ! isValidItinerary ) { revalidate ( ) ; } else { checkPrimitiveValidity ( ) ; } } return true ; }
Add a bus itinerary inside the bus line .
229
10
6,881
public void removeAllBusItineraries ( ) { for ( final BusItinerary itinerary : this . itineraries ) { itinerary . setContainer ( null ) ; itinerary . setEventFirable ( true ) ; } this . itineraries . clear ( ) ; fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . ALL_ITINERARIES_REMOVED , null , - 1 , "shape" , //$NON-NLS-1$ null , null ) ) ; checkPrimitiveValidity ( ) ; }
Remove all the bus itineraries from the current line .
119
11
6,882
public boolean removeBusItinerary ( BusItinerary itinerary ) { final int index = this . itineraries . indexOf ( itinerary ) ; if ( index >= 0 ) { return removeBusItinerary ( index ) ; } return false ; }
Remove a bus itinerary from this line . All the associated stops will be removed also .
54
18
6,883
public boolean removeBusItinerary ( int index ) { try { final BusItinerary busItinerary = this . itineraries . remove ( index ) ; busItinerary . setContainer ( null ) ; busItinerary . setEventFirable ( true ) ; fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . ITINERARY_REMOVED , busItinerary , index , "shape" , //$NON-NLS-1$ null , null ) ) ; checkPrimitiveValidity ( ) ; return true ; } catch ( Throwable exception ) { // } return false ; }
Remove the bus itinerary at the specified index . All the associated stops will be removed also .
135
19
6,884
public BusItinerary getBusItinerary ( UUID uuid ) { if ( uuid == null ) { return null ; } for ( final BusItinerary busItinerary : this . itineraries ) { if ( uuid . equals ( busItinerary . getUUID ( ) ) ) { return busItinerary ; } } return null ; }
Replies the bus itinerary with the specified uuid .
79
12
6,885
public BusItinerary getBusItinerary ( String name , Comparator < String > nameComparator ) { if ( name == null ) { return null ; } final Comparator < String > cmp = nameComparator == null ? BusNetworkUtilities . NAME_COMPARATOR : nameComparator ; for ( final BusItinerary itinerary : this . itineraries ) { if ( cmp . compare ( name , itinerary . getName ( ) ) == 0 ) { return itinerary ; } } return null ; }
Replies the bus itinerary with the specified name .
112
11
6,886
@ Override public final Parameters load ( final File configFile ) throws IOException { final Loading loading = new Loading ( ) ; loading . topLoad ( configFile ) ; return Parameters . fromMap ( loading . ret ) ; }
Parses a BBN - style parameter file to a Map .
47
14
6,887
@ Override @ Pure protected Class < ? > findClass ( final String name ) throws ClassNotFoundException { try { return AccessController . doPrivileged ( new PrivilegedExceptionAction < Class < ? > > ( ) { @ Override public Class < ? > run ( ) throws ClassNotFoundException { final String path = name . replace ( ' ' , ' ' ) . concat ( ".class" ) ; //$NON-NLS-1$ final sun . misc . Resource res = DynamicURLClassLoader . this . ucp . getResource ( path , false ) ; if ( res != null ) { try { return defineClass ( name , res ) ; } catch ( IOException e ) { throw new ClassNotFoundException ( name , e ) ; } } throw new ClassNotFoundException ( name ) ; } } , this . acc ) ; } catch ( java . security . PrivilegedActionException pae ) { throw ( ClassNotFoundException ) pae . getException ( ) ; } }
Finds and loads the class with the specified name from the URL search path . Any URLs referring to JAR files are loaded and opened as needed until the class is found .
213
35
6,888
protected Class < ? > defineClass ( String name , sun . misc . Resource res ) throws IOException { final int i = name . lastIndexOf ( ' ' ) ; final URL url = res . getCodeSourceURL ( ) ; if ( i != - 1 ) { final String pkgname = name . substring ( 0 , i ) ; // Check if package already loaded. final Package pkg = getPackage ( pkgname ) ; final Manifest man = res . getManifest ( ) ; if ( pkg != null ) { // Package found, so check package sealing. if ( pkg . isSealed ( ) ) { // Verify that code source URL is the same. if ( ! pkg . isSealed ( url ) ) { throw new SecurityException ( Locale . getString ( "E1" , pkgname ) ) ; //$NON-NLS-1$ } } else { // Make sure we are not attempting to seal the package // at this code source URL. if ( ( man != null ) && isSealed ( pkgname , man ) ) { throw new SecurityException ( Locale . getString ( "E2" , pkgname ) ) ; //$NON-NLS-1$ } } } else { if ( man != null ) { definePackage ( pkgname , man , url ) ; } else { definePackage ( pkgname , null , null , null , null , null , null , null ) ; } } } // Now read the class bytes and define the class final java . nio . ByteBuffer bb = res . getByteBuffer ( ) ; if ( bb != null ) { // Use (direct) ByteBuffer: final CodeSigner [ ] signers = res . getCodeSigners ( ) ; final CodeSource cs = new CodeSource ( url , signers ) ; return defineClass ( name , bb , cs ) ; } final byte [ ] b = res . getBytes ( ) ; // must read certificates AFTER reading bytes. final CodeSigner [ ] signers = res . getCodeSigners ( ) ; final CodeSource cs = new CodeSource ( url , signers ) ; return defineClass ( name , b , 0 , b . length , cs ) ; }
Defines a Class using the class bytes obtained from the specified Resource . The resulting Class must be resolved before it can be used .
482
26
6,889
@ SuppressWarnings ( "checkstyle:npathcomplexity" ) protected Package definePackage ( String name , Manifest man , URL url ) throws IllegalArgumentException { final String path = name . replace ( ' ' , ' ' ) . concat ( "/" ) ; //$NON-NLS-1$ String specTitle = null ; String specVersion = null ; String specVendor = null ; String implTitle = null ; String implVersion = null ; String implVendor = null ; String sealed = null ; URL sealBase = null ; Attributes attr = man . getAttributes ( path ) ; if ( attr != null ) { specTitle = attr . getValue ( Name . SPECIFICATION_TITLE ) ; specVersion = attr . getValue ( Name . SPECIFICATION_VERSION ) ; specVendor = attr . getValue ( Name . SPECIFICATION_VENDOR ) ; implTitle = attr . getValue ( Name . IMPLEMENTATION_TITLE ) ; implVersion = attr . getValue ( Name . IMPLEMENTATION_VERSION ) ; implVendor = attr . getValue ( Name . IMPLEMENTATION_VENDOR ) ; sealed = attr . getValue ( Name . SEALED ) ; } attr = man . getMainAttributes ( ) ; if ( attr != null ) { if ( specTitle == null ) { specTitle = attr . getValue ( Name . SPECIFICATION_TITLE ) ; } if ( specVersion == null ) { specVersion = attr . getValue ( Name . SPECIFICATION_VERSION ) ; } if ( specVendor == null ) { specVendor = attr . getValue ( Name . SPECIFICATION_VENDOR ) ; } if ( implTitle == null ) { implTitle = attr . getValue ( Name . IMPLEMENTATION_TITLE ) ; } if ( implVersion == null ) { implVersion = attr . getValue ( Name . IMPLEMENTATION_VERSION ) ; } if ( implVendor == null ) { implVendor = attr . getValue ( Name . IMPLEMENTATION_VENDOR ) ; } if ( sealed == null ) { sealed = attr . getValue ( Name . SEALED ) ; } } if ( "true" . equalsIgnoreCase ( sealed ) ) { //$NON-NLS-1$ sealBase = url ; } return definePackage ( name , specTitle , specVersion , specVendor , implTitle , implVersion , implVendor , sealBase ) ; }
Defines a new package by name in this ClassLoader . The attributes contained in the specified Manifest will be used to obtain package version and sealing information . For sealed packages the additional URL specifies the code source URL from which the package was loaded .
551
48
6,890
@ Override @ Pure public URL findResource ( final String name ) { /* * The same restriction to finding classes applies to resources */ final URL url = AccessController . doPrivileged ( new PrivilegedAction < URL > ( ) { @ Override public URL run ( ) { return DynamicURLClassLoader . this . ucp . findResource ( name , true ) ; } } , this . acc ) ; return url != null ? this . ucp . checkURL ( url ) : null ; }
Finds the resource with the specified name on the URL search path .
103
14
6,891
@ Override @ Pure public Enumeration < URL > findResources ( final String name ) throws IOException { final Enumeration < ? > e = this . ucp . findResources ( name , true ) ; return new Enumeration < URL > ( ) { private URL url ; private boolean next ( ) { if ( this . url != null ) { return true ; } do { final URL u = AccessController . doPrivileged ( new PrivilegedAction < URL > ( ) { @ Override public URL run ( ) { if ( ! e . hasMoreElements ( ) ) { return null ; } return ( URL ) e . nextElement ( ) ; } } , DynamicURLClassLoader . this . acc ) ; if ( u == null ) { break ; } this . url = DynamicURLClassLoader . this . ucp . checkURL ( u ) ; } while ( this . url == null ) ; return this . url != null ; } @ Override public URL nextElement ( ) { if ( ! next ( ) ) { throw new NoSuchElementException ( ) ; } final URL u = this . url ; this . url = null ; return u ; } @ Override public boolean hasMoreElements ( ) { return next ( ) ; } } ; }
Returns an Enumeration of URLs representing all of the resources on the URL search path having the specified name .
267
22
6,892
@ Override protected PermissionCollection getPermissions ( CodeSource codesource ) { final PermissionCollection perms = super . getPermissions ( codesource ) ; final URL url = codesource . getLocation ( ) ; Permission permission ; URLConnection urlConnection ; try { urlConnection = url . openConnection ( ) ; permission = urlConnection . getPermission ( ) ; } catch ( IOException ioe ) { permission = null ; urlConnection = null ; } if ( ( permission != null ) && ( permission instanceof FilePermission ) ) { // if the permission has a separator char on the end, // it means the codebase is a directory, and we need // to add an additional permission to read recursively String path = permission . getName ( ) ; if ( path . endsWith ( File . separator ) ) { path += "-" ; //$NON-NLS-1$ permission = new FilePermission ( path , sun . security . util . SecurityConstants . FILE_READ_ACTION ) ; } } else if ( ( permission == null ) && ( URISchemeType . FILE . isURL ( url ) ) ) { String path = url . getFile ( ) . replace ( ' ' , File . separatorChar ) ; path = sun . net . www . ParseUtil . decode ( path ) ; if ( path . endsWith ( File . separator ) ) { path += "-" ; //$NON-NLS-1$ } permission = new FilePermission ( path , sun . security . util . SecurityConstants . FILE_READ_ACTION ) ; } else { URL locUrl = url ; if ( urlConnection instanceof JarURLConnection ) { locUrl = ( ( JarURLConnection ) urlConnection ) . getJarFileURL ( ) ; } String host = locUrl . getHost ( ) ; if ( host == null ) { host = "localhost" ; //$NON-NLS-1$ } permission = new SocketPermission ( host , sun . security . util . SecurityConstants . SOCKET_CONNECT_ACCEPT_ACTION ) ; } // make sure the person that created this class loader // would have this permission final SecurityManager sm = System . getSecurityManager ( ) ; if ( sm != null ) { final Permission fp = permission ; AccessController . doPrivileged ( new PrivilegedAction < Object > ( ) { @ Override public Object run ( ) throws SecurityException { sm . checkPermission ( fp ) ; return null ; } } , this . acc ) ; } perms . add ( permission ) ; return perms ; }
Returns the permissions for the given codesource object . The implementation of this method first calls super . getPermissions and then adds permissions based on the URL of the codesource .
557
35
6,893
private static URL [ ] mergeClassPath ( URL ... urls ) { final String path = System . getProperty ( "java.class.path" ) ; //$NON-NLS-1$ final String separator = System . getProperty ( "path.separator" ) ; //$NON-NLS-1$ final String [ ] parts = path . split ( Pattern . quote ( separator ) ) ; final URL [ ] u = new URL [ parts . length + urls . length ] ; for ( int i = 0 ; i < parts . length ; ++ i ) { try { u [ i ] = new File ( parts [ i ] ) . toURI ( ) . toURL ( ) ; } catch ( MalformedURLException exception ) { // ignore exception } } System . arraycopy ( urls , 0 , u , parts . length , urls . length ) ; return u ; }
Merge the specified URLs to the current classpath .
195
11
6,894
public static < E > int remove ( List < E > list , Comparator < ? super E > comparator , E data ) { assert list != null ; assert comparator != null ; assert data != null ; int first = 0 ; int last = list . size ( ) - 1 ; while ( last >= first ) { final int center = ( first + last ) / 2 ; final E dt = list . get ( center ) ; final int cmpR = comparator . compare ( data , dt ) ; if ( cmpR == 0 ) { list . remove ( center ) ; return center ; } else if ( cmpR < 0 ) { last = center - 1 ; } else { first = center + 1 ; } } return - 1 ; }
Remove the given element from the list using a dichotomic algorithm .
160
14
6,895
@ Inline ( value = "add($1, $2, $3, false, false)" ) public static < E > int addIfAbsent ( List < E > list , Comparator < ? super E > comparator , E data ) { return add ( list , comparator , data , false , false ) ; }
Add the given element in the main list using a dichotomic algorithm if the element is not already present .
69
22
6,896
public static < E > int add ( List < E > list , Comparator < ? super E > comparator , E data , boolean allowMultipleOccurencesOfSameValue , boolean allowReplacement ) { assert list != null ; assert comparator != null ; assert data != null ; int first = 0 ; int last = list . size ( ) - 1 ; while ( last >= first ) { final int center = ( first + last ) / 2 ; final E dt = list . get ( center ) ; final int cmpR = comparator . compare ( data , dt ) ; if ( cmpR == 0 && ! allowMultipleOccurencesOfSameValue ) { if ( allowReplacement ) { list . set ( center , data ) ; return center ; } return - 1 ; } if ( cmpR < 0 ) { last = center - 1 ; } else { first = center + 1 ; } } list . add ( first , data ) ; return first ; }
Add the given element in the main list using a dichotomic algorithm .
206
15
6,897
@ Pure public static < E > boolean contains ( List < E > list , Comparator < ? super E > comparator , E data ) { assert list != null ; assert comparator != null ; assert data != null ; int first = 0 ; int last = list . size ( ) - 1 ; while ( last >= first ) { final int center = ( first + last ) / 2 ; final E dt = list . get ( center ) ; final int cmpR = comparator . compare ( data , dt ) ; if ( cmpR == 0 ) { return true ; } else if ( cmpR < 0 ) { last = center - 1 ; } else { first = center + 1 ; } } return false ; }
Replies if the given element is inside the list using a dichotomic algorithm .
154
17
6,898
public static < T > Iterator < T > reverseIterator ( final List < T > list ) { return new Iterator < T > ( ) { private int next = list . size ( ) - 1 ; @ Override @ Pure public boolean hasNext ( ) { return this . next >= 0 ; } @ Override public T next ( ) { final int n = this . next ; -- this . next ; try { return list . get ( n ) ; } catch ( IndexOutOfBoundsException exception ) { throw new NoSuchElementException ( ) ; } } } ; }
Replies an iterator that goes from end to start of the given list .
121
15
6,899
@ Pure public static Class < ? > getAttributeClassWithDefault ( Node document , boolean caseSensitive , Class < ? > defaultValue , String ... path ) { assert document != null : AssertMessages . notNullParameter ( 0 ) ; final String v = getAttributeValue ( document , caseSensitive , 0 , path ) ; if ( v != null && ! v . isEmpty ( ) ) { try { final ClassLoader loader = ClassLoaderFinder . findClassLoader ( ) ; return loader . loadClass ( v ) ; } catch ( Throwable e ) { // } } return defaultValue ; }
Read a java class .
128
5