Java Examples for java.util.HashMap

The following java examples will help you to understand the usage of java.util.HashMap. These source code samples are taken from different open source projects.

Example 1
Project: ijoomer-adv-sdk-master  File: JomCachingConstants.java View source code
public static HashMap<String, String> getUnnormlizeFields() {
    HashMap<String, String> unNormalizeFields = new HashMap<String, String>() {

        {
            put(// jom
            "menu", // jom
            "");
            put("adminMenu", "");
            put(// jom
            "options", // jom
            "");
            put(// jom
            "option", // jom
            "");
            put("group_data", "");
            put("event_data", "");
            put("image_data", "");
            put(// jom
            "privacy", // jom
            "");
            put("profile_video", "");
            put("condition", "");
            put("content_data", "");
        }
    };
    return unNormalizeFields;
}
Example 2
Project: android_platform_libcore-master  File: HashMapTest.java View source code
/**
     * java.util.HashMap#HashMap(int, float)
     */
public void test_ConstructorIF() {
    // Test for method java.util.HashMap(int, float)
    HashMap hm2 = new HashMap(5, (float) 0.5);
    assertEquals("Created incorrect HashMap", 0, hm2.size());
    try {
        new HashMap(0, 0);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    }
    HashMap empty = new HashMap(0, 0.75f);
    assertNull("Empty hashtable access", empty.get("nothing"));
    empty.put("something", "here");
    assertTrue("cannot get element", empty.get("something") == "here");
}
Example 3
Project: android-libcore64-master  File: HashMapTest.java View source code
/**
     * java.util.HashMap#HashMap(int, float)
     */
public void test_ConstructorIF() {
    // Test for method java.util.HashMap(int, float)
    HashMap hm2 = new HashMap(5, (float) 0.5);
    assertEquals("Created incorrect HashMap", 0, hm2.size());
    try {
        new HashMap(0, 0);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    }
    HashMap empty = new HashMap(0, 0.75f);
    assertNull("Empty hashtable access", empty.get("nothing"));
    empty.put("something", "here");
    assertTrue("cannot get element", empty.get("something") == "here");
}
Example 4
Project: ARTPart-master  File: HashMapTest.java View source code
/**
     * java.util.HashMap#HashMap(int, float)
     */
public void test_ConstructorIF() {
    // Test for method java.util.HashMap(int, float)
    HashMap hm2 = new HashMap(5, (float) 0.5);
    assertEquals("Created incorrect HashMap", 0, hm2.size());
    try {
        new HashMap(0, 0);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    }
    HashMap empty = new HashMap(0, 0.75f);
    assertNull("Empty hashtable access", empty.get("nothing"));
    empty.put("something", "here");
    assertTrue("cannot get element", empty.get("something") == "here");
}
Example 5
Project: j2objc-master  File: HashMapTest.java View source code
/**
     * java.util.HashMap#HashMap(int, float)
     */
public void test_ConstructorIF() {
    // Test for method java.util.HashMap(int, float)
    HashMap hm2 = new HashMap(5, (float) 0.5);
    assertEquals("Created incorrect HashMap", 0, hm2.size());
    try {
        new HashMap(0, 0);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    }
    HashMap empty = new HashMap(0, 0.75f);
    assertNull("Empty hashtable access", empty.get("nothing"));
    empty.put("something", "here");
    assertTrue("cannot get element", empty.get("something") == "here");
}
Example 6
Project: android-sdk-sources-for-api-level-23-master  File: HashMapTest.java View source code
/**
     * java.util.HashMap#HashMap(int, float)
     */
