return getLong( obj ); return uuid( obj ); return string( obj ); return getBoolean( obj ); return getInt( obj ); return getDouble( obj ); return getFloat( obj ); return bytes( obj ); return bytebuffer( obj );
public ByteBuffer asciibuffer( String s ) { return ByteBuffer.wrap( ascii( s ) ); }
public static Map<String, Object> coerceMap( Map<String, Class<?>> types, Map<String, Object> values ) { for ( Map.Entry<String, Object> entry : values.entrySet() ) { if ( types.containsKey( entry.getKey() ) ) { values.put( entry.getKey(), coerce( types.get( entry.getKey() ), entry.getValue() ) ); } } return values; } }
public UserInfo( UUID applicationId, Map<String, Object> properties ) { this.applicationId = applicationId; id = uuid( properties.remove( PROPERTY_UUID ) ); username = string( properties.remove( PROPERTY_USERNAME ) ); name = string( properties.remove( PROPERTY_NAME ) ); email = string( properties.remove( PROPERTY_EMAIL ) ); confirmed = getBoolean( properties.remove( PROPERTY_CONFIRMED ) ); activated = getBoolean( properties.remove( PROPERTY_ACTIVATED ) ); disabled = getBoolean( properties.remove( PROPERTY_DISABLED ) ); admin = getBoolean( properties.remove( PROPERTY_ADMIN) ); this.properties = properties; }
/** * @param s * @return */ public static byte[] ascii( String s ) { if ( s == null ) { return new byte[0]; } return bytes( s, ASCII_ENCODING ); }
/** * @param obj * @return */ public static UUID uuid( Object obj ) { return uuid( obj, UUIDUtils.ZERO_UUID ); }
/** * @param bytes * @return */ public static String string( byte[] bytes ) { if ( bytes == null ) { return null; } return string( bytes, 0, bytes.length, UTF8_ENCODING ); }
public static ByteBuffer serializeEntityProperty( String entityType, String propertyName, Object propertyValue ) { ByteBuffer bytes = null; if ( PROPERTY_UUID.equals( propertyName ) ) { bytes = bytebuffer( uuid( propertyValue ) ); } else if ( PROPERTY_TYPE.equals( propertyName ) ) { bytes = bytebuffer( string( propertyValue ) ); } else { bytes = Schema.serializePropertyValueToJsonBinary( toJsonNode( propertyValue ) ); if ( Schema.getDefaultSchema().isPropertyEncrypted( entityType, propertyName ) ) { bytes.rewind(); bytes = encrypt( bytes ); } } return bytes; }
/** Returns a UUID that is -1 of the passed uuid, sorted by time uuid only */ public static UUID decrement( UUID uuid ) { if ( !isTimeBased( uuid ) ) { throw new IllegalArgumentException( "The uuid must be a time type" ); } //timestamp is in the 60 bit timestamp long timestamp = uuid.timestamp(); timestamp--; if ( timestamp < 0 ) { throw new IllegalArgumentException( "You must specify a time uuid with a timestamp > 0" ); } //get our bytes, then set the smaller timestamp into it byte[] uuidBytes = bytes( uuid ); setTime( uuidBytes, timestamp ); return uuid( uuidBytes ); }
public static List<ByteBuffer> bytebuffers( List<?> l ) { List<ByteBuffer> results = new ArrayList<ByteBuffer>( l.size() ); for ( Object o : l ) { results.add( bytebuffer( o ) ); } return results; }
columnNames[i] = entityHasDictionary ? bytebuffer( elementNames[i] ) : DynamicComposite.toByteBuffer( elementNames[i] ); values = new HashMap<String, Object>(); for ( HColumn<ByteBuffer, ByteBuffer> result : results.getColumns() ) { String name = entityHasDictionary ? string( result.getName() ) : DynamicComposite.fromByteBuffer( result.getName() ).get( 0, se ); if ( entityHasDictionary && coTypeIsBasic ) { values.put( name, object( dictionaryCoType, result.getValue() ) );
public static boolean isUserActivated( Entity user ) { if ( user == null ) { return false; } return getBoolean( user.getProperty( PROPERTY_ACTIVATED ) ); }
@Override public Map<String, Role> getRolesWithTitles( Set<String> roleNames ) throws Exception { Map<String, Role> rolesWithTitles = new HashMap<String, Role>(); Map<String, Object> nameResults = null; if ( roleNames != null ) { nameResults = getDictionaryElementValues( getApplicationRef(), DICTIONARY_ROLENAMES, roleNames.toArray( new String[roleNames.size()] ) ); } else { nameResults = cast( getDictionaryAsMap( getApplicationRef(), DICTIONARY_ROLENAMES ) ); roleNames = nameResults.keySet(); } Map<String, Object> timeResults = getDictionaryElementValues( getApplicationRef(), DICTIONARY_ROLETIMES, roleNames.toArray( new String[roleNames.size()] ) ); for ( String roleName : roleNames ) { String savedTitle = string( nameResults.get( roleName ) ); // no title, skip the role if ( savedTitle == null ) { continue; } Role newRole = new Role(); newRole.setName( roleName ); newRole.setTitle( savedTitle ); newRole.setInactivity( getLong( timeResults.get( roleName ) ) ); rolesWithTitles.put( roleName, newRole ); } return rolesWithTitles; }
long t = getLong( first( params.get( "time" ) ) ); if ( t > 0 ) { query.setLastTimestamp( t ); query.setUpdate( ConversionUtils.getBoolean( first( params.get( "update" ) ) ) ); query.setSynchronized( ConversionUtils.getBoolean( first( params.get( "synchronized" ) ) ) ); query.setTimeout( ConversionUtils.getLong( first( params.get( "timeout" ) ) ) );
byteStream.write( uuidToBytesNullOk( connectingEntity.getUuid() ) ); UUID id = connection.getUuid(); byteStream.write( ascii( StringUtils.lowerCase( type ) ) ); byteStream.write( uuidToBytesNullOk( id ) ); byteStream.write( ascii( StringUtils.lowerCase( connectionType ) ) ); byteStream.write( ascii( StringUtils.lowerCase( connectedEntityType ) ) );
cass.getColumn(cass.getApplicationKeyspace(applicationId), dictionaryCf, CassandraPersistenceUtils.key(entity.getUuid(), dictionaryName), entityHasDictionary ? bytebuffer(elementName) : DynamicComposite.toByteBuffer(elementName), be, be); value = object( dictionaryCoType, result.getValue() );
@SuppressWarnings("unchecked") public Message( Map<String, Object> properties ) { this.properties.putAll( coerceMap( ( Map<String, Class<?>> ) cast( MESSAGE_PROPERTIES ), properties ) ); }
public static double getDouble( Object obj ) { if ( obj instanceof Double ) { return ( Double ) obj; } if ( obj instanceof Number ) { return ( ( Number ) obj ).doubleValue(); } if ( obj instanceof String ) { return NumberUtils.toDouble( ( String ) obj ); } if ( obj instanceof Date ) { return ( ( Date ) obj ).getTime(); } if ( obj instanceof byte[] ) { return getDouble( ( byte[] ) obj ); } if ( obj instanceof ByteBuffer ) { return getDouble( ( ByteBuffer ) obj ); } return 0; }