Example usage for java.util SortedSet size

List of usage examples for java.util SortedSet size

Introduction

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

Prototype

int size();

Source Link

Document

Returns the number of elements in this set (its cardinality).

Usage

From source file:com.streamsets.pipeline.stage.destination.cassandra.CassandraTarget.java

@Override
protected List<ConfigIssue> init() {
    List<ConfigIssue> issues = super.init();
    errorRecordHandler = new DefaultErrorRecordHandler(getContext());

    Target.Context context = getContext();
    if (addresses.isEmpty()) {
        issues.add(context.createConfigIssue(Groups.CASSANDRA.name(), "contactNodes", Errors.CASSANDRA_00));
    }/*from   ww  w . j  av  a 2 s .c om*/

    for (String address : addresses) {
        if (address.isEmpty()) {
            issues.add(context.createConfigIssue(Groups.CASSANDRA.name(), "contactNodes", Errors.CASSANDRA_01));
        }
    }

    contactPoints = new ArrayList<>(addresses.size());
    for (String address : addresses) {
        if (null == address) {
            LOG.warn("A null value was passed in as a contact point.");
            // This isn't valid but InetAddress won't complain so we skip this entry.
            continue;
        }

        try {
            contactPoints.add(InetAddress.getByName(address));
        } catch (UnknownHostException e) {
            issues.add(context.createConfigIssue(Groups.CASSANDRA.name(), "contactNodes", Errors.CASSANDRA_04,
                    address));
        }
    }

    if (contactPoints.size() < 1) {
        issues.add(context.createConfigIssue(Groups.CASSANDRA.name(), "contactNodes", Errors.CASSANDRA_00));
    }

    if (!qualifiedTableName.contains(".")) {
        issues.add(
                context.createConfigIssue(Groups.CASSANDRA.name(), "qualifiedTableName", Errors.CASSANDRA_02));
    } else {
        if (checkCassandraReachable(issues)) {
            List<String> invalidColumns = checkColumnMappings();
            if (invalidColumns.size() != 0) {
                issues.add(context.createConfigIssue(Groups.CASSANDRA.name(), "columnNames",
                        Errors.CASSANDRA_08, Joiner.on(", ").join(invalidColumns)));
            }
        }
    }

    if (issues.isEmpty()) {
        cluster = Cluster.builder().addContactPoints(contactPoints).withCompression(compression).withPort(port)
                // If authentication is disabled on the C* cluster, this method has no effect.
                .withCredentials(username, password).build();

        try {
            session = cluster.connect();

            statementCache = CacheBuilder.newBuilder()
                    // No expiration as prepared statements are good for the entire session.
                    .build(new CacheLoader<SortedSet<String>, PreparedStatement>() {
                        @Override
                        public PreparedStatement load(SortedSet<String> columns) {
                            // The INSERT query we're going to perform (parameterized).
                            SortedSet<String> statementColumns = new TreeSet<>();
                            for (String fieldPath : columnMappings.keySet()) {
                                final String fieldName = fieldPath.replaceAll("/", "");
                                if (columns.contains(fieldName)) {
                                    statementColumns.add(fieldName);
                                }
                            }
                            final String query = String.format("INSERT INTO %s (%s) VALUES (%s);",
                                    qualifiedTableName, Joiner.on(", ").join(statementColumns),
                                    Joiner.on(", ").join(Collections.nCopies(statementColumns.size(), "?")));
                            LOG.trace("Prepared Query: {}", query);
                            return session.prepare(query);
                        }
                    });
        } catch (NoHostAvailableException | AuthenticationException | IllegalStateException e) {
            issues.add(context.createConfigIssue(null, null, Errors.CASSANDRA_03, e.toString()));
        }
    }
    return issues;
}

From source file:com.cloud.utils.net.NetUtils.java

/**
 * Given a cidr, this method returns an ip address within the range but
 * is not in the avoid list./*from w ww.  j a  va2s.c o m*/
 * Note: the gateway address has to be specified in the avoid list
 *
 * @param cidr ip that the cidr starts with
 * @param size size of the cidr
 * @param avoid set of ips to avoid
 * @return ip that is within the cidr range but not in the avoid set.  -1 if unable to find one.
 */
