Example usage for java.lang Short compare

List of usage examples for java.lang Short compare

Introduction

In this page you can find the example usage for java.lang Short compare.

Prototype

public static int compare(short x, short y) 

Source Link

Document

Compares two short values numerically.

Usage

From source file:Main.java

public static void main(String[] args) {
    short s1 = 1;
    short s2 = 2;
    System.out.println(Short.compare(s1, s2));
}

From source file:com.linkedin.cubert.memory.ShortArrayList.java

@Override
public int compareIndices(int i1, int i2) {
    return Short.compare(getShort(i1), getShort(i2));
}

From source file:se.uu.it.cs.recsys.service.preference.SameCourseFinder.java

/**
 * Gets the info about course id collection representing the same course.
 * E.g a course with code "1DL301" can be planned in year 2015 and 2016 and
 * it will have different ids in DB in this case.
 *
 * @param scheduleInfo the info regarding which years are planned, e.g 2015;
 * non-empty input./*from ww  w.  jav  a  2  s. c om*/
 * @return non-null collection regarding id set for same course.
 * @throws IllegalArgumentException if input is null or empty
 */
public Set<Set<Integer>> getIdCollectionForSameCourse(Set<CourseSchedule> scheduleInfo) {

    if (scheduleInfo == null || scheduleInfo.isEmpty()) {
        throw new IllegalArgumentException("Schedule input must be non-empty");
    }

    List<Course> allCourses = this.courseRepository.findAll();

    // find the first plan year, e.g 2015
    int firstPlanYear = scheduleInfo.stream().sorted(
            (schedule1, schedule2) -> Short.compare(schedule1.getTaughtYear(), schedule2.getTaughtYear()))
            .findFirst().get().getTaughtYear();

    // only get the course ids for plan year, e.g 2015, 2016
    Set<Course> planYearCourseSet = allCourses.stream()
            .filter(course -> course.getTaughtYear() >= firstPlanYear).collect(Collectors.toSet());

    Map<String, Set<Integer>> codeToIdSet = CourseFlattener.flattenToCodeAndIdSet(planYearCourseSet);

    Set<Set<Integer>> idCollectionForSameCourse = new HashSet<>();

    codeToIdSet.entrySet().stream().filter(entry -> entry.getValue().size() > 1).forEach(entry -> {
        idCollectionForSameCourse.add(entry.getValue());
    });

    return idCollectionForSameCourse;
}

From source file:se.uu.it.cs.recsys.service.preference.ConstraintSolverPreferenceBuilder.java

private static short getFirstPlanYear(Set<CourseSchedule> scheduleInfo) {
    return scheduleInfo.stream().sorted((s1, s2) -> Short.compare(s1.getTaughtYear(), s2.getTaughtYear()))
            .findFirst().get().getTaughtYear();
}

From source file:se.uu.it.cs.recsys.service.preference.ConstraintSolverPreferenceBuilder.java

private static boolean inPlanYear(Course course, Set<CourseSchedule> scheduleInfo) {
    Set<Boolean> bingo = new HashSet<>();

    scheduleInfo.forEach(schedule -> {
        if (Short.compare(course.getTaughtYear(), schedule.getTaughtYear()) == 0
                && Short.compare(course.getStartPeriod(), schedule.getStartPeriod()) == 0) {
            bingo.add(Boolean.TRUE);
        }//from w w  w  .ja  v a  2 s .c  om
    });

    return !bingo.isEmpty();

}

From source file:com.sonicle.webtop.mail.MailManager.java

