Example usage for java.util Hashtable Hashtable

List of usage examples for java.util Hashtable Hashtable

Introduction

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

Prototype

public Hashtable() 

Source Link

Document

Constructs a new, empty hashtable with a default initial capacity (11) and load factor (0.75).

Usage

From source file:algorithm.MetsSubmissionInformationPackageTest.java

@Test
public void MetsSipTest() {
    try {/*ww w.  j  av  a  2 s .co  m*/
        File carrier = TestDataProvider.TXT_FILE;
        File payload1 = TestDataProvider.TXT_FILE_2;
        File payload2 = TestDataProvider.XML_FILE;
        List<File> payloadList = new ArrayList<File>();
        payloadList.add(payload1);
        payloadList.add(payload2);

        MetsSubmissionInformationPackage algorithm = new MetsSubmissionInformationPackage();
        // Test encapsulation:
        File outputFile = algorithm.encapsulate(carrier, payloadList);
        assertNotNull(outputFile);
        assertTrue(outputFile.length() > carrier.length());

        // Test restore:
        Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>();
        for (RestoredFile file : algorithm.restore(outputFile)) {
            outputHash.put(file.getName(), file);
        }
        assertEquals(4, outputHash.size());// files+map!
        RestoredFile restoredCarrier = outputHash.get(carrier.getName());
        RestoredFile restoredPayload1 = outputHash.get(payload1.getName());
        RestoredFile restoredPayload2 = outputHash.get(payload2.getName());
        assertNotNull(restoredCarrier);
        assertNotNull(restoredPayload1);
        assertNotNull(restoredPayload2);
        assertEquals(FileUtils.checksumCRC32(carrier), FileUtils.checksumCRC32(restoredCarrier));
        assertEquals(FileUtils.checksumCRC32(payload1), FileUtils.checksumCRC32(restoredPayload1));
        assertEquals(FileUtils.checksumCRC32(payload2), FileUtils.checksumCRC32(restoredPayload2));

        // check restoration metadata:
        assertEquals(algorithm, restoredCarrier.algorithm);
        assertTrue(restoredCarrier.checksumValid);
        assertTrue(restoredPayload1.checksumValid);
        assertTrue(restoredPayload2.checksumValid);
        // every file in a zip package is payload!:
        assertTrue(restoredCarrier.wasPayload);
        assertFalse(restoredCarrier.wasCarrier);
        assertTrue(restoredPayload1.wasPayload);
        assertFalse(restoredPayload1.wasCarrier);
        assertTrue(restoredPayload2.wasPayload);
        assertFalse(restoredPayload2.wasCarrier);
        assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload1));
        assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload2));
        assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier));
        assertTrue(restoredPayload1.relatedFiles.contains(restoredCarrier));
        assertTrue(restoredPayload1.relatedFiles.contains(restoredPayload2));
        assertFalse(restoredPayload1.relatedFiles.contains(restoredPayload1));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.control.JMTimer.java

/** Creates a new instance of JMTimer */
public JMTimer(DispatchServ dispatcher) {
    this.dispatcher = dispatcher;
    timer = new Timer();
    sessionTasks = new Hashtable();

}

From source file:algorithm.OaiOreSubmissionInformationPackageTest.java

@Test
public void OaiOreSipTest() {
    try {//  www.ja  va2 s  .c  om
        File carrier = TestDataProvider.TXT_FILE;
        File payload1 = TestDataProvider.TXT_FILE_2;
        File payload2 = TestDataProvider.XML_FILE;
        List<File> payloadList = new ArrayList<File>();
        payloadList.add(payload1);
        payloadList.add(payload2);

        OaiOreSubmissionInformationPackage algorithm = new OaiOreSubmissionInformationPackage();
        // Test encapsulation:
        File outputFile = algorithm.encapsulate(carrier, payloadList);
        assertNotNull(outputFile);
        assertTrue(outputFile.length() > carrier.length());

        // Test restore:
        Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>();
        for (RestoredFile file : algorithm.restore(outputFile)) {
            outputHash.put(file.getName(), file);
        }
        assertEquals(4, outputHash.size());// files+map!
        RestoredFile restoredCarrier = outputHash.get(carrier.getName());
        RestoredFile restoredPayload1 = outputHash.get(payload1.getName());
        RestoredFile restoredPayload2 = outputHash.get(payload2.getName());
        assertNotNull(restoredCarrier);
        assertNotNull(restoredPayload1);
        assertNotNull(restoredPayload2);
        assertEquals(FileUtils.checksumCRC32(carrier), FileUtils.checksumCRC32(restoredCarrier));
        assertEquals(FileUtils.checksumCRC32(payload1), FileUtils.checksumCRC32(restoredPayload1));
        assertEquals(FileUtils.checksumCRC32(payload2), FileUtils.checksumCRC32(restoredPayload2));

        // check restoration metadata:
        assertEquals(algorithm, restoredCarrier.algorithm);
        assertTrue(restoredCarrier.checksumValid);
        assertTrue(restoredPayload1.checksumValid);
        assertTrue(restoredPayload2.checksumValid);
        // every file in a zip package is payload!:
        assertTrue(restoredCarrier.wasPayload);
        assertFalse(restoredCarrier.wasCarrier);
        assertTrue(restoredPayload1.wasPayload);
        assertFalse(restoredPayload1.wasCarrier);
        assertTrue(restoredPayload2.wasPayload);
        assertFalse(restoredPayload2.wasCarrier);
        assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload1));
        assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload2));
        assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier));
        assertTrue(restoredPayload1.relatedFiles.contains(restoredCarrier));
        assertTrue(restoredPayload1.relatedFiles.contains(restoredPayload2));
        assertFalse(restoredPayload1.relatedFiles.contains(restoredPayload1));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:dk.netarkivet.common.distribute.Synchronizer.java

