Giter Site home page Giter Site logo

preferences's Introduction

Preferences

Build Status codecov Maven Central

A simplified and typesafe entry point to the Java Preferences API (java.util.prefs). I wrote this library out of my wish to use the then-new Java 5 feature of enum's as keys for preference values instead of String constants like most people were doing before Java 5 days.

Installation

Minimum of Java 8 required.

For Maven and Maven-compatible dependency managers

Add a dependency to your project with the following co-ordinates:

  • GroupId: nz.net.ultraq.preferences
  • ArtifactId: preferences
  • Version: 3.1.0

Check the project releases for a list of available versions. Each release page also includes a downloadable JAR if you want to manually add it to your project classpath.

Usage

Implement enums that extend from UserPreference or SystemPreference to create user/system preferences respectively. Then, use those enum values over an instance of nz.net.ultraq.preferences.Preferences to load/save the relevant preferences. eg:

public enum MyPreferences implements UserPreference {

  WINDOW_WIDTH  (800),
  WINDOW_HEIGHT (600);

  public final Object defaultValue;

  MyPreferences(Object defaultValue) {
    this.defaultValue = defaultValue;
  }

  @Override
  public Object getDefaultValue() {
    return defaultValue;
  }
}

public class MyClass {

  public static void main(String[] args) {

    Preferences preferences = new Preferences();

    int windowWidth = preferences.get(MyPreferences.WINDOW_WIDTH);
    int windowHeight = preferences.get(MyPreferences.WINDOW_HEIGHT);

    preferences.set(MyPreferences.WINDOW_WIDTH, 1024);
  }
}

API

Browse the online groovydocs for this library here: https://javadoc.io/doc/nz.net.ultraq.preferences/preferences

preferences's People

Contributors

ultraq avatar

Stargazers

Igor avatar Emmanuel Castro avatar G.Grandes avatar José V. Dal Prá Junior avatar

Watchers

James Cloos avatar  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.