idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
10,600
public static void inclusiveBetween ( final double start , final double end , final double value , final String message ) { if ( value < start || value > end ) { throw new IllegalArgumentException ( message ) ; } }
Validate that the specified primitive value falls between the two inclusive values specified ; otherwise throws an exception with the specified message .
10,601
@ SuppressWarnings ( "boxing" ) public static void exclusiveBetween ( final long start , final long end , final long value ) { if ( value <= start || value >= end ) { throw new IllegalArgumentException ( StringUtils . simpleFormat ( DEFAULT_EXCLUSIVE_BETWEEN_EX_MESSAGE , value , start , end ) ) ; } }
Validate that the specified primitive value falls between the two exclusive values specified ; otherwise throws an exception .
10,602
public static void exclusiveBetween ( final long start , final long end , final long value , final String message ) { if ( value <= start || value >= end ) { throw new IllegalArgumentException ( message ) ; } }
Validate that the specified primitive value falls between the two exclusive values specified ; otherwise throws an exception with the specified message .
10,603
@ GwtIncompatible ( "incompatible method" ) public static void isInstanceOf ( final Class < ? > type , final Object obj ) { if ( ! type . isInstance ( obj ) ) { throw new IllegalArgumentException ( StringUtils . simpleFormat ( DEFAULT_IS_INSTANCE_OF_EX_MESSAGE , type . getName ( ) , obj == null ? "null" : obj . getClass ( ) . getName ( ) ) ) ; } }
Validates that the argument is an instance of the specified class if not throws an exception .
10,604
private StringBuilder spacer ( final int spaces ) { final StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < spaces ; i ++ ) { sb . append ( " " ) ; } return sb ; }
Creates a StringBuilder responsible for the indenting .
10,605
private boolean performStateCheck ( final int increment ) { CheckIntervalData currentData ; CheckIntervalData nextData ; State currentState ; do { final long time = now ( ) ; currentState = state . get ( ) ; currentData = checkIntervalData . get ( ) ; nextData = nextCheckIntervalData ( increment , currentData , currentState , time ) ; } while ( ! updateCheckIntervalData ( currentData , nextData ) ) ; if ( stateStrategy ( currentState ) . isStateTransition ( this , currentData , nextData ) ) { currentState = currentState . oppositeState ( ) ; changeStateAndStartNewCheckInterval ( currentState ) ; } return ! isOpen ( currentState ) ; }
Actually checks the state of this circuit breaker and executes a state transition if necessary .
10,606
private static Map < State , StateStrategy > createStrategyMap ( ) { final Map < State , StateStrategy > map = new EnumMap < > ( State . class ) ; map . put ( State . CLOSED , new StateStrategyClosed ( ) ) ; map . put ( State . OPEN , new StateStrategyOpen ( ) ) ; return map ; }
Creates the map with strategy objects . It allows access for a strategy for a given state .
10,607
public String [ ] [ ] lemmatize ( int numTaggings , String [ ] toks , String [ ] tags ) { Sequence [ ] bestSequences = model . bestSequences ( numTaggings , toks , new Object [ ] { tags } , contextGenerator , sequenceValidator ) ; String [ ] [ ] lemmaClasses = new String [ bestSequences . length ] [ ] ; for ( int i = 0 ; i < lemmaClasses . length ; i ++ ) { List < String > t = bestSequences [ i ] . getOutcomes ( ) ; lemmaClasses [ i ] = t . toArray ( new String [ t . size ( ) ] ) ; } return lemmaClasses ; }
Generates a specified number of lemma classes for the input tokens and tags .
10,608
@ GwtIncompatible ( "incompatible method" ) public String getFormattedExceptionMessage ( final String baseMessage ) { final StringBuilder buffer = new StringBuilder ( 256 ) ; if ( baseMessage != null ) { buffer . append ( baseMessage ) ; } if ( contextValues . size ( ) > 0 ) { if ( buffer . length ( ) > 0 ) { buffer . append ( '\n' ) ; } buffer . append ( "Exception Context:\n" ) ; int i = 0 ; for ( final Pair < String , Object > pair : contextValues ) { buffer . append ( "\t[" ) ; buffer . append ( ++ i ) ; buffer . append ( ':' ) ; buffer . append ( pair . getKey ( ) ) ; buffer . append ( "=" ) ; final Object value = pair . getValue ( ) ; if ( value == null ) { buffer . append ( "null" ) ; } else { String valueStr ; try { valueStr = value . toString ( ) ; } catch ( final Exception e ) { valueStr = "Exception thrown on toString(): " + ExceptionUtils . getStackTrace ( e ) ; } buffer . append ( valueStr ) ; } buffer . append ( "]\n" ) ; } buffer . append ( "---------------------------------" ) ; } return buffer . toString ( ) ; }
Builds the message containing the contextual information .
10,609
public final String [ ] getTokensWithMultiWords ( final String [ ] tokens ) { final Span [ ] multiWordSpans = multiWordsToSpans ( tokens ) ; final List < String > tokenList = new ArrayList < String > ( Arrays . asList ( tokens ) ) ; int counter = 0 ; for ( final Span mwSpan : multiWordSpans ) { final int fromIndex = mwSpan . getStart ( ) - counter ; final int toIndex = mwSpan . getEnd ( ) - counter ; counter = counter + tokenList . subList ( fromIndex , toIndex ) . size ( ) - 1 ; final String multiWord = Joiner . on ( "#" ) . join ( tokenList . subList ( fromIndex , toIndex ) ) ; tokenList . subList ( fromIndex , toIndex ) . clear ( ) ; tokenList . add ( fromIndex , multiWord ) ; } return tokenList . toArray ( new String [ tokenList . size ( ) ] ) ; }
Get input text and join the multiwords found in the dictionary object .
10,610
public final Span [ ] multiWordsToSpans ( final String [ ] tokens ) { final List < Span > multiWordsFound = new LinkedList < Span > ( ) ; for ( int offsetFrom = 0 ; offsetFrom < tokens . length ; offsetFrom ++ ) { Span multiwordFound = null ; String tokensSearching [ ] = new String [ ] { } ; for ( int offsetTo = offsetFrom ; offsetTo < tokens . length ; offsetTo ++ ) { final int lengthSearching = offsetTo - offsetFrom + 1 ; if ( lengthSearching > getMaxTokenCount ( ) ) { break ; } else { tokensSearching = new String [ lengthSearching ] ; System . arraycopy ( tokens , offsetFrom , tokensSearching , 0 , lengthSearching ) ; final String entryForSearch = StringUtils . getStringFromTokens ( tokensSearching ) ; final String entryValue = dictionary . get ( entryForSearch . toLowerCase ( ) ) ; if ( entryValue != null ) { multiwordFound = new Span ( offsetFrom , offsetTo + 1 , entryValue ) ; } } } if ( multiwordFound != null ) { multiWordsFound . add ( multiwordFound ) ; offsetFrom += multiwordFound . length ( ) - 1 ; } } return multiWordsFound . toArray ( new Span [ multiWordsFound . size ( ) ] ) ; }
Detects multiword expressions ignoring case .
10,611
private int compareDate ( Date a , Date b ) { final Date ta = new Date ( a . getTime ( ) ) ; final Date tb = new Date ( b . getTime ( ) ) ; final long d1 = setHourToZero ( ta ) . getTime ( ) ; final long d2 = setHourToZero ( tb ) . getTime ( ) ; return ( int ) Math . round ( ( d2 - d1 ) / 1000.0 / 60.0 / 60.0 / 24.0 ) ; }
Calculate the number of days between two dates
10,612
@ SuppressWarnings ( "deprecation" ) private Date setHourToZero ( Date in ) { final Date d = new Date ( in . getTime ( ) ) ; d . setHours ( 0 ) ; d . setMinutes ( 0 ) ; d . setSeconds ( 0 ) ; long t = d . getTime ( ) / 1000 ; t = t * 1000 ; return new Date ( t ) ; }
Set hour minutes second and milliseconds to zero .
10,613
@ SuppressWarnings ( "deprecation" ) private Date getWeekOne ( int year ) { GregorianCalendar weekOne = new GregorianCalendar ( ) ; weekOne . setFirstDayOfWeek ( getFirstDayOfWeek ( ) ) ; weekOne . setMinimalDaysInFirstWeek ( getMinimalDaysInFirstWeek ( ) ) ; weekOne . setTime ( new Date ( year , 0 , 1 ) ) ; int dow = weekOne . get ( DAY_OF_WEEK ) ; if ( dow < weekOne . getFirstDayOfWeek ( ) ) dow += 7 ; int eow = weekOne . getFirstDayOfWeek ( ) + 7 ; if ( ( eow - dow ) < weekOne . getMinimalDaysInFirstWeek ( ) ) { weekOne . add ( DATE , 7 ) ; } weekOne . set ( DAY_OF_WEEK , weekOne . getFirstDayOfWeek ( ) ) ; return weekOne . getTime ( ) ; }
Gets the date of the first week for the specified year .
10,614
protected final void createTagDictionary ( final String dictPath ) { if ( ! dictPath . equalsIgnoreCase ( Flags . DEFAULT_DICT_PATH ) ) { try { getPosTaggerFactory ( ) . setTagDictionary ( getPosTaggerFactory ( ) . createTagDictionary ( new File ( dictPath ) ) ) ; } catch ( final IOException e ) { throw new TerminateToolException ( - 1 , "IO error while loading POS Dictionary: " + e . getMessage ( ) , e ) ; } } }
Create a tag dictionary with the dictionary contained in the dictPath .
10,615
protected final void createAutomaticDictionary ( final ObjectStream < POSSample > aDictSamples , final int aDictCutOff ) { if ( aDictCutOff != Flags . DEFAULT_DICT_CUTOFF ) { try { TagDictionary dict = getPosTaggerFactory ( ) . getTagDictionary ( ) ; if ( dict == null ) { dict = getPosTaggerFactory ( ) . createEmptyTagDictionary ( ) ; getPosTaggerFactory ( ) . setTagDictionary ( dict ) ; } if ( dict instanceof MutableTagDictionary ) { POSTaggerME . populatePOSDictionary ( aDictSamples , ( MutableTagDictionary ) dict , aDictCutOff ) ; } else { throw new IllegalArgumentException ( "Can't extend a POSDictionary" + " that does not implement MutableTagDictionary." ) ; } this . dictSamples . reset ( ) ; } catch ( final IOException e ) { throw new TerminateToolException ( - 1 , "IO error while creating/extending POS Dictionary: " + e . getMessage ( ) , e ) ; } } }
Automatically create a tag dictionary from training data .
10,616
protected final Dictionary createNgramDictionary ( final ObjectStream < POSSample > aDictSamples , final int aNgramCutoff ) { Dictionary ngramDict = null ; if ( aNgramCutoff != Flags . DEFAULT_DICT_CUTOFF ) { System . err . print ( "Building ngram dictionary ... " ) ; try { ngramDict = POSTaggerME . buildNGramDictionary ( aDictSamples , aNgramCutoff ) ; this . dictSamples . reset ( ) ; } catch ( final IOException e ) { throw new TerminateToolException ( - 1 , "IO error while building NGram Dictionary: " + e . getMessage ( ) , e ) ; } System . err . println ( "done" ) ; } return ngramDict ; }
Create ngram dictionary from training data .
10,617
public String getQualifiedSurroundingClassName ( ) { TypeElement typeElement = ( TypeElement ) field . getEnclosingElement ( ) ; return typeElement . getQualifiedName ( ) . toString ( ) ; }
Get the full qualified class name this field is part of .
10,618
private static void setInternal ( int [ ] array , int fromIndex , int toIndex ) { int first = wordIndex ( fromIndex ) ; int last = wordIndex ( toIndex ) ; maybeGrowArrayToIndex ( array , last ) ; int startBit = bitOffset ( fromIndex ) ; int endBit = bitOffset ( toIndex ) ; if ( first == last ) { maskInWord ( array , first , startBit , endBit ) ; } else { maskInWord ( array , first , startBit , BITS_PER_WORD ) ; maskInWord ( array , last , 0 , endBit ) ; for ( int i = first + 1 ; i < last ; i ++ ) { array [ i ] = WORD_MASK ; } } }
Sets all bits to true within the given range .
10,619
private static int lastSetWordIndex ( int [ ] array ) { int i = array . length - 1 ; for ( ; i >= 0 && wordAt ( array , i ) == 0 ; -- i ) { } return i ; }
Returns the index of the last word containing a true bit in an array or - 1 if none .
10,620
private static void flipMaskedWord ( int [ ] array , int index , int from , int to ) { if ( from == to ) { return ; } to = 32 - to ; int word = wordAt ( array , index ) ; word ^= ( ( 0xffffffff >>> from ) << ( from + to ) ) >>> to ; array [ index ] = word & WORD_MASK ; }
Flips all bits in a word within the given range .
10,621
private static void maskInWord ( int [ ] array , int index , int from , int to ) { if ( from == to ) { return ; } to = 32 - to ; int word = wordAt ( array , index ) ; word |= ( ( 0xffffffff >>> from ) << ( from + to ) ) >>> to ; array [ index ] = word & WORD_MASK ; }
Sets all bits to true in a word within the given bit range .
10,622
private static void maskOutWord ( int [ ] array , int index , int from , int to ) { if ( from == to ) { return ; } int word = wordAt ( array , index ) ; if ( word == 0 ) { return ; } int mask ; if ( from != 0 ) { mask = 0xffffffff >>> ( 32 - from ) ; } else { mask = 0 ; } if ( to != 32 ) { mask |= 0xffffffff << to ; } word &= mask ; array [ index ] = word & WORD_MASK ; }
Sets all bits to false in a word within the given bit range .
10,623
public final List < Morpheme > getMorphemes ( final String [ ] tokens ) { final List < String > origPosTags = posAnnotate ( tokens ) ; final List < Morpheme > morphemes = getMorphemesFromStrings ( origPosTags , tokens ) ; return morphemes ; }
Get morphological analysis from a tokenized sentence .
10,624
public final List < String > posAnnotate ( final String [ ] tokens ) { final String [ ] annotatedText = this . posTagger . tag ( tokens ) ; final List < String > posTags = new ArrayList < String > ( Arrays . asList ( annotatedText ) ) ; return posTags ; }
Produce postags from a tokenized sentence .
10,625
public final String [ ] [ ] getAllPosTags ( final String [ ] tokens ) { final String [ ] [ ] allPosTags = this . posTagger . tag ( 13 , tokens ) ; return allPosTags ; }
Produces a multidimensional array containing all the tagging possible for a given sentence .
10,626
@ GwtIncompatible ( "incompatible method" ) public static < T extends Comparable < ? super T > > T median ( final T ... items ) { Validate . notEmpty ( items ) ; Validate . noNullElements ( items ) ; final TreeSet < T > sort = new TreeSet < > ( ) ; Collections . addAll ( sort , items ) ; @ SuppressWarnings ( "unchecked" ) final T result = ( T ) sort . toArray ( ) [ ( sort . size ( ) - 1 ) / 2 ] ; return result ; }
Find the best guess middle value among comparables . If there is an even number of total values the lower of the two middle values will be returned .
10,627
public static < T > T mode ( final T ... items ) { if ( ArrayUtils . isNotEmpty ( items ) ) { final HashMap < T , MutableInt > occurrences = new HashMap < > ( items . length ) ; for ( final T t : items ) { final MutableInt count = occurrences . get ( t ) ; if ( count == null ) { occurrences . put ( t , new MutableInt ( 1 ) ) ; } else { count . increment ( ) ; } } T result = null ; int max = 0 ; for ( final Map . Entry < T , MutableInt > e : occurrences . entrySet ( ) ) { final int cmp = e . getValue ( ) . intValue ( ) ; if ( cmp == max ) { result = null ; } else if ( cmp > max ) { max = cmp ; result = e . getKey ( ) ; } } return result ; } return null ; }
Find the most frequently occurring item .
10,628
public final void crossValidate ( final TrainingParameters params ) { POSTaggerCrossValidator validator = null ; try { validator = getPOSTaggerCrossValidator ( params ) ; validator . evaluate ( this . trainSamples , this . folds ) ; } catch ( final IOException e ) { System . err . println ( "IO error while loading training set!" ) ; e . printStackTrace ( ) ; System . exit ( 1 ) ; } finally { try { this . trainSamples . close ( ) ; } catch ( final IOException e ) { System . err . println ( "IO error with the train samples!" ) ; } } if ( this . detailedListener == null ) { System . out . println ( validator . getWordAccuracy ( ) ) ; } else { System . out . println ( validator . getWordAccuracy ( ) ) ; } }
Cross validate when no separate testset is available .
10,629
private POSTaggerCrossValidator getPOSTaggerCrossValidator ( final TrainingParameters params ) { final File dictPath = new File ( Flags . getDictionaryFeatures ( params ) ) ; if ( this . posTaggerFactory == null ) { throw new IllegalStateException ( "You must create the POSTaggerFactory features!" ) ; } POSTaggerCrossValidator validator = null ; if ( dictPath . getName ( ) . equals ( Flags . DEFAULT_DICT_PATH ) ) { if ( this . dictCutOff == Flags . DEFAULT_DICT_CUTOFF ) { validator = new POSTaggerCrossValidator ( this . lang , params , null , null , null , this . posTaggerFactory . getClass ( ) . getName ( ) , this . listeners . toArray ( new POSTaggerEvaluationMonitor [ this . listeners . size ( ) ] ) ) ; } else { validator = new POSTaggerCrossValidator ( this . lang , params , null , null , this . dictCutOff , this . posTaggerFactory . getClass ( ) . getName ( ) , this . listeners . toArray ( new POSTaggerEvaluationMonitor [ this . listeners . size ( ) ] ) ) ; } } else { if ( this . dictCutOff == Flags . DEFAULT_DICT_CUTOFF ) { validator = new POSTaggerCrossValidator ( this . lang , params , dictPath , null , null , this . posTaggerFactory . getClass ( ) . getName ( ) , this . listeners . toArray ( new POSTaggerEvaluationMonitor [ this . listeners . size ( ) ] ) ) ; } else { validator = new POSTaggerCrossValidator ( this . lang , params , dictPath , null , this . dictCutOff , this . posTaggerFactory . getClass ( ) . getName ( ) , this . listeners . toArray ( new POSTaggerEvaluationMonitor [ this . listeners . size ( ) ] ) ) ; } } return validator ; }
Get the postagger cross validator .
10,630
private static Type [ ] extractTypeArgumentsFrom ( final Map < TypeVariable < ? > , Type > mappings , final TypeVariable < ? > [ ] variables ) { final Type [ ] result = new Type [ variables . length ] ; int index = 0 ; for ( final TypeVariable < ? > var : variables ) { Validate . isTrue ( mappings . containsKey ( var ) , "missing argument mapping for %s" , toString ( var ) ) ; result [ index ++ ] = mappings . get ( var ) ; } return result ; }
Helper method to establish the formal parameters for a parameterized type .
10,631
public static < V > String replace ( final Object source , final Map < String , V > valueMap ) { return new StrSubstitutor ( valueMap ) . replace ( source ) ; }
Replaces all the occurrences of variables in the given source object with their matching values from the map .
10,632
public static < V > String replace ( final Object source , final Map < String , V > valueMap , final String prefix , final String suffix ) { return new StrSubstitutor ( valueMap , prefix , suffix ) . replace ( source ) ; }
Replaces all the occurrences of variables in the given source object with their matching values from the map . This method allows to specify a custom variable prefix and suffix
10,633
public static String replace ( final Object source , final Properties valueProperties ) { if ( valueProperties == null ) { return source . toString ( ) ; } final Map < String , String > valueMap = new HashMap < > ( ) ; final Enumeration < ? > propNames = valueProperties . propertyNames ( ) ; while ( propNames . hasMoreElements ( ) ) { final String propName = ( String ) propNames . nextElement ( ) ; final String propValue = valueProperties . getProperty ( propName ) ; valueMap . put ( propName , propValue ) ; } return StrSubstitutor . replace ( source , valueMap ) ; }
Replaces all the occurrences of variables in the given source object with their matching values from the properties .
10,634
public String replace ( final CharSequence source ) { if ( source == null ) { return null ; } return replace ( source , 0 , source . length ( ) ) ; }
Replaces all the occurrences of variables with their matching values from the resolver using the given source as a template . The source is not altered by this method .
10,635
public String replace ( final StrBuilder source ) { if ( source == null ) { return null ; } final StrBuilder buf = new StrBuilder ( source . length ( ) ) . append ( source ) ; substitute ( buf , 0 , buf . length ( ) ) ; return buf . toString ( ) ; }
Replaces all the occurrences of variables with their matching values from the resolver using the given source builder as a template . The builder is not altered by this method .
10,636
public boolean replaceIn ( final StrBuilder source ) { if ( source == null ) { return false ; } return substitute ( source , 0 , source . length ( ) ) ; }
Replaces all the occurrences of variables within the given source builder with their matching values from the resolver .
10,637
@ SuppressWarnings ( "unchecked" ) public static < L , M , R > ImmutableTriple < L , M , R > nullTriple ( ) { return NULL ; }
Returns an immutable triple of nulls .
10,638
static Token [ ] lexx ( final String format ) { final ArrayList < Token > list = new ArrayList < > ( format . length ( ) ) ; boolean inLiteral = false ; StringBuilder buffer = null ; Token previous = null ; for ( int i = 0 ; i < format . length ( ) ; i ++ ) { final char ch = format . charAt ( i ) ; if ( inLiteral && ch != '\'' ) { buffer . append ( ch ) ; continue ; } Object value = null ; switch ( ch ) { case '\'' : if ( inLiteral ) { buffer = null ; inLiteral = false ; } else { buffer = new StringBuilder ( ) ; list . add ( new Token ( buffer ) ) ; inLiteral = true ; } break ; case 'y' : value = y ; break ; case 'M' : value = M ; break ; case 'd' : value = d ; break ; case 'H' : value = H ; break ; case 'm' : value = m ; break ; case 's' : value = s ; break ; case 'S' : value = S ; break ; default : if ( buffer == null ) { buffer = new StringBuilder ( ) ; list . add ( new Token ( buffer ) ) ; } buffer . append ( ch ) ; } if ( value != null ) { if ( previous != null && previous . getValue ( ) . equals ( value ) ) { previous . increment ( ) ; } else { final Token token = new Token ( value ) ; list . add ( token ) ; previous = token ; } buffer = null ; } } if ( inLiteral ) { throw new IllegalArgumentException ( "Unmatched quote in format: " + format ) ; } return list . toArray ( new Token [ list . size ( ) ] ) ; }
Parses a classic date format string into Tokens
10,639
public StrBuilder setNullText ( String nullText ) { if ( nullText != null && nullText . isEmpty ( ) ) { nullText = null ; } this . nullText = nullText ; return this ; }
Sets the text to be appended when null is added .
10,640
public StrBuilder setLength ( final int length ) { if ( length < 0 ) { throw new StringIndexOutOfBoundsException ( length ) ; } if ( length < size ) { size = length ; } else if ( length > size ) { ensureCapacity ( length ) ; final int oldEnd = size ; final int newEnd = length ; size = length ; for ( int i = oldEnd ; i < newEnd ; i ++ ) { buffer [ i ] = CharUtils . NUL ; } } return this ; }
Updates the length of the builder by either dropping the last characters or adding filler of Unicode zero .
10,641
public StrBuilder ensureCapacity ( final int capacity ) { if ( capacity > buffer . length ) { final char [ ] old = buffer ; buffer = new char [ capacity * 2 ] ; System . arraycopy ( old , 0 , buffer , 0 , size ) ; } return this ; }
Checks the capacity and ensures that it is at least the size specified .
10,642
public StrBuilder minimizeCapacity ( ) { if ( buffer . length > length ( ) ) { final char [ ] old = buffer ; buffer = new char [ length ( ) ] ; System . arraycopy ( old , 0 , buffer , 0 , size ) ; } return this ; }
Minimizes the capacity to the actual length of the string .
10,643
public StrBuilder setCharAt ( final int index , final char ch ) { if ( index < 0 || index >= length ( ) ) { throw new StringIndexOutOfBoundsException ( index ) ; } buffer [ index ] = ch ; return this ; }
Sets the character at the specified index .
10,644
public StrBuilder deleteCharAt ( final int index ) { if ( index < 0 || index >= size ) { throw new StringIndexOutOfBoundsException ( index ) ; } deleteImpl ( index , index + 1 , 1 ) ; return this ; }
Deletes the character at the specified index .
10,645
public char [ ] toCharArray ( ) { if ( size == 0 ) { return ArrayUtils . EMPTY_CHAR_ARRAY ; } final char chars [ ] = new char [ size ] ; System . arraycopy ( buffer , 0 , chars , 0 , size ) ; return chars ; }
Copies the builder s character array into a new character array .
10,646
public char [ ] toCharArray ( final int startIndex , int endIndex ) { endIndex = validateRange ( startIndex , endIndex ) ; final int len = endIndex - startIndex ; if ( len == 0 ) { return ArrayUtils . EMPTY_CHAR_ARRAY ; } final char chars [ ] = new char [ len ] ; System . arraycopy ( buffer , startIndex , chars , 0 , len ) ; return chars ; }
Copies part of the builder s character array into a new character array .
10,647
public StrBuilder append ( final boolean value ) { if ( value ) { ensureCapacity ( size + 4 ) ; buffer [ size ++ ] = 't' ; buffer [ size ++ ] = 'r' ; buffer [ size ++ ] = 'u' ; buffer [ size ++ ] = 'e' ; } else { ensureCapacity ( size + 5 ) ; buffer [ size ++ ] = 'f' ; buffer [ size ++ ] = 'a' ; buffer [ size ++ ] = 'l' ; buffer [ size ++ ] = 's' ; buffer [ size ++ ] = 'e' ; } return this ; }
Appends a boolean value to the string builder .
10,648
public StrBuilder append ( final char ch ) { final int len = length ( ) ; ensureCapacity ( len + 1 ) ; buffer [ size ++ ] = ch ; return this ; }
Appends a char value to the string builder .
10,649
public StrBuilder appendSeparator ( final String standard , final String defaultIfEmpty ) { final String str = isEmpty ( ) ? defaultIfEmpty : standard ; if ( str != null ) { append ( str ) ; } return this ; }
Appends one of both separators to the StrBuilder . If the builder is currently empty it will append the defaultIfEmpty - separator Otherwise it will append the standard - separator
10,650
public StrBuilder appendPadding ( final int length , final char padChar ) { if ( length >= 0 ) { ensureCapacity ( size + length ) ; for ( int i = 0 ; i < length ; i ++ ) { buffer [ size ++ ] = padChar ; } } return this ; }
Appends the pad character to the builder the specified number of times .
10,651
public StrBuilder insert ( final int index , final Object obj ) { if ( obj == null ) { return insert ( index , nullText ) ; } return insert ( index , obj . toString ( ) ) ; }
Inserts the string representation of an object into this builder . Inserting null will use the stored null text value .
10,652
public StrBuilder insert ( final int index , String str ) { validateIndex ( index ) ; if ( str == null ) { str = nullText ; } if ( str != null ) { final int strLen = str . length ( ) ; if ( strLen > 0 ) { final int newSize = size + strLen ; ensureCapacity ( newSize ) ; System . arraycopy ( buffer , index , buffer , index + strLen , size - index ) ; size = newSize ; str . getChars ( 0 , strLen , buffer , index ) ; } } return this ; }
Inserts the string into this builder . Inserting null will use the stored null text value .
10,653
public StrBuilder insert ( final int index , final char chars [ ] ) { validateIndex ( index ) ; if ( chars == null ) { return insert ( index , nullText ) ; } final int len = chars . length ; if ( len > 0 ) { ensureCapacity ( size + len ) ; System . arraycopy ( buffer , index , buffer , index + len , size - index ) ; System . arraycopy ( chars , 0 , buffer , index , len ) ; size += len ; } return this ; }
Inserts the character array into this builder . Inserting null will use the stored null text value .
10,654
public StrBuilder insert ( final int index , final char chars [ ] , final int offset , final int length ) { validateIndex ( index ) ; if ( chars == null ) { return insert ( index , nullText ) ; } if ( offset < 0 || offset > chars . length ) { throw new StringIndexOutOfBoundsException ( "Invalid offset: " + offset ) ; } if ( length < 0 || offset + length > chars . length ) { throw new StringIndexOutOfBoundsException ( "Invalid length: " + length ) ; } if ( length > 0 ) { ensureCapacity ( size + length ) ; System . arraycopy ( buffer , index , buffer , index + length , size - index ) ; System . arraycopy ( chars , offset , buffer , index , length ) ; size += length ; } return this ; }
Inserts part of the character array into this builder . Inserting null will use the stored null text value .
10,655
public StrBuilder delete ( final int startIndex , int endIndex ) { endIndex = validateRange ( startIndex , endIndex ) ; final int len = endIndex - startIndex ; if ( len > 0 ) { deleteImpl ( startIndex , endIndex , len ) ; } return this ; }
Deletes the characters between the two specified indices .
10,656
public StrBuilder deleteAll ( final String str ) { final int len = ( str == null ? 0 : str . length ( ) ) ; if ( len > 0 ) { int index = indexOf ( str , 0 ) ; while ( index >= 0 ) { deleteImpl ( index , index + len , len ) ; index = indexOf ( str , index ) ; } } return this ; }
Deletes the string wherever it occurs in the builder .
10,657
public StrBuilder replace ( final int startIndex , int endIndex , final String replaceStr ) { endIndex = validateRange ( startIndex , endIndex ) ; final int insertLen = ( replaceStr == null ? 0 : replaceStr . length ( ) ) ; replaceImpl ( startIndex , endIndex , endIndex - startIndex , replaceStr , insertLen ) ; return this ; }
Replaces a portion of the string builder with another string . The length of the inserted string does not have to match the removed length .
10,658
public StrBuilder replaceAll ( final char search , final char replace ) { if ( search != replace ) { for ( int i = 0 ; i < size ; i ++ ) { if ( buffer [ i ] == search ) { buffer [ i ] = replace ; } } } return this ; }
Replaces the search character with the replace character throughout the builder .
10,659
public StrBuilder replaceFirst ( final char search , final char replace ) { if ( search != replace ) { for ( int i = 0 ; i < size ; i ++ ) { if ( buffer [ i ] == search ) { buffer [ i ] = replace ; break ; } } } return this ; }
Replaces the first instance of the search character with the replace character in the builder .
10,660
public StrBuilder replaceAll ( final String searchStr , final String replaceStr ) { final int searchLen = ( searchStr == null ? 0 : searchStr . length ( ) ) ; if ( searchLen > 0 ) { final int replaceLen = ( replaceStr == null ? 0 : replaceStr . length ( ) ) ; int index = indexOf ( searchStr , 0 ) ; while ( index >= 0 ) { replaceImpl ( index , index + searchLen , searchLen , replaceStr , replaceLen ) ; index = indexOf ( searchStr , index + replaceLen ) ; } } return this ; }
Replaces the search string with the replace string throughout the builder .
10,661
public StrBuilder reverse ( ) { if ( size == 0 ) { return this ; } final int half = size / 2 ; final char [ ] buf = buffer ; for ( int leftIdx = 0 , rightIdx = size - 1 ; leftIdx < half ; leftIdx ++ , rightIdx -- ) { final char swap = buf [ leftIdx ] ; buf [ leftIdx ] = buf [ rightIdx ] ; buf [ rightIdx ] = swap ; } return this ; }
Reverses the string builder placing each character in the opposite index .
10,662
public StrBuilder trim ( ) { if ( size == 0 ) { return this ; } int len = size ; final char [ ] buf = buffer ; int pos = 0 ; while ( pos < len && buf [ pos ] <= ' ' ) { pos ++ ; } while ( pos < len && buf [ len - 1 ] <= ' ' ) { len -- ; } if ( len < size ) { delete ( len , size ) ; } if ( pos > 0 ) { delete ( 0 , pos ) ; } return this ; }
Trims the builder by removing characters less than or equal to a space from the beginning and end .
10,663
public boolean contains ( final char ch ) { final char [ ] thisBuf = buffer ; for ( int i = 0 ; i < this . size ; i ++ ) { if ( thisBuf [ i ] == ch ) { return true ; } } return false ; }
Checks if the string builder contains the specified char .
10,664
public int indexOf ( final char ch , int startIndex ) { startIndex = ( startIndex < 0 ? 0 : startIndex ) ; if ( startIndex >= size ) { return - 1 ; } final char [ ] thisBuf = buffer ; for ( int i = startIndex ; i < size ; i ++ ) { if ( thisBuf [ i ] == ch ) { return i ; } } return - 1 ; }
Searches the string builder to find the first reference to the specified char .
10,665
public int lastIndexOf ( final char ch , int startIndex ) { startIndex = ( startIndex >= size ? size - 1 : startIndex ) ; if ( startIndex < 0 ) { return - 1 ; } for ( int i = startIndex ; i >= 0 ; i -- ) { if ( buffer [ i ] == ch ) { return i ; } } return - 1 ; }
Searches the string builder to find the last reference to the specified char .
10,666
public boolean equalsIgnoreCase ( final StrBuilder other ) { if ( this == other ) { return true ; } if ( this . size != other . size ) { return false ; } final char thisBuf [ ] = this . buffer ; final char otherBuf [ ] = other . buffer ; for ( int i = size - 1 ; i >= 0 ; i -- ) { final char c1 = thisBuf [ i ] ; final char c2 = otherBuf [ i ] ; if ( c1 != c2 && Character . toUpperCase ( c1 ) != Character . toUpperCase ( c2 ) ) { return false ; } } return true ; }
Checks the contents of this builder against another to see if they contain the same character content ignoring case .
10,667
protected int validateRange ( final int startIndex , int endIndex ) { if ( startIndex < 0 ) { throw new StringIndexOutOfBoundsException ( startIndex ) ; } if ( endIndex > size ) { endIndex = size ; } if ( startIndex > endIndex ) { throw new StringIndexOutOfBoundsException ( "end < start" ) ; } return endIndex ; }
Validates parameters defining a range of the builder .
10,668
public T get ( ) throws ConcurrentException { T result = object ; if ( result == NO_INIT ) { synchronized ( this ) { result = object ; if ( result == NO_INIT ) { object = result = initialize ( ) ; } } } return result ; }
Returns the object wrapped by this instance . On first access the object is created . After that it is cached and can be accessed pretty fast .
10,669
public static Thread findThreadById ( final long threadId , final ThreadGroup threadGroup ) { Validate . isTrue ( threadGroup != null , "The thread group must not be null" ) ; final Thread thread = findThreadById ( threadId ) ; if ( thread != null && threadGroup . equals ( thread . getThreadGroup ( ) ) ) { return thread ; } return null ; }
Return the active thread with the specified id if it belongs to the specified thread group .
10,670
public static Thread findThreadById ( final long threadId , final String threadGroupName ) { Validate . isTrue ( threadGroupName != null , "The thread group name must not be null" ) ; final Thread thread = findThreadById ( threadId ) ; if ( thread != null && thread . getThreadGroup ( ) != null && thread . getThreadGroup ( ) . getName ( ) . equals ( threadGroupName ) ) { return thread ; } return null ; }
Return the active thread with the specified id if it belongs to a thread group with the specified group name .
10,671
public static Collection < Thread > findThreadsByName ( final String threadName , final ThreadGroup threadGroup ) { return findThreads ( threadGroup , false , new NamePredicate ( threadName ) ) ; }
Return active threads with the specified name if they belong to a specified thread group .
10,672
public static Collection < Thread > findThreadsByName ( final String threadName , final String threadGroupName ) { Validate . isTrue ( threadName != null , "The thread name must not be null" ) ; Validate . isTrue ( threadGroupName != null , "The thread group name must not be null" ) ; final Collection < ThreadGroup > threadGroups = findThreadGroups ( new NamePredicate ( threadGroupName ) ) ; if ( threadGroups . isEmpty ( ) ) { return Collections . emptyList ( ) ; } final Collection < Thread > result = new ArrayList < > ( ) ; final NamePredicate threadNamePredicate = new NamePredicate ( threadName ) ; for ( final ThreadGroup group : threadGroups ) { result . addAll ( findThreads ( group , false , threadNamePredicate ) ) ; } return Collections . unmodifiableCollection ( result ) ; }
Return active threads with the specified name if they belong to a thread group with the specified group name .
10,673
public static Thread findThreadById ( final long threadId ) { final Collection < Thread > result = findThreads ( new ThreadIdPredicate ( threadId ) ) ; return result . isEmpty ( ) ? null : result . iterator ( ) . next ( ) ; }
Return the active thread with the specified id .
10,674
public < T > Optional < T > as ( Class < T > type ) { return inner . filter ( d -> d . is ( type ) ) . map ( d -> d . as ( type ) ) ; }
Returns inner value as optional of input type if the inner value is absent or not an instance of the input type an empty optional is returned
10,675
@ SuppressWarnings ( "unchecked" ) private static < R , T extends Throwable > R typeErasure ( final Throwable throwable ) throws T { throw ( T ) throwable ; }
Claim a Throwable is another Exception type using type erasure . This hides a checked exception from the java compiler allowing a checked exception to be thrown without having the exception in the method s throw clause .
10,676
@ GwtIncompatible ( "incompatible method" ) public static boolean hasCause ( Throwable chain , final Class < ? extends Throwable > type ) { if ( chain instanceof UndeclaredThrowableException ) { chain = chain . getCause ( ) ; } return type . isInstance ( chain ) ; }
Does the throwable s causal chain have an immediate or wrapped exception of the given type?
10,677
private boolean hasStage ( InputProcessor processor ) { if ( ! ( processor instanceof InputMultiplexer ) ) { return processor == stage ; } InputMultiplexer im = ( InputMultiplexer ) processor ; SnapshotArray < InputProcessor > ips = im . getProcessors ( ) ; for ( InputProcessor ip : ips ) { if ( hasStage ( ip ) ) { return true ; } } return false ; }
Compares the given processor to the console s stage . If given a multiplexer it is iterated through recursively to check all of the multiplexer s processors for comparison .
10,678
public String tag ( final String word , final String posTag ) { final List < WordData > wdList = this . dictLookup . lookup ( word . toLowerCase ( ) ) ; String newPosTag = null ; for ( final WordData wd : wdList ) { newPosTag = wd . getTag ( ) . toString ( ) ; } if ( newPosTag == null ) { newPosTag = posTag ; } return newPosTag ; }
Get the postag for a surface form from a FSA morfologik generated dictionary .
10,679
private static String appendIfMissing ( final String str , final CharSequence suffix , final boolean ignoreCase , final CharSequence ... suffixes ) { if ( str == null || isEmpty ( suffix ) || endsWith ( str , suffix , ignoreCase ) ) { return str ; } if ( suffixes != null && suffixes . length > 0 ) { for ( final CharSequence s : suffixes ) { if ( endsWith ( str , s , ignoreCase ) ) { return str ; } } } return str + suffix . toString ( ) ; }
Appends the suffix to the end of the string if the string does not already end with the suffix .
10,680
public static String appendIfMissing ( final String str , final CharSequence suffix , final CharSequence ... suffixes ) { return appendIfMissing ( str , suffix , false , suffixes ) ; }
Appends the suffix to the end of the string if the string does not already end with any of the suffixes .
10,681
public static String appendIfMissingIgnoreCase ( final String str , final CharSequence suffix , final CharSequence ... suffixes ) { return appendIfMissing ( str , suffix , true , suffixes ) ; }
Appends the suffix to the end of the string if the string does not already end case insensitive with any of the suffixes .
10,682
public static String prependIfMissingIgnoreCase ( final String str , final CharSequence prefix , final CharSequence ... prefixes ) { return prependIfMissing ( str , prefix , true , prefixes ) ; }
Prepends the prefix to the start of the string if the string does not already start case insensitive with any of the prefixes .
10,683
public final void getAllTagsLemmasToNAF ( final KAFDocument kaf ) { final List < List < WF > > sentences = kaf . getSentences ( ) ; for ( final List < WF > wfs : sentences ) { final List < ixa . kaflib . Span < WF > > tokenSpans = new ArrayList < ixa . kaflib . Span < WF > > ( ) ; final String [ ] tokens = new String [ wfs . size ( ) ] ; for ( int i = 0 ; i < wfs . size ( ) ; i ++ ) { tokens [ i ] = wfs . get ( i ) . getForm ( ) ; final List < WF > wfTarget = new ArrayList < WF > ( ) ; wfTarget . add ( wfs . get ( i ) ) ; tokenSpans . add ( KAFDocument . newWFSpan ( wfTarget ) ) ; } String [ ] [ ] allPosTags = this . posTagger . getAllPosTags ( tokens ) ; ListMultimap < String , String > morphMap = lemmatizer . getMultipleLemmas ( tokens , allPosTags ) ; for ( int i = 0 ; i < tokens . length ; i ++ ) { final Term term = kaf . newTerm ( tokenSpans . get ( i ) ) ; List < String > posLemmaValues = morphMap . get ( tokens [ i ] ) ; if ( this . dictLemmatizer != null ) { dictLemmatizer . getAllPosLemmas ( tokens [ i ] , posLemmaValues ) ; } String allPosLemmasSet = StringUtils . getSetStringFromList ( posLemmaValues ) ; final String posId = Resources . getKafTagSet ( allPosTags [ 0 ] [ i ] , lang ) ; final String type = Resources . setTermType ( posId ) ; term . setType ( type ) ; term . setLemma ( posLemmaValues . get ( 0 ) . split ( "#" ) [ 1 ] ) ; term . setPos ( posId ) ; term . setMorphofeat ( allPosLemmasSet ) ; } } }
Add all postags and lemmas to morphofeat attribute .
10,684
public final String getAllTagsLemmasToCoNLL ( final KAFDocument kaf ) { final StringBuilder sb = new StringBuilder ( ) ; final List < List < WF > > sentences = kaf . getSentences ( ) ; for ( final List < WF > wfs : sentences ) { final List < ixa . kaflib . Span < WF > > tokenSpans = new ArrayList < ixa . kaflib . Span < WF > > ( ) ; final String [ ] tokens = new String [ wfs . size ( ) ] ; for ( int i = 0 ; i < wfs . size ( ) ; i ++ ) { tokens [ i ] = wfs . get ( i ) . getForm ( ) ; final List < WF > wfTarget = new ArrayList < WF > ( ) ; wfTarget . add ( wfs . get ( i ) ) ; tokenSpans . add ( KAFDocument . newWFSpan ( wfTarget ) ) ; } String [ ] [ ] allPosTags = this . posTagger . getAllPosTags ( tokens ) ; ListMultimap < String , String > morphMap = lemmatizer . getMultipleLemmas ( tokens , allPosTags ) ; for ( int i = 0 ; i < tokens . length ; i ++ ) { List < String > posLemmaValues = morphMap . get ( tokens [ i ] ) ; if ( this . dictLemmatizer != null ) { dictLemmatizer . getAllPosLemmas ( tokens [ i ] , posLemmaValues ) ; } String allPosLemmasSet = StringUtils . getSetStringFromList ( posLemmaValues ) ; sb . append ( tokens [ i ] ) . append ( "\t" ) . append ( allPosLemmasSet ) . append ( "\n" ) ; } sb . append ( "\n" ) ; } return sb . toString ( ) ; }
Give all lemmas and tags possible for a sentence in conll tabulated format .
10,685
private boolean isSetterForField ( ExecutableElement setter , VariableElement field ) { return setter . getParameters ( ) != null && setter . getParameters ( ) . size ( ) == 1 && setter . getParameters ( ) . get ( 0 ) . asType ( ) . equals ( field . asType ( ) ) ; }
Checks if the setter method is valid for the given field
10,686
private TypeElement getSurroundingClass ( Element e ) throws ProcessingException { if ( e . getEnclosingElement ( ) . getKind ( ) == ElementKind . CLASS ) { return ( TypeElement ) e . getEnclosingElement ( ) ; } throw new ProcessingException ( e , "Field %s is not part of a class. Only fields in a class can be annotated with %s" , e . getSimpleName ( ) . toString ( ) , Column . class . getSimpleName ( ) ) ; }
Checks if a Element is in class and returns the TypeElement of the surrounding class
10,687
private TypeElement checkAndGetClass ( Element e ) throws ProcessingException { if ( e . getKind ( ) != ElementKind . CLASS ) { throw new ProcessingException ( e , "%s is annotated with @%s but only classes can be annotated with this annotation" , e . toString ( ) , ObjectMappable . class . getSimpleName ( ) ) ; } return ( TypeElement ) e ; }
Check the Element if it s a class and returns the corresponding TypeElement
10,688
private FieldSpec generateRxMappingMethod ( ObjectMappableAnnotatedClass clazz ) { String objectVarName = "item" ; String cursorVarName = "cursor" ; TypeName elementType = ClassName . get ( clazz . getElement ( ) . asType ( ) ) ; CodeBlock . Builder initBlockBuilder = CodeBlock . builder ( ) . add ( "new $L<$L, $L>() {\n" , Func1 . class . getSimpleName ( ) , Cursor . class . getSimpleName ( ) , elementType ) . indent ( ) . add ( "@Override public $L call($L cursor) {\n" , elementType , Cursor . class . getSimpleName ( ) ) . indent ( ) ; generateColumnIndexCode ( initBlockBuilder , clazz . getColumnAnnotatedElements ( ) , cursorVarName ) ; initBlockBuilder . addStatement ( "$T $L = new $T()" , elementType , objectVarName , elementType ) ; for ( ColumnAnnotateable e : clazz . getColumnAnnotatedElements ( ) ) { String indexVaName = e . getColumnName ( ) + "Index" ; initBlockBuilder . beginControlFlow ( "if ($L >= 0)" , indexVaName ) ; e . generateAssignStatement ( initBlockBuilder , objectVarName , cursorVarName , indexVaName ) ; initBlockBuilder . endControlFlow ( ) ; } initBlockBuilder . addStatement ( "return $L" , objectVarName ) . unindent ( ) . add ( "}\n" ) . unindent ( ) . add ( "}" ) . build ( ) ; ParameterizedTypeName fieldType = ParameterizedTypeName . get ( ClassName . get ( Func1 . class ) , ClassName . get ( Cursor . class ) , elementType ) ; return FieldSpec . builder ( fieldType , "MAPPER" , Modifier . PUBLIC , Modifier . STATIC , Modifier . FINAL ) . initializer ( initBlockBuilder . build ( ) ) . build ( ) ; }
Generates the field that can be used as RxJava method
10,689
private TypeSpec generateContentValuesBuilderClass ( ObjectMappableAnnotatedClass clazz , String mapperClassName , String className ) { String cvVarName = "contentValues" ; MethodSpec constructor = MethodSpec . constructorBuilder ( ) . addModifiers ( Modifier . PRIVATE ) . addStatement ( "$L = new $T()" , cvVarName , ClassName . get ( ContentValues . class ) ) . build ( ) ; TypeSpec . Builder builder = TypeSpec . classBuilder ( className ) . addJavadoc ( "Builder class to generate type sage {@link $T } . At the end you have to call {@link #build()}\n" , TypeName . get ( ContentValues . class ) ) . addModifiers ( Modifier . PUBLIC , Modifier . STATIC ) . addField ( ContentValues . class , cvVarName , Modifier . PRIVATE ) . addMethod ( constructor ) . addMethod ( MethodSpec . methodBuilder ( "build" ) . addJavadoc ( "Creates and returns a $T from the builder\n" , TypeName . get ( ContentValues . class ) ) . addJavadoc ( "@return $T" , TypeName . get ( ContentValues . class ) ) . addModifiers ( Modifier . PUBLIC ) . addStatement ( "return $L" , cvVarName ) . returns ( ContentValues . class ) . build ( ) ) ; String packageName = getPackageName ( clazz ) ; for ( ColumnAnnotateable e : clazz . getColumnAnnotatedElements ( ) ) { e . generateContentValuesBuilderMethod ( builder , ClassName . get ( packageName , mapperClassName , className ) , cvVarName ) ; } return builder . build ( ) ; }
Generates the ContentValues Builder Class
10,690
private MethodSpec generateContentValuesMethod ( ObjectMappableAnnotatedClass clazz , String mapperClassName , String className ) { ClassName typeName = ClassName . get ( getPackageName ( clazz ) , mapperClassName , className ) ; return MethodSpec . methodBuilder ( "contentValues" ) . addJavadoc ( "Get a typesafe ContentValues Builder \n" ) . addJavadoc ( "@return The ContentValues Builder \n" ) . addModifiers ( Modifier . PUBLIC , Modifier . STATIC ) . returns ( typeName ) . addStatement ( "return new $T()" , typeName ) . build ( ) ; }
Generates a static file to get
10,691
private String getPackageName ( ObjectMappableAnnotatedClass clazz ) { PackageElement pkg = elements . getPackageOf ( clazz . getElement ( ) ) ; return pkg . isUnnamed ( ) ? "" : pkg . getQualifiedName ( ) . toString ( ) ; }
Get the package name of a certain clazz
10,692
protected QueryBuilder rawQueryOnManyTables ( final Iterable < String > tables , final String sql ) { return new QueryBuilder ( tables , sql ) ; }
Creates a raw query and enables auto updates for the given tables
10,693
private QueryObservable executeQuery ( QueryBuilder queryBuilder ) { String sql = queryBuilder . rawStatement ; Iterable < String > affectedTables = queryBuilder . rawStatementAffectedTables ; if ( queryBuilder . statement != null ) { SqlCompileable . CompileableStatement compileableStatement = queryBuilder . statement . asCompileableStatement ( ) ; sql = compileableStatement . sql ; affectedTables = compileableStatement . tables ; } if ( ! queryBuilder . autoUpdate || affectedTables == null ) { affectedTables = Collections . emptySet ( ) ; } return db . createQuery ( affectedTables , sql , queryBuilder . args ) ; }
Executes the a query
10,694
protected Observable < Long > insert ( final String table , final ContentValues contentValues ) { return Observable . defer ( new Func0 < Observable < Long > > ( ) { public Observable < Long > call ( ) { return Observable . just ( db . insert ( table , contentValues ) ) ; } } ) ; }
Insert a row into the given table
10,695
protected Observable < Integer > delete ( final String table ) { return delete ( table , null ) ; }
Deletes all rows from a table
10,696
protected Observable < Integer > delete ( final String table , final String whereClause , final String ... whereArgs ) { return Observable . defer ( new Func0 < Observable < Integer > > ( ) { public Observable < Integer > call ( ) { return Observable . just ( db . delete ( table , whereClause , whereArgs ) ) ; } } ) ; }
Delete data from a table
10,697
private static Locale parseLocale ( final String str ) { if ( isISO639LanguageCode ( str ) ) { return new Locale ( str ) ; } final String [ ] segments = str . split ( "_" , - 1 ) ; final String language = segments [ 0 ] ; if ( segments . length == 2 ) { final String country = segments [ 1 ] ; if ( isISO639LanguageCode ( language ) && isISO3166CountryCode ( country ) || isNumericAreaCode ( country ) ) { return new Locale ( language , country ) ; } } else if ( segments . length == 3 ) { final String country = segments [ 1 ] ; final String variant = segments [ 2 ] ; if ( isISO639LanguageCode ( language ) && ( country . length ( ) == 0 || isISO3166CountryCode ( country ) || isNumericAreaCode ( country ) ) && variant . length ( ) > 0 ) { return new Locale ( language , country , variant ) ; } } throw new IllegalArgumentException ( "Invalid locale format: " + str ) ; }
Tries to parse a locale from the given String .
10,698
private static boolean isISO639LanguageCode ( final String str ) { return StringUtils . isAllLowerCase ( str ) && ( str . length ( ) == 2 || str . length ( ) == 3 ) ; }
Checks whether the given String is a ISO 639 compliant language code .
10,699
public static int compareModifierVisibility ( Element a , Element b ) { if ( a . getModifiers ( ) . contains ( Modifier . PUBLIC ) && ! b . getModifiers ( ) . contains ( Modifier . PUBLIC ) ) { return - 1 ; } if ( isDefaultModifier ( a . getModifiers ( ) ) && ! isDefaultModifier ( b . getModifiers ( ) ) ) { return - 1 ; } if ( a . getModifiers ( ) . contains ( Modifier . PROTECTED ) && ! b . getModifiers ( ) . contains ( Modifier . PROTECTED ) ) { return - 1 ; } if ( b . getModifiers ( ) . contains ( Modifier . PUBLIC ) && ! a . getModifiers ( ) . contains ( Modifier . PUBLIC ) ) { return 1 ; } if ( isDefaultModifier ( b . getModifiers ( ) ) && ! isDefaultModifier ( a . getModifiers ( ) ) ) { return 1 ; } if ( b . getModifiers ( ) . contains ( Modifier . PROTECTED ) && ! a . getModifiers ( ) . contains ( Modifier . PROTECTED ) ) { return 1 ; } return 0 ; }
Compare the modifier of two elements