Example usage for org.apache.commons.lang3 StringUtils substring

List of usage examples for org.apache.commons.lang3 StringUtils substring

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils substring.

Prototype

public static String substring(final String str, int start) 

Source Link

Document

Gets a substring from the specified String avoiding exceptions.

A negative start position can be used to start n characters from the end of the String.

A null String will return null .

Usage

From source file:com.neophob.sematrix.core.glue.PresetSettings.java

/**
 * Sets the present.//from  w  ww. j a va 2s  . com
 *
 * @param present the new present
 */
public void setPresent(String[] present) {
    List<String> list = new ArrayList<String>();
    for (String s : present) {
        if (StringUtils.startsWith(s, NAME_MARKER)) {
            String rawName = StringUtils.substring(s, NAME_MARKER.length());
            if (StringUtils.isNotBlank(rawName)) {
                this.name = rawName;
            }
        } else {
            list.add(s);
        }
    }
    this.present = list;
}

From source file:com.adeptj.modules.jaxrs.core.jwt.JwtExtractor.java

private static String cleanseJwt(String jwt) {
    return StringUtils.startsWith(jwt, AUTH_SCHEME_BEARER) ? StringUtils.substring(jwt, JWT_START_POS)
            : StringUtils.trim(jwt);/*from w w  w  . jav a 2 s. co m*/
}

From source file:ch.cyberduck.core.googledrive.DriveSearchFeatureTest.java

@Test
public void testSearchRoot() throws Exception {
    final String name = new AlphanumericRandomStringService().random();
    final Path workdir = new DriveHomeFinderService(session).find();
    final Path file = new DriveTouchFeature(session).touch(new Path(workdir, name, EnumSet.of(Path.Type.file)),
            new TransferStatus());
    final DriveSearchFeature feature = new DriveSearchFeature(session);
    assertTrue(//from w  w  w.ja v  a  2  s  .c  om
            feature.search(workdir, new SearchFilter(name), new DisabledListProgressListener()).contains(file));
    // Supports prefix matching only
    assertFalse(feature.search(workdir, new SearchFilter(StringUtils.substring(name, 2)),
            new DisabledListProgressListener()).contains(file));
    assertTrue(feature.search(workdir, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)),
            new DisabledListProgressListener()).contains(file));
    final Path subdir = new Path(workdir, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.directory));
    assertFalse(
            feature.search(subdir, new SearchFilter(name), new DisabledListProgressListener()).contains(file));
    new DriveDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
}

From source file:com.sonicle.webtop.contacts.bol.OCategory.java

public String getHexColor() {
    String color = getColor();
    return (StringUtils.indexOf(color, "#") == 0) ? StringUtils.substring(color, 1) : color;
}

From source file:ch.cyberduck.core.dropbox.DropboxSearchFeatureTest.java

@Test
public void testSearch() throws Exception {
    final String name = new AlphanumericRandomStringService().random();
    final Path workdir = new DefaultHomeFinderService(session).find();
    final Path file = new Path(workdir, name, EnumSet.of(Path.Type.file));
    new DropboxTouchFeature(session).touch(file, new TransferStatus());
    final DropboxSearchFeature feature = new DropboxSearchFeature(session);
    assertTrue(/* w  ww  .j a v  a  2s.c  o m*/
            feature.search(workdir, new SearchFilter(name), new DisabledListProgressListener()).contains(file));
    // Supports prefix matching only
    assertFalse(feature.search(workdir, new SearchFilter(StringUtils.substring(name, 2)),
            new DisabledListProgressListener()).contains(file));
    assertTrue(feature.search(workdir, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)),
            new DisabledListProgressListener()).contains(file));
    try {
        assertFalse(feature.search(
                new Path(workdir, new AlphanumericRandomStringService().random(),
                        EnumSet.of(Path.Type.directory)),
                new SearchFilter(name), new DisabledListProgressListener()).contains(file));
        fail();
    } catch (NotfoundException e) {
        //
    }
    final Path subdir = new Path(workdir, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.directory));
    new DropboxDirectoryFeature(session).mkdir(subdir, null, new TransferStatus());
    assertFalse(
            feature.search(subdir, new SearchFilter(name), new DisabledListProgressListener()).contains(file));
    final Path filesubdir = new DropboxTouchFeature(session).touch(
            new Path(subdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)),
            new TransferStatus());
    {
        final AttributedList<Path> result = feature.search(workdir, new SearchFilter(filesubdir.getName()),
                new DisabledListProgressListener());
        assertTrue(result.contains(filesubdir));
        assertEquals(subdir, result.find(new SimplePathPredicate(filesubdir)).getParent());
    }
    new DropboxDeleteFeature(session).delete(Arrays.asList(file, filesubdir, subdir),
            new DisabledLoginCallback(), new Delete.DisabledCallback());
}

From source file:ch.cyberduck.core.onedrive.OneDriveSearchFeatureTest.java

