java - Faster method of Grouping Times -


i receive json object filled data , 1 of tasks data group times together.

for example, if game_time 12:15 pm should under 12 pm header.

i came solution monstrosity , difficult debug, there has better way this.

    dbdate = dateformatter.parse(json_data.getstring("game_time"));  if (dbdate.compareto(dateformatter.parse("12:00 am")) == 0 || dbdate.compareto(dateformatter.parse("1:00 am") ) < 0)  {     users12am.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("1:00 am")) == 0 || dbdate.compareto(dateformatter.parse("2:00 am"))  < 0) {     users1am.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("2:00 am")) == 0 || dbdate.compareto(dateformatter.parse("3:00 am"))  < 0) {     users2am.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("3:00 am")) == 0 || dbdate.compareto(dateformatter.parse("4:00 am"))  < 0) {     users3am.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("4:00 am")) == 0 || dbdate.compareto(dateformatter.parse("5:00 am"))  < 0) {     users4am.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("5:00 am")) == 0 || dbdate.compareto(dateformatter.parse("6:00 am"))  < 0) {     users5am.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("6:00 am")) == 0 || dbdate.compareto(dateformatter.parse("7:00 am"))  < 0) {     users6am.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("7:00 am")) == 0 || dbdate.compareto(dateformatter.parse("8:00 am"))  < 0) {     users7am.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("8:00 am")) == 0 || dbdate.compareto(dateformatter.parse("9:00 am"))  < 0) {     users8am.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("9:00 am")) == 0 || dbdate.compareto(dateformatter.parse("10:00 am"))  < 0) {     users9am.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("10:00 am")) == 0 || dbdate.compareto(dateformatter.parse("11:00 am"))  < 0) {     users10am.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("11:00 pm")) == 0 || dbdate.compareto(dateformatter.parse("12:00 pm"))  < 0) {     users11am.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("12:00 pm")) == 0 || dbdate.compareto(dateformatter.parse("1:00 pm"))  < 0) {     users12pm.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("1:00 pm")) == 0 || dbdate.compareto(dateformatter.parse("2:00 pm"))  < 0) {     users1pm.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("2:00 pm")) == 0 || dbdate.compareto(dateformatter.parse("3:00 pm"))  < 0) {     users2pm.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("3:00 pm")) == 0 || dbdate.compareto(dateformatter.parse("4:00 pm"))  < 0) {     users3pm.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("4:00 pm")) == 0 || dbdate.compareto(dateformatter.parse("5:00 pm"))  < 0) {     users4pm.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("5:00 pm")) == 0 || dbdate.compareto(dateformatter.parse("6:00 pm"))  < 0) {     users5pm.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("6:00 pm")) == 0 || dbdate.compareto(dateformatter.parse("7:00 pm"))  < 0) {     users6pm.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("7:00 pm")) == 0 || dbdate.compareto(dateformatter.parse("8:00 pm"))  < 0) {     users7pm.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("8:00 pm")) == 0 || dbdate.compareto(dateformatter.parse("9:00 pm"))  < 0) {     users8pm.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("9:00 pm")) == 0 || dbdate.compareto(dateformatter.parse("10:00 pm"))  < 0) {     users9pm.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("10:00 pm")) == 0 || dbdate.compareto(dateformatter.parse("11:00 pm"))  < 0) {     users10pm.add(json_data.getstring("in_game_name")); } else if (dbdate.compareto(dateformatter.parse("11:00 pm")) == 0 || dbdate.compareto(dateformatter.parse("12:00 pm"))  < 0) {     users11pm.add(json_data.getstring("in_game_name")); } 

store in hashmap<date,string>. date key, identifying "group", , string ingame_name. first fill hashmap empty groups, , iterate on them.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -