Example usage for java.lang StringBuffer deleteCharAt

List of usage examples for java.lang StringBuffer deleteCharAt

Introduction

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

Prototype

@Override
public synchronized StringBuffer deleteCharAt(int index) 

Source Link

Usage

From source file:org.chiba.xml.xforms.xpath.ExtensionFunctionsHelper.java

/**
 * Returns a date parsed from a date/dateTime string formatted accorings to
 * ISO 8601 rules.//from   w w w.  j  av a2 s  . com
 *
 * @param date the formatted date/dateTime string.
 * @return the parsed date.
 * @throws ParseException if the date/dateTime string could not be parsed.
 */
public static Date parseISODate(String date) throws ParseException {
    String pattern;
    StringBuffer buffer = new StringBuffer(date);

    switch (buffer.length()) {
    case 4:
        // Year: yyyy (eg 1997)
        pattern = "yyyy";
        break;
    case 7:
        // Year and month: yyyy-MM (eg 1997-07)
        pattern = "yyyy-MM";
        break;
    case 10:
        // Complete date: yyyy-MM-dd (eg 1997-07-16)
        pattern = "yyyy-MM-dd";
        break;
    default:
        // Complete date plus hours and minutes: yyyy-MM-ddTHH:mmTZD (eg 1997-07-16T19:20+01:00)
        // Complete date plus hours, minutes and seconds: yyyy-MM-ddTHH:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
        // Complete date plus hours, minutes, seconds and a decimal fraction of a second: yyyy-MM-ddTHH:mm:ss.STZD (eg 1997-07-16T19:20:30.45+01:00)
        pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";

        if (buffer.length() == 16) {
            // add seconds
            buffer.append(":00");
        }
        if (buffer.length() > 16 && buffer.charAt(16) != ':') {
            // insert seconds
            buffer.insert(16, ":00");
        }
        if (buffer.length() == 19) {
            // add milliseconds
            buffer.append(".000");
        }
        if (buffer.length() > 19 && buffer.charAt(19) != '.') {
            // insert milliseconds
            buffer.insert(19, ".000");
        }
        if (buffer.length() == 23) {
            // append timzeone
            buffer.append("+0000");
        }
        if (buffer.length() == 24 && buffer.charAt(23) == 'Z') {
            // replace 'Z' with '+0000'
            buffer.replace(23, 24, "+0000");
        }
        if (buffer.length() == 29 && buffer.charAt(26) == ':') {
            // delete '.' from 'HH:mm'
            buffer.deleteCharAt(26);
        }
    }

    // always set time zone on formatter
    SimpleDateFormat format = new SimpleDateFormat(pattern);
    final String dateFromBuffer = buffer.toString();
    if (dateFromBuffer.length() > 10) {
        format.setTimeZone(TimeZone.getTimeZone("GMT" + dateFromBuffer.substring(23)));
    }
    if (!format.format(format.parse(dateFromBuffer)).equals(dateFromBuffer)) {
        throw new ParseException("Not a valid ISO date", 0);
    }
    format.setTimeZone(TimeZone.getTimeZone("UTC"));

    return format.parse(buffer.toString());
}

From source file:it.eng.spagobi.jpivotaddins.crossnavigation.SpagoBICrossNavigationConfig.java

private String getCrossNavigationUrl(Target target, Cell cell, MondrianModel model) {
    logger.debug("IN");
    StringBuffer buffer = new StringBuffer("parent.execCrossNavigation(window.name, '"
            + StringEscapeUtils.escapeJavaScript(target.documentLabel) + "', '");
    String query = model.getCurrentMdx();
    Connection monConnection = model.getConnection();
    Query monQuery = monConnection.parseQuery(query);
    Cube cube = monQuery.getCube();/*from   w  w  w.  ja va  2  s  .  c o m*/

    List<TargetParameter> parameters = target.parameters;
    if (!parameters.isEmpty()) {
        for (int i = 0; i < parameters.size(); i++) {
            TargetParameter aParameter = parameters.get(i);
            String parameterName = aParameter.name;
            String parameterValue = getParameterValue(aParameter, cube, cell);
            if (parameterValue != null) {
                buffer.append(StringEscapeUtils.escapeJavaScript(parameterName + "=" + parameterValue + "&"));
            }
        }
    }

    if (buffer.charAt(buffer.length() - 1) == '&') {
        buffer.deleteCharAt(buffer.length() - 1);
    }
    if (target.customizedView != null) {
        buffer.append("', '" + StringEscapeUtils.escapeJavaScript(target.customizedView) + "'");
    } else {
        buffer.append("', ''");
    }

    if (target.titleCross != null && target.targetCross != null && target.targetCross.equalsIgnoreCase("tab")) {
        buffer.append(",'" + target.titleCross + "','tab'");
    } else if (target.titleCross != null) {
        buffer.append(",'" + target.titleCross + "'");
    }

    buffer.append(");");
    String toReturn = buffer.toString();
    logger.debug("OUT: returning [" + toReturn + "]");
    return toReturn;
}

