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.minecraftforge.fml.common.Loader.java

private void disableRequestedMods() {
    String forcedModList = System.getProperty("fml.modStates", "");
    FMLLog.finer("Received a system property request \'%s\'", forcedModList);
    Map<String, String> sysPropertyStateList = Splitter.on(CharMatcher.anyOf(";:")).omitEmptyStrings()
            .trimResults().withKeyValueSeparator("=").split(forcedModList);
    FMLLog.finer("System property request managing the state of %d mods", sysPropertyStateList.size());
    Map<String, String> modStates = Maps.newHashMap();

    forcedModFile = new File(canonicalConfigDir, "fmlModState.properties");
    Properties forcedModListProperties = new Properties();
    if (forcedModFile.exists() && forcedModFile.isFile()) {
        FMLLog.finer("Found a mod state file %s", forcedModFile.getName());
        try {//from   ww  w.j  a v  a  2  s.  co m
            forcedModListProperties.load(new FileReader(forcedModFile));
            FMLLog.finer("Loaded states for %d mods from file", forcedModListProperties.size());
        } catch (Exception e) {
            FMLLog.log(Level.INFO, e, "An error occurred reading the fmlModState.properties file");
        }
    }
    modStates.putAll(Maps.fromProperties(forcedModListProperties));
    modStates.putAll(sysPropertyStateList);
    FMLLog.fine("After merging, found state information for %d mods", modStates.size());

    Map<String, Boolean> isEnabled = Maps.transformValues(modStates, new Function<String, Boolean>() {
        @Override
        public Boolean apply(String input) {
            return Boolean.parseBoolean(input);
        }
    });

    for (Map.Entry<String, Boolean> entry : isEnabled.entrySet()) {
        if (namedMods.containsKey(entry.getKey())) {
            FMLLog.info("Setting mod %s to enabled state %b", entry.getKey(), entry.getValue());
            namedMods.get(entry.getKey()).setEnabledState(entry.getValue());
        }
    }
}

From source file:org.apache.hadoop.conf.Configuration.java

public void write(DataOutput out) throws IOException {
    Properties props = getProps();
    WritableUtils.writeVInt(out, props.size());
    for (Map.Entry<Object, Object> item : props.entrySet()) {
        org.apache.hadoop.io.Text.writeString(out, (String) item.getKey());
        org.apache.hadoop.io.Text.writeString(out, (String) item.getValue());
    }//  w  ww. java 2  s .  com
}

From source file:org.jahia.services.usermanager.ldap.LDAPUserGroupProvider.java

private boolean isOrOperator(Properties ldapfilters, Properties searchCriteria) {
    if (ldapfilters.size() > 1) {
        if (searchCriteria.containsKey(JahiaUserManagerService.MULTI_CRITERIA_SEARCH_OPERATION)) {
            if (((String) searchCriteria.get(JahiaUserManagerService.MULTI_CRITERIA_SEARCH_OPERATION)).trim()
                    .toLowerCase().equals("and")) {
                return false;
            }/*w w  w  .  j a va  2s  . com*/
        }
    }
    return true;
}

From source file:dk.statsbiblioteket.util.XPropertiesTest.java

