idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
36,600
public byte [ ] digest ( String algorithm , byte [ ] bytes ) { try { MessageDigest md = MessageDigest . getInstance ( algorithm ) ; return md . digest ( bytes ) ; } catch ( NoSuchAlgorithmException exception ) { throw new IllegalStateException ( "unable to access MD5 algorithm" , exception ) ; } }
Generates a digest based on the given algorithm .
36,601
public String md5HexDigest ( String signature ) { byte [ ] bytes = md5Digest ( signature . getBytes ( ) ) ; return new String ( Hex . encodeHex ( bytes ) ) ; }
Creates a MD5 digest of the given signature and returns the result as a hex - encoded string .
36,602
public String md5Base64Digest ( String signature ) { byte [ ] bytes = md5Digest ( signature . getBytes ( ) ) ; return new String ( Base64 . encodeBase64 ( bytes ) ) ; }
Creates a MD5 digest of the given signature and returns the result as a Base64 - encoded string .
36,603
static ConstantInterfaceMethodInfo make ( ConstantPool cp , ConstantClassInfo parentClass , ConstantNameAndTypeInfo nameAndType ) { ConstantInfo ci = new ConstantInterfaceMethodInfo ( parentClass , nameAndType ) ; return ( ConstantInterfaceMethodInfo ) cp . addConstant ( ci ) ; }
Will return either a new ConstantInterfaceMethodInfo object or one already in the constant pool . If it is a new ConstantInterfaceMethodInfo it will be inserted into the pool .
36,604
static ConstantStringInfo make ( ConstantPool cp , String str ) { ConstantInfo ci = new ConstantStringInfo ( cp , str ) ; return ( ConstantStringInfo ) cp . addConstant ( ci ) ; }
Will return either a new ConstantStringInfo object or one already in the constant pool . If it is a new ConstantStringInfo it will be inserted into the pool .
36,605
public static int setPublic ( int modifier , boolean b ) { if ( b ) { return ( modifier | PUBLIC ) & ( ~ PROTECTED & ~ PRIVATE ) ; } else { return modifier & ~ PUBLIC ; } }
When set public the modifier is cleared from being private or protected .
36,606
public static int setPrivate ( int modifier , boolean b ) { if ( b ) { return ( modifier | PRIVATE ) & ( ~ PUBLIC & ~ PROTECTED ) ; } else { return modifier & ~ PRIVATE ; } }
When set private the modifier is cleared from being public or protected .
36,607
public static int setProtected ( int modifier , boolean b ) { if ( b ) { return ( modifier | PROTECTED ) & ( ~ PUBLIC & ~ PRIVATE ) ; } else { return modifier & ~ PROTECTED ; } }
When set protected the modifier is cleared from being public or private .
36,608
public static int setFinal ( int modifier , boolean b ) { if ( b ) { return ( modifier | FINAL ) & ( ~ INTERFACE & ~ ABSTRACT ) ; } else { return modifier & ~ FINAL ; } }
When set final the modifier is cleared from being an interface or abstract .
36,609
public static int setSynchronized ( int modifier , boolean b ) { if ( b ) { return ( modifier | SYNCHRONIZED ) & ( ~ VOLATILE & ~ TRANSIENT & ~ INTERFACE ) ; } else { return modifier & ~ SYNCHRONIZED ; } }
When set synchronized non - method settings are cleared .
36,610
public static int setVolatile ( int modifier , boolean b ) { if ( b ) { return ( modifier | VOLATILE ) & ( ~ SYNCHRONIZED & ~ NATIVE & ~ INTERFACE & ~ ABSTRACT & ~ STRICT ) ; } else { return modifier & ~ VOLATILE ; } }
When set volatile non - field settings are cleared .
36,611
public static int setTransient ( int modifier , boolean b ) { if ( b ) { return ( modifier | TRANSIENT ) & ( ~ SYNCHRONIZED & ~ NATIVE & ~ INTERFACE & ~ ABSTRACT & ~ STRICT ) ; } else { return modifier & ~ TRANSIENT ; } }
When set transient non - field settings are cleared .
36,612
public static int setNative ( int modifier , boolean b ) { if ( b ) { return ( modifier | NATIVE ) & ( ~ VOLATILE & ~ TRANSIENT & ~ INTERFACE & ~ ABSTRACT & ~ STRICT ) ; } else { return modifier & ~ NATIVE ; } }
When set native non - native - method settings are cleared .
36,613
public static int setInterface ( int modifier , boolean b ) { if ( b ) { return ( modifier | ( INTERFACE | ABSTRACT ) ) & ( ~ FINAL & ~ SYNCHRONIZED & ~ VOLATILE & ~ TRANSIENT & ~ NATIVE ) ; } else { return modifier & ~ INTERFACE ; } }
When set as an interface non - interface settings are cleared and the modifier is set abstract .
36,614
public static int setAbstract ( int modifier , boolean b ) { if ( b ) { return ( modifier | ABSTRACT ) & ( ~ FINAL & ~ VOLATILE & ~ TRANSIENT & ~ NATIVE & ~ SYNCHRONIZED & ~ STRICT ) ; } else { return modifier & ~ ABSTRACT & ~ INTERFACE ; } }
When set abstract the modifier is cleared from being final volatile transient native synchronized and strictfp . When cleared from being abstract the modifier is also cleared from being an interface .
36,615
public void destroy ( ) { for ( int j = 0 ; j < mApplications . length ; j ++ ) { if ( mApplications [ j ] != null ) { mApplications [ j ] . destroy ( ) ; } } }
This method destroys the ApplicationDepot .
36,616
private TeaServletContextSource createContextSource ( boolean http ) throws Exception { return new TeaServletContextSource ( getClass ( ) . getClassLoader ( ) , this , mEngine . getServletContext ( ) , mEngine . getLog ( ) , http , mEngine . getProperties ( ) . getBoolean ( "management.httpcontext" , false ) , mEngine . getProperties ( ) . getInt ( "management.httpcontext.readUrlCacheSize" , 500 ) , mEngine . getProperties ( ) . getBoolean ( "profiling.enabled" , true ) ) ; }
creates a single context source from the applications in the depot .
36,617
public static Set < MethodEntry > getMethodsToImplement ( Class < ? > iface , Map < String , Class < ? > > types , Class < ? > parent ) { Set < MethodEntry > methods = new HashSet < MethodEntry > ( ) ; addMethods ( methods , iface , types , parent ) ; return methods ; }
Get the set of methods that require implementation based on the given interface . If the types are specified then they will be passed through and methods overridden per the generic types . This may result in bridged methods . If parent is specified then only non - implemented methods will be returned .
36,618
private static boolean isBridgeRequired ( Map < String , Class < ? > > types , Method method ) { TypeVariable < ? > var = getTypeVariable ( method . getGenericReturnType ( ) ) ; if ( var != null && types . containsKey ( var . getName ( ) ) ) { return true ; } for ( Type paramType : method . getGenericParameterTypes ( ) ) { var = getTypeVariable ( paramType ) ; if ( var != null && types . containsKey ( var . getName ( ) ) ) { return true ; } } return false ; }
Check whether a bridge is required for the given method and generic type information . If the return type or any parameter contains a type variable that is specified and overridden with a more specific type via the given types then a bridge will be required .
36,619
private static final Class < ? > getRootType ( Map < String , Class < ? > > types , Type type ) { if ( type instanceof Class ) { return ( Class < ? > ) type ; } else if ( type instanceof ParameterizedType ) { Type raw = ( ( ParameterizedType ) type ) . getRawType ( ) ; return getRootType ( types , raw ) ; } else if ( type instanceof WildcardType ) { Type [ ] bounds = ( ( WildcardType ) type ) . getUpperBounds ( ) ; if ( bounds . length >= 1 ) { return getRootType ( types , bounds [ 0 ] ) ; } } else { TypeVariable < ? > raw = getTypeVariable ( type ) ; if ( raw != null ) { String name = raw . getName ( ) ; if ( types . containsKey ( name ) ) { Class < ? > actual = types . get ( name ) ; int dimensions = getDimensions ( type ) ; if ( dimensions >= 1 ) { actual = Array . newInstance ( actual , dimensions ) . getClass ( ) ; } return actual ; } } } return null ; }
Get the root class type based on the given type and set of named type variables . If the type is already a Class it is renamed as is . If the type is a parameterized type then the raw type is returned . If the type is a wildcard the lower bounds is returned . Otherwise if the type is a type variable its associated value from the types is returned .
36,620
private static Class < ? > getMethodType ( Map < String , Class < ? > > types , Type type , Class < ? > clazz ) { TypeVariable < ? > variable = getTypeVariable ( type ) ; if ( variable != null ) { String name = variable . getName ( ) ; if ( types . containsKey ( name ) ) { Class < ? > actual = types . get ( name ) ; int dimensions = getDimensions ( type ) ; if ( dimensions > 0 ) { actual = Array . newInstance ( actual , dimensions ) . getClass ( ) ; } return actual ; } } return clazz ; }
Get the actual type for the given type . If the type is a type variable that is specified in the given types then the associated class is returned . Otherwise the specified class is returned .
36,621
private static void addMethod ( Set < MethodEntry > methods , MethodEntry method ) { if ( ! method . isBridged ( ) ) { methods . remove ( method ) ; methods . add ( method ) ; } else if ( ! methods . contains ( method ) ) { methods . add ( method ) ; } }
Add a method to the set of existing methods . If the method is not bridged it will overwrite any existing signature . Otherwise it will only update the set if not previously defined . Note that the signature of the method entry includes the method name parameter types and the return type .
36,622
private static void addMethods ( Set < MethodEntry > methods , Class < ? > clazz , Map < String , Class < ? > > types , Class < ? > parent ) { if ( ! clazz . isInterface ( ) ) { throw new IllegalStateException ( "class must be interface: " + clazz ) ; } for ( Method method : clazz . getDeclaredMethods ( ) ) { addMethods ( methods , clazz , types , parent , method ) ; } addParentMethods ( methods , clazz , types , parent , null ) ; }
Recursive method that adds all applicable methods for the given class which is expected to be an interface . The tree is walked for the class and all super interfaces in recursive fashion to get each available method . Any method that is already defined by the given parent will be ignored . Otherwise the method including any required bridged methods will be added . The specified list of types define the optional type parameters of the given interface class . These types will propogate up the tree as necessary for any super - interfaces that match .
36,623
private static void addMethods ( Set < MethodEntry > methods , Class < ? > clazz , Map < String , Class < ? > > types , Class < ? > parent , Method method ) { MethodEntry impl = null ; boolean bridged = isBridgeRequired ( types , method ) ; if ( ! bridged && parent != null && findMethod ( parent , method ) != null ) { return ; } if ( bridged ) { Class < ? > returnType = getMethodType ( types , method . getGenericReturnType ( ) , method . getReturnType ( ) ) ; Type [ ] paramTypes = method . getGenericParameterTypes ( ) ; Class < ? > [ ] paramClasses = method . getParameterTypes ( ) ; for ( int i = 0 ; i < paramClasses . length ; i ++ ) { paramClasses [ i ] = getMethodType ( types , paramTypes [ i ] , paramClasses [ i ] ) ; } MethodEntry bridgeMethod = null ; if ( Arrays . equals ( paramClasses , method . getParameterTypes ( ) ) ) { for ( MethodEntry mentry : methods ) { if ( mentry . getName ( ) . equals ( method . getName ( ) ) && Arrays . equals ( mentry . getParamTypes ( ) , method . getParameterTypes ( ) ) ) { bridgeMethod = mentry ; } } } impl = new MethodEntry ( method . getName ( ) , returnType , paramClasses , bridgeMethod ) ; addMethod ( methods , impl ) ; } addMethod ( methods , new MethodEntry ( method . getName ( ) , method . getReturnType ( ) , method . getParameterTypes ( ) , impl ) ) ; addParentMethods ( methods , clazz , types , parent , method ) ; }
Recursive method that adds all applicable methods related to the given class which is expected to be an interface . The tree is walked for the class and all super interfaces in recursive fashion to get each available method that matches the provided method . Any method that is already defined by the given parent will be ignored . Otherwise the method including any required bridged methods will be added . The specified list of types define the optional type parameters of the given interface class . These types will propogate up the tree as necessary for any super - interfaces that match .
36,624
private static void addParentMethods ( Set < MethodEntry > methods , Class < ? > clazz , Map < String , Class < ? > > types , Class < ? > parent , Method method ) { Class < ? > [ ] ifaces = clazz . getInterfaces ( ) ; Type [ ] generics = clazz . getGenericInterfaces ( ) ; for ( int i = 0 ; i < ifaces . length ; i ++ ) { Class < ? > iface = ifaces [ i ] ; Type generic = iface ; if ( generics != null && i < generics . length ) { generic = generics [ i ] ; } if ( generic instanceof ParameterizedType ) { TypeVariable < ? > [ ] vars = iface . getTypeParameters ( ) ; ParameterizedType ptype = ( ParameterizedType ) generic ; Type [ ] arguments = ptype . getActualTypeArguments ( ) ; Map < String , Class < ? > > args = new HashMap < String , Class < ? > > ( ) ; for ( int j = 0 ; j < vars . length ; j ++ ) { Type arg = arguments [ j ] ; TypeVariable < ? > var = vars [ j ] ; Class < ? > root = getRootType ( types , arg ) ; if ( root != null ) { args . put ( var . getName ( ) , root ) ; } } if ( method == null ) { addMethods ( methods , ( Class < ? > ) ptype . getRawType ( ) , args , parent ) ; } else { addMethods ( methods , ( Class < ? > ) ptype . getRawType ( ) , args , parent , method ) ; } } else if ( iface instanceof Class < ? > ) { if ( method == null ) { addMethods ( methods , iface , new HashMap < String , Class < ? > > ( ) , parent ) ; } else { addMethods ( methods , iface , new HashMap < String , Class < ? > > ( ) , parent , method ) ; } } } }
Recursively add all methods walking the interface hiearchy for the given class .
36,625
public static File createTemplateClassesDir ( File tmpDir , String dirPath , Log log ) { File destDir = null ; if ( dirPath != null && ! dirPath . isEmpty ( ) ) { if ( dirPath . startsWith ( "file:" ) ) { destDir = new File ( dirPath . substring ( 5 ) ) ; } else { destDir = new File ( tmpDir , dirPath ) ; try { if ( ! destDir . getCanonicalPath ( ) . startsWith ( tmpDir . getCanonicalPath ( ) . concat ( File . separator ) ) ) { throw new IllegalStateException ( "invalid template classes directory: " + dirPath ) ; } } catch ( IOException ioe ) { throw new IllegalStateException ( "invalid template classes directory: " + dirPath , ioe ) ; } } if ( ! destDir . isDirectory ( ) ) { if ( ! destDir . mkdir ( ) ) { log . warn ( "Could not create template classes directory: " + destDir . getAbsolutePath ( ) ) ; destDir = null ; } } if ( destDir != null && ! destDir . canWrite ( ) ) { log . warn ( "Unable to write to template classes directory: " + destDir . getAbsolutePath ( ) ) ; destDir = null ; } } return destDir ; }
converts a path to a File for storing compiled template classes .
36,626
protected ClassInjector createClassInjector ( ) throws Exception { return new ResolvingInjector ( mConfig . getContextSource ( ) . getContextType ( ) . getClassLoader ( ) , new File [ ] { mCompiledDir } , mConfig . getPackagePrefix ( ) , false ) ; }
provides a default class injector using the contextType s ClassLoader as a parent .
36,627
protected boolean sourceSignatureChanged ( String tName , Compiler compiler ) throws IOException { TemplateRepository tRepo = TemplateRepository . getInstance ( ) ; TemplateInfo templateInfo = tRepo . getTemplateInfo ( tName ) ; if ( null == templateInfo ) { return false ; } CompilationUnit unit = compiler . getCompilationUnit ( tName , null ) ; if ( unit == null ) { return false ; } return ! unit . signatureEquals ( tName , templateInfo . getParameterTypes ( ) , templateInfo . getReturnType ( ) ) ; }
parses the tea source file and compares the signature to the signature of the current class file in the TemplateRepository
36,628
public CompilationSource createCompilationSource ( String name ) { File sourceFile = getSourceFile ( name ) ; if ( sourceFile == null || ! sourceFile . exists ( ) ) { return null ; } return new FileSource ( name , sourceFile ) ; }
Always returns an instance of FileCompiler . Unit . Any errors reported by the compiler that have a reference to a CompilationUnit will have been created by this factory method . Casting this to FileCompiler . Unit allows error reporters to access the source file via the getSourceFile method .
36,629
protected File getSourceFile ( String name ) { String fileName = name . replace ( '.' , File . separatorChar ) + ".tea" ; File file = new File ( mRootSourceDir , fileName ) ; return file ; }
Get the source file relative to the root source directory for the given template .
36,630
public boolean releaseLock ( ) { LockInfo info = ( LockInfo ) mLockInfoRef . get ( ) ; int type = info . mType ; int count = info . mCount ; if ( count > 0 ) { count -- ; } else { info . mType = type = NONE ; count = 0 ; } if ( ( info . mCount = count ) == 0 ) { switch ( type ) { case NONE : default : return false ; case READ : synchronized ( this ) { mReadLocks -- ; notifyAll ( ) ; } break ; case UPGRADABLE : synchronized ( this ) { mUpgradableLockHeld = null ; notifyAll ( ) ; } break ; case WRITE : synchronized ( this ) { mWriteLockHeld = null ; notifyAll ( ) ; } break ; } info . mType = NONE ; } else if ( type == WRITE && info . mUpgradeCount == count ) { info . mType = UPGRADABLE ; info . mUpgradeCount = 0 ; synchronized ( this ) { mWriteLockHeld = null ; notifyAll ( ) ; } } return true ; }
Release the lock held by the current thread .
36,631
private boolean writeLockAvailable ( int type ) { if ( mReadLocks == 0 && mWriteLockHeld == null ) { return ( type == UPGRADABLE ) ? true : mUpgradableLockHeld == null ; } return false ; }
Caller must be synchronized .
36,632
private void writePackageInfos ( File rootDir , File outputDir ) throws MojoExecutionException { getLog ( ) . debug ( "in writePackageInfos(" + rootDir + ", " + outputDir + ")" ) ; try { if ( shouldWritePackageInfo ( rootDir ) ) { if ( ! outputDir . exists ( ) && ! outputDir . mkdirs ( ) ) { throw new MojoExecutionException ( "outputDirectory was unable to be created: " + outputDir ) ; } writePackageInfo ( outputDir ) ; } else { getLog ( ) . debug ( "no files in:" + rootDir ) ; } } catch ( Throwable e ) { throw new MojoExecutionException ( "could not write PackageInfo.java in: " + outputDir , e ) ; } File [ ] subdirs = rootDir . listFiles ( new FileFilter ( ) { public boolean accept ( File pathname ) { return pathname . isDirectory ( ) ; } } ) ; if ( subdirs != null ) { for ( File subdir : subdirs ) { writePackageInfos ( subdir , new File ( outputDir , subdir . getName ( ) ) ) ; } } }
recurse into rootDir writing PackageInfos on the way in .
36,633
private boolean shouldWritePackageInfo ( File directory ) { if ( ! directory . isDirectory ( ) ) return false ; if ( ! directory . exists ( ) ) return false ; if ( isChild ( new File ( mSrcRootPath ) , mPackageRootDir ) ) { return mPackageRootDir . equals ( directory ) || isChild ( mPackageRootDir , directory ) ; } else { File [ ] files = directory . listFiles ( new FileFilter ( ) { public boolean accept ( File pathname ) { return pathname . isFile ( ) ; } } ) ; return files != null && files . length > 0 ; } }
Tests if a PackageInfo . java file should be written in the directory passed in .
36,634
public String readLine ( ) throws IOException { StringBuffer buf = new StringBuffer ( 80 ) ; int line = mLineNumber ; int c ; while ( line == mLineNumber && ( c = read ( ) ) >= 0 ) { buf . append ( ( char ) c ) ; } return buf . toString ( ) ; }
After calling readLine calling getLineNumber returns the next line number .
36,635
public static String createSequence ( char c , int length ) { if ( length < 0 ) length = 1 ; StringBuffer buf = new StringBuffer ( length ) ; for ( ; length > 0 ; length -- ) { buf . append ( c ) ; } return buf . toString ( ) ; }
Creates and returns a String containing a sequence of the specified length repeating the given character .
36,636
public Annotation [ ] getRuntimeInvisibleAnnotations ( ) { for ( int i = mAttributes . size ( ) ; -- i >= 0 ; ) { Attribute attr = mAttributes . get ( i ) ; if ( attr instanceof RuntimeInvisibleAnnotationsAttr ) { return ( ( AnnotationsAttr ) attr ) . getAnnotations ( ) ; } } return new Annotation [ 0 ] ; }
Returns all the runtime invisible annotations defined for this class file or an empty array if none .
36,637
public Annotation [ ] getRuntimeVisibleAnnotations ( ) { for ( int i = mAttributes . size ( ) ; -- i >= 0 ; ) { Attribute attr = mAttributes . get ( i ) ; if ( attr instanceof RuntimeVisibleAnnotationsAttr ) { return ( ( AnnotationsAttr ) attr ) . getAnnotations ( ) ; } } return new Annotation [ 0 ] ; }
Returns all the runtime visible annotations defined for this class file or an empty array if none .
36,638
public Annotation addRuntimeInvisibleAnnotation ( TypeDesc type ) { AnnotationsAttr attr = null ; for ( int i = mAttributes . size ( ) ; -- i >= 0 ; ) { Attribute a = mAttributes . get ( i ) ; if ( a instanceof RuntimeInvisibleAnnotationsAttr ) { attr = ( AnnotationsAttr ) a ; } } if ( attr == null ) { attr = new RuntimeInvisibleAnnotationsAttr ( mCp ) ; addAttribute ( attr ) ; } Annotation ann = new Annotation ( mCp ) ; ann . setType ( type ) ; attr . addAnnotation ( ann ) ; return ann ; }
Add a runtime invisible annotation .
36,639
public static void install ( ) { synchronized ( log ( ) ) { if ( ! cInstalled ) { cInstalled = true ; cOriginalOut = System . out ; cOriginalErr = System . err ; cSystemOut = new LogEventParsingOutputStream ( log ( ) , LogEvent . INFO_TYPE ) { public boolean isEnabled ( ) { return log ( ) . isInfoEnabled ( ) ; } } ; cSystemOut . addLogListener ( log ( ) ) ; System . setOut ( new PrintStream ( cSystemOut , true ) ) ; cSystemErr = new LogEventParsingOutputStream ( log ( ) , LogEvent . ERROR_TYPE ) { public boolean isEnabled ( ) { return log ( ) . isErrorEnabled ( ) ; } } ; cSystemErr . addLogListener ( log ( ) ) ; System . setErr ( new PrintStream ( cSystemErr , true ) ) ; } } }
When installed System . out and System . err are redirected to Syslog . log . System . out produces info events and System . err produces error events .
36,640
public static void uninstall ( ) { synchronized ( log ( ) ) { if ( cInstalled ) { cInstalled = false ; System . setOut ( cOriginalOut ) ; System . setErr ( cOriginalErr ) ; cOriginalOut = null ; cOriginalErr = null ; cSystemOut = null ; cSystemErr = null ; } } }
Uninstalls by restoring System . out and System . err .
36,641
public int read ( ) throws IOException { int c ; if ( mFirst != 0 ) { c = mFirst ; mFirst = 0 ; } else { c = super . read ( ) ; } if ( c == '\n' ) { mLine ++ ; } else if ( c == ENTER_CODE ) { mUnicodeReader . setEscapesEnabled ( true ) ; } else if ( c == ENTER_TEXT ) { mUnicodeReader . setEscapesEnabled ( false ) ; } return c ; }
All newline character patterns are are converted to \ n .
36,642
public CheckedSocket getSocket ( Object session ) throws ConnectException , SocketException { return CheckedSocket . check ( new LazySocket ( mFactory , session ) ) ; }
Returns a socket that will lazily connect .
36,643
public boolean add ( Object o ) { int idx = 0 ; if ( ! isEmpty ( ) ) { idx = findInsertionPoint ( o ) ; } try { super . add ( idx , o ) ; } catch ( IndexOutOfBoundsException e ) { return false ; } return true ; }
Adds an Object to this Collection .
36,644
private int compare ( Object k1 , Object k2 ) { return ( mComparator == null ? ( ( Comparable ) k1 ) . compareTo ( k2 ) : mComparator . compare ( k1 , k2 ) ) ; }
Compares two keys using the correct comparison method for this Collection .
36,645
private int findInsertionPoint ( Object o , int startIndex , int endIndex ) { int halfPt = ( ( endIndex - startIndex ) / 2 ) + startIndex ; int delta = compare ( get ( halfPt ) , o ) ; if ( delta < 0 ) { endIndex = halfPt ; } else if ( delta > 0 ) { startIndex = halfPt ; } else { return halfPt ; } if ( ( endIndex - startIndex ) <= 1 ) { return endIndex + 1 ; } return findInsertionPoint ( o , startIndex , endIndex ) ; }
Conducts a binary search to find the index where Object o should be inserted .
36,646
static ConstantUTFInfo make ( ConstantPool cp , String str ) { ConstantInfo ci = new ConstantUTFInfo ( str ) ; return ( ConstantUTFInfo ) cp . addConstant ( ci ) ; }
Will return either a new ConstantUTFInfo object or one already in the constant pool . If it is a new ConstantUTFInfo it will be inserted into the pool .
36,647
public Set < Map . Entry < K , V > > entrySet ( ) { HashSet s = new HashSet ( mBackingMap . size ( ) ) ; for ( Map . Entry e : mBackingMap . entrySet ( ) ) { if ( mFilter . accept ( e ) ) s . add ( e ) ; } return s ; }
Return a filtered set of entries .
36,648
public AppAdminLinks getAdminLinks ( ) { AppAdminLinks links = new AppAdminLinks ( mLog . getName ( ) ) ; links . addAdminLink ( "JMX Console" , "system.teaservlet.JMXConsole" ) ; return links ; }
Retrieves the administrative links for this application .
36,649
public double [ ] getRangeForBin ( int binIndex ) { if ( binIndex >= 0 && binIndex < ranges . length ) return new double [ ] { ranges [ binIndex ] , ranges [ binIndex + 1 ] } ; return null ; }
Returns the range for the bin at the specified index .
36,650
public int find ( double x ) { if ( x < xMinRangeLimit ) return Integer . MIN_VALUE ; else if ( x >= xMaxRangeLimit ) return Integer . MAX_VALUE ; return findSmaller ( ranges , x ) ; }
Returns the index of the bin containing the specified coordinate .
36,651
private static void initFromPackageInfo ( PackageDescriptor pd , Class < ? > packageInfoClass ) throws Exception { pd . setExists ( true ) ; Class < ? > [ ] ca = new Class [ 0 ] ; Object [ ] oa = new Object [ 0 ] ; pd . setSpecificationTitle ( ( String ) ( packageInfoClass . getMethod ( "getSpecificationTitle" , ca ) ) . invoke ( null , oa ) ) ; pd . setSpecificationVersion ( ( String ) ( packageInfoClass . getMethod ( "getSpecificationVersion" , ca ) ) . invoke ( null , oa ) ) ; pd . setSpecificationVendor ( ( String ) ( packageInfoClass . getMethod ( "getSpecificationVendor" , ca ) ) . invoke ( null , oa ) ) ; pd . setImplementationTitle ( ( String ) ( packageInfoClass . getMethod ( "getImplementationTitle" , ca ) ) . invoke ( null , oa ) ) ; pd . setImplementationVersion ( ( String ) ( packageInfoClass . getMethod ( "getImplementationVersion" , ca ) ) . invoke ( null , oa ) ) ; pd . setImplementationVendor ( ( String ) ( packageInfoClass . getMethod ( "getImplementationVendor" , ca ) ) . invoke ( null , oa ) ) ; pd . setBaseDirectory ( ( String ) ( packageInfoClass . getMethod ( "getBaseDirectory" , ca ) ) . invoke ( null , oa ) ) ; pd . setRepository ( ( String ) ( packageInfoClass . getMethod ( "getRepository" , ca ) ) . invoke ( null , oa ) ) ; pd . setUsername ( ( String ) ( packageInfoClass . getMethod ( "getUsername" , ca ) ) . invoke ( null , oa ) ) ; pd . setBuildMachine ( ( String ) ( packageInfoClass . getMethod ( "getBuildMachine" , ca ) ) . invoke ( null , oa ) ) ; pd . setGroup ( ( String ) ( packageInfoClass . getMethod ( "getGroup" , ca ) ) . invoke ( null , oa ) ) ; pd . setProject ( ( String ) ( packageInfoClass . getMethod ( "getProject" , ca ) ) . invoke ( null , oa ) ) ; pd . setBuildLocation ( ( String ) ( packageInfoClass . getMethod ( "getBuildLocation" , ca ) ) . invoke ( null , oa ) ) ; pd . setProduct ( ( String ) ( packageInfoClass . getMethod ( "getProduct" , ca ) ) . invoke ( null , oa ) ) ; pd . setProductVersion ( ( String ) ( packageInfoClass . getMethod ( "getProductVersion" , ca ) ) . invoke ( null , oa ) ) ; pd . setBuildNumber ( ( String ) ( packageInfoClass . getMethod ( "getBuildNumber" , ca ) ) . invoke ( null , oa ) ) ; pd . setBuildDate ( ( Date ) ( packageInfoClass . getMethod ( "getBuildDate" , ca ) ) . invoke ( null , oa ) ) ; }
Initialize the PackageDescriptor from the PackageInfo class
36,652
private static void initFromPackage ( PackageDescriptor pd , Package pkg ) { pd . setExists ( true ) ; String specificationTitle = pkg . getSpecificationTitle ( ) ; String specificationVersion = pkg . getSpecificationVersion ( ) ; String specificationVendor = pkg . getSpecificationVendor ( ) ; String implementationTitle = pkg . getImplementationTitle ( ) ; String implementationVersion = pkg . getImplementationVersion ( ) ; String implementationVendor = pkg . getImplementationVendor ( ) ; if ( implementationTitle == null ) { implementationTitle = specificationTitle ; } if ( implementationVersion == null ) { implementationVersion = specificationVersion ; } if ( implementationVendor == null ) { implementationVendor = specificationVendor ; } pd . setSpecificationTitle ( specificationTitle ) ; pd . setSpecificationVersion ( specificationVersion ) ; pd . setSpecificationVendor ( specificationVendor ) ; pd . setImplementationTitle ( implementationTitle ) ; pd . setImplementationVersion ( implementationVersion ) ; pd . setImplementationVendor ( implementationVendor ) ; pd . setProduct ( implementationTitle ) ; pd . setProductVersion ( implementationVersion ) ; }
Initialize the PackageDescriptor from the Package
36,653
public final void writeTo ( DataOutput dout ) throws IOException { dout . writeShort ( mNameConstant . getIndex ( ) ) ; dout . writeInt ( getLength ( ) ) ; writeDataTo ( dout ) ; }
This method writes the 16 bit name constant index followed by the 32 bit attribute length followed by the attribute specific data .
36,654
public static boolean start ( com . sun . javadoc . RootDoc root ) { try { BeanDocDoclet doclet = new BeanDocDoclet ( root ) ; doclet . start ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; return false ; } return true ; }
Starts the BeanDoc doclet . Called by the javadoc tool .
36,655
public void start ( ) { ClassDoc [ ] classDocs = mRootDoc . getClasses ( ) ; for ( int i = 0 ; i < classDocs . length ; i ++ ) { ClassDoc classDoc = classDocs [ i ] ; if ( ! accept ( classDoc ) ) { continue ; } try { generateBeanInfo ( classDoc ) ; } catch ( RuntimeException e ) { throw e ; } catch ( Exception e ) { e . printStackTrace ( ) ; throw new RuntimeException ( e . toString ( ) ) ; } } }
Generates BeanInfo . java files for each of the ClassDocs in the RootDoc .
36,656
protected void init ( com . sun . javadoc . RootDoc root , String dest , String templateClassName ) throws Exception { mRootDoc = new RootDoc ( root ) ; mDest = new File ( dest ) ; mDest . mkdirs ( ) ; mTemplateClassName = templateClassName ; if ( mTemplateClassName == null ) { printWarning ( "No template name" ) ; return ; } String [ ] templatePath = ClassDoc . parseClassName ( mTemplateClassName ) ; TemplateLoader loader = new TemplateLoader ( getClass ( ) . getClassLoader ( ) , templatePath [ 0 ] ) ; mTemplate = loader . getTemplate ( templatePath [ 1 ] ) ; Class [ ] params = mTemplate . getParameterTypes ( ) ; if ( params . length != 1 || params [ 0 ] != ClassDoc . class ) { printError ( "Template has incorrect param signature" ) ; } }
Initializes the BeanDocDoclet instance .
36,657
private void generateBeanInfo ( ClassDoc classDoc ) throws Exception { String beanInfoJavaFileName = classDoc . getTypeNameForFile ( ) + "BeanInfo.java" ; String beanInfoJavaFilePath = beanInfoJavaFileName ; String packageName = classDoc . getPackageName ( ) ; if ( packageName != null ) { beanInfoJavaFilePath = packageName . replace ( '.' , '/' ) + "/" + beanInfoJavaFileName ; } File dest = null ; if ( mDest != null ) { dest = new File ( mDest , beanInfoJavaFilePath ) ; } else { dest = new File ( beanInfoJavaFilePath ) ; } if ( dest . exists ( ) ) { if ( dest . canWrite ( ) ) { } else { if ( dest . delete ( ) ) { } else { printWarning ( "File exists and cannot be written: " + beanInfoJavaFileName ) ; return ; } } } BeanDocContext context = null ; try { context = new BeanDocContext ( this , dest ) ; if ( mTemplate != null ) { printNotice ( "Creating BeanInfo: " + beanInfoJavaFilePath ) ; mTemplate . execute ( context , new Object [ ] { classDoc } ) ; } else { printWarning ( "No template" ) ; } } finally { if ( context != null ) { context . close ( ) ; } } }
Using a Tea template generates a BeanInfo . java file for the specified ClassDoc .
36,658
public Object firstKey ( ) throws NoSuchElementException { Entry first = ( mReverse ) ? mLeastRecent : mMostRecent ; if ( first != null ) { return first . mKey ; } else if ( mRecentMap . size ( ) == 0 ) { throw new NoSuchElementException ( ) ; } else { return null ; } }
Returns the first key in the map the most recently used . If reverse order then the least recently used is returned .
36,659
public Object lastKey ( ) throws NoSuchElementException { Entry last = ( mReverse ) ? mMostRecent : mLeastRecent ; if ( last != null ) { return last . mKey ; } else if ( mRecentMap . size ( ) == 0 ) { throw new NoSuchElementException ( ) ; } else { return null ; } }
Returns the last key in the map the least recently used . If reverse order then the most recently used is returned .
36,660
public void unread ( ) throws IOException { mPushback ++ ; if ( mPushback > mMaxPushback - 2 ) { throw new IOException ( this . getClass ( ) . getName ( ) + ": pushback exceeded " + ( mMaxPushback - 2 ) ) ; } if ( ( -- mCursor ) < 0 ) mCursor += mMaxPushback ; if ( mCursor > 0 ) { mPosition = mPositions [ mCursor - 1 ] ; } else { mPosition = mPositions [ mMaxPushback - 1 ] ; } unreadHook ( mCharacters [ mCursor ] ) ; }
Unread the last character read .
36,661
public < T > boolean add ( Set < T > set , T object ) { if ( set == null || object == null ) { return false ; } return set . add ( object ) ; }
Add the given value to the given set .
36,662
public boolean contains ( Set < ? > set , Object object ) { if ( set == null || object == null ) { return false ; } return set . contains ( object ) ; }
Check whether the given set contains the given object instance .
36,663
public boolean remove ( Set < ? > set , Object object ) { if ( set == null || object == null ) { return false ; } return set . remove ( object ) ; }
Remove the given object from the given set .
36,664
@ SuppressWarnings ( "unchecked" ) public < T > T [ ] toArray ( Set < T > set ) { if ( set == null ) { return null ; } return ( T [ ] ) set . toArray ( new Object [ set . size ( ) ] ) ; }
Convert the given set to an array .
36,665
public boolean validateJMX ( ) { if ( getEdenMemoryPoolMXBean ( ) == null || getSurvivorMemoryPoolMXBean ( ) == null || getTenuredMemoryPoolMXBean ( ) == null || getPermGenMemoryPoolMXBean ( ) == null || getYoungCollectorMXBean ( ) == null || getTenuredCollectorMXBean ( ) == null ) { return false ; } return true ; }
Check whether or not the context is properly configured with valid memory pools and collectors including eden survivor and tenured generations .
36,666
static ConstantFloatInfo make ( ConstantPool cp , float value ) { ConstantInfo ci = new ConstantFloatInfo ( value ) ; return ( ConstantFloatInfo ) cp . addConstant ( ci ) ; }
Will return either a new ConstantFloatInfo object or one already in the constant pool . If it is a new ConstantFloatInfo it will be inserted into the pool .
36,667
public static boolean isDeprecated ( Method method ) { return isDeprecated ( method . getDeclaringClass ( ) , method . getName ( ) , method . getParameterTypes ( ) ) ; }
Check whether the given method is deprecated . This will also recursively inspect all parent classes and parent interfaces for any other class in the hiearchy that declares the method . It will also check if the class itself is deprecated .
36,668
public void set ( long index ) throws IOException { long pos = index >> 3 ; try { lock ( ) . acquireUpgradableLock ( ) ; int value = mFile . read ( pos ) ; int newValue ; if ( value <= 0 ) { newValue = ( 0x00000080 >> ( index & 7 ) ) ; } else { newValue = value | ( 0x00000080 >> ( index & 7 ) ) ; } if ( newValue != value ) { mFile . write ( pos , newValue ) ; } } catch ( InterruptedException e ) { throw new InterruptedIOException ( ) ; } finally { lock ( ) . releaseLock ( ) ; } }
Set the bit at the given index to one .
36,669
public long findFirstSet ( long start , byte [ ] temp ) throws IOException { long pos = start >> 3 ; try { lock ( ) . acquireReadLock ( ) ; while ( true ) { int amt = mFile . read ( pos , temp , 0 , temp . length ) ; if ( amt <= 0 ) { return - 1 ; } for ( int i = 0 ; i < amt ; i ++ , pos ++ ) { byte val ; if ( ( val = temp [ i ] ) != 0 ) { long index = pos << 3 ; if ( index < start ) { val &= ( 0x000000ff >>> ( start - index ) ) ; if ( val == 0 ) { continue ; } } return index + findSubIndex ( val ) ; } } } } catch ( InterruptedException e ) { throw new InterruptedIOException ( ) ; } finally { lock ( ) . releaseLock ( ) ; } }
Searches the bitlist for the first set bit and returns the index to it .
36,670
public long countClearBits ( ) throws IOException { byte [ ] temp ; long size = mFile . size ( ) ; if ( size > 1024 ) { temp = new byte [ 1024 ] ; } else { temp = new byte [ ( int ) size ] ; } long pos = 0 ; long count = 0 ; try { lock ( ) . acquireReadLock ( ) ; while ( true ) { int amt = mFile . read ( pos , temp , 0 , temp . length ) ; if ( amt <= 0 ) { break ; } for ( int i = 0 ; i < amt ; i ++ ) { byte val = temp [ i ] ; switch ( val & 15 ) { case 0 : count += 4 ; break ; case 1 : case 2 : case 4 : case 8 : count += 3 ; break ; case 3 : case 5 : case 6 : case 9 : case 10 : case 12 : count += 2 ; break ; case 7 : case 11 : case 13 : case 14 : count ++ ; break ; default : break ; } switch ( ( val >> 4 ) & 15 ) { case 0 : count += 4 ; break ; case 1 : case 2 : case 4 : case 8 : count += 3 ; break ; case 3 : case 5 : case 6 : case 9 : case 10 : case 12 : count += 2 ; break ; case 7 : case 11 : case 13 : case 14 : count ++ ; break ; default : break ; } } pos += amt ; } } catch ( InterruptedException e ) { throw new InterruptedIOException ( ) ; } finally { lock ( ) . releaseLock ( ) ; } return count ; }
Counts all the clear bits .
36,671
public String [ ] getInterfaces ( ) { int size = mInterfaces . size ( ) ; String [ ] names = new String [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { names [ i ] = mInterfaces . get ( i ) . getType ( ) . getRootName ( ) ; } return names ; }
Returns the names of all the interfaces that this class implements .
36,672
public FieldInfo [ ] getFields ( ) { FieldInfo [ ] fields = new FieldInfo [ mFields . size ( ) ] ; return mFields . toArray ( fields ) ; }
Returns all the fields defined in this class .
36,673
public MethodInfo [ ] getMethods ( ) { int size = mMethods . size ( ) ; List < MethodInfo > methodsOnly = new ArrayList < MethodInfo > ( size ) ; for ( int i = 0 ; i < size ; i ++ ) { MethodInfo method = mMethods . get ( i ) ; String name = method . getName ( ) ; if ( ! "<init>" . equals ( name ) && ! "<clinit>" . equals ( name ) ) { methodsOnly . add ( method ) ; } } MethodInfo [ ] methodsArray = new MethodInfo [ methodsOnly . size ( ) ] ; return methodsOnly . toArray ( methodsArray ) ; }
Returns all the methods defined in this class not including constructors and static initializers .
36,674
public MethodInfo [ ] getConstructors ( ) { int size = mMethods . size ( ) ; List < MethodInfo > ctorsOnly = new ArrayList < MethodInfo > ( size ) ; for ( int i = 0 ; i < size ; i ++ ) { MethodInfo method = mMethods . get ( i ) ; if ( "<init>" . equals ( method . getName ( ) ) ) { ctorsOnly . add ( method ) ; } } MethodInfo [ ] ctorsArray = new MethodInfo [ ctorsOnly . size ( ) ] ; return ctorsOnly . toArray ( ctorsArray ) ; }
Returns all the constructors defined in this class .
36,675
public MethodInfo getInitializer ( ) { int size = mMethods . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { MethodInfo method = mMethods . get ( i ) ; if ( "<clinit>" . equals ( method . getName ( ) ) ) { return method ; } } return null ; }
Returns the static initializer defined in this class or null if there isn t one .
36,676
public int getClassDepth ( ) { int depth = 0 ; ClassFile outer = mOuterClass ; while ( outer != null ) { depth ++ ; outer = outer . mOuterClass ; } return depth ; }
Returns a value indicating how deeply nested an inner class is with respect to its outermost enclosing class . For top level classes 0 is returned . For first level inner classes 1 is returned etc .
36,677
public FieldInfo addField ( Modifiers modifiers , String fieldName , TypeDesc type ) { FieldInfo fi = new FieldInfo ( this , modifiers , fieldName , type ) ; mFields . add ( fi ) ; return fi ; }
Add a field to this class .
36,678
public MethodInfo addInitializer ( ) { MethodDesc md = MethodDesc . forArguments ( null , null , null ) ; Modifiers af = new Modifiers ( ) ; af . setStatic ( true ) ; MethodInfo mi = new MethodInfo ( this , af , "<clinit>" , md , null ) ; mMethods . add ( mi ) ; return mi ; }
Add a static initializer to this class .
36,679
public void addAttribute ( Attribute attr ) { if ( attr instanceof SourceFileAttr ) { if ( mSource != null ) { mAttributes . remove ( mSource ) ; } mSource = ( SourceFileAttr ) attr ; } else if ( attr instanceof InnerClassesAttr ) { if ( mInnerClassesAttr != null ) { mAttributes . remove ( mInnerClassesAttr ) ; } mInnerClassesAttr = ( InnerClassesAttr ) attr ; } mAttributes . add ( attr ) ; }
Add an attribute to this class .
36,680
public void setVersion ( int major , int minor ) throws IllegalArgumentException { if ( major != JDK1_1_MAJOR_VERSION || minor != JDK1_1_MINOR_VERSION ) { throw new IllegalArgumentException ( "Version " + major + ", " + minor + " is not supported" ) ; } mMajorVersion = major ; mMinorVersion = minor ; }
Sets the version to use when writing the generated ClassFile . Currently only version 45 3 is supported and is set by default .
36,681
public void writeTo ( OutputStream out ) throws IOException { if ( ! ( out instanceof DataOutput ) ) { out = new DataOutputStream ( out ) ; } writeTo ( ( DataOutput ) out ) ; out . flush ( ) ; }
Writes the ClassFile to the given OutputStream . When finished the stream is flushed but not closed .
36,682
public void init ( ApplicationConfig config ) { PropertyMap properties = config . getProperties ( ) ; String contextClassName = properties . getString ( "contextClass" ) ; if ( contextClassName == null ) { throw new IllegalArgumentException ( "contextClass" ) ; } try { contextClass = Class . forName ( contextClassName ) ; context = contextClass . newInstance ( ) ; if ( context instanceof Context ) { Context castContext = ( Context ) context ; ContextConfig contextConfig = new ContextConfig ( config . getProperties ( ) , config . getLog ( ) , config . getName ( ) , config . getPlugins ( ) , config . getServletContext ( ) ) ; castContext . init ( contextConfig ) ; } } catch ( Exception e ) { throw new RuntimeException ( "Unable to create context: " + contextClassName , e ) ; } }
Initialize the application .
36,683
public void setConstantValue ( String value ) { addAttribute ( new ConstantValueAttr ( mCp , ConstantStringInfo . make ( mCp , value ) ) ) ; }
Set the constant value for this field as a string .
36,684
public static MethodInfo getTemplateExecuteMethod ( InputStream in ) throws IOException { ClassFile classFile = ClassFile . readFrom ( in ) ; MethodInfo executeMethod = null ; MethodInfo [ ] all = classFile . getMethods ( ) ; for ( int i = 0 ; i < all . length ; i ++ ) { if ( JavaClassGenerator . EXECUTE_METHOD_NAME . equals ( all [ i ] . getName ( ) ) && all [ i ] . getModifiers ( ) . isStatic ( ) ) { executeMethod = all [ i ] ; break ; } } in . close ( ) ; return executeMethod ; }
Find the execute method on the class file input stream .
36,685
private static MethodInfo getTemplateSubstituteMethod ( InputStream in ) throws IOException { ClassFile classFile = ClassFile . readFrom ( in ) ; MethodInfo substituteMethod = null ; MethodInfo [ ] all = classFile . getMethods ( ) ; for ( int i = 0 ; i < all . length ; i ++ ) { if ( "substitute" . equals ( all [ i ] . getName ( ) ) && all [ i ] . getMethodDescriptor ( ) . getParameterCount ( ) == 1 ) { substituteMethod = all [ i ] ; break ; } } in . close ( ) ; return substituteMethod ; }
Find the substitute method on the class file input stream .
36,686
public static String [ ] getTemplatesCalled ( String basePath , String templateName ) { final HashMap < String , String > templatesCalledMap = new HashMap < String , String > ( ) ; try { File templatePath = new File ( new File ( basePath ) , templateName . replace ( '.' , '/' ) + ".class" ) ; if ( ! templatePath . exists ( ) && templateName . startsWith ( TEMPLATE_PACKAGE ) ) { templatePath = new File ( new File ( basePath ) , templateName . substring ( TEMPLATE_PACKAGE . length ( ) ) . replace ( '.' , '/' ) + ".class" ) ; } MethodInfo executeMethod = getTemplateExecuteMethod ( new FileInputStream ( templatePath ) ) ; CodeDisassembler cd = new CodeDisassembler ( executeMethod ) ; cd . disassemble ( new CodeAssemblerPrinter ( executeMethod . getMethodDescriptor ( ) . getParameterTypes ( ) , true , null ) { public void invokeStatic ( String className , String methodName , TypeDesc ret , TypeDesc [ ] params ) { if ( JavaClassGenerator . EXECUTE_METHOD_NAME . equals ( methodName ) ) templatesCalledMap . put ( className . replace ( '.' , '/' ) , className ) ; } public void println ( String s ) { } } ) ; MethodInfo substituteMethod = getTemplateSubstituteMethod ( new FileInputStream ( templatePath ) ) ; if ( substituteMethod == null ) return ( String [ ] ) templatesCalledMap . keySet ( ) . toArray ( new String [ templatesCalledMap . keySet ( ) . size ( ) ] ) ; cd = new CodeDisassembler ( substituteMethod ) ; cd . disassemble ( new CodeAssemblerPrinter ( substituteMethod . getMethodDescriptor ( ) . getParameterTypes ( ) , true , null ) { public void invokeStatic ( String className , String methodName , TypeDesc ret , TypeDesc [ ] params ) { if ( JavaClassGenerator . EXECUTE_METHOD_NAME . equals ( methodName ) ) templatesCalledMap . put ( className . replace ( '.' , '/' ) , className ) ; } public void println ( String s ) { } } ) ; } catch ( IOException ix ) { return new String [ 0 ] ; } return ( String [ ] ) templatesCalledMap . keySet ( ) . toArray ( new String [ templatesCalledMap . keySet ( ) . size ( ) ] ) ; }
Get the names of all templates called within a template .
36,687
public void set ( long startTime , long stopTime , long contentLength ) { this . startTime = startTime ; this . endTime = stopTime ; this . contentLength = contentLength ; }
This methods sets the raw data values .
36,688
protected int selectFactoryIndex ( Object session ) throws ConnectException { Random rnd ; if ( session != null ) { return session . hashCode ( ) & 0x7fffffff ; } else if ( ( rnd = mRnd ) != null ) { return rnd . nextInt ( ) >>> 1 ; } else { synchronized ( mFactories ) { return mFactoryIndex ++ & 0x7fffffff ; } } }
Returns an index which is positive but may be out of the factory list bounds .
36,689
private SocketFactory getFactory ( int index ) throws ConnectException { synchronized ( mFactories ) { int size = mFactories . size ( ) ; if ( size <= 0 ) { throw new ConnectException ( "No SocketFactories available" ) ; } return ( SocketFactory ) mFactories . get ( index % size ) ; } }
The provided index must be positive but it can be out of the factory list bounds .
36,690
@ SuppressWarnings ( "unchecked" ) public < K > K [ ] getKeys ( Map < K , ? > map ) { K [ ] result = null ; Set < K > keySet = map . keySet ( ) ; if ( keySet . size ( ) > 0 ) { result = ( K [ ] ) keySet . toArray ( new Object [ keySet . size ( ) ] ) ; } return result ; }
Get the array of all keys in the given map .
36,691
public String [ ] getKeysAsStrings ( Map < String , ? > map ) { String [ ] result = null ; Set < String > keySet = map . keySet ( ) ; int keySize = keySet . size ( ) ; if ( keySize > 0 ) { result = keySet . toArray ( new String [ keySize ] ) ; } return result ; }
Get the array of all keys in the given map as strings . This assumes that each key in the given map is a String .
36,692
public < K , V > void putAll ( Map < K , V > mapToAddTo , Map < ? extends K , ? extends V > mapToAdd ) { mapToAddTo . putAll ( mapToAdd ) ; }
Put all of the given key and value pairs in the given map .
36,693
public < K , V > SortedMap < K , V > subMap ( SortedMap < K , V > map , K fromKey , K toKey ) { return map . subMap ( fromKey , toKey ) ; }
Get a portion of the given sorted map from the given fromKey inclusive up to but excluding the given toKey . The keys are based on the sort algorithm of the keys in the given map .
36,694
public void setTemplateSource ( String name , String source ) { mTemplateSources . put ( name , new TemplateSource ( name , source ) ) ; }
Add or overwrite an existing source for the given fully - qualified dot format of the given template name .
36,695
public static CheckedSocket check ( SocketFace socket ) throws SocketException { if ( socket instanceof CheckedSocket ) { return ( CheckedSocket ) socket ; } else { return new CheckedSocket ( socket ) ; } }
Returns a new CheckedSocket instance only if the given socket isn t already one .
36,696
public synchronized void addExceptionListener ( ExceptionListener listener ) { if ( mExceptionListeners == null ) { mExceptionListeners = new HashSet ( ) ; } mExceptionListeners . add ( listener ) ; }
Internally the collection of listeners is saved in a set so that listener instances may be added multiple times without harm .
36,697
public void storeLocal ( LocalVariable local ) { if ( local == null ) { throw new NullPointerException ( "No local variable specified" ) ; } int stackAdjust = local . getType ( ) . isDoubleWord ( ) ? - 2 : - 1 ; mInstructions . new StoreLocalInstruction ( stackAdjust , local ) ; }
store - from - stack - to - local style instructions
36,698
public void loadFromArray ( TypeDesc type ) { byte op ; int stackAdjust = - 1 ; switch ( type . getTypeCode ( ) ) { case TypeDesc . INT_CODE : op = Opcode . IALOAD ; break ; case TypeDesc . BOOLEAN_CODE : case TypeDesc . BYTE_CODE : op = Opcode . BALOAD ; break ; case TypeDesc . SHORT_CODE : op = Opcode . SALOAD ; break ; case TypeDesc . CHAR_CODE : op = Opcode . CALOAD ; break ; case TypeDesc . FLOAT_CODE : op = Opcode . FALOAD ; break ; case TypeDesc . LONG_CODE : stackAdjust = 0 ; op = Opcode . LALOAD ; break ; case TypeDesc . DOUBLE_CODE : stackAdjust = 0 ; op = Opcode . DALOAD ; break ; default : op = Opcode . AALOAD ; break ; } addCode ( stackAdjust , op ) ; }
load - to - stack - from - array style instructions
36,699
public void storeToArray ( TypeDesc type ) { byte op ; int stackAdjust = - 3 ; switch ( type . getTypeCode ( ) ) { case TypeDesc . INT_CODE : op = Opcode . IASTORE ; break ; case TypeDesc . BOOLEAN_CODE : case TypeDesc . BYTE_CODE : op = Opcode . BASTORE ; break ; case TypeDesc . SHORT_CODE : op = Opcode . SASTORE ; break ; case TypeDesc . CHAR_CODE : op = Opcode . CASTORE ; break ; case TypeDesc . FLOAT_CODE : op = Opcode . FASTORE ; break ; case TypeDesc . LONG_CODE : stackAdjust = - 4 ; op = Opcode . LASTORE ; break ; case TypeDesc . DOUBLE_CODE : stackAdjust = - 4 ; op = Opcode . DASTORE ; break ; default : op = Opcode . AASTORE ; break ; } addCode ( stackAdjust , op ) ; }
store - to - array - from - stack style instructions