Example usage for org.apache.commons.lang StringUtils remove

List of usage examples for org.apache.commons.lang StringUtils remove

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils remove.

Prototype

public static String remove(String str, char remove) 

Source Link

Document

Removes all occurrences of a character from within the source string.

Usage

From source file:org.sipfoundry.sipxconfig.admin.monitoring.MRTGConfigTest.java

public void testAddCustomTarget() {
    MRTGTarget customTarget = new MRTGTarget();
    customTarget.setId("custom");
    customTarget.setExpression("customExpresion");
    customTarget.setGroup("customGroup");
    customTarget.setTitle("customTitle");
    customTarget.setPageTop("customPageTop");
    customTarget.setMaxBytes(10);//w  ww.j  av  a 2 s .c om
    customTarget.setShortLegend("shortLegend");
    customTarget.setYLegend("YLegend");
    customTarget.setLegendI("ILegend");
    customTarget.setLegendO("OLegend");
    customTarget.setLegend1("Legend1");
    customTarget.setLegend2("Legend2");
    customTarget.setOptions("gauge,growright,nopercent");
    customTarget.setUnscaled("unscaled");
    customTarget.setkMG("kMG");
    customTarget.setFactor(4);
    customTarget.setKilo();

    String eol = System.getProperty("line.separator");
    List<MRTGTarget> targets = new ArrayList<MRTGTarget>();
    targets.add(customTarget);
    m_mrtgConfig.setTargets(targets);
    String m_mrtgConfigString = StringUtils.remove(m_mrtgConfig.toString(), eol);
    String outputToCompare = "RunAsDaemon: Yes" + "NoDetach: Yes" + "Interval: 5" + "workdir: /mrtg"
            + "threshdir: /mrtg/thresh"
            + "LoadMibs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt, /usr/share/snmp/mibs/TCP-MIB.txt"
            + "EnableIPv6: no" + "LogFormat: rrdtool" + "PathAdd: /usr/bin"
            + "#target-group=customGroup## customTitle#target[custom]: customExpresiontitle[custom]: customTitlepagetop[custom]: customPageTopmaxbytes[custom]: 10shortlegend[custom]: shortLegendylegend[custom]: YLegendlegendi[custom]: ILegendlegendo[custom]: OLegendlegend1[custom]: Legend1legend2[custom]: Legend2unscaled[custom]: unscaledoptions[custom]: gauge,growright,nopercent";
    assertEquals(m_mrtgConfigString, outputToCompare);
}

From source file:org.sipfoundry.sipxconfig.phone.polycom.CodecConfigurationForModelTest.java

private void assertCodecConfigurationForModel(CodecGroupType codecGroup, String phoneModelId) throws Exception {

    // Initialize the phone.
    m_phone = new PolycomPhone();
    m_phone.setModel(phoneModelBuilder(phoneModelId, getClass()));
    PhoneTestDriver.supplyTestData(m_phone, new LinkedList<User>());

    // Each model belongs to exactly one codec group.
    Collection<Setting> codecPref = m_phone.getSettings().getSetting("voice/codecPref").getValues();
    assertTrue(String.format("The '%s' model does not have a codec group.", phoneModelId),
            0 != codecPref.size());//w w w.  j a  v  a 2  s. c o  m
    String str_groups = "";
    for (Setting s : codecPref) {
        str_groups += "-" + s.getName();
    }
    assertEquals(
            String.format("The '%s' model has more than one codec group ('%s'):", phoneModelId, str_groups), 1,
            codecPref.size());

    // Make sure it's the correct codec group.
    Setting codec_adaptor = codecPref.iterator().next();
    assertEquals(String.format("The '%s' model has the wrong codec group:", phoneModelId),
            codecGroup.toString(), codec_adaptor.getName());

    // Collect the major types of the supported codec options. (Remove the minor bit/sample rates.)
    HashSet<String> major_supported_codecs = new HashSet<String>();
    Collection<String> options = ((MultiEnumSetting) codec_adaptor.getType()).getEnums().values();
    for (String option : options) {
        int i = option.indexOf('.');
        if (-1 != i) {
            option = option.substring(0, i);
        }
        major_supported_codecs.add(StringUtils.remove(option, "_"));
    }

    // Loop though the audioProfiles for the model. There should be one for major supported codec type.
    Collection<Setting> audioProfile = m_phone.getSettings().getSetting("voice/audioProfile").getValues();
    for (Setting s : audioProfile) {
        assertTrue(String.format("The '%s' model has an audioProfile for unsupported codec type '%s'.",
                phoneModelId, s.getName()), major_supported_codecs.remove(s.getName()));
    }
    assertEquals(String.format(
            "The '%s' model is missing an audioProfile for the following supported code type(s): %s.",
            phoneModelId, major_supported_codecs), 0, major_supported_codecs.size());
}

From source file:org.sipfoundry.sipximbot.FullUsers.java

public User findByjid(String jid) {
    String id = StringUtils.remove(jid, "@" + ImbotConfiguration.get().getSipxchangeDomainName());
    User user = UnfortunateLackOfSpringSupportFactory.getValidUsers().getUserByInsensitiveJid(id);
    if (user != null) {
        user.setJid(jid);//from  w w w .j  av  a 2  s . com
    }
    return user;
}

