Example usage for java.lang StringBuilder deleteCharAt

List of usage examples for java.lang StringBuilder deleteCharAt

Introduction

In this page you can find the example usage for java.lang StringBuilder deleteCharAt.

Prototype

@Override
public StringBuilder deleteCharAt(int index) 

Source Link

Usage

From source file:com.github.dryangkun.hbase.tidx.hive.HBaseSerDeHelper.java

/**
 * Trims by removing the trailing "," if any
 * //from w w w .java2 s  .com
 * @param sb StringBuilder to trim
 * @return StringBuilder trimmed StringBuilder
 * */
private static StringBuilder trim(StringBuilder sb) {
    if (sb.charAt(sb.length() - 1) == StringUtils.COMMA) {
        return sb.deleteCharAt(sb.length() - 1);
    }

    return sb;
}

From source file:info.mtgdb.api.Db.java

/**
 * //from  w w w .j av a  2  s  .c  o m
 * @param filters HashMap<String, String> containing a mapping of keys to values.  For example colors and black.
 * @return ArrayList
 */
public static ArrayList<Card> filterCards(HashMap<String, String> filters) {
    StringBuilder sb = new StringBuilder();
    sb.append(API_URL + "/cards/?");
    for (String key : filters.keySet()) {
        String value = filters.get(key);
        sb.append(key + "=" + value + "&");
    }
    if (filters.size() > 0)
        sb.deleteCharAt(sb.length() - 1);
    return getCardsFromUrl(sb.toString());
}

From source file:org.basdroid.common.NetworkUtils.java

public static String getMacAddressFromNetworkInterface(final Context context) {

    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    int ipAddress = wifiInfo.getIpAddress();

    // Convert little-endian to big-endianif needed
    if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) {
        ipAddress = Integer.reverseBytes(ipAddress);
    }//from  w w w .  j  av  a 2  s. c  om

    byte[] bytes = BigInteger.valueOf(ipAddress).toByteArray();

    String result;
    try {
        InetAddress addr = InetAddress.getByAddress(bytes);
        NetworkInterface netInterface = NetworkInterface.getByInetAddress(addr);
        Log.d(TAG, "Wifi netInterface.getName() = " + netInterface.getName());

        byte[] mac = netInterface.getHardwareAddress();
        if (mac == null || mac.length == 0)
            return "";
        StringBuilder buf = new StringBuilder();
        for (int idx = 0; idx < mac.length; idx++) {
            buf.append(String.format("%02X:", mac[idx]));
        }
        if (buf.length() > 0)
            buf.deleteCharAt(buf.length() - 1);
        return buf.toString();
    } catch (UnknownHostException ex) {
        Log.e(TAG, "getMacAddressFromNetworkInterface() Unknown host.", ex);
        result = null;
    } catch (SocketException ex) {
        Log.e(TAG, "getMacAddressFromNetworkInterface() Socket exception.", ex);
        result = null;
    } catch (Exception ex) {
        Log.e(TAG, "getMacAddressFromNetworkInterface() Exception.", ex);
        result = null;
    }

    return result;
}

From source file:org.basdroid.common.NetworkUtils.java

/**
 * Returns MAC address of the given interface name.
 * @param interfaceName eth0, wlan0 or NULL=use first interface
 * @return  mac address or empty string/*from w  ww.  j  a  va2  s. c  o  m*/
 */
public static String getMACAddress(String interfaceName) {
    try {
        List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface intf : interfaces) {
            if (interfaceName != null) {
                Log.d(TAG, "intf.getName() = " + intf.getName());
                if (!intf.getName().equalsIgnoreCase(interfaceName))
                    continue;
            }
            byte[] mac = intf.getHardwareAddress();
            if (mac == null)
                return "";
            StringBuilder buf = new StringBuilder();
            for (int idx = 0; idx < mac.length; idx++) {
                buf.append(String.format("%02X:", mac[idx]));
            }
            if (buf.length() > 0)
                buf.deleteCharAt(buf.length() - 1);
            return buf.toString();
        }
    } catch (Exception ex) {
    } // for now eat exceptions
    return "";
}

From source file:com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck.java

/**
 * Trims any trailing whitespace or the end of Javadoc comment string.
 * @param builder the StringBuilder to trim.
 */// w w  w  . ja va 2s . c  om
private static void trimTail(StringBuilder builder) {
    int index = builder.length() - 1;
    while (true) {
        if (Character.isWhitespace(builder.charAt(index))) {
            builder.deleteCharAt(index);
        } else if (builder.charAt(index) == '/' && builder.charAt(index - 1) == '*') {
            builder.deleteCharAt(index);
            builder.deleteCharAt(index - 1);
            index--;
            while (builder.charAt(index - 1) == '*') {
                builder.deleteCharAt(index - 1);
                index--;
            }
        } else {
            break;
        }
        index--;
    }
}

From source file:net.objectlab.kit.util.StringUtil.java

