當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalDateTime.compareTo方法代碼示例

本文整理匯總了Java中java.time.LocalDateTime.compareTo方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDateTime.compareTo方法的具體用法?Java LocalDateTime.compareTo怎麽用?Java LocalDateTime.compareTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.LocalDateTime的用法示例。


在下文中一共展示了LocalDateTime.compareTo方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: compareTo

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Override
public final int compareTo(Entry<?> other) {
    if (isFullDay() && other.isFullDay()) {
        return getStartDate().compareTo(other.getStartDate());
    }

    if (isFullDay()) {
        return -1;
    }

    if (other.isFullDay()) {
        return +1;
    }

    LocalDateTime a = LocalDateTime.of(getStartDate(), getStartTime());
    LocalDateTime b = LocalDateTime.of(other.getStartDate(), other.getStartTime());
    int result = a.compareTo(b);
    if (result == 0) {
        String titleA = getTitle() != null ? getTitle() : ""; //$NON-NLS-1$
        String titleB = other.getTitle() != null ? other.getTitle() : ""; //$NON-NLS-1$
        result = titleA.compareTo(titleB);
    }

    return result;
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:26,代碼來源:Entry.java

示例2: splitDatesIntoMonths

import java.time.LocalDateTime; //導入方法依賴的package包/類
public static List<Date[]> splitDatesIntoMonths(Date from, Date to) throws IllegalArgumentException {

    List<Date[]> dates = new ArrayList<>();

    LocalDateTime dFrom = asLocalDateTime(from);
    LocalDateTime dTo = asLocalDateTime(to);

    if (dFrom.compareTo(dTo) >= 0) {
      throw new IllegalArgumentException("Provide a to-date greater than the from-date");
    }

    while (dFrom.compareTo(dTo) < 0) {
      // check if current time frame is last
      boolean isLastTimeFrame = dFrom.getMonthValue() == dTo.getMonthValue() && dFrom.getYear() == dTo.getYear();

      // define day of month based on timeframe. if last - take boundaries from end date, else end of month and date
      int dayOfMonth = isLastTimeFrame ? dTo.getDayOfMonth() : dFrom.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
      LocalTime time = isLastTimeFrame ? dTo.toLocalTime() : LocalTime.MAX;


      // build timeframe
      Date[] dar = new Date[2];
      dar[0] = asDate(dFrom);
      dar[1] = asDate(dFrom.withDayOfMonth(dayOfMonth).toLocalDate().atTime(time));

      // add current timeframe
      dates.add(dar);

      // jump to beginning of next month
      dFrom = dFrom.plusMonths(1).withDayOfMonth(1).toLocalDate().atStartOfDay();
    }

    return dates;

  }
 
開發者ID:YagelNasManit,項目名稱:environment.monitor,代碼行數:36,代碼來源:DataUtils.java

示例3: determineDateRanges

import java.time.LocalDateTime; //導入方法依賴的package包/類
public void determineDateRanges() {
    	for(MatchableTableRow row : records.get()) {
    		
    		for(MatchableTableColumn col : schema.get()) {
    			
    			if(col.getType()==DataType.date) {
    				
    				LocalDateTime[] range = MapUtils.get(dateRanges, col.getColumnIndex(), new LocalDateTime[2]);
    				
    				Map<Integer, Integer> indexTranslation = getPropertyIndices().get(row.getTableId());
    				if(indexTranslation==null) {
    					System.err.println("Missing property index translation for table " + row.getTableId());
    				}
    				
//    				'secondColumnIndex' ('globalId' of dbpedia property) is used to get 'columnIndex' of dbpedia property in a respective table
    				Integer translatedIndex = indexTranslation.get(col.getColumnIndex());
    				if(translatedIndex!=null) {

	    				Object obj = row.get(translatedIndex);
	    				
	    				if(obj!=null && obj instanceof LocalDateTime) {
	    				
	    					LocalDateTime value = (LocalDateTime)row.get(translatedIndex);
	    					
	    					if(range[0]==null || value.compareTo(range[0]) < 0) {
	    						range[0] = value;
	    					}
	    					
	    					if(range[1]==null || value.compareTo(range[1]) > 0) {
	    						range[1] = value;
	    					}
	    					
	    				} else {
	    					if(obj!=null && !(obj instanceof LocalDateTime)) {
	    						System.err.println(String.format("{%s} row %d property %s has value of invalid type: '%s' (%s)", this.classIndices.get(row.getTableId()), row.getRowNumber(), col.getIdentifier(), obj, obj.getClass()));
	    					}
	    				}
    				}
    				
    			}
    			
    		}
    		
    	}
    }
 
開發者ID:olehmberg,項目名稱:T2KMatch,代碼行數:46,代碼來源:KnowledgeBase.java

示例4: RangeOfLocalDateTimes

import java.time.LocalDateTime; //導入方法依賴的package包/類
/**
 * Constructor
 * @param start     the start for range, inclusive
 * @param end       the end for range, exclusive
 * @param step      the step increment
 * @param excludes  optional predicate to exclude elements in this range
 */
RangeOfLocalDateTimes(LocalDateTime start, LocalDateTime end, Duration step, Predicate<LocalDateTime> excludes) {
    super(start, end);
    this.step = step;
    this.ascend = start.compareTo(end) <= 0;
    this.excludes = excludes;
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:14,代碼來源:RangeOfLocalDateTimes.java

示例5: inBounds

import java.time.LocalDateTime; //導入方法依賴的package包/類
/**
 * Checks that the value specified is in the bounds of this range
 * @param value     the value to check if in bounds
 * @return          true if in bounds
 */
private boolean inBounds(LocalDateTime value) {
    return ascend ? value.compareTo(start()) >=0 && value.isBefore(end()) : value.compareTo(start()) <=0 && value.isAfter(end());
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:9,代碼來源:RangeOfLocalDateTimes.java


注:本文中的java.time.LocalDateTime.compareTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。