public void test_ConstructorIF() {
    // Test for method java.util.HashMap(int, float)
    HashMap hm2 = new HashMap(5, (float) 0.5);
    assertEquals("Created incorrect HashMap", 0, hm2.size());
    try {
        new HashMap(0, 0);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    }
    HashMap empty = new HashMap(0, 0.75f);
    assertNull("Empty hashtable access", empty.get("nothing"));
    empty.put("something", "here");
    assertTrue("cannot get element", empty.get("something") == "here");
}
Example 7
Project: java8-tutorial-master  File: Lock4.java View source code
public static void main(String[] args) {
    ExecutorService executor = Executors.newFixedThreadPool(2);
    Map<String, String> map = new HashMap<>();
    StampedLock lock = new StampedLock();
    executor.submit(() -> {
        long stamp = lock.writeLock();
        try {
            ConcurrentUtils.sleep(1);
            map.put("foo", "bar");
        } finally {
            lock.unlockWrite(stamp);
        }
    });
    Runnable readTask = () -> {
        long stamp = lock.readLock();
        try {
            System.out.println(map.get("foo"));
            ConcurrentUtils.sleep(1);
        } finally {
            lock.unlockRead(stamp);
        }
    };
    executor.submit(readTask);
    executor.submit(readTask);
    ConcurrentUtils.stop(executor);
}
Example 8
Project: open-mika-master  File: AbstractMapTest.java View source code
/**
     * @tests java.util.AbstractMap#keySet()
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "Class is abstract. Functionality tested in subclasses for example in java.util.HashMap.",
        method = "keySet",
        args = {}
    )
     */
