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:storybook.ui.chart.jfreechart.ChartUtil.java

@SuppressWarnings("unchecked")
public static TreeSet<Date> correctDates(TreeSet<Date> paramTreeSet) {
    TreeSet localTreeSet = new TreeSet();
    Date localDate1 = (Date) paramTreeSet.first();
    Calendar localCalendar1 = Calendar.getInstance();
    localCalendar1.setTime(localDate1);/*from   w  w  w .j  a va2 s .c  om*/
    int i = localCalendar1.get(Calendar.YEAR);
    if (i > 1900) {
        return paramTreeSet;
    }
    for (Date localDate2 : paramTreeSet) {
        Calendar localCalendar2 = Calendar.getInstance();
        localCalendar2.setTime(localDate2);
        int j = localCalendar2.get(Calendar.YEAR);
        localDate2 = DateUtils.addYears(localDate2, 1900 - j);
        localTreeSet.add(localDate2);
    }
    return localTreeSet;
}

From source file:emperior.Main.java

public static TreeSet<Integer> generateSortedSet(Set<Integer> lineNumbers) {
    TreeSet<Integer> treeSet = new TreeSet<Integer>();
    for (Integer lineNumber : lineNumbers) {
        treeSet.add(lineNumber);
    }//w  ww.j  a va  2 s .  com
    return treeSet;
}

From source file:ImageIOTest.java

/**
 * Gets a set of "preferred" format names of all image writers. The preferred format name is the
 * first format name that a writer specifies.
 * @return the format name set/* w ww  . j  ava  2  s .c o m*/
 */
public static Set<String> getWriterFormats() {
    TreeSet<String> writerFormats = new TreeSet<String>();
    TreeSet<String> formatNames = new TreeSet<String>(Arrays.asList(ImageIO.getWriterFormatNames()));
    while (formatNames.size() > 0) {
        String name = formatNames.iterator().next();
        Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName(name);
        ImageWriter writer = iter.next();
        String[] names = writer.getOriginatingProvider().getFormatNames();
        String format = names[0];
        if (format.equals(format.toLowerCase()))
            format = format.toUpperCase();
        writerFormats.add(format);
        formatNames.removeAll(Arrays.asList(names));
    }
    return writerFormats;
}

From source file:com.github.mbenson.privileged.weaver.PrivilegedMethodWeaver.java

private static Set<CtMethod> getPrivilegedMethods(CtClass type) throws ClassNotFoundException {
    final TreeSet<CtMethod> result = new TreeSet<CtMethod>(CTMETHOD_COMPARATOR);
    for (final CtMethod m : type.getDeclaredMethods()) {
        if (Modifier.isAbstract(m.getModifiers()) || m.getAnnotation(Privileged.class) == null) {
            continue;
        }//from  w w w . jav a  2s.c o  m
        result.add(m);
    }
    return result;
}

From source file:com.android.calendar.event.EventLocationAdapter.java

/**
 * Post-process the query results to return the first MAX_LOCATION_SUGGESTIONS
 * unique locations in alphabetical order.
 * <p/>/* w w  w.  j ava 2  s. c  o  m*/
 * TODO: Refactor to share code with the recent titles auto-complete.
 */
private static List<Result> processLocationsQueryResults(Cursor cursor) {
    TreeSet<String> locations = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    cursor.moveToPosition(-1);

    // Remove dupes.
    while ((locations.size() < MAX_LOCATION_SUGGESTIONS) && cursor.moveToNext()) {
        String location = cursor.getString(EVENT_INDEX_LOCATION).trim();
        locations.add(location);
    }

    // Copy the sorted results.
    List<Result> results = new ArrayList<Result>();
    for (String location : locations) {
        results.add(new Result(null, location, R.drawable.ic_history_holo_light, null));
    }
    return results;
}

From source file:edu.umass.cs.utils.Util.java

public static Set<Integer> arrayToIntSet(int[] array) {
    TreeSet<Integer> set = new TreeSet<Integer>();
    for (int i = 0; i < array.length; i++) {
        set.add(array[i]);
    }/*ww w .  j a  v a2  s.  c o m*/
    return set;
}

From source file:gobblin.util.ConfigUtils.java

/**
 * Finds a list of properties whose keys are complete prefix of other keys. This function is
 * meant to be used during conversion from Properties to typesafe Config as the latter does not
 * support this scenario./* w  ww . j  a  v a 2  s. co  m*/
 * @param     properties      the Properties collection to inspect
 * @param     keyPrefix       an optional key prefix which limits which properties are inspected.
 * */
