com.stackmob.sdk.model
Class StackMobCounter

java.lang.Object
  extended by com.stackmob.sdk.model.StackMobCounter

public class StackMobCounter
extends Object

Represents a integer that can be incremented atomically. Its purpose is to allow you to have a value that can be incremented from multiple clients without worrying about synchronization. Use cases include a score tracker or thumbs-up button.


Constructor Summary
StackMobCounter()
           
 
Method Summary
 void forceTo(int val)
          Force the counter to a particular value, overriding the increment.
 int get()
          get the current local value of the counter
 int getIncrement()
          get the value that will be use for incrementing the counter on the next save
 int updateAtomicallyBy(int increment)
          Increment the value by a number (positive or negative).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StackMobCounter

public StackMobCounter()
Method Detail

updateAtomicallyBy

public int updateAtomicallyBy(int increment)
Increment the value by a number (positive or negative). This will change the local value immediately and the increment will be sent to the server as an atomic increment on the next save. The increment accumulates across multiple calls, so if you call this with values of 2 and -3 before saving, the sever-side value will be incremented by -1.

Parameters:
increment - the value to change the counter by
Returns:
the new value of the local counter

get

public int get()
get the current local value of the counter

Returns:
the current local value of the counter

getIncrement

public int getIncrement()
get the value that will be use for incrementing the counter on the next save

Returns:
the value that will be use for incrementing the counter on the next save

forceTo

public void forceTo(int val)
Force the counter to a particular value, overriding the increment. After calling this you can then save the model, which will cause the server-side value to be set rather than incremented.

Parameters:
val - the value the counter should be set to


Copyright © 2013 StackMob. All Rights Reserved.