public void testEnvironment() throws Exception {
    new Properties(null);

    Properties sysProps = new Properties();
    sysProps.setProperty("XProperty:foo", "bar");
    sysProps.setProperty("XProperty:int", "87");
    sysProps.setProperty("XProperty:negative", "-43");
    sysProps.setProperty("XProperty:double", "12.13");
    sysProps.setProperty("XProperty:negdouble", "-14.0");
    sysProps.setProperty("XProperty:true", "true");
    sysProps.setProperty("XProperty:false", "false");
    sysProps.setProperty("XProperty:sub/int", "88");
    sysProps.setProperty("XProperty:uboat/deep/s", "flam");

    System.getProperties().putAll(sysProps);

    XProperties properties = new XProperties();

    assertEquals("Should contain imported sysprops", sysProps.size(), properties.size());

    assertEquals("Environment-specified Strings should work", "bar", properties.getString("foo"));
    assertEquals("Environment-specified ints should work", 87, properties.getInteger("int"));
    assertEquals("Environment-specified negative ints should work", -43, properties.getInteger("negative"));
    assertEquals("Environment-specified doubles should work", 12.13, properties.getDouble("double"));
    assertEquals("Environment-specified negative doubles should work", -14.0,
            properties.getDouble("negdouble"));
    assertEquals("Environment-specified true should work", true, properties.getBoolean("true"));
    assertEquals("Environment-specified false should work", false, properties.getBoolean("false"));
    assertEquals("Environment-specified subproperty should work", 88,
            properties.getSubProperty("sub").getInteger("int"));
    assertEquals("Environment-specified subsubproperty should work", "flam",
            properties.getSubProperty("uboat").getSubProperty("deep").getString("s"));

    // Clean up// ww  w. ja v  a 2  s.co m
    for (Object prop : sysProps.keySet()) {
        System.clearProperty((String) prop);
    }
    assertEquals("System XProperties was not cleaned up", 0, new XProperties().size());
}

From source file:org.apache.directory.fortress.core.ldap.ApacheDsDataProvider.java

/**
 * Given a collection of {@link java.util.Properties}, convert to raw data name-value format and load into ldap
 * modification set in preparation for ldap modify.
 *
 * @param props    contains {@link java.util.Properties} targeted for removal from ldap.
 * @param mods     ldap modification set containing name-value pairs in raw ldap format to be removed.
 * @param attrName contains the name of the ldap attribute to be removed.
 *///  w  w  w .  j  a  va2s . c om
protected void removeProperties(Properties props, List<Modification> mods, String attrName) {
    if (props != null && props.size() > 0) {
        for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements();) {
            String key = (String) e.nextElement();
            String val = props.getProperty(key);

            // This LDAP attr is stored as a name-value pair separated by a ':'.
            mods.add(new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, attrName,
                    key + GlobalIds.PROP_SEP + val));
        }
    }
}

From source file:org.jahia.services.usermanager.ldap.LDAPUserGroupProvider.java

/**
 * Map jahia properties to ldap properties
 *
 * @param searchCriteria//  ww w  .  j  a v a 2 s  .  c  o  m
 * @param configProperties
 * @return
 */
private Properties mapJahiaPropertiesToLDAP(Properties searchCriteria, Map<String, String> configProperties) {
    if (searchCriteria.size() == 0) {
        return searchCriteria;
    }
    Properties p = new Properties();
    if (searchCriteria.containsKey("*")) {
        p.setProperty("*", searchCriteria.getProperty("*"));
        if (searchCriteria.size() == 1) {
            return p;
        }
    }

    for (Map.Entry<Object, Object> entry : searchCriteria.entrySet()) {
        if (configProperties.containsKey(entry.getKey())) {
            p.setProperty(configProperties.get(entry.getKey()), (String) entry.getValue());
        } else if (!entry.getKey().equals("*")
                && !entry.getKey().equals(JahiaUserManagerService.MULTI_CRITERIA_SEARCH_OPERATION)) {
            return null;
        }
    }

    return p;
}

From source file:org.sakaiproject.kernel1.Activator.java

/**
 * {@inheritDoc}/*from  w ww.  j  a va 2 s . co m*/
 * 
 * @see org.sakaiproject.kernel.api.ComponentActivator#activate(org.sakaiproject.kernel.api.Kernel)
 */
