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:com.ichi2.libanki.Utils.java

private static void printJSONObject(JSONObject jsonObject, String indentation, BufferedWriter buff) {
    try {//www  . jav  a  2  s  .com
        @SuppressWarnings("unchecked")
        Iterator<String> keys = (Iterator<String>) jsonObject.keys();
        TreeSet<String> orderedKeysSet = new TreeSet<String>();
        while (keys.hasNext()) {
            orderedKeysSet.add(keys.next());
        }

        Iterator<String> orderedKeys = orderedKeysSet.iterator();
        while (orderedKeys.hasNext()) {
            String key = orderedKeys.next();

            try {
                Object value = jsonObject.get(key);
                if (value instanceof JSONObject) {
                    if (buff != null) {
                        buff.write(indentation + " " + key + " : ");
                        buff.newLine();
                    }
                    Timber.i("  " + indentation + key + " : ");
                    printJSONObject((JSONObject) value, indentation + "-", buff);
                } else {
                    if (buff != null) {
                        buff.write(indentation + " " + key + " = " + jsonObject.get(key).toString());
                        buff.newLine();
                    }
                    Timber.i("  " + indentation + key + " = " + jsonObject.get(key).toString());
                }
            } catch (JSONException e) {
                Timber.e(e, "printJSONObject : JSONException");
            }
        }
    } catch (IOException e1) {
        Timber.e(e1, "printJSONObject : IOException");
    }
}

From source file:de.lgohlke.sonar.maven.lint.LintSensorTest.java

@Test
public void testConfiguredAllRulesInAnnotation() {

    class StringComparator implements Comparator<String> {
        @Override//from   w w w  . j  a v  a 2s  . c o  m
        public int compare(String o1, String o2) {
            return o1.compareTo(o2);
        }
    }

    Reflections reflections = new Reflections("de.lgohlke.sonar.maven.lint.rules");
    Set<Class<? extends MavenRule>> rulesImplemented = reflections.getSubTypesOf(MavenRule.class);

    Rules rules = LintSensor.class.getAnnotation(Rules.class);

    TreeSet<String> configuredRules = new TreeSet<String>(new StringComparator());
    for (Class clazz : rules.values()) {
        configuredRules.add(clazz.getCanonicalName());
    }
    TreeSet<String> implementedRules = new TreeSet<String>(new StringComparator());
    for (Class clazz : rulesImplemented) {
        implementedRules.add(clazz.getCanonicalName());
    }

    assertThat(configuredRules).isEqualTo(implementedRules);
}

From source file:desmoj.extensions.visualization2d.engine.modelGrafic.StatisticGrafic.java

/**
 * get all views (viewId's) with Statistic
 * @return//from  w w  w . j a v a  2s.c  om
 */
public static String[] getViews(Model model) {
    TreeSet<String> views = new TreeSet<String>();
    String[] ids = model.getStatistics().getAllIds();
    for (int i = 0; i < ids.length; i++) {
        Statistic statistic = model.getStatistics().get(ids[i]);
        StatisticGrafic statisticGrafic = (StatisticGrafic) statistic.getGrafic();
        if (statisticGrafic != null) {
            String viewId = statisticGrafic.getViewId();
            if (!views.contains(viewId))
                views.add(viewId);
        }
    }
    String[] out = new String[views.size()];
    int i = 0;
    for (Iterator<String> it = views.iterator(); it.hasNext();) {
        out[i] = it.next();
        i++;
    }
    return out;

}

From source file:net.spfbl.core.Client.java

public static TreeSet<Client> dropAll() throws ProcessException {
    TreeSet<Client> clientSet = new TreeSet<Client>();
    for (Client client : getSet()) {
        if (client != null) {
            String cidr = client.getCIDR();
            client = drop(cidr);//w  w  w  .  j  a  v  a2 s  . com
            if (client != null) {
                clientSet.add(client);
            }
        }
    }
    return clientSet;
}

From source file:com.izforge.izpack.uninstaller.resource.InstallLog.java

