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:com.edgenius.wiki.service.impl.ActivityLogServiceImpl.java

public void logAttachmentUploaded(String spaceUname, String pageTitle, User creator,
        List<FileNode> attachment) {
    try {/*from  w  ww  . j  av  a  2s .c  o  m*/
        ActivityLog activity = new ActivityLog();
        activity.setType(ActivityType.Type.ATTACHMENT_EVENT.getCode());
        activity.setSubType(ActivityType.SubType.CREATE.getCode());
        activity.setSrcResourceType(SecurityValues.RESOURCE_TYPES.ATTACHMENT.ordinal());
        //put spaceUname as extro info so that easy to do security check at retrieving
        StringBuffer files = new StringBuffer();
        for (FileNode fileNode : attachment) {
            files.append(fileNode.getFilename()).append(",");
        }
        if (files.length() > 0) {
            //delete last comma
            files.deleteCharAt(files.length() - 1);
        }

        activity.setSrcResourceName(files.toString());
        activity.setTgtResourceName(pageTitle);

        activity.setExtroInfo(spaceUname);

        activity.setCreator(creator);
        activity.setCreatedDate(new Date());
        this.save(activity);
    } catch (Exception e) {
        log.warn("Activity log failed for comment", e);
    }
}

From source file:com.antsdb.saltedfish.server.mysql.replication.MysqlSlave.java

@Override
public void onEvents(BinlogEventV4 event) {
    if (_log.isTraceEnabled()) {
        _log.trace(event.toString());/*  w ww.  ja  v a 2  s  .  c om*/
    }
    try {
        if (event instanceof XidEvent) {
            onCommit((XidEvent) event);
        } else if (event instanceof QueryEvent) {
            onQuery((QueryEvent) event);
            getCheckPoint().setSlaveLogPosition(event.getHeader().getNextPosition());
        } else if (event instanceof RotateEvent) {
            onRotate((RotateEvent) event);
        } else if (event instanceof WriteRowsEvent) {
            onWriteRows((WriteRowsEvent) event);
            getCheckPoint().setSlaveLogPosition(event.getHeader().getNextPosition());
        } else if (event instanceof WriteRowsEventV2) {
            onWriteRows((WriteRowsEventV2) event);
            getCheckPoint().setSlaveLogPosition(event.getHeader().getNextPosition());
        } else if (event instanceof UpdateRowsEvent) {
            onUpdateRows((UpdateRowsEvent) event);
            getCheckPoint().setSlaveLogPosition(event.getHeader().getNextPosition());
        } else if (event instanceof UpdateRowsEventV2) {
            onUpdateRows((UpdateRowsEventV2) event);
            getCheckPoint().setSlaveLogPosition(event.getHeader().getNextPosition());
        } else if (event instanceof DeleteRowsEvent) {
            onDeleteRows((DeleteRowsEvent) event);
            getCheckPoint().setSlaveLogPosition(event.getHeader().getNextPosition());
        } else if (event instanceof DeleteRowsEventV2) {
            onDeleteRows((DeleteRowsEventV2) event);
            getCheckPoint().setSlaveLogPosition(event.getHeader().getNextPosition());
        } else if (event instanceof TableMapEvent) {
            onTableMap((TableMapEvent) event);
        }
    } catch (Exception x) {
        _log.error("replication failed: {}", event, x);
        StringBuffer buf = new StringBuffer();
        this.tableById.forEach((id, name) -> {
            buf.append(id);
            buf.append("=[");
            buf.append(name[0]);
            buf.append(",");
            buf.append(name[1]);
            buf.append("],");
        });
        buf.deleteCharAt(buf.length() - 1);
        _log.error("table map: {}", buf.toString());
        stop();
    }
}

From source file:spade.storage.Prov.java

private String getProvNFormattedKeyValPair(Map<String, String> keyvals) {
    StringBuffer string = new StringBuffer();
    string.append("[ ");
    for (String key : keyvals.keySet()) {
        if (!key.equals("type")) {
            String value = keyvals.get(key);
            if (key.equals("time")) {
                value = convertUnixTimeToISO8601(value);
            }//ww w. j a  va  2  s  .  c o m
            string.append(getNSPrefixForAnnotation(key)).append(":").append(key).append("=\"").append(value)
                    .append("\",");
        }
    }
    string.deleteCharAt(string.length() - 1);
    string.append("]");
    return string.toString();
}

From source file:org.opennms.netmgt.mib2events.Mib2Events.java

