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:edu.ku.brc.af.core.db.BackupServiceFactory.java

/**
 * @param backFileName/*from  w w  w  . j a va 2  s .c om*/
 * @param newBackupName
 * @return
 */
public Vector<Object[]> doCompare(final Vector<String> tableNames, final String restoreFilePath) {
    String xmlName = getStatsName(restoreFilePath);
    File xmlFile = new File(xmlName);

    Properties oldStats = new Properties();
    if (xmlFile.exists()) {
        oldStats = readStats(xmlName);
    }

    Properties newStats = getCollectionStats(tableNames);
    if (oldStats != null && oldStats.size() > 0 && newStats != null && newStats.size() > 0) {
        return compareStats(tableNames, oldStats, newStats);
    }

    return null;
}

From source file:persistence.utils.CustomDBCPConnectionProvider.java

/**
 * Configuracion de DBCP.//w  w  w . j a  v  a 2s .  c om
 *
 * @param props
 * @exception HibernateException
 */
@SuppressWarnings("unchecked")
public void configure(Properties props) throws HibernateException {
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Configure CustomDBCPConnectionProvider");
        }

        // DBCP properties used to create the BasicDataSource
        Properties dbcpProperties = new Properties();

        // si estan seteadas estas propiedades cambio el Properties parametro 
        // por el que me retorna el EncryptManager

        // TODO reveer
        // Username / password
        String username = props.getProperty(Environment.USER);
        String password = props.getProperty(Environment.PASS);
        dbcpProperties.put("username", username);
        dbcpProperties.put("password", password);

        // DriverClass & url
        String jdbcDriverClass = props.getProperty(Environment.DRIVER);
        String jdbcUrl = props.getProperty(Environment.URL);
        dbcpProperties.put("driverClassName", jdbcDriverClass);
        dbcpProperties.put("url", jdbcUrl);

        // Isolation level
        String isolationLevel = props.getProperty(Environment.ISOLATION);
        if ((isolationLevel != null) && (isolationLevel.trim().length() > 0)) {
            dbcpProperties.put("defaultTransactionIsolation", isolationLevel);
        }

        // Turn off autocommit (unless autocommit property is set) 
        String autocommit = props.getProperty(AUTOCOMMIT);
        if ((autocommit != null) && (autocommit.trim().length() > 0)) {
            dbcpProperties.put("defaultAutoCommit", autocommit);
        } else {
            dbcpProperties.put("defaultAutoCommit", String.valueOf(Boolean.FALSE));
        }

        // Pool size
        String poolSize = props.getProperty(Environment.POOL_SIZE);
        if ((poolSize != null) && (poolSize.trim().length() > 0) && (Integer.parseInt(poolSize) > 0)) {
            dbcpProperties.put("maxActive", poolSize);
        }

        // Copy all "driver" properties into "connectionProperties"
        Properties driverProps = ConnectionProviderFactory.getConnectionProperties(props);
        if (driverProps.size() > 0) {
            StringBuffer connectionProperties = new StringBuffer();
            for (Iterator iter = driverProps.keySet().iterator(); iter.hasNext();) {
                String key = (String) iter.next();
                String value = driverProps.getProperty(key);
                connectionProperties.append(key).append('=').append(value);
                if (iter.hasNext()) {
                    connectionProperties.append(';');
                }
            }
            dbcpProperties.put("connectionProperties", connectionProperties.toString());
        }

        // Copy all DBCP properties removing the prefix
        for (Iterator iter = props.keySet().iterator(); iter.hasNext();) {
            String key = String.valueOf(iter.next());
            if (key.startsWith(PREFIX)) {
                String property = key.substring(PREFIX.length());
                String value = props.getProperty(key);
                dbcpProperties.put(property, value);
            }
        }

        // Backward-compatibility
        if (props.getProperty(DBCP_PS_MAXACTIVE) != null) {
            dbcpProperties.put("poolPreparedStatements", String.valueOf(Boolean.TRUE));
            dbcpProperties.put("maxOpenPreparedStatements", props.getProperty(DBCP_PS_MAXACTIVE));
        }

        // Some debug info
        if (logger.isDebugEnabled()) {
            logger.debug("Creating a DBCP BasicDataSource with the following DBCP factory properties:");
            StringWriter sw = new StringWriter();
            dbcpProperties.list(new PrintWriter(sw, true));
            logger.debug(sw.toString());
        }

        // Let the factory create the pool
        setDs((BasicDataSource) BasicDataSourceFactory.createDataSource(dbcpProperties));

        // The BasicDataSource has lazy initialization
        // borrowing a connection will start the DataSource
        // and make sure it is configured correctly.
        Connection conn = getDs().getConnection();
        conn.close();

        // Log pool statistics before continuing.
        logStatistics();
    } catch (Exception e) {
        String message = "Could not create a DBCP pool";
        logger.fatal(message, e);
        if (getDs() != null) {
            try {
                getDs().close();
            } catch (Exception e2) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Cannot close DBCP pool (not initialized)");
                }
            }
            setDs(null);
        }
        throw new HibernateException(message, e);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Configure CustomDBCPConnectionProvider complete");
    }
}

