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:edu.utexas.cs.tactex.BalancingManagerService.java

@Override
public double getFudgeCorrection(int currentTimeslotIndex) {

    // extract data for prediction
    ArrayList<Double> pastErrors = new ArrayList<Double>();
    TreeSet<Integer> debugTimeslots = new TreeSet<Integer>();
    for (Entry<Integer, Double> e : timeslotConsumption.descendingMap().entrySet()) {
        Integer timeslot = e.getKey();
        Double actualConsumption = e.getValue();
        Double prediction = timeslotPredictions.get(timeslot);
        if (prediction != null) {
            pastErrors.add(actualConsumption - prediction);
            // debug:
            debugTimeslots.add(timeslot);
            // stop when there are MEMORY_LENGTH elements
            if (pastErrors.size() >= MEMORY_LENGTH)
                break;
        }/*from www  . j av  a 2 s .c  om*/
    }

    for (int i = currentTimeslotIndex - 24; i < currentTimeslotIndex; ++i) {
        if (!debugTimeslots.contains(i))
            log.error("Timeslot " + i + " doesn't exist in fudge data for ts " + currentTimeslotIndex);
    }

    // compute prediction
    double fudgeFactor;
    if (pastErrors.size() >= MIN_DATA_SIZE) {
        // compute mean fraction
        double total = 0;
        for (Double error : pastErrors) {
            total += error;
            log.debug("fudge error " + error + " total " + total);
        }
        double meanError = total / pastErrors.size();
        fudgeFactor = -meanError; // - due to consumption being negative
    } else {
        log.debug("getFudgeCorrection() doesn't have enough data, returning default");
        fudgeFactor = 0.0;
    }
    log.debug("BalancingManager, fudge-factor=" + fudgeFactor);
    return fudgeFactor;
}

From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.PluginConfigurationServiceDefault.java

private SortedSet<SharedBuildNumber> getTranslatedSet(Collection<SharedBuildNumberEntity> buildNumbers,
        Comparator<SharedBuildNumber> comparator) {
    TreeSet<SharedBuildNumber> set = new TreeSet<SharedBuildNumber>(comparator);

    for (SharedBuildNumberEntity entity : buildNumbers)
        set.add(new SharedBuildNumber(entity));

    return set;//from   ww  w.j a  v a  2  s  . c o m
}

From source file:edu.ku.brc.specify.config.init.secwiz.SpecifyDBSecurityWizard.java

/**
 * Sets up initial preference settings.// w  w  w . j  a v  a 2 s  .  com
 */
protected void setupLoginPrefs() {
    String userName = props.getProperty("usrUsername");
    String password = props.getProperty("usrPassword");
    String saUserName = props.getProperty("saUserName");
    String saPassword = props.getProperty("saPassword");

    String encryptedMasterUP = UserAndMasterPasswordMgr.encrypt(saUserName, saPassword, password);

    DatabaseDriverInfo driverInfo = dbPanel.getDriver();
    AppPreferences ap = AppPreferences.getLocalPrefs();

    String loginDBPrefName = "login.databases";
    String loginDBs = ap.get(loginDBPrefName, null);
    if (StringUtils.isNotEmpty(loginDBs)) {
        TreeSet<String> dbNames = new TreeSet<String>();
        for (String dbNm : StringUtils.splitPreserveAllTokens(loginDBs)) {
            dbNames.add(dbNm);
        }
        StringBuilder sb = new StringBuilder();
        for (String dbNm : dbNames) {
            if (sb.length() > 0)
                sb.append(',');
            sb.append(dbNm);
        }
        if (sb.length() > 0)
            sb.append(',');
        sb.append(dbPanel.getDbName());
        loginDBs = sb.toString();
    } else {
        loginDBs = dbPanel.getDbName();
    }
    ap.put(userName + "_master.islocal", "true");
    ap.put(userName + "_master.path", encryptedMasterUP);
    ap.put("login.dbdriver_selected", driverInfo.getName());
    ap.put("login.username", props.getProperty("usrUsername"));
    ap.put("login.databases_selected", dbPanel.getDbName());
    ap.put(loginDBPrefName, loginDBs);
    ap.put("login.servers", props.getProperty("hostName"));
    ap.put("login.servers_selected", props.getProperty("hostName"));
    ap.put("login.rememberuser", "true");
    ap.put("extra.check", "true");
    ap.put("version_check.auto", "true");

    try {
        ap.flush();

    } catch (BackingStoreException ex) {
    }
}

