idx int64 0 41.2k | question stringlengths 83 4.15k | target stringlengths 5 715 |
|---|---|---|
11,900 | private static SeriesUpdate parseNextSeriesUpdate ( Element element ) { SeriesUpdate seriesUpdate = new SeriesUpdate ( ) ; seriesUpdate . setSeriesId ( DOMHelper . getValueFromElement ( element , "id" ) ) ; seriesUpdate . setTime ( DOMHelper . getValueFromElement ( element , TIME ) ) ; return seriesUpdate ; } | Parse the series update record from the document |
11,901 | private static EpisodeUpdate parseNextEpisodeUpdate ( Element element ) { EpisodeUpdate episodeUpdate = new EpisodeUpdate ( ) ; episodeUpdate . setSeriesId ( DOMHelper . getValueFromElement ( element , "id" ) ) ; episodeUpdate . setEpisodeId ( DOMHelper . getValueFromElement ( element , SERIES ) ) ; episodeUpdate . setTime ( DOMHelper . getValueFromElement ( element , TIME ) ) ; return episodeUpdate ; } | Parse the episode update record from the document |
11,902 | private static BannerUpdate parseNextBannerUpdate ( Element element ) { BannerUpdate bannerUpdate = new BannerUpdate ( ) ; bannerUpdate . setSeasonNum ( DOMHelper . getValueFromElement ( element , "SeasonNum" ) ) ; bannerUpdate . setSeriesId ( DOMHelper . getValueFromElement ( element , SERIES ) ) ; bannerUpdate . setFormat ( DOMHelper . getValueFromElement ( element , "format" ) ) ; bannerUpdate . setLanguage ( DOMHelper . getValueFromElement ( element , "language" ) ) ; bannerUpdate . setPath ( DOMHelper . getValueFromElement ( element , "path" ) ) ; bannerUpdate . setTime ( DOMHelper . getValueFromElement ( element , TIME ) ) ; bannerUpdate . setType ( DOMHelper . getValueFromElement ( element , "type" ) ) ; return bannerUpdate ; } | Parse the banner update record from the document |
11,903 | private static Language parseNextLanguage ( Element element ) { Language language = new Language ( ) ; language . setName ( DOMHelper . getValueFromElement ( element , "name" ) ) ; language . setAbbreviation ( DOMHelper . getValueFromElement ( element , "abbreviation" ) ) ; language . setId ( DOMHelper . getValueFromElement ( element , "id" ) ) ; return language ; } | Parses the next language . |
11,904 | private void copyBaseDirs ( File [ ] baseDirs ) { this . baseDirs = new File [ baseDirs . length ] ; for ( int i = 0 ; i < baseDirs . length ; i ++ ) { this . baseDirs [ i ] = baseDirs [ i ] . getAbsoluteFile ( ) ; } } | Convert the dirs to absolute paths to prevent that equals returns true for directories with the same name in a different location . |
11,905 | public Group < E > group ( String name ) { for ( Group < E > group : this . groups ( ) ) { if ( group . expr instanceof Expression . NamedGroup < ? > ) { Expression . NamedGroup < E > namedGroup = ( Expression . NamedGroup < E > ) group . expr ; if ( namedGroup . name . equals ( name ) ) { return group ; } } } return null ; } | Retrieve a group by name . |
11,906 | public BindingAssert < T > hasSameValue ( ObservableValue < T > expectedValue ) { new ObservableValueAssertions < > ( actual ) . hasSameValue ( expectedValue ) ; return this ; } | Verifies that the actual binding has the same value as the given observable . |
11,907 | public static LessCompilationEngine create ( String type , String executable ) { if ( type == null || RHINO . equals ( type ) ) { return create ( ) ; } if ( COMMAND_LINE . equals ( type ) ) { return new CommandLineLesscCompilationEngine ( executable ) ; } return new ScriptEngineLessCompilationEngine ( type ) ; } | Create a new engine of the specified type if available or a default engine . |
11,908 | public static void configure ( boolean verbose , boolean daemon ) { LoggerContext lc = ( LoggerContext ) LoggerFactory . getILoggerFactory ( ) ; ConsoleAppender < ILoggingEvent > ca = new ConsoleAppender < ILoggingEvent > ( ) ; ca . setContext ( lc ) ; ca . setName ( "less console" ) ; PatternLayoutEncoder pl = new PatternLayoutEncoder ( ) ; pl . setContext ( lc ) ; pl . setPattern ( "%msg%n" ) ; pl . start ( ) ; ca . setEncoder ( pl ) ; ca . start ( ) ; lc . getLogger ( Logger . ROOT_LOGGER_NAME ) . detachAndStopAllAppenders ( ) ; configureCompilerLogger ( verbose , lc , ca ) ; configureCompilationTaskLogger ( daemon , lc , ca ) ; configureLessCompilationEngineLogger ( verbose , lc , ca ) ; } | Configure the LessCompilerImpl logger with a ConsoleAppender |
11,909 | public static < E > Automaton < E > build ( List < Expression < E > > exprs ) { Expression . MatchingGroup < E > group = new Expression . MatchingGroup < E > ( exprs ) ; return group . build ( ) ; } | Build an NFA from the list of expressions . |
11,910 | public boolean apply ( List < E > tokens ) { if ( this . find ( tokens ) != null ) { return true ; } else { return false ; } } | Apply the expression against a list of tokens . |
11,911 | public Match < E > find ( List < E > tokens , int start ) { Match < E > match ; for ( int i = start ; i <= tokens . size ( ) - auto . minMatchingLength ( ) ; i ++ ) { match = this . lookingAt ( tokens , i ) ; if ( match != null ) { return match ; } } return null ; } | Find the first match of the regular expression against tokens starting at the specified index . |
11,912 | public Match < E > lookingAt ( List < E > tokens , int start ) { return auto . lookingAt ( tokens , start ) ; } | Determine if the regular expression matches the supplied tokens starting at the specified index . |
11,913 | public List < Match < E > > findAll ( List < E > tokens ) { List < Match < E > > results = new ArrayList < Match < E > > ( ) ; int start = 0 ; Match < E > match ; do { match = this . find ( tokens , start ) ; if ( match != null ) { start = match . endIndex ( ) ; if ( ! match . isEmpty ( ) ) { results . add ( match ) ; } } } while ( match != null ) ; return results ; } | Find all non - overlapping matches of the regular expression against tokens . |
11,914 | public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; RegularExpression < String > regex = RegularExpressionParsers . word . parse ( args [ 0 ] ) ; System . out . println ( "regex: " + regex ) ; System . out . println ( ) ; while ( scan . hasNextLine ( ) ) { String line = scan . nextLine ( ) ; System . out . println ( "contains: " + regex . apply ( Arrays . asList ( line . split ( "\\s+" ) ) ) ) ; System . out . println ( "matches: " + regex . matches ( Arrays . asList ( line . split ( "\\s+" ) ) ) ) ; System . out . println ( ) ; } scan . close ( ) ; } | An interactive program that compiles a word - based regular expression specified in arg1 and then reads strings from stdin evaluating them against the regular expression . |
11,915 | public boolean isEquivalent ( CompilationUnit other ) { if ( ! destination . getAbsoluteFile ( ) . equals ( other . destination . getAbsoluteFile ( ) ) ) return false ; if ( encoding != null ? ! encoding . equals ( other . encoding ) : other . encoding != null ) return false ; if ( resourceReader != null ? ! resourceReader . equals ( other . resourceReader ) : other . resourceReader != null ) return false ; if ( ! options . equals ( other . options ) ) return false ; if ( sourceMapFile != null ? ! sourceMapFile . equals ( other . sourceMapFile ) : other . sourceMapFile != null ) return false ; return sourceLocation . equals ( other . sourceLocation ) ; } | Checks whether two compilation units represent the same compilation . Only the imports may be different when they have not yet been set . |
11,916 | private static MessageDigest SHA512_Init ( ) { Log . d ( "Ed25519" , "SHA512_Init" ) ; try { return MessageDigest . getInstance ( "SHA-512" ) ; } catch ( NoSuchAlgorithmException e ) { e . printStackTrace ( ) ; } return null ; } | jni c code calls this for sha512 . |
11,917 | public void addIndexWarning ( String noIndexGiven ) { if ( jsonResponse == null ) { jsonResponse = new JSONObject ( ) ; } jsonResponse . put ( "warning:noIndexGiven" , noIndexGiven ) ; } | not implemented yet |
11,918 | public static DeleteFollowRequest checkRequest ( final HttpServletRequest request , final DeleteRequest deleteRequest , final DeleteFollowResponse deleteFollowResponse ) { final Node user = checkUserIdentifier ( request , deleteFollowResponse ) ; if ( user != null ) { final Node followed = checkFollowedIdentifier ( request , deleteFollowResponse ) ; if ( followed != null ) { return new DeleteFollowRequest ( deleteRequest . getType ( ) , user , followed ) ; } } return null ; } | check a delete follow edge request for validity concerning NSSP |
11,919 | protected void doGet ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { long start = System . nanoTime ( ) ; ProcessRetrieveResponse responseObject = ProcessRetrieveRequest . checkRequestParameter ( request , this . getServletContext ( ) ) ; String resultJson = responseObject . buildJsonResonse ( ) ; response . setContentType ( "application/json" ) ; PrintWriter out = response . getWriter ( ) ; long end = System . nanoTime ( ) ; out . println ( resultJson ) ; out . flush ( ) ; } | de . metalcon . autocompleteServer . Retrieve . RetrieveServlet |
11,920 | private static CreateRequestType checkType ( final FormItemList formItemList , final CreateResponse createResponse ) { final String sType = formItemList . getField ( ProtocolConstants . Parameters . Create . TYPE ) ; if ( sType != null ) { if ( CreateRequestType . USER . getIdentifier ( ) . equals ( sType ) ) { return CreateRequestType . USER ; } else if ( CreateRequestType . FOLLOW . getIdentifier ( ) . equals ( sType ) ) { return CreateRequestType . FOLLOW ; } else if ( CreateRequestType . STATUS_UPDATE . getIdentifier ( ) . equals ( sType ) ) { return CreateRequestType . STATUS_UPDATE ; } createResponse . typeInvalid ( sType ) ; } else { createResponse . typeMissing ( ) ; } return null ; } | check if the request contains a valid create request type |
11,921 | private void writeFiles ( final StatusUpdateTemplate template , final FormItemList items ) throws Exception { FormFile fileItem ; TemplateFileInfo fileInfo ; for ( String fileIdentifier : items . getFileIdentifiers ( ) ) { fileItem = items . getFile ( fileIdentifier ) ; fileInfo = template . getFiles ( ) . get ( fileIdentifier ) ; if ( fileInfo . getContentType ( ) . equals ( fileItem . getContentType ( ) ) ) { final File file = this . writeFile ( fileItem ) ; fileItem . setFile ( file ) ; } else { throw new StatusUpdateInstantiationFailedException ( "file \"" + fileIdentifier + "\" must have content type " + fileInfo . getContentType ( ) ) ; } } } | write the files posted if they are matching to the template targeted |
11,922 | private File writeFile ( final FormFile fileItem ) throws Exception { final String directory = this . getFileDir ( fileItem . getContentType ( ) ) ; final File file = new File ( directory + System . currentTimeMillis ( ) + "-" + fileItem . getOriginalFileName ( ) ) ; fileItem . getFormItem ( ) . write ( file ) ; return file ; } | write a file to the directory matching its content type |
11,923 | @ SuppressWarnings ( "unchecked" ) public JSONObject toJSONObject ( ) { final JSONObject activity = new JSONObject ( ) ; activity . put ( "published" , dateFormatter . format ( new Date ( this . timestamp ) ) ) ; activity . put ( "verb" , "read" ) ; final Map < String , Object > object = this . toObjectJSON ( ) ; activity . put ( "object" , object ) ; return activity ; } | parse the status update to an Activity JSON String |
11,924 | protected Map < String , Object > toObjectJSON ( ) { final Map < String , Object > objectJSON = new LinkedHashMap < String , Object > ( ) ; objectJSON . put ( "objectType" , "article" ) ; objectJSON . put ( "type" , this . type ) ; objectJSON . put ( "id" , this . id ) ; return objectJSON ; } | parse the status update to an Object JSON map |
11,925 | private static Properties loadProperties ( String propertiesFile ) { Properties properties = new Properties ( ) ; try ( InputStream is = new FileInputStream ( propertiesFile ) ) { properties . load ( is ) ; } catch ( IOException e ) { throw new RuntimeException ( "failed to load properties" , e ) ; } return properties ; } | Loads properties from a properties file on the local filesystem . |
11,926 | private static Properties loadPropertiesFromClasspath ( String propertiesFile ) { Properties properties = new Properties ( ) ; try ( InputStream is = Thread . currentThread ( ) . getContextClassLoader ( ) . getResourceAsStream ( propertiesFile ) ) { properties . load ( is ) ; } catch ( IOException e ) { throw new RuntimeException ( "failed to load properties" , e ) ; } return properties ; } | Loads properties from a properties file on the classpath . |
11,927 | public < T > Collection < T > getCollection ( String prefix , Function < String , T > factory ) { Collection < T > collection = new ArrayList < > ( ) ; for ( String property : properties . stringPropertyNames ( ) ) { if ( property . startsWith ( prefix + "." ) ) { collection . add ( factory . apply ( property ) ) ; } } return collection ; } | Reads a collection of properties based on a prefix . |
11,928 | public < K , V > Map < K , V > getMap ( String prefix , Function < String , K > keyFactory , Function < String , V > valueFactory ) { Map < K , V > map = new HashMap < > ( ) ; for ( String property : properties . stringPropertyNames ( ) ) { if ( property . startsWith ( prefix + "." ) ) { map . put ( keyFactory . apply ( property . substring ( prefix . length ( ) + 1 ) ) , valueFactory . apply ( properties . getProperty ( property ) ) ) ; } } return map ; } | Returns a map of properties for a given prefix . |
11,929 | public Class < ? > getClass ( String property ) { return getProperty ( property , className -> { try { return Class . forName ( className ) ; } catch ( ClassNotFoundException e ) { throw new ConfigurationException ( "unknown class: " + className , e ) ; } } ) ; } | Reads a class property . |
11,930 | public File getFile ( String property , File defaultValue ) { return getProperty ( property , defaultValue , File :: new ) ; } | Reads a file property . |
11,931 | public < T extends Enum < T > > T getEnum ( String property , Class < T > type ) { return Enum . valueOf ( type , getString ( property ) ) ; } | Reads an enum property . |
11,932 | public String getString ( String property , String defaultValue ) { return getProperty ( property , defaultValue , v -> v ) ; } | Reads a string property returning a default value if the property is not present . |
11,933 | public boolean getBoolean ( String property ) { return getProperty ( property , value -> { switch ( value . trim ( ) . toLowerCase ( ) ) { case "true" : case "1" : return true ; case "false" : case "0" : return false ; default : throw new ConfigurationException ( "invalid property value: " + property + " must be a boolean" ) ; } } ) ; } | Reads a boolean property . |
11,934 | public short getShort ( String property ) { return getProperty ( property , value -> { try { return Short . valueOf ( value ) ; } catch ( NumberFormatException e ) { throw new ConfigurationException ( "malformed property value: " + property + " must be a short" ) ; } } ) ; } | Reads a short property . |
11,935 | public int getInteger ( String property ) { return getProperty ( property , value -> { try { return Integer . valueOf ( value ) ; } catch ( NumberFormatException e ) { throw new ConfigurationException ( "malformed property value: " + property + " must be an integer" ) ; } } ) ; } | Reads an integer property . |
11,936 | public long getLong ( String property ) { return getProperty ( property , value -> { try { return Long . valueOf ( value ) ; } catch ( NumberFormatException e ) { throw new ConfigurationException ( "malformed property value: " + property + " must be a long" ) ; } } ) ; } | Reads a long property . |
11,937 | public float getFloat ( String property ) { return getProperty ( property , value -> { try { return Float . valueOf ( value ) ; } catch ( NumberFormatException e ) { throw new ConfigurationException ( "malformed property value: " + property + " must be a float" ) ; } } ) ; } | Reads a float property . |
11,938 | public double getDouble ( String property ) { return getProperty ( property , value -> { try { return Double . valueOf ( value ) ; } catch ( NumberFormatException e ) { throw new ConfigurationException ( "malformed property value: " + property + " must be a double" ) ; } } ) ; } | Reads a double property . |
11,939 | private < T > T getProperty ( String property , Function < String , T > transformer ) { Assert . notNull ( property , "property" ) ; String value = properties . getProperty ( property ) ; if ( value == null ) throw new ConfigurationException ( "missing property: " + property ) ; return transformer . apply ( value ) ; } | Reads an arbitrary property . |
11,940 | public void addFriend ( Friend friend ) { try { get ( ) . addEntry ( friend . get ( ) ) ; } catch ( NoResponseException | XMPPErrorException | NotConnectedException e ) { e . printStackTrace ( ) ; } } | Moves a friend to this group and removes the friend from his previous group . This is an asynchronous call . |
11,941 | public boolean contains ( Friend friend ) { for ( final Friend f : getFriends ( ) ) { if ( StringUtils . parseName ( f . getUserId ( ) ) . equals ( StringUtils . parseName ( friend . getUserId ( ) ) ) ) { return true ; } } return false ; } | Checks if a given Friend is part of this group . |
11,942 | public List < Friend > getFriends ( ) { final List < Friend > friends = new ArrayList < > ( ) ; for ( final RosterEntry e : get ( ) . getEntries ( ) ) { friends . add ( new Friend ( api , con , e ) ) ; } return friends ; } | Gets a list of all Friends in this FriendGroup . |
11,943 | public void setName ( String name ) { try { get ( ) . setName ( name ) ; } catch ( final NotConnectedException e ) { e . printStackTrace ( ) ; } } | Changes the name of this group . Case sensitive . |
11,944 | public static DeleteRequest checkRequest ( final HttpServletRequest request , final DeleteResponse deleteResponse ) { final DeleteRequestType type = checkType ( request , deleteResponse ) ; if ( type != null ) { return new DeleteRequest ( type ) ; } return null ; } | check a delete request for validity concerning NSSP |
11,945 | private static DeleteRequestType checkType ( final HttpServletRequest request , final DeleteResponse deleteResponse ) { { final String sType = request . getParameter ( ProtocolConstants . Parameters . Delete . TYPE ) ; if ( sType != null ) { if ( DeleteRequestType . USER . getIdentifier ( ) . equals ( sType ) ) { return DeleteRequestType . USER ; } else if ( DeleteRequestType . FOLLOW . getIdentifier ( ) . equals ( sType ) ) { return DeleteRequestType . FOLLOW ; } else if ( DeleteRequestType . STATUS_UPDATE . getIdentifier ( ) . equals ( sType ) ) { return DeleteRequestType . STATUS_UPDATE ; } else { deleteResponse . typeInvalid ( sType ) ; } } else { deleteResponse . typeMissing ( ) ; } return null ; } } | check if the request contains a valid delete request type |
11,946 | public static ProcessRetrieveResponse checkRequestParameter ( HttpServletRequest request , ServletContext context ) { ProcessRetrieveResponse response = new ProcessRetrieveResponse ( context ) ; Integer numItems = checkNumItems ( request , response ) ; String term = checkTerm ( request , response ) ; if ( term == null ) { return response ; } SuggestTree index = checkIndexName ( request , response , context ) ; if ( index == null ) { response . addError ( RetrieveStatusCodes . NO_INDEX_AVAILABLE ) ; return response ; } retrieveSuggestions ( request , response , index , term , numItems ) ; return response ; } | checks if the request Parameters follow the Protocol or corrects them . |
11,947 | private static SuggestTree checkIndexName ( HttpServletRequest request , ProcessRetrieveResponse response , ServletContext context ) { String indexName = request . getParameter ( ProtocolConstants . INDEX_PARAMETER ) ; SuggestTree index = null ; if ( indexName == null ) { indexName = ProtocolConstants . DEFAULT_INDEX_NAME ; response . addIndexWarning ( RetrieveStatusCodes . NO_INDEX_GIVEN ) ; index = ContextListener . getIndex ( indexName , context ) ; } else { index = ContextListener . getIndex ( indexName , context ) ; if ( index == null ) { indexName = ProtocolConstants . DEFAULT_INDEX_NAME ; response . addIndexWarning ( RetrieveStatusCodes . INDEX_UNKNOWN ) ; index = ContextListener . getIndex ( indexName , context ) ; } } return index ; } | Returns the search Index according to the indexName Parameter of the ASTP if no Parameter was in the request the default index will be used . if the parameter did not match any known index the default index will be used . returns null if the default index is requested but does not exist |
11,948 | public static org . neo4j . graphdb . Node createTemplateFileInfoNode ( final AbstractGraphDatabase graphDatabase , final TemplateFileInfo fileInfo ) { final org . neo4j . graphdb . Node fileNode = TemplateItemInfo . createTemplateItemNode ( graphDatabase , fileInfo ) ; fileNode . setProperty ( TemplateXMLFields . FILE_CONTENT_TYPE , fileInfo . getContentType ( ) ) ; return fileNode ; } | create a database node representing a template file information |
11,949 | @ SuppressWarnings ( "unchecked" ) public void addActivityStream ( final List < JSONObject > activities ) { final JSONArray items = new JSONArray ( ) ; for ( JSONObject activity : activities ) { items . add ( activity ) ; } this . json . put ( "items" , items ) ; } | add the news stream according to the Activitystrea . ms format |
11,950 | protected static CatalystThread getThread ( ExecutorService executor ) { final AtomicReference < CatalystThread > thread = new AtomicReference < > ( ) ; try { executor . submit ( ( ) -> { thread . set ( ( CatalystThread ) Thread . currentThread ( ) ) ; } ) . get ( ) ; } catch ( InterruptedException | ExecutionException e ) { throw new IllegalStateException ( "failed to initialize thread state" , e ) ; } return thread . get ( ) ; } | Gets the thread from a single threaded executor service . |
11,951 | public static org . neo4j . graphdb . Node createTemplateFieldInfoNode ( final AbstractGraphDatabase graphDatabase , final TemplateFieldInfo fieldInfo ) { final org . neo4j . graphdb . Node fieldNode = TemplateItemInfo . createTemplateItemNode ( graphDatabase , fieldInfo ) ; fieldNode . setProperty ( TemplateXMLFields . FIELD_TYPE , fieldInfo . getType ( ) ) ; return fieldNode ; } | create a database node representing a template field information |
11,952 | public static BitArray allocate ( long bits ) { if ( ! ( bits > 0 & ( bits & ( bits - 1 ) ) == 0 ) ) throw new IllegalArgumentException ( "size must be a power of 2" ) ; return new BitArray ( UnsafeHeapBytes . allocate ( Math . max ( bits / 8 + 8 , 8 ) ) , bits ) ; } | Allocates a new direct bit set . |
11,953 | public boolean set ( long index ) { if ( ! ( index < size ) ) throw new IndexOutOfBoundsException ( ) ; if ( ! get ( index ) ) { bytes . writeLong ( offset ( index ) , bytes . readLong ( offset ( index ) ) | ( 1l << position ( index ) ) ) ; count ++ ; return true ; } return false ; } | Sets the bit at the given index . |
11,954 | public boolean get ( long index ) { if ( ! ( index < size ) ) throw new IndexOutOfBoundsException ( ) ; return ( bytes . readLong ( offset ( index ) ) & ( 1l << ( position ( index ) ) ) ) != 0 ; } | Gets the bit at the given index . |
11,955 | public BitArray resize ( long size ) { bytes . resize ( Math . max ( size / 8 + 8 , 8 ) ) ; this . size = size ; return this ; } | Resizes the bit array to a new count . |
11,956 | BufferAllocator allocator ( ) { Class < ? > allocator = reader . getClass ( ALLOCATOR , UnpooledUnsafeHeapAllocator . class ) ; try { return ( BufferAllocator ) allocator . newInstance ( ) ; } catch ( InstantiationException | IllegalAccessException e ) { throw new ConfigurationException ( e ) ; } catch ( ClassCastException e ) { throw new ConfigurationException ( "invalid allocator class: " + allocator . getName ( ) ) ; } } | Returns the serializer buffer allocator . |
11,957 | private int idToInt ( String value ) { try { return Integer . valueOf ( value ) ; } catch ( NumberFormatException e ) { throw new ConfigurationException ( "invalid type ID: " + value ) ; } } | Converts a string to an integer . |
11,958 | private Class < ? > serializerToClass ( String value ) { try { return Thread . currentThread ( ) . getContextClassLoader ( ) . loadClass ( value ) ; } catch ( ClassNotFoundException e ) { throw new ConfigurationException ( "unknown serializable type: " + value ) ; } } | Converts a string to a class . |
11,959 | CompletableFuture < Void > connect ( LocalConnection connection ) { LocalConnection localConnection = new LocalConnection ( listener . context , connections ) ; connections . add ( localConnection ) ; connection . connect ( localConnection ) ; localConnection . connect ( connection ) ; return CompletableFuture . runAsync ( ( ) -> listener . listener . accept ( localConnection ) , listener . context . executor ( ) ) ; } | Connects to the server . |
11,960 | public Serializer registerClassLoader ( String className , ClassLoader classLoader ) { classLoaders . put ( className , classLoader ) ; return this ; } | Registers a ClassLoader for a class . |
11,961 | @ SuppressWarnings ( "unchecked" ) private BufferOutput writeById ( int id , Object object , BufferOutput output , TypeSerializer serializer ) { for ( Identifier identifier : Identifier . values ( ) ) { if ( identifier . accept ( id ) ) { identifier . write ( id , output . writeByte ( identifier . code ( ) ) ) ; serializer . write ( object , output , this ) ; return output ; } } throw new SerializationException ( "invalid type ID: " + id ) ; } | Writes an object to the buffer using the given serialization ID . |
11,962 | @ SuppressWarnings ( "unchecked" ) private BufferOutput writeByClass ( Class < ? > type , Object object , BufferOutput output , TypeSerializer serializer ) { if ( whitelistRequired . get ( ) ) throw new SerializationException ( "cannot serialize unregistered type: " + type ) ; serializer . write ( object , output . writeByte ( Identifier . CLASS . code ( ) ) . writeUTF8 ( type . getName ( ) ) , this ) ; return output ; } | Writes an object to the buffer with its class name . |
11,963 | @ SuppressWarnings ( "unchecked" ) private < T > T readById ( int id , BufferInput < ? > buffer ) { Class < T > type = ( Class < T > ) registry . type ( id ) ; if ( type == null ) throw new SerializationException ( "cannot deserialize: unknown type" ) ; TypeSerializer < T > serializer = getSerializer ( type ) ; if ( serializer == null ) throw new SerializationException ( "cannot deserialize: unknown type" ) ; return serializer . read ( type , buffer , this ) ; } | Reads a serializable object . |
11,964 | @ SuppressWarnings ( "unchecked" ) private < T > T readByClass ( BufferInput < ? > buffer ) { String name = buffer . readUTF8 ( ) ; if ( whitelistRequired . get ( ) ) throw new SerializationException ( "cannot deserialize unregistered type: " + name ) ; Class < T > type = ( Class < T > ) types . get ( name ) ; if ( type == null ) { try { type = ( Class < T > ) Class . forName ( name ) ; if ( type == null ) throw new SerializationException ( "cannot deserialize: unknown type" ) ; types . put ( name , type ) ; } catch ( ClassNotFoundException e ) { throw new SerializationException ( "object class not found: " + name , e ) ; } } TypeSerializer < T > serializer = getSerializer ( type ) ; if ( serializer == null ) throw new SerializationException ( "cannot deserialize unregistered type: " + name ) ; return serializer . read ( type , buffer , this ) ; } | Reads a writable object . |
11,965 | public static org . neo4j . graphdb . Node createTemplateNode ( final AbstractGraphDatabase graphDatabase , final StatusUpdateTemplate template ) { final org . neo4j . graphdb . Node templateNode = graphDatabase . createNode ( ) ; templateNode . setProperty ( Properties . Templates . IDENTIFIER , template . getName ( ) ) ; templateNode . setProperty ( Properties . Templates . VERSION , template . getVersion ( ) ) ; templateNode . setProperty ( Properties . Templates . CODE , template . getJavaCode ( ) ) ; org . neo4j . graphdb . Node itemNode ; TemplateFieldInfo fieldInfo ; for ( String fieldName : template . getFields ( ) . keySet ( ) ) { fieldInfo = template . getFields ( ) . get ( fieldName ) ; itemNode = TemplateFieldInfo . createTemplateFieldInfoNode ( graphDatabase , fieldInfo ) ; templateNode . createRelationshipTo ( itemNode , SocialGraphRelationshipType . Templates . FIELD ) ; } TemplateFileInfo fileInfo ; for ( String fileName : template . getFiles ( ) . keySet ( ) ) { fileInfo = template . getFiles ( ) . get ( fileName ) ; itemNode = TemplateFileInfo . createTemplateFileInfoNode ( graphDatabase , fileInfo ) ; templateNode . createRelationshipTo ( itemNode , SocialGraphRelationshipType . Templates . FILE ) ; } return templateNode ; } | create a database node representing a status update template |
11,966 | public void createUser ( final String userId , final String displayName , final String profilePicturePath ) { final Node user = NeoUtils . createUserNode ( userId ) ; user . setProperty ( Properties . User . DISPLAY_NAME , displayName ) ; user . setProperty ( Properties . User . PROFILE_PICTURE_PATH , profilePicturePath ) ; } | create a new user |
11,967 | public void deleteUser ( final Node user ) { Node userReplica , following ; for ( Relationship replica : user . getRelationships ( SocialGraphRelationshipType . REPLICA , Direction . INCOMING ) ) { userReplica = replica . getEndNode ( ) ; following = NeoUtils . getPrevSingleNode ( userReplica , SocialGraphRelationshipType . FOLLOW ) ; this . removeFriendship ( following , user ) ; } } | delete a user removing it from all replica layers of following users |
11,968 | private int getInt ( XMLProperty p , int defaultValue ) { final String value = get ( p ) ; if ( value . isEmpty ( ) ) { return defaultValue ; } return Integer . parseInt ( value ) ; } | If the value exists it returns its value else the default value |
11,969 | public void start ( ) { this . workerThread = new Thread ( this ) ; System . out . println ( "starting worker thread" ) ; this . workerThread . start ( ) ; System . out . println ( "worker thread started" ) ; } | start the worker thread |
11,970 | private void sendRequest ( Object request , ContextualFuture future ) { if ( open && connection . open ) { long requestId = ++ this . requestId ; futures . put ( requestId , future ) ; connection . handleRequest ( requestId , request ) ; } else { future . context . executor ( ) . execute ( ( ) -> future . completeExceptionally ( new ConnectException ( "connection closed" ) ) ) ; } if ( request instanceof ReferenceCounted ) { ( ( ReferenceCounted < ? > ) request ) . release ( ) ; } } | Sends a request . |
11,971 | private void handleResponseError ( long requestId , Throwable error ) { ContextualFuture future = futures . remove ( requestId ) ; if ( future != null ) { future . context . execute ( ( ) -> future . completeExceptionally ( error ) ) ; } } | Handles a response error . |
11,972 | @ SuppressWarnings ( "unchecked" ) private void handleRequest ( long requestId , Object request ) { HandlerHolder holder = handlers . get ( request . getClass ( ) ) ; if ( holder == null ) { connection . handleResponseError ( requestId , new ConnectException ( "no handler registered" ) ) ; return ; } Function < Object , CompletableFuture < Object > > handler = ( Function < Object , CompletableFuture < Object > > ) holder . handler ; try { holder . context . executor ( ) . execute ( ( ) -> { if ( open && connection . open ) { CompletableFuture < Object > responseFuture = handler . apply ( request ) ; if ( responseFuture != null ) { responseFuture . whenComplete ( ( response , error ) -> { if ( ! open || ! connection . open ) { connection . handleResponseError ( requestId , new ConnectException ( "connection closed" ) ) ; } else if ( error == null ) { connection . handleResponseOk ( requestId , response ) ; } else { connection . handleResponseError ( requestId , error ) ; } } ) ; } } else { connection . handleResponseError ( requestId , new ConnectException ( "connection closed" ) ) ; } } ) ; } catch ( RejectedExecutionException e ) { connection . handleResponseError ( requestId , new ConnectException ( "connection closed" ) ) ; } } | Receives a message . |
11,973 | private static Map < String , String > loadDatabaseConfig ( final Configuration config ) { final Map < String , String > databaseConfig = new HashMap < String , String > ( ) ; databaseConfig . put ( "cache_type" , config . getCacheType ( ) ) ; databaseConfig . put ( "use_memory_mapped_buffers" , config . getUseMemoryMappedBuffers ( ) ) ; return databaseConfig ; } | load the database configuration map for neo4j databases |
11,974 | private static void loadLuceneIndices ( final AbstractGraphDatabase graphDatabase ) { INDEX_STATUS_UPDATE_TEMPLATES = graphDatabase . index ( ) . forNodes ( "tmpl" ) ; INDEX_USERS = graphDatabase . index ( ) . forNodes ( "user" ) ; INDEX_STATUS_UPDATES = graphDatabase . index ( ) . forNodes ( "stup" ) ; } | load the lucene indices for a database |
11,975 | public static AbstractGraphDatabase getSocialGraphDatabase ( final Configuration config ) { final Map < String , String > graphConfig = loadDatabaseConfig ( config ) ; AbstractGraphDatabase database ; if ( config . getReadOnly ( ) ) { database = new EmbeddedReadOnlyGraphDatabase ( config . getDatabasePath ( ) , graphConfig ) ; } else { database = new EmbeddedGraphDatabase ( config . getDatabasePath ( ) , graphConfig ) ; } DATABASE = database ; loadLuceneIndices ( database ) ; return database ; } | open the neo4j graph database |
11,976 | public static boolean deleteFile ( final File file ) { if ( file . isDirectory ( ) ) { final File [ ] children = file . listFiles ( ) ; for ( File child : children ) { if ( ! deleteFile ( child ) ) { return false ; } } } return file . delete ( ) ; } | delete file or directory |
11,977 | public static Node getPrevSingleNode ( final Node user , RelationshipType relationshipType ) { final Relationship rel = user . getSingleRelationship ( relationshipType , Direction . INCOMING ) ; return ( rel == null ) ? ( null ) : ( rel . getStartNode ( ) ) ; } | find an incoming relation from the user passed of the specified type |
11,978 | public static Node getNextSingleNode ( final Node user , RelationshipType relationshipType ) { Relationship rel = null ; try { rel = user . getSingleRelationship ( relationshipType , Direction . OUTGOING ) ; } catch ( final NonWritableChannelException e ) { } return ( rel == null ) ? ( null ) : ( rel . getEndNode ( ) ) ; } | find an outgoing relation from the user passed of the specified type |
11,979 | public static Relationship getRelationshipBetween ( final Node source , final Node target , final RelationshipType relationshipType , final Direction direction ) { for ( Relationship relationship : source . getRelationships ( relationshipType , direction ) ) { if ( relationship . getEndNode ( ) . equals ( target ) ) { return relationship ; } } return null ; } | Search for a relationship between two nodes |
11,980 | public static Node createUserNode ( final String userId ) { if ( INDEX_USERS . get ( IDENTIFIER , userId ) . getSingle ( ) == null ) { final Node user = DATABASE . createNode ( ) ; user . setProperty ( Properties . User . IDENTIFIER , userId ) ; INDEX_USERS . add ( user , IDENTIFIER , userId ) ; return user ; } throw new IllegalArgumentException ( "user node with identifier \"" + userId + "\" already existing!" ) ; } | create a user node in the active database |
11,981 | public static Node createStatusUpdateNode ( final String statusUpdateId ) { if ( INDEX_STATUS_UPDATES . get ( IDENTIFIER , statusUpdateId ) . getSingle ( ) == null ) { final Node statusUpdate = DATABASE . createNode ( ) ; statusUpdate . setProperty ( Properties . StatusUpdate . IDENTIFIER , statusUpdateId ) ; INDEX_STATUS_UPDATES . add ( statusUpdate , IDENTIFIER , statusUpdateId ) ; return statusUpdate ; } throw new IllegalArgumentException ( "status update node with identifier \"" + statusUpdateId + "\" already existing!" ) ; } | create a status update node in the active database |
11,982 | public static void storeStatusUpdateTemplateNode ( final AbstractGraphDatabase graphDatabase , final String templateId , final Node templateNode , final Node previousTemplateNode ) { if ( previousTemplateNode != null ) { INDEX_STATUS_UPDATE_TEMPLATES . remove ( previousTemplateNode , IDENTIFIER , templateId ) ; } INDEX_STATUS_UPDATE_TEMPLATES . add ( templateNode , IDENTIFIER , templateId ) ; } | store a status update template node in the index replacing previous occurrences |
11,983 | public void start ( ) { this . commandWorker . start ( ) ; while ( ! this . commandWorker . isRunning ( ) ) { System . out . println ( "waiting for worker to connect..." ) ; try { Thread . sleep ( 50 ) ; } catch ( final InterruptedException e ) { System . out . println ( "server thread could not wait for worker" ) ; e . printStackTrace ( ) ; } } } | start the server and wait for it to be running |
11,984 | private void handleRequestFailure ( long requestId , Throwable error , ThreadContext context ) { ByteBuf buffer = channel . alloc ( ) . buffer ( 10 ) . writeByte ( RESPONSE ) . writeLong ( requestId ) . writeByte ( FAILURE ) ; try { writeError ( buffer , error , context ) ; } catch ( SerializationException e ) { return ; } channel . writeAndFlush ( buffer , channel . voidPromise ( ) ) ; } | Handles a request failure . |
11,985 | void handleResponse ( ByteBuf response ) { long requestId = response . readLong ( ) ; byte status = response . readByte ( ) ; switch ( status ) { case SUCCESS : try { handleResponseSuccess ( requestId , readResponse ( response ) ) ; } catch ( SerializationException e ) { handleResponseFailure ( requestId , e ) ; } break ; case FAILURE : try { handleResponseFailure ( requestId , readError ( response ) ) ; } catch ( SerializationException e ) { handleResponseFailure ( requestId , e ) ; } break ; } response . release ( ) ; } | Handles response . |
11,986 | @ SuppressWarnings ( "unchecked" ) private void handleResponseSuccess ( long requestId , Object response ) { ContextualFuture future = responseFutures . remove ( requestId ) ; if ( future != null ) { future . context . executor ( ) . execute ( ( ) -> future . complete ( response ) ) ; } } | Handles a successful response . |
11,987 | private void handleResponseFailure ( long requestId , Throwable t ) { ContextualFuture future = responseFutures . remove ( requestId ) ; if ( future != null ) { future . context . executor ( ) . execute ( ( ) -> future . completeExceptionally ( t ) ) ; } } | Handles a failure response . |
11,988 | private ByteBuf writeRequest ( ByteBuf buffer , Object request , ThreadContext context ) { context . serializer ( ) . writeObject ( request , OUTPUT . get ( ) . setByteBuf ( buffer ) ) ; if ( request instanceof ReferenceCounted ) { ( ( ReferenceCounted ) request ) . release ( ) ; } return buffer ; } | Writes a request to the given buffer . |
11,989 | private ByteBuf writeResponse ( ByteBuf buffer , Object request , ThreadContext context ) { context . serializer ( ) . writeObject ( request , OUTPUT . get ( ) . setByteBuf ( buffer ) ) ; return buffer ; } | Writes a response to the given buffer . |
11,990 | private ByteBuf writeError ( ByteBuf buffer , Throwable t , ThreadContext context ) { context . serializer ( ) . writeObject ( t , OUTPUT . get ( ) . setByteBuf ( buffer ) ) ; return buffer ; } | Writes an error to the given buffer . |
11,991 | private Object readRequest ( ByteBuf buffer ) { return context . serializer ( ) . readObject ( INPUT . get ( ) . setByteBuf ( buffer ) ) ; } | Reads a request from the given buffer . |
11,992 | private Throwable readError ( ByteBuf buffer ) { return context . serializer ( ) . readObject ( INPUT . get ( ) . setByteBuf ( buffer ) ) ; } | Reads an error from the given buffer . |
11,993 | void handleException ( Throwable t ) { if ( failure == null ) { failure = t ; for ( ContextualFuture < ? > responseFuture : responseFutures . values ( ) ) { responseFuture . context . executor ( ) . execute ( ( ) -> responseFuture . completeExceptionally ( t ) ) ; } responseFutures . clear ( ) ; for ( Listener < Throwable > listener : exceptionListeners ) { listener . accept ( t ) ; } } } | Handles an exception . |
11,994 | void handleClosed ( ) { if ( ! closed ) { closed = true ; for ( ContextualFuture < ? > responseFuture : responseFutures . values ( ) ) { responseFuture . context . executor ( ) . execute ( ( ) -> responseFuture . completeExceptionally ( new ConnectException ( "connection closed" ) ) ) ; } responseFutures . clear ( ) ; for ( Listener < Connection > listener : closeListeners ) { listener . accept ( this ) ; } timeout . cancel ( ) ; } } | Handles the channel being closed . |
11,995 | void timeout ( ) { long time = System . currentTimeMillis ( ) ; Iterator < Map . Entry < Long , ContextualFuture > > iterator = responseFutures . entrySet ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { ContextualFuture future = iterator . next ( ) . getValue ( ) ; if ( future . time + requestTimeout < time ) { iterator . remove ( ) ; future . context . executor ( ) . execute ( ( ) -> future . completeExceptionally ( new TimeoutException ( "request timed out" ) ) ) ; } else { break ; } } } | Times out requests . |
11,996 | protected static org . neo4j . graphdb . Node createTemplateItemNode ( final AbstractGraphDatabase graphDatabase , final TemplateItemInfo itemInfo ) { final org . neo4j . graphdb . Node itemNode = graphDatabase . createNode ( ) ; itemNode . setProperty ( TemplateXMLFields . ITEM_NAME , itemInfo . getName ( ) ) ; return itemNode ; } | create a database node representing a template item information |
11,997 | public static CreateUserRequest checkRequest ( final FormItemList formItemList , final CreateRequest createRequest , final CreateUserResponse createUserResponse ) { final String userId = checkUserIdentifier ( formItemList , createUserResponse ) ; if ( userId != null ) { final String displayName = checkDisplayName ( formItemList , createUserResponse ) ; if ( displayName != null ) { final String profilePicturePath = checkProfilePicturePath ( formItemList , createUserResponse ) ; return new CreateUserRequest ( createRequest . getType ( ) , userId , displayName , profilePicturePath ) ; } } return null ; } | check a create user request for validity concerning NSSP |
11,998 | private static String checkDisplayName ( final FormItemList formItemList , final CreateUserResponse createUserResponse ) { final String displayName = formItemList . getField ( ProtocolConstants . Parameters . Create . User . DISPLAY_NAME ) ; if ( displayName != null ) { return displayName ; } else { createUserResponse . displayNameMissing ( ) ; } return null ; } | check if the request contains a display name |
11,999 | private static String checkProfilePicturePath ( final FormItemList formItemList , final CreateUserResponse createUserResponse ) { final String profilePicturePath = formItemList . getField ( ProtocolConstants . Parameters . Create . User . PROFILE_PICTURE_PATH ) ; if ( profilePicturePath != null ) { return profilePicturePath ; } else { createUserResponse . profilePicturePathMissing ( ) ; } return null ; } | check if the request contains a profile picture path |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.