/** * Overloads the left shift operator to provide an easy way to add * components to a menu.<p> * * @param self a JMenu * @param gstr a GString to be added to the menu. * @return same menu, after the value was added to it. * @since 1.6.4 */ public static JMenu leftShift(JMenu self, GString gstr) { self.add(gstr.toString()); return self; }
/** * Overloads the left shift operator to provide an easy way to add * components to a popupMenu.<p> * * @param self a JPopupMenu * @param gstr a GString to be added to the popupMenu. * @return same popupMenu, after the value was added to it. * @since 1.6.4 */ public static JPopupMenu leftShift(JPopupMenu self, GString gstr) { self.add(gstr.toString()); return self; }
@Override public char charAt(int index) { return toString().charAt(index); }
@Override public int hashCode() { return 37 + toString().hashCode(); }
@Override public int length() { return toString().length(); }
public byte[] getBytes(String charset) throws UnsupportedEncodingException { return toString().getBytes(charset); } }
@Override public CharSequence subSequence(int start, int end) { return toString().subSequence(start, end); }
@Override public int compareTo(Object that) { return toString().compareTo(that.toString()); }
/** * Support the subscript operator for GString. * * @param text a GString * @param index the index of the Character to get * @return the Character at the given index * @since 2.3.7 */ public static String getAt(GString text, int index) { return (String) getAt(text.toString(), index); }
/** * Support the range subscript operator for GString * * @param text a GString * @param range a Range * @return the String of characters corresponding to the provided range * @since 2.3.7 */ public static String getAt(GString text, Range range) { return getAt(text.toString(), range); }
/** * A GString variant of the equivalent CharSequence method. * * @param self the original GString * @param num the number of chars to take from this GString * @return a String consisting of the first <code>num</code> chars, * or else the whole GString if it has less then <code>num</code> elements. * @since 2.3.7 */ public static String take(GString self, int num) { return take(self.toString(), num); }
/** * Turns a String into a regular expression pattern * * @return the regular expression pattern */ public Pattern negate() { return StringGroovyMethods.bitwiseNegate(toString()); }
/** * A GString variant of the equivalent CharSequence method. * * @param self the original GString * @param num the number of characters to drop from this GString * @return a String consisting of all characters except the first <code>num</code> ones, * or else an empty String, if the toString() of this GString has less than <code>num</code> characters. * @see #drop(String, int) * @since 2.3.7 */ public static String drop(GString self, int num) { return drop(self.toString(), num); }
/** * A GString variant of the equivalent GString method. * * @param self the original GString * @param condition the closure that must evaluate to true to continue taking elements * @return a prefix of elements in the GString where each * element passed to the given closure evaluates to true * @since 2.3.7 */ public static String takeWhile(GString self, @ClosureParams(value=FromString.class, conflictResolutionStrategy=PickFirstResolver.class, options={"String", "Character"}) Closure condition) { return takeWhile(self.toString(), condition); }
public void testConstructorWithGStringCoercion() throws Throwable { GString gstring = new GString(new Object[]{new Integer(123)}) { public String[] getStrings() { return new String[]{""}; } }; Object expected = new Long(gstring.toString()); assertConstructor(expected, new Object[]{gstring}); }
public void testCoerceGStringToString() throws Throwable { GString param = new GString(new Object[]{"James"}) { public String[] getStrings() { return new String[]{"Hello "}; } }; Object value = invoke(this, "methodTakesString", new Object[]{param}); assertEquals("converted GString to string", param.toString(), value); }
public void testAppendString2() { DummyGString a = new DummyGString(new Object[]{"James"}, new String[]{"Hello "}); GString result = a.plus(" how are you?"); System.out.println("Strings: " + InvokerHelper.toString(result.getStrings())); System.out.println("Values: " + InvokerHelper.toString(result.getValues())); assertEquals("Hello James how are you?", result.toString()); }
public void testAppendGString2() { DummyGString a = new DummyGString(new Object[]{"James"}, new String[]{"Hello "}); DummyGString b = new DummyGString(new Object[]{"Bob"}, new String[]{"Hello "}); GString result = a.plus(b); assertEquals("Hello JamesHello Bob", result.toString()); }
public void testAppendGString() { DummyGString a = new DummyGString(new Object[]{"James"}); DummyGString b = new DummyGString(new Object[]{"Bob"}); GString result = a.plus(b); assertEquals("Hello James!Hello Bob!", result.toString()); }
public void testAppendString() { DummyGString a = new DummyGString(new Object[]{"James"}); GString result = a.plus(" how are you?"); assertEquals("Hello James! how are you?", result.toString()); assertEquals('J', a.charAt(6)); assertEquals("o J", a.subSequence(4, 7)); }