From source file:com.webcohesion.enunciate.modules.java_json_client.JavaJSONClientModule.java

public Set<String> getServerSideTypesToUse() {
    List<HierarchicalConfiguration> typeElements = this.config.configurationsAt("server-side-type");
    TreeSet<String> types = new TreeSet<String>();
    for (HierarchicalConfiguration typeElement : typeElements) {
        types.add(typeElement.getString("[@pattern]"));
    }//from ww  w .  j a  va  2  s  .  c  o m
    return types;
}

From source file:net.padlocksoftware.padlock.license.LicenseImpl.java

private SortedSet<String> extractHardwareAddresses(String addresses) {
    TreeSet<String> set = new TreeSet<String>();

    // Addresses are a space separated String of hex characters
    for (String address : addresses.split(" ")) {
        address = address.trim();/*  www .  j  a v a 2s.  c  o  m*/
        if (address.length() > 0) {
            set.add(address);
        }
    }

    return set;
}

From source file:com.qpark.maven.plugin.springintegration.SpringIntegrationConfigGenerator.java

public void generateService(final String serviceId) {
    this.log.debug("+generateService");
    final String capitalizeName = new StringBuffer(Util.capitalizePackageName(this.basePackageName))
            .append(ServiceIdRegistry.capitalize(serviceId)).toString();
    final String servicePackageName = new StringBuffer(this.basePackageName).append(".").append(serviceId)
            .toString();/*from   www.j  a va 2  s  . com*/
    final String fileName = new StringBuffer(64).append(servicePackageName)
            .append("-integration-spring-config.xml").toString();
    XsdContainer messageDefinitionXsdContainer = null;

    final TreeSet<String> packageNames = new TreeSet<String>();
    for (final ElementType element : this.config.getElementTypes()) {
        if (element.isRequest() && element.getServiceId().equals(serviceId)) {
            packageNames.add(element.getPackageName());
        }
    }
    for (final ElementType element : this.config.getElementTypes()) {
        if (element.getServiceId().equals(serviceId)) {
            messageDefinitionXsdContainer = this.config.getXsdContainer(element.getTargetNamespace());
            break;
        }
    }

    final StringBuffer xml = new StringBuffer();
    final StringBuffer sb = new StringBuffer();
    final StringBuffer properties = new StringBuffer();

    xml.append(this.getXmlDefinition());
    sb.append(Util.getGeneratedAtXmlComment(this.getClass(), this.eipVersion));

    xml.append("\n\t<!-- Define the security interceptor \"eipCaller").append(capitalizeName)
            .append("Wss4jSecurityInterceptor\" somewhere outside:\n");
    xml.append("\t<import resource=\"classpath:").append(fileName).append("\" />\n");
    xml.append("\t<bean id=\"").append(capitalizeName).append(
            "WebServiceSecurmentPropertyProvider\" class=\"com.qpark.eip.core.spring.security.DefaultEipSecurmentPropertyProvider\">\n");
    xml.append("\t\t<property name=\"securementUsername\" value=\"${").append(servicePackageName)
            .append(".userName}\"/>\n");
    xml.append("\t\t<property name=\"securementPassword\" value=\"${").append(servicePackageName)
            .append(".password}\"/>\n");
    xml.append("\t</bean>\n");
    xml.append("\t<bean id=\"eipCaller").append(capitalizeName).append(
            "Wss4jSecurityInterceptor\" class=\"com.qpark.eip.core.spring.security.EipWss4jSecurityInterceptor\">\n");
    xml.append("\t\t<property name=\"securementPropertyProvider\" ref=\"").append(capitalizeName)
            .append("WebServiceSecurmentPropertyProvider\" />\n");
    xml.append("\t</bean>\n");

    properties.append("\n#Properties used in ").append(fileName).append(":\n");
    properties.append(servicePackageName).append(".userName=XXXXXX\n");
    properties.append(servicePackageName).append(".password=password\n");

    if (messageDefinitionXsdContainer != null && messageDefinitionXsdContainer.getRelativeName() != null) {
        sb.append("\n\t<!-- Payload validation interceptor -->\n");
        sb.append("\t<bean id=\"eipCaller").append(capitalizeName).append(
                "PayloadValidatingInterceptor\" class=\"org.springframework.ws.client.support.interceptor.PayloadValidatingInterceptor\">\n");
        sb.append("\t\t<property name=\"schemas\">\n");
        sb.append("\t\t\t<list>\n");
        sb.append("\t\t\t\t<value>/WEB-INF/classes/");
        sb.append(messageDefinitionXsdContainer.getRelativeName());
        sb.append("</value>\n");
        sb.append("\t\t\t</list>\n");
        sb.append("\t\t</property>\n");
        sb.append("\t\t<property name=\"validateRequest\" value=\"${");
        sb.append(servicePackageName);
        sb.append(".validate.request.message:false}\" />\n");
        sb.append("\t\t<property name=\"validateResponse\" value=\"${");
        sb.append(servicePackageName);
        sb.append(".validate.response.message:false}\" />\n");
        sb.append("\t</bean>\n");
        properties.append(servicePackageName).append(".validate.request.message=false\n");
        properties.append(servicePackageName).append(".validate.response.message=false\n");

    }

    sb.append("\t<!-- Interceptor list of services -->\n");
    sb.append("\t<util:list id=\"eipCaller").append(capitalizeName).append("WsInterceptors\">\n");
    sb.append("\t\t<ref bean=\"eipCaller").append(capitalizeName).append("Wss4jSecurityInterceptor\"/>\n");
    if (messageDefinitionXsdContainer != null && messageDefinitionXsdContainer.getRelativeName() != null) {
        sb.append("\t\t<ref bean=\"eipCaller").append(capitalizeName)
                .append("PayloadValidatingInterceptor\"/>\n");
    }
    sb.append("\t</util:list>\n");

    sb.append("\t<!-- Marshaller of services -->\n");
    sb.append("\t<bean id=\"eipCaller").append(capitalizeName).append("Marshaller\"");
    sb.append(" class=\"org.springframework.oxm.jaxb.Jaxb2Marshaller\">\n");

    sb.append("\t\t<property name=\"packagesToScan\">\n");
    sb.append("\t\t\t<list>\n");
    final List<String> sids = ServiceIdRegistry.splitServiceIds(serviceId);
    if (sids.isEmpty()) {
        sids.addAll(this.config.getServiceIdRegistry().getAllServiceIds());
    }
    sids.stream().map(sid -> this.config.getServiceIdRegistry().getServiceIdEntry(sid)).forEach(side -> {
        sb.append("\t\t\t\t<value>");
        sb.append(side.getPackageName());
        sb.append("</value>\n");
    });
    sb.append("\t\t\t</list>\n");
    sb.append("\t\t</property>\n");

    sb.append("\t</bean>\n");

    sb.append("\n");
    final StringBuffer channels = new StringBuffer();
    final StringBuffer gateways = new StringBuffer();
    final StringBuffer router = new StringBuffer();
    channels.append("\t<!-- Channel definitions of service ").append(serviceId).append(" -->\n");
    channels.append("\t<int:channel id=\"internalEipCaller").append(capitalizeName)
            .append("RequestChannel\" />\n");

    router.append("\t<!-- Response type router of service ").append(serviceId).append(" -->\n");
    router.append("\t<int:router id=\"internalEipCaller").append(capitalizeName)
            .append("ResponseTypeRouter\"\n");
    router.append("\t\tinput-channel=\"internalEipCaller").append(capitalizeName)
            .append("WsOutgoingChannel\" \n");
    router.append("\t\tref=\"internalEipCaller").append(capitalizeName)
            .append("JAXBElementAwarePayloadTypeRouter\"\n");
    router.append("\t/>\n");
    router.append("\t<bean id=\"internalEipCaller").append(capitalizeName).append(
            "JAXBElementAwarePayloadTypeRouter\" class=\"com.qpark.eip.core.spring.JAXBElementAwarePayloadTypeRouter\">\n");
    router.append("\t\t<property name=\"channelMappings\">\n");
    router.append("\t\t\t<map>\n");

    for (final ElementType element : this.config.getElementTypes()) {
        if (element.getServiceId().equals(serviceId)) {
            final ElementType elementResponse = XsdsUtil.findResponse(element, this.config.getElementTypes(),
                    this.config);
            if (element.isRequest() && elementResponse != null) {
                final ComplexType ctResponse = new ComplexType(elementResponse.getElement().getType(),
                        this.config);
                if (ctResponse != null && !ctResponse.isSimpleType() && !ctResponse.isPrimitiveType()) {
                    gateways.append("\t<int:gateway id=\"eipCaller").append(capitalizeName)
                            .append(Util.capitalize(element.getMethodName())).append("Gateway\"\n");
                    gateways.append("\t\tservice-interface=\"").append(element.getPackageNameGateway())
                            .append(".").append(element.getClassNameGateway()).append("\"\n");
                    gateways.append("\t\tdefault-request-channel=\"internalEipCaller").append(capitalizeName)
                            .append("RequestChannel\"\n");
                    gateways.append("\t\tdefault-reply-channel=\"internalEipCaller").append(capitalizeName)
                            .append(Util.capitalize(element.getMethodName()))
                            .append("ResponseChannel\"\n\t/>\n");
                    channels.append("\t<int:channel id=\"internalEipCaller").append(capitalizeName)
                            .append(Util.capitalize(element.getMethodName())).append("ResponseChannel\" />\n");
                    router.append("\t\t\t\t<entry key=\"").append(ctResponse.getClassNameFullQualified())
                            .append("\" value=\"internalEipCaller").append(capitalizeName)
                            .append(Util.capitalize(element.getMethodName())).append("ResponseChannel\" />\n");
                }
            }
        }
    }
    channels.append("\t<int:channel id=\"internalEipCaller").append(capitalizeName)
            .append("WsOutgoingChannel\" />\n");

    router.append("\t\t\t</map>\n");
    router.append("\t\t</property>\n");
    router.append("\t</bean>\n");

    sb.append("<!-- ").append(ServiceIdRegistry.capitalize(serviceId)).append(" definition start -->\n");
    sb.append("\t<!-- Gateway of the service ").append(serviceId).append(" (to be used in your code) -->\n");
    sb.append(gateways);
    sb.append(channels);
    sb.append(router);
    sb.append("\t<!-- Outbound gateway of the service ").append(serviceId).append(" -->\n");
    sb.append("\t<int-ws:outbound-gateway id=\"eipCaller").append(capitalizeName).append("OutboundGateway\"\n");
    sb.append("\t\trequest-channel=\"internalEipCaller").append(capitalizeName).append("RequestChannel\"\n");
    sb.append("\t\treply-channel=\"internalEipCaller").append(capitalizeName).append("WsOutgoingChannel\"\n");

    /* Not supported any more. */
    // sb.append("\t\treply-timeout=\"${service.endpoint.timeout.ms.")
    // .append(servicePackageName).append(":-1}\"\n");

    sb.append("\t\turi=\"${service.endpoint.url.").append(servicePackageName)
            .append(":http://localhost:8080/}\"\n");
    properties.append("service.endpoint.url.").append(servicePackageName).append("=http://localhost:8080/")
            .append(serviceId).append("\n");
    // properties.append("service.endpoint.timeout.ms.")
    // .append(servicePackageName).append("=-1\n");

    sb.append("\t\tinterceptors=\"eipCaller").append(capitalizeName).append("WsInterceptors\"\n");
    sb.append("\t\tmessage-factory=\"soap12MessageFactory\"\n");
    sb.append("\t\tmarshaller=\"eipCaller").append(capitalizeName)
            .append("Marshaller\" unmarshaller=\"eipCaller").append(capitalizeName).append("Marshaller\"\n");
    sb.append("\t/>\n");
    sb.append("<!-- ").append(ServiceIdRegistry.capitalize(serviceId)).append(" definition end -->\n\n");

    sb.append("\n</beans>\n");

    properties.append("\t-->\n\n");

    xml.append(properties);
    xml.append(sb);
    final File f = Util.getFile(this.outputDirectory, "", fileName);
    this.log.info(new StringBuffer().append("Write ").append(f.getAbsolutePath()));
    try {
        Util.writeToFile(f, xml.toString());
    } catch (final Exception e) {
        this.log.error(e.getMessage());
        e.printStackTrace();
    }
    this.log.debug("-generateService");
}

