Utils { @Nonnull public static String strip(@Nonnull final String str, final boolean leading) { if (str.trim().isEmpty()) { return ""; } final Matcher matcher = STRIP_PATTERN.matcher(str); if (!matcher.find()) { throw new Error("Unexpected error in strip(String): " + str); } return leading ? matcher.group(2) + matcher.group(3) : matcher.group(1) + matcher.group(2); } private  Utils(); @Nullable static InputStream findInputStreamForResource(@Nonnull final ZipFile zipFile, @Nonnull final String resourcePath); @Nullable static byte[] toByteArray(@Nonnull final ZipFile zipFile, @Nonnull final String path); @Nonnull static Document loadHtmlDocument(@Nonnull final InputStream inStream, @Nullable final String charset, final boolean autoClose); @Nonnull static Document loadXmlDocument(@Nonnull final InputStream inStream, @Nullable final String charset, final boolean autoClose); @Nullable static Element findFirstElement(@Nonnull final Element node, @Nonnull final String elementName); @Nonnull @MustNotContainNull static List<Element> findDirectChildrenForName(@Nonnull final Element element, @Nonnull final String childElementname); static boolean isUriCorrect(@Nonnull final String uri); static int getMaxImageSize(); @Nullable static String rescaleImageAndEncodeAsBase64(@Nonnull final InputStream in, final int maxSize); @Nonnull static String rescaleImageAndEncodeAsBase64(@Nonnull final File file, final int maxSize); @Nonnull static RenderQuality getDefaultRenderQialityForOs(); @Nonnull static String rescaleImageAndEncodeAsBase64(@Nonnull Image image, final int maxSize); static int calculateColorBrightness(@Nonnull final Color color); static boolean isDarkTheme(); @Nonnull static String convertCamelCasedToHumanForm(@Nonnull final String camelCasedString, final boolean capitalizeFirstChar); @Nonnull @MustNotContainNull static Topic[] getLeftToRightOrderedChildrens(@Nonnull final Topic topic); static boolean safeObjectEquals(@Nullable final Object obj1, @Nullable final Object obj2); static void setAttribute(@Nonnull final String name, @Nullable final String value, @Nonnull @MustNotContainNull final Topic[] topics); @Nullable static Color html2color(@Nullable final String str, final boolean hasAlpha); @Nullable static String color2html(@Nullable final Color color, final boolean hasAlpha); @Nonnull static String getFirstLine(@Nonnull final String text); @Nonnull static String makeShortTextVersion(@Nonnull String text, final int maxLength); static void safeSwingCall(@Nonnull final Runnable runnable); static void safeSwingBlockingCall(@Nonnull final Runnable runnable); @Nonnull @MustNotContainNull static String[] breakToLines(@Nonnull final String text); static int numberOfLines(@Nonnull final String text); @ImplementationNote("Must be called from Swing UI thread") static void foldUnfoldTree(@Nonnull final JTree tree, final boolean unfold); static @Nonnull String removeAllISOControlsButTabs(@Nonnull final String str); @Nullable static Point2D findRectEdgeIntersection(@Nonnull final Rectangle2D rect, final double outboundX, final double outboundY); static boolean isPlantUmlFileExtension(@Nonnull final String lowerCasedTrimmedExtension); @Nullable static Image scaleImage(@Nonnull final Image src, final double baseScaleX, final double baseScaleY, final double scale); @Nonnull static Image renderWithTransparency(final float opacity, @Nonnull final AbstractElement element, @Nonnull final MindMapPanelConfig config, @Nonnull final RenderQuality quality); @Nonnull static Color makeContrastColor(@Nonnull final Color color); static void assertSwingDispatchThread(); static boolean isDataFlavorAvailable(@Nonnull final Clipboard clipboard, @Nonnull final DataFlavor flavor); @Nonnull static JPopupMenu makePopUp(
      @Nonnull final PluginContext context,
      final boolean fullScreenModeActive,
      @Nullable final Topic topicUnderMouse
  ); static boolean isKeyStrokeEvent(@Nullable final KeyStroke keyStroke, final int keyEventType, @Nullable final KeyEvent event); @Nonnull static byte[] base64decode(@Nonnull final String text); @Nonnull static String strip(@Nonnull final String str, final boolean leading); @Nonnull static String base64encode(@Nonnull final byte[] data); static final UIComponentFactory UI_COMPO_FACTORY; static final ImageIconService ICON_SERVICE; static final String PROPERTY_MAX_EMBEDDED_IMAGE_SIDE_SIZE; static final boolean LTR_LANGUAGE; }
@Test public void testStrip() { assertEquals("", Utils.strip("", true)); assertEquals("", Utils.strip("", false)); assertEquals("", Utils.strip(" ", true)); assertEquals("", Utils.strip(" ", false)); assertEquals("huz aa", Utils.strip("huz aa", true)); assertEquals("huz aa", Utils.strip("huz aa", false)); assertEquals("huz aa", Utils.strip(" huz aa", true)); assertEquals(" huz aa", Utils.strip(" huz aa", false)); assertEquals("huz aa ", Utils.strip("huz aa ", true)); assertEquals("huz aa", Utils.strip("huz aa ", false)); assertEquals("huz aa ", Utils.strip(" huz aa ", true)); assertEquals(" huz aa", Utils.strip(" huz aa ", false)); }