Example usage for java.lang String endsWith

List of usage examples for java.lang String endsWith

Introduction

In this page you can find the example usage for java.lang String endsWith.

Prototype

public boolean endsWith(String suffix) 

Source Link

Document

Tests if this string ends with the specified suffix.

Usage

From source file:cat.calidos.morfeu.model.transform.injection.StringFormatModule.java

@Produces
@Named("EffectiveContent")
public static String produceEffectiveContent(@Named("DestinationContentURI") URI uri,
        @Named("TransformedContent") Producer<String> transformedContentProducer,
        @Named("Content") Producer<String> contentProducer) throws TransformException {

    String name = FilenameUtils.getName(uri.getPath());

    try {/* www  .  j  a  va  2 s  .c  o m*/
        if (name.endsWith("yaml")) {

            return transformedContentProducer.get().get();

        } else {

            return contentProducer.get().get(); // no transformation required

        }
    } catch (InterruptedException | ExecutionException e) {
        log.error("Could not get effective content for '{}' ({})", uri, e);
        throw new TransformException("Problem when getting effective content to save '" + uri + "'", e);
    }

}

From source file:com.npower.dl.DownloadFactory.java

/**
 * Extract Download operation from URL/*from   www  . j a v a2s .c om*/
 * @param uri
 * @return
 */
public static String parserOperation(String uri) {
    if (StringUtils.isEmpty(uri)) {
        return null;
    }
    String result = uri.trim();
    while (result.endsWith("/")) {
        result = result.substring(0, result.length() - 1);
    }
    result = result.substring(0, result.lastIndexOf('/'));

    result = result.substring(result.lastIndexOf('/') + 1, result.length());
    return result;
}

From source file:io.logspace.hq.core.solr.utils.SolrQueryHelper.java

public static void addSort(SolrQuery solrQuery, String sort, FieldDefinitions fieldDefinitions) {
    if (sort.endsWith(" asc") || sort.endsWith(" ASC")) {
        String apiFieldName = sort.substring(0, sort.length() - 4);
        String solrFieldName = fieldDefinitions.getSolrFieldName(apiFieldName);
        solrQuery.addSort(SortClause.asc(solrFieldName));
        return;//  w  ww .j ava 2s.  co m
    }

    if (sort.endsWith(" desc") || sort.endsWith(" DESC")) {
        String apiFieldName = sort.substring(0, sort.length() - 5);
        String solrFieldName = fieldDefinitions.getSolrFieldName(apiFieldName);
        solrQuery.addSort(SortClause.desc(solrFieldName));
        return;
    }

    throw new IllegalArgumentException("Invalid sort argument. Expected 'fieldname asc' or 'fieldname desc'.");
}

From source file:Main.java

static final Float convertUnits(String name, XmlPullParser atts, float dpi, float width, float height) {
    String value = getStringAttr(name, atts);
    if (value == null) {
        return null;
    } else if (value.endsWith("px")) {
        return Float.parseFloat(value.substring(0, value.length() - 2));
    } else if (value.endsWith("pt")) {
        return Float.valueOf(value.substring(0, value.length() - 2)) * dpi / 72;
    } else if (value.endsWith("pc")) {
        return Float.valueOf(value.substring(0, value.length() - 2)) * dpi / 6;
    } else if (value.endsWith("cm")) {
        return Float.valueOf(value.substring(0, value.length() - 2)) * dpi / 2.54f;
    } else if (value.endsWith("mm")) {
        return Float.valueOf(value.substring(0, value.length() - 2)) * dpi / 254;
    } else if (value.endsWith("in")) {
        return Float.valueOf(value.substring(0, value.length() - 2)) * dpi;
    } else if (value.endsWith("%")) {
        Float result = Float.valueOf(value.substring(0, value.length() - 1));
        float mult;
        if (name.contains("x") || name.equals("width")) {
            mult = width / 100f;//w  w w  .ja  va 2s  .c  om
        } else if (name.contains("y") || name.equals("height")) {
            mult = height / 100f;
        } else {
            mult = (height + width) / 2f;
        }
        return result * mult;
    } else {
        return Float.valueOf(value);
    }
}

