idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
42,800 | protected String removeInvalidHeaderCommentsAndProcessVelocityMacros ( String text ) { String answer = "" ; String [ ] lines = text . split ( "\r?\n" ) ; for ( String line : lines ) { String l = line . trim ( ) ; // a bit of Velocity here if ( ! l . startsWith ( "##" ) && ! l . startsWith ( "#set(" ) ) { if ( line . co... | This method should do a full Velocity macro processing ... | 156 | 10 |
42,801 | public File findRootPackage ( File directory ) throws IOException { if ( ! directory . isDirectory ( ) ) { throw new IllegalArgumentException ( "Can't find package inside file. Argument should be valid directory." ) ; } File [ ] children = directory . listFiles ( new FileFilter ( ) { @ Override public boolean accept ( ... | Recursively looks for first nested directory which contains at least one source file | 220 | 15 |
42,802 | public boolean isValidSourceFileOrDir ( File file ) { String name = file . getName ( ) ; return ! isExcludedDotFile ( name ) && ! excludeExtensions . contains ( Files . getExtension ( file . getName ( ) ) ) ; } | Returns true if this file is a valid source file ; so excluding things like . svn directories and whatnot | 57 | 22 |
42,803 | public void writeXmlDocument ( Document document , File file ) throws IOException { try { Transformer tr = transformerFactory . newTransformer ( ) ; tr . setOutputProperty ( OutputKeys . ENCODING , "UTF-8" ) ; tr . setOutputProperty ( OutputKeys . INDENT , "yes" ) ; FileOutputStream fileOutputStream = new FileOutputStr... | Serializes the Document to a File . | 138 | 8 |
42,804 | public String writeXmlDocumentAsString ( Document document ) throws IOException { try { Transformer tr = transformerFactory . newTransformer ( ) ; tr . setOutputProperty ( OutputKeys . ENCODING , "UTF-8" ) ; tr . setOutputProperty ( OutputKeys . INDENT , "yes" ) ; StringWriter writer = new StringWriter ( ) ; StreamResu... | Serializes the Document to a String . | 150 | 8 |
42,805 | public static void notNull ( final Object object , final String argumentName ) { if ( object == null ) { throw new NullPointerException ( getMessage ( "null" , argumentName ) ) ; } } | Validates that the supplied object is not null and throws a NullPointerException otherwise . | 44 | 18 |
42,806 | public static void notEmpty ( final String aString , final String argumentName ) { // Check sanity notNull ( aString , argumentName ) ; if ( aString . length ( ) == 0 ) { throw new IllegalArgumentException ( getMessage ( "empty" , argumentName ) ) ; } } | Validates that the supplied object is not null and throws an IllegalArgumentException otherwise . | 63 | 18 |
42,807 | private String getNamespace ( final Attr attribute ) { final Element parent = attribute . getOwnerElement ( ) ; return parent . getAttribute ( NAMESPACE ) ; } | Retrieves the value of the namespace attribute found within the parent element of the provided attribute . | 37 | 19 |
42,808 | public void restore ( ) { if ( ! restored ) { // Remove the extra Handler from the RootLogger rootLogger . removeHandler ( mavenLogHandler ) ; // Restore the original state to the Root logger rootLogger . setLevel ( originalRootLoggerLevel ) ; for ( Handler current : originalHandlers ) { rootLogger . addHandler ( curre... | Restores the original root Logger state including Level and Handlers . | 89 | 14 |
42,809 | public static LoggingHandlerEnvironmentFacet create ( final Log mavenLog , final Class < ? extends AbstractJaxbMojo > caller , final String encoding ) { // Check sanity Validate . notNull ( mavenLog , "mavenLog" ) ; Validate . notNull ( caller , "caller" ) ; Validate . notEmpty ( encoding , "encoding" ) ; // Find the s... | Factory method creating a new LoggingHandlerEnvironmentFacet wrapping the supplied properties . | 176 | 16 |
42,810 | public ThreadContextClassLoaderBuilder addURL ( final URL anURL ) { // Check sanity Validate . notNull ( anURL , "anURL" ) ; // Add the segment unless already added. for ( URL current : urlList ) { if ( current . toString ( ) . equalsIgnoreCase ( anURL . toString ( ) ) ) { if ( log . isWarnEnabled ( ) ) { log . warn ( ... | Adds the supplied anURL to the list of internal URLs which should be used to build an URLClassLoader . Will only add an URL once and warns about trying to re - add an URL . | 314 | 39 |
42,811 | public static ThreadContextClassLoaderBuilder createFor ( final ClassLoader classLoader , final Log log , final String encoding ) { // Check sanity Validate . notNull ( classLoader , "classLoader" ) ; Validate . notNull ( log , "log" ) ; // All done. return new ThreadContextClassLoaderBuilder ( classLoader , log , enco... | Creates a new ThreadContextClassLoaderBuilder using the supplied original classLoader as well as the supplied Maven Log . | 77 | 24 |
42,812 | public static ThreadContextClassLoaderBuilder createFor ( final Class < ? > aClass , final Log log , final String encoding ) { // Check sanity Validate . notNull ( aClass , "aClass" ) ; // Delegate return createFor ( aClass . getClassLoader ( ) , log , encoding ) ; } | Creates a new ThreadContextClassLoaderBuilder using the original ClassLoader from the supplied Class as well as the given Maven Log . | 67 | 27 |
42,813 | public static String getClassPathElement ( final URL anURL , final String encoding ) throws IllegalArgumentException { // Check sanity Validate . notNull ( anURL , "anURL" ) ; final String protocol = anURL . getProtocol ( ) ; String toReturn = null ; if ( FILE . supports ( protocol ) ) { final String originalPath = anU... | Converts the supplied URL to a class path element . | 281 | 11 |
42,814 | protected String renderJavaDocTag ( final String name , final String value , final SortableLocation location ) { final String nameKey = name != null ? name . trim ( ) : "" ; final String valueKey = value != null ? value . trim ( ) : "" ; // All Done. return "(" + nameKey + "): " + harmonizeNewlines ( valueKey ) ; } | Override this method to yield another | 81 | 6 |
42,815 | protected String harmonizeNewlines ( final String original ) { final String toReturn = original . trim ( ) . replaceAll ( "[\r\n]+" , "\n" ) ; return toReturn . endsWith ( "\n" ) ? toReturn : toReturn + "\n" ; } | Squashes newline characters into | 62 | 6 |
42,816 | @ SuppressWarnings ( "all" ) protected void warnAboutIncorrectPluginConfiguration ( final String propertyName , final String description ) { final StringBuilder builder = new StringBuilder ( ) ; builder . append ( "\n+=================== [Incorrect Plugin Configuration Detected]\n" ) ; builder . append ( "|\n" ) ; buil... | Convenience method to invoke when some plugin configuration is incorrect . Will output the problem as a warning with some degree of log formatting . | 167 | 27 |
42,817 | protected final File getStaleFile ( ) { final String staleFileName = "." + ( getExecution ( ) == null ? "nonExecutionJaxb" : getExecution ( ) . getExecutionId ( ) ) + "-" + getStaleFileName ( ) ; return new File ( staleFileDirectory , staleFileName ) ; } | Acquires the staleFile for this execution | 76 | 9 |
42,818 | protected void logSystemPropertiesAndBasedir ( ) { if ( getLog ( ) . isDebugEnabled ( ) ) { final StringBuilder builder = new StringBuilder ( ) ; builder . append ( "\n+=================== [System properties]\n" ) ; builder . append ( "|\n" ) ; // Sort the system properties final SortedMap < String , Object > props = n... | Prints out the system properties to the Maven Log at Debug level . | 285 | 15 |
42,819 | public static LocaleFacet createFor ( final String localeString , final Log log ) throws MojoExecutionException { // Check sanity Validate . notNull ( log , "log" ) ; Validate . notEmpty ( localeString , "localeString" ) ; final StringTokenizer tok = new StringTokenizer ( localeString , "," , false ) ; final int numTok... | Helper method used to parse a locale configuration string into a Locale instance . | 257 | 15 |
42,820 | public static Level getJavaUtilLoggingLevelFor ( final Log mavenLog ) { // Check sanity Validate . notNull ( mavenLog , "mavenLog" ) ; Level toReturn = Level . SEVERE ; if ( mavenLog . isDebugEnabled ( ) ) { toReturn = Level . FINER ; } else if ( mavenLog . isInfoEnabled ( ) ) { toReturn = Level . INFO ; } else if ( ma... | Retrieves the JUL Level matching the supplied Maven Log . | 125 | 13 |
42,821 | public static Filter getLoggingFilter ( final String ... requiredPrefixes ) { // Check sanity Validate . notNull ( requiredPrefixes , "requiredPrefixes" ) ; // All done. return new Filter ( ) { // Internal state private List < String > requiredPrefs = Arrays . asList ( requiredPrefixes ) ; @ Override public boolean isL... | Retrieves a java . util . Logging filter used to ensure that only LogRecords whose logger names start with any of the required prefixes are logged . | 142 | 33 |
42,822 | public static boolean isNamedElement ( final Node aNode ) { final boolean isElementNode = aNode != null && aNode . getNodeType ( ) == Node . ELEMENT_NODE ; return isElementNode && getNamedAttribute ( aNode , NAME_ATTRIBUTE ) != null && ! getNamedAttribute ( aNode , NAME_ATTRIBUTE ) . isEmpty ( ) ; } | Checks if the supplied DOM Node is a DOM Element having a defined name attribute . | 88 | 17 |
42,823 | public static String getElementTagName ( final Node aNode ) { if ( aNode != null && aNode . getNodeType ( ) == Node . ELEMENT_NODE ) { final Element theElement = ( Element ) aNode ; return theElement . getTagName ( ) ; } // The Node was not an Element. return null ; } | Retrieves the TagName for the supplied Node if it is an Element and null otherwise . | 73 | 19 |
42,824 | public static String getXPathFor ( final Node aNode ) { List < String > nodeNameList = new ArrayList < String > ( ) ; for ( Node current = aNode ; current != null ; current = current . getParentNode ( ) ) { final String currentNodeName = current . getNodeName ( ) ; final String nameAttribute = DomHelper . getNameAttrib... | Retrieves the XPath for the supplied Node within its document . | 306 | 14 |
42,825 | public static ClassLocation getClassLocation ( final Node aNode , final Set < ClassLocation > classLocations ) { if ( aNode != null ) { // The LocalName of the supplied DOM Node should be either "complexType" or "simpleType". final String nodeLocalName = aNode . getLocalName ( ) ; final boolean acceptableType = "comple... | Retrieves the ClassLocation for the supplied aNode . | 235 | 12 |
42,826 | public static MethodLocation getMethodLocation ( final Node aNode , final Set < MethodLocation > methodLocations ) { MethodLocation toReturn = null ; if ( aNode != null && CLASS_FIELD_METHOD_ELEMENT_NAMES . contains ( aNode . getLocalName ( ) . toLowerCase ( ) ) ) { final MethodLocation validLocation = getFieldOrMethod... | Finds the MethodLocation within the given Set which corresponds to the supplied DOM Node . | 171 | 17 |
42,827 | public static FieldLocation getFieldLocation ( final Node aNode , final Set < FieldLocation > fieldLocations ) { FieldLocation toReturn = null ; if ( aNode != null ) { if ( CLASS_FIELD_METHOD_ELEMENT_NAMES . contains ( aNode . getLocalName ( ) . toLowerCase ( ) ) ) { // This is a ComplexType which correspond to a Java ... | Retrieves a FieldLocation from the supplied Set provided that the FieldLocation matches the supplied Node . | 209 | 20 |
42,828 | public static < T extends FieldLocation > T getFieldOrMethodLocationIfValid ( final Node aNode , final Node containingClassNode , final Set < ? extends FieldLocation > locations ) { T toReturn = null ; if ( containingClassNode != null ) { // Do we have a FieldLocation corresponding to the supplied Node? for ( FieldLoca... | Retrieves a FieldLocation or MethodLocation from the supplied Set of Field - or MethodLocations provided that the supplied Node has the given containing Node corresponding to a Class or an Enum . | 501 | 39 |
42,829 | public static void insertXmlDocumentationAnnotationsFor ( final Node aNode , final SortedMap < ClassLocation , JavaDocData > classJavaDocs , final SortedMap < FieldLocation , JavaDocData > fieldJavaDocs , final SortedMap < MethodLocation , JavaDocData > methodJavaDocs , final JavaDocRenderer renderer ) { JavaDocData ja... | Processes the supplied DOM Node inserting XML Documentation annotations if applicable . | 475 | 13 |
42,830 | private void initialize ( final Reader xmlFileStream ) { // Build a DOM model. final Document parsedDocument = XsdGeneratorHelper . parseXmlStream ( xmlFileStream ) ; // Process the DOM model. XsdGeneratorHelper . process ( parsedDocument . getFirstChild ( ) , true , new NamespaceAttributeNodeProcessor ( ) ) ; } | Initializes this SimpleNamespaceResolver to collect namespace data from the provided stream . | 75 | 17 |
42,831 | public final void setPatternPrefix ( final String patternPrefix ) { // Check sanity validateDiSetterCalledBeforeInitialization ( "patternPrefix" ) ; // Check sanity if ( patternPrefix != null ) { // Assign internal state this . patternPrefix = patternPrefix ; } else { addDelayedLogMessage ( "warn" , "Received null patt... | Assigns a prefix to be prepended to any patterns submitted to this AbstractPatternFilter . | 113 | 19 |
42,832 | public void setConverter ( final StringConverter < T > converter ) { // Check sanity Validate . notNull ( converter , "converter" ) ; validateDiSetterCalledBeforeInitialization ( "converter" ) ; // Assign internal state this . converter = converter ; } | Assigns the StringConverter used to convert T - type objects to Strings . This StringConverter is used to acquire input comparison values for all Patterns to T - object candidates . | 65 | 40 |
42,833 | public static < T > boolean matchAtLeastOnce ( final T object , final List < Filter < T > > filters ) { // Check sanity Validate . notNull ( filters , "filters" ) ; boolean acceptedByAtLeastOneFilter = false ; for ( Filter < T > current : filters ) { if ( current . accept ( object ) ) { acceptedByAtLeastOneFilter = tru... | Algorithms for accepting the supplied object if at least one of the supplied Filters accepts it . | 104 | 20 |
42,834 | public static < T > boolean rejectAtLeastOnce ( final T object , final List < Filter < T > > filters ) { // Check sanity Validate . notNull ( filters , "filters" ) ; boolean rejectedByAtLeastOneFilter = false ; for ( Filter < T > current : filters ) { if ( ! current . accept ( object ) ) { rejectedByAtLeastOneFilter = ... | Algorithms for rejecting the supplied object if at least one of the supplied Filters does not accept it . | 105 | 22 |
42,835 | public static < T > boolean noFilterMatches ( final T object , final List < Filter < T > > filters ) { // Check sanity Validate . notNull ( filters , "filters" ) ; boolean matchedAtLeastOnce = false ; for ( Filter < T > current : filters ) { if ( current . accept ( object ) ) { matchedAtLeastOnce = true ; } } // All do... | Algorithms for rejecting the supplied object if at least one of the supplied Filters rejects it . | 96 | 20 |
42,836 | public static FileFilter adapt ( final Filter < File > toAdapt ) { // Check sanity Validate . notNull ( toAdapt , "toAdapt" ) ; // Already a FileFilter? if ( toAdapt instanceof FileFilter ) { return ( FileFilter ) toAdapt ; } // Wrap and return. return new FileFilter ( ) { @ Override public boolean accept ( final File ... | Adapts the Filter specification to the FileFilter interface to enable immediate use for filtering File lists . | 95 | 19 |
42,837 | public static List < FileFilter > adapt ( final List < Filter < File > > toAdapt ) { final List < FileFilter > toReturn = new ArrayList < FileFilter > ( ) ; if ( toAdapt != null ) { for ( Filter < File > current : toAdapt ) { toReturn . add ( adapt ( current ) ) ; } } // All done. return toReturn ; } | Adapts the supplied List of Filter specifications to a List of FileFilters . | 82 | 16 |
42,838 | public static < T > void initialize ( final Log log , final List < Filter < T > > filters ) { // Check sanity Validate . notNull ( log , "log" ) ; Validate . notNull ( filters , "filters" ) ; for ( Filter < T > current : filters ) { current . initialize ( log ) ; } } | Initializes the supplied Filters by assigning the given Log . | 73 | 12 |
42,839 | public static File getCanonicalFile ( final File file ) { // Check sanity Validate . notNull ( file , "file" ) ; // All done try { return file . getCanonicalFile ( ) ; } catch ( IOException e ) { throw new IllegalArgumentException ( "Could not acquire the canonical file for [" + file . getAbsolutePath ( ) + "]" , e ) ;... | Acquires the canonical File for the supplied file . | 88 | 11 |
42,840 | public static URL getUrlFor ( final File aFile ) throws IllegalArgumentException { // Check sanity Validate . notNull ( aFile , "aFile" ) ; try { return aFile . toURI ( ) . normalize ( ) . toURL ( ) ; } catch ( MalformedURLException e ) { throw new IllegalArgumentException ( "Could not retrieve the URL from file [" + g... | Retrieves the URL for the supplied File . Convenience method which hides exception handling for the operation in question . | 104 | 24 |
42,841 | public static File getFileFor ( final URL anURL , final String encoding ) { // Check sanity Validate . notNull ( anURL , "anURL" ) ; Validate . notNull ( encoding , "encoding" ) ; final String protocol = anURL . getProtocol ( ) ; File toReturn = null ; if ( "file" . equalsIgnoreCase ( protocol ) ) { try { final String ... | Acquires the file for a supplied URL provided that its protocol is is either a file or a jar . | 417 | 22 |
42,842 | public static void createDirectory ( final File aDirectory , final boolean cleanBeforeCreate ) throws MojoExecutionException { // Check sanity Validate . notNull ( aDirectory , "aDirectory" ) ; validateFileOrDirectoryName ( aDirectory ) ; // Clean an existing directory? if ( cleanBeforeCreate ) { try { FileUtils . dele... | Convenience method to successfully create a directory - or throw an exception if failing to create it . | 258 | 20 |
42,843 | public static String relativize ( final String path , final File parentDir , final boolean removeInitialFileSep ) { // Check sanity Validate . notNull ( path , "path" ) ; Validate . notNull ( parentDir , "parentDir" ) ; final String basedirPath = FileSystemUtilities . getCanonicalPath ( parentDir ) ; String toReturn = ... | If the supplied path refers to a file or directory below the supplied basedir the returned path is identical to the part below the basedir . | 175 | 28 |
42,844 | public String getNormalizedXml ( String filePath ) { // Read the provided filename final StringWriter toReturn = new StringWriter ( ) ; final BufferedReader in ; try { in = new BufferedReader ( new FileReader ( new File ( filePath ) ) ) ; } catch ( FileNotFoundException e ) { throw new IllegalArgumentException ( "Could... | Reads the XML file found at the provided filePath returning a normalized XML form suitable for comparison . | 248 | 20 |
42,845 | public static Map < String , SimpleNamespaceResolver > getFileNameToResolverMap ( final File outputDirectory ) throws MojoExecutionException { final Map < String , SimpleNamespaceResolver > toReturn = new TreeMap < String , SimpleNamespaceResolver > ( ) ; // Each generated schema file should be written to the output di... | Acquires a map relating generated schema filename to its SimpleNamespaceResolver . | 195 | 17 |
42,846 | public static void validateSchemasInPluginConfiguration ( final List < TransformSchema > configuredTransformSchemas ) throws MojoExecutionException { final List < String > uris = new ArrayList < String > ( ) ; final List < String > prefixes = new ArrayList < String > ( ) ; final List < String > fileNames = new ArrayLis... | Validates that the list of Schemas provided within the configuration all contain unique values . Should a MojoExecutionException be thrown it contains informative text about the exact nature of the configuration problem - we should simplify for all plugin users . | 534 | 48 |
42,847 | public static int insertJavaDocAsAnnotations ( final Log log , final String encoding , final File outputDir , final SearchableDocumentation docs , final JavaDocRenderer renderer ) { // Check sanity Validate . notNull ( docs , "docs" ) ; Validate . notNull ( log , "log" ) ; Validate . notNull ( outputDir , "outputDir" )... | Inserts XML documentation annotations into all generated XSD files found within the supplied outputDir . | 416 | 18 |
42,848 | public static void replaceNamespacePrefixes ( final Map < String , SimpleNamespaceResolver > resolverMap , final List < TransformSchema > configuredTransformSchemas , final Log mavenLog , final File schemaDirectory , final String encoding ) throws MojoExecutionException { if ( mavenLog . isDebugEnabled ( ) ) { mavenLog... | Replaces all namespaces within generated schema files as instructed by the configured Schema instances . | 615 | 18 |
42,849 | public static void renameGeneratedSchemaFiles ( final Map < String , SimpleNamespaceResolver > resolverMap , final List < TransformSchema > configuredTransformSchemas , final Log mavenLog , final File schemaDirectory , final String charsetName ) { // Create the map relating namespace URI to desired filenames. Map < Str... | Updates all schemaLocation attributes within the generated schema files to match the file properties within the Schemas read from the plugin configuration . After that the files are physically renamed . | 634 | 35 |
42,850 | public static Document parseXmlStream ( final Reader xmlStream ) { // Build a DOM model of the provided xmlFileStream. final DocumentBuilderFactory factory = DocumentBuilderFactory . newInstance ( ) ; factory . setNamespaceAware ( true ) ; try { return factory . newDocumentBuilder ( ) . parse ( new InputSource ( xmlStr... | Parses the provided InputStream to create a dom Document . | 101 | 13 |
42,851 | protected static String getHumanReadableXml ( final Node node ) { StringWriter toReturn = new StringWriter ( ) ; try { Transformer transformer = getFactory ( ) . newTransformer ( ) ; transformer . setOutputProperty ( OutputKeys . INDENT , "yes" ) ; transformer . setOutputProperty ( OutputKeys . STANDALONE , "yes" ) ; t... | Converts the provided DOM Node to a pretty - printed XML - formatted string . | 148 | 16 |
42,852 | private static Document parseXmlToDocument ( final File xmlFile ) { Document result = null ; Reader reader = null ; try { reader = new FileReader ( xmlFile ) ; result = parseXmlStream ( reader ) ; } catch ( FileNotFoundException e ) { // This should never happen... } finally { IOUtil . close ( reader ) ; } return resul... | Creates a Document from parsing the XML within the provided xmlFile . | 80 | 14 |
42,853 | public ArgumentBuilder withPreCompiledArguments ( final List < String > preCompiledArguments ) { // Check sanity Validate . notNull ( preCompiledArguments , "preCompiledArguments" ) ; // Add the preCompiledArguments in the exact order they were given. synchronized ( lock ) { for ( String current : preCompiledArguments ... | Adds the supplied pre - compiled arguments in the same order as they were given . | 96 | 16 |
42,854 | public static int getJavaMajorVersion ( ) { final String [ ] versionElements = System . getProperty ( JAVA_VERSION_PROPERTY ) . split ( "\\." ) ; final int [ ] versionNumbers = new int [ versionElements . length ] ; for ( int i = 0 ; i < versionElements . length ; i ++ ) { try { versionNumbers [ i ] = Integer . parseIn... | Retrieves the major java runtime version as an integer . | 219 | 12 |
42,855 | public < V , T extends Enum & Option > OptionsMapper env ( final String name , final T option , final Function < String , V > converter ) { register ( "env: " + name , option , System . getenv ( name ) , converter ) ; return this ; } | Map environment variable value to option . | 60 | 7 |
42,856 | public < V , T extends Enum & Option > OptionsMapper string ( final T option , final String value , final Function < String , V > converter ) { register ( "" , option , value , converter ) ; return this ; } | Map string to option . When value is null or empty - nothing happens . | 49 | 15 |
42,857 | public static Managed registerInjector ( final Application application , final Injector injector ) { Preconditions . checkNotNull ( application , "Application instance required" ) ; Preconditions . checkArgument ( ! INJECTORS . containsKey ( application ) , "Injector already registered for application %s" , application... | Used internally to register application specific injector . | 140 | 9 |
42,858 | @ SuppressWarnings ( "unchecked" ) public static < T > Class < T > getInstanceClass ( final T object ) { final Class cls = object . getClass ( ) ; return cls . getName ( ) . contains ( "$$EnhancerByGuice" ) ? ( Class < T > ) cls . getSuperclass ( ) : cls ; } | Used to get correct object type even if it s guice proxy . | 82 | 14 |
42,859 | public void scan ( final ClassVisitor visitor ) { if ( scanned == null ) { performScan ( ) ; } for ( Class < ? > cls : scanned ) { visitor . visit ( cls ) ; } } | Scan configured classpath packages . | 46 | 6 |
42,860 | public static < T > List < T > removeTypes ( final List < T > list , final List < Class < ? extends T > > filter ) { final Iterator it = list . iterator ( ) ; while ( it . hasNext ( ) ) { final Class type = it . next ( ) . getClass ( ) ; if ( filter . contains ( type ) ) { it . remove ( ) ; } } return list ; } | Filter list from objects of type present in filter list . | 90 | 11 |
42,861 | public ConfigPath findByPath ( final String path ) { return paths . stream ( ) . filter ( it -> it . getPath ( ) . equalsIgnoreCase ( path ) ) . findFirst ( ) . orElse ( null ) ; } | Case insensitive exact match . | 51 | 5 |
42,862 | public List < ConfigPath > findAllRootPaths ( ) { return paths . stream ( ) . filter ( it -> ! it . getPath ( ) . contains ( DOT ) ) . collect ( Collectors . toList ( ) ) ; } | For example it would always contain logging metrics and server paths from dropwizard configuration . | 51 | 17 |
42,863 | public void hkManage ( final Class < ? > type ) { if ( ! JerseyBinding . isHK2Managed ( type , options . get ( JerseyExtensionsManagedByGuice ) ) ) { throw new WrongContextException ( "HK2 creates service %s which must be managed by guice." , type . getName ( ) ) ; } hkManaged . add ( type ) ; } | Called by specific HK2 lifecycle listener to check if bean is properly instantiated by HK2 . | 88 | 21 |
42,864 | public void guiceManage ( final Class < ? > type ) { if ( JerseyBinding . isHK2Managed ( type , options . get ( JerseyExtensionsManagedByGuice ) ) ) { throw new WrongContextException ( "Guice creates service %s which must be managed by HK2." , type . getName ( ) ) ; } guiceManaged . add ( type ) ; } | Called by specific guice provision listener to check if bean is properly instantiated by guice . | 87 | 20 |
42,865 | private void checkHkFirstMode ( ) { final boolean guiceyFirstMode = context . option ( JerseyExtensionsManagedByGuice ) ; if ( ! guiceyFirstMode ) { Preconditions . checkState ( context . option ( UseHkBridge ) , "HK2 management for jersey extensions is enabled by default " + "(InstallersOptions.JerseyExtensionsManaged... | When HK2 management for jersey extensions is enabled by default then guice bridge must be enabled . Without it guice beans could not be used in resources and other jersey extensions . If this is expected then guice support is not needed at all . | 127 | 49 |
42,866 | public static void register ( final GuiceyConfigurationHook hook ) { if ( HOOKS . get ( ) == null ) { // to avoid duplicate registrations HOOKS . set ( new LinkedHashSet <> ( ) ) ; } HOOKS . get ( ) . add ( hook ) ; } | Register hook for current thread . Must be called before application initialization otherwise will not be used at all . | 65 | 20 |
42,867 | @ SuppressWarnings ( "unchecked" ) public static void configureModules ( final ConfigurationContext context ) { final Options options = new Options ( context . options ( ) ) ; for ( Module mod : context . getEnabledModules ( ) ) { if ( mod instanceof BootstrapAwareModule ) { ( ( BootstrapAwareModule ) mod ) . setBootst... | Post - process registered modules by injecting bootstrap configuration environment and options objects . | 224 | 15 |
42,868 | public void activate ( ) { GuiceBridge . getGuiceBridge ( ) . initializeGuiceBridge ( locator ) ; final GuiceIntoHK2Bridge guiceBridge = locator . getService ( GuiceIntoHK2Bridge . class ) ; guiceBridge . bridgeGuiceInjector ( injector ) ; } | Activate HK2 guice bridge . | 71 | 8 |
42,869 | protected boolean isForceSingleton ( final Class < ? > type , final boolean hkManaged ) { return ( ( Boolean ) option ( ForceSingletonForJerseyExtensions ) ) && ! hasScopeAnnotation ( type , hkManaged ) ; } | Singleton binding should not be forced if bean has explicit scope declaration . | 55 | 14 |
42,870 | private boolean hasScopeAnnotation ( final Class < ? > type , final boolean hkManaged ) { boolean found = false ; for ( Annotation ann : type . getAnnotations ( ) ) { final Class < ? extends Annotation > annType = ann . annotationType ( ) ; if ( annType . isAnnotationPresent ( Scope . class ) ) { found = true ; break ;... | Checks scope annotation presence directly on bean . Base classes are not checked as scope is not inheritable . | 126 | 21 |
42,871 | public void registerCommands ( final List < Class < Command > > commands ) { setScope ( ConfigScope . ClasspathScan . getType ( ) ) ; for ( Class < Command > cmd : commands ) { register ( ConfigItem . Command , cmd ) ; } closeScope ( ) ; } | Register commands resolved with classpath scan . | 61 | 8 |
42,872 | private void applyPredicatesForRegisteredItems ( final List < PredicateHandler > predicates ) { ImmutableList . builder ( ) . addAll ( getEnabledModules ( ) ) . addAll ( getEnabledBundles ( ) ) . addAll ( getEnabledExtensions ( ) ) . addAll ( getEnabledInstallers ( ) ) . build ( ) . stream ( ) . < ItemInfo > map ( this... | Disable predicate could be registered after some items registration and to make sure that predicate affects all these items - apply to all currenlty registered items . | 111 | 30 |
42,873 | @ SuppressWarnings ( "unchecked" ) private < T extends ItemInfoImpl > T getOrCreateInfo ( final ConfigItem type , final Object item ) { final Class < ? > itemType = getType ( item ) ; final T info ; // details holder allows to implicitly filter by type and avoid duplicate registration if ( detailsHolder . containsKey (... | Disabled items may not be actually registered . In order to register disable info in uniform way dummy container is created . | 142 | 23 |
42,874 | @ SafeVarargs public final OptionsConfig hideGroups ( final Class < Enum > ... groups ) { hiddenGroups . addAll ( Arrays . asList ( groups ) ) ; return this ; } | Hide option groups from reporting . | 43 | 6 |
42,875 | public static void overrideScope ( final Runnable action ) { override . set ( true ) ; try { action . run ( ) ; } finally { override . remove ( ) ; } } | Use to register overriding modules . Such complex approach was used because overriding modules is the only item that require additional parameter during registration . This parameter may be used in disable predicate to differentiate overriding modules from normal modules . | 39 | 41 |
42,876 | public final Reporter line ( final String line , final Object ... args ) { counter ++ ; wasEmptyLine = false ; message . append ( TAB ) . append ( String . format ( line , args ) ) . append ( NEWLINE ) ; return this ; } | Prints formatted line . | 54 | 5 |
42,877 | @ Override public String renderReport ( final ContextTreeConfig config ) { final Set < Class < ? > > scopes = service . getActiveScopes ( ! config . isHideDisables ( ) ) ; final TreeNode root = new TreeNode ( "APPLICATION" ) ; if ( ! config . getHiddenScopes ( ) . contains ( Application . getType ( ) ) ) { renderScopeC... | Renders configuration tree report according to provided config . By default report padded left with one tab . Subtrees are always padded with empty lines for better visibility . | 243 | 32 |
42,878 | private void renderBundle ( final ContextTreeConfig config , final TreeNode root , final Class < ? > scope , final Class < Object > bundle ) { final BundleItemInfo info = service . getData ( ) . getInfo ( bundle ) ; if ( isHidden ( config , info , scope ) ) { return ; } final List < String > markers = Lists . newArrayL... | Renders bundle if allowed . | 221 | 6 |
42,879 | @ SuppressWarnings ( "checkstyle:BooleanExpressionComplexity" ) private boolean isHidden ( final ContextTreeConfig config , final ItemInfo info , final Class < ? > scope ) { // item explicitly hidden final boolean hidden = config . getHiddenItems ( ) . contains ( info . getItemType ( ) ) ; // installer disabled final b... | Checks element visibility according to config . Universal place to check visibility for either simple config items or bundles and special scopes . | 220 | 25 |
42,880 | public static ConfigurationTree build ( final Bootstrap bootstrap , final Configuration configuration , final boolean introspect ) { final List < Class > roots = resolveRootTypes ( new ArrayList <> ( ) , configuration . getClass ( ) ) ; if ( introspect ) { final List < ConfigPath > content = resolvePaths ( bootstrap . ... | Analyze configuration object to extract bindable parts . | 163 | 10 |
42,881 | @ Override public String renderReport ( final OptionsConfig config ) { final StringBuilder res = new StringBuilder ( ) ; render ( config , res ) ; return res . toString ( ) ; } | Renders options report . | 41 | 5 |
42,882 | public void count ( final Stat name , final int count ) { Integer value = counters . get ( name ) ; value = value == null ? count : value + count ; counters . put ( name , value ) ; } | Inserts value for first call and sum values for consequent calls . | 45 | 14 |
42,883 | public void startHkTimer ( final Stat name ) { timer ( GuiceyTime ) ; if ( ! HKTime . equals ( name ) ) { timer ( HKTime ) ; } timer ( name ) ; } | Special methods for tracking time in HK2 scope . Such complication used to avoid using 3 different trackers in code . HK2 initialization is performed after bundles run and so out of scope of GuiceBundle . | 45 | 42 |
42,884 | private List < FeatureInstaller > prepareInstallers ( final List < Class < ? extends FeatureInstaller > > installerClasses ) { final List < FeatureInstaller > installers = Lists . newArrayList ( ) ; // different instance then used in guice context, but it's just an accessor object final Options options = new Options ( ... | Instantiate all found installers using default constructor . | 192 | 10 |
42,885 | @ SuppressWarnings ( "PMD.PrematureDeclaration" ) private void resolveExtensions ( final ExtensionsHolder holder ) { final Stopwatch timer = context . stat ( ) . timer ( Stat . ExtensionsRecognitionTime ) ; final boolean guiceFirstMode = context . option ( JerseyExtensionsManagedByGuice ) ; final List < Class < ? > > m... | Performs one more classpath scan to search for extensions or simply install manually provided extension classes . | 304 | 19 |
42,886 | @ SuppressWarnings ( "unchecked" ) private void bindExtension ( final ExtensionItemInfo item , final FeatureInstaller installer , final ExtensionsHolder holder ) { final Class < ? extends FeatureInstaller > installerClass = installer . getClass ( ) ; final Class < ? > type = item . getType ( ) ; holder . register ( ins... | Bind extension to guice context . | 156 | 7 |
42,887 | public static String renderDisabledInstaller ( final Class < FeatureInstaller > type ) { return String . format ( "-%-19s %-38s" , FeatureUtils . getInstallerExtName ( type ) , brackets ( renderClass ( type ) ) ) ; } | Renders disabled installer line . The same as installer line but with - before installer name and without markers . | 58 | 21 |
42,888 | public static String renderPackage ( final Class < ? > type ) { return PACKAGE_FORMATTER . abbreviate ( type . isMemberClass ( ) && ! type . isAnonymousClass ( ) ? type . getDeclaringClass ( ) . getName ( ) : type . getPackage ( ) . getName ( ) ) ; } | If provided type is inner class then declaring class will be rendered instead of package . | 70 | 16 |
42,889 | @ Override public String renderReport ( final DiagnosticConfig config ) { final StringBuilder res = new StringBuilder ( ) ; printCommands ( config , res ) ; printBundles ( config , res ) ; if ( config . isPrintInstallers ( ) ) { printInstallers ( config , res ) ; printDisabledExtensions ( config , res , true ) ; } else... | Renders diagnostic report according to config . | 111 | 8 |
42,890 | private void configureFromBundles ( ) { context . lifecycle ( ) . runPhase ( context . getConfiguration ( ) , context . getConfigurationTree ( ) , context . getEnvironment ( ) ) ; final Stopwatch timer = context . stat ( ) . timer ( BundleTime ) ; final Stopwatch resolutionTimer = context . stat ( ) . timer ( BundleRes... | Apply configuration from registered bundles . If dropwizard bundles support is enabled lookup them too . | 177 | 18 |
42,891 | @ SuppressWarnings ( "deprecation" ) private void bindEnvironment ( ) { bind ( Bootstrap . class ) . toInstance ( bootstrap ( ) ) ; bind ( Environment . class ) . toInstance ( environment ( ) ) ; install ( new ConfigBindingModule ( configuration ( ) , configurationTree ( ) , context . option ( BindConfigurationInterfac... | Bind bootstrap configuration and environment objects to be able to use them as injectable . | 82 | 17 |
42,892 | @ SafeVarargs public static void enableBundles ( final Class < ? extends GuiceyBundle > ... bundles ) { final String prop = Joiner . on ( ' ' ) . join ( toStrings ( Lists . newArrayList ( bundles ) ) ) ; System . setProperty ( BUNDLES_PROPERTY , prop ) ; } | Sets system property value to provided classes . Shortcut is useful to set property from code for example in unit tests . | 75 | 24 |
42,893 | public boolean cancel ( boolean ign ) { assert op != null : "No operation" ; op . cancel ( ) ; notifyListeners ( ) ; return op . getState ( ) == OperationState . WRITE_QUEUED ; } | Cancel this operation if possible . | 49 | 7 |
42,894 | public Long getCas ( ) { if ( cas == null ) { try { get ( ) ; } catch ( InterruptedException e ) { status = new OperationStatus ( false , "Interrupted" , StatusCode . INTERRUPTED ) ; } catch ( ExecutionException e ) { getLogger ( ) . warn ( "Error getting cas of operation" , e ) ; } } if ( cas == null && status . isSuc... | Get the CAS for this operation . | 121 | 7 |
42,895 | public OperationStatus getStatus ( ) { if ( status == null ) { try { get ( ) ; } catch ( InterruptedException e ) { status = new OperationStatus ( false , "Interrupted" , StatusCode . INTERRUPTED ) ; } catch ( ExecutionException e ) { getLogger ( ) . warn ( "Error getting status of operation" , e ) ; } } return status ... | Get the current status of this operation . | 85 | 8 |
42,896 | public void set ( T o , OperationStatus s ) { objRef . set ( o ) ; status = s ; } | Set the Operation associated with this OperationFuture . | 25 | 9 |
42,897 | public static Logger getLogger ( String name ) { if ( name == null ) { throw new NullPointerException ( "Logger name may not be null." ) ; } init ( ) ; return ( instance . internalGetLogger ( name ) ) ; } | Get a logger by name . | 56 | 6 |
42,898 | private Logger internalGetLogger ( String name ) { assert name != null : "Name was null" ; Logger rv = instances . get ( name ) ; if ( rv == null ) { Logger newLogger = null ; try { newLogger = getNewInstance ( name ) ; } catch ( Exception e ) { throw new RuntimeException ( "Problem getting logger" , e ) ; } Logger tmp... | Get an instance of Logger from internal mechanisms . | 146 | 10 |
42,899 | @ SuppressWarnings ( "unchecked" ) private void getConstructor ( ) { Class < ? extends Logger > c = DefaultLogger . class ; String className = System . getProperty ( "net.spy.log.LoggerImpl" ) ; if ( className != null ) { try { c = ( Class < ? extends Logger > ) Class . forName ( className ) ; } catch ( NoClassDefFound... | Find the appropriate constructor | 471 | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.