Given a descending list of dates represented as longs, this method computes a map from the dates
to their age in (local) days.<p>

@param sortedDates a descending list of dates represented as longs

@return a map from dates to ages (measured in days)
978783
public Map<Long, Integer> computeDays(List<Long> sortedDates) {

        if (sortedDates.isEmpty()) {
            return Collections.<Long, Integer> emptyMap();
        }
        Map<Long, Integer> days = new HashMap<Long, Integer>();
        long lastDate = System.currentTimeMillis();
        int dayCounter = 0;
        for (Long dateObj : sortedDates) {
            long date = dateObj.longValue();
            long dayDifference = getDayDifference(lastDate, date);
            dayCounter += dayDifference;
            lastDate = date;
            days.put(dateObj, new Integer(dayCounter));
        }
        return days;
    }
953537
public static @Nullable Date mostRecent(Date @NotNull... dates) {
    Date mostRecentDate = null;
    for (Date date : dates) {
      if (date != null && (mostRecentDate == null || date.after(mostRecentDate))) {
        mostRecentDate = date;
      }
    }
    return mostRecentDate;
  }
622171
public static Date dateReservedYear999(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);

        return dateReservedYear999(calendar);
    }
1163045
private JSONValue datesToJsonArray(Collection<Date> dates) {

        if (null != dates) {
            JSONArray result = new JSONArray();
            for (Date d : dates) {
                result.set(result.size(), dateToJson(d));
            }
            return result;
        }
        return null;
    }
566574
public static <T> Map<Percentage, T> percentiles(final List<T> sortedList) {
        N.checkArgNotNullOrEmpty(sortedList, "The spcified 'sortedList' can not be null or empty");

        final int size = sortedList.size();
        final Map<Percentage, T> m = new LinkedHashMap<>(N.initHashCapacity(Percentage.values().length));

        for (Percentage p : Percentage.values()) {
            m.put(p, sortedList.get((int) (size * p.doubleValue())));
        }

        return ImmutableMap.of(m);
    }
905772
public static Map<Percentage, Long> percentiles(final long[] sortedArray) {
        N.checkArgNotNullOrEmpty(sortedArray, "The spcified 'sortedArray' can not be null or empty");

        final int len = sortedArray.length;
        final Map<Percentage, Long> m = new LinkedHashMap<>(N.initHashCapacity(Percentage.values().length));

        for (Percentage p : Percentage.values()) {
            m.put(p, sortedArray[(int) (len * p.doubleValue())]);
        }

        return ImmutableMap.of(m);
    }
33794
public static Fodselsnummer getFodselsnummerForDate(Date date){
		List<Fodselsnummer> fodselsnummerList = getManyFodselsnummerForDate(date);
		Collections.shuffle(fodselsnummerList);
		return fodselsnummerList.get(0);
	}
889470
public void getCalendarDateFromFixedDate(CalendarDate date,
                                             long fixedDate) {
        Date gdate = (Date) date;
        int year;
        long jan1;
        boolean isLeap;
        if (gdate.hit(fixedDate)) {
            year = gdate.getCachedYear();
            jan1 = gdate.getCachedJan1();
            isLeap = isLeapYear(year);
        } else {
            // Looking up FIXED_DATES[] here didn't improve performance
            // much. So we calculate year and jan1. getFixedDate()
            // will look up FIXED_DATES[] actually.
            year = getGregorianYearFromFixedDate(fixedDate);
            jan1 = getFixedDate(year, JANUARY, 1, null);
            isLeap = isLeapYear(year);
            // Update the cache data
            gdate.setCache (year, jan1, isLeap ? 366 : 365);
        }

        int priorDays = (int)(fixedDate - jan1);
        long mar1 = jan1 + 31 + 28;
        if (isLeap) {
            ++mar1;
        }
        if (fixedDate >= mar1) {
            priorDays += isLeap ? 1 : 2;
        }
        int month = 12 * priorDays + 373;
        if (month > 0) {
            month /= 367;
        } else {
            month = CalendarUtils.floorDivide(month, 367);
        }
        long month1 = jan1 + ACCUMULATED_DAYS_IN_MONTH[month];
        if (isLeap && month >= MARCH) {
            ++month1;
        }
        int dayOfMonth = (int)(fixedDate - month1) + 1;
        int dayOfWeek = getDayOfWeekFromFixedDate(fixedDate);
        assert dayOfWeek > 0 : "negative day of week " + dayOfWeek;
        gdate.setNormalizedYear(year);
        gdate.setMonth(month);
        gdate.setDayOfMonth(dayOfMonth);
        gdate.setDayOfWeek(dayOfWeek);
        gdate.setLeapYear(isLeap);
        gdate.setNormalized(true);
    }