From source file:net.sf.yal10n.analyzer.ExploratoryEncodingTest.java

/**
 * Test to load java properties files with a BOM, when the first line starts with a comment.
 * @throws Exception any error//from  www . j  a v  a 2 s.  c o m
 */
@Test
public void testPropertiesWithBOMandComment() throws Exception {
    Properties properties = new Properties();
    InputStream in = ExploratoryEncodingTest.class.getResourceAsStream("/UTF8BOMwithComment.properties");

    properties.load(new InputStreamReader(in, "UTF-8"));
    Assert.assertEquals(4, properties.size());

    Assert.assertEquals("", properties.get("\ufeff#abc"));
    Assert.assertEquals("first key", properties.getProperty("testkey1"));
    Assert.assertEquals("second key", properties.getProperty("testkey2"));
    Assert.assertEquals("This file is encoded as UTF-8 with BOM .", properties.getProperty("description"));
}

From source file:net.sf.yal10n.analyzer.ExploratoryEncodingTest.java

/**
 * Test to load java properties with a BOM, when the first line is blank.
 * @throws Exception any error//from   www  .  j av a2s .c  o m
 */
@Test
public void testPropertiesWithBOMandBlankLine() throws Exception {
    Properties properties = new Properties();
    InputStream in = ExploratoryEncodingTest.class.getResourceAsStream("/UTF8BOMwithBlankLine.properties");

    properties.load(new InputStreamReader(in, "UTF-8"));
    Assert.assertEquals(4, properties.size());

    Assert.assertEquals("", properties.get("\ufeff"));
    Assert.assertEquals("first key", properties.getProperty("testkey1"));
    Assert.assertEquals("second key", properties.getProperty("testkey2"));
    Assert.assertEquals("This file is encoded as UTF-8 with BOM .", properties.getProperty("description"));
}

From source file:org.ebayopensource.turmeric.eclipse.mavenapi.impl.MavenEclipseApi.java

private Model generateModel(final ProjectMavenizationRequest req, IProgressMonitor monitor) {
    final Model model = new Model();
    model.setModelVersion("4.0.0");

    final ArtifactMetadata artifact = req.getArtifact();
    if ((monitor instanceof NullProgressMonitor) == false) {
        monitor = new SubProgressMonitor(monitor, 50);
        monitor.setTaskName("Mavenizing project->" + req.getEclipseProject());
    }//  w w  w.  ja  va 2s  .  com
    if (req.getParent() != null) {
        final ArtifactMetadata md = req.getParent();
        final Parent parent = new Parent();
        parent.setGroupId(md.getGroupId());
        parent.setArtifactId(md.getArtifactId());
        parent.setVersion(md.getVersion());
        model.setParent(parent);
    }
    monitor.worked(5);

    model.setGroupId(artifact.getGroupId());
    model.setArtifactId(artifact.getArtifactId());
    model.setVersion(artifact.getVersion());
    model.setName(req.getEclipseProject().getName());

    if (isNotBlank(artifact.getType()) && !StringUtils.equalsIgnoreCase(artifact.getType().trim(), "jar"))
        model.setPackaging(artifact.getType());

    final Properties props = req.getProperties();
    if (props != null && props.size() > 0)
        model.setProperties(props);
    monitor.worked(5);

    // build is first set into model here
    if (req.getSourcePath() != null) {
        final String sp = req.getSourcePath();
        final Build build = model.getBuild() != null ? model.getBuild() : new Build();
        build.setSourceDirectory(sp);
        model.setBuild(build);
    }

    if (req.getTestSourcePath() != null) {
        final Build build = model.getBuild() != null ? model.getBuild() : new Build();
        build.setTestSourceDirectory(req.getTestSourcePath());
        model.setBuild(build);
    }

    if (req.getTestOutputPath() != null) {
        final Build build = model.getBuild() != null ? model.getBuild() : new Build();
        build.setTestOutputDirectory(req.getTestOutputPath());
        model.setBuild(build);
    }

    if (req.getResourceDirectories() != null && req.getResourceDirectories().isEmpty() == false) {
        final Build build = model.getBuild() != null ? model.getBuild() : new Build();
        build.setResources(req.getResourceDirectories());
        model.setBuild(build);
    }
    monitor.worked(5);

    if (req.getTestResourceDirectories() != null && req.getTestResourceDirectories().isEmpty() == false) {
        final Build build = model.getBuild() != null ? model.getBuild() : new Build();
        build.setTestResources(req.getTestResourceDirectories());
        model.setBuild(build);
    }
    monitor.worked(5);

    if (req.getBuildPlugins() != null && req.getBuildPlugins().isEmpty() == false) {
        final Build build = model.getBuild() != null ? model.getBuild() : new Build();
        for (Plugin buildPlugin : req.getBuildPlugins()) {
            build.addPlugin(buildPlugin);
        }
    }

    if (req.getOutputPath() != null) {
        final Build build = model.getBuild() != null ? model.getBuild() : new Build();
        build.setOutputDirectory(req.getOutputPath());
    }

    if (req.getDependencies() != null && req.getDependencies().isEmpty() == false) {
        for (final ArtifactMetadata am : req.getDependencies()) {
            model.addDependency(MavenEclipseUtil.dependency(am));
        }
    }
    monitor.worked(5);
    return model;
}

