idx int64 0 41.2k | question stringlengths 74 4.21k | target stringlengths 5 888 |
|---|---|---|
17,900 | public void updateServiceInstance ( ProvidedServiceInstance instance ) { ProtocolHeader header = new ProtocolHeader ( ) ; header . setType ( ProtocolType . UpdateServiceInstance ) ; UpdateServiceInstanceProtocol p = new UpdateServiceInstanceProtocol ( instance ) ; connection . submitRequest ( header , p , null ) ; } | Update the ServiceInstance . |
17,901 | public void updateServiceInstance ( ProvidedServiceInstance instance , final RegistrationCallback cb , Object context ) { ProtocolHeader header = new ProtocolHeader ( ) ; header . setType ( ProtocolType . UpdateServiceInstance ) ; UpdateServiceInstanceProtocol p = new UpdateServiceInstanceProtocol ( instance ) ; ProtocolCallback pcb = new ProtocolCallback ( ) { public void call ( boolean result , Response response , ErrorCode error , Object ctx ) { cb . call ( result , error , ctx ) ; } } ; connection . submitCallbackRequest ( header , p , pcb , context ) ; } | Update the ServiceInstance with callback . |
17,902 | public void updateServiceInstanceUri ( String serviceName , String instanceId , String uri ) { ProtocolHeader header = new ProtocolHeader ( ) ; header . setType ( ProtocolType . UpdateServiceInstanceUri ) ; UpdateServiceInstanceUriProtocol p = new UpdateServiceInstanceUriProtocol ( serviceName , instanceId , uri ) ; connection . submitRequest ( header , p , null ) ; } | Update ServiceInstance URI . |
17,903 | public void updateServiceInstanceUri ( String serviceName , String instanceId , String uri , final RegistrationCallback cb , Object context ) { ProtocolHeader header = new ProtocolHeader ( ) ; header . setType ( ProtocolType . UpdateServiceInstanceUri ) ; UpdateServiceInstanceUriProtocol p = new UpdateServiceInstanceUriProtocol ( serviceName , instanceId , uri ) ; ProtocolCallback pcb = new ProtocolCallback ( ) { public void call ( boolean result , Response response , ErrorCode error , Object ctx ) { cb . call ( result , error , ctx ) ; } } ; connection . submitCallbackRequest ( header , p , pcb , context ) ; } | Update ServiceInstance URI in Callback . |
17,904 | public void unregisterServiceInstance ( String serviceName , String instanceId ) { ProtocolHeader header = new ProtocolHeader ( ) ; header . setType ( ProtocolType . UnregisterServiceInstance ) ; UnregisterServiceInstanceProtocol p = new UnregisterServiceInstanceProtocol ( serviceName , instanceId ) ; connection . submitRequest ( header , p , null ) ; } | Unregister the ServiceInstance . |
17,905 | public void unregisterServiceInstance ( String serviceName , String instanceId , final RegistrationCallback cb , Object context ) { ProtocolHeader header = new ProtocolHeader ( ) ; header . setType ( ProtocolType . UnregisterServiceInstance ) ; UnregisterServiceInstanceProtocol p = new UnregisterServiceInstanceProtocol ( serviceName , instanceId ) ; ProtocolCallback pcb = new ProtocolCallback ( ) { public void call ( boolean result , Response response , ErrorCode error , Object ctx ) { cb . call ( result , error , ctx ) ; } } ; connection . submitCallbackRequest ( header , p , pcb , context ) ; } | Unregister the ServiceInstance in Callback . |
17,906 | public ModelService getService ( String serviceName , Watcher watcher ) { WatcherRegistration wcb = null ; if ( watcher != null ) { wcb = new WatcherRegistration ( serviceName , watcher ) ; } ProtocolHeader header = new ProtocolHeader ( ) ; header . setType ( ProtocolType . GetService ) ; GetServiceProtocol p = new GetServiceProtocol ( serviceName ) ; p . setWatcher ( watcher != null ) ; GetServiceResponse resp ; resp = ( GetServiceResponse ) connection . submitRequest ( header , p , wcb ) ; return resp . getService ( ) ; } | Get the Service . |
17,907 | public void getService ( String serviceName , final GetServiceCallback cb , Object context ) { ProtocolHeader header = new ProtocolHeader ( ) ; header . setType ( ProtocolType . GetService ) ; GetServiceProtocol p = new GetServiceProtocol ( serviceName ) ; p . setWatcher ( false ) ; ProtocolCallback pcb = new ProtocolCallback ( ) { public void call ( boolean result , Response response , ErrorCode error , Object ctx ) { ModelService rsp = null ; if ( response != null ) { rsp = ( ( GetServiceResponse ) response ) . getService ( ) ; } cb . call ( result , rsp , error , ctx ) ; } } ; connection . submitCallbackRequest ( header , p , pcb , context ) ; } | Get Service in Callback . |
17,908 | public ServiceDirectoryFuture asyncGetService ( String serviceName , Watcher watcher ) { WatcherRegistration wcb = null ; if ( watcher != null ) { wcb = new WatcherRegistration ( serviceName , watcher ) ; } ProtocolHeader header = new ProtocolHeader ( ) ; header . setType ( ProtocolType . GetService ) ; GetServiceProtocol p = new GetServiceProtocol ( serviceName ) ; p . setWatcher ( false ) ; return connection . submitAsyncRequest ( header , p , wcb ) ; } | Asynchronized get Service . |
17,909 | public List < ModelServiceInstance > getAllInstances ( ) { ProtocolHeader header = new ProtocolHeader ( ) ; header . setType ( ProtocolType . GetAllServices ) ; GetAllServicesResponse resp = ( GetAllServicesResponse ) connection . submitRequest ( header , null , null ) ; return resp . getInstances ( ) ; } | Get All ModelServiceInstance in the ServiceDirectory . |
17,910 | public List < ModelServiceInstance > queryService ( List < StringCommand > commands ) { ProtocolHeader header = new ProtocolHeader ( ) ; header . setType ( ProtocolType . QueryService ) ; List < QueryCommand > cs = new ArrayList < QueryCommand > ( ) ; for ( StringCommand c : commands ) { cs . add ( c . getStringCommand ( ) ) ; } QueryServiceProtocol p = new QueryServiceProtocol ( cs ) ; QueryServiceResponse resp ; resp = ( QueryServiceResponse ) connection . submitRequest ( header , p , null ) ; return resp . getInstances ( ) ; } | Query Service . |
17,911 | public void queryService ( List < StringCommand > commands , final QueryServiceCallback cb , Object context ) { ProtocolHeader header = new ProtocolHeader ( ) ; header . setType ( ProtocolType . QueryService ) ; List < QueryCommand > cs = new ArrayList < QueryCommand > ( ) ; for ( StringCommand c : commands ) { cs . add ( c . getStringCommand ( ) ) ; } QueryServiceProtocol p = new QueryServiceProtocol ( cs ) ; ProtocolCallback pcb = new ProtocolCallback ( ) { public void call ( boolean result , Response response , ErrorCode error , Object ctx ) { List < ModelServiceInstance > rsp = null ; if ( response != null ) { rsp = ( ( QueryServiceResponse ) response ) . getInstances ( ) ; } cb . call ( result , rsp , error , ctx ) ; } } ; connection . submitCallbackRequest ( header , p , pcb , context ) ; } | Query service in Callback . |
17,912 | public ServiceDirectoryFuture asyncQueryService ( List < StringCommand > commands ) { ProtocolHeader header = new ProtocolHeader ( ) ; header . setType ( ProtocolType . QueryService ) ; List < QueryCommand > cs = new ArrayList < QueryCommand > ( ) ; for ( StringCommand c : commands ) { cs . add ( c . getStringCommand ( ) ) ; } QueryServiceProtocol p = new QueryServiceProtocol ( cs ) ; return connection . submitAsyncRequest ( header , p , null ) ; } | Asynchronized query service . |
17,913 | public void close ( ) { if ( connection != null ) { try { connection . close ( ) ; } catch ( IOException e ) { LOGGER . warn ( "Close the DirectoryConnection get exception - " + e . getMessage ( ) ) ; } connection = null ; } if ( watcherManager != null ) { watcherManager . cleanup ( ) ; watcherManager = null ; } } | Close the DirectoryServiceClient . |
17,914 | private DirectorySocket getDirectorySocket ( ) { DirectorySocket socket = null ; if ( ServiceDirectory . getServiceDirectoryConfig ( ) . containsProperty ( SD_API_DIRECTORY_SOCKET_PROVIDER_PROPERTY ) ) { String provider = ServiceDirectory . getServiceDirectoryConfig ( ) . getString ( SD_API_DIRECTORY_SOCKET_PROVIDER_PROPERTY ) ; try { Class < ? > provideClass = Class . forName ( provider ) ; if ( DirectorySocket . class . isAssignableFrom ( provideClass ) ) { socket = ( DirectorySocket ) provideClass . newInstance ( ) ; } } catch ( Exception e ) { LOGGER . warn ( "fail to initialize the DirectorySocket provider - " + provider , e ) ; } } if ( socket == null ) { return new WSDirectorySocket ( ) ; } else { return socket ; } } | Get the DirectorySoeckt . |
17,915 | public synchronized void addPropertyChangeListener ( String propertyName , PropertyChangeListener listener ) { if ( ! ArrayUtils . contains ( listener , getPropertyChangeListeners ( propertyName ) ) ) { super . addPropertyChangeListener ( propertyName , listener ) ; } } | add listener if not already added to property |
17,916 | public SerialArrayList < U > add ( SerialArrayList < U > right ) { return new SerialArrayList < U > ( factory , this , right ) ; } | Add serial array list . |
17,917 | public U get ( int i ) { ByteBuffer view = getView ( i ) ; try { return factory . read ( view ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } | Get u . |
17,918 | public synchronized U update ( int i , Function < U , U > updater ) { U updated = updater . apply ( this . get ( i ) ) ; set ( i , updated ) ; return updated ; } | Update u . |
17,919 | public synchronized int addAll ( Collection < U > data ) { int startIndex = length ( ) ; putAll ( data , startIndex ) ; return startIndex ; } | Add all int . |
17,920 | protected JsTreeNodeData populateTreeNodeData ( FileObject root , FileObject file ) throws FileSystemException { boolean noChild = true ; FileType type = file . getType ( ) ; if ( type . equals ( FileType . FOLDER ) || type . equals ( FileType . FILE_OR_FOLDER ) ) { noChild = file . getChildren ( ) . length == 0 ; } String relativePath = root . getName ( ) . getRelativeName ( file . getName ( ) ) ; return populateTreeNodeData ( file , noChild , relativePath ) ; } | Populate a node . |
17,921 | protected JsTreeNodeData populateTreeNodeData ( FileObject file , boolean noChild , String relativePath ) throws FileSystemException { JsTreeNodeData node = new JsTreeNodeData ( ) ; String baseName = file . getName ( ) . getBaseName ( ) ; FileContent content = file . getContent ( ) ; FileType type = file . getType ( ) ; node . setData ( baseName ) ; Map < String , Object > attr = new HashMap < String , Object > ( ) ; node . setAttr ( attr ) ; attr . put ( "id" , relativePath ) ; attr . put ( "rel" , type . getName ( ) ) ; attr . put ( "fileType" , type . getName ( ) ) ; if ( content != null ) { long fileLastModifiedTime = file . getContent ( ) . getLastModifiedTime ( ) ; attr . put ( "fileLastModifiedTime" , fileLastModifiedTime ) ; attr . put ( "fileLastModifiedTimeForDisplay" , DateFormat . getDateTimeInstance ( ) . format ( new Date ( fileLastModifiedTime ) ) ) ; if ( file . getType ( ) != FileType . FOLDER ) { attr . put ( "fileSize" , content . getSize ( ) ) ; attr . put ( "fileSizeForDisplay" , FileUtils . byteCountToDisplaySize ( content . getSize ( ) ) ) ; } } if ( ! noChild ) { node . setState ( JsTreeNodeData . STATE_CLOSED ) ; } return node ; } | It transforms FileObject into JsTreeNodeData . |
17,922 | public CompositeExceptionHandler buildHandlersFor ( XmlRules rules ) { ImmutableList . Builder < RuleExceptionHandler > builder = ImmutableList . builder ( ) ; for ( XmlRules . ExceptionRule rule : rules . getExceptionRules ( ) ) { builder . add ( buildHandlerFor ( rule ) ) ; } return new CompositeExceptionHandler ( builder . build ( ) ) ; } | translate the xml rules in to specific predicates to return RuleExceHandler |
17,923 | public TreeMap < Bits , Long > computeSums ( ) { final TreeMap < Bits , Long > sums = new TreeMap < Bits , Long > ( ) ; long total = 0 ; for ( final Entry < Bits , AtomicInteger > e : this . map . entrySet ( ) ) { sums . put ( e . getKey ( ) , total += e . getValue ( ) . get ( ) ) ; } return sums ; } | Compute sums tree run . |
17,924 | protected BranchCounts readBranchCounts ( final BitInputStream in , final Bits code , final long size ) throws IOException { final BranchCounts branchCounts = new BranchCounts ( code , size ) ; final CodeType currentCodeType = this . getType ( code ) ; long maximum = size ; if ( currentCodeType == CodeType . Unknown ) { branchCounts . terminals = this . readTerminalCount ( in , maximum ) ; } else if ( currentCodeType == CodeType . Terminal ) { branchCounts . terminals = size ; } else { branchCounts . terminals = 0 ; } maximum -= branchCounts . terminals ; if ( maximum > 0 ) { assert Thread . currentThread ( ) . getStackTrace ( ) . length < 100 ; branchCounts . zeroCount = this . readZeroBranchSize ( in , maximum , code ) ; } maximum -= branchCounts . zeroCount ; branchCounts . oneCount = maximum ; return branchCounts ; } | Read branch counts branch counts . |
17,925 | protected long readTerminalCount ( final BitInputStream in , final long size ) throws IOException { if ( SERIALIZATION_CHECKS ) { in . expect ( SerializationChecks . BeforeTerminal ) ; } final long readBoundedLong = in . readBoundedLong ( 1 + size ) ; if ( SERIALIZATION_CHECKS ) { in . expect ( SerializationChecks . AfterTerminal ) ; } return readBoundedLong ; } | Read terminal count long . |
17,926 | protected long readZeroBranchSize ( final BitInputStream in , final long max , final Bits code ) throws IOException { if ( 0 == max ) { return 0 ; } final long value ; if ( SERIALIZATION_CHECKS ) { in . expect ( SerializationChecks . BeforeCount ) ; } if ( this . useBinomials ) { value = Gaussian . fromBinomial ( 0.5 , max ) . decode ( in , max ) ; } else { value = in . readBoundedLong ( 1 + max ) ; } if ( SERIALIZATION_CHECKS ) { in . expect ( SerializationChecks . AfterCount ) ; } return value ; } | Read zero branch size long . |
17,927 | public long sum ( final Collection < Long > values ) { long total = 0 ; for ( final Long v : values ) { total += v ; } return total ; } | Sum long . |
17,928 | protected void writeBranchCounts ( final BranchCounts branch , final BitOutputStream out ) throws IOException { final CodeType currentCodeType = this . getType ( branch . path ) ; long maximum = branch . size ; assert maximum >= branch . terminals ; if ( currentCodeType == CodeType . Unknown ) { this . writeTerminalCount ( out , branch . terminals , maximum ) ; } else if ( currentCodeType == CodeType . Terminal ) { assert branch . size == branch . terminals ; assert 0 == branch . zeroCount ; assert 0 == branch . oneCount ; } else assert currentCodeType != CodeType . Prefix || 0 == branch . terminals ; maximum -= branch . terminals ; assert maximum >= branch . zeroCount ; if ( 0 < maximum ) { this . writeZeroBranchSize ( out , branch . zeroCount , maximum , branch . path ) ; maximum -= branch . zeroCount ; } else { assert 0 == branch . zeroCount ; } assert maximum == branch . oneCount ; } | Write branch counts . |
17,929 | protected void writeTerminalCount ( final BitOutputStream out , final long value , final long max ) throws IOException { assert 0 <= value ; assert max >= value ; if ( SERIALIZATION_CHECKS ) { out . write ( SerializationChecks . BeforeTerminal ) ; } out . writeBoundedLong ( value , 1 + max ) ; if ( SERIALIZATION_CHECKS ) { out . write ( SerializationChecks . AfterTerminal ) ; } } | Write terminal count . |
17,930 | protected void writeZeroBranchSize ( final BitOutputStream out , final long value , final long max , final Bits bits ) throws IOException { assert 0 <= value ; assert max >= value ; if ( SERIALIZATION_CHECKS ) { out . write ( SerializationChecks . BeforeCount ) ; } if ( this . useBinomials ) { Gaussian . fromBinomial ( 0.5 , max ) . encode ( out , value , max ) ; } else { out . writeBoundedLong ( value , 1 + max ) ; } if ( SERIALIZATION_CHECKS ) { out . write ( SerializationChecks . AfterCount ) ; } } | Write zero branch size . |
17,931 | public static CharTrie indexWords ( Collection < String > documents , int maxLevels , int minWeight ) { return create ( documents , maxLevels , minWeight , true ) ; } | Index words char trie . |
17,932 | public static CharTrie indexFulltext ( Collection < String > documents , int maxLevels , int minWeight ) { return create ( documents , maxLevels , minWeight , false ) ; } | Index fulltext char trie . |
17,933 | public CharTrieIndex index ( int maxLevels , int minWeight ) { AtomicInteger numberSplit = new AtomicInteger ( 0 ) ; int depth = - 1 ; do { numberSplit . set ( 0 ) ; if ( 0 == ++ depth ) { numberSplit . incrementAndGet ( ) ; root ( ) . split ( ) ; } else { root ( ) . streamDecendents ( depth ) . forEach ( node -> { TrieNode godparent = node . godparent ( ) ; if ( node . getDepth ( ) < maxLevels ) { if ( null == godparent || godparent . getCursorCount ( ) > minWeight ) { if ( node . getChar ( ) != NodewalkerCodec . END_OF_STRING || node . getDepth ( ) == 0 ) { ( ( IndexNode ) node ) . split ( ) ; numberSplit . incrementAndGet ( ) ; } } } } ) ; } } while ( numberSplit . get ( ) > 0 ) ; return this ; } | Creates the index tree using the accumulated documents |
17,934 | public int addDocument ( String document ) { if ( root ( ) . getNumberOfChildren ( ) >= 0 ) { throw new IllegalStateException ( "Tree sorting has begun" ) ; } final int index ; synchronized ( this ) { index = documents . size ( ) ; documents . add ( document ) ; } cursors . addAll ( IntStream . range ( 0 , document . length ( ) + 1 ) . mapToObj ( i -> new CursorData ( index , i ) ) . collect ( Collectors . toList ( ) ) ) ; nodes . update ( 0 , node -> node . setCursorCount ( cursors . length ( ) ) ) ; return index ; } | Adds a document to be indexed . This can only be performed before splitting . |
17,935 | public CharTrie addAlphabet ( String document ) { document . chars ( ) . mapToObj ( i -> new String ( Character . toChars ( i ) ) ) . forEach ( s -> addDocument ( s ) ) ; return this ; } | Add alphabet char trie . |
17,936 | public void reinitServiceDirectoryManagerFactory ( ServiceDirectoryManagerFactory factory ) throws ServiceException { if ( factory == null ) { throw new ServiceException ( ErrorCode . SERVICE_DIRECTORY_NULL_ARGUMENT_ERROR , ErrorCode . SERVICE_DIRECTORY_NULL_ARGUMENT_ERROR . getMessageTemplate ( ) , "ServiceDirectoryManagerFactory" ) ; } synchronized ( this ) { if ( isShutdown ) { throw new ServiceException ( ErrorCode . SERVICE_DIRECTORY_IS_SHUTDOWN ) ; } if ( this . directoryManagerFactory != null ) { directoryManagerFactory . stop ( ) ; LOGGER . info ( "Resetting ServiceDirectoryManagerFactory, old={}, new={}." , this . directoryManagerFactory . getClass ( ) . getName ( ) , factory . getClass ( ) . getName ( ) ) ; this . directoryManagerFactory = factory ; } else { this . directoryManagerFactory = factory ; LOGGER . info ( "Setting ServiceDirectoryManagerFactory, factory={}." , factory . getClass ( ) . getName ( ) ) ; } directoryManagerFactory . start ( ) ; } } | Set the ServiceDirectoryManagerFactory . |
17,937 | public Object get ( String key ) { if ( key == null ) return null ; else if ( key . indexOf ( '.' ) > 0 ) return RecursiveObjectReader . getProperty ( this , key ) ; else return super . get ( key ) ; } | Gets a map element specified by its key . |
17,938 | public Object put ( String key , Object value ) { if ( key == null ) return null ; else if ( key . indexOf ( '.' ) > 0 ) RecursiveObjectWriter . setProperty ( this , key , value ) ; else super . put ( key , value ) ; return value ; } | Puts a new value into map element specified by its key . |
17,939 | public Parameters getAsNullableParameters ( String key ) { AnyValueMap value = getAsNullableMap ( key ) ; return value != null ? new Parameters ( value ) : null ; } | Converts map element into an Parameters or returns null if conversion is not possible . |
17,940 | public Parameters getAsParameters ( String key ) { AnyValueMap value = getAsMap ( key ) ; return new Parameters ( value ) ; } | Converts map element into an Parameters or returns empty Parameters if conversion is not possible . |
17,941 | public Parameters getAsParametersWithDefault ( String key , Parameters defaultValue ) { Parameters result = getAsNullableParameters ( key ) ; return result != null ? result : defaultValue ; } | Converts map element into an Parameters or returns default value if conversion is not possible . |
17,942 | public Parameters override ( Parameters parameters , boolean recursive ) { Parameters result = new Parameters ( ) ; if ( recursive ) { RecursiveObjectWriter . copyProperties ( result , this ) ; RecursiveObjectWriter . copyProperties ( result , parameters ) ; } else { ObjectWriter . setProperties ( result , this ) ; ObjectWriter . setProperties ( result , parameters ) ; } return result ; } | Overrides parameters with new values from specified Parameters and returns a new Parameters object . |
17,943 | public Parameters setDefaults ( Parameters defaultParameters , boolean recursive ) { Parameters result = new Parameters ( ) ; if ( recursive ) { RecursiveObjectWriter . copyProperties ( result , defaultParameters ) ; RecursiveObjectWriter . copyProperties ( result , this ) ; } else { ObjectWriter . setProperties ( result , defaultParameters ) ; ObjectWriter . setProperties ( result , this ) ; } return result ; } | Set default values from specified Parameters and returns a new Parameters object . |
17,944 | public Parameters pick ( String ... paths ) { Parameters result = new Parameters ( ) ; for ( String path : paths ) { if ( containsKey ( path ) ) result . put ( path , get ( path ) ) ; } return result ; } | Picks select parameters from this Parameters and returns them as a new Parameters object . |
17,945 | public Parameters omit ( String ... paths ) { Parameters result = new Parameters ( this ) ; for ( String path : paths ) result . remove ( path ) ; return result ; } | Omits selected parameters from this Parameters and returns the rest as a new Parameters object . |
17,946 | public static Parameters fromTuples ( Object ... tuples ) { AnyValueMap map = AnyValueMap . fromTuplesArray ( tuples ) ; return new Parameters ( map ) ; } | Creates a new Parameters object filled with provided key - value pairs called tuples . Tuples parameters contain a sequence of key1 value1 key2 value2 ... pairs . |
17,947 | public static Parameters mergeParams ( Parameters ... parameters ) { AnyValueMap map = AnyValueMap . fromMaps ( parameters ) ; return new Parameters ( map ) ; } | Merges two or more Parameters into one . The following Parameters override previously defined parameters . |
17,948 | public static Parameters fromJson ( String json ) { Map < String , Object > map = JsonConverter . toNullableMap ( json ) ; return map != null ? new Parameters ( map ) : new Parameters ( ) ; } | Creates new Parameters from JSON object . |
17,949 | public static Parameters fromConfig ( ConfigParams config ) { Parameters result = new Parameters ( ) ; if ( config == null || config . size ( ) == 0 ) return result ; for ( Map . Entry < String , String > entry : config . entrySet ( ) ) { result . put ( entry . getKey ( ) , entry . getValue ( ) ) ; } return result ; } | Creates new Parameters from ConfigMap object . |
17,950 | protected List < ConfigSource > sortDescending ( List < ConfigSource > configSources ) { Collections . sort ( configSources , new Comparator < ConfigSource > ( ) { public int compare ( ConfigSource configSource1 , ConfigSource configSource2 ) { int ordinal1 = getOrdinal ( configSource1 ) ; int ordinal2 = getOrdinal ( configSource2 ) ; if ( ordinal1 == ordinal2 ) { return configSource1 . getName ( ) . compareTo ( configSource2 . getName ( ) ) ; } return ( ordinal1 > ordinal2 ) ? - 1 : 1 ; } private int getOrdinal ( ConfigSource configSource ) { int result = 100 ; try { result = configSource . getOrdinal ( ) ; } catch ( AbstractMethodError e ) { } return result ; } } ) ; return configSources ; } | ConfigSources are sorted with descending ordinal . If 2 ConfigSources have the same ordinal then they get sorted according to their name alphabetically . |
17,951 | public void startDefinition ( ) { sequencer = new Sequencer ( ) ; states = Maps . synchronizedBiMap ( HashBiMap . < S , Integer > create ( ) ) ; transitions = new ConcurrentHashMap < DoubleValueBean < S , T > , Transition < S > > ( ) ; validTransitions = new PutIfAbsentMap < S , Set < T > > ( new HashMap < S , Set < T > > ( ) , new MapValueFactory < S , Set < T > > ( ) { public Set < T > createValue ( S key ) { return Collections . newSetFromMap ( new ConcurrentHashMap < T , Boolean > ( ) ) ; } } ) ; } | Initialize internal data structure for adding state and transitions later . |
17,952 | public void finishDefinition ( ) { sequencer = null ; states = ImmutableBiMap . copyOf ( states ) ; Map < S , Set < T > > validTransitionsCopied = new HashMap < S , Set < T > > ( ) ; for ( Map . Entry < S , Set < T > > entry : validTransitions . entrySet ( ) ) { validTransitionsCopied . put ( entry . getKey ( ) , ImmutableSet . copyOf ( entry . getValue ( ) ) ) ; } validTransitions = ImmutableMap . copyOf ( validTransitions ) ; } | Finalize internal data structure after all the states and transitions have been added . |
17,953 | public Integer getStateId ( S state ) { Integer id = states . get ( state ) ; if ( id == null ) { throw new IllegalArgumentException ( "State '" + state + "' has not been defined." ) ; } return id ; } | Get the internal integer ID of a state . |
17,954 | public Transition < S > getTransition ( S fromState , T transition ) { Transition < S > transitionDef = transitions . get ( new DoubleValueBean < S , T > ( fromState , transition ) ) ; if ( transitionDef == null ) { throw new IllegalArgumentException ( "Transition '" + transition + "' from state '" + fromState + "' has not been defined." ) ; } return transitionDef ; } | Get the transition definitions |
17,955 | public Set < T > getTransitions ( S state ) { getStateId ( state ) ; return validTransitions . get ( state ) ; } | Get all transitions valid for specified state |
17,956 | public Integer getFirstStateId ( ) { Set < Integer > ids = states . inverse ( ) . keySet ( ) ; if ( ids . size ( ) < 1 ) { throw new IllegalStateException ( "There is no state defined." ) ; } Integer [ ] idsArray = new Integer [ ids . size ( ) ] ; Arrays . sort ( ids . toArray ( idsArray ) ) ; return idsArray [ 0 ] ; } | Get the ID of the state that has been defined first . |
17,957 | static public FileSystemManager getManager ( ) { StandardFileSystemManager fsManager = new StandardFileSystemManager ( ) ; try { fsManager . init ( ) ; } catch ( FileSystemException e ) { log . error ( "Cannot initialize StandardFileSystemManager." , e ) ; } return fsManager ; } | Get a new instance of FileSystemManager . |
17,958 | static public void close ( FileSystemManager fsManager ) { if ( fsManager != null ) { if ( fsManager instanceof DefaultFileSystemManager ) { ( ( DefaultFileSystemManager ) fsManager ) . close ( ) ; } else { throw new IllegalStateException ( "Only instance of DefaultFileSystemManager can be closed here." ) ; } } } | Close the FileSystemManager . |
17,959 | static public void close ( FileObject fo ) { if ( fo != null ) { try { fo . close ( ) ; } catch ( FileSystemException e ) { log . debug ( "Exception when closing FileObject: " + fo . getName ( ) , e ) ; } } } | Close the FileObject . |
17,960 | static public void configHttpFileSystemProxy ( FileSystemOptions fsOptions , String webProxyHost , Integer webProxyPort , String webProxyUserName , String webProxyPassword ) { if ( webProxyHost != null && webProxyPort != null ) { HttpFileSystemConfigBuilder . getInstance ( ) . setProxyHost ( fsOptions , webProxyHost ) ; HttpFileSystemConfigBuilder . getInstance ( ) . setProxyPort ( fsOptions , webProxyPort ) ; if ( webProxyUserName != null ) { StaticUserAuthenticator auth = new StaticUserAuthenticator ( webProxyUserName , webProxyPassword , null ) ; HttpFileSystemConfigBuilder . getInstance ( ) . setProxyAuthenticator ( fsOptions , auth ) ; } } } | Configure FileSystemOptions for HttpFileSystem |
17,961 | public static Response put ( String url , String body , Map < String , String > query , Map < String , String > headers , int connectTimeOut , int readTimeOut ) throws HttpException { return execute ( "PUT" , url , body , query , headers , connectTimeOut , readTimeOut ) ; } | Makes PUT request to given URL |
17,962 | void setMemo ( String production , int position , int line , final MemoEntry stackElement ) { Map < String , MemoEntry > map = memo . get ( position ) ; if ( map == null ) { map = new HashMap < String , MemoEntry > ( ) ; memo . put ( position , map ) ; map . put ( production , stackElement ) ; } else { if ( map . containsKey ( production ) ) { throw new RuntimeException ( "We should not set a memo twice. Modifying is needed afterwards." ) ; } map . put ( production , stackElement ) ; } } | This method puts memozation elements into the buffer . It is designed in a way that entries once set are not changed anymore . This is needed not to break references! |
17,963 | public void start ( ) { synchronized ( _lock ) { _timer . purge ( ) ; TimerTask task = new TimerTask ( ) { public void run ( ) { try { _task . notify ( "pip-commons-timer" , new Parameters ( ) ) ; } catch ( Exception ex ) { } } } ; _timer . scheduleAtFixedRate ( task , _delay , _interval ) ; _started = true ; } } | Starts the timer . |
17,964 | public Function < String , Map < String , Double > > categorizationTree ( Map < String , List < String > > categories , int depth ) { return categorizationTree ( categories , depth , "" ) ; } | Categorization tree function . |
17,965 | public void setAutoRemoved ( boolean autoRemove ) { if ( ! autoRemove ) { if ( getMetadata ( ) == null ) { setMetadata ( new HashMap < String , String > ( ) ) ; } getMetadata ( ) . put ( "autoRemoved" , "false" ) ; } } | set auto removed to false which will set a metadata to let the instance will not be removed automatically if max living time is exceeed on the server side . The default setting always true to allow auto - removing .. |
17,966 | public boolean getAutoRemoved ( ) { Map < String , String > meta = getMetadata ( ) ; if ( meta != null && meta . containsKey ( "autoRemoved" ) ) { return ! "false" . equals ( meta . get ( "autoRemoved" ) ) ; } return true ; } | get the autoRemoved property of the service instance . |
17,967 | private void drawSeparator ( Separator sep ) { final Color color = sep . isHorizontal ( ) ? Color . BLUE : Color . RED ; browser . getOutputDisplay ( ) . drawRectangle ( sep , color ) ; } | Draws a single separator in the browser . |
17,968 | private List < String > getHeaderValues ( String name ) { List < String > values = headers . get ( name ) ; if ( values == null ) { values = new ArrayList < String > ( ) ; headers . put ( name , values ) ; } return values ; } | Convenience method to get a header value list initialize it and put it in the headers map if it does not exist |
17,969 | public static com . simiacryptus . util . data . ScalarStatistics stats ( final double [ ] data ) { final com . simiacryptus . util . data . ScalarStatistics statistics = new PercentileStatistics ( ) ; Arrays . stream ( data ) . forEach ( statistics :: add ) ; return statistics ; } | Stats scalar statistics . |
17,970 | public final synchronized com . simiacryptus . util . data . ScalarStatistics add ( final com . simiacryptus . util . data . ScalarStatistics right ) { final com . simiacryptus . util . data . ScalarStatistics sum = new com . simiacryptus . util . data . ScalarStatistics ( ) ; sum . sum0 += sum0 ; sum . sum0 += right . sum0 ; sum . sum1 += sum1 ; sum . sum1 += right . sum1 ; sum . sum2 += sum2 ; sum . sum2 += right . sum2 ; return sum ; } | Add scalar statistics . |
17,971 | public double getStdDev ( ) { return Math . sqrt ( Math . abs ( Math . pow ( getMean ( ) , 2 ) - sum2 / sum0 ) ) ; } | Gets std dev . |
17,972 | public static void setProperty ( Object obj , String name , Object value ) { if ( obj == null || name == null ) return ; String [ ] names = name . split ( "\\." ) ; if ( names == null || names . length == 0 ) return ; performSetProperty ( obj , names , 0 , value ) ; } | Recursively sets value of object and its subobjects property specified by its name . |
17,973 | public static void copyProperties ( Object dest , Object src ) { if ( dest == null || src == null ) return ; Map < String , Object > values = RecursiveObjectReader . getProperties ( src ) ; setProperties ( dest , values ) ; } | Copies content of one object to another object by recursively reading all properties from source object and then recursively writing them to destination object . |
17,974 | protected void setSttyMode ( STTYMode mode ) throws IOException { String [ ] cmd ; if ( mode == STTYMode . COOKED ) { cmd = new String [ ] { "/bin/sh" , "-c" , "stty -raw echo </dev/tty" } ; } else { cmd = new String [ ] { "/bin/sh" , "-c" , "stty raw -echo </dev/tty" } ; } Process p = runtime . exec ( cmd ) ; try { p . waitFor ( ) ; } catch ( InterruptedException ie ) { throw new IOException ( ie . getMessage ( ) , ie ) ; } try ( InputStreamReader in = new InputStreamReader ( p . getErrorStream ( ) , UTF_8 ) ; BufferedReader reader = new BufferedReader ( in ) ) { String err = reader . readLine ( ) ; if ( err != null ) { throw new IOException ( err ) ; } } } | Set terminal mode . |
17,975 | public static long getTimestampMinusParameters ( long targetTimestamp , int numOfWeeks , int numOfDays , int numOfHours , int numOfMinutes , int numOfSeconds ) { long sumOfParameters = numOfWeeks * aWeek + numOfDays * aDay + numOfHours * anHour + numOfMinutes * aMinute + numOfSeconds * aSecond ; return targetTimestamp - sumOfParameters ; } | Gets timestamp minus parameters . |
17,976 | public static long getCurrentTimestampMinusParameters ( int numOfWeeks , int numOfDays , int numOfHours , int numOfMinutes , int numOfSeconds ) { return getTimestampMinusParameters ( System . currentTimeMillis ( ) , numOfWeeks , numOfDays , numOfHours , numOfMinutes , numOfSeconds ) ; } | Gets current timestamp minus parameters . |
17,977 | public long incrementAndGet ( V value ) { synchronized ( countMap ) { countMap . put ( value , getCount ( value ) + 1 ) ; return countMap . get ( value ) ; } } | Increment and get long . |
17,978 | public JMCountMap < V > merge ( JMCountMap < V > jmCountMap ) { synchronized ( countMap ) { jmCountMap . forEach ( ( value , count ) -> countMap . put ( value , getCount ( value ) + count ) ) ; return this ; } } | Merge jm count map . |
17,979 | protected void findAnnotations ( final String content , final List < FileAnnotation > warnings ) throws ParsingCanceledException { Matcher matcher = pattern . matcher ( content ) ; while ( matcher . find ( ) ) { Warning warning = createWarning ( matcher ) ; if ( warning != FALSE_POSITIVE ) { detectPackageName ( warning ) ; warnings . add ( warning ) ; } if ( Thread . interrupted ( ) ) { throw new ParsingCanceledException ( ) ; } } } | Parses the specified string content and creates annotations for each found warning . |
17,980 | private void detectPackageName ( final Warning warning ) { if ( ! warning . hasPackageName ( ) ) { warning . setPackageName ( PackageDetectors . detectPackageName ( warning . getFileName ( ) ) ) ; } } | Detects the package name for the specified warning . |
17,981 | public static char pickChar ( String values ) { if ( values == null || values . length ( ) == 0 ) return '\0' ; int index = RandomInteger . nextInteger ( values . length ( ) ) ; return values . charAt ( index ) ; } | Picks a random character from a string . |
17,982 | public static String pick ( String [ ] values ) { if ( values == null || values . length == 0 ) return "" ; int index = RandomInteger . nextInteger ( values . length ) ; return values [ index ] ; } | Picks a random string from an array of string . |
17,983 | public static String distort ( String value ) { value = value . toLowerCase ( ) ; if ( RandomBoolean . chance ( 1 , 5 ) ) value = value . substring ( 0 , 1 ) . toUpperCase ( ) + value . substring ( 1 ) ; if ( RandomBoolean . chance ( 1 , 3 ) ) value = value + pickChar ( _symbols ) ; return value ; } | Distorts a string by randomly replacing characters in it . |
17,984 | public JMProgressiveManager < T , R > start ( ) { info ( log , "start" ) ; this . completableFuture = JMThread . runAsync ( ( ) -> targetCollection . stream ( ) . filter ( negate ( isStopped ( ) ) ) . map ( this :: moveNextTarget ) . map ( t -> JMMap . putGetNew ( resultMap , t , process ( t ) ) ) . forEach ( lastResult :: set ) ) . thenRun ( this :: setStopped ) . thenRun ( ( ) -> Optional . ofNullable ( completedConsumerList ) . ifPresent ( list -> list . parallelStream ( ) . forEach ( c -> c . accept ( this ) ) ) ) ; return this ; } | Start jm progressive manager . |
17,985 | public JMProgressiveManager < T , R > getAfterCompletion ( ) { try { completableFuture . get ( ) ; } catch ( InterruptedException | ExecutionException e ) { handleException ( log , e , "stopSync" ) ; } return this ; } | Gets after completion . |
17,986 | public JMProgressiveManager < T , R > registerCompletedConsumer ( Consumer < JMProgressiveManager < T , R > > completedConsumer ) { Optional . ofNullable ( completedConsumerList ) . orElseGet ( ( ) -> completedConsumerList = new ArrayList < > ( ) ) . add ( completedConsumer ) ; return this ; } | Register completed consumer jm progressive manager . |
17,987 | public JMProgressiveManager < T , R > registerLastResultChangeListener ( Consumer < Optional < R > > resultChangeListener ) { return registerListener ( lastResult , resultChangeListener ) ; } | Register last result change listener jm progressive manager . |
17,988 | public JMProgressiveManager < T , R > registerLastFailureChangeListener ( Consumer < Pair < T , Exception > > failureChangeListener ) { return registerListener ( lastFailure , failureChangeListener ) ; } | Register last failure change listener jm progressive manager . |
17,989 | public JMProgressiveManager < T , R > registerCountChangeListener ( Consumer < Number > countChangeListener ) { return registerListener ( progressiveCount , countChangeListener ) ; } | Register count change listener jm progressive manager . |
17,990 | public JMProgressiveManager < T , R > registerPercentChangeListener ( Consumer < Number > percentChangeListener ) { return registerListener ( progressivePercent , percentChangeListener ) ; } | Register percent change listener jm progressive manager . |
17,991 | public JMProgressiveManager < T , R > registerTargetChangeListener ( Consumer < T > targetChangeListener ) { return registerListener ( currentTarget , targetChangeListener ) ; } | Register target change listener jm progressive manager . |
17,992 | public Result processPayment ( Payment payment ) throws PaytrailException { try { String data = marshaller . objectToString ( payment ) ; String url = serviceUrl + "/api-payment/create" ; IOHandlerResult requestResult = postJsonRequest ( url , data ) ; if ( requestResult . getCode ( ) != 201 ) { JsonError jsonError = marshaller . stringToObject ( JsonError . class , requestResult . getResponse ( ) ) ; throw new PaytrailException ( jsonError . getErrorMessage ( ) ) ; } return marshaller . stringToObject ( Result . class , requestResult . getResponse ( ) ) ; } catch ( IOException e ) { throw new PaytrailException ( e ) ; } } | Get url for payment |
17,993 | public boolean confirmPayment ( String orderNumber , String timestamp , String paid , String method , String authCode ) { String base = new StringBuilder ( ) . append ( orderNumber ) . append ( '|' ) . append ( timestamp ) . append ( '|' ) . append ( paid ) . append ( '|' ) . append ( method ) . append ( '|' ) . append ( merchantSecret ) . toString ( ) ; return StringUtils . equals ( StringUtils . upperCase ( DigestUtils . md5Hex ( base ) ) , authCode ) ; } | This function can be used to validate parameters returned by return and notify requests . Parameters must be validated in order to avoid hacking of payment confirmation . |
17,994 | public boolean confirmFailure ( String orderNumber , String timestamp , String authCode ) { String base = new StringBuilder ( ) . append ( orderNumber ) . append ( '|' ) . append ( timestamp ) . append ( '|' ) . append ( merchantSecret ) . toString ( ) ; return StringUtils . equals ( StringUtils . upperCase ( DigestUtils . md5Hex ( base ) ) , authCode ) ; } | This function can be used to validate parameters returned by failure request . Parameters must be validated in order to avoid hacking of payment failure . |
17,995 | public List < Object > getAsList ( String field , String separator ) { Object value = get ( field ) ; if ( value == null ) { return Collections . emptyList ( ) ; } else { if ( value instanceof List ) { return ( List ) value ; } else { return Arrays . < Object > asList ( value . toString ( ) . split ( separator ) ) ; } } } | Get the field as List . If field was not a list returns an UnmodifiableList . Do not modify the ObjectMap content . |
17,996 | public void close ( ) throws IOException { if ( out != null ) { IOException ex = null ; try { if ( position > 0 ) { if ( breakLines && lineLength >= Base64 . MAX_LINE_LENGTH ) { if ( crlf ) { out . write ( Base64 . CR ) ; } out . write ( Base64 . LF ) ; } int len = Base64 . encode3to4 ( buffer , 0 , position , b4 , 0 , noPadding , alphabet ) ; out . write ( b4 , 0 , len ) ; } out . flush ( ) ; } catch ( IOException e ) { ex = e ; } try { if ( close ) { out . close ( ) ; } } catch ( IOException e ) { if ( ex != null ) { ex . addSuppressed ( e ) ; } else { throw e ; } } finally { out = null ; } if ( ex != null ) { throw ex ; } } } | Encodes and writes the remaining buffered bytes adds necessary padding and closes the output stream . |
17,997 | public List < ModelServiceInstance > getAllModelServiceInstance ( ) { return getData ( ) == null ? Collections . < ModelServiceInstance > emptyList ( ) : getData ( ) . getServiceInstances ( ) ; } | Get the list of ModelServiceInstances . |
17,998 | public static < T > T readJson ( File file ) { try { return objectMapper . readValue ( new String ( Files . readAllBytes ( file . toPath ( ) ) ) , new TypeReference < T > ( ) { } ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } | Read json t . |
17,999 | public static < T > void writeKryo ( T obj , OutputStream file ) { try { Output output = new Output ( buffer . get ( ) ) ; new KryoReflectionFactorySupport ( ) . writeClassAndObject ( output , obj ) ; output . close ( ) ; IOUtils . write ( CompressionUtil . encodeBZ ( Arrays . copyOf ( output . getBuffer ( ) , output . position ( ) ) ) , file ) ; file . close ( ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } | Write kryo . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.