public static String removeTrailingChar(final String original, final char charToRemove) {
    final StringBuilder builder = new StringBuilder(original);
    while (builder.length() > 0 && builder.charAt(builder.length() - 1) == charToRemove) {
        builder.deleteCharAt(builder.length() - 1);
    }//from w w  w .j a va2  s .  com
    return builder.toString();
}

From source file:DatasetCreation.DatasetCSVBuilder.java

/**
 * Return CSV string which represent the header row of the dataset
 *
 * @param selectedFeaturesNum the top selected features number to build the
 * dataset with//from w w w .  j a v a2  s . co m
 * @param addElementIDColumn add prefix column identifying the record
 * @param addClassificationColumn add suffix column identifying the class of
 * the record
 * @return CSV string which represent the header row of the dataset
 */
public static StringBuilder GetDatasetHeaderCSV(int selectedFeaturesNum, boolean addElementIDColumn,
        boolean addClassificationColumn) {
    StringBuilder datasetHeaderCSV = new StringBuilder();
    if (addElementIDColumn) {
        datasetHeaderCSV.append("Element,");
    }
    for (int i = 1; i <= selectedFeaturesNum; i++) {
        datasetHeaderCSV.append(String.format("f%s,", i));
    }
    if (addClassificationColumn) {
        datasetHeaderCSV.append("Class");
    } else {
        //To remove the last feature ","
        datasetHeaderCSV.deleteCharAt(datasetHeaderCSV.length() - 1);
    }
    return datasetHeaderCSV;
}

From source file:com.krawler.portal.tools.SourceFormatter.java

private static String _getTaglibRegex(String quoteType) {
    StringBuilder sb = new StringBuilder();

    sb.append("<(");

    for (int i = 0; i < _TAG_LIBRARIES.length; i++) {
        sb.append(_TAG_LIBRARIES[i]);// ww w .  java 2s. c  om
        sb.append(StringPool.PIPE);
    }

    sb.deleteCharAt(sb.length() - 1);
    sb.append("):([^>]|%>)*");
    sb.append(quoteType);
    sb.append("<%=[^>]*");
    sb.append(quoteType);
    sb.append("[^>]*%>");
    sb.append(quoteType);
    sb.append("([^>]|%>)*>");

    return sb.toString();
}

From source file:edu.ku.brc.ui.GraphicsUtils.java

/**
 * @param fm//from  w w  w  .  jav  a  2 s. com
 * @param text
 * @param availableWidth
 * @return
 */
public static String clipString(FontMetrics fm, String text, int availableWidth) {
    // first see if the string needs clipping at all

    if (text == null) {
        return "";
    }

    if (fm.stringWidth(text) < availableWidth) {
        return text;
    }

    String dots = "...";

    StringBuilder sb = new StringBuilder(text + dots);
    while (sb.length() - 4 > 0 && fm.stringWidth(sb.toString()) > availableWidth) {
        sb.deleteCharAt(sb.length() - 4);
    }
    return sb.toString();
}

From source file:com.facebook.presto.accumulo.index.Indexer.java

/**
 * Gets a collection of iterator settings that should be added to the metric table for the given Accumulo table. Don't forget! Please!
 *
 * @param table Table for retrieving metrics iterators, see AccumuloClient#getTable
 * @return Collection of iterator settings
 *//*  ww w.j a  v  a 2s  .  c  o  m*/
public static Collection<IteratorSetting> getMetricIterators(AccumuloTable table) {
    String cardQualifier = new String(CARDINALITY_CQ);
    String rowsFamily = new String(METRICS_TABLE_ROWS_CF.array());

    // Build a string for all columns where the summing combiner should be applied,
    // i.e. all indexed columns
    StringBuilder cardBuilder = new StringBuilder(rowsFamily + ":" + cardQualifier + ",");
    for (String s : getLocalityGroups(table).keySet()) {
        cardBuilder.append(s).append(":").append(cardQualifier).append(',');
    }
    cardBuilder.deleteCharAt(cardBuilder.length() - 1);

    // Configuration rows for the Min/Max combiners
    String firstRowColumn = rowsFamily + ":" + new String(METRICS_TABLE_FIRST_ROW_CQ.array());
    String lastRowColumn = rowsFamily + ":" + new String(METRICS_TABLE_LAST_ROW_CQ.array());

    // Summing combiner for cardinality columns
    IteratorSetting s1 = new IteratorSetting(1, SummingCombiner.class,
            ImmutableMap.of("columns", cardBuilder.toString(), "type", "STRING"));

    // Min/Max combiner for the first/last rows of the table
    IteratorSetting s2 = new IteratorSetting(2, MinByteArrayCombiner.class,
            ImmutableMap.of("columns", firstRowColumn));
    IteratorSetting s3 = new IteratorSetting(3, MaxByteArrayCombiner.class,
            ImmutableMap.of("columns", lastRowColumn));

    return ImmutableList.of(s1, s2, s3);
}