From source file:org.wso2.carbon.cep.siddhi.backend.SiddhiBackEndRuntimeFactory.java

public CEPBackEndRuntime createCEPBackEndRuntime(String bucketName, Properties providerConfiguration,
        List<InputMapping> mappings, int tenantId) throws CEPConfigurationException {

    try {/*from  w w w .  ja  v a2  s  .  c o  m*/
        long persistenceTimeInterval = 0;
        boolean isDistributedProcessingEnabled = false;
        if (providerConfiguration != null && providerConfiguration.size() > 0) {
            String timeString = providerConfiguration.getProperty(PERSISTENCE_SNAPSHOT_TIME_INTERVAL_MINUTES);
            try {
                persistenceTimeInterval = Long.parseLong(timeString);
            } catch (NumberFormatException e) {
                log.warn(
                        "Error reading siddhi persistence snapshot time interval, hence persistence is disabled for "
                                + bucketName);
            }
            String isDistributedProcessingEnabledString = providerConfiguration
                    .getProperty(ENABLE_DISTRIBUTED_PROCESSING);
            if (isDistributedProcessingEnabledString.toLowerCase().equals("true")
                    || isDistributedProcessingEnabledString.toLowerCase().equals("false")) {
                isDistributedProcessingEnabled = Boolean.parseBoolean(isDistributedProcessingEnabledString);
            } else {
                log.warn(
                        "Error reading siddhi enable distributed processing, hence distributed processing is disabled for "
                                + bucketName);
            }
        }
        SiddhiConfiguration siddhiConfig = new SiddhiConfiguration();
        siddhiConfig.setAsyncProcessing(false); //todo check which is good?
        siddhiConfig.setQueryPlanIdentifier(bucketName);
        siddhiConfig.setInstanceIdentifier("WSO2CEP-Siddhi-Instance-" + UUID.randomUUID().toString());
        siddhiConfig.setDistributedProcessing(isDistributedProcessingEnabled);
        if (null == SiddhiBackendRuntimeValueHolder.getInstance().getSiddhiExtentions()) {
            SiddhiBackendRuntimeValueHolder.getInstance()
                    .setSiddhiExtentions(SiddhiConfigLoader.loadSiddhiExtensions());
        }
        siddhiConfig.setSiddhiExtensions(SiddhiBackendRuntimeValueHolder.getInstance().getSiddhiExtentions());
        SiddhiManager siddhiManager = new SiddhiManager(siddhiConfig);
        if (persistenceTimeInterval > 0) {
            if (null == SiddhiBackendRuntimeValueHolder.getInstance().getPersistenceStore()) {
                Cluster cluster = SiddhiBackendRuntimeValueHolder.getInstance().getDataAccessService()
                        .getCluster(SiddhiBackendRuntimeValueHolder.getInstance().getClusterInformation());
                SiddhiBackendRuntimeValueHolder.getInstance().setClusterName(cluster.getName());
                CasandraPersistenceStore casandraPersistenceStore = new CasandraPersistenceStore(cluster);
                SiddhiBackendRuntimeValueHolder.getInstance().setPersistenceStore(casandraPersistenceStore);
            }
            siddhiManager.setPersistStore(SiddhiBackendRuntimeValueHolder.getInstance().getPersistenceStore());

        }

        Map<String, InputHandler> siddhiInputHandlerMap = new HashMap<String, InputHandler>();

        for (InputMapping mapping : mappings) {

            StreamDefinition streamDefinition = new StreamDefinition();
            streamDefinition.name(mapping.getStream());

            if (mapping instanceof TupleInputMapping) {
                TupleInputMapping tupleInputMapping = (TupleInputMapping) mapping;
                List<TupleInputProperty> properties = tupleInputMapping.getProperties();
                for (TupleInputProperty property1 : properties) {
                    streamDefinition.attribute(property1.getName(),
                            SiddhiBackEndRuntime.javaToSiddhiType.get(property1.getType()));
                }
            } else if (mapping instanceof MapInputMapping) {
                MapInputMapping mapInputMapping = (MapInputMapping) mapping;
                List<MapInputProperty> properties = mapInputMapping.getProperties();
                for (MapInputProperty property1 : properties) {
                    streamDefinition.attribute(property1.getName(),
                            SiddhiBackEndRuntime.javaToSiddhiType.get(property1.getType()));
                }
            } else { //Xml mapping
                XMLInputMapping xmlInputMapping = (XMLInputMapping) mapping;
                List<XMLInputProperty> properties = xmlInputMapping.getProperties();
                for (XMLInputProperty property1 : properties) {
                    streamDefinition.attribute(property1.getName(),
                            SiddhiBackEndRuntime.javaToSiddhiType.get(property1.getType()));
                }
            }

            //            try {
            siddhiInputHandlerMap.put(mapping.getStream(), siddhiManager.defineStream(streamDefinition));
            //            } catch (SiddhiException e) {
            //                throw new CEPConfigurationException("Invalid input stream configuration for " +
            //                                                    mapping.getStream(), e);
            //            }
        }

        return new SiddhiBackEndRuntime(bucketName, siddhiManager, siddhiInputHandlerMap, tenantId,
                persistenceTimeInterval);
    } catch (Throwable e) {
        throw new CEPConfigurationException("Error occurred in creating Siddhi Backend Runtime," + e);
    }
}

