Example usage for java.util Hashtable put

List of usage examples for java.util Hashtable put

Introduction

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

Prototype

public synchronized V put(K key, V value) 

Source Link

Document

Maps the specified key to the specified value in this hashtable.

Usage

From source file:algorithm.PDFFileAttacherTest.java

@Test
public void pdfSingleFileAttacherTest() {
    try {//from ww w.ja v a2 s .co m
        File carrier = TestDataProvider.PDF_FILE;
        File payload = TestDataProvider.TXT_FILE;
        PDFFileAttacher algorithm = new PDFFileAttacher();
        // Test encapsulation:
        List<File> payloadList = new ArrayList<File>();
        payloadList.add(payload);
        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(2, outputHash.size());
        RestoredFile restoredCarrier = outputHash.get(carrier.getName());
        RestoredFile restoredPayload = outputHash.get(payload.getName());
        assertNotNull(restoredCarrier);
        assertNotNull(restoredPayload);
        /*
         * TODO: as long as I can see, it is at the moment not possible to
         * remove the attached file with pdf box, so we can't restore the
         * carrier. We would have to use a different pdf library to solve
         * this.
         */
        // assertEquals(FileUtils.checksumCRC32(carrier),
        // FileUtils.checksumCRC32(restoredCarrier));
        assertEquals(FileUtils.checksumCRC32(payload), FileUtils.checksumCRC32(restoredPayload));

        // check restoration metadata:
        // (This algorithm doesn't save original file paths, as it doesn't
        // use the payload segment)
        assertEquals(algorithm, restoredCarrier.algorithm);
        // 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();
    }
}

From source file:com.cloudbase.datacommands.CBSearchCondition.java

/**
 * Add a sorting condition to your search. You can add multiple fields to sort by.
 * It is only possible to sort on top level fields and not on objects.
 * @param field The name of the field in the collection
 * @param direction The direction of the sort (1 = ascending / -1 = descending)
 *//*ww w  . j  a va  2  s.  c  o  m*/
public void addSortField(String field, int direction) {
    if (this.sortKeys == null)
        this.sortKeys = new Vector();

    Hashtable newSortField = new Hashtable();
    newSortField.put(field, "" + direction);
    this.sortKeys.addElement(newSortField);
}

From source file:algorithm.PDFFileAttacherTest.java

