Example usage for java.util TreeSet add

List of usage examples for java.util TreeSet add

Introduction

In this page you can find the example usage for java.util TreeSet add.

Prototype

public boolean add(E e) 

Source Link

Document

Adds the specified element to this set if it is not already present.

Usage

From source file:de.julielab.jcore.ae.lingpipegazetteer.chunking.ChunkerProviderImpl.java

private TreeSet<String> makeTermVariants(String term) {

    TreeSet<String> termVariants = new TreeSet<String>();
    termVariants.add(term);
    String termVariant = "";

    // replace hyphens with white space unless too many hyphens in term
    String[] splits = term.split("\\-");

    int limit = splits.length + 1;

    if (limit < NUM_HYPHENS4VARIANTS) {

        for (int i = 0; i < limit; i++) {
            splits = term.split("\\-", i);
            String result = "";
            for (String split : splits) {
                result += " " + split;
            }/* w w w  . j  ava2  s.c  om*/
            // System.err.println(result.trim());
            termVariants.add(result.trim());
            result = result.replaceFirst("\\-", " ");
            termVariants.add(result.trim());
        }

        termVariant = term.replaceAll("\\-", " ");
        termVariants.add(termVariant);
        termVariant = term.replaceFirst("\\-", " ");
        termVariants.add(termVariant);

        // replace hyphens with empty string iff term.length > NUM
        if (term.length() > 8) {

            splits = term.split("\\-");
            limit = splits.length + 1;
            for (int i = 0; i < limit; i++) {
                splits = term.split("\\-", i);
                String result = " ";
                for (String split : splits) {
                    result += "" + split;
                }
                // System.err.println(i + " " + result);
                termVariants.add(result.trim());
                result = result.replaceFirst("\\-", "");
                termVariants.add(result.trim());
            }

            termVariant = term.replaceAll("\\-", "");
            termVariants.add(termVariant);
            termVariant = term.replaceFirst("\\-", "");
            termVariants.add(termVariant);
        }

    }
    // replace internal parentheses with ""
    // in addition: add [hyphen to ""] variants
    if (term.contains("(") && term.contains(")")) {

        termVariant = term.replaceFirst("\\(", "");
        termVariant = termVariant.replaceFirst("\\)", "");
        termVariants.add(termVariant);
        termVariant = termVariant.replaceFirst("\\-", "");
        termVariants.add(termVariant);
        termVariant = termVariant.replaceAll("\\-", "");
        termVariants.add(termVariant);

        termVariant = term.replaceAll("\\(", "");
        termVariant = termVariant.replaceAll("\\)", "");
        termVariants.add(termVariant);
        termVariant = termVariant.replaceFirst("\\-", "");
        termVariants.add(termVariant);
        termVariant = termVariant.replaceAll("\\-", "");
        termVariants.add(termVariant);

    }

    // replace white spaces with hyphens
    splits = term.split(" ");
    limit = splits.length + 1;
    for (int i = 0; i < limit; i++) {
        splits = term.split(" ", i);
        String result = "";
        for (String split : splits) {
            result += "-" + split;
        }
        result = result.substring(1).trim();
        // System.err.println(i + " " + result);
        termVariants.add(result.trim());
        result = result.replaceFirst(" ", "-");
        termVariants.add(result.trim());
    }

    termVariant = term.replaceAll(" ", "-");
    termVariants.add(termVariant);
    termVariant = term.replaceFirst(" ", "-");
    termVariants.add(termVariant);

    // genitive 's
    termVariant = term.replaceFirst("'s", "");
    termVariants.add(termVariant);
    termVariant = term.replaceFirst("'s", "s");
    termVariants.add(termVariant);

    return termVariants;
}

From source file:com.qpark.eip.core.spring.security.EipRoleVoter.java

public String getGrantedRoles(final Authentication authentication) {
    TreeSet<String> ts = new TreeSet<String>();
    StringBuffer sb = new StringBuffer(1024);
    Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
    for (GrantedAuthority authority : authorities) {
        ts.add(authority.getAuthority());
    }/*from ww  w . j  a  v a 2s.  com*/
    for (String string : ts) {
        if (sb.length() > 0) {
            sb.append(", ");
        }
        sb.append(string);
    }

    return sb.toString();
}

From source file:org.dasein.cloud.cloudstack.CSMethod.java

