idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
700
protected Optional < String > parseXmlHasMore ( String xml , String elementName , String attributeKey , String newContinueKey ) { XmlElement rootElement = XmlConverter . getRootElement ( xml ) ; Optional < XmlElement > aContinue = rootElement . getChildOpt ( "continue" ) ; if ( aContinue . isPresent ( ) ) { return aContinue . get ( ) . getAttributeValueOpt ( newContinueKey ) ; } else { XmlElement queryContinue = rootElement . getChild ( "query-continue" ) . getChild ( elementName ) ; return queryContinue . getAttributeValueOpt ( attributeKey ) ; } }
XML related methods will be removed .
701
public synchronized < Z > Z map ( Function < T , Z > f ) { if ( ref == null ) { return f . apply ( null ) ; } else { return f . apply ( ref . get ( ) ) ; } }
Call some function f on the reference we are storing . Saving the value of T after this call returns is COMPLETELY UNSAFE . Don t do it .
702
public < Z > Z mapWithCopy ( Function < T , Z > f ) throws IOException { final SharedReference < T > localRef = getCopy ( ) ; try { if ( localRef == null ) { return f . apply ( null ) ; } else { return f . apply ( localRef . get ( ) ) ; } } finally { if ( localRef != null ) localRef . close ( ) ; } }
Call some function f on a threadsafe copy of the reference we are storing . Should be used if you expect the function to take a while to run . Saving the value of T after this call returns is COMPLETELY UNSAFE . Don t do it .
703
private static File writeDataToTempFileOrDie ( final OutputStreamCallback callback , final File targetFile , final Logger log ) throws IOException { Preconditions . checkNotNull ( callback , "callback argument is required!" ) ; Preconditions . checkNotNull ( log , "log argument is required!" ) ; Preconditions . checkNotNull ( targetFile , "targetFile argument is required!" ) ; FileOutputStream fileOut = null ; FileChannel fileChannel = null ; try { final String targetFinalName = targetFile . getName ( ) ; final File targetDirectory = targetFile . getParentFile ( ) ; final File tmpFile = File . createTempFile ( targetFinalName , ".tmp" , targetDirectory ) ; fileOut = new FileOutputStream ( tmpFile ) ; fileChannel = fileOut . getChannel ( ) ; callback . writeAndFlushData ( Channels . newOutputStream ( fileChannel ) ) ; return tmpFile ; } finally { try { if ( fileChannel != null ) { fileChannel . force ( true ) ; } } finally { if ( fileOut != null ) { fileOut . close ( ) ; } } } }
return a reference to a temp file that contains the written + flushed + fsynced + closed data
704
public static boolean writeObjectToFile ( Object obj , String file ) { try { writeObjectToFileOrDie ( obj , file , LOGGER ) ; return true ; } catch ( Exception e ) { LOGGER . error ( e . getClass ( ) + ": writeObjectToFile(" + file + ") encountered exception: " + e . getMessage ( ) , e ) ; return false ; } }
Writes an object to a file .
705
private static boolean arrayCompare ( byte [ ] a , int offset1 , byte [ ] a2 , int offset2 , int length ) { for ( int i = 0 ; i < length ; i ++ ) { if ( a [ offset1 ++ ] != a2 [ offset2 ++ ] ) return false ; } return true ; }
Returns true if the array chunks are equal false otherwise .
706
public static long parseTimestampFromUIDString ( String s , final int start , final int end ) { long ret = 0 ; for ( int i = start ; i < end && i < start + 9 ; i ++ ) { ret <<= 5 ; char c = s . charAt ( i ) ; if ( c >= '0' && c <= '9' ) { ret |= c - '0' ; } else if ( c >= 'a' && c <= 'v' ) { ret |= c - 'a' + 10 ; } else if ( c >= 'A' && c <= 'V' ) { ret |= c - 'A' + 10 ; } else { throw new IllegalArgumentException ( s . substring ( start , end ) + " is not a valid UID!" ) ; } } return ret ; }
Parses out the timestamp portion of the uid Strings used in the logrepo
707
public void advise ( long position , long length ) throws IOException { final long ap = address + position ; final long a = ( ap ) / PAGE_SIZE * PAGE_SIZE ; final long l = Math . min ( length + ( ap - a ) , address + memory . length ( ) - ap ) ; final int err = madvise ( a , l ) ; if ( err != 0 ) { throw new IOException ( "madvise failed with error code: " + err ) ; } }
this is not particularly useful the syscall takes forever
708
public static void madviseDontNeedTrackedBuffers ( ) { if ( openBuffersTracker == null ) { return ; } openBuffersTracker . forEachOpenTrackedBuffer ( new Function < MMapBuffer , Void > ( ) { public Void apply ( final MMapBuffer b ) { madviseDontNeed ( b . memory . getAddress ( ) , b . memory . length ( ) ) ; return null ; } } ) ; }
If open buffers tracking is enabled calls madvise with MADV_DONTNEED for all tracked buffers . If open buffers tracking is disabled does nothing .
709
public boolean isLoadedDataSuccessfullyRecently ( ) { final Integer timeSinceLastError = getSecondsSinceLastFailedLoad ( ) ; final Integer timeSinceLastSuccess = getSecondsSinceLastLoad ( ) ; if ( timeSinceLastSuccess == null ) { return false ; } if ( timeSinceLastError == null ) { return true ; } return lastLoadWasSuccessful ; }
useful for artifact - based healthchecks
710
public static Quicksortable getQuicksortableIntArray ( final int [ ] array ) { return new Quicksortable ( ) { public void swap ( int i , int j ) { int t = array [ i ] ; array [ i ] = array [ j ] ; array [ j ] = t ; } public int compare ( int a , int b ) { int x = array [ a ] ; int y = array [ b ] ; if ( x < y ) return - 1 ; if ( x == y ) return 0 ; return 1 ; } } ; }
the sorting code contained in this class was copied from Arrays . java and then modified
711
private static void sort1 ( Quicksortable q , int off , int k , int len ) { if ( off >= k ) return ; if ( len < 7 ) { for ( int i = off ; i < len + off ; i ++ ) for ( int j = i ; j > off && q . compare ( j , j - 1 ) < 0 ; j -- ) q . swap ( j , j - 1 ) ; return ; } int m = off + ( len >> 1 ) ; if ( len > 7 ) { int l = off ; int n = off + len - 1 ; if ( len > 40 ) { int s = len / 8 ; l = med3 ( q , l , l + s , l + 2 * s ) ; m = med3 ( q , m - s , m , m + s ) ; n = med3 ( q , n - 2 * s , n - s , n ) ; } m = med3 ( q , l , m , n ) ; } q . swap ( off , m ) ; m = off ; int a = off + 1 , b = a , c = off + len - 1 , d = c ; int cmp ; while ( true ) { while ( b <= c && ( cmp = q . compare ( b , off ) ) <= 0 ) { if ( cmp == 0 ) q . swap ( a ++ , b ) ; b ++ ; } while ( c >= b && ( cmp = q . compare ( c , off ) ) >= 0 ) { if ( cmp == 0 ) q . swap ( c , d -- ) ; c -- ; } if ( b > c ) break ; q . swap ( b ++ , c -- ) ; } int s , n = off + len ; s = Math . min ( a - off , b - a ) ; vecswap ( q , off , b - s , s ) ; s = Math . min ( d - c , n - d - 1 ) ; vecswap ( q , b , n - s , s ) ; if ( ( s = b - a ) > 1 ) sort1 ( q , off , k , s ) ; if ( ( s = d - c ) > 1 ) sort1 ( q , n - s , k , s ) ; }
Sorts the specified sub - array of integers into ascending order .
712
public static void heapSort ( Quicksortable q , int size ) { q = reverseQuicksortable ( q ) ; makeHeap ( q , size ) ; sortheap ( q , size ) ; }
sorts the elements in q using the heapsort method
713
private static void sortheap ( Quicksortable q , int size ) { for ( int i = size - 1 ; i >= 1 ; i -- ) { q . swap ( 0 , i ) ; heapifyDown ( q , 0 , i ) ; } }
sorts the heap stored in q
714
public static void partialSortUsingHeap ( Quicksortable q , int k , int size ) { Quicksortable revq = reverseQuicksortable ( q ) ; makeHeap ( revq , k ) ; for ( int i = k ; i < size ; i ++ ) { if ( q . compare ( 0 , i ) > 0 ) { q . swap ( 0 , i ) ; heapifyDown ( revq , 0 , k ) ; } } sortheap ( revq , k ) ; }
finds the lowest k elements of q and stores them in sorted order at the beginning of q by using a heap of size k
715
public static void partialHeapSort ( Quicksortable q , int k , int size ) { makeHeap ( q , size ) ; for ( int i = 0 ; i < k ; i ++ ) { q . swap ( 0 , size - i - 1 ) ; heapifyDown ( q , 0 , size - i - 1 ) ; } vecswap ( q , 0 , size - k , k ) ; reverse ( q , k ) ; }
finds the lowest k elements of q and stores them in sorted order at the beginning of q by turning q into a heap .
716
public static void makeHeap ( Quicksortable q , int size ) { for ( int i = ( size - 1 ) / 2 ; i >= 0 ; i -- ) { heapifyDown ( q , i , size ) ; } }
Makes a heap with the elements [ 0 size ) of q
717
public static void popHeap ( Quicksortable q , int size ) { q . swap ( 0 , size - 1 ) ; heapifyDown ( q , 0 , size - 1 ) ; }
Pops the lowest element off the heap and stores it in the last element
718
public static void topK ( Quicksortable qs , int totalSize , int k ) { if ( k > totalSize ) k = totalSize ; makeHeap ( qs , k ) ; for ( int i = k ; i < totalSize ; i ++ ) { if ( qs . compare ( i , 0 ) > 0 ) { qs . swap ( 0 , i ) ; heapifyDown ( qs , 0 , k ) ; } } sort ( qs , k ) ; reverse ( qs , k ) ; }
in an unspecified order
719
public static int binarySearch ( Quicksortable qs , int size ) { int low = 0 ; int high = size - 1 ; while ( low <= high ) { int mid = ( low + high ) >> 1 ; int cmp = qs . compare ( mid , - 1 ) ; if ( cmp < 0 ) low = mid + 1 ; else if ( cmp > 0 ) high = mid - 1 ; else return mid ; } return - ( low + 1 ) ; }
the compare function on Quicksortable will always pass - 1 as the second index swap function is never called
720
public final long plus ( final long value , final TimeUnit timeUnit ) { return this . millis . addAndGet ( timeUnit . toMillis ( value ) ) ; }
Add the specified amount of time to the current clock .
721
private static long findMaxTime ( Node n ) { long max = Long . MIN_VALUE ; for ( Map . Entry < String , Node > entry : n . children . entrySet ( ) ) { max = Math . max ( max , entry . getValue ( ) . time ) ; } return max ; }
used for aligning output for prettier printing
722
public final void and ( ThreadSafeBitSet other ) { if ( other . size != size ) throw new IllegalArgumentException ( "BitSets must be of equal size" ) ; for ( int i = 0 ; i < bits . length ; i ++ ) { bits [ i ] &= other . bits [ i ] ; } }
basically same as java s BitSet . and
723
public final void or ( ThreadSafeBitSet other ) { if ( other . size != size ) throw new IllegalArgumentException ( "BitSets must be of equal size" ) ; for ( int i = 0 ; i < bits . length ; i ++ ) { bits [ i ] |= other . bits [ i ] ; } }
this = this | other bitwise
724
public final void xor ( ThreadSafeBitSet other ) { if ( other . size != size ) throw new IllegalArgumentException ( "BitSets must be of equal size" ) ; for ( int i = 0 ; i < bits . length ; i ++ ) { bits [ i ] ^= other . bits [ i ] ; } }
this = this ^ other bitwise
725
public static int count ( final Path dir ) throws IOException { try ( final DirectoryStream < Path > stream = Files . newDirectoryStream ( dir ) ) { return Iterables . size ( stream ) ; } catch ( DirectoryIteratorException ex ) { throw ex . getCause ( ) ; } }
Count the number of entries in a directory .
726
public static void rename ( final Path oldName , final Path newName ) throws IOException { checkNotNull ( oldName ) ; checkNotNull ( newName ) ; final boolean sameDir = Files . isSameFile ( oldName . getParent ( ) , newName . getParent ( ) ) ; Files . move ( oldName , newName , StandardCopyOption . ATOMIC_MOVE ) ; fsync ( newName . getParent ( ) ) ; if ( ! sameDir ) { fsync ( oldName . getParent ( ) ) ; } }
Perform an atomic rename of oldName - &gt ; newName and fsync the containing directory . This is only truly fsync - safe if both files are in the same directory but it will at least try to do the right thing if the files are in different directories .
727
public static void ensureDirectoryExists ( final Path path ) throws IOException { if ( Files . exists ( path ) ) { if ( ! Files . isDirectory ( path ) ) { throw new IOException ( "path is not a directory: " + path ) ; } } else { Files . createDirectories ( path ) ; fsyncLineage ( path . getParent ( ) ) ; } }
Create a directory if it does not already exist . Fails if the path exists and is NOT a directory . Will fsync the parent directory inode .
728
public static int fsyncRecursive ( final Path root ) throws IOException { final FsyncingSimpleFileVisitor visitor = new FsyncingSimpleFileVisitor ( ) ; Files . walkFileTree ( root , visitor ) ; return visitor . getFileCount ( ) ; }
Walk a directory tree and Fsync both Directory and File inodes . This does NOT follow symlinks and does not attempt to fsync anything other than Directory or NormalFiles .
729
public static void fsync ( final Path path ) throws IOException { if ( ! Files . isDirectory ( path ) && ! Files . isRegularFile ( path ) ) { throw new IllegalArgumentException ( "fsync is only supported for regular files and directories: " + path ) ; } try ( final FileChannel channel = FileChannel . open ( path , StandardOpenOption . READ ) ) { channel . force ( true ) ; } }
Fsync a single path . Please only call this on things that are Directories or NormalFiles .
730
private static void fsyncLineage ( final Path path ) throws IOException { Path cursor = path . toRealPath ( ) ; while ( cursor != null ) { fsync ( cursor ) ; cursor = cursor . getParent ( ) ; } }
Fsync a path and all parents all the way up to the fs root .
731
public static void writeUTF8 ( final String value , final Path path ) throws IOException { write ( value . getBytes ( Charsets . UTF_8 ) , path ) ; }
Write the string to a temporary file fsync the file then atomically rename to the target path . On error it will make a best - effort to erase the temporary file .
732
public static void write ( final byte [ ] data , final Path path ) throws IOException { try ( final SafeOutputStream out = createAtomicFile ( path ) ) { out . write ( ByteBuffer . wrap ( data ) ) ; out . commit ( ) ; } }
Write the bytes to a temporary file fsync the file then atomically rename to the target path . On error it will make a best - effort to erase the temporary file .
733
public static String determineHostName ( ) throws UnknownHostException { if ( ! OPT_HOSTNAME . isPresent ( ) ) { final String hostName = InetAddress . getLocalHost ( ) . getHostName ( ) ; if ( Strings . isNullOrEmpty ( hostName ) ) { throw new UnknownHostException ( "Unable to lookup localhost, got back empty hostname" ) ; } if ( Strings . nullToEmpty ( hostName ) . equals ( "0.0.0.0" ) ) { throw new UnknownHostException ( "Unable to resolve correct hostname saw bad host" ) ; } OPT_HOSTNAME = Optional . of ( hostName ) ; return OPT_HOSTNAME . get ( ) ; } else { return OPT_HOSTNAME . get ( ) ; } }
Determine the hostname of the machine that we are on . Do not allow blank or 0 . 0 . 0 . 0 as valid hostnames . The host name will be save into the OPT_HOSTNAME static variable .
734
public static String determineHostName ( final String defaultValue ) { checkNotNull ( defaultValue , "Unable to use default value of null for hostname" ) ; if ( ! OPT_HOSTNAME . isPresent ( ) ) { try { return determineHostName ( ) ; } catch ( final UnknownHostException e ) { log . error ( "Unable to find hostname " + e . getMessage ( ) , e ) ; } } return OPT_HOSTNAME . or ( defaultValue ) ; }
Same as determineHostName but will use default value instead of throwing UnknownHostException
735
public static String determineIpAddress ( ) throws SocketException { SocketException caughtException = null ; for ( final Enumeration < NetworkInterface > networkInterfaces = NetworkInterface . getNetworkInterfaces ( ) ; networkInterfaces . hasMoreElements ( ) ; ) { try { final NetworkInterface nextInterface = networkInterfaces . nextElement ( ) ; if ( ! nextInterface . isLoopback ( ) && ! nextInterface . isVirtual ( ) && ! nextInterface . isPointToPoint ( ) ) { for ( final Enumeration < InetAddress > addresses = nextInterface . getInetAddresses ( ) ; addresses . hasMoreElements ( ) ; ) { final InetAddress inetAddress = addresses . nextElement ( ) ; final byte [ ] address = inetAddress . getAddress ( ) ; if ( ( address . length == 4 ) && ( ( address [ 0 ] != 127 ) || ( address [ 1 ] != 0 ) ) ) { return inetAddress . getHostAddress ( ) ; } } } } catch ( SocketException ex ) { caughtException = ex ; } } if ( caughtException != null ) { throw caughtException ; } return null ; }
Make a best effort to determine the IP address of this machine .
736
public static synchronized VarExporter forNamespace ( final Class < ? > clazz , final boolean declaredFieldsOnly ) { return getInstance ( clazz . getSimpleName ( ) , clazz , declaredFieldsOnly ) ; }
Load an exporter with a specified class .
737
@ SuppressWarnings ( "unchecked" ) public < T > T getValue ( final String variableName ) { final Variable variable = getVariable ( variableName ) ; return ( variable == null ) ? null : ( T ) variable . getValue ( ) ; }
Load the current value of a given variable .
738
@ SuppressWarnings ( "unchecked" ) public < T > Variable < T > getVariable ( final String variableName ) { final String [ ] subTokens = getSubVariableTokens ( variableName ) ; if ( subTokens != null ) { final Variable < T > sub = getSubVariable ( subTokens [ 0 ] , subTokens [ 1 ] ) ; if ( sub != null ) { return sub ; } } final Variable < T > v ; synchronized ( variables ) { v = variables . get ( variableName ) ; } return v ; }
Load the dynamic variable object .
739
public void visitVariables ( VariableVisitor visitor ) { final List < Variable > variablesCopy ; synchronized ( variables ) { variablesCopy = Lists . newArrayListWithExpectedSize ( variables . size ( ) ) ; final Iterator < Variable > iterator = variables . values ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { final Variable v = iterator . next ( ) ; if ( v . isLive ( ) ) { variablesCopy . add ( v ) ; } else { iterator . remove ( ) ; } } } for ( Variable v : variablesCopy ) { if ( v . isExpandable ( ) ) { Map < ? , ? > map = v . expand ( ) ; try { for ( final Map . Entry entry : map . entrySet ( ) ) { visitor . visit ( new EntryVariable ( entry , v , namespace ) ) ; } } catch ( ConcurrentModificationException e ) { log . warn ( "Failed to iterate map entry set for variable " + v . getName ( ) , e ) ; Map . Entry < String , String > errorEntry = new AbstractMap . SimpleEntry < String , String > ( "error" , e . getMessage ( ) ) ; visitor . visit ( new EntryVariable ( errorEntry , v , namespace ) ) ; } } else { visitor . visit ( v ) ; } } if ( variablesCopy . size ( ) > 0 && startTime != null ) { visitor . visit ( startTime ) ; } }
Visit all the values exported by this exporter .
740
public void dumpJson ( final PrintWriter out ) { out . append ( "{" ) ; visitVariables ( new Visitor ( ) { int count = 0 ; public void visit ( Variable var ) { if ( count ++ > 0 ) { out . append ( ", " ) ; } out . append ( var . getName ( ) ) . append ( "='" ) . append ( String . valueOf ( var . getValue ( ) ) ) . append ( "'" ) ; } } ) ; out . append ( "}" ) ; }
Write all variables as a JSON object . Will not escape names or values . All values are written as Strings .
741
public void merge ( final Object from , final Object target , final NullHandlingPolicy nullPolicy ) { if ( from == null || target == null ) { return ; } final BeanWrapper fromWrapper = beanWrapper ( from ) ; final BeanWrapper targetWrapper = beanWrapper ( target ) ; final DomainTypeAdministrationConfiguration domainTypeAdministrationConfiguration = configuration . forManagedDomainType ( target . getClass ( ) ) ; final PersistentEntity < ? , ? > entity = domainTypeAdministrationConfiguration . getPersistentEntity ( ) ; entity . doWithProperties ( new SimplePropertyHandler ( ) { public void doWithPersistentProperty ( PersistentProperty < ? > persistentProperty ) { Object sourceValue = fromWrapper . getPropertyValue ( persistentProperty . getName ( ) ) ; Object targetValue = targetWrapper . getPropertyValue ( persistentProperty . getName ( ) ) ; if ( entity . isIdProperty ( persistentProperty ) ) { return ; } if ( nullSafeEquals ( sourceValue , targetValue ) ) { return ; } if ( propertyIsHiddenInFormView ( persistentProperty , domainTypeAdministrationConfiguration ) ) { return ; } if ( nullPolicy == APPLY_NULLS || sourceValue != null ) { targetWrapper . setPropertyValue ( persistentProperty . getName ( ) , sourceValue ) ; } } } ) ; entity . doWithAssociations ( new SimpleAssociationHandler ( ) { @ SuppressWarnings ( "unchecked" ) public void doWithAssociation ( Association < ? extends PersistentProperty < ? > > association ) { PersistentProperty < ? > persistentProperty = association . getInverse ( ) ; Object fromValue = fromWrapper . getPropertyValue ( persistentProperty . getName ( ) ) ; Object targetValue = targetWrapper . getPropertyValue ( persistentProperty . getName ( ) ) ; if ( propertyIsHiddenInFormView ( persistentProperty , domainTypeAdministrationConfiguration ) ) { return ; } if ( ( fromValue == null && nullPolicy == APPLY_NULLS ) ) { targetWrapper . setPropertyValue ( persistentProperty . getName ( ) , fromValue ) ; } if ( persistentProperty . isCollectionLike ( ) ) { Collection < Object > sourceCollection = ( Collection ) fromValue ; Collection < Object > targetCollection = ( Collection ) targetValue ; Collection < Object > candidatesForAddition = candidatesForAddition ( sourceCollection , targetCollection , persistentProperty ) ; Collection < Object > candidatesForRemoval = candidatesForRemoval ( sourceCollection , targetCollection , persistentProperty ) ; removeReferencedItems ( targetCollection , candidatesForRemoval ) ; addReferencedItems ( targetCollection , candidatesForAddition ) ; return ; } if ( ! nullSafeEquals ( fromValue , targetWrapper . getPropertyValue ( persistentProperty . getName ( ) ) ) ) { targetWrapper . setPropertyValue ( persistentProperty . getName ( ) , fromValue ) ; } } } ) ; }
Merges the given target object into the source one .
742
public List getOptions ( int code ) { if ( options == null ) return Collections . EMPTY_LIST ; List list = Collections . EMPTY_LIST ; for ( Iterator it = options . iterator ( ) ; it . hasNext ( ) ; ) { EDNSOption opt = ( EDNSOption ) it . next ( ) ; if ( opt . getCode ( ) == code ) { if ( list == Collections . EMPTY_LIST ) list = new ArrayList ( ) ; list . add ( opt ) ; } } return list ; }
Gets all options in the OPTRecord with a specific code . This returns a list of EDNSOptions .
743
public RRset findExactMatch ( Name name , int type ) { Object types = exactName ( name ) ; if ( types == null ) return null ; return oneRRset ( types , type ) ; }
Looks up Records in the zone finding exact matches only .
744
public void addRRset ( RRset rrset ) { Name name = rrset . getName ( ) ; addRRset ( name , rrset ) ; }
Adds an RRset to the Zone
745
public void addRecord ( Record r ) { Name name = r . getName ( ) ; int rtype = r . getRRsetType ( ) ; synchronized ( this ) { RRset rrset = findRRset ( name , rtype ) ; if ( rrset == null ) { rrset = new RRset ( r ) ; addRRset ( name , rrset ) ; } else { rrset . addRR ( r ) ; } } }
Adds a Record to the Zone
746
public void removeRecord ( Record r ) { Name name = r . getName ( ) ; int rtype = r . getRRsetType ( ) ; synchronized ( this ) { RRset rrset = findRRset ( name , rtype ) ; if ( rrset == null ) return ; if ( rrset . size ( ) == 1 && rrset . first ( ) . equals ( r ) ) removeRRset ( name , rtype ) ; else rrset . deleteRR ( r ) ; } }
Removes a record from the Zone
747
public synchronized String toMasterFile ( ) { Iterator zentries = data . entrySet ( ) . iterator ( ) ; StringBuffer sb = new StringBuffer ( ) ; nodeToString ( sb , originNode ) ; while ( zentries . hasNext ( ) ) { Map . Entry entry = ( Map . Entry ) zentries . next ( ) ; if ( ! origin . equals ( entry . getKey ( ) ) ) nodeToString ( sb , entry . getValue ( ) ) ; } return sb . toString ( ) ; }
Returns the contents of the Zone in master file format .
748
public static String formatString ( byte [ ] b , int lineLength , String prefix , boolean addClose ) { String s = toString ( b ) ; StringBuffer sb = new StringBuffer ( ) ; for ( int i = 0 ; i < s . length ( ) ; i += lineLength ) { sb . append ( prefix ) ; if ( i + lineLength >= s . length ( ) ) { sb . append ( s . substring ( i ) ) ; if ( addClose ) sb . append ( " )" ) ; } else { sb . append ( s . substring ( i , i + lineLength ) ) ; sb . append ( "\n" ) ; } } return sb . toString ( ) ; }
Formats data into a nicely formatted base64 encoded String
749
public static byte [ ] fromString ( String str ) { ByteArrayOutputStream bs = new ByteArrayOutputStream ( ) ; byte [ ] raw = str . getBytes ( ) ; for ( int i = 0 ; i < raw . length ; i ++ ) { if ( ! Character . isWhitespace ( ( char ) raw [ i ] ) ) bs . write ( raw [ i ] ) ; } byte [ ] in = bs . toByteArray ( ) ; if ( in . length % 4 != 0 ) { return null ; } bs . reset ( ) ; DataOutputStream ds = new DataOutputStream ( bs ) ; for ( int i = 0 ; i < ( in . length + 3 ) / 4 ; i ++ ) { short [ ] s = new short [ 4 ] ; short [ ] t = new short [ 3 ] ; for ( int j = 0 ; j < 4 ; j ++ ) s [ j ] = ( short ) Base64 . indexOf ( in [ i * 4 + j ] ) ; t [ 0 ] = ( short ) ( ( s [ 0 ] << 2 ) + ( s [ 1 ] >> 4 ) ) ; if ( s [ 2 ] == 64 ) { t [ 1 ] = t [ 2 ] = ( short ) ( - 1 ) ; if ( ( s [ 1 ] & 0xF ) != 0 ) return null ; } else if ( s [ 3 ] == 64 ) { t [ 1 ] = ( short ) ( ( ( s [ 1 ] << 4 ) + ( s [ 2 ] >> 2 ) ) & 0xFF ) ; t [ 2 ] = ( short ) ( - 1 ) ; if ( ( s [ 2 ] & 0x3 ) != 0 ) return null ; } else { t [ 1 ] = ( short ) ( ( ( s [ 1 ] << 4 ) + ( s [ 2 ] >> 2 ) ) & 0xFF ) ; t [ 2 ] = ( short ) ( ( ( s [ 2 ] << 6 ) + s [ 3 ] ) & 0xFF ) ; } try { for ( int j = 0 ; j < 3 ; j ++ ) if ( t [ j ] >= 0 ) ds . writeByte ( t [ j ] ) ; } catch ( IOException e ) { } } return bs . toByteArray ( ) ; }
Convert a base64 - encoded String to binary data
750
public static long parse ( String s , boolean clamp ) { if ( s == null || s . length ( ) == 0 || ! Character . isDigit ( s . charAt ( 0 ) ) ) throw new NumberFormatException ( ) ; long value = 0 ; long ttl = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; long oldvalue = value ; if ( Character . isDigit ( c ) ) { value = ( value * 10 ) + Character . getNumericValue ( c ) ; if ( value < oldvalue ) throw new NumberFormatException ( ) ; } else { switch ( Character . toUpperCase ( c ) ) { case 'W' : value *= 7 ; case 'D' : value *= 24 ; case 'H' : value *= 60 ; case 'M' : value *= 60 ; case 'S' : break ; default : throw new NumberFormatException ( ) ; } ttl += value ; value = 0 ; if ( ttl > 0xFFFFFFFFL ) throw new NumberFormatException ( ) ; } } if ( ttl == 0 ) ttl = value ; if ( ttl > 0xFFFFFFFFL ) throw new NumberFormatException ( ) ; else if ( ttl > MAX_VALUE && clamp ) ttl = MAX_VALUE ; return ttl ; }
Parses a TTL - like value which can either be expressed as a number or a BIND - style string with numbers and units .
751
public static Message newQuery ( Record r ) { Message m = new Message ( ) ; m . header . setOpcode ( Opcode . QUERY ) ; m . header . setFlag ( Flags . RD ) ; m . addRecord ( r , Section . QUESTION ) ; return m ; }
Creates a new Message with a random Message ID suitable for sending as a query .
752
public void addRecord ( Record r , int section ) { if ( sections [ section ] == null ) sections [ section ] = new LinkedList ( ) ; header . incCount ( section ) ; sections [ section ] . add ( r ) ; }
Adds a record to a section of the Message and adjusts the header .
753
public boolean removeRecord ( Record r , int section ) { if ( sections [ section ] != null && sections [ section ] . remove ( r ) ) { header . decCount ( section ) ; return true ; } else return false ; }
Removes a record from a section of the Message and adjusts the header .
754
public boolean findRecord ( Record r , int section ) { return ( sections [ section ] != null && sections [ section ] . contains ( r ) ) ; }
Determines if the given record is already present in the given section .
755
public boolean findRecord ( Record r ) { for ( int i = Section . ANSWER ; i <= Section . ADDITIONAL ; i ++ ) if ( sections [ i ] != null && sections [ i ] . contains ( r ) ) return true ; return false ; }
Determines if the given record is already present in any section .
756
public boolean findRRset ( Name name , int type , int section ) { if ( sections [ section ] == null ) return false ; for ( int i = 0 ; i < sections [ section ] . size ( ) ; i ++ ) { Record r = ( Record ) sections [ section ] . get ( i ) ; if ( r . getType ( ) == type && name . equals ( r . getName ( ) ) ) return true ; } return false ; }
Determines if an RRset with the given name and type is already present in the given section .
757
public boolean findRRset ( Name name , int type ) { return ( findRRset ( name , type , Section . ANSWER ) || findRRset ( name , type , Section . AUTHORITY ) || findRRset ( name , type , Section . ADDITIONAL ) ) ; }
Determines if an RRset with the given name and type is already present in any section .
758
public Record getQuestion ( ) { List l = sections [ Section . QUESTION ] ; if ( l == null || l . size ( ) == 0 ) return null ; return ( Record ) l . get ( 0 ) ; }
Returns the first record in the QUESTION section .
759
public TSIGRecord getTSIG ( ) { int count = header . getCount ( Section . ADDITIONAL ) ; if ( count == 0 ) return null ; List l = sections [ Section . ADDITIONAL ] ; Record rec = ( Record ) l . get ( count - 1 ) ; if ( rec . type != Type . TSIG ) return null ; return ( TSIGRecord ) rec ; }
Returns the TSIG record from the ADDITIONAL section if one is present .
760
public OPTRecord getOPT ( ) { Record [ ] additional = getSectionArray ( Section . ADDITIONAL ) ; for ( int i = 0 ; i < additional . length ; i ++ ) if ( additional [ i ] instanceof OPTRecord ) return ( OPTRecord ) additional [ i ] ; return null ; }
Returns the OPT record from the ADDITIONAL section if one is present .
761
public Record [ ] getSectionArray ( int section ) { if ( sections [ section ] == null ) return emptyRecordArray ; List l = sections [ section ] ; return ( Record [ ] ) l . toArray ( new Record [ l . size ( ) ] ) ; }
Returns an array containing all records in the given section or an empty array if the section is empty .
762
public RRset [ ] getSectionRRsets ( int section ) { if ( sections [ section ] == null ) return emptyRRsetArray ; List sets = new LinkedList ( ) ; Record [ ] recs = getSectionArray ( section ) ; Set hash = new HashSet ( ) ; for ( int i = 0 ; i < recs . length ; i ++ ) { Name name = recs [ i ] . getName ( ) ; boolean newset = true ; if ( hash . contains ( name ) ) { for ( int j = sets . size ( ) - 1 ; j >= 0 ; j -- ) { RRset set = ( RRset ) sets . get ( j ) ; if ( set . getType ( ) == recs [ i ] . getRRsetType ( ) && set . getDClass ( ) == recs [ i ] . getDClass ( ) && set . getName ( ) . equals ( name ) ) { set . addRR ( recs [ i ] ) ; newset = false ; break ; } } } if ( newset ) { RRset set = new RRset ( recs [ i ] ) ; sets . add ( set ) ; hash . add ( name ) ; } } return ( RRset [ ] ) sets . toArray ( new RRset [ sets . size ( ) ] ) ; }
Returns an array containing all records in the given section grouped into RRsets .
763
public byte [ ] toWire ( ) { DNSOutput out = new DNSOutput ( ) ; toWire ( out ) ; size = out . current ( ) ; return out . toByteArray ( ) ; }
Returns an array containing the wire format representation of the Message .
764
public void setTSIG ( TSIG key , int error , TSIGRecord querytsig ) { this . tsigkey = key ; this . tsigerror = error ; this . querytsig = querytsig ; }
Sets the TSIG key and other necessary information to sign a message .
765
public String sectionToString ( int i ) { if ( i > 3 ) return null ; StringBuffer sb = new StringBuffer ( ) ; Record [ ] records = getSectionArray ( i ) ; for ( int j = 0 ; j < records . length ; j ++ ) { Record rec = records [ j ] ; if ( i == Section . QUESTION ) { sb . append ( ";;\t" + rec . name ) ; sb . append ( ", type = " + Type . string ( rec . type ) ) ; sb . append ( ", class = " + DClass . string ( rec . dclass ) ) ; } else sb . append ( rec ) ; sb . append ( "\n" ) ; } return sb . toString ( ) ; }
Converts the given section of the Message to a String .
766
String rrToString ( ) { StringBuffer sb = new StringBuffer ( ) ; Iterator it = strings . iterator ( ) ; while ( it . hasNext ( ) ) { byte [ ] array = ( byte [ ] ) it . next ( ) ; sb . append ( byteArrayToString ( array , true ) ) ; if ( it . hasNext ( ) ) sb . append ( " " ) ; } return sb . toString ( ) ; }
converts to a String
767
public boolean isCurrent ( ) { BasicHandler handler = getBasicHandler ( ) ; return ( handler . axfr == null && handler . ixfr == null ) ; }
Returns true if the response indicates that the zone is up to date . This will be true only if an IXFR was performed .
768
public void apply ( Message m , int error , TSIGRecord old ) { Record r = generate ( m , m . toWire ( ) , error , old ) ; m . addRecord ( r , Section . ADDITIONAL ) ; m . tsigState = Message . TSIG_SIGNED ; }
Generates a TSIG record with a specific error for a message and adds it to the message .
769
public static Integer toInteger ( int val ) { if ( val >= 0 && val < cachedInts . length ) return ( cachedInts [ val ] ) ; return new Integer ( val ) ; }
Converts an int into a possibly cached Integer .
770
public void add ( int val , String str ) { check ( val ) ; Integer value = toInteger ( val ) ; str = sanitize ( str ) ; strings . put ( str , value ) ; values . put ( value , str ) ; }
Defines the text representation of a numeric value .
771
public void addAll ( Mnemonic source ) { if ( wordcase != source . wordcase ) throw new IllegalArgumentException ( source . description + ": wordcases do not match" ) ; strings . putAll ( source . strings ) ; values . putAll ( source . values ) ; }
Copies all mnemonics from one table into another .
772
public String getText ( int val ) { check ( val ) ; String str = ( String ) values . get ( toInteger ( val ) ) ; if ( str != null ) return str ; str = Integer . toString ( val ) ; if ( prefix != null ) return prefix + str ; return str ; }
Gets the text mnemonic corresponding to a numeric value .
773
public int getValue ( String str ) { str = sanitize ( str ) ; Integer value = ( Integer ) strings . get ( str ) ; if ( value != null ) { return value . intValue ( ) ; } if ( prefix != null ) { if ( str . startsWith ( prefix ) ) { int val = parseNumeric ( str . substring ( prefix . length ( ) ) ) ; if ( val >= 0 ) { return val ; } } } if ( numericok ) { return parseNumeric ( str ) ; } return - 1 ; }
Gets the numeric value corresponding to a text mnemonic .
774
String rrToString ( ) { StringBuffer sb = new StringBuffer ( ) ; sb . append ( preference ) ; sb . append ( " " ) ; sb . append ( map822 ) ; sb . append ( " " ) ; sb . append ( mapX400 ) ; return sb . toString ( ) ; }
Converts the PX Record to a String
775
public PublicKey getPublicKey ( ) throws DNSSEC . DNSSECException { if ( publicKey != null ) return publicKey ; publicKey = DNSSEC . toPublicKey ( this ) ; return publicKey ; }
Returns a PublicKey corresponding to the data in this key .
776
public synchronized void addRecord ( Record r , int cred , Object o ) { Name name = r . getName ( ) ; int type = r . getRRsetType ( ) ; if ( ! Type . isRR ( type ) ) return ; Element element = findElement ( name , type , cred ) ; if ( element == null ) { CacheRRset crrset = new CacheRRset ( r , cred , maxcache ) ; addRRset ( crrset , cred ) ; } else if ( element . compareCredibility ( cred ) == 0 ) { if ( element instanceof CacheRRset ) { CacheRRset crrset = ( CacheRRset ) element ; crrset . addRR ( r ) ; } } }
Adds a record to the Cache .
777
public synchronized void addRRset ( RRset rrset , int cred ) { long ttl = rrset . getTTL ( ) ; Name name = rrset . getName ( ) ; int type = rrset . getType ( ) ; Element element = findElement ( name , type , 0 ) ; if ( ttl == 0 ) { if ( element != null && element . compareCredibility ( cred ) <= 0 ) removeElement ( name , type ) ; } else { if ( element != null && element . compareCredibility ( cred ) <= 0 ) element = null ; if ( element == null ) { CacheRRset crrset ; if ( rrset instanceof CacheRRset ) crrset = ( CacheRRset ) rrset ; else crrset = new CacheRRset ( rrset , cred , maxcache ) ; addElement ( name , crrset ) ; } } }
Adds an RRset to the Cache .
778
public synchronized void addNegative ( Name name , int type , SOARecord soa , int cred ) { long ttl = 0 ; if ( soa != null ) ttl = soa . getTTL ( ) ; Element element = findElement ( name , type , 0 ) ; if ( ttl == 0 ) { if ( element != null && element . compareCredibility ( cred ) <= 0 ) removeElement ( name , type ) ; } else { if ( element != null && element . compareCredibility ( cred ) <= 0 ) element = null ; if ( element == null ) addElement ( name , new NegativeElement ( name , type , soa , cred , maxncache ) ) ; } }
Adds a negative entry to the Cache .
779
protected synchronized SetResponse lookup ( Name name , int type , int minCred ) { int labels ; int tlabels ; Element element ; Name tname ; Object types ; SetResponse sr ; labels = name . labels ( ) ; for ( tlabels = labels ; tlabels >= 1 ; tlabels -- ) { boolean isRoot = ( tlabels == 1 ) ; boolean isExact = ( tlabels == labels ) ; if ( isRoot ) tname = Name . root ; else if ( isExact ) tname = name ; else tname = new Name ( name , labels - tlabels ) ; types = data . get ( tname ) ; if ( types == null ) continue ; if ( isExact && type == Type . ANY ) { sr = new SetResponse ( SetResponse . SUCCESSFUL ) ; Element [ ] elements = allElements ( types ) ; int added = 0 ; for ( int i = 0 ; i < elements . length ; i ++ ) { element = elements [ i ] ; if ( element . expired ( ) ) { removeElement ( tname , element . getType ( ) ) ; continue ; } if ( ! ( element instanceof CacheRRset ) ) continue ; if ( element . compareCredibility ( minCred ) < 0 ) continue ; sr . addRRset ( ( CacheRRset ) element ) ; added ++ ; } if ( added > 0 ) return sr ; } else if ( isExact ) { element = oneElement ( tname , types , type , minCred ) ; if ( element != null && element instanceof CacheRRset ) { sr = new SetResponse ( SetResponse . SUCCESSFUL ) ; sr . addRRset ( ( CacheRRset ) element ) ; return sr ; } else if ( element != null ) { sr = new SetResponse ( SetResponse . NXRRSET ) ; return sr ; } element = oneElement ( tname , types , Type . CNAME , minCred ) ; if ( element != null && element instanceof CacheRRset ) { return new SetResponse ( SetResponse . CNAME , ( CacheRRset ) element ) ; } } else { element = oneElement ( tname , types , Type . DNAME , minCred ) ; if ( element != null && element instanceof CacheRRset ) { return new SetResponse ( SetResponse . DNAME , ( CacheRRset ) element ) ; } } element = oneElement ( tname , types , Type . NS , minCred ) ; if ( element != null && element instanceof CacheRRset ) return new SetResponse ( SetResponse . DELEGATION , ( CacheRRset ) element ) ; if ( isExact ) { element = oneElement ( tname , types , 0 , minCred ) ; if ( element != null ) return SetResponse . ofType ( SetResponse . NXDOMAIN ) ; } } return SetResponse . ofType ( SetResponse . UNKNOWN ) ; }
Finds all matching sets or something that causes the lookup to stop .
780
public SetResponse lookupRecords ( Name name , int type , int minCred ) { return lookup ( name , type , minCred ) ; }
Looks up Records in the Cache . This follows CNAMEs and handles negatively cached data .
781
public String getString ( ) throws IOException { Token next = get ( ) ; if ( ! next . isString ( ) ) { throw exception ( "expected a string" ) ; } return next . value ; }
Gets the next token from a tokenizer and converts it to a string .
782
public long getLong ( ) throws IOException { String next = _getIdentifier ( "an integer" ) ; if ( ! Character . isDigit ( next . charAt ( 0 ) ) ) throw exception ( "expected an integer" ) ; try { return Long . parseLong ( next ) ; } catch ( NumberFormatException e ) { throw exception ( "expected an integer" ) ; } }
Gets the next token from a tokenizer and converts it to a long .
783
public long getTTL ( ) throws IOException { String next = _getIdentifier ( "a TTL value" ) ; try { return TTL . parseTTL ( next ) ; } catch ( NumberFormatException e ) { throw exception ( "expected a TTL value" ) ; } }
Gets the next token from a tokenizer and parses it as a TTL .
784
public long getTTLLike ( ) throws IOException { String next = _getIdentifier ( "a TTL-like value" ) ; try { return TTL . parse ( next , false ) ; } catch ( NumberFormatException e ) { throw exception ( "expected a TTL-like value" ) ; } }
Gets the next token from a tokenizer and parses it as if it were a TTL .
785
public Name getName ( Name origin ) throws IOException { String next = _getIdentifier ( "a name" ) ; try { Name name = Name . fromString ( next , origin ) ; if ( ! name . isAbsolute ( ) ) throw new RelativeNameException ( name ) ; return name ; } catch ( TextParseException e ) { throw exception ( e . getMessage ( ) ) ; } }
Gets the next token from a tokenizer and converts it to a name .
786
public byte [ ] getAddressBytes ( int family ) throws IOException { String next = _getIdentifier ( "an address" ) ; byte [ ] bytes = Address . toByteArray ( next , family ) ; if ( bytes == null ) throw exception ( "Invalid address: " + next ) ; return bytes ; }
Gets the next token from a tokenizer and converts it to a byte array containing an IP address .
787
public InetAddress getAddress ( int family ) throws IOException { String next = _getIdentifier ( "an address" ) ; try { return Address . getByAddress ( next , family ) ; } catch ( UnknownHostException e ) { throw exception ( e . getMessage ( ) ) ; } }
Gets the next token from a tokenizer and converts it to an IP Address .
788
public void getEOL ( ) throws IOException { Token next = get ( ) ; if ( next . type != EOL && next . type != EOF ) { throw exception ( "expected EOL or EOF" ) ; } }
Gets the next token from a tokenizer which must be an EOL or EOF .
789
private String remainingStrings ( ) throws IOException { StringBuffer buffer = null ; while ( true ) { Tokenizer . Token t = get ( ) ; if ( ! t . isString ( ) ) break ; if ( buffer == null ) buffer = new StringBuffer ( ) ; buffer . append ( t . value ) ; } unget ( ) ; if ( buffer == null ) return null ; return buffer . toString ( ) ; }
Returns a concatenation of the remaining strings from a Tokenizer .
790
public byte [ ] getHexString ( ) throws IOException { String next = _getIdentifier ( "a hex string" ) ; byte [ ] array = base16 . fromString ( next ) ; if ( array == null ) throw exception ( "invalid hex encoding" ) ; return array ; }
Gets the next token from a tokenizer and decodes it as hex .
791
public byte [ ] getBase32String ( base32 b32 ) throws IOException { String next = _getIdentifier ( "a base32 string" ) ; byte [ ] array = b32 . fromString ( next ) ; if ( array == null ) throw exception ( "invalid base32 encoding" ) ; return array ; }
Gets the next token from a tokenizer and decodes it as base32 .
792
public static int compare ( long serial1 , long serial2 ) { if ( serial1 < 0 || serial1 > MAX32 ) throw new IllegalArgumentException ( serial1 + " out of range" ) ; if ( serial2 < 0 || serial2 > MAX32 ) throw new IllegalArgumentException ( serial2 + " out of range" ) ; long diff = serial1 - serial2 ; if ( diff >= MAX32 ) diff -= ( MAX32 + 1 ) ; else if ( diff < - MAX32 ) diff += ( MAX32 + 1 ) ; return ( int ) diff ; }
Compares two numbers using serial arithmetic . The numbers are assumed to be 32 bit unsigned integers stored in longs .
793
public static long increment ( long serial ) { if ( serial < 0 || serial > MAX32 ) throw new IllegalArgumentException ( serial + " out of range" ) ; if ( serial == MAX32 ) return 0 ; return serial + 1 ; }
Increments a serial number . The number is assumed to be a 32 bit unsigned integer stored in a long . This basically adds 1 and resets the value to 0 if it is 2^32 .
794
public Message send ( Message query ) throws IOException { if ( Options . check ( "verbose" ) ) System . err . println ( "Sending to " + address . getAddress ( ) . getHostAddress ( ) + ":" + address . getPort ( ) ) ; if ( query . getHeader ( ) . getOpcode ( ) == Opcode . QUERY ) { Record question = query . getQuestion ( ) ; if ( question != null && question . getType ( ) == Type . AXFR ) return sendAXFR ( query ) ; } query = ( Message ) query . clone ( ) ; applyEDNS ( query ) ; if ( tsig != null ) tsig . apply ( query , null ) ; byte [ ] out = query . toWire ( Message . MAXLENGTH ) ; int udpSize = maxUDPSize ( query ) ; boolean tcp = false ; long endTime = System . currentTimeMillis ( ) + timeoutValue ; do { byte [ ] in ; if ( useTCP || out . length > udpSize ) tcp = true ; if ( tcp ) in = TCPClient . sendrecv ( localAddress , address , out , endTime ) ; else in = UDPClient . sendrecv ( localAddress , address , out , udpSize , endTime ) ; if ( in . length < Header . LENGTH ) { throw new WireParseException ( "invalid DNS header - " + "too short" ) ; } int id = ( ( in [ 0 ] & 0xFF ) << 8 ) + ( in [ 1 ] & 0xFF ) ; int qid = query . getHeader ( ) . getID ( ) ; if ( id != qid ) { String error = "invalid message id: expected " + qid + "; got id " + id ; if ( tcp ) { throw new WireParseException ( error ) ; } else { if ( Options . check ( "verbose" ) ) { System . err . println ( error ) ; } continue ; } } Message response = parseMessage ( in ) ; verifyTSIG ( query , response , in , tsig ) ; if ( ! tcp && ! ignoreTruncation && response . getHeader ( ) . getFlag ( Flags . TC ) ) { tcp = true ; continue ; } return response ; } while ( true ) ; }
Sends a message to a single server and waits for a response . No checking is done to ensure that the response is associated with the query .
795
public Object sendAsync ( final Message query , final ResolverListener listener ) { final Object id ; synchronized ( this ) { id = new Integer ( uniqueID ++ ) ; } Record question = query . getQuestion ( ) ; String qname ; if ( question != null ) qname = question . getName ( ) . toString ( ) ; else qname = "(none)" ; String name = this . getClass ( ) + ": " + qname ; Thread thread = new ResolveThread ( this , query , id , listener ) ; thread . setName ( name ) ; thread . setDaemon ( true ) ; thread . start ( ) ; return id ; }
Asynchronously sends a message to a single server registering a listener to receive a callback on success or exception . Multiple asynchronous lookups can be performed in parallel . Since the callback may be invoked before the function returns external synchronization is necessary .
796
public static void set ( String option ) { if ( table == null ) table = new HashMap ( ) ; table . put ( option . toLowerCase ( ) , "true" ) ; }
Sets an option to true
797
public static boolean check ( String option ) { if ( table == null ) return false ; return ( table . get ( option . toLowerCase ( ) ) != null ) ; }
Checks if an option is defined
798
public static String value ( String option ) { if ( table == null ) return null ; return ( ( String ) table . get ( option . toLowerCase ( ) ) ) ; }
Returns the value of an option
799
public static int intValue ( String option ) { String s = value ( option ) ; if ( s != null ) { try { int val = Integer . parseInt ( s ) ; if ( val > 0 ) return ( val ) ; } catch ( NumberFormatException e ) { } } return ( - 1 ) ; }
Returns the value of an option as an integer or - 1 if not defined .