582066
public static <D extends Comparable> DateExpression<D> addDays(DateExpression<D> date, int days) {
        return Expressions.dateOperation(date.getType(), Ops.DateTimeOps.ADD_DAYS, date, ConstantImpl.create(days));
    }
972071
public static <K, V> SortedMap<K, V> unmodifiableSortedMap(final SortedMap<K, ? extends V> m) {
		return Collections.unmodifiableSortedMap(m);
	}
806143
public static long subYears(final Date date1, final Date date2) {

    return Math.abs(getYear(date1) - getYear(date2));
  }
271404
public static Date substractYearsFromDate(final Date date, final int substractYears)
	{
		final Calendar dateOnCalendar = Calendar.getInstance();
		dateOnCalendar.setTime(date);
		dateOnCalendar.add(Calendar.YEAR, substractYears * -1);
		return dateOnCalendar.getTime();
	}
638980
public static String getDateTerms(long date) {

        Calendar cal = Calendar.getInstance(OpenCms.getLocaleManager().getTimeZone());
        cal.setTimeInMillis(date);
        String day = CmsSearchIndex.DATES[cal.get(5)];
        String month = CmsSearchIndex.DATES[(cal.get(2) + 1)];
        String year = String.valueOf(cal.get(1));

        StringBuffer result = new StringBuffer();
        result.append(year);
        result.append(month);
        result.append(day);
        result.append(' ');
        result.append(year);
        result.append(month);
        result.append(' ');
        result.append(year);
        return result.toString();
    }
348569
public Comparer<Long> since(String targetDate) {
		return since(this.style.from().apply(targetDate));
	}
207838
private static long getMostRecentDate(CmsObject cms) {

        long mostRecentDate = Long.MIN_VALUE;

        try {
            final List<CmsResource> resources = cms.getResourcesInFolder(
                DEFAULT_DICTIONARY_DIRECTORY,
                CmsResourceFilter.DEFAULT_FILES);

            for (final CmsResource resource : resources) {
                final String resourceName = resource.getName();
                // Check whether the resource matches the desired patterns
                if (resourceName.matches(DICTIONARY_NAME_REGEX)
                    || resourceName.matches(ZIP_NAME_REGEX)
                    || resourceName.matches(CUSTOM_DICTIONARY)) {
                    if (resource.getDateLastModified() > mostRecentDate) {
                        mostRecentDate = resource.getDateLastModified();
                    }
                }
            }
        } catch (CmsException e) {
            LOG.error("Could not read spellchecker dictionaries. ");
        }

        return mostRecentDate;
    }
1308329
public static List<DayOfTheWeek> getPart(@NotNull final DayOfTheWeek from, @NotNull final DayOfTheWeek to) {
        final List<DayOfTheWeek> days = new ArrayList<>();
        for (final DayOfTheWeek day : ALL) {
            if (day.id >= from.id && day.id <= to.id) {
                days.add(day);
            }
        }
        return Collections.unmodifiableList(days);
    }
587886
public static Date[] getHolidays(int year) {
		Set<Date> days = getHolidaySet(year);
		Date[] dates = days.toArray(new Date[days.size()]);
		Arrays.sort(dates);
		return dates;
	}