ClearCounterRow { public void clear() { Mutator<K> mutator = HFactory.createMutator(this.keyspace, this.keySerializer, new BatchSizeHint(1, this.mutateInterval)); SliceCounterQuery<K, N> query = HFactory.createCounterSliceQuery(this.keyspace, this.keySerializer, this.nameSerializer). setColumnFamily(this.cf). setKey(this.rowKey); SliceCounterIterator<K, N> iterator = new SliceCounterIterator<K, N>(query, null, (N) null, false, this.count); while(iterator.hasNext()) { HCounterColumn<N> column = iterator.next(); mutator.incrementCounter(this.rowKey, this.cf, column.getName(), column.getValue() * -1); } mutator.execute(); } ClearCounterRow(Keyspace keyspace, Serializer<K> keySerializer, Serializer<N> nameSerializer); ClearCounterRow<K, N> setColumnFamily(String cf); ClearCounterRow<K, N> setRowKey(K rowKey); ClearCounterRow<K, N> setMutateInterval(int interval); ClearCounterRow<K, N> setCount(int count); void clear();  }
@Test public void testClear() { Mutator<String> mutator = createMutator(keyspace, ss); for (int i = 1; i <= 10; i++) { mutator.addCounter(key, cf, createCounterColumn("" + i, i)); } mutator.execute(); SliceCounterQuery query = HFactory.createCounterSliceQuery(keyspace, ss, ss); query.setColumnFamily(cf); query.setKey(key); SliceCounterIterator<String, String> iterator = new SliceCounterIterator<String, String>(query, null, (String) null, false, 10); while(iterator.hasNext()) { HCounterColumn<String> column = iterator.next(); long expected = Long.parseLong(column.getName()); assertEquals(expected, (long) column.getValue()); } new ClearCounterRow(keyspace, ss, ss).setColumnFamily(cf).setRowKey(key).clear(); iterator = new SliceCounterIterator<String, String>(query, null, (String) null, false, 10); while(iterator.hasNext()) { HCounterColumn<String> column = iterator.next(); long expected = 0; assertEquals(expected, (long) column.getValue()); } }