public void test_keySet() {
    AbstractMap map1 = new HashMap(0);
    assertSame("HashMap(0)", map1.keySet(), map1.keySet());
    AbstractMap map2 = new HashMap(10);
    assertSame("HashMap(10)", map2.keySet(), map2.keySet());
    Map map3 = Collections.EMPTY_MAP;
    assertSame("EMPTY_MAP", map3.keySet(), map3.keySet());
    AbstractMap map4 = new IdentityHashMap(1);
    assertSame("IdentityHashMap", map4.keySet(), map4.keySet());
    AbstractMap map5 = new LinkedHashMap(122);
    assertSame("LinkedHashMap", map5.keySet(), map5.keySet());
    AbstractMap map6 = new TreeMap();
    assertSame("TreeMap", map6.keySet(), map6.keySet());
    AbstractMap map7 = new WeakHashMap();
    assertSame("WeakHashMap", map7.keySet(), map7.keySet());
}
Example 9
Project: magnificent-mileage-master  File: TravelModeWrapperTest.java View source code
@Test
public void testToTraverseMode() {
    Map<TravelMode, TraverseMode> modeMap = new HashMap<TravelMode, TraverseMode>();
    modeMap.put(TravelMode.BICYCLE, TraverseMode.BICYCLE);
    modeMap.put(TravelMode.CAR, TraverseMode.CAR);
    modeMap.put(TravelMode.CUSTOM_MOTOR_VEHICLE, TraverseMode.CUSTOM_MOTOR_VEHICLE);
    modeMap.put(TravelMode.WALK, TraverseMode.WALK);
    modeMap.put(TravelMode.ANY_TRAIN, TraverseMode.TRAINISH);
    modeMap.put(TravelMode.ANY_TRANSIT, TraverseMode.TRANSIT);
    for (TravelMode travelMode : modeMap.keySet()) {
        TraverseMode expectedTraverseMode = modeMap.get(travelMode);
        TraverseMode actualTraverseMode = (new TravelModeWrapper(travelMode)).toTraverseMode();
        assertEquals(expectedTraverseMode, actualTraverseMode);
    }
}
Example 10
Project: spring4-showcase-master  File: PropertyResolverTest.java View source code
@Test
public void test() throws Exception {
    Map<String, Object> map = new HashMap<>();
    map.put("encoding", "gbk");
    PropertySource propertySource1 = new MapPropertySource("map", map);
    ResourcePropertySource propertySource2 = new ResourcePropertySource("resource", "classpath:resources.properties");
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addFirst(propertySource1);
    propertySources.addLast(propertySource2);
    PropertyResolver propertyResolver = new PropertySourcesPropertyResolver(propertySources);
    System.out.println(propertyResolver.getProperty("encoding"));
    System.out.println(propertyResolver.getProperty("no", "default"));
    System.out.println(propertyResolver.resolvePlaceholders("must be encoding ${encoding}"));
}
Example 11
Project: sonar-java-master  File: URLHashCodeAndEqualsCheck.java View source code
public void foo(URL url) throws Exception {
    // Noncompliant [[sc=5;ec=22]] {{Use the URI class instead.}}
    Map<URL, Integer> sites = new HashMap<>();
    // Noncompliant {{Use the URI class instead.}}
    Set<URL> otherSites = new HashSet<>();
    // Compliant
    URL homepage = new URL("http://sonarsource.com");
    // Noncompliant [[sc=5;ec=25]] {{Use the URI class instead.}}
    homepage.equals(url);
    // Noncompliant {{Use the URI class instead.}}
    homepage.hashCode();
    // Compliant
    homepage.getPath();
    // Compliant
    Map<URI, URL> uriToUrl = new HashMap<>();
    // Compliant
    Map uriToUrl2 = new Hashmap();
    // Compliant
    Map<> uriToUrl3 = new Hashmap<>();
}
Example 12
Project: FeedMeAndroid-master  File: Pay.java View source code
public static void makePayment() {
    Stripe.apiKey = "L8px8dWKTJmab3qzAuq7Vh4hwp3sXbK4";
    Map<String, Object> chargeMap = new HashMap<String, Object>();
    chargeMap.put("amount", 100);
    chargeMap.put("currency", "usd");
    Map<String, Object> cardMap = new HashMap<String, Object>();
    cardMap.put("number", "4242424242424242");
    cardMap.put("exp_month", 12);
    cardMap.put("exp_year", 2012);
    chargeMap.put("card", cardMap);
    try {
        Charge charge = Charge.create(chargeMap);
        System.out.println(charge);
    } catch (StripeException e) {
        e.printStackTrace();
    }
}
Example 13
Project: extension-aws-master  File: ReplacerTest.java View source code
public void testReplacer() throws Exception {
    SearcherManager manager = (SearcherManager) getBean("searcherManager");
    Replacer replacer = new Replacer();
    replacer.setCatalogId("system");
    replacer.setAlwaysReplace(true);
    replacer.setSearcherManager(manager);
    String code = "${one}/${longvariable}/${user.email}/${notfound}/${two}/${user.id}${nogap1}${nogap2}";
    Map vars = new HashMap();
    vars.put("user", "admin");
    vars.put("one", "Uno");
    vars.put("nogap1", "123");
    vars.put("nogap2", "456");
    vars.put("two", "TOOOOLONG");
    vars.put("longvariable", "short");
    String returned = replacer.replace(code, vars);
    assertEquals("[email protected]//TOOOOLONG/admin123456", returned);
}
Example 14
Project: polly-master  File: GBPasteService.java View source code
@Override
public String doPaste(String message) throws IOException {
    Map<String, String> properties = new HashMap<String, String>(10);
    //$NON-NLS-1$ //$NON-NLS-2$
    properties.put("nick", "polly");
    //$NON-NLS-1$ //$NON-NLS-2$
    properties.put("lang", "text");
    //$NON-NLS-1$ //$NON-NLS-2$
    properties.put("private", "1");
    //$NON-NLS-1$ //$NON-NLS-2$
    properties.put("desc", "polly log entries");
    //$NON-NLS-1$
    properties.put("code", message);
    return this.postRequest(new URL("http://gbpaste.org/upload"), //$NON-NLS-1$
    properties).getResultURL();
}
Example 15
Project: sitebricks-master  File: TextFieldWidgetTest.java View source code
//    @Test
public final void textTagRender() {
    final String[] out = new String[1];
    Respond mockRespond = createMock(Respond.class);
    final String boundTo = "aString";
    new TextFieldWidget(new ProceedingWidgetChain(), "boundTo", new MvelEvaluator()).render(new HashMap<String, Object>() {

        {
            put("boundTo", boundTo);
        }
    }, mockRespond);
    //assert the validity of the text tag:
    assert out[0] != null : "Nothing rendered!";
    String tag = out[0].trim();
    assert tag.startsWith("<input ");
    assert tag.endsWith(">");
    assert tag.contains("value=\"" + boundTo + "\"");
    assert tag.contains("name=\"boundTo\"");
    assert tag.contains("type=\"text\"");
}
Example 16
Project: Katari-master  File: ModuleWithEntryPointsAndWebletsTest.java View source code
@SuppressWarnings("deprecation")
public void testInit() {
    Map<String, ServletAndParameters> entryPoints;
    entryPoints = new HashMap<String, ServletAndParameters>();
    Map<String, String> weblets = new HashMap<String, String>();
    ModuleWithEntryPointsAndWeblets module;
    module = new ModuleWithEntryPointsAndWeblets(entryPoints, weblets);
    ModuleContext context = createMock(ModuleContext.class);
    context.registerEntryPoints(entryPoints);
    context.registerWeblets(weblets);
    replay(context);
    module.init(context);
    verify(context);
}
Example 17
Project: dk-master  File: IInvestServiceTest.java View source code
@Test
public void testSelectSuccessRecordPage() {
    PageDo page = new PageDo();
    Map<String, Object> parameterMap = new HashMap<String, Object>();
    //parameterMap.put("number", number);
    //parameterMap.put("publishTimeStart", publishTimeStart);
    //parameterMap.put("endTime", endTime);
    //parameterMap.put("investor", user.getId());
    //parameterMap.put("userName", userName);
    //新旧page类不同,需要转换
    page.setPageNum(1);
    page.setPageSize(10);
    page.setTotalNum(10);
    investService.selectInvestSuccessRecordPage(parameterMap, page);
}
Example 18
Project: NucleusFramework-master  File: AgentHashMapTest.java View source code
@Test
public void test() {
    AgentMap<String, ISubscriberAgent> map = new AgentHashMap<String, ISubscriberAgent>() {

        Map<String, ISubscriberAgent> internalMap = new HashMap<>(10);

        @Override
        protected Map<String, ISubscriberAgent> map() {
            return internalMap;
        }
    };
    ISubscriberAgent agent1 = new SubscriberAgent() {
    };
    ISubscriberAgent agent2 = new SubscriberAgent() {
    };
    ISubscriberAgent agent3 = new SubscriberAgent() {
    };
    MapRunnable<String, ISubscriberAgent> test = new MapRunnable<>(map, "a", "b", "c", agent1, agent2, agent3);
    test.run();
}
Example 19
Project: nmonvisualizer-master  File: XMLParserHelper.java View source code
public static Map<String, String> parseAttributes(String unparsedAttributes) {
    if ((unparsedAttributes == null) || "".equals(unparsedAttributes)) {
        return java.util.Collections.emptyMap();
    }
    String[] parts = ATTRIBUTE_SPLIITTER.split(unparsedAttributes);
    int size = parts.length / 2;
    Map<String, String> attributes = new java.util.HashMap<String, String>(size);
    // drop odd numbered end index from array
    size *= 2;
    for (int i = 0; i < size; ) {
        attributes.put(DataHelper.newString(parts[i++].trim()), DataHelper.newString(parts[i++].trim()));
    }
    return attributes;
}
Example 20
Project: SideScrollerGDW2012-Max-master  File: FileMuffin.java View source code
/**
	 * @see org.newdawn.slick.muffin.Muffin#saveFile(java.util.HashMap,
	 *      java.lang.String)
	 */
