Example usage for java.util.prefs Preferences getLong

List of usage examples for java.util.prefs Preferences getLong

Introduction

In this page you can find the example usage for java.util.prefs Preferences getLong.

Prototype

public abstract long getLong(String key, long def);

Source Link

Document

Returns the long value represented by the string associated with the specified key in this preference node.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(Main.class);

    // Preference key name
    final String PREF_NAME = "name_of_preference";

    // Save//from  w ww.j a  v  a  2s  . c  om
    prefs.put(PREF_NAME, "a string"); // String
    prefs.putBoolean(PREF_NAME, true); // boolean
    prefs.putInt(PREF_NAME, 123); // int
    prefs.putLong(PREF_NAME, 123L); // long
    prefs.putFloat(PREF_NAME, 12.3F); // float
    prefs.putDouble(PREF_NAME, 12.3); // double
    byte[] bytes = new byte[1024];
    prefs.putByteArray(PREF_NAME, bytes); // byte[]

    // Retrieve
    String s = prefs.get(PREF_NAME, "a string"); // String
    boolean b = prefs.getBoolean(PREF_NAME, true); // boolean
    int i = prefs.getInt(PREF_NAME, 123); // int
    long l = prefs.getLong(PREF_NAME, 123L); // long
    float f = prefs.getFloat(PREF_NAME, 12.3F); // float
    double d = prefs.getDouble(PREF_NAME, 12.3); // double
    bytes = prefs.getByteArray(PREF_NAME, bytes); // byte[]
}

From source file:org.pdfsam.module.PreferencesUsageDataStore.java

public long getTotalUsage() {
    Preferences node = Preferences.userRoot().node(USAGE_PATH);
    return node.getLong(TASKS_EXECUTED_KEY, 0);
}

From source file:org.pdfsam.module.PreferencesUsageDataStore.java

private void incrementTotalUsage() {
    Preferences node = Preferences.userRoot().node(USAGE_PATH);
    node.putLong(TASKS_EXECUTED_KEY, node.getLong(TASKS_EXECUTED_KEY, 0) + 1);
}

From source file:codeswarm.repository.svn.SVNHistory.java

/**
 * looks up the cache. Stops proceeding if a cached version for this
 * repository was found.//w w w.  j  av  a2s  . c o m
 * @param pRevision the latest repository revision.
 * @return false if a cached version was found, true if the history shall
 * be fetched from repository.
 */
public boolean handleFetchingLatestRepositoryRevision(Long pRevision) {
    long revision = pRevision.longValue();
    Preferences p = Preferences.userNodeForPackage(SVNHistory.class);
    long l = p.getLong(Integer.toString(this.url.hashCode()), -1l);
    if (l == revision) {
        if (logger.isDebugEnabled()) {
            logger.debug("skip fetching " + String.valueOf(l) + " (latest revision is " + revision + ") for "
                    + this.url);
        }
        return false;
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("proceed fetching (latest revision is " + String.valueOf(pRevision)
                    + " , cached revision is " + String.valueOf(l) + " for repository " + this.url);
        }
        Preferences.userNodeForPackage(SVNHistory.class).putLong(Integer.toString(this.url.hashCode()),
                revision);
        try {
            Preferences.userNodeForPackage(SVNHistory.class).flush();
        } catch (BackingStoreException ex) {
            logger.error(null, ex);
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("fetching until revision " + revision);
    }
    return true;
}

From source file:de.elomagic.carafile.client.CaraCloud.java

private List<Path> checkLocalFolder(final Path basePath) throws IOException {
    Preferences preferences = Preferences.systemNodeForPackage(getClass());
    final long lastScanMillis = preferences.getLong("lastScan", 0);

    final List<Path> changedPathList = getLocalChangeList(basePath, lastScanMillis);

    for (Path path : basePath) {
        // xxx/* w ww . ja va2  s  .c o m*/
    }

    return changedPathList;
}

From source file:de.innovationgate.wgpublisher.WGACore.java

public long getCharacterEncodingLastModified() {
    Preferences prefs = Preferences.userNodeForPackage(this.getClass());
    return prefs.getLong("CharacterEncodingModified", System.currentTimeMillis());
}

From source file:de.innovationgate.wgpublisher.WGACore.java

public long getDesignEncodingLastModified(String dbkey) {
    Preferences prefs = Preferences.userNodeForPackage(this.getClass());
    try {/*from w w  w .  j  a  v a2 s . c o  m*/
        return prefs.getLong(createPrefKeyDesignEncodingLastModified(dbkey), System.currentTimeMillis());
    } catch (Exception e) {
        log.error("Unable to retrieve preferences for 'DesignEncodingModified'", e);
        return System.currentTimeMillis();
    }
}