Search in sources :

Example 21 with ChoiceFormat

use of java.text.ChoiceFormat in project opennms by OpenNMS.

the class UpdateGroupServlet method doPost.

/**
 * {@inheritDoc}
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession userSession = request.getSession(false);
    if (userSession != null) {
        // group.modifyGroup.jsp
        Group newGroup = (Group) userSession.getAttribute("group");
        // get the rest of the group information from the form
        newGroup.clearUsers();
        String[] users = request.getParameterValues("selectedUsers");
        if (users != null) {
            for (int i = 0; i < users.length; i++) {
                newGroup.addUser(users[i]);
            }
        }
        Vector<Object> newSchedule = new Vector<>();
        ChoiceFormat days = new ChoiceFormat("0#Mo|1#Tu|2#We|3#Th|4#Fr|5#Sa|6#Su");
        Collection<String> dutySchedules = getDutySchedulesForGroup(newGroup);
        dutySchedules.clear();
        int dutyCount = WebSecurityUtils.safeParseInt(request.getParameter("dutySchedules"));
        for (int duties = 0; duties < dutyCount; duties++) {
            newSchedule.clear();
            String deleteFlag = request.getParameter("deleteDuty" + duties);
            // don't save any duties that were marked for deletion
            if (deleteFlag == null) {
                for (int i = 0; i < 7; i++) {
                    String curDayFlag = request.getParameter("duty" + duties + days.format(i));
                    if (curDayFlag != null) {
                        newSchedule.addElement(Boolean.TRUE);
                    } else {
                        newSchedule.addElement(Boolean.FALSE);
                    }
                }
                newSchedule.addElement(request.getParameter("duty" + duties + "Begin"));
                newSchedule.addElement(request.getParameter("duty" + duties + "End"));
                DutySchedule newDuty = new DutySchedule(newSchedule);
                dutySchedules.add(newDuty.toString());
            }
        }
        userSession.setAttribute("group", newGroup);
    }
    // forward the request for proper display
    RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher(request.getParameter("redirect"));
    dispatcher.forward(request, response);
}
Also used : Group(org.opennms.netmgt.config.groups.Group) HttpSession(javax.servlet.http.HttpSession) ChoiceFormat(java.text.ChoiceFormat) DutySchedule(org.opennms.netmgt.config.users.DutySchedule) Vector(java.util.Vector) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 22 with ChoiceFormat

use of java.text.ChoiceFormat in project j2objc by google.

the class ChoiceFormatTest method test_Constructor$D$Ljava_lang_String.

/**
     * @tests java.text.ChoiceFormat#ChoiceFormat(double[], java.lang.String[])
     */
public void test_Constructor$D$Ljava_lang_String() {
    // Test for method java.text.ChoiceFormat(double [], java.lang.String
    // [])
    String formattedString;
    double[] appleLimits = { 1, 2, 3, 4, 5 };
    String[] appleFormats = { "Tiny Apple", "Small Apple", "Medium Apple", "Large Apple", "Huge Apple" };
    ChoiceFormat cf = new ChoiceFormat(appleLimits, appleFormats);
    formattedString = cf.format(Double.NEGATIVE_INFINITY);
    assertTrue("a) Incorrect format returned: " + formattedString, formattedString.equals("Tiny Apple"));
    formattedString = cf.format(0.5d);
    assertTrue("b) Incorrect format returned: " + formattedString, formattedString.equals("Tiny Apple"));
    formattedString = cf.format(1d);
    assertTrue("c) Incorrect format returned: " + formattedString, formattedString.equals("Tiny Apple"));
    formattedString = cf.format(1.5d);
    assertTrue("d) Incorrect format returned: " + formattedString, formattedString.equals("Tiny Apple"));
    formattedString = cf.format(2d);
    assertTrue("e) Incorrect format returned: " + formattedString, formattedString.equals("Small Apple"));
    formattedString = cf.format(2.5d);
    assertTrue("f) Incorrect format returned: " + formattedString, formattedString.equals("Small Apple"));
    formattedString = cf.format(3d);
    assertTrue("g) Incorrect format returned: " + formattedString, formattedString.equals("Medium Apple"));
    formattedString = cf.format(4d);
    assertTrue("h) Incorrect format returned: " + formattedString, formattedString.equals("Large Apple"));
    formattedString = cf.format(5d);
    assertTrue("i) Incorrect format returned: " + formattedString, formattedString.equals("Huge Apple"));
    formattedString = cf.format(5.5d);
    assertTrue("j) Incorrect format returned: " + formattedString, formattedString.equals("Huge Apple"));
    formattedString = cf.format(6.0d);
    assertTrue("k) Incorrect format returned: " + formattedString, formattedString.equals("Huge Apple"));
    formattedString = cf.format(Double.POSITIVE_INFINITY);
    assertTrue("l) Incorrect format returned: " + formattedString, formattedString.equals("Huge Apple"));
}
Also used : ChoiceFormat(java.text.ChoiceFormat)