From source file:com.hihsoft.baseclass.web.controller.javahihBaseController.java

/**
 * ?//from  ww  w.  ja  va 2 s.  c  o m
 * 
 * @param request
 * @param response
 * @throws ControllerException
 * @author xiaoB
 * @since 2011-6-30
 * */
@RequestMapping(params = "method=getRoleTypeLower")
public String getRoleTypeLower(HttpServletRequest request, HttpServletResponse response) {
    TsysOrg org = (TsysOrg) request.getSession().getAttribute(Consts.USER_DEFAULT_ORG);
    String orgType = org.getOrgClass();
    int orgtype = Integer.parseInt(orgType);
    List<TsysParameter> roleType = ParamUtil.getInstance().getByType("roleType");
    StringBuffer buffer = new StringBuffer();
    for (int i = orgtype; i <= roleType.size(); i++) {
        buffer.append("'" + i + "'");
        buffer.append(",");
    }
    if (buffer.length() > 0) {
        buffer.deleteCharAt(buffer.length() - 1);
    }
    return buffer.toString();
}

From source file:gov.guilin.service.impl.OrderServiceImpl.java

@Transactional(readOnly = true)
public Order build(Cart cart, Receiver receiver, PaymentMethod paymentMethod, ShippingMethod shippingMethod,
        CouponCode couponCode, boolean isInvoice, String invoiceTitle, boolean useBalance, String memo) {
    Assert.notNull(cart);//from w ww  .jav  a  2 s . c o m
    Assert.notNull(cart.getMember());
    Assert.notEmpty(cart.getCartItems());

    Order order = new Order();
    order.setShippingStatus(ShippingStatus.unshipped);
    order.setFee(new BigDecimal(0));
    order.setPromotionDiscount(cart.getDiscount());
    order.setCouponDiscount(new BigDecimal(0));
    order.setOffsetAmount(new BigDecimal(0));
    order.setPoint(cart.getEffectivePoint());
    order.setMemo(memo);
    order.setMember(cart.getMember());
    Supplier supplier = cart.getCartItems().iterator().next().getProduct().getSupplier();
    Assert.notNull(supplier);
    order.setSupplier(supplier);

    if (receiver != null) {
        order.setConsignee(receiver.getConsignee());
        order.setAreaName(receiver.getAreaName());
        order.setAddress(receiver.getAddress());
        order.setZipCode(receiver.getZipCode());
        order.setPhone(receiver.getPhone());
        order.setArea(receiver.getArea());
    }

    if (!cart.getPromotions().isEmpty()) {
        StringBuffer promotionName = new StringBuffer();
        for (Promotion promotion : cart.getPromotions()) {
            if (promotion != null && promotion.getName() != null) {
                promotionName.append(" " + promotion.getName());
            }
        }
        if (promotionName.length() > 0) {
            promotionName.deleteCharAt(0);
        }
        order.setPromotion(promotionName.toString());
    }

    order.setPaymentMethod(paymentMethod);

    if (shippingMethod != null && paymentMethod != null
            && paymentMethod.getShippingMethods().contains(shippingMethod)) {
        BigDecimal freight = shippingMethod.calculateFreight(cart.getWeight());
        for (Promotion promotion : cart.getPromotions()) {
            if (promotion.getIsFreeShipping()) {
                freight = new BigDecimal(0);
                break;
            }
        }
        order.setFreight(freight);
        order.setShippingMethod(shippingMethod);
    } else {
        order.setFreight(new BigDecimal(0));
    }

    if (couponCode != null && cart.isCouponAllowed()) {
        couponCodeDao.lock(couponCode, LockModeType.PESSIMISTIC_WRITE);
        if (!couponCode.getIsUsed() && couponCode.getCoupon() != null && cart.isValid(couponCode.getCoupon())) {
            BigDecimal couponDiscount = cart.getEffectivePrice().subtract(
                    couponCode.getCoupon().calculatePrice(cart.getQuantity(), cart.getEffectivePrice()));
            couponDiscount = couponDiscount.compareTo(new BigDecimal(0)) > 0 ? couponDiscount
                    : new BigDecimal(0);
            order.setCouponDiscount(couponDiscount);
            order.setCouponCode(couponCode);
        }
    }

    List<OrderItem> orderItems = order.getOrderItems();
    for (CartItem cartItem : cart.getCartItems()) {
        if (cartItem != null && cartItem.getProduct() != null) {
            Product product = cartItem.getProduct();
            OrderItem orderItem = new OrderItem();
            orderItem.setSn(product.getSn());
            orderItem.setName(product.getName());
            orderItem.setFullName(product.getFullName());
            orderItem.setPrice(cartItem.getPrice());
            orderItem.setWeight(product.getWeight());
            orderItem.setThumbnail(product.getThumbnail());
            orderItem.setIsGift(false);
            orderItem.setQuantity(cartItem.getQuantity());
            orderItem.setShippedQuantity(0);
            orderItem.setReturnQuantity(0);
            orderItem.setProduct(product);
            orderItem.setOrder(order);
            orderItems.add(orderItem);
        }
    }

    for (GiftItem giftItem : cart.getGiftItems()) {
        if (giftItem != null && giftItem.getGift() != null) {
            Product gift = giftItem.getGift();
            OrderItem orderItem = new OrderItem();
            orderItem.setSn(gift.getSn());
            orderItem.setName(gift.getName());
            orderItem.setFullName(gift.getFullName());
            orderItem.setPrice(new BigDecimal(0));
            orderItem.setWeight(gift.getWeight());
            orderItem.setThumbnail(gift.getThumbnail());
            orderItem.setIsGift(true);
            orderItem.setQuantity(giftItem.getQuantity());
            orderItem.setShippedQuantity(0);
            orderItem.setReturnQuantity(0);
            orderItem.setProduct(gift);
            orderItem.setOrder(order);
            orderItems.add(orderItem);
        }
    }

    Setting setting = SettingUtils.get();
    if (setting.getIsInvoiceEnabled() && isInvoice && StringUtils.isNotEmpty(invoiceTitle)) {
        order.setIsInvoice(true);
        order.setInvoiceTitle(invoiceTitle);
        order.setTax(order.calculateTax());
    } else {
        order.setIsInvoice(false);
        order.setTax(new BigDecimal(0));
    }

    if (useBalance) {
        Member member = cart.getMember();
        if (member.getBalance().compareTo(order.getAmount()) >= 0) {
            order.setAmountPaid(order.getAmount());
        } else {
            order.setAmountPaid(member.getBalance());
        }
    } else {
        order.setAmountPaid(new BigDecimal(0));
    }

    if (order.getAmountPayable().compareTo(new BigDecimal(0)) == 0) {
        order.setOrderStatus(OrderStatus.confirmed);
        order.setPaymentStatus(PaymentStatus.paid);
    } else if (order.getAmountPayable().compareTo(new BigDecimal(0)) > 0
            && order.getAmountPaid().compareTo(new BigDecimal(0)) > 0) {
        order.setOrderStatus(OrderStatus.confirmed);
        order.setPaymentStatus(PaymentStatus.partialPayment);
    } else {
        order.setOrderStatus(OrderStatus.unconfirmed);
        order.setPaymentStatus(PaymentStatus.unpaid);
    }

    if (paymentMethod != null && paymentMethod.getTimeout() != null
            && order.getPaymentStatus() == PaymentStatus.unpaid) {
        order.setExpire(DateUtils.addMinutes(new Date(), paymentMethod.getTimeout()));
    }

    return order;
}

