【发布时间】:2018-07-10 07:43:53
【问题描述】:
在我正在制作的程序中,我试图获取给定季节的格式化季节名称(格式化为它。我将格式化名称保留在界面中,因为如果我要使用地图,那将是不必要的重新生成,因为我没有创建 TeamBuilder 的实例
四季界面:
public interface Seasons {
/*
* Contains a formatted list of seasons.
*
* An interface is being used as an alternative to using a Map in the
* TeamBuilder class, since calling parseTeam would have to build
* mappings for the seasons each time it
* was called. This way, the formatted name can simply be grabbed
*/
final String Skyrise = "Skyrise";
final String Toss_Up = "Toss%20Up";
final String Sack_Attack = "Sack%20Attack";
final String GateWay = "Gateway";
final String Round_Up = "Round%20Up";
final String Clean_Sweep = "Clean%20Sweep";
final String Elevation = "Elevation";
final String Bridge_Battle = "Bridge%20Battle";
final String Nothing_But_Net = "Nothing%20But%20Net";
final String Starstruck = "Starstruck";
final String In_The_Zone = "In%20The%20Zone";
final String Turning_Point = "Turning%20Point";
}
当我试图抓住这些季节时,问题就来了。我的 TeamBuilder 类接受一个未格式化的参数(字符串季节)。 我的问题是,有什么方法可以使用 String 参数作为方法从接口获取特定项目?这比使用 HashMap 更可取,因为它会不必要地重新生成相同的信息
所有这些课程都可以在该项目的Github 页面上找到。
【问题讨论】:
-
为什么 HashMap 会重新生成任何东西?
-
如果“格式化”是指“url-escaped”,则应该使用库来执行此操作,而不是保留单独的常量列表。
-
你为什么不直接使用枚举?
-
@StriplingWarrior 我可以使用哪个库?
-
怎么样:
String encodedUrl = URLEncoder.encode(string, "UTF-8");stackoverflow.com/questions/24229660/… 或 stackoverflow.com/questions/724043/…
标签: java