/**
 * Returns the installed files, in leaf first order.
 *
 * @param reader the <em>install.log</em> reader
 * @return the installed files/*from  ww  w.j a  v  a2  s  .  c  om*/
 * @throws IOException for any I/O error
 */
private List<File> getFiles(BufferedReader reader) throws IOException {
    TreeSet<File> files = new TreeSet<File>(Collections.reverseOrder());
    String read = reader.readLine();
    while (read != null) {
        files.add(new File(read));
        read = reader.readLine();
    }

    // We return it
    return new ArrayList<File>(files);
}

From source file:com.rapidminer.operator.preprocessing.discretization.UserBasedDiscretization.java

@Override
public PreprocessingModel createPreprocessingModel(ExampleSet exampleSet) throws OperatorException {
    HashMap<String, SortedSet<Tupel<Double, String>>> ranges = new HashMap<String, SortedSet<Tupel<Double, String>>>();
    List<String[]> rangeList = getParameterList(PARAMETER_RANGE_NAMES);

    TreeSet<Tupel<Double, String>> thresholdPairs = new TreeSet<Tupel<Double, String>>();
    for (String[] pair : rangeList) {
        thresholdPairs.add(new Tupel<Double, String>(Double.valueOf(pair[1]), pair[0]));
    }/*  w  w  w.  j  av a2 s .c om*/
    for (Attribute attribute : exampleSet.getAttributes()) {
        if (attribute.isNumerical()) {
            ranges.put(attribute.getName(), thresholdPairs);
        }
    }

    DiscretizationModel model = new DiscretizationModel(exampleSet);
    model.setRanges(ranges);
    return model;
}

From source file:com.opencredo.service.BookServiceImpl.java

public SortedSet<Book> getAllBooks() {
    TreeSet<Book> treeSet = new TreeSet<Book>();
    for (Iterator<Book> i = this.books.values().iterator(); i.hasNext();) {
        Book book = i.next();//from  ww w .  j a  va 2  s  .  c  o m
        treeSet.add(cloneBook(book));
    }
    return treeSet;
}

From source file:de.uzk.hki.da.cb.ScanForPresentationAction.java

