Java Properties Create totalPolicies(Class className)

Here you can find the source of totalPolicies(Class className)

Description

total Policies

License

Open Source License

Declaration

public static int totalPolicies(Class className) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006-2010 eBay Inc. All Rights Reserved.
 * 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
 *
 *******************************************************************************/

import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static int totalPolicies(Class className) throws IOException {
        Properties props = new Properties();
        InputStream input = className.getResourceAsStream(className.getSimpleName() + ".properties");
        props.load(input);//from  ww w  .  j  a v  a 2  s  .c  om

        Pattern pattern = Pattern.compile("policyName" + "_" + "policy(\\d)");
        Matcher matcher = null;
        Set s = props.keySet();
        Iterator ite = s.iterator();

        int max = 0;
        int value;
        while (ite.hasNext()) {
            matcher = pattern.matcher(ite.next().toString());
            if (matcher.find()) {
                value = Integer.parseInt(matcher.group(1));
                if (value > max)
                    max = value;
            }
        }
        System.out.println("max value=" + max);
        return max;
    }
}

Related

  1. toProperties(final Map map)
  2. toProperties(final String value)
  3. toProperties(String jsonStr)
  4. toProperties(String props)
  5. toRawString(Properties props)