public static long getRandomIpFromCidr(final long cidr, final int size, final SortedSet<Long> avoid) {
    assert size < MAX_CIDR : "You do know this is not for ipv6 right?  Keep it smaller than 32 but you have "
            + size;

    final long startNetMask = ip2Long(getCidrNetmask(size));
    final long startIp = (cidr & startNetMask) + 1; //exclude the first ip since it isnt valid, e.g., 192.168.10.0
    int range = 1 << MAX_CIDR - size; //e.g., /24 = 2^8 = 256
    range = range - 1; //exclude end of the range since that is the broadcast address, e.g., 192.168.10.255

    if (avoid.size() >= range) {
        return -1;
    }

    //Reduce the range by the size of the avoid set
    //e.g., cidr = 192.168.10.0, size = /24, avoid = 192.168.10.1, 192.168.10.20, 192.168.10.254
    // range = 2^8 - 1 - 3 = 252
    range = range - avoid.size();
    final int next = s_rand.nextInt(range); //note: nextInt excludes last value
    long ip = startIp + next;
    for (final Long avoidable : avoid) {
        if (ip >= avoidable) {
            ip++;
        } else {
            break;
        }
    }

    return ip;
}

From source file:dinistiq.Dinistiq.java

/**
 * Create a dinistiq context from the given class resolver and optional external beans.
 * Add all the external named beans from thei given map for later lookup to the context as well
 * and be sure that your class resolver takes the resources in the dinistiq/ path of your
 * class path into cosideration./*from  www  .  j  a  v a  2s  . c  om*/
 *
 * @param classResolver resolver to us when resolving all types of classes
 * @param externalBeans map of beans with their id (name) as the key
 * @throws java.lang.Exception thrown with a readable message if something goes wrong
 */