From source file:com.allinfinance.common.select.LoadRecordMethod.java

/**
 * ?// ww w .  j a v  a  2 s.co m
 * 
 * @param src
 * @return 2011-6-22?01:43:30
 */
public String getMessage(String[] srcs) {

    StringBuffer sb = new StringBuffer("{\"data\":[{");
    for (String src : srcs) {
        src = src.substring(2).trim();
        sb.append(src);
        sb.delete(sb.length() - 2, sb.length());
        sb.append(",");
    }
    sb.deleteCharAt(sb.length() - 1);
    sb.append("}]}");
    return sb.toString();
}

From source file:dao.PersonalinfoDaoDb.java

public Userpage getMyProfile(String loginId, Hdlogin hdlogin) {

    Object[] params = { (Object) loginId };

    /** Jboss methods//from ww w  .  j  a  v a  2  s  .  c o  m
     * fqn - full qualified name
     * check if the userpage already set in the cache
     * If it exists, return the userpage from the cache.
     */

    String login = hdlogin.getValue(DbConstants.LOGIN);

    /**
     *  Get scalability datasource for usertab/mykeywords/hdprofile - not partitioned
     */
    String sourceName = scalabilityManager.getReadZeroScalability();
    ds = scalabilityManager.getSource(sourceName);
    if (ds == null) {
        throw new BaseDaoException("ds null, getMyProfile() " + sourceName);
    }

    List uResult = null;
    try {
        uResult = userpageQuery.execute(params);
    } catch (Exception e) {
        throw new BaseDaoException("exception occured in executing UserpageQuery() " + userpageQuery.getSql()
                + ", loginId = " + loginId, e);
    }

    if (uResult == null) {
        return null;
    }

    Userpage userpage = (Userpage) uResult.get(0);
    String dob = userpage.getValue(DbConstants.DOB);
    MyUtils myutils = new MyUtils();

    if (!RegexStrUtil.isNull(dob)) {
        userpage.setValue(DbConstants.BMONTH, myutils.getMonth(dob));
        userpage.setValue(DbConstants.BYEAR, myutils.getYear(dob));
        userpage.setValue(DbConstants.BDAY, myutils.getDay(dob));
        userpage.setValue(DbConstants.BMONTH_NUM, myutils.getMonthNum(dob));
    }
    if (hdlogin != null) {
        userpage.setValue(DbConstants.FIRST_NAME, hdlogin.getValue(DbConstants.FIRST_NAME));
        userpage.setValue(DbConstants.LAST_NAME, hdlogin.getValue(DbConstants.LAST_NAME));
        userpage.setValue(DbConstants.MIDDLE_NAME, hdlogin.getValue(DbConstants.MIDDLE_NAME));
        userpage.setValue(DbConstants.EMAIL, hdlogin.getValue(DbConstants.EMAIL));
        userpage.setValue(DbConstants.PASSWORD, hdlogin.getValue(DbConstants.PASSWORD));
    }

    // for profile preferences
    List prefResult = null;
    try {
        prefResult = profileQuery.execute(params);
    } catch (Exception e) {
        throw new BaseDaoException("exception occured in executing HdprofileQuery() " + profileQuery.getSql(),
                e);
    }

    if (prefResult != null) {
        if (prefResult.size() == 1) {
            Hdprofile hdprofile = (Hdprofile) prefResult.get(0);
            userpage.setValue(DbConstants.INFORM_PM, hdprofile.getValue(DbConstants.INFORM_PM));
            userpage.setValue(DbConstants.INFORM_BB, hdprofile.getValue(DbConstants.INFORM_BB));
            userpage.setValue(DbConstants.INFORM_FD, hdprofile.getValue(DbConstants.INFORM_FD));
        }
    }

    List result = null;
    try {
        result = myKeywordsQuery.execute(loginId);
    } catch (Exception e) {
        throw new BaseDaoException("exception occured in executing MykeywordsQuery() "
                + myKeywordsQuery.getSql() + ", loginId = " + loginId, e);
    }

    if (result != null) {
        int size = result.size();
        StringBuffer allMywords = new StringBuffer();
        if ((size > 0)) {
            for (int i = 0; i < size; i++) {
                Mykeywords mywords = (Mykeywords) result.get(i);
                allMywords = allMywords.append(mywords.getValue("keyword"));
                allMywords = allMywords.append(",");
            }
            allMywords = allMywords.deleteCharAt(allMywords.length() - 1);
            userpage.setValue(DbConstants.MYKEYWORDS, allMywords.toString());
        }
    }

    getYourkeywords(loginId, userpage);
    /*
       if (userpage != null) {
          treeCache.put(fqn, login, userpage);
       }
    */
    return userpage;
}