public void saveFile(HashMap scoreMap, String fileName) throws IOException {
    String userHome = System.getProperty("user.home");
    File file = new File(userHome);
    file = new File(file, ".java");
    if (!file.exists()) {
        file.mkdir();
    }
    file = new File(file, fileName);
    FileOutputStream fos = new FileOutputStream(file);
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    // save hashMap
    oos.writeObject(scoreMap);
    oos.close();
}
Example 21
Project: sosies-generator-master  File: LazyMapTest.java View source code
@Test
public void mapGetWithFactory() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(), this, "mapGetWithFactory");
    Map<java.lang.Integer, java.lang.Number> map = LazyMap.lazyMap(new java.util.HashMap<java.lang.Integer, java.lang.Number>(), oneFactory);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(), 809, map, 808, map.size());
    final Number i1 = map.get("foo");
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(), 810, i1);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(), 812, map, 811, map.size());
    final Number i2 = map.get(new String(new char[] { 'F', 'i', 'v', 'e' }));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(), 813, i2);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(), 815, map, 814, map.size());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(), 816, i1);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(), 817, i2);
    map = LazyMap.lazyMap(new java.util.HashMap<java.lang.Integer, java.lang.Number>(), org.apache.commons.collections4.FactoryUtils.<Long>nullFactory());
    final Object o = map.get("Five");
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(), 818, o);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(), 820, map, 819, map.size());
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
Example 22
Project: sysart-itext-master  File: BookmarksTest.java View source code
@Test
public void testNoBreakSpace() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, baos);
    document.open();
    writer.setPageEvent(new PdfPageEventHelper() {

        public void onParagraph(PdfWriter writer, Document document, float position) {
            PdfContentByte cb = writer.getDirectContent();
            PdfDestination destination = new PdfDestination(PdfDestination.FITH, position);
            new PdfOutline(cb.getRootOutline(), destination, TITLE);
        }
    });
    document.add(new Paragraph("Hello World"));
    document.close();
    // read bookmark back
    PdfReader r = new PdfReader(baos.toByteArray());
    List bookmarks = SimpleBookmark.getBookmark(r);
    assertEquals("bookmark size", 1, bookmarks.size());
    HashMap<String, Object> b = (HashMap<String, Object>) bookmarks.get(0);
    String title = (String) b.get("Title");
    assertEquals("bookmark title", TITLE, title);
}
Example 23
Project: Mint-Programming-Language-master  File: ViewStrings.java View source code
@Override
public Pointer apply(SmartList<Pointer> args) throws MintException {
    short i = 0;
    while (i < Short.MAX_VALUE) {
        try {
            HashMap<Integer, String> strs = Heap.strings;
            if (strs == null) {
                return EMPTY_LIST;
            }
            Table tbl = new Table();
            ArrayList<Integer> keys = new ArrayList<Integer>();
            Set<Integer> s = strs.keySet();
            for (int element : s) {
                keys.add(element);
            }
            s = null;
            for (int key : keys) {
                SmartList<Pointer> pair = new SmartList<Pointer>();
                pair.add(new Pointer(Constants.INT_TYPE, key));
                pair.add(Heap.allocateString(strs.get(key)));
                tbl.addBinding(pair);
            }
            return Heap.allocateTable(tbl);
        } catch (Throwable t) {
        }
        ++i;
    }
    try {
        return Heap.allocateString(Heap.strings.toString());
    } catch (Throwable t) {
        return ChangeString.ERROR;
    }
}
Example 24
Project: LambdaDojo-master  File: S406StreamInsteadOfFor.java View source code
private void wordCount() {
    List<String> sentences = Arrays.asList("Peter Piper picked", "a peck of pickled peppers.", "A peck of pickled peppers", "Peter Piper picked. ", "If Peter Piper picked", "a peck of pickled peppers,", "Where's the peck of pickled peppers", "Peter Piper picked? ");
    Map<String, Integer> result = new HashMap<>();
    for (String sentence : sentences) {
        String[] splitedSentence = sentence.split("[\\.,\\? ]");
        for (String word : splitedSentence) {
            String lowerWord = word.toLowerCase();
            int count = result.getOrDefault(lowerWord, 0);
            result.put(lowerWord, count + 1);
        }
    }
    System.out.println(result);
}
Example 25
Project: bigtable-sql-master  File: EntryPanelManager.java View source code
public void init(ISyntaxHighlightTokenMatcherFactory syntaxHighlightTokenMatcherFactory, ToolsPopupAccessor tpa) {
    HashMap props = new HashMap();
    props.put(IParserEventsProcessorFactory.class.getName(), null);
    if (null != syntaxHighlightTokenMatcherFactory) {
        props.put(ISyntaxHighlightTokenMatcherFactory.class.getName(), syntaxHighlightTokenMatcherFactory);
    }
    if (null != tpa) {
        props.put(ToolsPopupAccessor.class.getName(), tpa);
    }
    _entry = _session.getApplication().getSQLEntryPanelFactory().createSQLEntryPanel(_session, props);
    _component = _entry.getTextComponent();
    if (false == _entry.getDoesTextComponentHaveScroller()) {
        _component = new JScrollPane(_entry.getTextComponent());
        _component.setBorder(BorderFactory.createEmptyBorder());
    }
    new UndoHandlerImpl(_session.getApplication(), _entry);
}