public Dinistiq(ClassResolver classResolver, Map<String, Object> externalBeans) throws Exception {
    // measure time for init process
    long start = System.currentTimeMillis();

    Map<String, Set<Object>> dependencies = new HashMap<>();

    // Use all externally provided beans
    if (externalBeans != null) {
        beans.putAll(externalBeans);
        for (String externalBeanName : externalBeans.keySet()) {
            dependencies.put(externalBeanName, new HashSet<>());
        } // for
    } // if

    // Add system properties to scope and split potential URL values
    for (Object keyObject : System.getProperties().keySet()) {
        String key = keyObject.toString();
        beans.put(key, System.getProperty(key));
        storeUrlParts(key, System.getProperty(key), beans);
    } // for
      // Add environment to scope and split potential URL values
    for (String key : environment.keySet()) {
        storeUrlParts(key, environment.get(key), beans);
    } // for
    LOG.debug("() initial beans {}", beans);

    // Read bean list from properties files mapping names to names of the classes to be instanciated
    Properties beanlist = new Properties();
    SortedSet<String> propertiesFilenames = classResolver.getProperties(PRODUCT_BASE_PATH + "/");
    LOG.debug("() checking {} files for properties", propertiesFilenames.size());
    for (String propertyResource : propertiesFilenames) {
        LOG.debug("() check {}", propertyResource);
        // ignore subfolders!
        if (propertyResource.indexOf('/', PRODUCT_BASE_PATH.length() + 1) < 0) {
            LOG.debug("() resource {}", propertyResource);
            beanlist.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(propertyResource));
        } // if
    } // for
    List<Class<?>> classList = new ArrayList<>();
    List<String> nameList = new ArrayList<>();
    for (String key : beanlist.stringPropertyNames()) {
        String className = beanlist.getProperty(key);
        if (MAP_TYPE.equals(className)) {
            beans.put(key, new HashMap<>());
            dependencies.put(key, new HashSet<>());
        } else {
            // expect java.lang.Xyz("value")
            int idx = className.indexOf('(');
            if (className.startsWith(JAVALANG_PREFIX) && (idx > 0)) {
                String value = getReferenceValue(className.substring(idx + 2, className.length() - 2))
                        .toString();
                className = className.substring(0, idx);
                LOG.debug("() instanciating {} :{}", value, className);
                Class<? extends Object> c = Class.forName(className.substring(0, idx));
                Object instance = c.getConstructor(String.class).newInstance(value);
                LOG.info("() storing value {} :{} - {}", key, instance.getClass().getName(), instance);
                beans.put(key, instance);
                dependencies.put(key, new HashSet<>());
            } else {
                boolean setType = className.startsWith(SET_TYPE);
                if ((setType || className.startsWith(LIST_TYPE)) && (idx > 0)) {
                    String values[] = getReferenceValue(className.substring(idx + 1, className.length() - 1))
                            .toString().split(",");
                    Collection<String> instance = setType ? new HashSet<>(Arrays.asList(values))
                            : Arrays.asList(values);
                    LOG.debug("() collection {} (set {}): {}", key, setType, instance);
                    beans.put(key, instance);
                    dependencies.put(key, new HashSet<>());
                } else {
                    LOG.debug("() listing {}", className);
                    Class<? extends Object> c = Class.forName(className);
                    classList.add(c);
                    nameList.add(key);
                } // if
            } // if
        } // if
    } // for
    LOG.info("() beanlist {}", beanlist);

    // List annotated beans
    final Set<Class<Object>> classes = classResolver.getAnnotated(Singleton.class);
    LOG.info("() number of annotated beans {}", classes.size());
    for (Class<? extends Object> c : classes) {
        classList.add(c);
        nameList.add(null);
    } // for
    LOG.debug("() beans {}", beans.keySet());

    // Instanciate beans from the properties files and from annotations taking constructor injection dependencies into account
    int ripCord = 10;
    while ((ripCord > 0) && (!classList.isEmpty())) {
        LOG.debug("() trying {} beans: {}", nameList.size(), classList);
        ripCord--;
        List<Class<?>> restClassList = new ArrayList<>();
        List<String> restNameList = new ArrayList<>();
        for (int i = 0; i < classList.size(); i++) {
            try {
                createAndRegisterInstance(dependencies, classList.get(i), nameList.get(i));
            } catch (Exception e) {
                LOG.warn("() will retry {} later: {} - {}", classList.get(i), e.getClass().getName(),
                        e.getMessage());
                restClassList.add(classList.get(i));
                restNameList.add(nameList.get(i));
            } // try/catch
        } // for
        classList = restClassList;
        nameList = restNameList;
    } // while

    // Fill in injections and note needed dependencies
    for (String key : new HashSet<>(beans.keySet())) {
        injectDependencies(dependencies, key, beans.get(key));
    } // for

    // sort beans according to dependencies
    LOG.info("() sorting beans according to dependencies");
    ripCord = 10;
    while ((ripCord > 0) && (!dependencies.isEmpty())) {
        ripCord--;
        LOG.info("() {} beans left", dependencies.size());
        Set<String> deletions = new HashSet<>();
        for (String key : dependencies.keySet()) {
            LOG.debug("() checking if {} with {} dependencies can be safely put into the ordered list {}", key,
                    dependencies.get(key).size(), dependencies.get(key));
            boolean dependenciesMet = true;
            for (Object dep : dependencies.get(key)) {
                boolean isMet = orderedBeans.contains(dep);
                LOG.debug("() {} depends on {} :{} missing? {} collection= {}", key, dep,
                        dep.getClass().getName(), !isMet, (dep instanceof Collection));
                dependenciesMet = dependenciesMet && isMet;
            } // for
            if (dependenciesMet) {
                LOG.info("() adding {} to the list {}", key, orderedBeans);
                orderedBeans.add(beans.get(key));
                deletions.add(key);
            } // if
        } // for
        for (String key : deletions) {
            dependencies.remove(key);
        } // for
    } // while
    if (dependencies.size() > 0) {
        throw new Exception("Circular bean injection and initialization dependencies detected after "
                + (System.currentTimeMillis() - start) + "ms" + " " + dependencies);
    } // if

    // Call Post Construct
    LOG.info("() calling post construct on ordered beans {}", orderedBeans);
    for (Object bean : orderedBeans) {
        LOG.info("() bean {}", bean);
        callPostConstruct(bean);
    } // for
    LOG.info("() calling post construct for the rest of the beans");
    for (String key : beans.keySet()) {
        Object bean = beans.get(key);
        if (!orderedBeans.contains(bean) && !String.class.isAssignableFrom(bean.getClass())) {
            LOG.warn("() bean without dependencies to call post construct method on {} :{}", key,
                    bean.getClass().getSimpleName());
            callPostConstruct(bean);
        } // if
    } // for
    LOG.info("() setup completed after {}ms", (System.currentTimeMillis() - start));
}

