@@ -31,9 +31,9 @@ public List<Object> loginTimeFrame(long from, long to, String scale, String idpE
3131 List <Object > result = new ArrayList <>();
3232 for (long i = from ; i <= to ; i += step ) {
3333 Map <String , Object > point = new HashMap <>();
34- point .put ("count_user_id" , countValue (scale ));
34+ point .put ("count_user_id" , countValue ());
3535 if (!"minute" .equals (scale ) && !"hour" .equals (scale )) {
36- point .put ("distinct_count_user_id" , countValue (scale ));
36+ point .put ("distinct_count_user_id" , countValue ());
3737 }
3838 if (StringUtils .hasText (spEntityId )) {
3939 point .put ("sp_entity_id" , spEntityId );
@@ -48,23 +48,27 @@ public List<Object> loginTimeFrame(long from, long to, String scale, String idpE
4848 @ Override
4949 public List <Object > loginAggregated (String period , String idpEntityId , String spEntityId ) {
5050 Calendar today = Calendar .getInstance ();
51- today .set (Calendar .YEAR , Integer .valueOf (period .substring (0 , 4 )));
51+ today .set (Calendar .YEAR , Integer .parseInt (period .substring (0 , 4 )));
5252 today .set (Calendar .HOUR_OF_DAY , 0 );
5353 today .set (Calendar .MINUTE , 0 );
5454 today .set (Calendar .DAY_OF_MONTH , 1 );
5555 if (period .length () > 4 ) {
5656 switch (period .substring (4 , 5 ).toUpperCase ()) {
5757 case "Q" : {
58- today .set (Calendar .MONTH , ((Integer .valueOf (period .substring (5 )) - 1 ) * 3 ));
58+ today .set (Calendar .MONTH , ((Integer .parseInt (period .substring (5 )) - 1 ) * 3 ));
59+ break ;
5960 }
6061 case "M" : {
61- today .set (Calendar .MONTH , Integer .valueOf (period .substring (5 )) - 1 );
62+ today .set (Calendar .MONTH , Integer .parseInt (period .substring (5 )) - 1 );
63+ break ;
6264 }
6365 case "W" : {
64- today .set (Calendar .WEEK_OF_YEAR , Integer .valueOf (period .substring (5 )));
66+ today .set (Calendar .WEEK_OF_YEAR , Integer .parseInt (period .substring (5 )));
67+ break ;
6568 }
6669 case "D" : {
67- today .set (Calendar .DAY_OF_YEAR , Integer .valueOf (period .substring (5 )));
70+ today .set (Calendar .DAY_OF_YEAR , Integer .parseInt (period .substring (5 )));
71+ break ;
6872 }
6973 }
7074 } else {
@@ -84,8 +88,8 @@ public List<Object> loginAggregated(String period, String idpEntityId, String sp
8488 .filter (sp -> !StringUtils .hasText (spEntityId ) || spEntityId .equals (getData (sp ).get ("entityid" )))
8589 .map (sp -> {
8690 Map <String , Object > point = new HashMap <>();
87- point .put ("count_user_id" , countValue (periodToScale ( period ) ));
88- point .put ("distinct_count_user_id" , countValue (periodToScale ( period ) ) / 2 );
91+ point .put ("count_user_id" , countValue ());
92+ point .put ("distinct_count_user_id" , countValue () / 2 );
8993 point .put ("sp_entity_id" , getData (sp ).get ("entityid" ));
9094 point .put ("idp_entity_id" , idpEntityId );
9195 point .put ("time" , date );
@@ -97,59 +101,29 @@ public List<Object> loginAggregated(String period, String idpEntityId, String sp
97101 public List <Object > uniqueLoginCount (long from , long to , String idpEntityId , String spEntityId ) {
98102 List <Object > result = new ArrayList <>();
99103 Map <String , Object > point = new HashMap <>();
100- point .put ("count_user_id" , countValue ("year" ));
104+ point .put ("count_user_id" , countValue ());
101105 point .put ("sp_entity_id" , spEntityId );
102106 point .put ("idp_entity_id" , idpEntityId );
103107 point .put ("time" , from );
104108 result .add (point );
105109 return result ;
106110 }
107111
108- private String periodToScale (String period ) {
109- if (period .length () == 4 ) {
110- return "year" ;
111- }
112- switch (period .substring (4 , 5 ).toLowerCase ()) {
113- case "d" :
114- return "day" ;
115- case "w" :
116- return "week" ;
117- case "m" :
118- return "month" ;
119- case "q" :
120- return "quarter" ;
121- default :
122- throw new IllegalArgumentException ("Unknown period:" + period );
123- }
124- }
125-
126- private long countValue (String scale ) {
112+ private long countValue () {
127113 double base = Math .floor (10000 * (Math .random () + 1 ));
128114 return (long ) base ;
129115 }
130116
131- private long doSwitch (String scale , long base ) {
132- switch (scale ) {
133- case "minute" :
134- return base * 60 ;
135- case "hour" :
136- return base * 60 * 60 ;
137- case "day" :
138- return base * 24 * 60 * 60 ;
139- case "week" :
140- return base * 7 * 24 * 60 * 60 ;
141- case "month" :
142- return base * 30 * 24 * 60 * 60 ;
143- case "quarter" :
144- return base * 90 * 24 * 60 * 60 ;
145- case "year" :
146- return base * 365 * 24 * 60 * 60 ;
147- default :
148- throw new IllegalArgumentException ("Unknown scale:" + scale );
149- }
150- }
151-
152117 private long step (String scale ) {
153- return doSwitch (scale , 1L );
118+ return switch (scale ) {
119+ case "minute" -> 60 ;
120+ case "hour" -> 60 * 60 ;
121+ case "day" -> 24 * 60 * 60 ;
122+ case "week" -> 7 * 24 * 60 * 60 ;
123+ case "month" -> 30 * 24 * 60 * 60 ;
124+ case "quarter" -> 90 * 24 * 60 * 60 ;
125+ case "year" -> 365 * 24 * 60 * 60 ;
126+ default -> throw new IllegalArgumentException ("Unknown scale:" + scale );
127+ };
154128 }
155129}
0 commit comments