Example usage for java.util TreeSet addAll

List of usage examples for java.util TreeSet addAll

Introduction

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

Prototype

public boolean addAll(Collection<? extends E> c) 

Source Link

Document

Adds all of the elements in the specified collection to this set.

Usage

From source file:com.metamx.druid.utils.ExposeS3DataSource.java

public static void main(String[] args) throws ServiceException, IOException, NoSuchAlgorithmException {
    CLI cli = new CLI();
    cli.addOption(new RequiredOption(null, "s3Bucket", true, "s3 bucket to pull data from"));
    cli.addOption(new RequiredOption(null, "s3Path", true,
            "base input path in s3 bucket.  Everything until the date strings."));
    cli.addOption(new RequiredOption(null, "timeInterval", true, "ISO8601 interval of dates to index"));
    cli.addOption(new RequiredOption(null, "granularity", true, String.format(
            "granularity of index, supported granularities: [%s]", Arrays.asList(Granularity.values()))));
    cli.addOption(new RequiredOption(null, "zkCluster", true, "Cluster string to connect to ZK with."));
    cli.addOption(new RequiredOption(null, "zkBasePath", true, "The base path to register index changes to."));

    CommandLine commandLine = cli.parse(args);

    if (commandLine == null) {
        return;/*  ww  w .  j a  v a 2 s .  c  o  m*/
    }

    String s3Bucket = commandLine.getOptionValue("s3Bucket");
    String s3Path = commandLine.getOptionValue("s3Path");
    String timeIntervalString = commandLine.getOptionValue("timeInterval");
    String granularity = commandLine.getOptionValue("granularity");
    String zkCluster = commandLine.getOptionValue("zkCluster");
    String zkBasePath = commandLine.getOptionValue("zkBasePath");

    Interval timeInterval = new Interval(timeIntervalString);
    Granularity gran = Granularity.valueOf(granularity.toUpperCase());
    final RestS3Service s3Client = new RestS3Service(new AWSCredentials(
            System.getProperty("com.metamx.aws.accessKey"), System.getProperty("com.metamx.aws.secretKey")));
    ZkClient zkClient = new ZkClient(new ZkConnection(zkCluster), Integer.MAX_VALUE, new StringZkSerializer());

    zkClient.waitUntilConnected();

    for (Interval interval : gran.getIterable(timeInterval)) {
        log.info("Processing interval[%s]", interval);
        String s3DatePath = JOINER.join(s3Path, gran.toPath(interval.getStart()));
        if (!s3DatePath.endsWith("/")) {
            s3DatePath += "/";
        }

        StorageObjectsChunk chunk = s3Client.listObjectsChunked(s3Bucket, s3DatePath, "/", 2000, null, true);
        TreeSet<String> commonPrefixes = Sets.newTreeSet();
        commonPrefixes.addAll(Arrays.asList(chunk.getCommonPrefixes()));

        if (commonPrefixes.isEmpty()) {
            log.info("Nothing at s3://%s/%s", s3Bucket, s3DatePath);
            continue;
        }

        String latestPrefix = commonPrefixes.last();

        log.info("Latest segments at [s3://%s/%s]", s3Bucket, latestPrefix);

        chunk = s3Client.listObjectsChunked(s3Bucket, latestPrefix, "/", 2000, null, true);
        Integer partitionNumber;
        if (chunk.getCommonPrefixes().length == 0) {
            partitionNumber = null;
        } else {
            partitionNumber = -1;
            for (String partitionPrefix : chunk.getCommonPrefixes()) {
                String[] splits = partitionPrefix.split("/");
                partitionNumber = Math.max(partitionNumber, Integer.parseInt(splits[splits.length - 1]));
            }
        }

        log.info("Highest segment partition[%,d]", partitionNumber);

        if (partitionNumber == null) {
            final S3Object s3Obj = new S3Object(new S3Bucket(s3Bucket),
                    String.format("%sdescriptor.json", latestPrefix));
            updateWithS3Object(zkBasePath, s3Client, zkClient, s3Obj);
        } else {
            for (int i = partitionNumber; i >= 0; --i) {
                final S3Object partitionObject = new S3Object(new S3Bucket(s3Bucket),
                        String.format("%s%s/descriptor.json", latestPrefix, i));

                updateWithS3Object(zkBasePath, s3Client, zkClient, partitionObject);
            }
        }
    }
}