From source file:org.sonar.api.rules.Rule.java

private String removeNewLineCharacters(String text) {
    String removedCRLF = StringUtils.remove(text, "\n");
    removedCRLF = StringUtils.remove(removedCRLF, "\r");
    removedCRLF = StringUtils.remove(removedCRLF, "\n\r");
    removedCRLF = StringUtils.remove(removedCRLF, "\r\n");
    return removedCRLF;
}

From source file:org.sonar.core.persistence.profiling.ProfilingStatementHandler.java

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (method.getName().startsWith("execute")) {
        Profiler profiler = Profiler.create(ProfiledDataSource.SQL_LOGGER).start();
        Object result = null;//  w w  w. j a va2s.  c o  m
        try {
            result = InvocationUtils.invokeQuietly(statement, method, args);
        } finally {
            profiler.addContext("sql", StringUtils.remove((String) args[0], '\n'));
            profiler.stopTrace("");
        }
        return result;
    } else {
        return InvocationUtils.invokeQuietly(statement, method, args);
    }
}

From source file:org.sonar.db.profiling.ProfilingPreparedStatementHandler.java

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (method.getName().startsWith("execute")) {
        Profiler profiler = Profiler.create(ProfiledDataSource.SQL_LOGGER).start();
        Object result = null;//from ww w . j  a  v a  2 s .co m
        try {
            result = InvocationUtils.invokeQuietly(statement, method, args);
        } finally {
            profiler.addContext("sql", StringUtils.remove(sql, '\n'));
            profiler.stopTrace("");
        }
        return result;
    } else if (method.getName().startsWith("set") && args.length > 1) {
        arguments.set((Integer) args[0] - 1, args[1]);
        return InvocationUtils.invokeQuietly(statement, method, args);
    } else {
        return InvocationUtils.invokeQuietly(statement, method, args);
    }
}

From source file:org.sonar.java.checks.verifier.CheckVerifier.java

protected void collectExpectedIssues(String comment, int line) {
    String expectedStart = getExpectedIssueTrigger();
    if (comment.startsWith(expectedStart)) {
        String cleanedComment = StringUtils.remove(comment, expectedStart);

        EnumMap<IssueAttribute, String> attr = new EnumMap<>(IssueAttribute.class);
        String expectedMessage = StringUtils.substringBetween(cleanedComment, "{{", "}}");
        if (StringUtils.isNotEmpty(expectedMessage)) {
            attr.put(IssueAttribute.MESSAGE, expectedMessage);
        }/*from   w  ww.ja va  2  s .  c  o  m*/
        int expectedLine = line;
        String attributesSubstr = extractAttributes(comment, attr);

        cleanedComment = StringUtils
                .stripEnd(StringUtils.remove(StringUtils.remove(cleanedComment, "[[" + attributesSubstr + "]]"),
                        "{{" + expectedMessage + "}}"), " \t");
        if (StringUtils.startsWith(cleanedComment, "@")) {
            final int lineAdjustment;
            final char firstChar = cleanedComment.charAt(1);
            final int endIndex = cleanedComment.indexOf(' ');
            if (endIndex == -1) {
                lineAdjustment = Integer.parseInt(cleanedComment.substring(2));
            } else {
                lineAdjustment = Integer.parseInt(cleanedComment.substring(2, endIndex));
            }
            if (firstChar == '+') {
                expectedLine += lineAdjustment;
            } else if (firstChar == '-') {
                expectedLine -= lineAdjustment;
            } else {
                Fail.fail("Use only '@+N' or '@-N' to shifts messages.");
            }
        }
        updateEndLine(expectedLine, attr);
        expected.put(expectedLine, attr);
    }
}

From source file:org.sonar.php.checks.FieldNameCheck.java

@Override
public void visitNode(Tree tree) {
    ClassPropertyDeclarationTree property = (ClassPropertyDeclarationTree) tree;
    for (VariableDeclarationTree variableDeclarationTree : property.declarations()) {
        String propertyName = variableDeclarationTree.identifier().text();
        if (!pattern.matcher(StringUtils.remove(propertyName, "$")).matches()) {
            context().newIssue(this, String.format(MESSAGE, propertyName, format)).tree(property);
        }//from  w ww .ja  v a 2s .c om
    }
}

From source file:org.sonar.php.checks.LocalVariableAndParameterNameCheck.java

private boolean isCompliant(String varName) {
    return pattern.matcher(StringUtils.remove(varName, "$")).matches() || isSuperGlobal(varName);
}

From source file:org.sonar.php.checks.utils.AbstractUnusedPrivateClassMemberCheck.java

/**
 * Returns "::$field" for static field and "->field" for others.
 *
 * @param identifierNode node that correspond to the name of the class member.
 *//*from   ww  w .ja  v a 2 s.co m*/
protected String getCalledName(AstNode identifierNode, List<AstNode> modifiers) {
    if (CheckUtils.isStaticClassMember(modifiers)) {
        return "::" + identifierNode.getTokenOriginalValue();
    } else {
        return "->" + StringUtils.remove(identifierNode.getTokenOriginalValue(), "$");
    }
}