From source file:com.inclouds.hbase.test.BaseTest.java

/**
 * Gets the column set./* www.ja  va2  s  . c o  m*/
 *
 * @param cols the cols
 * @return the column set
 */
protected NavigableSet<byte[]> getColumnSet(List<byte[]> cols) {
    if (cols == null)
        return null;
    TreeSet<byte[]> set = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
    for (byte[] c : cols) {
        set.add(c);
    }
    return set;
}

From source file:com.joliciel.jochre.boundaries.SplitCandidateFinderImpl.java

@Override
public List<Split> findSplitCandidates(Shape shape) {
    List<Split> splitCandidates = new ArrayList<Split>();

    // generate a list giving the total distance from the top and bottom to the shape's edge
    // the hypothesis is that splits almost always occur at x-coordinates
    // where there's a summit in the distance to the shape's edge, between two valleys
    int[] edgeDistances = new int[shape.getWidth()];
    int[][] verticalContour = shape.getVerticalContour();
    for (int x = 0; x < shape.getWidth(); x++) {
        int edgeDistance = verticalContour[x][0] + ((shape.getHeight() - 1) - verticalContour[x][1]);
        if (edgeDistance > shape.getHeight() - 1)
            edgeDistance = shape.getHeight() - 1;

        edgeDistances[x] = edgeDistance;
    }//from   w  w  w  .  j  a v a  2 s .  c  o m

    int[] maximaMinima = new int[shape.getWidth()];
    int lastDistance = -1;
    boolean rising = true;
    int i = 0;
    for (int edgeDistance : edgeDistances) {
        if (lastDistance >= 0) {
            if (edgeDistance < lastDistance && rising) {
                maximaMinima[i - 1] = 1;
            }
            if (edgeDistance > lastDistance && !rising) {
                maximaMinima[i - 1] = -1;
            }
        }
        if (edgeDistance > lastDistance) {
            rising = true;
        } else if (edgeDistance < lastDistance) {
            rising = false;
        }

        lastDistance = edgeDistance;
        i++;
    }
    maximaMinima[0] = 1;
    if (rising)
        maximaMinima[shape.getWidth() - 1] = 1;
    else
        maximaMinima[shape.getWidth() - 1] = -1;

    for (int x = 0; x < shape.getWidth(); x++) {
        String maxMin = "";
        if (maximaMinima[x] < 0)
            maxMin = " min";
        if (maximaMinima[x] > 0)
            maxMin = " max";
        LOG.trace("edgeDistance[" + x + "]: " + edgeDistances[x] + maxMin);
    }

    boolean haveMinimum = false;
    int lastMaximum = -1;
    int lastMinValue = 0;
    int lastMaxValue = 0;
    TreeSet<SplitCandidateValue> splitCandidateValues = new TreeSet<SplitCandidateFinderImpl.SplitCandidateValue>();
    for (i = 0; i < shape.getWidth(); i++) {
        if (maximaMinima[i] < 0) {
            haveMinimum = true;
            if (lastMaximum > 0) {
                double diff = (double) ((lastMaxValue - lastMinValue) + (lastMaxValue - edgeDistances[i]))
                        / 2.0;
                splitCandidateValues.add(new SplitCandidateValue(lastMaximum, diff));
            }
            lastMinValue = edgeDistances[i];
        }
        if (maximaMinima[i] > 0) {
            if (haveMinimum) {
                lastMaximum = i;
                lastMaxValue = edgeDistances[i];
            }
            haveMinimum = false;
        }
    }

    List<SplitCandidateValue> candidatesToRemove = new ArrayList<SplitCandidateFinderImpl.SplitCandidateValue>();
    for (SplitCandidateValue thisValue : splitCandidateValues) {
        if (candidatesToRemove.contains(thisValue))
            continue;
        for (SplitCandidateValue otherValue : splitCandidateValues) {
            if (candidatesToRemove.contains(otherValue))
                continue;
            if (otherValue.equals(thisValue))
                break;
            int distance = thisValue.getPosition() - otherValue.getPosition();
            if (distance < 0)
                distance = 0 - distance;
            if (distance < this.minDistanceBetweenSplits) {
                LOG.trace("Removing candidate " + otherValue.getPosition() + ", distance=" + distance);
                candidatesToRemove.add(otherValue);
            }
        }
    }
    splitCandidateValues.removeAll(candidatesToRemove);

    TreeMap<Integer, Split> splitCandidateMap = new TreeMap<Integer, Split>();
    for (SplitCandidateValue candidateValue : splitCandidateValues) {
        Split splitCandidate = boundaryServiceInternal.getEmptySplit(shape);
        splitCandidate.setPosition(candidateValue.getPosition());
        splitCandidateMap.put(candidateValue.getPosition(), splitCandidate);
    }

    for (Split split : splitCandidateMap.values())
        splitCandidates.add(split);
    return splitCandidates;
}

