java 如何在java中管理会议管理项目来跟踪时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12948406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to track time with management of items for conference management in java?
提问by GOK
I had written a program for extracting information from a file and i need to track up time in this problem and set up a conference schedule for the same
我编写了一个从文件中提取信息的程序,我需要跟踪这个问题的时间并为此设置一个会议时间表
Code:
代码:
package org.example;
import java.io.*;
import java.util.*;
public class Test {
public static void main(String[] args) {
try{
// Open the file that is the first command line parameter
FileInputStream fstream = new FileInputStream("C:\test.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String timer, strLine;
StringBuffer inputText = new StringBuffer();
StringBuffer timeFrames = new StringBuffer();
Map<String, String> mapper = new LinkedHashMap<String, String>();
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
inputText.append(strLine+"\n");
if("lightning".equalsIgnoreCase(strLine.substring(strLine.lastIndexOf(" ")+1))){
timeFrames.append("5min\n");
timer = "5min";
}else{
timeFrames.append(strLine.substring(strLine.lastIndexOf(" ")+1)+"\n");
timer = strLine.substring(strLine.lastIndexOf(" ")+1);
}
mapper.put(strLine, timer);
}
System.out.println("Input Text:");
System.out.println(inputText);
System.out.println("Time Frames");
System.out.println(timeFrames);
for (Map.Entry<String, String> entry : mapper.entrySet()) {
System.out.println(entry.getValue()+" "+entry.getKey());
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
test.txt:
测试.txt:
Writing Fast Tests Against Enterprise Rails 60min
Overdoing it in Python 45min
Lua for the Masses 30min
Ruby Errors from Mismatched Gem Versions 45min
Common Ruby Errors 45min
Rails for Python Developers lightning
Communicating Over Distance 60min
Accounting-Driven Development 45min
Woah 30min
Sit Down and Write 30min
Pair Programming vs Noise 45min
Rails Magic 60min
Ruby on Rails: Why We Should Move On 60min
Clojure Ate Scala (on my project) 45min
Programming in the Boondocks of Seattle 30min
Ruby vs. Clojure for Back-End Development 30min
Ruby on Rails Legacy App Maintenance 60min
A World Without HackerNews 30min
User Interface CSS in Rails Apps 30min
I need to perform calculations and set this items on track of a schedule to create a perfect conference.
我需要执行计算并将这些项目设置在时间表上以创建一个完美的会议。
The conference is starting from 09:00AN - 01-00; Lunch time - 01:00 - 02:00, second half is from 02:00 -05:00
会议从09:00AN - 01-00开始;午餐时间 - 01:00 - 02:00,下半场为 02:00 -05:00
Any ideas is well appreciated and thanks in advance
任何想法都非常感谢,并提前致谢
Cheers!!!
干杯!!!
回答by KappaMax
Okay, I'm going to take the algorithmic approach to answering your question. It looks like the classic Bin Packing algorithm, which is one of the NP-hard algorithms out there.
好的,我将采用算法方法来回答您的问题。它看起来像经典的装箱算法,它是 NP-hard 算法之一。
There's one thing you might want to do to optimize this if it's a real problem you're attempting to solve.
如果这是您尝试解决的实际问题,您可能需要做一件事来优化它。
Make sure you have enough hours in your day to handle your conference, including breaks and lunch. For example if you have 10hrs of content needed to fit in 1, 8hr day, in 1 track with 2hrs of breaks, you'd want this program to fail fast and tell you that you need to add more tracks to split up the talks. Of course if you're spliting up the tracks you may want to add an additional piece of data to keep similar talks on the same track. Again, if it's a real problem human curation of your list can help you, otherwise some more sophisticated techniques might be needed.
确保您一天中有足够的时间来处理您的会议,包括休息时间和午餐时间。例如,如果您需要 10 小时的内容来适应 1 天 8 小时的时间,在 1 个曲目中包含 2 小时的休息时间,您会希望该程序快速失败并告诉您需要添加更多曲目来拆分谈话。当然,如果您要拆分曲目,您可能需要添加额外的数据以在同一曲目上保持类似的谈话。同样,如果这是一个真正的问题,人工管理您的列表可以帮助您,否则可能需要一些更复杂的技术。
Okay, after you get that out of the way, you will then know the problem is solvable. If you don't then you're gonna be wasting your time and processor time.
好的,在你解决这个问题之后,你就会知道问题是可以解决的。如果你不这样做,那么你将浪费你的时间和处理器时间。
Then if the number is small, you can do a brute force algorithm to find all the possible combinations that fit in the specified time, which might be practical in terms of developer effort for a one-off real life problem, since the number N of talks is small. But again, if your problem is more academic... then you're going to need to apply a heuristic.
然后,如果数量很小,您可以执行蛮力算法以找到适合指定时间的所有可能组合,这对于一次性现实生活问题的开发人员努力而言可能是实用的,因为数量 N谈话很小。但同样,如果您的问题更具学术性……那么您将需要应用启发式方法。
回答by Aman Agnihotri
So following is my code for the ConferenceTrackManagement program. I kept the GUI code away from the logic. They both are in different classes. The only assumption my program makes is that you provide it with some proper input which can be segregated into proper tracks while following the rules which are provided.
下面是我的 ConferenceTrackManagement 程序代码。我让 GUI 代码远离逻辑。他们俩在不同的班级。我的程序所做的唯一假设是您为它提供了一些适当的输入,这些输入可以在遵循提供的规则的同时被分离到适当的轨道中。
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
public abstract class CommonInterface {
protected CommonInterface(final String title) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
makeGUI(title);
showGUI();
}
});
}
protected JFrame frame;
protected JTextArea textArea;
protected JButton button;
protected JLabel label;
protected String originalInputText, inputText, outputText = "";
protected void makeGUI(final String title) {
frame = new JFrame(title + " : By Aman Agnihotri");
textArea = new JTextArea(30, 40);
button = new JButton("Compute");
label = new JLabel("Test Input:");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBorder(new EmptyBorder(5, 5, 2, 5));
panel.add(label, BorderLayout.WEST);
panel.add(button, BorderLayout.EAST);
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setBorder(new EmptyBorder(2, 5, 5, 5));
frame.add(panel, BorderLayout.NORTH);
frame.add(scrollPane, BorderLayout.CENTER);
frame.pack();
frame.setMinimumSize(frame.getSize());
frame.setLocationRelativeTo(null);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (button.getText().equals("Compute")) {
refresh();
computeOutput();
button.setText("Back");
label.setText("Test Output:");
textArea.setText(outputText);
} else {
button.setText("Compute");
label.setText("Test Input:");
textArea.setText(originalInputText);
}
}
});
}
protected abstract void refresh();
protected abstract void computeOutput();
protected void showGUI() {
frame.setVisible(true);
}
}
public class ConferenceTrackManagement extends CommonInterface {
private String[] eventArray;
private int[] timeArray;
private boolean isOutputInvalid;
private final int MAX_TRACK_TIME = 420; // 1 Track Max Time = 420 minutes.
public ConferenceTrackManagement() {
super("Conference Track Management");
}
@Override
protected void refresh() {
isOutputInvalid = false;
outputText = "";
}
@Override
protected void computeOutput() {
originalInputText = textArea.getText();
inputText = originalInputText;
computeEventAndTimeArray();
if (!isOutputInvalid) {
computeTracks();
}
}
private int startIndex = -1, endIndex = -1, time;
private void computeTracks() {
int totalTime = getTotalTime();
int requiredTracks = totalTime / MAX_TRACK_TIME + 1;
sortEventAndTimeArray();
for (int i = 1; i <= requiredTracks; i++) {
boolean found = exactSubArraySum(timeArray, 180); // morning time
if (found) {
time = 9 * 60; // starts at 9 am [9 * 60 is in minutes]
outputText += "Track " + i + ":\n\n";
for (int j = startIndex; j <= endIndex; j++) {
outputText += timeStamp(time, "AM") + " " + eventArray[j]
+ "\n";
time += timeArray[j];
}
deleteProperElements();
outputText += "12:00PM Lunch\n";
boolean relativeFound = relativeSubArraySum(timeArray, 180, 240);
if (relativeFound) {
time = 60; // starts at 1 pm [1 * 60 is in minutes]
outputText += "\n";
for (int j = startIndex; j <= endIndex; j++) {
outputText += timeStamp(time, "PM") + " "
+ eventArray[j] + "\n";
time += timeArray[j];
}
deleteProperElements();
outputText += timeStamp(time, "PM") + " Networking Event"
+ "\n";
outputText += "\n\n";
}
} else
outputText = "No proper solution found.";
}
}
private String timeStamp(int time, String mode) {
String timeStamp = "";
int hours = time / 60;
int minutes = time % 60;
String hourHint = "", minuteHint = "";
if (hours < 10)
hourHint = "0";
if (minutes < 10)
minuteHint = "0";
timeStamp = hourHint + hours + ":" + minuteHint + minutes + mode;
return timeStamp;
}
private void deleteProperElements() {
String[] tempEventArray = new String[eventArray.length
- (endIndex - startIndex) - 1];
int[] tempTimeArray = new int[tempEventArray.length];
int index = 0;
for (int j = 0; j < startIndex; j++) {
tempEventArray[index] = eventArray[j];
tempTimeArray[index] = timeArray[j];
index++;
}
for (int j = endIndex + 1; j < eventArray.length; j++) {
tempEventArray[index] = eventArray[j];
tempTimeArray[index] = timeArray[j];
index++;
}
timeArray = tempTimeArray;
eventArray = tempEventArray;
}
private boolean exactSubArraySum(int array[], int sum) {
if (!(array.length >= 1))
return false;
int currentSum = array[0], start = 0;
for (int i = 1; i <= array.length; i++) {
while (currentSum > sum && start < i - 1) {
currentSum -= array[start];
start++;
}
if (currentSum == sum) {
startIndex = start;
endIndex = i - 1;
return true;
}
if (i < array.length)
currentSum += array[i];
}
return false; // No sub array found.
}
private boolean relativeSubArraySum(int array[], int minimumSum,
int maximumSum) {
if (!(array.length >= 1))
return false;
int currentSum = array[0], start = 0;
for (int i = 1; i <= array.length; i++) {
while (currentSum > maximumSum && start < i - 1) {
currentSum -= array[start];
start++;
}
if (currentSum >= minimumSum && currentSum <= maximumSum) {
startIndex = start;
endIndex = i - 1;
return true;
}
if (i < array.length)
currentSum += array[i];
}
return false; // No sub array found.
}
private void sortEventAndTimeArray() {
for (int i = 1; i < timeArray.length; i++) {
for (int j = 0; j < timeArray.length - i; j++) {
if (timeArray[j] > timeArray[j + 1]) {
int tempTime = timeArray[j];
timeArray[j] = timeArray[j + 1];
timeArray[j + 1] = tempTime;
String tempEvent = eventArray[j];
eventArray[j] = eventArray[j + 1];
eventArray[j + 1] = tempEvent;
}
}
}
}
private int getTotalTime() {
int timeSum = 0;
for (int i = 0; i < timeArray.length; i++)
timeSum += timeArray[i];
return timeSum;
}
private void computeEventAndTimeArray() {
String lines[] = inputText.split("[\r\n]+");
eventArray = new String[lines.length];
timeArray = new int[lines.length];
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
line = line.trim();
int lastIndexOfSpace = line.lastIndexOf(' ');
eventArray[i] = line.substring(0, lastIndexOfSpace);
String currentTime = line.substring(lastIndexOfSpace + 1);
currentTime = currentTime.toLowerCase();
if (currentTime.endsWith("lightning"))
setEventAndTimeFor(i, currentTime, "lightning", 5);
else if (currentTime.endsWith("min"))
setEventAndTimeFor(i, currentTime, "min", 1);
else {
setOutputAsInvalid(i);
}
}
}
private void setEventAndTimeFor(int i, String currentTime, String type,
int scale) {
String timeValue = currentTime.substring(0, currentTime.indexOf(type));
if (timeValue.equals(""))
timeArray[i] = scale;
else {
try {
timeArray[i] = Integer.parseInt(timeValue) * scale;
} catch (Exception e) {
setOutputAsInvalid(i);
}
}
}
private void setOutputAsInvalid(int lineNumber) {
outputText += "Invalid Time Entry in line " + (lineNumber + 1) + "\n";
isOutputInvalid = true;
}
public static void main(String args[]) {
new ConferenceTrackManagement();
}
}
回答by Raghavendra Prasad
package conference.time.management.main;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import conference.time.management.exceptions.InvalidTalkException;
public class ConferenceTimeManager {
public static void main(String[] args) {
String fileName = "D:\Java_Softwares\new-softwares\CTM.txt";
ConferenceTimeManager conferenceTimeManager = new ConferenceTimeManager();
try {
List<String> talkList = conferenceTimeManager
.getTalkListFromFile(fileName);
CopyOnWriteArrayList<String> talksWith60MinDuration = new CopyOnWriteArrayList<String>();
CopyOnWriteArrayList<String> talksWith45MinDuration = new CopyOnWriteArrayList<String>();
CopyOnWriteArrayList<String> talksWith30MinDuration = new CopyOnWriteArrayList<String>();
List<String> talksWithlightning = new ArrayList<String>();
for (String talk : talkList) {
if (talk.endsWith("60min")) {
talksWith60MinDuration.add(talk);
} else if (talk.endsWith("45min")) {
talksWith45MinDuration.add(talk);
} else if (talk.endsWith("30min")) {
talksWith30MinDuration.add(talk);
} else if (talk.endsWith("lightning")) {
talksWithlightning.add(talk);
} else {
throw new InvalidTalkException("Talk may not scheduled");
}
}
talksWith30MinDuration.addAll(talksWithlightning);
CopyOnWriteArrayList<String> sortedtalkList = new CopyOnWriteArrayList<String>();
sortedtalkList.addAll(talksWith60MinDuration);
sortedtalkList.addAll(talksWith45MinDuration);
sortedtalkList.addAll(talksWith30MinDuration);
/*
* for (String string : sortedtalkList) {
*
* System.out.println(string); }
*/
doNewTracking(sortedtalkList);
/*
* System.out.println(
* "#####################################################################################"
* ); List<String> unScheduled60MinTalks =
* prepareFirstDayMorningSessionWith180Min(talksWith60MinDuration);
* System.out.println(
* "****************************************************************"
* ); List<String> unScheduled45MinTalks =
* prepareSecondDayMorningSessionWith180Min(talksWith45MinDuration);
* System.out.println(
* "****************************************************************"
* ); CopyOnWriteArrayList<String> unScheduledTalks = new
* CopyOnWriteArrayList<String>();
* unScheduledTalks.addAll(unScheduled45MinTalks);
* unScheduledTalks.addAll(unScheduled60MinTalks);
*
* List<String> unScheduledMiscTalks =
* prepareFirstDayAfternoonSessionWith210Min(unScheduledTalks);
* System.out.println(
* "****************************************************************************"
* );
* prepareSecondDayAfternoonSessionWith215Min(talksWith30MinDuration
* );
*
* System.out.println(
* "------------------------------------------------------------------------"
* ); for (String unScheduledMiscTalk : unScheduledMiscTalks) {
* System.out.println(unScheduledMiscTalk); }
*/
} catch (InvalidTalkException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void doNewTracking(
CopyOnWriteArrayList<String> sortedtalkList) {
int firstDayMorningSession = 180;
int firstDayAfternoonSession = 210;
int secondDayMorningSession = 180;
int secondDayAfternoonSession = 215;
List<Integer> sessionList = new ArrayList<Integer>();
sessionList.add(firstDayMorningSession);
sessionList.add(firstDayAfternoonSession);
sessionList.add(secondDayMorningSession);
sessionList.add(secondDayAfternoonSession);
for (Integer session : sessionList) {
arrangeConf(sortedtalkList, session);
}
}
private static void arrangeConf(
CopyOnWriteArrayList<String> sortedtalkList, int maxLimit) {
Date date = new Date(0);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mma");
date.setHours(9);
date.setMinutes(0);
date.setSeconds(0);
Iterator<String> iterator = sortedtalkList.listIterator();
String timString = null;
String talk = null;
Date lunchdate = new Date(0);
SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mma");
lunchdate.setHours(12);
lunchdate.setMinutes(0);
lunchdate.setSeconds(0);
String dateLunch = dateFormat.format(lunchdate);
SimpleDateFormat dateFormat3 = null;
Date afterlunchdate = null;
int totalTime = 0;
while (iterator.hasNext()) {
talk = iterator.next();
if (totalTime > 450) {
date.setHours(9);
date.setMinutes(0);
date.setSeconds(0);
totalTime = 0;
}
timString = simpleDateFormat.format(date);
if (timString.equalsIgnoreCase(dateLunch)) {
System.out.println(dateLunch + ":" + "Lunch");
afterlunchdate = new Date(0);
dateFormat3 = new SimpleDateFormat("hh:mma");
afterlunchdate.setHours(13);
afterlunchdate.setMinutes(0);
afterlunchdate.setSeconds(0);
String afterdateLunch = dateFormat3.format(afterlunchdate);
timString = afterdateLunch;
System.out.println(timString);
} else {
if (totalTime > 180 && totalTime < 240) {
afterlunchdate = new Date(0);
dateFormat3 = new SimpleDateFormat("hh:mma");
afterlunchdate.setHours(13);
afterlunchdate.setMinutes(0);
afterlunchdate.setSeconds(0);
String afterdateLunch = dateFormat3.format(afterlunchdate);
timString = afterdateLunch;
// System.out.println(timString+": "+talk);
}
System.out.println(timString + ": " + talk);
sortedtalkList.remove(talk);
}
if (talk.endsWith("60min")) {
totalTime = totalTime + 60;
date.setHours(date.getHours() + 1);
} else if (talk.endsWith("45min")) {
totalTime = totalTime + 45;
date.setMinutes(date.getMinutes() + 45);
} else if (talk.endsWith("30min")) {
totalTime = totalTime + 30;
date.setMinutes(date.getMinutes() + 30);
}
}
// System.out.println(timString);
}
private static void prepareSecondDayAfternoonSessionWith215Min(
CopyOnWriteArrayList<String> talksWith30MinDuration) {
int totalTimeForThisSession = 215;
int timeOccupied = 0;
Iterator<String> iterator = talksWith30MinDuration.iterator();
while (iterator.hasNext()) {
String talk = iterator.next();
int timeToRemove = 0;
if (timeOccupied < 215) {
if (talk.endsWith("30min")) {
timeToRemove = 30;
} else {
timeToRemove = 5;
}
System.out.println("talk 4 : " + talk);
talksWith30MinDuration.remove(talk);
timeOccupied = timeOccupied + timeToRemove;
}
}
}
private static List<String> prepareFirstDayAfternoonSessionWith210Min(
CopyOnWriteArrayList<String> unScheduledTalks) {
int totalTimeForThisSession = 200;
int timeOccupied = 0;
Iterator<String> iterator = unScheduledTalks.iterator();
while (iterator.hasNext()) {
String talk = iterator.next();
int timeToRemove = 0;
if (timeOccupied < 200) {
if (talk.endsWith("60min")) {
timeToRemove = 60;
} else if (talk.endsWith("45min")) {
timeToRemove = 45;
} else if (talk.endsWith("30min")) {
timeToRemove = 30;
}
System.out.println("talk 2 : " + talk);
unScheduledTalks.remove(talk);
timeOccupied = timeOccupied + timeToRemove;
}
}
return unScheduledTalks;
}
private static List<String> prepareSecondDayMorningSessionWith180Min(
CopyOnWriteArrayList<String> talksWith45MinDuration) {
int totalTimeForThisSession = 180;
int timeOccupied = 0;
Iterator<String> iterator = talksWith45MinDuration.iterator();
while (iterator.hasNext()) {
String talk = iterator.next();
if (timeOccupied < 180 && talk.endsWith("45min")) {
System.out.println("talk 3 : " + talk);
talksWith45MinDuration.remove(talk);
timeOccupied = timeOccupied + 45;
}
}
return talksWith45MinDuration;
}
@SuppressWarnings("deprecation")
private static List<String> prepareFirstDayMorningSessionWith180Min(
CopyOnWriteArrayList<String> talksWith60MinDuration) {
int totalTimeForThisSession = 180;
int timeOccupied = 0;
Iterator<String> iterator = talksWith60MinDuration.iterator();
while (iterator.hasNext()) {
String talk = iterator.next();
if (timeOccupied < 180 && talk.endsWith("60min")) {
/*
* Date date = new Date(); SimpleDateFormat dateFormat = new
* SimpleDateFormat ("hh:mma"); date.setHours(9);
* date.setMinutes(0); date.setSeconds(0);
*
* String scheduledTime = dateFormat.format(date);
*/
System.out.println(/*
* scheduledTime.getHours()+scheduledTime.
* getSeconds()+
*/"talk 1 : " + talk);
talksWith60MinDuration.remove(talk);
timeOccupied = timeOccupied + 60;
}
}
return talksWith60MinDuration;
}
public List<String> getTalkListFromFile(String fileName)
throws InvalidTalkException {
List<String> talkList = new ArrayList<String>();
try {
FileInputStream fstream = new FileInputStream(fileName);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine = br.readLine();
while (strLine != null) {
talkList.add(strLine);
strLine = br.readLine();
}
in.close();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
return talkList;
}
}
回答by TOSHASHU123
Here is the solution for your problem, hope this will help you
以上就是你遇到的问题的解决方法,希望对你有帮助
public List<TrackInfo> readFile(BufferedReader reader) throws IOException {
TrackInfo trackInfo=null;
List<TrackInfo> trackList = new ArrayList<TrackInfo>();
String line;
while((line = reader.readLine())!= null){
trackInfo = new TrackInfo();
if("lightning".equalsIgnoreCase(line.substring(line.lastIndexOf(" ")+1))){
trackInfo.setEventTime("5min");
}else{
trackInfo.setEventTime(line.substring(line.lastIndexOf(" ")+1));
}
trackInfo.setEventDesc(line.substring(0, line.lastIndexOf(" ")));
trackList.add(trackInfo);
}
return trackList;
}
@SuppressWarnings("deprecation")
@Override
public Map<String, List<String>> processEventTime(List<TrackInfo> trackInfo) {
Calendar cal = new GregorianCalendar();
SimpleDateFormat sdf = new SimpleDateFormat(SIMPLE_DATE_FORMAT);
cal.set(Calendar.HOUR_OF_DAY, HOUR_OF_DAY);
cal.set(Calendar.MINUTE, MIN);
String startTime;
String finishTime;
int track =1;
List<String> eventTime = new ArrayList<String>();
Map<String, List<String>> confRoomData = new HashMap<String, List<String>>();
for(TrackInfo trackData: trackInfo){
startTime = sdf.format(cal.getTime());
finishTime = getFormattedTime(trackData.getEventTime(), cal, sdf);
String flag = getTimeDiff(startTime, finishTime);
if(LUNCH_TIME.equals(flag)){
eventTime.add(flag+": LUNCH");
int minute = Integer.valueOf(trackData.getEventTime().replaceAll("min", ""));
cal.add(Calendar.MINUTE, -cal.getTime().getMinutes());
cal.add(Calendar.MINUTE, 60);
eventTime.add(sdf.format(cal.getTime())+": "+trackData.getEventDesc());
cal.add(Calendar.MINUTE, minute);
}else if(END_OF_DAY.equals(flag)){
eventTime.add(flag+": Networking Event");
cal.set(Calendar.HOUR_OF_DAY, HOUR_OF_DAY);
cal.set(Calendar.MINUTE, MIN);
confRoomData.put(("track_"+track), eventTime);
eventTime = new ArrayList<String>();
eventTime.add(sdf.format(cal.getTime())+": "+trackData.getEventDesc());
finishTime = getFormattedTime(trackData.getEventTime(), cal, sdf);
++track;
}else{
eventTime.add(startTime+": "+trackData.getEventDesc());
}
}
confRoomData.put(("track_"+track), eventTime);
return confRoomData;
}
/*
* This method calculating time difference for Lunch time (12:00 pm) & end of day i.e. 05:00pm
* @input 'startEventTime' and 'finishEventTime'
* @return time difference as String
*/
private String getTimeDiff(String startEventTime, String finishEventTime) {
DateFormat df = new SimpleDateFormat("h:mma");
try {
Date startTime = (Date) df.parse(startEventTime);
Date finishTime = (Date) df.parse(finishEventTime);
Date lunchTime = (Date) df.parse(LUNCH_TIME);
Date endOfDay = (Date) df.parse(END_OF_DAY);
if(finishTime.compareTo(lunchTime) == 0 && startTime.compareTo(lunchTime) > 0){
return LUNCH_TIME;
} else if(startTime.compareTo(lunchTime) == 0 && finishTime.compareTo(lunchTime) > 0){
return LUNCH_TIME;
} else if(startTime.compareTo(lunchTime) < 0 && finishTime.compareTo(lunchTime) > 0){
return LUNCH_TIME;
}
if(endOfDay.compareTo(finishTime)<0){
return END_OF_DAY;
}
} catch (ParseException e) {
e.printStackTrace();
}
return "";
}
private String getFormattedTime(String eventTime, Calendar cal, SimpleDateFormat sdf) {
if(null != eventTime && !"".equals(eventTime)){
eventTime = eventTime.replaceAll("min", "");
}
cal.add(Calendar.MINUTE, Integer.valueOf(eventTime));
return sdf.format(cal.getTime());
}