idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
500
final boolean hasNoMajorSolarTerm ( long utcDays ) { double jd0 = JulianDay . ofEphemerisTime ( this . midnight ( utcDays ) ) . getValue ( ) ; int index0 = ( 2 + ( int ) Math . floor ( SolarTerm . solarLongitude ( jd0 ) / 30 ) ) % 12 ; double jd1 = JulianDay . ofEphemerisTime ( this . midnight ( this . newMoonOnOrAfter...
leap months have no major solar terms
501
private long newYearInSui ( long utcDays ) { long s1 = this . winterOnOrBefore ( utcDays ) ; long s2 = this . winterOnOrBefore ( s1 + 370 ) ; long m12 = this . newMoonOnOrAfter ( s1 + 1 ) ; long m13 = this . newMoonOnOrAfter ( m12 + 1 ) ; long nextM11 = this . newMoonBefore ( s2 + 1 ) ; if ( ( lunations ( m12 , nextM11...
a sui is the period from one winter to next winter ensuring that winter solstice is always in 11th month
502
private long newYearOnOrBefore ( long utcDays ) { long ny = this . newYearInSui ( utcDays ) ; if ( utcDays >= ny ) { return ny ; } else { return this . newYearInSui ( utcDays - 180 ) ; } }
start of lunisolar year
503
private boolean hasLeapMonth ( long m0 , long m ) { return ( ( m >= m0 ) && ( this . hasNoMajorSolarTerm ( m ) || this . hasLeapMonth ( m0 , this . newMoonBefore ( m ) ) ) ) ; }
is there any leap month between m0 and m?
504
private long winterOnOrBefore ( long utcDays ) { ZonalOffset offset = this . getOffset ( utcDays ) ; PlainDate date = PlainDate . of ( utcDays , EpochDays . UTC ) ; int year = ( ( ( date . getMonth ( ) <= 11 ) || ( date . getDayOfMonth ( ) <= 15 ) ) ? date . getYear ( ) - 1 : date . getYear ( ) ) ; Moment winter = Astr...
search for winter solstice
505
private static int search ( long utcDays , long [ ] firstOfMonth ) { int low = 0 ; int high = firstOfMonth . length - 1 ; while ( low <= high ) { int middle = ( low + high ) / 2 ; if ( firstOfMonth [ middle ] <= utcDays ) { low = middle + 1 ; } else { high = middle - 1 ; } } return low - 1 ; }
returns index of month - start associated with utcDays
506
private static double decode ( byte [ ] data , int pointer ) { long ntp = 0L ; for ( int i = 0 ; i < 8 ; i ++ ) { long unsigned = ( data [ i + pointer ] & 0xFF ) ; ntp |= ( unsigned << ( 56 - i * 8 ) ) ; } long integer = ( ( ntp >>> 32 ) & 0xFFFFFFFFL ) ; long fraction = ( ( ( ntp & 0xFFFFFFFFL ) * MIO ) >>> 32 ) ; lon...
NTP - Timestamp aus byte - Array dekodieren
507
private static void encode ( byte [ ] data , int pointer , double timestamp ) { long ut1 = convert ( timestamp ) ; boolean before2036 = ( ut1 + OFFSET_2036 < 0 ) ; long micros ; if ( before2036 ) { micros = ut1 + OFFSET_1900 ; } else { micros = ut1 + OFFSET_2036 ; } long integer = micros / MIO ; long fraction = ( ( mic...
NTP - Timestamp als byte - Array kodieren
508
private static Object readBoundary ( ObjectInput in , byte header ) throws IOException , ClassNotFoundException { int past = ( header & 0x1 ) ; if ( past == 1 ) { return Boundary . infinitePast ( ) ; } int future = ( header & 0x2 ) ; if ( future == 2 ) { return Boundary . infiniteFuture ( ) ; } int openClosed = in . re...
serialization of a single boundary object
509
MomentInterval in ( Timezone tz ) { Boundary < Moment > b1 ; Boundary < Moment > b2 ; if ( this . getStart ( ) . isInfinite ( ) ) { b1 = Boundary . infinitePast ( ) ; } else { Moment m1 = this . getStart ( ) . getTemporal ( ) . in ( tz ) ; b1 = Boundary . of ( this . getStart ( ) . getEdge ( ) , m1 ) ; } if ( this . ge...
combines this local timestamp interval with given timezone to a global UTC - interval
510
static double getValue ( Moment moment , TimeScale scale ) { long elapsedTime = moment . getElapsedTime ( scale ) + jdOffset ( scale ) ; int nano = moment . getNanosecond ( scale ) ; double secs = elapsedTime + nano / ( MRD * 1.0 ) ; return secs / DAY_IN_SECONDS ; }
obtains the JD - value for given moment and scale
511
static DayPeriod of ( Locale locale , String calendarType ) { String lang = locale . getLanguage ( ) ; if ( lang . equals ( "nn" ) ) { locale = new Locale ( "nb" ) ; } Map < String , String > resourceMap = loadTextForms ( locale , calendarType ) ; SortedMap < PlainTime , String > codeMap = Collections . emptySortedMap ...
package - private because used in deserialization
512
double getHighestElevationOfSun ( PlainDate date ) { Moment noon = date . get ( this . transitAtNoon ( ) ) ; double jde = JulianDay . getValue ( noon , TimeScale . TT ) ; double decInRad = Math . toRadians ( this . getCalculator ( ) . getFeature ( jde , DECLINATION ) ) ; double latInRad = Math . toRadians ( this . lati...
used in test classes too
513
HistoricEra getPreferredEra ( HistoricDate hd , PlainDate date ) { if ( ( this . era == null ) || date . isBefore ( this . start ) || date . isAfter ( this . end ) ) { return ( ( hd . compareTo ( AD1 ) < 0 ) ? HistoricEra . BC : HistoricEra . AD ) ; } else if ( ( this . era == HistoricEra . HISPANIC ) && ( hd . compare...
determines the preferred era for a given historic date
514
void dump ( int size , Appendable buffer ) throws IOException { for ( int i = 0 ; i < size ; i ++ ) { ZonalTransition transition = this . transitions [ i ] ; TransitionModel . dump ( transition , buffer ) ; } }
Called by CompositeTransitionModel
515
private static int search ( long posixTime , ZonalTransition [ ] transitions ) { int low = 0 ; int high = transitions . length - 1 ; while ( low <= high ) { int middle = ( low + high ) / 2 ; if ( transitions [ middle ] . getPosixTime ( ) <= posixTime ) { low = middle + 1 ; } else { high = middle - 1 ; } } return low ; ...
returns index of first transition after posixTime
516
private static int searchLocal ( long localSecs , ZonalTransition [ ] transitions ) { int low = 0 ; int high = transitions . length - 1 ; while ( low <= high ) { int middle = ( low + high ) / 2 ; ZonalTransition zt = transitions [ middle ] ; int offset = Math . max ( zt . getTotalOffset ( ) , zt . getPreviousOffset ( )...
returns index of first transition after local date and time
517
< V > ElementRule < T , V > getRule ( ChronoElement < V > element ) { return this . getChronology ( ) . getRule ( element ) ; }
Determines the associated element rule .
518
int getValue ( ) { if ( this . matches ( Selector . NORTHERN_COURT ) ) { return ( this . index - NORTHERN_NENGOS . length + NENGO_OEI . index - Nengo . SHOWA . index + 1 ) ; } return ( this . index - Nengo . SHOWA . index + 1 ) ; }
verwendet in JapaneseCalendar
519
static long transform ( int relgregyear , int dayOfYear ) { if ( relgregyear >= 1873 ) { return PlainDate . of ( relgregyear , dayOfYear ) . getDaysSinceEpochUTC ( ) ; } else { return START_OF_YEAR [ relgregyear - 701 ] + dayOfYear - 1 ; } }
also used in serialization
520
int getPrefixedDigitArea ( ) { if ( this . multi == null ) { return 0 ; } int digits = 0 ; for ( int i = 0 , n = this . multi . length ( ) ; i < n && Character . isDigit ( this . multi . charAt ( i ) ) ; i ++ ) { digits ++ ; } return digits ; }
count of leading digits
521
static int subSequenceEquals ( CharSequence test , int offset , CharSequence expected , boolean caseInsensitive , boolean rtl ) { int j = 0 ; int max = test . length ( ) ; int len = expected . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) { char c = '\u0000' ; char exp = expected . charAt ( i ) ; if ( isBidi ( exp ) ...
also used by LocalizedGMTProcessor
522
ChronoFormatter < T > with ( Map < ChronoElement < ? > , Object > outerDefaults , AttributeSet outerAttrs ) { AttributeSet merged = AttributeSet . merge ( outerAttrs , this . globalAttributes ) ; return new ChronoFormatter < > ( new ChronoFormatter < > ( this , outerDefaults ) , merged , merged . get ( HistoricAttribut...
used by CustomizedProcessor
523
static boolean hasUnixChronology ( Chronology < ? > chronology ) { Chronology < ? > c = chronology ; do { if ( UnixTime . class . isAssignableFrom ( c . getChronoType ( ) ) ) { return true ; } } while ( ( c = c . preparser ( ) ) != null ) ; return false ; }
also called in PatternType
524
private static double sinAlt ( double mjd0 , double hour , double longitudeRad , double cosLatitude , double sinLatitude , double geodeticAngle , double refraction , double deltaT ) { double mjd = mjd0 + hour / 24.0 ; double jct = toJulianCenturies ( mjd + ( deltaT / 86400 ) ) ; double [ ] data = MoonPosition . calcula...
sinus of moon altitude above or below horizon
525
public static String removeZones ( String pattern ) { boolean literal = false ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 , n = pattern . length ( ) ; i < n ; i ++ ) { char c = pattern . charAt ( i ) ; if ( c == '\'' ) { if ( i + 1 < n && pattern . charAt ( i + 1 ) == '\'' ) { sb . append ( c ) ; i ++ ...
Strips off any timezone symbols in clock time patterns .
526
static void printNanos ( StringBuilder sb , int nano ) { sb . append ( PlainTime . ISO_DECIMAL_SEPARATOR ) ; String num = Integer . toString ( nano ) ; int len ; if ( ( nano % MIO ) == 0 ) { len = 3 ; } else if ( ( nano % KILO ) == 0 ) { len = 6 ; } else { len = 9 ; } for ( int i = num . length ( ) ; i < 9 ; i ++ ) { s...
also called by ZonalDateTime
527
static AttributeSet merge ( AttributeSet outer , AttributeSet inner ) { Map < String , Object > internalsNew = new HashMap < > ( ) ; internalsNew . putAll ( inner . internals ) ; internalsNew . putAll ( outer . internals ) ; Attributes attributesNew = new Attributes . Builder ( ) . setAll ( inner . attributes ) . setAl...
used to create merged global attributes for a new formatter
528
void reset ( ) { if ( this . keys == null ) { this . len = Integer . MIN_VALUE ; this . mask = Integer . MIN_VALUE ; this . threshold = Integer . MIN_VALUE ; this . count = Integer . MIN_VALUE ; for ( int i = 0 ; i < 3 ; i ++ ) { this . ints [ i ] = Integer . MIN_VALUE ; } this . map = null ; } else { this . keys = new...
called in context of erraneous or - block
529
static int parsePeriod ( String period , char symbol ) throws ParseException { if ( period . isEmpty ( ) ) { throw new ParseException ( "Empty period." , 0 ) ; } boolean negative = false ; int index = 0 ; int len = period . length ( ) ; if ( period . charAt ( 0 ) == '-' ) { index ++ ; negative = true ; } if ( ( index <...
called by subclasses
530
static void writeTransitions ( ZonalTransition [ ] transitions , int size , DataOutput out ) throws IOException { int n = Math . min ( size , transitions . length ) ; out . writeInt ( n ) ; if ( n > 0 ) { int stdOffset = transitions [ 0 ] . getPreviousOffset ( ) ; writeOffset ( out , stdOffset ) ; for ( int i = 0 ; i <...
called by ArrayTransitionModel
531
protected TextAccessor accessor ( AttributeQuery attributes , OutputContext outputContext , boolean leap ) { Locale lang = attributes . get ( Attributes . LANGUAGE , Locale . ROOT ) ; TextWidth textWidth = attributes . get ( Attributes . TEXT_WIDTH , TextWidth . WIDE ) ; CalendarText cnames = CalendarText . getInstance...
Might be overridden in special cases .
532
static HijriAdjustment from ( String variant ) { int index = variant . indexOf ( ':' ) ; if ( index == - 1 ) { return new HijriAdjustment ( variant , 0 ) ; } else { try { int adjustment = Integer . parseInt ( variant . substring ( index + 1 ) ) ; return new HijriAdjustment ( variant . substring ( 0 , index ) , adjustme...
also called by Hijri calendar systems
533
private int unFilledSpacesInHeaderGroup ( int header ) { if ( mNumColumns == 0 ) { return 0 ; } int remainder = mDelegate . getCountForHeader ( header ) % mNumColumns ; return remainder == 0 ? 0 : mNumColumns - remainder ; }
Counts the number of items that would be need to fill out the last row in the group of items with the given header .
534
public View getHeaderAt ( int position ) { if ( position == MATCHED_STICKIED_HEADER ) { return mStickiedHeader ; } try { return ( View ) getChildAt ( position ) . getTag ( ) ; } catch ( Exception e ) { } return null ; }
Gets the header at an item position . However the position must be that of a HeaderFiller .
535
@ TargetApi ( Build . VERSION_CODES . HONEYCOMB ) public void setActivateOnItemClick ( boolean activateOnItemClick ) { if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . HONEYCOMB ) { mGridView . setChoiceMode ( activateOnItemClick ? ListView . CHOICE_MODE_SINGLE : ListView . CHOICE_MODE_NONE ) ; } }
Turns on activate - on - click mode . When this mode is on list items will be given the activated state when touched .
536
@ TargetApi ( Build . VERSION_CODES . ICE_CREAM_SANDWICH ) void addScrapView ( View scrap , int position , int viewType ) { Scrap item = new Scrap ( scrap , true ) ; if ( viewTypeCount == 1 ) { currentScraps . put ( position , item ) ; } else { scraps [ viewType ] . put ( position , item ) ; } if ( Build . VERSION . SD...
Put a view into the ScrapViews list . These views are unordered .
537
private void setDrawWithLayer ( View v , boolean drawWithLayer ) { if ( isHardwareAccelerated ( ) ) { if ( v . getLayerType ( ) != LAYER_TYPE_HARDWARE && drawWithLayer ) { v . setLayerType ( LAYER_TYPE_HARDWARE , null ) ; } else if ( v . getLayerType ( ) != LAYER_TYPE_NONE && ! drawWithLayer ) { v . setLayerType ( LAYE...
Enable a hardware layer for the view .
538
public static Parser < Void > many ( CharPredicate predicate ) { return Patterns . isChar ( predicate ) . many ( ) . toScanner ( predicate + "*" ) ; }
A scanner that scans greedily for 0 or more characters that satisfies the given CharPredicate .
539
public static Parser < Void > many1 ( CharPredicate predicate ) { return Patterns . many1 ( predicate ) . toScanner ( predicate + "+" ) ; }
A scanner that scans greedily for 1 or more characters that satisfies the given CharPredicate .
540
public static Parser < Void > many1 ( Pattern pattern , String name ) { return pattern . many1 ( ) . toScanner ( name ) ; }
A scanner that scans greedily for 1 or more occurrences of the given pattern .
541
public static Parser < Void > stringCaseInsensitive ( String str ) { return Patterns . stringCaseInsensitive ( str ) . toScanner ( str ) ; }
A scanner that matches the input against the specified string case insensitively .
542
public static void checkState ( boolean condition , String message , Object ... args ) throws IllegalStateException { if ( ! condition ) { throw new IllegalStateException ( String . format ( message , args ) ) ; } }
Checks a certain state .
543
static Parser < Expression > simpleNewExpression ( Parser < Expression > arg , Parser < DefBody > body ) { return Parsers . sequence ( term ( "new" ) . next ( TypeLiteralParser . ELEMENT_TYPE_LITERAL ) , argumentList ( arg ) , body . optional ( ) , ( type , args , defBody ) -> new NewExpression ( null , type , args , d...
new a class instance
544
public OperatorTable < T > prefix ( Parser < ? extends Function < ? super T , ? extends T > > parser , int precedence ) { ops . add ( new Operator ( parser , precedence , Associativity . PREFIX ) ) ; return this ; }
Adds a prefix unary operator .
545
public OperatorTable < T > postfix ( Parser < ? extends Function < ? super T , ? extends T > > parser , int precedence ) { ops . add ( new Operator ( parser , precedence , Associativity . POSTFIX ) ) ; return this ; }
Adds a postfix unary operator .
546
public OperatorTable < T > infixl ( Parser < ? extends BiFunction < ? super T , ? super T , ? extends T > > parser , int precedence ) { ops . add ( new Operator ( parser , precedence , Associativity . LASSOC ) ) ; return this ; }
Adds an infix left - associative binary operator .
547
public OperatorTable < T > infixr ( Parser < ? extends BiFunction < ? super T , ? super T , ? extends T > > parser , int precedence ) { ops . add ( new Operator ( parser , precedence , Associativity . RASSOC ) ) ; return this ; }
Adds an infix right - associative binary operator .
548
public OperatorTable < T > infixn ( Parser < ? extends BiFunction < ? super T , ? super T , ? extends T > > parser , int precedence ) { ops . add ( new Operator ( parser , precedence , Associativity . NASSOC ) ) ; return this ; }
Adds an infix non - associative binary operator .
549
public static long cleartextSize ( long ciphertextSize , Cryptor cryptor ) { checkArgument ( ciphertextSize >= 0 , "expected ciphertextSize to be positive, but was %s" , ciphertextSize ) ; long cleartextChunkSize = cryptor . fileContentCryptor ( ) . cleartextChunkSize ( ) ; long ciphertextChunkSize = cryptor . fileCont...
Calculates the size of the cleartext resulting from the given ciphertext decrypted with the given cryptor .
550
public static long ciphertextSize ( long cleartextSize , Cryptor cryptor ) { checkArgument ( cleartextSize >= 0 , "expected cleartextSize to be positive, but was %s" , cleartextSize ) ; long cleartextChunkSize = cryptor . fileContentCryptor ( ) . cleartextChunkSize ( ) ; long ciphertextChunkSize = cryptor . fileContent...
Calculates the size of the ciphertext resulting from the given cleartext encrypted with the given cryptor .
551
public static int copy ( ByteBuffer source , ByteBuffer destination ) { final int numBytes = Math . min ( source . remaining ( ) , destination . remaining ( ) ) ; final ByteBuffer tmp = source . asReadOnlyBuffer ( ) ; tmp . limit ( tmp . position ( ) + numBytes ) ; destination . put ( tmp ) ; source . position ( tmp . ...
Copies as many bytes as possible from the given source to the destination buffer . The position of both buffers will be incremented by as many bytes as have been copied .
552
public static KeyFile parse ( byte [ ] serialized ) { try ( InputStream in = new ByteArrayInputStream ( serialized ) ; Reader reader = new InputStreamReader ( in , UTF_8 ) ; JsonReader jsonReader = GSON . newJsonReader ( reader ) ) { JsonObject jsonObj = new JsonParser ( ) . parse ( jsonReader ) . getAsJsonObject ( ) ;...
Parses a json keyfile .
553
public < T extends KeyFile > T as ( Class < T > clazz ) { T result = GSON . fromJson ( jsonObj , clazz ) ; ( ( KeyFile ) result ) . jsonObj = jsonObj ; return result ; }
Creates a new version - specific KeyFile instance from this instance .
554
public static < T > void register ( Class < T > pluginClass , T pluginImpl ) throws IllegalStateException { INSTANCE . registerInternal ( pluginClass , pluginImpl ) ; }
Registers an implementation as a global override of any injected or default implementations .
555
private static Object getPluginImplementationViaProperty ( Class < ? > pluginClass ) { String className = pluginClass . getCanonicalName ( ) ; if ( className == null ) { throw new IllegalArgumentException ( "Class " + pluginClass + " does not have a canonical name!" ) ; } String implementingClass = System . getProperty...
Returns an implementation of the given class using the system properties as a registry .
556
public static < T > Function < T , Boolean > forPredicate ( Predicate < T > predicate ) { return predicate :: test ; }
Creates a function that returns the same boolean output as the given predicate for all inputs .
557
public final Optional < L > asOptionalLeft ( ) { return fold ( Optional :: of , val -> Optional . < L > empty ( ) ) ; }
Returns the left side as an Optional .
558
public final Optional < R > asOptionalRight ( ) { return fold ( val -> Optional . < R > empty ( ) , Optional :: of ) ; }
Returns the right side as an Optional .
559
public final < T > T fold ( Function < ? super L , ? extends T > left , Function < ? super R , ? extends T > right ) { if ( isLeft ( ) ) { return left . apply ( getLeft ( ) ) ; } else { return right . apply ( getRight ( ) ) ; } }
Applies either the left or the right function as appropriate .
560
public final void accept ( Consumer < ? super L > left , Consumer < ? super R > right ) { if ( isLeft ( ) ) { left . accept ( getLeft ( ) ) ; } else { right . accept ( getRight ( ) ) ; } }
Accepts either the left or the right consumer as appropriate .
561
public final void acceptBoth ( Consumer < ? super L > left , Consumer < ? super R > right , L defaultLeft , R defaultRight ) { left . accept ( isLeft ( ) ? getLeft ( ) : defaultLeft ) ; right . accept ( isRight ( ) ? getRight ( ) : defaultRight ) ; }
Accepts both the left and right consumers using the default values to set the empty side .
562
public static < L , R > Either < L , R > create ( L l , R r ) { if ( l == null && r != null ) { return createRight ( r ) ; } else if ( l != null && r == null ) { return createLeft ( l ) ; } else { if ( l == null ) { throw new IllegalArgumentException ( "Both arguments were null." ) ; } else { throw new IllegalArgumentE...
Creates a left or right depending on which element is non - null . Precisely one element should be non - null .
563
public static < L , R > Either < L , R > createLeft ( L l ) { return new Left < > ( l ) ; }
Creates an instance of Left .
564
public static < L , R > Either < L , R > createRight ( R r ) { return new Right < > ( r ) ; }
Creates an instance of Right .
565
public TreeComparison < E , A > decorateErrorsWith ( Function < ? super E , String > expectedToString , Function < ? super A , String > actualToString ) { this . expectedToString = expectedToString ; this . actualToString = actualToString ; return this ; }
Decorates errors thrown by any assertions with the given functions .
566
private AssertionError createComparisonFailure ( String className , String expected , String actual ) throws Exception { Class < ? > clazz = Class . forName ( className ) ; Constructor < ? > constructor = clazz . getConstructor ( String . class , String . class , String . class ) ; return ( AssertionError ) constructor...
Attempts to create an instance of junit s ComparisonFailure exception using reflection .
567
public < T > SameType < T > mapToSame ( Function < ? super E , ? extends T > mapExpected , Function < ? super A , ? extends T > mapActual ) { return new SameTypeImp < > ( this , mapExpected , mapActual ) ; }
Maps both sides of the comparison to the same type for easier comparison and assertions .
568
public void sortChildrenByContent ( Comparator < ? super T > comparator ) { Comparator < TreeNode < T > > byContent = Comparator . comparing ( TreeNode :: getContent , comparator ) ; sortChildrenByNode ( byContent ) ; }
Recursively sorts all children using the given comparator of their content .
569
public void sortChildrenByNode ( Comparator < TreeNode < T > > comparator ) { Collections . sort ( children , comparator ) ; for ( TreeNode < T > child : children ) { child . sortChildrenByNode ( comparator ) ; } }
Recursively sorts all children using the given comparator of TreeNode .
570
public static < T > TreeNode < T > copy ( TreeDef < T > treeDef , T root ) { return copy ( treeDef , root , Function . identity ( ) ) ; }
Creates a hierarchy of TreeNodes that copies the structure and content of the given tree .
571
public TreeNode < T > findByContent ( T content ) { Optional < TreeNode < T > > opt = TreeStream . breadthFirst ( treeDef ( ) , this ) . filter ( node -> node . getContent ( ) . equals ( content ) ) . findFirst ( ) ; if ( opt . isPresent ( ) ) { return opt . get ( ) ; } else { throw new IllegalArgumentException ( this ...
Searches breadth - first for the TreeNode with the given content .
572
public static < T > boolean isDescendantOf ( TreeDef . Parented < T > treeDef , T child , T parent ) { T candidateParent = treeDef . parentOf ( child ) ; while ( candidateParent != null ) { if ( candidateParent . equals ( parent ) ) { return true ; } else { candidateParent = treeDef . parentOf ( candidateParent ) ; } }...
Returns true iff child is a descendant of parent .
573
public static < T > boolean isDescendantOfOrEqualTo ( TreeDef . Parented < T > treeDef , T child , T parent ) { if ( child . equals ( parent ) ) { return true ; } else { return isDescendantOf ( treeDef , child , parent ) ; } }
Returns true iff child is a descendant of parent or if child is equal to parent .
574
public static < T > T root ( TreeDef . Parented < T > treeDef , T node ) { T lastParent ; T parent = node ; do { lastParent = parent ; parent = treeDef . parentOf ( lastParent ) ; } while ( parent != null ) ; return lastParent ; }
Returns the root of the given tree .
575
private static < T > Optional < T > lowestCommonAncestor ( TreeDef . Parented < T > treeDef , T nodeA , T nodeB ) { class TreeSearcher { private T tip ; private final Set < T > visited ; public TreeSearcher ( T start ) { this . tip = start ; this . visited = new HashSet < > ( ) ; } public boolean hasMore ( ) { return t...
Returns the common parent of the two given elements .
576
public static < T > String path ( TreeDef . Parented < T > treeDef , T node , Function < ? super T , String > toString , String delimiter ) { List < T > toRoot = toRoot ( treeDef , node ) ; ListIterator < T > iterator = toRoot . listIterator ( toRoot . size ( ) ) ; StringBuilder builder = new StringBuilder ( ) ; while ...
Returns the path of the given node .
577
public Runnable wrap ( Throwing . Runnable runnable ) { return ( ) -> { try { runnable . run ( ) ; } catch ( Throwable e ) { handler . accept ( e ) ; } } ; }
Returns a Runnable whose exceptions are handled by this Errors .
578
public < T > Consumer < T > wrap ( Throwing . Consumer < T > consumer ) { return val -> { try { consumer . accept ( val ) ; } catch ( Throwable e ) { handler . accept ( e ) ; } } ; }
Returns a Consumer whose exceptions are handled by this Errors .
579
public static RuntimeException asRuntime ( Throwable e ) { if ( e instanceof RuntimeException ) { return ( RuntimeException ) e ; } else { return new WrappedAsRuntimeException ( e ) ; } }
Casts or wraps the given exception to be a RuntimeException .
580
private static Object tryCall ( String methodName , Throwing . Supplier < Object > supplier ) { try { return supplier . get ( ) ; } catch ( Throwable error ) { return new CallException ( methodName , error ) ; } }
Executes the given function return any exceptions it might throw as wrapped values .
581
private static < K , V > Map . Entry < K , V > createEntry ( K key , V value ) { return new Map . Entry < K , V > ( ) { public K getKey ( ) { return key ; } public V getValue ( ) { return value ; } public V setValue ( V value ) { throw new UnsupportedOperationException ( ) ; } } ; }
Creates an immutable Map . Entry .
582
public static void dump ( String message , Throwable exception ) { printEmphasized ( StringPrinter . buildString ( printer -> { printer . println ( message ) ; exception . printStackTrace ( printer . toPrintWriter ( ) ) ; } ) ) ; }
Dumps the given message and exception stack to the system error console
583
public static PrintStream wrapAndDumpWhenContains ( PrintStream source , String trigger ) { StringPrinter wrapped = new StringPrinter ( StringPrinter . stringsToLines ( perLine -> { source . println ( perLine ) ; if ( perLine . contains ( trigger ) ) { dump ( "Triggered by " + trigger ) ; } } ) ) ; return wrapped . toP...
Returns a PrintStream which will redirect all of its output to the source PrintStream . If the trigger string is passed through the wrapped PrintStream then it will dump the stack trace of the call that printed the trigger .
584
public static List < StackTraceElement > captureStackBelow ( Class < ? > ... clazzes ) { List < Class < ? > > toIgnore = new ArrayList < > ( clazzes . length + 1 ) ; toIgnore . addAll ( Arrays . asList ( clazzes ) ) ; toIgnore . add ( StackDumper . class ) ; Predicate < StackTraceElement > isSkipped = element -> toIgno...
Captures all of the current stack which is below the given classes .
585
private static void printEmphasized ( String toPrint ) { pristineSysErr . println ( "+----------\\" ) ; for ( String line : toPrint . split ( "\n" ) ) { pristineSysErr . println ( "| " + line ) ; } pristineSysErr . println ( "+----------/" ) ; }
Prints the given string to the the given printer wrapped in hierarchy - friendly braces . Useful for emphasizing a specific event from a sea of logging statements .
586
public static String buildString ( Consumer < StringPrinter > printer ) { StringBuilder builder = new StringBuilder ( ) ; printer . accept ( new StringPrinter ( builder :: append ) ) ; return builder . toString ( ) ; }
Easy way to create a String using a StringPrinter .
587
public static String buildStringFromLines ( String ... lines ) { int numChars = lines . length ; for ( String line : lines ) { numChars += line . length ( ) ; } StringBuilder builder = new StringBuilder ( numChars ) ; for ( String line : lines ) { builder . append ( line ) ; builder . append ( '\n' ) ; } return builder...
Easy way to create a String from a bunch of lines .
588
public PrintStream toPrintStream ( Charset charset ) { return Errors . rethrow ( ) . get ( ( ) -> { return new PrintStream ( toOutputStream ( charset ) , true , charset . name ( ) ) ; } ) ; }
Creates a PrintStream of the given charset which passes its content to this StringPrinter .
589
public Writer toWriter ( ) { return new Writer ( ) { public Writer append ( char c ) { consumer . accept ( new String ( new char [ ] { c } ) ) ; return this ; } public Writer append ( CharSequence csq ) { if ( csq instanceof String ) { consumer . accept ( ( String ) csq ) ; } else { consumer . accept ( toStringSafely (...
Creates a Writer which passes its content to this StringPrinter .
590
public static double getDouble ( final String key ) { return Double . longBitsToDouble ( getPreferences ( ) . getLong ( key , Double . doubleToLongBits ( 0.0d ) ) ) ; }
Returns the double that has been saved as a long raw bits value in the long preferences . Returns 0 if the preference does not exist .
591
public static String getString ( final String key , final String defValue ) { return getPreferences ( ) . getString ( key , defValue ) ; }
Retrieves a stored String value .
592
public static void putLong ( final String key , final long value ) { final Editor editor = getPreferences ( ) . edit ( ) ; editor . putLong ( key , value ) ; editor . apply ( ) ; }
Stores a long value .
593
public static void putDouble ( final String key , final double value ) { final Editor editor = getPreferences ( ) . edit ( ) ; editor . putLong ( key , Double . doubleToRawLongBits ( value ) ) ; editor . apply ( ) ; }
Stores a double value as a long raw bits value .
594
public static void remove ( final String key ) { SharedPreferences prefs = getPreferences ( ) ; final Editor editor = prefs . edit ( ) ; if ( prefs . contains ( key + LENGTH ) ) { int stringSetLength = prefs . getInt ( key + LENGTH , - 1 ) ; if ( stringSetLength >= 0 ) { editor . remove ( key + LENGTH ) ; for ( int i =...
Removes a preference value .
595
public static Editor clear ( ) { final Editor editor = getPreferences ( ) . edit ( ) . clear ( ) ; editor . apply ( ) ; return editor ; }
Removed all the stored keys and values .
596
protected String fetchMarkdownTagletDescriptionFile ( String resourceName ) { final URL url = this . getClass ( ) . getResource ( resourceName ) ; if ( url != null ) { try { return FileUtils . readFileToString ( new File ( url . toURI ( ) ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } return "" ; }
Fetch the markdown taglet description from a resource within your classpath .
597
public void render ( Tag tag , StringBuilder target , MarkdownDoclet doclet ) { Counter counter ; if ( tag . holder ( ) instanceof MemberDoc ) { counter = getCounter ( ( ( MemberDoc ) tag . holder ( ) ) . containingClass ( ) ) ; } else { counter = getCounter ( tag . holder ( ) ) ; } target . append ( "<div class=\"todo...
Render the tag .
598
public void appendOption ( String ... option ) { options = Arrays . copyOf ( options , options . length + 1 ) ; options [ options . length - 1 ] = option ; }
Append an option to the doclet options .
599
protected void processOverview ( ) { if ( options . getOverviewFile ( ) != null ) { try { rootDoc . setRawCommentText ( Files . toString ( options . getOverviewFile ( ) , options . getEncoding ( ) ) ) ; defaultProcess ( rootDoc , false ) ; } catch ( IOException e ) { printError ( "Error loading overview from " + option...
Process the overview file if specified .