public Logmsg getTrapEventLogmsg(MibValueSymbol trapValueSymbol) {
    Logmsg msg = new Logmsg();
    msg.setDest("logndisplay");

    final StringBuffer dbuf = new StringBuffer();
    dbuf.append("<p>");
    dbuf.append("\n");
    dbuf.append("\t").append(trapValueSymbol.getName()).append(" trap received\n");
    int vbNum = 1;
    for (MibValue vb : getTrapVars(trapValueSymbol)) {
        dbuf.append("\t").append(vb.getName()).append("=%parm[#").append(vbNum).append("]%\n");
        vbNum++;// w  w  w. j ava  2  s .c o  m
    }

    if (dbuf.charAt(dbuf.length() - 1) == '\n') {
        dbuf.deleteCharAt(dbuf.length() - 1); // delete the \n at the end
    }
    dbuf.append("</p>\n\t");

    msg.setContent(dbuf.toString());

    return msg;
}

From source file:cx.fbn.nevernote.threads.IndexRunner.java

private void addToIndex(String guid, String word, String type) {
    if (foundWords.contains(word))
        return;//w w w  .  j  av  a 2 s  .c  o  m
    StringBuffer buffer = new StringBuffer(word.toLowerCase());
    for (int i = buffer.length() - 1; i >= 0; i--) {
        if (!Character.isLetterOrDigit(buffer.charAt(i))
                && specialIndexCharacters.indexOf(buffer.charAt(i)) == -1)
            buffer.deleteCharAt(i);
        else
            break;
    }
    buffer = buffer.reverse();
    for (int i = buffer.length() - 1; i >= 0; i--) {
        if (!Character.isLetterOrDigit(buffer.charAt(i)))
            buffer.deleteCharAt(i);
        else
            break;
    }
    buffer = buffer.reverse();
    if (buffer.length() > 0) {
        // We have a good word, now let's trim off junk at the beginning or end
        if (!foundWords.contains(buffer.toString())) {
            foundWords.add(buffer.toString());
            foundWords.add(word);
            conn.getWordsTable().addWordToNoteIndex(guid, buffer.toString(), type, 100);
            uncommittedCount++;
            if (uncommittedCount > 100) {
                conn.commitTransaction();
                uncommittedCount = 0;
            }
        }
    }
    return;
}

From source file:com.wabacus.system.component.application.report.configbean.crosslist.CrossListReportDynDatasetBean.java

private String getDynamicCrossStatiSelectColsWithVerticalStati(Map<String, String> mAllSelectCols) {
    if (this.lstIncludeCrossStatiColAndGroupBeans == null || lstIncludeCrossStatiColAndGroupBeans.size() == 0)
        return "";
    if (mAllSelectCols == null || mAllSelectCols.size() == 0)
        return "";
    StringBuffer resultBuf = new StringBuffer();
    String selectColsTmp;/*w w  w  . j a  v  a  2 s .  c  om*/
    for (AbsCrossListReportColAndGroupBean colgroupBeanTmp : lstIncludeCrossStatiColAndGroupBeans) {
        if (!colgroupBeanTmp.getInnerDynamicColBean().isHasVerticalstatistic())
            continue;
        selectColsTmp = mAllSelectCols.get(colgroupBeanTmp.getRootCrossColGroupId());
        if (selectColsTmp == null || selectColsTmp.trim().equals(""))
            continue;
        resultBuf.append(selectColsTmp).append(",");
    }
    if (resultBuf.length() > 0 && resultBuf.charAt(resultBuf.length() - 1) == ',')
        resultBuf.deleteCharAt(resultBuf.length() - 1);
    return resultBuf.toString();
}

From source file:net.sf.morph.transform.converters.TextToNumberConverter.java

/**
 * Determines whether negation of the conversion result is needed based on
 * the presence and handling method of parentheses.
 * //from  w w w  . j  a  v a2 s.  com
 * @param charactersToParse
 *            the characters to parse
 * @param locale
 *            the locale
 * @return <code>true</code>, if the number is enclosed by parantheses
 *         and parantheses handling is set to PARENTHESES_NEGATE or<br>
 *         <code>false</code>, otherwise
 */
private boolean handleParenthesesNegation(StringBuffer charactersToParse, Locale locale) {
    int lastCharIndex = charactersToParse.length() - 1;
    // if this is a number enclosed with parentheses and we should be
    // negating values in parentheses
    if (getParenthesesHandling() == PARENTHESES_NEGATE && charactersToParse.charAt(0) == LEFT_PARENTHESES
            && charactersToParse.charAt(lastCharIndex) == RIGHT_PARENTHESES) {
        // delete the closing paran
        charactersToParse.deleteCharAt(lastCharIndex);
        // delete the opening paran
        charactersToParse.deleteCharAt(0);
        // return true to indicate negation should take place
        return true;
    }
    // return false to indicate negation should not happen
    return false;
}

From source file:architecture.common.util.TextUtils.java

