idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
6,000
private ProxyType extendedProxyTypeAsProxyType ( ExtendedProxyType pt ) { switch ( pt ) { case DRAFT_RFC : return ProxyType . DRAFT_RFC ; case LEGACY : return ProxyType . LEGACY ; case RFC3820 : return ProxyType . RFC3820 ; default : return null ; } }
Why we have to do this nonsense?
67
8
6,001
@ Pure @ SuppressWarnings ( "checkstyle:magicnumber" ) public static String encodeBase26 ( int number ) { final StringBuilder value = new StringBuilder ( ) ; int code = number ; do { final int rest = code % 26 ; value . insert ( 0 , ( char ) ( ' ' + rest ) ) ; code = code / 26 - 1 ; } while ( code >= 0 ) ; return value . toString ( ) ; }
Replies a base 26 encoding string for the given number .
96
12
6,002
@ Pure @ SuppressWarnings ( "checkstyle:npathcomplexity" ) public static Map < Character , String > getJavaToHTMLTranslationTable ( ) { Map < Character , String > map = null ; try { LOCK . lock ( ) ; if ( javaToHtmlTransTbl != null ) { map = javaToHtmlTransTbl . get ( ) ; } } finally { LOCK . unlock ( ) ; } if ( map != null ) { return map ; } // Get the resource file ResourceBundle resource = null ; try { resource = ResourceBundle . getBundle ( TextUtil . class . getCanonicalName ( ) , java . util . Locale . getDefault ( ) ) ; } catch ( MissingResourceException exep ) { return null ; } // get the resource string final String result ; try { result = resource . getString ( "HTML_TRANS_TBL" ) ; //$NON-NLS-1$ } catch ( Exception e ) { return null ; } map = new TreeMap <> ( ) ; final String [ ] pairs = result . split ( "(\\}\\{)|\\{|\\}" ) ; //$NON-NLS-1$ Integer isoCode ; String entity ; String code ; for ( int i = 1 ; ( i + 1 ) < pairs . length ; i += 2 ) { try { entity = pairs [ i ] ; code = pairs [ i + 1 ] ; isoCode = Integer . valueOf ( code ) ; if ( isoCode != null ) { map . put ( ( char ) isoCode . intValue ( ) , entity ) ; } } catch ( Throwable exception ) { // } } try { LOCK . lock ( ) ; javaToHtmlTransTbl = new SoftReference <> ( map ) ; } finally { LOCK . unlock ( ) ; } return map ; }
Replies the java - to - html s translation table .
403
12
6,003
@ Pure @ SuppressWarnings ( "checkstyle:magicnumber" ) public static String parseHTML ( String html ) { if ( html == null ) { return null ; } final Map < String , Integer > transTbl = getHtmlToJavaTranslationTable ( ) ; assert transTbl != null ; if ( transTbl . isEmpty ( ) ) { return html ; } final Pattern pattern = Pattern . compile ( "[&](([a-zA-Z]+)|(#x?[0-9]+))[;]" ) ; //$NON-NLS-1$ final Matcher matcher = pattern . matcher ( html ) ; final StringBuilder result = new StringBuilder ( ) ; String entity ; Integer isoCode ; int lastIndex = 0 ; while ( matcher . find ( ) ) { final int idx = matcher . start ( ) ; result . append ( html . substring ( lastIndex , idx ) ) ; lastIndex = matcher . end ( ) ; entity = matcher . group ( 1 ) ; if ( entity . startsWith ( "#x" ) ) { //$NON-NLS-1$ try { isoCode = Integer . valueOf ( entity . substring ( 2 ) , 16 ) ; } catch ( Throwable exception ) { isoCode = null ; } } else if ( entity . startsWith ( "#" ) ) { //$NON-NLS-1$ try { isoCode = Integer . valueOf ( entity . substring ( 1 ) ) ; } catch ( Throwable exception ) { isoCode = null ; } } else { isoCode = transTbl . get ( entity ) ; } if ( isoCode == null ) { result . append ( matcher . group ( ) ) ; } else { result . append ( ( char ) isoCode . intValue ( ) ) ; } } if ( lastIndex < html . length ( ) ) { result . append ( html . substring ( lastIndex ) ) ; } return result . toString ( ) ; }
Parse the given HTML text and replace all the HTML entities by the corresponding unicode character .
432
19
6,004
@ Pure public static String toHTML ( String text ) { if ( text == null ) { return null ; } final Map < Character , String > transTbl = getJavaToHTMLTranslationTable ( ) ; assert transTbl != null ; if ( transTbl . isEmpty ( ) ) { return text ; } final StringBuilder patternStr = new StringBuilder ( ) ; for ( final Character c : transTbl . keySet ( ) ) { if ( patternStr . length ( ) > 0 ) { patternStr . append ( "|" ) ; //$NON-NLS-1$ } patternStr . append ( Pattern . quote ( c . toString ( ) ) ) ; } final Pattern pattern = Pattern . compile ( patternStr . toString ( ) ) ; final Matcher matcher = pattern . matcher ( text ) ; final StringBuilder result = new StringBuilder ( ) ; String character ; String entity ; int lastIndex = 0 ; while ( matcher . find ( ) ) { final int idx = matcher . start ( ) ; result . append ( text . substring ( lastIndex , idx ) ) ; lastIndex = matcher . end ( ) ; character = matcher . group ( ) ; if ( character . length ( ) == 1 ) { entity = transTbl . get ( Character . valueOf ( character . charAt ( 0 ) ) ) ; if ( entity != null ) { entity = "&" + entity + ";" ; //$NON-NLS-1$ //$NON-NLS-2$ } else { entity = character ; } } else { entity = character ; } result . append ( entity ) ; } if ( lastIndex < text . length ( ) ) { result . append ( text . substring ( lastIndex ) ) ; } return result . toString ( ) ; }
Translate all the special character from the given text to their equivalent HTML entities .
390
16
6,005
public static void cutStringAsArray ( String text , CutStringCritera critera , List < String > output ) { cutStringAlgo ( text , critera , new CutStringToArray ( output ) ) ; }
Format the text to be sure that each line is not more longer than the specified critera .
46
19
6,006
@ Pure public static char getMnemonicChar ( String text ) { if ( text != null ) { final int pos = text . indexOf ( ' ' ) ; if ( ( pos != - 1 ) && ( pos < text . length ( ) - 1 ) ) { return text . charAt ( pos + 1 ) ; } } return ' ' ; }
Replies the character which follow the first &amp ; .
75
12
6,007
@ Pure public static String removeMnemonicChar ( String text ) { if ( text == null ) { return text ; } return text . replaceFirst ( "&" , "" ) ; //$NON-NLS-1$ //$NON-NLS-2$ }
Remove the mnemonic char from the specified string .
60
11
6,008
@ Pure @ SuppressWarnings ( "checkstyle:npathcomplexity" ) public static Map < Character , String > getAccentTranslationTable ( ) { Map < Character , String > map = null ; try { LOCK . lock ( ) ; if ( accentTransTbl != null ) { map = accentTransTbl . get ( ) ; } } finally { LOCK . unlock ( ) ; } if ( map != null ) { return map ; } // Get the resource file ResourceBundle resource = null ; try { resource = ResourceBundle . getBundle ( TextUtil . class . getCanonicalName ( ) , java . util . Locale . getDefault ( ) ) ; } catch ( MissingResourceException exep ) { return null ; } // get the resource string final String result ; try { result = resource . getString ( "ACCENT_TRANS_TBL" ) ; //$NON-NLS-1$ } catch ( Exception e ) { return null ; } map = new TreeMap <> ( ) ; final String [ ] pairs = result . split ( "(\\}\\{)|\\{|\\}" ) ; //$NON-NLS-1$ for ( final String pair : pairs ) { if ( pair . length ( ) > 1 ) { map . put ( pair . charAt ( 0 ) , pair . substring ( 1 ) ) ; } } try { LOCK . lock ( ) ; accentTransTbl = new SoftReference <> ( map ) ; } finally { LOCK . unlock ( ) ; } return map ; }
Replies the accent s translation table .
338
8
6,009
@ Pure public static String removeAccents ( String text ) { final Map < Character , String > map = getAccentTranslationTable ( ) ; if ( ( map == null ) || ( map . isEmpty ( ) ) ) { return text ; } return removeAccents ( text , map ) ; }
Remove the accents inside the specified string .
63
8
6,010
@ Pure public static String [ ] split ( char leftSeparator , char rightSeparator , String str ) { final SplitSeparatorToArrayAlgorithm algo = new SplitSeparatorToArrayAlgorithm ( ) ; splitSeparatorAlgorithm ( leftSeparator , rightSeparator , str , algo ) ; return algo . toArray ( ) ; }
Split the given string according to the separators . The separators are used to delimit the groups of characters .
82
23
6,011
@ Pure public static < T > String join ( char leftSeparator , char rightSeparator , @ SuppressWarnings ( "unchecked" ) T ... strs ) { final StringBuilder buffer = new StringBuilder ( ) ; for ( final Object s : strs ) { buffer . append ( leftSeparator ) ; if ( s != null ) { buffer . append ( s . toString ( ) ) ; } buffer . append ( rightSeparator ) ; } return buffer . toString ( ) ; }
Merge the given strings with to separators . The separators are used to delimit the groups of characters .
111
23
6,012
@ Pure public static String toUpperCaseWithoutAccent ( String text , Map < Character , String > map ) { final StringBuilder buffer = new StringBuilder ( ) ; for ( final char c : text . toCharArray ( ) ) { final String trans = map . get ( c ) ; if ( trans != null ) { buffer . append ( trans . toUpperCase ( ) ) ; } else { buffer . append ( Character . toUpperCase ( c ) ) ; } } return buffer . toString ( ) ; }
Translate the specified string to upper case and remove the accents .
112
13
6,013
@ Pure public static String formatDouble ( double amount , int decimalCount ) { final int dc = ( decimalCount < 0 ) ? 0 : decimalCount ; final StringBuilder str = new StringBuilder ( "#0" ) ; //$NON-NLS-1$ if ( dc > 0 ) { str . append ( ' ' ) ; for ( int i = 0 ; i < dc ; ++ i ) { str . append ( ' ' ) ; } } final DecimalFormat fmt = new DecimalFormat ( str . toString ( ) ) ; return fmt . format ( amount ) ; }
Format the given double value .
124
6
6,014
public static int getLevenshteinDistance ( String firstString , String secondString ) { final String s0 = firstString == null ? "" : firstString ; //$NON-NLS-1$ final String s1 = secondString == null ? "" : secondString ; //$NON-NLS-1$ final int len0 = s0 . length ( ) + 1 ; final int len1 = s1 . length ( ) + 1 ; // the array of distances int [ ] cost = new int [ len0 ] ; int [ ] newcost = new int [ len0 ] ; // initial cost of skipping prefix in String s0 for ( int i = 0 ; i < len0 ; ++ i ) { cost [ i ] = i ; } // dynamically computing the array of distances // transformation cost for each letter in s1 for ( int j = 1 ; j < len1 ; ++ j ) { // initial cost of skipping prefix in String s1 newcost [ 0 ] = j ; // transformation cost for each letter in s0 for ( int i = 1 ; i < len0 ; ++ i ) { // matching current letters in both strings final int match = ( s0 . charAt ( i - 1 ) == s1 . charAt ( j - 1 ) ) ? 0 : 1 ; // computing cost for each transformation final int costReplace = cost [ i - 1 ] + match ; final int costInsert = cost [ i ] + 1 ; final int costDelete = newcost [ i - 1 ] + 1 ; // keep minimum cost newcost [ i ] = Math . min ( Math . min ( costInsert , costDelete ) , costReplace ) ; } // swap cost/newcost arrays final int [ ] swap = cost ; cost = newcost ; newcost = swap ; } // the distance is the cost for transforming all letters in both strings return cost [ len0 - 1 ] ; }
Compute the Levenshstein distance between two strings .
403
12
6,015
@ Pure public static String toJavaString ( String text ) { final StringEscaper escaper = new StringEscaper ( ) ; return escaper . escape ( text ) ; }
Translate the given string to its Java string equivalent . All the special characters will be escaped . The enclosing double quote characters are not added .
37
29
6,016
@ Pure public static String toJsonString ( String text ) { final StringEscaper escaper = new StringEscaper ( StringEscaper . JAVA_ESCAPE_CHAR , StringEscaper . JAVA_STRING_CHAR , StringEscaper . JAVA_ESCAPE_CHAR , StringEscaper . JSON_SPECIAL_ESCAPED_CHAR ) ; return escaper . escape ( text ) ; }
Translate the given string to its Json string equivalent . All the special characters will be escaped . The enclosing double quote characters are not added .
93
30
6,017
public static VariableDecls extend ( Binder binder ) { return new VariableDecls ( io . bootique . BQCoreModule . extend ( binder ) ) ; }
Create an extended from the given binder .
37
9
6,018
public VariableDecls declareVar ( String bootiqueVariable ) { this . extender . declareVar ( bootiqueVariable , VariableNames . toEnvironmentVariableName ( bootiqueVariable ) ) ; return this ; }
Declare an environment variable which is linked to the given Bootique variable and has its name defined from the name of the Bootique variable .
43
28
6,019
protected void initializeElements ( ) { final BusItinerary itinerary = getBusItinerary ( ) ; if ( itinerary != null ) { int i = 0 ; for ( final BusItineraryHalt halt : itinerary . busHalts ( ) ) { onBusItineraryHaltAdded ( halt , i , null ) ; ++ i ; } } }
Run the initialization of the elements from the current bus itinerary .
80
13
6,020
@ Pure @ SuppressWarnings ( "unchecked" ) protected static < VALUET > VALUET maskNull ( VALUET value ) { return ( value == null ) ? ( VALUET ) NULL_VALUE : value ; }
Mask the null values given by the used of this map .
52
12
6,021
@ Pure protected static < VALUET > VALUET unmaskNull ( VALUET value ) { return ( value == NULL_VALUE ) ? null : value ; }
Unmask the null values given by the used of this map .
36
13
6,022
@ SuppressWarnings ( "unchecked" ) static < T > T [ ] finishToArray ( T [ ] array , Iterator < ? > it ) { T [ ] rp = array ; int i = rp . length ; while ( it . hasNext ( ) ) { final int cap = rp . length ; if ( i == cap ) { int newCap = ( ( cap / 2 ) + 1 ) * 3 ; if ( newCap <= cap ) { // integer overflow if ( cap == Integer . MAX_VALUE ) { throw new OutOfMemoryError ( ) ; } newCap = Integer . MAX_VALUE ; } rp = Arrays . copyOf ( rp , newCap ) ; } rp [ ++ i ] = ( T ) it . next ( ) ; } // trim if overallocated return ( i == rp . length ) ? rp : Arrays . copyOf ( rp , i ) ; }
Reallocates the array being used within toArray when the iterator returned more elements than expected and finishes filling it from the iterator .
201
26
6,023
protected final ReferencableValue < K , V > makeValue ( K key , V value ) { return makeValue ( key , value , this . queue ) ; }
Create a storage object that permits to put the specified elements inside this map .
36
15
6,024
@ Pure public static String getFirstFreeBusItineraryName ( BusLine busline ) { if ( busline == null ) { return null ; } int nb = busline . getBusItineraryCount ( ) ; String name ; do { ++ nb ; name = Locale . getString ( "NAME_TEMPLATE" , Integer . toString ( nb ) ) ; //$NON-NLS-1$ } while ( busline . getBusItinerary ( name ) != null ) ; return name ; }
Replies a bus itinerary name that was not exist in the specified bus line .
116
17
6,025
public void invert ( ) { final boolean isEventFirable = isEventFirable ( ) ; setEventFirable ( false ) ; try { final int count = this . roadSegments . getRoadSegmentCount ( ) ; // Invert the segments this . roadSegments . invert ( ) ; // Invert the bus halts and their indexes. final int middle = this . validHalts . size ( ) / 2 ; for ( int i = 0 , j = this . validHalts . size ( ) - 1 ; i < middle ; ++ i , -- j ) { final BusItineraryHalt h1 = this . validHalts . get ( i ) ; final BusItineraryHalt h2 = this . validHalts . get ( j ) ; this . validHalts . set ( i , h2 ) ; this . validHalts . set ( j , h1 ) ; int idx = h1 . getRoadSegmentIndex ( ) ; idx = count - idx - 1 ; h1 . setRoadSegmentIndex ( idx ) ; idx = h2 . getRoadSegmentIndex ( ) ; idx = count - idx - 1 ; h2 . setRoadSegmentIndex ( idx ) ; } if ( middle * 2 != this . validHalts . size ( ) ) { final BusItineraryHalt h1 = this . validHalts . get ( middle ) ; int idx = h1 . getRoadSegmentIndex ( ) ; idx = count - idx - 1 ; h1 . setRoadSegmentIndex ( idx ) ; } } finally { setEventFirable ( isEventFirable ) ; } fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . ITINERARY_INVERTED , this , indexInParent ( ) , "busHalts" , //$NON-NLS-1$ null , null ) ) ; }
Invert the order of this itinerary .
418
9
6,026
@ Pure public boolean hasBusHaltOnSegment ( RoadSegment segment ) { if ( this . roadSegments . isEmpty ( ) || this . validHalts . isEmpty ( ) ) { return false ; } int cIdxSegment ; int lIdxSegment = - 1 ; RoadSegment cSegment ; for ( final BusItineraryHalt bushalt : this . validHalts ) { cIdxSegment = bushalt . getRoadSegmentIndex ( ) ; if ( cIdxSegment >= 0 && cIdxSegment < this . roadSegments . getRoadSegmentCount ( ) && cIdxSegment != lIdxSegment ) { cSegment = this . roadSegments . getRoadSegmentAt ( cIdxSegment ) ; lIdxSegment = cIdxSegment ; if ( segment == cSegment ) { return true ; } } } return false ; }
Replies if the given segment has a bus halt on it .
204
13
6,027
@ Pure public List < BusItineraryHalt > getBusHaltsOnSegment ( RoadSegment segment ) { if ( this . roadSegments . isEmpty ( ) || this . validHalts . isEmpty ( ) ) { return Collections . emptyList ( ) ; } int cIdxSegment ; int lIdxSegment = - 1 ; int sIdxSegment = - 1 ; RoadSegment cSegment ; final List < BusItineraryHalt > halts = new ArrayList <> ( ) ; for ( final BusItineraryHalt bushalt : this . validHalts ) { cIdxSegment = bushalt . getRoadSegmentIndex ( ) ; if ( cIdxSegment >= 0 && cIdxSegment < this . roadSegments . getRoadSegmentCount ( ) && cIdxSegment != lIdxSegment ) { cSegment = this . roadSegments . getRoadSegmentAt ( cIdxSegment ) ; lIdxSegment = cIdxSegment ; if ( segment == cSegment ) { sIdxSegment = cIdxSegment ; } else if ( sIdxSegment != - 1 ) { // halt loop now because I'm sure there has no more bus halt break ; } } if ( sIdxSegment != - 1 ) { halts . add ( bushalt ) ; } } return halts ; }
Replies the bus halts on the given segment .
310
11
6,028
@ Pure public Map < BusItineraryHalt , Pair < Integer , Double > > getBusHaltBinding ( ) { final Comparator < BusItineraryHalt > comp = ( elt1 , elt2 ) -> { if ( elt1 == elt2 ) { return 0 ; } if ( elt1 == null ) { return - 1 ; } if ( elt2 == null ) { return 1 ; } return elt1 . getName ( ) . compareTo ( elt2 . getName ( ) ) ; } ; final Map < BusItineraryHalt , Pair < Integer , Double > > haltBinding = new TreeMap <> ( comp ) ; for ( final BusItineraryHalt halt : busHalts ( ) ) { haltBinding . put ( halt , new Pair <> ( halt . getRoadSegmentIndex ( ) , halt . getPositionOnSegment ( ) ) ) ; } return haltBinding ; }
Replies the binding informations for all the bus halts of this itinerary .
209
17
6,029
public void setBusHaltBinding ( Map < BusItineraryHalt , Pair < Integer , Float > > binding ) { if ( binding != null ) { BusItineraryHalt halt ; boolean shapeChanged = false ; for ( final Entry < BusItineraryHalt , Pair < Integer , Float > > entry : binding . entrySet ( ) ) { halt = entry . getKey ( ) ; halt . setRoadSegmentIndex ( entry . getValue ( ) . getKey ( ) ) ; halt . setPositionOnSegment ( entry . getValue ( ) . getValue ( ) ) ; halt . checkPrimitiveValidity ( ) ; shapeChanged = true ; } if ( shapeChanged ) { fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . ITINERARY_CHANGED , null , - 1 , "shape" , //$NON-NLS-1$ null , null ) ) ; } checkPrimitiveValidity ( ) ; } }
Set the binding informations for all the bus halts of this itinerary .
212
16
6,030
@ Pure public double getLength ( ) { double length = this . roadSegments . getLength ( ) ; if ( isValidPrimitive ( ) ) { BusItineraryHalt halt = this . validHalts . get ( 0 ) ; assert halt != null ; RoadSegment sgmt = halt . getRoadSegment ( ) ; assert sgmt != null ; Direction1D dir = this . roadSegments . getRoadSegmentDirectionAt ( halt . getRoadSegmentIndex ( ) ) ; assert dir != null ; if ( dir == Direction1D . SEGMENT_DIRECTION ) { length -= halt . getPositionOnSegment ( ) ; } else { length -= sgmt . getLength ( ) - halt . getPositionOnSegment ( ) ; } halt = this . validHalts . get ( this . validHalts . size ( ) - 1 ) ; assert halt != null ; sgmt = halt . getRoadSegment ( ) ; assert sgmt != null ; dir = this . roadSegments . getRoadSegmentDirectionAt ( halt . getRoadSegmentIndex ( ) ) ; assert dir != null ; if ( dir == Direction1D . SEGMENT_DIRECTION ) { length -= sgmt . getLength ( ) - halt . getPositionOnSegment ( ) ; } else { length -= halt . getPositionOnSegment ( ) ; } if ( length < 0. ) { length = 0. ; } } return length ; }
Replies the length of this itinerary .
322
9
6,031
@ Pure public double getDistanceBetweenBusHalts ( int firsthaltIndex , int lasthaltIndex ) { if ( firsthaltIndex < 0 || firsthaltIndex >= this . validHalts . size ( ) - 1 ) { throw new ArrayIndexOutOfBoundsException ( firsthaltIndex ) ; } if ( lasthaltIndex <= firsthaltIndex || lasthaltIndex >= this . validHalts . size ( ) ) { throw new ArrayIndexOutOfBoundsException ( lasthaltIndex ) ; } double length = 0 ; final BusItineraryHalt b1 = this . validHalts . get ( firsthaltIndex ) ; final BusItineraryHalt b2 = this . validHalts . get ( lasthaltIndex ) ; final int firstSegment = b1 . getRoadSegmentIndex ( ) ; final int lastSegment = b2 . getRoadSegmentIndex ( ) ; for ( int i = firstSegment + 1 ; i < lastSegment ; ++ i ) { final RoadSegment segment = this . roadSegments . getRoadSegmentAt ( i ) ; length += segment . getLength ( ) ; } Direction1D direction = getRoadSegmentDirection ( firstSegment ) ; if ( direction . isRevertedSegmentDirection ( ) ) { length += b1 . getPositionOnSegment ( ) ; } else { length += this . roadSegments . getRoadSegmentAt ( firstSegment ) . getLength ( ) - b1 . getPositionOnSegment ( ) ; } direction = getRoadSegmentDirection ( lastSegment ) ; if ( direction . isSegmentDirection ( ) ) { length += b2 . getPositionOnSegment ( ) ; } else { length += this . roadSegments . getRoadSegmentAt ( firstSegment ) . getLength ( ) - b2 . getPositionOnSegment ( ) ; } return length ; }
Replies the distance between two bus halt .
420
9
6,032
boolean addBusHalt ( BusItineraryHalt halt , int insertToIndex ) { //set index for right ordering when add to invalid list ! if ( insertToIndex < 0 ) { halt . setInvalidListIndex ( this . insertionIndex ) ; } else { halt . setInvalidListIndex ( insertToIndex ) ; } if ( halt . isValidPrimitive ( ) ) { ListUtil . addIfAbsent ( this . validHalts , VALID_HALT_COMPARATOR , halt ) ; } else { ListUtil . addIfAbsent ( this . invalidHalts , INVALID_HALT_COMPARATOR , halt ) ; } halt . setEventFirable ( isEventFirable ( ) ) ; ++ this . insertionIndex ; if ( isEventFirable ( ) ) { fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . ITINERARY_HALT_ADDED , halt , halt . indexInParent ( ) , "shape" , null , null ) ) ; //$NON-NLS-1$ checkPrimitiveValidity ( ) ; } return true ; }
Add the given bus halt in this itinerary .
245
10
6,033
public void removeAllBusHalts ( ) { for ( final BusItineraryHalt bushalt : this . invalidHalts ) { bushalt . setContainer ( null ) ; bushalt . setRoadSegmentIndex ( - 1 ) ; bushalt . setPositionOnSegment ( Float . NaN ) ; bushalt . checkPrimitiveValidity ( ) ; } final BusItineraryHalt [ ] halts = new BusItineraryHalt [ this . validHalts . size ( ) ] ; this . validHalts . toArray ( halts ) ; this . validHalts . clear ( ) ; this . invalidHalts . clear ( ) ; for ( final BusItineraryHalt bushalt : halts ) { bushalt . setContainer ( null ) ; bushalt . setRoadSegmentIndex ( - 1 ) ; bushalt . setPositionOnSegment ( Float . NaN ) ; bushalt . checkPrimitiveValidity ( ) ; } fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . ALL_ITINERARY_HALTS_REMOVED , null , - 1 , "shape" , //$NON-NLS-1$ null , null ) ) ; checkPrimitiveValidity ( ) ; }
Remove all the bus halts from the current itinerary .
272
12
6,034
public boolean removeBusHalt ( BusItineraryHalt bushalt ) { try { int index = ListUtil . indexOf ( this . validHalts , VALID_HALT_COMPARATOR , bushalt ) ; if ( index >= 0 ) { return removeBusHalt ( index ) ; } index = ListUtil . indexOf ( this . invalidHalts , INVALID_HALT_COMPARATOR , bushalt ) ; if ( index >= 0 ) { index += this . validHalts . size ( ) ; return removeBusHalt ( index ) ; } } catch ( Throwable exception ) { // } return false ; }
Remove a bus bus from this itinerary .
139
9
6,035
public boolean removeBusHalt ( String name ) { Iterator < BusItineraryHalt > iterator = this . validHalts . iterator ( ) ; BusItineraryHalt bushalt ; int i = 0 ; while ( iterator . hasNext ( ) ) { bushalt = iterator . next ( ) ; if ( name . equals ( bushalt . getName ( ) ) ) { return removeBusHalt ( i ) ; } ++ i ; } iterator = this . invalidHalts . iterator ( ) ; i = 0 ; while ( iterator . hasNext ( ) ) { bushalt = iterator . next ( ) ; if ( name . equals ( bushalt . getName ( ) ) ) { return removeBusHalt ( i ) ; } ++ i ; } return false ; }
Remove the bus halt with the given name .
165
9
6,036
public boolean removeBusHalt ( int index ) { try { final BusItineraryHalt removedBushalt ; if ( index < this . validHalts . size ( ) ) { removedBushalt = this . validHalts . remove ( index ) ; } else { final int idx = index - this . validHalts . size ( ) ; removedBushalt = this . invalidHalts . remove ( idx ) ; } removedBushalt . setContainer ( null ) ; removedBushalt . setRoadSegmentIndex ( - 1 ) ; removedBushalt . setPositionOnSegment ( Float . NaN ) ; removedBushalt . setEventFirable ( true ) ; removedBushalt . checkPrimitiveValidity ( ) ; fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . ITINERARY_HALT_REMOVED , removedBushalt , removedBushalt . indexInParent ( ) , "shape" , //$NON-NLS-1$ null , null ) ) ; checkPrimitiveValidity ( ) ; return true ; } catch ( Throwable exception ) { // } return false ; }
Remove the bus halt at the specified index .
242
9
6,037
@ Pure public int indexOf ( BusItineraryHalt bushalt ) { if ( bushalt == null ) { return - 1 ; } if ( bushalt . isValidPrimitive ( ) ) { return ListUtil . indexOf ( this . validHalts , VALID_HALT_COMPARATOR , bushalt ) ; } int idx = ListUtil . indexOf ( this . invalidHalts , INVALID_HALT_COMPARATOR , bushalt ) ; if ( idx >= 0 ) { idx += this . validHalts . size ( ) ; } return idx ; }
Replies the index of the specified bus halt .
131
10
6,038
@ Pure public boolean contains ( BusItineraryHalt bushalt ) { if ( bushalt == null ) { return false ; } if ( bushalt . isValidPrimitive ( ) ) { return ListUtil . contains ( this . validHalts , VALID_HALT_COMPARATOR , bushalt ) ; } return ListUtil . contains ( this . invalidHalts , INVALID_HALT_COMPARATOR , bushalt ) ; }
Replies if the given bus halt is inside this bus itinerary .
98
14
6,039
@ Pure public BusItineraryHalt getBusHaltAt ( int index ) { if ( index < this . validHalts . size ( ) ) { return this . validHalts . get ( index ) ; } return this . invalidHalts . get ( index - this . validHalts . size ( ) ) ; }
Replies the halt at the specified index .
70
9
6,040
@ Pure public BusItineraryHalt getBusHalt ( UUID uuid ) { if ( uuid == null ) { return null ; } for ( final BusItineraryHalt busHalt : this . validHalts ) { if ( uuid . equals ( busHalt . getUUID ( ) ) ) { return busHalt ; } } for ( final BusItineraryHalt busHalt : this . invalidHalts ) { if ( uuid . equals ( busHalt . getUUID ( ) ) ) { return busHalt ; } } return null ; }
Replies the bus halt with the specified uuid .
128
11
6,041
@ Pure public BusItineraryHalt getBusHalt ( String name , Comparator < String > nameComparator ) { if ( name == null ) { return null ; } final Comparator < String > cmp = nameComparator == null ? BusNetworkUtilities . NAME_COMPARATOR : nameComparator ; for ( final BusItineraryHalt bushalt : this . validHalts ) { if ( cmp . compare ( name , bushalt . getName ( ) ) == 0 ) { return bushalt ; } } for ( final BusItineraryHalt bushalt : this . invalidHalts ) { if ( cmp . compare ( name , bushalt . getName ( ) ) == 0 ) { return bushalt ; } } return null ; }
Replies the bus halt with the specified name .
164
10
6,042
@ Pure public BusItineraryHalt [ ] toBusHaltArray ( ) { final BusItineraryHalt [ ] tab = new BusItineraryHalt [ this . validHalts . size ( ) + this . invalidHalts . size ( ) ] ; int i = 0 ; for ( final BusItineraryHalt h : this . validHalts ) { tab [ i ] = h ; ++ i ; } for ( final BusItineraryHalt h : this . invalidHalts ) { tab [ i ] = h ; ++ i ; } return tab ; }
Replies an array of the bus halts inside this itinerary . This function copy the internal data structures into the array .
126
25
6,043
@ Pure public BusItineraryHalt [ ] toInvalidBusHaltArray ( ) { final BusItineraryHalt [ ] tab = new BusItineraryHalt [ this . invalidHalts . size ( ) ] ; return this . invalidHalts . toArray ( tab ) ; }
Replies an array of the invalid bus halts inside this itinerary . This function copy the internal data structures into the array .
64
26
6,044
@ Pure public BusItineraryHalt [ ] toValidBusHaltArray ( ) { final BusItineraryHalt [ ] tab = new BusItineraryHalt [ this . validHalts . size ( ) ] ; return this . validHalts . toArray ( tab ) ; }
Replies an array of the valid bus halts inside this itinerary . This function copy the internal data structures into the array .
64
26
6,045
@ Pure public RoadSegment getNearestRoadSegment ( Point2D < ? , ? > point ) { assert point != null ; double distance = Double . MAX_VALUE ; RoadSegment nearestSegment = null ; final Iterator < RoadSegment > iterator = this . roadSegments . roadSegments ( ) ; RoadSegment segment ; while ( iterator . hasNext ( ) ) { segment = iterator . next ( ) ; final double d = segment . distance ( point ) ; if ( d < distance ) { distance = d ; nearestSegment = segment ; } } return nearestSegment ; }
Replies the nearest road segment from this itinerary to the given point .
128
15
6,046
public boolean addRoadSegments ( RoadPath segments , boolean autoConnectHalts , boolean enableLoopAutoBuild ) { if ( segments == null || segments . isEmpty ( ) ) { return false ; } BusItineraryHalt halt ; RoadSegment sgmt ; final Map < BusItineraryHalt , RoadSegment > haltMapping = new TreeMap <> ( ( obj1 , obj2 ) -> Integer . compare ( System . identityHashCode ( obj1 ) , System . identityHashCode ( obj2 ) ) ) ; final Iterator < BusItineraryHalt > haltIterator = this . validHalts . iterator ( ) ; while ( haltIterator . hasNext ( ) ) { halt = haltIterator . next ( ) ; sgmt = this . roadSegments . getRoadSegmentAt ( halt . getRoadSegmentIndex ( ) ) ; haltMapping . put ( halt , sgmt ) ; } final boolean isValidBefore = isValidPrimitive ( ) ; final RoadPath changedPath = this . roadSegments . addAndGetPath ( segments ) ; if ( changedPath != null ) { if ( enableLoopAutoBuild ) { autoLoop ( isValidBefore , changedPath , segments ) ; } int nIdx ; for ( final Entry < BusItineraryHalt , RoadSegment > entry : haltMapping . entrySet ( ) ) { halt = entry . getKey ( ) ; sgmt = entry . getValue ( ) ; nIdx = this . roadSegments . indexOf ( sgmt ) ; halt . setRoadSegmentIndex ( nIdx ) ; halt . checkPrimitiveValidity ( ) ; } final BusItineraryHalt [ ] tabV = new BusItineraryHalt [ this . validHalts . size ( ) ] ; this . validHalts . toArray ( tabV ) ; this . validHalts . clear ( ) ; for ( final BusItineraryHalt busHalt : tabV ) { assert busHalt != null && busHalt . isValidPrimitive ( ) ; ListUtil . addIfAbsent ( this . validHalts , VALID_HALT_COMPARATOR , busHalt ) ; } if ( this . roadNetwork == null ) { final RoadNetwork network = segments . getFirstSegment ( ) . getRoadNetwork ( ) ; this . roadNetwork = new WeakReference <> ( network ) ; network . addRoadNetworkListener ( this ) ; } fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . SEGMENT_ADDED , segments . getLastSegment ( ) , this . roadSegments . indexOf ( segments . getLastSegment ( ) ) , "shape" , //$NON-NLS-1$ null , null ) ) ; // Try to connect the itinerary halts to // the road segments if ( autoConnectHalts ) { putInvalidHaltsOnRoads ( ) ; } else { checkPrimitiveValidity ( ) ; } return true ; } return false ; }
Add road segments inside the bus itinerary .
656
9
6,047
@ SuppressWarnings ( "checkstyle:nestedifdepth" ) public boolean putHaltOnRoad ( BusItineraryHalt halt , RoadSegment road ) { if ( contains ( halt ) ) { final BusStop stop = halt . getBusStop ( ) ; if ( stop != null ) { final Point2d stopPosition = stop . getPosition2D ( ) ; if ( stopPosition != null ) { final int idx = indexOf ( road ) ; if ( idx >= 0 ) { final Point1d pos = road . getNearestPosition ( stopPosition ) ; if ( pos != null ) { halt . setRoadSegmentIndex ( idx ) ; halt . setPositionOnSegment ( pos . getCurvilineCoordinate ( ) ) ; halt . checkPrimitiveValidity ( ) ; fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . ITINERARY_CHANGED , null , - 1 , "shape" , //$NON-NLS-1$ null , null ) ) ; checkPrimitiveValidity ( ) ; return true ; } } return false ; } } } return true ; }
Put the given bus itinerary halt on the nearest point on road .
249
14
6,048
public void removeAllRoadSegments ( ) { for ( final BusItineraryHalt halt : this . invalidHalts ) { halt . setRoadSegmentIndex ( - 1 ) ; halt . setPositionOnSegment ( Float . NaN ) ; halt . checkPrimitiveValidity ( ) ; } final BusItineraryHalt [ ] halts = new BusItineraryHalt [ this . validHalts . size ( ) ] ; this . validHalts . toArray ( halts ) ; for ( final BusItineraryHalt halt : halts ) { halt . setRoadSegmentIndex ( - 1 ) ; halt . setPositionOnSegment ( Float . NaN ) ; halt . checkPrimitiveValidity ( ) ; } if ( this . roadNetwork != null ) { final RoadNetwork network = this . roadNetwork . get ( ) ; if ( network != null ) { network . removeRoadNetworkListener ( this ) ; } this . roadNetwork = null ; } this . roadSegments . clear ( ) ; fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . ALL_SEGMENTS_REMOVED , null , - 1 , "shape" , //$NON-NLS-1$ null , null ) ) ; checkPrimitiveValidity ( ) ; }
Remove all the road segments from the current itinerary .
281
11
6,049
public boolean removeRoadSegment ( int segmentIndex ) { if ( segmentIndex >= 0 && segmentIndex < this . roadSegments . getRoadSegmentCount ( ) ) { final RoadSegment segment = this . roadSegments . getRoadSegmentAt ( segmentIndex ) ; if ( segment != null ) { // // Invalidate the bus halts on the segment // final Map < BusItineraryHalt , RoadSegment > segmentMap = new TreeMap <> ( ( obj1 , obj2 ) -> Integer . compare ( System . identityHashCode ( obj1 ) , System . identityHashCode ( obj2 ) ) ) ; final Iterator < BusItineraryHalt > haltIterator = this . validHalts . iterator ( ) ; while ( haltIterator . hasNext ( ) ) { final BusItineraryHalt halt = haltIterator . next ( ) ; final int sgmtIndex = halt . getRoadSegmentIndex ( ) ; if ( sgmtIndex == segmentIndex ) { segmentMap . put ( halt , null ) ; } else { final RoadSegment sgmt = this . roadSegments . getRoadSegmentAt ( sgmtIndex ) ; segmentMap . put ( halt , sgmt ) ; } } // // Remove the road segment itself on the segment // this . roadSegments . removeRoadSegmentAt ( segmentIndex ) ; // // Force the road segment indexes // for ( final Entry < BusItineraryHalt , RoadSegment > entry : segmentMap . entrySet ( ) ) { final BusItineraryHalt halt = entry . getKey ( ) ; final RoadSegment sgmt = entry . getValue ( ) ; if ( sgmt == null ) { halt . setRoadSegmentIndex ( - 1 ) ; halt . setPositionOnSegment ( Float . NaN ) ; halt . checkPrimitiveValidity ( ) ; } else { final int sgmtIndex = halt . getRoadSegmentIndex ( ) ; final int idx = this . roadSegments . indexOf ( sgmt ) ; if ( idx != sgmtIndex ) { halt . setRoadSegmentIndex ( idx ) ; halt . checkPrimitiveValidity ( ) ; } } } // // Change the road network reference // if ( this . roadSegments . isEmpty ( ) && this . roadNetwork != null ) { final RoadNetwork network = this . roadNetwork . get ( ) ; if ( network != null ) { network . removeRoadNetworkListener ( this ) ; } this . roadNetwork = null ; } fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . SEGMENT_REMOVED , segment , segmentIndex , "shape" , //$NON-NLS-1$ null , null ) ) ; checkPrimitiveValidity ( ) ; return true ; } } return false ; }
Remove a road segment from this itinerary .
615
9
6,050
@ Pure public Iterable < RoadSegment > roadSegments ( ) { return new Iterable < RoadSegment > ( ) { @ Override public Iterator < RoadSegment > iterator ( ) { return roadSegmentsIterator ( ) ; } } ; }
Replies the list of the road segments of the bus itinerary .
55
14
6,051
@ SuppressWarnings ( "unchecked" ) /** * Creates an aligner given a single function from items to equivalence classes (requires left * and right items to both be of types compatible with this function). */ public static < InT , EqClass > EquivalenceBasedProvenancedAligner < InT , InT , EqClass > forEquivalenceFunction ( Function < ? super InT , ? extends EqClass > equivalenceFunction ) { return new EquivalenceBasedProvenancedAligner < InT , InT , EqClass > ( ( Function < InT , EqClass > ) equivalenceFunction , ( Function < InT , EqClass > ) equivalenceFunction ) ; }
we don t need
158
4
6,052
@ Pure public static String getExecutableFilename ( String name ) { if ( OperatingSystem . WIN . isCurrentOS ( ) ) { return name + ".exe" ; //$NON-NLS-1$ } return name ; }
Replies a binary executable filename depending of the current platform .
50
12
6,053
@ Pure public static String getVMBinary ( ) { final String javaHome = System . getProperty ( "java.home" ) ; //$NON-NLS-1$ final File binDir = new File ( new File ( javaHome ) , "bin" ) ; //$NON-NLS-1$ if ( binDir . isDirectory ( ) ) { File exec = new File ( binDir , getExecutableFilename ( "javaw" ) ) ; //$NON-NLS-1$ if ( exec . isFile ( ) ) { return exec . getAbsolutePath ( ) ; } exec = new File ( binDir , getExecutableFilename ( "java" ) ) ; //$NON-NLS-1$ if ( exec . isFile ( ) ) { return exec . getAbsolutePath ( ) ; } } return null ; }
Replies the current java VM binary .
188
8
6,054
@ SuppressWarnings ( "checkstyle:magicnumber" ) public static Process launchVMWithJar ( File jarFile , String ... additionalParams ) throws IOException { final String javaBin = getVMBinary ( ) ; if ( javaBin == null ) { throw new FileNotFoundException ( "java" ) ; //$NON-NLS-1$ } final long totalMemory = Runtime . getRuntime ( ) . maxMemory ( ) / 1024 ; final String userDir = FileSystem . getUserHomeDirectoryName ( ) ; final int nParams = 4 ; final String [ ] params = new String [ additionalParams . length + nParams ] ; params [ 0 ] = javaBin ; params [ 1 ] = "-Xmx" + totalMemory + "k" ; //$NON-NLS-1$ //$NON-NLS-2$ params [ 2 ] = "-jar" ; //$NON-NLS-1$ params [ 3 ] = jarFile . getAbsolutePath ( ) ; System . arraycopy ( additionalParams , 0 , params , nParams , additionalParams . length ) ; return Runtime . getRuntime ( ) . exec ( params , null , new File ( userDir ) ) ; }
Run a jar file inside a new VM .
272
9
6,055
@ Pure @ SuppressWarnings ( { "checkstyle:cyclomaticcomplexity" , "checkstyle:npathcomplexity" } ) public static String [ ] getAllCommandLineParameters ( ) { final int osize = commandLineOptions == null ? 0 : commandLineOptions . size ( ) ; final int psize = commandLineParameters == null ? 0 : commandLineParameters . length ; final int tsize = ( osize > 0 && psize > 0 ) ? 1 : 0 ; final List < String > params = new ArrayList <> ( osize + tsize ) ; if ( osize > 0 ) { List < Object > values ; String name ; String prefix ; String v ; for ( final Entry < String , List < Object > > entry : commandLineOptions . entrySet ( ) ) { name = entry . getKey ( ) ; prefix = ( name . length ( ) > 1 ) ? "--" : "-" ; //$NON-NLS-1$ //$NON-NLS-2$ values = entry . getValue ( ) ; if ( values == null || values . isEmpty ( ) ) { params . add ( prefix + name ) ; } else { for ( final Object value : values ) { if ( value != null ) { v = value . toString ( ) ; if ( v != null && v . length ( ) > 0 ) { params . add ( prefix + name + "=" + v ) ; //$NON-NLS-1$ } else { params . add ( prefix + name ) ; } } } } } } if ( tsize > 0 ) { params . add ( "--" ) ; //$NON-NLS-1$ } final String [ ] tab = new String [ params . size ( ) + psize ] ; params . toArray ( tab ) ; params . clear ( ) ; if ( psize > 0 ) { System . arraycopy ( commandLineParameters , 0 , tab , osize + tsize , psize ) ; } return tab ; }
Replies the command line including the options and the standard parameters .
434
13
6,056
public static String shiftCommandLineParameters ( ) { String removed = null ; if ( commandLineParameters != null ) { if ( commandLineParameters . length == 0 ) { commandLineParameters = null ; } else if ( commandLineParameters . length == 1 ) { removed = commandLineParameters [ 0 ] ; commandLineParameters = null ; } else { removed = commandLineParameters [ 0 ] ; final String [ ] newTab = new String [ commandLineParameters . length - 1 ] ; System . arraycopy ( commandLineParameters , 1 , newTab , 0 , commandLineParameters . length - 1 ) ; commandLineParameters = newTab ; } } return removed ; }
Shift the command line parameters by one on the left . The first parameter is removed from the list .
138
20
6,057
@ Pure public static Map < String , List < Object > > getCommandLineOptions ( ) { if ( commandLineOptions != null ) { return Collections . unmodifiableSortedMap ( commandLineOptions ) ; } return Collections . emptyMap ( ) ; }
Replies the command line options .
54
7
6,058
@ Pure public static List < Object > getCommandLineOption ( String name ) { if ( commandLineOptions != null && commandLineOptions . containsKey ( name ) ) { final List < Object > value = commandLineOptions . get ( name ) ; return value == null ? Collections . emptyList ( ) : value ; } return Collections . emptyList ( ) ; }
Replies one command option .
76
6
6,059
@ Pure @ SuppressWarnings ( "static-method" ) public Object getFirstOptionValue ( String optionLabel ) { final List < Object > options = getCommandLineOption ( optionLabel ) ; if ( options == null || options . isEmpty ( ) ) { return null ; } return options . get ( 0 ) ; }
Replies the first value of the option .
70
9
6,060
@ Pure @ SuppressWarnings ( "static-method" ) public List < Object > getOptionValues ( String optionLabel ) { final List < Object > options = getCommandLineOption ( optionLabel ) ; if ( options == null ) { return Collections . emptyList ( ) ; } return Collections . unmodifiableList ( options ) ; }
Replies the values of the option .
73
8
6,061
@ Pure @ SuppressWarnings ( "static-method" ) public boolean isParameterExists ( int index ) { final String [ ] params = getCommandLineParameters ( ) ; return index >= 0 && index < params . length && params [ index ] != null ; }
Replies if the given index corresponds to a command line parameter .
58
13
6,062
private int firstInGroup ( int groupIndex ) { if ( this . pointCoordinates == null ) { throw new IndexOutOfBoundsException ( ) ; } final int count = getGroupCount ( ) ; if ( groupIndex < 0 ) { throw new IndexOutOfBoundsException ( groupIndex + "<0" ) ; //$NON-NLS-1$ } if ( groupIndex >= count ) { throw new IndexOutOfBoundsException ( groupIndex + ">=" + count ) ; //$NON-NLS-1$ } final int g = groupIndex - 1 ; if ( g >= 0 && this . partIndexes != null && g < this . partIndexes . length ) { return this . partIndexes [ g ] ; } return 0 ; }
Replies the starting index of a point in a group .
168
12
6,063
private int lastInGroup ( int groupIndex ) { if ( this . pointCoordinates == null ) { throw new IndexOutOfBoundsException ( ) ; } final int count = getGroupCount ( ) ; if ( groupIndex < 0 ) { throw new IndexOutOfBoundsException ( groupIndex + "<0" ) ; //$NON-NLS-1$ } if ( groupIndex >= count ) { throw new IndexOutOfBoundsException ( groupIndex + ">=" + count ) ; //$NON-NLS-1$ } if ( this . partIndexes != null && groupIndex < this . partIndexes . length ) { return this . partIndexes [ groupIndex ] - 2 ; } return this . pointCoordinates . length - 2 ; }
Replies the ending index of a point in a group .
168
12
6,064
private int groupIndexForPoint ( int pointIndex ) { if ( this . pointCoordinates == null || pointIndex < 0 || pointIndex >= this . pointCoordinates . length ) { throw new IndexOutOfBoundsException ( ) ; } if ( this . partIndexes == null ) { return 0 ; } for ( int i = 0 ; i < this . partIndexes . length ; ++ i ) { if ( pointIndex < this . partIndexes [ i ] ) { return i ; } } return this . partIndexes . length ; }
Replies the group index inside which the point is located at the specified index .
119
16
6,065
@ Pure public int getPointCountInGroup ( int groupIndex ) { if ( groupIndex == 0 && this . pointCoordinates == null ) { return 0 ; } final int firstInGroup = firstInGroup ( groupIndex ) ; final int lastInGroup = lastInGroup ( groupIndex ) ; return ( lastInGroup - firstInGroup ) / 2 + 1 ; }
Replies the count of points in the specified group .
80
11
6,066
@ Pure public int getPointIndex ( int groupIndex , int position ) { final int groupMemberCount = getPointCountInGroup ( groupIndex ) ; final int pos ; if ( position < 0 ) { pos = 0 ; } else if ( position >= groupMemberCount ) { pos = groupMemberCount - 1 ; } else { pos = position ; } // Move the start/end indexes to corresponds to the bounds of the new points return ( firstInGroup ( groupIndex ) + pos * 2 ) / 2 ; }
Replies the global index of the point that corresponds to the position in the given group .
108
18
6,067
@ Pure public int getPointIndex ( int groupIndex , Point2D < ? , ? > point2d ) { if ( ! this . containsPoint ( point2d , groupIndex ) ) { return - 1 ; } Point2d cur = null ; int pos = - 1 ; for ( int i = 0 ; i < getPointCountInGroup ( groupIndex ) ; ++ i ) { cur = getPointAt ( groupIndex , i ) ; if ( cur . epsilonEquals ( point2d , MapElementConstants . POINT_FUSION_DISTANCE ) ) { pos = i ; break ; } } return ( firstInGroup ( groupIndex ) + pos * 2 ) / 2 ; }
Replies the global index of the point2d in the given group .
153
15
6,068
@ Pure public PointGroup getGroupAt ( int index ) { final int count = getGroupCount ( ) ; if ( index < 0 ) { throw new IndexOutOfBoundsException ( index + "<0" ) ; //$NON-NLS-1$ } if ( index >= count ) { throw new IndexOutOfBoundsException ( index + ">=" + count ) ; //$NON-NLS-1$ } return new PointGroup ( index ) ; }
Replies the part at the specified index .
102
9
6,069
@ Pure public Iterable < PointGroup > groups ( ) { return new Iterable < PointGroup > ( ) { @ Override public Iterator < PointGroup > iterator ( ) { return MapComposedElement . this . groupIterator ( ) ; } } ; }
Replies the iterator on the groups .
55
8
6,070
@ Pure public Iterable < Point2d > points ( ) { return new Iterable < Point2d > ( ) { @ Override public Iterator < Point2d > iterator ( ) { return MapComposedElement . this . pointIterator ( ) ; } } ; }
Replies the iterator on the points .
58
8
6,071
public int addPoint ( double x , double y ) { int pointIndex ; if ( this . pointCoordinates == null ) { this . pointCoordinates = new double [ ] { x , y } ; this . partIndexes = null ; pointIndex = 0 ; } else { double [ ] pts = new double [ this . pointCoordinates . length + 2 ] ; System . arraycopy ( this . pointCoordinates , 0 , pts , 0 , this . pointCoordinates . length ) ; pointIndex = pts . length - 2 ; pts [ pointIndex ] = x ; pts [ pointIndex + 1 ] = y ; this . pointCoordinates = pts ; pts = null ; pointIndex /= 2 ; } fireShapeChanged ( ) ; fireElementChanged ( ) ; return pointIndex ; }
Add the specified point at the end of the last group .
173
12
6,072
public int addGroup ( double x , double y ) { int pointIndex ; if ( this . pointCoordinates == null ) { this . pointCoordinates = new double [ ] { x , y } ; this . partIndexes = null ; pointIndex = 0 ; } else { double [ ] pts = new double [ this . pointCoordinates . length + 2 ] ; System . arraycopy ( this . pointCoordinates , 0 , pts , 0 , this . pointCoordinates . length ) ; pointIndex = pts . length - 2 ; pts [ pointIndex ] = x ; pts [ pointIndex + 1 ] = y ; final int groupCount = getGroupCount ( ) ; int [ ] grps = new int [ groupCount ] ; if ( this . partIndexes != null ) { System . arraycopy ( this . partIndexes , 0 , grps , 0 , groupCount - 1 ) ; } grps [ groupCount - 1 ] = pointIndex ; this . pointCoordinates = pts ; pts = null ; this . partIndexes = grps ; grps = null ; pointIndex /= 2 ; } fireShapeChanged ( ) ; fireElementChanged ( ) ; return pointIndex ; }
Add the specified point into a newgroup .
259
9
6,073
public MapComposedElement invertPointsIn ( int groupIndex ) { if ( this . pointCoordinates == null ) { throw new IndexOutOfBoundsException ( ) ; } final int grpCount = getGroupCount ( ) ; if ( groupIndex < 0 ) { throw new IndexOutOfBoundsException ( groupIndex + "<0" ) ; //$NON-NLS-1$ } if ( groupIndex > grpCount ) { throw new IndexOutOfBoundsException ( groupIndex + ">" + grpCount ) ; //$NON-NLS-1$ } final int count = this . getPointCountInGroup ( groupIndex ) ; final int first = firstInGroup ( groupIndex ) ; double [ ] tmp = new double [ count * 2 ] ; for ( int i = 0 ; i < count * 2 ; i += 2 ) { tmp [ i ] = this . pointCoordinates [ first + 2 * count - 1 - ( i + 1 ) ] ; tmp [ i + 1 ] = this . pointCoordinates [ first + 2 * count - 1 - i ] ; } System . arraycopy ( tmp , 0 , this . pointCoordinates , first , tmp . length ) ; tmp = null ; return this ; }
invert the points coordinates of this element on the groupIndex in argument .
271
15
6,074
public MapComposedElement invert ( ) { if ( this . pointCoordinates == null ) { throw new IndexOutOfBoundsException ( ) ; } double [ ] tmp = new double [ this . pointCoordinates . length ] ; for ( int i = 0 ; i < this . pointCoordinates . length ; i += 2 ) { tmp [ i ] = this . pointCoordinates [ this . pointCoordinates . length - 1 - ( i + 1 ) ] ; tmp [ i + 1 ] = this . pointCoordinates [ this . pointCoordinates . length - 1 - i ] ; } System . arraycopy ( tmp , 0 , this . pointCoordinates , 0 , this . pointCoordinates . length ) ; if ( this . partIndexes != null ) { int [ ] tmpint = new int [ this . partIndexes . length ] ; //part 0 not inside the index array for ( int i = 0 ; i < this . partIndexes . length ; ++ i ) { tmpint [ this . partIndexes . length - 1 - i ] = this . pointCoordinates . length - this . partIndexes [ i ] ; } System . arraycopy ( tmpint , 0 , this . partIndexes , 0 , this . partIndexes . length ) ; tmpint = null ; } tmp = null ; return this ; }
Invert the order of points coordinates of this element and reorder the groupIndex too .
296
18
6,075
@ Pure public Point2d getPointAt ( int index ) { final int count = getPointCount ( ) ; int idx = index ; if ( idx < 0 ) { idx = count + idx ; } if ( idx < 0 ) { throw new IndexOutOfBoundsException ( idx + "<0" ) ; //$NON-NLS-1$ } if ( idx >= count ) { throw new IndexOutOfBoundsException ( idx + ">=" + count ) ; //$NON-NLS-1$ } return new Point2d ( this . pointCoordinates [ idx * 2 ] , this . pointCoordinates [ idx * 2 + 1 ] ) ; }
Replies the specified point at the given index .
157
10
6,076
@ Pure public Point2d getPointAt ( int groupIndex , int indexInGroup ) { final int startIndex = firstInGroup ( groupIndex ) ; // Besure that the member's index is in the group index's range final int groupMemberCount = getPointCountInGroup ( groupIndex ) ; if ( indexInGroup < 0 ) { throw new IndexOutOfBoundsException ( indexInGroup + "<0" ) ; //$NON-NLS-1$ } if ( indexInGroup >= groupMemberCount ) { throw new IndexOutOfBoundsException ( indexInGroup + ">=" + groupMemberCount ) ; //$NON-NLS-1$ } return new Point2d ( this . pointCoordinates [ startIndex + indexInGroup * 2 ] , this . pointCoordinates [ startIndex + indexInGroup * 2 + 1 ] ) ; }
Replies the specified point at the given index in the specified group .
190
14
6,077
public boolean removeGroupAt ( int groupIndex ) { try { final int startIndex = firstInGroup ( groupIndex ) ; final int lastIndex = lastInGroup ( groupIndex ) ; final int ptsToRemoveCount = ( lastIndex - startIndex + 2 ) / 2 ; int rest = this . pointCoordinates . length / 2 - ptsToRemoveCount ; if ( rest > 0 ) { // Remove the points rest *= 2 ; final double [ ] newPts = new double [ rest ] ; System . arraycopy ( this . pointCoordinates , 0 , newPts , 0 , startIndex ) ; System . arraycopy ( this . pointCoordinates , lastIndex + 2 , newPts , startIndex , rest - startIndex ) ; this . pointCoordinates = newPts ; // Remove the group if ( this . partIndexes != null ) { // Shift the group's indexes for ( int i = groupIndex ; i < this . partIndexes . length ; ++ i ) { this . partIndexes [ i ] -= ptsToRemoveCount * 2 ; } // Removing the group int [ ] newGroups = null ; if ( this . partIndexes . length > 1 ) { newGroups = new int [ this . partIndexes . length - 1 ] ; if ( groupIndex == 0 ) { System . arraycopy ( this . partIndexes , 1 , newGroups , 0 , this . partIndexes . length - 1 ) ; } else { System . arraycopy ( this . partIndexes , 0 , newGroups , 0 , groupIndex - 1 ) ; System . arraycopy ( this . partIndexes , groupIndex , newGroups , groupIndex - 1 , this . partIndexes . length - groupIndex ) ; } } this . partIndexes = newGroups ; } } else { // Remove all the points this . pointCoordinates = null ; this . partIndexes = null ; } fireShapeChanged ( ) ; fireElementChanged ( ) ; return true ; } catch ( IndexOutOfBoundsException exception ) { // } return false ; }
Remove the specified group .
450
5
6,078
public Point2d removePointAt ( int groupIndex , int indexInGroup ) { final int startIndex = firstInGroup ( groupIndex ) ; final int lastIndex = lastInGroup ( groupIndex ) ; // Translate local point's coordinate into global point's coordinate final int g = indexInGroup * 2 + startIndex ; // Be sure that the member's index is in the group index's range if ( g < startIndex ) { throw new IndexOutOfBoundsException ( g + "<" + startIndex ) ; //$NON-NLS-1$ } if ( g > lastIndex ) { throw new IndexOutOfBoundsException ( g + ">" + lastIndex ) ; //$NON-NLS-1$ } final Point2d p = new Point2d ( this . pointCoordinates [ g ] , this . pointCoordinates [ g + 1 ] ) ; // Deleting the point final double [ ] newPtsArray ; if ( this . pointCoordinates . length <= 2 ) { newPtsArray = null ; } else { newPtsArray = new double [ this . pointCoordinates . length - 2 ] ; System . arraycopy ( this . pointCoordinates , 0 , newPtsArray , 0 , g ) ; System . arraycopy ( this . pointCoordinates , g + 2 , newPtsArray , g , this . pointCoordinates . length - g - 2 ) ; } this . pointCoordinates = newPtsArray ; if ( this . partIndexes != null ) { // Shift the group's indexes for ( int i = groupIndex ; i < this . partIndexes . length ; ++ i ) { this . partIndexes [ i ] -= 2 ; } // Removing the group final int ptsCount = ( lastIndex - startIndex ) / 2 ; if ( ptsCount <= 0 ) { int [ ] newGroups = null ; if ( this . partIndexes . length > 1 ) { newGroups = new int [ this . partIndexes . length - 1 ] ; if ( groupIndex == 0 ) { System . arraycopy ( this . partIndexes , 1 , newGroups , 0 , this . partIndexes . length - 1 ) ; } else { System . arraycopy ( this . partIndexes , 0 , newGroups , 0 , groupIndex - 1 ) ; System . arraycopy ( this . partIndexes , groupIndex , newGroups , groupIndex - 1 , this . partIndexes . length - groupIndex ) ; } } this . partIndexes = newGroups ; } } fireShapeChanged ( ) ; fireElementChanged ( ) ; return p ; }
Remove the specified point at the given index in the specified group .
574
13
6,079
private boolean canonize ( int index ) { final int count = getPointCount ( ) ; int ix = index ; if ( ix < 0 ) { ix = count + ix ; } if ( ix < 0 ) { throw new IndexOutOfBoundsException ( ix + "<0" ) ; //$NON-NLS-1$ } if ( ix >= count ) { throw new IndexOutOfBoundsException ( ix + ">=" + count ) ; //$NON-NLS-1$ } final int partIndex = groupIndexForPoint ( ix ) ; final int firstPts = firstInGroup ( partIndex ) ; final int endPts = lastInGroup ( partIndex ) ; final int myIndex = ix * 2 ; int firstToRemove = myIndex ; int lastToRemove = myIndex ; boolean removeOne = false ; final double xbase = this . pointCoordinates [ ix * 2 ] ; final double ybase = this . pointCoordinates [ ix * 2 + 1 ] ; final PointFusionValidator validator = getPointFusionValidator ( ) ; // Search for the first point to remove for ( int idx = myIndex - 2 ; idx >= firstPts ; idx -= 2 ) { final double x = this . pointCoordinates [ idx ] ; final double y = this . pointCoordinates [ idx + 1 ] ; if ( validator . isSame ( xbase , ybase , x , y ) ) { firstToRemove = idx ; removeOne = true ; } else { // Stop search break ; } } // Search for the last point to remove for ( int idx = myIndex + 2 ; idx <= endPts ; idx += 2 ) { final double x = this . pointCoordinates [ idx ] ; final double y = this . pointCoordinates [ idx + 1 ] ; if ( validator . isSame ( xbase , ybase , x , y ) ) { lastToRemove = idx ; removeOne = true ; } else { // Stop search break ; } } if ( removeOne ) { // A set of points are detected as too near. // They should be removed and replaced by the reference point final int removalCount = ( lastToRemove / 2 - firstToRemove / 2 ) * 2 ; // Deleting the point final double [ ] newPtsArray = new double [ this . pointCoordinates . length - removalCount ] ; assert newPtsArray . length >= 2 ; System . arraycopy ( this . pointCoordinates , 0 , newPtsArray , 0 , firstToRemove ) ; System . arraycopy ( this . pointCoordinates , lastToRemove + 2 , newPtsArray , firstToRemove + 2 , this . pointCoordinates . length - lastToRemove - 2 ) ; newPtsArray [ firstToRemove ] = xbase ; newPtsArray [ firstToRemove + 1 ] = ybase ; this . pointCoordinates = newPtsArray ; if ( this . partIndexes != null ) { // Shift the group's indexes for ( int i = partIndex ; i < this . partIndexes . length ; ++ i ) { this . partIndexes [ i ] -= removalCount ; } } return true ; } return false ; }
Remove unnecessary points from the specified index .
719
8
6,080
private Optional < IncludeAllPageWithOutput > addOutputInformation ( IncludeAllPage pages , FileResource baseResource , Path includeAllBasePath , Locale locale ) { // depth = 0 is the file that has the include-all directive if ( pages . depth == 0 ) { return of ( new IncludeAllPageWithOutput ( pages , pages . files . get ( 0 ) , pages . files . get ( 0 ) . getPath ( ) , locale ) ) ; } Path baseResourceParentPath = baseResource . getPath ( ) . getParent ( ) ; Optional < FileResource > virtualResource = pages . files . stream ( ) . findFirst ( ) . map ( fr -> new VirtualPathFileResource ( baseResourceParentPath . resolve ( includeAllBasePath . relativize ( fr . getPath ( ) ) . toString ( ) ) , fr ) ) ; return virtualResource . map ( vr -> { Path finalOutputPath = outputPathExtractor . apply ( vr ) . normalize ( ) ; return new IncludeAllPageWithOutput ( pages , vr , finalOutputPath , locale ) ; } ) ; }
generate the final output path
236
6
6,081
public Reactor getReactorByIndex ( int index ) { if ( index < 0 || index > reactorSet . length - 1 ) { throw new ArrayIndexOutOfBoundsException ( ) ; } return reactorSet [ index ] ; }
Find reactor by index
50
4
6,082
@ SuppressWarnings ( "rawtypes" ) public static CompoundPainter getCompoundPainter ( final Color matte , final Color gloss , final GlossPainter . GlossPosition position , final double angle , final Color pinstripe ) { final MattePainter mp = new MattePainter ( matte ) ; final GlossPainter gp = new GlossPainter ( gloss , position ) ; final PinstripePainter pp = new PinstripePainter ( pinstripe , angle ) ; final CompoundPainter compoundPainter = new CompoundPainter ( mp , pp , gp ) ; return compoundPainter ; }
Gets a CompoundPainter object .
134
9
6,083
@ SuppressWarnings ( "rawtypes" ) public static CompoundPainter getCompoundPainter ( final Color color , final GlossPainter . GlossPosition position , final double angle ) { final MattePainter mp = new MattePainter ( color ) ; final GlossPainter gp = new GlossPainter ( color , position ) ; final PinstripePainter pp = new PinstripePainter ( color , angle ) ; final CompoundPainter compoundPainter = new CompoundPainter ( mp , pp , gp ) ; return compoundPainter ; }
Gets the compound painter .
122
6
6,084
public static MattePainter getMattePainter ( final int width , final int height , final float [ ] fractions , final Color ... colors ) { final LinearGradientPaint gradientPaint = new LinearGradientPaint ( 0.0f , 0.0f , width , height , fractions , colors ) ; final MattePainter mattePainter = new MattePainter ( gradientPaint ) ; return mattePainter ; }
Gets a MattePainter object .
91
8
6,085
@ Override public void set ( Point3D center , double radius1 ) { this . cx = center . getX ( ) ; this . cy = center . getY ( ) ; this . cz = center . getZ ( ) ; this . radius = Math . abs ( radius1 ) ; }
Change the frame of te sphere .
63
7
6,086
public ListProperty < T > elementsProperty ( ) { if ( this . elements == null ) { this . elements = new SimpleListProperty <> ( this , MathFXAttributeNames . ELEMENTS , new InternalObservableList <> ( ) ) ; } return this . elements ; }
Replies the property that contains all the shapes in this multishape .
60
15
6,087
@ SuppressWarnings ( "unchecked" ) protected static < E > Class < ? extends E > extractClassFrom ( Collection < ? extends E > collection ) { Class < ? extends E > clazz = null ; for ( final E elt : collection ) { clazz = ( Class < ? extends E > ) ReflectionUtil . getCommonType ( clazz , elt . getClass ( ) ) ; } return clazz == null ? ( Class < E > ) Object . class : clazz ; }
Extract the upper class that contains all the elements of this array .
110
14
6,088
public HelpSet getHelpSet ( ) { HelpSet hs = null ; final String filename = "simple-hs.xml" ; final String path = "help/" + filename ; URL hsURL ; hsURL = ClassExtensions . getResource ( path ) ; try { if ( hsURL != null ) { hs = new HelpSet ( ClassExtensions . getClassLoader ( ) , hsURL ) ; } else { hs = new HelpSet ( ) ; } } catch ( final HelpSetException e ) { String title = e . getLocalizedMessage ( ) ; String htmlMessage = "<html><body width='650'>" + "<h2>" + title + "</h2>" + "<p>" + e . getMessage ( ) + "\n" + path ; JOptionPane . showMessageDialog ( this . getParent ( ) , htmlMessage , title , JOptionPane . ERROR_MESSAGE ) ; log . log ( Level . SEVERE , e . getMessage ( ) , e ) ; } return hs ; }
Gets the help set .
229
6
6,089
protected JMenu newHelpMenu ( final ActionListener listener ) { // Help menu final JMenu menuHelp = new JMenu ( newLabelTextHelp ( ) ) ; menuHelp . setMnemonic ( ' ' ) ; // Help JMenuItems // Help content final JMenuItem mihHelpContent = JComponentFactory . newJMenuItem ( newLabelTextContent ( ) , ' ' , ' ' ) ; menuHelp . add ( mihHelpContent ) ; // 2. assign help to components CSH . setHelpIDString ( mihHelpContent , newLabelTextOverview ( ) ) ; // 3. handle events final CSH . DisplayHelpFromSource displayHelpFromSource = new CSH . DisplayHelpFromSource ( helpBroker ) ; mihHelpContent . addActionListener ( displayHelpFromSource ) ; // Donate final JMenuItem mihDonate = new JMenuItem ( newLabelTextDonate ( ) ) ; mihDonate . addActionListener ( newOpenBrowserToDonateAction ( newLabelTextDonate ( ) , applicationFrame ) ) ; menuHelp . add ( mihDonate ) ; // Licence final JMenuItem mihLicence = new JMenuItem ( newLabelTextLicence ( ) ) ; mihLicence . addActionListener ( newShowLicenseFrameAction ( newLabelTextLicence ( ) + "Action" , newLabelTextLicence ( ) ) ) ; menuHelp . add ( mihLicence ) ; // Info final JMenuItem mihInfo = new JMenuItem ( newLabelTextInfo ( ) , ' ' ) ; // $NON-NLS-1$ MenuExtensions . setCtrlAccelerator ( mihInfo , ' ' ) ; mihInfo . addActionListener ( newShowInfoDialogAction ( newLabelTextInfo ( ) , ( Frame ) applicationFrame , newLabelTextInfo ( ) ) ) ; menuHelp . add ( mihInfo ) ; return menuHelp ; }
Creates the help menu .
418
6
6,090
protected JMenu newLookAndFeelMenu ( final ActionListener listener ) { final JMenu menuLookAndFeel = new JMenu ( "Look and Feel" ) ; menuLookAndFeel . setMnemonic ( ' ' ) ; // Look and Feel JMenuItems // GTK JMenuItem jmiPlafGTK ; jmiPlafGTK = new JMenuItem ( "GTK" , ' ' ) ; //$NON-NLS-1$ MenuExtensions . setCtrlAccelerator ( jmiPlafGTK , ' ' ) ; jmiPlafGTK . addActionListener ( new LookAndFeelGTKAction ( "GTK" , this . applicationFrame ) ) ; menuLookAndFeel . add ( jmiPlafGTK ) ; // Metal default Metal theme JMenuItem jmiPlafMetal ; jmiPlafMetal = new JMenuItem ( "Metal" , ' ' ) ; //$NON-NLS-1$ MenuExtensions . setCtrlAccelerator ( jmiPlafMetal , ' ' ) ; jmiPlafMetal . addActionListener ( new LookAndFeelMetalAction ( "Metal" , this . applicationFrame ) ) ; menuLookAndFeel . add ( jmiPlafMetal ) ; // Metal Ocean theme JMenuItem jmiPlafOcean ; jmiPlafOcean = new JMenuItem ( "Ocean" , ' ' ) ; //$NON-NLS-1$ MenuExtensions . setCtrlAccelerator ( jmiPlafOcean , ' ' ) ; jmiPlafOcean . addActionListener ( new LookAndFeelMetalAction ( "Ocean" , this . applicationFrame ) ) ; menuLookAndFeel . add ( jmiPlafOcean ) ; // Motif JMenuItem jmiPlafMotiv ; jmiPlafMotiv = new JMenuItem ( "Motif" , ' ' ) ; //$NON-NLS-1$ MenuExtensions . setCtrlAccelerator ( jmiPlafMotiv , ' ' ) ; jmiPlafMotiv . addActionListener ( new LookAndFeelMotifAction ( "Motif" , this . applicationFrame ) ) ; menuLookAndFeel . add ( jmiPlafMotiv ) ; // Nimbus JMenuItem jmiPlafNimbus ; jmiPlafNimbus = new JMenuItem ( "Nimbus" , ' ' ) ; //$NON-NLS-1$ MenuExtensions . setCtrlAccelerator ( jmiPlafNimbus , ' ' ) ; jmiPlafNimbus . addActionListener ( new LookAndFeelNimbusAction ( "Nimbus" , this . applicationFrame ) ) ; menuLookAndFeel . add ( jmiPlafNimbus ) ; // Windows JMenuItem jmiPlafSystem ; jmiPlafSystem = new JMenuItem ( "System" , ' ' ) ; //$NON-NLS-1$ MenuExtensions . setCtrlAccelerator ( jmiPlafSystem , ' ' ) ; jmiPlafSystem . addActionListener ( new LookAndFeelSystemAction ( "System" , this . applicationFrame ) ) ; menuLookAndFeel . add ( jmiPlafSystem ) ; return menuLookAndFeel ; }
Creates the look and feel menu .
714
8
6,091
public NYTCorpusDocument parseNYTCorpusDocumentFromFile ( File file , boolean validating ) { Document document = null ; if ( validating ) { document = loadValidating ( file ) ; } else { document = loadNonValidating ( file ) ; } return parseNYTCorpusDocumentFromDOMDocument ( file , document ) ; }
Parse an New York Times Document from a file .
74
11
6,092
private Document loadNonValidating ( InputStream is ) { Document document ; StringBuffer sb = new StringBuffer ( ) ; BufferedReader in = null ; try { in = new BufferedReader ( new InputStreamReader ( is , "UTF8" ) ) ; String line = null ; while ( ( line = in . readLine ( ) ) != null ) { sb . append ( line + "\n" ) ; } String xmlData = sb . toString ( ) ; xmlData = xmlData . replace ( "<!DOCTYPE nitf " + "SYSTEM \"http://www.nitf.org/" + "IPTC/NITF/3.3/specification/dtd/nitf-3-3.dtd\">" , "" ) ; document = parseStringToDOM ( xmlData , "UTF-8" ) ; return document ; } catch ( UnsupportedEncodingException e ) { e . printStackTrace ( ) ; System . out . println ( "Error loading inputstream." ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; System . out . println ( "Error loading file inputstream." ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; System . out . println ( "Error loading file inputstream." ) ; } finally { if ( in != null ) try { in . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return null ; }
Load a document without validating it . Since instructing the java . xml libraries to do this does not actually disable validation this method disables validation by removing the doctype declaration from the XML document before it is parsed .
327
44
6,093
private Document parseStringToDOM ( String s , String encoding ) { try { DocumentBuilderFactory factory = DocumentBuilderFactory . newInstance ( ) ; factory . setValidating ( false ) ; InputStream is = new ByteArrayInputStream ( s . getBytes ( encoding ) ) ; Document doc = factory . newDocumentBuilder ( ) . parse ( is ) ; return doc ; } catch ( SAXException e ) { e . printStackTrace ( ) ; System . out . println ( "Exception processing string." ) ; } catch ( ParserConfigurationException e ) { e . printStackTrace ( ) ; System . out . println ( "Exception processing string." ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; System . out . println ( "Exception processing string." ) ; } return null ; }
Parse a string to a DOM document .
175
9
6,094
private Document getDOMObject ( String filename , boolean validating ) throws SAXException , IOException , ParserConfigurationException { // Create a builder factory DocumentBuilderFactory factory = DocumentBuilderFactory . newInstance ( ) ; if ( ! validating ) { factory . setValidating ( validating ) ; factory . setSchema ( null ) ; factory . setNamespaceAware ( false ) ; } DocumentBuilder builder = factory . newDocumentBuilder ( ) ; // Create the builder and parse the file Document doc = builder . parse ( new File ( filename ) ) ; return doc ; }
Parse a file containing an XML document into a DOM object .
121
13
6,095
@ Pure @ SuppressWarnings ( "unchecked" ) public Class < ? extends T > getValueType ( ) { if ( this . object == null ) { return null ; } return ( Class < ? extends T > ) this . object . getClass ( ) ; }
Replies the type of the value .
59
8
6,096
public void add ( T newValue ) { if ( this . isSet ) { if ( ! this . isMultiple && newValue != this . object && ( newValue == null || ! newValue . equals ( this . object ) ) ) { this . isMultiple = true ; this . object = null ; } } else { this . object = newValue ; this . isSet = true ; this . isMultiple = false ; } }
Add the given value to the styored value .
91
10
6,097
public String commandsWritingDataTo ( File dataDirectory ) throws IOException { final Map < DatafileReference , File > refsToFiles = Maps . newHashMap ( ) ; for ( final DatafileReference datafileReference : datafileReferences ) { final File randomFile = File . createTempFile ( "plotBundle" , ".dat" , dataDirectory ) ; randomFile . deleteOnExit ( ) ; refsToFiles . put ( datafileReference , randomFile ) ; Files . asCharSink ( randomFile , Charsets . UTF_8 ) . write ( datafileReference . data ) ; } final StringBuilder ret = new StringBuilder ( ) ; for ( final Object commandComponent : commandComponents ) { if ( commandComponent instanceof String ) { ret . append ( commandComponent ) ; } else if ( commandComponent instanceof DatafileReference ) { final File file = refsToFiles . get ( commandComponent ) ; if ( file != null ) { ret . append ( file . getAbsolutePath ( ) ) ; } else { throw new RuntimeException ( "PlotBundle references an unknown data source" ) ; } } else { throw new RuntimeException ( "Unknown command component " + commandComponent ) ; } } return ret . toString ( ) ; }
Writes the plot data to the indicated directory and returns the GnuPlot commands for the plot as a string . These commands will reference the written data files .
269
32
6,098
public void setCodePage ( DBaseCodePage code ) { if ( this . columns != null ) { throw new IllegalStateException ( ) ; } if ( code != null ) { this . language = code ; } }
Replies the output language to use in the dBASE file .
46
13
6,099
@ SuppressWarnings ( "checkstyle:magicnumber" ) private void writeDBFDate ( Date date ) throws IOException { final SimpleDateFormat format = new SimpleDateFormat ( "yyyyMMdd" ) ; //$NON-NLS-1$ writeDBFString ( format . format ( date ) , 8 , ( byte ) ' ' ) ; }
Write a formated date according to the Dbase specifications .
80
12