@Test
public void pdfMultipleFileAttacherTest() {
    try {/*from  w  ww .ja v  a 2 s  .  co m*/
        File carrier = TestDataProvider.PDF_FILE;
        File payload1 = TestDataProvider.TXT_FILE;
        File payload2 = TestDataProvider.TXT_FILE_2;
        List<File> payloadList = new ArrayList<File>();
        payloadList.add(payload1);
        payloadList.add(payload2);

        PDFFileAttacher algorithm = new PDFFileAttacher();
        // 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(3, outputHash.size());
        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);
        assertTrue(restoredCarrier.wasCarrier);
        assertFalse(restoredCarrier.wasPayload);
        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:algorithm.TarPackagingTest.java

@Test
public void multipleTarPackagingTest() {
    try {//from ww  w .j a va  2  s .  c  o  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);

        TarPackaging algorithm = new TarPackaging();
        // Test encapsulation:
        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(3, outputHash.size());
        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:
        // (algorithm doesn't save original file paths and checksums, as it
        // doesn't use the payload segment and restoration metadata)
        assertEquals(algorithm, restoredCarrier.algorithm);
        assertTrue(restoredCarrier.checksumValid);
        assertTrue(restoredPayload1.checksumValid);
        assertTrue(restoredPayload2.checksumValid);
        // Every file in a .tar archive is a payload file!
        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:com.modeln.build.ctrl.charts.CMnBuildListChart.java

/**
 * Generate a stacked bar graph representing test counts for each product area. 
 *
 * @param   builds   List of builds//from   w  ww . j ava2  s . c o  m
 * @param   suites   List of test suites
 * @param   areas    List of product areas 
 * 
 * @return  Pie graph representing build execution times across all builds 
 */
public static final JFreeChart getAreaTestCountChart(Vector<CMnDbBuildData> builds,
        Vector<CMnDbTestSuite> suites, Vector<CMnDbFeatureOwnerData> areas) {
    JFreeChart chart = null;

    // Collect the total times for each build, organized by area
    // This hashtable maps a build to the area/time information for that build
    Hashtable<Integer, Hashtable> buildTotals = new Hashtable<Integer, Hashtable>();

    // Generate placeholders for each build so the chart maintains a 
    // format consistent with the other charts that display build information
    if (builds != null) {
        Enumeration buildList = builds.elements();
        while (buildList.hasMoreElements()) {
            CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement();
            // Create the empty area list
            buildTotals.put(new Integer(build.getId()), new Hashtable<String, Integer>());
        }
    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    if ((suites != null) && (suites.size() > 0)) {

        // Collect build test numbers for each of the builds in the list 
        Enumeration suiteList = suites.elements();
        while (suiteList.hasMoreElements()) {

            // Process the test summary for the current build
            CMnDbTestSuite suite = (CMnDbTestSuite) suiteList.nextElement();
            Integer buildId = new Integer(suite.getParentId());
            Integer testCount = new Integer(suite.getTestCount());

            // Parse the build information so we can track the time by build
            Hashtable<String, Integer> areaCount = null;
            if (buildTotals.containsKey(buildId)) {
                areaCount = (Hashtable) buildTotals.get(buildId);
            } else {
                areaCount = new Hashtable<String, Integer>();
                buildTotals.put(buildId, areaCount);
            }

            // Iterate through each product area to determine who owns this suite
            CMnDbFeatureOwnerData area = null;
            Iterator iter = areas.iterator();
            while (iter.hasNext()) {
                CMnDbFeatureOwnerData currentArea = (CMnDbFeatureOwnerData) iter.next();
                if (currentArea.hasFeature(suite.getGroupName())) {
                    area = currentArea;
                }
            }

            // Add the elapsed time for the current suite to the area total
            Integer totalValue = null;
            String areaName = area.getDisplayName();
            if (areaCount.containsKey(areaName)) {
                Integer oldTotal = (Integer) areaCount.get(areaName);
                totalValue = oldTotal + testCount;
            } else {
                totalValue = testCount;
            }
            areaCount.put(areaName, totalValue);

        } // while list has elements

        // Make sure every area is represented in the build totals
        Enumeration bt = buildTotals.keys();
        while (bt.hasMoreElements()) {
            // Get the build ID for the current build
            Integer bid = (Integer) bt.nextElement();

            // Get the list of area totals for the current build
            Hashtable<String, Integer> ac = (Hashtable<String, Integer>) buildTotals.get(bid);
            Iterator a = areas.iterator();
            while (a.hasNext()) {
                // Add a value of zero if no total was found for the current area
                CMnDbFeatureOwnerData area = (CMnDbFeatureOwnerData) a.next();
                if (!ac.containsKey(area.getDisplayName())) {
                    ac.put(area.getDisplayName(), new Integer(0));
                }
            }
        }

        // Populate the data set with the area times for each build
        Collections.sort(builds, new CMnBuildIdComparator());
        Enumeration bList = builds.elements();
        while (bList.hasMoreElements()) {
            CMnDbBuildData build = (CMnDbBuildData) bList.nextElement();
            Integer buildId = new Integer(build.getId());
            Hashtable areaCount = (Hashtable) buildTotals.get(buildId);

            Enumeration areaKeys = areaCount.keys();
            while (areaKeys.hasMoreElements()) {
                String area = (String) areaKeys.nextElement();
                Integer count = (Integer) areaCount.get(area);
                dataset.addValue(count, area, buildId);
            }
        }

    } // if list has elements

    // API: ChartFactory.createStackedBarChart(title, domainAxisLabel, rangeAxisLabel, dataset, orientation, legend, tooltips, urls)
    chart = ChartFactory.createStackedBarChart("Automated Tests by Area", "Builds", "Test Count", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    // get a reference to the plot for further customization...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    chartFormatter.formatAreaChart(plot, dataset);

    return chart;
}

From source file:org.springframework.amqp.support.converter.Jackson2JsonMessageConverterTests.java

@Test
@SuppressWarnings("unchecked")
public void hashtable() {
    Hashtable<String, String> hashtable = new Hashtable<String, String>();
    hashtable.put("TICKER", "VMW");
    hashtable.put("PRICE", "103.2");

    Message message = converter.toMessage(hashtable, new MessageProperties());
    Hashtable<String, String> marhsalledHashtable = (Hashtable<String, String>) converter.fromMessage(message);

    assertEquals("VMW", marhsalledHashtable.get("TICKER"));
    assertEquals("103.2", marhsalledHashtable.get("PRICE"));
}

From source file:com.fluidinfo.fom.Object.java

@Override
public void getItem() throws FluidException, IOException, FOMException, JSONException {
    Hashtable<String, String> args = new Hashtable<String, String>();
    args.put("showAbout", "True");
    FluidResponse response = this.Call(Method.GET, 200, "", args);
    JSONObject jsonResult = this.getJsonObject(response);
    this.about = jsonResult.getString("about");
    if (jsonResult.has("tagPaths")) {
        this.tagPaths = StringUtil.getStringArrayFromJSONArray(jsonResult.getJSONArray("tagPaths"));
    } else {/* w  ww  .  j  a  v  a 2  s .  c o m*/
        this.tagPaths = new String[0];
    }
}

From source file:com.jkoolcloud.tnt4j.streams.inputs.JMSStream.java

@Override
protected void initialize() throws Exception {
    super.initialize();

    if (StringUtils.isEmpty(serverURL)) {
        throw new IllegalStateException(
                StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                        "TNTInputStream.property.undefined", StreamProperties.PROP_SERVER_URI));
    }//from w  w w. jav a2 s .co m

    if (StringUtils.isEmpty(queueName) && StringUtils.isEmpty(topicName)) {
        throw new IllegalStateException(StreamsResources.getStringFormatted(
                StreamsResources.RESOURCE_BUNDLE_NAME, "TNTInputStream.property.undefined.one.of",
                StreamProperties.PROP_QUEUE_NAME, StreamProperties.PROP_TOPIC_NAME));
    }

    jmsDataReceiver = new JMSDataReceiver();
    Hashtable<String, String> env = new Hashtable<>(2);
    env.put(Context.INITIAL_CONTEXT_FACTORY, jndiFactory);
    env.put(Context.PROVIDER_URL, serverURL);

    Context ic = new InitialContext(env);

    jmsDataReceiver.initialize(ic, StringUtils.isEmpty(queueName) ? topicName : queueName, jmsConnFactory);
}

From source file:com.khubla.cbean.serializer.impl.json.JSONObjectSerializer.java

@Override
public Object deserialize(String str) throws SerializerException {
    try {//w  w w .j a va 2 s .  co  m
        final JSONObject jsonObject = new JSONObject(str);
        final Hashtable<String, String> hash = new Hashtable<String, String>();
        final Iterator<String> keys = jsonObject.keys();
        while (keys.hasNext()) {
            final String key = keys.next();
            final String value = jsonObject.getString(key);
            hash.put(key, value);
        }
        return classHasher.hashToClass(hash);
    } catch (final Exception e) {
        throw new SerializerException(e);
    }
}

From source file:com.pmarlen.model.controller.EntityJPAToPlainPojoTransformer.java

public static void copyPlainValues(Entity entity, Object plain) {
    final Class entityClass;
    entityClass = entity.getClass();//from ww  w  .  j av  a  2  s.  c  om
    final String entityClassName = entityClass.getName();
    Hashtable<String, Object> propertiesToCopy = new Hashtable<String, Object>();
    Hashtable<String, Object> propertiesM2MToCopy = new Hashtable<String, Object>();
    List<String> propertiesWithNULLValueToCopy = new ArrayList<String>();
    List<String> propertiesKey = new ArrayList<String>();
    try {
        final Field[] declaredFields = entityClass.getDeclaredFields();
        for (Field f : declaredFields) {
            logger.trace("->create: \tcopy: " + entityClassName + "." + f.getName() + " accesible ? "
                    + (f.isAccessible()));
            if (!f.isAccessible()) {

                if (f.isAnnotationPresent(javax.persistence.Id.class)) {
                    propertiesKey.add(f.getName());
                }
                if (f.isAnnotationPresent(javax.persistence.Id.class)
                        && !f.isAnnotationPresent(javax.persistence.GeneratedValue.class)
                        && !Modifier.isStatic(f.getModifiers())) {

                    Object valueCopyed = PropertyUtils.getProperty(entity, f.getName());
                    if (valueCopyed != null) {
                        propertiesToCopy.put(f.getName(), valueCopyed);
                    } else {
                        propertiesWithNULLValueToCopy.add(f.getName());
                    }
                    logger.trace("->create:\t\t ID elegible 2 be copied, added to copy list: " + f.getName()
                            + " = " + valueCopyed + ", is really null?" + (valueCopyed == null));
                } else if (!f.isAnnotationPresent(javax.persistence.Id.class)
                        && !f.isAnnotationPresent(javax.persistence.OneToMany.class)
                        && !f.isAnnotationPresent(javax.persistence.ManyToMany.class)
                        && !Modifier.isStatic(f.getModifiers())) {

                    Object valueCopyed = PropertyUtils.getProperty(entity, f.getName());
                    if (valueCopyed != null) {
                        propertiesToCopy.put(f.getName(), valueCopyed);
                    } else {
                        propertiesWithNULLValueToCopy.add(f.getName());
                    }
                    logger.trace("->create:\t\t elegible 2 be copied, added to copy list: " + f.getName()
                            + " = " + valueCopyed + ", is really null?" + (valueCopyed == null));
                } else if (!f.isAnnotationPresent(javax.persistence.Id.class)
                        && f.isAnnotationPresent(javax.persistence.ManyToMany.class)) {

                    Object valueCopyed = PropertyUtils.getProperty(entity, f.getName());
                    if (valueCopyed != null) {
                        propertiesM2MToCopy.put(f.getName(), valueCopyed);
                    } else {
                        propertiesWithNULLValueToCopy.add(f.getName());
                    }
                    logger.trace("->create:\t\t M2M elegible 2 be copied, added to copy list: " + f.getName()
                            + " = " + valueCopyed + ", is really null?" + (valueCopyed == null));
                }
            }
        }
        logger.trace("->create:copy values ?");
        for (String p2c : propertiesToCopy.keySet()) {
            Object valueCopyed = propertiesToCopy.get(p2c);
            logger.trace("->create:\t\t copy value with SpringUtils: " + p2c + " = " + valueCopyed
                    + ", is null?" + (valueCopyed == null));
            BeanUtils.copyProperty(plain, p2c, valueCopyed);
        }
        for (String p2c : propertiesWithNULLValueToCopy) {
            logger.trace("->create:\t\t copy null with SpringUtils");
            BeanUtils.copyProperty(plain, p2c, null);
        }
    } catch (Exception e) {
        logger.error("..in copy", e);
    }
}