/**
 * Returns a string that has whitespace removed from both ends of the
 * String, as well as duplicate whitespace removed from within the String.
 */// w  ww. j a va 2 s  .  c o  m
public final static String innerTrim(String s) {
    StringBuffer b = new StringBuffer(s);
    int index = 0;

    while ((b.length() != 0) && (b.charAt(0) == ' ')) {
        b.deleteCharAt(0);
    }

    while (index < b.length()) {
        if (Character.isWhitespace(b.charAt(index))) {
            if (((index + 1) < b.length()) && (Character.isWhitespace(b.charAt(index + 1)))) {
                b.deleteCharAt(index + 1);
                index--; // let's restart at this character!
            }
        }

        index++;
    }

    if (b.length() > 0) {
        int l = b.length() - 1;

        if (b.charAt(l) == ' ') {
            b.setLength(l);
        }
    }

    String result = b.toString();

    return result;
}

From source file:com.cloud.bridge.util.RestAuth.java

/**
 * Used as part of the CanonalizedResource element of the StringToSign.
 * CanonicalizedResource = [ "/" + Bucket ] +
 * <HTTP-Request-URI, from the protocol name up to the query string> + [sub-resource]
 * The list of sub-resources that must be included when constructing the CanonicalizedResource Element are: acl, lifecycle, location, 
 * logging, notification, partNumber, policy, requestPayment, torrent, uploadId, uploads, versionId, versioning, versions and website.
 * (http://docs.amazonwebservices.com/AmazonS3/latest/dev/RESTAuthentication.html)
 * @param query - results from calling "HttpServletRequest req.getQueryString()"
 *///from  w w w.  jav a 2  s. c  o  m
public void setQueryString(String query) {
    if (null == query) {
        this.queryString = null;
        return;
    }

    // Sub-resources (i.e.: query params) must be lex sorted
    Set<String> subResources = new TreeSet<String>();

    String[] queryParams = query.split("&");
    StringBuffer builtQuery = new StringBuffer();
    for (String queryParam : queryParams) {
        // lookup parameter name
        String paramName = queryParam.split("=")[0];
        if (allowedQueryParams.contains(paramName)) {
            subResources.add(queryParam);
        }
    }
    for (String subResource : subResources) {
        builtQuery.append(subResource + "&");
    }
    // If anything inside the string buffer, add a "?" at the beginning, 
    // and then remove the last '&'
    if (builtQuery.length() > 0) {
        builtQuery.insert(0, "?");
        builtQuery.deleteCharAt(builtQuery.length() - 1);
    }
    this.queryString = builtQuery.toString();
}

From source file:com.cloud.hypervisor.guru.VMwareGuru.java

