Example usage for java.util Hashtable size

List of usage examples for java.util Hashtable size

Introduction

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

Prototype

public synchronized int size() 

Source Link

Document

Returns the number of keys in this hashtable.

Usage

From source file:org.hdiv.webflow.validator.EditableParameterValidator.java

/**
 * Obtains the errors from request detected by HDIV during the validation
 * process of the editable parameters.//from   w w w.ja v  a  2  s  .  c  o  m
 * 
 * @param formObject form object
 * @param errors errors detected by HDIV during the validation process of
 *            the editable parameters.
 */
public void validateEditableParameters(Object formObject, Errors errors) {

    ExternalContext externalContext = ExternalContextHolder.getExternalContext();
    Hashtable editableParameters = (Hashtable) externalContext.getRequestMap().get(EDITABLE_PARAMETER_ERROR);

    if ((editableParameters != null) && (editableParameters.size() > 0)) {

        for (Iterator it = editableParameters.keySet().iterator(); it.hasNext();) {

            String currentParameter = (String) it.next();
            String[] currentUnauthorizedValues = (String[]) editableParameters.get(currentParameter);

            if ((currentUnauthorizedValues.length == 1)
                    && (currentUnauthorizedValues[0].equals(HDIV_EDITABLE_PASSWORD_ERROR))) {

                errors.rejectValue(currentParameter, HDIV_EDITABLE_PASSWORD_ERROR);

            } else {
                String printedValue = this.createMessageError(currentUnauthorizedValues);
                errors.rejectValue(currentParameter, HDIV_EDITABLE_ERROR, new String[] { printedValue },
                        printedValue + " has not allowed characters");
            }
        }
    }
}

From source file:org.sipfoundry.sipxconfig.admin.commserver.configdb.ConfigDbSettingAdaptor.java

public boolean set(Setting setting) {
    Hashtable params = new Hashtable();
    setting.acceptVisitor(new ParamsCollector(params));
    int set = m_configDbParameter.set(setting.getProfileName(), params);
    return set == params.size();
}

From source file:org.wso2.carbon.custom.connector.EJBFactory.java

public Object[] buildArguments(MessageContext synCtx, String methodName) {
    log.info("inside build arg");
    Hashtable dyValues = getParameters(synCtx, methodName);
    Object[] args = new Object[dyValues.size()];
    Set set = dyValues.entrySet();
    int i = 0;//from   www .  jav  a 2 s  . com
    for (Object aSet : set) {
        Map.Entry entry = (Map.Entry) aSet;
        args[i] = entry.getValue();
        i++;
    }
    return args;

}

From source file:org.hdiv.web.validator.EditableParameterValidatorTest.java

@SuppressWarnings("unchecked")
public void testEditableValidator() {

    MockHttpServletRequest request = (MockHttpServletRequest) HDIVUtil.getHttpServletRequest();

    this.dataComposer.beginRequest(this.targetName);
    this.dataComposer.compose("paramName", "", true, "text");

    String pageState = this.dataComposer.endRequest();
    this.dataComposer.endPage();

    request.addParameter(hdivParameter, pageState);
    request.addParameter("paramName", "<script>storeCookie()</script>");

    RequestWrapper requestWrapper = new RequestWrapper(request);
    boolean result = helper.validate(requestWrapper).isValid();
    assertTrue(result);/* w w w .  j ava2 s  .c o m*/

    // Editable errors in request?
    Hashtable<String, String[]> parameters = (Hashtable<String, String[]>) requestWrapper
            .getAttribute(Constants.EDITABLE_PARAMETER_ERROR);
    assertEquals(1, parameters.size());

    // Set request attributes on threadlocal
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(requestWrapper));

    // New Editable instance
    EditableParameterValidator validator = new EditableParameterValidator();
    Errors errors = new MapBindingResult(new HashMap<String, String>(), "");
    assertFalse(errors.hasErrors());

    // move errors to Errors instance
    validator.validate("anyObject", errors);
    assertTrue(errors.hasErrors());

}

From source file:org.hdiv.web.validator.AbstractEditableParameterValidator.java

@SuppressWarnings("unchecked")
protected void validateEditableParameter(String param, Errors errors) {

    RequestAttributes attr = RequestContextHolder.getRequestAttributes();
    if (attr == null) {
        // This is not a web request
        return;//ww w . j  a  va2s .com
    }

    Hashtable<String, String[]> parameters = (Hashtable<String, String[]>) attr
            .getAttribute(Constants.EDITABLE_PARAMETER_ERROR, 0);
    if (parameters != null && parameters.size() > 0) {

        String[] unauthorizedValues = parameters.get(param);
        if (unauthorizedValues != null && unauthorizedValues.length > 0) {

            this.rejectParamValues(param, unauthorizedValues, errors);
        }
    }
}

From source file:org.hdiv.web.validator.AbstractEditableParameterValidator.java

/**
 * Obtains the errors from request detected by HDIV during the validation process of the editable parameters.
 * //from w  ww .  j a  v a  2s.  c  om
 * @param errors
 *            errors detected by HDIV during the validation process of the editable parameters.
 */
@SuppressWarnings("unchecked")
protected void validateEditableParameters(Errors errors) {

    RequestAttributes attr = RequestContextHolder.getRequestAttributes();
    if (attr == null) {
        // This is not a web request
        return;
    }

    Hashtable<String, String[]> parameters = (Hashtable<String, String[]>) attr
            .getAttribute(Constants.EDITABLE_PARAMETER_ERROR, 0);
    if (parameters != null && parameters.size() > 0) {

        for (String param : parameters.keySet()) {

            String[] unauthorizedValues = parameters.get(param);

            this.rejectParamValues(param, unauthorizedValues, errors);
        }
    }
}

