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()); }
@Override public boolean equals(Object that) { if (that instanceof GString) { return equals((GString) that); } return false; }
public GString plus(GString that) { Object[] values = getValues(); return new GStringImpl(appendValues(values, that.getValues()), appendStrings(getStrings(), that.getStrings(), values.length)); }
@Override public String toString() { Writer buffer = new StringBuilderWriter(calcInitialCapacity()); try { writeTo(buffer); } catch (IOException e) { throw new StringWriterIOException(e); } return buffer.toString(); }
public GString plus(String that) { String[] currentStrings = getStrings(); String[] newStrings = null; Object[] newValues = null; boolean appendToLastString = currentStrings.length > getValues().length; if (appendToLastString) { newStrings = new String[currentStrings.length]; } else { newStrings = new String[currentStrings.length + 1]; } newValues = new Object[getValues().length]; int lastIndex = currentStrings.length; System.arraycopy(currentStrings, 0, newStrings, 0, lastIndex); System.arraycopy(getValues(), 0, newValues, 0, getValues().length); if (appendToLastString) { newStrings[lastIndex - 1] += that; } else { newStrings[lastIndex] = that; } final String[] finalStrings = newStrings; return new GString(newValues) { public String[] getStrings() { return finalStrings; } }; }
private String assemblySegment(final List<String> cartesianValue, final GString segment) { StringBuilder result = new StringBuilder(); for (int i = 0; i < segment.getStrings().length; i++) { result.append(segment.getStrings()[i]); if (i < cartesianValue.size()) { result.append(cartesianValue.get(i)); } } return result.toString(); } }
/** * Hook to allow derived classes to override behavior associated with * extracting params from a GString. * * @param gstring a GString containing the SQL query with embedded params * @return extracts the parameters from the expression as a List * @see #expand(Object) */ protected List<Object> getParameters(GString gstring) { return new ArrayList<Object>(Arrays.asList(gstring.getValues())); }
public String toString() { StringWriter buffer = new StringWriter(); try { writeTo(buffer); } catch (IOException e) { throw new StringWriterIOException(e); } return buffer.toString(); }
public GString plus(String that) { String[] currentStrings = getStrings(); String[] newStrings; Object[] newValues; boolean appendToLastString = currentStrings.length > getValues().length; if (appendToLastString) { newStrings = new String[currentStrings.length]; } else { newStrings = new String[currentStrings.length + 1]; } newValues = new Object[getValues().length]; int lastIndex = currentStrings.length; System.arraycopy(currentStrings, 0, newStrings, 0, lastIndex); System.arraycopy(getValues(), 0, newValues, 0, getValues().length); if (appendToLastString) { newStrings[lastIndex - 1] += that; } else { newStrings[lastIndex] = that; } final String[] finalStrings = newStrings; return new GString(newValues) { public String[] getStrings() { return finalStrings; } }; }
private int calcInitialCapacity() { String[] strings = getStrings(); int initialCapacity = 0; for (String string : strings) { initialCapacity += string.length(); } initialCapacity += values.length * Math.max(initialCapacity / strings.length, 8); return Math.max((int) (initialCapacity * 1.2), 16); }
@SuppressWarnings("unchecked") private Set<List<String>> getCartesianValues(final GString segment) { List<Set<String>> result = new ArrayList<>(segment.getValues().length); for (Object each : segment.getValues()) { if (null == each) { continue; } if (each instanceof Collection) { result.add(Sets.newLinkedHashSet(Collections2.transform((Collection<Object>) each, new Function<Object, String>() { @Override public String apply(final Object input) { return input.toString(); } }))); } else { result.add(Sets.newHashSet(each.toString())); } } return Sets.cartesianProduct(result); }
public String toString() { StringWriter buffer = new StringWriter(); try { writeTo(buffer); } catch (IOException e) { throw new StringWriterIOException(e); } return buffer.toString(); }
/** * 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; }
public GString plus(String that) { String[] currentStrings = getStrings(); String[] newStrings = null; Object[] newValues = null; boolean appendToLastString = currentStrings.length > getValues().length; if (appendToLastString) { newStrings = new String[currentStrings.length]; } else { newStrings = new String[currentStrings.length + 1]; } newValues = new Object[getValues().length]; int lastIndex = currentStrings.length; System.arraycopy(currentStrings, 0, newStrings, 0, lastIndex); System.arraycopy(getValues(), 0, newValues, 0, getValues().length); if (appendToLastString) { newStrings[lastIndex - 1] += that; } else { newStrings[lastIndex] = that; } final String[] finalStrings = newStrings; return new GString(newValues) { public String[] getStrings() { return finalStrings; } }; }
String[] strings = gstring.getStrings(); if (strings.length <= 0) { throw new IllegalArgumentException("No SQL specified in GString: " + gstring);
/** * Hook to allow derived classes to override behavior associated with * extracting params from a GString. * * @param gstring a GString containing the SQL query with embedded params * @return extracts the parameters from the expression as a List * @see #expand(Object) */ protected List<Object> getParameters(GString gstring) { return new ArrayList<Object>(Arrays.asList(gstring.getValues())); }
public boolean equals(Object that) { if (that instanceof GString) { return equals((GString) that); } return false; }
public String toString() { StringWriter buffer = new StringWriter(); try { writeTo(buffer); } catch (IOException e) { throw new StringWriterIOException(e); } return buffer.toString(); }
/** * 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; }