private String getSignature(String command, String apiKey, String accessKey, Param... params)
        throws UnsupportedEncodingException, SignatureException {
    Logger logger = CSCloud.getLogger(CSMethod.class, "std");

    if (logger.isTraceEnabled()) {
        logger.trace("enter - " + CSMethod.class.getName() + ".getSignature(" + command + "," + apiKey + ","
                + accessKey + ",[params])");
    }/*from  www  .ja  v  a  2 s.c  o  m*/
    try {
        TreeSet<Param> sorted = new TreeSet<Param>();
        StringBuilder str = new StringBuilder();

        sorted.add(new Param("command",
                URLEncoder.encode(command, "UTF-8").replaceAll("\\+", "%20").toLowerCase()));
        sorted.add(
                new Param("apikey", URLEncoder.encode(apiKey, "UTF-8").replaceAll("\\+", "%20").toLowerCase()));
        for (Param param : params) {
            sorted.add(new Param(param.getKey().toLowerCase(),
                    URLEncoder.encode(param.getValue(), "UTF-8").replaceAll("\\+", "%20").toLowerCase()));
        }
        boolean first = true;
        for (Param param : sorted) {
            if (!first) {
                str.append("&");
            }
            first = false;
            str.append(param.getKey());
            str.append("=");
            str.append(param.getValue());
        }
        if (logger.isDebugEnabled()) {
            logger.debug("getSignature(): String to sign=" + str.toString());
        }
        return new String(Base64.encodeBase64(calculateHmac(str.toString(), accessKey)));
    } finally {
        if (logger.isTraceEnabled()) {
            logger.trace("exit - " + CSMethod.class.getName() + ".getSignature()");
        }
    }
}

From source file:com.redhat.example.rules.unittest.RuleCoverageLogger.java

/**
 * print the coverage result of a RuleGroup
 * @param ruleGroupName/*from ww w. j av a  2s  . c  om*/
 */
public int[] printCoverageOfRuleGroup(String ruleGroupName) {
    Set<Rule> rules = ruleGroupToRulesMap.get(ruleGroupName);
    int rulesNum = rules.size();
    int coveredNum = 0;
    TreeSet<String> notCoveredRules = new TreeSet<String>();
    Iterator<Rule> it = rules.iterator();
    while (it.hasNext()) {
        Rule rule = it.next();
        boolean isCovered = ruleCoverageMap.get(rule);
        if (isCovered) {
            coveredNum++;
        } else {
            notCoveredRules.add(rule.getName());
        }
    }
    if (rulesNum > 0) {
        logger.debug("# Rule group : \"{}\" - Coverage {}% ( {} / {} )", ruleGroupName,
                100 * coveredNum / rulesNum, coveredNum, rulesNum);
        for (String name : notCoveredRules) {
            logger.debug("  * Rule not covered : \"{}\"", name);
        }
    }
    return new int[] { coveredNum, rulesNum };
}

From source file:com.cyanogenmod.eleven.utils.PopupMenuHelper.java

/**
 * Creates the pop up menu by inflating the menu items
 * @param menu Menu to use for adding to
 *///from w  w w  .  ja v  a  2s  . co m
public void createPopupMenu(final Menu menu) {
    TreeSet<Integer> menuItems = new TreeSet<Integer>();

    // get the default items and add them
    int[] defaultItems = getIdsForType(mType);
    if (defaultItems != null) {
        for (int id : defaultItems) {
            menuItems.add(id);
        }
    }

    updateMenuIds(mType, menuItems);

    for (int id : menuItems) {
        addToMenu(menu, id, getAdditionalStringResourceForId(id));
    }
}

From source file:com.qpark.maven.plugin.flowmapper.AbstractGenerator.java

protected String getMapperDefinitions(final List<Entry<ComplexTypeChild, List<ComplexTypeChild>>> children,
        final Set<String> importedClasses) {
    final StringBuffer sb = new StringBuffer(1024);
    final TreeSet<String> usedInterfaces = new TreeSet<String>();
    children.stream().forEach(child -> child.getValue().stream().forEach(grandchild -> {
        final ComplexContent cc = this.getMapperDefinition(grandchild.getComplexType());
        if (cc != null && !usedInterfaces.contains(cc.getFQInterfaceName())) {
            usedInterfaces.add(cc.getFQInterfaceName());
            final String varName = Util.lowerize(cc.interfaceClassName);
            String className = cc.getFQInterfaceName();
            className = cc.getInterfaceName();
            sb.append("\t/** The ");
            // if (cc.isDirect) {// w  ww  . j av  a 2 s . co  m
            // sb.append("{@link DirectMappingType} ");
            // }
            sb.append("{@link ");
            sb.append(className);
            sb.append("}. */\n");
            sb.append("\t@Autowired\n");
            sb.append("\tprivate ");
            sb.append(className);
            sb.append(" ");
            sb.append(varName);
            sb.append(";\n");
        }
    }));
    return sb.toString();
}