From source file:de.marcelkapfer.morseconverter.MainActivity.java

public void decode(View view) {
    EditText editText = (EditText) findViewById(R.id.edit_message);
    StringBuffer message = new StringBuffer(editText.getText());
    if (message.toString().endsWith(" ")) {
        message = message.deleteCharAt(message.length() - 1);
    }// w w  w.j  av a 2s. c o m
    // Variables
    StringBuffer input = new StringBuffer();
    input = input.replace(0, input.length(), message.toString().toUpperCase());
    StringBuffer output = new StringBuffer();
    if (input.toString().equals("")) {
        tfOutput = "Please enter at least one character";
        After(view);
    } else if (input.toString().equals("LETTERSPACE")) {
        tfOutput = "#";
        After(view);
    } else if (input.toString().equals("END OF WORK")) {
        tfOutput = "000101";
        After(view);
    } else if (input.toString().equals("ERROR")) {
        tfOutput = "00000000";
        After(view);
    } else if (input.toString().equals("STARTING SIGNAL")) {
        tfOutput = "10101";
        After(view);
    } else if (input.toString().equals("ENDING SIGNAL")) {
        tfOutput = "01010";
        After(view);
    } else if (input.toString().equals("UNDERSTOOD")) {
        tfOutput = "00010";
        After(view);
    } else if (input.toString().equals("WAIT")) {
        tfOutput = "01000";
        After(view);
    } else if (input.toString().equals("SOS")) {
        tfOutput = "000111000";
        After(view);
    } else if (input.toString().equals("LETTER SPACE")) {
        tfOutput = "#";
        After(view);
    } else if (input.toString().equals("WORD SPACE")) {
        tfOutput = "+";
        After(view);
    } else {
        for (int c = input.length(); c > 0; c--) {

            if (input.toString().startsWith(" ")) {
                if (output.toString().endsWith("#")) {
                    output.delete(output.length() - 1, output.length());
                }
                output.append("+");
                input.delete(0, 1);
            } else if (input.toString().startsWith("A")) {
                output.append("01#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("B")) {
                output.append("1000#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("C")) {
                output.append("1010#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("D")) {
                output.append("100#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("E")) {
                output.append("0#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("F")) {
                output.append("0010#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("G")) {
                output.append("110#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("H")) {
                output.append("0000#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("I")) {
                output.append("00#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("J")) {
                output.append("0111#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("K")) {
                output.append("101#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("L")) {
                output.append("0100#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("M")) {
                output.append("11#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("N")) {
                output.append("10#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("O")) {
                output.append("111#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("P")) {
                output.append("0110#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("Q")) {
                output.append("1101#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("R")) {
                output.append("010#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("S")) {
                output.append("000#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("T")) {
                output.append("1#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("U")) {
                output.append("001#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("V")) {
                output.append("0001#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("W")) {
                output.append("011#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("X")) {
                output.append("1001#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("Y")) {
                output.append("1011#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("Z")) {
                output.append("1100#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("0")) {
                output.append("11111#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("1")) {
                output.append("01111#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("2")) {
                output.append("00111#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("3")) {
                output.append("00011#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("4")) {
                output.append("00001#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("5")) {
                output.append("00000#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("6")) {
                output.append("10000#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("7")) {
                output.append("11000#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("8")) {
                output.append("11100#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("9")) {
                output.append("11110#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("")) {
                output.append("0101#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("")) {
                output.append("1110#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("")) {
                output.append("0011#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("")) {
                output.append("00011000#");
                input.delete(0, 1);
            } else if (input.toString().startsWith(".")) {
                output.append("010101#");
                input.delete(0, 1);
            } else if (input.toString().startsWith(",")) {
                output.append("110011#");
                input.delete(0, 1);
            } else if (input.toString().startsWith(":")) {
                output.append("111000#");
                input.delete(0, 1);
            } else if (input.toString().startsWith(";")) {
                output.append("101010#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("?")) {
                output.append("001100#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("!")) {
                output.append("101011#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("-")) {
                output.append("100001#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("_")) {
                output.append("001101#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("(")) {
                output.append("10110#");
                input.delete(0, 1);
            } else if (input.toString().startsWith(")")) {
                output.append("101101#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("=")) {
                output.append("10001#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("+")) {
                output.append("01010#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("/")) {
                output.append("10010#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("@")) {
                output.append("011010#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("'")) {
                output.append("011110#");
                input.delete(0, 1);
            } else if (input.toString().startsWith("$")) {
                output.append("0001001#");
                input.delete(0, 1);
            } else {
                tfOutput = "Code not listed or wrong.";
            }
        }
        if (output.toString().endsWith("#")) {
            output.delete(output.length() - 1, output.length());
        }
        tfOutput = output.toString();
        lastFragment = 0;
        After(view);
    }
}

From source file:de.marcelkapfer.morseconverter.MainActivity.java

public void llm(View view) {
    EditText editText = (EditText) findViewById(R.id.edit_message);
    StringBuffer message = new StringBuffer(editText.getText());
    if (message.toString().endsWith(" ")) {
        message = message.deleteCharAt(message.length() - 1);
    }/* w  w  w.  j  av  a2 s. c o  m*/
    // Variables
    // Variables
    StringBuffer input = new StringBuffer();
    input = input.replace(0, input.length(), message.toString().toUpperCase());
    StringBuffer output = new StringBuffer();
    if (input.toString().equals("")) {
        tfOutput = "Please enter at least one character";
        After(view);
    } else if (input.toString().equals("LETTERSPACE")) {
        tfOutput = "   ";
        After(view);
    } else if (input.toString().equals("END OF WORK")) {
        tfOutput = "...-.-";
        After(view);
    } else if (input.toString().equals("ERROR")) {
        tfOutput = "........";
        After(view);
    } else if (input.toString().equals("STARTING SIGNAL")) {
        tfOutput = "-.-.-";
        After(view);
    } else if (input.toString().equals("ENDING SIGNAL")) {
        tfOutput = ".-.-.";
        After(view);
    } else if (input.toString().equals("UNDERSTOOD")) {
        tfOutput = "...-.";
        After(view);
    } else if (input.toString().equals("WAIT")) {
        tfOutput = ".-...";
        After(view);
    } else if (input.toString().equals("SOS")) {
        tfOutput = "...---...";
        After(view);
    } else if (input.toString().equals("LETTER SPACE")) {
        tfOutput = "   ";
        After(view);
    } else if (input.toString().equals("WORD SPACE")) {
        tfOutput = "       ";
        After(view);
    } else {
        for (int c = input.length(); c > 0; c--) {
            if (input.toString().startsWith(" ")) {
                if (output.toString().endsWith("   ")) {
                    output.delete(output.length() - 3, output.length());
                }
                output.append("       ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("A")) {
                output.append(".-   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("B")) {
                output.append("-...   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("C")) {
                output.append("-.-.   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("D")) {
                output.append("-..   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("E")) {
                output.append(".   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("F")) {
                output.append("..-.   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("G")) {
                output.append("--.   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("H")) {
                output.append("....   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("I")) {
                output.append("..   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("J")) {
                output.append(".---   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("K")) {
                output.append("-.-   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("L")) {
                output.append(".-..   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("M")) {
                output.append("--   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("N")) {
                output.append("-.   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("O")) {
                output.append("---   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("P")) {
                output.append(".--.   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("Q")) {
                output.append("--.-   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("R")) {
                output.append(".-.   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("S")) {
                output.append("...   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("T")) {
                output.append("-   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("U")) {
                output.append("..-   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("V")) {
                output.append("...-   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("W")) {
                output.append(".--   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("X")) {
                output.append("-..-   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("Y")) {
                output.append("-.--   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("Z")) {
                output.append("--..   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("0")) {
                output.append("-----   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("1")) {
                output.append(".----   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("2")) {
                output.append("..---   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("3")) {
                output.append("...--   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("4")) {
                output.append("....-   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("5")) {
                output.append(".....   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("6")) {
                output.append("-....   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("7")) {
                output.append("--...   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("8")) {
                output.append("---..   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("9")) {
                output.append("----.   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("")) {
                output.append(".-.-   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("")) {
                output.append("---.   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("")) {
                output.append("..--   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("")) {
                output.append("...--...   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith(".")) {
                output.append(".-.-.-   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith(",")) {
                output.append("--..--   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith(":")) {
                output.append("---...   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith(";")) {
                output.append("-.-.-.   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("?")) {
                output.append("..--..   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("!")) {
                output.append("-.-.--   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("-")) {
                output.append("-....-   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("_")) {
                output.append("..--.-   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("(")) {
                output.append("-.--.   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith(")")) {
                output.append("-.--.-   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("=")) {
                output.append("-...-   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("+")) {
                output.append(".-.-.   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("/")) {
                output.append("-..-.   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("@")) {
                output.append(".--.-.   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("'")) {
                output.append(".----.   ");
                input.delete(0, 1);
            } else if (input.toString().startsWith("$")) {
                output.append("...-..-   ");
                input.delete(0, 1);
            } else {
                tfOutput = "Code not listed or wrong.";
            }
        }
        if (output.toString().endsWith("   ")) {
            output.delete(output.length() - 3, output.length());
        }
        tfOutput = output.toString();
        lastFragment = 1;
        After(view);
    }
}

From source file:com.instantme.api.InstagramAPI.java

private String encodeUrl(Hashtable params) {

    StringBuffer encodedUrl = new StringBuffer();

    for (Enumeration elements = params.keys(); elements.hasMoreElements();) {
        String key = (String) elements.nextElement();
        String value = (String) params.get(key);
        //println("encodeUrl: " + key + "=" + value);
        encodedUrl.append(key);/*from w ww.j  a v  a2s .c o m*/
        encodedUrl.append("=");
        encodedUrl.append(escapeUrl(value));
        encodedUrl.append("&");
    }
    // remove last "&"
    if (encodedUrl.length() > 0) {
        encodedUrl.deleteCharAt(encodedUrl.length() - 1);
    }

    return encodedUrl.toString();
}

From source file:com.example.phonetic.Nysiis.java

/**
 * Retrieves the NYSIIS code for a given String object.
 *
 * @param str String to encode using the NYSIIS algorithm
 * @return A NYSIIS code for the String supplied
 *//*from  www  .  j  a  v a  2  s .  co m*/
public String nysiis(String str) {
    if (str == null) {
        return null;
    }

    // Use the same clean rules as Soundex
    str = clean(str);

    if (str.length() == 0) {
        return str;
    }

    // Translate first characters of name:
    // MAC -> MCC, KN -> NN, K -> C, PH | PF -> FF, SCH -> SSS
    str = PAT_MAC.matcher(str).replaceFirst("MCC");
    str = PAT_KN.matcher(str).replaceFirst("NN");
    str = PAT_K.matcher(str).replaceFirst("C");
    str = PAT_PH_PF.matcher(str).replaceFirst("FF");
    str = PAT_SCH.matcher(str).replaceFirst("SSS");

    // Translate last characters of name:
    // EE -> Y, IE -> Y, DT | RT | RD | NT | ND -> D
    str = PAT_EE_IE.matcher(str).replaceFirst("Y");
    str = PAT_DT_ETC.matcher(str).replaceFirst("D");

    // First character of key = first character of name.
    StringBuffer key = new StringBuffer(str.length());
    key.append(str.charAt(0));

    // Transcode remaining characters, incrementing by one character each time
    final char[] chars = str.toCharArray();
    final int len = chars.length;

    for (int i = 1; i < len; i++) {
        final char next = i < len - 1 ? chars[i + 1] : SPACE;
        final char aNext = i < len - 2 ? chars[i + 2] : SPACE;
        final char[] transcoded = transcodeRemaining(chars[i - 1], chars[i], next, aNext);
        System.arraycopy(transcoded, 0, chars, i, transcoded.length);

        // only append the current char to the key if it is different from the last one
        if (chars[i] != chars[i - 1]) {
            key.append(chars[i]);
        }
    }

    if (key.length() > 1) {
        char lastChar = key.charAt(key.length() - 1);

        // If last character is S, remove it.
        if (lastChar == 'S') {
            key.deleteCharAt(key.length() - 1);
            lastChar = key.charAt(key.length() - 1);
        }

        if (key.length() > 2) {
            final char last2Char = key.charAt(key.length() - 2);
            // If last characters are AY, replace with Y.
            if (last2Char == 'A' && lastChar == 'Y') {
                key.deleteCharAt(key.length() - 2);
            }
        }

        // If last character is A, remove it.
        if (lastChar == 'A') {
            key.deleteCharAt(key.length() - 1);
        }
    }

    final String string = key.toString();
    return this.isStrict() ? string.substring(0, Math.min(TRUE_LENGTH, string.length())) : string;
}