idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
5,700
protected void checkTransitions ( StreamTokenizer streamTokenizer ) throws FSMParseException { if ( getStates ( ) . isEmpty ( ) ) { getStates ( ) . addAll ( transitionsFSM . keySet ( ) ) ; } final Set < Integer > newStates = new HashSet < > ( getStates ( ) ) ; final Integer initialState = getStates ( ) . iterator ( ) . next ( ) ; makeTransitions ( initialState , null , newStates , 0 , output != null ? new WordBuilder < > ( ) : null , streamTokenizer ) ; if ( ! newStates . isEmpty ( ) ) { throw new FSMParseException ( String . format ( PARTIAL_FSM , newStates , initialState ) , streamTokenizer ) ; } }
Creates the actual Mealy machine transitions .
5,701
public static int invokeProcess ( String [ ] commandLine , Reader input ) throws IOException , InterruptedException { return invokeProcess ( commandLine , input , new NOPConsumer ( ) ) ; }
Runs the given set of command line arguments as a system process and returns the exit value of the spawned process . Additionally allows to supply an input stream to the invoked program . Discards any output of the process .
5,702
protected void removeEntry ( T entry ) { T prev = entry . getPrev ( ) ; T next = entry . getNext ( ) ; if ( prev != null ) { prev . setNext ( next ) ; } else { head = next ; } if ( next != null ) { next . setPrev ( prev ) ; } else { last = prev ; } size -- ; }
Removes an entry from the list .
5,703
protected void replaceEntry ( T oldEntry , T newEntry ) { T prev = oldEntry . getPrev ( ) ; T next = newEntry . getNext ( ) ; if ( prev != null ) { prev . setNext ( newEntry ) ; } else { head = newEntry ; } if ( next != null ) { next . setPrev ( newEntry ) ; } else { last = newEntry ; } }
Replaces an entry in the list .
5,704
protected void pushBackEntry ( T e ) { e . setNext ( null ) ; e . setPrev ( last ) ; if ( last != null ) { last . setNext ( e ) ; } else { head = e ; } last = e ; size ++ ; }
Adds an entry at the end of the list .
5,705
public ElementReference pushBack ( E element ) { T entry = makeEntry ( element ) ; pushBackEntry ( entry ) ; return entry ; }
Adds an element at the end of the list .
5,706
public ElementReference pushFront ( E element ) { T entry = makeEntry ( element ) ; pushFrontEntry ( entry ) ; return entry ; }
Adds an element at the beginning of the list .
5,707
protected void pushFrontEntry ( T e ) { e . setPrev ( null ) ; e . setNext ( head ) ; if ( head != null ) { head . setPrev ( e ) ; } else { last = e ; } head = e ; size ++ ; }
Adds an entry at the beginning of the list .
5,708
public void swap ( AbstractLinkedList < E , T > other ) { int sizeTmp = this . size ; T headTmp = this . head ; T lastTmp = this . last ; this . size = other . size ; this . head = other . head ; this . last = other . last ; other . size = sizeTmp ; other . head = headTmp ; other . last = lastTmp ; }
Swaps the contents of two linked lists with the same entry types . This method runs in constant time .
5,709
void addState ( State < S , L > state ) { ElementReference ref = states . referencedAdd ( state ) ; state . setBlockReference ( ref ) ; state . setBlock ( this ) ; }
Adds a state to this block .
5,710
boolean addToBucket ( State < S , L > state ) { boolean first = bucket . isEmpty ( ) ; bucket . pushBack ( state ) ; return first ; }
Adds a state to this blocks bucket .
5,711
void addToSubBlock ( State < S , L > state ) { if ( currSubBlock == null ) { throw new IllegalStateException ( "No current sub block" ) ; } currSubBlock . referencedAdd ( state ) ; elementsInSubBlocks ++ ; }
Adds a state to the current sub block .
5,712
private void purge ( State state ) { StateSignature sig = state . getSignature ( ) ; if ( sig == null ) { return ; } if ( state . getAcceptance ( ) == Acceptance . TRUE ) { throw new IllegalStateException ( "Attempting to purge accepting state" ) ; } if ( register . remove ( sig ) == null ) { return ; } sig . acceptance = Acceptance . FALSE ; for ( int i = 0 ; i < alphabetSize ; i ++ ) { State succ = sig . successors . array [ i ] ; if ( succ != null ) { purge ( succ ) ; } } }
Removes a state and all of its successors from the register .
5,713
public boolean union ( int x , int y ) { int rx = x ; int ry = y ; int px = p [ rx ] ; int py = p [ ry ] ; while ( px != py ) { if ( px < py ) { if ( rx == px ) { p [ rx ] = py ; return true ; } p [ rx ] = py ; rx = px ; px = p [ rx ] ; } else { if ( ry == py ) { p [ ry ] = px ; return true ; } p [ ry ] = px ; ry = py ; py = p [ ry ] ; } } return false ; }
Unites the sets containing the two given elements .
5,714
private void remove ( int index ) { int lastIndex = -- size ; Reference < E > removed = storage . array [ index ] ; Reference < E > lastElem = storage . array [ lastIndex ] ; storage . array [ index ] = lastElem ; lastElem . index = index ; removed . index = - 1 ; storage . array [ lastIndex ] = null ; }
Removes an element by its index .
5,715
private int extractValidIndex ( ElementReference ref ) { Reference < E > iRef = asIndexedRef ( ref ) ; int idx = iRef . index ; if ( idx < 0 || idx >= size ) { throw new InvalidReferenceException ( "Index " + idx + " is not valid for collection with size " + size + "." ) ; } return idx ; }
Convenience method for extracting the index stored in an ElementReference and throws a more specific exception if the cast fails or the index is not valid .
5,716
public String readUTF ( DataInput input , int len ) throws IOException { StaticBuffers staticBuffers = StaticBuffers . getInstance ( ) ; ByteBuffer utf8buf = staticBuffers . byteBuffer ( UTF8_BUFFER , 1024 * 8 ) ; byte [ ] rawUtf8Buf = utf8buf . array ( ) ; CharsetDecoder dec = getUTF8Decoder ( ) ; int expectedLen = ( len > 0 ? ( int ) ( dec . averageCharsPerByte ( ) * len ) + 1 : 1024 ) ; CharBuffer cb = staticBuffers . charBuffer ( UTF8_BUFFER , expectedLen ) ; try { while ( len != 0 || utf8buf . position ( ) > 0 ) { if ( len < 0 ) { while ( utf8buf . remaining ( ) > 0 ) { byte b = input . readByte ( ) ; if ( b == 0 ) { len = 0 ; break ; } utf8buf . put ( b ) ; } utf8buf . flip ( ) ; } else if ( len > 0 ) { int r = Math . min ( len , utf8buf . remaining ( ) ) ; input . readFully ( rawUtf8Buf , utf8buf . position ( ) , r ) ; len -= r ; utf8buf . limit ( utf8buf . position ( ) + r ) ; utf8buf . rewind ( ) ; } else { utf8buf . flip ( ) ; } CoderResult cr = dec . decode ( utf8buf , cb , len == 0 ) ; if ( cr . isUnderflow ( ) ) { utf8buf . compact ( ) ; } else if ( cr . isOverflow ( ) ) { utf8buf . compact ( ) ; CharBuffer newBuf = staticBuffers . charBuffer ( UTF8_BUFFER , cb . capacity ( ) + 1024 ) ; cb . flip ( ) ; newBuf . put ( cb ) ; cb = newBuf ; } else if ( cr . isError ( ) ) { cr . throwException ( ) ; } } } finally { dec . flush ( cb ) ; dec . reset ( ) ; staticBuffers . releaseCharBuffer ( UTF8_BUFFER , cb ) ; staticBuffers . releaseByteBuffer ( UTF8_BUFFER , utf8buf ) ; } cb . flip ( ) ; return cb . toString ( ) ; }
Reads a modified UTF - 8 string from a DataInput object
5,717
protected static byte [ ] uuidToLittleEndianBytes ( UUID uuid ) { long msb = uuid . getMostSignificantBits ( ) ; long lsb = uuid . getLeastSignificantBits ( ) ; byte [ ] buffer = new byte [ 16 ] ; for ( int i = 0 ; i < 8 ; i ++ ) { buffer [ i ] = ( byte ) ( msb >>> 8 * i ) ; } for ( int i = 8 ; i < 16 ; i ++ ) { buffer [ i ] = ( byte ) ( lsb >>> 8 * ( i - 16 ) ) ; } return buffer ; }
Utility routine for converting UUIDs to bytes in little endian format .
5,718
protected ByteBuffer allocateBuffer ( ) { if ( _buffersToReuse != null && ! _buffersToReuse . isEmpty ( ) ) { ByteBuffer bb = _buffersToReuse . poll ( ) ; bb . rewind ( ) ; bb . limit ( bb . capacity ( ) ) ; return bb ; } ByteBuffer r = StaticBuffers . getInstance ( ) . byteBuffer ( BUFFER_KEY , _bufferSize ) ; r . limit ( _bufferSize ) ; return r . order ( _order ) ; }
Allocates a new buffer or attempts to reuse an existing one .
5,719
protected void deallocateBuffer ( int n ) { ByteBuffer bb = _buffers . set ( n , null ) ; if ( bb != null && _reuseBuffersCount > 0 ) { if ( _buffersToReuse == null ) { _buffersToReuse = new LinkedList < ByteBuffer > ( ) ; } if ( _reuseBuffersCount > _buffersToReuse . size ( ) ) { _buffersToReuse . add ( bb ) ; } } }
Removes a buffer from the list of internal buffers and saves it for reuse if this feature is enabled .
5,720
protected ByteBuffer getBuffer ( int position ) { int n = position / _bufferSize ; while ( n >= _buffers . size ( ) ) { addNewBuffer ( ) ; } return _buffers . get ( n ) ; }
Gets the buffer that holds the byte at the given absolute position . Automatically adds new internal buffers if the position lies outside the current range of all internal buffers .
5,721
public void clear ( ) { if ( _buffersToReuse != null && ! _buffersToReuse . isEmpty ( ) ) { StaticBuffers . getInstance ( ) . releaseByteBuffer ( BUFFER_KEY , _buffersToReuse . peek ( ) ) ; } else if ( ! _buffers . isEmpty ( ) ) { StaticBuffers . getInstance ( ) . releaseByteBuffer ( BUFFER_KEY , _buffers . get ( 0 ) ) ; } if ( _buffersToReuse != null ) { _buffersToReuse . clear ( ) ; } _buffers . clear ( ) ; _position = 0 ; _flushPosition = 0 ; _size = 0 ; }
Clear the buffer and reset size and write position
5,722
public void putByte ( int pos , byte b ) { adaptSize ( pos + 1 ) ; ByteBuffer bb = getBuffer ( pos ) ; int i = pos % _bufferSize ; bb . put ( i , b ) ; }
Puts a byte into the buffer at the given position . Does not increase the write position .
5,723
public void putBytes ( int pos , byte ... bs ) { adaptSize ( pos + bs . length ) ; ByteBuffer bb = null ; int i = _bufferSize ; for ( byte b : bs ) { if ( i == _bufferSize ) { bb = getBuffer ( pos ) ; i = pos % _bufferSize ; } bb . put ( i , b ) ; ++ i ; ++ pos ; } }
Puts several bytes into the buffer at the given position . Does not increase the write position .
5,724
public void putInt ( int pos , int i ) { adaptSize ( pos + 4 ) ; ByteBuffer bb = getBuffer ( pos ) ; int index = pos % _bufferSize ; if ( bb . limit ( ) - index >= 4 ) { bb . putInt ( index , i ) ; } else { byte b0 = ( byte ) i ; byte b1 = ( byte ) ( i >> 8 ) ; byte b2 = ( byte ) ( i >> 16 ) ; byte b3 = ( byte ) ( i >> 24 ) ; if ( _order == ByteOrder . BIG_ENDIAN ) { putBytes ( pos , b3 , b2 , b1 , b0 ) ; } else { putBytes ( pos , b0 , b1 , b2 , b3 ) ; } } }
Puts a 32 - bit integer into the buffer at the given position . Does not increase the write position .
5,725
public void putLong ( int pos , long l ) { adaptSize ( pos + 8 ) ; ByteBuffer bb = getBuffer ( pos ) ; int index = pos % _bufferSize ; if ( bb . limit ( ) - index >= 8 ) { bb . putLong ( index , l ) ; } else { byte b0 = ( byte ) l ; byte b1 = ( byte ) ( l >> 8 ) ; byte b2 = ( byte ) ( l >> 16 ) ; byte b3 = ( byte ) ( l >> 24 ) ; byte b4 = ( byte ) ( l >> 32 ) ; byte b5 = ( byte ) ( l >> 40 ) ; byte b6 = ( byte ) ( l >> 48 ) ; byte b7 = ( byte ) ( l >> 56 ) ; if ( _order == ByteOrder . BIG_ENDIAN ) { putBytes ( pos , b7 , b6 , b5 , b4 , b3 , b2 , b1 , b0 ) ; } else { putBytes ( pos , b0 , b1 , b2 , b3 , b4 , b5 , b6 , b7 ) ; } } }
Puts a 64 - bit integer into the buffer at the given position . Does not increase the write position .
5,726
public void putString ( int pos , CharSequence s ) { for ( int i = 0 ; i < s . length ( ) ; ++ i ) { char c = s . charAt ( i ) ; byte b0 = ( byte ) c ; byte b1 = ( byte ) ( c >> 8 ) ; if ( _order == ByteOrder . BIG_ENDIAN ) { putBytes ( pos , b1 , b0 ) ; } else { putBytes ( pos , b0 , b1 ) ; } pos += 2 ; } }
Puts a character sequence into the buffer at the given position . Does not increase the write position .
5,727
public int putUTF8 ( String s ) { int written = putUTF8 ( _position , s ) ; _position += written ; return written ; }
Encodes the given string as UTF - 8 puts it into the buffer and increases the write position accordingly .
5,728
public int putUTF8 ( int pos , String s ) { ByteBuffer minibb = null ; CharsetEncoder enc = getUTF8Encoder ( ) ; CharBuffer in = CharBuffer . wrap ( s ) ; int pos2 = pos ; ByteBuffer bb = getBuffer ( pos2 ) ; int index = pos2 % _bufferSize ; bb . position ( index ) ; while ( in . remaining ( ) > 0 ) { CoderResult res = enc . encode ( in , bb , true ) ; if ( bb == minibb ) { bb . flip ( ) ; while ( bb . remaining ( ) > 0 ) { putByte ( pos2 , bb . get ( ) ) ; ++ pos2 ; } } else { pos2 += bb . position ( ) - index ; } if ( res . isOverflow ( ) ) { if ( bb . remaining ( ) > 0 ) { if ( minibb == null ) { minibb = ByteBuffer . allocate ( 4 ) ; } minibb . clear ( ) ; bb = minibb ; index = 0 ; } else { bb = getBuffer ( pos2 ) ; index = pos2 % _bufferSize ; bb . position ( index ) ; } } else if ( res . isError ( ) ) { try { res . throwException ( ) ; } catch ( CharacterCodingException e ) { throw new RuntimeException ( "Could not encode string" , e ) ; } } } adaptSize ( pos2 ) ; return pos2 - pos ; }
Puts the given string as UTF - 8 into the buffer at the given position . This method does not increase the write position .
5,729
public void flushTo ( WritableByteChannel out ) throws IOException { int n1 = _flushPosition / _bufferSize ; int n2 = _position / _bufferSize ; while ( n1 < n2 ) { ByteBuffer bb = _buffers . get ( n1 ) ; bb . rewind ( ) ; out . write ( bb ) ; deallocateBuffer ( n1 ) ; _flushPosition += _bufferSize ; ++ n1 ; } }
Tries to copy as much bytes as possible from this buffer to the given channel . This method always copies whole internal buffers and deallocates them afterwards . It does not deallocate the buffer the write position is currently pointing to nor does it deallocate buffers following the write position . The method increases an internal pointer so consecutive calls also copy consecutive bytes .
5,730
protected JsonToken handleNewDocument ( boolean array ) throws IOException { if ( _in == null ) { byte [ ] buf = new byte [ Integer . SIZE / Byte . SIZE ] ; int len = 0 ; while ( len < buf . length ) { int l = _rawInputStream . read ( buf , len , buf . length - len ) ; if ( l == - 1 ) { throw new IOException ( "Not enough bytes for length of document" ) ; } len += l ; } int documentLength = ByteBuffer . wrap ( buf ) . order ( ByteOrder . LITTLE_ENDIAN ) . getInt ( ) ; InputStream in = new BoundedInputStream ( _rawInputStream , documentLength - buf . length ) ; if ( ! ( _rawInputStream instanceof BufferedInputStream ) ) { in = new StaticBufferedInputStream ( in ) ; } _counter = new CountingInputStream ( in ) ; _in = new LittleEndianInputStream ( _counter ) ; } else { _in . readInt ( ) ; } _currentContext = new Context ( _currentContext , array ) ; return array ? JsonToken . START_ARRAY : JsonToken . START_OBJECT ; }
Can be called when a new embedded document is found . Reads the document s header and creates a new context on the stack .
5,731
protected JsonToken handleBinary ( ) throws IOException { int size = _in . readInt ( ) ; byte subtype = _in . readByte ( ) ; Context ctx = getContext ( ) ; switch ( subtype ) { case BsonConstants . SUBTYPE_BINARY_OLD : int size2 = _in . readInt ( ) ; byte [ ] buf2 = new byte [ size2 ] ; _in . readFully ( buf2 ) ; ctx . value = buf2 ; break ; case BsonConstants . SUBTYPE_UUID : long l1 = _in . readLong ( ) ; long l2 = _in . readLong ( ) ; ctx . value = new UUID ( l1 , l2 ) ; break ; default : byte [ ] buf = new byte [ size ] ; _in . readFully ( buf ) ; ctx . value = buf ; break ; } return JsonToken . VALUE_EMBEDDED_OBJECT ; }
Reads binary data from the input stream
5,732
protected JsonToken handleRegEx ( ) throws IOException { String regex = readCString ( ) ; String pattern = readCString ( ) ; getContext ( ) . value = Pattern . compile ( regex , regexStrToFlags ( pattern ) ) ; return JsonToken . VALUE_EMBEDDED_OBJECT ; }
Reads and compiles a regular expression
5,733
protected JsonToken handleDBPointer ( ) throws IOException { Map < String , Object > pointer = new LinkedHashMap < String , Object > ( ) ; pointer . put ( "$ns" , readString ( ) ) ; pointer . put ( "$id" , readObjectId ( ) ) ; getContext ( ) . value = pointer ; return JsonToken . VALUE_EMBEDDED_OBJECT ; }
Reads a DBPointer from the stream
5,734
protected JsonToken handleJavascriptWithScope ( ) throws IOException { _in . readInt ( ) ; String code = readString ( ) ; Map < String , Object > doc = readDocument ( ) ; getContext ( ) . value = new JavaScript ( code , doc ) ; return JsonToken . VALUE_EMBEDDED_OBJECT ; }
Can be called when embedded javascript code with scope is found . Reads the code and the embedded document .
5,735
protected Timestamp readTimestamp ( ) throws IOException { int inc = _in . readInt ( ) ; int time = _in . readInt ( ) ; return new Timestamp ( time , inc ) ; }
Reads a timestamp object from the input stream
5,736
protected ObjectId readObjectId ( ) throws IOException { int time = ByteOrderUtil . flip ( _in . readInt ( ) ) ; int machine = ByteOrderUtil . flip ( _in . readInt ( ) ) ; int inc = ByteOrderUtil . flip ( _in . readInt ( ) ) ; return new ObjectId ( time , machine , inc ) ; }
Reads a ObjectID from the input stream
5,737
protected Map < String , Object > readDocument ( ) throws IOException { ObjectCodec codec = getCodec ( ) ; if ( codec == null ) { throw new IllegalStateException ( "Could not parse embedded document " + "because BSON parser has no codec" ) ; } _currToken = handleNewDocument ( false ) ; return codec . readValue ( this , new TypeReference < Map < String , Object > > ( ) { } ) ; }
Fully reads an embedded document reusing this parser
5,738
protected void _writeStartObject ( boolean array ) throws IOException { _writeArrayFieldNameIfNeeded ( ) ; if ( _currentDocument != null ) { _buffer . putByte ( _typeMarker , array ? BsonConstants . TYPE_ARRAY : BsonConstants . TYPE_DOCUMENT ) ; } _currentDocument = new DocumentInfo ( _currentDocument , _buffer . size ( ) , array ) ; reserveHeader ( ) ; }
Creates a new embedded document or array
5,739
public void writeDateTime ( Date date ) throws IOException { _writeArrayFieldNameIfNeeded ( ) ; _verifyValueWrite ( "write datetime" ) ; _buffer . putByte ( _typeMarker , BsonConstants . TYPE_DATETIME ) ; _buffer . putLong ( date . getTime ( ) ) ; flushBuffer ( ) ; }
Write a BSON date time
5,740
public void writeObjectId ( ObjectId objectId ) throws IOException { _writeArrayFieldNameIfNeeded ( ) ; _verifyValueWrite ( "write datetime" ) ; _buffer . putByte ( _typeMarker , BsonConstants . TYPE_OBJECTID ) ; int time = ByteOrderUtil . flip ( objectId . getTime ( ) ) ; int machine = ByteOrderUtil . flip ( objectId . getMachine ( ) ) ; int inc = ByteOrderUtil . flip ( objectId . getInc ( ) ) ; _buffer . putInt ( time ) ; _buffer . putInt ( machine ) ; _buffer . putInt ( inc ) ; flushBuffer ( ) ; }
Write a BSON ObjectId
5,741
protected String flagsToRegexOptions ( int flags ) { StringBuilder options = new StringBuilder ( ) ; if ( ( flags & Pattern . CASE_INSENSITIVE ) != 0 ) { options . append ( "i" ) ; } if ( ( flags & Pattern . MULTILINE ) != 0 ) { options . append ( "m" ) ; } if ( ( flags & Pattern . DOTALL ) != 0 ) { options . append ( "s" ) ; } if ( ( flags & Pattern . UNICODE_CASE ) != 0 ) { options . append ( "u" ) ; } return options . toString ( ) ; }
Converts a a Java flags word into a BSON options pattern
5,742
public void writeRegex ( Pattern pattern ) throws IOException { _writeArrayFieldNameIfNeeded ( ) ; _verifyValueWrite ( "write regex" ) ; _buffer . putByte ( _typeMarker , BsonConstants . TYPE_REGEX ) ; _writeCString ( pattern . pattern ( ) ) ; _writeCString ( flagsToRegexOptions ( pattern . flags ( ) ) ) ; flushBuffer ( ) ; }
Write a BSON regex
5,743
public void writeTimestamp ( Timestamp timestamp ) throws IOException { _writeArrayFieldNameIfNeeded ( ) ; _verifyValueWrite ( "write timestamp" ) ; _buffer . putByte ( _typeMarker , BsonConstants . TYPE_TIMESTAMP ) ; _buffer . putInt ( timestamp . getInc ( ) ) ; _buffer . putInt ( timestamp . getTime ( ) ) ; flushBuffer ( ) ; }
Write a MongoDB timestamp
5,744
public void writeJavaScript ( JavaScript javaScript , SerializerProvider provider ) throws IOException { _writeArrayFieldNameIfNeeded ( ) ; _verifyValueWrite ( "write javascript" ) ; if ( javaScript . getScope ( ) == null ) { _buffer . putByte ( _typeMarker , BsonConstants . TYPE_JAVASCRIPT ) ; _writeString ( javaScript . getCode ( ) ) ; } else { _buffer . putByte ( _typeMarker , BsonConstants . TYPE_JAVASCRIPT_WITH_SCOPE ) ; int p = _buffer . size ( ) ; _buffer . putInt ( 0 ) ; _writeString ( javaScript . getCode ( ) ) ; nextObjectIsEmbeddedInValue = true ; provider . findValueSerializer ( Map . class , null ) . serialize ( javaScript . getScope ( ) , this , provider ) ; if ( ! isEnabled ( Feature . ENABLE_STREAMING ) ) { int l = _buffer . size ( ) - p ; _buffer . putInt ( p , l ) ; } } flushBuffer ( ) ; }
Write a BSON JavaScript object
5,745
public void writeSymbol ( Symbol symbol ) throws IOException { _writeArrayFieldNameIfNeeded ( ) ; _verifyValueWrite ( "write symbol" ) ; _buffer . putByte ( _typeMarker , BsonConstants . TYPE_SYMBOL ) ; _writeString ( symbol . getSymbol ( ) ) ; flushBuffer ( ) ; }
Write a BSON Symbol object
5,746
public static int flip ( int i ) { int result = 0 ; result |= ( i & 0xFF ) << 24 ; result |= ( i & 0xFF00 ) << 8 ; result |= ( ( i & 0xFF0000 ) >> 8 ) & 0xFF00 ; result |= ( ( i & 0xFF000000 ) >> 24 ) & 0xFF ; return result ; }
Flips the byte order of an integer
5,747
protected void parseTemplateString ( ) throws MalformedUriTemplateException { final String templateString = getTemplate ( ) ; final UriTemplateParser scanner = new UriTemplateParser ( ) ; this . components = scanner . scan ( templateString ) ; initExpressions ( ) ; }
Parse the URI template string into the template model .
5,748
private void initExpressions ( ) { expressions = new LinkedList < > ( ) ; for ( UriTemplateComponent c : components ) { if ( c instanceof Expression ) { expressions . add ( ( Expression ) c ) ; } } }
Initializes the collection of expressions in the template .
5,749
public String expand ( Map < String , Object > vars ) throws VariableExpansionException { this . values = vars ; return expand ( ) ; }
Expand the URI template using the supplied values
5,750
public String expand ( ) throws VariableExpansionException { String template = getTemplate ( ) ; for ( Expression expression : expressions ) { final String replacement = expressionReplacementString ( expression , false ) ; template = template . replaceAll ( expression . getReplacementPattern ( ) , replacement ) ; } return template ; }
Applies variable substitution the URI Template and returns the expanded URI .
5,751
public UriTemplate set ( String variableName , Object value ) { values . put ( variableName , value ) ; return this ; }
Sets a value on the URI template expression variable .
5,752
private boolean hasExpressionWithOperator ( Operator op ) { for ( UriTemplateComponent c : components ) { if ( Expression . class . isInstance ( c ) ) { Expression e = ( Expression ) c ; if ( e . getOperator ( ) == op ) { return true ; } } } return false ; }
Scans the components for an expression with the specified operator .
5,753
private void initValues ( ) throws VarExploderException { Class < ? > c = source . getClass ( ) ; if ( c . isAnnotation ( ) || c . isArray ( ) || c . isEnum ( ) || c . isPrimitive ( ) ) { throw new IllegalArgumentException ( "The value must an object" ) ; } if ( source instanceof Map ) { this . pairs = ( Map < String , Object > ) source ; return ; } Method [ ] methods = c . getMethods ( ) ; for ( Method method : methods ) { inspectGetters ( method ) ; } scanFields ( c ) ; }
Initializes the values from the object properties and constructs a map from those values .
5,754
private void inspectGetters ( Method method ) { String methodName = method . getName ( ) ; int prefixLength = 0 ; if ( methodName . startsWith ( GET_PREFIX ) ) { prefixLength = GET_PREFIX . length ( ) ; } if ( methodName . startsWith ( IS_PREIX ) ) { prefixLength = IS_PREIX . length ( ) ; } if ( prefixLength == 0 ) { return ; } String name = decapitalize ( methodName . substring ( prefixLength ) ) ; if ( ! isValidProperty ( name ) ) { return ; } Class propertyType = method . getReturnType ( ) ; if ( propertyType == null || propertyType == void . class ) { return ; } if ( prefixLength == 2 ) { if ( ! ( propertyType == boolean . class ) ) { return ; } } Class [ ] paramTypes = method . getParameterTypes ( ) ; if ( paramTypes . length > 1 || ( paramTypes . length == 1 && paramTypes [ 0 ] != int . class ) ) { return ; } if ( ! method . isAnnotationPresent ( UriTransient . class ) && ! "class" . equals ( name ) ) { Object value = getValue ( method ) ; if ( method . isAnnotationPresent ( VarName . class ) ) { name = method . getAnnotation ( VarName . class ) . value ( ) ; } if ( value != null ) { pairs . put ( name , value ) ; } } }
A lite version of the introspection logic performed by the BeanInfo introspector .
5,755
private void scanFields ( Class < ? > c ) { if ( ! c . isInterface ( ) ) { Field [ ] fields = c . getDeclaredFields ( ) ; for ( Field field : fields ) { String fieldName = field . getName ( ) ; if ( pairs . containsKey ( fieldName ) ) { if ( field . isAnnotationPresent ( UriTransient . class ) ) { pairs . remove ( fieldName ) ; } else if ( field . isAnnotationPresent ( VarName . class ) ) { String name = field . getAnnotation ( VarName . class ) . value ( ) ; pairs . put ( name , pairs . get ( fieldName ) ) ; pairs . remove ( fieldName ) ; } } } } if ( ! c . getSuperclass ( ) . equals ( Object . class ) ) { scanFields ( c . getSuperclass ( ) ) ; } }
Scans the fields on the class or super classes to look for field - level annotations .
5,756
private Object getValue ( Method method ) throws VarExploderException { try { if ( method == null ) { return null ; } return method . invoke ( source ) ; } catch ( IllegalArgumentException e ) { throw new VarExploderException ( e ) ; } catch ( IllegalAccessException e ) { throw new VarExploderException ( e ) ; } catch ( InvocationTargetException e ) { throw new VarExploderException ( e ) ; } }
Return the value of the property .
5,757
public LinkedList < UriTemplateComponent > scan ( String templateString ) throws MalformedUriTemplateException { char [ ] template = templateString . toCharArray ( ) ; startTemplate ( ) ; int i ; for ( i = 0 ; i < template . length ; i ++ ) { char c = template [ i ] ; if ( c == EXPR_START ) { if ( literalCaptureOn ) { endLiteral ( i ) ; } startExpression ( i ) ; } if ( c != EXPR_START ) { startLiteral ( i ) ; } if ( expressionCaptureOn || literalCaptureOn ) { capture ( c ) ; } if ( c == EXPR_END ) { endExpression ( i ) ; startLiteral ( i ) ; } } if ( literalCaptureOn ) { endLiteral ( i ) ; } endTemplate ( i ) ; return components ; }
Scans the URI template looking for literal string components and expressions .
5,758
private void startLiteral ( int position ) throws MalformedUriTemplateException { if ( startedTemplate ) { if ( ! literalCaptureOn ) { literalCaptureOn = true ; startPosition = position ; } } else { throw new IllegalStateException ( "Cannot start a literal without beginning the template" ) ; } }
Marks the start of
5,759
private void startExpression ( int position ) throws MalformedUriTemplateException { if ( startedTemplate ) { if ( expressionCaptureOn ) { throw new MalformedUriTemplateException ( "A new expression start brace found at " + position + " but another unclosed expression was found at " + startPosition , position ) ; } literalCaptureOn = false ; expressionCaptureOn = true ; startPosition = position ; } else { throw new IllegalStateException ( "Cannot start an expression without beginning the template" ) ; } }
Called when the start of an expression has been encountered .
5,760
private void endExpression ( int position ) throws MalformedUriTemplateException { if ( startedTemplate ) { if ( ! expressionCaptureOn ) { throw new MalformedUriTemplateException ( "Expression close brace was found at position " + position + " yet there was no start brace." , position ) ; } expressionCaptureOn = false ; components . add ( new Expression ( buffer . toString ( ) , this . startPosition ) ) ; buffer = null ; } else { throw new IllegalStateException ( "Cannot end an expression without beginning the template" ) ; } }
Called when the end of an expression has been encountered .
5,761
private String createFragment ( final Value resource ) { if ( resource instanceof URI ) { String frag = ( ( URI ) resource ) . getLocalName ( ) ; return RESERVED_FRAGMENTS . contains ( frag ) ? frag + "_" : frag ; } else { return resource . stringValue ( ) ; } }
Simplifies the lexical representation of a value in particular by taking the fragment identifier of URIs . This is a lossy operation ; many distinct URIs may map to the same fragment . Conflicts with reserved tokens are avoided .
5,762
public FaunusPipeline _ ( ) { this . state . assertNotLocked ( ) ; this . compiler . addMap ( IdentityMap . Map . class , NullWritable . class , FaunusVertex . class , IdentityMap . createConfiguration ( ) ) ; makeMapReduceString ( IdentityMap . class ) ; return this ; }
The identity step does not alter the graph in anyway . It has the benefit of emitting various useful graph statistic counters .
5,763
public FaunusPipeline transform ( final String closure ) { this . state . assertNotLocked ( ) ; this . state . assertNoProperty ( ) ; this . compiler . addMap ( TransformMap . Map . class , NullWritable . class , FaunusVertex . class , TransformMap . createConfiguration ( this . state . getElementType ( ) , this . validateClosure ( closure ) ) ) ; this . state . lock ( ) ; makeMapReduceString ( TransformMap . class ) ; return this ; }
Apply the provided closure to the current element and emit the result .
5,764
public FaunusPipeline V ( ) { this . state . assertNotLocked ( ) ; this . state . assertNoProperty ( ) ; this . state . set ( Vertex . class ) ; this . compiler . addMap ( VerticesMap . Map . class , NullWritable . class , FaunusVertex . class , VerticesMap . createConfiguration ( this . state . incrStep ( ) != 0 ) ) ; makeMapReduceString ( VerticesMap . class ) ; return this ; }
Start a traversal at all vertices in the graph .
5,765
public FaunusPipeline E ( ) { this . state . assertNotLocked ( ) ; this . state . assertNoProperty ( ) ; this . state . set ( Edge . class ) ; this . compiler . addMap ( EdgesMap . Map . class , NullWritable . class , FaunusVertex . class , EdgesMap . createConfiguration ( this . state . incrStep ( ) != 0 ) ) ; makeMapReduceString ( EdgesMap . class ) ; return this ; }
Start a traversal at all edges in the graph .
5,766
public FaunusPipeline v ( final long ... ids ) { this . state . assertNotLocked ( ) ; this . state . assertNoProperty ( ) ; this . state . set ( Vertex . class ) ; this . state . incrStep ( ) ; this . compiler . addMap ( VertexMap . Map . class , NullWritable . class , FaunusVertex . class , VertexMap . createConfiguration ( ids ) ) ; makeMapReduceString ( VertexMap . class ) ; return this ; }
Start a traversal at the vertices identified by the provided ids .
5,767
public FaunusPipeline property ( final String key , final Class type ) { this . state . assertNotLocked ( ) ; this . state . assertNoProperty ( ) ; this . state . setProperty ( key , type ) ; return this ; }
Emit the property value of an element .
5,768
public FaunusPipeline map ( ) { this . state . assertNotLocked ( ) ; this . state . assertNoProperty ( ) ; this . compiler . addMap ( PropertyMapMap . Map . class , LongWritable . class , Text . class , PropertyMapMap . createConfiguration ( this . state . getElementType ( ) ) ) ; makeMapReduceString ( PropertyMap . class ) ; this . state . lock ( ) ; return this ; }
Emit a string representation of the property map .
5,769
public FaunusPipeline label ( ) { this . state . assertNotLocked ( ) ; this . state . assertNoProperty ( ) ; this . state . assertAtEdge ( ) ; this . property ( Tokens . LABEL , String . class ) ; return this ; }
Emit the label of the current edge .
5,770
public FaunusPipeline path ( ) { this . state . assertNotLocked ( ) ; this . state . assertNoProperty ( ) ; this . compiler . addMap ( PathMap . Map . class , NullWritable . class , Text . class , PathMap . createConfiguration ( this . state . getElementType ( ) ) ) ; this . state . lock ( ) ; makeMapReduceString ( PathMap . class ) ; return this ; }
Emit the path taken from start to current element .
5,771
public FaunusPipeline filter ( final String closure ) { this . state . assertNotLocked ( ) ; this . state . assertNoProperty ( ) ; this . compiler . addMap ( FilterMap . Map . class , NullWritable . class , FaunusVertex . class , FilterMap . createConfiguration ( this . state . getElementType ( ) , this . validateClosure ( closure ) ) ) ; makeMapReduceString ( FilterMap . class ) ; return this ; }
Emit or deny the current element based upon the provided boolean - based closure .
5,772
public FaunusPipeline hasNot ( final String key , final Compare compare , final Object ... values ) { return this . has ( key , compare . opposite ( ) , values ) ; }
Emit the current element if it does not have a property value comparable to the provided values .
5,773
public FaunusPipeline has ( final String key , final Object ... values ) { return ( values . length == 0 ) ? this . has ( key , Compare . NOT_EQUAL , new Object [ ] { null } ) : this . has ( key , Compare . EQUAL , values ) ; }
Emit the current element it has a property value equal to the provided values .
5,774
public FaunusPipeline interval ( final String key , final Object startValue , final Object endValue ) { this . state . assertNotLocked ( ) ; this . state . assertNoProperty ( ) ; this . compiler . addMap ( IntervalFilterMap . Map . class , NullWritable . class , FaunusVertex . class , IntervalFilterMap . createConfiguration ( this . state . getElementType ( ) , key , startValue , endValue ) ) ; makeMapReduceString ( IntervalFilterMap . class , key , startValue , endValue ) ; return this ; }
Emit the current element it has a property value equal within the provided range .
5,775
public FaunusPipeline dedup ( ) { this . state . assertNotLocked ( ) ; this . state . assertNoProperty ( ) ; this . compiler . addMap ( DuplicateFilterMap . Map . class , NullWritable . class , FaunusVertex . class , DuplicateFilterMap . createConfiguration ( this . state . getElementType ( ) ) ) ; makeMapReduceString ( DuplicateFilterMap . class ) ; return this ; }
Remove any duplicate traversers at a single element .
5,776
public FaunusPipeline back ( final String step ) { this . state . assertNotLocked ( ) ; this . state . assertNoProperty ( ) ; this . compiler . addMapReduce ( BackFilterMapReduce . Map . class , BackFilterMapReduce . Combiner . class , BackFilterMapReduce . Reduce . class , LongWritable . class , Holder . class , NullWritable . class , FaunusVertex . class , BackFilterMapReduce . createConfiguration ( this . state . getElementType ( ) , this . state . getStep ( step ) ) ) ; makeMapReduceString ( BackFilterMapReduce . class , step ) ; return this ; }
Go back to an element a named step ago . Currently only backing up to vertices is supported .
5,777
public FaunusPipeline simplePath ( ) { this . state . assertNotLocked ( ) ; this . state . assertNoProperty ( ) ; this . compiler . addMap ( CyclicPathFilterMap . Map . class , NullWritable . class , FaunusVertex . class , CyclicPathFilterMap . createConfiguration ( this . state . getElementType ( ) ) ) ; makeMapReduceString ( CyclicPathFilterMap . class ) ; return this ; }
Emit the element only if it was arrived at via a path that does not have cycles in it .
5,778
public FaunusPipeline sideEffect ( final String closure ) { this . state . assertNotLocked ( ) ; this . state . assertNoProperty ( ) ; this . compiler . addMap ( SideEffectMap . Map . class , NullWritable . class , FaunusVertex . class , SideEffectMap . createConfiguration ( this . state . getElementType ( ) , this . validateClosure ( closure ) ) ) ; makeMapReduceString ( SideEffectMap . class ) ; return this ; }
Emit the element but compute some sideeffect in the process . For example mutate the properties of the element .
5,779
public FaunusPipeline as ( final String name ) { this . state . assertNotLocked ( ) ; this . state . assertNoProperty ( ) ; this . state . addStep ( name ) ; final String string = "As(" + name + "," + this . stringRepresentation . get ( this . state . getStep ( name ) ) + ")" ; this . stringRepresentation . set ( this . state . getStep ( name ) , string ) ; return this ; }
Name a step in order to reference it later in the expression .
5,780
public FaunusPipeline linkIn ( final String label , final String step , final String mergeWeightKey ) { return this . link ( IN , label , step , mergeWeightKey ) ; }
Have the elements for the named step previous project an edge to the current vertex with provided label . If a merge weight key is provided then count the number of duplicate edges between the same two vertices and add a weight . No weight key is specified by _ and then all duplicates are merged but no weight is added to the resultant edge .
5,781
public FaunusPipeline linkIn ( final String label , final String step ) { return this . link ( IN , label , step , null ) ; }
Have the elements for the named step previous project an edge to the current vertex with provided label .
5,782
public FaunusPipeline linkOut ( final String label , final String step , final String mergeWeightKey ) { return link ( OUT , label , step , mergeWeightKey ) ; }
Have the elements for the named step previous project an edge from the current vertex with provided label . If a merge weight key is provided then count the number of duplicate edges between the same two vertices and add a weight . No weight key is specified by _ and then all duplicates are merged but no weight is added to the resultant edge .
5,783
public FaunusPipeline linkOut ( final String label , final String step ) { return this . link ( OUT , label , step , null ) ; }
Have the elements for the named step previous project an edge from the current vertex with provided label .
5,784
public FaunusPipeline groupCount ( final String keyClosure , final String valueClosure ) { this . state . assertNotLocked ( ) ; this . compiler . addMapReduce ( GroupCountMapReduce . Map . class , GroupCountMapReduce . Combiner . class , GroupCountMapReduce . Reduce . class , Text . class , LongWritable . class , Text . class , LongWritable . class , GroupCountMapReduce . createConfiguration ( this . state . getElementType ( ) , this . validateClosure ( keyClosure ) , this . validateClosure ( valueClosure ) ) ) ; makeMapReduceString ( GroupCountMapReduce . class ) ; return this ; }
Apply the provided closure to the incoming element to determine the grouping key . Then apply the value closure to the current element to determine the count increment . The results are stored in the jobs sideeffect file in HDFS .
5,785
public FaunusPipeline count ( ) { this . state . assertNotLocked ( ) ; this . compiler . addMapReduce ( CountMapReduce . Map . class , CountMapReduce . Combiner . class , CountMapReduce . Reduce . class , NullWritable . class , LongWritable . class , NullWritable . class , LongWritable . class , CountMapReduce . createConfiguration ( this . state . getElementType ( ) ) ) ; makeMapReduceString ( CountMapReduce . class ) ; this . state . lock ( ) ; return this ; }
Count the number of traversers currently in the graph
5,786
public void submit ( final String script , final Boolean showHeader ) throws Exception { this . done ( ) ; if ( MapReduceFormat . class . isAssignableFrom ( this . graph . getGraphOutputFormat ( ) ) ) { this . state . assertNotLocked ( ) ; ( ( Class < ? extends MapReduceFormat > ) this . graph . getGraphOutputFormat ( ) ) . getConstructor ( ) . newInstance ( ) . addMapReduceJobs ( this . compiler ) ; } this . compiler . completeSequence ( ) ; ToolRunner . run ( this . compiler , new String [ ] { script , showHeader . toString ( ) } ) ; }
Submit the FaunusPipeline to the Hadoop cluster and ensure that a header is emitted in the logs .
5,787
public Path getInputLocation ( ) { if ( null == this . configuration . get ( FAUNUS_INPUT_LOCATION ) ) return null ; return new Path ( this . configuration . get ( FAUNUS_INPUT_LOCATION ) ) ; }
INPUT AND OUTPUT LOCATIONS
5,788
public Object [ ] nextRecord ( ) { try { int nextByte ; do { nextByte = dataInput . readByte ( ) ; if ( nextByte == DATA_ENDED ) { return null ; } else if ( nextByte == DATA_DELETED ) { dataInput . skipBytes ( header . getRecordLength ( ) - 1 ) ; } } while ( nextByte == DATA_DELETED ) ; Object recordObjects [ ] = new Object [ header . getFieldsCount ( ) ] ; for ( int i = 0 ; i < header . getFieldsCount ( ) ; i ++ ) { recordObjects [ i ] = readFieldValue ( header . getField ( i ) ) ; } return recordObjects ; } catch ( EOFException e ) { return null ; } catch ( IOException e ) { throw new DbfException ( "Cannot read next record form Dbf file" , e ) ; } }
Reads and returns the next row in the Dbf stream
5,789
public BigDecimal getBigDecimal ( String fieldName ) throws DbfException { Object value = get ( fieldName ) ; return value == null ? null : new BigDecimal ( value . toString ( ) ) ; }
Retrieves the value of the designated field as java . math . BigDecimal .
5,790
public Date getDate ( String fieldName ) throws DbfException { Date value = ( Date ) get ( fieldName ) ; return value == null ? null : value ; }
Retrieves the value of the designated field as java . util . Date .
5,791
public String getString ( String fieldName , Charset charset ) throws DbfException { Object value = get ( fieldName ) ; return value == null ? null : new String ( trimLeftSpaces ( ( byte [ ] ) value ) , charset ) ; }
Retrieves the value of the designated field as String using given charset .
5,792
public boolean getBoolean ( String fieldName ) throws DbfException { Boolean value = ( Boolean ) get ( fieldName ) ; return value != null && value ; }
Retrieves the value of the designated field as boolean .
5,793
public SSLContextBuilder withCipherFilter ( SSLCipherFilter cipherFilter ) { if ( cipherFilter == null ) { this . nettyCipherSuiteFilter = null ; } else { this . nettyCipherSuiteFilter = ( ciphers , defaultCiphers , supportedCiphers ) -> { List < String > selected = cipherFilter . selectCiphers ( supportedCiphers , defaultCiphers ) ; if ( selected == null ) { selected = defaultCiphers ; } return selected . toArray ( new String [ 0 ] ) ; } ; } return this ; }
Sets a filter allowing you to specify which ciphers you would like to support .
5,794
public MuServerBuilder withGzip ( long minimumGzipSize , Set < String > mimeTypesToGzip ) { this . gzipEnabled = true ; this . mimeTypesToGzip = mimeTypesToGzip ; this . minimumGzipSize = minimumGzipSize ; return this ; }
Enables gzip for files of at least the specified size that match the given mime - types . By default gzip is enabled for text - based mime types over 1400 bytes . It is recommended to keep the defaults and only use this method if you have very specific requirements around GZIP .
5,795
public static synchronized RuntimeDelegate ensureSet ( ) { if ( singleton == null ) { singleton = new MuRuntimeDelegate ( ) ; RuntimeDelegate . setInstance ( singleton ) ; } return singleton ; }
Registers the mu RuntimeDelegate with jax - rs if it was not already .
5,796
public static ResourceHandler . Builder classpathHandler ( String classpathRoot ) { return new Builder ( ) . withResourceProviderFactory ( ResourceProviderFactory . classpathBased ( classpathRoot ) ) ; }
Creates a handler that serves files from the classpath ..
5,797
public static MuHandler route ( Method method , String uriTemplate , RouteHandler muHandler ) { UriPattern uriPattern = UriPattern . uriTemplateToRegex ( uriTemplate ) ; return ( request , response ) -> { boolean methodMatches = method == null || method . equals ( request . method ( ) ) ; if ( methodMatches ) { PathMatch matcher = uriPattern . matcher ( request . relativePath ( ) ) ; if ( matcher . fullyMatches ( ) ) { muHandler . handle ( request , response , matcher . params ( ) ) ; return true ; } } return false ; } ; }
Creates a new handler that will only be called if it matches the given route info .
5,798
public CORSHandlerBuilder withAllowedMethods ( Method ... methods ) { if ( methods == null ) { allowedMethods = null ; } else { allowedMethods = new HashSet < > ( asList ( methods ) ) ; } return this ; }
Specifies the headers allowed for CORS requests . Defaults to all methods except Trace and Connect .
5,799
public static void copy ( InputStream from , OutputStream to , int bufferSize ) throws IOException { byte [ ] buffer = new byte [ bufferSize ] ; int read ; while ( ( read = from . read ( buffer ) ) > - 1 ) { to . write ( buffer , 0 , read ) ; } }
Copies an input stream to another stream