idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
7,500
public boolean remove ( String path , String httpMethod ) { if ( StringUtils . isEmpty ( path ) ) { throw new IllegalArgumentException ( "path cannot be null or blank" ) ; } if ( StringUtils . isEmpty ( httpMethod ) ) { throw new IllegalArgumentException ( "httpMethod cannot be null or blank" ) ; } HttpMethod method = HttpMethod . valueOf ( httpMethod ) ; return removeRoute ( method , path ) ; }
Removes a particular route from the collection of those that have been previously routed . Search for a previously established routes using the given path and HTTP method removing any matches that are found .
7,501
public boolean remove ( String path ) { if ( StringUtils . isEmpty ( path ) ) { throw new IllegalArgumentException ( "path cannot be null or blank" ) ; } return removeRoute ( ( HttpMethod ) null , path ) ; }
Removes a particular route from the collection of those that have been previously routed . Search for a previously established routes using the given path and removes any matches that are found .
7,502
private Map < String , RouteEntry > getAcceptedMimeTypes ( List < RouteEntry > routes ) { Map < String , RouteEntry > acceptedTypes = new HashMap < > ( ) ; for ( RouteEntry routeEntry : routes ) { if ( ! acceptedTypes . containsKey ( routeEntry . acceptedType ) ) { acceptedTypes . put ( routeEntry . acceptedType , routeEntry ) ; } } return acceptedTypes ; }
can be cached? I don t think so .
7,503
public void add ( String route , String acceptType , Object target ) { try { int singleQuoteIndex = route . indexOf ( SINGLE_QUOTE ) ; String httpMethod = route . substring ( 0 , singleQuoteIndex ) . trim ( ) . toLowerCase ( ) ; String url = route . substring ( singleQuoteIndex + 1 , route . length ( ) - 1 ) . trim ( ) ; HttpMethod method ; try { method = HttpMethod . valueOf ( httpMethod ) ; } catch ( IllegalArgumentException e ) { LOG . error ( "The @Route value: " + route + " has an invalid HTTP method part: " + httpMethod + "." ) ; return ; } add ( method , url , acceptType , target ) ; } catch ( Exception e ) { LOG . error ( "The @Route value: " + route + " is not in the correct format" , e ) ; } }
Parse and validates a route and adds it
7,504
public String queryParamOrDefault ( String queryParam , String defaultValue ) { String value = queryParams ( queryParam ) ; return value != null ? value : defaultValue ; }
Gets the query param or returns default value
7,505
@ SuppressWarnings ( "unchecked" ) public < T > T attribute ( String attribute ) { return ( T ) servletRequest . getAttribute ( attribute ) ; }
Gets the value of the provided attribute
7,506
public Session session ( ) { if ( session == null || ! validSession ) { validSession ( true ) ; session = new Session ( servletRequest . getSession ( ) , this ) ; } return session ; }
Returns the current session associated with this request or if the request does not have a session creates one .
7,507
public String cookie ( String name ) { Cookie [ ] cookies = servletRequest . getCookies ( ) ; if ( cookies != null ) { for ( Cookie cookie : cookies ) { if ( cookie . getName ( ) . equals ( name ) ) { return cookie . getValue ( ) ; } } } return null ; }
Gets cookie by name .
7,508
public static ServerConnector createSocketConnector ( Server server , String host , int port ) { Assert . notNull ( server , "'server' must not be null" ) ; Assert . notNull ( host , "'host' must not be null" ) ; HttpConnectionFactory httpConnectionFactory = createHttpConnectionFactory ( ) ; ServerConnector connector = new ServerConnector ( server , httpConnectionFactory ) ; initializeConnector ( connector , host , port ) ; return connector ; }
Creates an ordinary non - secured Jetty server jetty .
7,509
public static ServerConnector createSecureSocketConnector ( Server server , String host , int port , SslStores sslStores ) { Assert . notNull ( server , "'server' must not be null" ) ; Assert . notNull ( host , "'host' must not be null" ) ; Assert . notNull ( sslStores , "'sslStores' must not be null" ) ; SslContextFactory sslContextFactory = new SslContextFactory ( sslStores . keystoreFile ( ) ) ; if ( sslStores . keystorePassword ( ) != null ) { sslContextFactory . setKeyStorePassword ( sslStores . keystorePassword ( ) ) ; } if ( sslStores . certAlias ( ) != null ) { sslContextFactory . setCertAlias ( sslStores . certAlias ( ) ) ; } if ( sslStores . trustStoreFile ( ) != null ) { sslContextFactory . setTrustStorePath ( sslStores . trustStoreFile ( ) ) ; } if ( sslStores . trustStorePassword ( ) != null ) { sslContextFactory . setTrustStorePassword ( sslStores . trustStorePassword ( ) ) ; } if ( sslStores . needsClientCert ( ) ) { sslContextFactory . setNeedClientAuth ( true ) ; sslContextFactory . setWantClientAuth ( true ) ; } HttpConnectionFactory httpConnectionFactory = createHttpConnectionFactory ( ) ; ServerConnector connector = new ServerConnector ( server , sslContextFactory , httpConnectionFactory ) ; initializeConnector ( connector , host , port ) ; return connector ; }
Creates a ssl jetty socket jetty . Keystore required truststore optional . If truststore not specified keystore will be reused .
7,510
public String stem ( String s ) { if ( stem ( s . toCharArray ( ) , s . length ( ) ) ) return toString ( ) ; else return s ; }
Stem a word provided as a String . Returns the result as a String .
7,511
public < T > T set ( Object jsonObject , Object newVal , Configuration configuration ) { notNull ( jsonObject , "json can not be null" ) ; notNull ( configuration , "configuration can not be null" ) ; EvaluationContext evaluationContext = path . evaluate ( jsonObject , jsonObject , configuration , true ) ; for ( PathRef updateOperation : evaluationContext . updateOperations ( ) ) { updateOperation . set ( newVal , configuration ) ; } return resultByConfiguration ( jsonObject , configuration , evaluationContext ) ; }
Set the value this path points to in the provided jsonObject
7,512
public < T > T put ( Object jsonObject , String key , Object value , Configuration configuration ) { notNull ( jsonObject , "json can not be null" ) ; notEmpty ( key , "key can not be null or empty" ) ; notNull ( configuration , "configuration can not be null" ) ; EvaluationContext evaluationContext = path . evaluate ( jsonObject , jsonObject , configuration , true ) ; for ( PathRef updateOperation : evaluationContext . updateOperations ( ) ) { updateOperation . put ( key , value , configuration ) ; } return resultByConfiguration ( jsonObject , configuration , evaluationContext ) ; }
Adds or updates the Object this path points to in the provided jsonObject with a key with a value
7,513
@ SuppressWarnings ( { "unchecked" } ) public < T > T read ( URL jsonURL ) throws IOException { return read ( jsonURL , Configuration . defaultConfiguration ( ) ) ; }
Applies this JsonPath to the provided json URL
7,514
public static JsonPath compile ( String jsonPath , Predicate ... filters ) { notEmpty ( jsonPath , "json can not be null or empty" ) ; return new JsonPath ( jsonPath , filters ) ; }
Compiles a JsonPath
7,515
@ SuppressWarnings ( { "unchecked" } ) public static < T > T read ( String json , String jsonPath , Predicate ... filters ) { return new ParseContextImpl ( ) . parse ( json ) . read ( jsonPath , filters ) ; }
Creates a new JsonPath and applies it to the provided Json string
7,516
private RootPathToken invertScannerFunctionRelationship ( final RootPathToken path ) { if ( path . isFunctionPath ( ) && path . next ( ) instanceof ScanPathToken ) { PathToken token = path ; PathToken prior = null ; while ( null != ( token = token . next ( ) ) && ! ( token instanceof FunctionPathToken ) ) { prior = token ; } if ( token instanceof FunctionPathToken ) { prior . setNext ( null ) ; path . setTail ( prior ) ; Parameter parameter = new Parameter ( ) ; parameter . setPath ( new CompiledPath ( path , true ) ) ; parameter . setType ( ParamType . PATH ) ; ( ( FunctionPathToken ) token ) . setParameters ( Arrays . asList ( parameter ) ) ; RootPathToken functionRoot = new RootPathToken ( '$' ) ; functionRoot . setTail ( token ) ; functionRoot . setNext ( token ) ; return functionRoot ; } } return path ; }
In the event the writer of the path referenced a function at the tail end of a scanner augment the query such that the root node is the function and the parameter to the function is the scanner . This way we maintain relative sanity in the path expression functions either evaluate scalar values or arrays they re not re - entrant nor should they maintain state they do however take parameters .
7,517
protected boolean checkArrayModel ( String currentPath , Object model , EvaluationContextImpl ctx ) { if ( model == null ) { if ( ! isUpstreamDefinite ( ) ) { return false ; } else { throw new PathNotFoundException ( "The path " + currentPath + " is null" ) ; } } if ( ! ctx . jsonProvider ( ) . isArray ( model ) ) { if ( ! isUpstreamDefinite ( ) ) { return false ; } else { throw new PathNotFoundException ( format ( "Filter: %s can only be applied to arrays. Current context is: %s" , toString ( ) , model ) ) ; } } return true ; }
Check if model is non - null and array .
7,518
public static PathFunction newFunction ( String name ) throws InvalidPathException { Class functionClazz = FUNCTIONS . get ( name ) ; if ( functionClazz == null ) { throw new InvalidPathException ( "Function with name: " + name + " does not exist." ) ; } else { try { return ( PathFunction ) functionClazz . newInstance ( ) ; } catch ( Exception e ) { throw new InvalidPathException ( "Function of name: " + name + " cannot be created" , e ) ; } } }
Returns the function by name or throws InvalidPathException if function not found .
7,519
public Criteria and ( String key ) { checkComplete ( ) ; return new Criteria ( this . criteriaChain , ValueNode . toValueNode ( prefixPath ( key ) ) ) ; }
Static factory method to create a Criteria using the provided key
7,520
public Criteria is ( Object o ) { this . criteriaType = RelationalOperator . EQ ; this . right = ValueNode . toValueNode ( o ) ; return this ; }
Creates a criterion using equality
7,521
public Criteria regex ( Pattern pattern ) { notNull ( pattern , "pattern can not be null" ) ; this . criteriaType = RelationalOperator . REGEX ; this . right = ValueNode . toValueNode ( pattern ) ; return this ; }
Creates a criterion using a Regex
7,522
public static Criteria parse ( String criteria ) { if ( criteria == null ) { throw new InvalidPathException ( "Criteria can not be null" ) ; } String [ ] split = criteria . trim ( ) . split ( " " ) ; if ( split . length == 3 ) { return create ( split [ 0 ] , split [ 1 ] , split [ 2 ] ) ; } else if ( split . length == 1 ) { return create ( split [ 0 ] , "EXISTS" , "true" ) ; } else { throw new InvalidPathException ( "Could not parse criteria" ) ; } }
Parse the provided criteria
7,523
public static Criteria create ( String left , String operator , String right ) { Criteria criteria = new Criteria ( ValueNode . toValueNode ( left ) ) ; criteria . criteriaType = RelationalOperator . fromString ( operator ) ; criteria . right = ValueNode . toValueNode ( right ) ; return criteria ; }
Creates a new criteria
7,524
public Configuration addEvaluationListeners ( EvaluationListener ... evaluationListener ) { return Configuration . builder ( ) . jsonProvider ( jsonProvider ) . mappingProvider ( mappingProvider ) . options ( options ) . evaluationListener ( evaluationListener ) . build ( ) ; }
Creates a new Configuration by the provided evaluation listeners to the current listeners
7,525
public Configuration addOptions ( Option ... options ) { EnumSet < Option > opts = EnumSet . noneOf ( Option . class ) ; opts . addAll ( this . options ) ; opts . addAll ( asList ( options ) ) ; return Configuration . builder ( ) . jsonProvider ( jsonProvider ) . mappingProvider ( mappingProvider ) . options ( opts ) . evaluationListener ( evaluationListeners ) . build ( ) ; }
Creates a new configuration by adding the new options to the options used in this configuration .
7,526
public Configuration setOptions ( Option ... options ) { return Configuration . builder ( ) . jsonProvider ( jsonProvider ) . mappingProvider ( mappingProvider ) . options ( options ) . evaluationListener ( evaluationListeners ) . build ( ) ; }
Creates a new configuration with the provided options . Options in this configuration are discarded .
7,527
public static Configuration defaultConfiguration ( ) { Defaults defaults = getEffectiveDefaults ( ) ; return Configuration . builder ( ) . jsonProvider ( defaults . jsonProvider ( ) ) . options ( defaults . options ( ) ) . build ( ) ; }
Creates a new configuration based on default values
7,528
public Object getMapValue ( Object obj , String key ) { Map m = ( Map ) obj ; if ( ! m . containsKey ( key ) ) { return JsonProvider . UNDEFINED ; } else { return m . get ( key ) ; } }
Extracts a value from an map
7,529
@ SuppressWarnings ( "unchecked" ) public void setProperty ( Object obj , Object key , Object value ) { if ( isMap ( obj ) ) ( ( Map ) obj ) . put ( key . toString ( ) , value ) ; else { throw new JsonPathException ( "setProperty operation cannot be used with " + obj != null ? obj . getClass ( ) . getName ( ) : "null" ) ; } }
Sets a value in an object
7,530
@ SuppressWarnings ( "unchecked" ) public void removeProperty ( Object obj , Object key ) { if ( isMap ( obj ) ) ( ( Map ) obj ) . remove ( key . toString ( ) ) ; else { List list = ( List ) obj ; int index = key instanceof Integer ? ( Integer ) key : Integer . parseInt ( key . toString ( ) ) ; list . remove ( index ) ; } }
Removes a value in an object or array
7,531
@ SuppressWarnings ( "unchecked" ) public Collection < String > getPropertyKeys ( Object obj ) { if ( isArray ( obj ) ) { throw new UnsupportedOperationException ( ) ; } else { return ( ( Map ) obj ) . keySet ( ) ; } }
Returns the keys from the given object
7,532
public int length ( Object obj ) { if ( isArray ( obj ) ) { return ( ( List ) obj ) . size ( ) ; } else if ( isMap ( obj ) ) { return getPropertyKeys ( obj ) . size ( ) ; } else if ( obj instanceof String ) { return ( ( String ) obj ) . length ( ) ; } throw new JsonPathException ( "length operation cannot be applied to " + obj != null ? obj . getClass ( ) . getName ( ) : "null" ) ; }
Get the length of an array or object
7,533
public static < T > List < T > toList ( final Class < T > type , final EvaluationContext ctx , final List < Parameter > parameters ) { List < T > values = new ArrayList ( ) ; if ( null != parameters ) { for ( Parameter param : parameters ) { consume ( type , ctx , values , param . getValue ( ) ) ; } } return values ; }
Translate the collection of parameters into a collection of values of type T .
7,534
public static void consume ( Class expectedType , EvaluationContext ctx , Collection collection , Object value ) { if ( ctx . configuration ( ) . jsonProvider ( ) . isArray ( value ) ) { for ( Object o : ctx . configuration ( ) . jsonProvider ( ) . toIterable ( value ) ) { if ( o != null && expectedType . isAssignableFrom ( o . getClass ( ) ) ) { collection . add ( o ) ; } else if ( o != null && expectedType == String . class ) { collection . add ( o . toString ( ) ) ; } } } else { if ( value != null && expectedType . isAssignableFrom ( value . getClass ( ) ) ) { collection . add ( value ) ; } } }
Either consume the object as an array and add each element to the collection or alternatively add each element
7,535
public static < E > Matcher < ? super Collection < ? extends E > > hasSize ( Matcher < ? super Integer > size ) { return new IsCollectionWithSize < E > ( size ) ; }
Does collection size satisfy a given matcher?
7,536
private void updateParams ( ) { for ( int m = 0 ; m < documents . length ; m ++ ) { for ( int k = 0 ; k < K ; k ++ ) { thetasum [ m ] [ k ] += ( nd [ m ] [ k ] + alpha ) / ( ndsum [ m ] + K * alpha ) ; } } for ( int k = 0 ; k < K ; k ++ ) { for ( int w = 0 ; w < V ; w ++ ) { phisum [ k ] [ w ] += ( word_topic_matrix [ w ] [ k ] + beta ) / ( nwsum [ k ] + V * beta ) ; } } numstats ++ ; }
Add to the statistics the values of theta and phi for the current state .
7,537
public static void hist ( float [ ] data , int fmax ) { float [ ] hist = new float [ data . length ] ; float hmax = 0 ; for ( int i = 0 ; i < data . length ; i ++ ) { hmax = Math . max ( data [ i ] , hmax ) ; } float shrink = fmax / hmax ; for ( int i = 0 ; i < data . length ; i ++ ) { hist [ i ] = shrink * data [ i ] ; } NumberFormat nf = new DecimalFormat ( "00" ) ; String scale = "" ; for ( int i = 1 ; i < fmax / 10 + 1 ; i ++ ) { scale += " . " + i % 10 ; } System . out . println ( "x" + nf . format ( hmax / fmax ) + "\t0" + scale ) ; for ( int i = 0 ; i < hist . length ; i ++ ) { System . out . print ( i + "\t|" ) ; for ( int j = 0 ; j < Math . round ( hist [ i ] ) ; j ++ ) { if ( ( j + 1 ) % 10 == 0 ) System . out . print ( "]" ) ; else System . out . print ( "|" ) ; } System . out . println ( ) ; } }
Print table of multinomial data
7,538
public void configure ( int iterations , int burnIn , int thinInterval , int sampleLag ) { ITERATIONS = iterations ; BURN_IN = burnIn ; THIN_INTERVAL = thinInterval ; SAMPLE_LAG = sampleLag ; }
Configure the gibbs sampler
7,539
public static String shadefloat ( float d , float max ) { int a = ( int ) Math . floor ( d * 10 / max + 0.5 ) ; if ( a > 10 || a < 0 ) { String x = lnf . format ( d ) ; a = 5 - x . length ( ) ; for ( int i = 0 ; i < a ; i ++ ) { x += " " ; } return "<" + x + ">" ; } return "[" + shades [ a ] + "]" ; }
create a string representation whose gray value appears as an indicator of magnitude cf . Hinton diagrams in statistics .
7,540
public long hash64 ( final byte [ ] data , int length , int seed ) { final long m = 0xc6a4a7935bd1e995L ; final int r = 47 ; long h = ( seed & 0xffffffffl ) ^ ( length * m ) ; int length8 = length / 8 ; for ( int i = 0 ; i < length8 ; i ++ ) { final int i8 = i * 8 ; long k = ( ( long ) data [ i8 + 0 ] & 0xff ) + ( ( ( long ) data [ i8 + 1 ] & 0xff ) << 8 ) + ( ( ( long ) data [ i8 + 2 ] & 0xff ) << 16 ) + ( ( ( long ) data [ i8 + 3 ] & 0xff ) << 24 ) + ( ( ( long ) data [ i8 + 4 ] & 0xff ) << 32 ) + ( ( ( long ) data [ i8 + 5 ] & 0xff ) << 40 ) + ( ( ( long ) data [ i8 + 6 ] & 0xff ) << 48 ) + ( ( ( long ) data [ i8 + 7 ] & 0xff ) << 56 ) ; k *= m ; k ^= k >>> r ; k *= m ; h ^= k ; h *= m ; } switch ( length % 8 ) { case 7 : h ^= ( long ) ( data [ ( length & ~ 7 ) + 6 ] & 0xff ) << 48 ; case 6 : h ^= ( long ) ( data [ ( length & ~ 7 ) + 5 ] & 0xff ) << 40 ; case 5 : h ^= ( long ) ( data [ ( length & ~ 7 ) + 4 ] & 0xff ) << 32 ; case 4 : h ^= ( long ) ( data [ ( length & ~ 7 ) + 3 ] & 0xff ) << 24 ; case 3 : h ^= ( long ) ( data [ ( length & ~ 7 ) + 2 ] & 0xff ) << 16 ; case 2 : h ^= ( long ) ( data [ ( length & ~ 7 ) + 1 ] & 0xff ) << 8 ; case 1 : h ^= ( long ) ( data [ length & ~ 7 ] & 0xff ) ; h *= m ; } ; h ^= h >>> r ; h *= m ; h ^= h >>> r ; return h ; }
Generates 64 bit hash from byte array of the given length and seed .
7,541
private float weight ( int c1 , int c2 ) { float w ; float pc1 = wordProb . get ( c1 ) ; float pc2 = wordProb . get ( c2 ) ; if ( c1 == c2 ) { float pcc = getProb ( c1 , c1 ) ; w = clacW ( pcc , pc1 , pc2 ) ; } else { float pcc1 = getProb ( c1 , c2 ) ; float p1 = clacW ( pcc1 , pc1 , pc2 ) ; float pcc2 = getProb ( c2 , c1 ) ; float p2 = clacW ( pcc2 , pc2 , pc1 ) ; w = p1 + p2 ; } setweight ( c1 , c2 , w ) ; return w ; }
total graph weight
7,542
public float calcL ( int c1 , int c2 ) { float L = 0 ; TIntIterator it = slots . iterator ( ) ; while ( it . hasNext ( ) ) { int k = it . next ( ) ; if ( k == c2 ) continue ; L += weight ( c1 , c2 , k ) ; } it = slots . iterator ( ) ; while ( it . hasNext ( ) ) { int k = it . next ( ) ; L -= getweight ( c1 , k ) ; L -= getweight ( c2 , k ) ; } return L ; }
calculate the value L
7,543
private void addEdge ( int i , int j ) { if ( ! nodes . contains ( i ) ) { nodes . add ( i ) ; edges . put ( i , new HashSet < Integer > ( ) ) ; size ++ ; } else if ( ! edges . containsKey ( i ) ) { edges . put ( i , new HashSet < Integer > ( ) ) ; } if ( ! nodes . contains ( j ) ) { nodes . add ( j ) ; size ++ ; } edgesInv . put ( j , i ) ; if ( ! edges . get ( i ) . contains ( j ) ) { edges . get ( i ) . add ( j ) ; } }
i - > j
7,544
public void plus ( ISparseVector sv ) { if ( sv instanceof HashSparseVector ) { TIntFloatIterator it = ( ( HashSparseVector ) sv ) . data . iterator ( ) ; while ( it . hasNext ( ) ) { it . advance ( ) ; data . adjustOrPutValue ( it . key ( ) , it . value ( ) , it . value ( ) ) ; } } else if ( sv instanceof BinarySparseVector ) { TIntIterator it = ( ( BinarySparseVector ) sv ) . data . iterator ( ) ; while ( it . hasNext ( ) ) { int i = it . next ( ) ; data . adjustOrPutValue ( i , DefaultValue , DefaultValue ) ; } } }
v + sv
7,545
public void SFFS ( ) throws Exception { int NumTemplate = Templates . length ; CurSet = new boolean [ NumTemplate ] ; LeftSet = new boolean [ NumTemplate ] ; for ( int i = 0 ; i < NumTemplate ; i ++ ) { CurSet [ i ] = false ; LeftSet [ i ] = true ; } Evaluate ( Templates , CurSet ) ; boolean continueDelete = false ; while ( SetSize ( CurSet ) <= NumTemplate ) { if ( ! continueDelete ) { Integer theInt = BooleanSet2Integer ( CurSet ) ; int best = BestFeatureByAdding ( CurSet , LeftSet ) ; if ( best != - 1 ) { System . out . println ( "Add Best " + best ) ; AlreadyAdded . add ( theInt ) ; CurSet [ best ] = true ; LeftSet [ best ] = false ; printAccuracy ( CurSet ) ; } } Integer theInt = BooleanSet2Integer ( CurSet ) ; if ( AlreadyRemoved . contains ( theInt ) ) { continueDelete = false ; continue ; } else { int worst = WorstFeatureByRemoving ( CurSet ) ; boolean [ ] TestSet = CurSet . clone ( ) ; TestSet [ worst ] = false ; double accuracy = Evaluate ( Templates , TestSet ) ; if ( accuracy >= AccuracyRecords . get ( theInt ) ) { System . out . println ( "Remove Worst " + worst ) ; AlreadyRemoved . add ( theInt ) ; CurSet [ worst ] = false ; LeftSet [ worst ] = true ; printAccuracy ( CurSet ) ; if ( SetSize ( CurSet ) == 0 ) { continueDelete = false ; } else continueDelete = true ; } else { continueDelete = false ; continue ; } } } printAccuracyRecords ( AccuracyRecords ) ; ObjectOutputStream oos = new ObjectOutputStream ( new FileOutputStream ( "/home/zliu/corpus/testTemplate/SFFS.ser" ) ) ; oos . writeObject ( AccuracyRecords ) ; oos . close ( ) ; }
SFFS alg .
7,546
public GraphQLInterfaceType transform ( Consumer < Builder > builderConsumer ) { Builder builder = newInterface ( this ) ; builderConsumer . accept ( builder ) ; return builder . build ( ) ; }
This helps you transform the current GraphQLInterfaceType into another one by starting a builder with all the current values and allows you to transform it how you want .
7,547
@ SuppressWarnings ( "TypeParameterUnusedInFormals" ) public < T extends GraphQLType > T decorate ( GraphQLType objectType ) { GraphQLType out = objectType ; Stack < Class < ? > > wrappingStack = new Stack < > ( ) ; wrappingStack . addAll ( this . decoration ) ; while ( ! wrappingStack . isEmpty ( ) ) { Class < ? > clazz = wrappingStack . pop ( ) ; if ( clazz . equals ( NonNullType . class ) ) { out = nonNull ( out ) ; } if ( clazz . equals ( ListType . class ) ) { out = list ( out ) ; } } return ( T ) out ; }
This will decorate a graphql type with the original hierarchy of non null and list ness it originally contained in its definition type
7,548
public DataFetcher getDataFetcher ( GraphQLFieldsContainer parentType , GraphQLFieldDefinition fieldDefinition ) { return getDataFetcherImpl ( parentType , fieldDefinition , dataFetcherMap , systemDataFetcherMap ) ; }
Returns a data fetcher associated with a field within a container type
7,549
private CompletableFuture < NodeMultiZipper < ExecutionResultNode > > resolveNodes ( ExecutionContext executionContext , List < NodeMultiZipper < ExecutionResultNode > > unresolvedNodes ) { assertNotEmpty ( unresolvedNodes , "unresolvedNodes can't be empty" ) ; ExecutionResultNode commonRoot = unresolvedNodes . get ( 0 ) . getCommonRoot ( ) ; CompletableFuture < List < List < NodeZipper < ExecutionResultNode > > > > listListCF = Async . flatMap ( unresolvedNodes , executionResultMultiZipper -> fetchAndAnalyze ( executionContext , executionResultMultiZipper . getZippers ( ) ) ) ; return flatList ( listListCF ) . thenApply ( zippers -> new NodeMultiZipper < ExecutionResultNode > ( commonRoot , zippers , RESULT_NODE_ADAPTER ) ) ; }
all multizipper have the same root
7,550
public GraphQLFieldDefinition transform ( Consumer < Builder > builderConsumer ) { Builder builder = newFieldDefinition ( this ) ; builderConsumer . accept ( builder ) ; return builder . build ( ) ; }
This helps you transform the current GraphQLFieldDefinition into another one by starting a builder with all the current values and allows you to transform it how you want .
7,551
public static < U > SimpleInstrumentationContext < U > whenDispatched ( Consumer < CompletableFuture < U > > codeToRun ) { return new SimpleInstrumentationContext < > ( codeToRun , null ) ; }
Allows for the more fluent away to return an instrumentation context that runs the specified code on instrumentation step dispatch .
7,552
public static < U > SimpleInstrumentationContext < U > whenCompleted ( BiConsumer < U , Throwable > codeToRun ) { return new SimpleInstrumentationContext < > ( null , codeToRun ) ; }
Allows for the more fluent away to return an instrumentation context that runs the specified code on instrumentation step completion .
7,553
private void run ( final RunNode current ) { try { current . runnable . run ( ) ; } catch ( final Throwable thrown ) { reportFailure ( Thread . currentThread ( ) , thrown ) ; } }
Runs a single RunNode and deals with any thing it throws
7,554
private void runAll ( RunNode next ) { for ( ; ; ) { final RunNode current = next ; run ( current ) ; if ( ( next = current . get ( ) ) == null ) { if ( last . compareAndSet ( current , null ) ) { return ; } else { while ( ( next = current . get ( ) ) == null ) { } } } } }
Runs all the RunNodes starting with next
7,555
public List < GraphQLObjectType > findImplementations ( GraphQLSchema schema , GraphQLInterfaceType interfaceType ) { List < GraphQLObjectType > result = new ArrayList < > ( ) ; for ( GraphQLType type : schema . getAllTypesAsList ( ) ) { if ( ! ( type instanceof GraphQLObjectType ) ) { continue ; } GraphQLObjectType objectType = ( GraphQLObjectType ) type ; if ( ( objectType ) . getInterfaces ( ) . contains ( interfaceType ) ) { result . add ( objectType ) ; } } return result ; }
This method is deprecated due to a performance concern .
7,556
public static < T > CompletableFuture < T > toCompletableFuture ( T t ) { if ( t instanceof CompletionStage ) { return ( ( CompletionStage < T > ) t ) . toCompletableFuture ( ) ; } else { return CompletableFuture . completedFuture ( t ) ; } }
Turns an object T into a CompletableFuture if its not already
7,557
public Optional < GraphQLError > addAll ( Collection < SDLDefinition > definitions ) { for ( SDLDefinition definition : definitions ) { Optional < GraphQLError > error = add ( definition ) ; if ( error . isPresent ( ) ) { return error ; } } return Optional . empty ( ) ; }
Adds a a collections of definitions to the registry
7,558
public Optional < GraphQLError > add ( SDLDefinition definition ) { if ( definition instanceof ObjectTypeExtensionDefinition ) { ObjectTypeExtensionDefinition newEntry = ( ObjectTypeExtensionDefinition ) definition ; return defineExt ( objectTypeExtensions , newEntry , ObjectTypeExtensionDefinition :: getName ) ; } else if ( definition instanceof InterfaceTypeExtensionDefinition ) { InterfaceTypeExtensionDefinition newEntry = ( InterfaceTypeExtensionDefinition ) definition ; return defineExt ( interfaceTypeExtensions , newEntry , InterfaceTypeExtensionDefinition :: getName ) ; } else if ( definition instanceof UnionTypeExtensionDefinition ) { UnionTypeExtensionDefinition newEntry = ( UnionTypeExtensionDefinition ) definition ; return defineExt ( unionTypeExtensions , newEntry , UnionTypeExtensionDefinition :: getName ) ; } else if ( definition instanceof EnumTypeExtensionDefinition ) { EnumTypeExtensionDefinition newEntry = ( EnumTypeExtensionDefinition ) definition ; return defineExt ( enumTypeExtensions , newEntry , EnumTypeExtensionDefinition :: getName ) ; } else if ( definition instanceof ScalarTypeExtensionDefinition ) { ScalarTypeExtensionDefinition newEntry = ( ScalarTypeExtensionDefinition ) definition ; return defineExt ( scalarTypeExtensions , newEntry , ScalarTypeExtensionDefinition :: getName ) ; } else if ( definition instanceof InputObjectTypeExtensionDefinition ) { InputObjectTypeExtensionDefinition newEntry = ( InputObjectTypeExtensionDefinition ) definition ; return defineExt ( inputObjectTypeExtensions , newEntry , InputObjectTypeExtensionDefinition :: getName ) ; } else if ( definition instanceof ScalarTypeDefinition ) { ScalarTypeDefinition newEntry = ( ScalarTypeDefinition ) definition ; return define ( scalarTypes , scalarTypes , newEntry ) ; } else if ( definition instanceof TypeDefinition ) { TypeDefinition newEntry = ( TypeDefinition ) definition ; return define ( types , types , newEntry ) ; } else if ( definition instanceof DirectiveDefinition ) { DirectiveDefinition newEntry = ( DirectiveDefinition ) definition ; return define ( directiveDefinitions , directiveDefinitions , newEntry ) ; } else if ( definition instanceof SchemaDefinition ) { SchemaDefinition newSchema = ( SchemaDefinition ) definition ; if ( schema != null ) { return Optional . of ( new SchemaRedefinitionError ( this . schema , newSchema ) ) ; } else { schema = newSchema ; } } else { return Assert . assertShouldNeverHappen ( ) ; } return Optional . empty ( ) ; }
Adds a definition to the registry
7,559
public < T extends TypeDefinition > List < T > getTypes ( Class < T > targetClass ) { return types . values ( ) . stream ( ) . filter ( targetClass :: isInstance ) . map ( targetClass :: cast ) . collect ( Collectors . toList ( ) ) ; }
Returns a list of types in the registry of that specified class
7,560
public < T extends TypeDefinition > Map < String , T > getTypesMap ( Class < T > targetClass ) { List < T > list = getTypes ( targetClass ) ; return FpKit . getByName ( list , TypeDefinition :: getName , FpKit . mergeFirst ( ) ) ; }
Returns a map of types in the registry of that specified class keyed by name
7,561
public List < ObjectTypeDefinition > getImplementationsOf ( InterfaceTypeDefinition targetInterface ) { List < ObjectTypeDefinition > objectTypeDefinitions = getTypes ( ObjectTypeDefinition . class ) ; return objectTypeDefinitions . stream ( ) . filter ( objectTypeDefinition -> { List < Type > implementsList = objectTypeDefinition . getImplements ( ) ; for ( Type iFace : implementsList ) { Optional < InterfaceTypeDefinition > interfaceTypeDef = getType ( iFace , InterfaceTypeDefinition . class ) ; if ( interfaceTypeDef . isPresent ( ) ) { boolean equals = interfaceTypeDef . get ( ) . getName ( ) . equals ( targetInterface . getName ( ) ) ; if ( equals ) { return true ; } } } return false ; } ) . collect ( Collectors . toList ( ) ) ; }
Returns the list of object types that implement the given interface type
7,562
@ SuppressWarnings ( "ConstantConditions" ) public boolean isPossibleType ( Type abstractType , Type possibleObjectType ) { if ( ! isInterfaceOrUnion ( abstractType ) ) { return false ; } if ( ! isObjectType ( possibleObjectType ) ) { return false ; } ObjectTypeDefinition targetObjectTypeDef = getType ( possibleObjectType , ObjectTypeDefinition . class ) . get ( ) ; TypeDefinition abstractTypeDef = getType ( abstractType ) . get ( ) ; if ( abstractTypeDef instanceof UnionTypeDefinition ) { List < Type > memberTypes = ( ( UnionTypeDefinition ) abstractTypeDef ) . getMemberTypes ( ) ; for ( Type memberType : memberTypes ) { Optional < ObjectTypeDefinition > checkType = getType ( memberType , ObjectTypeDefinition . class ) ; if ( checkType . isPresent ( ) ) { if ( checkType . get ( ) . getName ( ) . equals ( targetObjectTypeDef . getName ( ) ) ) { return true ; } } } return false ; } else { InterfaceTypeDefinition iFace = ( InterfaceTypeDefinition ) abstractTypeDef ; List < ObjectTypeDefinition > objectTypeDefinitions = getImplementationsOf ( iFace ) ; return objectTypeDefinitions . stream ( ) . anyMatch ( od -> od . getName ( ) . equals ( targetObjectTypeDef . getName ( ) ) ) ; } }
Returns true of the abstract type is in implemented by the object type
7,563
public static ExecutionPath fromList ( List < ? > objects ) { assertNotNull ( objects ) ; ExecutionPath path = ExecutionPath . rootPath ( ) ; for ( Object object : objects ) { if ( object instanceof Number ) { path = path . segment ( ( ( Number ) object ) . intValue ( ) ) ; } else { path = path . segment ( String . valueOf ( object ) ) ; } } return path ; }
This will create an execution path from the list of objects
7,564
public static String printAst ( Node node ) { StringWriter sw = new StringWriter ( ) ; printAst ( sw , node ) ; return sw . toString ( ) ; }
This will pretty print the AST node in graphql language format
7,565
public static String printAstCompact ( Node node ) { StringWriter sw = new StringWriter ( ) ; printImpl ( sw , node , true ) ; return sw . toString ( ) ; }
This will print the Ast node in graphql language format in a compact manner with no new lines and comments stripped out of the text .
7,566
public GraphQLSchema transform ( Consumer < Builder > builderConsumer ) { Builder builder = newSchema ( this ) ; builderConsumer . accept ( builder ) ; return builder . build ( ) ; }
This helps you transform the current GraphQLSchema object into another one by starting a builder with all the current values and allows you to transform it how you want .
7,567
public static Builder newSchema ( GraphQLSchema existingSchema ) { return new Builder ( ) . query ( existingSchema . getQueryType ( ) ) . mutation ( existingSchema . getMutationType ( ) ) . subscription ( existingSchema . getSubscriptionType ( ) ) . codeRegistry ( existingSchema . getCodeRegistry ( ) ) . clearAdditionalTypes ( ) . clearDirectives ( ) . additionalDirectives ( existingSchema . directives ) . additionalTypes ( existingSchema . additionalTypes ) ; }
This allows you to build a schema from an existing schema . It copies everything from the existing schema and then allows you to replace them .
7,568
public static < T > Map < String , T > getByName ( List < T > namedObjects , Function < T , String > nameFn , BinaryOperator < T > mergeFunc ) { return namedObjects . stream ( ) . collect ( Collectors . toMap ( nameFn , identity ( ) , mergeFunc , LinkedHashMap :: new ) ) ; }
From a list of named things get a map of them by name merging them according to the merge function
7,569
public static < T , NewKey > Map < NewKey , List < T > > groupingBy ( List < T > list , Function < T , NewKey > function ) { return list . stream ( ) . collect ( Collectors . groupingBy ( function , LinkedHashMap :: new , mapping ( Function . identity ( ) , Collectors . toList ( ) ) ) ) ; }
normal groupingBy but with LinkedHashMap
7,570
public static < T > Map < String , T > getByName ( List < T > namedObjects , Function < T , String > nameFn ) { return getByName ( namedObjects , nameFn , mergeFirst ( ) ) ; }
From a list of named things get a map of them by name merging them first one added
7,571
@ SuppressWarnings ( "unchecked" ) public static < T > Collection < T > toCollection ( Object iterableResult ) { if ( iterableResult . getClass ( ) . isArray ( ) ) { List < Object > collect = IntStream . range ( 0 , Array . getLength ( iterableResult ) ) . mapToObj ( i -> Array . get ( iterableResult , i ) ) . collect ( Collectors . toList ( ) ) ; return ( List < T > ) collect ; } if ( iterableResult instanceof Collection ) { return ( Collection < T > ) iterableResult ; } Iterable < T > iterable = ( Iterable < T > ) iterableResult ; Iterator < T > iterator = iterable . iterator ( ) ; List < T > list = new ArrayList < > ( ) ; while ( iterator . hasNext ( ) ) { list . add ( iterator . next ( ) ) ; } return list ; }
Converts an object that should be an Iterable into a Collection efficiently leaving it alone if it is already is one . Useful when you want to get the size of something
7,572
public static < T > List < T > concat ( List < T > l1 , List < T > l2 ) { ArrayList < T > l = new ArrayList < > ( l1 ) ; l . addAll ( l2 ) ; l . trimToSize ( ) ; return l ; }
Concatenates two lists into one
7,573
public static < T > List < T > valuesToList ( Map < ? , T > map ) { return new ArrayList < > ( map . values ( ) ) ; }
quickly turn a map of values into its list equivalent
7,574
public static TypeRuntimeWiring newTypeWiring ( String typeName , UnaryOperator < Builder > builderFunction ) { return builderFunction . apply ( newTypeWiring ( typeName ) ) . build ( ) ; }
This form allows a lambda to be used as the builder
7,575
public CacheControl hint ( DataFetchingEnvironment dataFetchingEnvironment , Integer maxAge , Scope scope ) { assertNotNull ( dataFetchingEnvironment ) ; assertNotNull ( scope ) ; hint ( dataFetchingEnvironment . getExecutionStepInfo ( ) . getPath ( ) , maxAge , scope ) ; return this ; }
This creates a cache control hint for the specified field being fetched
7,576
public CacheControl hint ( DataFetchingEnvironment dataFetchingEnvironment , Integer maxAge ) { hint ( dataFetchingEnvironment , maxAge , Scope . PUBLIC ) ; return this ; }
This creates a cache control hint for the specified field being fetched with a PUBLIC scope
7,577
public CacheControl hint ( DataFetchingEnvironment dataFetchingEnvironment , Scope scope ) { return hint ( dataFetchingEnvironment , null , scope ) ; }
This creates a cache control hint for the specified field being fetched with a specified scope
7,578
public GraphQLUnionType transform ( Consumer < Builder > builderConsumer ) { Builder builder = newUnionType ( this ) ; builderConsumer . accept ( builder ) ; return builder . build ( ) ; }
This helps you transform the current GraphQLUnionType into another one by starting a builder with all the current values and allows you to transform it how you want .
7,579
public SimpleFieldValidation addRule ( ExecutionPath fieldPath , BiFunction < FieldAndArguments , FieldValidationEnvironment , Optional < GraphQLError > > rule ) { rules . put ( fieldPath , rule ) ; return this ; }
Adds the rule against the field address path . If the rule returns an error it will be added to the list of errors
7,580
protected CompletableFuture < ExecutionResult > completeValueForObject ( ExecutionContext executionContext , ExecutionStrategyParameters parameters , GraphQLObjectType resolvedObjectType , Object result ) { ExecutionStepInfo executionStepInfo = parameters . getExecutionStepInfo ( ) ; FieldCollectorParameters collectorParameters = newParameters ( ) . schema ( executionContext . getGraphQLSchema ( ) ) . objectType ( resolvedObjectType ) . fragments ( executionContext . getFragmentsByName ( ) ) . variables ( executionContext . getVariables ( ) ) . build ( ) ; MergedSelectionSet subFields = fieldCollector . collectFields ( collectorParameters , parameters . getField ( ) ) ; ExecutionStepInfo newExecutionStepInfo = executionStepInfo . changeTypeWithPreservedNonNull ( resolvedObjectType ) ; NonNullableFieldValidator nonNullableFieldValidator = new NonNullableFieldValidator ( executionContext , newExecutionStepInfo ) ; ExecutionStrategyParameters newParameters = parameters . transform ( builder -> builder . executionStepInfo ( newExecutionStepInfo ) . fields ( subFields ) . nonNullFieldValidator ( nonNullableFieldValidator ) . source ( result ) ) ; return executionContext . getQueryStrategy ( ) . execute ( executionContext , newParameters ) ; }
Called to turn an java object value into an graphql object value
7,581
protected ExecutionStepInfo createExecutionStepInfo ( ExecutionContext executionContext , ExecutionStrategyParameters parameters , GraphQLFieldDefinition fieldDefinition , GraphQLObjectType fieldContainer ) { GraphQLOutputType fieldType = fieldDefinition . getType ( ) ; List < Argument > fieldArgs = parameters . getField ( ) . getArguments ( ) ; GraphQLCodeRegistry codeRegistry = executionContext . getGraphQLSchema ( ) . getCodeRegistry ( ) ; Map < String , Object > argumentValues = valuesResolver . getArgumentValues ( codeRegistry , fieldDefinition . getArguments ( ) , fieldArgs , executionContext . getVariables ( ) ) ; return newExecutionStepInfo ( ) . type ( fieldType ) . fieldDefinition ( fieldDefinition ) . fieldContainer ( fieldContainer ) . field ( parameters . getField ( ) ) . path ( parameters . getPath ( ) ) . parentInfo ( parameters . getExecutionStepInfo ( ) ) . arguments ( argumentValues ) . build ( ) ; }
Builds the type info hierarchy for the current field
7,582
public SourceAndLine getSourceAndLineFromOverallLine ( int overallLineNumber ) { SourceAndLine sourceAndLine = new SourceAndLine ( ) ; if ( sourceParts . isEmpty ( ) ) { return sourceAndLine ; } SourcePart currentPart ; if ( currentIndex >= sourceParts . size ( ) ) { currentPart = sourceParts . get ( sourceParts . size ( ) - 1 ) ; } else { currentPart = sourceParts . get ( currentIndex ) ; } int page = 0 ; int previousPage ; for ( SourcePart sourcePart : sourceParts ) { sourceAndLine . sourceName = sourcePart . sourceName ; if ( sourcePart == currentPart ) { int offset = currentPart . lineReader . getLineNumber ( ) ; previousPage = page ; page += offset ; if ( page > overallLineNumber ) { sourceAndLine . line = overallLineNumber - previousPage ; } else { sourceAndLine . line = page ; } return sourceAndLine ; } else { previousPage = page ; page += sourcePart . lineReader . getLineNumber ( ) ; if ( page > overallLineNumber ) { sourceAndLine . line = overallLineNumber - previousPage ; return sourceAndLine ; } } } sourceAndLine . line = overallLineNumber - page ; return sourceAndLine ; }
This returns the source name and line number given an overall line number
7,583
public < T > T validate ( ExecutionPath path , T result ) throws NonNullableFieldWasNullException { if ( result == null ) { if ( executionStepInfo . isNonNullType ( ) ) { NonNullableFieldWasNullException nonNullException = new NonNullableFieldWasNullException ( executionStepInfo , path ) ; executionContext . addError ( new NonNullableFieldWasNullError ( nonNullException ) , path ) ; throw nonNullException ; } } return result ; }
Called to check that a value is non null if the type requires it to be non null
7,584
public static boolean isLeaf ( GraphQLType type ) { GraphQLUnmodifiedType unmodifiedType = unwrapAll ( type ) ; return unmodifiedType instanceof GraphQLScalarType || unmodifiedType instanceof GraphQLEnumType ; }
Returns true if the given type is a leaf type that it cant contain any more fields
7,585
public static boolean isInput ( GraphQLType type ) { GraphQLUnmodifiedType unmodifiedType = unwrapAll ( type ) ; return unmodifiedType instanceof GraphQLScalarType || unmodifiedType instanceof GraphQLEnumType || unmodifiedType instanceof GraphQLInputObjectType ; }
Returns true if the given type is an input type
7,586
public static GraphQLType unwrapOne ( GraphQLType type ) { if ( isNonNull ( type ) ) { return ( ( GraphQLNonNull ) type ) . getWrappedType ( ) ; } else if ( isList ( type ) ) { return ( ( GraphQLList ) type ) . getWrappedType ( ) ; } return type ; }
Unwraps one layer of the type or just returns the type again if its not a wrapped type
7,587
public static GraphQLUnmodifiedType unwrapAll ( GraphQLType type ) { while ( true ) { if ( isNotWrapped ( type ) ) { return ( GraphQLUnmodifiedType ) type ; } type = unwrapOne ( type ) ; } }
Unwraps all layers of the type or just returns the type again if its not a wrapped type
7,588
public String getResultKey ( ) { Field singleField = getSingleField ( ) ; if ( singleField . getAlias ( ) != null ) { return singleField . getAlias ( ) ; } return singleField . getName ( ) ; }
Returns the key of this MergedField for the overall result . This is either an alias or the field name .
7,589
public ExecutionResult toExecutionResult ( ) { ExecutionResult executionResult = new ExecutionResultImpl ( this ) ; if ( ! this . getUnderlyingErrors ( ) . isEmpty ( ) ) { executionResult = new ExecutionResultImpl ( this . getUnderlyingErrors ( ) ) ; } return executionResult ; }
This is useful for turning this abort signal into an execution result which is an error state with the underlying errors in it .
7,590
public Document createSchemaDefinition ( ExecutionResult introspectionResult ) { Map < String , Object > introspectionResultMap = introspectionResult . getData ( ) ; return createSchemaDefinition ( introspectionResultMap ) ; }
Returns a IDL Document that represents the schema as defined by the introspection execution result
7,591
@ SuppressWarnings ( "unchecked" ) public Document createSchemaDefinition ( Map < String , Object > introspectionResult ) { assertTrue ( introspectionResult . get ( "__schema" ) != null , "__schema expected" ) ; Map < String , Object > schema = ( Map < String , Object > ) introspectionResult . get ( "__schema" ) ; Map < String , Object > queryType = ( Map < String , Object > ) schema . get ( "queryType" ) ; assertNotNull ( queryType , "queryType expected" ) ; TypeName query = TypeName . newTypeName ( ) . name ( ( String ) queryType . get ( "name" ) ) . build ( ) ; boolean nonDefaultQueryName = ! "Query" . equals ( query . getName ( ) ) ; SchemaDefinition . Builder schemaDefinition = SchemaDefinition . newSchemaDefinition ( ) ; schemaDefinition . operationTypeDefinition ( OperationTypeDefinition . newOperationTypeDefinition ( ) . name ( "query" ) . typeName ( query ) . build ( ) ) ; Map < String , Object > mutationType = ( Map < String , Object > ) schema . get ( "mutationType" ) ; boolean nonDefaultMutationName = false ; if ( mutationType != null ) { TypeName mutation = TypeName . newTypeName ( ) . name ( ( String ) mutationType . get ( "name" ) ) . build ( ) ; nonDefaultMutationName = ! "Mutation" . equals ( mutation . getName ( ) ) ; schemaDefinition . operationTypeDefinition ( OperationTypeDefinition . newOperationTypeDefinition ( ) . name ( "mutation" ) . typeName ( mutation ) . build ( ) ) ; } Map < String , Object > subscriptionType = ( Map < String , Object > ) schema . get ( "subscriptionType" ) ; boolean nonDefaultSubscriptionName = false ; if ( subscriptionType != null ) { TypeName subscription = TypeName . newTypeName ( ) . name ( ( ( String ) subscriptionType . get ( "name" ) ) ) . build ( ) ; nonDefaultSubscriptionName = ! "Subscription" . equals ( subscription . getName ( ) ) ; schemaDefinition . operationTypeDefinition ( OperationTypeDefinition . newOperationTypeDefinition ( ) . name ( "subscription" ) . typeName ( subscription ) . build ( ) ) ; } Document . Builder document = Document . newDocument ( ) ; if ( nonDefaultQueryName || nonDefaultMutationName || nonDefaultSubscriptionName ) { document . definition ( schemaDefinition . build ( ) ) ; } List < Map < String , Object > > types = ( List < Map < String , Object > > ) schema . get ( "types" ) ; for ( Map < String , Object > type : types ) { TypeDefinition typeDefinition = createTypeDefinition ( type ) ; if ( typeDefinition == null ) continue ; document . definition ( typeDefinition ) ; } return document . build ( ) ; }
Returns a IDL Document that reprSesents the schema as defined by the introspection result map
7,592
static < T , E extends GraphQLError > void checkNamedUniqueness ( List < GraphQLError > errors , List < T > listOfNamedThings , Function < T , String > namer , BiFunction < String , T , E > errorFunction ) { Set < String > names = new LinkedHashSet < > ( ) ; listOfNamedThings . forEach ( thing -> { String name = namer . apply ( thing ) ; if ( names . contains ( name ) ) { errors . add ( errorFunction . apply ( name , thing ) ) ; } else { names . add ( name ) ; } } ) ; }
A simple function that takes a list of things asks for their names and checks that the names are unique within that list . If not it calls the error handler function
7,593
public static String assertValidName ( String name ) { if ( name != null && ! name . isEmpty ( ) && name . matches ( "[_A-Za-z][_0-9A-Za-z]*" ) ) { return name ; } throw new AssertException ( String . format ( invalidNameErrorMessage , name ) ) ; }
Validates that the Lexical token name matches the current spec . currently non null non empty
7,594
public Map < String , Object > snapshotTracingData ( ) { Map < String , Object > traceMap = new LinkedHashMap < > ( ) ; traceMap . put ( "version" , 1L ) ; traceMap . put ( "startTime" , rfc3339 ( startRequestTime ) ) ; traceMap . put ( "endTime" , rfc3339 ( Instant . now ( ) ) ) ; traceMap . put ( "duration" , System . nanoTime ( ) - startRequestNanos ) ; traceMap . put ( "parsing" , copyMap ( parseMap ) ) ; traceMap . put ( "validation" , copyMap ( validationMap ) ) ; traceMap . put ( "execution" , executionData ( ) ) ; return traceMap ; }
This will snapshot this tracing and return a map of the results
7,595
public GraphQLEnumType transform ( Consumer < Builder > builderConsumer ) { Builder builder = newEnum ( this ) ; builderConsumer . accept ( builder ) ; return builder . build ( ) ; }
This helps you transform the current GraphQLEnumType into another one by starting a builder with all the current values and allows you to transform it how you want .
7,596
public static DiffSet diffSet ( Map < String , Object > introspectionOld , Map < String , Object > introspectionNew ) { return new DiffSet ( introspectionOld , introspectionNew ) ; }
Creates a diff set out of the result of 2 introspection queries .
7,597
public static DiffSet diffSet ( GraphQLSchema schemaOld , GraphQLSchema schemaNew ) { Map < String , Object > introspectionOld = introspect ( schemaOld ) ; Map < String , Object > introspectionNew = introspect ( schemaNew ) ; return diffSet ( introspectionOld , introspectionNew ) ; }
Creates a diff set out of the result of 2 schemas .
7,598
public GraphQLArgument transform ( Consumer < Builder > builderConsumer ) { Builder builder = newArgument ( this ) ; builderConsumer . accept ( builder ) ; return builder . build ( ) ; }
This helps you transform the current GraphQLArgument into another one by starting a builder with all the current values and allows you to transform it how you want .
7,599
@ SuppressWarnings ( "unchecked" ) public int diffSchema ( DiffSet diffSet , DifferenceReporter reporter ) { CountingReporter countingReporter = new CountingReporter ( reporter ) ; diffSchemaImpl ( diffSet , countingReporter ) ; return countingReporter . breakingCount ; }
This will perform a difference on the two schemas . The reporter callback interface will be called when differences are encountered .