Find the change in value in a time series

I have a card that stores the time series data of a person’s salary in the following format

HashMap<Date,Double> salaryHistory;

A variable salaryHistorycan have data from 1AD to 2100AD.

I use subMapto filter data from a hash map, but this is a task in the following scenario

Consider the salary of a person like this

Jan-01-1969, 100
Jan-01-1979, 200

When a user requests a salary from January 1 to January 1, 1970, subMapreturns "null", but in fact he should return 100, since in 1969 the person’s salary was 100, and it never changed until 1979.

Is there an easy way to do this? Like a library.

Please provide your valuable suggestions.

+4
2

, SortedMap, HashMap, :

   Date j1969 = DateTimeUtils.convertStringToDate("1969-01-01");
   Date j1974 = DateTimeUtils.convertStringToDate("1974-01-01");
   Date j1979 = DateTimeUtils.convertStringToDate("1979-01-01");
   Date j1989 = DateTimeUtils.convertStringToDate("1989-01-01");

   TreeMap<Date, Double> treemap = new TreeMap<Date, Double>();
   SortedMap<Date, Double> treemapincl = new TreeMap<Date, Double>();

   // populating tree map
   treemap.put(j1969, 100.0);
   treemap.put(j1979, 200.0);
   treemap.put(j1989, 300.0);

   treemapincl=treemap.subMap(j1969,j1974);
   System.out.println("Sub map values: "+treemapincl);   

:

Sub map values: {Wed Jan 01 00:00:00 GMT-05:00 1969=100.0}
+1

HashMap, TreeMap. TreeMap.floorEntry() Entry.

0

Source: https://habr.com/ru/post/1629834/


All Articles