Example 23 with ChoiceFormat

use of java.text.ChoiceFormat in project j2objc by google.

the class ChoiceFormatTest method testEscapedPatternWithConsecutiveQuotes.

// http://b/19011159
public void testEscapedPatternWithConsecutiveQuotes() {
    ChoiceFormat format = new ChoiceFormat("0#1'2''3'''4''''.");
    String formatted = format.format(0);
    assertEquals("12'3'4''.", formatted);
    format = new ChoiceFormat("0#1'2''3'''''4''''.");
    formatted = format.format(0);
    assertEquals("12'3''4''.", formatted);
}
Also used : ChoiceFormat(java.text.ChoiceFormat)

Example 24 with ChoiceFormat

use of java.text.ChoiceFormat in project j2objc by google.

the class ChoiceFormatTest method test_formatD.

/**
	 * @tests java.text.ChoiceFormat#format(double)
	 */
public void test_formatD() {
    ChoiceFormat fmt = new ChoiceFormat("-1#NEGATIVE_ONE|0#ZERO|1#ONE|1<GREATER_THAN_ONE");
    assertEquals("NEGATIVE_ONE", fmt.format(Double.NEGATIVE_INFINITY));
    assertEquals("NEGATIVE_ONE", fmt.format(-999999999D));
    assertEquals("NEGATIVE_ONE", fmt.format(-1.1));
    assertEquals("NEGATIVE_ONE", fmt.format(-1.0));
    assertEquals("NEGATIVE_ONE", fmt.format(-0.9));
    assertEquals("ZERO", fmt.format(0.0));
    assertEquals("ZERO", fmt.format(0.9));
    assertEquals("ONE", fmt.format(1.0));
    assertEquals("GREATER_THAN_ONE", fmt.format(1.1));
    assertEquals("GREATER_THAN_ONE", fmt.format(999999999D));
    assertEquals("GREATER_THAN_ONE", fmt.format(Double.POSITIVE_INFINITY));
}
Also used : ChoiceFormat(java.text.ChoiceFormat)

Example 25 with ChoiceFormat

use of java.text.ChoiceFormat in project j2objc by google.

the class MessageFormatTest method test_setFormatsByArgumentIndex$Ljava_text_Format.