From source file:org.openinfobutton.responder.service.impl.ResponderServiceImplMockitoTest.java

/**
 * Test of getApplicationProperties method, of class ResponderServiceImpl.
 *//*from w w w  . j a  va  2s . c  o m*/
@Test
public void testGetApplicationProperties() {
    System.out.println("getApplicationProperties");

    String propertyGroup = "atom.feed";
    when(responderAppPropertyDao.getAppPropertyGroup(propertyGroup)).thenReturn(getAppPropertyList());

    Properties result = responderServiceImpl.getApplicationProperties(propertyGroup);

    assertTrue(result.size() == getAppPropertyList().size());
}

From source file:org.openinfobutton.responder.service.impl.ResponderServiceImplMockitoTest.java

@Test
public void testGetApplicationProperties2() {
    System.out.println("getApplicationProperties");

    String propertyGroup = "atom.feed";
    when(responderAppPropertyDao.getAppPropertyGroup(propertyGroup)).thenReturn(getAppPropertyList());

    Properties first = responderServiceImpl.getApplicationProperties(propertyGroup);
    responderServiceImpl.setAppProperties(first);
    Properties result = responderServiceImpl.getApplicationProperties(propertyGroup);

    assertTrue(result.size() == getAppPropertyList().size());
}

From source file:net.padlocksoftware.padlock.license.LicenseImpl.java

public boolean equals(Object obj) {
    if (this == obj)
        return true;

    if (obj instanceof LicenseImpl) {
        LicenseImpl other = (LicenseImpl) obj;
        Properties properties = other.props;
        if (props.size() != properties.size())
            return false;
        for (String key : propertyNames(props)) {
            String value = props.getProperty(key);
            if (!value.equals(properties.getProperty(key))) {
                return false;
            }// w w w  . j  av a 2 s.co  m
        }

        return true;

    } else
        return false;
}

From source file:io.cloudslang.content.database.utils.SQLInputsUtilsTest.java

@Test
public void getOrDefaultDBPoolingPropertiesDefault() throws Exception {
    final Properties dbProperties = getOrDefaultDBPoolingProperties(EMPTY, "Truth = Beauty");
    assertThat("Beauty", is(dbProperties.getProperty("Truth")));
    assertThat(1, is(dbProperties.size()));
}