From source file:org.openmrs.util.OpenmrsUtilTest.java

/**
 * test the collection contains method//from  ww  w  .  j  a v  a  2  s .c  o  m
 * 
 * @see OpenmrsUtil#collectionContains(Collection<*>,Object)
 */
@Test
public void collectionContains_shouldUseEqualsMethodForComparisonInsteadOfCompareToGivenSortedSetCollection() {

    SortedSet<PatientIdentifier> identifiers = new TreeSet<>();

    PatientIdentifier pi = new PatientIdentifier();
    pi.setIdentifier("123");
    pi.setIdentifierType(new PatientIdentifierType(1));
    pi.setDateCreated(new Date());
    pi.setCreator(new User(1));

    identifiers.add(pi);

    // sanity check
    identifiers.add(pi);
    assertTrue("There should still be only 1 identifier in the patient object now", identifiers.size() == 1);

    pi.setDateCreated(null);
    pi.setCreator(null);

    assertTrue("Just because the date is null, doesn't make it not in the list anymore",
            OpenmrsUtil.collectionContains(identifiers, pi));
}

From source file:org.apache.blur.store.hdfs.HdfsDirectory.java

@Override
public String[] listAll() throws IOException {
    LOG.debug("listAll [{0}]", getPath());

    if (_useCache) {
        Set<String> names = new HashSet<String>(_fileStatusMap.keySet());
        return names.toArray(new String[names.size()]);
    }/* w  w w  .j ava2s  .  com*/

    Tracer trace = Trace.trace("filesystem - list", Trace.param("path", getPath()));
    try {
        FileStatus[] files = _fileSystem.listStatus(getPath(), new PathFilter() {
            @Override
            public boolean accept(Path path) {
                try {
                    return _fileSystem.isFile(path);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        SortedSet<String> result = new TreeSet<String>();
        for (int i = 0; i < files.length; i++) {
            String name = files[i].getPath().getName();
            if (name.endsWith(LNK)) {
                result.add(getRealFileName(name));
            } else {
                result.add(name);
            }
        }
        return result.toArray(new String[result.size()]);
    } finally {
        trace.done();
    }
}

From source file:org.libreplan.business.test.orders.entities.OrderElementTest.java

@Test
@Transactional/*from  ww  w.j  a v  a  2s  .  c  o  m*/
public void checkAdvanceMeasurementMerge() throws DuplicateValueTrueReportGlobalAdvanceException,
        DuplicateAdvanceAssignmentForOrderElementException {

    OrderElement orderElement = givenOrderLineGroupWithTwoOrderLines(1000, 2000);

    List<OrderElement> children = orderElement.getChildren();

    LocalDate one = new LocalDate(2009, 9, 1);
    LocalDate two = new LocalDate(2009, 9, 2);
    LocalDate three = new LocalDate(2009, 9, 3);
    LocalDate four = new LocalDate(2009, 9, 4);
    LocalDate five = new LocalDate(2009, 9, 5);

    AdvanceType advanceType = PredefinedAdvancedTypes.UNITS.getType();

    addAdvanceAssignmentWithMeasurements(children.get(0), advanceType, true, new BigDecimal(1000), one,
            new BigDecimal(200), three, new BigDecimal(400), five, new BigDecimal(500));

    addAdvanceAssignmentWithMeasurements(children.get(1), advanceType, true, new BigDecimal(1000), two,
            new BigDecimal(100), three, new BigDecimal(350), four, new BigDecimal(400));

    assertThat(orderElement.getAdvancePercentage(), sameValueAs(division.divide(4333, 10000)));

    Set<DirectAdvanceAssignment> directAdvanceAssignments = orderElement.getDirectAdvanceAssignments();
    assertThat(directAdvanceAssignments.size(), equalTo(0));

    Set<IndirectAdvanceAssignment> indirectAdvanceAssignments = orderElement.getIndirectAdvanceAssignments();
    assertThat(indirectAdvanceAssignments.size(), equalTo(2));

    DirectAdvanceAssignment advanceAssignment = null;
    for (IndirectAdvanceAssignment indirectAdvanceAssignment : indirectAdvanceAssignments) {
        if (indirectAdvanceAssignment.getAdvanceType().equals(advanceType)) {
            advanceAssignment = orderElement.calculateFakeDirectAdvanceAssignment(indirectAdvanceAssignment);
            break;
        }
    }
    assertThat(advanceAssignment.getMaxValue(), equalTo(new BigDecimal(2000)));

    SortedSet<AdvanceMeasurement> advanceMeasurements = advanceAssignment.getAdvanceMeasurements();
    assertThat(advanceMeasurements.size(), equalTo(5));

    ArrayList<AdvanceMeasurement> list = new ArrayList<>(advanceMeasurements);
    Collections.sort(list, new AdvanceMeasurementComparator());
    Collections.reverse(list);
    Iterator<AdvanceMeasurement> iterator = list.iterator();

    AdvanceMeasurement next = iterator.next();
    assertThat(next.getDate(), equalTo(one));
    assertThat(next.getValue(), equalTo(new BigDecimal(200)));

    next = iterator.next();
    assertThat(next.getDate(), equalTo(two));
    assertThat(next.getValue(), equalTo(new BigDecimal(300)));

    next = iterator.next();
    assertThat(next.getDate(), equalTo(three));
    assertThat(next.getValue(), equalTo(new BigDecimal(750)));

    next = iterator.next();
    assertThat(next.getDate(), equalTo(four));
    assertThat(next.getValue(), equalTo(new BigDecimal(800)));

    next = iterator.next();
    assertThat(next.getDate(), equalTo(five));
    assertThat(next.getValue(), equalTo(new BigDecimal(900)));

}

From source file:org.libreplan.business.test.orders.entities.OrderElementTest.java

@Test
@Transactional/*from  w w  w .  j  a  v a  2s  . c  o m*/
public void checkAdvanceMeasurementMergePercentageAdvanceType()
        throws DuplicateValueTrueReportGlobalAdvanceException,
        DuplicateAdvanceAssignmentForOrderElementException {

    OrderElement orderElement = givenOrderLineGroupWithTwoOrderLines(1000, 2000);

    List<OrderElement> children = orderElement.getChildren();

    LocalDate one = new LocalDate(2009, 9, 1);
    LocalDate two = new LocalDate(2009, 9, 2);
    LocalDate three = new LocalDate(2009, 9, 3);
    LocalDate four = new LocalDate(2009, 9, 4);
    LocalDate five = new LocalDate(2009, 9, 5);

    AdvanceType advanceType = PredefinedAdvancedTypes.PERCENTAGE.getType();

    addAdvanceAssignmentWithMeasurements(children.get(0), advanceType, true, new BigDecimal(100), two,
            new BigDecimal(10), three, new BigDecimal(20), four, new BigDecimal(40));

    addAdvanceAssignmentWithMeasurements(children.get(1), advanceType, true, new BigDecimal(100), one,
            new BigDecimal(10), four, new BigDecimal(20), five, new BigDecimal(50));

    assertThat(orderElement.getAdvancePercentage(), sameValueAs(division.divide(4666, 10000)));

    Set<DirectAdvanceAssignment> directAdvanceAssignments = orderElement.getDirectAdvanceAssignments();
    assertThat(directAdvanceAssignments.size(), equalTo(0));

    Set<IndirectAdvanceAssignment> indirectAdvanceAssignments = orderElement.getIndirectAdvanceAssignments();
    assertThat(indirectAdvanceAssignments.size(), equalTo(2));

    DirectAdvanceAssignment advanceAssignment = null;
    for (IndirectAdvanceAssignment indirectAdvanceAssignment : indirectAdvanceAssignments) {
        if (indirectAdvanceAssignment.getAdvanceType().equals(advanceType)) {
            advanceAssignment = orderElement.calculateFakeDirectAdvanceAssignment(indirectAdvanceAssignment);
            break;
        }
    }
    assertThat(advanceAssignment.getMaxValue(), equalTo(new BigDecimal(100)));

    SortedSet<AdvanceMeasurement> advanceMeasurements = advanceAssignment.getAdvanceMeasurements();
    assertThat(advanceMeasurements.size(), equalTo(5));

    ArrayList<AdvanceMeasurement> list = new ArrayList<>(advanceMeasurements);
    Collections.sort(list, new AdvanceMeasurementComparator());
    Collections.reverse(list);
    Iterator<AdvanceMeasurement> iterator = list.iterator();

    AdvanceMeasurement next = iterator.next();
    assertThat(next.getDate(), equalTo(one));
    assertThat(next.getValue(), equalTo(new BigDecimal(6)));
    // FIXME real value should be: 6.66

    next = iterator.next();
    assertThat(next.getDate(), equalTo(two));
    assertThat(next.getValue(), equalTo(new BigDecimal(9)));
    // FIXME real value should be: 10

    next = iterator.next();
    assertThat(next.getDate(), equalTo(three));
    assertThat(next.getValue(), equalTo(new BigDecimal(12)));
    // FIXME real value should be: 13.33

    next = iterator.next();
    assertThat(next.getDate(), equalTo(four));
    assertThat(next.getValue(), equalTo(new BigDecimal(24)));
    // FIXME real value should be: 26.66

    next = iterator.next();
    assertThat(next.getDate(), equalTo(five));
    assertThat(next.getValue(), equalTo(new BigDecimal(44)));
    // FIXME real value should be: 46.66

}

From source file:com.github.FraggedNoob.GitLabTransfer.GitlabRelatedData.java

/**
 * Obtains all notes for all project issues.
 * @return F indicates a problem, T success (beware T may mean no notes exist)
 *//* w  w w. ja va  2 s  .  c  om*/
public boolean getAllProjNotes() {

    SortedSet<GitlabNote> sortedNotes = new TreeSet<GitlabNote>(new NoteOrderByID());

    for (GitlabIssue i : issues) {
        if (!getIssueNotes(i, sortedNotes)) {
            return false;
        }
        if (sortedNotes.size() > 0) {
            issueNotes.put(i.getIid(), sortedNotes);
            sortedNotes = new TreeSet<GitlabNote>(new NoteOrderByID());
        }
    }

    return true;
}

From source file:org.libreplan.business.test.orders.entities.OrderElementTest.java

@Test
@Transactional/*from w w w . j  a v  a 2 s.c o  m*/
public void checkAdvanceMeasurementMergeWithDifferentAdvanceTypes()
        throws DuplicateValueTrueReportGlobalAdvanceException,
        DuplicateAdvanceAssignmentForOrderElementException {

    OrderElement orderElement = givenOrderLineGroupWithTwoOrderLines(1000, 2000);

    List<OrderElement> children = orderElement.getChildren();

    LocalDate one = new LocalDate(2009, 9, 1);
    LocalDate two = new LocalDate(2009, 9, 2);
    LocalDate three = new LocalDate(2009, 9, 3);
    LocalDate four = new LocalDate(2009, 9, 4);
    LocalDate five = new LocalDate(2009, 9, 5);

    AdvanceType advanceType1 = AdvanceType.create("test1", new BigDecimal(10000), true, new BigDecimal(1), true,
            false);

    addAdvanceAssignmentWithMeasurements(children.get(0), advanceType1, true, new BigDecimal(1000), one,
            new BigDecimal(200), three, new BigDecimal(400), five, new BigDecimal(500));

    AdvanceType advanceType2 = AdvanceType.create("test2", new BigDecimal(10000), true, new BigDecimal(1), true,
            false);

    addAdvanceAssignmentWithMeasurements(children.get(1), advanceType2, true, new BigDecimal(1000), two,
            new BigDecimal(100), three, new BigDecimal(350), four, new BigDecimal(400));

    assertThat(orderElement.getAdvancePercentage(), sameValueAs(division.divide(4333, 10000)));

    Set<DirectAdvanceAssignment> directAdvanceAssignments = orderElement.getDirectAdvanceAssignments();
    assertThat(directAdvanceAssignments.size(), equalTo(0));

    Set<IndirectAdvanceAssignment> indirectAdvanceAssignments = orderElement.getIndirectAdvanceAssignments();
    assertThat(indirectAdvanceAssignments.size(), equalTo(3));

    DirectAdvanceAssignment advanceAssignment = null;
    for (IndirectAdvanceAssignment indirectAdvanceAssignment : indirectAdvanceAssignments) {

        if (indirectAdvanceAssignment.getAdvanceType().getUnitName()
                .equals(PredefinedAdvancedTypes.CHILDREN.getTypeName())) {

            advanceAssignment = orderElement.calculateFakeDirectAdvanceAssignment(indirectAdvanceAssignment);
            break;
        }
    }
    assertThat(advanceAssignment.getMaxValue(), equalTo(new BigDecimal(100)));

    SortedSet<AdvanceMeasurement> advanceMeasurements = advanceAssignment.getAdvanceMeasurements();
    assertThat(advanceMeasurements.size(), equalTo(5));

    ArrayList<AdvanceMeasurement> list = new ArrayList<>(advanceMeasurements);
    Collections.sort(list, new AdvanceMeasurementComparator());
    Collections.reverse(list);
    Iterator<AdvanceMeasurement> iterator = list.iterator();

    AdvanceMeasurement next = iterator.next();
    assertThat(next.getDate(), equalTo(one));

    assertThat(next.getValue(), sameValueAs(division.divide(66600, 10000)));

    next = iterator.next();
    assertThat(next.getDate(), equalTo(two));
    assertThat(next.getValue(), sameValueAs(division.divide(133300, 10000)));

    next = iterator.next();
    assertThat(next.getDate(), equalTo(three));
    assertThat(next.getValue(), sameValueAs(division.divide(366600, 10000)));

    next = iterator.next();
    assertThat(next.getDate(), equalTo(four));
    assertThat(next.getValue(), equalTo(new BigDecimal(40).setScale(4)));

    next = iterator.next();
    assertThat(next.getDate(), equalTo(five));
    assertThat(next.getValue(), sameValueAs(division.divide(4333, 100)));
}

From source file:org.apache.ctakes.ytex.kernel.KernelUtilImpl.java

@Override
public double[][] loadGramMatrix(SortedSet<Long> instanceIds, String name, String splitName, String experiment,
        String label, int run, int fold, double param1, String param2) {
    int foldId = 0;
    double[][] gramMatrix = null;
    if (run != 0 && fold != 0) {
        CrossValidationFold f = this.classifierEvaluationDao.getCrossValidationFold(name, splitName, label, run,
                fold);/*  ww w . jav  a 2  s. com*/
        if (f != null)
            foldId = f.getCrossValidationFoldId();
    }
    KernelEvaluation kernelEval = this.kernelEvaluationDao.getKernelEval(name, experiment, label, foldId,
            param1, param2);
    if (kernelEval == null) {
        log.warn("could not find kernelEvaluation.  name=" + name + ", experiment=" + experiment + ", label="
                + label + ", fold=" + fold + ", run=" + run);
    } else {
        gramMatrix = new double[instanceIds.size()][instanceIds.size()];
        fillGramMatrix(kernelEval, instanceIds, gramMatrix);
    }
    return gramMatrix;
}