idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
6,300
private static < P extends GISPrimitive , N extends AbstractGISTreeSetNode < P , N > > Point2d computeCutPoint ( IcosepQuadTreeZone region , N parent ) { final double w = parent . nodeWidth / 4. ; final double h = parent . nodeHeight / 4. ; final double x ; final double y ; switch ( region ) { case SOUTH_WEST : x = parent . verticalSplit - w ; y = parent . horizontalSplit - h ; break ; case SOUTH_EAST : x = parent . verticalSplit + w ; y = parent . horizontalSplit - h ; break ; case NORTH_WEST : x = parent . verticalSplit - w ; y = parent . horizontalSplit + h ; break ; case NORTH_EAST : x = parent . verticalSplit + w ; y = parent . horizontalSplit + h ; break ; case ICOSEP : default : return null ; } return new Point2d ( x , y ) ; }
Computes the cut planes position of the given region .
212
11
6,301
private static < P extends GISPrimitive , N extends AbstractGISTreeSetNode < P , N > > N rearrangeTree ( AbstractGISTreeSet < P , N > tree , N node , Rectangle2afp < ? , ? , ? , ? , ? , ? > desiredBounds , GISTreeSetNodeFactory < P , N > builder ) { // Search for the node that completely contains the desired area N topNode = node . getParentNode ( ) ; while ( topNode != null && isOutsideNodeBuildingBounds ( topNode , desiredBounds ) ) { topNode = topNode . getParentNode ( ) ; } final Rectangle2afp < ? , ? , ? , ? , ? , ? > dr ; if ( topNode == null ) { // Node node found, the entire tree should be rebuilt topNode = tree . getTree ( ) . getRoot ( ) ; if ( topNode == null ) { throw new IllegalStateException ( ) ; } dr = union ( topNode , desiredBounds ) ; } else { dr = getNormalizedNodeBuildingBounds ( topNode , desiredBounds ) ; } // Build a new subtree final N parent = topNode . getParentNode ( ) ; final Iterator < P > dataIterator = new PrefixDataDepthFirstTreeIterator <> ( topNode ) ; final N newTopNode = builder . newNode ( topNode . getZone ( ) , dr . getMinX ( ) , dr . getMinY ( ) , dr . getWidth ( ) , dr . getHeight ( ) ) ; while ( dataIterator . hasNext ( ) ) { if ( ! addInside ( tree , newTopNode , dataIterator . next ( ) , builder , false ) ) { throw new IllegalStateException ( ) ; } } // Replace rearranged subtree by the new one if ( parent != null ) { parent . setChildAt ( topNode . getZone ( ) . ordinal ( ) , newTopNode ) ; return parent ; } tree . getTree ( ) . setRoot ( newTopNode ) ; return newTopNode ; }
Try to rearrange the cut planes of the given node .
450
12
6,302
protected synchronized void addShapeGeometryChangeListener ( ShapeGeometryChangeListener listener ) { assert listener != null : AssertMessages . notNullParameter ( ) ; if ( this . geometryListeners == null ) { this . geometryListeners = new WeakArrayList <> ( ) ; } this . geometryListeners . add ( listener ) ; }
Add listener on geometry changes .
73
6
6,303
protected synchronized void removeShapeGeometryChangeListener ( ShapeGeometryChangeListener listener ) { assert listener != null : AssertMessages . notNullParameter ( ) ; if ( this . geometryListeners != null ) { this . geometryListeners . remove ( listener ) ; if ( this . geometryListeners . isEmpty ( ) ) { this . geometryListeners = null ; } } }
Remove listener on geometry changes .
81
6
6,304
protected synchronized void fireGeometryChange ( ) { if ( this . geometryListeners == null ) { return ; } final ShapeGeometryChangeListener [ ] array = new ShapeGeometryChangeListener [ this . geometryListeners . size ( ) ] ; this . geometryListeners . toArray ( array ) ; for ( final ShapeGeometryChangeListener listener : array ) { listener . shapeGeometryChange ( this ) ; } }
Notify any listener of a geometry change .
89
9
6,305
protected void setupListeners ( ) { addDrawingListener ( new DrawingListener ( ) { private long time ; @ Override public void onDrawingStart ( ) { this . time = System . currentTimeMillis ( ) ; getCorner ( ) . setColor ( Color . ORANGERED ) ; } @ Override public void onDrawingEnd ( ) { getCorner ( ) . setColor ( null ) ; final long duration = System . currentTimeMillis ( ) - this . time ; getLogger ( ) . fine ( "Rendering duration: " + Duration . millis ( duration ) . toString ( ) ) ; //$NON-NLS-1$ } } ) ; }
Setup the response based on listeners .
152
7
6,306
@ SuppressWarnings ( { "checkstyle:cyclomaticcomplexity" , "checkstyle:npathcomplexity" , "checkstyle:nestedifdepth" } ) protected void setupMousing ( ) { final ZoomableCanvas < T > canvas = getDocumentCanvas ( ) ; canvas . addEventHandler ( MouseEvent . MOUSE_PRESSED , e -> { this . pressX = e . getX ( ) ; this . pressY = e . getY ( ) ; this . hbarValue = this . hbar . getValue ( ) ; this . vbarValue = this . vbar . getValue ( ) ; } ) ; setOnDragDetected ( getDefaultOnDragDetectedEventHandler ( ) ) ; addEventFilter ( MouseEvent . MOUSE_RELEASED , e -> { if ( this . dragDetected ) { this . dragDetected = false ; final Cursor scurs = this . savedCursor ; this . savedCursor = null ; if ( scurs != null ) { getDocumentCanvas ( ) . setCursor ( scurs ) ; requestLayout ( ) ; } } } ) ; addEventHandler ( DragEvent . DRAG_DONE , event -> { if ( this . dragDetected ) { this . dragDetected = false ; final Cursor scurs = this . savedCursor ; this . savedCursor = null ; if ( scurs != null ) { getDocumentCanvas ( ) . setCursor ( scurs ) ; requestLayout ( ) ; } } } ) ; addEventHandler ( MouseEvent . MOUSE_DRAGGED , getDefaultOnMouseDraggedEventHandler ( ) ) ; addEventHandler ( ScrollEvent . SCROLL_STARTED , event -> { this . scrollDetected = true ; } ) ; addEventHandler ( ScrollEvent . SCROLL_FINISHED , event -> { this . scrollDetected = false ; } ) ; addEventHandler ( ScrollEvent . SCROLL , event -> { if ( ! this . scrollDetected ) { event . consume ( ) ; final double delta ; if ( event . getDeltaY ( ) != 0. ) { delta = event . getDeltaY ( ) ; } else { delta = event . getDeltaX ( ) ; } if ( delta < 0 ) { zoomOut ( ) ; } else { zoomIn ( ) ; } } } ) ; }
Setup the response of the pane to mouse events .
517
10
6,307
protected void setupKeying ( ) { setOnKeyPressed ( event -> { switch ( event . getCode ( ) ) { case LEFT : moveLeft ( event . isShiftDown ( ) , event . isControlDown ( ) , false ) ; event . consume ( ) ; break ; case RIGHT : moveRight ( event . isShiftDown ( ) , event . isControlDown ( ) , false ) ; event . consume ( ) ; break ; case UP : if ( event . isAltDown ( ) ) { zoomIn ( ) ; } else { moveUp ( event . isShiftDown ( ) , event . isControlDown ( ) , false ) ; } event . consume ( ) ; break ; case DOWN : if ( event . isAltDown ( ) ) { zoomOut ( ) ; } else { moveDown ( event . isShiftDown ( ) , event . isControlDown ( ) , false ) ; } event . consume ( ) ; break ; case PAGE_UP : if ( event . isControlDown ( ) ) { moveLeft ( false , false , true ) ; } else { moveUp ( false , false , true ) ; } event . consume ( ) ; break ; case PAGE_DOWN : if ( event . isControlDown ( ) ) { moveRight ( false , false , true ) ; } else { moveDown ( false , false , true ) ; } event . consume ( ) ; break ; //$CASES-OMITTED$ default : } } ) ; }
Setup the response of the pane to key events .
313
10
6,308
public void moveLeft ( boolean isUnit , boolean isLarge , boolean isVeryLarge ) { double inc = isUnit ? this . hbar . getUnitIncrement ( ) : ( isLarge ? LARGE_MOVE_FACTOR : ( isVeryLarge ? VERY_LARGE_MOVE_FACTOR : STANDARD_MOVE_FACTOR ) ) * this . hbar . getBlockIncrement ( ) ; if ( ! isInvertedAxisX ( ) ) { inc = - inc ; } this . hbar . setValue ( Utils . clamp ( this . hbar . getMin ( ) , this . hbar . getValue ( ) + inc , this . hbar . getMax ( ) ) ) ; }
Move the viewport left .
160
6
6,309
public void moveUp ( boolean isUnit , boolean isLarge , boolean isVeryLarge ) { double inc = isUnit ? this . vbar . getUnitIncrement ( ) : ( isLarge ? LARGE_MOVE_FACTOR : ( isVeryLarge ? VERY_LARGE_MOVE_FACTOR : STANDARD_MOVE_FACTOR ) ) * this . vbar . getBlockIncrement ( ) ; if ( ! isInvertedAxisY ( ) ) { inc = - inc ; } this . vbar . setValue ( Utils . clamp ( this . vbar . getMin ( ) , this . vbar . getValue ( ) + inc , this . vbar . getMax ( ) ) ) ; }
Move the viewport up .
160
6
6,310
public ObjectProperty < Logger > loggerProperty ( ) { if ( this . logger == null ) { this . logger = new SimpleObjectProperty < Logger > ( this , LOGGER_PROPERTY , Logger . getLogger ( getClass ( ) . getName ( ) ) ) { @ Override protected void invalidated ( ) { final Logger log = get ( ) ; if ( log == null ) { set ( Logger . getLogger ( getClass ( ) . getName ( ) ) ) ; } } } ; } return this . logger ; }
Replies the property that contains the logger .
120
9
6,311
public ObjectProperty < MouseButton > panButtonProperty ( ) { if ( this . panButton == null ) { this . panButton = new StyleableObjectProperty < MouseButton > ( DEFAULT_PAN_BUTTON ) { @ SuppressWarnings ( "synthetic-access" ) @ Override protected void invalidated ( ) { final MouseButton button = get ( ) ; if ( button == null ) { set ( DEFAULT_PAN_BUTTON ) ; } } @ Override public CssMetaData < ZoomablePane < ? > , MouseButton > getCssMetaData ( ) { return StyleableProperties . PAN_BUTTON ; } @ Override public Object getBean ( ) { return ZoomablePane . this ; } @ Override public String getName ( ) { return PAN_BUTTON_PROPERTY ; } } ; } return this . panButton ; }
Replies the property for the button that serves for starting the mouse scrolling .
194
15
6,312
public DoubleProperty panSensitivityProperty ( ) { if ( this . panSensitivity == null ) { this . panSensitivity = new StyleableDoubleProperty ( DEFAULT_PAN_SENSITIVITY ) { @ Override public void invalidated ( ) { if ( get ( ) <= MIN_PAN_SENSITIVITY ) { set ( MIN_PAN_SENSITIVITY ) ; } } @ Override public CssMetaData < ZoomablePane < ? > , Number > getCssMetaData ( ) { return StyleableProperties . PAN_SENSITIVITY ; } @ Override public Object getBean ( ) { return ZoomablePane . this ; } @ Override public String getName ( ) { return PAN_SENSITIVITY_PROPERTY ; } } ; } return this . panSensitivity ; }
Replies the property that indicates the sensibility of the panning moves . The sensibility is a strictly positive number that is multiplied to the distance covered by the mouse motion for obtaining the move to apply to the document . The default value is 1 .
187
50
6,313
public double getPanSensitivity ( boolean unitSensitivityModifier , boolean hugeSensivityModifier ) { if ( unitSensitivityModifier ) { return DEFAULT_PAN_SENSITIVITY ; } final double sens = getPanSensitivity ( ) ; if ( hugeSensivityModifier ) { return sens * LARGE_MOVE_FACTOR ; } return sens ; }
Replies the sensibility of the panning moves after applying dynamic user interaction modifiers . The sensibility is a strictly positive number that is multiplied to the distance covered by the mouse motion for obtaining the move to apply to the document . The default value is 1 .
85
52
6,314
public static void setGlobalSplineApproximationRatio ( Double distance ) { if ( distance == null || Double . isNaN ( distance . doubleValue ( ) ) ) { globalSplineApproximation = GeomConstants . SPLINE_APPROXIMATION_RATIO ; } else { globalSplineApproximation = Math . max ( 0 , distance ) ; } }
Change the maximum distance that the line segments used to approximate the curved segments are allowed to deviate from any point on the original curve .
84
27
6,315
public ESRIBounds createUnion ( ESRIBounds bounds ) { final ESRIBounds eb = new ESRIBounds ( ) ; eb . minx = ( bounds . minx < this . minx ) ? bounds . minx : this . minx ; eb . maxx = ( bounds . maxx < this . maxx ) ? this . maxx : bounds . maxx ; eb . miny = ( bounds . miny < this . miny ) ? bounds . miny : this . miny ; eb . maxy = ( bounds . maxy < this . maxy ) ? this . maxy : bounds . maxy ; eb . minz = ( bounds . minz < this . minz ) ? bounds . minz : this . minz ; eb . maxz = ( bounds . maxz < this . maxz ) ? this . maxz : bounds . maxz ; eb . minm = ( bounds . minm < this . minm ) ? bounds . minm : this . minm ; eb . maxm = ( bounds . maxm < this . maxm ) ? this . maxm : bounds . maxm ; return eb ; }
Create and replies an union of this bounds and the given bounds .
250
13
6,316
public void add ( ESRIPoint point ) { if ( point . getX ( ) < this . minx ) { this . minx = point . getX ( ) ; } if ( point . getX ( ) > this . maxx ) { this . maxx = point . getX ( ) ; } if ( point . getY ( ) < this . miny ) { this . miny = point . getY ( ) ; } if ( point . getY ( ) > this . maxy ) { this . maxy = point . getY ( ) ; } if ( point . getZ ( ) < this . minz ) { this . minz = point . getZ ( ) ; } if ( point . getZ ( ) > this . maxz ) { this . maxz = point . getZ ( ) ; } if ( point . getM ( ) < this . minm ) { this . minm = point . getM ( ) ; } if ( point . getM ( ) > this . maxm ) { this . maxm = point . getM ( ) ; } }
Add a point to this bounds .
236
7
6,317
@ Pure public Rectangle2d toRectangle2d ( ) { final Rectangle2d bounds = new Rectangle2d ( ) ; bounds . setFromCorners ( this . minx , this . miny , this . maxx , this . maxy ) ; return bounds ; }
Replies the 2D bounds .
62
7
6,318
public void ensureMinMax ( ) { double t ; if ( this . maxx < this . minx ) { t = this . minx ; this . minx = this . maxx ; this . maxx = t ; } if ( this . maxy < this . miny ) { t = this . miny ; this . miny = this . maxy ; this . maxy = t ; } if ( this . maxz < this . minz ) { t = this . minz ; this . minz = this . maxz ; this . maxz = t ; } if ( this . maxm < this . minm ) { t = this . minm ; this . minm = this . maxm ; this . maxm = t ; } }
Ensure that min and max values are correctly ordered .
164
11
6,319
public ESRIBounds getBoundsFromHeader ( ) { try { readHeader ( ) ; } catch ( IOException exception ) { return null ; } return new ESRIBounds ( this . minx , this . maxx , this . miny , this . maxy , this . minz , this . maxz , this . minm , this . maxm ) ; }
Replies the bounds read from the shape file header .
81
11
6,320
public E read ( ) throws IOException { boolean status = false ; try { // Read header if not already read readHeader ( ) ; // Read the records E element ; try { do { element = readRecord ( this . nextExpectedRecordIndex ) ; if ( ! postRecordReadingStage ( element ) ) { element = null ; } ++ this . nextExpectedRecordIndex ; } while ( element == null ) ; } catch ( EOFException e ) { element = null ; close ( ) ; postReadingStage ( true ) ; } status = true ; return element ; } finally { if ( this . taskProgression != null ) { this . taskProgression . setValue ( this . buffer . position ( ) + HEADER_BYTES ) ; } if ( ! status ) { close ( ) ; postReadingStage ( status ) ; } } }
Read the elements for a shape file .
179
8
6,321
protected void setReadingPosition ( int recordIndex , int byteIndex ) throws IOException { if ( this . seekEnabled ) { this . nextExpectedRecordIndex = recordIndex ; this . buffer . position ( byteIndex ) ; } else { throw new SeekOperationDisabledException ( ) ; } }
Set the reading position excluding the header .
62
8
6,322
protected void ensureAvailableBytes ( int amount ) throws IOException { if ( ! this . seekEnabled && amount > this . buffer . remaining ( ) ) { this . bufferPosition += this . buffer . position ( ) ; this . buffer . compact ( ) ; int limit = this . buffer . position ( ) ; final int read = this . stream . read ( this . buffer ) ; if ( read < 0 ) { if ( limit == 0 ) { throw new EOFException ( ) ; } } else { limit += read ; } this . buffer . rewind ( ) ; this . buffer . limit ( limit ) ; } if ( amount > this . buffer . remaining ( ) ) { throw new EOFException ( ) ; } }
Ensure that the reading buffer is containing enoug bytes to read .
152
14
6,323
protected void skipBytes ( int amount ) throws IOException { ensureAvailableBytes ( amount ) ; this . buffer . position ( this . buffer . position ( ) + amount ) ; }
Skip an amount of bytes .
37
6
6,324
@ Pure public Point2D < ? , ? > predictTargetPosition ( Point2D < ? , ? > targetPosition , Vector2D < ? , ? > targetLinearMotion ) { return new Point2d ( targetPosition . getX ( ) + targetLinearMotion . getX ( ) * this . predictionDuration , targetPosition . getY ( ) + targetLinearMotion . getY ( ) * this . predictionDuration ) ; }
Predict the next position of the target .
94
9
6,325
protected void reconnect ( Session session ) { if ( this . hsClient . isStarted ( ) ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Add reconnectRequest to connector " + session . getRemoteSocketAddress ( ) ) ; } HandlerSocketSession hSession = ( HandlerSocketSession ) session ; InetSocketAddress addr = hSession . getRemoteSocketAddress ( ) ; this . hsClient . getConnector ( ) . addToWatingQueue ( new ReconnectRequest ( addr , 0 , this . hsClient . getHealConnectionInterval ( ) ) ) ; } }
Auto reconect request to hs4j server
131
10
6,326
public AStarSegmentReplacer < ST > setSegmentReplacer ( AStarSegmentReplacer < ST > replacer ) { final AStarSegmentReplacer < ST > old = this . segmentReplacer ; this . segmentReplacer = replacer ; return old ; }
Set the object to use to replace the segments in the shortest path .
60
14
6,327
public AStarSegmentOrientation < ST , PT > setSegmentOrientationTool ( AStarSegmentOrientation < ST , PT > tool ) { final AStarSegmentOrientation < ST , PT > old = this . segmentOrientation ; this . segmentOrientation = tool ; return old ; }
Set the tool that permits to retreive the orinetation of the segments .
71
17
6,328
public AStarCostComputer < ? super ST , ? super PT > setCostComputer ( AStarCostComputer < ? super ST , ? super PT > costComputer ) { final AStarCostComputer < ? super ST , ? super PT > old = this . costComputer ; this . costComputer = costComputer ; return old ; }
Set the tool that permits to compute the costs of the nodes and the edges .
68
16
6,329
@ Pure protected double estimate ( PT p1 , PT p2 ) { assert p1 != null && p2 != null ; if ( this . heuristic == null ) { throw new IllegalStateException ( Locale . getString ( "E1" ) ) ; //$NON-NLS-1$ } return this . heuristic . evaluate ( p1 , p2 ) ; }
Evaluate the distance between two points in the graph .
82
12
6,330
@ Pure protected double computeCostFor ( ST segment ) { if ( this . costComputer != null ) { return this . costComputer . computeCostFor ( segment ) ; } return segment . getLength ( ) ; }
Compute and replies the cost to traverse the given graph segment .
45
13
6,331
@ SuppressWarnings ( { "unchecked" , "rawtypes" } ) @ Pure protected GP newPath ( PT startPoint , ST segment ) { if ( this . pathFactory != null ) { return this . pathFactory . newPath ( startPoint , segment ) ; } try { return ( GP ) new GraphPath ( segment , startPoint ) ; } catch ( Throwable e ) { throw new IllegalStateException ( Locale . getString ( "E2" ) , e ) ; //$NON-NLS-1$ } }
Create an empty path .
117
5
6,332
protected boolean addToPath ( GP path , ST segment ) { if ( this . pathFactory != null ) { return this . pathFactory . addToPath ( path , segment ) ; } assert path != null ; assert segment != null ; try { return path . add ( segment ) ; } catch ( Throwable e ) { throw new IllegalStateException ( e ) ; } }
Add the given segment into the given path .
78
9
6,333
@ Pure protected ST replaceSegment ( int index , ST segment ) { ST rep = null ; if ( this . segmentReplacer != null ) { rep = this . segmentReplacer . replaceSegment ( index , segment ) ; } if ( rep == null ) { rep = segment ; } return rep ; }
Invoked to replace a segment before adding it to the shortest path .
65
14
6,334
public static Vector2d convert ( Tuple2D < ? > tuple ) { if ( tuple instanceof Vector2d ) { return ( Vector2d ) tuple ; } return new Vector2d ( tuple . getX ( ) , tuple . getY ( ) ) ; }
Convert the given tuple to a real Vector2d .
58
12
6,335
public boolean addBusLine ( BusLine busLine ) { if ( busLine == null ) { return false ; } if ( this . busLines . indexOf ( busLine ) != - 1 ) { return false ; } if ( ! this . busLines . add ( busLine ) ) { return false ; } final boolean isValidLine = busLine . isValidPrimitive ( ) ; busLine . setEventFirable ( isEventFirable ( ) ) ; busLine . setContainer ( this ) ; if ( isEventFirable ( ) ) { fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . LINE_ADDED , busLine , this . busLines . size ( ) - 1 , "shape" , //$NON-NLS-1$ null , null ) ) ; if ( ! isValidLine ) { revalidate ( ) ; } else { checkPrimitiveValidity ( ) ; } } return true ; }
Add a bus line inside the bus network .
205
9
6,336
public void removeAllBusLines ( ) { for ( final BusLine busline : this . busLines ) { busline . setContainer ( null ) ; busline . setEventFirable ( true ) ; } this . busLines . clear ( ) ; fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . ALL_LINES_REMOVED , null , - 1 , "shape" , //$NON-NLS-1$ null , null ) ) ; checkPrimitiveValidity ( ) ; }
Remove all the bus lines from the current network .
115
10
6,337
public boolean removeBusLine ( BusLine busLine ) { final int index = this . busLines . indexOf ( busLine ) ; if ( index >= 0 ) { return removeBusLine ( index ) ; } return false ; }
Remove a bus line from this network . All the itineraries and the associated stops will be removed also . If this bus line removal implies empty hubs these hubs will be also removed .
49
36
6,338
public boolean removeBusLine ( String name ) { final Iterator < BusLine > iterator = this . busLines . iterator ( ) ; BusLine busLine ; int i = 0 ; while ( iterator . hasNext ( ) ) { busLine = iterator . next ( ) ; if ( name . equals ( busLine . getName ( ) ) ) { iterator . remove ( ) ; busLine . setContainer ( null ) ; busLine . setEventFirable ( true ) ; fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . LINE_REMOVED , busLine , i , "shape" , //$NON-NLS-1$ null , null ) ) ; checkPrimitiveValidity ( ) ; return true ; } ++ i ; } return false ; }
Remove the bus line with the given name . All the itineraries and the associated stops will be removed also . If this bus line removal implies empty hubs these hubs will be also removed .
167
37
6,339
public boolean removeBusLine ( int index ) { try { final BusLine busLine = this . busLines . remove ( index ) ; busLine . setContainer ( null ) ; busLine . setEventFirable ( true ) ; fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . LINE_REMOVED , busLine , index , "shape" , //$NON-NLS-1$ null , null ) ) ; checkPrimitiveValidity ( ) ; return true ; } catch ( Throwable exception ) { // } return false ; }
Remove the bus line at the specified index . All the itineraries and the associated stops will be removed also . If this bus line removal implies empty hubs these hubs will be also removed .
121
37
6,340
@ Pure public BusLine getBusLine ( UUID uuid ) { if ( uuid == null ) { return null ; } for ( final BusLine busLine : this . busLines ) { if ( uuid . equals ( busLine . getUUID ( ) ) ) { return busLine ; } } return null ; }
Replies the bus line with the specified uuid .
70
11
6,341
@ Pure public BusLine getBusLine ( String name , Comparator < String > nameComparator ) { if ( name == null ) { return null ; } final Comparator < String > cmp = nameComparator == null ? BusNetworkUtilities . NAME_COMPARATOR : nameComparator ; for ( final BusLine busLine : this . busLines ) { if ( cmp . compare ( name , busLine . getName ( ) ) == 0 ) { return busLine ; } } return null ; }
Replies the bus line with the specified name .
109
10
6,342
public boolean addBusStop ( BusStop busStop ) { if ( busStop == null ) { return false ; } if ( this . validBusStops . contains ( busStop ) ) { return false ; } if ( ListUtil . contains ( this . invalidBusStops , INVALID_STOP_COMPARATOR , busStop ) ) { return false ; } final boolean isValidPrimitive = busStop . isValidPrimitive ( ) ; if ( isValidPrimitive ) { if ( ! this . validBusStops . add ( busStop ) ) { return false ; } } else if ( ListUtil . addIfAbsent ( this . invalidBusStops , INVALID_STOP_COMPARATOR , busStop ) < 0 ) { return false ; } busStop . setEventFirable ( isEventFirable ( ) ) ; busStop . setContainer ( this ) ; if ( isEventFirable ( ) ) { fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . STOP_ADDED , busStop , - 1 , "shape" , //$NON-NLS-1$ null , null ) ) ; busStop . checkPrimitiveValidity ( ) ; checkPrimitiveValidity ( ) ; } return true ; }
Add a bus stop inside the bus network .
273
9
6,343
public void removeAllBusStops ( ) { for ( final BusStop busStop : this . validBusStops ) { busStop . setContainer ( null ) ; busStop . setEventFirable ( true ) ; } for ( final BusStop busStop : this . invalidBusStops ) { busStop . setContainer ( null ) ; busStop . setEventFirable ( true ) ; } this . validBusStops . clear ( ) ; this . invalidBusStops . clear ( ) ; fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . ALL_STOPS_REMOVED , null , - 1 , "shape" , //$NON-NLS-1$ null , null ) ) ; revalidate ( ) ; }
Remove all the bus stops from the current network .
163
10
6,344
public boolean removeBusStop ( BusStop busStop ) { if ( this . validBusStops . remove ( busStop ) ) { busStop . setContainer ( null ) ; busStop . setEventFirable ( true ) ; fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . STOP_REMOVED , busStop , - 1 , "shape" , //$NON-NLS-1$ null , null ) ) ; checkPrimitiveValidity ( ) ; return true ; } final int idx = ListUtil . remove ( this . invalidBusStops , INVALID_STOP_COMPARATOR , busStop ) ; if ( idx >= 0 ) { busStop . setContainer ( null ) ; fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . STOP_REMOVED , busStop , - 1 , "shape" , //$NON-NLS-1$ null , null ) ) ; checkPrimitiveValidity ( ) ; return true ; } return false ; }
Remove a bus stop from this network . If this bus stop removal implies empty hubs these hubs will be also removed .
222
23
6,345
public boolean removeBusStop ( String name ) { Iterator < BusStop > iterator ; BusStop busStop ; iterator = this . validBusStops . iterator ( ) ; while ( iterator . hasNext ( ) ) { busStop = iterator . next ( ) ; if ( name . equals ( busStop . getName ( ) ) ) { iterator . remove ( ) ; busStop . setContainer ( null ) ; busStop . setEventFirable ( true ) ; fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . STOP_REMOVED , busStop , - 1 , "shape" , //$NON-NLS-1$ null , null ) ) ; checkPrimitiveValidity ( ) ; return true ; } } iterator = this . invalidBusStops . iterator ( ) ; while ( iterator . hasNext ( ) ) { busStop = iterator . next ( ) ; if ( name . equals ( busStop . getName ( ) ) ) { iterator . remove ( ) ; busStop . setContainer ( null ) ; fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . STOP_REMOVED , busStop , - 1 , "shape" , //$NON-NLS-1$ null , null ) ) ; checkPrimitiveValidity ( ) ; return true ; } } return false ; }
Remove the bus stops with the given name . If this bus stop removal implies empty hubs these hubs will be also removed .
286
24
6,346
@ Pure public BusStop getBusStop ( UUID id ) { if ( id == null ) { return null ; } for ( final BusStop busStop : this . validBusStops ) { final UUID busid = busStop . getUUID ( ) ; if ( id . equals ( busid ) ) { return busStop ; } } for ( final BusStop busStop : this . invalidBusStops ) { final UUID busid = busStop . getUUID ( ) ; if ( id . equals ( busid ) ) { return busStop ; } } return null ; }
Replies the bus stop with the specified id .
125
10
6,347
@ Pure public BusStop getBusStop ( String name , Comparator < String > nameComparator ) { if ( name == null ) { return null ; } final Comparator < String > cmp = nameComparator == null ? BusNetworkUtilities . NAME_COMPARATOR : nameComparator ; for ( final BusStop busStop : this . validBusStops ) { if ( cmp . compare ( name , busStop . getName ( ) ) == 0 ) { return busStop ; } } for ( final BusStop busStop : this . invalidBusStops ) { if ( cmp . compare ( name , busStop . getName ( ) ) == 0 ) { return busStop ; } } return null ; }
Replies the bus stop with the specified name .
153
10
6,348
@ Pure public Iterator < BusStop > getBusStopsIn ( Rectangle2afp < ? , ? , ? , ? , ? , ? > clipBounds ) { return Iterators . unmodifiableIterator ( this . validBusStops . iterator ( clipBounds ) ) ; }
Replies the set of bus stops that have an intersection with the specified rectangle .
63
16
6,349
@ Pure public BusStop getNearestBusStop ( double x , double y ) { double distance = Double . POSITIVE_INFINITY ; BusStop bestStop = null ; double dist ; for ( final BusStop stop : this . validBusStops ) { dist = stop . distance ( x , y ) ; if ( dist < distance ) { distance = dist ; bestStop = stop ; } } return bestStop ; }
Replies the nearest bus stops to the given point .
90
11
6,350
private boolean addBusHub ( BusHub hub ) { if ( hub == null ) { return false ; } if ( this . validBusHubs . contains ( hub ) ) { return false ; } if ( ListUtil . contains ( this . invalidBusHubs , INVALID_HUB_COMPARATOR , hub ) ) { return false ; } final boolean isValidPrimitive = hub . isValidPrimitive ( ) ; if ( isValidPrimitive ) { if ( ! this . validBusHubs . add ( hub ) ) { return false ; } } else if ( ListUtil . addIfAbsent ( this . invalidBusHubs , INVALID_HUB_COMPARATOR , hub ) < 0 ) { return false ; } hub . setEventFirable ( isEventFirable ( ) ) ; hub . setContainer ( this ) ; if ( isEventFirable ( ) ) { firePrimitiveChanged ( new BusChangeEvent ( this , BusChangeEventType . HUB_ADDED , hub , - 1 , null , null , null ) ) ; hub . checkPrimitiveValidity ( ) ; checkPrimitiveValidity ( ) ; } return true ; }
Add the given bus hub in the network .
252
9
6,351
public void removeAllBusHubs ( ) { for ( final BusHub busHub : this . validBusHubs ) { busHub . setContainer ( null ) ; busHub . setEventFirable ( true ) ; } for ( final BusHub busHub : this . invalidBusHubs ) { busHub . setContainer ( null ) ; busHub . setEventFirable ( true ) ; } this . validBusHubs . clear ( ) ; this . invalidBusHubs . clear ( ) ; firePrimitiveChanged ( new BusChangeEvent ( this , BusChangeEventType . ALL_HUBS_REMOVED , null , - 1 , null , null , null ) ) ; revalidate ( ) ; }
Remove all the bus hubs from the current network .
153
10
6,352
public boolean removeBusHub ( BusHub busHub ) { if ( this . validBusHubs . remove ( busHub ) ) { busHub . setContainer ( null ) ; busHub . setEventFirable ( true ) ; firePrimitiveChanged ( new BusChangeEvent ( this , BusChangeEventType . HUB_REMOVED , busHub , - 1 , null , null , null ) ) ; checkPrimitiveValidity ( ) ; return true ; } final int idx = ListUtil . remove ( this . invalidBusHubs , INVALID_HUB_COMPARATOR , busHub ) ; if ( idx >= 0 ) { busHub . setContainer ( null ) ; busHub . setEventFirable ( true ) ; firePrimitiveChanged ( new BusChangeEvent ( this , BusChangeEventType . HUB_REMOVED , busHub , - 1 , null , null , null ) ) ; checkPrimitiveValidity ( ) ; return true ; } return false ; }
Remove a bus hubs from this network .
213
8
6,353
public boolean removeBusHub ( String name ) { Iterator < BusHub > iterator ; BusHub busHub ; iterator = this . validBusHubs . iterator ( ) ; while ( iterator . hasNext ( ) ) { busHub = iterator . next ( ) ; if ( name . equals ( busHub . getName ( ) ) ) { iterator . remove ( ) ; busHub . setContainer ( null ) ; busHub . setEventFirable ( true ) ; firePrimitiveChanged ( new BusChangeEvent ( this , BusChangeEventType . HUB_REMOVED , busHub , - 1 , null , null , null ) ) ; checkPrimitiveValidity ( ) ; return true ; } } iterator = this . invalidBusHubs . iterator ( ) ; while ( iterator . hasNext ( ) ) { busHub = iterator . next ( ) ; if ( name . equals ( busHub . getName ( ) ) ) { iterator . remove ( ) ; busHub . setContainer ( null ) ; firePrimitiveChanged ( new BusChangeEvent ( this , BusChangeEventType . HUB_REMOVED , busHub , - 1 , null , null , null ) ) ; checkPrimitiveValidity ( ) ; return true ; } } return false ; }
Remove the bus hub with the given name .
266
9
6,354
@ Pure public BusHub getBusHub ( UUID uuid ) { if ( uuid == null ) { return null ; } for ( final BusHub busHub : this . validBusHubs ) { if ( uuid . equals ( busHub . getUUID ( ) ) ) { return busHub ; } } for ( final BusHub busHub : this . invalidBusHubs ) { if ( uuid . equals ( busHub . getUUID ( ) ) ) { return busHub ; } } return null ; }
Replies the bus hub with the specified uuid .
111
11
6,355
@ Pure public BusHub getBusHub ( String name , Comparator < String > nameComparator ) { if ( name == null ) { return null ; } final Comparator < String > cmp = nameComparator == null ? BusNetworkUtilities . NAME_COMPARATOR : nameComparator ; for ( final BusHub busHub : this . validBusHubs ) { if ( cmp . compare ( name , busHub . getName ( ) ) == 0 ) { return busHub ; } } for ( final BusHub busHub : this . invalidBusHubs ) { if ( cmp . compare ( name , busHub . getName ( ) ) == 0 ) { return busHub ; } } return null ; }
Replies the bus hub with the specified name .
153
10
6,356
@ Pure public Iterator < BusHub > getBusHubsIn ( Rectangle2afp < ? , ? , ? , ? , ? , ? > clipBounds ) { return Iterators . unmodifiableIterator ( this . validBusHubs . iterator ( clipBounds ) ) ; }
Replies the set of bus hubs that have an intersection with the specified rectangle .
63
16
6,357
public void setValue ( Object instance , Object value ) { try { setMethod . invoke ( instance , value ) ; } catch ( Exception e ) { throw new PropertyNotFoundException ( klass , getType ( ) , fieldName ) ; } }
Set new value
52
3
6,358
public static Vector3dfx convert ( Tuple3D < ? > tuple ) { if ( tuple instanceof Vector3dfx ) { return ( Vector3dfx ) tuple ; } return new Vector3dfx ( tuple . getX ( ) , tuple . getY ( ) , tuple . getZ ( ) ) ; }
Convert the given tuple to a real Vector3dfx .
65
12
6,359
public void shuffleSelectedRightRowToLeftTableModel ( final int selectedRow ) { if ( - 1 < selectedRow ) { final T row = rightTableModel . removeAt ( selectedRow ) ; leftTableModel . add ( row ) ; } }
Shuffle selected right row to left table model .
53
10
6,360
public OffsetGroup startReferenceOffsetsForContentOffset ( CharOffset contentOffset ) { return characterRegions ( ) . get ( regionIndexContainingContentOffset ( contentOffset ) ) . startOffsetGroupForPosition ( contentOffset ) ; }
Get the earliest reference string offsets corresponding to the given content string offset .
50
14
6,361
public OffsetGroup endReferenceOffsetsForContentOffset ( CharOffset contentOffset ) { return characterRegions ( ) . get ( regionIndexContainingContentOffset ( contentOffset ) ) . endOffsetGroupForPosition ( contentOffset ) ; }
Get the latest reference string offsets corresponding to the given content string offset .
50
14
6,362
public final Optional < UnicodeFriendlyString > referenceSubstringByContentOffsets ( final OffsetRange < CharOffset > contentOffsets ) { if ( referenceString ( ) . isPresent ( ) ) { return Optional . of ( referenceString ( ) . get ( ) . substringByCodePoints ( OffsetGroupRange . from ( startReferenceOffsetsForContentOffset ( contentOffsets . startInclusive ( ) ) , endReferenceOffsetsForContentOffset ( contentOffsets . endInclusive ( ) ) ) . asCharOffsetRange ( ) ) ) ; } else { return Optional . absent ( ) ; } }
Gets the substring of the reference string corresponding to a range of content string offsets . This will include intervening characters which may not themselves correspond to any content string character .
130
34
6,363
@ SuppressWarnings ( "checkstyle:localvariablename" ) @ Pure public int getLatitudeMinute ( ) { double p = Math . abs ( this . phi ) ; p = p - ( int ) p ; return ( int ) ( p * 60. ) ; }
Replies the minute of the sexagesimal representation of the latitude phi .
64
16
6,364
@ SuppressWarnings ( "checkstyle:localvariablename" ) @ Pure public double getLatitudeSecond ( ) { double p = Math . abs ( this . phi ) ; p = ( p - ( int ) p ) * 60. ; p = p - ( int ) p ; return p * 60. ; }
Replies the second of the sexagesimal representation of the latitude phi .
72
16
6,365
@ SuppressWarnings ( "checkstyle:localvariablename" ) @ Pure public int getLongitudeMinute ( ) { double l = Math . abs ( this . lambda ) ; l = l - ( int ) l ; return ( int ) ( l * 60. ) ; }
Replies the minute of the sexagesimal representation of the longitude phi .
63
17
6,366
@ SuppressWarnings ( "checkstyle:localvariablename" ) @ Pure public double getLongitudeSecond ( ) { double p = Math . abs ( this . lambda ) ; p = ( p - ( int ) p ) * 60. ; p = p - ( int ) p ; return p * 60. ; }
Replies the second of the sexagesimal representation of the longitude phi .
71
17
6,367
public static void setPreferredStringRepresentation ( GeodesicPositionStringRepresentation representation , boolean useSymbolicDirection ) { final Preferences prefs = Preferences . userNodeForPackage ( GeodesicPosition . class ) ; if ( prefs != null ) { if ( representation == null ) { prefs . remove ( "STRING_REPRESENTATION" ) ; //$NON-NLS-1$ prefs . remove ( "SYMBOL_IN_STRING_REPRESENTATION" ) ; //$NON-NLS-1$ } else { prefs . put ( "STRING_REPRESENTATION" , representation . toString ( ) ) ; //$NON-NLS-1$ prefs . putBoolean ( "SYMBOL_IN_STRING_REPRESENTATION" , useSymbolicDirection ) ; //$NON-NLS-1$ } } }
Set the preferred format of the string representation of a geodesic position .
201
15
6,368
@ Pure public static GeodesicPositionStringRepresentation getPreferredStringRepresentation ( boolean allowNullValue ) { final Preferences prefs = Preferences . userNodeForPackage ( GeodesicPosition . class ) ; if ( prefs != null ) { final String v = prefs . get ( "STRING_REPRESENTATION" , null ) ; //$NON-NLS-1$ if ( v != null && ! "" . equals ( v ) ) { //$NON-NLS-1$ try { GeodesicPositionStringRepresentation rep ; try { rep = GeodesicPositionStringRepresentation . valueOf ( v . toUpperCase ( ) ) ; } catch ( Throwable exception ) { rep = null ; } if ( rep != null ) { return rep ; } } catch ( AssertionError e ) { throw e ; } catch ( Throwable exception ) { // } } } if ( allowNullValue ) { return null ; } return DEFAULT_STRING_REPRESENTATION ; }
Replies the preferred format of the string representation of a geodesic position .
218
16
6,369
@ Pure public static boolean getDirectionSymbolInPreferredStringRepresentation ( ) { final Preferences prefs = Preferences . userNodeForPackage ( GeodesicPosition . class ) ; if ( prefs != null ) { return prefs . getBoolean ( "SYMBOL_IN_STRING_REPRESENTATION" , DEFAULT_SYMBOL_IN_STRING_REPRESENTATION ) ; //$NON-NLS-1$ } return DEFAULT_SYMBOL_IN_STRING_REPRESENTATION ; }
Replies if the direction symbol should be output in the preferred string representation of a geodesic position .
119
21
6,370
public synchronized void addForestListener ( ForestListener listener ) { if ( this . listeners == null ) { this . listeners = new ArrayList <> ( ) ; } this . listeners . add ( listener ) ; }
Add forest listener .
44
4
6,371
public synchronized void removeForestListener ( ForestListener listener ) { if ( this . listeners != null ) { this . listeners . remove ( listener ) ; if ( this . listeners . isEmpty ( ) ) { this . listeners = null ; } } }
Remove forest listener .
51
4
6,372
@ SuppressWarnings ( "static-method" ) @ Provides @ Singleton public Log4jIntegrationConfig getLog4jIntegrationConfig ( ConfigurationFactory configFactory , Injector injector ) { final Log4jIntegrationConfig config = Log4jIntegrationConfig . getConfiguration ( configFactory ) ; injector . injectMembers ( config ) ; return config ; }
Replies the instance of the log4j integration configuration ..
81
12
6,373
@ SuppressWarnings ( "static-method" ) @ Singleton @ Provides public Logger provideRootLogger ( ConfigurationFactory configFactory , Provider < Log4jIntegrationConfig > config ) { final Logger root = Logger . getRootLogger ( ) ; // Reroute JUL SLF4JBridgeHandler . removeHandlersForRootLogger ( ) ; SLF4JBridgeHandler . install ( ) ; final Log4jIntegrationConfig cfg = config . get ( ) ; if ( ! cfg . getUseLog4jConfig ( ) ) { cfg . configureLogger ( root ) ; } return root ; }
Provide the root logger .
138
6
6,374
@ Override protected void onInitializeComponents ( ) { lpNoProxy = new JLayeredPane ( ) ; lpNoProxy . setBorder ( new EtchedBorder ( EtchedBorder . RAISED , null , null ) ) ; lpHostOrIpaddress = new JLayeredPane ( ) ; lpHostOrIpaddress . setBorder ( new EtchedBorder ( EtchedBorder . RAISED , null , null ) ) ; rdbtnManualProxyConfiguration = new JRadioButton ( "Manual proxy configuration" ) ; rdbtnManualProxyConfiguration . setBounds ( 6 , 7 , 313 , 23 ) ; lpHostOrIpaddress . add ( rdbtnManualProxyConfiguration ) ; lblHostOrIpaddress = new JLabel ( "Host or IP-address:" ) ; lblHostOrIpaddress . setBounds ( 26 , 37 , 109 , 14 ) ; lpHostOrIpaddress . add ( lblHostOrIpaddress ) ; txtHostOrIpaddress = new JTextField ( ) ; txtHostOrIpaddress . setBounds ( 145 , 37 , 213 , 20 ) ; lpHostOrIpaddress . add ( txtHostOrIpaddress ) ; txtHostOrIpaddress . setColumns ( 10 ) ; lblPort = new JLabel ( "Port:" ) ; lblPort . setBounds ( 368 , 40 , 46 , 14 ) ; lpHostOrIpaddress . add ( lblPort ) ; txtPort = new JTextField ( ) ; txtPort . setBounds ( 408 , 37 , 67 , 20 ) ; lpHostOrIpaddress . add ( txtPort ) ; txtPort . setColumns ( 10 ) ; rdbtnNoProxy = new JRadioButton ( "Direct connection to internet (no proxy)" ) ; rdbtnNoProxy . setBounds ( 6 , 7 , 305 , 23 ) ; lpNoProxy . add ( rdbtnNoProxy ) ; lpUseSystemSettings = new JLayeredPane ( ) ; lpUseSystemSettings . setBorder ( new EtchedBorder ( EtchedBorder . RAISED , null , null ) ) ; rdbtnUseSystemSettings = new JRadioButton ( "Use proxy settings from system" ) ; rdbtnUseSystemSettings . setBounds ( 6 , 7 , 305 , 23 ) ; lpUseSystemSettings . add ( rdbtnUseSystemSettings ) ; // Group the radio buttons. btngrpProxySettings = new ButtonGroup ( ) ; btngrpProxySettings . add ( rdbtnNoProxy ) ; btngrpProxySettings . add ( rdbtnManualProxyConfiguration ) ; chckbxSocksProxy = new JCheckBox ( "SOCKS-Proxy?" ) ; chckbxSocksProxy . setToolTipText ( "Is it a SOCKS-Proxy?" ) ; chckbxSocksProxy . setBounds ( 26 , 63 , 97 , 23 ) ; lpHostOrIpaddress . add ( chckbxSocksProxy ) ; btngrpProxySettings . add ( rdbtnUseSystemSettings ) ; }
Initialize components .
709
4
6,375
@ Pure public static Iterator < BusItineraryHalt > getBusHalts ( BusLine busLine ) { assert busLine != null ; return new LineHaltIterator ( busLine ) ; }
Replies all the bus itinerary halts in the given bus line .
43
15
6,376
@ Pure public static Iterator < BusItineraryHalt > getBusHalts ( BusNetwork busNetwork ) { assert busNetwork != null ; return new NetworkHaltIterator ( busNetwork ) ; }
Replies all the bus itinerary halts in the given bus network .
43
15
6,377
protected Method getActionMethod ( Class actionClass , String methodName ) throws NoSuchMethodException { Method method ; try { method = actionClass . getMethod ( methodName , new Class [ 0 ] ) ; } catch ( NoSuchMethodException e ) { // hmm -- OK, try doXxx instead try { String altMethodName = "do" + methodName . substring ( 0 , 1 ) . toUpperCase ( ) + methodName . substring ( 1 ) ; method = actionClass . getMethod ( altMethodName , new Class [ 0 ] ) ; } catch ( NoSuchMethodException e1 ) { // throw the original one throw e ; } } return method ; }
This is copied from DefaultActionInvocation
146
8
6,378
private String cutYear ( String str ) { if ( str . length ( ) > 3 ) { return str . substring ( str . length ( ) - 3 , str . length ( ) ) ; } else { return str ; } }
Remove the 2 - bit year number from input date string
49
11
6,379
@ Override public Point3d getPivot ( ) { Point3d pivot = this . cachedPivot == null ? null : this . cachedPivot . get ( ) ; if ( pivot == null ) { pivot = getProjection ( 0. , 0. , 0. ) ; this . cachedPivot = new WeakReference <> ( pivot ) ; } return pivot ; }
Replies the pivot point around which the rotation must be done .
81
13
6,380
private static String decodeHTMLEntities ( String string ) { if ( string == null ) { return null ; } try { return URLDecoder . decode ( string , Charset . defaultCharset ( ) . displayName ( ) ) ; } catch ( UnsupportedEncodingException exception ) { return string ; } }
Replace the HTML entities by the current charset characters .
69
12
6,381
private static String encodeHTMLEntities ( String string ) { if ( string == null ) { return null ; } try { return URLEncoder . encode ( string , Charset . defaultCharset ( ) . displayName ( ) ) ; } catch ( UnsupportedEncodingException exception ) { return string ; } }
Replace the special characters by HTML entities .
70
9
6,382
@ Pure @ Inline ( value = "URISchemeType.JAR.isURL($1)" , imported = { URISchemeType . class } ) public static boolean isJarURL ( URL url ) { return URISchemeType . JAR . isURL ( url ) ; }
Replies if the given URL has a jar scheme .
64
11
6,383
@ Pure public static URL getJarURL ( URL url ) { if ( ! isJarURL ( url ) ) { return null ; } String path = url . getPath ( ) ; final int idx = path . lastIndexOf ( JAR_URL_FILE_ROOT ) ; if ( idx >= 0 ) { path = path . substring ( 0 , idx ) ; } try { return new URL ( path ) ; } catch ( MalformedURLException exception ) { return null ; } }
Replies the jar part of the jar - scheme URL .
108
12
6,384
@ Pure public static File getJarFile ( URL url ) { if ( isJarURL ( url ) ) { final String path = url . getPath ( ) ; final int idx = path . lastIndexOf ( JAR_URL_FILE_ROOT ) ; if ( idx >= 0 ) { return new File ( decodeHTMLEntities ( path . substring ( idx + 1 ) ) ) ; } } return null ; }
Replies the file part of the jar - scheme URL .
94
12
6,385
@ Pure public static boolean isCaseSensitiveFilenameSystem ( ) { switch ( OperatingSystem . getCurrentOS ( ) ) { case AIX : case ANDROID : case BSD : case FREEBSD : case NETBSD : case OPENBSD : case LINUX : case SOLARIS : case HPUX : return true ; //$CASES-OMITTED$ default : return false ; } }
Replies if the current operating system uses case - sensitive filename .
85
13
6,386
@ Pure public static String extension ( File filename ) { if ( filename == null ) { return null ; } final String largeBasename = largeBasename ( filename ) ; final int idx = largeBasename . lastIndexOf ( getFileExtensionCharacter ( ) ) ; if ( idx <= 0 ) { return "" ; //$NON-NLS-1$ } return largeBasename . substring ( idx ) ; }
Reply the extension of the specified file .
92
8
6,387
@ Pure public static boolean hasExtension ( File filename , String extension ) { if ( filename == null ) { return false ; } assert extension != null ; String extent = extension ; if ( ! "" . equals ( extent ) && ! extent . startsWith ( EXTENSION_SEPARATOR ) ) { //$NON-NLS-1$ extent = EXTENSION_SEPARATOR + extent ; } final String ext = extension ( filename ) ; if ( ext == null ) { return false ; } if ( isCaseSensitiveFilenameSystem ( ) ) { return ext . equals ( extent ) ; } return ext . equalsIgnoreCase ( extent ) ; }
Replies if the specified file has the specified extension .
139
11
6,388
@ Pure public static File getSystemConfigurationDirectoryFor ( String software ) { if ( software == null || "" . equals ( software ) ) { //$NON-NLS-1$ throw new IllegalArgumentException ( ) ; } final OperatingSystem os = OperatingSystem . getCurrentOS ( ) ; if ( os == OperatingSystem . ANDROID ) { return join ( File . listRoots ( ) [ 0 ] , Android . CONFIGURATION_DIRECTORY , Android . makeAndroidApplicationName ( software ) ) ; } else if ( os . isUnixCompliant ( ) ) { final File [ ] roots = File . listRoots ( ) ; return join ( roots [ 0 ] , "etc" , software ) ; //$NON-NLS-1$ } else if ( os == OperatingSystem . WIN ) { File pfDirectory ; for ( final File root : File . listRoots ( ) ) { pfDirectory = new File ( root , "Program Files" ) ; //$NON-NLS-1$ if ( pfDirectory . isDirectory ( ) ) { return new File ( root , software ) ; } } } return null ; }
Replies the system configuration directory for the specified software .
248
11
6,389
@ Pure public static String getSystemSharedLibraryDirectoryNameFor ( String software ) { final File f = getSystemSharedLibraryDirectoryFor ( software ) ; if ( f == null ) { return null ; } return f . getAbsolutePath ( ) ; }
Replies the system shared library directory for the specified software .
55
12
6,390
@ Pure public static File convertStringToFile ( String filename ) { if ( filename == null || "" . equals ( filename ) ) { //$NON-NLS-1$ return null ; } if ( isWindowsNativeFilename ( filename ) ) { return normalizeWindowsNativeFilename ( filename ) ; } // Test for malformed filenames. return new File ( extractLocalPath ( filename ) . replaceAll ( Pattern . quote ( UNIX_SEPARATOR_STRING ) , Matcher . quoteReplacement ( File . separator ) ) ) ; }
Convert a string which represents a local file into a File .
118
13
6,391
@ Pure @ SuppressWarnings ( "checkstyle:npathcomplexity" ) public static File convertURLToFile ( URL url ) { URL theUrl = url ; if ( theUrl == null ) { return null ; } if ( URISchemeType . RESOURCE . isURL ( theUrl ) ) { theUrl = Resources . getResource ( decodeHTMLEntities ( theUrl . getFile ( ) ) ) ; if ( theUrl == null ) { theUrl = url ; } } URI uri ; try { // this is the step that can fail, and so // it should be this step that should be fixed uri = theUrl . toURI ( ) ; } catch ( URISyntaxException e ) { // OK if we are here, then obviously the URL did // not comply with RFC 2396. This can only // happen if we have illegal unescaped characters. // If we have one unescaped character, then // the only automated fix we can apply, is to assume // all characters are unescaped. // If we want to construct a URI from unescaped // characters, then we have to use the component // constructors: try { uri = new URI ( theUrl . getProtocol ( ) , theUrl . getUserInfo ( ) , theUrl . getHost ( ) , theUrl . getPort ( ) , decodeHTMLEntities ( theUrl . getPath ( ) ) , decodeHTMLEntities ( theUrl . getQuery ( ) ) , theUrl . getRef ( ) ) ; } catch ( URISyntaxException e1 ) { // The URL is broken beyond automatic repair throw new IllegalArgumentException ( Locale . getString ( "E1" , theUrl ) ) ; //$NON-NLS-1$ } } if ( uri != null && URISchemeType . FILE . isURI ( uri ) ) { final String auth = uri . getAuthority ( ) ; String path = uri . getPath ( ) ; if ( path == null ) { path = uri . getRawPath ( ) ; } if ( path == null ) { path = uri . getSchemeSpecificPart ( ) ; } if ( path == null ) { path = uri . getRawSchemeSpecificPart ( ) ; } if ( path != null ) { if ( auth == null || "" . equals ( auth ) ) { //$NON-NLS-1$ // absolute filename in URI path = decodeHTMLEntities ( path ) ; } else { // relative filename in URI, extract it directly path = decodeHTMLEntities ( auth + path ) ; } if ( Pattern . matches ( "^" + Pattern . quote ( URL_PATH_SEPARATOR ) //$NON-NLS-1$ + "[a-zA-Z][:|].*$" , path ) ) { //$NON-NLS-1$ path = path . substring ( URL_PATH_SEPARATOR . length ( ) ) ; } return new File ( path ) ; } } throw new IllegalArgumentException ( Locale . getString ( "E2" , theUrl ) ) ; //$NON-NLS-1$ }
Convert an URL which represents a local file or a resource into a File .
696
16
6,392
@ Pure @ SuppressWarnings ( { "checkstyle:cyclomaticcomplexity" , "checkstyle:npathcomplexity" } ) public static URL getParentURL ( URL url ) throws MalformedURLException { if ( url == null ) { return url ; } String path = url . getPath ( ) ; final String prefix ; final String parentStr ; switch ( URISchemeType . getSchemeType ( url ) ) { case JAR : final int index = path . indexOf ( JAR_URL_FILE_ROOT ) ; assert index > 0 ; prefix = path . substring ( 0 , index + 1 ) ; path = path . substring ( index + 1 ) ; parentStr = URL_PATH_SEPARATOR ; break ; case FILE : prefix = null ; parentStr = ".." + URL_PATH_SEPARATOR ; //$NON-NLS-1$ break ; //$CASES-OMITTED$ default : prefix = null ; parentStr = URL_PATH_SEPARATOR ; } if ( path == null || "" . equals ( path ) ) { //$NON-NLS-1$ path = parentStr ; } int index = path . lastIndexOf ( URL_PATH_SEPARATOR_CHAR ) ; if ( index == - 1 ) { path = parentStr ; } else if ( index == path . length ( ) - 1 ) { index = path . lastIndexOf ( URL_PATH_SEPARATOR_CHAR , index - 1 ) ; if ( index == - 1 ) { path = parentStr ; } else { path = path . substring ( 0 , index + 1 ) ; } } else { path = path . substring ( 0 , index + 1 ) ; } if ( prefix != null ) { path = prefix + path ; } return new URL ( url . getProtocol ( ) , url . getHost ( ) , url . getPort ( ) , path ) ; }
Replies the parent URL for the given URL .
420
10
6,393
@ Pure @ SuppressWarnings ( "checkstyle:magicnumber" ) private static String extractLocalPath ( String filename ) { if ( filename == null ) { return null ; } final int max = Math . min ( FILE_PREFIX . length , filename . length ( ) ) ; final int inner = max - 2 ; if ( inner <= 0 ) { return filename ; } boolean foundInner = false ; boolean foundFull = false ; for ( int i = 0 ; i < max ; ++ i ) { final char c = Character . toLowerCase ( filename . charAt ( i ) ) ; if ( FILE_PREFIX [ i ] != c ) { foundFull = false ; foundInner = i >= inner ; break ; } foundFull = true ; } String fn ; if ( foundFull ) { fn = filename . substring ( FILE_PREFIX . length ) ; } else if ( foundInner ) { fn = filename . substring ( inner ) ; } else { fn = filename ; } if ( Pattern . matches ( "^(" + Pattern . quote ( URL_PATH_SEPARATOR ) + "|" //$NON-NLS-1$ //$NON-NLS-2$ + Pattern . quote ( WINDOWS_SEPARATOR_STRING ) + ")[a-zA-Z][:|].*$" , fn ) ) { //$NON-NLS-1$ fn = fn . substring ( 1 ) ; } return fn ; }
Test if the given filename is a local filename and extract the path component .
324
15
6,394
@ Pure public static boolean isWindowsNativeFilename ( String filename ) { final String fn = extractLocalPath ( filename ) ; if ( fn == null || fn . length ( ) == 0 ) { return false ; } final Pattern pattern = Pattern . compile ( WINDOW_NATIVE_FILENAME_PATTERN ) ; final Matcher matcher = pattern . matcher ( fn ) ; return matcher . matches ( ) ; }
Replies if the given string contains a Windows&reg ; native long filename .
91
16
6,395
@ Pure public static File normalizeWindowsNativeFilename ( String filename ) { final String fn = extractLocalPath ( filename ) ; if ( fn != null && fn . length ( ) > 0 ) { final Pattern pattern = Pattern . compile ( WINDOW_NATIVE_FILENAME_PATTERN ) ; final Matcher matcher = pattern . matcher ( fn ) ; if ( matcher . find ( ) ) { return new File ( fn . replace ( WINDOWS_SEPARATOR_CHAR , File . separatorChar ) ) ; } } return null ; }
Normalize the given string contains a Windows&reg ; native long filename and replies a Java - standard version .
121
22
6,396
@ Pure public static URL makeCanonicalURL ( URL url ) { if ( url != null ) { final String [ ] pathComponents = url . getPath ( ) . split ( Pattern . quote ( URL_PATH_SEPARATOR ) ) ; final List < String > canonicalPath = new LinkedList <> ( ) ; for ( final String component : pathComponents ) { if ( ! CURRENT_DIRECTORY . equals ( component ) ) { if ( PARENT_DIRECTORY . equals ( component ) ) { if ( ! canonicalPath . isEmpty ( ) ) { canonicalPath . remove ( canonicalPath . size ( ) - 1 ) ; } else { canonicalPath . add ( component ) ; } } else { canonicalPath . add ( component ) ; } } } final StringBuilder newPathBuffer = new StringBuilder ( ) ; boolean isFirst = true ; for ( final String component : canonicalPath ) { if ( ! isFirst ) { newPathBuffer . append ( URL_PATH_SEPARATOR_CHAR ) ; } else { isFirst = false ; } newPathBuffer . append ( component ) ; } try { return new URI ( url . getProtocol ( ) , url . getUserInfo ( ) , url . getHost ( ) , url . getPort ( ) , newPathBuffer . toString ( ) , url . getQuery ( ) , url . getRef ( ) ) . toURL ( ) ; } catch ( MalformedURLException | URISyntaxException exception ) { // } try { return new URL ( url . getProtocol ( ) , url . getHost ( ) , newPathBuffer . toString ( ) ) ; } catch ( Throwable exception ) { // } } return url ; }
Make the given URL canonical .
368
6
6,397
public static void zipFile ( File input , File output ) throws IOException { try ( FileOutputStream fos = new FileOutputStream ( output ) ) { zipFile ( input , fos ) ; } }
Create a zip file from the given input file .
44
10
6,398
@ SuppressWarnings ( "checkstyle:npathcomplexity" ) public static void zipFile ( File input , OutputStream output ) throws IOException { try ( ZipOutputStream zos = new ZipOutputStream ( output ) ) { if ( input == null ) { return ; } final LinkedList < File > candidates = new LinkedList <> ( ) ; candidates . add ( input ) ; final byte [ ] buffer = new byte [ BUFFER_SIZE ] ; int len ; File file ; File relativeFile ; String zipFilename ; final File rootDirectory = ( input . isDirectory ( ) ) ? input : input . getParentFile ( ) ; while ( ! candidates . isEmpty ( ) ) { file = candidates . removeFirst ( ) ; assert file != null ; if ( file . getAbsoluteFile ( ) . equals ( rootDirectory . getAbsoluteFile ( ) ) ) { relativeFile = null ; } else { relativeFile = makeRelative ( file , rootDirectory , false ) ; } if ( file . isDirectory ( ) ) { if ( relativeFile != null ) { zipFilename = fromFileStandardToURLStandard ( relativeFile ) + URL_PATH_SEPARATOR ; final ZipEntry zipEntry = new ZipEntry ( zipFilename ) ; zos . putNextEntry ( zipEntry ) ; zos . closeEntry ( ) ; } candidates . addAll ( Arrays . asList ( file . listFiles ( ) ) ) ; } else if ( relativeFile != null ) { try ( FileInputStream fis = new FileInputStream ( file ) ) { zipFilename = fromFileStandardToURLStandard ( relativeFile ) ; final ZipEntry zipEntry = new ZipEntry ( zipFilename ) ; zos . putNextEntry ( zipEntry ) ; while ( ( len = fis . read ( buffer ) ) > 0 ) { zos . write ( buffer , 0 , len ) ; } zos . closeEntry ( ) ; } } } } }
Create a zip file from the given input file . If the input file is a directory the content of the directory is zipped . If the input file is a standard file it is zipped .
416
39
6,399
public static void unzipFile ( InputStream input , File output ) throws IOException { if ( output == null ) { return ; } output . mkdirs ( ) ; if ( ! output . isDirectory ( ) ) { throw new IOException ( Locale . getString ( "E3" , output ) ) ; //$NON-NLS-1$ } try ( ZipInputStream zis = new ZipInputStream ( input ) ) { final byte [ ] buffer = new byte [ BUFFER_SIZE ] ; int len ; ZipEntry zipEntry = zis . getNextEntry ( ) ; while ( zipEntry != null ) { final String name = zipEntry . getName ( ) ; final File outFile = new File ( output , name ) . getCanonicalFile ( ) ; if ( zipEntry . isDirectory ( ) ) { outFile . mkdirs ( ) ; } else { outFile . getParentFile ( ) . mkdirs ( ) ; try ( FileOutputStream fos = new FileOutputStream ( outFile ) ) { while ( ( len = zis . read ( buffer ) ) > 0 ) { fos . write ( buffer , 0 , len ) ; } } } zipEntry = zis . getNextEntry ( ) ; } } }
Unzip the given stream and write out the file in the output . If the input file is a directory the content of the directory is zipped . If the input file is a standard file it is zipped .
271
43