From source file:com.joliciel.talismane.parser.ParseEvaluationSentenceWriter.java

@Override
public void onNextParseConfiguration(ParseConfiguration realConfiguration,
        List<ParseConfiguration> guessedConfigurations) {
    try {/*w  w w .ja v  a2  s  .  c  o m*/
        TreeSet<Integer> startIndexes = new TreeSet<Integer>();
        for (PosTaggedToken posTaggedToken : realConfiguration.getPosTagSequence()) {
            if (!posTaggedToken.getTag().equals(PosTag.ROOT_POS_TAG)) {
                Token token = posTaggedToken.getToken();
                startIndexes.add(token.getStartIndex());
            }
        }
        if (hasTokeniser || hasPosTagger) {
            int i = 0;
            for (ParseConfiguration guessedConfiguration : guessedConfigurations) {
                for (PosTaggedToken posTaggedToken : guessedConfiguration.getPosTagSequence()) {
                    if (!posTaggedToken.getTag().equals(PosTag.ROOT_POS_TAG)) {
                        Token token = posTaggedToken.getToken();
                        startIndexes.add(token.getStartIndex());
                    }
                }
                i++;
                if (i == guessCount)
                    break;
            }
        }
        Map<Integer, Integer> startIndexMap = new HashMap<Integer, Integer>();
        int j = 0;
        for (int startIndex : startIndexes) {
            startIndexMap.put(startIndex, j++);
        }

        PosTagSequence posTagSequence = realConfiguration.getPosTagSequence();
        PosTaggedToken[] realTokens = new PosTaggedToken[startIndexes.size()];
        for (PosTaggedToken posTaggedToken : posTagSequence) {
            if (!posTaggedToken.getTag().equals(PosTag.ROOT_POS_TAG)) {
                realTokens[startIndexMap.get(posTaggedToken.getToken().getStartIndex())] = posTaggedToken;
            }
        }

        for (PosTaggedToken posTaggedToken : realTokens) {
            if (posTaggedToken != null) {
                csvFileWriter.write(CSV.format(posTaggedToken.getToken().getOriginalText()));
            } else {
                csvFileWriter.write(CSV.getCsvSeparator());
            }
        }

        csvFileWriter.write("\n");
        for (PosTaggedToken posTaggedToken : realTokens) {
            if (posTaggedToken != null) {
                csvFileWriter.write(CSV.format(posTaggedToken.getTag().getCode()));
            } else {
                csvFileWriter.write(CSV.getCsvSeparator());
            }
        }
        csvFileWriter.write("\n");
        for (PosTaggedToken posTaggedToken : realTokens) {
            if (posTaggedToken != null) {
                DependencyArc realArc = realConfiguration.getGoverningDependency(posTaggedToken);
                String realLabel = realArc.getLabel() == null ? "null" : realArc.getLabel();
                csvFileWriter.write(CSV.format(realLabel));
            } else {
                csvFileWriter.write(CSV.getCsvSeparator());
            }
        }
        csvFileWriter.write("\n");
        for (PosTaggedToken posTaggedToken : realTokens) {
            if (posTaggedToken != null) {
                DependencyArc realArc = realConfiguration.getGoverningDependency(posTaggedToken);
                int startIndex = -1;
                if (realArc != null) {
                    PosTaggedToken head = realArc.getHead();
                    if (!head.getTag().equals(PosTag.ROOT_POS_TAG)) {
                        startIndex = head.getToken().getStartIndex();
                    }
                }
                if (startIndex < 0)
                    csvFileWriter.write(CSV.format("ROOT"));
                else
                    csvFileWriter
                            .write(CSV.getColumnLabel(startIndexMap.get(startIndex)) + CSV.getCsvSeparator());
            } else {
                csvFileWriter.write(CSV.getCsvSeparator());
            }
        }
        csvFileWriter.write("\n");

        for (int i = 0; i < guessCount; i++) {
            if (i < guessedConfigurations.size()) {
                ParseConfiguration guessedConfiguration = guessedConfigurations.get(i);
                PosTaggedToken[] guessedTokens = new PosTaggedToken[startIndexes.size()];
                for (PosTaggedToken posTaggedToken : guessedConfiguration.getPosTagSequence()) {
                    if (!posTaggedToken.getTag().equals(PosTag.ROOT_POS_TAG)) {
                        guessedTokens[startIndexMap
                                .get(posTaggedToken.getToken().getStartIndex())] = posTaggedToken;
                    }
                }

                if (hasTokeniser) {
                    for (PosTaggedToken posTaggedToken : guessedTokens) {
                        if (posTaggedToken != null) {
                            csvFileWriter.write(CSV.format(posTaggedToken.getToken().getOriginalText()));
                        } else {
                            csvFileWriter.write(CSV.getCsvSeparator());
                        }
                    }

                    csvFileWriter.write("\n");
                }

                if (hasPosTagger) {
                    for (PosTaggedToken posTaggedToken : guessedTokens) {
                        if (posTaggedToken != null) {
                            csvFileWriter.write(CSV.format(posTaggedToken.getTag().getCode()));
                        } else {
                            csvFileWriter.write(CSV.getCsvSeparator());
                        }
                    }
                    csvFileWriter.write("\n");
                }

                for (PosTaggedToken posTaggedToken : guessedTokens) {
                    if (posTaggedToken != null) {
                        DependencyArc guessedArc = guessedConfiguration.getGoverningDependency(posTaggedToken);
                        String guessedLabel = "";
                        if (guessedArc != null) {
                            guessedLabel = guessedArc.getLabel() == null ? "null" : guessedArc.getLabel();
                        }
                        csvFileWriter.write(CSV.format(guessedLabel));
                    } else {
                        csvFileWriter.write(CSV.getCsvSeparator());
                    }
                }
                csvFileWriter.write("\n");
                for (PosTaggedToken posTaggedToken : guessedTokens) {
                    if (posTaggedToken != null) {
                        DependencyArc guessedArc = guessedConfiguration.getGoverningDependency(posTaggedToken);
                        int startIndex = -1;
                        if (guessedArc != null) {
                            PosTaggedToken head = guessedArc.getHead();
                            if (!head.getTag().equals(PosTag.ROOT_POS_TAG)) {
                                startIndex = head.getToken().getStartIndex();
                            }
                        }
                        if (startIndex < 0)
                            csvFileWriter.write(CSV.format("ROOT"));
                        else
                            csvFileWriter.write(
                                    CSV.getColumnLabel(startIndexMap.get(startIndex)) + CSV.getCsvSeparator());
                    } else {
                        csvFileWriter.write(CSV.getCsvSeparator());
                    }
                }
                csvFileWriter.write("\n");
                for (PosTaggedToken posTaggedToken : guessedTokens) {
                    if (posTaggedToken != null) {
                        DependencyArc guessedArc = guessedConfiguration.getGoverningDependency(posTaggedToken);
                        double prob = 1.0;
                        if (guessedArc != null) {
                            Transition transition = guessedConfiguration.getTransition(guessedArc);
                            if (transition != null)
                                prob = transition.getDecision().getProbability();
                        }
                        csvFileWriter.write(CSV.format(prob));
                    } else {
                        csvFileWriter.write(CSV.getCsvSeparator());
                    }
                }
                csvFileWriter.write("\n");

            } else {
                csvFileWriter.write("\n");
                csvFileWriter.write("\n");
            } // have more configurations
        } // next guessed configuration
        csvFileWriter.flush();
    } catch (IOException ioe) {
        LogUtils.logError(LOG, ioe);
        throw new RuntimeException(ioe);
    }
}

