Example usage for java.util TreeSet TreeSet

List of usage examples for java.util TreeSet TreeSet

Introduction

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

Prototype

public TreeSet() 

Source Link

Document

Constructs a new, empty tree set, sorted according to the natural ordering of its elements.

Usage

From source file:edu.harvard.med.screensaver.ui.arch.util.converter.EmptyWellsConverter.java

public String getAsString(FacesContext context, UIComponent component, Object value) throws ConverterException {
    if (value == null) {
        return "";
    }/*from www  . j av a  2  s . c o m*/
    Set<WellName> wellNames = new TreeSet<WellName>();
    wellNames.addAll((Set<WellName>) value);
    StringBuilder s = new StringBuilder();
    Set<WellName> toRemove = new HashSet<WellName>();
    for (Integer fullColumn : getFullColumns(wellNames)) {
        if (s.length() > 0) {
            s.append(DELIMITER);
        }
        s.append("Col:").append(WellName.getColumnLabel(fullColumn));
        toRemove.addAll(makeFullColumn(fullColumn));
    }
    for (Integer fullRow : getFullRows(wellNames)) {
        if (s.length() > 0) {
            s.append(DELIMITER);
        }
        s.append("Row:").append(WellName.getRowLabel(fullRow));
        toRemove.addAll(makeFullRow(fullRow));
    }
    wellNames.removeAll(toRemove);
    if (s.length() > 0 && wellNames.size() > 0) {
        s.append(DELIMITER);
    }
    s.append(StringUtils.join(wellNames.iterator(), DELIMITER));
    return s.toString();
}

From source file:org.openmrs.module.distrotools.AbstractOrderedDescriptorTest.java

@Test
public void compareTo() {
    TreeSet<TestDescriptor> tree = new TreeSet<TestDescriptor>();
    tree.add(descriptor3);//from   w w w .  ja v  a  2  s .c  o m
    tree.add(descriptor2);
    tree.add(descriptor1);

    Assert.assertThat(tree, contains(descriptor1, descriptor2, descriptor3));
}

From source file:net.leegorous.jsc.TestJavaScriptDocument.java

public void testFindImportException() throws Exception {
    File file = new File(getFileName("/scripts/test/pkg/n1.js"));
    Set classpath = new TreeSet();
    classpath.add(new File(getFileName("/scripts/test")));
    try {//from  w  w  w .j av a 2 s.  c om
        JavaScriptDocument jsdoc = new JavaScriptDocument(null, file, classpath);
        jsdoc.findImports();
        fail("Cycle import exception excepted.");
    } catch (LoopedImportException e) {
        assertNotNull(e.getMessage());
    } catch (Exception e) {
        fail("Exception unexcepted.");
    }
}

From source file:com.sap.research.connectivity.gw.converters.GwEndpointConverter.java

public boolean getAllPossibleValues(final List<Completion> completions, final Class<?> requiredType,
        String existingData, final String optionContext, final MethodTarget target) {

    existingData = StringUtils.stripToEmpty(existingData);

    // Search for all files matching the pattern *_metadata.xml (we assume that the connectivity class corresponding to the endpoint xml 
    // contains the same name (e.g. gw1.java and gw1_metadata.xml)
    SortedSet<FileDetails> files = new TreeSet<FileDetails>();
    if (!optionContext.isEmpty()) {
        files = fileManager/*from w  w  w.j a  v  a 2  s .c o  m*/
                .findMatchingAntPath(getSubPackagePath(optionContext) + SEPARATOR + "*_metadata.xml");
    }

    String filePath = "", nameSpace = "";
    for (FileDetails f : files) {
        filePath = f.getCanonicalPath();
        nameSpace = filePath.substring(filePath.lastIndexOf(SEPARATOR) + 1,
                filePath.lastIndexOf("_metadata.xml"));
        completions.add(new Completion(nameSpace));
    }

    return false;
}

From source file:org.brutusin.rpc.RpcUtils.java

public static Set<String> getUserRoles(Object securityContext) {
    Set<String> roleSet = new TreeSet<String>();
    if (securityContext != null) {
        SecurityContext sc = (SecurityContext) securityContext;
        Collection<? extends GrantedAuthority> authorities = sc.getAuthentication().getAuthorities();
        for (GrantedAuthority authority : authorities) {
            String auth = authority.getAuthority();
            if (auth.startsWith("ROLE_")) {
                auth = auth.substring(5);
            }//from   w w  w  . ja v  a2s  .  co  m
            roleSet.add(auth);
        }
    }
    return Collections.unmodifiableSet(roleSet);
}

From source file:com.incapture.rapgen.output.OutputWriter.java

/**
 * Some files are composed of multiple templates. So the map passed in here is filename to template order to template.
 * E.g. "file.txt"->1->"some code" "file.txt"->2->"other code" and so on.
 *
 * @param rootFolder/*from  www .  jav  a2 s .co m*/
 * @param pathToTemplate
 */