/**
 * Initialise maps containing requests and replies.
 *//*from w ww.j  ava 2 s.c om*/
public Synchronizer() {
    requests = new Hashtable<String, NetarkivetMessage>();
    replies = new Hashtable<String, NetarkivetMessage>();
}

From source file:io.apiman.gateway.engine.policies.auth.LDAPIdentityValidator.java

/**
 * @see io.apiman.gateway.engine.policies.auth.IIdentityValidator#validate(java.lang.String, java.lang.String, io.apiman.gateway.engine.beans.ServiceRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.async.IAsyncHandler)
 *//*from w w  w .  j av a 2  s  . co m*/
@Override
public void validate(String username, String password, ServiceRequest request, IPolicyContext context,
        LDAPIdentitySource config, IAsyncResultHandler<Boolean> handler) {
    String url = config.getUrl();
    String dn = formatDn(config.getDnPattern(), username, request);

    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); //$NON-NLS-1$
    env.put(Context.PROVIDER_URL, url);

    env.put(Context.SECURITY_AUTHENTICATION, "simple"); //$NON-NLS-1$
    env.put(Context.SECURITY_PRINCIPAL, dn);
    env.put(Context.SECURITY_CREDENTIALS, password);
    try {
        new InitialDirContext(env);
        handler.handle(AsyncResultImpl.create(Boolean.TRUE));
    } catch (AuthenticationException e) {
        handler.handle(AsyncResultImpl.create(Boolean.FALSE));
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.adobe.acs.commons.http.headers.impl.AbstractExpiresHeaderFilterTest.java

@Before
public void setup() throws Exception {
    properties = new Hashtable<String, Object>();
    properties.put(AbstractExpiresHeaderFilter.PROP_EXPIRES_TIME, exipres);

    agents = new HashSet<String>();
    expires = new HashSet<String>();
    params = new HashMap();

    filter = new AbstractExpiresHeaderFilter() {
        @Override// ww  w  . j  a  v  a2 s  .  c o  m
        protected void adjustExpires(Calendar nextExpiration) {
            // Do nothing.
        }
    };

    when(request.getMethod()).thenReturn("GET");
    when(request.getParameterMap()).thenReturn(params);
    agents.add(AbstractDispatcherCacheHeaderFilter.DISPATCHER_AGENT_HEADER_VALUE);
    when(request.getHeaders(AbstractDispatcherCacheHeaderFilter.SERVER_AGENT_NAME))
            .thenReturn(Collections.enumeration(agents));

}

From source file:com.bstek.dorado.data.entity.BeanEntityEnhancer.java

protected synchronized void buildReflectionCahce() throws Exception {
    synchronized (cachedTypes) {
        if (!cachedTypes.contains(beanType)) {
            cachedTypes.add(beanType);// w w w .  j a va 2 s  .co m

            Map<String, Boolean> properties = new Hashtable<String, Boolean>();
            Map<Method, String> readMethods = new Hashtable<Method, String>();
            Map<Method, String> writeMethods = new Hashtable<Method, String>();
            PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(beanType);
            for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
                String property = propertyDescriptor.getName();
                if (propertyDescriptor.getReadMethod() == null) {
                    continue;
                }

                properties.put(property, Boolean.valueOf(propertyDescriptor.getWriteMethod() != null));

                Method readMethod = propertyDescriptor.getReadMethod();
                Method writeMethod = propertyDescriptor.getWriteMethod();
                if (readMethod != null) {
                    if (readMethod.getDeclaringClass() != beanType) {
                        readMethod = beanType.getMethod(readMethod.getName(), readMethod.getParameterTypes());
                    }
                    readMethods.put(readMethod, property);
                }
                if (writeMethod != null) {
                    if (writeMethod.getDeclaringClass() != beanType) {
                        writeMethod = beanType.getMethod(writeMethod.getName(),
                                writeMethod.getParameterTypes());
                    }
                    writeMethods.put(writeMethod, property);
                }
            }
            propertiesCache.put(beanType, properties);
            readMethodsCache.put(beanType, readMethods);
            writeMethodsCache.put(beanType, writeMethods);
            this.properties = properties;
            this.readMethods = readMethods;
            this.writeMethods = writeMethods;
        } else {
            this.properties = propertiesCache.get(beanType);
            this.readMethods = readMethodsCache.get(beanType);
            this.writeMethods = writeMethodsCache.get(beanType);
        }
    }
}