public void activate(Kernel kernel) throws ComponentActivatorException {

    this.kernel = kernel;
    // here I want to create my services and register them
    // I could use Guice or Spring to do this, but I am going to do manual IoC
    // to keep it really simple
    InternalDateServiceImpl internalDateService = new InternalDateServiceImpl();
    HelloWorldService helloWorldService = new HelloWorldServiceImpl(internalDateService);

    org.sakaiproject.component.api.ComponentManager cm = null;

    long start = System.currentTimeMillis();
    try {
        LOG.info("START---------------------- Loading kernel 1");
        cm = ComponentManager.getInstance();
    } catch (Throwable t) {
        LOG.error("Failed to Startup ", t);
    }
    LOG.info("END------------------------ Loaded kernel 1 in  " + (System.currentTimeMillis() - start) + "ms");

    Properties localProperties = new Properties();
    try {
        InputStream is = ResourceLoader.openResource(K1_PROPERTIES, this.getClass().getClassLoader());
        localProperties.load(is);
    } catch (IOException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }

    /**
     * plagerized from k2 bootstrap module **
     */

    for (Entry<Object, Object> o : localProperties.entrySet()) {
        String k = o.getKey().toString();

        if (k.startsWith("+")) {
            String p = properties.getProperty(k.substring(1));
            if (p != null) {
                properties.put(k.substring(1), p + o.getValue());
            } else {
                properties.put(o.getKey(), o.getValue());
            }
        } else {
            properties.put(o.getKey(), o.getValue());
        }
    }
    LOG.info("Loaded " + localProperties.size() + " properties from " + K1_PROPERTIES);

    /**
     * plagerized from the ComponentLoaderService
     */

    ArtifactResolverService artifactResolverService = new Maven2ArtifactResolver();

    List<URL> locations = new ArrayList<URL>();
    String[] locs = StringUtils.split(properties.getProperty(K1_COMPONENT_LOCATION), ';');
    if (locs != null) {
        for (String location : locs) {
            location = location.trim();
            if (location.startsWith("maven-repo")) {
                Artifact dep = DependencyImpl.fromString(location);
                URL u = null;
                try {
                    u = artifactResolverService.resolve(null, dep);
                } catch (ComponentSpecificationException e) {
                    LOG.error("Can't resolve " + K1_COMPONENT_LOCATION + " property in file " + K1_PROPERTIES);
                    e.printStackTrace();
                }
                LOG.info("added k1 api bundle:" + u);
                locations.add(u);
            } else if (location.endsWith(".jar")) {
                if (location.indexOf("://") < 0) {
                    File f = new File(location);
                    if (!f.exists()) {
                        LOG.warn("Jar file " + f.getAbsolutePath() + " does not exist, will be ignored ");
                    } else {
                        try {
                            location = "file://" + f.getCanonicalPath();
                            locations.add(new URL(location));
                            LOG.info("added k1 api bundle:" + location);
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                } else {
                    LOG.info("added api bundle:" + location);
                    try {
                        locations.add(new URL(location));
                    } catch (MalformedURLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            } else {
                LOG.info("Locating api bundle in " + location);
                for (File f : FileUtil.findAll(location, ".jar")) {
                    String path = null;
                    try {
                        path = f.getCanonicalPath();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    if (path.indexOf("://") < 0) {
                        path = "file://" + path;
                    }
                    LOG.info("    added api bundle:" + path);
                    try {
                        locations.add(new URL(path));
                    } catch (MalformedURLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }
    }
    LOG.info("    bundle contains " + locations.size() + " uri's");

    // find all the instances
    URLClassLoader uclassloader = new URLClassLoader(locations.toArray(new URL[0]), null);

    /**
     * end plagerism.... for now
     */
    JarFile jar = null;
    for (URL url : locations) {
        try {
            jar = new JarFile(new File(url.toURI()));

            Enumeration<JarEntry> entries = jar.entries();

            for (; entries.hasMoreElements();) {
                JarEntry entry = entries.nextElement();
                if (entry != null && entry.getName().endsWith(".class")) {
                    ifcClassNames.add(entry.getName().replaceAll("/", "."));
                }
            }

            jar.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    // thats it. my service is ready to go, so lets register it
    // get the service manager
    ServiceManager serviceManager = kernel.getServiceManager();

    List<Class> ifcClasses = new ArrayList<Class>();
    String className = null;
    for (Iterator<String> i = ifcClassNames.iterator(); i.hasNext();) {
        try {
            className = i.next();
            ifcClasses.add(Class.forName(className));
        } catch (ClassNotFoundException e) {
            LOG.error("Can't find '" + className + "' in the classpath");
            i.remove(); // / with a sharp stick
            e.printStackTrace();
        }
    }

    for (Class clazz : ifcClasses) {
        ServiceSpec serviceSpec = new ServiceSpec(clazz);

        // register the service
        try {
            serviceManager.registerService(serviceSpec, cm.get(clazz));
        } catch (ServiceManagerException e) {
            // oops something happened, re-throw as an activation issue
            throw new ComponentActivatorException("Failed to register service ", e);
        }

    }

    // just for fun.. resolve the JCRService and get a reference to the
    // respository.
    LOG.info("Getting JCR =============================");
    JCRService service = serviceManager.getService(new ServiceSpec(JCRService.class));
    Repository repo = service.getRepository();
    for (String k : repo.getDescriptorKeys()) {
        LOG.info("  JCR Repo Key " + k + "::" + repo.getDescriptor(k));
    }
    LOG.info("Logged In OK-=============================");

    // create a ServiceSpecification for the class I want to register,
    // the class here MUST be a class that was exported (see component.xml)
    // otherwise
    // nothing else will be able to see it. The service manager might enforce
    // this if I get
    // arround to it.
    ServiceSpec serviceSpec = new ServiceSpec(HelloWorldService.class);

    // register the service
    try {
        serviceManager.registerService(serviceSpec, helloWorldService);
    } catch (ServiceManagerException e) {
        // oops something happened, re-throw as an activation issue
        throw new ComponentActivatorException("Failed to register service ", e);
    }

}

From source file:org.apache.directory.fortress.core.ldap.ApacheDsDataProvider.java

/**
 * Given a collection of {@link java.util.Properties}, convert to raw data name-value format and load into ldap
 * modification set in preparation for ldap add.
 *
 * @param props    contains {@link java.util.Properties} targeted for adding to ldap.
 * @param entry    contains ldap entry to pull attrs from.
 * @param attrName contains the name of the ldap attribute to be added.
 * @throws LdapException/*from w w  w  . j  a  va2 s  . c o m*/
 */
protected void loadProperties(Properties props, Entry entry, String attrName) throws LdapException {
    if ((props != null) && (props.size() > 0)) {
        Attribute attr = new DefaultAttribute(attrName);

        for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements();) {
            // This LDAP attr is stored as a name-value pair separated by a ':'.
            String key = (String) e.nextElement();
            String val = props.getProperty(key);
            String prop = key + GlobalIds.PROP_SEP + val;

            attr.add(prop);
        }

        if (attr.size() != 0) {
            entry.add(attr);
        }
    }
}

From source file:org.jahia.services.usermanager.ldap.LDAPUserGroupProvider.java

@Override
public List<String> searchGroups(Properties searchCriteria, long offset, long limit) {
    if (searchCriteria.containsKey("groupname") && searchCriteria.size() == 1
            && !searchCriteria.getProperty("groupname").contains("*")) {
        try {//from   w w  w. j  a v  a  2 s.  co  m
            JahiaGroup group = getGroup((String) searchCriteria.get("groupname"));
            return Arrays.asList(group.getGroupname());
        } catch (GroupNotFoundException e) {
            return Collections.emptyList();
        }
    }

    List<String> groups = new LinkedList<String>(searchGroups(searchCriteria, false));

    // handle dynamics
    if (groupConfig.isDynamicEnabled()) {
        groups.addAll(searchGroups(searchCriteria, true));
    }

    return groups.subList(Math.min((int) offset, groups.size()),
            limit < 0 ? groups.size() : Math.min((int) (offset + limit), groups.size()));
}