public void test_setFormatsByArgumentIndex$Ljava_text_Format() {
    MessageFormat f1 = (MessageFormat) format1.clone();
    // test with repeating formats and max argument index < max offset
    // compare getFormatsByArgumentIndex() results after calls to
    // setFormatsByArgumentIndex(Format[])
    Format[] correctFormats = new Format[] { DateFormat.getTimeInstance(), new ChoiceFormat("0#off|1#on"), DateFormat.getTimeInstance(), NumberFormat.getCurrencyInstance(), new ChoiceFormat("1#few|2#ok|3#a lot") };
    f1.setFormatsByArgumentIndex(correctFormats);
    Format[] formats = f1.getFormatsByArgumentIndex();
    assertEquals("Test1A:Returned wrong number of formats:", correctFormats.length, formats.length);
    for (int i = 0; i < correctFormats.length; i++) {
        assertEquals("Test1B:wrong format for argument index " + i + ":", correctFormats[i], formats[i]);
    }
    // compare getFormats() results after calls to
    // setFormatByArgumentIndex()
    formats = f1.getFormats();
    correctFormats = new Format[] { NumberFormat.getCurrencyInstance(), DateFormat.getTimeInstance(), DateFormat.getTimeInstance(), new ChoiceFormat("1#few|2#ok|3#a lot"), new ChoiceFormat("0#off|1#on"), DateFormat.getTimeInstance() };
    assertEquals("Test1C:Returned wrong number of formats:", correctFormats.length, formats.length);
    for (int i = 0; i < correctFormats.length; i++) {
        assertEquals("Test1D:wrong format for pattern index " + i + ":", correctFormats[i], formats[i]);
    }
    // test setting argumentIndexes that are not used
    MessageFormat f2 = (MessageFormat) format2.clone();
    Format[] inputFormats = new Format[] { DateFormat.getDateInstance(), new ChoiceFormat("0#off|1#on"), NumberFormat.getPercentInstance(), NumberFormat.getCurrencyInstance(), DateFormat.getTimeInstance(), null, null, null, DateFormat.getTimeInstance() };
    f2.setFormatsByArgumentIndex(inputFormats);
    formats = f2.getFormatsByArgumentIndex();
    correctFormats = format2.getFormatsByArgumentIndex();
    assertEquals("Test2A:Returned wrong number of formats:", correctFormats.length, formats.length);
    for (int i = 0; i < correctFormats.length; i++) {
        assertEquals("Test2B:wrong format for argument index " + i + ":", correctFormats[i], formats[i]);
    }
    formats = f2.getFormats();
    correctFormats = new Format[] { NumberFormat.getCurrencyInstance(), DateFormat.getTimeInstance(), DateFormat.getDateInstance(), null, new ChoiceFormat("0#off|1#on"), DateFormat.getDateInstance() };
    assertEquals("Test2C:Returned wrong number of formats:", correctFormats.length, formats.length);
    for (int i = 0; i < correctFormats.length; i++) {
        assertEquals("Test2D:wrong format for pattern index " + i + ":", correctFormats[i], formats[i]);
    }
    // test exceeding the argumentIndex number
    MessageFormat f3 = (MessageFormat) format3.clone();
    f3.setFormatsByArgumentIndex(inputFormats);
    formats = f3.getFormatsByArgumentIndex();
    assertEquals("Test3A:Returned wrong number of formats:", 0, formats.length);
    formats = f3.getFormats();
    assertEquals("Test3B:Returned wrong number of formats:", 0, formats.length);
}
Also used : Format(java.text.Format) DecimalFormat(java.text.DecimalFormat) SimpleDateFormat(java.text.SimpleDateFormat) NumberFormat(java.text.NumberFormat) MessageFormat(java.text.MessageFormat) ChoiceFormat(java.text.ChoiceFormat) DateFormat(java.text.DateFormat) MessageFormat(java.text.MessageFormat) ChoiceFormat(java.text.ChoiceFormat)

Aggregations

ChoiceFormat (java.text.ChoiceFormat)33 NumberFormat (java.text.NumberFormat)15 MessageFormat (java.text.MessageFormat)11 Format (java.text.Format)10 DateFormat (java.text.DateFormat)9 DecimalFormat (java.text.DecimalFormat)7 SimpleDateFormat (java.text.SimpleDateFormat)7 DutySchedule (org.opennms.netmgt.config.users.DutySchedule)4 Currency (java.util.Currency)3 Locale (java.util.Locale)3 Vector (java.util.Vector)3 HttpSession (javax.servlet.http.HttpSession)3 FieldPosition (java.text.FieldPosition)2 ParseException (java.text.ParseException)2 RequestDispatcher (javax.servlet.RequestDispatcher)2 Support_MessageFormat (tests.support.Support_MessageFormat)2 ParsePosition (java.text.ParsePosition)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ServletException (javax.servlet.ServletException)1