Example usage for java.lang String subSequence

List of usage examples for java.lang String subSequence

Introduction

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

Prototype

public CharSequence subSequence(int beginIndex, int endIndex) 

Source Link

Document

Returns a character sequence that is a subsequence of this sequence.

Usage

From source file:com.bloatit.framework.webprocessor.url.UrlParameter.java

private String makeStringPretty(final String theValue) {
    String tmp = theValue.replaceAll("[ ,\\.\\'\\\"\\&\\?\r\n%\\*\\!:\\^\\+#/]", "-");
    tmp = tmp.replaceAll("--+", "-");
    tmp = tmp.subSequence(0, Math.min(tmp.length(), 80)).toString();
    tmp = tmp.replaceAll("-+$", "");
    tmp = tmp.toLowerCase();//w w  w .j  ava  2 s.co  m
    tmp = AsciiUtils.convertNonAscii(tmp);
    return tmp;
}

From source file:org.jsconf.core.ConfigurationFactory.java

private List<String> getDefinition(String name) {
    List<String> ressourcesName = new ArrayList<>();
    if (this.withDefinition) {
        int idx = name.lastIndexOf(".");
        if (idx > 0) {
            ressourcesName.add(name.subSequence(0, idx) + ".def" + name.substring(idx));
        } else {//from www .  ja v a2  s.  c o  m
            ressourcesName.add(name + ".def");
        }
    }
    ressourcesName.add(name);
    return ressourcesName;
}

From source file:org.apache.hadoop.hdfs.server.namenode.TestDecommissioningStatus.java

private void checkDFSAdminDecommissionStatus(List<DatanodeDescriptor> expectedDecomm, DistributedFileSystem dfs,
        DFSAdmin admin) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    PrintStream oldOut = System.out;
    System.setOut(ps);/*from   w w  w.  j  a  v a2s. c  o m*/
    try {
        // Parse DFSAdmin just to check the count
        admin.report(new String[] { "-decommissioning" }, 0);
        String[] lines = baos.toString().split("\n");
        Integer num = null;
        int count = 0;
        for (String line : lines) {
            if (line.startsWith("Decommissioning datanodes")) {
                // Pull out the "(num)" and parse it into an int
                String temp = line.split(" ")[2];
                num = Integer.parseInt((String) temp.subSequence(1, temp.length() - 2));
            }
            if (line.contains("Decommission in progress")) {
                count++;
            }
        }
        assertTrue("No decommissioning output", num != null);
        assertEquals("Unexpected number of decomming DNs", expectedDecomm.size(), num.intValue());
        assertEquals("Unexpected number of decomming DNs", expectedDecomm.size(), count);
        // Check Java API for correct contents
        List<DatanodeInfo> decomming = new ArrayList<DatanodeInfo>(
                Arrays.asList(dfs.getDataNodeStats(DatanodeReportType.DECOMMISSIONING)));
        assertEquals("Unexpected number of decomming DNs", expectedDecomm.size(), decomming.size());
        for (DatanodeID id : expectedDecomm) {
            assertTrue("Did not find expected decomming DN " + id, decomming.contains(id));
        }
    } finally {
        System.setOut(oldOut);
    }
}

From source file:org.kalypso.zml.ui.table.nat.tooltip.ZmlTableTooltip.java

private Object buildInfoText(final String label, final String value) {
    String tabs;/*from   w  w w  . j av  a  2  s.c  om*/
    if (label.length() > 8)
        tabs = "\t"; //$NON-NLS-1$
    else
        tabs = "\t\t"; //$NON-NLS-1$

    String v;
    if (value.length() > 60) {
        v = value.subSequence(0, 60) + "\n\t\t" + value.substring(60); //$NON-NLS-1$
    } else
        v = value;

    return String.format("%s:%s%s\n", label, tabs, v); //$NON-NLS-1$
}

From source file:org.dataconservancy.dcs.util.FileContentDigestPathAlgorithm.java

private String appendDirectories(String fileName) {

    if (fileName == null)
        return null;
    StringBuilder path = new StringBuilder();
    int length = 2 * directoryWidth;
    for (int depth = 0; depth < directoryDepth; depth++) {
        int start = 2 * directoryWidth * depth;
        path.append(fileName.subSequence(start, start + length));
        if (length > 0) {
            path.append(File.separator);
        }/*from  w  ww  . ja va2  s . co  m*/
    }

    path.append(fileName);
    return path.toString();
}

