Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.backendless.hive.HiveSortedSet Maven / Gradle / Ivy
package com.backendless.hive;
import com.backendless.core.responder.AdaptingResponder;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
public final class HiveSortedSet extends HiveGeneralForComplexStore
{
public final static String HIVE_SORTED_SET_ALIAS = "com.backendless.services.hive.HiveSortedSetService";
HiveSortedSet( String hiveName, String storeKey )
{
super( hiveName, StoreType.SortedSet, storeKey );
}
public static final class ScoreRangeOptions
{
private double minScore;
private ValueBound minBound;
private double maxScore;
private ValueBound maxBound;
public ScoreRangeOptions setMinScore( double minScore )
{
this.minScore = minScore;
return this;
}
public ScoreRangeOptions setMinBound( ValueBound minBound )
{
this.minBound = minBound;
return this;
}
public ScoreRangeOptions setMaxScore( double maxScore )
{
this.maxScore = maxScore;
return this;
}
public ScoreRangeOptions setMaxBound( ValueBound maxBound )
{
this.maxBound = maxBound;
return this;
}
}
public CompletableFuture add( ScoreValuePair item )
{
return add( Collections.singleton( item ), null, null, null );
}
public CompletableFuture add( Set> items )
{
return add( items, null, null, null );
}
public CompletableFuture add( Set> items, DuplicateBehaviour duplicateBehaviour, ScoreUpdateMode scoreUpdateMode, ResultType resultType )
{
return makeRemoteCall( "add", new AdaptingResponder<>( Long.class ), ScoreValuePair.toObjectArray( items ), duplicateBehaviour, scoreUpdateMode, resultType );
}
public CompletableFuture incrementScore( double scoreAmount, String member )
{
return makeRemoteCall( "increment", scoreAmount, member );
}
public CompletableFuture decrementScore( double scoreAmount, String member )
{
return incrementScore( -scoreAmount, member );
}
public CompletableFuture>> getAndDeleteMaxScore( int count )
{
return this.makeRemoteCall( "getAndRemoveMax", count )
.thenApply( ScoreValuePair::fromObjectArray );
}
public CompletableFuture>> getAndDeleteMinScore( int count )
{
return this.makeRemoteCall( "getAndRemoveMin", count )
.thenApply( ScoreValuePair::fromObjectArray );
}
public CompletableFuture> getRandom( int count )
{
return this.makeRemoteCall( "getRandom", count )
.thenApply( HiveSerializer::deserializeAsList );
}
public CompletableFuture>> getRandomWithScores( int count )
{
return this.makeRemoteCall( "getRandomWithScores", count )
.thenApply( ScoreValuePair::fromObjectArrayToList );
}
public CompletableFuture getScore( String member )
{
return makeRemoteCall( "getScore", member );
}
public CompletableFuture getRank( String member, boolean reverse )
{
if( reverse )
return getReverseRank( member );
else
return getRank( member );
}
private CompletableFuture getRank( String member )
{
return makeRemoteCall( "getRank", new AdaptingResponder<>( Long.class ), member );
}
private CompletableFuture getReverseRank( String member )
{
return makeRemoteCall( "getReverseRank", new AdaptingResponder<>( Long.class ), member );
}
public CompletableFuture> getRangeByRank( long startRank, long stopRank, boolean reverse )
{
if( reverse )
return getReverseRangeByRank( startRank, stopRank );
else
return getRangeByRank( startRank, stopRank );
}
private CompletableFuture> getRangeByRank( long startRank, long stopRank )
{
return this.makeRemoteCall( "getRangeByRank", startRank, stopRank )
.thenApply( HiveSerializer::deserializeAsLinkedSet );
}
private CompletableFuture> getReverseRangeByRank( long startRank, long stopRank )
{
return this.makeRemoteCall( "getReverseRangeByRank", startRank, stopRank )
.thenApply( HiveSerializer::deserializeAsLinkedSet );
}
public CompletableFuture>> getRangeWithScoresByRank( long startRank, long stopRank, boolean reverse )
{
if( reverse )
return getReverseRangeWithScoresByRank( startRank, stopRank );
else
return getRangeWithScoresByRank( startRank, stopRank );
}
private CompletableFuture>> getRangeWithScoresByRank( long startRank, long stopRank )
{
return this.makeRemoteCall( "getRangeWithScoresByRank", startRank, stopRank )
.thenApply( ScoreValuePair::fromObjectArray );
}
private CompletableFuture>> getReverseRangeWithScoresByRank( long startRank, long stopRank )
{
return this.makeRemoteCall( "getReverseRangeWithScoresByRank", startRank, stopRank )
.thenApply( ScoreValuePair::fromObjectArray );
}
public CompletableFuture> getRangeByScore( ScoreRangeOptions options, long offset, long pageSize, boolean reverse )
{
if( reverse )
return getReverseRangeByScore( options.minScore, options.minBound, options.maxScore, options.maxBound, offset, pageSize );
else
return getRangeByScore( options.minScore, options.minBound, options.maxScore, options.maxBound, offset, pageSize );
}
private CompletableFuture> getRangeByScore( double minScore, ValueBound minBound, double maxScore, ValueBound maxBound, long offset, long pageSize )
{
return this.makeRemoteCall( "getRangeByScore", minScore, minBound, maxScore, maxBound, offset, pageSize )
.thenApply( HiveSerializer::deserializeAsLinkedSet );
}
private CompletableFuture> getReverseRangeByScore( double minScore, ValueBound minBound, double maxScore, ValueBound maxBound, long offset, long pageSize )
{
return this.makeRemoteCall( "getReverseRangeByScore", minScore, minBound, maxScore, maxBound, offset, pageSize )
.thenApply( HiveSerializer::deserializeAsLinkedSet );
}
public CompletableFuture>> getRangeWithScoresByScore( ScoreRangeOptions options, long offset, long pageSize, boolean reverse )
{
if( reverse )
return getReverseRangeWithScoresByScore( options.minScore, options.minBound, options.maxScore, options.maxBound, offset, pageSize );
else
return getRangeWithScoresByScore( options.minScore, options.minBound, options.maxScore, options.maxBound, offset, pageSize );
}
private CompletableFuture>> getRangeWithScoresByScore( double minScore, ValueBound minBound, double maxScore, ValueBound maxBound, long offset, long pageSize )
{
return this.makeRemoteCall( "getRangeWithScoresByScore", minScore, minBound, maxScore, maxBound, offset, pageSize )
.thenApply( ScoreValuePair::fromObjectArray );
}
private CompletableFuture>> getReverseRangeWithScoresByScore( double minScore, ValueBound minBound, double maxScore, ValueBound maxBound, long offset, long pageSize )
{
return this.makeRemoteCall( "getReverseRangeWithScoresByScore", minScore, minBound, maxScore, maxBound, offset, pageSize )
.thenApply( ScoreValuePair::fromObjectArray );
}
public CompletableFuture delete( Set values )
{
return makeRemoteCall( "remove", new AdaptingResponder<>( Long.class ), values );
}
public CompletableFuture deleteByRank( long startRank, long stopRank )
{
return makeRemoteCall( "removeByRank", new AdaptingResponder<>( Long.class ), startRank, stopRank );
}
public CompletableFuture deleteByScore( ScoreRangeOptions options )
{
return deleteByScore( options.minScore, options.minBound, options.maxScore, options.maxBound );
}
public CompletableFuture deleteByScore( double minScore, ValueBound minBound, double maxScore, ValueBound maxBound )
{
return makeRemoteCall( "removeByScore", new AdaptingResponder<>( Long.class ), minScore, minBound, maxScore, maxBound );
}
public CompletableFuture length( )
{
return makeRemoteCall( "size", new AdaptingResponder<>( Long.class ) );
}
public CompletableFuture countBetweenScores( ScoreRangeOptions options )
{
return countBetweenScores( options.minScore, options.minBound, options.maxScore, options.maxBound );
}
private CompletableFuture countBetweenScores( double minScore, ValueBound minBound, double maxScore, ValueBound maxBound )
{
return makeRemoteCall( "count", new AdaptingResponder<>( Long.class ), minScore, minBound, maxScore, maxBound );
}
// ----------------------------------------
private CompletableFuture makeRemoteCall( String methodName, Object... args )
{
return makeRemoteCallWithStoreKey( HIVE_SORTED_SET_ALIAS, methodName, args );
}
private CompletableFuture makeRemoteCall( String methodName, AdaptingResponder adaptingResponder, Object... args )
{
return makeRemoteCallWithStoreKey( HIVE_SORTED_SET_ALIAS, methodName, adaptingResponder, args );
}
}