From source file:Main.java

public static void main(String[] args) {

    TreeSet<Integer> treeone = new TreeSet<Integer>();
    TreeSet<Integer> treetwo = new TreeSet<Integer>();

    treeone.add(12);//from w w w.j  a  v  a  2  s.  c  om
    treeone.add(13);
    treeone.add(14);

    treetwo.add(15);
    treetwo.add(16);
    treetwo.add(17);

    // adding treetwo to treeone
    treeone.addAll(treetwo);

    Iterator<Integer> iterator = treeone.iterator();

    while (iterator.hasNext()) {
        System.out.print(iterator.next());
    }
}

From source file:org.unitime.timetable.solver.curricula.students.CurModel.java

public static void main(String[] args) {
    try {/*from ww  w .  j  a  va2s.  com*/
        Logger.getRootLogger().setLevel(Level.DEBUG);

        List<CurStudent> students = new ArrayList<CurStudent>();
        for (int i = 0; i < 20; i++)
            students.add(new CurStudent(new Long(1 + i), (i < 10 ? 0.5f : 2f)));
        CurModel m = new CurModel(students);
        for (int i = 1; i <= 10; i++)
            m.addCourse((long) i, "C" + i, 2 * i, null);
        for (int i = 1; i < 10; i++)
            for (int j = i + 1; j <= 10; j++)
                m.setTargetShare((long) i, (long) j, i, false);
        m.setStudentLimits();

        Document d0 = DocumentHelper.createDocument();
        Assignment<CurVariable, CurValue> a = new DefaultSingleAssignment<CurVariable, CurValue>();
        m.saveAsXml(d0.addElement("curriculum"), a);
        sLog.info(d0.asXML());

        sLog.info("Loaded: " + ToolBox.dict2string(m.getInfo(a), 2));

        m.solve(a);

        sLog.info("Solution: " + ToolBox.dict2string(m.getInfo(a), 2));

        Document d1 = DocumentHelper.createDocument();
        m.saveAsXml(d1.addElement("curriculum"), a);
        sLog.info(d1.asXML());

        Solution<CurVariable, CurValue> x = loadFromXml(d1.getRootElement());
        sLog.info("Reloaded: " + ToolBox.dict2string(x.getInfo(), 2));

        TreeSet<CurCourse> courses = new TreeSet<CurCourse>(new Comparator<CurCourse>() {
            public int compare(CurCourse c1, CurCourse c2) {
                int cmp = c1.getCourseName().compareTo(c2.getCourseName());
                if (cmp != 0)
                    return cmp;
                return c1.getCourseId().compareTo(c2.getCourseId());
            }
        });
        courses.addAll(m.getCourses());
        int penalty = 0;
        for (CurCourse course : courses) {
            sLog.info(course.getCourseName() + ": " + m.getCourse(course.getCourseId()).getStudents(a) + " ("
                    + course.getSize(a) + "/" + course.getOriginalMaxSize() + ")");
            for (CurCourse other : courses) {
                if (other.getCourseId() <= course.getCourseId())
                    continue;
                double share = course.share(a, other);
                double target = course.getTargetShare(other.getCourseId());
                sLog.info("  " + other.getCourseName() + ": share=" + share + ", target=" + target
                        + ", penalty=" + Math.abs(target - share));
                penalty += Math.abs(target - share);
            }
        }
        sLog.info("Total penalty: " + penalty);

        Document doc = DocumentHelper.createDocument();
        m.saveAsXml(doc.addElement("curriculum"), a);
        FileOutputStream fos = new FileOutputStream("/Users/muller/solution.xml");
        (new XMLWriter(fos, OutputFormat.createPrettyPrint())).write(doc);
        fos.flush();
        fos.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static TreeSet copySet(List ls) {
    TreeSet s = new TreeSet();
    s.addAll(ls);
    return s;//from  w  w w.  j  av a  2s  .  c o  m
}

From source file:Main.java

/** Adds a two-dimensional array to a TreeSet. */
public static void addDataToSet(TreeSet set, Number[][] data) {
    for (int i = 0; i < data.length; i++) {
        set.addAll(Arrays.asList(data[i]));
    }//from  ww w  . j  ava  2 s  .  c o m
}

From source file:info.magnolia.module.imaging.tools.ImageIOPluginsPage.java

/**
 * Removes duplicates and returns a sorted set of all entries in lowercase.
 *///from w  ww.  j av a 2s  .co m
protected static Collection<String> filter(String... formats) {
    final TreeSet<String> set = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    set.addAll(Arrays.asList(formats));
    CollectionUtils.transform(set, new Transformer() {
        @Override
        public Object transform(Object input) {
            return ((String) input).toLowerCase();
        }
    });
    return set;
}

From source file:at.porscheinformatik.sonarqube.licensecheck.mavenlicense.MavenLicense.java

public static String createString(Collection<MavenLicense> mavenLicenses) {
    TreeSet<MavenLicense> mavenLicenseSet = new TreeSet<>();
    mavenLicenseSet.addAll(mavenLicenses);

    StringWriter jsonString = new StringWriter();
    JsonGenerator generator = Json.createGenerator(jsonString);
    generator.writeStartArray();/*from w  w w .j ava 2 s .c o  m*/
    for (MavenLicense mavenLicense : mavenLicenseSet) {
        generator.writeStartObject();
        generator.write("licenseNameRegEx", mavenLicense.getLicenseNameRegEx().pattern());
        generator.write("license", mavenLicense.getLicense());
        generator.writeEnd();
    }
    generator.writeEnd();
    generator.close();

    return jsonString.toString();
}

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   ww w.j a v  a  2s.  c om
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:at.porscheinformatik.sonarqube.licensecheck.license.License.java

public static String createString(Collection<License> licenses) {
    TreeSet<License> licenseSet = new TreeSet<>();
    licenseSet.addAll(licenses);

    StringWriter jsonString = new StringWriter();
    JsonGenerator generator = Json.createGenerator(jsonString);
    generator.writeStartArray();//from w  ww.j a v  a2s  .c  o  m
    for (License license : licenseSet) {
        generator.writeStartObject();
        generator.write("name", license.getName());
        generator.write("identifier", license.getIdentifier());
        generator.write("status", license.getStatus());
        generator.writeEnd();
    }
    generator.writeEnd();
    generator.close();

    return jsonString.toString();
}

From source file:org.ut.biolab.medsavant.shared.model.Range.java

/**
 * Get the list you get by merging the Range objects in the collection
 *
 * @param range/*from  w  w  w.  j  a  va 2s . co m*/
 * @return the merged list.
 */
public static List<Range> merge(Collection<Range> range) {
    List<Range> mergedList = new ArrayList<Range>();

    // Arrange first in order by starting positions.
    TreeSet<Range> allRangesInOrder = new TreeSet<Range>();
    allRangesInOrder.addAll(range);

    // Merge now.
    Range curMerged = null;

    for (Range r : allRangesInOrder) {
        if (curMerged != null && curMerged.canBeMergedWith(r)) {
            // merge them here
            curMerged.max = Math.max(curMerged.max, r.max);
            curMerged.min = Math.min(curMerged.min, r.min);
        } else {
            if (curMerged != null) {
                mergedList.add(curMerged);
            }
            curMerged = new Range(r.min, r.max);
        }
    }
    // Merge in the last one.
    if (curMerged != null) {
        mergedList.add(curMerged);
    }
    return mergedList;
}