Java String Remove removeModuleReference(String allStr, String refStr)

Here you can find the source of removeModuleReference(String allStr, String refStr)

Description

Removes reference from RefSource and returns the new references.

License

Open Source License

Parameter

Parameter Description
allStr the RefSource.
refStr the removing reference.

Return

the new references.

Declaration

public static String removeModuleReference(String allStr, String refStr) 

Method Source Code

//package com.java2s;

import java.util.ArrayList;
import java.util.Arrays;

public class Main {
    /**/*from w w w .  j  a  v  a  2  s. co  m*/
     * the separator string of references.
     */
    private static final String REFERENCE_SEPARATOR_NAME = ";";

    /**
     * Removes reference from RefSource and returns the new references.
     * 
     * @param allStr
     *            the RefSource.
     * @param refStr
     *            the removing reference.
     * @return the new references.
     */
    public static String removeModuleReference(String allStr, String refStr) {
        ArrayList<String> orgList = null;
        if (allStr != null) {
            orgList = new ArrayList<String>(Arrays.asList(allStr.split(REFERENCE_SEPARATOR_NAME)));
        } else {
            orgList = new ArrayList<String>();
        }
        if (orgList.contains(refStr)) {
            orgList.remove(refStr);
        }
        return makeModuleReference(orgList);
    }

    /**
     * Returns the RefSource attribute value.
     * 
     * @param list
     *            the reference list.
     * @return the RefSource attribute value.
     */
    private static String makeModuleReference(ArrayList<String> list) {
        StringBuffer buffer = new StringBuffer();
        for (String attr : list) {
            if (buffer.length() > 0) {
                buffer.append(REFERENCE_SEPARATOR_NAME);
            }
            buffer.append(attr);
        }
        return buffer.toString();
    }
}

Related

  1. removeGender(String pos)
  2. removeGenericQuote(String str)
  3. removeIllegalXMLChars(String in)
  4. removeImportClass(String className)
  5. removeKeyPrefix(Properties properties, String prefix)
  6. removeNewLineAndTab(String value)
  7. removePostfixedNewline(String s)
  8. removeProperty(String name)
  9. removePropertyNameModifier(String name)