Git Product home page Git Product logo

eventcounter's Introduction

EventCounter

The easiest way to count events.

image

##Importing to your project Add this dependency to your build.gradle file:

dependencies {
    compile 'com.hrules:eventcounter:2.0.0'
}

##Usage This lib is easy to use. If you want to create a counter and increase or decrement his value, you only have to write these lines. There are two ways to do that: (The key value is only an ID for your counter, use any that you want)

  • Create an EventCounter object and manage it:
public static final String EVENTCOUNTER_KEY = "KEY";
public static final int EVENTCOUNTER_DEFAULT_VALUE = 0;
public static final int EVENTCOUNTER_EXPECTED_VALUE = 5;

EventCounter eventCounter = new EventCounter(context);

// Increase value (Default increment 1, add an integer param to set value to increment)
eventCounter.increment(EVENTCOUNTER_KEY);

// Decrement value (Default decrement 1, add an integer param to set value to decrement)
eventCounter.decrement(EVENTCOUNTER_KEY);

// Get value
int value = eventCounter.get(EVENTCOUNTER_KEY); 
int value = eventCounter.get(EVENTCOUNTER_KEY, EVENTCOUNTER_DEFAULT_VALUE); // default value to return

// Check value 
boolean bool = eventCounter.check(EVENTCOUNTER_KEY, EVENTCOUNTER_EXPECTED_VALUE); 
boolean bool = eventCounter.check(EVENTCOUNTER_KEY, EVENTCOUNTER_EXPECTED_VALUE, EventCounter.GREATER_THAN_OR_EQUAL_TO);

// Reset value
eventCounter.reset(EVENTCOUNTER_KEY);

// Reset all
eventCounter.resetAll();

// Add or remove key
eventCounter.add(EVENTCOUNTER_KEY);
eventCounter.remove(EVENTCOUNTER_KEY);

// Remove all
eventCounter.removeAll();
  • Use it as singleton:
public static final String EVENTCOUNTER_KEY = "KEY";
public static final int EVENTCOUNTER_DEFAULT_VALUE = 0;
public static final int EVENTCOUNTER_EXPECTED_VALUE = 5;

// Increase value
EventCounter.with(context).increment(EVENTCOUNTER_KEY);

// Decrement value
EventCounter.with(context).decrement(EVENTCOUNTER_KEY);

// Get value
int value = EventCounter.with(context).get(EVENTCOUNTER_KEY);
int value = EventCounter.with(context).get(EVENTCOUNTER_KEY, EVENTCOUNTER_DEFAULT_VALUE); // default value to return

// Check value
boolean bool = EventCounter.with(context).check(EVENTCOUNTER_KEY, EVENTCOUNTER_EXPECTED_VALUE);
boolean bool = EventCounter.with(context).check(EVENTCOUNTER_KEY, EVENTCOUNTER_EXPECTED_VALUE, EventCounter.GREATER_THAN_OR_EQUAL_TO);

// Reset counter
EventCounter.with(context).reset(EVENTCOUNTER_KEY);

Readme added by Mun0n Nice to meet you! ;-)

##Code Example

public static final String EVENTCOUNTER_KEY = "KEY";
public static final int EVENTCOUNTER_EXPECTED_VALUE = 5;

if (EventCounter.with(this).increment(EVENTCOUNTER_KEY).check(EVENTCOUNTER_KEY, EVENTCOUNTER_EXPECTED_VALUE) {
    // ...

    // Reset counter
    // EventCounter.with(this).reset(EVENTCOUNTER_KEY);
}

Developed by

Héctor de Isidro - hrules6872 Twitter

License

Copyright 2015 Héctor de Isidro - hrules6872

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

eventcounter's People

Contributors

hrules6872 avatar mun0n avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.