@Test
@Ignore// w ww . java 2s . c o m
public void testSearch() throws Exception {
    final String name = new AlphanumericRandomStringService().random();
    final Path drive = new OneDriveHomeFinderFeature(session).find();
    final Path directory = new OneDriveDirectoryFeature(session).mkdir(
            new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)),
            null, new TransferStatus());
    final Path file = new OneDriveTouchFeature(session)
            .touch(new Path(directory, name, EnumSet.of(Path.Type.file)), new TransferStatus());
    final OneDriveSearchFeature feature = new OneDriveSearchFeature(session);
    assertTrue(
            feature.search(drive, new SearchFilter(name), new DisabledListProgressListener()).contains(file));
    assertFalse(feature
            .search(drive, new SearchFilter(StringUtils.substring(name, 2)), new DisabledListProgressListener())
            .contains(file));
    assertTrue(feature.search(drive, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)),
            new DisabledListProgressListener()).contains(file));
    assertTrue(feature.search(directory, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)),
            new DisabledListProgressListener()).contains(file));
    try {
        assertFalse(feature.search(
                new Path(drive, new AlphanumericRandomStringService().random(),
                        EnumSet.of(Path.Type.directory)),
                new SearchFilter(name), new DisabledListProgressListener()).contains(file));
        fail();
    } catch (NotfoundException e) {
        //
    }
    final Path subdir = new OneDriveDirectoryFeature(session).mkdir(new Path(directory,
            new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), null,
            new TransferStatus());
    assertNull(feature.search(subdir, new SearchFilter(name), new DisabledListProgressListener())
            .find(new SimplePathPredicate(file)));
    final Path filesubdir = new OneDriveTouchFeature(session).touch(
            new Path(subdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)),
            new TransferStatus());
    {
        final AttributedList<Path> result = feature.search(directory, new SearchFilter(filesubdir.getName()),
                new DisabledListProgressListener());
        assertNotNull(result.find(new SimplePathPredicate(filesubdir)));
        assertEquals(subdir, result.find(new SimplePathPredicate(filesubdir)).getParent());
    }
    new OneDriveDeleteFeature(session).delete(Arrays.asList(file, filesubdir, subdir),
            new DisabledLoginCallback(), new Delete.DisabledCallback());
}

From source file:com.thinkbiganalytics.alerts.rest.AlertsModel.java

public String alertTypeDisplayName(String type) {
    String part = type;/*  ww  w . jav a 2s. co  m*/
    if (part.startsWith(AlertConstants.KYLO_ALERT_TYPE_PREFIX + "/alert")) {
        part = StringUtils.substringAfter(part, AlertConstants.KYLO_ALERT_TYPE_PREFIX + "/alert");
    } else if (part.startsWith(AlertConstants.KYLO_ALERT_TYPE_PREFIX)) {
        part = StringUtils.substringAfter(part, AlertConstants.KYLO_ALERT_TYPE_PREFIX);
    } else {
        int idx = StringUtils.lastOrdinalIndexOf(part, "/", 2);
        part = StringUtils.substring(part, idx);
    }
    String[] parts = part.split("/");
    return Arrays.asList(parts).stream().map(s -> StringUtils.capitalize(s)).collect(Collectors.joining(" "));
}

From source file:de.jcup.egradle.codeassist.dsl.MethodUtils.java

/**
 * Create a method signature string//from   w  w w.  j  a  v  a 2  s .c o  m
 * 
 * @param method
 *            - if <code>null</code> - result will be "null"
 * @param longTypeNames
 * @param withParameterNames
 *            - when true signature contains parameter names
 * @return string, never <code>null</code>
 */
public static String createSignature(Method method, boolean longTypeNames, boolean withParameterNames) {
    if (method == null) {
        return "null";
    }
    StringBuilder signatureSb = new StringBuilder();
    signatureSb.append(method.getName());
    signatureSb.append('(');

    List<Parameter> params = method.getParameters();
    int pos = 0;
    for (Parameter param : params) {
        String pname = param.getName();
        if (StringUtils.isBlank(pname)) {
            pname = "arg" + pos;
        }
        if (pos > 0) {
            signatureSb.append(", ");
        }
        String typeAsString = null;
        Type pType = param.getType();
        if (pType != null) {
            if (longTypeNames) {
                typeAsString = pType.getName();
            } else {
                typeAsString = pType.getShortName();
            }
        } else {
            typeAsString = param.getTypeAsString();
        }
        if (typeAsString == null) {
            typeAsString = "<UNKNOWN>";
        }
        if (typeAsString != null) {
            if (!longTypeNames) {
                int index = typeAsString.lastIndexOf('.');
                if (index != -1) {
                    typeAsString = StringUtils.substring(typeAsString, index + 1);
                }
            }
            signatureSb.append(typeAsString);
            if (withParameterNames) {
                signatureSb.append(" ");
            }
        }
        if (withParameterNames) {
            signatureSb.append(pname);
        }
        pos++;
    }
    signatureSb.append(')');
    return signatureSb.toString();
}

From source file:com.vwf5.base.utils.DataUtil.java

/**
 * Upper first character//  w w w .  j  a v  a2s  .c  o  m
 *
 * @param input
 * @return
 */
public static String upperFirstChar(String input) {
    if (StringUtils.isBlank(input)) {
        return input;
    }
    return input.substring(0, 1).toUpperCase() + StringUtils.substring(input, 1);
}

From source file:de.jcup.egradle.sdk.builder.action.type.SaveTypesToSDKTargetFolder.java

String extractSubPathFromFile(File file, File parent) throws IOException {
    StringBuilder sb = new StringBuilder();
    File current = file;/* w  ww  . j  a v  a  2  s . co m*/
    boolean parentFound = false;

    while (current != null) {
        if (current.equals(parent)) {
            parentFound = true;
            break;
        }
        sb.insert(0, current.getName());
        sb.insert(0, '/');
        current = current.getParentFile();
    }
    if (!parentFound) {
        throw new IllegalArgumentException("Parent:" + parent + "\ndoes not contain\nFile:" + file);
    }
    String result = sb.toString();
    if (result.startsWith("/")) {
        result = StringUtils.substring(result, 1);
    }
    return result;
}