From source file:Main.java

/**
 * Constructs a file from a path and file name.
 * //from  ww w  . ja v  a  2  s  .co  m
 * @param curdir
 * @param file
 * @return
 */
public static File getFile(String curdir, String file) {
    String separator = "/";
    if (curdir.endsWith("/")) {
        separator = "";
    }
    File clickedFile = new File(curdir + separator + file);
    return clickedFile;
}

From source file:org.n52.web.common.RequestUtils.java

/**
 * Get the full request {@link URL} including the query parameter
 *
 * @return Request {@link URL} with query parameter
 * @throws IOException//from ww w.j  ava  2  s.com
 * @throws URISyntaxException
 */
public static String resolveFullRequestUrl() throws IOException, URISyntaxException {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest();

    URL url = new URL(request.getRequestURL().toString());

    String scheme = url.getProtocol();
    String userInfo = url.getUserInfo();
    String host = url.getHost();

    int port = url.getPort();

    String path = request.getRequestURI();
    if (path != null && path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
    }
    String query = request.getQueryString();

    URI uri = new URI(scheme, userInfo, host, port, path, query, null);
    return uri.toString();
}

From source file:com.mgmtp.perfload.core.common.util.PropertiesUtils.java

public static Map<String, String> getSubMap(final PropertiesMap properties, final String keyPrefix) {
    final String prefix = keyPrefix.endsWith(".") ? keyPrefix : keyPrefix + ".";
    Map<String, String> map = Maps.filterKeys(properties, new Predicate<String>() {
        @Override/*from w  ww . j  a  v a 2s. c om*/
        public boolean apply(final String input) {
            return input.startsWith(prefix);
        }
    });

    Map<String, String> result = newHashMapWithExpectedSize(map.size());
    for (Entry<String, String> entry : map.entrySet()) {
        result.put(substringAfter(entry.getKey(), prefix), entry.getValue());
    }
    return result;
}

From source file:Main.java

public static String parseRegionName(URI endpoint) {
    String host = endpoint.getHost();

    // If we don't recognize the domain, just return the default
    if (!host.endsWith(".amazonaws.com"))
        return "us-east-1";

    String serviceAndRegion = host.substring(0, host.indexOf(".amazonaws.com"));

    // S3 is different from other services, which supports virtual host and
    // use '-' as separator, the host may look like
    // 'bucketName.s3-us-west-2.amazonaws.com'
    if (serviceAndRegion.contains("s3-")) {
        return serviceAndRegion.substring(serviceAndRegion.lastIndexOf("s3-") + 3);
    }//from   w  w  w .  jav  a2  s .  c o  m

    char separator = '.';

    if (serviceAndRegion.indexOf(separator) == -1)
        return "us-east-1";

    String region = serviceAndRegion.substring(serviceAndRegion.indexOf(separator) + 1);
    if ("us-gov".equals(region)) {
        return "us-gov-west-1";
    }

    return region;
}

From source file:Main.java

/**
 * Joins many String path segments into one path
 * @param segments A vararg (or String array) of path segments
 * @return The passed-in segements normalized and joined by "/"
 *//*from  w  w  w  .  j a v a2s .c om*/
public static String joinSegments(String... segments) {
    if (segments.length <= 0) {
        return "";
    }

    String s1 = segments[0];
    for (int i = 1; i < segments.length; i++) {
        String s2 = segments[i];
        if (s1.endsWith("/")) {
            if (s2.startsWith("/")) {
                s1 = s1 + s2.substring(1);
            } else {
                s1 = s1 + s2;
            }
        } else {
            if (s2.startsWith("/")) {
                s1 = s1 + s2;
            } else {
                s1 = s1 + "/" + s2;
            }
        }
    }
    return s1;
}

From source file:Main.java

public static String getResourcePath(String path, String extension) {
    if (extension == null) {
        return path;
    }//w ww  .j  av  a 2  s .  c  o  m
    extension = "." + extension;
    if (path.endsWith(extension)) {
        return path;
    }
    return path.replace('.', '/') + extension;
}