public void setExceptionMessage(String exceptionMessage) { this.exceptionMessage = StringUtils.abbreviate(exceptionMessage, MAX_EXCEPTION_MESSAGE_LENGTH); }
return abbreviate(str, defaultAbbrevMarker, 0, maxWidth);
return abbreviate(str, defaultAbbrevMarker, offset, maxWidth);
return abbreviate(str, abbrevMarker, 0, maxWidth);
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("HistoricDetailVariableInstanceUpdateEntity["); sb.append("id=").append(id); sb.append(", name=").append(name); sb.append(", type=").append(variableType != null ? variableType.getTypeName() : "null"); if (longValue != null) { sb.append(", longValue=").append(longValue); } if (doubleValue != null) { sb.append(", doubleValue=").append(doubleValue); } if (textValue != null) { sb.append(", textValue=").append(StringUtils.abbreviate(textValue, 40)); } if (textValue2 != null) { sb.append(", textValue2=").append(StringUtils.abbreviate(textValue2, 40)); } if (byteArrayRef != null && byteArrayRef.getId() != null) { sb.append(", byteArrayValueId=").append(byteArrayRef.getId()); } sb.append("]"); return sb.toString(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("VariableInstanceEntity["); sb.append("id=").append(id); sb.append(", name=").append(name); sb.append(", type=").append(type != null ? type.getTypeName() : "null"); if (longValue != null) { sb.append(", longValue=").append(longValue); } if (doubleValue != null) { sb.append(", doubleValue=").append(doubleValue); } if (textValue != null) { sb.append(", textValue=").append(StringUtils.abbreviate(textValue, 40)); } if (textValue2 != null) { sb.append(", textValue2=").append(StringUtils.abbreviate(textValue2, 40)); } if (byteArrayRef != null && byteArrayRef.getId() != null) { sb.append(", byteArrayValueId=").append(byteArrayRef.getId()); } sb.append("]"); return sb.toString(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("HistoricVariableInstanceEntity["); sb.append("id=").append(id); sb.append(", name=").append(name); sb.append(", revision=").append(revision); sb.append(", type=").append(variableType != null ? variableType.getTypeName() : "null"); if (longValue != null) { sb.append(", longValue=").append(longValue); } if (doubleValue != null) { sb.append(", doubleValue=").append(doubleValue); } if (textValue != null) { sb.append(", textValue=").append(StringUtils.abbreviate(textValue, 40)); } if (textValue2 != null) { sb.append(", textValue2=").append(StringUtils.abbreviate(textValue2, 40)); } if (byteArrayRef != null && byteArrayRef.getId() != null) { sb.append(", byteArrayValueId=").append(byteArrayRef.getId()); } sb.append("]"); return sb.toString(); }
return abbrevMarker + abbreviate(str.substring(offset), abbrevMarker, maxWidth - abbrevMarkerLength);
@Override public String evaluate(FunctionArgs args, EvaluationContext context) { final String value = valueParam.required(args, context); final Long required = widthParam.required(args, context); if (required == null) { return null; } final Long maxWidth = Math.max(required, 4L); return StringUtils.abbreviate(value, saturatedCast(maxWidth)); }
/** * Shortens and escapes (for markdown) some special characters. Otherwise the shortened text * could contain some unfinished sequences. * @param rule * @return */ private static String getShortRuleDescription(Rule rule) { return StringEscapeUtils.escapeHtml4( StringUtils.abbreviate( StringUtils.stripToEmpty( rule.getDescription() .replaceAll("\n|\r", "") .replaceAll("\\|", "\\\\|") .replaceAll("`", "'") .replaceAll("\\*", "")), 100)); }
String formatCell(Object value, int column) { int width = columnWidths.get(column); TextTableAlignment align = columnAlignments.get(column); Function<Object, String> formatter = columnFormatters.get(column); String content = formatter.apply(value); if (content.length() > width) { // truncate content = StringUtils.abbreviate(content, width); } else if (content.length() < width) { // add padding switch (align) { case LEFT: content = StringUtils.rightPad(content, width); break; case RIGHT: content = StringUtils.leftPad(content, width); break; case CENTER: content = StringUtils.center(content, width); break; } } return content; }
private static void logRetrievedMsg(final ZKWatcher zkw, final String znode, final byte [] data, final boolean watcherSet) { if (!LOG.isTraceEnabled()) { return; } LOG.trace(zkw.prefix("Retrieved " + ((data == null)? 0: data.length) + " byte(s) of data from znode " + znode + (watcherSet? " and set watcher; ": "; data=") + (data == null? "null": data.length == 0? "empty": ( znode.startsWith(zkw.getZNodePaths().metaZNodePrefix)? getServerNameOrEmptyString(data): znode.startsWith(zkw.getZNodePaths().backupMasterAddressesZNode)? getServerNameOrEmptyString(data): StringUtils.abbreviate(Bytes.toStringBinary(data), 32))))); }
@Test public void testAbbreviate_StringInt() { assertNull(StringUtils.abbreviate(null, 10)); assertEquals("", StringUtils.abbreviate("", 10)); assertEquals("short", StringUtils.abbreviate("short", 10)); assertEquals("Now is ...", StringUtils.abbreviate("Now is the time for all good men to come to the aid of their party.", 10)); final String raspberry = "raspberry peach"; assertEquals("raspberry p...", StringUtils.abbreviate(raspberry, 14)); assertEquals("raspberry peach", StringUtils.abbreviate("raspberry peach", 15)); assertEquals("raspberry peach", StringUtils.abbreviate("raspberry peach", 16)); assertEquals("abc...", StringUtils.abbreviate("abcdefg", 6)); assertEquals("abcdefg", StringUtils.abbreviate("abcdefg", 7)); assertEquals("abcdefg", StringUtils.abbreviate("abcdefg", 8)); assertEquals("a...", StringUtils.abbreviate("abcdefg", 4)); assertEquals("", StringUtils.abbreviate("", 4)); try { StringUtils.abbreviate("abc", 3); fail("StringUtils.abbreviate expecting IllegalArgumentException"); } catch (final IllegalArgumentException expected) { // empty } }
private void assertAbbreviateWithOffset(final String expected, final int offset, final int maxWidth) { final String abcdefghijklmno = "abcdefghijklmno"; final String message = "abbreviate(String,int,int) failed"; final String actual = StringUtils.abbreviate(abcdefghijklmno, offset, maxWidth); if (offset >= 0 && offset < abcdefghijklmno.length()) { assertTrue(message + " -- should contain offset character", actual.indexOf((char) ('a' + offset)) != -1); } assertTrue(message + " -- should not be greater than maxWidth", actual.length() <= maxWidth); assertEquals(message, expected, actual); }
private void assertAbbreviateWithAbbrevMarkerAndOffset(final String expected, final String abbrevMarker, final int offset, final int maxWidth) { final String abcdefghijklmno = "abcdefghijklmno"; final String message = "abbreviate(String,String,int,int) failed"; final String actual = StringUtils.abbreviate(abcdefghijklmno, abbrevMarker, offset, maxWidth); if (offset >= 0 && offset < abcdefghijklmno.length()) { assertTrue(message + " -- should contain offset character", actual.indexOf((char) ('a' + offset)) != -1); } assertTrue(message + " -- should not be greater than maxWidth", actual.length() <= maxWidth); assertEquals(message, expected, actual); }
@Test public void testAbbreviate_StringStringInt() { assertNull(StringUtils.abbreviate(null, null, 10)); assertNull(StringUtils.abbreviate(null, "...", 10)); assertEquals("paranaguacu", StringUtils.abbreviate("paranaguacu", null, 10)); assertEquals("", StringUtils.abbreviate("", "...", 2)); assertEquals("wai**", StringUtils.abbreviate("waiheke", "**", 5)); assertEquals("And af,,,,", StringUtils.abbreviate("And after a long time, he finally met his son.", ",,,,", 10)); final String raspberry = "raspberry peach"; assertEquals("raspberry pe..", StringUtils.abbreviate(raspberry, "..", 14)); assertEquals("raspberry peach", StringUtils.abbreviate("raspberry peach", "---*---", 15)); assertEquals("raspberry peach", StringUtils.abbreviate("raspberry peach", ".", 16)); assertEquals("abc()(", StringUtils.abbreviate("abcdefg", "()(", 6)); assertEquals("abcdefg", StringUtils.abbreviate("abcdefg", ";", 7)); assertEquals("abcdefg", StringUtils.abbreviate("abcdefg", "_-", 8)); assertEquals("abc.", StringUtils.abbreviate("abcdefg", ".", 4)); assertEquals("", StringUtils.abbreviate("", 4)); try { @SuppressWarnings("unused") final String res = StringUtils.abbreviate("abcdefghij", "...", 3); fail("StringUtils.abbreviate expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { // empty } }
private void writeRoomTalks(List<Timeslot> dayTimeslotList, Room room, List<Talk> roomTalkList) { Timeslot mergePreviousTimeslot = null; int mergeStart = -1; for (Timeslot timeslot : dayTimeslotList) { List<Talk> talkList = roomTalkList.stream() .filter(talk -> talk.getTimeslot() == timeslot).collect(toList()); if (talkList.isEmpty() && mergePreviousTimeslot != null && timeslot.getStartDateTime().compareTo(mergePreviousTimeslot.getEndDateTime()) < 0) { nextCellVertically(); } else { if (mergePreviousTimeslot != null && mergeStart < currentRowNumber) { currentSheet.addMergedRegion(new CellRangeAddress(mergeStart, currentRowNumber, currentColumnNumber, currentColumnNumber)); } boolean unavailable = room.getUnavailableTimeslotSet().contains(timeslot) || Collections.disjoint(room.getTalkTypeSet(), timeslot.getTalkTypeSet()); nextTalkListCell(unavailable, talkList, talk -> StringUtils.abbreviate(talk.getTitle(), 50) + "\n" + StringUtils.abbreviate(talk.getSpeakerList().stream().map(Speaker::getName).collect(joining(", ")), 30), true); mergePreviousTimeslot = talkList.isEmpty() ? null : timeslot; mergeStart = currentRowNumber; } } if (mergePreviousTimeslot != null && mergeStart < currentRowNumber) { currentSheet.addMergedRegion(new CellRangeAddress(mergeStart, currentRowNumber, currentColumnNumber, currentColumnNumber)); } }
int y = translator.translateLatitudeToY(airport.getLatitude()); g.fillRect(x - 1, y - 1, 3, 3); g.drawString(StringUtils.abbreviate(airport.getCode(), 20), x + 3, y - 3);
@Test public void testAbbreviate_StringStringIntInt() { assertNull(StringUtils.abbreviate(null, null, 10, 12)); assertNull(StringUtils.abbreviate(null, "...", 10, 12)); assertEquals("", StringUtils.abbreviate("", null, 0, 10)); assertEquals("", StringUtils.abbreviate("", "...", 2, 10)); StringUtils.abbreviate("abcdefghij", "::", 0, 2); fail("StringUtils.abbreviate expecting IllegalArgumentException"); } catch (final IllegalArgumentException expected) { StringUtils.abbreviate("abcdefghij", "!!!", 5, 6); fail("StringUtils.abbreviate expecting IllegalArgumentException"); } catch (final IllegalArgumentException expected) { assertEquals("raspberry peach", StringUtils.abbreviate(raspberry, "--", 12, 15)); assertNull(StringUtils.abbreviate(null, ";", 7, 14)); assertAbbreviateWithAbbrevMarkerAndOffset("abcdefgh;;", ";;", -1, 10); assertAbbreviateWithAbbrevMarkerAndOffset("abcdefghi.", ".", 0, 10);
@Test public void testAbbreviate_StringIntInt() { assertNull(StringUtils.abbreviate(null, 10, 12)); assertEquals("", StringUtils.abbreviate("", 0, 10)); assertEquals("", StringUtils.abbreviate("", 2, 10)); StringUtils.abbreviate("abcdefghij", 0, 3); fail("StringUtils.abbreviate expecting IllegalArgumentException"); } catch (final IllegalArgumentException expected) { StringUtils.abbreviate("abcdefghij", 5, 6); fail("StringUtils.abbreviate expecting IllegalArgumentException"); } catch (final IllegalArgumentException expected) { assertEquals("raspberry peach", StringUtils.abbreviate(raspberry, 11, 15)); assertNull(StringUtils.abbreviate(null, 7, 14)); assertAbbreviateWithOffset("abcdefg...", -1, 10); assertAbbreviateWithOffset("abcdefg...", 0, 10);