idx int64 0 165k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
8,500 | public static double normalizeLogProps ( double [ ] logProps ) { double logPropSum = DoubleArrays . logSum ( logProps ) ; if ( logPropSum == Double . NEGATIVE_INFINITY ) { double uniform = FastMath . log ( 1.0 / ( double ) logProps . length ) ; for ( int d = 0 ; d < logProps . length ; d ++ ) { logProps [ d ] = uniform ; } } else if ( logPropSum == Double . POSITIVE_INFINITY ) { int count = DoubleArrays . count ( logProps , Double . POSITIVE_INFINITY ) ; if ( count == 0 ) { throw new RuntimeException ( "Unable to normalize since sum is infinite but contains no infinities: " + Arrays . toString ( logProps ) ) ; } double constant = FastMath . log ( 1.0 / ( double ) count ) ; for ( int d = 0 ; d < logProps . length ; d ++ ) { if ( logProps [ d ] == Double . POSITIVE_INFINITY ) { logProps [ d ] = constant ; } else { logProps [ d ] = Double . NEGATIVE_INFINITY ; } } } else { for ( int d = 0 ; d < logProps . length ; d ++ ) { logProps [ d ] -= logPropSum ; assert ( ! Double . isNaN ( logProps [ d ] ) ) ; } } return logPropSum ; } | In the log - semiring normalize the proportions and return their sum . |
8,501 | public static double klDivergence ( double [ ] p , double [ ] q ) { if ( p . length != q . length ) { throw new IllegalStateException ( "The length of p and q must be the same." ) ; } double delta = 1e-8 ; if ( ! Multinomials . isMultinomial ( p , delta ) ) { throw new IllegalStateException ( "p is not a multinomial" ) ; } if ( ! Multinomials . isMultinomial ( q , delta ) ) { throw new IllegalStateException ( "q is not a multinomial" ) ; } double kl = 0.0 ; for ( int i = 0 ; i < p . length ; i ++ ) { if ( p [ i ] == 0.0 || q [ i ] == 0.0 ) { continue ; } kl += p [ i ] * FastMath . log ( p [ i ] / q [ i ] ) ; } return kl ; } | Gets the KL divergence between two multinomial distributions p and q . |
8,502 | public double [ ] toNativeArray ( ) { final double [ ] arr = new double [ getNumImplicitEntries ( ) ] ; iterate ( new FnIntDoubleToVoid ( ) { public void call ( int idx , double val ) { arr [ idx ] = val ; } } ) ; return arr ; } | Gets a NEW array containing all the elements in this vector . |
8,503 | private String getLabel ( String key ) { String label = StrUtil . getLabel ( "cwf.shell.about." + key . toString ( ) ) ; return label == null ? key : label ; } | Returns the label value for the specified key . |
8,504 | public H2DataSource init ( ) throws Exception { if ( dbMode == DBMode . LOCAL ) { String port = getPort ( ) ; if ( port . isEmpty ( ) ) { server = Server . createTcpServer ( ) ; } else { server = Server . createTcpServer ( "-tcpPort" , port ) ; } server . start ( ) ; } return this ; } | If running H2 in local mode starts the server . |
8,505 | private String getPort ( ) { String url = getUrl ( ) ; int i = url . indexOf ( "://" ) + 3 ; int j = url . indexOf ( "/" , i ) ; String s = i == 2 || j == - 1 ? "" : url . substring ( i , j ) ; i = s . indexOf ( ":" ) ; return i == - 1 ? "" : s . substring ( i + 1 ) ; } | Extract the TCP port from the connection URL . |
8,506 | public String nextLine ( Map < String , Object > extraClasses ) { return mainClass . render ( null , preprocessExtraClasses ( extraClasses ) ) ; } | Returns a random line of text driven by the underlying spew file and the given classes . For example to drive a spew file but add some parameters to it call this method with the class names as the map keys and the Strings that you d like substituted as the values . |
8,507 | public boolean isDuplicate ( HelpTopic topic ) { return ObjectUtils . equals ( url , topic . url ) && compareTo ( topic ) == 0 ; } | Returns true if the topic is considered a duplicate . |
8,508 | protected void updateStatus ( ) { if ( ! plugins . isEmpty ( ) ) { boolean disabled = isDisabled ( ) ; for ( ElementPlugin container : plugins ) { container . setDisabled ( disabled ) ; } } } | Updates the disabled status of all registered containers . |
8,509 | private Enum getYesNoEnum ( String answer ) { return answer . equals ( "Y" ) ? YesNoDataType . Y_YES : YesNoDataType . N_NO ; } | This method is to return YesNoDataType enum . |
8,510 | public static IAction createAction ( String label , String script ) { return new Action ( script , label , script ) ; } | Creates an action object from fields . |
8,511 | public static ActionListener removeAction ( BaseComponent component , String eventName ) { ActionListener listener = getListener ( component , eventName ) ; if ( listener != null ) { listener . removeAction ( ) ; } return listener ; } | Removes any action associated with a component . |
8,512 | public static void disableAction ( BaseComponent component , String eventName , boolean disable ) { ActionListener listener = getListener ( component , eventName ) ; if ( listener != null ) { listener . setDisabled ( disable ) ; } } | Enables or disables the deferred event listener associated with the component . |
8,513 | private static IAction createAction ( String action ) { IAction actn = null ; if ( ! StringUtils . isEmpty ( action ) ) { if ( ( actn = ActionRegistry . getRegisteredAction ( action ) ) == null ) { actn = ActionUtil . createAction ( null , action ) ; } } return actn ; } | Returns an IAction object given an action . |
8,514 | public static ActionListener getListener ( BaseComponent component , String eventName ) { return ( ActionListener ) component . getAttribute ( ActionListener . getAttrName ( eventName ) ) ; } | Returns the listener associated with the given component and event . |
8,515 | public static SSLContext buildSSLContext ( HttpClientConfig config ) throws IOException , GeneralSecurityException { KeyManagerFactory kmf = null ; if ( isSslKeyManagerEnabled ( config ) ) { kmf = getKeyManagerFactory ( config . getKeyStorePath ( ) , new StoreProperties ( config . getKeyStorePassword ( ) , config . getKeyManagerType ( ) , config . getKeyStoreType ( ) , config . getKeyStoreProvider ( ) ) ) ; } TrustManagerFactory tmf = null ; if ( isSslTrustStoreEnbaled ( config ) ) { tmf = getTrustManagerFactory ( config . getTrustStorePath ( ) , new StoreProperties ( config . getTrustStorePassword ( ) , config . getTrustManagerType ( ) , config . getTrustStoreType ( ) , config . getTrustStoreProvider ( ) ) ) ; } SSLContext sslContext = SSLContext . getInstance ( config . getSslContextType ( ) ) ; sslContext . init ( kmf != null ? kmf . getKeyManagers ( ) : null , tmf != null ? tmf . getTrustManagers ( ) : null , null ) ; return sslContext ; } | Build SSL Socket factory . |
8,516 | private static InputStream getResourceAsStream ( String path ) throws IOException { if ( StringUtils . isEmpty ( path ) ) { return null ; } File file = new File ( path ) ; if ( file . exists ( ) && file . isFile ( ) ) { return new FileInputStream ( file ) ; } return CertificateLoader . class . getResourceAsStream ( path ) ; } | Tries to load the given resource as file or if no file exists as classpath resource . |
8,517 | private static String getFilenameInfo ( String path ) { if ( StringUtils . isEmpty ( path ) ) { return null ; } try { return new File ( path ) . getCanonicalPath ( ) ; } catch ( IOException ex ) { return new File ( path ) . getAbsolutePath ( ) ; } } | Generate filename info for given path for error messages . |
8,518 | public static boolean isSslKeyManagerEnabled ( HttpClientConfig config ) { return StringUtils . isNotEmpty ( config . getSslContextType ( ) ) && StringUtils . isNotEmpty ( config . getKeyManagerType ( ) ) && StringUtils . isNotEmpty ( config . getKeyStoreType ( ) ) && StringUtils . isNotEmpty ( config . getKeyStorePath ( ) ) ; } | Checks whether a SSL key store is configured . |
8,519 | public static boolean isSslTrustStoreEnbaled ( HttpClientConfig config ) { return StringUtils . isNotEmpty ( config . getSslContextType ( ) ) && StringUtils . isNotEmpty ( config . getTrustManagerType ( ) ) && StringUtils . isNotEmpty ( config . getTrustStoreType ( ) ) && StringUtils . isNotEmpty ( config . getTrustStorePath ( ) ) ; } | Checks whether a SSL trust store is configured . |
8,520 | public static SSLContext createDefaultSSlContext ( ) throws SSLInitializationException { try { final SSLContext sslcontext = SSLContext . getInstance ( SSL_CONTEXT_TYPE_DEFAULT ) ; sslcontext . init ( null , null , null ) ; return sslcontext ; } catch ( NoSuchAlgorithmException ex ) { throw new SSLInitializationException ( ex . getMessage ( ) , ex ) ; } catch ( KeyManagementException ex ) { throw new SSLInitializationException ( ex . getMessage ( ) , ex ) ; } } | Creates default SSL context . |
8,521 | private static void swap ( byte [ ] array , int i , int j ) { if ( i != j ) { byte valAtI = array [ i ] ; array [ i ] = array [ j ] ; array [ j ] = valAtI ; numSwaps ++ ; } } | Swaps the elements at positions i and j . |
8,522 | public String getUrl ( String mockupType ) { return mockupType == null ? null : mockupTypes . getProperty ( mockupType ) ; } | Returns the url given the mockup type . |
8,523 | public Iterator < String > iterator ( ) { List < String > list = new ArrayList < > ( mockupTypes . stringPropertyNames ( ) ) ; Collections . sort ( list , String . CASE_INSENSITIVE_ORDER ) ; return list . iterator ( ) ; } | Returns an alphabetically sorted iterator of recognized mockup framework types . |
8,524 | public int lookupIndex ( short value ) { for ( int i = 0 ; i < elements . length ; i ++ ) { if ( elements [ i ] == value ) { return i ; } } return - 1 ; } | Gets the index of the first element in this list with the specified value or - 1 if it is not present . |
8,525 | public static short [ ] ensureCapacity ( short [ ] elements , int size ) { if ( size > elements . length ) { short [ ] tmp = new short [ size * 2 ] ; System . arraycopy ( elements , 0 , tmp , 0 , elements . length ) ; elements = tmp ; } return elements ; } | Ensure that the array has space to contain the specified number of elements . |
8,526 | private PluginDefinition pluginById ( String id ) { PluginDefinition def = pluginRegistry . get ( id ) ; if ( def == null ) { throw new PluginException ( EXC_UNKNOWN_PLUGIN , null , null , id ) ; } return def ; } | Lookup a plugin definition by its id . Raises a runtime exception if the plugin is not found . |
8,527 | public ElementMenuItem registerMenu ( String path , String action ) { ElementMenuItem menu = getElement ( path , getDesktop ( ) . getMenubar ( ) , ElementMenuItem . class ) ; menu . setAction ( action ) ; return menu ; } | Register a menu . |
8,528 | public void registerLayout ( String path , String resource ) throws Exception { Layout layout = LayoutParser . parseResource ( resource ) ; ElementUI parent = parentFromPath ( path ) ; if ( parent != null ) { layout . materialize ( parent ) ; } } | Registers a layout at the specified path . |
8,529 | private ElementUI parentFromPath ( String path ) throws Exception { if ( TOOLBAR_PATH . equalsIgnoreCase ( path ) ) { return getDesktop ( ) . getToolbar ( ) ; } String [ ] pieces = path . split ( delim , 2 ) ; ElementTabPane tabPane = pieces . length == 0 ? null : findTabPane ( pieces [ 0 ] ) ; ElementUI parent = pieces . length < 2 ? null : getPathResolver ( ) . resolvePath ( tabPane , pieces [ 1 ] ) ; return parent == null ? tabPane : parent ; } | Returns the parent UI element based on the provided path . |
8,530 | private ElementTabPane findTabPane ( String name ) throws Exception { ElementTabView tabView = getTabView ( ) ; ElementTabPane tabPane = null ; while ( ( tabPane = tabView . getChild ( ElementTabPane . class , tabPane ) ) != null ) { if ( name . equalsIgnoreCase ( tabPane . getLabel ( ) ) ) { return tabPane ; } } tabPane = new ElementTabPane ( ) ; tabPane . setParent ( tabView ) ; tabPane . setLabel ( name ) ; return tabPane ; } | Locate the tab with the corresponding label or create one if not found . |
8,531 | private String getDefaultPluginId ( ) { if ( defaultPluginId == null ) { try { defaultPluginId = PropertyUtil . getValue ( "CAREWEB.INITIAL.SECTION" , null ) ; if ( defaultPluginId == null ) { defaultPluginId = "" ; } } catch ( Exception e ) { defaultPluginId = "" ; } } return defaultPluginId ; } | Returns the default plugin id as a user preference . |
8,532 | public void setResources ( Resource [ ] resources ) throws IOException { clear ( ) ; for ( Resource resource : resources ) { addResource ( resource ) ; } } | Initializes the properties from a multiple resources . |
8,533 | public void afterInitialized ( BaseComponent comp ) { super . afterInitialized ( comp ) ; createLabel ( "default" ) ; getEventManager ( ) . subscribe ( EventUtil . STATUS_EVENT , this ) ; } | Creates the default pane . |
8,534 | private Label getLabel ( String pane ) { Label lbl = root . findByName ( pane , Label . class ) ; return lbl == null ? createLabel ( pane ) : lbl ; } | Returns the label associated with the named pane or creates a new one if necessary . |
8,535 | private Label createLabel ( String label ) { Pane pane = new Pane ( ) ; root . addChild ( pane ) ; Label lbl = new Label ( ) ; lbl . setName ( label ) ; pane . addChild ( lbl ) ; adjustPanes ( ) ; return lbl ; } | Create a new status pane and associated label . |
8,536 | public synchronized int addSubscriber ( String eventName , IGenericEvent < T > subscriber ) { List < IGenericEvent < T > > subscribers = getSubscribers ( eventName , true ) ; subscribers . add ( subscriber ) ; return subscribers . size ( ) ; } | Adds a subscriber to the specified event . |
8,537 | public synchronized int removeSubscriber ( String eventName , IGenericEvent < T > subscriber ) { List < IGenericEvent < T > > subscribers = getSubscribers ( eventName , false ) ; if ( subscribers != null ) { subscribers . remove ( subscriber ) ; if ( subscribers . isEmpty ( ) ) { subscriptions . remove ( eventName ) ; } return subscribers . size ( ) ; } return - 1 ; } | Removes a subscriber from the specified event . |
8,538 | public boolean hasSubscribers ( String eventName , boolean exact ) { while ( ! StringUtils . isEmpty ( eventName ) ) { if ( hasSubscribers ( eventName ) ) { return true ; } else if ( exact ) { return false ; } else { eventName = stripLevel ( eventName ) ; } } return false ; } | Returns true If the event has subscribers . |
8,539 | public synchronized Iterable < IGenericEvent < T > > getSubscribers ( String eventName ) { List < IGenericEvent < T > > subscribers = getSubscribers ( eventName , false ) ; return subscribers == null ? null : new ArrayList < > ( subscribers ) ; } | Returns a thread - safe iterable for the subscriber list . |
8,540 | public void invokeCallbacks ( String eventName , T eventData ) { String name = eventName ; while ( ! StringUtils . isEmpty ( name ) ) { Iterable < IGenericEvent < T > > subscribers = getSubscribers ( name ) ; if ( subscribers != null ) { for ( IGenericEvent < T > subscriber : subscribers ) { try { if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "Firing local Event[name=%s,data=%s]" , eventName , eventData ) ) ; } subscriber . eventCallback ( eventName , eventData ) ; } catch ( Throwable e ) { log . error ( "Error during local event callback." , e ) ; } } } name = stripLevel ( name ) ; } } | Invokes callbacks on all subscribers of this and parent events . |
8,541 | private List < IGenericEvent < T > > getSubscribers ( String eventName , boolean canCreate ) { List < IGenericEvent < T > > subscribers = subscriptions . get ( eventName ) ; if ( subscribers == null && canCreate ) { subscribers = new LinkedList < > ( ) ; subscriptions . put ( eventName , subscribers ) ; } return subscribers ; } | Gets the list of subscribers associated with an event . |
8,542 | private String stripLevel ( String eventName ) { int i = eventName . lastIndexOf ( '.' ) ; return i > 1 ? eventName . substring ( 0 , i ) : "" ; } | Strips the lowest hierarchical level from the event type . |
8,543 | public void start ( ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Executing ThreadEx [target=" + target . getClass ( ) . getName ( ) + "]" ) ; } ThreadUtil . startThread ( this . thread ) ; } | Starts the background thread . |
8,544 | protected void done ( ) { try { page . getEventQueue ( ) . queue ( event ) ; } catch ( Exception e ) { log . error ( e ) ; } } | Invoked by the background thread when it has completed the target operation even if aborted . This schedules a notification on the desktop s event thread where the requester is notified of the completion . |
8,545 | public void setAttribute ( String name , Object value ) { synchronized ( attribute ) { attribute . put ( name , value ) ; } } | Sets the named attribute to the specified value . |
8,546 | public void revertImplementation ( Page page ) { Integer previousImplementedVersion = getPreviousImplementedVersion ( page ) ; if ( previousImplementedVersion != null ) { saveImplementedVersion ( page , previousImplementedVersion ) ; savePreviousImplementedVersion ( page , null ) ; } } | Sets the implemented version to the previous implemented version . |
8,547 | public Integer getPreviousImplementedVersion ( Page page ) { ContentEntityObject entityObject = getContentEntityManager ( ) . getById ( page . getId ( ) ) ; String value = getContentPropertyManager ( ) . getStringProperty ( entityObject , PREVIOUS_IMPLEMENTED_VERSION ) ; return value == null ? null : Integer . valueOf ( value ) ; } | Retrieves the previous implemented version of the specification . |
8,548 | public void savePreviousImplementedVersion ( Page page , Integer version ) { String value = version != null ? String . valueOf ( version ) : null ; ContentEntityObject entityObject = getContentEntityManager ( ) . getById ( page . getId ( ) ) ; getContentPropertyManager ( ) . setStringProperty ( entityObject , PREVIOUS_IMPLEMENTED_VERSION , value ) ; } | Saves the sprecified version as the Previous implemented version |
8,549 | public boolean canBeImplemented ( Page page ) { Integer implementedVersion = getImplementedVersion ( page ) ; return implementedVersion == null || page . getVersion ( ) != implementedVersion ; } | Verifies if the specification can be Implemented . |
8,550 | public Integer getImplementedVersion ( Page page ) { ContentEntityObject entityObject = getContentEntityManager ( ) . getById ( page . getId ( ) ) ; String value = getContentPropertyManager ( ) . getStringProperty ( entityObject , IMPLEMENTED_VERSION ) ; return value == null ? null : Integer . valueOf ( value ) ; } | Retrieves the implemented version of the specification . |
8,551 | public void saveImplementedVersion ( Page page , Integer version ) { Integer previousImplementedVersion = getImplementedVersion ( page ) ; if ( previousImplementedVersion != null && version != null && previousImplementedVersion == version ) return ; if ( previousImplementedVersion != null ) savePreviousImplementedVersion ( page , previousImplementedVersion ) ; String value = version != null ? String . valueOf ( version ) : null ; ContentEntityObject entityObject = getContentEntityManager ( ) . getById ( page . getId ( ) ) ; getContentPropertyManager ( ) . setStringProperty ( entityObject , IMPLEMENTED_VERSION , value ) ; } | Saves the sprecified version as the Iimplemented version |
8,552 | public boolean isImplementationDue ( Page page ) { int version = page . getVersion ( ) ; Integer implementedVersion = getImplementedVersion ( page ) ; if ( implementedVersion != null ) version = page . getVersion ( ) == implementedVersion ? implementedVersion : implementedVersion + 1 ; Date date = getPageManager ( ) . getPageByVersion ( page , version ) . getLastModificationDate ( ) ; Period period = Period . fromTo ( date , new Date ( System . currentTimeMillis ( ) ) ) ; return period . daysCount ( ) > CRITICAL_PERIOD ; } | Verifies if the Specification has stayed to long in the WORKING state . |
8,553 | public boolean getExecuteChildren ( Page page ) { ContentEntityObject entityObject = getContentEntityManager ( ) . getById ( page . getId ( ) ) ; String value = getContentPropertyManager ( ) . getStringProperty ( entityObject , EXECUTE_CHILDREN ) ; return value == null ? false : Boolean . valueOf ( value ) ; } | Retrieves from the page propeties the Execute childs boolean . If none registered false is returned . |
8,554 | public static Document toDocument ( BaseComponent root , String ... excludedProperties ) { try { CWF2XML instance = new CWF2XML ( excludedProperties ) ; instance . toXML ( root , instance . doc ) ; return instance . doc ; } catch ( ParserConfigurationException e ) { return null ; } } | Returns an XML document that mirrors the CWF component tree starting at the specified root . |
8,555 | public static String toXML ( BaseComponent root , String ... excludedProperties ) { return XMLUtil . toString ( toDocument ( root , excludedProperties ) ) ; } | Returns an XML - formatted string that mirrors the CWF component tree starting at the specified root . |
8,556 | private void toXML ( BaseComponent root , Node parent ) { TreeMap < String , String > properties = new TreeMap < > ( String . CASE_INSENSITIVE_ORDER ) ; Class < ? > clazz = root . getClass ( ) ; ComponentDefinition def = root . getDefinition ( ) ; String cmpname = def . getTag ( ) ; if ( def . getComponentClass ( ) != clazz ) { properties . put ( "impl" , clazz . getName ( ) ) ; } Node child = doc . createElement ( cmpname ) ; parent . appendChild ( child ) ; for ( PropertyDescriptor propDx : PropertyUtils . getPropertyDescriptors ( root ) ) { Method getter = propDx . getReadMethod ( ) ; Method setter = propDx . getWriteMethod ( ) ; String name = propDx . getName ( ) ; if ( getter != null && setter != null && ! isExcluded ( name , cmpname , null ) && ! setter . isAnnotationPresent ( Deprecated . class ) && ( getter . getReturnType ( ) == String . class || getter . getReturnType ( ) . isPrimitive ( ) ) ) { try { Object raw = getter . invoke ( root ) ; String value = raw == null ? null : raw . toString ( ) ; if ( StringUtils . isEmpty ( value ) || ( "id" . equals ( name ) && value . startsWith ( "z_" ) ) || isExcluded ( name , cmpname , value ) ) { continue ; } properties . put ( name , value . toString ( ) ) ; } catch ( Exception e ) { } } } for ( Entry < String , String > entry : properties . entrySet ( ) ) { Attr attr = doc . createAttribute ( entry . getKey ( ) ) ; child . getAttributes ( ) . setNamedItem ( attr ) ; attr . setValue ( entry . getValue ( ) ) ; } properties = null ; for ( BaseComponent cmp : root . getChildren ( ) ) { toXML ( cmp , child ) ; } } | Adds the root component to the XML document at the current level along with all bean properties that return String or primitive types . Then recurses over all of the root component s children . |
8,557 | private boolean isExcluded ( String name , String cmpname , String value ) { return exclude . contains ( excludeKey ( name , null , value ) ) || exclude . contains ( excludeKey ( name , cmpname , value ) ) ; } | Returns true if the property is to be excluded . |
8,558 | private String excludeKey ( String name , String cmpname , String value ) { StringBuilder sb = new StringBuilder ( cmpname == null ? "" : cmpname + "." ) ; sb . append ( name ) . append ( value == null ? "" : "=" + value ) ; return sb . toString ( ) ; } | Returns the exclusion lookup key for the property . |
8,559 | protected void putToRingBuffer ( IQueueMessage < ID , DATA > msg ) throws QueueException . QueueIsFull { if ( msg == null ) { throw new NullPointerException ( "Supplied queue message is null!" ) ; } LOCK_PUT . lock ( ) ; try { if ( ! ringBuffer . tryPublishEvent ( ( event , _seq ) -> { event . set ( msg ) ; knownPublishedSeq = _seq > knownPublishedSeq ? _seq : knownPublishedSeq ; } ) ) { throw new QueueException . QueueIsFull ( getRingSize ( ) ) ; } } finally { LOCK_PUT . unlock ( ) ; } } | Put a message to the ring buffer . |
8,560 | protected IQueueMessage < ID , DATA > takeFromRingBuffer ( ) { LOCK_TAKE . lock ( ) ; try { long l = consumedSeq . get ( ) + 1 ; if ( l <= knownPublishedSeq ) { try { Event < ID , DATA > eventHolder = ringBuffer . get ( l ) ; try { return eventHolder . get ( ) ; } finally { eventHolder . set ( null ) ; } } finally { consumedSeq . incrementAndGet ( ) ; } } else { knownPublishedSeq = ringBuffer . getCursor ( ) ; } return null ; } finally { LOCK_TAKE . unlock ( ) ; } } | Takes a message from the ring buffer . |
8,561 | protected void setHumanSubjectInvolvedAndVertebrateAnimalUsed ( OtherResearchTrainingPlan researchTrainingPlan ) { researchTrainingPlan . setHumanSubjectsInvolved ( YesNoDataType . N_NO ) ; researchTrainingPlan . setVertebrateAnimalsUsed ( YesNoDataType . N_NO ) ; for ( ProposalSpecialReviewContract propSpecialReview : pdDoc . getDevelopmentProposal ( ) . getPropSpecialReviews ( ) ) { switch ( Integer . parseInt ( propSpecialReview . getSpecialReviewType ( ) . getCode ( ) ) ) { case 1 : researchTrainingPlan . setHumanSubjectsInvolved ( YesNoDataType . Y_YES ) ; break ; case 2 : researchTrainingPlan . setVertebrateAnimalsUsed ( YesNoDataType . Y_YES ) ; break ; default : break ; } } } | This method is used to set HumanSubjectInvoved and VertebrateAnimalUsed XMLObject Data . |
8,562 | public List < Pair < A , B > > getEntries ( ) { List < Pair < A , B > > l = new ArrayList < > ( size ( ) ) ; for ( Map . Entry < A , B > x : map1 . entrySet ( ) ) l . add ( new Pair < > ( x . getKey ( ) , x . getValue ( ) ) ) ; return l ; } | Returns a new List with all the entries in this bimap |
8,563 | public static void show ( DialogControl < ? > control ) { DialogResponse < ? > response = control . getLastResponse ( ) ; if ( response != null ) { control . callback ( response ) ; return ; } Window root = null ; try { Map < String , Object > args = Collections . singletonMap ( "control" , control ) ; root = ( Window ) PageUtil . createPage ( DialogConstants . RESOURCE_PREFIX + "promptDialog.fsp" , ExecutionContext . getPage ( ) , args ) . get ( 0 ) ; root . modal ( null ) ; } catch ( Exception e ) { log . error ( "Error Displaying Dialog" , e ) ; if ( root != null ) { root . destroy ( ) ; } throw MiscUtil . toUnchecked ( e ) ; } } | Display the prompt dialog . |
8,564 | public static SecurityContext getSecurityContext ( ) { Session session = ExecutionContext . getSession ( ) ; @ SuppressWarnings ( "resource" ) WebSocketSession ws = session == null ? null : session . getSocket ( ) ; return ws == null ? null : ( SecurityContext ) ws . getAttributes ( ) . get ( HttpSessionSecurityContextRepository . SPRING_SECURITY_CONTEXT_KEY ) ; } | Returns the security context from the execution context . |
8,565 | public void logout ( boolean force , String target , String message ) { log . trace ( "Logging Out" ) ; IContextManager contextManager = ContextManager . getInstance ( ) ; if ( contextManager == null ) { logout ( target , message ) ; } else { contextManager . reset ( force , ( response ) -> { if ( force || ! response . rejected ( ) ) { logout ( target , message ) ; } } ) ; } } | Logout out the current page instance . |
8,566 | protected Boolean hasPersonnelBudget ( KeyPersonDto keyPerson , int period ) { List < ? extends BudgetLineItemContract > budgetLineItemList = new ArrayList < > ( ) ; ProposalDevelopmentBudgetExtContract budget = s2SCommonBudgetService . getBudget ( pdDoc . getDevelopmentProposal ( ) ) ; budgetLineItemList = budget . getBudgetPeriods ( ) . get ( period - 1 ) . getBudgetLineItems ( ) ; for ( BudgetLineItemContract budgetLineItem : budgetLineItemList ) { for ( BudgetPersonnelDetailsContract budgetPersonnelDetails : budgetLineItem . getBudgetPersonnelDetailsList ( ) ) { if ( budgetPersonnelDetails . getPersonId ( ) . equals ( keyPerson . getPersonId ( ) ) ) { return true ; } else if ( keyPerson . getRolodexId ( ) != null && budgetPersonnelDetails . getPersonId ( ) . equals ( keyPerson . getRolodexId ( ) . toString ( ) ) ) { return true ; } } } return false ; } | This method check whether the key person has a personnel budget |
8,567 | public static < T > List < DialogResponse < T > > toResponseList ( T [ ] responses , T [ ] exclusions , T dflt ) { List < DialogResponse < T > > list = new ArrayList < > ( ) ; boolean forceDefault = dflt == null && responses . length == 1 ; for ( T response : responses ) { DialogResponse < T > rsp = new DialogResponse < > ( response , response . toString ( ) , exclusions != null && ArrayUtils . contains ( exclusions , response ) , forceDefault || response . equals ( dflt ) ) ; list . add ( rsp ) ; } return list ; } | Returns list of response objects created from a string of vertical bar delimited captions . |
8,568 | private boolean isResponseType ( String text , String label ) { return label . equals ( text ) || StrUtil . formatMessage ( label ) . equals ( text ) ; } | Returns true if the text corresponds to a specific response type . |
8,569 | public double get ( long i ) { if ( i < 0 || i >= idxAfterLast ) { return missingEntries ; } return elements [ SafeCast . safeLongToInt ( i ) ] ; } | Gets the i th entry in the vector . |
8,570 | public String getName ( ) { return getName ( hasGivenNames ( ) ? Collections . singletonList ( givenNames . get ( 0 ) ) : Collections . < String > emptyList ( ) ) ; } | Will return a standard Firstname Lastname representation of the person with middle names omitted . |
8,571 | public Resource [ ] getResources ( String pattern ) { Resource [ ] resources = cache . get ( pattern ) ; return resources == null ? internalGet ( pattern ) : resources ; } | Returns an array of resources corresponding to the specified pattern . If the pattern has not yet been cached the resources will be enumerated by the application context and stored in the cache . |
8,572 | private synchronized Resource [ ] internalGet ( String pattern ) { Resource [ ] resources = cache . get ( pattern ) ; if ( resources != null ) { return resources ; } try { resources = resolver . getResources ( pattern ) ; } catch ( IOException e ) { throw MiscUtil . toUnchecked ( e ) ; } if ( resources == null ) { resources = new Resource [ 0 ] ; } else { Arrays . sort ( resources , resourceComparator ) ; } cache . put ( pattern , resources ) ; return resources ; } | Use application context to enumerate resources . This call is thread safe . |
8,573 | private void setQuestionnaireAnswers ( CoverSheet coverSheet , ProjectNarrative projectNarrative ) { List < ? extends AnswerContract > answers = getPropDevQuestionAnswerService ( ) . getQuestionnaireAnswers ( pdDoc . getDevelopmentProposal ( ) . getProposalNumber ( ) , getNamespace ( ) , getFormName ( ) ) ; for ( AnswerContract answer : answers ) { Integer seqId = getQuestionAnswerService ( ) . findQuestionById ( answer . getQuestionId ( ) ) . getQuestionSeqId ( ) ; switch ( seqId ) { case PRELIMINARY : YesNoNotApplicableDataType . Enum yesNoNotApplicableDataType = YesNoNotApplicableDataType . N_NO ; if ( QUESTIONNAIRE_ANSWER_YES . equals ( answer . getAnswer ( ) ) ) { yesNoNotApplicableDataType = YesNoNotApplicableDataType . Y_YES ; } else if ( QUESTIONNAIRE_ANSWER_NO . equals ( answer . getAnswer ( ) ) ) { yesNoNotApplicableDataType = YesNoNotApplicableDataType . N_NO ; } else if ( QUESTIONNAIRE_ANSWER_X . equals ( answer . getAnswer ( ) ) ) { yesNoNotApplicableDataType = YesNoNotApplicableDataType . NA_NOT_APPLICABLE ; } coverSheet . setCheckFullApp ( yesNoNotApplicableDataType ) ; break ; case MERIT_REVIEW : if ( QUESTIONNAIRE_ANSWER_YES . equals ( answer . getAnswer ( ) ) ) { projectNarrative . setCheckMeritReview ( YesNoNotApplicableDataType . Y_YES ) ; } else if ( QUESTIONNAIRE_ANSWER_NO . equals ( answer . getAnswer ( ) ) ) { projectNarrative . setCheckMeritReview ( YesNoNotApplicableDataType . N_NO ) ; } else if ( QUESTIONNAIRE_ANSWER_X . equals ( answer . getAnswer ( ) ) ) { projectNarrative . setCheckMeritReview ( YesNoNotApplicableDataType . NA_NOT_APPLICABLE ) ; } break ; case MENTORING : if ( QUESTIONNAIRE_ANSWER_YES . equals ( answer . getAnswer ( ) ) ) { projectNarrative . setCheckMentoring ( YesNoNotApplicableDataType . Y_YES ) ; } else if ( QUESTIONNAIRE_ANSWER_NO . equals ( answer . getAnswer ( ) ) ) { projectNarrative . setCheckMentoring ( YesNoNotApplicableDataType . N_NO ) ; } break ; case PRIOR_SUPPORT : if ( QUESTIONNAIRE_ANSWER_YES . equals ( answer . getAnswer ( ) ) ) projectNarrative . setCheckPriorSupport ( YesNoNotApplicableDataType . Y_YES ) ; if ( QUESTIONNAIRE_ANSWER_NO . equals ( answer . getAnswer ( ) ) ) projectNarrative . setCheckPriorSupport ( YesNoNotApplicableDataType . N_NO ) ; if ( QUESTIONNAIRE_ANSWER_X . equals ( answer . getAnswer ( ) ) ) projectNarrative . setCheckPriorSupport ( YesNoNotApplicableDataType . NA_NOT_APPLICABLE ) ; break ; case HR_QUESTION : if ( QUESTIONNAIRE_ANSWER_NO . equals ( answer . getAnswer ( ) ) ) { projectNarrative . setCheckHRInfo ( YesNoNotApplicableDataType . N_NO ) ; } break ; case HR_REQUIRED_INFO : if ( QUESTIONNAIRE_ANSWER_YES . equals ( answer . getAnswer ( ) ) ) { projectNarrative . setCheckHRInfo ( YesNoNotApplicableDataType . Y_YES ) ; } break ; default : break ; } } } | Setting the Coversheet and ProjectNarrative details according the Questionnaire Answers . |
8,574 | private Map < String , Object > getMetadata ( ) { if ( metadata == null ) { metadata = new HashMap < > ( ) ; } return metadata ; } | Returns the metadata map creating it if not already so . |
8,575 | public void setMetadata ( String key , Object value ) { if ( value != null ) { getMetadata ( ) . put ( key , value ) ; } } | Sets a metadata value . |
8,576 | public List < ProposalPersonContract > getNKeyPersons ( List < ? extends ProposalPersonContract > proposalPersons , int n ) { ProposalPersonContract proposalPerson , previousProposalPerson ; int size = proposalPersons . size ( ) ; for ( int i = size - 1 ; i > 0 ; i -- ) { proposalPerson = proposalPersons . get ( i ) ; previousProposalPerson = proposalPersons . get ( i - 1 ) ; if ( proposalPerson . getPersonId ( ) != null && previousProposalPerson . getPersonId ( ) != null && proposalPerson . getPersonId ( ) . equals ( previousProposalPerson . getPersonId ( ) ) ) { proposalPersons . remove ( i ) ; } else if ( proposalPerson . getRolodexId ( ) != null && previousProposalPerson . getRolodexId ( ) != null && proposalPerson . getRolodexId ( ) . equals ( previousProposalPerson . getRolodexId ( ) ) ) { proposalPersons . remove ( i ) ; } } size = proposalPersons . size ( ) ; List < ProposalPersonContract > firstNPersons = new ArrayList < > ( ) ; if ( size > n ) { size = n ; } for ( int i = 0 ; i < size ; i ++ ) { firstNPersons . add ( proposalPersons . get ( i ) ) ; } return firstNPersons ; } | This method limits the number of key persons to n returns list of key persons . |
8,577 | public ProposalPersonContract getPrincipalInvestigator ( ProposalDevelopmentDocumentContract pdDoc ) { ProposalPersonContract proposalPerson = null ; if ( pdDoc != null ) { for ( ProposalPersonContract person : pdDoc . getDevelopmentProposal ( ) . getProposalPersons ( ) ) { if ( person . isPrincipalInvestigator ( ) ) { proposalPerson = person ; } } } return proposalPerson ; } | This method is to get PrincipalInvestigator from person list |
8,578 | public List < ProposalPersonContract > getCoInvestigators ( ProposalDevelopmentDocumentContract pdDoc ) { List < ProposalPersonContract > investigators = new ArrayList < > ( ) ; if ( pdDoc != null ) { for ( ProposalPersonContract person : pdDoc . getDevelopmentProposal ( ) . getProposalPersons ( ) ) { if ( person . isCoInvestigator ( ) || person . isMultiplePi ( ) ) { investigators . add ( person ) ; } } } return investigators ; } | Finds all the Investigators associated with the provided pdDoc . |
8,579 | public List < ProposalPersonContract > getKeyPersons ( ProposalDevelopmentDocumentContract pdDoc ) { List < ProposalPersonContract > keyPersons = new ArrayList < > ( ) ; if ( pdDoc != null ) { for ( ProposalPersonContract person : pdDoc . getDevelopmentProposal ( ) . getProposalPersons ( ) ) { if ( person . isKeyPerson ( ) ) { keyPersons . add ( person ) ; } } } return keyPersons ; } | Finds all the key Person associated with the provided pdDoc . |
8,580 | public static Window show ( String dialog , Map < String , Object > args , boolean closable , boolean sizable , boolean show , IEventListener closeListener ) { Window parent = new Window ( ) ; Page currentPage = ExecutionContext . getPage ( ) ; parent . setParent ( currentPage ) ; Window window = null ; try { PageUtil . createPage ( dialog , parent , args ) ; window = parent . getChild ( Window . class ) ; if ( window != null ) { window . setParent ( null ) ; BaseComponent child ; while ( ( child = parent . getFirstChild ( ) ) != null ) { child . setParent ( window ) ; } parent . destroy ( ) ; window . setParent ( currentPage ) ; } else { window = parent ; } window . setClosable ( closable ) ; window . setSizable ( sizable ) ; if ( show ) { window . modal ( closeListener ) ; } } catch ( Exception e ) { if ( window != null ) { window . destroy ( ) ; window = null ; } if ( parent != null ) { parent . destroy ( ) ; } DialogUtil . showError ( e ) ; log . error ( "Error materializing page" , e ) ; } return window ; } | Can be used to popup any page definition as a modal dialog . |
8,581 | private String loadfromFromFile ( String queryName ) throws IllegalStateException { try ( final InputStream is = getClass ( ) . getResourceAsStream ( scriptsFolder + queryName + ".sql" ) ; ) { String sql = StringUtils . join ( IOUtils . readLines ( is , StandardCharsets . UTF_8 ) , IOUtils . LINE_SEPARATOR ) ; final String [ ] tokens = StringUtils . substringsBetween ( sql , "${" , "}" ) ; if ( tokens != null && tokens . length > 0 ) { final Map < String , String > values = Arrays . stream ( tokens ) . collect ( Collectors . toMap ( Function . identity ( ) , this :: load , ( o , n ) -> o ) ) ; sql = StrSubstitutor . replace ( sql , values ) ; } return sql ; } catch ( Exception e ) { throw new IllegalStateException ( "Could not load query " + scriptsFolder + queryName , e ) ; } } | Loads the query from the informed path and adds to cache |
8,582 | synchronized void open ( ) throws IOException { if ( opened ) { return ; } opened = true ; CompletableFuture < Void > future = new CompletableFuture < > ( ) ; OnRegistration onRegistration = new OnRegistration ( future ) ; try { registrationId = face . registerPrefix ( prefix , this , ( OnRegisterFailed ) onRegistration , onRegistration ) ; future . get ( 10 , TimeUnit . SECONDS ) ; announcementService . announceEntrance ( publisherId ) ; } catch ( IOException | SecurityException | InterruptedException | ExecutionException | TimeoutException e ) { throw new IOException ( "Failed to register NDN prefix; pub-sub IO will be impossible" , e ) ; } } | Open the publisher registering prefixes and announcing group entry . If the publisher is already open this method immediately returns |
8,583 | private boolean initPropertyService ( ) { if ( propertyService == null && appContext . containsBean ( "propertyService" ) ) { propertyService = appContext . getBean ( "propertyService" , IPropertyService . class ) ; } return propertyService != null ; } | Initializes the property service . |
8,584 | public static < T > Stream < T > of ( Iterable < T > iterable ) { checkNotNull ( iterable ) ; return new StreamImpl < T > ( iterable ) ; } | Creates a stream from an iterable . |
8,585 | public static < T > Stream < T > of ( T ... items ) { checkNotNull ( items ) ; return new StreamImpl < T > ( Arrays . asList ( items ) ) ; } | Creates a stream from items . |
8,586 | public static Layout parseResource ( String resource ) { int i = resource . indexOf ( ":" ) ; if ( i > 0 ) { String loaderId = resource . substring ( 0 , i ) ; ILayoutLoader layoutLoader = LayoutLoaderRegistry . getInstance ( ) . get ( loaderId ) ; if ( layoutLoader != null ) { String name = resource . substring ( i + 1 ) ; return layoutLoader . loadLayout ( name ) ; } } InputStream strm = ExecutionContext . getSession ( ) . getServletContext ( ) . getResourceAsStream ( resource ) ; if ( strm == null ) { throw new CWFException ( "Unable to locate layout resource: " + resource ) ; } return parseStream ( strm ) ; } | Loads a layout from the specified resource using a registered layout loader or failing that using the default loadFromUrl method . |
8,587 | public static Layout parseText ( String xml ) { try { return parseDocument ( XMLUtil . parseXMLFromString ( xml ) ) ; } catch ( Exception e ) { throw MiscUtil . toUnchecked ( e ) ; } } | Parse the layout from XML content . |
8,588 | public static Layout parseStream ( InputStream stream ) { try ( InputStream is = stream ) { return parseDocument ( XMLUtil . parseXMLFromStream ( is ) ) ; } catch ( Exception e ) { throw MiscUtil . toUnchecked ( e ) ; } } | Parse layout from an input stream . |
8,589 | public static Layout parseDocument ( Document document ) { return new Layout ( instance . parseChildren ( document , null , Tag . LAYOUT ) ) ; } | Parse the layout from an XML document . |
8,590 | private LayoutElement parseElement ( Element node , LayoutElement parent ) { LayoutElement layoutElement = newLayoutElement ( node , parent , null ) ; parseChildren ( node , layoutElement , Tag . ELEMENT , Tag . TRIGGER ) ; return layoutElement ; } | Parse a layout element node . |
8,591 | private String getRequiredAttribute ( Element node , String name ) { String value = node . getAttribute ( name ) ; if ( value . isEmpty ( ) ) { throw new IllegalArgumentException ( "Missing " + name + " attribute on node: " + node . getTagName ( ) ) ; } return value ; } | Returns the value of the named attribute from a DOM node throwing an exception if not found . |
8,592 | private void parseTrigger ( Element node , LayoutElement parent ) { LayoutTrigger trigger = new LayoutTrigger ( ) ; parent . getTriggers ( ) . add ( trigger ) ; parseChildren ( node , trigger , Tag . CONDITION , Tag . ACTION ) ; } | Parse a trigger node . |
8,593 | private void parseCondition ( Element node , LayoutTrigger parent ) { new LayoutTriggerCondition ( parent , getDefinition ( null , node ) ) ; } | Parse a trigger condition node . |
8,594 | private void parseAction ( Element node , LayoutTrigger parent ) { new LayoutTriggerAction ( parent , getDefinition ( null , node ) ) ; } | Parse a trigger action node . |
8,595 | private Tag getTag ( Element node , Tag ... tags ) { String name = node . getTagName ( ) ; String error = null ; try { Tag tag = Tag . valueOf ( name . toUpperCase ( ) ) ; int i = ArrayUtils . indexOf ( tags , tag ) ; if ( i < 0 ) { error = "Tag '%s' is not valid at this location" ; } else { if ( ! tag . allowMultiple ) { tags [ i ] = null ; } return tag ; } } catch ( IllegalArgumentException e ) { error = "Unrecognized tag '%s' in layout" ; } throw new IllegalArgumentException ( getInvalidTagError ( error , name , tags ) ) ; } | Return and validate the tag type throwing an exception if the tag is unknown or among the allowable types . |
8,596 | private LayoutRoot parseUI ( ElementBase root ) { LayoutRoot ele = new LayoutRoot ( ) ; if ( root instanceof ElementDesktop ) { copyAttributes ( root , ele ) ; } parseChildren ( root , ele ) ; return ele ; } | Parse the layout from the UI element tree . |
8,597 | private void copyAttributes ( ElementBase src , LayoutElement dest ) { for ( PropertyInfo propInfo : src . getDefinition ( ) . getProperties ( ) ) { Object value = propInfo . isSerializable ( ) ? propInfo . getPropertyValue ( src ) : null ; String val = value == null ? null : propInfo . getPropertyType ( ) . getSerializer ( ) . serialize ( value ) ; if ( ! ObjectUtils . equals ( value , propInfo . getDefault ( ) ) ) { dest . getAttributes ( ) . put ( propInfo . getId ( ) , val ) ; } } } | Copy attributes from a UI element to layout element . |
8,598 | public static String readContent ( File file ) throws IOException { Reader input = null ; try { input = new FileReader ( file ) ; return readContent ( input ) ; } finally { closeQuietly ( input ) ; } } | Returns the content of a file as a String . |
8,599 | public static void log ( Marker marker , PerformanceMetrics metrics ) { if ( log . isDebugEnabled ( ) ) { log . debug ( marker , getEndMetrics ( metrics ) ) ; } } | Log line of measured performance of single operation specifying by performance metrics parameter . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.