@Override public MapBeanBuilder setString(MetaProperty<?> metaProperty, String value) { // no type information to perform a conversion // this approach allows meta-property from one MapBean to be used with another bean.put(metaProperty.name(), value); return this; }
@Override public BeanBuilder<MapBean> setAll(Map<String, ? extends Object> propertyValueMap) { for (Entry<String, ? extends Object> entry : propertyValueMap.entrySet()) { bean.put(entry.getKey(), entry.getValue()); } return this; }
@Test @SuppressWarnings("unchecked") public void rawMapClassesShouldBeEmpty() { final MapBean mapBean = enhancedRandom.nextObject(MapBean.class); assertThat(mapBean).isNotNull(); assertThat(mapBean.getHashMap()).isEmpty(); assertThat(mapBean.getHashtable()).isEmpty(); assertThat(mapBean.getLinkedHashMap()).isEmpty(); assertThat(mapBean.getWeakHashMap()).isEmpty(); assertThat(mapBean.getIdentityHashMap()).isEmpty(); assertThat(mapBean.getTreeMap()).isEmpty(); assertThat(mapBean.getConcurrentSkipListMap()).isEmpty(); }
@Test @SuppressWarnings("unchecked") public void rawMapInterfacesShouldBeEmpty() { final MapBean mapBean = enhancedRandom.nextObject(MapBean.class); assertThat(mapBean).isNotNull(); assertThat(mapBean.getMap()).isEmpty(); assertThat(mapBean.getSortedMap()).isEmpty(); assertThat(mapBean.getNavigableMap()).isEmpty(); assertThat(mapBean.getConcurrentMap()).isEmpty(); assertThat(mapBean.getConcurrentNavigableMap()).isEmpty(); }
@Test public void typedMapClassesShouldNotBeEmpty() { final MapBean mapBean = enhancedRandom.nextObject(MapBean.class); assertThat(mapBean).isNotNull(); assertContainsNonZeroIntegers(mapBean.getTypedHashMap().keySet()); assertContainsOnlyNonEmptyPersons(mapBean.getTypedHashMap().values()); assertContainsNonZeroIntegers(mapBean.getTypedHashtable().keySet()); assertContainsOnlyNonEmptyPersons(mapBean.getTypedHashtable().values()); assertContainsNonZeroIntegers(mapBean.getTypedLinkedHashMap().keySet()); assertContainsOnlyNonEmptyPersons(mapBean.getTypedLinkedHashMap().values()); assertContainsNonZeroIntegers(mapBean.getTypedWeakHashMap().keySet()); assertContainsOnlyNonEmptyPersons(mapBean.getTypedWeakHashMap().values()); assertContainsNonZeroIntegers(mapBean.getTypedIdentityHashMap().keySet()); assertContainsOnlyNonEmptyPersons(mapBean.getTypedIdentityHashMap().values()); assertContainsNonZeroIntegers(mapBean.getTypedTreeMap().keySet()); assertContainsOnlyNonEmptyPersons(mapBean.getTypedTreeMap().values()); assertContainsNonZeroIntegers(mapBean.getTypedConcurrentSkipListMap().keySet()); assertContainsOnlyNonEmptyPersons(mapBean.getTypedConcurrentSkipListMap().values()); }
@Test public void typedMapInterfacesShouldNotBeEmpty() { final MapBean mapBean = enhancedRandom.nextObject(MapBean.class); assertThat(mapBean).isNotNull(); assertContainsNonZeroIntegers(mapBean.getTypedMap().keySet()); assertContainsOnlyNonEmptyPersons(mapBean.getTypedMap().values()); assertContainsNonZeroIntegers(mapBean.getTypedSortedMap().keySet()); assertContainsOnlyNonEmptyPersons(mapBean.getTypedSortedMap().values()); assertContainsNonZeroIntegers(mapBean.getTypedNavigableMap().keySet()); assertContainsOnlyNonEmptyPersons(mapBean.getTypedNavigableMap().values()); assertContainsNonZeroIntegers(mapBean.getTypedConcurrentMap().keySet()); assertContainsOnlyNonEmptyPersons(mapBean.getTypedConcurrentMap().values()); assertContainsNonZeroIntegers(mapBean.getTypedConcurrentNavigableMap().keySet()); assertContainsOnlyNonEmptyPersons(mapBean.getTypedConcurrentNavigableMap().values()); }
@Override public MapBeanBuilder set(MetaProperty<?> metaProperty, Object value) { // this approach allows meta-property from one bean to be used with another bean.put(metaProperty.name(), value); return this; }
@Override public MapBeanBuilder setString(String propertyName, String value) { // no type information to perform a conversion bean.put(propertyName, value); return this; }
// ----------------------------------------------------------------------- @Override public MapBeanBuilder set(String propertyName, Object value) { bean.put(propertyName, value); return this; }
@Override public Object get(MetaProperty<?> metaProperty) { // this approach allows meta-property from one bean to be used with another return bean.get(metaProperty.name()); }
// ----------------------------------------------------------------------- @Override public Object get(String propertyName) { // lenient getter return bean.get(propertyName); }
public void actionPerformed(ActionEvent ae) { Debug.message("saveimage", "SaveAsImageMenuItem: actionPerformed"); if (mapHandler == null) { Debug.output("SaveAsImageMenuItem: mapHandler = null, returning"); return; } MapBean mb = (MapBean) mapHandler.get("com.bbn.openmap.MapBean"); if (mb != null) { Debug.message("saveimage", "MapBean found, creating image"); try { while (true) { SaveAsImageFileChooser chooser = new SaveAsImageFileChooser(mb.getWidth(), mb.getHeight()); int returnVal = chooser.showSaveDialog(getParent()); if (returnVal == JFileChooser.APPROVE_OPTION) { String filename = chooser.getSelectedFile().getAbsolutePath(); if (formatter == null) { break; } filename = checkFileName(filename, formatter.getFormatLabel().toLowerCase()); if (filename == null) { // This is the reason for the while // loop, the name didn't really pass // muster, so we'll try again. continue; } int imageHeight = chooser.getImageHeight(); int imageWidth = chooser.getImageWidth(); byte[] imageBytes = formatter.getImageFromMapBean(mb, imageWidth, imageHeight); FileOutputStream binFile = new FileOutputStream(filename); binFile.write(imageBytes); binFile.close(); if (Debug.debugging("saveimage")) { com.bbn.openmap.proj.Projection proj = mb.getProjection(); Debug.output( "Created image at " + filename + "where projection covers " + proj.getUpperLeft() + " to " + proj.getLowerRight()); } break; } else if (returnVal == JFileChooser.CANCEL_OPTION) { break; } } } catch (IOException e) { Debug.error("SaveAsImageMenuItem: " + e); } } return; }
// [JACKSON-576] public void testMapWithEnumKeys() throws Exception { MapBean bean = new MapBean(); bean.add(TestEnum.B, 3); String json = mapper.writeValueAsString(bean); assertEquals("{\"map\":{\"b\":3}}", json); }