From source file:org.nuxeo.ecm.platform.picture.web.PictureBookManagerBean.java

protected String formatFileName(String filename, String count) {
    StringBuilder sb = new StringBuilder();
    CharSequence name = filename.subSequence(0, filename.lastIndexOf(""));
    CharSequence extension = filename.subSequence(filename.lastIndexOf(""), filename.length());
    sb.append(name).append(count).append(extension);
    return sb.toString();
}

From source file:io.engine.EngineIO.java

void transportPacket(IOTransport transport, String data) {
    LOGGER.info("< " + data);
    try {/*w w w . j ava2 s  .co  m*/
        char type = data.charAt(0);
        CharSequence message = data.subSequence(1, data.length());
        switch (type) {
        case TYPE_OPEN:
            receivedOpen(transport, message);
            break;
        case TYPE_CLOSE:
            receivedClose(transport);
            break;
        case TYPE_PING:
            send(transport, TYPE_PONG, message.toString());
            break;
        case TYPE_PONG:
            receivedPong(transport, message);
            break;
        case TYPE_MESSAGE:
            onMessage(message.toString());
            break;
        // We're not supposed to handle them
        case TYPE_UPGRADE:
        default:
            LOGGER.warning("Received package type " + type + ". We can't handle this.");
        }
        resetPingTimeout();
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Garbaged packet. Ignoring...", e);
    }
}

From source file:edu.cornell.med.icb.goby.util.SimulateBisulfiteReads.java

private MutableString context(int i, CharSequence segmentBases) {
    MutableString context = new MutableString();
    int contextLength = 10;
    int start = Math.max(0, i - contextLength);
    int end = Math.min(segmentBases.length(), i + contextLength);

    final String bases = segmentBases.toString();
    context.append(bases.subSequence(start, i));
    context.append('>');
    context.append(bases.charAt(i));/*w ww .j a  v a  2 s. c om*/
    context.append('<');
    final int a = i + 1;
    if (a < end) {
        final CharSequence sequence = bases.subSequence(a, end);
        context.append(sequence);
    }
    return context;
}

From source file:de.fahrgemeinschaft.FahrgemeinschaftConnector.java

@Override
public String publish(Ride offer) throws Exception {
    HttpURLConnection post;//  w w w  .  jav a2s.  co m
    if (offer.getRef() == null) {
        post = (HttpURLConnection) new URL(endpoint + TRIP).openConnection();
        post.setRequestMethod(POST);
    } else {
        post = (HttpURLConnection) new URL(
                new StringBuffer().append(endpoint).append(TRIP).append(ID).append(offer.getRef()).toString())
                        .openConnection();
        post.setRequestMethod(PUT);
    }
    post.setRequestProperty("User-Agent", USER_AGENT);
    post.setRequestProperty(APIKEY, Secret.APIKEY);
    if (getAuth() != null)
        post.setRequestProperty(AUTHKEY, getAuth());
    post.setDoOutput(true);
    JSONObject json = new JSONObject();
    //        json.put("Smoker", "no");
    json.put(TRIPTYPE, OFFER);
    json.put(TRIP_ID, offer.getRef());
    json.put(ID_USER, get(USER));
    if (offer.getMode() != null && offer.getMode().equals(Mode.TRAIN)) {
        json.put(PLATE, BAHN);
    } else {
        json.put(PLATE, offer.get(PLATE));
    }
    if (offer.isActive()) {
        json.put(RELEVANCE, 10);
    } else {
        json.put(RELEVANCE, 0);
    }
    json.put(PLACES, offer.getSeats());
    json.put(PRICE, offer.getPrice() / 100);
    json.put(CONTACTMAIL, offer.get(EMAIL));
    json.put(CONTACTMOBILE, offer.get(MOBILE));
    json.put(CONTACTLANDLINE, offer.get(LANDLINE));
    String dep = fulldf.format(offer.getDep());
    json.put(STARTDATE, dep.subSequence(0, 8));
    json.put(STARTTIME, dep.subSequence(8, 12));
    json.put(DESCRIPTION, offer.get(COMMENT));
    if (!offer.getDetails().isNull(PRIVACY))
        json.put(PRIVACY, offer.getDetails().getJSONObject(PRIVACY));
    if (!offer.getDetails().isNull(REOCCUR))
        json.put(REOCCUR, offer.getDetails().getJSONObject(REOCCUR));
    ArrayList<JSONObject> routings = new ArrayList<JSONObject>();
    List<Place> stops = offer.getPlaces();
    int max = stops.size() - 1;
    for (int dest = max; dest >= 0; dest--) {
        for (int orig = 0; orig < dest; orig++) {
            int idx = (orig == 0 ? (dest == max ? 0 : dest) : -dest);
            JSONObject route = new JSONObject();
            route.put(ROUTING_INDEX, idx);
            route.put(ORIGIN, place(stops.get(orig)));
            route.put(DESTINATION, place(stops.get(dest)));
            routings.add(route);
        }
    }
    json.put(ROUTINGS, new JSONArray(routings));
    OutputStreamWriter out = new OutputStreamWriter(post.getOutputStream());
    out.write(json.toString());
    out.flush();
    out.close();
    JSONObject response = loadJson(post);
    if (!response.isNull(TRIP_ID_WITH_SMALL_t)) {
        offer.ref(response.getString(TRIP_ID_WITH_SMALL_t));
    }
    return offer.getRef();
}

