Git Product home page Git Product logo

centralannotations's Introduction

Central Annotations

A simple annotations to help making your code centred around the user.

Badge

IntroductionKey FeaturesHow To UseFuture WorkLicense

Introduction

Annotation triggered method call for controlling the execution of methods using the concepts of AOP.

In most cases in our application, we have some different types of Users, plans and so on, each with different layouts and functionality unique to them, and we have to always handle this with a list of If conditions or Switch cases like these.

switch(user.type){
  case NORMAL:
        setAsNormalUser();
        break;
  case PREMIUM:
        setAsPremiumUser();
        break;
  case ADMIN:
        setAsAdmin();
}

Shouldn't it be easier?

By just adding @RestrictToType(type = YOUR_DESIRED_TYPE) and call it normally and it will not get executed unless it's this type.

Key Features

  • Control the execution of methods
  • Log the entry of the methods you want

How To Use

First add jitpack repository in your Project level build.gradle.

repositories {
        maven { url "https://jitpack.io" }
    }

Then add it to your project by this line.

 classpath 'com.github.ahmedvargos.centralannotations:central-main-plugin:1.0'

Finally apply the plugin in your module level build.gradle

apply plguin: 'central'

To use it first set the type of your user or plan by this line.

 Central.setType(NORMAL_USER); //it can be in your application class or any location to set the user type

Then call all the methods normally without cases, and just add the annotation with the type before it like this:

@RestrictToType(type = NORMAL_USER)
    private void setAsNormalUser() {
        textView.setText("Normal");
    }

Or adding more than just one type like this:

@RestrictToType(type = {NORMAL_USER, ADMIN})

But make sure that the types are Integers.

You could also use the @LogAtEntry annotation to log in the debug if the method is entered or not.

Future Work

• Adding support to kotlin
• Adding more helpful annotations to the library

License

MIT

centralannotations's People

Contributors

ahmedvargos 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.