@Test public void ofString() { final Width a = Width.ofString("this string has a longish-style word in it"); assertEquals(13, a.getMin()); assertEquals(42, a.getMax()); assertEquals("Width{min=13, max=42}", a.toString()); final Width b = Width.ofString("this string has a word that is not quite as long"); assertEquals(6, b.getMin()); assertEquals(48, b.getMax()); assertEquals("Width{min=6, max=48}", b.toString()); }
public static Width ofString(final String string) { final String wrapped = Wrap.wrap(string, 1); final int maximum = string.length(); final int minimum = Stream.of(wrapped.split(System.lineSeparator())) .map(String::length) .reduce(Math::max) .orElse(0); return new Width(minimum, maximum); }
Width { public static Width ofString(final String string) { final String wrapped = Wrap.wrap(string, 1); final int maximum = string.length(); final int minimum = Stream.of(wrapped.split(System.lineSeparator())) .map(String::length) .reduce(Math::max) .orElse(0); return new Width(minimum, maximum); } }
Width { public static Width ofString(final String string) { final String wrapped = Wrap.wrap(string, 1); final int maximum = string.length(); final int minimum = Stream.of(wrapped.split(System.lineSeparator())) .map(String::length) .reduce(Math::max) .orElse(0); return new Width(minimum, maximum); } Width(final int min, final int max); }
Width { public static Width ofString(final String string) { final String wrapped = Wrap.wrap(string, 1); final int maximum = string.length(); final int minimum = Stream.of(wrapped.split(System.lineSeparator())) .map(String::length) .reduce(Math::max) .orElse(0); return new Width(minimum, maximum); } Width(final int min, final int max); Width toMin(); Width toMax(); static Width ofString(final String string); Width adjust(final Width that); Width add(final Width that); Width subtract(final Width that); int getMin(); int getMax(); @Override String toString(); }
Width { public static Width ofString(final String string) { final String wrapped = Wrap.wrap(string, 1); final int maximum = string.length(); final int minimum = Stream.of(wrapped.split(System.lineSeparator())) .map(String::length) .reduce(Math::max) .orElse(0); return new Width(minimum, maximum); } Width(final int min, final int max); Width toMin(); Width toMax(); static Width ofString(final String string); Width adjust(final Width that); Width add(final Width that); Width subtract(final Width that); int getMin(); int getMax(); @Override String toString(); static final Width ZERO; }