大转换切换到哈希值(或其他建议) [英] Convert Large Switch to Hash (Or Other Recommendation)

查看:228
本文介绍了大转换切换到哈希值(或其他建议)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一个显示时间表渡船Android应用程序。该应用程序可以显示完整的时间表(只是一个巨大的列表),但在应用程序的卖点是它会显示在接下来的两个渡轮出发,如何从当前时间发车很长。

I currently have an Android application that displays a schedule for a ferry boat. The application can display the full schedule (just a giant list), but the selling point in the application is it will display when the next two ferries are departing and how long from the current time that departure is.

我是比较新的Java和目前使用的大开关()语句在我的code。基本上它得到当前电话时间,并将其与所有在日程表的时间,此时它显示接下来的两个出发时间,然后计算当前时间与启程时间之间的差。

I am relatively new to Java and currently use large Switch() statements in my code. Basically it gets the current phone time and compares it to all of the times in the schedule at which point it displays the next two departure times and then calculates the difference between current time and the departure times.

我相信,一个switch语句是不求速度的目的最好的办法以及code更改的目的。例如,如果一次改变其一堆code线的去和修复为那一个时间的变化。此外,如果整个日程更改每个人都有更新他们的应用程序的时间更改生效。我理想的情况是在一些地方保存在我的网络服务器,可以下载并插入到一个HashMap中的文件(我认为是正确的术语),如果有一个时间的变化,将加载新的时间表。

I am sure that a switch statement is not the best idea for speed purposes as well as code changing purposes. For example if one time changes its a bunch of lines of code to go in and fix for that one time change. Also if the entire schedule changes everyone has to update their app for the time change to take effect. My ideal situation would be to store a file somewhere on my webserver that could be downloaded and inserted into a hashmap (I think is the correct term) that would load the new schedule if there was a time change.

不知道如何混乱,这是,但它会大大pciated如果有人能解释如何我可能会使用HashMap或别的东西,你可能会建议得到这个任务完成AP $ P $。目前的变量是两个客运码头,以及因为每天的日程安排变化(周​​一,周二,周五,周六,周日),在一周的某一天

Not sure how confusing this is, but it would be greatly appreciated if someone could explain how I might use a hashmap or something else you might recommend to get this task accomplished. Currently the variables are the two ferry terminals as well as the day of the week since the schedule changes per day (monday, tues-friday, saturday, sunday).

下面是应用程序的截图,所以你可以把它理解,如果我的职位是不明确的。谢谢你在前进。

Below is a screenshot of the application so you can understand it if my post wasn't clear. Thank you in advance.

截图:

推荐答案

在排序后的数组存储日程表对象。然后,您可以二进制搜索的第一个值比当前时间越大数组。你可能会使用一些包括位置和星期适用一天父阵列。

Store the schedule objects in a sorted array. You can then binary search the array for the first value greater than the current time. You'll probably use some parent array consisting of the location and applicable day of the week.

您可以轻松编写那种数据结构到正在读&放文件;由应用程序解析,而不是被编译到code更新。

You can easily write that kind of data structure to a file that is read & parsed by the application for updates instead of being compiled into the code.

这个细节?首先,了解资源在Android中。如果没有更新的安排存在,回落到默认的资源。

Details of this? First, understand resources in Android. If no updated schedule exists, fall back to the default resource.

二,使用HTTP头请求,检查是否有更新文件是否存在。如果是这样,解析,下载和放大器;保存状态。 如何保存一个Android应用程序的状态?

Second, use an HTTP head request to check if a newer file exists. If it does, parse, download & save state. How do I save an Android application's state?.

最后,XML是非常方便的数据分布,即使它不是很快。每个人都知道它,它很容易更新或交班。

Finally, XML is handy for data distribution, even if it's not fast. Everybody understands it and it's easy to update or hand off.

<ferry location=0 time=2045>
    <day>1</day>
    <day>2</day>
    <day>3</day>
    <day>4</day>
    <day>5</day>
</ferry>

<ferry location=0 time=0800>
    <day>6</day>
</ferry>

这篇关于大转换切换到哈希值(或其他建议)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