Example usage for java.util Properties size

List of usage examples for java.util Properties size

Introduction

In this page you can find the example usage for java.util Properties size.

Prototype

@Override
    public int size() 

Source Link

Usage

From source file:net.padlocksoftware.padlock.licensevalidator.Main.java

/**
 * @param args the command line arguments
 *///from ww w .j av  a2 s  .  com
public static void main(String[] args) {
    parse(args);
    Date currentDate = new Date();

    Validator v = new Validator(license, new String(Hex.encodeHex(pair.getPublic().getEncoded())));
    v.setIgnoreFloatTime(true);

    boolean ex = false;
    LicenseState state;
    try {
        state = v.validate();
    } catch (ValidatorException e) {
        state = e.getLicenseState();
    }

    // Show test status
    System.out.println("\nValidation Test Results:");
    System.out.println("========================\n");
    for (TestResult result : state.getTests()) {
        System.out.println(
                "\t" + result.getTest().getName() + "\t\t\t" + (result.passed() ? "Passed" : "Failed"));
    }

    System.out.println("\nLicense state: " + (state.isValid() ? "Valid" : "Invalid"));

    //
    // Cycle through any dates
    //
    Date d = license.getCreationDate();
    System.out.println("\nCreation date: \t\t" + d);

    d = license.getStartDate();
    System.out.println("Start date: \t\t" + d);

    d = license.getExpirationDate();
    System.out.println("Expiration date: \t" + d);

    Long floatPeroid = license.getFloatingExpirationPeriod();
    if (floatPeroid != null) {
        long seconds = floatPeroid / 1000L;
        System.out.println("\nExpire after first run: " + seconds + " seconds");

    }

    if (floatPeroid != null || license.getExpirationDate() != null) {
        long remaining = v.getTimeRemaining(currentDate) / 1000L;
        System.out.println("\nTime remaining: " + remaining + " seconds");

    }

    //
    // License properties
    //
    System.out.println("\nLicense Properties");
    Properties p = license.getProperties();
    if (p.size() == 0) {
        System.out.println("None");
    }

    for (final Enumeration propNames = p.propertyNames(); propNames.hasMoreElements();) {
        final String key = (String) propNames.nextElement();
        System.out.println("Property: " + key + " = " + p.getProperty(key));
    }

    //
    // Hardware locking
    //
    for (String address : license.getHardwareAddresses()) {
        System.out.println("\nHardware lock: " + address);
    }
    System.out.println("\n");
}

