/** * Converts a string to upper case, where the string may be null. * * @param aString the string to convert. * @return the string converted to upper case, or null if the supplied string was null. */ public static String upperCase(final String aString) { if (!empty(aString)) { return aString.toUpperCase(); } return aString; }
/** * {@inheritDoc} */ @Override protected boolean doCompare(final Object aVal, final Object bVal) { return !Util.equals(aVal, bVal); }
/** * {@inheritDoc} */ @Override public int compare(final Comparable<?> obj1, final Comparable<?> obj2) { return Util.compareAllowNull(obj1, obj2); } }
/** * Set the value of the {@code autocomplete} attribute for the current field. * @param autocompleteValue the value to set as a (optionally space delimited list of) String value(s). */ protected void setAutocomplete(final String autocompleteValue) { final String newValue = Util.empty(autocompleteValue) ? null : autocompleteValue; if (!Util.equals(newValue, getAutocomplete())) { getOrCreateComponentModel().autocomplete = newValue; } }
String toolTip = button.getToolTip(); if (Util.empty(text) && imageUrl == null && Util.empty(accessibleText) && Util.empty(toolTip)) { throw new SystemException("WButton text or imageUrl must be specified"); if (Util.empty(text) && Util.empty(toolTip) && Util.empty(accessibleText)) { xml.appendOptionalAttribute("aria-label", accessibleText); xml.appendOptionalAttribute("aria-haspopup", button.isPopupTrigger(), "true"); xml.appendOptionalAttribute("accesskey", Util.upperCase(button.getAccessKeyAsString())); xml.appendOptionalAttribute("data-wc-btnmsg", button.getMessage());
@Test public void testRightTrim() { Assert.assertNull("Incorrect right trimmed value returned", Util.rightTrim(null)); Assert.assertEquals("Incorrect right trimmed value returned", "", Util.rightTrim("")); Assert.assertEquals("Incorrect right trimmed value returned", "", Util.rightTrim(" ")); Assert.assertEquals("Incorrect right trimmed value returned", "", Util.rightTrim(" ")); Assert.assertEquals("Incorrect right trimmed value returned", "A", Util.rightTrim("A")); Assert.assertEquals("Incorrect right trimmed value returned", "A", Util.rightTrim("A ")); Assert.assertEquals("Incorrect right trimmed value returned", " A", Util.rightTrim(" A ")); Assert.assertEquals("Incorrect right trimmed value returned", " A", Util.rightTrim(" A ")); Assert. assertEquals("Incorrect right trimmed value returned", " A", Util. rightTrim(" A ")); Assert.assertEquals("Incorrect right trimmed value returned", "A B C", Util.rightTrim( "A B C")); Assert.assertEquals("Incorrect right trimmed value returned", " A B C", Util.rightTrim( " A B C")); Assert.assertEquals("Incorrect right trimmed value returned", " A B C", Util.rightTrim( " A B C ")); Assert.assertEquals("Incorrect right trimmed value returned", " A B C", Util.rightTrim( " A B C ")); }
xml.appendOptionalAttribute("accessKey", Util.upperCase(panel.getAccessKeyAsString())); xml.appendOptionalAttribute("type", getPanelType(panel)); xml.appendOptionalAttribute("mode", getPanelMode(panel));
@Test public void testLeftTrim() { Assert.assertNull("Incorrect left trimmed value returned", Util.leftTrim(null)); Assert.assertEquals("Incorrect left trimmed value returned", "", Util.leftTrim("")); Assert.assertEquals("Incorrect left trimmed value returned", "", Util.leftTrim(" ")); Assert.assertEquals("Incorrect left trimmed value returned", "", Util.leftTrim(" ")); Assert.assertEquals("Incorrect left trimmed value returned", "A", Util.leftTrim("A")); Assert.assertEquals("Incorrect left trimmed value returned", "A ", Util.leftTrim("A ")); Assert.assertEquals("Incorrect left trimmed value returned", "A ", Util.leftTrim(" A ")); Assert.assertEquals("Incorrect left trimmed value returned", "A ", Util.leftTrim(" A ")); Assert.assertEquals("Incorrect left trimmed value returned", "A ", Util.leftTrim(" A ")); Assert. assertEquals("Incorrect left trimmed value returned", "A B C", Util. leftTrim("A B C")); Assert.assertEquals("Incorrect left trimmed value returned", "A B C", Util.leftTrim( " A B C")); Assert.assertEquals("Incorrect left trimmed value returned", "A B C ", Util.leftTrim( " A B C ")); Assert.assertEquals("Incorrect left trimmed value returned", "A B C ", Util.leftTrim( " A B C ")); }
/** * Set the WPartialDateField with the given day, month and year. Each of the day, month and year parameters that * make up the partial date are optional. * * @param day a number from 1 to 31 or null if unknown. * @param month a number from 1 to 12, or null if unknown. * @param year a number, or null if unknown. * @param padding the padding character for the partial date * @return the formatted partial date, or null if invalid */ private String formatPartialDateToString(final Integer day, final Integer month, final Integer year, final char padding) { if (year == null && month == null && day == null) { return null; } if (!isValidYear(year) || !isValidMonth(month) || !isValidDay(day)) { return null; } StringBuffer dateString = new StringBuffer(DATE_TOTAL_CHARS); append(dateString, year, YEAR_DIGITS, padding); append(dateString, month, MONTH_DIGITS, padding); append(dateString, day, DAY_DIGITS, padding); // TRIM trailing spaces (will only "trim" if the padding character is a space) String trimmed = Util.rightTrim(dateString.toString()); return trimmed; }
xml.appendOptionalAttribute("hiddencomponent", (what != null && what.isHidden()), "true"); xml.appendOptionalAttribute("hint", label.getHint()); xml.appendOptionalAttribute("accessKey", Util.upperCase(label.getAccessKeyAsString())); xml.appendOptionalAttribute("hidden", label.isHidden(), "true"); xml.appendOptionalAttribute("toolTip", label.getToolTip());
/** * @param url URL to a resource */ public ApplicationResource(final String url) { if (Util.empty(url)) { throw new IllegalArgumentException("A URL must be provided."); } this.resourceId = "url:" + url; this.url = url; this.resource = null; }
/** * Indicates whether the given object is equal to this one. * * @param obj the object to test for equality. * @return true if the object is a TableEntry and has the same code as this one. */ @Override public boolean equals(final Object obj) { return (obj instanceof TableEntry) && Util.equals(code, ((TableEntry) obj).code); }
@Test public void testCompareAllowNull() { Assert.assertEquals("Two nulls should be equal", 0, Util.compareAllowNull(null, null)); Assert.assertTrue("Nulls should be less than anything else", Util. compareAllowNull(null, "a") < 0); Assert.assertTrue("Anything should be greater than null", Util.compareAllowNull("a", null) > 0); Assert.assertEquals("Equal values should be equal", 0, Util.compareAllowNull("a", "a")); Assert.assertTrue("'A' should be less than 'B'", Util.compareAllowNull("a", "b") < 0); Assert.assertTrue("'B' should be greater than 'A'", Util.compareAllowNull("b", "a") > 0); }
/** * Remove a value from the HTML class name list. * @param className the value to remove */ protected void removeHtmlClass(final String className) { if (this.htmlClasses != null && !Util.empty(className)) { this.htmlClasses.remove(className); } }
/** * {@inheritDoc} */ @Override protected boolean doCompare(final Object aVal, final Object bVal) { return Util.equals(aVal, bVal); }
/** * {@inheritDoc} */ @Override public int compare(final Object obj1, final Object obj2) { Comparable<?> comparable1 = getComparable(obj1); Comparable<?> comparable2 = getComparable(obj2); return Util.compareAllowNull(comparable1, comparable2); } }
/** * @param text The HTML class name text to set. */ protected void addHtmlClass(final String text) { if (!Util.empty(text)) { if (this.htmlClasses == null) { this.htmlClasses = new HashSet<>(); } this.htmlClasses.add(text); } }
/** * Performs basic sanity checks on the file being requested. * * @param name the file name * @return true if the requested file name is ok, false if not. */ private static boolean checkThemeFile(final String name) { return !(Util.empty(name) // name must exist || name.contains("..") // prevent directory traversal || name.charAt(0) == '/' // all theme references should be relative || name.indexOf(':') != -1 // forbid use of protocols such as jar:, http: etc. ); }