idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
29,800 | public JsonAssert isEqualTo ( Object expected ) { Diff diff = Diff . create ( expected , actual , "fullJson" , path . asPrefix ( ) , configuration ) ; String overridingErrorMessage = info . overridingErrorMessage ( ) ; if ( ! isNullOrEmpty ( overridingErrorMessage ) && ! diff . similar ( ) ) { failWithMessage ( overridingErrorMessage ) ; } else { diff . failIfDifferent ( MessageFormatter . instance ( ) . format ( info . description ( ) , info . representation ( ) , "" ) ) ; } return this ; } | Compares JSONs . |
29,801 | private void failWithMessage ( String errorMessage ) { AssertionError assertionError = Failures . instance ( ) . failureIfErrorMessageIsOverridden ( info ) ; if ( assertionError == null ) { String description = MessageFormatter . instance ( ) . format ( info . description ( ) , info . representation ( ) , "" ) ; assertionError = new AssertionError ( description + errorMessage ) ; } Failures . instance ( ) . removeAssertJRelatedElementsFromStackTraceIfNeeded ( assertionError ) ; throw assertionError ; } | Copy from AssertJ to prevent errors with percents in error message |
29,802 | public MapAssert < String , Object > isObject ( ) { Node node = assertType ( OBJECT ) ; return new JsonMapAssert ( ( Map < String , Object > ) node . getValue ( ) , path . asPrefix ( ) , configuration ) . as ( "Different value found in node \"%s\"" , path ) ; } | Asserts that given node is present and is of type object . |
29,803 | public BigDecimalAssert asNumber ( ) { isPresent ( NUMBER . getDescription ( ) ) ; Node node = getNode ( actual , "" ) ; if ( node . getNodeType ( ) == NUMBER ) { return createBigDecimalAssert ( node . decimalValue ( ) ) ; } else if ( node . getNodeType ( ) == STRING ) { try { return createBigDecimalAssert ( new BigDecimal ( node . asText ( ) ) ) ; } catch ( NumberFormatException e ) { failWithMessage ( "Node \"" + path + "\" can not be converted to number expected: <a number> but was: <" + quoteTextValue ( node . getValue ( ) ) + ">." ) ; } } else { failOnType ( node , "number or string" ) ; } return null ; } | Asserts that given node is present and is of type number or a string that can be parsed as a number . |
29,804 | public ListAssert < Object > isArray ( ) { Node node = assertType ( ARRAY ) ; return new JsonListAssert ( ( List < ? > ) node . getValue ( ) , path . asPrefix ( ) , configuration ) . as ( "Different value found in node \"%s\"" , path ) ; } | Asserts that given node is present and is of type array . |
29,805 | public BooleanAssert isBoolean ( ) { Node node = assertType ( BOOLEAN ) ; return new BooleanAssert ( ( Boolean ) node . getValue ( ) ) . as ( "Different value found in node \"%s\"" , path ) ; } | Asserts that given node is present and is of type boolean . |
29,806 | public StringAssert isString ( ) { Node node = assertType ( STRING ) ; return new StringAssert ( ( String ) node . getValue ( ) ) . as ( "Different value found in node \"%s\"" , path ) ; } | Asserts that given node is present and is of type string . |
29,807 | public JsonAssert isNotNull ( ) { isPresent ( "not null" ) ; Node node = getNode ( actual , "" ) ; if ( node . getNodeType ( ) == NULL ) { failOnType ( node , "not null" ) ; } return this ; } | Asserts that given node is present and is not null . |
29,808 | Path toField ( String name ) { if ( isRoot ( ) ) { return copy ( name ) ; } else { return copy ( path + "." + name ) ; } } | Construct path to a filed . |
29,809 | public static < T > ConfigurableJsonMatcher < T > jsonPartEquals ( String path , Object expected ) { return new JsonPartMatcher < > ( path , expected ) ; } | Is the part of the JSON equivalent? |
29,810 | public static < T > Matcher < T > jsonPartMatches ( String path , Matcher < ? > matcher ) { return new MatcherApplyingMatcher < > ( path , matcher ) ; } | Applies matcher to the part of the JSON . |
29,811 | static boolean isClassPresent ( String className ) { try { ClassUtils . class . getClassLoader ( ) . loadClass ( className ) ; return true ; } catch ( Throwable e ) { return false ; } } | Checks if given class is present . |
29,812 | public Configuration withTolerance ( BigDecimal tolerance ) { return new Configuration ( tolerance , options , ignorePlaceholder , matchers , pathsToBeIgnored , differenceListener ) ; } | Sets numerical comparison tolerance . |
29,813 | public Configuration withOptions ( Option first , Option ... next ) { return new Configuration ( tolerance , options . with ( first , next ) , ignorePlaceholder , matchers , pathsToBeIgnored , differenceListener ) ; } | Adds comparison options . |
29,814 | public Configuration withOptions ( Options options ) { return new Configuration ( tolerance , options , ignorePlaceholder , matchers , pathsToBeIgnored , differenceListener ) ; } | Sets comparison options . |
29,815 | public Configuration withIgnorePlaceholder ( String ignorePlaceholder ) { return new Configuration ( tolerance , options , ignorePlaceholder , matchers , pathsToBeIgnored , differenceListener ) ; } | Sets ignore placeholder . |
29,816 | public Configuration withDifferenceListener ( DifferenceListener differenceListener ) { return new Configuration ( tolerance , options , ignorePlaceholder , matchers , pathsToBeIgnored , differenceListener ) ; } | Sets difference listener |
29,817 | public static Reader resource ( String resourceName ) { if ( resourceName == null ) { throw new NullPointerException ( "'null' passed instead of resource name" ) ; } final InputStream resourceStream = ClassLoader . getSystemResourceAsStream ( resourceName ) ; if ( resourceStream == null ) { throw new IllegalArgumentException ( format ( "resource '%s' not found" , resourceName ) ) ; } return new BufferedReader ( new InputStreamReader ( resourceStream ) ) ; } | Helper method to read a classpath resource . |
29,818 | public ResultMatcher isPresent ( ) { return new AbstractResultMatcher ( path , configuration ) { public void doMatch ( Object actual ) { isPresent ( actual ) ; } } ; } | Fails if the node is missing . |
29,819 | public ResultMatcher isArray ( ) { return new AbstractResultMatcher ( path , configuration ) { public void doMatch ( Object actual ) { isPresent ( actual ) ; Node node = getNode ( actual ) ; if ( node . getNodeType ( ) != ARRAY ) { failOnType ( node , "an array" ) ; } } } ; } | Fails if the selected JSON is not an Array or is not present . |
29,820 | public ResultMatcher isObject ( ) { return new AbstractResultMatcher ( path , configuration ) { public void doMatch ( Object actual ) { isPresent ( actual ) ; Node node = getNode ( actual ) ; if ( node . getNodeType ( ) != OBJECT ) { failOnType ( node , "an object" ) ; } } } ; } | Fails if the selected JSON is not an Object or is not present . |
29,821 | public ResultMatcher isString ( ) { return new AbstractResultMatcher ( path , configuration ) { public void doMatch ( Object actual ) { isString ( actual ) ; } } ; } | Fails if the selected JSON is not a String or is not present . |
29,822 | public ResultMatcher isNull ( ) { return new AbstractResultMatcher ( path , configuration ) { public void doMatch ( Object actual ) { isNull ( actual ) ; } } ; } | Fails if selected JSON is not null . |
29,823 | public ResultMatcher isNotNull ( ) { return new AbstractResultMatcher ( path , configuration ) { public void doMatch ( Object actual ) { isNotNull ( actual ) ; } } ; } | Fails if selected JSON is null . |
29,824 | public static Node valueToNode ( Object source ) { if ( source instanceof Node ) { return ( Node ) source ; } else { return converter . valueToNode ( source ) ; } } | Converts value to Json node . It can be Map String null or primitive . Should not be parsed just converted . |
29,825 | public static boolean nodeExists ( Object json , String path ) { return ! getNode ( json , path ) . isMissingNode ( ) ; } | Returns true if the node exists . |
29,826 | static boolean nodeAbsent ( Object json , Path path , boolean treatNullAsAbsent ) { Node node = getNode ( json , path ) ; if ( node . isNull ( ) ) { return treatNullAsAbsent ; } else { return node . isMissingNode ( ) ; } } | Returns true if the is absent . |
29,827 | private List < Integer > getEqualToUsedOnlyInEquivalentElements ( List < Integer > equalTo , List < Integer > equivalentElements ) { List < Integer > result = new ArrayList < > ( equalTo ) ; for ( int i = 0 ; i < equalElements . size ( ) ; i ++ ) { if ( ! alreadyMatched . get ( i ) ) { if ( ! equivalentElements . contains ( i ) ) { result . removeAll ( equalElements . get ( i ) ) ; } } } return result ; } | If there are more equivalent elements we can match those that are not used anywhere else we iterate over actual elements that are not in equivalentElements and from equalTo remove those that are used outside equivalent elements |
29,828 | private void compareObjectNodes ( Context context ) { Node expected = context . getExpectedNode ( ) ; Node actual = context . getActualNode ( ) ; Path path = context . getActualPath ( ) ; Map < String , Node > expectedFields = getFields ( expected ) ; Map < String , Node > actualFields = getFields ( actual ) ; Set < String > expectedKeys = expectedFields . keySet ( ) ; Set < String > actualKeys = actualFields . keySet ( ) ; if ( ! expectedKeys . equals ( actualKeys ) ) { Set < String > missingKeys = getMissingKeys ( expectedKeys , actualKeys ) ; Set < String > extraKeys = getExtraKeys ( expectedKeys , actualKeys ) ; if ( hasOption ( Option . TREATING_NULL_AS_ABSENT ) ) { extraKeys = getNotNullExtraKeys ( actual , extraKeys ) ; } removePathsToBeIgnored ( path , extraKeys ) ; removeMissingIgnoredElements ( expected , missingKeys ) ; if ( ! missingKeys . isEmpty ( ) || ! extraKeys . isEmpty ( ) ) { for ( String key : missingKeys ) { reportDifference ( DifferenceImpl . missing ( context . inField ( key ) ) ) ; } for ( String key : extraKeys ) { reportDifference ( DifferenceImpl . extra ( context . inField ( key ) ) ) ; } String missingKeysMessage = getMissingKeysMessage ( missingKeys , path ) ; String extraKeysMessage = getExtraKeysMessage ( extraKeys , path ) ; structureDifferenceFound ( context , "Different keys found in node \"%s\"%s%s, " + differenceString ( ) , path , missingKeysMessage , extraKeysMessage , normalize ( expected ) , normalize ( actual ) ) ; } } for ( String fieldName : commonFields ( expectedFields , actualFields ) ) { compareNodes ( context . inField ( fieldName ) ) ; } } | Compares object nodes . |
29,829 | private Set < String > getNotNullExtraKeys ( Node actual , Set < String > extraKeys ) { Set < String > notNullExtraKeys = new TreeSet < > ( ) ; for ( String extraKey : extraKeys ) { if ( ! actual . get ( extraKey ) . isNull ( ) ) { notNullExtraKeys . add ( extraKey ) ; } } return notNullExtraKeys ; } | Returns extra keys that are not null . |
29,830 | private void compareNodes ( Context context ) { if ( shouldIgnorePath ( context . getActualPath ( ) ) ) { return ; } Node expectedNode = context . getExpectedNode ( ) ; Node actualNode = context . getActualNode ( ) ; NodeType expectedNodeType = expectedNode . getNodeType ( ) ; NodeType actualNodeType = actualNode . getNodeType ( ) ; Path fieldPath = context . getActualPath ( ) ; if ( expectedNodeType == NodeType . STRING && configuration . shouldIgnore ( expectedNode . asText ( ) ) ) { return ; } if ( shouldIgnoreElement ( expectedNode ) ) { return ; } if ( checkAny ( NodeType . NUMBER , ANY_NUMBER_PLACEHOLDER , "a number" , context ) ) { return ; } if ( checkAny ( NodeType . BOOLEAN , ANY_BOOLEAN_PLACEHOLDER , "a boolean" , context ) ) { return ; } if ( checkAny ( NodeType . STRING , ANY_STRING_PLACEHOLDER , "a string" , context ) ) { return ; } if ( checkMatcher ( context ) ) { return ; } if ( ! expectedNodeType . equals ( actualNodeType ) ) { reportValueDifference ( context , "Different value found in node \"%s\", " + differenceString ( ) + "." , fieldPath , quoteTextValue ( expectedNode ) , quoteTextValue ( actualNode ) ) ; } else { switch ( expectedNodeType ) { case OBJECT : compareObjectNodes ( context ) ; break ; case ARRAY : compareArrayNodes ( context ) ; break ; case STRING : compareStringValues ( context ) ; break ; case NUMBER : BigDecimal actualValue = actualNode . decimalValue ( ) ; BigDecimal expectedValue = expectedNode . decimalValue ( ) ; if ( configuration . getTolerance ( ) != null && ! hasOption ( IGNORING_VALUES ) ) { BigDecimal diff = expectedValue . subtract ( actualValue ) . abs ( ) ; if ( diff . compareTo ( configuration . getTolerance ( ) ) > 0 ) { reportValueDifference ( context , "Different value found in node \"%s\", " + differenceString ( ) + ", difference is %s, tolerance is %s" , fieldPath , quoteTextValue ( expectedValue ) , quoteTextValue ( actualValue ) , diff . toString ( ) , configuration . getTolerance ( ) ) ; } } else { compareValues ( context , expectedValue , actualValue ) ; } break ; case BOOLEAN : compareValues ( context , expectedNode . asBoolean ( ) , actualNode . asBoolean ( ) ) ; break ; case NULL : break ; default : throw new IllegalStateException ( "Unexpected node type " + expectedNodeType ) ; } } } | Compares two nodes . |
29,831 | private static Map < String , Node > getFields ( Node node ) { Map < String , Node > result = new HashMap < > ( ) ; Iterator < KeyValue > fields = node . fields ( ) ; while ( fields . hasNext ( ) ) { KeyValue field = fields . next ( ) ; result . put ( field . getKey ( ) , field . getValue ( ) ) ; } return Collections . unmodifiableMap ( result ) ; } | Returns children of an ObjectNode . |
29,832 | static Converter createDefaultConverter ( ) { List < NodeFactory > factories ; String property = System . getProperty ( LIBRARIES_PROPERTY_NAME ) ; if ( property != null && property . trim ( ) . length ( ) > 0 ) { factories = createFactoriesSpecifiedInProperty ( property ) ; } else { factories = createDefaultFactories ( ) ; } if ( factories . isEmpty ( ) ) { throw new IllegalStateException ( "Please add either json.org, Jackson 1.x, Jackson 2.x or Gson to the classpath" ) ; } return new Converter ( factories ) ; } | Creates converter based on the libraries on the classpath . |
29,833 | public static void assertJsonNotEquals ( Object expected , Object fullJson , Configuration configuration ) { assertJsonPartNotEquals ( expected , fullJson , ROOT , configuration ) ; } | Compares JSONs and fails if they are equal . |
29,834 | public static void assertJsonNodeAbsent ( Object actual , String path ) { if ( ! nodeAbsent ( actual , path , configuration ) ) { doFail ( "Node \"" + path + "\" is present." ) ; } } | Fails if node in given path exists . |
29,835 | public static void assertJsonNodePresent ( Object actual , String path ) { if ( nodeAbsent ( actual , path , configuration ) ) { doFail ( "Node \"" + path + "\" is missing." ) ; } } | Fails if node in given does not exist . |
29,836 | public static Configuration when ( Option first , Option ... next ) { return Configuration . empty ( ) . withOptions ( first , next ) ; } | Creates empty configuration and sets options . |
29,837 | public JsonFluentAssert isEqualTo ( Object expected ) { Diff diff = createDiff ( expected , configuration ) ; diff . failIfDifferent ( description ) ; return this ; } | Compares JSON for equality . The expected object is converted to JSON before comparison . Ignores order of sibling nodes and whitespaces . |
29,838 | public JsonFluentAssert hasSameStructureAs ( Object expected ) { Diff diff = createDiff ( expected , configuration . withOptions ( COMPARING_ONLY_STRUCTURE ) ) ; diff . failIfDifferent ( ) ; return this ; } | Compares JSON structure . Ignores values only compares shape of the document and key names . Is too lenient ignores types prefer IGNORING_VALUES option instead . |
29,839 | public JsonFluentAssert node ( String newPath ) { return new JsonFluentAssert ( actual , path . copy ( newPath ) , description , configuration ) ; } | Creates an assert object that only compares given node . The path is denoted by JSON path for example . |
29,840 | boolean requestLandscapeLock ( ) { int requestedOrientation = activity . getRequestedOrientation ( ) ; if ( requestedOrientation == SCREEN_ORIENTATION_SENSOR_LANDSCAPE ) { return false ; } activity . setRequestedOrientation ( SCREEN_ORIENTATION_SENSOR_LANDSCAPE ) ; return isPortrait ( ) ; } | Returns true if we ve requested a lock and are expecting an orientation change as a result . |
29,841 | public void replaceHistory ( final Object key , final Direction direction ) { setHistory ( getHistory ( ) . buildUpon ( ) . clear ( ) . push ( key ) . build ( ) , direction ) ; } | Replaces the history with the given key and dispatches in the given direction . |
29,842 | public void replaceTop ( final Object key , final Direction direction ) { setHistory ( getHistory ( ) . buildUpon ( ) . pop ( 1 ) . push ( key ) . build ( ) , direction ) ; } | Replaces the top key of the history with the given key and dispatches in the given direction . |
29,843 | public < T > T peek ( int index ) { return ( T ) history . get ( history . size ( ) - index - 1 ) ; } | Returns the app state at the provided index in history . 0 is the newest entry . |
29,844 | protected void addListeners ( ) { Editable text = getText ( ) ; if ( text != null ) { text . setSpan ( spanWatcher , 0 , text . length ( ) , Spanned . SPAN_INCLUSIVE_INCLUSIVE ) ; addTextChangedListener ( textWatcher ) ; } } | Add the TextChangedListeners |
29,845 | protected void removeListeners ( ) { Editable text = getText ( ) ; if ( text != null ) { TokenSpanWatcher [ ] spanWatchers = text . getSpans ( 0 , text . length ( ) , TokenSpanWatcher . class ) ; for ( TokenSpanWatcher watcher : spanWatchers ) { text . removeSpan ( watcher ) ; } removeTextChangedListener ( textWatcher ) ; } } | Remove the TextChangedListeners |
29,846 | private void init ( ) { if ( initialized ) return ; setTokenizer ( new CharacterTokenizer ( Arrays . asList ( ',' , ';' ) , "," ) ) ; Editable text = getText ( ) ; assert null != text ; spanWatcher = new TokenSpanWatcher ( ) ; textWatcher = new TokenTextWatcher ( ) ; hiddenContent = null ; countSpan = new CountSpan ( ) ; addListeners ( ) ; setTextIsSelectable ( false ) ; setLongClickable ( false ) ; setInputType ( getInputType ( ) | InputType . TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType . TYPE_TEXT_FLAG_AUTO_COMPLETE ) ; setHorizontallyScrolling ( false ) ; setOnEditorActionListener ( this ) ; setFilters ( new InputFilter [ ] { new InputFilter ( ) { public CharSequence filter ( CharSequence source , int start , int end , Spanned dest , int destinationStart , int destinationEnd ) { if ( internalEditInProgress ) { return null ; } if ( tokenLimit != - 1 && getObjects ( ) . size ( ) == tokenLimit ) { return "" ; } if ( tokenizer . containsTokenTerminator ( source ) ) { if ( preventFreeFormText || currentCompletionText ( ) . length ( ) > 0 ) { performCompletion ( ) ; return "" ; } } if ( destinationStart < prefix . length ( ) ) { if ( destinationStart == 0 && destinationEnd == 0 ) { return null ; } else if ( destinationEnd <= prefix . length ( ) ) { return prefix . subSequence ( destinationStart , destinationEnd ) ; } else { return prefix . subSequence ( destinationStart , prefix . length ( ) ) ; } } return null ; } } } ) ; initialized = true ; } | Initialise the variables and various listeners |
29,847 | public List < T > getObjects ( ) { ArrayList < T > objects = new ArrayList < > ( ) ; Editable text = getText ( ) ; if ( hiddenContent != null ) { text = hiddenContent ; } for ( TokenImageSpan span : text . getSpans ( 0 , text . length ( ) , TokenImageSpan . class ) ) { objects . add ( span . getToken ( ) ) ; } return objects ; } | Get the list of Tokens |
29,848 | @ SuppressWarnings ( "unused" ) public CharSequence getTextForAccessibility ( ) { if ( getObjects ( ) . size ( ) == 0 ) { return getText ( ) ; } SpannableStringBuilder description = new SpannableStringBuilder ( ) ; Editable text = getText ( ) ; int selectionStart = - 1 ; int selectionEnd = - 1 ; int i ; for ( i = 0 ; i < text . length ( ) ; ++ i ) { int origSelectionStart = Selection . getSelectionStart ( text ) ; if ( i == origSelectionStart ) { selectionStart = description . length ( ) ; } int origSelectionEnd = Selection . getSelectionEnd ( text ) ; if ( i == origSelectionEnd ) { selectionEnd = description . length ( ) ; } TokenImageSpan [ ] tokens = text . getSpans ( i , i , TokenImageSpan . class ) ; if ( tokens . length > 0 ) { TokenImageSpan token = tokens [ 0 ] ; description = description . append ( tokenizer . wrapTokenValue ( token . getToken ( ) . toString ( ) ) ) ; i = text . getSpanEnd ( token ) ; continue ; } description = description . append ( text . subSequence ( i , i + 1 ) ) ; } int origSelectionStart = Selection . getSelectionStart ( text ) ; if ( i == origSelectionStart ) { selectionStart = description . length ( ) ; } int origSelectionEnd = Selection . getSelectionEnd ( text ) ; if ( i == origSelectionEnd ) { selectionEnd = description . length ( ) ; } if ( selectionStart >= 0 && selectionEnd >= 0 ) { Selection . setSelection ( description , selectionStart , selectionEnd ) ; } return description ; } | Correctly build accessibility string for token contents |
29,849 | @ SuppressWarnings ( "unused" ) public void clearCompletionText ( ) { if ( currentCompletionText ( ) . length ( ) == 0 ) { return ; } Range currentRange = getCurrentCandidateTokenRange ( ) ; internalEditInProgress = true ; getText ( ) . delete ( currentRange . start , currentRange . end ) ; internalEditInProgress = false ; } | Clear the completion text only . |
29,850 | private void handleDone ( ) { performCompletion ( ) ; InputMethodManager imm = ( InputMethodManager ) getContext ( ) . getSystemService ( Context . INPUT_METHOD_SERVICE ) ; if ( imm != null ) { imm . hideSoftInputFromWindow ( getWindowToken ( ) , 0 ) ; } } | Create a token and hide the keyboard when the user sends the DONE IME action Use IME_NEXT if you want to create a token and go to the next field |
29,851 | public void performCollapse ( boolean hasFocus ) { internalEditInProgress = true ; if ( ! hasFocus ) { final Editable text = getText ( ) ; if ( text != null && hiddenContent == null && lastLayout != null ) { text . removeSpan ( spanWatcher ) ; CountSpan temp = preventFreeFormText ? countSpan : null ; Spanned ellipsized = SpanUtils . ellipsizeWithSpans ( prefix , temp , getObjects ( ) . size ( ) , lastLayout . getPaint ( ) , text , maxTextWidth ( ) ) ; if ( ellipsized != null ) { hiddenContent = new SpannableStringBuilder ( text ) ; setText ( ellipsized ) ; TextUtils . copySpansFrom ( ellipsized , 0 , ellipsized . length ( ) , TokenImageSpan . class , getText ( ) , 0 ) ; TextUtils . copySpansFrom ( text , 0 , hiddenContent . length ( ) , TokenImageSpan . class , hiddenContent , 0 ) ; hiddenContent . setSpan ( spanWatcher , 0 , hiddenContent . length ( ) , Spanned . SPAN_INCLUSIVE_INCLUSIVE ) ; } else { getText ( ) . setSpan ( spanWatcher , 0 , getText ( ) . length ( ) , Spanned . SPAN_INCLUSIVE_INCLUSIVE ) ; } } } else { if ( hiddenContent != null ) { setText ( hiddenContent ) ; TextUtils . copySpansFrom ( hiddenContent , 0 , hiddenContent . length ( ) , TokenImageSpan . class , getText ( ) , 0 ) ; hiddenContent = null ; if ( hintVisible ) { setSelection ( prefix . length ( ) ) ; } else { post ( new Runnable ( ) { public void run ( ) { setSelection ( getText ( ) . length ( ) ) ; } } ) ; } TokenSpanWatcher [ ] watchers = getText ( ) . getSpans ( 0 , getText ( ) . length ( ) , TokenSpanWatcher . class ) ; if ( watchers . length == 0 ) { getText ( ) . setSpan ( spanWatcher , 0 , getText ( ) . length ( ) , Spanned . SPAN_INCLUSIVE_INCLUSIVE ) ; } } } internalEditInProgress = false ; } | Collapse the view by removing all the tokens not on the first line . Displays a + x token . Restores the hidden tokens when the view gains focus . |
29,852 | public void addObjectSync ( T object ) { if ( object == null ) return ; if ( shouldIgnoreToken ( object ) ) { if ( listener != null ) { listener . onTokenIgnored ( object ) ; } return ; } if ( tokenLimit != - 1 && getObjects ( ) . size ( ) == tokenLimit ) return ; insertSpan ( buildSpanForObject ( object ) ) ; if ( getText ( ) != null && isFocused ( ) ) setSelection ( getText ( ) . length ( ) ) ; } | Append a token object to the object list . May only be called from the main thread . |
29,853 | public void clearAsync ( ) { post ( new Runnable ( ) { public void run ( ) { for ( T object : getObjects ( ) ) { removeObjectSync ( object ) ; } } } ) ; } | Remove all objects from the token list . Objects will be removed on the main thread . |
29,854 | private void updateCountSpan ( ) { if ( ! preventFreeFormText ) { return ; } Editable text = getText ( ) ; int visibleCount = getText ( ) . getSpans ( 0 , getText ( ) . length ( ) , TokenImageSpan . class ) . length ; countSpan . setCount ( getObjects ( ) . size ( ) - visibleCount ) ; SpannableStringBuilder spannedCountText = new SpannableStringBuilder ( countSpan . getCountText ( ) ) ; spannedCountText . setSpan ( countSpan , 0 , spannedCountText . length ( ) , Spanned . SPAN_EXCLUSIVE_EXCLUSIVE ) ; internalEditInProgress = true ; int countStart = text . getSpanStart ( countSpan ) ; if ( countStart != - 1 ) { text . replace ( countStart , text . getSpanEnd ( countSpan ) , spannedCountText ) ; } else { text . append ( spannedCountText ) ; } internalEditInProgress = false ; } | Set the count span the current number of hidden objects |
29,855 | private void removeSpan ( Editable text , TokenImageSpan span ) { int end = text . getSpanEnd ( span ) ; if ( end < text . length ( ) && text . charAt ( end ) == ' ' ) { end += 1 ; } internalEditInProgress = true ; text . delete ( text . getSpanStart ( span ) , end ) ; internalEditInProgress = false ; if ( allowCollapse && ! isFocused ( ) ) { updateCountSpan ( ) ; } } | Remove a span from the current EditText and fire the appropriate callback |
29,856 | private void insertSpan ( TokenImageSpan tokenSpan ) { CharSequence ssb = tokenizer . wrapTokenValue ( tokenToString ( tokenSpan . token ) ) ; Editable editable = getText ( ) ; if ( editable == null ) return ; if ( hiddenContent == null ) { internalEditInProgress = true ; int offset = editable . length ( ) ; if ( hintVisible ) { offset = prefix . length ( ) ; } else { Range currentRange = getCurrentCandidateTokenRange ( ) ; if ( currentRange . length ( ) > 0 ) { offset = currentRange . start ; } } editable . insert ( offset , ssb ) ; editable . insert ( offset + ssb . length ( ) , " " ) ; editable . setSpan ( tokenSpan , offset , offset + ssb . length ( ) , Spanned . SPAN_EXCLUSIVE_EXCLUSIVE ) ; internalEditInProgress = false ; } else { CharSequence tokenText = tokenizer . wrapTokenValue ( tokenToString ( tokenSpan . getToken ( ) ) ) ; int start = hiddenContent . length ( ) ; hiddenContent . append ( tokenText ) ; hiddenContent . append ( " " ) ; hiddenContent . setSpan ( tokenSpan , start , start + tokenText . length ( ) , Spanned . SPAN_EXCLUSIVE_EXCLUSIVE ) ; updateCountSpan ( ) ; } } | Insert a new span for an Object |
29,857 | private Class reifyParameterizedTypeClass ( ) { Class < ? > viewClass = getClass ( ) ; while ( ! viewClass . getSuperclass ( ) . equals ( TokenCompleteTextView . class ) ) { viewClass = viewClass . getSuperclass ( ) ; } ParameterizedType superclass = ( ParameterizedType ) viewClass . getGenericSuperclass ( ) ; Type type = superclass . getActualTypeArguments ( ) [ 0 ] ; return ( Class ) type ; } | Used to determine if we can use the Parcelable interface |
29,858 | @ SuppressWarnings ( "BooleanMethodIsAlwaysInverted" ) public boolean canDeleteSelection ( int beforeLength ) { if ( getObjects ( ) . size ( ) < 1 ) return true ; int endSelection = getSelectionEnd ( ) ; int startSelection = beforeLength == 1 ? getSelectionStart ( ) : endSelection - beforeLength ; Editable text = getText ( ) ; TokenImageSpan [ ] spans = text . getSpans ( 0 , text . length ( ) , TokenImageSpan . class ) ; for ( TokenImageSpan span : spans ) { int startTokenSelection = text . getSpanStart ( span ) ; int endTokenSelection = text . getSpanEnd ( span ) ; if ( isTokenRemovable ( span . token ) ) continue ; if ( startSelection == endSelection ) { if ( endTokenSelection + 1 == endSelection ) { return false ; } } else { if ( startSelection <= startTokenSelection && endTokenSelection + 1 <= endSelection ) { return false ; } } } return true ; } | Checks if selection can be deleted . This method is called from TokenInputConnection . |
29,859 | public Query toQuery ( ) throws UnsupportedEncodingException { return new Query ( ) . appendIf ( "email" , email ) . appendIf ( "password" , password ) . appendIf ( "reset_password" , resetPassword ) . appendIf ( "username" , username ) . appendIf ( "name" , name ) . appendIf ( "skype" , skype ) . appendIf ( "linkedin" , linkedin ) . appendIf ( "twitter" , twitter ) . appendIf ( "website_url" , websiteUrl ) . appendIf ( "organization" , organization ) . appendIf ( "projects_limit" , projectsLimit ) . appendIf ( "extern_uid" , externUid ) . appendIf ( "provider" , provider ) . appendIf ( "bio" , bio ) . appendIf ( "location" , location ) . appendIf ( "admin" , admin ) . appendIf ( "can_create_group" , canCreateGroup ) . appendIf ( "skip_confirmation" , skipConfirmation ) . appendIf ( "external" , external ) . appendIf ( "avatar" , avatar ) ; } | Generates a query based on this request s properties . |
29,860 | public GitlabHTTPRequestor authenticate ( String token , TokenType type , AuthMethod method ) { this . apiToken = token ; this . tokenType = type ; this . authMethod = method ; return this ; } | Sets authentication data for the request . Has a fluent api for method chaining . |
29,861 | public List < GitlabUser > findUsers ( String emailOrUsername ) throws IOException { List < GitlabUser > users = new ArrayList < > ( ) ; if ( emailOrUsername != null && ! emailOrUsername . equals ( "" ) ) { String tailUrl = GitlabUser . URL + "?search=" + emailOrUsername ; GitlabUser [ ] response = retrieve ( ) . to ( tailUrl , GitlabUser [ ] . class ) ; users = Arrays . asList ( response ) ; } return users ; } | Finds users by email address or username . |
29,862 | public GitlabUser getUser ( ) throws IOException { String tailUrl = GitlabUser . USER_URL ; return retrieve ( ) . to ( tailUrl , GitlabUser . class ) ; } | Return API User |
29,863 | public GitlabUser createUser ( String email , String password , String username , String fullName , String skypeId , String linkedIn , String twitter , String website_url , Integer projects_limit , String extern_uid , String extern_provider_name , String bio , Boolean isAdmin , Boolean can_create_group , Boolean skip_confirmation , Boolean external ) throws IOException { Query query = new Query ( ) . append ( "email" , email ) . appendIf ( "skip_confirmation" , skip_confirmation ) . appendIf ( "password" , password ) . appendIf ( "username" , username ) . appendIf ( "name" , fullName ) . appendIf ( "skype" , skypeId ) . appendIf ( "linkedin" , linkedIn ) . appendIf ( "twitter" , twitter ) . appendIf ( "website_url" , website_url ) . appendIf ( "projects_limit" , projects_limit ) . appendIf ( "extern_uid" , extern_uid ) . appendIf ( "provider" , extern_provider_name ) . appendIf ( "bio" , bio ) . appendIf ( "admin" , isAdmin ) . appendIf ( "can_create_group" , can_create_group ) . appendIf ( "external" , external ) ; String tailUrl = GitlabUser . USERS_URL + query . toString ( ) ; return dispatch ( ) . to ( tailUrl , GitlabUser . class ) ; } | Create a new User |
29,864 | public GitlabUser createUser ( CreateUserRequest request ) throws IOException { String tailUrl = GitlabUser . USERS_URL + request . toQuery ( ) . toString ( ) ; return dispatch ( ) . to ( tailUrl , GitlabUser . class ) ; } | Create a new user . This may succeed only if the requester is an administrator . |
29,865 | public GitlabUser updateUser ( Integer targetUserId , String email , String password , String username , String fullName , String skypeId , String linkedIn , String twitter , String website_url , Integer projects_limit , String extern_uid , String extern_provider_name , String bio , Boolean isAdmin , Boolean can_create_group , Boolean external ) throws IOException { Query query = new Query ( ) . append ( "email" , email ) . appendIf ( "password" , password ) . appendIf ( "username" , username ) . appendIf ( "name" , fullName ) . appendIf ( "skype" , skypeId ) . appendIf ( "linkedin" , linkedIn ) . appendIf ( "twitter" , twitter ) . appendIf ( "website_url" , website_url ) . appendIf ( "projects_limit" , projects_limit ) . appendIf ( "extern_uid" , extern_uid ) . appendIf ( "provider" , extern_provider_name ) . appendIf ( "bio" , bio ) . appendIf ( "admin" , isAdmin ) . appendIf ( "can_create_group" , can_create_group ) . appendIf ( "external" , external ) ; String tailUrl = GitlabUser . USERS_URL + "/" + targetUserId + query . toString ( ) ; return retrieve ( ) . method ( PUT ) . to ( tailUrl , GitlabUser . class ) ; } | Update a user |
29,866 | public void blockUser ( Integer targetUserId ) throws IOException { String tailUrl = GitlabUser . USERS_URL + "/" + targetUserId + GitlabUser . BLOCK_URL ; retrieve ( ) . method ( POST ) . to ( tailUrl , Void . class ) ; } | Block a user |
29,867 | public void unblockUser ( Integer targetUserId ) throws IOException { String tailUrl = GitlabUser . USERS_URL + "/" + targetUserId + GitlabUser . UNBLOCK_URL ; retrieve ( ) . method ( POST ) . to ( tailUrl , Void . class ) ; } | Unblock a user |
29,868 | public GitlabSSHKey createSSHKey ( Integer targetUserId , String title , String key ) throws IOException { Query query = new Query ( ) . append ( "title" , title ) . append ( "key" , key ) ; String tailUrl = GitlabUser . USERS_URL + "/" + targetUserId + GitlabSSHKey . KEYS_URL + query . toString ( ) ; return dispatch ( ) . to ( tailUrl , GitlabSSHKey . class ) ; } | Create a new ssh key for the user |
29,869 | public GitlabSSHKey createSSHKey ( String title , String key ) throws IOException { Query query = new Query ( ) . append ( "title" , title ) . append ( "key" , key ) ; String tailUrl = GitlabUser . USER_URL + GitlabSSHKey . KEYS_URL + query . toString ( ) ; return dispatch ( ) . to ( tailUrl , GitlabSSHKey . class ) ; } | Create a new ssh key for the authenticated user . |
29,870 | public void deleteSSHKey ( Integer targetUserId , Integer targetKeyId ) throws IOException { String tailUrl = GitlabUser . USERS_URL + "/" + targetUserId + GitlabSSHKey . KEYS_URL + "/" + targetKeyId ; retrieve ( ) . method ( DELETE ) . to ( tailUrl , Void . class ) ; } | Delete user s ssh key |
29,871 | public List < GitlabSSHKey > getSSHKeys ( Integer targetUserId ) throws IOException { String tailUrl = GitlabUser . USERS_URL + "/" + targetUserId + GitlabSSHKey . KEYS_URL ; return Arrays . asList ( retrieve ( ) . to ( tailUrl , GitlabSSHKey [ ] . class ) ) ; } | Gets all ssh keys for a user |
29,872 | public GitlabSSHKey getSSHKey ( Integer keyId ) throws IOException { String tailUrl = GitlabSSHKey . KEYS_URL + "/" + keyId ; return retrieve ( ) . to ( tailUrl , GitlabSSHKey . class ) ; } | Get key with user information by ID of an SSH key . |
29,873 | public void deleteUser ( Integer targetUserId ) throws IOException { String tailUrl = GitlabUser . USERS_URL + "/" + targetUserId ; retrieve ( ) . method ( DELETE ) . to ( tailUrl , Void . class ) ; } | Delete a user |
29,874 | public GitlabGroup getGroup ( String path ) throws IOException { String tailUrl = GitlabGroup . URL + "/" + URLEncoder . encode ( path , "UTF-8" ) ; return retrieve ( ) . to ( tailUrl , GitlabGroup . class ) ; } | Get a group by path |
29,875 | public List < GitlabProject > getGroupProjects ( Integer groupId ) { String tailUrl = GitlabGroup . URL + "/" + groupId + GitlabProject . URL + PARAM_MAX_ITEMS_PER_PAGE ; return retrieve ( ) . getAll ( tailUrl , GitlabProject [ ] . class ) ; } | Get all the projects for a group . |
29,876 | public List < GitlabGroupMember > getGroupMembers ( Integer groupId ) { String tailUrl = GitlabGroup . URL + "/" + groupId + GitlabGroupMember . URL + PARAM_MAX_ITEMS_PER_PAGE ; return retrieve ( ) . getAll ( tailUrl , GitlabGroupMember [ ] . class ) ; } | Gets all members of a Group |
29,877 | public GitlabGroup updateGroup ( GitlabGroup group , GitlabUser sudoUser ) throws IOException { Query query = new Query ( ) . appendIf ( "name" , group . getName ( ) ) . appendIf ( "path" , group . getPath ( ) ) . appendIf ( "description" , group . getDescription ( ) ) . appendIf ( "membership_lock" , group . getMembershipLock ( ) ) . appendIf ( "share_with_group_lock" , group . getShareWithGroupLock ( ) ) . appendIf ( "visibility" , group . getVisibility ( ) . toString ( ) ) . appendIf ( "lfs_enabled" , group . isLfsEnabled ( ) ) . appendIf ( "request_access_enabled" , group . isRequestAccessEnabled ( ) ) . appendIf ( "shared_runners_minutes_limit" , group . getSharedRunnersMinutesLimit ( ) ) . appendIf ( "ldap_cn" , group . getLdapCn ( ) ) . appendIf ( "ldap_access" , group . getLdapAccess ( ) ) . appendIf ( PARAM_SUDO , sudoUser != null ? sudoUser . getId ( ) : null ) ; String tailUrl = GitlabGroup . URL + "/" + group . getId ( ) + query . toString ( ) ; return retrieve ( ) . method ( PUT ) . to ( tailUrl , GitlabGroup . class ) ; } | Updates a Group |
29,878 | public void deleteGroup ( Integer groupId ) throws IOException { String tailUrl = GitlabGroup . URL + "/" + groupId ; retrieve ( ) . method ( DELETE ) . to ( tailUrl , Void . class ) ; } | Delete a group . |
29,879 | public List < GitlabProject > getAllProjects ( ) { String tailUrl = GitlabProject . URL ; return retrieve ( ) . getAll ( tailUrl , GitlabProject [ ] . class ) ; } | Get s all projects in Gitlab requires sudo user |
29,880 | public GitlabProject getProject ( Serializable projectId ) throws IOException { String tailUrl = GitlabProject . URL + "/" + sanitizeProjectId ( projectId ) ; return retrieve ( ) . to ( tailUrl , GitlabProject . class ) ; } | Get Project by project Id |
29,881 | public GitlabProject getProject ( String namespace , String projectName ) throws IOException { String tailUrl = GitlabProject . URL + "/" + sanitizeGroupId ( namespace ) + "%2F" + sanitizeProjectId ( projectName ) ; return retrieve ( ) . to ( tailUrl , GitlabProject . class ) ; } | use namespace & project name to get project |
29,882 | public List < GitlabProject > getProjectsWithPagination ( int page , int perPage ) throws IOException { Pagination pagination = new Pagination ( ) . withPage ( page ) . withPerPage ( perPage ) ; return getProjectsWithPagination ( pagination ) ; } | Get a list of projects of size perPage accessible by the authenticated user . |
29,883 | public List < GitlabProject > getProjectsWithPagination ( Pagination pagination ) throws IOException { StringBuilder tailUrl = new StringBuilder ( GitlabProject . URL ) ; if ( pagination != null ) { Query query = pagination . asQuery ( ) ; tailUrl . append ( query . toString ( ) ) ; } return Arrays . asList ( retrieve ( ) . method ( GET ) . to ( tailUrl . toString ( ) , GitlabProject [ ] . class ) ) ; } | Get a list of projects by pagination accessible by the authenticated user . |
29,884 | public List < GitlabProject > getOwnedProjects ( ) throws IOException { Query query = new Query ( ) . append ( "owned" , "true" ) ; query . mergeWith ( new Pagination ( ) . withPerPage ( Pagination . MAX_ITEMS_PER_PAGE ) . asQuery ( ) ) ; String tailUrl = GitlabProject . URL + query . toString ( ) ; return retrieve ( ) . getAll ( tailUrl , GitlabProject [ ] . class ) ; } | Get a list of projects owned by the authenticated user . |
29,885 | public List < GitlabProject > getProjectsViaSudoWithPagination ( GitlabUser user , int page , int perPage ) throws IOException { Pagination pagination = new Pagination ( ) . withPage ( page ) . withPerPage ( perPage ) ; return getProjectsViaSudoWithPagination ( user , pagination ) ; } | Get a list of projects of perPage elements accessible by the authenticated user given page offset |
29,886 | public List < GitlabProject > getProjectsViaSudoWithPagination ( GitlabUser user , Pagination pagination ) throws IOException { StringBuilder tailUrl = new StringBuilder ( GitlabProject . URL ) ; Query query = new Query ( ) . appendIf ( PARAM_SUDO , user . getId ( ) ) ; if ( pagination != null ) { query . mergeWith ( pagination . asQuery ( ) ) ; } tailUrl . append ( query . toString ( ) ) ; return Arrays . asList ( retrieve ( ) . method ( GET ) . to ( tailUrl . toString ( ) , GitlabProject [ ] . class ) ) ; } | Get a list of projects of with Pagination . |
29,887 | public List < GitlabNamespace > getNamespaces ( ) { String tailUrl = GitlabNamespace . URL + PARAM_MAX_ITEMS_PER_PAGE ; return retrieve ( ) . getAll ( tailUrl , GitlabNamespace [ ] . class ) ; } | Get a list of the namespaces of the authenticated user . If the user is an administrator a list of all namespaces in the GitLab instance is shown . |
29,888 | public GitlabUpload uploadFile ( GitlabProject project , File file ) throws IOException { String tailUrl = GitlabProject . URL + "/" + sanitizeProjectId ( project . getId ( ) ) + GitlabUpload . URL ; return dispatch ( ) . withAttachment ( "file" , file ) . to ( tailUrl , GitlabUpload . class ) ; } | Uploads a file to a project |
29,889 | public List < GitlabJob > getProjectJobs ( Integer projectId ) { String tailUrl = GitlabProject . URL + "/" + sanitizeProjectId ( projectId ) + GitlabJob . URL + PARAM_MAX_ITEMS_PER_PAGE ; return retrieve ( ) . getAll ( tailUrl , GitlabJob [ ] . class ) ; } | Gets a list of a project s jobs in Gitlab |
29,890 | public GitlabJob getProjectJob ( Integer projectId , Integer jobId ) throws IOException { String tailUrl = GitlabProject . URL + "/" + sanitizeProjectId ( projectId ) + GitlabJob . URL + "/" + jobId ; return retrieve ( ) . to ( tailUrl , GitlabJob . class ) ; } | Gets a build for a project |
29,891 | public byte [ ] getJobArtifact ( GitlabProject project , GitlabJob job ) throws IOException { return getJobArtifact ( project . getId ( ) , job . getId ( ) ) ; } | Get build artifacts of a project build |
29,892 | public GitlabProject createProject ( String name ) throws IOException { return createProject ( name , null , null , null , null , null , null , null , null , null , null ) ; } | Creates a private Project |
29,893 | public GitlabProject createUserProject ( Integer userId , String name ) throws IOException { return createUserProject ( userId , name , null , null , null , null , null , null , null , null , null ) ; } | Creates a Project for a specific User |
29,894 | public GitlabProject updateProject ( Integer projectId , String name , String description , String defaultBranch , Boolean issuesEnabled , Boolean wallEnabled , Boolean mergeRequestsEnabled , Boolean wikiEnabled , Boolean snippetsEnabled , String visibility ) throws IOException { Query query = new Query ( ) . appendIf ( "name" , name ) . appendIf ( "description" , description ) . appendIf ( "default_branch" , defaultBranch ) . appendIf ( "issues_enabled" , issuesEnabled ) . appendIf ( "wall_enabled" , wallEnabled ) . appendIf ( "merge_requests_enabled" , mergeRequestsEnabled ) . appendIf ( "wiki_enabled" , wikiEnabled ) . appendIf ( "snippets_enabled" , snippetsEnabled ) . appendIf ( "visibility" , visibility ) ; String tailUrl = GitlabProject . URL + "/" + projectId + query . toString ( ) ; return retrieve ( ) . method ( PUT ) . to ( tailUrl , GitlabProject . class ) ; } | Updates a Project |
29,895 | public void deleteProject ( Serializable projectId ) throws IOException { String tailUrl = GitlabProject . URL + "/" + sanitizeProjectId ( projectId ) ; retrieve ( ) . method ( DELETE ) . to ( tailUrl , null ) ; } | Delete a Project . |
29,896 | public GitlabMergeRequestApprovals getMergeRequestApprovals ( GitlabMergeRequest mr ) throws IOException { String tailUrl = GitlabProject . URL + "/" + sanitizeProjectId ( mr . getProjectId ( ) ) + GitlabMergeRequest . URL + "/" + mr . getIid ( ) + GitlabMergeRequestApprovals . URL ; return retrieve ( ) . to ( tailUrl , GitlabMergeRequestApprovals . class ) ; } | Get information about the approvals present and required for a merge request EE only . |
29,897 | public GitlabMergeRequestApprovals setMergeRequestApprovals ( GitlabMergeRequest mr , int count ) throws IOException { String tailUrl = GitlabProject . URL + "/" + sanitizeProjectId ( mr . getProjectId ( ) ) + GitlabMergeRequest . URL + "/" + mr . getIid ( ) + GitlabMergeRequestApprovals . URL ; return dispatch ( ) . with ( "approvals_required" , count ) . to ( tailUrl , GitlabMergeRequestApprovals . class ) ; } | Set the number of required approvers . |
29,898 | public GitlabCommit cherryPick ( Serializable projectId , String sha , String targetBranchName ) throws IOException { String tailUrl = GitlabProject . URL + "/" + sanitizeProjectId ( projectId ) + "/repository/commits/" + sha + "/cherry_pick" ; return retrieve ( ) . with ( "branch" , targetBranchName ) . to ( tailUrl , GitlabCommit . class ) ; } | Cherry picks a commit . |
29,899 | public GitlabMergeRequest getMergeRequestByIid ( Serializable projectId , Integer mergeRequestIid ) throws IOException { String tailUrl = GitlabProject . URL + "/" + sanitizeProjectId ( projectId ) + GitlabMergeRequest . URL + "/" + mergeRequestIid ; return retrieve ( ) . to ( tailUrl , GitlabMergeRequest . class ) ; } | Return Merge Request . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.