From source file:io.anserini.index.UserPostFrequencyDistribution.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(new Option(HELP_OPTION, "show help"));

    options.addOption(new Option(STORE_TERM_VECTORS_OPTION, "store term vectors"));

    options.addOption(OptionBuilder.withArgName("collection").hasArg()
            .withDescription("source collection directory").create(COLLECTION_OPTION));
    options.addOption(OptionBuilder.withArgName("property").hasArg()
            .withDescription("source collection directory").create("property"));
    options.addOption(OptionBuilder.withArgName("collection_pattern").hasArg()
            .withDescription("source collection directory").create("collection_pattern"));

    CommandLine cmdline = null;//from  w  w  w  .j  ava  2  s .co  m
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (cmdline.hasOption(HELP_OPTION) || !cmdline.hasOption(COLLECTION_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(UserPostFrequencyDistribution.class.getName(), options);
        System.exit(-1);
    }

    String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION);

    final FieldType textOptions = new FieldType();
    textOptions.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
    textOptions.setStored(true);
    textOptions.setTokenized(true);
    textOptions.setStoreTermVectors(true);

    LOG.info("collection: " + collectionPath);
    LOG.info("collection_pattern " + cmdline.getOptionValue("collection_pattern"));
    LOG.info("property " + cmdline.getOptionValue("property"));
    LongOpenHashSet deletes = null;

    long startTime = System.currentTimeMillis();
    File file = new File(collectionPath);
    if (!file.exists()) {
        System.err.println("Error: " + file + " does not exist!");
        System.exit(-1);
    }

    final JsonStatusCorpusReader stream = new JsonStatusCorpusReader(file,
            cmdline.getOptionValue("collection_pattern"));

    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {

            try {

                stream.close();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            ;

            System.out.println("# of users indexed this round: " + userIndexedCount);

            System.out.println("Shutting down");

        }
    });
    Status status;
    boolean readerNotInitialized = true;

    try {
        Properties prop = new Properties();
        while ((status = stream.next()) != null) {

            // try{
            // status = DataObjectFactory.createStatus(s);
            // if (status==null||status.getText() == null) {
            // continue;
            // }}catch(Exception e){
            //
            // }
            //

            boolean pittsburghRelated = false;
            try {

                if (Math.abs(status.getLongitude() - pittsburghLongitude) < 0.05d
                        && Math.abs(status.getlatitude() - pittsburghLatitude) < 0.05d)
                    pittsburghRelated = true;
            } catch (Exception e) {

            }
            try {
                if (status.getPlace().contains("Pittsburgh, PA"))
                    pittsburghRelated = true;
            } catch (Exception e) {

            }
            try {
                if (status.getUserLocation().contains("Pittsburgh, PA"))
                    pittsburghRelated = true;
            } catch (Exception e) {

            }

            try {
                if (status.getText().contains("Pittsburgh"))
                    pittsburghRelated = true;
            } catch (Exception e) {

            }

            if (pittsburghRelated) {

                int previousPostCount = 0;

                if (prop.containsKey(String.valueOf(status.getUserid()))) {
                    previousPostCount = Integer
                            .valueOf(prop.getProperty(String.valueOf(status.getUserid())).split(" ")[1]);
                }

                prop.setProperty(String.valueOf(status.getUserid()),
                        String.valueOf(status.getStatusesCount()) + " " + (1 + previousPostCount));
                if (prop.size() > 0 && prop.size() % 1000 == 0) {
                    Runtime runtime = Runtime.getRuntime();
                    runtime.gc();
                    System.out.println("Property size " + prop.size() + "Memory used:  "
                            + ((runtime.totalMemory() - runtime.freeMemory()) / (1024L * 1024L)) + " MB\n");
                }
                OutputStream output = new FileOutputStream(cmdline.getOptionValue("property"), false);
                prop.store(output, null);
                output.close();

            }
        }
        //         prop.store(output, null);
        LOG.info(String.format("Total of %s statuses added", userIndexedCount));
        LOG.info("Total elapsed time: " + (System.currentTimeMillis() - startTime) + "ms");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {

        stream.close();
    }
}

From source file:Main.java

/**
 * Convert a {@link Properties} into a {@link HashMap}.<br />
 * @param properties/*from  w  w  w .j av a 2 s.co m*/
 *        the properties to convert.
 * @return the map with the same objects.
 */
public static Map<String, String> convertPropertiesToMap(final Properties properties) {
    Objects.requireNonNull(properties);
    final Map<String, String> map = new HashMap<>(properties.size());
    for (final Entry<Object, Object> property : properties.entrySet()) {
        // Properties are always Strings (left as Object in JDK for backward compatibility purposes)
        map.put((String) property.getKey(), (String) property.getValue());
    }
    return map;
}

From source file:net.sf.ehcache.util.PropertyUtil.java

/**
 * @return null if their is no property for the key, or their are no properties
 *//*from   w  w  w  .  j  a v a2 s  .c o m*/
public static String extractAndLogProperty(String name, Properties properties) {
    if (properties == null || properties.size() == 0) {
        return null;
    }
    String foundValue = (String) properties.get(name);
    if (foundValue != null) {
        foundValue = foundValue.trim();
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(new StringBuffer().append("Value found for ").append(name).append(": ").append(foundValue)
                .toString());
    }
    return foundValue;
}

From source file:io.unravelling.ferguson.configuration.FergusonConfiguration.java

/**
 * Validates the received configuration for the Ferguson library.
 * @param configuration Configuration on the form of properties.
 * @return True if configuration is valid.
 *//*  ww w .  j  a v a 2s .  c  o  m*/
