Examples of CustomNumberEditor


Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

    assertEquals("7", gb.getLongMap().get(new Long("6")));
  }

  public void testGenericMapWithCollectionValueFactoryMethod() throws MalformedURLException {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    bf.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
    RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
    rbd.setFactoryMethodName("createInstance");

    Map input = new HashMap();
    HashSet value1 = new HashSet();
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

    this.defaultEditors.put(boolean.class, new CustomBooleanEditor(false));
    this.defaultEditors.put(Boolean.class, new CustomBooleanEditor(true));

    // The JDK does not contain default editors for number wrapper types!
    // Override JDK primitive number editors with our own CustomNumberEditor.
    this.defaultEditors.put(byte.class, new CustomNumberEditor(Byte.class, false));
    this.defaultEditors.put(Byte.class, new CustomNumberEditor(Byte.class, true));
    this.defaultEditors.put(short.class, new CustomNumberEditor(Short.class, false));
    this.defaultEditors.put(Short.class, new CustomNumberEditor(Short.class, true));
    this.defaultEditors.put(int.class, new CustomNumberEditor(Integer.class, false));
    this.defaultEditors.put(Integer.class, new CustomNumberEditor(Integer.class, true));
    this.defaultEditors.put(long.class, new CustomNumberEditor(Long.class, false));
    this.defaultEditors.put(Long.class, new CustomNumberEditor(Long.class, true));
    this.defaultEditors.put(float.class, new CustomNumberEditor(Float.class, false));
    this.defaultEditors.put(Float.class, new CustomNumberEditor(Float.class, true));
    this.defaultEditors.put(double.class, new CustomNumberEditor(Double.class, false));
    this.defaultEditors.put(Double.class, new CustomNumberEditor(Double.class, true));
    this.defaultEditors.put(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, true));
    this.defaultEditors.put(BigInteger.class, new CustomNumberEditor(BigInteger.class, true));

    // Only register config value editors if explicitly requested.
    if (this.configValueEditorsActive) {
      StringArrayPropertyEditor sae = new StringArrayPropertyEditor();
      this.defaultEditors.put(String[].class, sae);
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

        public void setType(Class<?> type) {
            this.type = type;
        }

        public void registerCustomEditors(PropertyEditorRegistry registry) {
            PropertyEditor editor = new CustomNumberEditor(Long.class, true) {
                @Override
                public void setAsText(String text) {
                    if ("ten".equals(text)) {
                        setValue(10L);
                    } else {
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

        }
    }

    public static class MyRegistrar implements PropertyEditorRegistrar {
        public void registerCustomEditors(PropertyEditorRegistry registry) {
            PropertyEditor editor = new CustomNumberEditor(Long.class, true) {
                @Override
                public void setAsText(String text) {
                    if ("ten".equals(text)) {
                        setValue(10L);
                    } else {
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

    public static class MyRegistrar implements PropertyEditorRegistrar {
        private final static String[] NUMBERS = { "zero", "one", "two", "three", "four", "five", "six", "seven",
                                                  "eight", "nine", "ten" };

        public void registerCustomEditors(PropertyEditorRegistry registry) {
            PropertyEditor editor = new CustomNumberEditor(Long.class, true) {
                @Override
                public void setAsText(String text) {
                    for (int i = 0; i < NUMBERS.length; i++) {
                        if (NUMBERS[i].equalsIgnoreCase(text)) {
                            setValue(i);
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

  }

  public void testGenericMapWithCollectionValue() {
    GenericBean gb = new GenericBean();
    BeanWrapper bw = new BeanWrapperImpl(gb);
    bw.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
    Map input = new HashMap();
    HashSet value1 = new HashSet();
    value1.add(new Integer(1));
    input.put("1", value1);
    ArrayList value2 = new ArrayList();
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

  public void testGenericMapElementWithCollectionValue() {
    GenericBean gb = new GenericBean();
    gb.setCollectionMap(new HashMap<Number, Collection<? extends Object>>());
    BeanWrapper bw = new BeanWrapperImpl(gb);
    bw.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
    HashSet value1 = new HashSet();
    value1.add(new Integer(1));
    bw.setPropertyValue("collectionMap[1]", value1);
    assertTrue(gb.getCollectionMap().get(new Integer(1)) instanceof HashSet);
  }
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

    BeanWrapperFieldSetMapper<TestObject> mapper = new BeanWrapperFieldSetMapper<TestObject>();
    mapper.setTargetType(TestObject.class);

    FieldSet fieldSet = new DefaultFieldSet(new String[] { "00009" }, new String[] { "varLong" });

    mapper.setCustomEditors(Collections.singletonMap(Long.TYPE, new CustomNumberEditor(Long.class, NumberFormat
        .getNumberInstance(), true)));
    TestObject bean = mapper.mapFieldSet(fieldSet);

    assertEquals(9, bean.getVarLong());
  }
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

    BeanWrapperFieldSetMapper<TestObject> mapper = new BeanWrapperFieldSetMapper<TestObject>();
    mapper.setTargetType(TestObject.class);

    FieldSet fieldSet = new DefaultFieldSet(new String[] { "00009", "78" }, new String[] { "varLong", "varInt" });

    mapper.setCustomEditors(Collections.singletonMap(Long.TYPE, new CustomNumberEditor(Long.class, NumberFormat
        .getNumberInstance(), true)));
    TestObject bean = mapper.mapFieldSet(fieldSet);

    assertEquals(9, bean.getVarLong());
    assertEquals(78, bean.getVarInt());
View Full Code Here

Examples of org.springframework.beans.propertyeditors.CustomNumberEditor

    FieldSet fieldSet = new DefaultFieldSet(new String[] { "9.876,1", "7,890.1" }, new String[] { "varDouble",
        "varFloat" });

    Map<Class<?>, PropertyEditor> editors = new HashMap<Class<?>, PropertyEditor>();
    editors.put(Double.TYPE, new CustomNumberEditor(Double.class, NumberFormat.getInstance(Locale.GERMAN), true));
    editors.put(Float.TYPE, new CustomNumberEditor(Float.class, NumberFormat.getInstance(Locale.UK), true));
    mapper.setCustomEditors(editors);

    TestObject bean = mapper.mapFieldSet(fieldSet);

    assertEquals(9876.1, bean.getVarDouble(), 0.01);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.