From source file:byps.test.TestSerializerList.java

/**
 * Test complex for collection: List<Map<Integer,Set<List<PrimitiveTypes>>>>
 * This test fails, if the generated class PrimitiveTypes is used, since it does not have an equals method.
 * @throws BException/*w  w w  .  j a v a2s . c o  m*/
 */
@Test
public void testListMapSetListInteger() throws BException {
    log.info("testListMapSetListInteger(");

    List<Map<Integer, List<TreeSet<Integer>>>> list = new ArrayList<Map<Integer, List<TreeSet<Integer>>>>();
    for (int i = 0; i < 2; i++) {
        Map<Integer, List<TreeSet<Integer>>> map = new HashMap<Integer, List<TreeSet<Integer>>>();
        for (int j = 0; j < 3; j++) {
            List<TreeSet<Integer>> arr = new ArrayList<TreeSet<Integer>>();
            for (int k = 0; k < 4; k++) {
                TreeSet<Integer> set = new TreeSet<Integer>();
                for (int n = 0; n < 5; n++) {
                    Integer pt = (n + 1) * (k + 1) * (j + 1) * (i + 1);
                    set.add(pt);
                }
                arr.add(set);
            }
            map.put(j, arr);
        }
        list.add(map);
    }
    internalTestListMapSetListInteger(list);

    log.info(")testListMapSetListInteger");
}