idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
5,200 | public void add ( AbstractSchemaProperty property ) { Class type = property . getClass ( ) ; properties . put ( type , property ) ; if ( SchemaProperty . class . isAssignableFrom ( type ) ) { propertyNames . add ( property . getName ( ) ) ; } else if ( SchemaPropertyList . class . isAssignableFrom ( type ) ) { propertyNames . add ( property . getName ( ) ) ; } else if ( SchemaPropertyRef . class . isAssignableFrom ( type ) ) { referenceNames . add ( property . getName ( ) ) ; } else if ( SchemaPropertyRefList . class . isAssignableFrom ( type ) ) { referenceNames . add ( property . getName ( ) ) ; } else if ( SchemaPropertyRefMap . class . isAssignableFrom ( type ) ) { referenceNames . add ( property . getName ( ) ) ; } else { throw new IllegalArgumentException ( "Unknown property type " + type . getName ( ) ) ; } } | Adds a property of a specific type to this schema . Not to be used by users . | 225 | 18 |
5,201 | public < T extends AbstractSchemaProperty > Set < T > getIndexed ( ) { HashSet < AbstractSchemaProperty > indexed = new HashSet <> ( ) ; for ( AbstractSchemaProperty prop : properties . values ( ) ) { if ( prop . isIndexed ( ) ) indexed . add ( prop ) ; } return ( Set < T > ) indexed ; } | Returns all properties that have been marked as indexed . | 80 | 10 |
5,202 | @ SuppressWarnings ( { "unchecked" , "rawtypes" } ) public < T extends AbstractSchemaProperty > Set < T > get ( final Class < T > clazz ) { return ( Set < T > ) properties . get ( clazz ) ; } | Returns all the properties of a particular type . | 59 | 9 |
5,203 | public < T extends AbstractSchemaProperty > T get ( final Class < T > clazz , final String name ) { Set < T > propertyCollection = get ( clazz ) ; for ( T property : propertyCollection ) { if ( property . getName ( ) . equals ( name ) ) { return property ; } } return null ; } | Returns a specific properties of a particular type identified with a name . | 71 | 13 |
5,204 | public void setVelocityPropertiesMap ( Map < String , Object > velocityPropertiesMap ) { if ( velocityPropertiesMap != null ) { this . velocityProperties . putAll ( velocityPropertiesMap ) ; } } | Set Velocity properties as Map to allow for non - String values like ds . resource . loader . instance . | 48 | 22 |
5,205 | public VelocityEngine createVelocityEngine ( ) throws IOException , VelocityException { VelocityEngine velocityEngine = newVelocityEngine ( ) ; Map < String , Object > props = new HashMap < String , Object > ( ) ; // Load config file if set. if ( this . configLocation != null ) { if ( logger . isInfoEnabled ( ) ) { logger . info ( "Loading Velocity config from [" + this . configLocation + "]" ) ; } CollectionUtils . mergePropertiesIntoMap ( PropertiesLoaderUtils . loadProperties ( this . configLocation ) , props ) ; } // Merge local properties if set. if ( ! this . velocityProperties . isEmpty ( ) ) { props . putAll ( this . velocityProperties ) ; } // Set a resource loader path, if required. if ( this . resourceLoaderPath != null ) { initVelocityResourceLoader ( velocityEngine , this . resourceLoaderPath ) ; } // Log via Commons Logging? if ( this . overrideLogging ) { velocityEngine . setProperty ( RuntimeConstants . RUNTIME_LOG_LOGSYSTEM , new CommonsLogLogChute ( ) ) ; } // Apply properties to VelocityEngine. for ( Map . Entry < String , Object > entry : props . entrySet ( ) ) { velocityEngine . setProperty ( entry . getKey ( ) , entry . getValue ( ) ) ; } postProcessVelocityEngine ( velocityEngine ) ; // Perform actual initialization. velocityEngine . init ( ) ; return velocityEngine ; } | Prepare the VelocityEngine instance and return it . | 321 | 10 |
5,206 | private synchronized void set ( Artifact artifact , Content content ) { Map < String , Map < String , Map < Artifact , Content > > > artifactMap = contents . get ( artifact . getGroupId ( ) ) ; if ( artifactMap == null ) { artifactMap = new HashMap < String , Map < String , Map < Artifact , Content > > > ( ) ; contents . put ( artifact . getGroupId ( ) , artifactMap ) ; } Map < String , Map < Artifact , Content > > versionMap = artifactMap . get ( artifact . getArtifactId ( ) ) ; if ( versionMap == null ) { versionMap = new HashMap < String , Map < Artifact , Content > > ( ) ; artifactMap . put ( artifact . getArtifactId ( ) , versionMap ) ; } Map < Artifact , Content > filesMap = versionMap . get ( artifact . getVersion ( ) ) ; if ( filesMap == null ) { filesMap = new HashMap < Artifact , Content > ( ) ; versionMap . put ( artifact . getVersion ( ) , filesMap ) ; } filesMap . put ( artifact , content ) ; } | Sets the content for a specified artifact . | 240 | 9 |
5,207 | public static BeanId create ( final String instanceId , final String schemaName ) { if ( instanceId == null || "" . equals ( instanceId ) ) { throw CFG107_MISSING_ID ( ) ; } return new BeanId ( instanceId , schemaName ) ; } | Create a bean identification . | 60 | 5 |
5,208 | public static boolean isPredecessor ( KeyValue kv ) { if ( Bytes . equals ( kv . getFamily ( ) , PRED_COLUMN_FAMILY ) ) { return true ; } return false ; } | If this key value is of predecessor familiy type . | 50 | 12 |
5,209 | public static HOTPProvider instantiateProvider ( boolean allowTestProvider ) { HOTPProvider resultProvider = null ; ServiceLoader < HOTPProvider > loader = ServiceLoader . load ( HOTPProvider . class ) ; Iterator < HOTPProvider > iterator = loader . iterator ( ) ; if ( iterator . hasNext ( ) ) { while ( iterator . hasNext ( ) ) { HOTPProvider provider = iterator . next ( ) ; if ( ! "com.payneteasy.superfly.spring.TestHOTPProvider" . equals ( provider . getClass ( ) . getName ( ) ) || allowTestProvider ) { resultProvider = provider ; break ; } } } return resultProvider ; } | Instantiates a provider using service loader . | 147 | 9 |
5,210 | public static Lookup get ( ) { if ( LOOKUP != null ) { return LOOKUP ; } synchronized ( Lookup . class ) { // allow for override of the Lookup.class String overrideClassName = System . getProperty ( Lookup . class . getName ( ) ) ; ClassLoader l = Thread . currentThread ( ) . getContextClassLoader ( ) ; try { if ( overrideClassName != null && ! "" . equals ( overrideClassName ) ) { LOOKUP = ( Lookup ) Class . forName ( overrideClassName , true , l ) . newInstance ( ) ; } else { LOOKUP = new Lookup ( ) ; } } catch ( Exception e ) { // ignore } // ServiceLoader and CDI are used by defaults, important that // CDI is used first so that beans are enabled for injection CdiLookup cdiLookup = new CdiLookup ( ) ; LOOKUP . lookupProviders . add ( cdiLookup ) ; ServiceLoaderLookup serviceLoaderLookup = new ServiceLoaderLookup ( ) ; LOOKUP . lookupProviders . add ( serviceLoaderLookup ) ; // Use ServiceLoader to find other LookupProviders Collection < LookupProvider > providers = serviceLoaderLookup . lookupAll ( LookupProvider . class ) ; LOOKUP . lookupProviders . addAll ( providers ) ; } return LOOKUP ; } | Acquire the Lookup registry . | 291 | 7 |
5,211 | private static String formatName ( String name ) { if ( name . length ( ) < NAME_COL_WIDTH ) { return name ; } return name . substring ( 0 , NAME_COL_WIDTH - 1 ) + ">" ; } | Formats a name for the fixed width layout of the html index . | 54 | 14 |
5,212 | private void instrument ( CtClass proxy , final SchemaPropertyRef ref ) throws Exception { final Schema schema = schemas . get ( ref . getSchemaName ( ) ) ; checkNotNull ( schema , "Schema not found for SchemaPropertyRef [" + ref + "]" ) ; final String fieldName = ref . getFieldName ( ) ; // for help on javassist syntax, see chapter around javassist.expr.FieldAccess at // http://www.csg.ci.i.u-tokyo.ac.jp/~chiba/javassist/tutorial/tutorial2.html#before proxy . instrument ( new ExprEditor ( ) { public void edit ( FieldAccess f ) throws CannotCompileException { if ( f . getFieldName ( ) . equals ( ref . getFieldName ( ) ) ) { StringBuilder code = new StringBuilder ( ) ; code . append ( "{" ) ; code . append ( "$_=(" + schema . getType ( ) + ") this." + PROXY_FIELD_NAME + ".getObjectReference(\"" + fieldName + "\", \"" + schema . getName ( ) + "\");" ) ; code . append ( "}" ) ; f . replace ( code . toString ( ) ) ; } } } ) ; } | Instrument a single reference field using the ConfigReferenceHolder to fetch the real reference from the cache and replace it with a real object . | 287 | 28 |
5,213 | public static byte [ ] remove ( byte [ ] arr , int n ) { int index = binarySearch ( arr , n ) ; byte [ ] arr2 = new byte [ arr . length - 4 ] ; System . arraycopy ( arr , 0 , arr2 , 0 , index ) ; System . arraycopy ( arr , index + 4 , arr2 , index , arr . length - index - 4 ) ; return arr2 ; } | Remove a big - endian 4 - byte integer to a sorted array of bytes . | 90 | 17 |
5,214 | public static int binarySearch ( byte [ ] a , int key ) { int low = 0 ; int high = a . length ; while ( low < high ) { int mid = ( low + high ) >>> 1 ; if ( mid % 4 != 0 ) { if ( high == a . length ) { mid = low ; } else { mid = high ; } } int midVal = getInt ( a , mid ) ; if ( midVal < key ) low = mid + 4 ; else if ( midVal > key ) high = mid - 4 ; else return mid ; // key found } if ( low == a . length ) { return low ; } return key > getInt ( a , low ) ? low + 4 : low ; } | Search for a big - endian 4 - byte integer in a array of bytes . | 154 | 17 |
5,215 | protected FileSystemServer createFileSystemServer ( ArtifactStore artifactStore ) { return new FileSystemServer ( ArtifactUtils . versionlessKey ( project . getGroupId ( ) , project . getArtifactId ( ) ) , Math . max ( 0 , Math . min ( port , 65535 ) ) , new AutoDigestFileSystem ( new ArtifactStoreFileSystem ( artifactStore ) ) , getSettingsServletPath ( ) ) ; } | Creates a file system server from an artifact store . | 92 | 11 |
5,216 | public static void deleteProperties ( BeanId id ) { Query query = getEmOrFail ( ) . createNamedQuery ( DELETE_ALL_PROPERTIES_FOR_BEANID_NAME ) ; query . setParameter ( 1 , id . getInstanceId ( ) ) ; query . setParameter ( 2 , id . getSchemaName ( ) ) ; query . setParameter ( 3 , BEAN_MARKER_PROPERTY_NAME ) ; query . executeUpdate ( ) ; } | Delete list properties EXCEPT the marker . This is useful for set operations that need to clear existing properties . | 109 | 21 |
5,217 | public static void deletePropertiesAndMarker ( BeanId id ) { Query query = getEmOrFail ( ) . createNamedQuery ( DELETE_ALL_PROPERTIES_FOR_BEANID_NAME ) ; query . setParameter ( 1 , id . getInstanceId ( ) ) ; query . setParameter ( 2 , id . getSchemaName ( ) ) ; // empty will marker will delete the marker aswell query . setParameter ( 3 , "" ) ; query . executeUpdate ( ) ; } | Deletes the JpaBean and list its properties and the marker . | 111 | 15 |
5,218 | public static void filterMarkerProperty ( List < JpaProperty > properties ) { ListIterator < JpaProperty > propIt = properties . listIterator ( ) ; while ( propIt . hasNext ( ) ) { if ( BEAN_MARKER_PROPERTY_NAME . equals ( propIt . next ( ) . getPropertyName ( ) ) ) { propIt . remove ( ) ; } } } | This property has no other meaning than knowing that a bean exits only by looking at the properties table . | 87 | 20 |
5,219 | public static < A extends Comparable < A > > BeanRestriction between ( String property , A lower , A upper ) { return new Between <> ( property , lower , upper ) ; } | Query which asserts that a property is between a lower and an upper bound inclusive . | 40 | 16 |
5,220 | public final void fireCreate ( Collection < Bean > beans ) { ConfigChanges changes = new ConfigChanges ( ) ; for ( Bean bean : beans ) { changes . add ( ConfigChange . created ( bean ) ) ; } fire ( changes ) ; } | Fire a notification for a collection of beans that have been created . | 51 | 13 |
5,221 | public final ConfigChanges deleted ( String schemaName , Collection < String > instanceIds ) { ConfigChanges changes = new ConfigChanges ( ) ; for ( String instanceId : instanceIds ) { BeanId id = BeanId . create ( instanceId , schemaName ) ; Optional < Bean > before = beanManager . getEager ( id ) ; if ( ! before . isPresent ( ) ) { throw Events . CFG304_BEAN_DOESNT_EXIST ( id ) ; } Bean bean = before . get ( ) ; schemaManager . setSchema ( Arrays . asList ( bean ) ) ; changes . add ( ConfigChange . deleted ( bean ) ) ; } return changes ; } | Create a changes object from a delete operation . | 148 | 9 |
5,222 | public final void fireDelete ( List < Bean > beans ) { ConfigChanges changes = new ConfigChanges ( ) ; for ( Bean bean : beans ) { changes . add ( ConfigChange . deleted ( bean ) ) ; } fire ( changes ) ; } | Fire a notification for a collection of beans that have been deleted . | 51 | 13 |
5,223 | public final ConfigChanges updated ( Collection < Bean > after ) { ConfigChanges changes = new ConfigChanges ( ) ; for ( Bean bean : after ) { Optional < Bean > optional = beanManager . getEager ( bean . getId ( ) ) ; if ( ! optional . isPresent ( ) ) { throw Events . CFG304_BEAN_DOESNT_EXIST ( bean . getId ( ) ) ; } Bean before = optional . get ( ) ; schemaManager . setSchema ( Arrays . asList ( before ) ) ; changes . add ( ConfigChange . updated ( before , bean ) ) ; } return changes ; } | Create a changes object from an update operation . | 135 | 9 |
5,224 | private static Path parsePathExpression ( Iterator < Token > expression , ConfigOrigin origin , String originalText ) { // each builder in "buf" is an element in the path. List < Element > buf = new ArrayList < Element > ( ) ; buf . add ( new Element ( "" , false ) ) ; if ( ! expression . hasNext ( ) ) { throw new ConfigException . BadPath ( origin , originalText , "Expecting a field name or path here, but got nothing" ) ; } while ( expression . hasNext ( ) ) { Token t = expression . next ( ) ; if ( Tokens . isValueWithType ( t , ConfigValueType . STRING ) ) { AbstractConfigValue v = Tokens . getValue ( t ) ; // this is a quoted string; so any periods // in here don't count as path separators String s = v . transformToString ( ) ; addPathText ( buf , true , s ) ; } else if ( t == Tokens . END ) { // ignore this; when parsing a file, it should not happen // since we're parsing a token list rather than the main // token iterator, and when parsing a path expression from the // API, it's expected to have an END. } else { // any periods outside of a quoted string count as // separators String text ; if ( Tokens . isValue ( t ) ) { // appending a number here may add // a period, but we _do_ count those as path // separators, because we basically want // "foo 3.0bar" to parse as a string even // though there's a number in it. The fact that // we tokenize non-string values is largely an // implementation detail. AbstractConfigValue v = Tokens . getValue ( t ) ; text = v . transformToString ( ) ; } else if ( Tokens . isUnquotedText ( t ) ) { text = Tokens . getUnquotedText ( t ) ; } else { throw new ConfigException . BadPath ( origin , originalText , "Token not allowed in path expression: " + t + " (you can double-quote this token if you really want it here)" ) ; } addPathText ( buf , false , text ) ; } } PathBuilder pb = new PathBuilder ( ) ; for ( Element e : buf ) { if ( e . sb . length ( ) == 0 && ! e . canBeEmpty ) { throw new ConfigException . BadPath ( origin , originalText , "path has a leading, trailing, or two adjacent period '.' (use quoted \"\" empty string if you want an empty element)" ) ; } else { pb . appendKey ( e . sb . toString ( ) ) ; } } return pb . result ( ) ; } | originalText may be null if not available | 586 | 8 |
5,225 | private static boolean hasUnsafeChars ( String s ) { for ( int i = 0 ; i < s . length ( ) ; ++ i ) { char c = s . charAt ( i ) ; if ( Character . isLetter ( c ) || c == ' ' ) continue ; else return true ; } return false ; } | full parser to deal with . | 69 | 6 |
5,226 | public static void setShort ( final byte [ ] b , final short n , final int offset ) { b [ offset + 0 ] = ( byte ) ( n >>> 8 ) ; b [ offset + 1 ] = ( byte ) ( n >>> 0 ) ; } | Writes a big - endian 2 - byte short at an offset in the given array . | 54 | 19 |
5,227 | public static void setInt ( final byte [ ] b , final int n , final int offset ) { b [ offset + 0 ] = ( byte ) ( n >>> 24 ) ; b [ offset + 1 ] = ( byte ) ( n >>> 16 ) ; b [ offset + 2 ] = ( byte ) ( n >>> 8 ) ; b [ offset + 3 ] = ( byte ) ( n >>> 0 ) ; } | Writes a big - endian 4 - byte int at an offset in the given array . | 86 | 19 |
5,228 | public static void setLong ( final byte [ ] b , final long n , final int offset ) { b [ offset + 0 ] = ( byte ) ( n >>> 56 ) ; b [ offset + 1 ] = ( byte ) ( n >>> 48 ) ; b [ offset + 2 ] = ( byte ) ( n >>> 40 ) ; b [ offset + 3 ] = ( byte ) ( n >>> 32 ) ; b [ offset + 4 ] = ( byte ) ( n >>> 24 ) ; b [ offset + 5 ] = ( byte ) ( n >>> 16 ) ; b [ offset + 6 ] = ( byte ) ( n >>> 8 ) ; b [ offset + 7 ] = ( byte ) ( n >>> 0 ) ; } | Writes a big - endian 8 - byte long at an offset in the given array . | 150 | 19 |
5,229 | public Set < HBeanRow > filterUnvisted ( Set < HBeanRow > rows ) { Set < HBeanRow > unvisted = new HashSet <> ( ) ; for ( HBeanRow row : rows ) { if ( ! references . containsKey ( row ) && ! inital . containsKey ( row ) ) { unvisted . add ( row ) ; } } return unvisted ; } | Filter out the rows that we have not yet visited . | 92 | 11 |
5,230 | public List < Bean > getBeans ( ) { Map < BeanId , Bean > referenceMap = new HashMap <> ( ) ; List < Bean > result = new ArrayList <> ( ) ; for ( HBeanRow row : inital . keySet ( ) ) { Bean bean = row . getBean ( ) ; result . add ( bean ) ; referenceMap . put ( bean . getId ( ) , bean ) ; } for ( HBeanRow row : references . keySet ( ) ) { Bean bean = row . getBean ( ) ; referenceMap . put ( bean . getId ( ) , bean ) ; } for ( Bean bean : referenceMap . values ( ) ) { for ( BeanId id : bean . getReferences ( ) ) { Bean ref = referenceMap . get ( id ) ; id . setBean ( ref ) ; } } return result ; } | Convert the collected rows into a hierarchy of beans where list references are initalized . | 190 | 18 |
5,231 | public static void validatePublicKey ( String value , PublicKeyCrypto crypto ) throws BadPublicKeyException { if ( org . springframework . util . StringUtils . hasText ( value ) ) { int open = value . indexOf ( "-----BEGIN PGP PUBLIC KEY BLOCK-----" ) ; int close = value . indexOf ( "-----END PGP PUBLIC KEY BLOCK-----" ) ; if ( open < 0 ) { throw new BadPublicKeyException ( "PublicKeyValidator.noBeginBlock" ) ; } if ( close < 0 ) { throw new BadPublicKeyException ( "PublicKeyValidator.noEndBlock" ) ; } if ( open >= 0 && close >= 0 && open >= close ) { throw new BadPublicKeyException ( "PublicKeyValidator.wrongBlockOrder" ) ; } if ( ! crypto . isPublicKeyValid ( value ) ) { throw new BadPublicKeyException ( "PublicKeyValidator.invalidKey" ) ; } } } | Validates a PGP public key . | 210 | 8 |
5,232 | private static boolean hasReferences ( Bean target , BeanId reference ) { for ( String name : target . getReferenceNames ( ) ) { for ( BeanId ref : target . getReference ( name ) ) { if ( ref . equals ( reference ) ) { return true ; } } } return false ; } | Returns the a list of property names of the target bean that have references to the bean id . | 63 | 19 |
5,233 | public static long getId ( final byte [ ] rowkey ) { return ( rowkey [ 0 ] & 0xFF L ) << 40 | ( rowkey [ 1 ] & 0xFF L ) << 32 | ( rowkey [ 2 ] & 0xFF L ) << 24 | ( rowkey [ 3 ] & 0xFF L ) << 16 | ( rowkey [ 4 ] & 0xFF L ) << 8 | ( rowkey [ 5 ] & 0xFF L ) << 0 ; } | Convert the row key to a long id . | 106 | 10 |
5,234 | private static byte [ ] getRowKey ( long id ) { final byte [ ] b = new byte [ 6 ] ; b [ 0 ] = ( byte ) ( id >>> 40 ) ; b [ 1 ] = ( byte ) ( id >>> 32 ) ; b [ 2 ] = ( byte ) ( id >>> 24 ) ; b [ 3 ] = ( byte ) ( id >>> 16 ) ; b [ 4 ] = ( byte ) ( id >>> 8 ) ; b [ 5 ] = ( byte ) ( id >>> 0 ) ; return b ; } | The bean rowkey is stored as 6 bytes but it is represented as a big - endian 8 - byte long . | 113 | 24 |
5,235 | public static byte [ ] getRowKey ( final BeanId id , final UniqueIds uids ) { final byte [ ] iid = uids . getUiid ( ) . getId ( id . getInstanceId ( ) ) ; final byte [ ] sid = uids . getUsid ( ) . getId ( id . getSchemaName ( ) ) ; final byte [ ] rowkey = new byte [ sid . length + iid . length ] ; System . arraycopy ( sid , 0 , rowkey , 0 , sid . length ) ; System . arraycopy ( iid , 0 , rowkey , sid . length , iid . length ) ; return rowkey ; } | Get the hbase rowkey of some bean id . | 146 | 11 |
5,236 | public static void setColumnFilter ( Object op , FetchType ... column ) { ArrayList < byte [ ] > columns = new ArrayList <> ( ) ; columns . add ( DUMMY_COLUMN_FAMILY ) ; if ( column . length == 0 ) { // default behaviour columns . add ( PROP_COLUMN_FAMILY ) ; columns . add ( PRED_COLUMN_FAMILY ) ; columns . add ( REF_COLUMN_FAMILY ) ; columns . add ( SINGLETON_COLUMN_FAMILY ) ; columns . add ( HBeanKeyValue . BEAN_COLUMN_FAMILY ) ; } else if ( FetchType . KEY_ONLY == column [ 0 ] ) { // only IID_FAMILY final FilterList list = new FilterList ( ) ; list . addFilter ( new FirstKeyOnlyFilter ( ) ) ; if ( op instanceof Scan ) { ( ( Scan ) op ) . setFilter ( list ) ; } else if ( op instanceof Get ) { ( ( Get ) op ) . setFilter ( list ) ; } } for ( byte [ ] familiy : columns ) { if ( op instanceof Scan ) { ( ( Scan ) op ) . addFamily ( familiy ) ; } else if ( op instanceof Get ) { ( ( Get ) op ) . addFamily ( familiy ) ; } } } | Add column filter based fetch type on operation Get or Scan . | 312 | 12 |
5,237 | public < T > T convert ( final Object source , final Class < T > targetclass ) { if ( source == null ) { return null ; } final Class < ? > sourceclass = source . getClass ( ) ; if ( targetclass . isPrimitive ( ) && String . class . isAssignableFrom ( sourceclass ) ) { return ( T ) parsePrimitive ( source . toString ( ) , targetclass ) ; } final int sourceId = ids . getId ( sourceclass ) ; final int targetId = ids . getId ( targetclass ) ; final SourceTargetPairKey key = new SourceTargetPairKey ( sourceId , targetId ) ; Converter converter = cache . get ( key ) ; if ( converter != null ) { return ( T ) converter . convert ( source , targetclass ) ; } final LinkedList < SourceTargetPairMatch > matches = new LinkedList <> ( ) ; for ( SourceTargetPair pair : converters . values ( ) ) { SourceTargetPairMatch match = pair . match ( sourceclass , targetclass ) ; if ( match . matchesSource ( ) && match . matchesTarget ( ) ) { matches . add ( match ) ; } } if ( matches . size ( ) == 0 ) { throw new ConversionException ( "No suitable converter found for target class [" + targetclass . getName ( ) + "] and source value [" + sourceclass . getName ( ) + "]. The following converters are available [" + converters . keySet ( ) + "]" ) ; } Collections . sort ( matches , SourceTargetPairMatch . bestTargetMatch ( ) ) ; converter = matches . get ( 0 ) . pair . converter ; cache . put ( key , converter ) ; return ( T ) converter . convert ( source , targetclass ) ; } | Convert a value to a specific class . | 387 | 9 |
5,238 | private List < Bean > findReferences ( BeanId reference , Collection < Bean > predecessors , ArrayList < Bean > matches , ArrayList < Bean > checked ) { for ( Bean predecessor : predecessors ) { findReferences ( reference , predecessor , matches , checked ) ; } return matches ; } | Does a recursive check if predecessor have a particular reference and if so return those predecessor references . | 58 | 18 |
5,239 | @ SuppressWarnings ( "unused" ) private void initalizeReferences ( Collection < Bean > beans ) { Map < BeanId , Bean > userProvided = BeanUtils . uniqueIndex ( beans ) ; for ( Bean bean : beans ) { for ( String name : bean . getReferenceNames ( ) ) { List < BeanId > values = bean . getReference ( name ) ; if ( values == null ) { continue ; } for ( BeanId beanId : values ) { // the does not exist in storage, but may exist in the // set of beans provided by the user. Bean ref = userProvided . get ( beanId ) ; if ( ref == null ) { Optional < Bean > optional = beanManager . getEager ( beanId ) ; if ( optional . isPresent ( ) ) { ref = optional . get ( ) ; } } beanId . setBean ( ref ) ; schemaManager . setSchema ( Arrays . asList ( beanId . getBean ( ) ) ) ; } } } } | Used for setting or creating a multiple beans . | 221 | 9 |
5,240 | @ Override public void execute ( ) throws BuildException { try { DirectoryScanner dsc = fileset . getDirectoryScanner ( getProject ( ) ) ; File baseDir = dsc . getBasedir ( ) ; String [ ] files = dsc . getIncludedFiles ( ) ; for ( int i = 0 ; i < files . length ; i ++ ) { String currentFile = files [ i ] ; File moduleXml = new File ( baseDir , currentFile ) ; String modulePath = currentFile . substring ( 0 , currentFile . lastIndexOf ( File . separator ) ) ; File libDir = new File ( targetDir , modulePath ) ; File destFile = new File ( targetDir , currentFile ) ; System . out . println ( "Processing descriptor for module " + modulePath ) ; System . out . println ( "* Source module descriptor: " + moduleXml ) ; System . out . println ( "* Destination module descriptor: " + destFile ) ; String c = readFileContents ( moduleXml ) ; if ( libDir . exists ( ) ) { String [ ] libs = libDir . list ( new FilenameFilter ( ) { @ Override public boolean accept ( File dir , String name ) { return name . endsWith ( ".jar" ) || name . endsWith ( ".ear" ) || name . endsWith ( ".sar" ) || name . endsWith ( ".war" ) ; } } ) ; BufferedWriter out = new BufferedWriter ( new FileWriter ( destFile ) ) ; out . write ( updateContents ( c , libs ) ) ; out . close ( ) ; } else { libDir . mkdirs ( ) ; BufferedWriter out = new BufferedWriter ( new FileWriter ( destFile ) ) ; out . write ( c ) ; out . close ( ) ; } } } catch ( Exception e ) { e . printStackTrace ( ) ; throw new BuildException ( e ) ; } } | the fileset of module . xml files to be processed | 423 | 11 |
5,241 | public static Set < Bean > getBeanToValidate ( Set < BeanId > ids ) { List < JpaRef > targetPredecessors = JpaRef . getDirectPredecessors ( ids ) ; Set < BeanId > beansToValidate = new HashSet <> ( ) ; for ( JpaRef ref : targetPredecessors ) { beansToValidate . add ( ref . getSource ( ) ) ; } beansToValidate . addAll ( ids ) ; JpaBeanQueryAssembler query = new JpaBeanQueryAssembler ( beansToValidate ) ; collectRefs ( beansToValidate , query , 2 ) ; List < JpaProperty > allProperties = JpaProperty . findProperties ( query . getIds ( ) ) ; query . addProperties ( allProperties ) ; return new HashSet <> ( query . assembleBeans ( ) ) ; } | Will return the target bean and its direct predecessors for validation | 201 | 11 |
5,242 | @ SuppressWarnings ( "unused" ) private static JpaBean getJpaBeanAndProperties ( BeanId id ) { List < JpaProperty > props = JpaProperty . findProperties ( id ) ; if ( props . size ( ) == 0 ) { // no marker, bean does not exist return null ; } JpaBean bean = new JpaBean ( new JpaBeanPk ( id ) ) ; JpaProperty . filterMarkerProperty ( props ) ; bean . properties . addAll ( props ) ; return bean ; } | Need not consult the JpaBean table since the property marker in JpaProperties table is an indicator that the JpaBean really exist even if it has no properties . | 124 | 37 |
5,243 | private static void join ( ArrayList < AbstractConfigValue > builder , AbstractConfigValue origRight ) { AbstractConfigValue left = builder . get ( builder . size ( ) - 1 ) ; AbstractConfigValue right = origRight ; // check for an object which can be converted to a list // (this will be an object with numeric keys, like foo.0, foo.1) if ( left instanceof ConfigObject && right instanceof SimpleConfigList ) { left = DefaultTransformer . transform ( left , ConfigValueType . LIST ) ; } else if ( left instanceof SimpleConfigList && right instanceof ConfigObject ) { right = DefaultTransformer . transform ( right , ConfigValueType . LIST ) ; } // Since this depends on the type of two instances, I couldn't think // of much alternative to an instanceof chain. Visitors are sometimes // used for multiple dispatch but seems like overkill. AbstractConfigValue joined = null ; if ( left instanceof ConfigObject && right instanceof ConfigObject ) { joined = right . withFallback ( left ) ; } else if ( left instanceof SimpleConfigList && right instanceof SimpleConfigList ) { joined = ( ( SimpleConfigList ) left ) . concatenate ( ( SimpleConfigList ) right ) ; } else if ( left instanceof ConfigConcatenation || right instanceof ConfigConcatenation ) { throw new BugOrBroken ( "unflattened ConfigConcatenation" ) ; } else if ( left instanceof Unmergeable || right instanceof Unmergeable ) { // leave joined=null, cannot join } else { // handle primitive type or primitive type mixed with object or list String s1 = left . transformToString ( ) ; String s2 = right . transformToString ( ) ; if ( s1 == null || s2 == null ) { throw new WrongType ( left . origin ( ) , "Cannot concatenate object or list with a non-object-or-list, " + left + " and " + right + " are not compatible" ) ; } else { ConfigOrigin joinedOrigin = SimpleConfigOrigin . mergeOrigins ( left . origin ( ) , right . origin ( ) ) ; joined = new ConfigString ( joinedOrigin , s1 + s2 ) ; } } if ( joined == null ) { builder . add ( right ) ; } else { builder . remove ( builder . size ( ) - 1 ) ; builder . add ( joined ) ; } } | Add left and right or their merger to builder . | 519 | 10 |
5,244 | public static void mergeTemplate ( VelocityEngine velocityEngine , String templateLocation , String encoding , Map < String , Object > model , Writer writer ) throws VelocityException { VelocityContext velocityContext = new VelocityContext ( model ) ; velocityEngine . mergeTemplate ( templateLocation , encoding , velocityContext , writer ) ; } | Merge the specified Velocity template with the given model and write the result to the given Writer . | 63 | 19 |
5,245 | public static long parseDuration ( String input , ConfigOrigin originForException , String pathForException ) { String s = ConfigImplUtil . unicodeTrim ( input ) ; String originalUnitString = getUnits ( s ) ; String unitString = originalUnitString ; String numberString = ConfigImplUtil . unicodeTrim ( s . substring ( 0 , s . length ( ) - unitString . length ( ) ) ) ; TimeUnit units = null ; // this would be caught later anyway, but the error message // is more helpful if we check it here. if ( numberString . length ( ) == 0 ) throw new ConfigException . BadValue ( originForException , pathForException , "No number in duration value '" + input + "'" ) ; if ( unitString . length ( ) > 2 && ! unitString . endsWith ( "s" ) ) unitString = unitString + "s" ; // note that this is deliberately case-sensitive if ( unitString . equals ( "" ) || unitString . equals ( "ms" ) || unitString . equals ( "milliseconds" ) ) { units = TimeUnit . MILLISECONDS ; } else if ( unitString . equals ( "us" ) || unitString . equals ( "microseconds" ) ) { units = TimeUnit . MICROSECONDS ; } else if ( unitString . equals ( "ns" ) || unitString . equals ( "nanoseconds" ) ) { units = TimeUnit . NANOSECONDS ; } else if ( unitString . equals ( "d" ) || unitString . equals ( "days" ) ) { units = TimeUnit . DAYS ; } else if ( unitString . equals ( "h" ) || unitString . equals ( "hours" ) ) { units = TimeUnit . HOURS ; } else if ( unitString . equals ( "s" ) || unitString . equals ( "seconds" ) ) { units = TimeUnit . SECONDS ; } else if ( unitString . equals ( "m" ) || unitString . equals ( "minutes" ) ) { units = TimeUnit . MINUTES ; } else { throw new ConfigException . BadValue ( originForException , pathForException , "Could not parse time unit '" + originalUnitString + "' (try ns, us, ms, s, m, d)" ) ; } try { // if the string is purely digits, parse as an integer to avoid // possible precision loss; // otherwise as a double. if ( numberString . matches ( "[0-9]+" ) ) { return units . toNanos ( Long . parseLong ( numberString ) ) ; } else { long nanosInUnit = units . toNanos ( 1 ) ; return ( long ) ( Double . parseDouble ( numberString ) * nanosInUnit ) ; } } catch ( NumberFormatException e ) { throw new ConfigException . BadValue ( originForException , pathForException , "Could not parse duration number '" + numberString + "'" ) ; } } | Parses a duration string . If no units are specified in the string it is assumed to be in milliseconds . The returned duration is in nanoseconds . The purpose of this function is to implement the duration - related methods in the ConfigObject interface . | 654 | 52 |
5,246 | public static Restriction in ( String property , Object ... values ) { return new In ( property , Arrays . asList ( values ) ) ; } | A shorthand way to create an OR query comprised of several equal queries . | 31 | 14 |
5,247 | public static Restriction and ( Restriction r1 , Restriction r2 ) { return new And ( Arrays . asList ( r1 , r2 ) ) ; } | A query representing a logical AND of the provided restrictions . s | 36 | 12 |
5,248 | public static Restriction or ( Restriction r1 , Restriction r2 ) { return new Or ( Arrays . asList ( r1 , r2 ) ) ; } | A restriction representing a logical OR of the provided restrictions . s | 36 | 12 |
5,249 | @ Override public void send ( MidiMessage message , long timeStamp ) { if ( this . launchpadReceiver != null && message instanceof ShortMessage ) { ShortMessage sm = ( ShortMessage ) message ; Pad pad = Pad . findMidi ( sm ) ; if ( pad != null ) { this . launchpadReceiver . receive ( pad ) ; } } } | Please do not use this method . It s the internal implementation to receive midi commands . | 80 | 18 |
5,250 | private synchronized List < Entry > getEntriesList ( DirectoryEntry directory ) { List < Entry > entries = contents . get ( directory ) ; if ( entries == null ) { entries = new ArrayList < Entry > ( ) ; contents . put ( directory , entries ) ; } return entries ; } | Gets the list of entries in the specified directory . | 61 | 11 |
5,251 | public Object getObjectReference ( String field , String schemaName ) { List < String > instanceIds = references . get ( field ) ; if ( instanceIds == null || instanceIds . size ( ) == 0 ) { return null ; } String instanceId = instanceIds . get ( 0 ) ; if ( instanceId == null ) { return null ; } BeanId id = BeanId . create ( instanceId , schemaName ) ; Object instance = instances . get ( id ) ; if ( instance != null ) { return instance ; } instance = cache . get ( id ) ; instances . put ( id , instance ) ; return instance ; } | Called by a proxy to lookup single object reference . The proxy knows the schema name so the hold does not need to bother storing it . | 136 | 28 |
5,252 | public Collection < Object > getObjectReferenceList ( String field , String schemaName ) { List < String > instanceIds = references . get ( field ) ; if ( instanceIds == null || instanceIds . size ( ) == 0 ) { return null ; } List < Object > objects = new ArrayList <> ( ) ; for ( String instanceId : instanceIds ) { BeanId id = BeanId . create ( instanceId , schemaName ) ; Object instance = instances . get ( id ) ; if ( instance != null ) { objects . add ( instance ) ; } else { instance = cache . get ( id ) ; instances . put ( id , instance ) ; objects . add ( instance ) ; } } return objects ; } | Called by a proxy to lookup a list of object references . The proxy knows the schema name so the hold does not need to bother storing it . | 155 | 30 |
5,253 | public Map < String , Object > getObjectReferenceMap ( String field , String schemaName ) { List < String > instanceIds = references . get ( field ) ; if ( instanceIds == null || instanceIds . size ( ) == 0 ) { return null ; } Map < String , Object > objects = new HashMap <> ( ) ; for ( String instanceId : instanceIds ) { BeanId id = BeanId . create ( instanceId , schemaName ) ; Object instance = instances . get ( id ) ; if ( instance != null ) { objects . put ( instanceId , instance ) ; } else { instance = cache . get ( id ) ; instances . put ( id , instance ) ; objects . put ( instanceId , instance ) ; } } return objects ; } | Called by a proxy to lookup a map of object references . The proxy knows the schema name so the hold does not need to bother storing it . | 165 | 30 |
5,254 | static SysProperties toSystemProperties ( final String [ ] arguments ) { final SysProperties retVal = new SysProperties ( ) ; if ( arguments != null && arguments . length != 0 ) { for ( final String argument : arguments ) { if ( argument . startsWith ( "-D" ) ) { Variable var = AntTaskHelper . toVariable ( argument ) ; retVal . addVariable ( var ) ; } } } return retVal ; } | Converts array of JVM arguments to ANT SysProperties object . | 98 | 16 |
5,255 | private static Variable toVariable ( final String argument ) { final Variable retVal = new Variable ( ) ; final int equalSignIndex = argument . indexOf ( ' ' ) ; if ( equalSignIndex == - 1 ) { final String key = argument . substring ( 2 ) ; retVal . setKey ( key ) ; } else { final String key = argument . substring ( 2 , equalSignIndex ) ; retVal . setKey ( key ) ; final String value = argument . substring ( equalSignIndex + 1 ) ; retVal . setValue ( value ) ; } return retVal ; } | Converts JVM property of format - Dkey = value to ANT Variable object . | 126 | 18 |
5,256 | public static String [ ] [ ] getProperties ( final Bean bean ) { final List < String > propertyNames = bean . getPropertyNames ( ) ; final int psize = propertyNames . size ( ) ; final String [ ] [ ] properties = new String [ psize ] [ ] ; for ( int i = 0 ; i < psize ; i ++ ) { final String propertyName = propertyNames . get ( i ) ; final List < String > values = bean . getValues ( propertyName ) ; final int vsize = values . size ( ) ; properties [ i ] = new String [ vsize + 1 ] ; properties [ i ] [ 0 ] = propertyName ; for ( int j = 0 ; j < vsize ; j ++ ) { properties [ i ] [ j + 1 ] = values . get ( j ) ; } } return properties ; } | In order to reduce the amount of property data stored we convert the properties into a String matrix . The first element is the property name followed by its values . | 181 | 31 |
5,257 | public void setPropertiesOn ( final Bean bean ) { String [ ] [ ] properties = getProperties ( ) ; for ( int i = 0 ; i < properties . length ; i ++ ) { if ( properties [ i ] . length < 2 ) { continue ; } for ( int j = 0 ; j < properties [ i ] . length - 1 ; j ++ ) { bean . addProperty ( properties [ i ] [ 0 ] , properties [ i ] [ j + 1 ] ) ; } } } | Set a string matrix of properties on a particular bean . | 106 | 11 |
5,258 | public static String getPropertyName ( KeyValue kv , UniqueIds uids ) { final byte [ ] qualifier = kv . getQualifier ( ) ; final byte [ ] pid = new byte [ ] { qualifier [ 2 ] , qualifier [ 3 ] } ; final String propertyName = uids . getUsid ( ) . getName ( pid ) ; return propertyName ; } | Extract the property name from a key value . | 81 | 10 |
5,259 | public static boolean isProperty ( KeyValue kv ) { if ( Bytes . equals ( kv . getFamily ( ) , PROP_COLUMN_FAMILY ) ) { return true ; } return false ; } | If this key value is of property familiy type . | 48 | 12 |
5,260 | public HBeanRowCollector listEager ( String schemaName , FetchType ... fetchType ) throws HBeanNotFoundException { Set < HBeanRow > rows = listLazy ( schemaName , fetchType ) ; HBeanRowCollector collector = new HBeanRowCollector ( rows ) ; getEager ( rows , collector , FETCH_DEPTH_MAX , fetchType ) ; return collector ; } | Fetch list rows for a particular schema and traverse and fetch references eagerly . | 94 | 15 |
5,261 | public HBeanRowCollector getEager ( Set < HBeanRow > rows , FetchType ... fetchType ) throws HBeanNotFoundException { Set < HBeanRow > result ; result = getLazy ( rows , fetchType ) ; HBeanRowCollector collector = new HBeanRowCollector ( result ) ; getEager ( result , collector , FETCH_DEPTH_MAX , fetchType ) ; return collector ; } | Fetch a set of rows and traverse and fetch references eagerly . | 100 | 13 |
5,262 | public void put ( Set < HBeanRow > rows ) { final List < Row > create = new ArrayList <> ( ) ; try { for ( HBeanRow row : rows ) { final Put write = new Put ( row . getRowKey ( ) ) ; if ( row . getPropertiesKeyValue ( ) != null ) { write . add ( row . getPropertiesKeyValue ( ) ) ; } for ( KeyValue kv : row . getPredecessors ( ) ) { write . add ( kv ) ; } for ( KeyValue kv : row . getReferencesKeyValue ( ) . values ( ) ) { write . add ( kv ) ; } KeyValue hBean = row . getHBeanKeyValue ( ) ; write . add ( hBean ) ; if ( row . isSingleton ( ) ) { write . add ( new KeyValue ( row . getRowKey ( ) , HBeanRow . SINGLETON_COLUMN_FAMILY , HBeanRow . SINGLETON_COLUMN_FAMILY , new byte [ ] { 1 } ) ) ; } // hbase cannot have rowkeys without columns so we need // a dummy value to represent beans without any values write . add ( new KeyValue ( row . getRowKey ( ) , HBeanRow . DUMMY_COLUMN_FAMILY , HBeanRow . DUMMY_COLUMN_FAMILY , new byte [ ] { 1 } ) ) ; create . add ( write ) ; } table . batch ( create ) ; table . flushCommits ( ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } | Put a set of rows . | 367 | 6 |
5,263 | private void getEager ( Set < HBeanRow > rows , HBeanRowCollector collector , int level , FetchType ... fetchType ) throws HBeanNotFoundException { int size = rows . size ( ) ; if ( size == 0 ) { return ; } if ( -- level < 0 ) { return ; } Set < HBeanRow > refs = new HashSet <> ( ) ; for ( HBeanRow row : rows ) { refs . addAll ( row . getReferenceRows ( ) ) ; } // only recurse rowkeys we havent already // visited to break circular references refs = collector . filterUnvisted ( refs ) ; refs = getLazy ( refs , fetchType ) ; collector . addReferences ( refs ) ; getEager ( refs , collector , level , fetchType ) ; } | Recursive method for traversing and collecting row references . | 186 | 11 |
5,264 | public void delete ( Set < HBeanRow > rows ) { final List < Row > delete = new ArrayList <> ( ) ; try { for ( HBeanRow row : rows ) { delete . add ( new Delete ( row . getRowKey ( ) ) ) ; } table . batch ( delete ) ; table . flushCommits ( ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } | Delete a set of rows . | 92 | 6 |
5,265 | public static Optional < ValidationManager > lookup ( ) { ValidationManager manager = lookup . lookup ( ValidationManager . class ) ; if ( manager != null ) { return Optional . of ( manager ) ; } else { return Optional . absent ( ) ; } } | Lookup the most suitable ValidationManager available . | 55 | 10 |
5,266 | public void addProperties ( List < JpaProperty > queryProperties ) { for ( JpaProperty prop : queryProperties ) { Bean bean = putIfAbsent ( prop . getId ( ) ) ; if ( ! JpaProperty . BEAN_MARKER_PROPERTY_NAME . equals ( prop . getPropertyName ( ) ) ) { bean . addProperty ( prop . getPropertyName ( ) , prop . getValue ( ) ) ; } } } | Add properties to appropriate bean found from a partial query of bean properties . | 101 | 14 |
5,267 | public void addRefs ( Multimap < BeanId , JpaRef > queryRefs ) { refs . putAll ( queryRefs ) ; for ( BeanId id : refs . keySet ( ) ) { putIfAbsent ( id ) ; for ( JpaRef ref : refs . get ( id ) ) { putIfAbsent ( ref . getTarget ( ) ) ; } } } | Add references found from a partial query of bean references . | 88 | 11 |
5,268 | public Set < BeanId > getIds ( ) { Set < BeanId > ids = new HashSet <> ( ) ; ids . addAll ( beansQuery ) ; ids . addAll ( beans . keySet ( ) ) ; return ids ; } | Return list bean ids that the assembler is currently aware of . | 57 | 14 |
5,269 | private Bean putIfAbsent ( BeanId id ) { Bean bean = beans . get ( id ) ; if ( bean == null ) { bean = Bean . create ( id ) ; beans . put ( id , bean ) ; } return bean ; } | Add a empty bean based on id if it does not already exist . | 52 | 14 |
5,270 | public List < Bean > assembleBeans ( ) { connectReferences ( ) ; if ( beansQuery . size ( ) == 0 ) { // if no specific beans where requested (such as query for a // specific schema) return what is available. return new ArrayList <> ( beans . values ( ) ) ; } List < Bean > initalQuery = new ArrayList <> ( ) ; for ( BeanId id : beansQuery ) { Bean bean = beans . get ( id ) ; if ( bean != null ) { initalQuery . add ( beans . get ( id ) ) ; } } return initalQuery ; } | Assemble beans and initalize their properties and references from what have been provided . | 130 | 17 |
5,271 | private void connectReferences ( ) { // ready to associate initalized beans with references for ( Bean bean : beans . values ( ) ) { for ( JpaRef ref : refs . get ( bean . getId ( ) ) ) { BeanId target = ref . getTarget ( ) ; Bean targetBean = beans . get ( target ) ; target . setBean ( targetBean ) ; bean . addReference ( ref . getPropertyName ( ) , target ) ; } } } | Assemble beans and initalize references from what have been provided . | 103 | 14 |
5,272 | private Set < Bean > flattenReferences ( Bean bean ) { Set < Bean > beans = new HashSet <> ( ) ; for ( String referenceName : bean . getReferenceNames ( ) ) { List < BeanId > ids = bean . getReference ( referenceName ) ; for ( BeanId id : ids ) { if ( id . getBean ( ) == null ) { continue ; } beans . addAll ( flattenReferences ( id . getBean ( ) ) ) ; } } beans . add ( bean ) ; return beans ; } | Bean may but not necessarily have deep hierarchies of references to other beans . Since a cache store beans per schema we must dig out this hierarchy and flatten it out | 117 | 34 |
5,273 | public static UniqueIds createUids ( Configuration conf ) { UniqueId usid = new UniqueId ( SID_TABLE , SID_WIDTH , conf , true ) ; UniqueId uiid = new UniqueId ( IID_TABLE , IID_WIDTH , conf , true ) ; UniqueId upid = new UniqueId ( PID_TABLE , PID_WIDTH , conf , true ) ; return new UniqueIds ( uiid , usid , upid ) ; } | Create the unique lookup tables . | 108 | 6 |
5,274 | private byte [ ] getContent ( ) throws IOException { InputStream is = null ; try { MessageDigest digest = MessageDigest . getInstance ( "MD5" ) ; digest . reset ( ) ; byte [ ] buffer = new byte [ 8192 ] ; int read ; try { is = entry . getInputStream ( ) ; while ( ( read = is . read ( buffer ) ) > 0 ) { digest . update ( buffer , 0 , read ) ; } } catch ( IOException e ) { if ( is != null ) { throw e ; } } final String md5 = StringUtils . leftPad ( new BigInteger ( 1 , digest . digest ( ) ) . toString ( 16 ) , 32 , "0" ) ; return md5 . getBytes ( ) ; } catch ( NoSuchAlgorithmException e ) { IOException ioe = new IOException ( "Unable to calculate hash" ) ; ioe . initCause ( e ) ; throw ioe ; } finally { IOUtils . closeQuietly ( is ) ; } } | Generates the digest . | 226 | 5 |
5,275 | AbstractConfigValue peekPath ( Path path ) { try { return peekPath ( this , path , null ) ; } catch ( NotPossibleToResolve e ) { throw new BugOrBroken ( "NotPossibleToResolve happened though we had no ResolveContext in peekPath" ) ; } } | Looks up the path . Doesn t do any resolution will throw if any is needed . | 65 | 17 |
5,276 | private static AbstractConfigValue peekPath ( AbstractConfigObject self , Path path , ResolveContext context ) throws NotPossibleToResolve { try { if ( context != null ) { // walk down through the path resolving only things along that // path, and then recursively call ourselves with no resolve // context. AbstractConfigValue partiallyResolved = context . restrict ( path ) . resolve ( self ) ; if ( partiallyResolved instanceof AbstractConfigObject ) { return peekPath ( ( AbstractConfigObject ) partiallyResolved , path , null ) ; } else { throw new BugOrBroken ( "resolved object to non-object " + self + " to " + partiallyResolved ) ; } } else { // with no resolver, we'll fail if anything along the path can't // be looked at without resolving. Path next = path . remainder ( ) ; AbstractConfigValue v = self . attemptPeekWithPartialResolve ( path . first ( ) ) ; if ( next == null ) { return v ; } else { if ( v instanceof AbstractConfigObject ) { return peekPath ( ( AbstractConfigObject ) v , next , null ) ; } else { return null ; } } } } catch ( NotResolved e ) { throw ConfigImpl . improveNotResolved ( path , e ) ; } } | the child itself if needed . | 277 | 6 |
5,277 | public String getName ( ) { if ( name == null ) { name = MessageFormat . format ( "{0}-{1}{2}.{3}" , new Object [ ] { artifactId , getTimestampVersion ( ) , ( classifier == null ? "" : "-" + classifier ) , type } ) ; } return name ; } | Returns the name of the artifact . | 73 | 7 |
5,278 | public static Bean create ( final BeanId id ) { Preconditions . checkNotNull ( id ) ; Bean bean = new Bean ( id ) ; bean . set ( id . getSchema ( ) ) ; return bean ; } | Create a admin bean instance . | 48 | 6 |
5,279 | public List < String > getPropertyNames ( ) { ArrayList < String > names = new ArrayList <> ( properties . keySet ( ) ) ; Collections . sort ( names ) ; return names ; } | Return the list of property names which have values . Properties with default values are not returned . | 43 | 18 |
5,280 | public List < String > getReferenceNames ( ) { ArrayList < String > names = new ArrayList <> ( references . keySet ( ) ) ; Collections . sort ( names ) ; return names ; } | Return the list of property names which are references . | 43 | 10 |
5,281 | public void addProperty ( final String propertyName , final Collection < String > values ) { Preconditions . checkNotNull ( values ) ; Preconditions . checkNotNull ( propertyName ) ; List < String > list = properties . get ( propertyName ) ; if ( list == null ) { properties . put ( propertyName , new ArrayList <> ( values ) ) ; } else { list . addAll ( values ) ; } } | Add a list of value to a property on this bean . | 92 | 12 |
5,282 | public void addProperty ( final String propertyName , final String value ) { Preconditions . checkNotNull ( propertyName ) ; Preconditions . checkNotNull ( value ) ; List < String > values = properties . get ( propertyName ) ; if ( values == null ) { values = new ArrayList <> ( ) ; values . add ( value ) ; properties . put ( propertyName , values ) ; } else { values . add ( value ) ; } } | Add a value to a property on this bean . | 98 | 10 |
5,283 | public void setProperty ( final String propertyName , final String value ) { Preconditions . checkNotNull ( propertyName ) ; if ( value == null ) { properties . put ( propertyName , null ) ; return ; } List < String > values = new ArrayList <> ( ) ; values . add ( value ) ; properties . put ( propertyName , values ) ; } | Overwrite the current values with the provided value . | 79 | 10 |
5,284 | public void clear ( final String propertyName ) { Preconditions . checkNotNull ( propertyName ) ; if ( properties . containsKey ( propertyName ) ) { properties . put ( propertyName , null ) ; } else if ( references . containsKey ( propertyName ) ) { references . put ( propertyName , null ) ; } } | Clear the values of a property or reference setting it to null . | 70 | 13 |
5,285 | public void remove ( final String propertyName ) { Preconditions . checkNotNull ( propertyName ) ; if ( properties . containsKey ( propertyName ) ) { properties . remove ( propertyName ) ; } else if ( references . containsKey ( propertyName ) ) { references . remove ( propertyName ) ; } } | Remove a property or reference as a property from this bean . | 66 | 12 |
5,286 | public List < String > getValues ( final String propertyName ) { Preconditions . checkNotNull ( propertyName ) ; List < String > values = properties . get ( propertyName ) ; if ( values == null ) { return null ; } // creates a shallow defensive copy return new ArrayList <> ( values ) ; } | Get the values of a property on a bean . | 68 | 10 |
5,287 | public String getSingleValue ( final String propertyName ) { Preconditions . checkNotNull ( propertyName ) ; List < String > values = getValues ( propertyName ) ; if ( values == null || values . size ( ) < 1 ) { return null ; } return values . get ( 0 ) ; } | A helper method for getting the value of single valued properties . Returns null if the property does not exist . | 65 | 21 |
5,288 | public void addReference ( final String propertyName , final Collection < BeanId > refs ) { Preconditions . checkNotNull ( refs ) ; Preconditions . checkNotNull ( propertyName ) ; checkCircularReference ( refs . toArray ( new BeanId [ refs . size ( ) ] ) ) ; List < BeanId > list = references . get ( propertyName ) ; if ( list == null ) { list = new ArrayList <> ( ) ; list . addAll ( refs ) ; references . put ( propertyName , list ) ; } else { list . addAll ( refs ) ; } } | Add a list of references to a property on this bean . | 134 | 12 |
5,289 | private void checkCircularReference ( final BeanId ... references ) { for ( BeanId beanId : references ) { if ( getId ( ) . equals ( beanId ) ) { throw CFG310_CIRCULAR_REF ( getId ( ) , getId ( ) ) ; } } } | Check that references does not point to self . | 63 | 9 |
5,290 | public void addReference ( final String propertyName , final BeanId ref ) { Preconditions . checkNotNull ( ref ) ; Preconditions . checkNotNull ( propertyName ) ; checkCircularReference ( ref ) ; List < BeanId > list = references . get ( propertyName ) ; if ( list == null ) { list = new ArrayList <> ( ) ; list . add ( ref ) ; references . put ( propertyName , list ) ; } else { list . add ( ref ) ; } } | Add a reference to a property on this bean . | 108 | 10 |
5,291 | public List < BeanId > getReference ( final String propertyName ) { List < BeanId > values = references . get ( propertyName ) ; if ( values == null ) { return null ; } return values ; } | Get the references of a property on a bean . | 45 | 10 |
5,292 | public List < BeanId > getReferences ( ) { if ( references == null ) { return new ArrayList <> ( ) ; } ArrayList < BeanId > result = new ArrayList <> ( ) ; for ( List < BeanId > b : references . values ( ) ) { if ( b != null ) { result . addAll ( b ) ; } } return result ; } | Get all references for all properties of this bean . | 81 | 10 |
5,293 | public BeanId getFirstReference ( final String propertyName ) { List < BeanId > refrences = getReference ( propertyName ) ; if ( refrences == null || refrences . size ( ) < 1 ) { return null ; } return refrences . get ( 0 ) ; } | A helper method for getting the value of single referenced property . Returns null if the refrences does not exist . | 59 | 22 |
5,294 | public static Optional < CacheManager > lookup ( ) { CacheManager manager = lookup . lookup ( CacheManager . class ) ; if ( manager != null ) { return Optional . of ( manager ) ; } else { return Optional . absent ( ) ; } } | Lookup the most suitable CacheManager available . | 52 | 9 |
5,295 | public static String percentEncode ( String source ) throws AuthException { try { return URLEncoder . encode ( source , "UTF-8" ) . replace ( "+" , "%20" ) . replace ( "*" , "%2A" ) . replace ( "%7E" , "~" ) ; } catch ( UnsupportedEncodingException ex ) { throw new AuthException ( "cannot encode value '" + source + "'" , ex ) ; } } | Returns an encoded string . | 101 | 5 |
5,296 | public static String percentDecode ( String source ) throws AuthException { try { return URLDecoder . decode ( source , "UTF-8" ) ; } catch ( java . io . UnsupportedEncodingException ex ) { throw new AuthException ( "cannot decode value '" + source + "'" , ex ) ; } } | Returns a decoded string . | 70 | 6 |
5,297 | public static < T > T wrapTempFileList ( T original , com . aoindustries . io . TempFileList tempFileList , Wrapper < T > wrapper ) { if ( tempFileList != null ) { return wrapper . call ( original , tempFileList ) ; } else { // Warn once synchronized ( tempFileWarningLock ) { if ( ! tempFileWarned ) { if ( logger . isLoggable ( Level . WARNING ) ) { logger . log ( Level . WARNING , "TempFileContext not initialized: refusing to automatically create temp files for large buffers. " + "Additional heap space may be used for large requests. " + "Please add the " + TempFileContext . class . getName ( ) + " filter to your web.xml file." , new Throwable ( "Stack Trace" ) ) ; } tempFileWarned = true ; } } return original ; } } | If the TempFileContext is enabled wraps the original object . When the context is inactive the original object is returned unaltered . This is logged as a warning the first time not wrapped . | 192 | 38 |
5,298 | public List < Method > listMethods ( final Class < ? > classObj , final String methodName ) { // // Get the array of methods for my classname. // Method [ ] methods = classObj . getMethods ( ) ; List < Method > methodSignatures = new ArrayList < Method > ( ) ; // // Loop round all the methods and print them out. // for ( int ii = 0 ; ii < methods . length ; ++ ii ) { if ( methods [ ii ] . getName ( ) . equals ( methodName ) ) { methodSignatures . add ( methods [ ii ] ) ; } } return methodSignatures ; } | Given an object and a method name list the methods that match the method name on the class .. | 134 | 19 |
5,299 | private Map < Integer , Double > predict ( final double [ ] x ) { Map < Integer , Double > result = new HashMap <> ( ) ; for ( int i = 0 ; i < model . weights . length ; i ++ ) { double y = VectorUtils . dotProduct ( x , model . weights [ i ] ) ; y += model . bias [ i ] ; result . put ( i , y ) ; } return result ; } | Key is LabelIndex . | 94 | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.