Skip to content

Commit

Permalink
Partial code cleanup (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
kao78 authored Aug 9, 2022
1 parent 95e4956 commit de21a43
Show file tree
Hide file tree
Showing 72 changed files with 233 additions and 307 deletions.
4 changes: 2 additions & 2 deletions src/com/backendless/AbstractDataPermission.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ private <T> Object[] buildArgs( T dataObject, String principal, PermissionTypes
private <T> void serverCall( AsyncCallback<T> responder, String method, Object[] args, Class type )
{
if( responder == null )
Invoker.invokeSync( PERMISSION_SERVICE, method, args, new AdaptingResponder<T>( type, new PoJoAdaptingPolicy<T>() ) );
Invoker.invokeSync( PERMISSION_SERVICE, method, args, new AdaptingResponder<>( type, new PoJoAdaptingPolicy<T>() ) );
else
Invoker.invokeAsync( PERMISSION_SERVICE, method, args, responder, new AdaptingResponder<T>( type, new PoJoAdaptingPolicy<T>() ) );
Invoker.invokeAsync( PERMISSION_SERVICE, method, args, responder, new AdaptingResponder<>( type, new PoJoAdaptingPolicy<T>() ) );
}
}
11 changes: 0 additions & 11 deletions src/com/backendless/AndroidService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,13 @@
@Deprecated
public class AndroidService extends Service
{
@Override
public void onCreate()
{
super.onCreate();
}

@Override
public int onStartCommand( Intent intent, int flags, int startId )
{
return START_NOT_STICKY;
}

@Override
public void onDestroy()
{
super.onDestroy();
}

@Override
public IBinder onBind( Intent intent )
{
Expand Down
2 changes: 1 addition & 1 deletion src/com/backendless/Backendless.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public final class Backendless
private static final BackendlessPrefs prefs;

@Getter
private static Map<String, String> forwardableHeaders = Collections.unmodifiableMap( new HashMap<String, String>() );
private static final Map<String, String> forwardableHeaders = Collections.unmodifiableMap( new HashMap<String, String>() );

public static final FootprintsManager FootprintsManager = com.backendless.FootprintsManager.getInstance();
public static final UserService UserService = com.backendless.UserService.getInstance();
Expand Down
11 changes: 4 additions & 7 deletions src/com/backendless/BackendlessUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

public class BackendlessUser implements Serializable
{
private final Map<String, Object> properties = new HashMap<String, Object>();
private final Map<String, Object> properties = new HashMap<>();

public static final String PASSWORD_KEY = "password";
public static final String EMAIL_KEY = "email";
Expand All @@ -46,7 +46,7 @@ public BackendlessUser()
*/
public Map<String, Object> getProperties()
{
return new HashMap<String, Object>( properties );
return new HashMap<>( properties );
}

public void setProperties( Map<String, Object> properties )
Expand Down Expand Up @@ -151,18 +151,15 @@ public boolean equals( Object o )

BackendlessUser that = (BackendlessUser) o;

if( !properties.equals( that.properties ) )
return false;

return true;
return properties.equals( that.properties );
}

private Object marker;// = new Object();

@Override
public int hashCode()
{
Set<Object> refCache = new HashSet<Object>( );
Set<Object> refCache = new HashSet<>();
return hashCode( refCache );
}

Expand Down
12 changes: 6 additions & 6 deletions src/com/backendless/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private Cache()

public <T> ICache<T> with( String key, Class<? extends T> type )
{
return new CacheService<T>( type, key );
return new CacheService<>( type, key );
}

public void put( String key, Object object, int timeToLive, AsyncCallback<Object> callback )
Expand All @@ -79,7 +79,7 @@ public void put( String key, Object object, int timeToLive )

public <T> T get( String key, Class<? extends T> type )
{
byte[] bytes = Invoker.invokeSync( CACHE_SERVER_ALIAS, "getBytes", new Object[] { key }, new AdaptingResponder<byte[]>( byte[].class, new PoJoAdaptingPolicy<byte[]>() ) );
byte[] bytes = Invoker.invokeSync( CACHE_SERVER_ALIAS, "getBytes", new Object[] { key }, new AdaptingResponder<>( byte[].class, new PoJoAdaptingPolicy<byte[]>() ) );

if( bytes == null )
return null;
Expand All @@ -100,15 +100,15 @@ public void run()
try
{
T result = (T) get( key, asyncCallbackType );
ResponseCarrier.getInstance().deliverMessage( new AsyncMessage<T>( result, callback ) );
ResponseCarrier.getInstance().deliverMessage( new AsyncMessage<>( result, callback ) );
}
catch( BackendlessException e )
{
ResponseCarrier.getInstance().deliverMessage( new AsyncMessage<T>( new BackendlessFault( e ), callback ) );
ResponseCarrier.getInstance().deliverMessage( new AsyncMessage<>( new BackendlessFault( e ), callback ) );
}
catch( Exception e )
{
ResponseCarrier.getInstance().deliverMessage( new AsyncMessage<T>( new BackendlessFault( e ), callback ) );
ResponseCarrier.getInstance().deliverMessage( new AsyncMessage<>( new BackendlessFault( e ), callback ) );
}
}
} );
Expand Down Expand Up @@ -171,7 +171,7 @@ private static <T> IChainedResponder getChainedResponder()

private static Object deserialize( byte[] bytes, Type type )
{
Object object = null;
Object object;
try
{
object = weborb.util.io.Serializer.fromBytes( bytes, ISerializer.AMF3, true );
Expand Down
4 changes: 2 additions & 2 deletions src/com/backendless/Commerce.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private Commerce()

public GooglePlayPurchaseStatus validatePlayPurchase( String packageName, String productId, String token )
{
return (GooglePlayPurchaseStatus) Invoker.invokeSync( COMMERCE_MANAGER_SERVER_ALIAS, "validatePlayPurchase", new Object[] { packageName, productId, token } );
return Invoker.invokeSync( COMMERCE_MANAGER_SERVER_ALIAS, "validatePlayPurchase", new Object[] { packageName, productId, token } );
}

public void validatePlayPurchase( String packageName, String productId, String token,
Expand All @@ -56,7 +56,7 @@ public void validatePlayPurchase( String packageName, String productId, String t

public GooglePlaySubscriptionStatus getPlaySubscriptionsStatus( String packageName, String subscriptionId, String token )
{
return (GooglePlaySubscriptionStatus) Invoker.invokeSync( COMMERCE_MANAGER_SERVER_ALIAS, "getPlaySubscriptionsStatus", new Object[] { packageName, subscriptionId, token } );
return Invoker.invokeSync( COMMERCE_MANAGER_SERVER_ALIAS, "getPlaySubscriptionsStatus", new Object[] { packageName, subscriptionId, token } );
}

public void getPlaySubscriptionsStatus( String packageName, String subscriptionId, String token,
Expand Down
2 changes: 1 addition & 1 deletion src/com/backendless/Counters.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public <T> void getAndAdd( String counterName, Number value, AsyncCallback<T> re

public boolean compareAndSet( String counterName, Number expected, Number updated )
{
return (Boolean) Invoker.invokeSync( ATOMIC_MANAGER_SERVER_ALIAS, "compareAndSet", new Object[] { counterName, expected, updated } );
return Invoker.invokeSync( ATOMIC_MANAGER_SERVER_ALIAS, "compareAndSet", new Object[] { counterName, expected, updated } );
}

public void compareAndSet( String counterName, Number expected, Number updated, AsyncCallback<Boolean> responder )
Expand Down
9 changes: 4 additions & 5 deletions src/com/backendless/CustomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.backendless.async.callback.AsyncCallback;
import com.backendless.core.responder.AdaptingResponder;
import com.backendless.core.responder.policy.PoJoAdaptingPolicy;
import com.backendless.core.responder.policy.UniversalAdaptingPolicy;
import com.backendless.servercode.ExecutionType;

Expand All @@ -44,25 +43,25 @@ static CustomService getInstance()
public <T> T invoke( String serviceName, String method, Object[] arguments )
{
Object[] args = new Object[] { serviceName, method, arguments };
return (T) Invoker.invokeSync( CUSTOM_SERVICE_ALIAS, METHOD_NAME_ALIAS, args );
return Invoker.invokeSync( CUSTOM_SERVICE_ALIAS, METHOD_NAME_ALIAS, args );
}

public <T> T invoke( String serviceName, String method, Object[] arguments, ExecutionType executionType )
{
Object[] args = new Object[] { serviceName, method, arguments, executionType };
return (T) Invoker.invokeSync( CUSTOM_SERVICE_ALIAS, METHOD_NAME_ALIAS, args );
return Invoker.invokeSync( CUSTOM_SERVICE_ALIAS, METHOD_NAME_ALIAS, args );
}

public <T> T invoke( String serviceName, String method, Object[] arguments, Class<?> clazz )
{
Object[] args = new Object[] { serviceName, method, arguments };
return (T) Invoker.invokeSync( CUSTOM_SERVICE_ALIAS, METHOD_NAME_ALIAS, args, new AdaptingResponder( clazz, new UniversalAdaptingPolicy() ) );
return Invoker.invokeSync( CUSTOM_SERVICE_ALIAS, METHOD_NAME_ALIAS, args, new AdaptingResponder( clazz, new UniversalAdaptingPolicy() ) );
}

public <T> T invoke( String serviceName, String method, Object[] arguments, ExecutionType executionType, Class<?> clazz )
{
Object[] args = new Object[] { serviceName, method, arguments, executionType };
return (T) Invoker.invokeSync( CUSTOM_SERVICE_ALIAS, METHOD_NAME_ALIAS, args, new AdaptingResponder( clazz, new UniversalAdaptingPolicy() ) );
return Invoker.invokeSync( CUSTOM_SERVICE_ALIAS, METHOD_NAME_ALIAS, args, new AdaptingResponder( clazz, new UniversalAdaptingPolicy() ) );
}

public <E> void invoke( String serviceName, String method, Object[] arguments, AsyncCallback<E> callback )
Expand Down
8 changes: 4 additions & 4 deletions src/com/backendless/DataStoreFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@

class DataStoreFactory
{
private static final List<String> emptyRelations = new ArrayList<String>();
private static final List<String> emptyRelations = new ArrayList<>();
private final static EventHandlerFactory eventHandlerFactory = new EventHandlerFactory();

protected static <E> IDataStore<E> createDataStore( final Class<E> entityClass )
{

return new IDataStore<E>()
{
private EventHandler<E> eventHandler = eventHandlerFactory.of( entityClass );
private final EventHandler<E> eventHandler = eventHandlerFactory.of( entityClass );

@Override
public List<String> create( List<E> objects ) throws BackendlessException
Expand Down Expand Up @@ -211,7 +211,7 @@ public E findLast( Integer relationsDepth ) throws BackendlessException
@Override
public E findLast( List<String> relations ) throws BackendlessException
{
return findLast( relations, (Integer)null, null );
return findLast( relations, null, null );
}

@Override
Expand Down Expand Up @@ -361,7 +361,7 @@ public void findById( E entity, AsyncCallback<E> responder )
@Override
public void findById( E entity, List<String> relations, AsyncCallback<E> responder )
{
findById( entity, relations, (Integer)null, responder );
findById( entity, relations, null, responder );
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/com/backendless/DeviceRegistration.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class DeviceRegistration
protected String os;
protected String osVersion;
protected Date expiration;
private List<String> channels = new ArrayList<String>();
private List<String> channels = new ArrayList<>();

public String getId()
{
Expand Down Expand Up @@ -100,7 +100,7 @@ public void setExpiration( Date expiration )
public List<String> getChannels()
{
if( channels == null )
return channels = new ArrayList<String>();
return channels = new ArrayList<>();

return channels;
}
Expand All @@ -113,7 +113,7 @@ public synchronized void setChannels( List<String> channels )
public synchronized void addChannel( String channel )
{
if( channels == null )
channels = new ArrayList<String>();
channels = new ArrayList<>();

channels.add( channel );
}
Expand Down
4 changes: 2 additions & 2 deletions src/com/backendless/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ static Events getInstance()

public Map dispatch( String eventName, Map eventArgs )
{
return (Map) Invoker.invokeSync( EVENTS_MANAGER_SERVER_ALIAS, "dispatchEvent", new Object[] { eventName, eventArgs } );
return Invoker.invokeSync( EVENTS_MANAGER_SERVER_ALIAS, "dispatchEvent", new Object[] { eventName, eventArgs } );
}

public Map dispatch( String eventName, Map eventArgs, ExecutionType executionType )
{
return (Map) Invoker.invokeSync( EVENTS_MANAGER_SERVER_ALIAS, "dispatchEvent", new Object[] { eventName, eventArgs, executionType } );
return Invoker.invokeSync( EVENTS_MANAGER_SERVER_ALIAS, "dispatchEvent", new Object[] { eventName, eventArgs, executionType } );
}

public void dispatch( String eventName, Map eventArgs, AsyncCallback<Map> callback )
Expand Down
15 changes: 6 additions & 9 deletions src/com/backendless/Files.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -196,7 +197,7 @@ public BackendlessFile uploadFromStream( OutputStreamRouter outputStreamRouter,
connection.addRequestProperty( key, HeadersManager.getInstance().getHeaders().get( key ) );

try ( OutputStream outputStream = connection.getOutputStream();
PrintWriter writer = new PrintWriter( new OutputStreamWriter( outputStream, "UTF-8" ), true ) )
PrintWriter writer = new PrintWriter( new OutputStreamWriter( outputStream, StandardCharsets.UTF_8 ), true ) )
{
writer.append( "--" ).append( boundary ).append( CRLF );
writer.append( "Content-Disposition: form-data; name=\"file\"; filename=\"" ).append( name ).append( "\"" ).append( CRLF );
Expand Down Expand Up @@ -246,11 +247,7 @@ public BackendlessFile uploadFromStream( OutputStreamRouter outputStreamRouter,
return new BackendlessFile( fileUrl );
}
}
catch( MalformedURLException e )
{
throw new IllegalArgumentException( ExceptionMessage.FILE_UPLOAD_ERROR, e );
}
catch( UnsupportedEncodingException e )
catch( MalformedURLException | UnsupportedEncodingException e )
{
throw new IllegalArgumentException( ExceptionMessage.FILE_UPLOAD_ERROR, e );
}
Expand Down Expand Up @@ -464,7 +461,7 @@ public List<FileInfo> listing( String path, String pattern, boolean recursive )
public List<FileInfo> listing( String path, String pattern, boolean recursive, int pagesize,
int offset )
{
List<FileInfo> fileInfoList = Invoker.invokeSync( FILE_MANAGER_SERVER_ALIAS, "listing", new Object[] { path, pattern, recursive, pagesize, offset }, new AdaptingResponder<FileInfo>( FileInfo.class, new CollectionAdaptingPolicy<FileInfo>() ) );
List<FileInfo> fileInfoList = Invoker.invokeSync( FILE_MANAGER_SERVER_ALIAS, "listing", new Object[] { path, pattern, recursive, pagesize, offset }, new AdaptingResponder<>( FileInfo.class, new CollectionAdaptingPolicy<FileInfo>() ) );
return fileInfoList;
}

Expand Down Expand Up @@ -497,7 +494,7 @@ public void handleFault( BackendlessFault fault )
if( responder != null )
responder.handleFault( fault );
}
}, new AdaptingResponder<FileInfo>( FileInfo.class, new CollectionAdaptingPolicy<FileInfo>() ) );
}, new AdaptingResponder<>( FileInfo.class, new CollectionAdaptingPolicy<FileInfo>() ) );
}

public int getFileCount( String path, String pattern, boolean recursive, boolean countDirectories )
Expand Down Expand Up @@ -561,7 +558,7 @@ public void exists( String path, AsyncCallback<Boolean> responder )
Invoker.invokeAsync( FILE_MANAGER_SERVER_ALIAS, "exists", new Object[] { path }, responder );
}

private class EmptyUploadCallback implements UploadCallback
private static class EmptyUploadCallback implements UploadCallback
{
public void onProgressUpdate( Integer progress )
{
Expand Down
2 changes: 1 addition & 1 deletion src/com/backendless/Footprint.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static Footprint initFromEntity( Map<String, Object> entity )

public void initObjectId( Object entity )
{
Field objectIdField = null;
Field objectIdField;
try
{
objectIdField = entity.getClass().getDeclaredField( Persistence.DEFAULT_OBJECT_ID_FIELD );
Expand Down
10 changes: 5 additions & 5 deletions src/com/backendless/FootprintsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
public class FootprintsManager
{
private static final FootprintsManager instance = new FootprintsManager();
private static Set<Object> marked = new HashSet<Object>(); //for cyclic entities
private static final Set<Object> marked = new HashSet<>(); //for cyclic entities
public final Inner Inner = new Inner();
private final Map<Object, Footprint> persistenceCache = new WeakHashMap<Object, Footprint>();
private final Map<Object, Footprint> persistenceCache = new WeakHashMap<>();

private FootprintsManager()
{
Expand Down Expand Up @@ -68,11 +68,11 @@ public String getMeta( Object entity )
{
Object obj = persistenceCache.get( entity );

if( obj != null && obj instanceof Footprint )
if( obj instanceof Footprint )
return ((Footprint) obj).get__meta();

if( obj != null && obj instanceof BackendlessUser )
((BackendlessUser) obj).getProperty( "__meta" );
if( obj instanceof BackendlessUser )
return (String) ((BackendlessUser) obj).getProperty( "__meta" );

return null;
}
Expand Down
Loading

0 comments on commit de21a43

Please sign in to comment.