public static void writeMultiPartTemplates(String rootFolder,
        Map<String, Map<String, StringTemplate>> pathToTemplate) {
    // For each file, dump the templates
    for (Map.Entry<String, Map<String, StringTemplate>> entry : pathToTemplate.entrySet()) {
        File file = new File(rootFolder, entry.getKey());
        file.getParentFile().mkdirs();

        BufferedWriter bow = null;
        try {
            bow = new BufferedWriter(new FileWriter(file));
            Set<String> sections = entry.getValue().keySet();
            SortedSet<String> sorted = new TreeSet<String>();
            sorted.addAll(sections);
            for (String sec : sorted) {
                bow.write(entry.getValue().get(sec).toString());
                bow.newLine();
            }
            bow.close();
        } catch (IOException e) {
            System.err.println(e.getMessage());
        } finally {
            if (bow != null) {
                try {
                    bow.close();
                } catch (IOException e) {
                    System.err.println("Error closing output stream: " + ExceptionToString.format(e));
                }
            }
        }
    }
}

From source file:com.cloudbees.plugins.credentials.oauth.OAuth2Client.java

@DataBoundConstructor
public OAuth2Client(String name, String clientId, String clientSecret, JSONObject scopes) {
    this.name = name;
    this.clientId = clientId;
    this.scopes = new TreeSet<String>();
    if (scopes != null) {
        for (Object scope : scopes.keySet()) {
            if (scope instanceof String && scopes.getBoolean((String) scope)) {
                this.scopes.add((String) scope);
            }//from   ww  w . jav  a 2  s. c  o m
        }
    }
    this.clientSecret = Secret.fromString(clientSecret);
}

From source file:com.spotify.heroic.filter.impl.OrFilterImpl.java

private static Filter optimize(SortedSet<Filter> statements) {
    final SortedSet<Filter> result = new TreeSet<>();

    root: for (final Filter f : statements) {
        if (f instanceof Filter.Not) {
            final Filter.Not not = (Filter.Not) f;

            if (statements.contains(not.first())) {
                return TrueFilterImpl.get();
            }/*from   w ww .  java2s  . c  o  m*/

            result.add(f);
            continue;
        }

        if (f instanceof Filter.StartsWith) {
            final Filter.StartsWith outer = (Filter.StartsWith) f;

            for (final Filter inner : statements) {
                if (inner.equals(outer)) {
                    continue;
                }

                if (inner instanceof Filter.StartsWith) {
                    final Filter.StartsWith starts = (Filter.StartsWith) inner;

                    if (!outer.first().equals(starts.first())) {
                        continue;
                    }

                    if (FilterComparatorUtils.prefixedWith(outer.second(), starts.second())) {
                        continue root;
                    }
                }
            }

            result.add(f);
            continue;
        }

        // all ok!
        result.add(f);
    }

    if (result.isEmpty()) {
        return TrueFilterImpl.get();
    }

    if (result.size() == 1) {
        return result.iterator().next();
    }

    return new OrFilterImpl(new ArrayList<>(result));
}

From source file:avantssar.aslanpp.testing.DiskSpecificationsProvider.java

public DiskSpecificationsProvider(String baseDirectory) {
    File base = new File(baseDirectory);
    if (!base.exists() || !base.isDirectory()) {
        throw new IllegalArgumentException(
                "Path '" + baseDirectory + "' cannot be accessed or does not point to a directory.");
    }//from w  ww . ja  va 2s.co  m
    IOFileFilter filter = FileFilterUtils.suffixFileFilter(".aslan++");
    IOFileFilter dirFilter = FileFilterUtils.makeCVSAware(FileFilterUtils.makeSVNAware(null));
    Collection<File> specs = FileUtils.listFiles(base, filter, dirFilter);
    List<String> forSort = new ArrayList<String>();
    SortedSet<String> forASLanPath = new TreeSet<String>();
    for (File f : specs) {
        if (isSpec(f)) {
            forSort.add(f.getAbsolutePath());
            forASLanPath.add(f.getParent());
        }
    }
    Collections.sort(forSort);
    for (String s : forSort) {
        add(new DiskTestTask(new File(s)));
    }
    String temp = "";
    for (String s : forASLanPath) {
        if (temp.length() > 0) {
            temp += File.pathSeparator;
        }
        temp += s;
    }
    aslanPath = temp;
}

From source file:com.baidu.cc.web.filter.AuthCheckFilter.java

@Override
protected void doInit(FilterConfig filterConfig) throws ServletException {
    includePathv = new TreeSet<String>();
    if (includePath != null) {
        String[] paths = includePath.split(";\n?");
        for (String p : paths) {
            if (p != null && p.length() > 0)
                includePathv.add(p.trim());
        }//from   w w  w  . ja v  a 2 s  .com
    }

    accessSettingService = (AccessSettingService) ServiceLocator.getInstance().getBean("accessSettingService");
}