public long getAndSet ( T item , long value ) { MutableLong entry = map . get ( item ) ; if ( entry == null ) { entry = MutableLong . valueOf ( value ) ; map . put ( item , entry ) ; total += value ; return 0 ; } long oldValue = entry . value ; total = total - oldValue + value ; entry . value = value ; return oldValue ; }
Set counter for item and return previous value