idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
3,100
void detach ( ) { mLock . lock ( ) ; try { if ( mDetached || mTxnMgr . removeLocalScope ( this ) ) { mDetached = true ; } else { throw new IllegalStateException ( "Transaction is attached to a different thread" ) ; } } finally { mLock . unlock ( ) ; } }
Called by TransactionImpl .
3,101
void close ( ) throws RepositoryException { mLock . lock ( ) ; if ( mClosed ) { mLock . unlock ( ) ; return ; } Map < Class < ? > , CursorList < TransactionImpl < Txn > > > cursors ; try { cursors = mCursors ; mCursors = null ; while ( mActive != null ) { mActive . exit ( ) ; } } finally { mTxnMgr = ( TransactionManager < Txn > ) TransactionManager . Closed . THE ; mClosed = true ; mLock . unlock ( ) ; } if ( cursors != null ) { for ( CursorList < TransactionImpl < Txn > > cursorList : cursors . values ( ) ) { cursorList . closeCursors ( ) ; } } }
Exits all transactions and closes all cursors . Should be called only when repository is closed .
3,102
@ SuppressWarnings ( "unchecked" ) public void addKey ( StorableKey < S > key ) { if ( key == null ) { throw new IllegalArgumentException ( ) ; } add ( new StorableIndex < S > ( key , Direction . UNSPECIFIED ) ) ; }
Adds the key as a unique index preserving the property arrangement .
3,103
public void reduce ( Direction defaultDirection ) { List < StorableIndex < S > > group = new ArrayList < StorableIndex < S > > ( ) ; Map < StorableIndex < S > , StorableIndex < S > > mergedReplacements = new TreeMap < StorableIndex < S > , StorableIndex < S > > ( STORABLE_INDEX_COMPARATOR ) ; Iterator < StorableIndex < S > > it = iterator ( ) ; while ( it . hasNext ( ) ) { StorableIndex < S > candidate = it . next ( ) ; if ( group . size ( ) == 0 || isDifferentGroup ( group . get ( 0 ) , candidate ) ) { group . clear ( ) ; group . add ( candidate ) ; continue ; } if ( isRedundant ( group , candidate , mergedReplacements ) ) { it . remove ( ) ; } else { group . add ( candidate ) ; } } replaceEntries ( mergedReplacements ) ; setDefaultDirection ( defaultDirection ) ; }
Reduces the size of the set by removing redundant indexes and merges others together .
3,104
public void setDefaultDirection ( Direction defaultDirection ) { if ( defaultDirection != Direction . UNSPECIFIED ) { Map < StorableIndex < S > , StorableIndex < S > > replacements = null ; for ( StorableIndex < S > index : this ) { StorableIndex < S > replacement = index . setDefaultDirection ( defaultDirection ) ; if ( replacement != index ) { if ( replacements == null ) { replacements = new HashMap < StorableIndex < S > , StorableIndex < S > > ( ) ; } replacements . put ( index , replacement ) ; } } replaceEntries ( replacements ) ; } }
Set the default direction for all index properties .
3,105
public void markClustered ( boolean clustered ) { Map < StorableIndex < S > , StorableIndex < S > > replacements = null ; for ( StorableIndex < S > index : this ) { StorableIndex < S > replacement = index . clustered ( clustered ) ; if ( replacement != index ) { if ( replacements == null ) { replacements = new HashMap < StorableIndex < S > , StorableIndex < S > > ( ) ; } replacements . put ( index , replacement ) ; } } replaceEntries ( replacements ) ; }
Marks all indexes as clustered or non - clustered .
3,106
public void uniquify ( StorableInfo < S > info ) { if ( info == null ) { throw new IllegalArgumentException ( ) ; } uniquify ( info . getPrimaryKey ( ) ) ; }
Augment non - unique indexes with primary key properties thus making them unique .
3,107
public void uniquify ( StorableKey < S > key ) { if ( key == null ) { throw new IllegalArgumentException ( ) ; } { Map < StorableIndex < S > , StorableIndex < S > > replacements = null ; for ( StorableIndex < S > index : this ) { if ( ! index . isUnique ( ) && isUniqueImplied ( index ) ) { if ( replacements == null ) { replacements = new HashMap < StorableIndex < S > , StorableIndex < S > > ( ) ; } replacements . put ( index , index . unique ( true ) ) ; } } replaceEntries ( replacements ) ; } { Map < StorableIndex < S > , StorableIndex < S > > replacements = null ; for ( StorableIndex < S > index : this ) { StorableIndex < S > replacement = index . uniquify ( key ) ; if ( replacement != index ) { if ( replacements == null ) { replacements = new HashMap < StorableIndex < S > , StorableIndex < S > > ( ) ; } replacements . put ( index , replacement ) ; } } replaceEntries ( replacements ) ; } }
Augment non - unique indexes with key properties thus making them unique .
3,108
private boolean isUniqueImplied ( StorableIndex < S > candidate ) { if ( candidate . isUnique ( ) ) { return true ; } if ( this . size ( ) <= 1 ) { return false ; } Set < StorableProperty < S > > candidateProps = new HashSet < StorableProperty < S > > ( ) ; for ( int i = candidate . getPropertyCount ( ) ; -- i >= 0 ; ) { candidateProps . add ( candidate . getProperty ( i ) ) ; } search : for ( StorableIndex < S > index : this ) { if ( ! index . isUnique ( ) ) { continue search ; } for ( int i = index . getPropertyCount ( ) ; -- i >= 0 ; ) { if ( ! candidateProps . contains ( index . getProperty ( i ) ) ) { continue search ; } } return true ; } return false ; }
Return true if index is unique or fully contains the members of a unique index .
3,109
private boolean isRedundant ( List < StorableIndex < S > > group , StorableIndex < S > candidate , Map < StorableIndex < S > , StorableIndex < S > > mergedReplacements ) { int count = candidate . getPropertyCount ( ) ; ListIterator < StorableIndex < S > > it = group . listIterator ( ) ; groupScan : while ( it . hasNext ( ) ) { StorableIndex < S > member = it . next ( ) ; boolean moreQualified = false ; boolean canReverse = true ; boolean reverse = false ; for ( int i = 0 ; i < count ; i ++ ) { Direction candidateOrder = candidate . getPropertyDirection ( i ) ; if ( candidateOrder == Direction . UNSPECIFIED ) { continue ; } Direction memberOrder = member . getPropertyDirection ( i ) ; if ( memberOrder == Direction . UNSPECIFIED ) { moreQualified = true ; continue ; } if ( reverse ) { candidateOrder = candidateOrder . reverse ( ) ; } if ( candidateOrder == memberOrder ) { canReverse = false ; continue ; } if ( canReverse ) { reverse = true ; canReverse = false ; continue ; } continue groupScan ; } if ( moreQualified ) { Direction [ ] directions = member . getPropertyDirections ( ) ; for ( int i = 0 ; i < count ; i ++ ) { if ( directions [ i ] == Direction . UNSPECIFIED ) { Direction direction = candidate . getPropertyDirection ( i ) ; directions [ i ] = reverse ? direction . reverse ( ) : direction ; } } StorableIndex < S > merged = new StorableIndex < S > ( member . getProperties ( ) , directions ) . unique ( member . isUnique ( ) ) ; mergedReplacements . put ( member , merged ) ; it . set ( merged ) ; } return true ; } return false ; }
Returns true if candidate index is less qualified than an existing group member or if it was merged with another group member . If it was merged then an entry is placed in the merged map and the given group list is updated .
3,110
private boolean doTryUpdateNoLock ( S storable ) { S existing = mMap . get ( new Key < S > ( storable , mFullComparator ) ) ; if ( existing == null ) { return false ; } else { existing . markAllPropertiesDirty ( ) ; storable . copyDirtyProperties ( existing ) ; existing . markAllPropertiesClean ( ) ; storable . markAllPropertiesDirty ( ) ; existing . copyAllProperties ( storable ) ; storable . markAllPropertiesClean ( ) ; return true ; } }
Caller must hold write lock .
3,111
void mapPut ( S storable ) { mMap . put ( new Key < S > ( storable , mFullComparator ) , storable ) ; }
Called by MapTransaction which implicitly holds lock .
3,112
public void addProperty ( String propertyName , Direction direction ) { if ( propertyName == null ) { throw new IllegalArgumentException ( ) ; } if ( direction == null ) { direction = Direction . UNSPECIFIED ; } if ( direction != Direction . UNSPECIFIED ) { if ( propertyName . length ( ) > 0 ) { if ( propertyName . charAt ( 0 ) == '-' || propertyName . charAt ( 0 ) == '+' ) { propertyName = propertyName . substring ( 1 ) ; } } propertyName = direction . toCharacter ( ) + propertyName ; } mPropertyList . add ( propertyName ) ; }
Adds a property to this index with the specified direction .
3,113
public static < S > Comparator < S > createComparator ( Class < S > type , String ... orderProperties ) { BeanComparator bc = BeanComparator . forClass ( type ) ; if ( Storable . class . isAssignableFrom ( type ) ) { StorableInfo info = StorableIntrospector . examine ( ( Class ) type ) ; for ( String property : orderProperties ) { bc = orderBy ( bc , OrderedProperty . parse ( info , property ) ) ; } } else { for ( String property : orderProperties ) { Class propertyType ; { String name = property ; if ( name . startsWith ( "+" ) || name . startsWith ( "-" ) ) { name = name . substring ( 1 ) ; } propertyType = propertyType ( type , name ) ; } bc = orderBy ( bc , property , propertyType , Direction . ASCENDING ) ; } } return bc ; }
Convenience method to create a comparator which orders storables by the given order - by properties . The property names may be prefixed with + or - to indicate ascending or descending order . If the prefix is omitted ascending order is assumed .
3,114
public static < S extends Storable > Comparator < S > createComparator ( OrderedProperty < S > ... properties ) { if ( properties == null || properties . length == 0 || properties [ 0 ] == null ) { throw new IllegalArgumentException ( ) ; } Class < S > type = properties [ 0 ] . getChainedProperty ( ) . getPrimeProperty ( ) . getEnclosingType ( ) ; BeanComparator bc = BeanComparator . forClass ( type ) ; for ( OrderedProperty < S > property : properties ) { if ( property == null ) { throw new IllegalArgumentException ( ) ; } bc = orderBy ( bc , property ) ; } return bc ; }
Convenience method to create a comparator which orders storables by the given properties .
3,115
private static String chainToBeanString ( ChainedProperty property ) { int count = property . getChainCount ( ) ; if ( count <= 0 ) { return property . getPrimeProperty ( ) . getBeanName ( ) ; } StringBuilder b = new StringBuilder ( ) ; b . append ( property . getPrimeProperty ( ) . getBeanName ( ) ) ; for ( int i = 0 ; i < count ; i ++ ) { b . append ( '.' ) ; b . append ( property . getChainedProperty ( i ) . getBeanName ( ) ) ; } return b . toString ( ) ; }
Creates a dotted name string using the bean property names .
3,116
public Comparator < S > comparator ( ) { if ( mChunkMatcher == null ) { return mChunkSorter ; } return new Comparator < S > ( ) { public int compare ( S a , S b ) { int result = mChunkMatcher . compare ( a , b ) ; if ( result == 0 ) { result = mChunkSorter . compare ( a , b ) ; } return result ; } } ; }
Returns a comparator representing the effective sort order of this cursor .
3,117
public String buildStatement ( int initialCapacity , FilterValues < S > filterValues ) { StringBuilder b = new StringBuilder ( initialCapacity ) ; this . appendTo ( b , filterValues ) ; return b . toString ( ) ; }
Builds a statement string from the given values .
3,118
public static < Type > Validator < Type > conjunctive ( final Context context , final Validator < Type > ... validators ) { return ConjunctiveValidator . create ( context , R . string . default_error_message , validators ) ; }
Creates and returns a validator which allows to combine multiple validators in a conjunctive manner . If all single validators succeed the resulting validator will also succeed .
3,119
public static Validator < CharSequence > regex ( final CharSequence errorMessage , final Pattern regex ) { return new RegexValidator ( errorMessage , regex ) ; }
Creates and returns a validator which allows to validate texts to ensure that they match a certain regular expression .
3,120
public final void assertReady ( ) throws ConfigurationException { ArrayList < String > messages = new ArrayList < String > ( ) ; errorCheck ( messages ) ; int size = messages . size ( ) ; if ( size == 0 ) { return ; } StringBuilder b = new StringBuilder ( ) ; if ( size > 1 ) { b . append ( "Multiple problems: " ) ; } for ( int i = 0 ; i < size ; i ++ ) { if ( i > 0 ) { b . append ( "; " ) ; } b . append ( messages . get ( i ) ) ; } throw new ConfigurationException ( b . toString ( ) ) ; }
Throw a configuration exception if the configuration is not filled out sufficiently and correctly such that a repository could be instantiated from it .
3,121
private void initializeUsernameEditText ( ) { usernameEditText = ( EditText ) findViewById ( R . id . username_edit_text ) ; usernameEditText . addValidator ( Validators . notEmpty ( this , R . string . not_empty_validator_error_message ) ) ; usernameEditText . addValidator ( Validators . maxLength ( this , R . string . max_length_validator_error_messsage , MAX_CHARACTERS ) ) ; usernameEditText . addValidator ( Validators . letterOrNumber ( this , R . string . letter_or_number_validator_error_message , Case . CASE_INSENSITIVE , false , new char [ ] { '-' , '_' } ) ) ; }
Initializes the edit text which allows to enter an username .
3,122
private void initializePasswordEditText ( ) { passwordEditText = ( PasswordEditText ) findViewById ( R . id . password_edit_text ) ; passwordEditText . addValidator ( Validators . minLength ( this , R . string . password_min_length_validator_error_message , MIN_PASSWORD_LENGTH ) ) ; passwordEditText . addValidator ( Validators . maxLength ( this , R . string . max_length_validator_error_messsage , MAX_CHARACTERS ) ) ; passwordEditText . addValidator ( Validators . noWhitespace ( this , R . string . no_whitespace_validator_error_message ) ) ; passwordEditText . addAllConstraints ( Constraints . minLength ( SUGGESTED_PASSWORD_LENGTH ) , Constraints . containsLetter ( ) , Constraints . containsNumber ( ) , Constraints . containsSymbol ( ) ) ; passwordEditText . addAllHelperTextIds ( R . string . password_edit_text_helper_text0 , R . string . password_edit_text_helper_text1 , R . string . password_edit_text_helper_text2 , R . string . password_edit_text_helper_text3 , R . string . password_edit_text_helper_text4 ) ; passwordEditText . addAllHelperTextColorIds ( R . color . password_edit_text_helper_text_color0 , R . color . password_edit_text_helper_text_color1 , R . color . password_edit_text_helper_text_color2 , R . color . password_edit_text_helper_text_color3 , R . color . password_edit_text_helper_text_color4 ) ; }
Initializes the edit text which allows to enter a password .
3,123
private void initializePasswordRepetitionEditText ( ) { passwordRepetitionEditText = ( EditText ) findViewById ( R . id . password_repetition_edit_text ) ; passwordRepetitionEditText . addValidator ( Validators . equal ( this , R . string . equal_validator_error_message , passwordEditText ) ) ; }
Initializes the edit text which allows to enter a password repetition .
3,124
private void initializeGenderSpinner ( ) { genderSpinner = ( Spinner ) findViewById ( R . id . gender_spinner ) ; genderSpinner . addValidator ( Validators . notNull ( this , R . string . not_null_validator_error_message ) ) ; }
Initializes the spinner which allows to choose a gender .
3,125
private void initializeFirstNameEditText ( ) { firstNameEditText = ( EditText ) findViewById ( R . id . first_name_edit_text ) ; firstNameEditText . addValidator ( Validators . minLength ( this , R . string . min_length_validator_error_message , MIN_NAME_LENGTH ) ) ; firstNameEditText . addValidator ( Validators . beginsWithUppercaseLetter ( this , R . string . begins_with_uppercase_letter_validator_error_message ) ) ; firstNameEditText . addValidator ( Validators . letter ( this , R . string . letter_validator_error_message , Case . CASE_INSENSITIVE , false , new char [ ] { '-' } ) ) ; }
Initializes the edit text which allows to enter a first name .
3,126
private void initializeLastNameEditText ( ) { lastNameEditText = ( EditText ) findViewById ( R . id . last_name_edit_text ) ; lastNameEditText . addValidator ( Validators . minLength ( this , R . string . min_length_validator_error_message , MIN_NAME_LENGTH ) ) ; lastNameEditText . addValidator ( Validators . beginsWithUppercaseLetter ( this , R . string . begins_with_uppercase_letter_validator_error_message ) ) ; lastNameEditText . addValidator ( Validators . letter ( this , R . string . letter_validator_error_message , Case . CASE_INSENSITIVE , false , new char [ ] { '-' } ) ) ; }
Initializes the edit text which allows to enter a last name .
3,127
private void initializeValidateButton ( ) { Button button = ( Button ) findViewById ( R . id . validate_button ) ; button . setOnClickListener ( new OnClickListener ( ) { public void onClick ( final View v ) { usernameEditText . validate ( ) ; passwordEditText . validate ( ) ; passwordRepetitionEditText . validate ( ) ; genderSpinner . validate ( ) ; firstNameEditText . validate ( ) ; lastNameEditText . validate ( ) ; additionalInformationEditText . validate ( ) ; } } ) ; }
Initializes the button which allows to validate the values of all views .
3,128
public static DataSource create ( DataSource ds , Log log ) { if ( ds == null ) { throw new IllegalArgumentException ( ) ; } if ( log == null ) { log = LogFactory . getLog ( LoggingDataSource . class ) ; } if ( ! log . isDebugEnabled ( ) ) { return ds ; } return new LoggingDataSource ( log , ds ) ; }
Wraps the given DataSource which logs to the given log . If debug logging is disabled the original DataSource is returned .
3,129
Object getPrimaryDatabase ( ) throws FetchException { Object database = mPrimaryDatabase ; if ( database == null ) { checkClosed ( ) ; throw new IllegalStateException ( "BDBStorage not opened" ) ; } return database ; }
Caller must hold transaction lock . May throw FetchException if storage is closed .
3,130
void checkClosed ( ) throws FetchException { TransactionScope < Txn > scope = localTransactionScope ( ) ; scope . getLock ( ) . lock ( ) ; try { if ( mPrimaryDatabase == null ) { try { scope . getTxn ( ) ; } catch ( Exception e ) { } throw new FetchException ( "Repository closed" ) ; } } finally { scope . getLock ( ) . unlock ( ) ; } }
If open returns normally . If shutting down blocks forever . Otherwise if closed throws FetchException . Method blocks forever on shutdown to prevent threads from starting work that will likely fail along the way .
3,131
private boolean isProperJoin ( StorableProperty < ? > property ) throws SupportException , RepositoryException { if ( ! property . isJoin ( ) || property . isQuery ( ) ) { return false ; } Filter < ? > filter = Filter . getOpenFilter ( property . getEnclosingType ( ) ) ; int count = property . getJoinElementCount ( ) ; for ( int i = 0 ; i < count ; i ++ ) { filter = filter . and ( property . getInternalJoinElement ( i ) . getName ( ) , RelOp . EQ ) ; } Collection indexes = indexesFor ( filter . getStorableType ( ) ) ; if ( indexes != null ) { for ( Object index : indexes ) { FilteringScore score = FilteringScore . evaluate ( ( StorableIndex ) index , filter ) ; if ( score . getRemainderCount ( ) == 0 ) { return true ; } } } return false ; }
Checks if the property is a join and its internal properties are fully indexed .
3,132
private static int primitiveWidth ( TypeDesc type ) { switch ( type . getTypeCode ( ) ) { default : return 0 ; case TypeDesc . BOOLEAN_CODE : return 1 ; case TypeDesc . BYTE_CODE : return 2 ; case TypeDesc . SHORT_CODE : return 3 ; case TypeDesc . CHAR_CODE : return 4 ; case TypeDesc . INT_CODE : return 5 ; case TypeDesc . FLOAT_CODE : return 6 ; case TypeDesc . LONG_CODE : return 7 ; case TypeDesc . DOUBLE_CODE : return 8 ; } }
1 = boolean 2 = byte 3 = short 4 = char 5 = int 6 = float 7 = long 8 = double
3,133
public Class < ? > getBoxedType ( ) { if ( mBoxedType == null ) { mBoxedType = TypeDesc . forClass ( getType ( ) ) . toObjectType ( ) . toClass ( ) ; } return mBoxedType ; }
Returns the type of the ChainedProperty property boxed into an object if primitive .
3,134
public PropertyFilter < S > constant ( Object value ) { if ( mBindID == BOUND_CONSTANT ) { if ( mConstant == null ) { if ( value == null ) { return this ; } } else if ( mConstant . equals ( value ) ) { return this ; } } return getCanonical ( mProperty , mOp , adaptValue ( value ) ) ; }
Returns another PropertyFilter instance which is bound to the given constant value .
3,135
public static byte [ ] EncodeSubjectPublicKeyInfo ( byte [ ] algorithm , byte [ ] keyBytes ) throws CoseException { try { ArrayList < byte [ ] > xxx = new ArrayList < byte [ ] > ( ) ; xxx . add ( algorithm ) ; xxx . add ( new byte [ ] { 3 } ) ; xxx . add ( ComputeLength ( keyBytes . length + 1 ) ) ; xxx . add ( new byte [ ] { 0 } ) ; xxx . add ( keyBytes ) ; return Sequence ( xxx ) ; } catch ( ArrayIndexOutOfBoundsException e ) { System . out . print ( e . toString ( ) ) ; throw e ; } }
Encode a subject public key info structure from an OID and the data bytes for the key This function assumes that we are encoding an EC Public key . d
3,136
public static byte [ ] EncodeEcPrivateKey ( byte [ ] oid , byte [ ] keyBytes , byte [ ] spki ) throws CoseException { ArrayList < byte [ ] > xxx = new ArrayList < byte [ ] > ( ) ; xxx . add ( new byte [ ] { 2 , 1 , 1 } ) ; xxx . add ( OctetStringTag ) ; xxx . add ( ComputeLength ( keyBytes . length ) ) ; xxx . add ( keyBytes ) ; xxx . add ( new byte [ ] { ( byte ) 0xa0 } ) ; xxx . add ( ComputeLength ( oid . length ) ) ; xxx . add ( oid ) ; if ( spki != null ) { xxx . add ( new byte [ ] { ( byte ) 0xa1 } ) ; xxx . add ( ComputeLength ( spki . length + 1 ) ) ; xxx . add ( new byte [ ] { 0 } ) ; xxx . add ( spki ) ; } byte [ ] ecPrivateKey = Sequence ( xxx ) ; return ecPrivateKey ; }
Encode an EC Private key
3,137
@ SuppressWarnings ( "unchecked" ) static synchronized < S extends Storable > GenericStorableCodec < S > getInstance ( GenericStorableCodecFactory factory , GenericEncodingStrategy < S > encodingStrategy , boolean isMaster , Layout layout , RawSupport support ) throws SupportException { Object layoutKey = layout == null ? null : new LayoutKey ( layout ) ; Object key = KeyFactory . createKey ( new Object [ ] { encodingStrategy , isMaster , layoutKey } ) ; Class < ? extends S > storableImpl = ( Class < ? extends S > ) cCache . get ( key ) ; if ( storableImpl == null ) { storableImpl = generateStorable ( encodingStrategy , isMaster , layout ) ; cCache . put ( key , storableImpl ) ; } return new GenericStorableCodec < S > ( key , factory , encodingStrategy . getType ( ) , storableImpl , encodingStrategy , layout , support ) ; }
Returns an instance of the codec . The Storable type itself may be an interface or a class . If it is a class then it must not be final and it must have a public no - arg constructor .
3,138
@ SuppressWarnings ( "unchecked" ) public SearchKeyFactory < S > getSearchKeyFactory ( OrderedProperty < S > [ ] properties ) { Object key = KeyFactory . createKey ( new Object [ ] { mCodecKey , properties } ) ; synchronized ( cCodecSearchKeyFactories ) { SearchKeyFactory < S > factory = ( SearchKeyFactory < S > ) cCodecSearchKeyFactories . get ( key ) ; if ( factory == null ) { factory = generateSearchKeyFactory ( properties ) ; cCodecSearchKeyFactories . put ( key , factory ) ; } return factory ; } }
Returns a search key factory which is useful for implementing indexes and queries .
3,139
public Decoder < S > getDecoder ( int generation ) throws FetchNoneException , FetchException { try { synchronized ( mLayout ) { IntHashMap decoders = mDecoders ; if ( decoders == null ) { mDecoders = decoders = new IntHashMap ( ) ; } Decoder < S > decoder = ( Decoder < S > ) decoders . get ( generation ) ; if ( decoder == null ) { synchronized ( cCodecDecoders ) { Object altLayoutKey = new LayoutKey ( mLayout . getGeneration ( generation ) ) ; Object key = KeyFactory . createKey ( new Object [ ] { mCodecKey , generation , altLayoutKey } ) ; decoder = ( Decoder < S > ) cCodecDecoders . get ( key ) ; if ( decoder == null ) { decoder = generateDecoder ( generation ) ; cCodecDecoders . put ( key , decoder ) ; } } mDecoders . put ( generation , decoder ) ; } return decoder ; } } catch ( NullPointerException e ) { if ( mLayout == null ) { throw new FetchNoneException ( "Layout evolution not supported" ) ; } throw e ; } }
Returns a data decoder for the given generation .
3,140
public static < S > Cursor < S > apply ( Cursor < S > source , Query . Controller controller ) { return controller == null ? source : new ControllerCursor < S > ( source , controller ) ; }
Returns a ControllerCursor depending on whether a controller instance is passed in or not .
3,141
public void AddProtected ( HeaderKeys label , byte [ ] value ) throws CoseException { addAttribute ( label , value , PROTECTED ) ; }
Set an attribute in the protect bucket of the COSE object
3,142
public void AddUnprotected ( CBORObject label , CBORObject value ) throws CoseException { addAttribute ( label , value , UNPROTECTED ) ; }
Set an attribute in the unprotected bucket of the COSE object
3,143
public void removeAttribute ( CBORObject label ) throws CoseException { if ( objProtected . ContainsKey ( label ) ) { if ( rgbProtected != null ) throw new CoseException ( "Operation would modify integrity protected attributes" ) ; objProtected . Remove ( label ) ; } if ( objUnprotected . ContainsKey ( label ) ) objUnprotected . Remove ( label ) ; if ( objDontSend . ContainsKey ( label ) ) objDontSend . Remove ( label ) ; }
Remove an attribute from the set of all attribute maps .
3,144
private static void callSetPropertyValue ( CodeBuilder b , OrderedProperty < ? > op ) { StorableProperty < ? > property = op . getChainedProperty ( ) . getLastProperty ( ) ; TypeDesc propType = TypeDesc . forClass ( property . getType ( ) ) ; if ( propType != TypeDesc . OBJECT ) { TypeDesc objectType = propType . toObjectType ( ) ; b . checkCast ( objectType ) ; b . convert ( objectType , propType ) ; } b . invoke ( property . getWriteMethod ( ) ) ; }
Creates code to call set method . Assumes Storable and property value are already on the stack .
3,145
static < S extends Storable > BlobReplicationTrigger < S > create ( Storage < S > masterStorage ) { Map < String , ? extends StorableProperty < S > > properties = StorableIntrospector . examine ( masterStorage . getStorableType ( ) ) . getDataProperties ( ) ; List < String > blobNames = new ArrayList < String > ( 2 ) ; for ( StorableProperty < S > property : properties . values ( ) ) { if ( property . getType ( ) == Blob . class ) { blobNames . add ( property . getName ( ) ) ; } } if ( blobNames . size ( ) == 0 ) { return null ; } return new BlobReplicationTrigger < S > ( masterStorage , blobNames . toArray ( new String [ blobNames . size ( ) ] ) ) ; }
Returns null if no Blobs need to be replicated .
3,146
public void sign ( OneKey key ) throws CoseException { if ( rgbContent == null ) throw new CoseException ( "No Content Specified" ) ; if ( rgbSignature != null ) return ; if ( rgbProtected == null ) { if ( objProtected . size ( ) > 0 ) rgbProtected = objProtected . EncodeToBytes ( ) ; else rgbProtected = new byte [ 0 ] ; } CBORObject obj = CBORObject . NewArray ( ) ; obj . Add ( contextString ) ; obj . Add ( rgbProtected ) ; obj . Add ( externalData ) ; obj . Add ( rgbContent ) ; rgbSignature = computeSignature ( obj . EncodeToBytes ( ) , key ) ; ProcessCounterSignatures ( ) ; }
Create a signature for the message if one does not exist .
3,147
public boolean validate ( OneKey cnKey ) throws CoseException { CBORObject obj = CBORObject . NewArray ( ) ; obj . Add ( contextString ) ; if ( objProtected . size ( ) > 0 ) obj . Add ( rgbProtected ) ; else obj . Add ( CBORObject . FromObject ( new byte [ 0 ] ) ) ; obj . Add ( externalData ) ; obj . Add ( rgbContent ) ; return validateSignature ( obj . EncodeToBytes ( ) , rgbSignature , cnKey ) ; }
Validate the signature on the message using the passed in key .
3,148
private Label addEnterTransaction ( CodeBuilder b , String opType , LocalVariable txnVar ) { if ( ! alwaysHasTxn ( opType ) ) { return null ; } TypeDesc repositoryType = TypeDesc . forClass ( Repository . class ) ; TypeDesc transactionType = TypeDesc . forClass ( Transaction . class ) ; TypeDesc triggerSupportType = TypeDesc . forClass ( TriggerSupport . class ) ; TypeDesc masterSupportType = TypeDesc . forClass ( MasterSupport . class ) ; TypeDesc isolationLevelType = TypeDesc . forClass ( IsolationLevel . class ) ; b . loadThis ( ) ; b . loadField ( StorableGenerator . SUPPORT_FIELD_NAME , triggerSupportType ) ; b . invokeInterface ( masterSupportType , "getRootRepository" , repositoryType , null ) ; if ( requiresTxnForUpdate ( opType ) ) { b . invokeInterface ( repositoryType , ENTER_TRANSACTION_METHOD_NAME , transactionType , null ) ; b . storeLocal ( txnVar ) ; b . loadLocal ( txnVar ) ; b . loadConstant ( true ) ; b . invokeInterface ( transactionType , SET_FOR_UPDATE_METHOD_NAME , null , new TypeDesc [ ] { TypeDesc . BOOLEAN } ) ; } else { LocalVariable repoVar = b . createLocalVariable ( null , repositoryType ) ; b . storeLocal ( repoVar ) ; b . loadLocal ( repoVar ) ; b . invokeInterface ( repositoryType , GET_TRANSACTION_ISOLATION_LEVEL_METHOD_NAME , isolationLevelType , null ) ; Label notInTxn = b . createLabel ( ) ; b . ifNullBranch ( notInTxn , true ) ; b . loadNull ( ) ; Label storeTxn = b . createLabel ( ) ; b . branch ( storeTxn ) ; notInTxn . setLocation ( ) ; b . loadLocal ( repoVar ) ; b . invokeInterface ( repositoryType , ENTER_TRANSACTION_METHOD_NAME , transactionType , null ) ; storeTxn . setLocation ( ) ; b . storeLocal ( txnVar ) ; } return b . createLabel ( ) . setLocation ( ) ; }
Generates code to enter a transaction if required and if none in progress .
3,149
private void unsetVersionProperty ( CodeBuilder b ) throws SupportException { StorableProperty < ? > property = mInfo . getVersionProperty ( ) ; { String stateFieldName = StorableGenerator . PROPERTY_STATE_FIELD_NAME + ( property . getNumber ( ) >> 4 ) ; b . loadThis ( ) ; b . loadThis ( ) ; b . loadField ( stateFieldName , TypeDesc . INT ) ; int shift = ( property . getNumber ( ) & 0xf ) * 2 ; b . loadConstant ( ~ ( StorableGenerator . PROPERTY_STATE_MASK << shift ) ) ; b . math ( Opcode . IAND ) ; b . storeField ( stateFieldName , TypeDesc . INT ) ; } TypeDesc type = TypeDesc . forClass ( property . getType ( ) ) ; b . loadThis ( ) ; CodeBuilderUtil . blankValue ( b , type ) ; b . storeField ( property . getName ( ) , type ) ; }
Sets the version property to its initial uninitialized state .
3,150
private void addNormalizationRollback ( CodeBuilder b , Label doTryStart , List < PropertyCopy > unnormalized ) { if ( unnormalized == null ) { return ; } Label doTryEnd = b . createLabel ( ) . setLocation ( ) ; b . dup ( ) ; Label success = b . createLabel ( ) ; b . ifZeroComparisonBranch ( success , "!=" ) ; for ( int i = 0 ; i < 2 ; i ++ ) { if ( i == 0 ) { } else { b . exceptionHandler ( doTryStart , doTryEnd , null ) ; } for ( PropertyCopy copy : unnormalized ) { copy . restore ( b ) ; } if ( i == 0 ) { b . branch ( success ) ; } else { b . throwObject ( ) ; } } success . setLocation ( ) ; }
Assumes a boolean is on the stack as returned by doTryInsert or doTryUpdate .
3,151
protected CBORObject EncodeCBORObject ( ) throws CoseException { if ( rgbEncrypt == null ) throw new CoseException ( "Encrypt function not called" ) ; CBORObject obj = CBORObject . NewArray ( ) ; if ( objProtected . size ( ) > 0 ) obj . Add ( objProtected . EncodeToBytes ( ) ) ; else obj . Add ( CBORObject . FromObject ( new byte [ 0 ] ) ) ; obj . Add ( objUnprotected ) ; if ( emitContent ) obj . Add ( rgbEncrypt ) ; else obj . Add ( CBORObject . Null ) ; return obj ; }
Internal function used to construct the CBORObject
3,152
public static int encodeDesc ( Integer value , byte [ ] dst , int dstOffset ) { if ( value == null ) { dst [ dstOffset ] = NULL_BYTE_LOW ; return 1 ; } else { dst [ dstOffset ] = NOT_NULL_BYTE_LOW ; DataEncoder . encode ( ~ value . intValue ( ) , dst , dstOffset + 1 ) ; return 5 ; } }
Encodes the given signed Integer object into exactly 1 or 5 bytes for descending order . If the Integer object is never expected to be null consider encoding as an int primitive .
3,153
public static int encodeDesc ( Long value , byte [ ] dst , int dstOffset ) { if ( value == null ) { dst [ dstOffset ] = NULL_BYTE_LOW ; return 1 ; } else { dst [ dstOffset ] = NOT_NULL_BYTE_LOW ; DataEncoder . encode ( ~ value . longValue ( ) , dst , dstOffset + 1 ) ; return 9 ; } }
Encodes the given signed Long object into exactly 1 or 9 bytes for descending order . If the Long object is never expected to be null consider encoding as a long primitive .
3,154
public static int encodeDesc ( Byte value , byte [ ] dst , int dstOffset ) { if ( value == null ) { dst [ dstOffset ] = NULL_BYTE_LOW ; return 1 ; } else { dst [ dstOffset ] = NOT_NULL_BYTE_LOW ; dst [ dstOffset + 1 ] = ( byte ) ( value ^ 0x7f ) ; return 2 ; } }
Encodes the given signed Byte object into exactly 1 or 2 bytes for descending order . If the Byte object is never expected to be null consider encoding as a byte primitive .
3,155
public static int encodeDesc ( Short value , byte [ ] dst , int dstOffset ) { if ( value == null ) { dst [ dstOffset ] = NULL_BYTE_LOW ; return 1 ; } else { dst [ dstOffset ] = NOT_NULL_BYTE_LOW ; DataEncoder . encode ( ( short ) ~ value . shortValue ( ) , dst , dstOffset + 1 ) ; return 3 ; } }
Encodes the given signed Short object into exactly 1 or 3 bytes for descending order . If the Short object is never expected to be null consider encoding as a short primitive .
3,156
public static int encodeDesc ( Character value , byte [ ] dst , int dstOffset ) { if ( value == null ) { dst [ dstOffset ] = NULL_BYTE_LOW ; return 1 ; } else { dst [ dstOffset ] = NOT_NULL_BYTE_LOW ; DataEncoder . encode ( ( char ) ~ value . charValue ( ) , dst , dstOffset + 1 ) ; return 3 ; } }
Encodes the given Character object into exactly 1 or 3 bytes for descending order . If the Character object is never expected to be null consider encoding as a char primitive .
3,157
public static void encodeDesc ( Boolean value , byte [ ] dst , int dstOffset ) { if ( value == null ) { dst [ dstOffset ] = NULL_BYTE_LOW ; } else { dst [ dstOffset ] = value . booleanValue ( ) ? ( byte ) 127 : ( byte ) 128 ; } }
Encodes the given Boolean object into exactly 1 byte for descending order .
3,158
public static void encodeDesc ( float value , byte [ ] dst , int dstOffset ) { int bits = Float . floatToIntBits ( value ) ; if ( bits >= 0 ) { bits ^= 0x7fffffff ; } dst [ dstOffset ] = ( byte ) ( bits >> 24 ) ; dst [ dstOffset + 1 ] = ( byte ) ( bits >> 16 ) ; dst [ dstOffset + 2 ] = ( byte ) ( bits >> 8 ) ; dst [ dstOffset + 3 ] = ( byte ) bits ; }
Encodes the given float into exactly 4 bytes for descending order .
3,159
public static void encodeDesc ( Float value , byte [ ] dst , int dstOffset ) { if ( value == null ) { DataEncoder . encode ( ~ 0x7fffffff , dst , dstOffset ) ; } else { encodeDesc ( value . floatValue ( ) , dst , dstOffset ) ; } }
Encodes the given Float object into exactly 4 bytes for descending order . A non - canonical NaN value is used to represent null .
3,160
public static void encodeDesc ( double value , byte [ ] dst , int dstOffset ) { long bits = Double . doubleToLongBits ( value ) ; if ( bits >= 0 ) { bits ^= 0x7fffffffffffffffL ; } int w = ( int ) ( bits >> 32 ) ; dst [ dstOffset ] = ( byte ) ( w >> 24 ) ; dst [ dstOffset + 1 ] = ( byte ) ( w >> 16 ) ; dst [ dstOffset + 2 ] = ( byte ) ( w >> 8 ) ; dst [ dstOffset + 3 ] = ( byte ) w ; w = ( int ) bits ; dst [ dstOffset + 4 ] = ( byte ) ( w >> 24 ) ; dst [ dstOffset + 5 ] = ( byte ) ( w >> 16 ) ; dst [ dstOffset + 6 ] = ( byte ) ( w >> 8 ) ; dst [ dstOffset + 7 ] = ( byte ) w ; }
Encodes the given double into exactly 8 bytes for descending order .
3,161
public static void encodeDesc ( Double value , byte [ ] dst , int dstOffset ) { if ( value == null ) { DataEncoder . encode ( ~ 0x7fffffffffffffffL , dst , dstOffset ) ; } else { encodeDesc ( value . doubleValue ( ) , dst , dstOffset ) ; } }
Encodes the given Double object into exactly 8 bytes for descending order . A non - canonical NaN value is used to represent null .
3,162
public static int encodeDesc ( BigInteger value , byte [ ] dst , int dstOffset ) { if ( value == null ) { dst [ dstOffset ] = NULL_BYTE_LOW ; return 1 ; } byte [ ] bytes = value . toByteArray ( ) ; int bytesLength = bytes . length ; int headerSize ; if ( bytesLength < 0x7f ) { if ( value . signum ( ) < 0 ) { dst [ dstOffset ] = ( byte ) ( bytesLength + 0x7f ) ; } else { dst [ dstOffset ] = ( byte ) ( 0x80 - bytesLength ) ; } headerSize = 1 ; } else { dst [ dstOffset ] = ( byte ) ( value . signum ( ) < 0 ? 0xfe : 1 ) ; int encodedLen = value . signum ( ) < 0 ? bytesLength : - bytesLength ; DataEncoder . encode ( encodedLen , dst , dstOffset + 1 ) ; headerSize = 5 ; } dstOffset += headerSize ; for ( int i = 0 ; i < bytesLength ; i ++ ) { dst [ dstOffset + i ] = ( byte ) ~ bytes [ i ] ; } return headerSize + bytesLength ; }
Encodes the given optional BigInteger into a variable amount of bytes for descending order . If the BigInteger is null exactly 1 byte is written . Otherwise the amount written can be determined by calling calculateEncodedLength .
3,163
public static int calculateEncodedLength ( BigInteger value ) { if ( value == null ) { return 1 ; } int bytesLength = ( value . bitLength ( ) >> 3 ) + 1 ; return bytesLength < 0x7f ? ( 1 + bytesLength ) : ( 5 + bytesLength ) ; }
Returns the amount of bytes required to encode a BigInteger .
3,164
public static int encodeDesc ( BigDecimal value , byte [ ] dst , int dstOffset ) { if ( value == null ) { dst [ dstOffset ] = NULL_BYTE_LOW ; return 1 ; } if ( value . signum ( ) == 0 ) { dst [ dstOffset ] = ( byte ) 0x7f ; return 1 ; } return encode ( value ) . copyDescTo ( dst , dstOffset ) ; }
Encodes the given optional BigDecimal into a variable amount of bytes for descending order . If the BigDecimal is null exactly 1 byte is written . Otherwise the amount written can be determined by calling calculateEncodedLength .
3,165
public static int calculateEncodedLength ( BigDecimal value ) { if ( value == null || value . signum ( ) == 0 ) { return 1 ; } return encode ( value ) . mLength ; }
Returns the amount of bytes required to encode a BigDecimal .
3,166
public static int encode ( byte [ ] value , int valueOffset , int valueLength , byte [ ] dst , int dstOffset ) { return encode ( value , valueOffset , valueLength , dst , dstOffset , 0 ) ; }
Encodes the given optional unsigned byte array into a variable amount of bytes . If the byte array is null exactly 1 byte is written . Otherwise the amount written can be determined by calling calculateEncodedLength .
3,167
public static int encodeDesc ( byte [ ] value , byte [ ] dst , int dstOffset ) { if ( value == null ) { dst [ dstOffset ] = NULL_BYTE_LOW ; return 1 ; } return encode ( value , 0 , value . length , dst , dstOffset , - 1 ) ; }
Encodes the given optional unsigned byte array into a variable amount of bytes for descending order . If the byte array is null exactly 1 byte is written . Otherwise the amount written is determined by calling calculateEncodedLength .
3,168
private static void emitDigit ( int value , byte [ ] dst , int dstOffset , int xorMask ) { int a = ( value * 21845 ) >> 22 ; int b = value - ( ( a << 7 ) + ( a << 6 ) ) ; if ( b == 192 ) { a ++ ; b = 0 ; } dst [ dstOffset ++ ] = ( byte ) ( ( a + 32 ) ^ xorMask ) ; dst [ dstOffset ] = ( byte ) ( ( b + 32 ) ^ xorMask ) ; }
Emits a base - 32768 digit using exactly two bytes . The first byte is in the range 32 .. 202 and the second byte is in the range 32 .. 223 .
3,169
public static int calculateEncodedStringLength ( String value ) { int encodedLen = 1 ; if ( value != null ) { int valueLength = value . length ( ) ; for ( int i = 0 ; i < valueLength ; i ++ ) { int c = value . charAt ( i ) ; if ( c <= ( 0x7f - 2 ) ) { encodedLen ++ ; } else if ( c <= ( 12415 - 2 ) ) { encodedLen += 2 ; } else { if ( c >= 0xd800 && c <= 0xdbff ) { if ( i + 1 < valueLength ) { int c2 = value . charAt ( i + 1 ) ; if ( c2 >= 0xdc00 && c2 <= 0xdfff ) { i ++ ; } } } encodedLen += 3 ; } } } return encodedLen ; }
Returns the amount of bytes required to encode the given String .
3,170
public static byte [ ] encodeSingleDesc ( byte [ ] value , int prefixPadding , int suffixPadding ) { int length = value . length ; if ( prefixPadding <= 0 && suffixPadding <= 0 && length == 0 ) { return value ; } byte [ ] dst = new byte [ prefixPadding + length + suffixPadding ] ; while ( -- length >= 0 ) { dst [ prefixPadding + length ] = ( byte ) ( ~ value [ length ] ) ; } return dst ; }
Encodes the given byte array for use when there is only a single required property descending order whose type is a byte array . The original byte array is returned if the length and padding lengths are zero .
3,171
public static byte [ ] encodeSingleNullableDesc ( byte [ ] value , int prefixPadding , int suffixPadding ) { if ( prefixPadding <= 0 && suffixPadding <= 0 ) { if ( value == null ) { return new byte [ ] { NULL_BYTE_LOW } ; } int length = value . length ; if ( length == 0 ) { return new byte [ ] { NOT_NULL_BYTE_LOW } ; } byte [ ] dst = new byte [ 1 + length ] ; dst [ 0 ] = NOT_NULL_BYTE_LOW ; while ( -- length >= 0 ) { dst [ 1 + length ] = ( byte ) ( ~ value [ length ] ) ; } return dst ; } if ( value == null ) { byte [ ] dst = new byte [ prefixPadding + 1 + suffixPadding ] ; dst [ prefixPadding ] = NULL_BYTE_LOW ; return dst ; } int length = value . length ; byte [ ] dst = new byte [ prefixPadding + 1 + length + suffixPadding ] ; dst [ prefixPadding ] = NOT_NULL_BYTE_LOW ; while ( -- length >= 0 ) { dst [ prefixPadding + 1 + length ] = ( byte ) ( ~ value [ length ] ) ; } return dst ; }
Encodes the given byte array for use when there is only a single nullable property descending order whose type is a byte array .
3,172
public static void encode ( int value , byte [ ] dst , int dstOffset ) { value ^= 0x80000000 ; dst [ dstOffset ] = ( byte ) ( value >> 24 ) ; dst [ dstOffset + 1 ] = ( byte ) ( value >> 16 ) ; dst [ dstOffset + 2 ] = ( byte ) ( value >> 8 ) ; dst [ dstOffset + 3 ] = ( byte ) value ; }
Encodes the given signed integer into exactly 4 bytes .
3,173
public static int encode ( Integer value , byte [ ] dst , int dstOffset ) { if ( value == null ) { dst [ dstOffset ] = NULL_BYTE_HIGH ; return 1 ; } else { dst [ dstOffset ] = NOT_NULL_BYTE_HIGH ; encode ( value . intValue ( ) , dst , dstOffset + 1 ) ; return 5 ; } }
Encodes the given signed Integer object into exactly 1 or 5 bytes . If the Integer object is never expected to be null consider encoding as an int primitive .
3,174
public static void encode ( long value , byte [ ] dst , int dstOffset ) { int w = ( ( int ) ( value >> 32 ) ) ^ 0x80000000 ; dst [ dstOffset ] = ( byte ) ( w >> 24 ) ; dst [ dstOffset + 1 ] = ( byte ) ( w >> 16 ) ; dst [ dstOffset + 2 ] = ( byte ) ( w >> 8 ) ; dst [ dstOffset + 3 ] = ( byte ) w ; w = ( int ) value ; dst [ dstOffset + 4 ] = ( byte ) ( w >> 24 ) ; dst [ dstOffset + 5 ] = ( byte ) ( w >> 16 ) ; dst [ dstOffset + 6 ] = ( byte ) ( w >> 8 ) ; dst [ dstOffset + 7 ] = ( byte ) w ; }
Encodes the given signed long into exactly 8 bytes .
3,175
public static int encode ( Long value , byte [ ] dst , int dstOffset ) { if ( value == null ) { dst [ dstOffset ] = NULL_BYTE_HIGH ; return 1 ; } else { dst [ dstOffset ] = NOT_NULL_BYTE_HIGH ; encode ( value . longValue ( ) , dst , dstOffset + 1 ) ; return 9 ; } }
Encodes the given signed Long object into exactly 1 or 9 bytes . If the Long object is never expected to be null consider encoding as a long primitive .
3,176
public static int encode ( Byte value , byte [ ] dst , int dstOffset ) { if ( value == null ) { dst [ dstOffset ] = NULL_BYTE_HIGH ; return 1 ; } else { dst [ dstOffset ] = NOT_NULL_BYTE_HIGH ; dst [ dstOffset + 1 ] = ( byte ) ( value ^ 0x80 ) ; return 2 ; } }
Encodes the given signed Byte object into exactly 1 or 2 bytes . If the Byte object is never expected to be null consider encoding as a byte primitive .
3,177
public static void encode ( short value , byte [ ] dst , int dstOffset ) { value ^= 0x8000 ; dst [ dstOffset ] = ( byte ) ( value >> 8 ) ; dst [ dstOffset + 1 ] = ( byte ) value ; }
Encodes the given signed short into exactly 2 bytes .
3,178
public static int encode ( Short value , byte [ ] dst , int dstOffset ) { if ( value == null ) { dst [ dstOffset ] = NULL_BYTE_HIGH ; return 1 ; } else { dst [ dstOffset ] = NOT_NULL_BYTE_HIGH ; encode ( value . shortValue ( ) , dst , dstOffset + 1 ) ; return 3 ; } }
Encodes the given signed Short object into exactly 1 or 3 bytes . If the Short object is never expected to be null consider encoding as a short primitive .
3,179
public static int encode ( Character value , byte [ ] dst , int dstOffset ) { if ( value == null ) { dst [ dstOffset ] = NULL_BYTE_HIGH ; return 1 ; } else { dst [ dstOffset ] = NOT_NULL_BYTE_HIGH ; encode ( value . charValue ( ) , dst , dstOffset + 1 ) ; return 3 ; } }
Encodes the given Character object into exactly 1 or 3 bytes . If the Character object is never expected to be null consider encoding as a char primitive .
3,180
public static void encode ( Boolean value , byte [ ] dst , int dstOffset ) { if ( value == null ) { dst [ dstOffset ] = NULL_BYTE_HIGH ; } else { dst [ dstOffset ] = value . booleanValue ( ) ? ( byte ) 128 : ( byte ) 127 ; } }
Encodes the given Boolean object into exactly 1 byte .
3,181
public static void encode ( float value , byte [ ] dst , int dstOffset ) { int bits = Float . floatToIntBits ( value ) ; bits ^= ( bits < 0 ) ? 0xffffffff : 0x80000000 ; dst [ dstOffset ] = ( byte ) ( bits >> 24 ) ; dst [ dstOffset + 1 ] = ( byte ) ( bits >> 16 ) ; dst [ dstOffset + 2 ] = ( byte ) ( bits >> 8 ) ; dst [ dstOffset + 3 ] = ( byte ) bits ; }
Encodes the given float into exactly 4 bytes .
3,182
public static void encode ( Float value , byte [ ] dst , int dstOffset ) { if ( value == null ) { encode ( 0x7fffffff , dst , dstOffset ) ; } else { encode ( value . floatValue ( ) , dst , dstOffset ) ; } }
Encodes the given Float object into exactly 4 bytes . A non - canonical NaN value is used to represent null .
3,183
public static int calculateEncodedLength ( BigInteger value ) { if ( value == null ) { return 1 ; } int byteCount = ( value . bitLength ( ) >> 3 ) + 1 ; return unsignedVarIntLength ( byteCount ) + byteCount ; }
Returns the amount of bytes required to encode the given BigInteger .
3,184
public static int calculateEncodedLength ( BigDecimal value ) { if ( value == null ) { return 1 ; } return signedVarIntLength ( value . scale ( ) ) + calculateEncodedLength ( value . unscaledValue ( ) ) ; }
Returns the amount of bytes required to encode the given BigDecimal .
3,185
public static int writeLength ( int valueLength , OutputStream out ) throws IOException { if ( valueLength < 128 ) { out . write ( valueLength ) ; return 1 ; } else if ( valueLength < 16384 ) { out . write ( ( valueLength >> 8 ) | 0x80 ) ; out . write ( valueLength ) ; return 2 ; } else if ( valueLength < 2097152 ) { out . write ( ( valueLength >> 16 ) | 0xc0 ) ; out . write ( valueLength >> 8 ) ; out . write ( valueLength ) ; return 3 ; } else if ( valueLength < 268435456 ) { out . write ( ( valueLength >> 24 ) | 0xe0 ) ; out . write ( valueLength >> 16 ) ; out . write ( valueLength >> 8 ) ; out . write ( valueLength ) ; return 4 ; } else { out . write ( 0xf0 ) ; out . write ( valueLength >> 24 ) ; out . write ( valueLength >> 16 ) ; out . write ( valueLength >> 8 ) ; out . write ( valueLength ) ; return 5 ; } }
Writes a positive length value in up to five bytes .
3,186
public static byte [ ] encodeSingle ( byte [ ] value , int prefixPadding , int suffixPadding ) { if ( prefixPadding <= 0 && suffixPadding <= 0 ) { return value ; } int length = value . length ; byte [ ] dst = new byte [ prefixPadding + length + suffixPadding ] ; System . arraycopy ( value , 0 , dst , prefixPadding , length ) ; return dst ; }
Encodes the given byte array for use when there is only a single property whose type is a byte array . The original byte array is returned if the padding lengths are zero .
3,187
public static byte [ ] encodeSingleNullable ( byte [ ] value , int prefixPadding , int suffixPadding ) { if ( prefixPadding <= 0 && suffixPadding <= 0 ) { if ( value == null ) { return new byte [ ] { NULL_BYTE_HIGH } ; } int length = value . length ; if ( length == 0 ) { return new byte [ ] { NOT_NULL_BYTE_HIGH } ; } byte [ ] dst = new byte [ 1 + length ] ; dst [ 0 ] = NOT_NULL_BYTE_HIGH ; System . arraycopy ( value , 0 , dst , 1 , length ) ; return dst ; } if ( value == null ) { byte [ ] dst = new byte [ prefixPadding + 1 + suffixPadding ] ; dst [ prefixPadding ] = NULL_BYTE_HIGH ; return dst ; } int length = value . length ; byte [ ] dst = new byte [ prefixPadding + 1 + length + suffixPadding ] ; dst [ prefixPadding ] = NOT_NULL_BYTE_HIGH ; System . arraycopy ( value , 0 , dst , prefixPadding + 1 , length ) ; return dst ; }
Encodes the given byte array for use when there is only a single nullable property whose type is a byte array .
3,188
@ SuppressWarnings ( "unchecked" ) public < C extends Capability > C getCapability ( Class < C > capabilityType ) { if ( capabilityType . isInstance ( this ) ) { return ( C ) this ; } return null ; }
Default implementation checks if Repository implements Capability interface and if so returns the Repository .
3,189
public synchronized void setAutoShutdownEnabled ( boolean enabled ) { try { if ( mShutdownHook == null ) { if ( enabled ) { ShutdownHook hook = new ShutdownHook ( this ) ; Runtime . getRuntime ( ) . addShutdownHook ( hook ) ; mShutdownHook = hook ; } } else { if ( ! enabled ) { Runtime . getRuntime ( ) . removeShutdownHook ( mShutdownHook ) ; mShutdownHook = null ; } } } catch ( IllegalStateException e ) { } }
Required by ShutdownCapability .
3,190
public final void setValidator ( final Validator < Type > validator ) { Condition . INSTANCE . ensureNotNull ( validator , "The validator may not be null" ) ; this . validator = validator ; }
Sets the validator whose result should be negated .
3,191
private void setupKey ( OneKey key ) throws CoseException { CBORObject cn2 ; CBORObject cn ; cnKey = key ; if ( rgbSignature != null ) return ; cn = key . get ( KeyKeys . Algorithm ) ; if ( cn != null ) { cn2 = findAttribute ( HeaderKeys . Algorithm ) ; if ( cn2 == null ) addAttribute ( HeaderKeys . Algorithm , cn , Attribute . PROTECTED ) ; } cn = key . get ( KeyKeys . KeyId ) ; if ( cn != null ) { cn2 = findAttribute ( HeaderKeys . KID ) ; if ( cn2 == null ) addAttribute ( HeaderKeys . KID , cn , Attribute . UNPROTECTED ) ; } }
Set the key on the object if there is not a signature on this object then set the algorithm and the key id from the key if they exist on the key and do not exist in the message .
3,192
public static Repository newRepository ( ) { try { MapRepositoryBuilder builder = new MapRepositoryBuilder ( ) ; return builder . build ( ) ; } catch ( RepositoryException e ) { throw new RuntimeException ( e ) ; } }
Convenience method to build a new MapRepository .
3,193
public void setLockTimeout ( int timeout , TimeUnit unit ) { if ( timeout < 0 || unit == null ) { throw new IllegalArgumentException ( ) ; } mLockTimeout = timeout ; mLockTimeoutUnit = unit ; }
Set the lock timeout . Default value is 500 milliseconds .
3,194
public final void setIcon ( final Context context , final int resourceId ) { Condition . INSTANCE . ensureNotNull ( context , "The context may not be null" ) ; this . icon = ContextCompat . getDrawable ( context , resourceId ) ; }
Sets the icon which should be shown if the validation fails .
3,195
private void obtainPasswordVerificationPrefix ( final TypedArray typedArray ) { String format = typedArray . getString ( R . styleable . PasswordEditText_passwordVerificationPrefix ) ; if ( format == null ) { format = getResources ( ) . getString ( R . string . password_verification_prefix ) ; } setPasswordVerificationPrefix ( format ) ; }
Obtains the prefix of helper texts which are shown depending on the password strength from a specific typed array .
3,196
private TextWatcher createTextChangeListener ( ) { return new TextWatcher ( ) { public final void beforeTextChanged ( final CharSequence s , final int start , final int count , final int after ) { } public final void onTextChanged ( final CharSequence s , final int start , final int before , final int count ) { } public final void afterTextChanged ( final Editable s ) { verifyPasswordStrength ( ) ; } } ; }
Creates and returns a listener which allows to verify the password strength when the password has been changed .
3,197
private void verifyPasswordStrength ( ) { if ( isEnabled ( ) && ! constraints . isEmpty ( ) && ! TextUtils . isEmpty ( getText ( ) ) ) { float score = getPasswordStrength ( ) ; adaptHelperText ( score ) ; } else { setHelperText ( regularHelperText ) ; } }
Verifies the strength of the current password depending on the constraints which have been added and adapts the appearance of the view accordingly .
3,198
private float getPasswordStrength ( ) { int absoluteScore = 0 ; CharSequence password = getView ( ) . getText ( ) ; for ( Constraint < CharSequence > constraint : constraints ) { if ( constraint . isSatisfied ( password ) ) { absoluteScore ++ ; } } return ( ( float ) absoluteScore / ( float ) constraints . size ( ) ) ; }
Returns the strength of the current password depending on the constraints which have been added .
3,199
private void adaptHelperText ( final float score ) { if ( ! helperTexts . isEmpty ( ) ) { CharSequence helperText = getHelperText ( score ) ; if ( helperText != null ) { int color = getHelperTextColor ( score ) ; helperText = "<font color=\"" + color + "\">" + helperText + "</font>" ; String prefix = getPasswordVerificationPrefix ( ) ; if ( prefix != null ) { prefix = "<font color=\"" + regularHelperTextColor + "\">" + prefix + ": </font>" ; } else { prefix = "" ; } setHelperText ( Html . fromHtml ( prefix + helperText ) ) ; } else { setHelperText ( regularHelperText ) ; } } else { setHelperText ( regularHelperText ) ; } }
Adapts the helper text depending on a specific password strength .