idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
21,200
public StitchObjectMapper withCodecRegistry ( final CodecRegistry codecRegistry ) { final CodecRegistry newReg = CodecRegistries . fromRegistries ( BsonUtils . DEFAULT_CODEC_REGISTRY , codecRegistry ) ; return new StitchObjectMapper ( this , newReg ) ; }
Applies the given codec registry to be used alongside the default codec registry .
21,201
public StitchEvent < T > nextEvent ( ) throws IOException { final Event nextEvent = eventStream . nextEvent ( ) ; if ( nextEvent == null ) { return null ; } return StitchEvent . fromEvent ( nextEvent , this . decoder ) ; }
Fetch the next event from a given stream
21,202
public StitchUserT getUser ( ) { authLock . readLock ( ) . lock ( ) ; try { return activeUser ; } finally { authLock . readLock ( ) . unlock ( ) ; } }
Returns the active logged in user .
21,203
private synchronized Response doAuthenticatedRequest ( final StitchAuthRequest stitchReq , final AuthInfo authInfo ) { try { return requestClient . doRequest ( prepareAuthRequest ( stitchReq , authInfo ) ) ; } catch ( final StitchServiceException ex ) { return handleAuthFailure ( ex , stitchReq ) ; } }
Internal method which performs the authenticated request by preparing the auth request with the provided auth info and request .
21,204
private void tryRefreshAccessToken ( final Long reqStartedAt ) { authLock . writeLock ( ) . lock ( ) ; try { if ( ! isLoggedIn ( ) ) { throw new StitchClientException ( StitchClientErrorCode . LOGGED_OUT_DURING_REQUEST ) ; } try { final Jwt jwt = Jwt . fromEncoded ( getAuthInfo ( ) . getAccessToken ( ) ) ; if ( jwt . getIssuedAt ( ) >= reqStartedAt ) { return ; } } catch ( final IOException e ) { } refreshAccessToken ( ) ; } finally { authLock . writeLock ( ) . unlock ( ) ; } }
prevent too many refreshes happening one after the other .
21,205
private StitchUserT doLogin ( final StitchCredential credential , final boolean asLinkRequest ) { final Response response = doLoginRequest ( credential , asLinkRequest ) ; final StitchUserT previousUser = activeUser ; final StitchUserT user = processLoginResponse ( credential , response , asLinkRequest ) ; if ( asLinkRequest ) { onUserLinked ( user ) ; } else { onUserLoggedIn ( user ) ; onActiveUserChanged ( activeUser , previousUser ) ; } return user ; }
callers of doLogin should be serialized before calling in .
21,206
private static Interval parseStartExtended ( CharSequence startStr , CharSequence endStr ) { Instant start = Instant . parse ( startStr ) ; if ( endStr . length ( ) > 0 ) { char c = endStr . charAt ( 0 ) ; if ( c == 'P' || c == 'p' ) { PeriodDuration amount = PeriodDuration . parse ( endStr ) ; long move = start . isBefore ( Instant . EPOCH ) ? 1000 * 86400 : - 1000 * 86400 ; Instant end = start . plusSeconds ( move ) . atOffset ( ZoneOffset . UTC ) . plus ( amount ) . toInstant ( ) . minusSeconds ( move ) ; return Interval . of ( start , end ) ; } } return parseEndDateTime ( start , ZoneOffset . UTC , endStr ) ; }
handle case where Instant is outside the bounds of OffsetDateTime
21,207
private static Interval parseEndDateTime ( Instant start , ZoneOffset offset , CharSequence endStr ) { try { TemporalAccessor temporal = DateTimeFormatter . ISO_DATE_TIME . parseBest ( endStr , OffsetDateTime :: from , LocalDateTime :: from ) ; if ( temporal instanceof OffsetDateTime ) { OffsetDateTime odt = ( OffsetDateTime ) temporal ; return Interval . of ( start , odt . toInstant ( ) ) ; } else { LocalDateTime ldt = ( LocalDateTime ) temporal ; return Interval . of ( start , ldt . toInstant ( offset ) ) ; } } catch ( DateTimeParseException ex ) { Instant end = Instant . parse ( endStr ) ; return Interval . of ( start , end ) ; } }
parse when there are two date - times
21,208
public AccountingDate date ( int prolepticYear , int month , int dayOfMonth ) { return AccountingDate . of ( this , prolepticYear , month , dayOfMonth ) ; }
Obtains a local date in Accounting calendar system from the proleptic - year month - of - year and day - of - month fields .
21,209
public AccountingDate dateYearDay ( Era era , int yearOfEra , int dayOfYear ) { return dateYearDay ( prolepticYear ( era , yearOfEra ) , dayOfYear ) ; }
Obtains a local date in Accounting calendar system from the era year - of - era and day - of - year fields .
21,210
@ SuppressWarnings ( "unchecked" ) public ChronoLocalDateTime < AccountingDate > localDateTime ( TemporalAccessor temporal ) { return ( ChronoLocalDateTime < AccountingDate > ) super . localDateTime ( temporal ) ; }
Obtains a Accounting local date - time from another date - time object .
21,211
@ SuppressWarnings ( "unchecked" ) public ChronoZonedDateTime < AccountingDate > zonedDateTime ( TemporalAccessor temporal ) { return ( ChronoZonedDateTime < AccountingDate > ) super . zonedDateTime ( temporal ) ; }
Obtains a Accounting zoned date - time from another date - time object .
21,212
public CopticDate date ( int prolepticYear , int month , int dayOfMonth ) { return CopticDate . of ( prolepticYear , month , dayOfMonth ) ; }
Obtains a local date in Coptic calendar system from the proleptic - year month - of - year and day - of - month fields .
21,213
public CopticDate dateYearDay ( Era era , int yearOfEra , int dayOfYear ) { return dateYearDay ( prolepticYear ( era , yearOfEra ) , dayOfYear ) ; }
Obtains a local date in Coptic calendar system from the era year - of - era and day - of - year fields .
21,214
@ SuppressWarnings ( "unchecked" ) public ChronoLocalDateTime < CopticDate > localDateTime ( TemporalAccessor temporal ) { return ( ChronoLocalDateTime < CopticDate > ) super . localDateTime ( temporal ) ; }
Obtains a Coptic local date - time from another date - time object .
21,215
@ SuppressWarnings ( "unchecked" ) public ChronoZonedDateTime < CopticDate > zonedDateTime ( TemporalAccessor temporal ) { return ( ChronoZonedDateTime < CopticDate > ) super . zonedDateTime ( temporal ) ; }
Obtains a Coptic zoned date - time from another date - time object .
21,216
private YearQuarter with ( int newYear , Quarter newQuarter ) { if ( year == newYear && quarter == newQuarter ) { return this ; } return new YearQuarter ( newYear , newQuarter ) ; }
Returns a copy of this year - quarter with the new year and quarter checking to see if a new object is in fact required .
21,217
@ SuppressWarnings ( "unchecked" ) public ChronoLocalDateTime < BritishCutoverDate > localDateTime ( TemporalAccessor temporal ) { return ( ChronoLocalDateTime < BritishCutoverDate > ) super . localDateTime ( temporal ) ; }
Obtains a British Cutover local date - time from another date - time object .
21,218
@ SuppressWarnings ( "unchecked" ) public ChronoZonedDateTime < BritishCutoverDate > zonedDateTime ( TemporalAccessor temporal ) { return ( ChronoZonedDateTime < BritishCutoverDate > ) super . zonedDateTime ( temporal ) ; }
Obtains a British Cutover zoned date - time from another date - time object .
21,219
private static int weekRange ( int weekBasedYear ) { LocalDate date = LocalDate . of ( weekBasedYear , 1 , 1 ) ; if ( date . getDayOfWeek ( ) == THURSDAY || ( date . getDayOfWeek ( ) == WEDNESDAY && date . isLeapYear ( ) ) ) { return 53 ; } return 52 ; }
from IsoFields in ThreeTen - Backport
21,220
private YearWeek with ( int newYear , int newWeek ) { if ( year == newYear && week == newWeek ) { return this ; } return of ( newYear , newWeek ) ; }
Returns a copy of this year - week with the new year and week checking to see if a new object is in fact required .
21,221
void register ( long mjDay , int leapAdjustment ) { if ( leapAdjustment != - 1 && leapAdjustment != 1 ) { throw new IllegalArgumentException ( "Leap adjustment must be -1 or 1" ) ; } Data data = dataRef . get ( ) ; int pos = Arrays . binarySearch ( data . dates , mjDay ) ; int currentAdj = pos > 0 ? data . offsets [ pos ] - data . offsets [ pos - 1 ] : 0 ; if ( currentAdj == leapAdjustment ) { return ; } if ( mjDay <= data . dates [ data . dates . length - 1 ] ) { throw new IllegalArgumentException ( "Date must be after the last configured leap second date" ) ; } long [ ] dates = Arrays . copyOf ( data . dates , data . dates . length + 1 ) ; int [ ] offsets = Arrays . copyOf ( data . offsets , data . offsets . length + 1 ) ; long [ ] taiSeconds = Arrays . copyOf ( data . taiSeconds , data . taiSeconds . length + 1 ) ; int offset = offsets [ offsets . length - 2 ] + leapAdjustment ; dates [ dates . length - 1 ] = mjDay ; offsets [ offsets . length - 1 ] = offset ; taiSeconds [ taiSeconds . length - 1 ] = tai ( mjDay , offset ) ; Data newData = new Data ( dates , offsets , taiSeconds ) ; if ( dataRef . compareAndSet ( data , newData ) == false ) { throw new ConcurrentModificationException ( "Unable to update leap second rules as they have already been updated" ) ; } }
Adds a new leap second to these rules .
21,222
private static Data loadLeapSeconds ( ) { Data bestData = null ; URL url = null ; try { Enumeration < URL > en = Thread . currentThread ( ) . getContextClassLoader ( ) . getResources ( "META-INF/" + LEAP_SECONDS_TXT ) ; while ( en . hasMoreElements ( ) ) { url = en . nextElement ( ) ; Data candidate = loadLeapSeconds ( url ) ; if ( bestData == null || candidate . getNewestDate ( ) > bestData . getNewestDate ( ) ) { bestData = candidate ; } } en = Thread . currentThread ( ) . getContextClassLoader ( ) . getResources ( LEAP_SECONDS_TXT ) ; while ( en . hasMoreElements ( ) ) { url = en . nextElement ( ) ; Data candidate = loadLeapSeconds ( url ) ; if ( bestData == null || candidate . getNewestDate ( ) > bestData . getNewestDate ( ) ) { bestData = candidate ; } } url = SystemUtcRules . class . getResource ( "/" + LEAP_SECONDS_TXT ) ; if ( url != null ) { Data candidate = loadLeapSeconds ( url ) ; if ( bestData == null || candidate . getNewestDate ( ) > bestData . getNewestDate ( ) ) { bestData = candidate ; } } } catch ( Exception ex ) { throw new RuntimeException ( "Unable to load time-zone rule data: " + url , ex ) ; } if ( bestData == null ) { bestData = new Data ( new long [ ] { 41317L } , new int [ ] { 10 } , new long [ ] { tai ( 41317L , 10 ) } ) ; } return bestData ; }
Loads the rules from files in the class loader often jar files .
21,223
private static Data loadLeapSeconds ( URL url ) throws ClassNotFoundException , IOException { List < String > lines ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( url . openStream ( ) , StandardCharsets . UTF_8 ) ) ) { lines = reader . lines ( ) . collect ( Collectors . toList ( ) ) ; } List < Long > dates = new ArrayList < > ( ) ; List < Integer > offsets = new ArrayList < > ( ) ; for ( String line : lines ) { line = line . trim ( ) ; if ( line . isEmpty ( ) || line . startsWith ( "#" ) ) { continue ; } Matcher matcher = LEAP_FILE_FORMAT . matcher ( line ) ; if ( matcher . matches ( ) == false ) { throw new StreamCorruptedException ( "Invalid leap second file" ) ; } dates . add ( LocalDate . parse ( matcher . group ( 1 ) ) . getLong ( JulianFields . MODIFIED_JULIAN_DAY ) ) ; offsets . add ( Integer . valueOf ( matcher . group ( 2 ) ) ) ; } long [ ] datesData = new long [ dates . size ( ) ] ; int [ ] offsetsData = new int [ dates . size ( ) ] ; long [ ] taiData = new long [ dates . size ( ) ] ; for ( int i = 0 ; i < datesData . length ; i ++ ) { datesData [ i ] = dates . get ( i ) ; offsetsData [ i ] = offsets . get ( i ) ; taiData [ i ] = tai ( datesData [ i ] , offsetsData [ i ] ) ; } return new Data ( datesData , offsetsData , taiData ) ; }
Loads the leap second rules from a URL often in a jar file .
21,224
static InternationalFixedDate create ( int prolepticYear , int month , int dayOfMonth ) { YEAR_RANGE . checkValidValue ( prolepticYear , ChronoField . YEAR_OF_ERA ) ; MONTH_OF_YEAR_RANGE . checkValidValue ( month , ChronoField . MONTH_OF_YEAR ) ; DAY_OF_MONTH_RANGE . checkValidValue ( dayOfMonth , ChronoField . DAY_OF_MONTH ) ; if ( dayOfMonth == DAYS_IN_LONG_MONTH && month != 6 && month != MONTHS_IN_YEAR ) { throw new DateTimeException ( "Invalid date: " + prolepticYear + '/' + month + '/' + dayOfMonth ) ; } if ( month == 6 && dayOfMonth == DAYS_IN_LONG_MONTH && ! INSTANCE . isLeapYear ( prolepticYear ) ) { throw new DateTimeException ( "Invalid Leap Day as '" + prolepticYear + "' is not a leap year" ) ; } return new InternationalFixedDate ( prolepticYear , month , dayOfMonth ) ; }
Factory method validates the given triplet year month and dayOfMonth .
21,225
public JulianDate date ( int prolepticYear , int month , int dayOfMonth ) { return JulianDate . of ( prolepticYear , month , dayOfMonth ) ; }
Obtains a local date in Julian calendar system from the proleptic - year month - of - year and day - of - month fields .
21,226
public JulianDate dateYearDay ( Era era , int yearOfEra , int dayOfYear ) { return dateYearDay ( prolepticYear ( era , yearOfEra ) , dayOfYear ) ; }
Obtains a local date in Julian calendar system from the era year - of - era and day - of - year fields .
21,227
@ SuppressWarnings ( "unchecked" ) public ChronoLocalDateTime < JulianDate > localDateTime ( TemporalAccessor temporal ) { return ( ChronoLocalDateTime < JulianDate > ) super . localDateTime ( temporal ) ; }
Obtains a Julian local date - time from another date - time object .
21,228
@ SuppressWarnings ( "unchecked" ) public ChronoZonedDateTime < JulianDate > zonedDateTime ( TemporalAccessor temporal ) { return ( ChronoZonedDateTime < JulianDate > ) super . zonedDateTime ( temporal ) ; }
Obtains a Julian zoned date - time from another date - time object .
21,229
public Symmetry454Date date ( int prolepticYear , int month , int dayOfMonth ) { return Symmetry454Date . of ( prolepticYear , month , dayOfMonth ) ; }
Obtains a local date in Symmetry454 calendar system from the proleptic - year month - of - year and day - of - month fields .
21,230
public Symmetry454Date dateYearDay ( Era era , int yearOfEra , int dayOfYear ) { return dateYearDay ( prolepticYear ( era , yearOfEra ) , dayOfYear ) ; }
Obtains a local date in Symmetry454 calendar system from the era year - of - era and day - of - year fields .
21,231
@ SuppressWarnings ( "unchecked" ) public ChronoLocalDateTime < Symmetry454Date > localDateTime ( TemporalAccessor temporal ) { return ( ChronoLocalDateTime < Symmetry454Date > ) super . localDateTime ( temporal ) ; }
Obtains a Symmetry454 local date - time from another date - time object .
21,232
@ SuppressWarnings ( "unchecked" ) public ChronoZonedDateTime < Symmetry454Date > zonedDateTime ( TemporalAccessor temporal ) { return ( ChronoZonedDateTime < Symmetry454Date > ) super . zonedDateTime ( temporal ) ; }
Obtains a Symmetry454 zoned date - time from another date - time object .
21,233
public Symmetry010Date date ( int prolepticYear , int month , int dayOfMonth ) { return Symmetry010Date . of ( prolepticYear , month , dayOfMonth ) ; }
Obtains a local date in Symmetry010 calendar system from the proleptic - year month - of - year and day - of - month fields .
21,234
public Symmetry010Date dateYearDay ( Era era , int yearOfEra , int dayOfYear ) { return dateYearDay ( prolepticYear ( era , yearOfEra ) , dayOfYear ) ; }
Obtains a local date in Symmetry010 calendar system from the era year - of - era and day - of - year fields .
21,235
@ SuppressWarnings ( "unchecked" ) public ChronoLocalDateTime < Symmetry010Date > localDateTime ( TemporalAccessor temporal ) { return ( ChronoLocalDateTime < Symmetry010Date > ) super . localDateTime ( temporal ) ; }
Obtains a Symmetry010 local date - time from another date - time object .
21,236
@ SuppressWarnings ( "unchecked" ) public ChronoZonedDateTime < Symmetry010Date > zonedDateTime ( TemporalAccessor temporal ) { return ( ChronoZonedDateTime < Symmetry010Date > ) super . zonedDateTime ( temporal ) ; }
Obtains a Symmetry010 zoned date - time from another date - time object .
21,237
public PaxDate date ( int prolepticYear , int month , int dayOfMonth ) { return PaxDate . of ( prolepticYear , month , dayOfMonth ) ; }
Obtains a local date in Pax calendar system from the proleptic - year month - of - year and day - of - month fields .
21,238
public PaxDate dateYearDay ( Era era , int yearOfEra , int dayOfYear ) { return dateYearDay ( prolepticYear ( era , yearOfEra ) , dayOfYear ) ; }
Obtains a local date in Pax calendar system from the era year - of - era and day - of - year fields .
21,239
@ SuppressWarnings ( "unchecked" ) public ChronoLocalDateTime < PaxDate > localDateTime ( TemporalAccessor temporal ) { return ( ChronoLocalDateTime < PaxDate > ) super . localDateTime ( temporal ) ; }
Obtains a Pax local date - time from another date - time object .
21,240
@ SuppressWarnings ( "unchecked" ) public ChronoZonedDateTime < PaxDate > zonedDateTime ( TemporalAccessor temporal ) { return ( ChronoZonedDateTime < PaxDate > ) super . zonedDateTime ( temporal ) ; }
Obtains a Pax zoned date - time from another date - time object .
21,241
public EthiopicDate date ( Era era , int yearOfEra , int month , int dayOfMonth ) { return date ( prolepticYear ( era , yearOfEra ) , month , dayOfMonth ) ; }
Obtains a local date in Ethiopic calendar system from the era year - of - era month - of - year and day - of - month fields .
21,242
public EthiopicDate date ( int prolepticYear , int month , int dayOfMonth ) { return EthiopicDate . of ( prolepticYear , month , dayOfMonth ) ; }
Obtains a local date in Ethiopic calendar system from the proleptic - year month - of - year and day - of - month fields .
21,243
public EthiopicDate dateYearDay ( Era era , int yearOfEra , int dayOfYear ) { return dateYearDay ( prolepticYear ( era , yearOfEra ) , dayOfYear ) ; }
Obtains a local date in Ethiopic calendar system from the era year - of - era and day - of - year fields .
21,244
@ SuppressWarnings ( "unchecked" ) public ChronoLocalDateTime < EthiopicDate > localDateTime ( TemporalAccessor temporal ) { return ( ChronoLocalDateTime < EthiopicDate > ) super . localDateTime ( temporal ) ; }
Obtains a Ethiopic local date - time from another date - time object .
21,245
@ SuppressWarnings ( "unchecked" ) public ChronoZonedDateTime < EthiopicDate > zonedDateTime ( TemporalAccessor temporal ) { return ( ChronoZonedDateTime < EthiopicDate > ) super . zonedDateTime ( temporal ) ; }
Obtains a Ethiopic zoned date - time from another date - time object .
21,246
public DiscordianDate date ( int prolepticYear , int month , int dayOfMonth ) { return DiscordianDate . of ( prolepticYear , month , dayOfMonth ) ; }
Obtains a local date in Discordian calendar system from the proleptic - year month - of - year and day - of - month fields .
21,247
public DiscordianDate dateYearDay ( Era era , int yearOfEra , int dayOfYear ) { return dateYearDay ( prolepticYear ( era , yearOfEra ) , dayOfYear ) ; }
Obtains a local date in Discordian calendar system from the era year - of - era and day - of - year fields .
21,248
@ SuppressWarnings ( "unchecked" ) public ChronoLocalDateTime < DiscordianDate > localDateTime ( TemporalAccessor temporal ) { return ( ChronoLocalDateTime < DiscordianDate > ) super . localDateTime ( temporal ) ; }
Obtains a Discordian local date - time from another date - time object .
21,249
@ SuppressWarnings ( "unchecked" ) public ChronoZonedDateTime < DiscordianDate > zonedDateTime ( TemporalAccessor temporal ) { return ( ChronoZonedDateTime < DiscordianDate > ) super . zonedDateTime ( temporal ) ; }
Obtains a Discordian zoned date - time from another date - time object .
21,250
public InternationalFixedDate date ( int prolepticYear , int month , int dayOfMonth ) { return InternationalFixedDate . of ( prolepticYear , month , dayOfMonth ) ; }
Obtains a local date in International Fixed calendar system from the proleptic - year month - of - year and day - of - month fields .
21,251
public InternationalFixedDate dateYearDay ( Era era , int yearOfEra , int dayOfYear ) { return dateYearDay ( prolepticYear ( era , yearOfEra ) , dayOfYear ) ; }
Obtains a local date in International Fixed calendar system from the era year - of - era and day - of - year fields .
21,252
@ SuppressWarnings ( "unchecked" ) public ChronoLocalDateTime < InternationalFixedDate > localDateTime ( TemporalAccessor temporal ) { return ( ChronoLocalDateTime < InternationalFixedDate > ) super . localDateTime ( temporal ) ; }
Obtains a International Fixed local date - time from another date - time object .
21,253
@ SuppressWarnings ( "unchecked" ) public ChronoZonedDateTime < InternationalFixedDate > zonedDateTime ( TemporalAccessor temporal ) { return ( ChronoZonedDateTime < InternationalFixedDate > ) super . zonedDateTime ( temporal ) ; }
Obtains a International Fixed zoned date - time from another date - time object .
21,254
public final ReadOnlyObjectProperty < LatLongBounds > boundsProperty ( ) { if ( bounds == null ) { bounds = new ReadOnlyObjectWrapper < > ( getBounds ( ) ) ; addStateEventHandler ( MapStateEventType . idle , ( ) -> { bounds . set ( getBounds ( ) ) ; } ) ; } return bounds . getReadOnlyProperty ( ) ; }
A property tied to the map updated when the idle state event is fired .
21,255
public void addMarker ( Marker marker ) { if ( markers == null ) { markers = new HashSet < > ( ) ; } markers . add ( marker ) ; marker . setMap ( this ) ; }
Adds the supplied marker to the map .
21,256
public void removeMarker ( Marker marker ) { if ( markers != null && markers . contains ( marker ) ) { markers . remove ( marker ) ; } marker . setMap ( null ) ; }
Removes the supplied marker from the map .
21,257
public void clearMarkers ( ) { if ( markers != null && ! markers . isEmpty ( ) ) { markers . forEach ( ( m ) -> { m . setMap ( null ) ; } ) ; markers . clear ( ) ; } }
Removes all of the markers from the map .
21,258
protected void setProperty ( String propertyName , JavascriptObject propertyValue ) { jsObject . setMember ( propertyName , propertyValue . getJSObject ( ) ) ; }
Sets a property on this Javascript object for which the value is a Javascript object itself .
21,259
protected void setProperty ( String propertyName , JavascriptEnum propertyValue ) { jsObject . setMember ( propertyName , propertyValue . getEnumValue ( ) ) ; }
Sets a property on this Javascript object for which the value is a JavascriptEnum
21,260
protected < T > T getProperty ( String key , Class < T > type ) { Object returnValue = getProperty ( key ) ; if ( returnValue != null ) { return ( T ) returnValue ; } else { return null ; } }
Gets the property and casts to the appropriate type
21,261
protected < T > T invokeJavascriptReturnValue ( String function , Class < T > returnType ) { Object returnObject = invokeJavascript ( function ) ; if ( returnObject instanceof JSObject ) { try { Constructor < T > constructor = returnType . getConstructor ( JSObject . class ) ; return constructor . newInstance ( ( JSObject ) returnObject ) ; } catch ( Exception ex ) { throw new IllegalStateException ( ex ) ; } } else { return ( T ) returnObject ; } }
Invokes a JavaScript function that takes no arguments .
21,262
protected Object checkUndefined ( Object val ) { if ( val instanceof String && ( ( String ) val ) . equals ( "undefined" ) ) { return null ; } return val ; }
JSObject will return the String undefined at certain times so we need to make sure we re not getting a value that looks valid but isn t .
21,263
protected Boolean checkBoolean ( Object val , Boolean def ) { return ( val == null ) ? def : ( Boolean ) val ; }
Checks a returned Javascript value where we expect a boolean but could get null .
21,264
public String registerHandler ( GFXEventHandler handler ) { String uuid = UUID . randomUUID ( ) . toString ( ) ; handlers . put ( uuid , handler ) ; return uuid ; }
Registers a handler and returns the callback key to be passed to Javascript .
21,265
public void handleStateEvent ( String callbackKey ) { if ( handlers . containsKey ( callbackKey ) && handlers . get ( callbackKey ) instanceof StateEventHandler ) { ( ( StateEventHandler ) handlers . get ( callbackKey ) ) . handle ( ) ; } else { System . err . println ( "Error in handle: " + callbackKey + " for state handler " ) ; } }
This method is called from Javascript passing in the previously created callback key . It uses that to find the correct handler and then passes on the call . State events in the Google Maps API don t pass any parameters .
21,266
public static final PolygonOptions buildClosedArc ( LatLong center , LatLong start , LatLong end , ArcType arcType ) { MVCArray res = buildArcPoints ( center , start , end ) ; if ( ArcType . ROUND . equals ( arcType ) ) { res . push ( center ) ; } return new PolygonOptions ( ) . paths ( res ) ; }
Builds the path for a closed arc returning a PolygonOptions that can be further customised before use .
21,267
public static final PolylineOptions buildOpenArc ( LatLong center , LatLong start , LatLong end ) { MVCArray res = buildArcPoints ( center , start , end ) ; return new PolylineOptions ( ) . path ( res ) ; }
Builds the path for an open arc based on a PolylineOptions .
21,268
public static final MVCArray buildArcPoints ( LatLong center , double startBearing , double endBearing , double radius ) { int points = DEFAULT_ARC_POINTS ; MVCArray res = new MVCArray ( ) ; if ( startBearing > endBearing ) { endBearing += 360.0 ; } double deltaBearing = endBearing - startBearing ; deltaBearing = deltaBearing / points ; for ( int i = 0 ; ( i < points + 1 ) ; i ++ ) { res . push ( center . getDestinationPoint ( startBearing + i * deltaBearing , radius ) ) ; } return res ; }
Generates the points for an arc based on two bearings from a centre point and a radius .
21,269
public LatLong getLocation ( ) { if ( location == null ) { location = new LatLong ( ( JSObject ) ( getJSObject ( ) . getMember ( "location" ) ) ) ; } return location ; }
The location for this elevation .
21,270
protected String getArgString ( Object arg ) { if ( arg instanceof JavascriptObject ) { return ( ( JavascriptObject ) arg ) . getVariableName ( ) ; } else if ( arg instanceof JavascriptEnum ) { return ( ( JavascriptEnum ) arg ) . getEnumValue ( ) . toString ( ) ; } else { return arg . toString ( ) ; } }
Takes the specified object and converts the argument to a String .
21,271
private String registerEventHandler ( GFXEventHandler h ) { if ( ! registeredOnJS ) { JSObject doc = ( JSObject ) runtime . execute ( "document" ) ; doc . setMember ( "jsHandlers" , jsHandlers ) ; registeredOnJS = true ; } return jsHandlers . registerHandler ( h ) ; }
Registers an event handler in the repository shared between Javascript and Java .
21,272
public void addUIEventHandler ( JavascriptObject obj , UIEventType type , UIEventHandler h ) { String key = registerEventHandler ( h ) ; String mcall = "google.maps.event.addListener(" + obj . getVariableName ( ) + ", '" + type . name ( ) + "', " + "function(event) {document.jsHandlers.handleUIEvent('" + key + "', event);});" ; runtime . execute ( mcall ) ; }
Adds a handler for a mouse type event on the map .
21,273
public double distanceFrom ( LatLong end ) { double dLat = ( end . getLatitude ( ) - getLatitude ( ) ) * Math . PI / 180 ; double dLon = ( end . getLongitude ( ) - getLongitude ( ) ) * Math . PI / 180 ; double a = Math . sin ( dLat / 2 ) * Math . sin ( dLat / 2 ) + Math . cos ( getLatitude ( ) * Math . PI / 180 ) * Math . cos ( end . getLatitude ( ) * Math . PI / 180 ) * Math . sin ( dLon / 2 ) * Math . sin ( dLon / 2 ) ; double c = 2.0 * Math . atan2 ( Math . sqrt ( a ) , Math . sqrt ( 1 - a ) ) ; double d = EarthRadiusMeters * c ; return d ; }
From v3_epoly . js calculates the distance between this LatLong point and another .
21,274
public LatLong getDestinationPoint ( double bearing , double distance ) { double brng = Math . toRadians ( bearing ) ; double lat1 = latToRadians ( ) ; double lon1 = longToRadians ( ) ; double lat2 = Math . asin ( Math . sin ( lat1 ) * Math . cos ( distance / EarthRadiusMeters ) + Math . cos ( lat1 ) * Math . sin ( distance / EarthRadiusMeters ) * Math . cos ( brng ) ) ; double lon2 = lon1 + Math . atan2 ( Math . sin ( brng ) * Math . sin ( distance / EarthRadiusMeters ) * Math . cos ( lat1 ) , Math . cos ( distance / EarthRadiusMeters ) - Math . sin ( lat1 ) * Math . sin ( lat2 ) ) ; return new LatLong ( Math . toDegrees ( lat2 ) , Math . toDegrees ( lon2 ) ) ; }
Calculates the LatLong position of the end point of a line the specified distance from this LatLong along the provided bearing where North is 0 East is 90 etc .
21,275
public double getBearing ( LatLong end ) { if ( this . equals ( end ) ) { return 0 ; } double lat1 = latToRadians ( ) ; double lon1 = longToRadians ( ) ; double lat2 = end . latToRadians ( ) ; double lon2 = end . longToRadians ( ) ; double angle = - Math . atan2 ( Math . sin ( lon1 - lon2 ) * Math . cos ( lat2 ) , Math . cos ( lat1 ) * Math . sin ( lat2 ) - Math . sin ( lat1 ) * Math . cos ( lat2 ) * Math . cos ( lon1 - lon2 ) ) ; if ( angle < 0.0 ) { angle += Math . PI * 2.0 ; } if ( angle > Math . PI ) { angle -= Math . PI * 2.0 ; } return Math . toDegrees ( angle ) ; }
Calculates the bearing in degrees of the end LatLong point from this LatLong point .
21,276
public void getElevationForLocations ( LocationElevationRequest req , ElevationServiceCallback callback ) { this . callback = callback ; JSObject doc = ( JSObject ) getJSObject ( ) . eval ( "document" ) ; doc . setMember ( getVariableName ( ) , this ) ; StringBuilder r = new StringBuilder ( getVariableName ( ) ) . append ( "." ) . append ( "getElevationForLocations(" ) . append ( req . getVariableName ( ) ) . append ( ", " ) . append ( "function(results, status) {alert('rec:'+status);\ndocument." ) . append ( getVariableName ( ) ) . append ( ".processResponse(results, status);});" ) ; LOG . trace ( "ElevationService direct call: " + r . toString ( ) ) ; getJSObject ( ) . eval ( r . toString ( ) ) ; }
Create a request for elevations for multiple locations .
21,277
public void getElevationAlongPath ( PathElevationRequest req , ElevationServiceCallback callback ) { this . callback = callback ; JSObject doc = ( JSObject ) getJSObject ( ) . eval ( "document" ) ; doc . setMember ( getVariableName ( ) , this ) ; StringBuilder r = new StringBuilder ( getVariableName ( ) ) . append ( "." ) . append ( "getElevationAlongPath(" ) . append ( req . getVariableName ( ) ) . append ( ", " ) . append ( "function(results, status) {document." ) . append ( getVariableName ( ) ) . append ( ".processResponse(results, status);});" ) ; getJSObject ( ) . eval ( r . toString ( ) ) ; }
Create a request for elevations for samples along a path .
21,278
public static double distance ( double lat1 , double lon1 , double lat2 , double lon2 ) { double dLat = Math . toRadians ( lat2 - lat1 ) ; double dLon = Math . toRadians ( lon2 - lon1 ) ; lat1 = Math . toRadians ( lat1 ) ; lat2 = Math . toRadians ( lat2 ) ; double a = Math . sin ( dLat / 2 ) * Math . sin ( dLat / 2 ) + Math . sin ( dLon / 2 ) * Math . sin ( dLon / 2 ) * Math . cos ( lat1 ) * Math . cos ( lat2 ) ; double c = 2 * Math . atan2 ( Math . sqrt ( a ) , Math . sqrt ( 1 - a ) ) ; return R * c ; }
Returns the distance between the two points in meters .
21,279
public static String soundex ( String str ) { if ( str . length ( ) < 1 ) return "" ; char [ ] key = new char [ 4 ] ; key [ 0 ] = str . charAt ( 0 ) ; int pos = 1 ; char prev = '0' ; for ( int ix = 1 ; ix < str . length ( ) && pos < 4 ; ix ++ ) { char ch = str . charAt ( ix ) ; int charno ; if ( ch >= 'A' && ch <= 'Z' ) charno = ch - 'A' ; else if ( ch >= 'a' && ch <= 'z' ) charno = ch - 'a' ; else continue ; if ( number [ charno ] != '0' && number [ charno ] != prev ) key [ pos ++ ] = number [ charno ] ; prev = number [ charno ] ; } for ( ; pos < 4 ; pos ++ ) key [ pos ] = '0' ; return new String ( key ) ; }
Produces the Soundex key for the given string .
21,280
private static char [ ] buildTable ( ) { char [ ] table = new char [ 26 ] ; for ( int ix = 0 ; ix < table . length ; ix ++ ) table [ ix ] = '0' ; table [ 'B' - 'A' ] = '1' ; table [ 'P' - 'A' ] = '1' ; table [ 'F' - 'A' ] = '1' ; table [ 'V' - 'A' ] = '1' ; table [ 'C' - 'A' ] = '2' ; table [ 'S' - 'A' ] = '2' ; table [ 'K' - 'A' ] = '2' ; table [ 'G' - 'A' ] = '2' ; table [ 'J' - 'A' ] = '2' ; table [ 'Q' - 'A' ] = '2' ; table [ 'X' - 'A' ] = '2' ; table [ 'Z' - 'A' ] = '2' ; table [ 'D' - 'A' ] = '3' ; table [ 'T' - 'A' ] = '3' ; table [ 'L' - 'A' ] = '4' ; table [ 'M' - 'A' ] = '5' ; table [ 'N' - 'A' ] = '5' ; table [ 'R' - 'A' ] = '6' ; return table ; }
Builds the mapping table .
21,281
private void addStatement ( RecordImpl record , String subject , String property , String object ) { Collection < Column > cols = columns . get ( property ) ; if ( cols == null ) { if ( property . equals ( RDF_TYPE ) && ! types . isEmpty ( ) ) addValue ( record , subject , property , object ) ; return ; } for ( Column col : cols ) { String cleaned = object ; if ( col . getCleaner ( ) != null ) cleaned = col . getCleaner ( ) . clean ( object ) ; if ( cleaned != null && ! cleaned . equals ( "" ) ) addValue ( record , subject , col . getProperty ( ) , cleaned ) ; } }
common utility method for adding a statement to a record
21,282
public Filter geoSearch ( String value ) { GeopositionComparator comp = ( GeopositionComparator ) prop . getComparator ( ) ; double dist = comp . getMaxDistance ( ) ; double degrees = DistanceUtils . dist2Degrees ( dist , DistanceUtils . EARTH_MEAN_RADIUS_KM * 1000.0 ) ; Shape circle = spatialctx . makeCircle ( parsePoint ( value ) , degrees ) ; SpatialArgs args = new SpatialArgs ( SpatialOperation . Intersects , circle ) ; return strategy . makeFilter ( args ) ; }
Returns a geoquery .
21,283
private Point parsePoint ( String point ) { int comma = point . indexOf ( ',' ) ; if ( comma == - 1 ) return null ; float lat = Float . valueOf ( point . substring ( 0 , comma ) ) ; float lng = Float . valueOf ( point . substring ( comma + 1 ) ) ; return spatialctx . makePoint ( lng , lat ) ; }
Parses coordinates into a Spatial4j point shape .
21,284
public static Statement open ( String jndiPath ) { try { Context ctx = new InitialContext ( ) ; DataSource ds = ( DataSource ) ctx . lookup ( jndiPath ) ; Connection conn = ds . getConnection ( ) ; return conn . createStatement ( ) ; } catch ( NamingException e ) { throw new DukeException ( "No database configuration found via JNDI at " + jndiPath , e ) ; } catch ( SQLException e ) { throw new DukeException ( "Error connecting to database via " + jndiPath , e ) ; } }
Get a configured database connection via JNDI .
21,285
public static Statement open ( String driverklass , String jdbcuri , Properties props ) { try { Driver driver = ( Driver ) ObjectUtils . instantiate ( driverklass ) ; Connection conn = driver . connect ( jdbcuri , props ) ; if ( conn == null ) throw new DukeException ( "Couldn't connect to database at " + jdbcuri ) ; return conn . createStatement ( ) ; } catch ( SQLException e ) { throw new DukeException ( e ) ; } }
Opens a JDBC connection with the given parameters .
21,286
public static void close ( Statement stmt ) { try { Connection conn = stmt . getConnection ( ) ; try { if ( ! stmt . isClosed ( ) ) stmt . close ( ) ; } catch ( UnsupportedOperationException e ) { stmt . close ( ) ; } if ( conn != null && ! conn . isClosed ( ) ) conn . close ( ) ; } catch ( SQLException e ) { throw new DukeException ( e ) ; } }
Closes the JDBC statement and its associated connection .
21,287
public static boolean validate ( Statement stmt ) { try { Connection conn = stmt . getConnection ( ) ; if ( conn == null ) return false ; if ( ! conn . isClosed ( ) && conn . isValid ( 10 ) ) return true ; stmt . close ( ) ; conn . close ( ) ; } catch ( SQLException e ) { } return false ; }
Verifies that the connection is still alive . Returns true if it is false if it is not . If the connection is broken we try closing everything too so that the caller need only open a new connection .
21,288
public static int queryForInt ( Statement stmt , String sql , int nullvalue ) { try { ResultSet rs = stmt . executeQuery ( sql ) ; try { if ( ! rs . next ( ) ) return nullvalue ; return rs . getInt ( 1 ) ; } finally { rs . close ( ) ; } } catch ( SQLException e ) { throw new DukeException ( e ) ; } }
Runs a query that returns a single int .
21,289
public static boolean queryHasResult ( Statement stmt , String sql ) { try { ResultSet rs = stmt . executeQuery ( sql ) ; try { return rs . next ( ) ; } finally { rs . close ( ) ; } } catch ( SQLException e ) { throw new DukeException ( e ) ; } }
Returns true if the query result has at least one row .
21,290
public static String replaceAnyOf ( String value , String chars , char replacement ) { char [ ] tmp = new char [ value . length ( ) ] ; int pos = 0 ; for ( int ix = 0 ; ix < tmp . length ; ix ++ ) { char ch = value . charAt ( ix ) ; if ( chars . indexOf ( ch ) != - 1 ) tmp [ pos ++ ] = replacement ; else tmp [ pos ++ ] = ch ; } return new String ( tmp , 0 , tmp . length ) ; }
Replaces all characters in the second parameter found in the first parameter with the final character .
21,291
public static String normalizeWS ( String value ) { char [ ] tmp = new char [ value . length ( ) ] ; int pos = 0 ; boolean prevws = false ; for ( int ix = 0 ; ix < tmp . length ; ix ++ ) { char ch = value . charAt ( ix ) ; if ( ch != ' ' && ch != '\t' && ch != '\n' && ch != '\r' ) { if ( prevws && pos != 0 ) tmp [ pos ++ ] = ' ' ; tmp [ pos ++ ] = ch ; prevws = false ; } else prevws = true ; } return new String ( tmp , 0 , pos ) ; }
Removes trailing and leading whitespace and also reduces each sequence of internal whitespace to a single space .
21,292
public static String get ( Properties props , String name , String defval ) { String value = props . getProperty ( name ) ; if ( value == null ) value = defval ; return value ; }
Returns the value of an optional property if the property is set . If it is not set defval is returned .
21,293
public Collection < DataSource > getDataSources ( int groupno ) { if ( groupno == 1 ) return group1 ; else if ( groupno == 2 ) return group2 ; else throw new DukeConfigException ( "Invalid group number: " + groupno ) ; }
Returns the data sources belonging to a particular group of data sources . Data sources are grouped in record linkage mode but not in deduplication mode so only use this method in record linkage mode .
21,294
public void addDataSource ( int groupno , DataSource datasource ) { if ( groupno == 0 ) datasources . add ( datasource ) ; else if ( groupno == 1 ) group1 . add ( datasource ) ; else if ( groupno == 2 ) group2 . add ( datasource ) ; }
Adds a data source to the configuration . If in deduplication mode groupno == 0 otherwise it gives the number of the group to which the data source belongs .
21,295
public double compare ( String v1 , String v2 ) { if ( comparator == null ) return 0.5 ; double sim = comparator . compare ( v1 , v2 ) ; if ( sim >= 0.5 ) return ( ( high - 0.5 ) * ( sim * sim ) ) + 0.5 ; else return low ; }
Returns the probability that the records v1 and v2 came from represent the same entity based on high and low probability settings etc .
21,296
public SparqlResult runQuery ( String endpoint , String query ) { return SparqlClient . execute ( endpoint , query , username , password ) ; }
An extension point so we can control how the query gets executed . This exists for testing purposes not because we believe it will actually be used for real .
21,297
private void merge ( Integer cid1 , Integer cid2 ) { Collection < String > klass1 = classix . get ( cid1 ) ; Collection < String > klass2 = classix . get ( cid2 ) ; if ( klass1 . size ( ) < klass2 . size ( ) ) { Collection < String > tmp = klass2 ; klass2 = klass1 ; klass1 = tmp ; Integer itmp = cid2 ; cid2 = cid1 ; cid1 = itmp ; } for ( String id : klass2 ) { klass1 . add ( id ) ; recordix . put ( id , cid1 ) ; } classix . remove ( cid2 ) ; }
Merges the two classes into a single class . The smaller class is removed while the largest class is kept .
21,298
private void bumpScores ( Map < Long , Score > candidates , List < Bucket > buckets , int ix ) { for ( ; ix < buckets . size ( ) ; ix ++ ) { Bucket b = buckets . get ( ix ) ; if ( b . nextfree > CUTOFF_FACTOR_2 * candidates . size ( ) ) return ; double score = b . getScore ( ) ; for ( Score s : candidates . values ( ) ) if ( b . contains ( s . id ) ) s . score += score ; } }
Goes through the buckets from ix and out checking for each candidate if it s in one of the buckets and if so increasing its score accordingly . No new candidates are added .
21,299
private int collectCandidates ( Map < Long , Score > candidates , List < Bucket > buckets , int threshold ) { int ix ; for ( ix = 0 ; ix < threshold && candidates . size ( ) < ( CUTOFF_FACTOR_1 * max_search_hits ) ; ix ++ ) { Bucket b = buckets . get ( ix ) ; long [ ] ids = b . records ; double score = b . getScore ( ) ; for ( int ix2 = 0 ; ix2 < b . nextfree ; ix2 ++ ) { Score s = candidates . get ( ids [ ix2 ] ) ; if ( s == null ) { s = new Score ( ids [ ix2 ] ) ; candidates . put ( ids [ ix2 ] , s ) ; } s . score += score ; } if ( DEBUG ) System . out . println ( "Bucket " + b . nextfree + " -> " + candidates . size ( ) ) ; } return ix ; }
Goes through the first buckets picking out candidate records and tallying up their scores .