public static Set<String> findFullPrefixKeys(Properties properties, Optional<String> keyPrefix) {
    TreeSet<String> propNames = new TreeSet<>();
    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        String entryKey = entry.getKey().toString();
        if (StringUtils.startsWith(entryKey, keyPrefix.or(StringUtils.EMPTY))) {
            propNames.add(entryKey);
        }
    }

    Set<String> result = new HashSet<>();
    String lastKey = null;
    Iterator<String> sortedKeysIter = propNames.iterator();
    while (sortedKeysIter.hasNext()) {
        String propName = sortedKeysIter.next();
        if (null != lastKey && propName.startsWith(lastKey + ".")) {
            result.add(lastKey);
        }
        lastKey = propName;
    }

    return result;
}

From source file:base.Engine.java

static Set<TreeSet<PatternInstance>> resolveTree(Set<TreeSet<PatternInstance>> returnSet,
        Set<PatternInstance> colls) {
    TreeSet<PatternInstance> workingTree = new TreeSet<>(new InstanceComparator());
    for (PatternInstance p : colls) {
        TreeSet<PatternInstance> onThisTree = null;
        for (TreeSet<PatternInstance> it : returnSet) {
            if (it.contains(p)) {
                onThisTree = it;// w  ww  .j  a v a2  s  .  c  o m
                break;
            }
        }

        if (onThisTree == null) {
            workingTree.add(p);
        } else {
            workingTree.addAll(onThisTree);
            returnSet.remove(onThisTree);
        }
    }
    returnSet.add(workingTree);
    return returnSet;
}

From source file:it.unibz.instasearch.prefs.PreferenceInitializer.java

/**
 * Get extensions that Eclipse knows of and the default ones
 * @return comma separated string of extensions
 *///from  w  w  w. ja  va2  s. c o  m
public static String getIndexableExtensions() {
    String defaultExtArray[] = DEFAULT_EXTENSIONS.split(",");

    TreeSet<String> extensions = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    extensions.addAll(Arrays.asList(defaultExtArray));

    IFileEditorMapping[] allMappings = ((EditorRegistry) PlatformUI.getWorkbench().getEditorRegistry())
            .getUnifiedMappings();

    IContentType text = Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT);

    for (int i = 0; i < allMappings.length; i++) {
        if (allMappings[i].getName().equals("*")) {
            String ext = allMappings[i].getExtension();
            IContentType type = Platform.getContentTypeManager().findContentTypeFor("." + ext);

            if (type != null && type.isKindOf(text))
                extensions.add(ext);
        }
    }

    IContentType[] types = Platform.getContentTypeManager().getAllContentTypes();
    for (IContentType type : types) {
        if (type.isKindOf(text)) {
            String exts[] = type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
            extensions.addAll(Arrays.asList(exts));
        }
    }

    return StringUtils.join(extensions.toArray(), ",");
}

From source file:com.hoho.android.usbserial.examples.SerialConsoleActivity.java

static void parseGesture() {
    int len = gestureRaw.size();
    if (len >= stopSize) {
        boolean check = true;
        int finalState = gestureRaw.get(len - 1);
        for (int i = 0; i < stopSize; i++) {
            if (gestureRaw.get(len - 1 - i) != finalState) {
                check = false;//from   w w w .  j av a  2 s . com
                break;
            }
        }
        if (check) {
            gestureParse.clear();
            int c1 = 1, pstate = gestureRaw.get(0);
            if (pstate != 0)
                gestureParse.add(pstate);
            for (Integer state : gestureRaw) {
                if (c1 == 1 && state == pstate)
                    continue;
                else {
                    if (state != 0)
                        gestureParse.add(state);

                    pstate = state;
                    c1 = 0;
                }
            }
            gestureRaw.clear();
            while (gestureParse.size() >= 2
                    && gestureParse.get(gestureParse.size() - 1) == gestureParse.get(gestureParse.size() - 2)) {
                gestureParse.remove(gestureParse.size() - 1);
            }
            TreeSet<Integer> size = new TreeSet<Integer>();
            for (Integer integer : gestureParse) {
                size.add(integer);
            }
            if (gestureParse.size() >= gestureSize && size.size() > 2) {
                System.err.println(gestureParse);
                gestureToWrite.clear();
                int length = gestureParse.size(); //  gestureToWrite size is always  numberOfGuestureInputs
                int filled = 0;
                for (int i = 1; i <= length; i++) {
                    int upto = (numberOfGuestureInputs - 1) * i / length;
                    for (; filled <= upto; filled++) {
                        gestureToWrite.add(gestureParse.get(i - 1));
                    }

                }
                if (recognize) {
                    g = svmg.getPrediction(gestureToWrite);
                    gestureF = g + 1;
                    updateGesture = true;
                    System.out.println("gesture: " + g);

                }
            }
        }
    }
}