From source file:com.miz.mizuu.AddNetworkFilesourceDialog.java

@SuppressLint("UseSparseArrays")
public void search(View v) {
    final ArrayList<FileSource> sources = new ArrayList<FileSource>();

    DbAdapterSources dbHelper = MizuuApplication.getSourcesAdapter();

    // Fetch all movie sources and add them to the array
    Cursor cursor = dbHelper.fetchAllSources();
    while (cursor.moveToNext()) {
        if (cursor.getInt(cursor.getColumnIndex(DbAdapterSources.KEY_FILESOURCE_TYPE)) == FileSource.SMB)
            sources.add(new FileSource(cursor.getLong(cursor.getColumnIndex(DbAdapterSources.KEY_ROWID)),
                    cursor.getString(cursor.getColumnIndex(DbAdapterSources.KEY_FILEPATH)),
                    cursor.getInt(cursor.getColumnIndex(DbAdapterSources.KEY_FILESOURCE_TYPE)),
                    cursor.getString(cursor.getColumnIndex(DbAdapterSources.KEY_USER)),
                    cursor.getString(cursor.getColumnIndex(DbAdapterSources.KEY_PASSWORD)),
                    cursor.getString(cursor.getColumnIndex(DbAdapterSources.KEY_DOMAIN)),
                    cursor.getString(cursor.getColumnIndex(DbAdapterSources.KEY_TYPE))));
    }//from   w  w  w  .j  a  v a  2 s  .c  o m

    cursor.close();

    TreeSet<String> uniqueSources = new TreeSet<String>();

    int count = sources.size();
    for (int i = 0; i < count; i++) {
        String temp = sources.get(i).getFilepath().replace("smb://", "");
        temp = temp.substring(0, temp.indexOf("/"));
        uniqueSources.add(temp);
    }

    final CharSequence[] items = new CharSequence[uniqueSources.size() + 1];

    count = 0;
    Iterator<String> it = uniqueSources.iterator();
    while (it.hasNext()) {
        items[count] = it.next();
        count++;
    }

    items[items.length - 1] = getString(R.string.scanForSources);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.browseSources));
    builder.setItems(items, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            if (which == (items.length - 1)) {
                Intent intent = new Intent();
                intent.setClass(getApplicationContext(), SearchForNetworkShares.class);
                startActivity(intent);
            } else {
                showUserDialog(items, which);
            }
        }
    });
    builder.show();
}

From source file:com.inmobi.databus.local.LocalStreamService.java

protected String getCurrentFile(FileSystem fs, FileStatus[] files, long lastFileTimeout) {
    //Proposed Algo :-> Sort files based on timestamp
    //if ((currentTimeStamp - last file's timestamp) > 5min ||
    //     if there are no files)
    // then null (implying process this file as non-current file)
    // else//from   w  ww .  j  a  v  a  2  s .c  om
    // return last file as the current file
    class FileTimeStampComparator implements Comparator {
        public int compare(Object o, Object o1) {
            FileStatus file1 = (FileStatus) o;
            FileStatus file2 = (FileStatus) o1;
            long file1Time = file1.getModificationTime();
            long file2Time = file2.getModificationTime();
            if ((file1Time < file2Time))
                return -1;
            else
                return 1;
        }
    }

    if (files == null || files.length == 0)
        return null;
    TreeSet<FileStatus> sortedFiles = new TreeSet<FileStatus>(new FileTimeStampComparator());
    for (FileStatus file : files) {
        sortedFiles.add(file);
    }

    //get last file from set
    FileStatus lastFile = sortedFiles.last();

    long currentTime = System.currentTimeMillis();
    long lastFileTime = lastFile.getModificationTime();
    if (currentTime - lastFileTime >= lastFileTimeout) {
        return null;
    } else
        return lastFile.getPath().getName();
}