idx int64 0 41.2k | question stringlengths 74 4.21k | target stringlengths 5 888 |
|---|---|---|
17,700 | public static < T > Stream < T > buildConcatStream ( List < T > sample1 , List < T > sample2 ) { return Stream . concat ( sample1 . stream ( ) , sample2 . stream ( ) ) ; } | Build concat stream stream . |
17,701 | public static DoubleStream buildRandomNumberStream ( int count ) { return IntStream . range ( 0 , count ) . mapToDouble ( i -> Math . random ( ) ) ; } | Build random number stream double stream . |
17,702 | public List < T > getAllByHql ( String secondHalfOfHql , Object paramValue , Type paramType ) { return getAllByHql ( secondHalfOfHql , new Object [ ] { paramValue } , new Type [ ] { paramType } , null , null ) ; } | Get all by HQL with one pair of parameterType - value |
17,703 | public List < T > getAllByHql ( String secondHalfOfHql , Object paramValue1 , Type paramType1 , Object paramValue2 , Type paramType2 ) { return getAllByHql ( secondHalfOfHql , new Object [ ] { paramValue1 , paramValue2 } , new Type [ ] { paramType2 , paramType2 } , null , null ) ; } | Get all by HQL with two pairs of parameterType - value |
17,704 | public List < T > getAllBySql ( String fullSql , Integer offset , Integer limit ) { return getAllBySql ( fullSql , null , null , offset , limit ) ; } | Get all by SQL with specific offset and limit |
17,705 | public List < T > getAllBySql ( String fullSql , Object [ ] paramValues , Type [ ] paramTypes ) { return getAllBySql ( fullSql , paramValues , paramTypes , null , null ) ; } | Get all by SQL with pairs of parameterType - value |
17,706 | public List < T > getAllBySql ( String fullSql , Object paramValue , Type paramType ) { return getAllBySql ( fullSql , new Object [ ] { paramValue } , new Type [ ] { paramType } , null , null ) ; } | Get all by SQL with one pair of parameterType - value |
17,707 | public List < T > getAllBySql ( String fullSql , Object paramValue1 , Type paramType1 , Object paramValue2 , Type paramType2 , Object paramValue3 , Type paramType3 ) { return getAllBySql ( fullSql , new Object [ ] { paramValue1 , paramValue2 , paramValue3 } , new Type [ ] { paramType1 , paramType2 , paramType3 } , null , null ) ; } | Get all by SQL with three pairs of parameterType - value |
17,708 | private void setupQuery ( Query query , Object [ ] paramValues , Type [ ] paramTypes , Integer offset , Integer limit ) { if ( paramValues != null && paramTypes != null ) { query . setParameters ( paramValues , paramTypes ) ; } if ( offset != null ) { query . setFirstResult ( offset ) ; } if ( limit != null ) { query . setMaxResults ( limit ) ; } } | Setup a query with parameters and other configurations . |
17,709 | public int updateByHql ( String secondHalfOfHql , Object [ ] paramValues , Type [ ] paramTypes ) { StringBuilder queryStr = new StringBuilder ( ) ; queryStr . append ( "update " ) . append ( this . clazz . getName ( ) ) . append ( " " ) ; if ( secondHalfOfHql != null ) { queryStr . append ( secondHalfOfHql ) ; } Session session = this . getCurrentSession ( ) ; Query query = session . createQuery ( queryStr . toString ( ) ) ; setupQuery ( query , paramValues , paramTypes , null , null ) ; return query . executeUpdate ( ) ; } | Update by criteria specified as HQL |
17,710 | public static < E > E firstInList ( List < E > list ) { if ( list == null || list . size ( ) == 0 ) { return null ; } else { return list . get ( 0 ) ; } } | Get the first element in the list |
17,711 | public Object getAsObject ( ) { Map < String , Object > result = new HashMap < String , Object > ( ) ; for ( Map . Entry < String , Object > entry : this . entrySet ( ) ) result . put ( entry . getKey ( ) , entry . getValue ( ) ) ; return result ; } | Gets the value stored in this map element without any conversions |
17,712 | public void setAsObject ( Object value ) { clear ( ) ; Map < String , Object > values = MapConverter . toMap ( value ) ; append ( values ) ; } | Sets a new value for this array element |
17,713 | public String getAsNullableString ( String key ) { Object value = getAsObject ( key ) ; return StringConverter . toNullableString ( value ) ; } | Converts map element into a string or returns null if conversion is not possible . |
17,714 | public String getAsStringWithDefault ( String key , String defaultValue ) { Object value = getAsObject ( key ) ; return StringConverter . toStringWithDefault ( value , defaultValue ) ; } | Converts map element into a string or returns default value if conversion is not possible . |
17,715 | public Boolean getAsNullableBoolean ( String key ) { Object value = getAsObject ( key ) ; return BooleanConverter . toNullableBoolean ( value ) ; } | Converts map element into a boolean or returns null if conversion is not possible . |
17,716 | public boolean getAsBooleanWithDefault ( String key , boolean defaultValue ) { Object value = getAsObject ( key ) ; return BooleanConverter . toBooleanWithDefault ( value , defaultValue ) ; } | Converts map element into a boolean or returns default value if conversion is not possible . |
17,717 | public Integer getAsNullableInteger ( String key ) { Object value = getAsObject ( key ) ; return IntegerConverter . toNullableInteger ( value ) ; } | Converts map element into an integer or returns null if conversion is not possible . |
17,718 | public int getAsIntegerWithDefault ( String key , int defaultValue ) { Object value = getAsObject ( key ) ; return IntegerConverter . toIntegerWithDefault ( value , defaultValue ) ; } | Converts map element into an integer or returns default value if conversion is not possible . |
17,719 | public Long getAsNullableLong ( String key ) { Object value = getAsObject ( key ) ; return LongConverter . toNullableLong ( value ) ; } | Converts map element into a long or returns null if conversion is not possible . |
17,720 | public long getAsLongWithDefault ( String key , long defaultValue ) { Object value = getAsObject ( key ) ; return LongConverter . toLongWithDefault ( value , defaultValue ) ; } | Converts map element into a long or returns default value if conversion is not possible . |
17,721 | public Float getAsNullableFloat ( String key ) { Object value = getAsObject ( key ) ; return FloatConverter . toNullableFloat ( value ) ; } | Converts map element into a float or returns null if conversion is not possible . |
17,722 | public float getAsFloatWithDefault ( String key , float defaultValue ) { Object value = getAsObject ( key ) ; return FloatConverter . toFloatWithDefault ( value , defaultValue ) ; } | Converts map element into a flot or returns default value if conversion is not possible . |
17,723 | public Double getAsNullableDouble ( String key ) { Object value = getAsObject ( key ) ; return DoubleConverter . toNullableDouble ( value ) ; } | Converts map element into a double or returns null if conversion is not possible . |
17,724 | public double getAsDoubleWithDefault ( String key , double defaultValue ) { Object value = getAsObject ( key ) ; return DoubleConverter . toDoubleWithDefault ( value , defaultValue ) ; } | Converts map element into a double or returns default value if conversion is not possible . |
17,725 | public ZonedDateTime getAsNullableDateTime ( String key ) { Object value = getAsObject ( key ) ; return DateTimeConverter . toNullableDateTime ( value ) ; } | Converts map element into a Date or returns null if conversion is not possible . |
17,726 | public ZonedDateTime getAsDateTimeWithDefault ( String key , ZonedDateTime defaultValue ) { Object value = getAsObject ( key ) ; return DateTimeConverter . toDateTimeWithDefault ( value , defaultValue ) ; } | Converts map element into a Date or returns default value if conversion is not possible . |
17,727 | public < T > T getAsNullableType ( Class < T > type , String key ) { Object value = getAsObject ( key ) ; return TypeConverter . toNullableType ( type , value ) ; } | Converts map element into a value defined by specied typecode . If conversion is not possible it returns null . |
17,728 | public < T > T getAsType ( Class < T > type , String key ) { return getAsTypeWithDefault ( type , key , null ) ; } | Converts map element into a value defined by specied typecode . If conversion is not possible it returns default value for the specified type . |
17,729 | public < T > T getAsTypeWithDefault ( Class < T > type , String key , T defaultValue ) { Object value = getAsObject ( key ) ; return TypeConverter . toTypeWithDefault ( type , value , defaultValue ) ; } | Converts map element into a value defined by specied typecode . If conversion is not possible it returns default value . |
17,730 | public AnyValue getAsValue ( String key ) { Object value = getAsObject ( key ) ; return new AnyValue ( value ) ; } | Converts map element into an AnyValue or returns an empty AnyValue if conversion is not possible . |
17,731 | public AnyValueArray getAsNullableArray ( String key ) { Object value = getAsObject ( key ) ; return value != null ? AnyValueArray . fromValue ( value ) : null ; } | Converts map element into an AnyValueArray or returns null if conversion is not possible . |
17,732 | public AnyValueArray getAsArray ( String key ) { Object value = getAsObject ( key ) ; return AnyValueArray . fromValue ( value ) ; } | Converts map element into an AnyValueArray or returns empty AnyValueArray if conversion is not possible . |
17,733 | public AnyValueArray getAsArrayWithDefault ( String key , AnyValueArray defaultValue ) { AnyValueArray result = getAsNullableArray ( key ) ; return result != null ? result : defaultValue ; } | Converts map element into an AnyValueArray or returns default value if conversion is not possible . |
17,734 | public AnyValueMap getAsNullableMap ( String key ) { Object value = getAsObject ( key ) ; return value != null ? AnyValueMap . fromValue ( value ) : null ; } | Converts map element into an AnyValueMap or returns null if conversion is not possible . |
17,735 | public AnyValueMap getAsMap ( String key ) { Object value = getAsObject ( key ) ; return AnyValueMap . fromValue ( value ) ; } | Converts map element into an AnyValueMap or returns empty AnyValueMap if conversion is not possible . |
17,736 | public AnyValueMap getAsMapWithDefault ( String key , AnyValueMap defaultValue ) { AnyValueMap result = getAsNullableMap ( key ) ; return result != null ? result : defaultValue ; } | Converts map element into an AnyValueMap or returns default value if conversion is not possible . |
17,737 | public static AnyValueMap fromValue ( Object value ) { AnyValueMap result = new AnyValueMap ( ) ; result . setAsObject ( value ) ; return result ; } | Converts specified value into AnyValueMap . |
17,738 | public void registerService ( ProvidedServiceInstance serviceInstance ) { getServiceDirectoryClient ( ) . registerServiceInstance ( serviceInstance ) ; getCacheServiceInstances ( ) . put ( new ServiceInstanceToken ( serviceInstance . getServiceName ( ) , serviceInstance . getProviderId ( ) ) , new InstanceHealthPair ( null ) ) ; } | Register a ProvidedServiceInstance . |
17,739 | public void registerService ( ProvidedServiceInstance serviceInstance , ServiceInstanceHealth registryHealth ) { registerService ( serviceInstance ) ; getCacheServiceInstances ( ) . put ( new ServiceInstanceToken ( serviceInstance . getServiceName ( ) , serviceInstance . getProviderId ( ) ) , new InstanceHealthPair ( registryHealth ) ) ; } | Register a ProvidedServiceInstance with the OperationalStatus and the ServiceInstanceHealth callback . |
17,740 | public void updateServiceUri ( String serviceName , String providerId , String uri ) { getServiceDirectoryClient ( ) . updateServiceInstanceUri ( serviceName , providerId , uri ) ; } | Update the uri of the ProvidedServiceInstance by serviceName and providerId . |
17,741 | public void updateServiceOperationalStatus ( String serviceName , String providerId , OperationalStatus status ) { getServiceDirectoryClient ( ) . updateServiceInstanceStatus ( serviceName , providerId , status ) ; } | Update the OperationalStatus of the ProvidedServiceInstance by serviceName and providerId . |
17,742 | public void unregisterService ( String serviceName , String providerId ) { getServiceDirectoryClient ( ) . unregisterServiceInstance ( serviceName , providerId ) ; getCacheServiceInstances ( ) . remove ( new ServiceInstanceToken ( serviceName , providerId ) ) ; } | Unregister a ProvidedServiceInstance by serviceName and providerId . |
17,743 | public List < Permission > getUserPermission ( String userName ) { ACL acl = getServiceDirectoryClient ( ) . getACL ( AuthScheme . DIRECTORY , userName ) ; int permissionId = 0 ; if ( acl != null ) { permissionId = acl . getPermission ( ) ; } return PermissionUtil . id2Permissions ( permissionId ) ; } | Get the user permission . |
17,744 | private Map < ServiceInstanceToken , InstanceHealthPair > getCacheServiceInstances ( ) { if ( instanceCache == null ) { synchronized ( this ) { if ( instanceCache == null ) { instanceCache = new ConcurrentHashMap < ServiceInstanceToken , InstanceHealthPair > ( ) ; initJobTasks ( ) ; } } } return instanceCache ; } | Get the CachedProviderServiceInstance Set . |
17,745 | private void initJobTasks ( ) { healthJob = Executors . newSingleThreadScheduledExecutor ( new ThreadFactory ( ) { public Thread newThread ( Runnable r ) { Thread t = new Thread ( r ) ; t . setName ( "SD API RegistryHealth Check" ) ; t . setDaemon ( true ) ; return t ; } } ) ; int rhDelay = Configurations . getInt ( SD_API_REGISTRY_HEALTH_CHECK_DELAY_PROPERTY , SD_API_REGISTRY_HEALTH_CHECK_DELAY_DEFAULT ) ; int rhInterval = Configurations . getInt ( SD_API_REGISTRY_HEALTH_CHECK_INTERVAL_PROPERTY , SD_API_REGISTRY_HEALTH_CHECK_INTERVAL_DEFAULT ) ; LOGGER . info ( "Start the SD API RegistryHealth Task scheduler, delay=" + rhDelay + ", interval=" + rhInterval ) ; healthJob . scheduleAtFixedRate ( new HealthCheckTask ( ) , rhDelay , rhInterval , TimeUnit . SECONDS ) ; } | initialize the Heartbeat task and Health Check task . It invoked in the getCacheServiceInstances method which is thread safe no synchronized needed . |
17,746 | public static long [ ] allocate ( long amount , int ... ratios ) { if ( ( ratios == null ) || ( ratios . length == 0 ) ) { throw new IllegalArgumentException ( "At least one ratio value needs to be provided." ) ; } int total = 0 ; for ( int i = 0 ; i < ratios . length ; i ++ ) total += ratios [ i ] ; if ( total <= 0 ) { throw new IllegalArgumentException ( "The sum of all ratios need to be greater than zero!" ) ; } long remainder = amount ; long [ ] results = new long [ ratios . length ] ; for ( int i = 0 ; i < results . length ; i ++ ) { results [ i ] = amount * ratios [ i ] / total ; remainder -= results [ i ] ; } for ( int i = 0 ; i < remainder ; i ++ ) { results [ i ] ++ ; } return results ; } | Splits a long value into an array of long values which sum up to the original value but are splitted into amounts given by ratios . |
17,747 | public static void queuePacket ( Packet packet ) { if ( isEnabled ) { if ( LOGGER . isDebugEnabled ( ) ) { LOGGER . debug ( "queue packet latency = " + ( System . currentTimeMillis ( ) - packet . getCreateTime ( ) ) ) ; } } } | Collect the queue Packet latency . |
17,748 | public static boolean deleteRecursive ( File file ) { if ( ! file . exists ( ) ) { return false ; } if ( file . isDirectory ( ) ) { for ( File child : file . listFiles ( ) ) { deleteRecursive ( child ) ; } } return file . delete ( ) ; } | Deletes specified file from the file system recursively if directory |
17,749 | public static void copy ( InputStream is , File file ) throws IOException { Asserts . notNullParameter ( "is" , is ) ; Asserts . notNullParameter ( "file" , file ) ; FileOutputStream os = null ; os = new FileOutputStream ( file ) ; copy ( is , os ) ; } | save data from the specified input stream to file |
17,750 | public static void copy ( InputStream is , OutputStream os ) throws IOException { Asserts . notNullParameter ( "is" , is ) ; Asserts . notNullParameter ( "os" , os ) ; try { byte [ ] buf = new byte [ 1024 ] ; int len = 0 ; while ( ( len = is . read ( buf ) ) > 0 ) { os . write ( buf , 0 , len ) ; } } finally { if ( os != null ) { try { os . close ( ) ; } catch ( IOException e ) { } } if ( is != null ) { try { is . close ( ) ; } catch ( IOException e ) { } } } } | copy data from the specified input stream to the specified output stream |
17,751 | public com . simiacryptus . util . io . MarkdownNotebookOutput setAbsoluteUrl ( final String absoluteUrl ) { this . absoluteUrl = absoluteUrl ; return this ; } | Sets absolute url . |
17,752 | public String linkTo ( final File file ) throws IOException { return codeFile ( file ) ; } | Link to string . |
17,753 | public Map < String , ThreadPoolStatus > getStatusOfThreadPools ( ) { Map < String , ThreadPoolStatus > result = new TreeMap < String , ThreadPoolStatus > ( ) ; for ( Map . Entry < String , ? extends ThreadPoolExecutor > entry : threadPools . entrySet ( ) ) { ThreadPoolStatus status = new ThreadPoolStatus ( ) ; status . setName ( entry . getKey ( ) ) ; ThreadPoolExecutor pool = entry . getValue ( ) ; status . setActive ( pool . getActiveCount ( ) ) ; status . setKeepAliveSeconds ( pool . getKeepAliveTime ( TimeUnit . SECONDS ) ) ; status . setLargestSize ( pool . getLargestPoolSize ( ) ) ; status . setMaxSize ( pool . getMaximumPoolSize ( ) ) ; status . setSize ( pool . getPoolSize ( ) ) ; status . setQueueLength ( pool . getQueue ( ) . size ( ) ) ; result . put ( entry . getKey ( ) , status ) ; } return result ; } | Get current status of all the thread pools |
17,754 | public static boolean isOnSameLine ( Area a1 , Area a2 , int threshold ) { final Rectangular gp1 = a1 . getBounds ( ) ; final Rectangular gp2 = a2 . getBounds ( ) ; return ( Math . abs ( gp1 . getY1 ( ) - gp2 . getY1 ( ) ) <= threshold && Math . abs ( gp1 . getY2 ( ) - gp2 . getY2 ( ) ) <= threshold ) ; } | Checks if the given areas are on the same line . |
17,755 | public boolean isSeparatorAt ( int x , int y ) { return containsSeparatorAt ( x , y , bsep ) || containsSeparatorAt ( x , y , hsep ) || containsSeparatorAt ( x , y , vsep ) ; } | Checks if a point is covered by a separator . |
17,756 | protected void filterMarginalSeparators ( ) { for ( Iterator < Separator > it = hsep . iterator ( ) ; it . hasNext ( ) ; ) { Separator sep = it . next ( ) ; if ( sep . getY1 ( ) == root . getY1 ( ) || sep . getY2 ( ) == root . getY2 ( ) ) it . remove ( ) ; } for ( Iterator < Separator > it = vsep . iterator ( ) ; it . hasNext ( ) ; ) { Separator sep = it . next ( ) ; if ( sep . getX1 ( ) == root . getX1 ( ) || sep . getX2 ( ) == root . getX2 ( ) ) it . remove ( ) ; } } | Removes the separators that are placed on the area borders . |
17,757 | protected void filterSeparators ( ) { int hthreshold = getMinHSepHeight ( ) ; int vthreshold = getMinVSepWidth ( ) ; for ( Iterator < Separator > it = hsep . iterator ( ) ; it . hasNext ( ) ; ) { Separator sep = it . next ( ) ; AreaImpl above = root . findContentAbove ( sep ) ; if ( above != null ) hthreshold = ( int ) ( above . getFontSize ( ) * HSEP_MIN_HEIGHT ) ; else hthreshold = ( int ) ( root . getFontSize ( ) * HSEP_MIN_HEIGHT ) ; if ( sep . getWeight ( ) < hthreshold ) it . remove ( ) ; else if ( sep . getWidth ( ) / ( double ) sep . getHeight ( ) < SEP_MIN_RATIO ) it . remove ( ) ; } for ( Iterator < Separator > it = vsep . iterator ( ) ; it . hasNext ( ) ; ) { Separator sep = it . next ( ) ; if ( sep . getWeight ( ) < vthreshold ) it . remove ( ) ; else if ( sep . getHeight ( ) / ( double ) sep . getWidth ( ) < SEP_MIN_RATIO ) it . remove ( ) ; } } | Removes all the separators where the weight is lower than the specified threshold . |
17,758 | protected void processIntersectionsSplitHorizontal ( ) { boolean change ; do { Vector < Separator > newsep = new Vector < Separator > ( hsep . size ( ) ) ; change = false ; for ( Separator hs : hsep ) { boolean split = false ; for ( Separator vs : vsep ) { if ( hs . intersects ( vs ) ) { Separator nhs = hs . hsplit ( vs ) ; newsep . add ( hs ) ; if ( nhs != null ) newsep . add ( nhs ) ; split = true ; change = true ; break ; } } if ( ! split ) newsep . add ( hs ) ; } hsep = newsep ; } while ( change ) ; } | Processes the separators so that they do not intersect . The vertical separators are left untouched the horizontal separators are split by the vertical ones when necessary . |
17,759 | protected void processIntersectionsRemoveHorizontal ( ) { for ( Iterator < Separator > hit = hsep . iterator ( ) ; hit . hasNext ( ) ; ) { Separator hs = hit . next ( ) ; for ( Separator vs : vsep ) { if ( hs . intersects ( vs ) ) { hit . remove ( ) ; break ; } } } } | Processes the separators so that they do not intersect . The vertical separators are left untouched the horizontal separators are removed when they intersect with a vertical one . |
17,760 | private void findAreaSeparators ( AreaImpl root ) { bsep = new Vector < Separator > ( ) ; for ( int i = 0 ; i < root . getChildCount ( ) ; i ++ ) { Area child = root . getChildAt ( i ) ; if ( child instanceof AreaImpl ) analyzeAreaSeparators ( ( AreaImpl ) child ) ; } } | Creates a list of separators that are implemented as visual area borders . |
17,761 | private void analyzeAreaSeparators ( AreaImpl area ) { boolean isep = area . isExplicitlySeparated ( ) || area . isBackgroundSeparated ( ) ; if ( isep || area . separatedUp ( ) ) bsep . add ( new Separator ( Separator . BOXH , area . getX1 ( ) , area . getY1 ( ) , area . getX2 ( ) , area . getY1 ( ) + ART_SEP_WIDTH - 1 ) ) ; if ( isep || area . separatedDown ( ) ) bsep . add ( new Separator ( Separator . BOXH , area . getX1 ( ) , area . getY2 ( ) - ART_SEP_WIDTH + 1 , area . getX2 ( ) , area . getY2 ( ) ) ) ; if ( isep || area . separatedLeft ( ) ) bsep . add ( new Separator ( Separator . BOXV , area . getX1 ( ) , area . getY1 ( ) , area . getX1 ( ) + ART_SEP_WIDTH - 1 , area . getY2 ( ) ) ) ; if ( isep || area . separatedRight ( ) ) bsep . add ( new Separator ( Separator . BOXV , area . getX2 ( ) - ART_SEP_WIDTH + 1 , area . getY1 ( ) , area . getX2 ( ) , area . getY2 ( ) ) ) ; } | Analyzes the area and detects the separators that are implemented as borders or background changes . |
17,762 | public Area findBasicAreas ( ) { AreaImpl rootarea = new AreaImpl ( 0 , 0 , 0 , 0 ) ; setRoot ( rootarea ) ; rootarea . setAreaTree ( this ) ; rootarea . setPage ( page ) ; for ( int i = 0 ; i < page . getRoot ( ) . getChildCount ( ) ; i ++ ) { Box cbox = page . getRoot ( ) . getChildAt ( i ) ; Area sub = new AreaImpl ( cbox ) ; if ( sub . getWidth ( ) > 1 || sub . getHeight ( ) > 1 ) { findStandaloneAreas ( page . getRoot ( ) . getChildAt ( i ) , sub ) ; rootarea . appendChild ( sub ) ; } } createGrids ( rootarea ) ; return rootarea ; } | Creates the area tree skeleton - selects the visible boxes and converts them to areas |
17,763 | private void findStandaloneAreas ( Box boxroot , Area arearoot ) { if ( boxroot . isVisible ( ) ) { for ( int i = 0 ; i < boxroot . getChildCount ( ) ; i ++ ) { Box child = boxroot . getChildAt ( i ) ; if ( child . isVisible ( ) ) { if ( isVisuallySeparated ( child ) ) { Area newnode = new AreaImpl ( child ) ; if ( newnode . getWidth ( ) > 1 || newnode . getHeight ( ) > 1 ) { findStandaloneAreas ( child , newnode ) ; arearoot . appendChild ( newnode ) ; } } else findStandaloneAreas ( child , arearoot ) ; } } } } | Goes through a box tree and tries to identify the boxes that form standalone visual areas . From these boxes new areas are created which are added to the area tree . Other boxes are ignored . |
17,764 | public static String getIndent ( final String txt ) { final Matcher matcher = Pattern . compile ( "^\\s+" ) . matcher ( txt ) ; return matcher . find ( ) ? matcher . group ( 0 ) : "" ; } | Gets indent . |
17,765 | public static String getInnerText ( final StackTraceElement callingFrame ) throws IOException { try { final File file = com . simiacryptus . util . lang . CodeUtil . findFile ( callingFrame ) ; assert null != file ; final int start = callingFrame . getLineNumber ( ) - 1 ; final List < String > allLines = Files . readAllLines ( file . toPath ( ) ) ; final String txt = allLines . get ( start ) ; final String indent = com . simiacryptus . util . lang . CodeUtil . getIndent ( txt ) ; final ArrayList < String > lines = new ArrayList < > ( ) ; for ( int i = start + 1 ; i < allLines . size ( ) && ( com . simiacryptus . util . lang . CodeUtil . getIndent ( allLines . get ( i ) ) . length ( ) > indent . length ( ) || allLines . get ( i ) . trim ( ) . isEmpty ( ) ) ; i ++ ) { final String line = allLines . get ( i ) ; lines . add ( line . substring ( Math . min ( indent . length ( ) , line . length ( ) ) ) ) ; } return lines . stream ( ) . collect ( Collectors . joining ( "\n" ) ) ; } catch ( final Throwable e ) { return "" ; } } | Gets heapCopy text . |
17,766 | public static String getJavadoc ( final Class < ? > clazz ) { try { if ( null == clazz ) return null ; final File source = com . simiacryptus . util . lang . CodeUtil . findFile ( clazz ) ; if ( null == source ) return clazz . getName ( ) + " not found" ; final List < String > lines = IOUtils . readLines ( new FileInputStream ( source ) , Charset . forName ( "UTF-8" ) ) ; final int classDeclarationLine = IntStream . range ( 0 , lines . size ( ) ) . filter ( i -> lines . get ( i ) . contains ( "class " + clazz . getSimpleName ( ) ) ) . findFirst ( ) . getAsInt ( ) ; final int firstLine = IntStream . rangeClosed ( 1 , classDeclarationLine ) . map ( i -> classDeclarationLine - i ) . filter ( i -> ! lines . get ( i ) . matches ( "\\s*[/\\*@].*" ) ) . findFirst ( ) . orElse ( - 1 ) + 1 ; final String javadoc = lines . subList ( firstLine , classDeclarationLine ) . stream ( ) . filter ( s -> s . matches ( "\\s*[/\\*].*" ) ) . map ( s -> s . replaceFirst ( "^[ \t]*[/\\*]+" , "" ) . trim ( ) ) . filter ( x -> ! x . isEmpty ( ) ) . reduce ( ( a , b ) -> a + "\n" + b ) . orElse ( "" ) ; return javadoc . replaceAll ( "<p>" , "\n" ) ; } catch ( final Throwable e ) { e . printStackTrace ( ) ; return "" ; } } | Gets javadoc . |
17,767 | public void addSubItem ( WebMenuItem item ) { if ( subMenu == null ) { subMenu = new ArrayList < WebMenuItem > ( ) ; } subMenu . add ( item ) ; } | Add a MenuItem as the last one in its sub - menu . |
17,768 | public void put ( Object locator , Object component ) { if ( locator == null ) throw new NullPointerException ( "Locator cannot be null" ) ; if ( component == null ) throw new NullPointerException ( "Reference cannot be null" ) ; synchronized ( _lock ) { _references . add ( new Reference ( locator , component ) ) ; } } | Puts a new reference into this reference map . |
17,769 | public List < Object > removeAll ( Object locator ) { List < Object > components = new ArrayList < Object > ( ) ; if ( locator == null ) return components ; synchronized ( _lock ) { for ( int index = _references . size ( ) - 1 ; index >= 0 ; index -- ) { Reference reference = _references . get ( index ) ; if ( reference . match ( locator ) ) { _references . remove ( index ) ; components . add ( reference . getComponent ( ) ) ; } } } return components ; } | Removes all component references that match the specified locator . |
17,770 | public List < Object > getAllLocators ( ) { List < Object > locators = new ArrayList < Object > ( ) ; synchronized ( _lock ) { for ( Reference reference : _references ) locators . add ( reference . getLocator ( ) ) ; } return locators ; } | Gets locators for all registered component references in this reference map . |
17,771 | public List < Object > getAll ( ) { List < Object > components = new ArrayList < Object > ( ) ; synchronized ( _lock ) { for ( Reference reference : _references ) components . add ( reference . getComponent ( ) ) ; } return components ; } | Gets all component references registered in this reference map . |
17,772 | public Object getOneOptional ( Object locator ) { try { List < Object > components = find ( Object . class , locator , false ) ; return components . size ( ) > 0 ? components . get ( 0 ) : null ; } catch ( Exception ex ) { return null ; } } | Gets an optional component reference that matches specified locator . |
17,773 | public < T > T getOneOptional ( Class < T > type , Object locator ) { try { List < T > components = find ( type , locator , false ) ; return components . size ( ) > 0 ? components . get ( 0 ) : null ; } catch ( Exception ex ) { return null ; } } | Gets an optional component reference that matches specified locator and matching to the specified type . |
17,774 | public Object getOneRequired ( Object locator ) throws ReferenceException { List < Object > components = find ( Object . class , locator , true ) ; return components . size ( ) > 0 ? components . get ( 0 ) : null ; } | Gets a required component reference that matches specified locator . |
17,775 | public < T > T getOneRequired ( Class < T > type , Object locator ) throws ReferenceException { List < T > components = find ( type , locator , true ) ; return components . size ( ) > 0 ? components . get ( 0 ) : null ; } | Gets a required component reference that matches specified locator and matching to the specified type . |
17,776 | public List < Object > getRequired ( Object locator ) throws ReferenceException { return find ( Object . class , locator , true ) ; } | Gets all component references that match specified locator . At least one component reference must be present . If it doesn t the method throws an error . |
17,777 | public < T > List < T > getRequired ( Class < T > type , Object locator ) throws ReferenceException { return find ( type , locator , true ) ; } | Gets all component references that match specified locator . At least one component reference must be present and matching to the specified type . |
17,778 | public String getLine ( ) { if ( preLoaded ) { if ( bufferOffset >= 0 ) { int lineStart = bufferOffset ; if ( linePos > 0 ) { lineStart -= linePos - 1 ; } int lineEnd = bufferOffset ; while ( lineEnd < bufferLimit && buffer [ lineEnd ] != '\n' ) { ++ lineEnd ; } return new String ( buffer , lineStart , lineEnd - lineStart ) ; } } else if ( bufferLimit > 0 ) { if ( Math . abs ( ( linePos - 1 ) - bufferOffset ) < 2 ) { return new String ( buffer , 0 , bufferLimit - ( bufferLineEnd ? 1 : 0 ) ) ; } } return "" ; } | Returns the current line in the buffer . Or empty string if not usable . |
17,779 | public String getRestOfLine ( ) throws IOException { if ( preLoaded ) { if ( bufferOffset < 0 || buffer [ bufferOffset ] == '\n' || ( lastChar == 0 && ! readNextChar ( ) ) ) { return "" ; } int start = bufferOffset ; int length = 1 ; while ( readNextChar ( ) ) { if ( lastChar == '\n' ) { lastChar = 0 ; break ; } ++ length ; } return new String ( buffer , start , length ) ; } if ( bufferOffset < 0 || buffer [ bufferOffset ] == '\n' || bufferOffset >= ( bufferLimit - 1 ) || ( lastChar == 0 && ! readNextChar ( ) ) ) { return "" ; } maybeConsolidateBuffer ( ) ; StringBuilder remainderBuilder = new StringBuilder ( ) ; do { int unreadChars = bufferLimit - bufferOffset ; remainderBuilder . append ( buffer , bufferOffset , unreadChars - ( bufferLineEnd ? 1 : 0 ) ) ; bufferOffset = bufferLimit ; linePos += unreadChars ; if ( bufferLineEnd ) { break ; } maybeConsolidateBuffer ( ) ; } while ( bufferOffset < ( bufferLimit - 1 ) ) ; lastChar = 0 ; return remainderBuilder . toString ( ) ; } | Return the rest of the current line . This is handy for handling unwanted content after the last expected token or character . |
17,780 | public List < String > getRemainingLines ( boolean trimAndSkipEmpty ) throws IOException { List < String > out = new ArrayList < > ( ) ; StringBuilder builder = new StringBuilder ( ) ; while ( bufferOffset <= bufferLimit || ! bufferLineEnd ) { if ( ! readNextChar ( ) ) { break ; } if ( lastChar == '\n' ) { String line = builder . toString ( ) ; if ( ! trimAndSkipEmpty || ! line . trim ( ) . isEmpty ( ) ) { out . add ( trimAndSkipEmpty ? line . trim ( ) : line ) ; } builder = new StringBuilder ( ) ; } else { builder . append ( ( char ) lastChar ) ; } } if ( builder . length ( ) > 0 ) { String line = builder . toString ( ) ; if ( ! trimAndSkipEmpty || ! line . trim ( ) . isEmpty ( ) ) { out . add ( builder . toString ( ) ) ; } } return out ; } | Read the rest of input from the reader and get the lines from there . This will consume the rest of the content of the reader . |
17,781 | private Object readResolve ( ) { if ( linkName == null ) { linkName = Messages . _Warnings_ProjectAction_Name ( ) . toString ( Locale . ENGLISH ) ; } if ( trendName == null ) { trendName = Messages . _Warnings_Trend_Name ( ) . toString ( Locale . ENGLISH ) ; } parser = createParser ( ) ; return this ; } | Adds link and trend names for 3 . x serializations . |
17,782 | public static void deleteRecursively ( Path path ) throws IOException { if ( Files . isDirectory ( path ) ) { Files . list ( path ) . forEach ( file -> { try { deleteRecursively ( file ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e . getMessage ( ) , e ) ; } } ) ; } Files . delete ( path ) ; } | Delete the file or directory recursively . |
17,783 | public Error getError ( ) { if ( isOk ( ) ) return error ; try { JAXBContext context = JAXBContext . newInstance ( Error . class ) ; Unmarshaller unmarshaller = context . createUnmarshaller ( ) ; StringReader xml = new StringReader ( content ) ; if ( ! content . isEmpty ( ) ) error = ( Error ) unmarshaller . unmarshal ( new StreamSource ( xml ) ) ; } catch ( JAXBException e ) { e . printStackTrace ( ) ; } return error ; } | Return an Error object with the error that have occurred or null . |
17,784 | public String stringAt ( String srcStr , int index ) { if ( 0 <= index && index < srcStr . length ( ) ) { return String . valueOf ( srcStr . charAt ( index ) ) ; } else { return "" ; } } | returns string at index |
17,785 | public String removeTail ( String srcStr , int charCount ) { return getLeftOf ( srcStr , srcStr . length ( ) - charCount ) ; } | Return the rest of the string that is cropped the number of chars from the end of string |
17,786 | public String removeHead ( String srcStr , int charCount ) { return getRightOf ( srcStr , srcStr . length ( ) - charCount ) ; } | Return the rest of the string that is cropped the number of chars from the beginning |
17,787 | public String getLeftOf ( String srcStr , int charCount ) { String retValue = "" ; if ( isNotBlank ( srcStr ) ) { int length = srcStr . length ( ) ; if ( charCount < length ) { retValue = srcStr . substring ( 0 , charCount ) ; } else { retValue = srcStr ; } } return retValue ; } | Returns the number of characters specified from left |
17,788 | public String getRightOf ( String srcStr , int charCount ) { String retVal = "" ; if ( isNotBlank ( srcStr ) ) { int length = srcStr . length ( ) ; if ( charCount < length ) { retVal = srcStr . substring ( length - charCount , length ) ; } else { retVal = srcStr ; } } else { } return retVal ; } | Returns the number of characters specified from right |
17,789 | public void setAsObject ( String key , Object value ) { put ( key , StringConverter . toNullableString ( value ) ) ; } | Sets a new value to map element specified by its index . When the index is not defined it resets the entire map value . This method has double purpose because method overrides are not supported in JavaScript . |
17,790 | public static StringValueMap fromString ( String line ) { StringValueMap result = new StringValueMap ( ) ; if ( line == null || line . length ( ) == 0 ) return result ; String [ ] tokens = line . split ( ";" , - 1 ) ; for ( String token : tokens ) { if ( token . length ( ) == 0 ) continue ; int index = token . indexOf ( '=' ) ; String key = index > 0 ? token . substring ( 0 , index ) . trim ( ) : token . trim ( ) ; String val = index > 0 ? token . substring ( index + 1 ) . trim ( ) : null ; result . put ( key , val ) ; } return result ; } | Parses semicolon - separated key - value pairs and returns them as a StringValueMap . |
17,791 | public void reinitServiceDirectoryManagerFactory ( ServiceDirectoryManagerFactory factory ) throws ServiceException { if ( factory == null ) { throw new IllegalArgumentException ( "The ServiceDirectoryManagerFactory cannot be NULL." ) ; } synchronized ( this ) { if ( isShutdown ) { ServiceDirectoryError error = new ServiceDirectoryError ( ErrorCode . SERVICE_DIRECTORY_IS_SHUTDOWN ) ; throw new ServiceException ( error ) ; } if ( this . directoryManagerFactory != null ) { if ( directoryManagerFactory instanceof Closable ) { ( ( Closable ) directoryManagerFactory ) . stop ( ) ; } LOGGER . info ( "Resetting ServiceDirectoryManagerFactory, old=" + this . directoryManagerFactory . getClass ( ) . getName ( ) + ", new=" + factory . getClass ( ) . getName ( ) + "." ) ; this . directoryManagerFactory = factory ; } else { this . directoryManagerFactory = factory ; LOGGER . info ( "Setting ServiceDirectoryManagerFactory, factory=" + factory . getClass ( ) . getName ( ) + "." ) ; } this . directoryManagerFactory . initialize ( this ) ; } } | Set the ServiceDirectoryManagerFactory in the sd - api . |
17,792 | public void shutdown ( ) { synchronized ( this ) { if ( ! isShutdown ) { if ( directoryManagerFactory != null ) { if ( directoryManagerFactory instanceof Closable ) { ( ( Closable ) directoryManagerFactory ) . stop ( ) ; } directoryManagerFactory = null ; } if ( client != null ) { client . close ( ) ; client = null ; } this . isShutdown = true ; } } } | Shutdown the ServiceDirectory and the ServiceDirectoryManagerFactory . |
17,793 | @ Requires ( "element != null" ) @ Ensures ( "result != null" ) TypeName getGenericTypeName ( TypeParameterElement element ) { String name = element . getSimpleName ( ) . toString ( ) ; List < ? extends TypeMirror > bounds = element . getBounds ( ) ; if ( bounds . isEmpty ( ) || ( bounds . size ( ) == 1 && bounds . get ( 0 ) . toString ( ) . equals ( "java.lang.Object" ) ) ) { return new TypeName ( name ) ; } StringBuilder buffer = new StringBuilder ( ) ; buffer . append ( name ) ; buffer . append ( " extends " ) ; Iterator < ? extends TypeMirror > iter = bounds . iterator ( ) ; for ( ; ; ) { buffer . append ( iter . next ( ) . toString ( ) ) ; if ( ! iter . hasNext ( ) ) { break ; } buffer . append ( " & " ) ; } return new TypeName ( buffer . toString ( ) ) ; } | Returns a Java - printable generic type name from the specified TypeParameterElement . |
17,794 | ElementKind getAnnotationKindForName ( AnnotationMirror annotation ) { String annotationName = annotation . getAnnotationType ( ) . toString ( ) ; ElementKind kind ; if ( annotationName . equals ( "com.google.java.contract.Invariant" ) ) { kind = ElementKind . INVARIANT ; } else if ( annotationName . equals ( "com.google.java.contract.Requires" ) ) { kind = ElementKind . REQUIRES ; } else if ( annotationName . equals ( "com.google.java.contract.Ensures" ) ) { kind = ElementKind . ENSURES ; } else if ( annotationName . equals ( "com.google.java.contract.ThrowEnsures" ) ) { kind = ElementKind . THROW_ENSURES ; } else { kind = null ; } return kind ; } | Gets the contract kind of an annotation given its qualified name . Returns null if the annotation is not a contract annotation . |
17,795 | private void getAllServices ( ) { try { List < ModelServiceInstance > instances = new DirectoryServiceRestfulClient ( ) . getAllInstances ( ) ; for ( ModelServiceInstance instance : instances ) { printServiceInstance ( ServiceInstanceUtils . toServiceInstance ( instance ) ) ; } } catch ( ServiceException e ) { e . printStackTrace ( ) ; fail ( e . getServiceDirectoryError ( ) . getErrorMessage ( ) ) ; } } | Do the getAllServices command . |
17,796 | private void lookupInstance ( String args [ ] ) { String serviceName = args [ 1 ] ; System . out . println ( "lookupInstance, serviceName=" + serviceName ) ; try { ServiceInstance instance = ServiceDirectory . getLookupManager ( ) . lookupInstance ( serviceName ) ; printServiceInstance ( instance ) ; } catch ( ServiceException e ) { e . printStackTrace ( ) ; fail ( e . getServiceDirectoryError ( ) . getErrorMessage ( ) ) ; } } | Do the lookupInstance command . |
17,797 | private void lookupInstances ( String args [ ] ) { String serviceName = args [ 1 ] ; System . out . println ( "lookupInstances, serviceName=" + serviceName ) ; try { List < ServiceInstance > instances = ServiceDirectory . getLookupManager ( ) . lookupInstances ( serviceName ) ; if ( instances . size ( ) == 0 ) { print ( "" ) ; } else { for ( ServiceInstance instance : instances ) { printServiceInstance ( instance ) ; } } } catch ( ServiceException e ) { e . printStackTrace ( ) ; fail ( e . getServiceDirectoryError ( ) . getErrorMessage ( ) ) ; } } | Do the lookupInstances command . |
17,798 | private ProvidedServiceInstance jsonToProvidedServiceInstance ( String jsonString ) throws JsonParseException , JsonMappingException , IOException { return deserialize ( jsonString . getBytes ( ) , ProvidedServiceInstance . class ) ; } | Convert the ProvidedServiceInstance Json String to ProvidedServiceInstance . |
17,799 | private void printServiceInstance ( ServiceInstance instance ) { print ( "\nServiceInstance\n-------------------------" ) ; if ( instance == null ) { print ( "null" ) ; return ; } print ( "serviceName: " + instance . getServiceName ( ) ) ; print ( "status: " + instance . getStatus ( ) ) ; print ( "uri: " + instance . getUri ( ) ) ; print ( "address: " + instance . getAddress ( ) ) ; print ( "monitorEnabled: " + instance . isMonitorEnabled ( ) ) ; print ( "metadata:" ) ; Map < String , String > meta = instance . getMetadata ( ) ; for ( Entry < String , String > entry : meta . entrySet ( ) ) { print ( " " + entry . getKey ( ) + " => " + entry . getValue ( ) ) ; } } | Print the ServiceInstance to console . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.