From source file:werecloud.api.controller.v1_0_0.VirtualMachineController.java

@RequestMapping(value = "name/{mac}.json", method = RequestMethod.GET)
public ModelAndView getVMNameFromMacJSON(@PathVariable("mac") String mac) {
    Map<String, String> toRet = new Hashtable<String, String>();
    toRet.put(mac, con.getVM(mac));//ww w.  j  a  va2s.c  o m
    return new ModelAndView("json", "model", toRet);
}

From source file:de.msg.terminfindung.common.jmx.TestJmxUeberwachung.java

@Test
public void testJmxUeberwachung() throws Exception {
    // SpringContext initialisieren und Komponente holen
    //Meldung meldung = (Meldung) SpringContextHolder.getBean("meldung");
    // Holen des MBeanServers
    ArrayList<MBeanServer> mBeanServerList = MBeanServerFactory.findMBeanServer(null);
    MBeanServer mBeanServer = mBeanServerList.get(0);
    // Lesen der gewnschten Information per JMX
    // de.bund.bva.isyfact.terminfindung:type=ServiceStatistik,name=&quot;Erstellung-Statistik&quot;
    Hashtable<String, String> table = new Hashtable<>();
    table.put("type", "ServiceStatistik");
    table.put("name", "\"Erstellung-Statistik\"");
    ObjectName testObjectName = new ObjectName("de.bund.bva.isyfact.terminfindung", table);
    String testAttributeName = "DurchschnittsDauerLetzteAufrufe";
    String result = mBeanServer.getAttribute(testObjectName, testAttributeName).toString();
    // Auswerten des Ergebnisses
    assertEquals("0", result);
    // Einen Anwendungsfall ausfhren
    contr.initialisiereModel(new ErstellenModel());
    result = mBeanServer.getAttribute(testObjectName, testAttributeName).toString();
    assertNotEquals("0", result);
}

From source file:com.hexidec.ekit.component.PropertiesDialog.java

public PropertiesDialog(Window parent, String[] fields, String[] types, String[] values, String title,
        boolean bModal) {
    super(parent, title);
    setModal(bModal);/*from  www  .  j  a  va 2s .  co m*/
    htInputFields = new Hashtable<String, JComponent>();
    final Object[] buttonLabels = { Translatrix.getTranslationString("DialogAccept"),
            Translatrix.getTranslationString("DialogCancel") };
    List<Object> panelContents = new ArrayList<Object>();
    for (int iter = 0; iter < fields.length; iter++) {
        String fieldName = fields[iter];
        String fieldType = types[iter];
        JComponent fieldComponent;
        JComponent panelComponent = null;
        if (fieldType.equals("text") || fieldType.equals("integer")) {
            fieldComponent = new JTextField(3);
            if (values[iter] != null && values[iter].length() > 0) {
                ((JTextField) (fieldComponent)).setText(values[iter]);
            }

            if (fieldType.equals("integer")) {
                ((AbstractDocument) ((JTextField) (fieldComponent)).getDocument())
                        .setDocumentFilter(new DocumentFilter() {

                            @Override
                            public void insertString(FilterBypass fb, int offset, String text,
                                    AttributeSet attrs) throws BadLocationException {
                                replace(fb, offset, 0, text, attrs);
                            }

                            @Override
                            public void replace(FilterBypass fb, int offset, int length, String text,
                                    AttributeSet attrs) throws BadLocationException {

                                if (StringUtils.isNumeric(text)) {
                                    super.replace(fb, offset, length, text, attrs);
                                }

                            }

                        });
            }
        } else if (fieldType.equals("bool")) {
            fieldComponent = new JCheckBox(fieldName);
            if (values[iter] != null) {
                ((JCheckBox) (fieldComponent)).setSelected(values[iter] == "true");
            }
            panelComponent = fieldComponent;
        } else if (fieldType.equals("combo")) {
            fieldComponent = new JComboBox();
            if (values[iter] != null) {
                StringTokenizer stParse = new StringTokenizer(values[iter], ",", false);
                while (stParse.hasMoreTokens()) {
                    ((JComboBox) (fieldComponent)).addItem(stParse.nextToken());
                }
            }
        } else {
            fieldComponent = new JTextField(3);
        }
        htInputFields.put(fieldName, fieldComponent);
        if (panelComponent == null) {
            panelContents.add(fieldName);
            panelContents.add(fieldComponent);
        } else {
            panelContents.add(panelComponent);
        }
    }
    jOptionPane = new JOptionPane(panelContents.toArray(), JOptionPane.QUESTION_MESSAGE,
            JOptionPane.OK_CANCEL_OPTION, null, buttonLabels, buttonLabels[0]);

    setContentPane(jOptionPane);
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

    jOptionPane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();
            if (isVisible() && (e.getSource() == jOptionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY)
                    || prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
                Object value = jOptionPane.getValue();
                if (value == JOptionPane.UNINITIALIZED_VALUE) {
                    return;
                }
                if (value.equals(buttonLabels[0])) {
                    setVisible(false);
                } else {
                    setVisible(false);
                }
            }
        }
    });
    this.pack();
    setLocation(SwingUtilities.getPointForCentering(this, parent));
}