idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
4,000
public int getNextVisualPositionFrom ( int pos , Position . Bias b , Shape a , int direction , Position . Bias [ ] biasRet ) throws BadLocationException { if ( view != null ) { int nextPos = view . getNextVisualPositionFrom ( pos , b , a , direction , biasRet ) ; if ( nextPos != - 1 ) { pos = nextPos ; } else { biasRet [ 0 ] = b ; } } return pos ; }
Provides a way to determine the next visually represented model location that one might place a caret . Some views may not be visible they might not be in the same order found in the model or they just might not allow access to some of the locations in the model .
4,001
public void setSize ( float width , float height ) { if ( view != null ) { view . setSize ( width , height ) ; } }
Sets the view size .
4,002
private void updateCommitted ( ) { List < Long > sorted = newArrayList ( ) ; for ( ReplicaManager manager : managers . values ( ) ) { sorted . add ( manager . getMatchIndex ( ) ) ; } sorted . add ( getLog ( ) . lastLogIndex ( ) ) ; Collections . sort ( sorted ) ; int n = sorted . size ( ) ; int quorumSize = ( n / 2 ) + 1 ; final long committed = sorted . get ( quorumSize - 1 ) ; LOGGER . debug ( "updating commitIndex to {}; sorted is {}" , committed , sorted ) ; getLog ( ) . commitIndex ( committed ) ; }
Find the median value of the list of matchIndex this value is the committedIndex since by definition half of the matchIndex values are greater and half are less than this value . So at least half of the replicas have stored the median value this is the definition of committed .
4,003
@ SuppressWarnings ( "rawtypes" ) public Object invokeMethod ( final Class sender , final Object receiver , final String methodName , final Object [ ] arguments , final boolean isCallToSuper , final boolean fromInsideClass ) { return invokeMethod ( receiver , methodName , arguments ) ; }
Invoke a method on the given receiver for the specified arguments . The sender is the class that invoked the method on the object . Attempt to establish the method to invoke based on the name and arguments provided .
4,004
public void setTarget ( final String t ) { final GantTarget gt = new GantTarget ( ) ; gt . setValue ( t ) ; targets . add ( gt ) ; }
Set the target to be achieved .
4,005
public void execute ( ) throws BuildException { final Project antProject = getOwningTarget ( ) . getProject ( ) ; final Project newProject = new Project ( ) ; newProject . init ( ) ; for ( final Object o : antProject . getBuildListeners ( ) ) { final BuildListener listener = ( BuildListener ) o ; if ( ! ( listener instanceof AntClassLoader ) ) { newProject . addBuildListener ( listener ) ; } } newProject . setBaseDir ( antProject . getBaseDir ( ) ) ; if ( inheritAll ) { addAlmostAll ( newProject , antProject ) ; } final File gantFile = newProject . resolveFile ( file ) ; if ( ! gantFile . exists ( ) ) { throw new BuildException ( "Gantfile does not exist." , getLocation ( ) ) ; } final GantBuilder ant = new GantBuilder ( newProject ) ; final Map < String , String > environmentParameter = new HashMap < String , String > ( ) ; environmentParameter . put ( "environment" , "environment" ) ; ant . invokeMethod ( "property" , new Object [ ] { environmentParameter } ) ; final GantBinding binding = new GantBinding ( ) ; binding . forcedSettingOfVariable ( "ant" , ant ) ; for ( final Definition definition : definitions ) { final Map < String , String > definitionParameter = new HashMap < String , String > ( ) ; definitionParameter . put ( "name" , definition . getName ( ) ) ; definitionParameter . put ( "value" , definition . getValue ( ) ) ; ant . invokeMethod ( "property" , new Object [ ] { definitionParameter } ) ; } final gant . Gant gant = new gant . Gant ( binding ) ; gant . loadScript ( gantFile ) ; final List < String > targetsAsStrings = new ArrayList < String > ( ) ; for ( final GantTarget g : targets ) { targetsAsStrings . add ( g . getValue ( ) ) ; } final int returnCode = gant . processTargets ( targetsAsStrings ) ; if ( returnCode != 0 ) { throw new BuildException ( "Gant execution failed with return code " + returnCode + '.' , getLocation ( ) ) ; } }
Load the file and then execute it .
4,006
private void addAlmostAll ( final Project newProject , final Project oldProject ) { final Hashtable < String , Object > properties = oldProject . getProperties ( ) ; final Enumeration < String > e = properties . keys ( ) ; while ( e . hasMoreElements ( ) ) { final String key = e . nextElement ( ) ; if ( ! ( MagicNames . PROJECT_BASEDIR . equals ( key ) || MagicNames . ANT_FILE . equals ( key ) ) ) { if ( newProject . getProperty ( key ) == null ) { newProject . setNewProperty ( key , ( String ) properties . get ( key ) ) ; } } } }
Russel Winder rehacked the code provided by Eric Van Dewoestine .
4,007
public Object invokeMethod ( final String name , final Object arguments ) { if ( GantState . dryRun ) { if ( GantState . verbosity > GantState . SILENT ) { final StringBuilder sb = new StringBuilder ( ) ; int padding = 9 - name . length ( ) ; if ( padding < 0 ) { padding = 0 ; } sb . append ( " " . substring ( 0 , padding ) + '[' + name + "] " ) ; final Object [ ] args = ( Object [ ] ) arguments ; if ( args [ 0 ] instanceof Map < ? , ? > ) { @ SuppressWarnings ( { "unchecked" , "rawtypes" } ) final Iterator < Map . Entry < ? , ? > > i = ( ( Map ) args [ 0 ] ) . entrySet ( ) . iterator ( ) ; while ( i . hasNext ( ) ) { final Map . Entry < ? , ? > e = i . next ( ) ; sb . append ( e . getKey ( ) + " : '" + e . getValue ( ) + '\'' ) ; if ( i . hasNext ( ) ) { sb . append ( ", " ) ; } } sb . append ( '\n' ) ; getProject ( ) . log ( sb . toString ( ) ) ; if ( args . length == 2 ) { ( ( Closure < ? > ) args [ 1 ] ) . call ( ) ; } } else if ( args [ 0 ] instanceof Closure ) { ( ( Closure < ? > ) args [ 0 ] ) . call ( ) ; } else { throw new RuntimeException ( "Unexpected type of parameter to method " + name ) ; } } return null ; } return super . invokeMethod ( name , arguments ) ; }
Invoke a method .
4,008
private boolean checkMerchant ( PurchaseDataModel details ) { if ( developerMerchantId == null ) return true ; if ( details . getPurchaseTime ( ) . before ( dateMerchantLimit1 ) ) return true ; if ( details . getPurchaseTime ( ) . after ( dateMerchantLimit2 ) ) return true ; if ( details . getOrderId ( ) == null || details . getOrderId ( ) . trim ( ) . length ( ) == 0 ) return false ; int index = details . getOrderId ( ) . indexOf ( '.' ) ; if ( index <= 0 ) return false ; String merchantId = details . getOrderId ( ) . substring ( 0 , index ) ; return merchantId . compareTo ( developerMerchantId ) == 0 ; }
Checks merchant s id validity . If purchase was generated by Freedom alike program it doesn t know real merchant id unless publisher GoogleId was hacked If merchantId was not supplied function checks nothing
4,009
protected static String getClassName ( ProgramElementDoc doc , boolean binaryName ) { PackageDoc containingPackage = doc . containingPackage ( ) ; String className = doc . name ( ) ; if ( binaryName ) { className = className . replaceAll ( "\\." , "\\$" ) ; } return containingPackage . name ( ) . length ( ) > 0 ? String . format ( "%s.%s" , containingPackage . name ( ) , className ) : String . format ( "%s" , className ) ; }
Reconstitute the class name from the given class JavaDoc object .
4,010
public String getSummaryForWorkUnit ( final DocWorkUnit workUnit ) { String summary = workUnit . getDocumentedFeature ( ) . summary ( ) ; if ( summary == null || summary . isEmpty ( ) ) { final CommandLineProgramProperties commandLineProperties = workUnit . getCommandLineProperties ( ) ; if ( commandLineProperties != null ) { summary = commandLineProperties . oneLineSummary ( ) ; } if ( summary == null || summary . isEmpty ( ) ) { summary = Arrays . stream ( workUnit . getClassDoc ( ) . firstSentenceTags ( ) ) . map ( tag -> tag . text ( ) ) . collect ( Collectors . joining ( ) ) ; } } return summary == null ? "" : summary ; }
Get the summary string to be used for a given work unit applying any fallback policy . This is called by the work unit handler after the work unit has been populated and may be overridden by subclasses to provide custom behavior .
4,011
public String getGroupNameForWorkUnit ( final DocWorkUnit workUnit ) { String groupName = workUnit . getDocumentedFeature ( ) . groupName ( ) ; if ( groupName == null || groupName . isEmpty ( ) ) { final CommandLineProgramGroup clpGroup = workUnit . getCommandLineProgramGroup ( ) ; if ( clpGroup != null ) { groupName = clpGroup . getName ( ) ; } if ( groupName == null || groupName . isEmpty ( ) ) { logger . warn ( "No group name declared for: " + workUnit . getClazz ( ) . getCanonicalName ( ) ) ; groupName = "" ; } } return groupName ; }
Get the group name string to be used for a given work unit applying any fallback policy . This is called by the work unit handler after the work unit has been populated and may be overridden by subclasses to provide custom behavior .
4,012
public String getGroupSummaryForWorkUnit ( final DocWorkUnit workUnit ) { String groupSummary = workUnit . getDocumentedFeature ( ) . groupSummary ( ) ; final CommandLineProgramGroup clpGroup = workUnit . getCommandLineProgramGroup ( ) ; if ( groupSummary == null || groupSummary . isEmpty ( ) ) { if ( clpGroup != null ) { groupSummary = clpGroup . getDescription ( ) ; } if ( groupSummary == null || groupSummary . isEmpty ( ) ) { logger . warn ( "No group summary declared for: " + workUnit . getClazz ( ) . getCanonicalName ( ) ) ; groupSummary = "" ; } } return groupSummary ; }
Get the group summary string to be used for a given work unit s group applying any fallback policy . This is called by the work unit handler after the work unit has been populated and may be overridden by subclasses to provide custom behavior .
4,013
protected String getDescription ( final DocWorkUnit currentWorkUnit ) { return Arrays . stream ( currentWorkUnit . getClassDoc ( ) . inlineTags ( ) ) . filter ( t -> getTagPrefix ( ) == null || ! t . name ( ) . startsWith ( getTagPrefix ( ) ) ) . map ( t -> t . text ( ) ) . collect ( Collectors . joining ( ) ) ; }
Return the description to be used for the work unit . We need to manually strip out any inline custom javadoc tags since we don t those in the summary .
4,014
protected void addHighLevelBindings ( final DocWorkUnit workUnit ) { workUnit . setProperty ( "name" , workUnit . getName ( ) ) ; workUnit . setProperty ( "group" , workUnit . getGroupName ( ) ) ; workUnit . setProperty ( "summary" , workUnit . getSummary ( ) ) ; workUnit . setProperty ( "beta" , workUnit . isBetaFeature ( ) ) ; workUnit . setProperty ( "experimental" , workUnit . isExperimentalFeature ( ) ) ; workUnit . setProperty ( "description" , getDescription ( workUnit ) ) ; workUnit . setProperty ( "version" , getDoclet ( ) . getBuildVersion ( ) ) ; workUnit . setProperty ( "timestamp" , getDoclet ( ) . getBuildTimeStamp ( ) ) ; }
Add high - level summary information such as name summary description version etc .
4,015
protected void addCustomBindings ( final DocWorkUnit currentWorkUnit ) { final String tagFilterPrefix = getTagPrefix ( ) ; Arrays . stream ( currentWorkUnit . getClassDoc ( ) . inlineTags ( ) ) . filter ( t -> t . name ( ) . startsWith ( tagFilterPrefix ) ) . forEach ( t -> currentWorkUnit . setProperty ( t . name ( ) . substring ( tagFilterPrefix . length ( ) ) , t . text ( ) ) ) ; }
Add any custom freemarker bindings discovered via custom javadoc tags . Subclasses can override this to provide additional custom bindings .
4,016
protected void addExtraDocsBindings ( final DocWorkUnit currentWorkUnit ) { final List < Map < String , Object > > extraDocsData = new ArrayList < Map < String , Object > > ( ) ; for ( final Class < ? > extraDocClass : currentWorkUnit . getDocumentedFeature ( ) . extraDocs ( ) ) { final DocWorkUnit otherUnit = getDoclet ( ) . findWorkUnitForClass ( extraDocClass ) ; if ( otherUnit != null ) { extraDocsData . add ( new HashMap < String , Object > ( ) { static final long serialVersionUID = 0L ; { put ( "name" , otherUnit . getName ( ) ) ; put ( "filename" , otherUnit . getTargetFileName ( ) ) ; } } ) ; } else { final String msg = String . format ( "An \"extradocs\" value (%s) was specified for (%s), but the target was not included in the " + "source list for this javadoc run, or the target has no documentation." , extraDocClass , currentWorkUnit . getName ( ) ) ; throw new DocException ( msg ) ; } } currentWorkUnit . setProperty ( "extradocs" , extraDocsData ) ; }
Add bindings describing related capabilities to currentWorkUnit
4,017
private Map < String , List < Map < String , Object > > > createArgumentMap ( ) { final Map < String , List < Map < String , Object > > > args = new HashMap < String , List < Map < String , Object > > > ( ) ; args . put ( "all" , new ArrayList < > ( ) ) ; args . put ( "common" , new ArrayList < > ( ) ) ; args . put ( "positional" , new ArrayList < > ( ) ) ; args . put ( "required" , new ArrayList < > ( ) ) ; args . put ( "optional" , new ArrayList < > ( ) ) ; args . put ( "advanced" , new ArrayList < > ( ) ) ; args . put ( "dependent" , new ArrayList < > ( ) ) ; args . put ( "hidden" , new ArrayList < > ( ) ) ; args . put ( "deprecated" , new ArrayList < > ( ) ) ; return args ; }
Create the argument map for holding class arguments
4,018
private List < Map < String , Object > > sortArguments ( final List < Map < String , Object > > unsorted ) { Collections . sort ( unsorted , new CompareArgumentsByName ( ) ) ; return unsorted ; }
Sorts the individual argument list in unsorted according to CompareArgumentsByName
4,019
private Object prettyPrintValueString ( final Object value ) { if ( value instanceof String ) { return value . equals ( "" ) ? "\"\"" : value ; } else { return value . toString ( ) ; } }
Pretty prints value
4,020
protected String argumentTypeString ( final Type type ) { if ( type instanceof ParameterizedType ) { final ParameterizedType parameterizedType = ( ParameterizedType ) type ; final List < String > subs = new ArrayList < > ( ) ; for ( final Type actualType : parameterizedType . getActualTypeArguments ( ) ) subs . add ( argumentTypeString ( actualType ) ) ; return argumentTypeString ( ( ( ParameterizedType ) type ) . getRawType ( ) ) + "[" + String . join ( "," , subs ) + "]" ; } else if ( type instanceof GenericArrayType ) { return argumentTypeString ( ( ( GenericArrayType ) type ) . getGenericComponentType ( ) ) + "[]" ; } else if ( type instanceof WildcardType ) { throw new RuntimeException ( "We don't support wildcards in arguments: " + type ) ; } else if ( type instanceof Class < ? > ) { return ( ( Class ) type ) . getSimpleName ( ) ; } else { throw new DocException ( "Unknown type: " + type ) ; } }
Returns a human readable string that describes the Type type of an argument .
4,021
private List < Map < String , Object > > docForEnumArgument ( final Class < ? > enumClass ) { final ClassDoc doc = this . getDoclet ( ) . getClassDocForClass ( enumClass ) ; if ( doc == null ) { throw new RuntimeException ( "Tried to get docs for enum " + enumClass + " but got null instead" ) ; } final Set < String > enumConstantFieldNames = enumConstantsNames ( enumClass ) ; final List < Map < String , Object > > bindings = new ArrayList < Map < String , Object > > ( ) ; for ( final FieldDoc fieldDoc : doc . fields ( false ) ) { if ( enumConstantFieldNames . contains ( fieldDoc . name ( ) ) ) { bindings . add ( new HashMap < String , Object > ( ) { static final long serialVersionUID = 0L ; { put ( "name" , fieldDoc . name ( ) ) ; put ( "summary" , fieldDoc . commentText ( ) ) ; } } ) ; } } return bindings ; }
Helper routine that provides a FreeMarker map for an enumClass grabbing the values of the enum and their associated javadoc documentation .
4,022
public static < T > JoinObservable < T > from ( Observable < T > o ) { return new JoinObservable < T > ( o ) ; }
Creates a JoinObservable from a regular Observable .
4,023
private static void prettyPrintWarningMessage ( final List < String > results , final String message ) { for ( final String line : message . split ( "\\r?\\n" ) ) { final StringBuilder builder = new StringBuilder ( line ) ; while ( builder . length ( ) > TEXT_WARNING_WIDTH ) { int space = getLastSpace ( builder , TEXT_WARNING_WIDTH ) ; if ( space <= 0 ) space = TEXT_WARNING_WIDTH ; results . add ( String . format ( "%s%s" , TEXT_WARNING_PREFIX , builder . substring ( 0 , space ) ) ) ; builder . delete ( 0 , space + 1 ) ; } results . add ( String . format ( "%s%s" , TEXT_WARNING_PREFIX , builder ) ) ; } }
pretty print the warning message supplied
4,024
private static int getLastSpace ( final CharSequence message , int width ) { final int length = message . length ( ) ; int stopPos = width ; int currPos = 0 ; int lastSpace = - 1 ; boolean inEscape = false ; while ( currPos < stopPos && currPos < length ) { final char c = message . charAt ( currPos ) ; if ( c == ESCAPE_CHAR ) { stopPos ++ ; inEscape = true ; } else if ( inEscape ) { stopPos ++ ; if ( Character . isLetter ( c ) ) inEscape = false ; } else if ( Character . isWhitespace ( c ) ) { lastSpace = currPos ; } currPos ++ ; } return lastSpace ; }
Returns the last whitespace location in string before width characters .
4,025
public static String dupString ( char c , int nCopies ) { char [ ] chars = new char [ nCopies ] ; Arrays . fill ( chars , c ) ; return new String ( chars ) ; }
Create a new string thats a n duplicate copies of c
4,026
public static String wrapParagraph ( final String input , final int width ) { if ( input == null || input . isEmpty ( ) ) { return input ; } final StringBuilder out = new StringBuilder ( ) ; try ( final BufferedReader bufReader = new BufferedReader ( new StringReader ( input ) ) ) { out . append ( bufReader . lines ( ) . map ( line -> WordUtils . wrap ( line , width ) ) . collect ( Collectors . joining ( "\n" ) ) ) ; } catch ( IOException e ) { throw new RuntimeException ( "Unreachable Statement.\nHow did the Buffered reader throw when it was " + "wrapping a StringReader?" , e ) ; } if ( input . charAt ( input . length ( ) - 1 ) == '\n' ) { out . append ( '\n' ) ; } return out . toString ( ) ; }
A utility method to wrap multiple lines of text while respecting the original newlines .
4,027
public void run ( ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "ListenerThread Starting." ) ; } while ( running ) { try { Socket clientSocket = serverSocket . accept ( ) ; WorkerThread worker = new WorkerThread ( container , clientSocket ) ; worker . start ( ) ; } catch ( SocketTimeoutException ste ) { } catch ( Exception e ) { if ( log . isErrorEnabled ( ) ) { log . error ( "Error Accepting: " + e . toString ( ) , e ) ; } } } try { serverSocket . close ( ) ; } catch ( IOException e ) { if ( log . isErrorEnabled ( ) ) { log . error ( "Error closing the server socket: " + e . toString ( ) , e ) ; } } }
ListenerThread execution begins .
4,028
public static boolean isConcrete ( Class < ? > clazz ) { return ! Modifier . isAbstract ( clazz . getModifiers ( ) ) && ! Modifier . isInterface ( clazz . getModifiers ( ) ) ; }
Is the specified class a concrete implementation of baseClass?
4,029
public static Field findField ( Class < ? > type , String fieldName ) { while ( type != null ) { Field [ ] fields = type . getDeclaredFields ( ) ; for ( Field field : fields ) { if ( field . getName ( ) . equals ( fieldName ) ) return field ; } type = type . getSuperclass ( ) ; } return null ; }
Find the field with the given name in the class . Will inspect all fields independent of access level .
4,030
public void processDoc ( final List < Map < String , String > > featureMaps , final List < Map < String , String > > groupMaps ) { workUnitHandler . processWorkUnit ( this , featureMaps , groupMaps ) ; }
Populate the property map for this work unit by delegating to the documented feature handler for this work unit .
4,031
public CommandLineProgramGroup getCommandLineProgramGroup ( ) { if ( commandLineProperties != null ) { try { return commandLineProperties . programGroup ( ) . newInstance ( ) ; } catch ( IllegalAccessException | InstantiationException e ) { logger . warn ( String . format ( "Can't instantiate program group class to retrieve summary for group %s for class %s" , commandLineProperties . programGroup ( ) . getName ( ) , clazz . getName ( ) ) ) ; } } return null ; }
Get the CommandLineProgramGroup object from the CommandLineProgramProperties of this work unit .
4,032
protected boolean startProcessDocs ( final RootDoc rootDoc ) throws IOException { for ( String [ ] options : rootDoc . options ( ) ) { parseOption ( options ) ; } if ( ( useDefaultTemplates && isSettingsDirSet ) || ( ! useDefaultTemplates && ! isSettingsDirSet ) ) { throw new RuntimeException ( "ERROR: must specify only ONE of: " + USE_DEFAULT_TEMPLATES_OPTION + " , " + SETTINGS_DIR_OPTION ) ; } if ( ! useDefaultTemplates ) { validateSettingsDir ( ) ; } validateDocletStartingState ( ) ; processDocs ( rootDoc ) ; return true ; }
Extracts the contents of certain types of javadoc and adds them to an output file .
4,033
public static int optionLength ( final String option ) { if ( option . equals ( DOC_TITLE_OPTION ) || option . equals ( WINDOW_TITLE_OPTION ) || option . equals ( SETTINGS_DIR_OPTION ) || option . equals ( DESTINATION_DIR_OPTION ) || option . equals ( BUILD_TIMESTAMP_OPTION ) || option . equals ( ABSOLUTE_VERSION_OPTION ) || option . equals ( OUTPUT_FILE_EXTENSION_OPTION ) || option . equals ( INDEX_FILE_EXTENSION_OPTION ) ) { return 2 ; } else if ( option . equals ( QUIET_OPTION ) || option . equals ( USE_DEFAULT_TEMPLATES_OPTION ) ) { return 1 ; } else { logger . error ( "The Javadoc command line option is not recognized by the Barclay doclet: " + option ) ; return 0 ; } }
Validates the given options against options supported by this doclet .
4,034
private void processDocs ( final RootDoc rootDoc ) { this . rootDoc = rootDoc ; workUnits = computeWorkUnits ( ) ; final Set < String > uniqueGroups = new HashSet < > ( ) ; final List < Map < String , String > > featureMaps = new ArrayList < > ( ) ; final List < Map < String , String > > groupMaps = new ArrayList < > ( ) ; workUnits . stream ( ) . forEach ( workUnit -> { featureMaps . add ( indexDataMap ( workUnit ) ) ; if ( ! uniqueGroups . contains ( workUnit . getGroupName ( ) ) ) { uniqueGroups . add ( workUnit . getGroupName ( ) ) ; groupMaps . add ( getGroupMap ( workUnit ) ) ; } } ) ; workUnits . stream ( ) . forEach ( workUnit -> { workUnit . processDoc ( featureMaps , groupMaps ) ; } ) ; emitOutputFromTemplates ( groupMaps , featureMaps ) ; }
Process the classes that have been included by the javadoc process in the rootDoc object .
4,035
private Set < DocWorkUnit > computeWorkUnits ( ) { final TreeSet < DocWorkUnit > workUnits = new TreeSet < > ( ) ; for ( final ClassDoc classDoc : rootDoc . classes ( ) ) { final Class < ? > clazz = getClassForClassDoc ( classDoc ) ; final DocumentedFeature documentedFeature = getDocumentedFeatureForClass ( clazz ) ; if ( documentedFeature != null ) { if ( documentedFeature . enable ( ) ) { DocWorkUnit workUnit = createWorkUnit ( documentedFeature , classDoc , clazz ) ; if ( workUnit != null ) { workUnits . add ( workUnit ) ; } } else { logger . info ( "Skipping disabled documentation for feature: " + classDoc ) ; } } } return workUnits ; }
For each class in the rootDoc class list delegate to the appropriate DocWorkUnitHandler to determine if it should be included in this run and for each included feature construct a DocWorkUnit .
4,036
public boolean includeInDocs ( final DocumentedFeature documentedFeature , final ClassDoc classDoc , final Class < ? > clazz ) { boolean hidden = ! showHiddenFeatures ( ) && clazz . isAnnotationPresent ( Hidden . class ) ; return ! hidden && JVMUtils . isConcrete ( clazz ) ; }
Determine if a particular class should be included in the output . This is called by the doclet to determine if a DocWorkUnit should be created for this feature .
4,037
protected DocWorkUnit createWorkUnit ( final DocumentedFeature documentedFeature , final ClassDoc classDoc , final Class < ? > clazz ) { return new DocWorkUnit ( new DefaultDocWorkUnitHandler ( this ) , documentedFeature , classDoc , clazz ) ; }
Create a work unit and handler capable of documenting the feature specified by the input arguments . Returns null if no appropriate handler is found or doc shouldn t be documented at all .
4,038
private DocumentedFeature getDocumentedFeatureForClass ( final Class < ? > clazz ) { if ( clazz != null && clazz . isAnnotationPresent ( DocumentedFeature . class ) ) { return clazz . getAnnotation ( DocumentedFeature . class ) ; } else { return null ; } }
Returns the instantiated DocumentedFeature that describes the doc for this class .
4,039
private Class < ? extends Object > getClassForClassDoc ( final ClassDoc doc ) { try { return DocletUtils . getClassForDoc ( doc ) ; } catch ( ClassNotFoundException e ) { return null ; } catch ( NoClassDefFoundError e ) { return null ; } catch ( UnsatisfiedLinkError e ) { return null ; } }
Return the Java class described by the ClassDoc doc
4,040
protected void processIndexTemplate ( final Configuration cfg , final List < DocWorkUnit > workUnitList , final List < Map < String , String > > groupMaps ) throws IOException { final Template template = cfg . getTemplate ( getIndexTemplateName ( ) ) ; final File indexFile = new File ( getDestinationDir ( ) , getIndexBaseFileName ( ) + '.' + getIndexFileExtension ( ) ) ; try ( final FileOutputStream fileOutStream = new FileOutputStream ( indexFile ) ; final OutputStreamWriter outWriter = new OutputStreamWriter ( fileOutStream ) ) { template . process ( groupIndexMap ( workUnitList , groupMaps ) , outWriter ) ; } catch ( TemplateException e ) { throw new DocException ( "Freemarker Template Exception during documentation index creation" , e ) ; } }
Create the php index listing all of the Docs features
4,041
protected Map < String , Object > groupIndexMap ( final List < DocWorkUnit > workUnitList , final List < Map < String , String > > groupMaps ) { Map < String , Object > root = new HashMap < > ( ) ; Collections . sort ( workUnitList ) ; List < Map < String , String > > data = new ArrayList < > ( ) ; workUnitList . stream ( ) . forEach ( workUnit -> data . add ( indexDataMap ( workUnit ) ) ) ; root . put ( "data" , data ) ; root . put ( "groups" , groupMaps ) ; root . put ( "timestamp" , getBuildTimeStamp ( ) ) ; root . put ( "version" , getBuildVersion ( ) ) ; return root ; }
Helpful function to create the php index . Given all of the already run DocWorkUnits create the high - level grouping data listing individual features by group .
4,042
protected Map < String , String > getGroupMap ( final DocWorkUnit workUnit ) { Map < String , String > propertyMap = new HashMap < > ( ) ; propertyMap . put ( "id" , getGroupIdFromName ( workUnit . getGroupName ( ) ) ) ; propertyMap . put ( "name" , workUnit . getGroupName ( ) ) ; propertyMap . put ( "summary" , workUnit . getGroupSummary ( ) ) ; return propertyMap ; }
Helper routine that returns the map of group name and summary given the workUnit . Subclasses that override this should call this method before doing further processing .
4,043
public Map < String , String > indexDataMap ( final DocWorkUnit workUnit ) { Map < String , String > propertyMap = new HashMap < > ( ) ; propertyMap . put ( "name" , workUnit . getName ( ) ) ; propertyMap . put ( "summary" , workUnit . getSummary ( ) ) ; propertyMap . put ( "filename" , workUnit . getTargetFileName ( ) ) ; propertyMap . put ( "group" , workUnit . getGroupName ( ) ) ; propertyMap . put ( "beta" , Boolean . toString ( workUnit . isBetaFeature ( ) ) ) ; propertyMap . put ( "experimental" , Boolean . toString ( workUnit . isExperimentalFeature ( ) ) ) ; return propertyMap ; }
Return a String - > String map suitable for FreeMarker to create an index to this WorkUnit
4,044
public final DocWorkUnit findWorkUnitForClass ( final Class < ? > c ) { for ( final DocWorkUnit workUnit : this . workUnits ) if ( workUnit . getClazz ( ) . equals ( c ) ) return workUnit ; return null ; }
Helper function that finding the DocWorkUnit associated with class from among all of the work units
4,045
protected void processWorkUnitTemplate ( final Configuration cfg , final DocWorkUnit workUnit , final List < Map < String , String > > indexByGroupMaps , final List < Map < String , String > > featureMaps ) { try { Template template = cfg . getTemplate ( workUnit . getTemplateName ( ) ) ; File outputPath = new File ( getDestinationDir ( ) , workUnit . getTargetFileName ( ) ) ; try ( final Writer out = new OutputStreamWriter ( new FileOutputStream ( outputPath ) ) ) { template . process ( workUnit . getRootMap ( ) , out ) ; } } catch ( IOException e ) { throw new DocException ( "IOException during documentation creation" , e ) ; } catch ( TemplateException e ) { throw new DocException ( "TemplateException during documentation creation" , e ) ; } GSONWorkUnit gsonworkunit = createGSONWorkUnit ( workUnit , indexByGroupMaps , featureMaps ) ; gsonworkunit . populate ( workUnit . getProperty ( "summary" ) . toString ( ) , workUnit . getProperty ( "gson-arguments" ) , workUnit . getProperty ( "description" ) . toString ( ) , workUnit . getProperty ( "name" ) . toString ( ) , workUnit . getProperty ( "group" ) . toString ( ) , Boolean . valueOf ( workUnit . getProperty ( "beta" ) . toString ( ) ) , Boolean . valueOf ( workUnit . getProperty ( "experimental" ) . toString ( ) ) ) ; File outputPathForJSON = new File ( getDestinationDir ( ) , workUnit . getJSONFileName ( ) ) ; try ( final BufferedWriter jsonWriter = new BufferedWriter ( new FileWriter ( outputPathForJSON ) ) ) { Gson gson = new GsonBuilder ( ) . serializeSpecialFloatingPointValues ( ) . setPrettyPrinting ( ) . create ( ) ; String json = gson . toJson ( gsonworkunit ) ; jsonWriter . write ( json ) ; } catch ( IOException e ) { throw new DocException ( "Failed to create JSON entry" , e ) ; } }
High - level function that processes a single DocWorkUnit unit using its handler
4,046
public String [ ] preprocessTaggedOptions ( final String [ ] argArray ) { List < String > finalArgs = new ArrayList < > ( argArray . length ) ; Iterator < String > argIt = Arrays . asList ( argArray ) . iterator ( ) ; while ( argIt . hasNext ( ) ) { final String arg = argIt . next ( ) ; if ( isShortOptionToken ( arg ) ) { replaceTaggedOption ( SHORT_OPTION_PREFIX , arg . substring ( SHORT_OPTION_PREFIX . length ( ) ) , argIt , finalArgs ) ; } else if ( isLongOptionToken ( arg ) ) { replaceTaggedOption ( LONG_OPTION_PREFIX , arg . substring ( LONG_OPTION_PREFIX . length ( ) ) , argIt , finalArgs ) ; } else { finalArgs . add ( arg ) ; } } return finalArgs . toArray ( new String [ finalArgs . size ( ) ] ) ; }
Given an array of raw arguments provided by the user return an array of args where tagged arguments have been replaced with curated arguments containing a key to be used by the parser to retrieve the actual values .
4,047
private void replaceTaggedOption ( final String optionPrefix , final String optionString , final Iterator < String > userArgIt , final List < String > finalArgList ) { final int separatorIndex = optionString . indexOf ( TaggedArgumentParser . ARGUMENT_TAG_NAME_SEPARATOR ) ; if ( separatorIndex == - 1 ) { detectAndRejectHybridSyntax ( optionString ) ; finalArgList . add ( optionPrefix + optionString ) ; } else { final String optionName = optionString . substring ( 0 , separatorIndex ) ; detectAndRejectHybridSyntax ( optionName ) ; if ( userArgIt . hasNext ( ) ) { if ( optionName . isEmpty ( ) ) { throw new CommandLineException ( "Zero length argument name found in tagged argument: " + optionString ) ; } final String tagNameAndValues = optionString . substring ( separatorIndex + 1 , optionString . length ( ) ) ; if ( tagNameAndValues . isEmpty ( ) ) { throw new CommandLineException ( "Zero length tag name found in tagged argument: " + optionString ) ; } final String argValue = userArgIt . next ( ) ; if ( isLongOptionToken ( argValue ) || isShortOptionToken ( argValue ) ) { throw new CommandLineException ( "No argument value found for tagged argument: " + optionString ) ; } final String pairKey = getSurrogateKeyForTaggedOption ( optionString , argValue , tagNameAndValues ) ; finalArgList . add ( optionPrefix + optionName ) ; finalArgList . add ( pairKey ) ; } else { throw new CommandLineException ( "No argument value found for tagged argument: " + optionString ) ; } } }
Process a single option and add it to the curated args list . If the option is tagged add the curated key and value . Otherwise just add the raw option .
4,048
private String getSurrogateKeyForTaggedOption ( final String rawOptionString , final String rawArgumentValue , final String tagString ) { final String surrogateKey = makeSurrogateKey ( rawOptionString , rawArgumentValue ) ; if ( null != tagSurrogates . put ( surrogateKey , Pair . of ( tagString , rawArgumentValue ) ) ) { throw new CommandLineException . BadArgumentValue ( String . format ( "The argument value: \"%s %s\" was duplicated on the command line" , rawOptionString , rawArgumentValue ) ) ; } return surrogateKey ; }
Stores the option string and value in the tagSurrogates hash map and returns a surrogate key .
4,049
public static void populateArgumentTags ( final TaggedArgument taggedArg , final String longArgName , final String tagString ) { if ( tagString == null ) { taggedArg . setTag ( null ) ; taggedArg . setTagAttributes ( Collections . emptyMap ( ) ) ; } else { final ParsedArgument pa = ParsedArgument . of ( longArgName , tagString ) ; taggedArg . setTag ( pa . getName ( ) ) ; taggedArg . setTagAttributes ( pa . keyValueMap ( ) ) ; } }
Parse a tag string and populate a TaggedArgument with values .
4,050
public static String getDisplayString ( final String longArgName , final TaggedArgument taggedArg ) { Utils . nonNull ( longArgName ) ; Utils . nonNull ( taggedArg ) ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( longArgName ) ; if ( taggedArg . getTag ( ) != null ) { sb . append ( ARGUMENT_TAG_NAME_SEPARATOR ) ; sb . append ( taggedArg . getTag ( ) ) ; if ( taggedArg . getTagAttributes ( ) != null ) { taggedArg . getTagAttributes ( ) . entrySet ( ) . stream ( ) . forEach ( entry -> { sb . append ( ARGUMENT_KEY_VALUE_PAIR_DELIMITER ) ; sb . append ( entry . getKey ( ) . toString ( ) ) ; sb . append ( ARGUMENT_KEY_VALUE_SEPARATOR ) ; sb . append ( entry . getValue ( ) . toString ( ) ) ; } ) ; } } return sb . toString ( ) ; }
Given a TaggedArgument implementation and a long argument name return a string representation of argument including the tag and attributes for display purposes .
4,051
public static int optionLength ( final String option ) { if ( option . equals ( CALLER_SCRIPT_NAME ) || option . equals ( CALLER_SCRIPT_PREFIX_LEGAL_ARGS ) || option . equals ( CALLER_SCRIPT_PREFIX_ARG_VALUE_TYPES ) || option . equals ( CALLER_SCRIPT_PREFIX_MUTEX_ARGS ) || option . equals ( CALLER_SCRIPT_PREFIX_ALIAS_ARGS ) || option . equals ( CALLER_SCRIPT_PREFIX_ARG_MIN_OCCURRENCES ) || option . equals ( CALLER_SCRIPT_PREFIX_ARG_MAX_OCCURRENCES ) || option . equals ( CALLER_SCRIPT_POSTFIX_LEGAL_ARGS ) || option . equals ( CALLER_SCRIPT_POSTFIX_ARG_VALUE_TYPES ) || option . equals ( CALLER_SCRIPT_POSTFIX_MUTEX_ARGS ) || option . equals ( CALLER_SCRIPT_POSTFIX_ALIAS_ARGS ) || option . equals ( CALLER_SCRIPT_POSTFIX_ARG_MIN_OCCURRENCES ) || option . equals ( CALLER_SCRIPT_POSTFIX_ARG_MAX_OCCURRENCES ) ) { return 2 ; } else { return HelpDoclet . optionLength ( option ) ; } }
Must add options that are applicable to this doclet so that they will be accepted .
4,052
protected void processIndexTemplate ( final Configuration cfg , final List < DocWorkUnit > workUnitList , final List < Map < String , String > > groupMaps ) throws IOException { final Map < String , Object > propertiesMap = new HashMap < > ( ) ; workUnits . stream ( ) . forEach ( workUnit -> propertiesMap . put ( workUnit . getName ( ) , workUnit . getRootMap ( ) ) ) ; final Map < String , Object > rootMap = new HashMap < > ( ) ; rootMap . put ( "tools" , propertiesMap ) ; final Map < String , Object > callerScriptOptionsMap = new HashMap < > ( ) ; callerScriptOptionsMap . put ( "callerScriptName" , callerScriptName ) ; callerScriptOptionsMap . put ( "callerScriptPrefixLegalArgs" , callerScriptPrefixLegalArgs ) ; callerScriptOptionsMap . put ( "callerScriptPrefixArgValueTypes" , callerScriptPrefixArgValueTypes ) ; callerScriptOptionsMap . put ( "callerScriptPrefixMutexArgs" , callerScriptPrefixMutexArgs ) ; callerScriptOptionsMap . put ( "callerScriptPrefixAliasArgs" , callerScriptPrefixAliasArgs ) ; callerScriptOptionsMap . put ( "callerScriptPrefixMinOccurrences" , callerScriptPrefixMinOccurrences ) ; callerScriptOptionsMap . put ( "callerScriptPrefixMaxOccurrences" , callerScriptPrefixMaxOccurrences ) ; callerScriptOptionsMap . put ( "callerScriptPostfixLegalArgs" , callerScriptPostfixLegalArgs ) ; callerScriptOptionsMap . put ( "callerScriptPostfixArgValueTypes" , callerScriptPostfixArgValueTypes ) ; callerScriptOptionsMap . put ( "callerScriptPostfixMutexArgs" , callerScriptPostfixMutexArgs ) ; callerScriptOptionsMap . put ( "callerScriptPostfixAliasArgs" , callerScriptPostfixAliasArgs ) ; callerScriptOptionsMap . put ( "callerScriptPostfixMinOccurrences" , callerScriptPostfixMinOccurrences ) ; callerScriptOptionsMap . put ( "callerScriptPostfixMaxOccurrences" , callerScriptPostfixMaxOccurrences ) ; if ( hasCallerScriptPostfixArgs ) { callerScriptOptionsMap . put ( "hasCallerScriptPostfixArgs" , "true" ) ; } else { callerScriptOptionsMap . put ( "hasCallerScriptPostfixArgs" , "false" ) ; } rootMap . put ( "callerScriptOptions" , callerScriptOptionsMap ) ; final Template template = cfg . getTemplate ( getIndexTemplateName ( ) ) ; final File indexFile = new File ( getDestinationDir ( ) , getIndexBaseFileName ( ) + "." + getIndexFileExtension ( ) ) ; try ( final FileOutputStream fileOutStream = new FileOutputStream ( indexFile ) ; final OutputStreamWriter outWriter = new OutputStreamWriter ( fileOutStream ) ) { template . process ( rootMap , outWriter ) ; } catch ( TemplateException e ) { throw new DocException ( "Freemarker Template Exception during documentation index creation" , e ) ; } }
The Index file in the Bash Completion Doclet is what generates the actual tab - completion script .
4,053
public void run ( ) { String client = socket . getInetAddress ( ) . getHostAddress ( ) ; if ( log . isDebugEnabled ( ) ) { log . info ( "Accepted Connection From: " + client ) ; } PrintWriter out = null ; BufferedReader in = null ; try { socket . setSoTimeout ( 1000 ) ; out = new PrintWriter ( socket . getOutputStream ( ) , true ) ; in = new BufferedReader ( new InputStreamReader ( socket . getInputStream ( ) ) ) ; String inputLine = in . readLine ( ) ; if ( inputLine . substring ( 0 , 4 ) . equals ( "ZBXD" ) ) { inputLine = inputLine . substring ( 13 , inputLine . length ( ) ) ; } if ( inputLine != null ) { try { Object value = container . getMetric ( inputLine ) ; out . print ( value . toString ( ) ) ; out . flush ( ) ; } catch ( MetricsException me ) { if ( log . isErrorEnabled ( ) ) { log . error ( "Client: " + client + " Sent Unknown Key: " + inputLine ) ; } out . print ( "ZBX_NOTSUPPORTED" ) ; out . flush ( ) ; } } } catch ( SocketTimeoutException ste ) { log . debug ( client + ": Timeout Detected." ) ; } catch ( Exception e ) { log . error ( client + ": Error: " + e . toString ( ) ) ; } finally { if ( log . isDebugEnabled ( ) ) { log . debug ( client + ": Disconnected." ) ; } try { if ( in != null ) { in . close ( ) ; } } catch ( Exception e ) { } try { if ( out != null ) { out . close ( ) ; } } catch ( Exception e ) { } try { socket . close ( ) ; } catch ( Exception e ) { } } }
WorkerThread execution begins .
4,054
public boolean hasWebDocumentation ( final Class < ? > clazz ) { for ( final String pkg : PACKAGES_WITH_WEB_DOCUMENTATION ) { if ( clazz . getPackage ( ) . getName ( ) . startsWith ( pkg ) ) { return true ; } } return false ; }
Determines if a class has web documentation based on its package name
4,055
public String usage ( final boolean printCommon , final boolean printHidden ) { final StringBuilder sb = new StringBuilder ( ) ; if ( ! printHidden ) { logger . warn ( "Hidden arguments are always printed in LegacyCommandLineArgumentParser" ) ; } if ( prefix . isEmpty ( ) ) { final String preamble = htmlUnescape ( convertFromHtml ( getStandardUsagePreamble ( callerOptions . getClass ( ) ) + getUsagePreamble ( ) ) ) ; checkForNonASCII ( preamble , "Tool description" ) ; sb . append ( Utils . wrapParagraph ( preamble , OPTION_COLUMN_WIDTH + DESCRIPTION_COLUMN_WIDTH ) ) ; sb . append ( "\nVersion: " + getVersion ( ) ) ; sb . append ( "\n" ) ; sb . append ( "\n\nOptions:\n\n" ) ; for ( final String [ ] optionDoc : FRAMEWORK_OPTION_DOC ) { printOptionParamUsage ( sb , optionDoc [ 0 ] , optionDoc [ 1 ] , null , optionDoc [ 2 ] ) ; } } if ( ! optionDefinitions . isEmpty ( ) ) { optionDefinitions . stream ( ) . filter ( optionDefinition -> printCommon || ! optionDefinition . isCommon ) . forEach ( optionDefinition -> printOptionUsage ( sb , optionDefinition ) ) ; } if ( printCommon ) { final Field fileField ; try { class OptionFileContainerForUsage { public File optionFileContainer ; } fileField = OptionFileContainerForUsage . class . getField ( "optionFileContainer" ) ; } catch ( final NoSuchFieldException e ) { throw new CommandLineException ( "Should never happen" , e ) ; } final OptionDefinition optionsFileOptionDefinition = new OptionDefinition ( fileField , null , OPTIONS_FILE , "" , "File of OPTION_NAME=value pairs. No positional parameters allowed. Unlike command-line options, " + "unrecognized options are ignored. " + "A single-valued option set in an options file may be overridden " + "by a subsequent command-line option. " + "A line starting with '#' is considered a comment." , false , false , 0 , Integer . MAX_VALUE , null , true , new String [ 0 ] ) ; printOptionUsage ( sb , optionsFileOptionDefinition ) ; } return sb . toString ( ) ; }
Print a usage message based on the options object passed to the ctor .
4,056
static String convertFromHtml ( final String textToConvert ) { final Map < String , String > regexps = new LinkedHashMap < > ( ) ; regexps . put ( "< *a *href=[\'\"](.*?)[\'\"] *>(.*?)</ *a *>" , "$2 ($1)" ) ; regexps . put ( "< *a *href=[\'\"](.*?)[\'\"] *>(.*?)< *a */>" , "$2 ($1)" ) ; regexps . put ( "</ *(br|p|table|h[1-4]|pre|hr|li|ul) *>" , "\n" ) ; regexps . put ( "< *(br|p|table|h[1-4]|pre|hr|li|ul) */>" , "\n" ) ; regexps . put ( "< *(p|table|h[1-4]|ul|pre) *>" , "\n" ) ; regexps . put ( "<li>" , " - " ) ; regexps . put ( "</th>" , "\t" ) ; regexps . put ( "<\\w*?>" , "" ) ; return regexps . entrySet ( ) . stream ( ) . sequential ( ) . reduce ( textToConvert , ( string , entrySet ) -> string . replaceAll ( entrySet . getKey ( ) , entrySet . getValue ( ) ) , ( a , b ) -> b ) ; }
package local for testing
4,057
public boolean parseArguments ( final PrintStream messageStream , final String [ ] args ) { this . argv = args ; this . messageStream = messageStream ; if ( prefix . isEmpty ( ) ) { commandLine = callerOptions . getClass ( ) . getSimpleName ( ) ; } for ( int i = 0 ; i < args . length ; ++ i ) { final String arg = args [ i ] ; if ( arg . equals ( "-h" ) || arg . equals ( "--help" ) ) { messageStream . append ( usage ( false , true ) ) ; return false ; } if ( arg . equals ( "-H" ) || arg . equals ( "--stdhelp" ) ) { messageStream . append ( usage ( true , true ) ) ; return false ; } if ( arg . equals ( "--version" ) ) { messageStream . println ( getVersion ( ) ) ; return false ; } final String [ ] pair = arg . split ( "=" , 2 ) ; if ( pair . length == 2 ) { if ( pair [ 1 ] . isEmpty ( ) && i < args . length - 1 ) { pair [ 1 ] = args [ ++ i ] ; } if ( ! parseOption ( pair [ 0 ] , pair [ 1 ] , false ) ) { messageStream . println ( ) ; messageStream . append ( usage ( true , true ) ) ; return false ; } } else if ( ! parsePositionalArgument ( arg ) ) { messageStream . println ( ) ; messageStream . append ( usage ( false , true ) ) ; return false ; } } if ( ! checkNumArguments ( ) ) { messageStream . println ( ) ; messageStream . append ( usage ( false , true ) ) ; return false ; } return true ; }
Parse command - line options and store values in callerOptions object passed to ctor .
4,058
private Class < ? > getUnderlyingType ( final Field field ) { if ( isCollectionField ( field ) ) { final ParameterizedType clazz = ( ParameterizedType ) ( field . getGenericType ( ) ) ; final Type [ ] genericTypes = clazz . getActualTypeArguments ( ) ; if ( genericTypes . length != 1 ) { throw new CommandLineException . CommandLineParserInternalException ( "Strange collection type for field " + field . getName ( ) ) ; } return ( Class ) genericTypes [ 0 ] ; } else { final Class < ? > type = field . getType ( ) ; if ( type == Byte . TYPE ) return Byte . class ; if ( type == Short . TYPE ) return Short . class ; if ( type == Integer . TYPE ) return Integer . class ; if ( type == Long . TYPE ) return Long . class ; if ( type == Float . TYPE ) return Float . class ; if ( type == Double . TYPE ) return Double . class ; if ( type == Boolean . TYPE ) return Boolean . class ; return type ; } }
Returns the type that each instance of the argument needs to be converted to . In the case of primitive fields it will return the wrapper type so that String constructors can be found .
4,059
public PatternN and ( Observable < ? extends Object > other ) { if ( other == null ) { throw new NullPointerException ( ) ; } List < Observable < ? extends Object > > list = new ArrayList < Observable < ? extends Object > > ( ) ; list . add ( o1 ) ; list . add ( o2 ) ; list . add ( o3 ) ; list . add ( o4 ) ; list . add ( o5 ) ; list . add ( o6 ) ; list . add ( o7 ) ; list . add ( o8 ) ; list . add ( o9 ) ; list . add ( other ) ; return new PatternN ( list ) ; }
Creates a pattern that matches when all nine observable sequences have an available element .
4,060
public boolean parseArguments ( final PrintStream messageStream , String [ ] args ) { final OptionSet parsedArguments ; final OptionParser parser = getOptionParser ( ) ; try { parsedArguments = parser . parse ( tagParser . preprocessTaggedOptions ( args ) ) ; } catch ( final OptionException e ) { throw new CommandLineException ( e . getMessage ( ) ) ; } if ( isSpecialFlagSet ( parsedArguments , SpecialArgumentsCollection . HELP_FULLNAME ) ) { messageStream . print ( usage ( true , isSpecialFlagSet ( parsedArguments , SpecialArgumentsCollection . SHOW_HIDDEN_FULLNAME ) ) ) ; return false ; } else if ( isSpecialFlagSet ( parsedArguments , SpecialArgumentsCollection . VERSION_FULLNAME ) ) { messageStream . println ( getVersion ( ) ) ; return false ; } else if ( parsedArguments . has ( SpecialArgumentsCollection . ARGUMENTS_FILE_FULLNAME ) ) { final List < String > newArgs = expandFromArgumentFile ( parsedArguments ) ; if ( ! newArgs . isEmpty ( ) ) { tagParser . resetTagSurrogates ( ) ; newArgs . addAll ( Arrays . asList ( args ) ) ; return parseArguments ( messageStream , newArgs . toArray ( new String [ newArgs . size ( ) ] ) ) ; } } return propagateParsedValues ( parsedArguments ) ; }
Parse command - line arguments and store values in callerArguments object passed to ctor .
4,061
public < T > T getPluginDescriptor ( final Class < T > targetDescriptor ) { return targetDescriptor . cast ( pluginDescriptors . get ( targetDescriptor . getName ( ) ) ) ; }
Return the plugin instance corresponding to the targetDescriptor class
4,062
private void validateArgumentDefinitions ( ) { for ( final NamedArgumentDefinition mutexSourceDef : namedArgumentDefinitions ) { for ( final String mutexTarget : mutexSourceDef . getMutexTargetList ( ) ) { final NamedArgumentDefinition mutexTargetDef = namedArgumentsDefinitionsByAlias . get ( mutexTarget ) ; if ( mutexTargetDef == null ) { throw new CommandLineException . CommandLineParserInternalException ( String . format ( "Argument '%s' references a nonexistent mutex argument '%s'" , mutexSourceDef . getArgumentAliasDisplayString ( ) , mutexTarget ) ) ; } else { mutexTargetDef . addMutexTarget ( mutexSourceDef . getLongName ( ) ) ; } } } }
arguments involved .
4,063
private void createCommandLinePluginArgumentDefinitions ( final List < ? extends CommandLinePluginDescriptor < ? > > requestedPluginDescriptors ) { requestedPluginDescriptors . forEach ( descriptor -> { pluginDescriptors . put ( descriptor . getClass ( ) . getName ( ) , descriptor ) ; createArgumentDefinitions ( descriptor , null ) ; findPluginsForDescriptor ( descriptor ) ; } ) ; }
Find all the instances of plugins specified by the provided plugin descriptors
4,064
private void findPluginsForDescriptor ( final CommandLinePluginDescriptor < ? > pluginDescriptor ) { final ClassFinder classFinder = new ClassFinder ( ) ; pluginDescriptor . getPackageNames ( ) . forEach ( pkg -> classFinder . find ( pkg , pluginDescriptor . getPluginBaseClass ( ) ) ) ; final Set < Class < ? > > pluginClasses = classFinder . getClasses ( ) ; for ( Class < ? > c : pluginClasses ) { if ( pluginDescriptor . includePluginClass ( c ) ) { try { final Object plugin = pluginDescriptor . createInstanceForPlugin ( c ) ; createArgumentDefinitions ( plugin , pluginDescriptor ) ; } catch ( InstantiationException | IllegalAccessException e ) { throw new CommandLineException . CommandLineParserInternalException ( "Problem making an instance of plugin " + c + " Do check that the class has a non-arg constructor" , e ) ; } } } }
instance each and add its ArgumentDefinitions
4,065
private boolean isSpecialFlagSet ( final OptionSet parsedArguments , final String flagName ) { if ( parsedArguments . has ( flagName ) ) { Object value = parsedArguments . valueOf ( flagName ) ; return ( value == null || ! value . equals ( "false" ) ) ; } else { return false ; } }
helper to deal with the case of special flags that are evaluated before the options are properly set
4,066
private List < NamedArgumentDefinition > validatePluginArgumentValues ( ) { final List < NamedArgumentDefinition > actualArgumentDefinitions = new ArrayList < > ( ) ; for ( final NamedArgumentDefinition argumentDefinition : namedArgumentDefinitions ) { if ( ! argumentDefinition . isControlledByPlugin ( ) ) { actualArgumentDefinitions . add ( argumentDefinition ) ; } else { final boolean isAllowed = argumentDefinition . getDescriptorForControllingPlugin ( ) . isDependentArgumentAllowed ( argumentDefinition . getContainingObject ( ) . getClass ( ) ) ; if ( argumentDefinition . getHasBeenSet ( ) ) { if ( ! isAllowed ) { throw new CommandLineException ( String . format ( "Argument \"%s/%s\" is only valid when the argument \"%s\" is specified" , argumentDefinition . getShortName ( ) , argumentDefinition . getLongName ( ) , argumentDefinition . getContainingObject ( ) . getClass ( ) . getSimpleName ( ) ) ) ; } actualArgumentDefinitions . add ( argumentDefinition ) ; } else if ( isAllowed ) { actualArgumentDefinitions . add ( argumentDefinition ) ; } } } pluginDescriptors . entrySet ( ) . forEach ( e -> e . getValue ( ) . validateAndResolvePlugins ( ) ) ; return actualArgumentDefinitions ; }
other arguments that require validation .
4,067
public List < String > expandFromExpansionFile ( final ArgumentDefinition argumentDefinition , final String stringValue , final List < String > originalValuesForPreservation ) { List < String > expandedValues = new ArrayList < > ( ) ; if ( EXPANSION_FILE_EXTENSIONS . stream ( ) . anyMatch ( ext -> stringValue . endsWith ( ext ) ) ) { expandedValues . addAll ( loadCollectionListFile ( stringValue ) ) ; argumentDefinition . setOriginalCommandLineValues ( originalValuesForPreservation ) ; } else { expandedValues . add ( stringValue ) ; } return expandedValues ; }
Expand any collection value that references a filename that ends in one of the accepted expansion extensions and add the contents of the file to the list of values for that argument .
4,068
public < T > List < Pair < ArgumentDefinition , T > > gatherArgumentValuesOfType ( final Class < T > type ) { final List < Pair < ArgumentDefinition , T > > argumentValues = new ArrayList < > ( ) ; final List < ArgumentDefinition > allArgDefs = new ArrayList < > ( namedArgumentDefinitions . size ( ) ) ; allArgDefs . addAll ( namedArgumentDefinitions ) ; if ( positionalArgumentDefinition != null ) { allArgDefs . add ( positionalArgumentDefinition ) ; } for ( final ArgumentDefinition argDef : allArgDefs ) { if ( type . isAssignableFrom ( argDef . getUnderlyingFieldClass ( ) ) ) { if ( argDef . isCollection ( ) ) { final Collection < ? > argumentContainer = ( Collection < ? > ) argDef . getArgumentValue ( ) ; if ( argumentContainer . isEmpty ( ) ) { argumentValues . add ( Pair . of ( argDef , null ) ) ; } else { for ( final Object argumentValue : argumentContainer ) { argumentValues . add ( Pair . of ( argDef , type . cast ( argumentValue ) ) ) ; } } } else { argumentValues . add ( Pair . of ( argDef , type . cast ( argDef . getArgumentValue ( ) ) ) ) ; } } } return argumentValues ; }
Locates and returns the VALUES of all Argument - annotated fields of a specified type in a given object pairing each field value with its corresponding Field object .
4,069
protected void scanDir ( final File file , final String path ) { for ( final File child : file . listFiles ( ) ) { final String newPath = ( path == null ? child . getName ( ) : path + '/' + child . getName ( ) ) ; if ( child . isDirectory ( ) ) { scanDir ( child , newPath ) ; } else { handleItem ( newPath ) ; } } }
Scans a directory on the filesystem for classes .
4,070
protected void handleItem ( final String name ) { if ( name . endsWith ( ".class" ) ) { final String classname = toClassName ( name ) ; try { final Class < ? > type = loader . loadClass ( classname ) ; if ( parentType . isAssignableFrom ( type ) ) { this . classes . add ( type ) ; } } catch ( Throwable t ) { log . debug ( "could not load class: " + classname , t ) ; } } }
Checks an item to see if it is a class and is annotated with the specified annotation . If so adds it to the set otherwise ignores it .
4,071
public static < T1 , T2 > Pattern2 < T1 , T2 > and ( Observable < T1 > left , Observable < T2 > right ) { if ( left == null ) { throw new NullPointerException ( "left" ) ; } if ( right == null ) { throw new NullPointerException ( "right" ) ; } return new Pattern2 < T1 , T2 > ( left , right ) ; }
Creates a pattern that matches when both observable sequences have an available element .
4,072
public static < T1 , R > Plan0 < R > then ( Observable < T1 > source , Func1 < T1 , R > selector ) { if ( source == null ) { throw new NullPointerException ( "source" ) ; } if ( selector == null ) { throw new NullPointerException ( "selector" ) ; } return new Pattern1 < T1 > ( source ) . then ( selector ) ; }
Matches when the observable sequence has an available element and projects the element by invoking the selector function .
4,073
public List < String > getArgumentAliases ( ) { final List < String > aliases = new ArrayList < > ( ) ; if ( ! getShortName ( ) . isEmpty ( ) ) { aliases . add ( getShortName ( ) ) ; } if ( ! getFullName ( ) . isEmpty ( ) ) { aliases . add ( getFullName ( ) ) ; } else { aliases . add ( getUnderlyingField ( ) . getName ( ) ) ; } return aliases ; }
Get the list of short and long aliases for this argument .
4,074
@ SuppressWarnings ( { "rawtypes" , "unchecked" } ) private void setCollectionValues ( final CommandLineArgumentParser commandLineArgumentParser , final List < String > preprocessedValues ) { final Collection c = ( Collection ) getArgumentValue ( ) ; if ( ! commandLineArgumentParser . getAppendToCollectionsParserOption ( ) ) { c . clear ( ) ; } for ( int i = 0 ; i < preprocessedValues . size ( ) ; i ++ ) { final String stringValue = preprocessedValues . get ( i ) ; if ( stringValue . equals ( NULL_ARGUMENT_STRING ) ) { if ( i != 0 ) { logger . warn ( String . format ( "A \"null\" value was detected for an option after values for that option were already set. " + "Clobbering previously set values for this option: %s." , getArgumentAliasDisplayString ( ) ) ) ; } if ( ! isOptional ( ) ) { throw new CommandLineException ( String . format ( "Non \"null\" value must be provided for '%s'" , getArgumentAliasDisplayString ( ) ) ) ; } c . clear ( ) ; } else { final Pair < String , String > normalizedSurrogatePair = getNormalizedTagValuePair ( commandLineArgumentParser , stringValue ) ; final List < String > expandedValues = argumentAnnotation . suppressFileExpansion ( ) ? Collections . singletonList ( normalizedSurrogatePair . getRight ( ) ) : commandLineArgumentParser . expandFromExpansionFile ( this , normalizedSurrogatePair . getRight ( ) , preprocessedValues ) ; for ( final String expandedValue : expandedValues ) { final Object actualValue = getValuePopulatedWithTags ( normalizedSurrogatePair . getLeft ( ) , expandedValue ) ; checkArgumentRange ( actualValue ) ; c . add ( actualValue ) ; } } } }
surrogate each instance added to the collection must be populated with any tags and attributes .
4,075
private void setScalarValue ( final CommandLineArgumentParser commandLineArgumentParser , final List < String > originalValues ) { if ( getHasBeenSet ( ) || originalValues . size ( ) > 1 ) { throw new CommandLineException . BadArgumentValue ( String . format ( "Argument '%s' cannot be specified more than once." , getArgumentAliasDisplayString ( ) ) ) ; } if ( isFlag ( ) && originalValues . isEmpty ( ) ) { setArgumentValue ( true ) ; } else { final String stringValue = originalValues . get ( 0 ) ; Object value = null ; if ( stringValue . equals ( NULL_ARGUMENT_STRING ) ) { if ( getUnderlyingField ( ) . getType ( ) . isPrimitive ( ) ) { throw new CommandLineException . BadArgumentValue ( String . format ( "Argument '%s' is not a nullable argument type." , getArgumentAliasDisplayString ( ) ) ) ; } } else { final Pair < String , String > normalizedSurrogatePair = getNormalizedTagValuePair ( commandLineArgumentParser , stringValue ) ; value = getValuePopulatedWithTags ( normalizedSurrogatePair . getLeft ( ) , normalizedSurrogatePair . getRight ( ) ) ; } checkArgumentRange ( value ) ; setArgumentValue ( value ) ; } }
one value in which case we throw .
4,076
public String getArgumentUsage ( final Map < String , NamedArgumentDefinition > allActualArguments , final Collection < CommandLinePluginDescriptor < ? > > pluginDescriptors , final int argumentColumnWidth , final int descriptionColumnWidth ) { final StringBuilder sb = new StringBuilder ( ) ; sb . append ( "--" ) . append ( getLongName ( ) ) ; if ( ! getShortName ( ) . isEmpty ( ) ) { sb . append ( ",-" ) . append ( getShortName ( ) ) ; } sb . append ( ":" ) . append ( getUnderlyingFieldClass ( ) . getSimpleName ( ) ) ; int labelLength = sb . toString ( ) . length ( ) ; int numSpaces = argumentColumnWidth - labelLength ; if ( labelLength > argumentColumnWidth ) { sb . append ( "\n" ) ; numSpaces = argumentColumnWidth ; } printSpaces ( sb , numSpaces ) ; final String description = getArgumentDescription ( allActualArguments , pluginDescriptors ) ; final String wrappedDescription = Utils . wrapParagraph ( description , descriptionColumnWidth ) ; final String [ ] descriptionLines = wrappedDescription . split ( "\n" ) ; for ( int i = 0 ; i < descriptionLines . length ; ++ i ) { if ( i > 0 ) { printSpaces ( sb , argumentColumnWidth ) ; } sb . append ( descriptionLines [ i ] ) ; sb . append ( "\n" ) ; } sb . append ( "\n" ) ; return sb . toString ( ) ; }
Return a string with the usage statement for this argument .
4,077
private String getNameValuePairForDisplay ( final Object value ) { if ( value != null ) { if ( argumentAnnotation . sensitive ( ) ) { return String . format ( "--%s ***********" , getLongName ( ) ) ; } else { if ( value instanceof TaggedArgument ) { return String . format ( "--%s %s" , TaggedArgumentParser . getDisplayString ( getLongName ( ) , ( TaggedArgument ) value ) , value ) ; } else { return String . format ( "--%s %s" , getLongName ( ) , value ) ; } } } return "" ; }
Get a name value pair for this argument and a value suitable for display .
4,078
private String convertDefaultValueToString ( ) { final Object initialValue = getArgumentValue ( ) ; if ( initialValue != null ) { if ( isCollection ( ) && ( ( Collection < ? > ) initialValue ) . isEmpty ( ) ) { return NULL_ARGUMENT_STRING ; } else { return initialValue . toString ( ) ; } } else { return NULL_ARGUMENT_STRING ; } }
Convert the initial value for this argument to a string representation .
4,079
private void validateBoundsDefinitions ( ) { if ( ! Number . class . isAssignableFrom ( getUnderlyingFieldClass ( ) ) ) { if ( hasBoundedRange ( ) || hasRecommendedRange ( ) ) { throw new CommandLineException . CommandLineParserInternalException ( String . format ( "Min/max value ranges can only be set for numeric arguments. " + "Argument --%s has a minimum or maximum value but has a non-numeric type." , getLongName ( ) ) ) ; } } if ( Integer . class . isAssignableFrom ( getUnderlyingFieldClass ( ) ) ) { if ( ! isInfinityOrMathematicalInteger ( getMaxValue ( ) ) || ! isInfinityOrMathematicalInteger ( getMinValue ( ) ) || ! isInfinityOrMathematicalInteger ( getMaxRecommendedValue ( ) ) || ! isInfinityOrMathematicalInteger ( getMinRecommendedValue ( ) ) ) { throw new CommandLineException . CommandLineParserInternalException ( String . format ( "Integer argument --%s has a minimum or maximum attribute with a non-integral value." , getLongName ( ) ) ) ; } } }
and are self - consistent .
4,080
private Object getValuePopulatedWithTags ( final String originalTag , final String stringValue ) { final Object value = constructFromString ( stringValue , getLongName ( ) ) ; if ( TaggedArgument . class . isAssignableFrom ( getUnderlyingFieldClass ( ) ) ) { TaggedArgument taggedArgument = ( TaggedArgument ) value ; TaggedArgumentParser . populateArgumentTags ( taggedArgument , getLongName ( ) , originalTag ) ; } else if ( originalTag != null ) { throw new CommandLineException ( String . format ( "The argument: \"%s/%s\" does not accept tags: \"%s\"" , getShortName ( ) , getFullName ( ) , originalTag ) ) ; } return value ; }
populated with the actual value and tags and attributes provided by the user for that argument .
4,081
private String getArgumentDescription ( final Map < String , NamedArgumentDefinition > allActualArguments , final Collection < CommandLinePluginDescriptor < ? > > pluginDescriptors ) { final StringBuilder sb = new StringBuilder ( ) ; if ( ! getDocString ( ) . isEmpty ( ) ) { sb . append ( getDocString ( ) ) ; sb . append ( " " ) ; } if ( isCollection ( ) ) { if ( isOptional ( ) ) { sb . append ( "This argument may be specified 0 or more times. " ) ; } else { sb . append ( "This argument must be specified at least once. " ) ; } } if ( isOptional ( ) ) { sb . append ( "Default value: " ) ; sb . append ( getDefaultValueAsString ( ) ) ; sb . append ( ". " ) ; } else { sb . append ( "Required. " ) ; } if ( ! usageForPluginDescriptorArgument ( sb , pluginDescriptors ) ) { sb . append ( getOptionsAsDisplayString ( ) ) ; } if ( ! getMutexTargetList ( ) . isEmpty ( ) ) { sb . append ( " Cannot be used in conjunction with argument(s)" ) ; for ( final String argument : getMutexTargetList ( ) ) { final NamedArgumentDefinition mutexArgumentDefinition = allActualArguments . get ( argument ) ; sb . append ( " " ) . append ( mutexArgumentDefinition . getUnderlyingField ( ) . getName ( ) ) ; if ( ! mutexArgumentDefinition . getShortName ( ) . isEmpty ( ) ) { sb . append ( " (" ) . append ( mutexArgumentDefinition . getShortName ( ) ) . append ( ")" ) ; } } } return sb . toString ( ) ; }
Return a usage string representing this argument .
4,082
private void checkArgumentRange ( final Object argumentValue ) { if ( ! Number . class . isAssignableFrom ( getUnderlyingFieldClass ( ) ) ) { return ; } final Double argumentDoubleValue = ( argumentValue == null ) ? null : ( ( Number ) argumentValue ) . doubleValue ( ) ; if ( hasBoundedRange ( ) && isValueOutOfRange ( argumentDoubleValue ) ) { throw new CommandLineException . OutOfRangeArgumentValue ( getLongName ( ) , getMinValue ( ) , getMaxValue ( ) , argumentValue ) ; } if ( hasRecommendedRange ( ) && isValueOutOfRange ( argumentDoubleValue ) ) { final boolean outMinValue = getMinRecommendedValue ( ) != Double . NEGATIVE_INFINITY ; final boolean outMaxValue = getMaxRecommendedValue ( ) != Double . POSITIVE_INFINITY ; if ( outMinValue && outMaxValue ) { logger . warn ( "Argument --{} has value {}, but recommended within range ({},{})" , getLongName ( ) , argumentDoubleValue , getMinRecommendedValue ( ) , getMaxRecommendedValue ( ) ) ; } else if ( outMinValue ) { logger . warn ( "Argument --{} has value {}, but minimum recommended is {}" , getLongName ( ) , argumentDoubleValue , getMinRecommendedValue ( ) ) ; } else if ( outMaxValue ) { logger . warn ( "Argument --{} has value {}, but maximum recommended is {}" , getLongName ( ) , argumentDoubleValue , getMaxRecommendedValue ( ) ) ; } } }
Check the provided value against any range constraints specified in the Argument annotation for the corresponding field . Throw an exception if limits are violated .
4,083
private void setArgumentValue ( final Object value ) { try { getUnderlyingField ( ) . set ( getContainingObject ( ) , value ) ; } catch ( final IllegalAccessException e ) { throw new CommandLineException . ShouldNeverReachHereException ( String . format ( "Couldn't set field value for %s in %s with value %s." , getUnderlyingField ( ) . getName ( ) , getContainingObject ( ) . toString ( ) , value . toString ( ) ) , e ) ; } }
Set the underlying field to the new value .
4,084
private boolean isValueOutOfRange ( final Double value ) { return value == null || getMinValue ( ) != Double . NEGATIVE_INFINITY && value < getMinValue ( ) || getMaxValue ( ) != Double . POSITIVE_INFINITY && value > getMaxValue ( ) ; }
null values are always out of range
4,085
public < T5 > Pattern5 < T1 , T2 , T3 , T4 , T5 > and ( Observable < T5 > other ) { if ( other == null ) { throw new NullPointerException ( ) ; } return new Pattern5 < T1 , T2 , T3 , T4 , T5 > ( o1 , o2 , o3 , o4 , other ) ; }
Creates a pattern that matches when all four observable sequences have an available element .
4,086
public String [ ] listProviders ( ) { String [ ] providers = new String [ container . size ( ) ] ; int i = 0 ; Iterator < String > ki = container . keySet ( ) . iterator ( ) ; while ( ki . hasNext ( ) ) { providers [ i ++ ] = ( String ) ki . next ( ) ; } return providers ; }
List the MetricsProvider keys in this MetricsContainer .
4,087
public void addProvider ( String name , MetricsProvider provider ) { if ( log . isInfoEnabled ( ) ) { log . info ( "Adding Provider: " + provider . getClass ( ) . getName ( ) + "=" + name ) ; } container . put ( name , provider ) ; }
Add a MetricsProvider to this container .
4,088
public MetricsProvider getProvider ( String name ) throws MetricsException { if ( container . containsKey ( name ) ) { return ( MetricsProvider ) container . get ( name ) ; } else { throw new MetricsException ( "No MetricsProvider with name: " + name ) ; } }
Retrieve a MetricsProvider .
4,089
public Object getMetric ( String key ) throws MetricsException { MetricsKey mk = new MetricsKey ( key ) ; MetricsProvider provider = getProvider ( mk . getProvider ( ) ) ; return provider . getValue ( mk ) ; }
Retrieve a value from this MetricsContainer .
4,090
protected void intializeCollection ( final String annotationType ) { final Field field = getUnderlyingField ( ) ; final Object callerArguments = containingObject ; try { if ( field . get ( containingObject ) == null ) { field . set ( callerArguments , field . getType ( ) . newInstance ( ) ) ; } } catch ( final Exception ex ) { try { field . set ( callerArguments , new ArrayList < > ( ) ) ; } catch ( final IllegalArgumentException e ) { throw new CommandLineException . CommandLineParserInternalException ( String . format ( "Collection member %s of type %s must be explicitly initialized. " + "It cannot be constructed or auto-initialized with ArrayList." , field . getName ( ) , annotationType ) ) ; } catch ( final IllegalAccessException e ) { throw new CommandLineException . ShouldNeverReachHereException ( "We should not have reached here because we set accessible to true" , e ) ; } } }
Initialize a collection value for this field . If the collection can t be instantiated directly because its the underlying type is not a concrete type an attempt assign an ArrayList will be made .
4,091
@ SuppressWarnings ( { "unchecked" , "rawtypes" } ) protected String getOptionsAsDisplayString ( ) { final Class < ? > clazz = getUnderlyingFieldClass ( ) ; if ( clazz == Boolean . class ) { return String . format ( "%s%s, %s%s" , OPTION_DOC_PREFIX , Boolean . TRUE , Boolean . FALSE , OPTION_DOC_SUFFIX ) ; } else if ( clazz . isEnum ( ) ) { final Class < ? extends Enum > enumClass = ( Class < ? extends Enum > ) clazz ; return getEnumOptions ( enumClass ) ; } else { return "" ; } }
Returns the list of possible options values for this argument .
4,092
public < T9 > Pattern9 < T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 > and ( Observable < T9 > other ) { if ( other == null ) { throw new NullPointerException ( ) ; } return new Pattern9 < T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 > ( o1 , o2 , o3 , o4 , o5 , o6 , o7 , o8 , other ) ; }
Creates a pattern that matches when all eight observable sequences have an available element .
4,093
public < T6 > Pattern6 < T1 , T2 , T3 , T4 , T5 , T6 > and ( Observable < T6 > other ) { if ( other == null ) { throw new NullPointerException ( ) ; } return new Pattern6 < T1 , T2 , T3 , T4 , T5 , T6 > ( o1 , o2 , o3 , o4 , o5 , other ) ; }
Creates a pattern that matches when all five observable sequences have an available element .
4,094
public PatternN and ( Observable < ? extends Object > other ) { if ( other == null ) { throw new NullPointerException ( ) ; } return new PatternN ( observables , other ) ; }
Creates a pattern that matches when all previous observable sequences have an available element .
4,095
public void setElementDefaultAction ( Integer index , String type , String url , Boolean messenger_extensions , String webview_height_ratio , String fallback_url ) { this . elements . get ( index ) . put ( "default_action_type" , type ) ; this . elements . get ( index ) . put ( "default_action_url" , url ) ; this . elements . get ( index ) . put ( "default_action_messenger_extensions" , String . valueOf ( messenger_extensions ) ) ; this . elements . get ( index ) . put ( "default_action_webview_height_ratio" , webview_height_ratio ) ; this . elements . get ( index ) . put ( "default_action_fallback_url" , fallback_url ) ; }
Set Element Default Action
4,096
public void setElementButton ( Integer index , String title , String type , String url , Boolean messenger_extensions , String webview_height_ratio , String fallback_url ) { if ( this . elements . get ( index ) . containsKey ( "buttons" ) ) { HashMap < String , String > button = new HashMap < String , String > ( ) ; button . put ( "title" , title ) ; button . put ( "type" , type ) ; button . put ( "url" , url ) ; button . put ( "messenger_extensions" , String . valueOf ( messenger_extensions ) ) ; button . put ( "webview_height_ratio" , webview_height_ratio ) ; button . put ( "fallback_url" , fallback_url ) ; @ SuppressWarnings ( "unchecked" ) ArrayList < HashMap < String , String > > element_buttons = ( ArrayList < HashMap < String , String > > ) this . elements . get ( index ) . get ( "buttons" ) ; element_buttons . add ( button ) ; this . elements . get ( index ) . put ( "buttons" , element_buttons ) ; } else { ArrayList < HashMap < String , String > > element_buttons = new ArrayList < HashMap < String , String > > ( ) ; HashMap < String , String > button = new HashMap < String , String > ( ) ; button . put ( "title" , title ) ; button . put ( "type" , type ) ; button . put ( "url" , url ) ; button . put ( "messenger_extensions" , String . valueOf ( messenger_extensions ) ) ; button . put ( "webview_height_ratio" , webview_height_ratio ) ; button . put ( "fallback_url" , fallback_url ) ; element_buttons . add ( button ) ; this . elements . get ( index ) . put ( "buttons" , element_buttons ) ; } }
Set Element Button
4,097
public Boolean challenge ( ) { if ( ( this . hub_mode . equals ( "subscribe" ) ) && ( this . hub_verify_token . equals ( this . configs . get ( "verify_token" , "" ) ) ) ) { Logger . info ( "Verify token validated successfully." ) ; return true ; } Logger . error ( "Error validating verify token." ) ; return false ; }
Verify Challenge Data
4,098
public void setQuickReply ( String content_type , String title , String payload , String image_url ) { HashMap < String , String > quick_reply = new HashMap < String , String > ( ) ; quick_reply . put ( "content_type" , content_type ) ; quick_reply . put ( "title" , title ) ; quick_reply . put ( "payload" , payload ) ; quick_reply . put ( "image_url" , image_url ) ; this . message_quick_replies . add ( quick_reply ) ; }
Set Quick Reply
4,099
public Boolean loadPropertiesFile ( String path ) throws IOException { Properties prop = new Properties ( ) ; InputStream input = null ; try { input = new FileInputStream ( path ) ; prop . load ( input ) ; for ( String key : prop . stringPropertyNames ( ) ) { String value = prop . getProperty ( key ) ; configs . put ( key , value ) ; } return true ; } catch ( IOException ex ) { return false ; } }
Load Properties File