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(SortedSet<E> s) 

Source Link

Document

Constructs a new tree set containing the same elements and using the same ordering as the specified sorted set.

Usage

From source file:br.com.ingenieux.mojo.beanstalk.env.TagEnvironmentMojo.java

@Override
protected Object executeInternal() throws AbstractMojoExecutionException {
    Set<String> configTemplates = new TreeSet<String>(super.getConfigurationTemplates(applicationName));
    String today = DATE_FORMAT.format(new Date());

    if (StringUtils.isBlank(templateName)) {
        int i = 1;

        do {/*from   www .j av  a 2  s  . c om*/
            templateName = String.format("%s-%s-%02d", curEnv.getEnvironmentName(), today, i++);
        } while (configTemplates.contains(templateName));
    }

    CreateConfigurationTemplateResult result = getService().createConfigurationTemplate(
            new CreateConfigurationTemplateRequest().withEnvironmentId(curEnv.getEnvironmentId())
                    .withTemplateName(templateName).withApplicationName(curEnv.getApplicationName()));

    getLog().info("Created config template " + templateName + " for environment " + curEnv.getEnvironmentId());

    return result;
}

From source file:info.magnolia.cms.beans.config.Bootstrapper.java

/**
 * Repositories appears to be empty and the <code>"magnolia.bootstrap.dir</code> directory is configured in
 * web.xml. Loops over all the repositories and try to load any xml file found in a subdirectory with the same name
 * of the repository. For example the <code>config</code> repository will be initialized using all the
 * <code>*.xml</code> files found in <code>"magnolia.bootstrap.dir</code><strong>/config</strong> directory.
 * @param bootdirs bootstrap dir//  w  w w . j  ava2 s. co  m
 */
protected static void bootstrapRepositories(String[] bootdirs) {

    if (log.isInfoEnabled()) {
        log.info("-----------------------------------------------------------------"); //$NON-NLS-1$
        log.info("Trying to initialize repositories from:");
        for (int i = 0; i < bootdirs.length; i++) {
            log.info(bootdirs[i]);
        }
        log.info("-----------------------------------------------------------------"); //$NON-NLS-1$
    }

    MgnlContext.setInstance(MgnlContext.getSystemContext());

    Iterator repositoryNames = ContentRepository.getAllRepositoryNames();
    while (repositoryNames.hasNext()) {
        String repository = (String) repositoryNames.next();

        Set xmlfileset = new TreeSet(new Comparator() {

            // remove file with the same name in different dirs
            public int compare(Object file1obj, Object file2obj) {
                File file1 = (File) file1obj;
                File file2 = (File) file2obj;
                String fn1 = file1.getParentFile().getName() + '/' + file1.getName();
                String fn2 = file2.getParentFile().getName() + '/' + file2.getName();
                return fn1.compareTo(fn2);
            }
        });

        for (int j = 0; j < bootdirs.length; j++) {
            String bootdir = bootdirs[j];
            File xmldir = new File(bootdir, repository);
            if (!xmldir.exists() || !xmldir.isDirectory()) {
                continue;
            }

            File[] files = xmldir.listFiles(new FilenameFilter() {

                public boolean accept(File dir, String name) {
                    return name.endsWith(DataTransporter.XML) || name.endsWith(DataTransporter.ZIP)
                            || name.endsWith(DataTransporter.GZ); //$NON-NLS-1$
                }
            });

            xmlfileset.addAll(Arrays.asList(files));

        }

        if (xmlfileset.isEmpty()) {
            log.info("No bootstrap files found in directory [{}], skipping...", repository); //$NON-NLS-1$
            continue;
        }

        log.info("Trying to import content from {} files into repository [{}]", //$NON-NLS-1$
                Integer.toString(xmlfileset.size()), repository);

        File[] files = (File[]) xmlfileset.toArray(new File[xmlfileset.size()]);
        Arrays.sort(files, new Comparator() {

            public int compare(Object file1, Object file2) {
                String name1 = StringUtils.substringBeforeLast(((File) file1).getName(), "."); //$NON-NLS-1$
                String name2 = StringUtils.substringBeforeLast(((File) file2).getName(), "."); //$NON-NLS-1$
                // a simple way to detect nested nodes
                return name1.length() - name2.length();
            }
        });

        try {
            for (int k = 0; k < files.length; k++) {

                File xmlfile = files[k];
                DataTransporter.executeBootstrapImport(xmlfile, repository);
            }

        } catch (IOException ioe) {
            log.error(ioe.getMessage(), ioe);
        } catch (OutOfMemoryError e) {
            int maxMem = (int) (Runtime.getRuntime().maxMemory() / 1024 / 1024);
            int needed = Math.max(256, maxMem + 128);
            log.error("Unable to complete bootstrapping: out of memory.\n" //$NON-NLS-1$
                    + "{} MB were not enough, try to increase the amount of memory available by adding the -Xmx{}m parameter to the server startup script.\n" //$NON-NLS-1$
                    + "You will need to completely remove the magnolia webapp before trying again", //$NON-NLS-1$
                    Integer.toString(maxMem), Integer.toString(needed));
            break;
        }

        log.info("Repository [{}] has been initialized.", repository); //$NON-NLS-1$

    }
}