From source file:com.apatar.flickr.function.UploadPhotoFlickrTable.java

public List<KeyInsensitiveMap> execute(FlickrNode node, Hashtable<String, Object> values, String strApi,
        String strSecret) throws IOException, XmlRpcException {
    byte[] photo = (byte[]) values.get("photo");

    int size = values.size() + 2;

    values.remove("photo");

    File newFile = ApplicationData.createFile("flicr", photo);

    PostMethod post = new PostMethod("http://api.flickr.com/services/upload");
    Part[] parts = new Part[size];

    parts[0] = new FilePart("photo", newFile);
    parts[1] = new StringPart("api_key", strApi);
    int i = 2;// w  ww  .ja  v  a  2  s  .c om
    for (String key : values.keySet())
        parts[i++] = new StringPart(key, values.get(key).toString());

    values.put("api_key", strApi);

    parts[i] = new StringPart("api_sig", FlickrUtils.Sign(values, strApi, strSecret));

    post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));

    HttpClient client = new HttpClient();
    client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
    int status = client.executeMethod(post);
    if (status != HttpStatus.SC_OK) {
        JOptionPane.showMessageDialog(ApatarUiMain.MAIN_FRAME,
                "Upload failed, response=" + HttpStatus.getStatusText(status));
        return null;
    } else {
        InputStream is = post.getResponseBodyAsStream();
        try {
            return createKeyInsensitiveMapFromElement(FlickrUtils.getRootElementFromInputStream(is));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}

From source file:nl.nn.adapterframework.jms.JNDIBase.java

/**
 *  Gets the Context<br/>//from   w ww  .j  a  va  2 s . c  o  m
 *  When InitialContextFactory and ProviderURL are set, these are used
 *  to get the <code>Context</code>. Otherwise the the InitialContext is
 *  retrieved without parameters.<br/>
 *  <b>Notice:</b> you can set the parameters on the commandline with <br/>
 *  java -Djava.naming.factory.initial= xxx -Djava.naming.provider.url=xxx
 * <br/><br/>
 *
 * @return                                   The context value
 * @exception  javax.naming.NamingException  Description of the Exception
 */
public Context getContext() throws NamingException {

    if (null == context) {
        Hashtable jndiEnv = getJndiEnv();
        if (jndiEnv.size() > 0) {
            log.debug("creating initial JNDI-context using specified environment");
            context = (Context) new InitialContext(jndiEnv);
        } else {
            log.debug("creating initial JNDI-context");
            context = (Context) new InitialContext();
        }
    }
    return context;
}

From source file:graficos.GraficoBarras.java

private void actualizarConjuntoDatos(Hashtable<Integer, Integer> datos_tabla, Integer rec_max_disp) {
    String serie_u = "Utilizados";
    String serie_d = "No utilizados";
    double num_u, num_d;
    Integer dias_totales = new Integer(datos_tabla.size());
    for (Integer dia = 1; dia <= dias_totales; dia++) {
        num_d = rec_max_disp - datos_tabla.get(dia);
        ((DefaultCategoryDataset) cjto_datos).addValue(num_d, serie_d, dia);
        num_u = datos_tabla.get(dia);/*from  w w  w  .jav  a 2 s .c o  m*/
        ((DefaultCategoryDataset) cjto_datos).addValue(num_u, serie_u, dia);
    }
}

From source file:algorithm.F5SteganographyTest.java

@Test
public void f5SteganographyAlgorithmTest() {
    try {/*from  w  ww  . java 2s  .  co m*/
        File carrier = TestDataProvider.JPG_FILE;
        File payload = TestDataProvider.TXT_FILE;
        F5Steganography algorithm = new F5Steganography();
        // Test encapsulation:
        List<File> payloadList = new ArrayList<File>();
        payloadList.add(payload);
        File outputFile = algorithm.encapsulate(carrier, payloadList);
        assertNotNull(outputFile);
        // Test restore:
        Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>();
        for (RestoredFile file : algorithm.restore(outputFile)) {
            outputHash.put(file.getName(), file);
        }
        assertEquals(outputHash.size(), 2);
        RestoredFile restoredCarrier = outputHash.get(carrier.getName());
        RestoredFile restoredPayload = outputHash.get(payload.getName());
        assertNotNull(restoredCarrier);
        assertNotNull(restoredPayload);
        // only original payload can be restored, not carrier
        assertEquals(FileUtils.checksumCRC32(payload), FileUtils.checksumCRC32(restoredPayload));
        assertEquals(FileUtils.checksumCRC32(outputFile), FileUtils.checksumCRC32(restoredCarrier));

        // check restoration metadata:
        assertEquals("" + carrier.getAbsolutePath(), restoredCarrier.originalFilePath);
        assertEquals("" + payload.getAbsolutePath(), restoredPayload.originalFilePath);
        assertEquals(algorithm, restoredCarrier.algorithm);
        // This can't be true for steganography algorithms:
        // assertTrue(restoredCarrier.checksumValid);
        assertTrue(restoredPayload.checksumValid);
        assertTrue(restoredCarrier.wasCarrier);
        assertFalse(restoredCarrier.wasPayload);
        assertTrue(restoredPayload.wasPayload);
        assertFalse(restoredPayload.wasCarrier);
        assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload));
        assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier));
        assertTrue(restoredPayload.relatedFiles.contains(restoredCarrier));
        assertFalse(restoredPayload.relatedFiles.contains(restoredPayload));
    } catch (IOException e) {
        e.printStackTrace();
    }
}