From source file:org.alfresco.po.share.FactorySharePage.java

/**
 * Extracts the String value from the last occurrence of slash in the url.
 *
 * @param url String url.//from ww  w.jav a 2 s  . c o  m
 * @return String page title
 */
protected static String resolvePage(String url) {
    if (url == null || url.isEmpty()) {
        throw new UnsupportedOperationException("Empty url is not allowed");
    }

    if (url.endsWith("dashboard")) {
        if (url.endsWith("customise-site-dashboard")) {
            return "customise-site-dashboard";
        }
        if (url.endsWith("customise-user-dashboard")) {
            return "customise-user-dashboard";
        }
        if (url.contains("/page/site/")) {
            return "site-dashboard";
        }
        return "dashboard";
    }

    if (url.endsWith("create")) {
        return "users-create";
    }

    if (url.contains(NODE_REF_IDENTIFIER)) {
        int index = url.indexOf(NODE_REF_IDENTIFIER);
        url = url.subSequence(0, index).toString();
    }

    if (url.contains(NODE_REFRESH_META_DATA_IDENTIFIER)) {
        int index = url.indexOf(NODE_REFRESH_META_DATA_IDENTIFIER);
        url = url.subSequence(0, index).toString();
    }

    if (url.contains("/repository")) {
        if (url.contains("#filter=path%7C%2FData%2520Dictionary%2FModels")) {
            return "models";
        }
        return "repository";
    }
    // The admin console has an unusual url which we handle here
    // 'application' by itself would be inappropriate
    if (url.contains("/admin-console/application")) {
        return "admin-console";
    }

    // Get the last element of url
    StringTokenizer st = new StringTokenizer(url, "/");
    String val = "";
    while (st.hasMoreTokens()) {
        if (st.hasMoreTokens()) {
            val = st.nextToken();
        }
    }

    // Check if its advance search folder or content
    if (val.contains("advsearch")) {
        if (val.contains("%3afolder")) {
            return "advfolder-search";
        } else if (val.contains("prop_crm")) {
            return "advCRM-search";
        } else if (val.contains("Acontent")) {
            return "advcontent-search";
        }
        return "advsearch";
    }
    if (val.startsWith("search?")) {
        if (url.contains("/site/")) {
            return "siteResultsPage";
        } else if (val.endsWith("&a=true&r=true")) {
            return "repositoryResultsPage";
        } else {
            return "allSitesResultsPage";
        }
    }

    // Remove any clutter.
    if (val.contains("?") || val.contains("#")) {
        val = extractName(val);
    }
    if (val.contains("edit") && url.contains("docs.google.com")) {
        val = "googledocsEditor";
    }

    if (url.contains(TPG_HASH)) {
        return "ManageTypesAndAspects";
    } else if (url.contains(PROPERTIES_HASH)) {
        return "ManageProperties";
    } else if (url.contains(FORM_EDITOR_HASH)) {
        return "FormEditor";
    } else if (url.contains(CMM_URL)) {
        return "ModelManager";
    }

    return val;
}