From source file:net.sourceforge.fenixedu.dataTransferObject.InfoSiteEvaluations.java

public Collection<WrittenEvaluation> getSortedWrittenEvaluations() {
    final Collection<WrittenEvaluation> sortedWrittenEvaluations = new TreeSet<WrittenEvaluation>(comparator);
    for (final Evaluation evaluation : getEvaluations()) {
        if (evaluation instanceof WrittenEvaluation) {
            sortedWrittenEvaluations.add((WrittenEvaluation) evaluation);
        }// w w  w .j  av a 2  s.com
    }
    return sortedWrittenEvaluations;
}

From source file:de.shadowhunt.subversion.internal.ListOperation.java

@Override
@CheckForNull/*from   w  w w .  j a  v a  2s. c  o  m*/
protected Set<Info> processResponse(final HttpResponse response) throws IOException {
    if (getStatusCode(response) == HttpStatus.SC_NOT_FOUND) {
        return null;
    }

    final Set<Info> result = new TreeSet<>(Info.RESOURCE_COMPARATOR);
    final List<Info> infoList = InfoImplReader.readAll(getContent(response));
    result.addAll(infoList);
    return result;
}

From source file:org.wallride.support.PageUtils.java

public List<TreeNode<Page>> getNodes(boolean includeUnpublished) {
    PageSearchRequest request = new PageSearchRequest();
    if (!includeUnpublished) {
        request.setStatus(Post.Status.PUBLISHED);
    }//from  ww w . jav a2  s .com
    Collection<Page> pages = new TreeSet<>(pageService.getPages(request).getContent());

    List<TreeNode<Page>> rootNodes = new ArrayList<>();
    Iterator<Page> i = pages.iterator();
    while (i.hasNext()) {
        Page page = i.next();
        if (page.getParent() == null) {
            TreeNode<Page> node = new TreeNode<>(page);
            rootNodes.add(node);
            i.remove();
        }
    }

    for (TreeNode<Page> node : rootNodes) {
        createNode(node, pages);
    }
    return rootNodes;
}

From source file:app.core.Db.java

public static Set<Class> getEntityClassList() {
    SortedSet<Class> classes = new TreeSet<Class>(new ORMUtils.DependencyComparator());
    SessionFactory sessionFactory = getSessionFactory();
    try {// w  w w .  j a va 2s.com
        for (String className : sessionFactory.getAllClassMetadata().keySet()) {
            classes.add(Class.forName(className));
        }
    } catch (ClassNotFoundException e) {
        //log();
    }
    return classes;
}

From source file:br.com.ingenieux.mojo.simpledb.cmd.PutAttributesCommand.java

private void createIfNeeded(PutAttributesContext ctx) {
    Set<String> domainSet = new TreeSet<String>(service.listDomains().getDomainNames());

    if (!domainSet.contains(ctx.getDomain()))
        service.createDomain(new CreateDomainRequest(ctx.domain));
}

From source file:com.github.springtestdbunit.entity.EntityAssert.java

public void assertValues(String... values) {
    SortedSet<String> expected = new TreeSet<String>(Arrays.asList(values));
    SortedSet<String> actual = new TreeSet<String>();
    TypedQuery<SampleEntity> query = this.entityManager.createQuery(this.criteriaQuery);
    List<SampleEntity> results = query.getResultList();
    for (SampleEntity sampleEntity : results) {
        actual.add(sampleEntity.getValue());
        this.entityManager.detach(sampleEntity);
    }/*  ww  w .  j  a  v a  2  s  .  co  m*/
    assertEquals(expected, actual);
}

From source file:com.spotify.heroic.metric.TagValues.java

public static List<TagValues> fromEntries(final Iterator<Map.Entry<String, String>> entries) {
    final Map<String, SortedSet<String>> key = new HashMap<>();

    while (entries.hasNext()) {
        final Map.Entry<String, String> e = entries.next();

        SortedSet<String> values = key.get(e.getKey());

        if (values == null) {
            values = new TreeSet<String>(COMPARATOR);
            key.put(e.getKey(), values);
        }/*from  ww  w .  ja va  2s.  co  m*/

        values.add(e.getValue());
    }

    final List<TagValues> group = new ArrayList<>(key.size());

    for (final Map.Entry<String, SortedSet<String>> e : key.entrySet()) {
        group.add(new TagValues(e.getKey(), new ArrayList<>(e.getValue())));
    }

    return group;
}

From source file:de.metanome.algorithm_integration.ColumnConditionOr.java

public ColumnConditionOr(TreeSet<ColumnCondition> treeSet) {
    this.columnValues = new TreeSet<>(treeSet);
}