@Override
public VirtualMachineTO implement(VirtualMachineProfile vm) {
    VirtualMachineTO to = toVirtualMachineTO(vm);
    to.setBootloader(BootloaderType.HVM);

    Map<String, String> details = to.getDetails();
    if (details == null)
        details = new HashMap<String, String>();

    Type vmType = vm.getType();/*  w  w  w.j  av a  2s.c  o m*/
    boolean userVm = !(vmType.equals(VirtualMachine.Type.DomainRouter)
            || vmType.equals(VirtualMachine.Type.ConsoleProxy)
            || vmType.equals(VirtualMachine.Type.SecondaryStorageVm));

    String nicDeviceType = details.get(VmDetailConstants.NIC_ADAPTER);
    if (!userVm) {

        if (nicDeviceType == null) {
            details.put(VmDetailConstants.NIC_ADAPTER, _vmwareMgr.getSystemVMDefaultNicAdapterType());
        } else {
            try {
                VirtualEthernetCardType.valueOf(nicDeviceType);
            } catch (Exception e) {
                s_logger.warn("Invalid NIC device type " + nicDeviceType
                        + " is specified in VM details, switch to default E1000");
                details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString());
            }
        }
    } else {
        // for user-VM, use E1000 as default
        if (nicDeviceType == null) {
            details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString());
        } else {
            try {
                VirtualEthernetCardType.valueOf(nicDeviceType);
            } catch (Exception e) {
                s_logger.warn("Invalid NIC device type " + nicDeviceType
                        + " is specified in VM details, switch to default E1000");
                details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString());
            }
        }
    }

    String diskDeviceType = details.get(VmDetailConstants.ROOT_DISK_CONTROLLER);
    if (userVm) {
        if (diskDeviceType == null) {
            details.put(VmDetailConstants.ROOT_DISK_CONTROLLER, _vmwareMgr.getRootDiskController());
        }
    }
    String diskController = details.get(VmDetailConstants.DATA_DISK_CONTROLLER);
    if (userVm) {
        if (diskController == null) {
            details.put(VmDetailConstants.DATA_DISK_CONTROLLER, DiskControllerType.lsilogic.toString());
        }
    }

    List<NicProfile> nicProfiles = vm.getNics();

    for (NicProfile nicProfile : nicProfiles) {
        if (nicProfile.getTrafficType() == TrafficType.Guest) {
            if (_networkMgr.isProviderSupportServiceInNetwork(nicProfile.getNetworkId(), Service.Firewall,
                    Provider.CiscoVnmc)) {
                details.put("ConfigureVServiceInNexus", Boolean.TRUE.toString());
            }
            break;
        }
    }

    long clusterId = getClusterId(vm.getId());
    details.put(VmwareReserveCpu.key(), VmwareReserveCpu.valueIn(clusterId).toString());
    details.put(VmwareReserveMemory.key(), VmwareReserveMemory.valueIn(clusterId).toString());
    to.setDetails(details);

    if (vmType.equals(VirtualMachine.Type.DomainRouter)) {

        NicProfile publicNicProfile = null;
        for (NicProfile nicProfile : nicProfiles) {
            if (nicProfile.getTrafficType() == TrafficType.Public) {
                publicNicProfile = nicProfile;
                break;
            }
        }

        if (publicNicProfile != null) {
            NicTO[] nics = to.getNics();

            // reserve extra NICs
            NicTO[] expandedNics = new NicTO[nics.length + _vmwareMgr.getRouterExtraPublicNics()];
            int i = 0;
            int deviceId = -1;
            for (i = 0; i < nics.length; i++) {
                expandedNics[i] = nics[i];
                if (nics[i].getDeviceId() > deviceId)
                    deviceId = nics[i].getDeviceId();
            }
            deviceId++;

            long networkId = publicNicProfile.getNetworkId();
            NetworkVO network = _networkDao.findById(networkId);

            for (; i < nics.length + _vmwareMgr.getRouterExtraPublicNics(); i++) {
                NicTO nicTo = new NicTO();

                nicTo.setDeviceId(deviceId++);
                nicTo.setBroadcastType(publicNicProfile.getBroadcastType());
                nicTo.setType(publicNicProfile.getTrafficType());
                nicTo.setIp("0.0.0.0");
                nicTo.setNetmask("255.255.255.255");

                try {
                    String mac = _networkMgr.getNextAvailableMacAddressInNetwork(networkId);
                    nicTo.setMac(mac);
                } catch (InsufficientAddressCapacityException e) {
                    throw new CloudRuntimeException("unable to allocate mac address on network: " + networkId);
                }
                nicTo.setDns1(publicNicProfile.getIPv4Dns1());
                nicTo.setDns2(publicNicProfile.getIPv4Dns2());
                if (publicNicProfile.getIPv4Gateway() != null) {
                    nicTo.setGateway(publicNicProfile.getIPv4Gateway());
                } else {
                    nicTo.setGateway(network.getGateway());
                }
                nicTo.setDefaultNic(false);
                nicTo.setBroadcastUri(publicNicProfile.getBroadCastUri());
                nicTo.setIsolationuri(publicNicProfile.getIsolationUri());

                Integer networkRate = _networkMgr.getNetworkRate(network.getId(), null);
                nicTo.setNetworkRateMbps(networkRate);

                expandedNics[i] = nicTo;
            }

            to.setNics(expandedNics);
        }

        StringBuffer sbMacSequence = new StringBuffer();
        for (NicTO nicTo : sortNicsByDeviceId(to.getNics())) {
            sbMacSequence.append(nicTo.getMac()).append("|");
        }
        if (!sbMacSequence.toString().isEmpty()) {
            sbMacSequence.deleteCharAt(sbMacSequence.length() - 1);
            String bootArgs = to.getBootArgs();
            to.setBootArgs(bootArgs + " nic_macs=" + sbMacSequence.toString());
        }

    }

    // Don't do this if the virtual machine is one of the special types
    // Should only be done on user machines
    if (userVm) {
        configureNestedVirtualization(details, to);
    }
    // Determine the VM's OS description
    GuestOSVO guestOS = _guestOsDao.findByIdIncludingRemoved(vm.getVirtualMachine().getGuestOSId());
    to.setOs(guestOS.getDisplayName());
    to.setHostName(vm.getHostName());
    HostVO host = _hostDao.findById(vm.getVirtualMachine().getHostId());
    GuestOSHypervisorVO guestOsMapping = null;
    if (host != null) {
        guestOsMapping = _guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(),
                getHypervisorType().toString(), host.getHypervisorVersion());
    }
    if (guestOsMapping == null || host == null) {
        to.setPlatformEmulator(null);
    } else {
        to.setPlatformEmulator(guestOsMapping.getGuestOsName());
    }
    return to;
}