idx
int64 0
41.2k
| question
stringlengths 83
4.15k
| target
stringlengths 5
715
|
---|---|---|
0 | public Blog blogInfo ( String blogName ) { Map < String , String > map = new HashMap < String , String > ( ) ; map . put ( "api_key" , this . apiKey ) ; return requestBuilder . get ( JumblrClient . blogPath ( blogName , "/info" ) , map ) . getBlog ( ) ; } | Get the blog info for a given blog |
1 | public List < User > blogFollowers ( String blogName , Map < String , ? > options ) { return requestBuilder . get ( JumblrClient . blogPath ( blogName , "/followers" ) , options ) . getUsers ( ) ; } | Get the followers for a given blog |
2 | public List < Post > blogLikes ( String blogName , Map < String , ? > options ) { if ( options == null ) { options = Collections . emptyMap ( ) ; } Map < String , Object > soptions = JumblrClient . safeOptionMap ( options ) ; soptions . put ( "api_key" , this . apiKey ) ; return requestBuilder . get ( JumblrClient . blogPath ( blogName , "/likes" ) , soptions ) . getLikedPosts ( ) ; } | Get the public likes for a given blog |
3 | public List < Post > blogPosts ( String blogName , Map < String , ? > options ) { if ( options == null ) { options = Collections . emptyMap ( ) ; } Map < String , Object > soptions = JumblrClient . safeOptionMap ( options ) ; soptions . put ( "api_key" , apiKey ) ; String path = "/posts" ; if ( soptions . containsKey ( "type" ) ) { path += "/" + soptions . get ( "type" ) . toString ( ) ; soptions . remove ( "type" ) ; } return requestBuilder . get ( JumblrClient . blogPath ( blogName , path ) , soptions ) . getPosts ( ) ; } | Get the posts for a given blog |
4 | public Post blogPost ( String blogName , Long postId ) { HashMap < String , String > options = new HashMap < String , String > ( ) ; options . put ( "id" , postId . toString ( ) ) ; List < Post > posts = this . blogPosts ( blogName , options ) ; return posts . size ( ) > 0 ? posts . get ( 0 ) : null ; } | Get an individual post by id |
5 | public List < Post > blogQueuedPosts ( String blogName , Map < String , ? > options ) { return requestBuilder . get ( JumblrClient . blogPath ( blogName , "/posts/queue" ) , options ) . getPosts ( ) ; } | Get the queued posts for a given blog |
6 | public List < Post > userLikes ( Map < String , ? > options ) { return requestBuilder . get ( "/user/likes" , options ) . getLikedPosts ( ) ; } | Get the likes for the authenticated user |
7 | public String blogAvatar ( String blogName , Integer size ) { String pathExt = size == null ? "" : "/" + size . toString ( ) ; return requestBuilder . getRedirectUrl ( JumblrClient . blogPath ( blogName , "/avatar" + pathExt ) ) ; } | Get a specific size avatar for a given blog |
8 | public void like ( Long postId , String reblogKey ) { Map < String , String > map = new HashMap < String , String > ( ) ; map . put ( "id" , postId . toString ( ) ) ; map . put ( "reblog_key" , reblogKey ) ; requestBuilder . post ( "/user/like" , map ) ; } | Like a given post |
9 | public void follow ( String blogName ) { Map < String , String > map = new HashMap < String , String > ( ) ; map . put ( "url" , JumblrClient . blogUrl ( blogName ) ) ; requestBuilder . post ( "/user/follow" , map ) ; } | Follow a given blog |
10 | public void postDelete ( String blogName , Long postId ) { Map < String , String > map = new HashMap < String , String > ( ) ; map . put ( "id" , postId . toString ( ) ) ; requestBuilder . post ( JumblrClient . blogPath ( blogName , "/post/delete" ) , map ) ; } | Delete a given post |
11 | public void postEdit ( String blogName , Long id , Map < String , ? > detail ) throws IOException { Map < String , Object > sdetail = JumblrClient . safeOptionMap ( detail ) ; sdetail . put ( "id" , id ) ; requestBuilder . postMultipart ( JumblrClient . blogPath ( blogName , "/post/edit" ) , sdetail ) ; } | Save edits for a given post |
12 | public Long postCreate ( String blogName , Map < String , ? > detail ) throws IOException { return requestBuilder . postMultipart ( JumblrClient . blogPath ( blogName , "/post" ) , detail ) . getId ( ) ; } | Create a post |
13 | public < T extends Post > T newPost ( String blogName , Class < T > klass ) throws IllegalAccessException , InstantiationException { T post = klass . newInstance ( ) ; post . setClient ( this ) ; post . setBlogName ( blogName ) ; return post ; } | Set up a new post of a given type |
14 | public List < User > followers ( Map < String , ? > options ) { return client . blogFollowers ( this . name , options ) ; } | Get followers for this blog |
15 | public List < Post > posts ( Map < String , ? > options ) { return client . blogPosts ( name , options ) ; } | Get the posts for this blog |
16 | public List < Post > likedPosts ( Map < String , ? > options ) { return client . blogLikes ( this . name , options ) ; } | Get likes posts for this blog |
17 | public List < Post > queuedPosts ( Map < String , ? > options ) { return client . blogQueuedPosts ( name , options ) ; } | Get the queued posts for this blog |
18 | public List < Post > draftPosts ( Map < String , ? > options ) { return client . blogDraftPosts ( name , options ) ; } | Get the draft posts for this blog |
19 | public List < Post > submissions ( Map < String , ? > options ) { return client . blogSubmissions ( name , options ) ; } | Get the submissions for this blog |
20 | public < T extends Post > T newPost ( Class < T > klass ) throws IllegalAccessException , InstantiationException { return client . newPost ( name , klass ) ; } | Create a new post of a given type for this blog |
21 | public PhotoType getType ( ) { if ( this . source != null ) { return PhotoType . SOURCE ; } if ( this . file != null ) { return PhotoType . FILE ; } return null ; } | Get the type of this photo |
22 | public Token postXAuth ( final String email , final String password ) { OAuthRequest request = constructXAuthPost ( email , password ) ; setToken ( "" , "" ) ; sign ( request ) ; return clearXAuth ( request . send ( ) ) ; } | Posts an XAuth request . A new method is needed because the response from the server is not a standard Tumblr JSON response . |
23 | private OAuthRequest constructXAuthPost ( String email , String password ) { OAuthRequest request = new OAuthRequest ( Verb . POST , xauthEndpoint ) ; request . addBodyParameter ( "x_auth_username" , email ) ; request . addBodyParameter ( "x_auth_password" , password ) ; request . addBodyParameter ( "x_auth_mode" , "client_auth" ) ; return request ; } | Construct an XAuth request |
24 | public LazyType getType ( int index ) throws LazyException { LazyNode token = getValueToken ( index ) ; switch ( token . type ) { case LazyNode . OBJECT : return LazyType . OBJECT ; case LazyNode . ARRAY : return LazyType . ARRAY ; case LazyNode . VALUE_TRUE : return LazyType . BOOLEAN ; case LazyNode . VALUE_FALSE : return LazyType . BOOLEAN ; case LazyNode . VALUE_NULL : return LazyType . NULL ; case LazyNode . VALUE_STRING : return LazyType . STRING ; case LazyNode . VALUE_ESTRING : return LazyType . STRING ; case LazyNode . VALUE_INTEGER : return LazyType . INTEGER ; case LazyNode . VALUE_FLOAT : return LazyType . FLOAT ; } return null ; } | Returns the value type of the given field . |
25 | public boolean getBoolean ( int index ) { LazyNode token = getValueToken ( index ) ; if ( token . type == LazyNode . VALUE_TRUE ) return true ; if ( token . type == LazyNode . VALUE_FALSE ) return false ; throw new LazyException ( "Requested value is not a boolean" , token ) ; } | Returns the boolean value stored at the given index . |
26 | public boolean optBoolean ( int index ) { LazyNode token = getOptionalValueToken ( index ) ; if ( token == null ) return false ; if ( token . type == LazyNode . VALUE_NULL ) return false ; if ( token . type == LazyNode . VALUE_TRUE ) return true ; if ( token . type == LazyNode . VALUE_FALSE ) return false ; throw new LazyException ( "Requested value is not a boolean" , token ) ; } | Returns the boolean value stored at the given index or null if there was no such value . |
27 | public String getString ( int index ) throws LazyException { LazyNode token = getValueToken ( index ) ; return token . getStringValue ( ) ; } | Returns the string value stored at the given index . |
28 | public String optString ( int index ) { LazyNode token = getOptionalValueToken ( index ) ; if ( token == null ) return null ; if ( token . type == LazyNode . VALUE_NULL ) return null ; return token . getStringValue ( ) ; } | Returns the string value stored at the given index or null if there was no such value . |
29 | public int optInt ( int index ) { LazyNode token = getOptionalValueToken ( index ) ; if ( token == null ) return 0 ; if ( token . type == LazyNode . VALUE_NULL ) return 0 ; return token . getIntValue ( ) ; } | Returns the int value stored at the given index or 0 if there was no such value . |
30 | public long optLong ( int index ) { LazyNode token = getOptionalValueToken ( index ) ; if ( token == null ) return 0l ; if ( token . type == LazyNode . VALUE_NULL ) return 0l ; return token . getLongValue ( ) ; } | Returns the long value stored at the given index or 0 if there was no such value . |
31 | public double optDouble ( int index ) { LazyNode token = getOptionalValueToken ( index ) ; if ( token == null ) return 0.0 ; if ( token . type == LazyNode . VALUE_NULL ) return 0.0 ; return token . getDoubleValue ( ) ; } | Returns the double value stored at the given index or 0 . 0 if there was no such value . |
32 | public boolean isNull ( int index ) throws LazyException { LazyNode token = getValueToken ( index ) ; if ( token . type == LazyNode . VALUE_NULL ) return true ; return false ; } | Returns true if the value stored at the given index is null . |
33 | private LazyNode getOptionalValueToken ( int index ) throws LazyException { if ( index < 0 ) throw new LazyException ( "Array undex can not be negative" ) ; int num = 0 ; LazyNode child = root . child ; if ( selectInt > - 1 && index >= selectInt ) { num = selectInt ; child = selectToken ; } while ( child != null ) { if ( num == index ) { selectInt = index ; selectToken = child ; return child ; } num ++ ; child = child . next ; } return null ; } | Values for an array are attached as children on the token representing the array itself . This method finds the correct child for a given index and returns it . |
34 | private void push ( final LazyNode token ) { stackTop . addChild ( token ) ; if ( ( stackPointer & STACK_INCREASE ) == STACK_INCREASE ) { LazyNode [ ] newStack = new LazyNode [ STACK_SIZE + STACK_INCREASE + 1 ] ; System . arraycopy ( stack , 0 , newStack , 0 , STACK_SIZE ) ; STACK_SIZE = STACK_SIZE + STACK_INCREASE + 1 ; stack = newStack ; } stack [ stackPointer ++ ] = token ; stackTop = token ; } | Push a token onto the stack and attach it to the previous top as a child |
35 | private LazyNode pop ( ) { LazyNode value = stackTop ; stackPointer -- ; if ( stackPointer > 0 ) { stackTop = stack [ stackPointer - 1 ] ; } return value ; } | Pop a token off the stack and reset the stackTop pointer |
36 | private final void consumeWhiteSpace ( ) { char c = cbuf [ n ] ; while ( c == CH_SPACE || c == CH_LINEFEED || c == CH_TAB || c == CH_CARRIAGE_RETURN ) { n ++ ; c = cbuf [ n ] ; } } | Utility method to consume sections of whitespace |
37 | private final boolean consumeString ( ) throws LazyException { boolean escaped = false ; n ++ ; char c = cbuf [ n ] ; while ( c != CH_QUOTE ) { if ( c == CH_BACKSLASH ) { n ++ ; c = cbuf [ n ] ; if ( ! ( c == CH_QUOTE || c == CH_BACKSLASH || c == CH_SLASH || c == CH_b || c == CH_f || c == CH_n || c == CH_r || c == CH_t || c == CH_u ) ) { throw new LazyException ( "Invalid escape code" , n ) ; } escaped = true ; } n ++ ; c = cbuf [ n ] ; } return escaped ; } | element if an escape character is found |
38 | private final boolean consumeNumber ( char c ) throws LazyException { boolean floatChar = false ; if ( c == CH_DASH ) { n ++ ; c = cbuf [ n ] ; if ( c < CH_0 || c > CH_9 ) { throw new LazyException ( "Digit expected" , n ) ; } } n ++ ; if ( c == CH_0 ) { c = cbuf [ n ] ; if ( c >= CH_0 && c <= CH_9 ) { throw new LazyException ( "Number may not start with leading zero" , n ) ; } } else { c = cbuf [ n ] ; } while ( ! ( c < CH_0 || c > CH_9 ) ) { n ++ ; c = cbuf [ n ] ; } if ( c == CH_DOT ) { floatChar = true ; n ++ ; c = cbuf [ n ] ; if ( c < CH_0 || c > CH_9 ) { throw new LazyException ( "Digit expected" , n ) ; } n ++ ; c = cbuf [ n ] ; while ( ! ( c < CH_0 || c > CH_9 ) ) { n ++ ; c = cbuf [ n ] ; } } if ( c == CH_e || c == CH_E ) { floatChar = true ; n ++ ; c = cbuf [ n ] ; if ( c == CH_DASH || c == CH_PLUS ) { n ++ ; c = cbuf [ n ] ; if ( c < CH_0 || c > CH_9 ) { throw new LazyException ( "Digit expected" , n ) ; } } else if ( c < CH_0 || c > CH_9 ) { throw new LazyException ( "Exponential part expected" , n ) ; } n ++ ; c = cbuf [ n ] ; while ( ! ( c < CH_0 || c > CH_9 ) ) { n ++ ; c = cbuf [ n ] ; } } return floatChar ; } | of the number does not validate correctly |
39 | private void init ( ) { slidingWindow = new LinkedHashMap < String , Integer > ( windowSize + 1 , .75F , false ) { protected boolean removeEldestEntry ( Map . Entry < String , Integer > eldest ) { return size ( ) > windowSize ; } } ; } | Initializes the internal sliding window data structure . |
40 | public String get ( short index ) { if ( index < 0 ) return null ; if ( index >= next ) return null ; return data [ index ] ; } | Returns the value held at a specific location in the dictionary . |
41 | public short put ( String value ) { if ( dataMap . containsKey ( value ) ) { dictionaryHit ++ ; return dataMap . get ( value ) ; } if ( next == MAX_SIZE ) { dictionaryMiss ++ ; return - 1 ; } if ( minRepetitions == 0 ) { data [ next ] = value ; dataMap . put ( value , next ) ; dirty = true ; dictionaryHit ++ ; return next ++ ; } if ( slidingWindow . containsKey ( value ) ) { int count = slidingWindow . get ( value ) + 1 ; if ( count > minRepetitions ) { slidingWindow . remove ( value ) ; data [ next ] = value ; dataMap . put ( value , next ) ; dirty = true ; dictionaryHit ++ ; return next ++ ; } else { slidingWindow . put ( value , count ) ; } } else { slidingWindow . put ( value , 1 ) ; } dictionaryMiss ++ ; return - 1 ; } | Add a new value to the dictionary if we have seen it a certain number of times within the current sliding window . If not return - 1 and mark that we saw it . If the value is already in the dictionary just return the lookup position . |
42 | protected void addChild ( LazyNode token ) { if ( lastChild == null ) { child = token ; lastChild = token ; return ; } lastChild . next = token ; lastChild = token ; } | Add a new child to the current linked list of child tokens |
43 | protected int getChildCount ( ) { int num = 0 ; LazyNode token = child ; while ( token != null ) { num ++ ; token = token . next ; } return num ; } | Count the children attached to this token . Be aware that this requires actual linked list traversal! |
44 | protected int getIntValue ( ) throws LazyException { int i = startIndex ; boolean sign = false ; int value = 0 ; if ( type == VALUE_FLOAT ) { return ( int ) getDoubleValue ( ) ; } else if ( type == VALUE_STRING || type == VALUE_ESTRING ) { if ( dirty ) { if ( dirtyBuf . charAt ( i ) == '-' ) { sign = true ; i ++ ; } for ( ; i < endIndex ; i ++ ) { char c = dirtyBuf . charAt ( i ) ; if ( c < '0' || c > '9' ) throw new LazyException ( "'" + getStringValue ( ) + "' is not a valid integer" , startIndex ) ; value += '0' - c ; if ( i + 1 < endIndex ) { value *= 10 ; } } } else { if ( cbuf [ i ] == '-' ) { sign = true ; i ++ ; } for ( ; i < endIndex ; i ++ ) { char c = cbuf [ i ] ; if ( c < '0' || c > '9' ) throw new LazyException ( "'" + getStringValue ( ) + "' is not a valid integer" , startIndex ) ; value += '0' - c ; if ( i + 1 < endIndex ) { value *= 10 ; } } } return sign ? value : - value ; } else if ( type == VALUE_INTEGER ) { if ( dirty ) { if ( dirtyBuf . charAt ( i ) == '-' ) { sign = true ; i ++ ; } for ( ; i < endIndex ; i ++ ) { char c = dirtyBuf . charAt ( i ) ; value += '0' - c ; if ( i + 1 < endIndex ) { value *= 10 ; } } } else { if ( cbuf [ i ] == '-' ) { sign = true ; i ++ ; } for ( ; i < endIndex ; i ++ ) { char c = cbuf [ i ] ; value += '0' - c ; if ( i + 1 < endIndex ) { value *= 10 ; } } } return sign ? value : - value ; } throw new LazyException ( "Not an integer" , startIndex ) ; } | Parses the characters of this token and attempts to construct an integer value from them . |
45 | protected double getDoubleValue ( ) throws LazyException { double d = 0.0 ; String str = getStringValue ( ) ; try { d = Double . parseDouble ( str ) ; } catch ( NumberFormatException nfe ) { } return d ; } | Parses the characters of this token and attempts to construct a double value from them . |
46 | protected String getStringValue ( ) { if ( type == VALUE_NULL ) { return null ; } else if ( ! ( type == VALUE_ESTRING || type == EFIELD ) ) { if ( dirty ) { return dirtyBuf . substring ( startIndex , endIndex ) ; } return new String ( cbuf , startIndex , endIndex - startIndex ) ; } else { StringBuilder buf = new StringBuilder ( endIndex - startIndex ) ; if ( dirty ) { for ( int i = startIndex ; i < endIndex ; i ++ ) { char c = dirtyBuf . charAt ( i ) ; if ( c == '\\' ) { i ++ ; c = dirtyBuf . charAt ( i ) ; if ( c == '"' || c == '\\' || c == '/' ) { buf . append ( c ) ; } else if ( c == 'b' ) { buf . append ( '\b' ) ; } else if ( c == 'f' ) { buf . append ( '\f' ) ; } else if ( c == 'n' ) { buf . append ( '\n' ) ; } else if ( c == 'r' ) { buf . append ( '\r' ) ; } else if ( c == 't' ) { buf . append ( '\t' ) ; } else if ( c == 'u' ) { String code = dirtyBuf . substring ( i + 1 , i + 5 ) ; buf . append ( ( char ) Integer . parseInt ( code , 16 ) ) ; i += 4 ; } } else { buf . append ( c ) ; } } } else { for ( int i = startIndex ; i < endIndex ; i ++ ) { char c = cbuf [ i ] ; if ( c == '\\' ) { i ++ ; c = cbuf [ i ] ; if ( c == '"' || c == '\\' || c == '/' ) { buf . append ( c ) ; } else if ( c == 'b' ) { buf . append ( '\b' ) ; } else if ( c == 'f' ) { buf . append ( '\f' ) ; } else if ( c == 'n' ) { buf . append ( '\n' ) ; } else if ( c == 'r' ) { buf . append ( '\r' ) ; } else if ( c == 't' ) { buf . append ( '\t' ) ; } else if ( c == 'u' ) { String code = new String ( cbuf , i + 1 , 4 ) ; buf . append ( ( char ) Integer . parseInt ( code , 16 ) ) ; i += 4 ; } } else { buf . append ( c ) ; } } } return buf . toString ( ) ; } } | Extracts a string containing the characters given by this token . If the token was marked as having escaped characters they will be unescaped before the value is returned . |
47 | private void addCommaSeparatedChildren ( Template template ) { LazyNode next = child ; boolean first = true ; while ( next != null ) { if ( first ) { first = false ; } else { template . addConstant ( "," ) ; } next . addSegments ( template ) ; next = next . next ; } } | Functionality for extracting templates |
48 | protected static LazyNode readFromBuffer ( byte [ ] raw ) { ByteBuffer buf = ByteBuffer . wrap ( raw ) ; return readFromBuffer ( buf ) ; } | Functionality for reading and writing LazyNode structures |
49 | public static LazyElement parse ( String str ) throws LazyException { int index = 0 ; while ( index < str . length ( ) ) { char ch = str . charAt ( index ) ; if ( ch == '[' ) { return new LazyArray ( str ) ; } if ( ch == '{' ) { return new LazyObject ( str ) ; } index ++ ; } throw new LazyException ( "The given string is not a JSON object or array" ) ; } | Parses a string and returns either a LazyObject or LazyArray |
50 | public int length ( ) { if ( root . child == null ) { return 0 ; } if ( length > - 1 ) { return length ; } length = root . getChildCount ( ) ; return length ; } | Returns the number of fields on this object |
51 | public String getString ( String key ) throws LazyException { LazyNode token = getFieldToken ( key ) ; return token . getStringValue ( ) ; } | Returns the string value stored in this object for the given key . |
52 | public String optString ( String key , String defaultValue ) { LazyNode token = getOptionalFieldToken ( key ) ; if ( token == null ) return defaultValue ; if ( token . type == LazyNode . VALUE_NULL ) return defaultValue ; return token . getStringValue ( ) ; } | Returns the string value stored in this object for the given key . Returns the default value if there is no such key . |
53 | public int getInt ( String key ) throws LazyException { LazyNode token = getFieldToken ( key ) ; return token . getIntValue ( ) ; } | Returns the integer value stored in this object for the given key . |
54 | public int optInt ( String key ) { LazyNode token = getOptionalFieldToken ( key ) ; if ( token == null ) return 0 ; if ( token . type == LazyNode . VALUE_NULL ) return 0 ; return token . getIntValue ( ) ; } | Returns the integer value stored in this object for the given key . Returns 0 if there is no such key . |
55 | public long getLong ( String key ) throws LazyException { LazyNode token = getFieldToken ( key ) ; return token . getLongValue ( ) ; } | Returns the long value stored in this object for the given key . |
56 | public long optLong ( String key ) { LazyNode token = getOptionalFieldToken ( key ) ; if ( token == null ) return 0l ; if ( token . type == LazyNode . VALUE_NULL ) return 0l ; return token . getLongValue ( ) ; } | Returns the long value stored in this object for the given key . Returns 0 if there is no such key . |
57 | public double getDouble ( String key ) throws LazyException { LazyNode token = getFieldToken ( key ) ; return token . getDoubleValue ( ) ; } | Returns the double value stored in this object for the given key . |
58 | public double optDouble ( String key ) { LazyNode token = getOptionalFieldToken ( key ) ; if ( token == null ) return 0.0 ; if ( token . type == LazyNode . VALUE_NULL ) return 0.0 ; return token . getDoubleValue ( ) ; } | Returns the double value stored in this object for the given key . Returns 0 . 0 if there is no such key . |
59 | public boolean isNull ( String key ) { LazyNode token = getOptionalFieldToken ( key ) ; if ( token == null ) return true ; if ( token . type == LazyNode . VALUE_NULL ) return true ; return false ; } | Returns true if the value stored in this object for the given key is null . |
60 | public boolean getBoolean ( String key ) { LazyNode token = getFieldToken ( key ) ; if ( token . type == LazyNode . VALUE_STRING || token . type == LazyNode . VALUE_ESTRING ) { String str = token . getStringValue ( ) . toLowerCase ( ) . trim ( ) ; if ( str . equals ( "true" ) ) return true ; if ( str . equals ( "false" ) ) return false ; throw new LazyException ( "Requested value is not a boolean" , token ) ; } if ( token . type == LazyNode . VALUE_TRUE ) return true ; if ( token . type == LazyNode . VALUE_FALSE ) return false ; throw new LazyException ( "Requested value is not a boolean" , token ) ; } | Returns the boolean value stored in this object for the given key . |
61 | public boolean optBoolean ( String key ) { LazyNode token = getOptionalFieldToken ( key ) ; if ( token == null ) return false ; if ( token . type == LazyNode . VALUE_STRING || token . type == LazyNode . VALUE_ESTRING ) { String str = token . getStringValue ( ) . toLowerCase ( ) . trim ( ) ; if ( str . equals ( "true" ) ) return true ; if ( str . equals ( "false" ) ) return false ; throw new LazyException ( "Requested value is not a boolean" , token ) ; } if ( token . type == LazyNode . VALUE_TRUE ) return true ; return false ; } | Returns the boolean value stored in this object for the given key . Returns false if there is no such key . |
62 | public LazyObject getJSONObject ( String key ) throws LazyException { LazyNode token = getFieldToken ( key ) ; if ( token . type != LazyNode . OBJECT ) throw new LazyException ( "Requested value is not an object" , token ) ; LazyObject obj = new LazyObject ( token ) ; obj . parent = this ; return obj ; } | Returns the JSON object stored in this object for the given key . |
63 | public LazyObject optJSONObject ( String key ) throws LazyException { LazyNode token = getOptionalFieldToken ( key ) ; if ( token == null ) return null ; if ( token . type == LazyNode . VALUE_NULL ) return null ; if ( token . type != LazyNode . OBJECT ) return null ; LazyObject obj = new LazyObject ( token ) ; obj . parent = this ; return obj ; } | Returns the JSON object stored in this object for the given key on null if the key doesn t exist . |
64 | public LazyArray getJSONArray ( String key ) throws LazyException { LazyNode token = getFieldToken ( key ) ; if ( token . type != LazyNode . ARRAY ) throw new LazyException ( "Requested value is not an array" , token ) ; LazyArray arr = new LazyArray ( token ) ; arr . parent = this ; return arr ; } | Returns the JSON array stored in this object for the given key . |
65 | public LazyArray optJSONArray ( String key ) throws LazyException { LazyNode token = getOptionalFieldToken ( key ) ; if ( token == null ) return null ; if ( token . type == LazyNode . VALUE_NULL ) return null ; if ( token . type != LazyNode . ARRAY ) return null ; LazyArray arr = new LazyArray ( token ) ; arr . parent = this ; return arr ; } | Returns the JSON array stored in this object for the given key or null if the key doesn t exist . |
66 | public Set < String > keySet ( ) { HashSet < String > set = new HashSet < String > ( ) ; Iterator < String > keys = keys ( ) ; while ( keys . hasNext ( ) ) { set . add ( keys . next ( ) ) ; } return set ; } | Returns a set containing all keys on this object . If possible use the keys iterator instead for improved performance . |
67 | private boolean keyMatch ( String key , LazyNode token ) { if ( token . type == LazyNode . EFIELD ) { String field = token . getStringValue ( ) ; return field . equals ( key ) ; } else { int length = key . length ( ) ; if ( token . endIndex - token . startIndex != length ) { return false ; } if ( token . dirty ) { for ( int i = 0 ; i < length ; i ++ ) { char c = key . charAt ( i ) ; if ( c != token . dirtyBuf . charAt ( token . startIndex + i ) ) { return false ; } } } else { for ( int i = 0 ; i < length ; i ++ ) { char c = key . charAt ( i ) ; if ( c != token . cbuf [ token . startIndex + i ] ) { return false ; } } } return true ; } } | Utility method to evaluate wether a given string matches the value of a field . |
68 | public boolean has ( String key ) { LazyNode child = root . child ; while ( child != null ) { if ( keyMatch ( key , child ) ) { return true ; } child = child . next ; } return false ; } | Returns true if the given key matches a field on this object . |
69 | public String read ( ByteBuffer buf , DictionaryCache dict ) { StringBuilder out = new StringBuilder ( ) ; if ( pre != null ) out . append ( pre ) ; if ( type == VOID ) return out . toString ( ) ; if ( type == NULL ) { out . append ( "null" ) ; return out . toString ( ) ; } if ( type == BYTE ) { out . append ( buf . get ( ) ) ; return out . toString ( ) ; } if ( type == SHORT ) { out . append ( buf . getShort ( ) ) ; return out . toString ( ) ; } if ( type == INT ) { out . append ( buf . getInt ( ) ) ; return out . toString ( ) ; } if ( type == LONG ) { out . append ( buf . getLong ( ) ) ; return out . toString ( ) ; } if ( type == DOUBLE ) { out . append ( buf . getDouble ( ) ) ; return out . toString ( ) ; } if ( type == BOOLEAN ) { out . append ( ( buf . get ( ) == 0 ? "false" : "true" ) ) ; return out . toString ( ) ; } if ( type == STRING ) { short pos = buf . getShort ( ) ; if ( pos > - 1 ) { out . append ( "\"" ) ; out . append ( dict . get ( pos ) ) ; out . append ( "\"" ) ; } else { int size = 0 ; int val = buf . get ( ) & 0xFF ; while ( val == 255 ) { size += val ; val = buf . get ( ) & 0xFF ; } size += val ; byte [ ] data = new byte [ size ] ; buf . get ( data ) ; out . append ( "\"" ) ; out . append ( new String ( data , StandardCharsets . UTF_8 ) ) ; out . append ( "\"" ) ; } return out . toString ( ) ; } return null ; } | Read this segment from a byte buffer using the given dictionary for lookups . The dictionary may be null if no dictionary values were used when writing data for this segment . |
70 | public static Builder fromJndi ( final Context context , final String lookupKey , Flavor flavor ) { Options options = new OptionsDefault ( flavor ) ; return new BuilderImpl ( null , ( ) -> { DataSource ds ; try { ds = ( DataSource ) context . lookup ( lookupKey ) ; } catch ( Exception e ) { throw new DatabaseException ( "Unable to locate the DataSource in JNDI using key " + lookupKey , e ) ; } try { return ds . getConnection ( ) ; } catch ( Exception e ) { throw new DatabaseException ( "Unable to obtain a connection from JNDI DataSource " + lookupKey , e ) ; } } , options ) ; } | Builder method to create and initialize an instance of this class using a JNDI resource . To use this method you must explicitly indicate what Flavor of database we are dealing with . |
71 | public static < T > Handler < T > mdc ( final Handler < T > handler ) { if ( handler == null ) { throw new IllegalArgumentException ( "handler may not be null" ) ; } final Map < String , String > mdc = MDC . getCopyOfContextMap ( ) ; return t -> { Map < String , String > restore = MDC . getCopyOfContextMap ( ) ; try { if ( mdc == null ) { MDC . clear ( ) ; } else { MDC . setContextMap ( mdc ) ; } handler . handle ( t ) ; } finally { if ( restore == null ) { MDC . clear ( ) ; } else { MDC . setContextMap ( restore ) ; } } } ; } | Wrap a Handler in a way that will preserve the SLF4J MDC context . The context from the current thread at the time of this method call will be cached and restored within the wrapper at the time the handler is invoked . This version delegates the handler call directly on the thread that calls it . |
72 | public Sql listSeparator ( String sql ) { if ( listFirstItem . peek ( ) ) { listFirstItem . pop ( ) ; listFirstItem . push ( false ) ; return this ; } else { return append ( sql ) ; } } | Appends the passed bit of sql only if a previous item has already been appended and notes that the list is not empty . |
73 | public Category getSelectedCategory ( ) { TreeItem < Category > selectedTreeItem = navigationView . treeView . getSelectionModel ( ) . getSelectedItem ( ) ; if ( selectedTreeItem != null ) { return navigationView . treeView . getSelectionModel ( ) . getSelectedItem ( ) . getValue ( ) ; } return null ; } | Retrieves the currently selected category in the TreeSearchView . |
74 | private void createRadioButtons ( ) { node . getChildren ( ) . clear ( ) ; radioButtons . clear ( ) ; for ( int i = 0 ; i < field . getItems ( ) . size ( ) ; i ++ ) { RadioButton rb = new RadioButton ( ) ; rb . setText ( field . getItems ( ) . get ( i ) . toString ( ) ) ; rb . setToggleGroup ( toggleGroup ) ; radioButtons . add ( rb ) ; } if ( field . getSelection ( ) != null ) { radioButtons . get ( field . getItems ( ) . indexOf ( field . getSelection ( ) ) ) . setSelected ( true ) ; } node . getChildren ( ) . addAll ( radioButtons ) ; } | This method creates radio buttons and adds them to radioButtons and is used when the itemsProperty on the field changes . |
75 | public void layoutParts ( ) { StringBuilder styleClass = new StringBuilder ( "group" ) ; int nextRow = PreferencesFxUtils . getRowCount ( grid ) + 1 ; if ( preferencesGroup . getTitle ( ) != null ) { grid . add ( titleLabel , 0 , nextRow ++ , 2 , 1 ) ; styleClass . append ( "-title" ) ; titleLabel . getStyleClass ( ) . add ( "group-title" ) ; } List < Field > fields = preferencesGroup . getElements ( ) . stream ( ) . map ( Field . class :: cast ) . collect ( Collectors . toList ( ) ) ; styleClass . append ( "-setting" ) ; int rowAmount = nextRow ; for ( int i = 0 ; i < fields . size ( ) ; i ++ ) { Field field = fields . get ( i ) ; SimpleControl c = ( SimpleControl ) field . getRenderer ( ) ; c . setField ( field ) ; grid . add ( c . getFieldLabel ( ) , 0 , i + rowAmount , 1 , 1 ) ; grid . add ( c . getNode ( ) , 1 , i + rowAmount , 1 , 1 ) ; GridPane . setHgrow ( c . getNode ( ) , Priority . SOMETIMES ) ; GridPane . setValignment ( c . getNode ( ) , VPos . CENTER ) ; GridPane . setValignment ( c . getFieldLabel ( ) , VPos . CENTER ) ; if ( i == fields . size ( ) - 1 ) { styleClass . append ( "-last" ) ; GridPane . setMargin ( c . getNode ( ) , new Insets ( 0 , 0 , PreferencesFxFormRenderer . SPACING * 4 , 0 ) ) ; GridPane . setMargin ( c . getFieldLabel ( ) , new Insets ( 0 , 0 , PreferencesFxFormRenderer . SPACING * 4 , 0 ) ) ; } c . getFieldLabel ( ) . getStyleClass ( ) . add ( styleClass . toString ( ) + "-label" ) ; c . getNode ( ) . getStyleClass ( ) . add ( styleClass . toString ( ) + "-node" ) ; } } | Defines the layout of the rendered group . |
76 | private void setupClose ( ) { this . getButtonTypes ( ) . add ( ButtonType . CLOSE ) ; Node closeButton = dialog . getDialogPane ( ) . lookupButton ( ButtonType . CLOSE ) ; closeButton . managedProperty ( ) . bind ( closeButton . visibleProperty ( ) ) ; closeButton . setVisible ( false ) ; } | Instantiates a close button and makes it invisible . Dialog requires at least one button to close the dialog window . |
77 | public void doWithoutListeners ( Setting setting , Runnable action ) { LOGGER . trace ( String . format ( "doWithoutListeners: setting: %s" , setting ) ) ; setListenerActive ( false ) ; LOGGER . trace ( "removed listener" ) ; action . run ( ) ; LOGGER . trace ( "performed action" ) ; setListenerActive ( true ) ; LOGGER . trace ( "add listener back" ) ; } | Enables to perform an action without firing the attached ChangeListener of a Setting . This is used by undo and redo since those shouldn t cause a new change to be added . |
78 | public boolean undo ( ) { LOGGER . trace ( "undo, before, size: " + changes . size ( ) + " pos: " + position . get ( ) + " validPos: " + validPosition . get ( ) ) ; Change lastChange = prev ( ) ; if ( lastChange != null ) { doWithoutListeners ( lastChange . getSetting ( ) , lastChange :: undo ) ; LOGGER . trace ( "undo, after, size: " + changes . size ( ) + " pos: " + position . get ( ) + " validPos: " + validPosition . get ( ) ) ; return true ; } return false ; } | Undos a change in the history . |
79 | public boolean redo ( ) { LOGGER . trace ( "redo, before, size: " + changes . size ( ) + " pos: " + position . get ( ) + " validPos: " + validPosition . get ( ) ) ; Change nextChange = next ( ) ; if ( nextChange != null ) { doWithoutListeners ( nextChange . getSetting ( ) , nextChange :: redo ) ; LOGGER . trace ( "redo, after, size: " + changes . size ( ) + " pos: " + position . get ( ) + " validPos: " + validPosition . get ( ) ) ; return true ; } return false ; } | Redos a change in the history . |
80 | public void clear ( boolean undoAll ) { LOGGER . trace ( "Clear called, with undoAll: " + undoAll ) ; if ( undoAll ) { undoAll ( ) ; } LOGGER . trace ( "Clearing changes" ) ; changes . clear ( ) ; position . set ( - 1 ) ; validPosition . set ( - 1 ) ; } | Clears the change history . |
81 | public void translate ( ) { if ( translationService == null ) { title . setValue ( titleKey . getValue ( ) ) ; return ; } if ( ! Strings . isNullOrEmpty ( titleKey . getValue ( ) ) ) { title . setValue ( translationService . translate ( titleKey . get ( ) ) ) ; } } | Updates the title based on the titleKey for i18n . If there is no translationService the title will be the same as the titleKey . If there is a translationService the titleKey will be used to lookup the translated variant using the translationService and the title is set . |
82 | private void createCheckboxes ( ) { node . getChildren ( ) . clear ( ) ; checkboxes . clear ( ) ; for ( int i = 0 ; i < field . getItems ( ) . size ( ) ; i ++ ) { CheckBox cb = new CheckBox ( ) ; cb . setText ( field . getItems ( ) . get ( i ) . toString ( ) ) ; cb . setSelected ( field . getSelection ( ) . contains ( field . getItems ( ) . get ( i ) ) ) ; checkboxes . add ( cb ) ; } node . getChildren ( ) . addAll ( checkboxes ) ; } | This method creates node and adds them to checkboxes and is used when the itemsProperty on the field changes . |
83 | private void setupCheckboxBindings ( ) { for ( CheckBox checkbox : checkboxes ) { checkbox . disableProperty ( ) . bind ( field . editableProperty ( ) . not ( ) ) ; } } | Sets up bindings for all checkboxes . |
84 | private void setupCheckboxEventHandlers ( ) { for ( int i = 0 ; i < checkboxes . size ( ) ; i ++ ) { final int j = i ; checkboxes . get ( i ) . setOnAction ( event -> { if ( checkboxes . get ( j ) . isSelected ( ) ) { field . select ( j ) ; } else { field . deselect ( j ) ; } } ) ; } } | Sets up event handlers for all checkboxes . |
85 | private void setupTextField ( ) { searchFld = new CustomTextField ( ) ; GlyphFont fontAwesome = GlyphFontRegistry . font ( "FontAwesome" ) ; Glyph glyph = fontAwesome . create ( FontAwesome . Glyph . SEARCH ) . color ( Color . GRAY ) ; glyph . setPadding ( new Insets ( 0 , 3 , 0 , 5 ) ) ; searchFld . setLeft ( glyph ) ; } | Initializes the TextField and sets the search icon . |
86 | public void init ( PreferencesFxModel model , StringProperty searchText , ObjectProperty < TreeItemPredicate < Category > > predicateProperty ) { this . model = model ; initializeSearch ( ) ; initializeSearchText ( searchText ) ; bindFilterPredicate ( predicateProperty ) ; } | Initializes the SearchHandler by initially creating all necessary lists for filtering and setting up the bindings . |
87 | private void initializeSearchTextListener ( ) { searchText . addListener ( ( observable , oldText , newText ) -> { if ( newText . equals ( "" ) ) { resetSearch ( ) ; } else { updateSearch ( newText ) ; } } ) ; } | Reacts upon changes in the search text . If the search text is empty everything will be unmarked else the search will be updated . |
88 | public void bindFilterPredicate ( ObjectProperty < TreeItemPredicate < Category > > predicateProperty ) { predicateProperty . bind ( Bindings . createObjectBinding ( ( ) -> { if ( searchText . get ( ) == null || searchText . get ( ) . isEmpty ( ) ) { return null ; } return TreeItemPredicate . create ( filterPredicate ) ; } , searchText ) ) ; } | Binds the predicateProperty to ensure filtering according to the searchText . |
89 | public PreferencesFx saveSettings ( boolean save ) { preferencesFxModel . setSaveSettings ( save ) ; if ( ! save ) { preferencesFxModel . getStorageHandler ( ) . clearPreferences ( ) ; } return this ; } | Defines whether the adjusted settings of the application should be saved or not . |
90 | public PreferencesFx removeEventHandler ( EventType < PreferencesFxEvent > eventType , EventHandler < ? super PreferencesFxEvent > eventHandler ) { preferencesFxModel . removeEventHandler ( eventType , eventHandler ) ; return this ; } | Unregisters a previously registered event handler from the model . One handler might have been registered for different event types so the caller needs to specify the particular event type from which to unregister the handler . |
91 | private void initializeCategoryTranslation ( ) { flatCategoriesLst . forEach ( category -> { translationServiceProperty ( ) . addListener ( ( observable , oldValue , newValue ) -> { category . translate ( newValue ) ; newValue . addListener ( ( ) -> category . translate ( newValue ) ) ; } ) ; } ) ; } | Sets up a binding of the TranslationService on the model so that the Category s title gets translated properly according to the TranslationService used . |
92 | public Category loadSelectedCategory ( ) { String breadcrumb = storageHandler . loadSelectedCategory ( ) ; Category defaultCategory = getCategories ( ) . get ( DEFAULT_CATEGORY ) ; if ( breadcrumb == null ) { return defaultCategory ; } return flatCategoriesLst . stream ( ) . filter ( category -> category . getBreadcrumb ( ) . equals ( breadcrumb ) ) . findAny ( ) . orElse ( defaultCategory ) ; } | Loads the last selected Category before exiting the Preferences window . |
93 | public void removeEventHandler ( EventType < PreferencesFxEvent > eventType , EventHandler < ? super PreferencesFxEvent > eventHandler ) { if ( eventType == null ) { throw new NullPointerException ( "Argument eventType must not be null" ) ; } if ( eventHandler == null ) { throw new NullPointerException ( "Argument eventHandler must not be null" ) ; } List < EventHandler < ? super PreferencesFxEvent > > list = this . eventHandlers . get ( eventType ) ; if ( list != null ) { list . remove ( eventHandler ) ; } } | Unregisters a previously registered event handler . One handler might have been registered for different event types so the caller needs to specify the particular event type from which to unregister the handler . |
94 | public ObservableList loadObservableList ( String breadcrumb , ObservableList defaultObservableList ) { String json = getSerializedPreferencesValue ( breadcrumb , gson . toJson ( defaultObservableList ) ) ; return FXCollections . observableArrayList ( gson . fromJson ( json , ArrayList . class ) ) ; } | Searches in the preferences after a serialized ArrayList using the given key deserializes and returns it as ObservableArrayList . When an ObservableList is deserialzed Gson returns an ArrayList and needs to be wrapped into an ObservableArrayList . This is only needed for loading . |
95 | public static < P > Setting of ( String description , ListProperty < P > items , ObjectProperty < P > selection ) { return new Setting < > ( description , Field . ofSingleSelectionType ( items , selection ) . label ( description ) . render ( new SimpleComboBoxControl < > ( ) ) , selection ) ; } | Creates a combobox with single selection . |
96 | public static < P > Setting of ( String description , ListProperty < P > items , ListProperty < P > selections ) { return new Setting < > ( description , Field . ofMultiSelectionType ( items , selections ) . label ( description ) . render ( new SimpleListViewControl < > ( ) ) , selections ) ; } | Creates a combobox with multiselection . At least one element has to be selected at all times . |
97 | public static < F extends Field < F > , P extends Property > Setting of ( String description , F field , P property ) { return new Setting < > ( description , field . label ( description ) , property ) ; } | Creates a setting of a custom defined field . |
98 | public final Setting validate ( Validator ... newValue ) { if ( field instanceof DataField ) { ( ( DataField ) field ) . validate ( newValue ) ; } else { throw new UnsupportedOperationException ( "Field type must be instance of DataField" ) ; } return this ; } | Sets the list of validators for the current field . This overrides all validators that have previously been added . |
99 | public void mark ( ) { if ( ! marked ) { SimpleControl renderer = ( SimpleControl ) getField ( ) . getRenderer ( ) ; Node markNode = renderer . getFieldLabel ( ) ; markNode . getStyleClass ( ) . add ( MARKED_STYLE_CLASS ) ; markNode . setOnMouseExited ( unmarker ) ; marked = ! marked ; } } | Marks a setting . Is used for the search which marks and unmarks items depending on the match as a form of visual feedback . |
End of preview. Expand
in Dataset Viewer.
No dataset card yet
New: Create and edit this dataset card directly on the website!
Contribute a Dataset Card- Downloads last month
- 58