public static boolean validateConfiguration(final Properties configuration) {

    return configuration != null && configuration.size() > 0 && validateServerType(configuration)
            && validateServerUrl(configuration) && validateServerUsername(configuration)
            && validateServerPassword(configuration);
}

From source file:Main.java

public static Map<String, String> toMap(Properties properties) {
    if (properties == null) {
        return new HashMap<String, String>(0);
    }/*  ww  w .  j a  v a  2s  .  c o  m*/
    Map<String, String> map = new HashMap<String, String>(properties.size());

    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        map.put(entry.getKey().toString(), entry.getValue().toString());
    }
    return map;
}

From source file:net.ontopia.utils.PropertyUtils.java

public static Map<String, String> toMap(Properties properties) {
    Map<String, String> result = new HashMap<String, String>(properties.size());
    for (String key : properties.stringPropertyNames()) {
        result.put(key, properties.getProperty(key));
    }/*  w  w w  .j ava  2 s. c  o  m*/
    return result;
}

From source file:Main.java

/**
 * Sorts property list and print out each key=value pair prepended with 
 * specific indentation.  If indent is null, do not prepend with
 * indentation. //  w ww  . jav  a 2  s.co  m
 *
 * The output string shows up in two styles, style 1 looks like
 * { key1=value1, key2=value2, key3=value3 }
 *
 * style 2 looks like
 *    key1=value1
 *    key2=value2
 *    key3=value3
 * where indent goes between the new line and the keys
 *
 * To get style 1, pass in a null indent
 * To get sytle 2, pass in non-null indent (whatever you want to go before
 * the key value)
 */
public static String sortProperties(Properties list, String indent) {
    int size = list == null ? 0 : list.size();
    int count = 0;
    String[] array = new String[size];
    String key;
    String value;
    StringBuffer buffer;

    // Calculate the number of properties in the property list and
    // build an array of all the property names.
    // We need to go thru the enumeration because Properties has a
    // recursive list of defaults.
    if (list != null) {
        for (Enumeration propertyNames = list.propertyNames(); propertyNames.hasMoreElements();) {
            if (count == size) {
                // need to expand the array
                size = size * 2;
                String[] expandedArray = new String[size];
                System.arraycopy(array, 0, expandedArray, 0, count);
                array = expandedArray;
            }
            key = (String) propertyNames.nextElement();
            array[count++] = key;
        }

        // now sort the array
        java.util.Arrays.sort(array, 0, count);
    }

    // now stringify the array
    buffer = new StringBuffer();
    if (indent == null)
        buffer.append("{ ");

    for (int ictr = 0; ictr < count; ictr++) {
        if (ictr > 0 && indent == null)
            buffer.append(", ");

        key = array[ictr];

        if (indent != null)
            buffer.append(indent);

        buffer.append(key);
        buffer.append("=");

        value = list.getProperty(key, "MISSING_VALUE");
        buffer.append(value);

        if (indent != null)
            buffer.append("\n");

    }
    if (indent == null)
        buffer.append(" }");

    return buffer.toString();
}

From source file:de.hypoport.ep2.support.configuration.properties.PropertiesLoader.java

private static void mergePropertiesIntoSystemPropertiesWithoutOverwriting(Properties properties) {
    if (properties == null || properties.size() == 0) {
        return;//from w w w  .j a  v  a2 s.  c  om
    }
    Properties systemProperties = System.getProperties();
    properties.putAll(systemProperties);
    systemProperties.putAll(properties);
}

From source file:Main.java

/**
 * Copies all elements from <code>properties</code> into a Map. The returned map might be unmodifiable
 * @param properties//from   ww w  . ja  va2  s  . c  om
 * @return The map containing all elements
 */
public static Map<String, String> toMap(Properties properties) {
    if (properties == null || properties.isEmpty())
        return Collections.<String, String>emptyMap();

    Map<String, String> props = new HashMap<String, String>(properties.size());
    putAll(properties, props);
    return props;
}