protected TreeSet<String> neverConverted() {
    TreeSet<String> ret = new TreeSet<String>();
    ret.add(PREMIS_XML);
    ret.add(C.PUBLIC_METS);//w w w. j a v  a  2  s .  c  o  m

    if (o.getMetadata_file() != null) {
        ret.add(o.getMetadata_file());
        String packageType = o.getPackage_type();

        if ("EAD".equals(packageType)) {
            String mfPathSrc = o.getLatest(o.getMetadata_file()).getPath().toString();
            EadMetsMetadataStructure emms = null;
            try {
                emms = new EadMetsMetadataStructure(wa.dataPath(), new File(mfPathSrc), o.getDocuments());
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (emms != null) {
                List<String> metse = emms.getMetsRefsInEad();
                for (int mmm = 0; mmm < metse.size(); mmm++) {
                    String mets = metse.get(mmm);
                    String normMets = FilenameUtils.normalize(mets);
                    if (normMets != null) {
                        mets = normMets;
                    }
                    ret.add(mets);
                }
            }
        }
    }

    return ret;
}

From source file:com.cloud.network.router.VpcNetworkHelperImpl.java

@Override
public void reallocateRouterNetworks(final RouterDeploymentDefinition vpcRouterDeploymentDefinition,
        final VirtualRouter router, final VMTemplateVO template, final HypervisorType hType)
        throws ConcurrentOperationException, InsufficientCapacityException {

    final TreeSet<String> publicVlans = new TreeSet<String>();
    publicVlans.add(vpcRouterDeploymentDefinition.getSourceNatIP().getVlanTag());

    //1) allocate nic for control and source nat public ip
    final LinkedHashMap<Network, List<? extends NicProfile>> networks = configureDefaultNics(
            vpcRouterDeploymentDefinition);

    final Long vpcId = vpcRouterDeploymentDefinition.getVpc().getId();
    //2) allocate nic for private gateways if needed
    final List<PrivateGateway> privateGateways = vpcMgr.getVpcPrivateGateways(vpcId);
    if (privateGateways != null && !privateGateways.isEmpty()) {
        for (final PrivateGateway privateGateway : privateGateways) {
            final NicProfile privateNic = nicProfileHelper.createPrivateNicProfileForGateway(privateGateway,
                    router);//w  w  w. j a va  2 s.  c  o m
            final Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
            networks.put(privateNetwork, new ArrayList<NicProfile>(Arrays.asList(privateNic)));
        }
    }

    //3) allocate nic for guest gateway if needed
    final List<? extends Network> guestNetworks = vpcMgr.getVpcNetworks(vpcId);
    for (final Network guestNetwork : guestNetworks) {
        if (_networkModel.isPrivateGateway(guestNetwork.getId())) {
            continue;
        }
        if (guestNetwork.getState() == Network.State.Implemented
                || guestNetwork.getState() == Network.State.Setup) {
            final NicProfile guestNic = nicProfileHelper
                    .createGuestNicProfileForVpcRouter(vpcRouterDeploymentDefinition, guestNetwork);
            networks.put(guestNetwork, new ArrayList<NicProfile>(Arrays.asList(guestNic)));
        }
    }

    //4) allocate nic for additional public network(s)
    final List<IPAddressVO> ips = _ipAddressDao.listByAssociatedVpc(vpcId, false);
    final List<NicProfile> publicNics = new ArrayList<NicProfile>();
    Network publicNetwork = null;
    for (final IPAddressVO ip : ips) {
        final PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId()));
        if ((ip.getState() == IpAddress.State.Allocated || ip.getState() == IpAddress.State.Allocating)
                && vpcMgr.isIpAllocatedToVpc(ip) && !publicVlans.contains(publicIp.getVlanTag())) {
            s_logger.debug("Allocating nic for router in vlan " + publicIp.getVlanTag());
            final NicProfile publicNic = new NicProfile();
            publicNic.setDefaultNic(false);
            publicNic.setIPv4Address(publicIp.getAddress().addr());
            publicNic.setIPv4Gateway(publicIp.getGateway());
            publicNic.setIPv4Netmask(publicIp.getNetmask());
            publicNic.setMacAddress(publicIp.getMacAddress());
            publicNic.setBroadcastType(BroadcastDomainType.Vlan);
            publicNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(publicIp.getVlanTag()));
            publicNic.setIsolationUri(IsolationType.Vlan.toUri(publicIp.getVlanTag()));
            final NetworkOffering publicOffering = _networkModel
                    .getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0);
            if (publicNetwork == null) {
                final List<? extends Network> publicNetworks = _networkMgr.setupNetwork(s_systemAccount,
                        publicOffering, vpcRouterDeploymentDefinition.getPlan(), null, null, false);
                publicNetwork = publicNetworks.get(0);
            }
            publicNics.add(publicNic);
            publicVlans.add(publicIp.getVlanTag());
        }
    }
    if (publicNetwork != null) {
        if (networks.get(publicNetwork) != null) {
            @SuppressWarnings("unchecked")
            final List<NicProfile> publicNicProfiles = (List<NicProfile>) networks.get(publicNetwork);
            publicNicProfiles.addAll(publicNics);
            networks.put(publicNetwork, publicNicProfiles);
        } else {
            networks.put(publicNetwork, publicNics);
        }
    }

    final ServiceOfferingVO routerOffering = _serviceOfferingDao
            .findById(vpcRouterDeploymentDefinition.getServiceOfferingId());

    _itMgr.allocate(router.getInstanceName(), template, routerOffering, networks,
            vpcRouterDeploymentDefinition.getPlan(), hType);
}

From source file:org.apache.synapse.transport.passthru.SourceResponse.java

public void addHeader(String name, String value) {
    if (headers.get(name) == null) {
        TreeSet<String> values = new TreeSet<String>();
        values.add(value);//from w w  w . j ava2 s. co  m
        headers.put(name, values);
    } else {
        TreeSet<String> values = headers.get(name);
        values.add(value);
    }
}