public void applySieveScript(boolean activate) throws WTException {
    UserProfile.Data ud = WT.getUserData(getTargetProfileId());
    SieveScriptBuilder ssb = new SieveScriptBuilder();
    MailServiceSettings mss = new MailServiceSettings(SERVICE_ID, getTargetProfileId().getDomainId());
    MailUserSettings mus = new MailUserSettings(getTargetProfileId(), mss);
    if (!mss.isSieveSpamFilterDisabled())
        ssb.setSpamFilter(mus.getFolderSpam());

    ensureUser();//from  w  w w.  j a  v a2  s  .c  om
    logger.debug("Working on autoresponder...");
    AutoResponder autoResp = getAutoResponder();
    if (autoResp.getEnabled()) {
        ssb.setVacation(autoResp.toSieveVacation(ud.getPersonalEmail(), ud.getTimeZone()));
    }

    logger.debug("Working on incoming filters...");
    List<MailFilter> filters = getMailFilters(MailFiltersType.INCOMING);

    // Arrange filters in the specified order and fill the builder
    Collections.sort(filters, new Comparator<MailFilter>() {
        @Override
        public int compare(MailFilter o1, MailFilter o2) {
            return Short.compare(o1.getOrder(), o2.getOrder());
        }
    });
    for (MailFilter filter : filters) {
        if (filter.getEnabled()) {
            ssb.addFilter(filter.getName(), filter.getSieveMatch(), filter.getSieveRules(),
                    filter.getSieveActions());
        }
    }

    String script = buildSieveScriptHeader() + ssb.build();

    ManageSieveClient client = null;
    try {
        if (sieveConfig == null)
            throw new WTException(
                    "SieveConfiguration not defined. Please call setSieveConfiguration(...) before call this method!");
        client = createSieveClient();
        SieveHelper.putScript(client, SIEVE_WEBTOP_SCRIPT, script);
        if (activate) {
            SieveHelper.activateScript(client, SIEVE_WEBTOP_SCRIPT);
        }
    } finally {
        SieveHelper.logoutSieveClientQuietly(client);
    }
}

From source file:org.apache.carbondata.core.scan.filter.FilterUtil.java

public static int compareFilterKeyBasedOnDataType(String dictionaryVal, String memberVal, DataType dataType) {
    try {/*from  w w w.j ava  2 s  .  c  o  m*/
        if (dataType == DataTypes.BOOLEAN) {
            return Boolean.compare((Boolean.parseBoolean(dictionaryVal)), (Boolean.parseBoolean(memberVal)));
        } else if (dataType == DataTypes.SHORT) {
            return Short.compare((Short.parseShort(dictionaryVal)), (Short.parseShort(memberVal)));
        } else if (dataType == DataTypes.INT) {
            return Integer.compare((Integer.parseInt(dictionaryVal)), (Integer.parseInt(memberVal)));
        } else if (dataType == DataTypes.DOUBLE) {
            return Double.compare((Double.parseDouble(dictionaryVal)), (Double.parseDouble(memberVal)));
        } else if (dataType == DataTypes.LONG) {
            return Long.compare((Long.parseLong(dictionaryVal)), (Long.parseLong(memberVal)));
        } else if (dataType == DataTypes.BOOLEAN) {
            return Boolean.compare((Boolean.parseBoolean(dictionaryVal)), (Boolean.parseBoolean(memberVal)));
        } else if (dataType == DataTypes.DATE || dataType == DataTypes.TIMESTAMP) {
            String format = CarbonUtil.getFormatFromProperty(dataType);
            SimpleDateFormat parser = new SimpleDateFormat(format);
            Date dateToStr;
            Date dictionaryDate;
            dateToStr = parser.parse(memberVal);
            dictionaryDate = parser.parse(dictionaryVal);
            return dictionaryDate.compareTo(dateToStr);
        } else if (DataTypes.isDecimal(dataType)) {
            java.math.BigDecimal javaDecValForDictVal = new java.math.BigDecimal(dictionaryVal);
            java.math.BigDecimal javaDecValForMemberVal = new java.math.BigDecimal(memberVal);
            return javaDecValForDictVal.compareTo(javaDecValForMemberVal);
        } else {
            return -1;
        }
    } catch (ParseException | NumberFormatException e) {
        return -1;
    }
}