java - 如何根据字符串做出决定
如果您有一个类似 volume-7,notcontact-xxxx,not_lightlevel-1280.0,
的字符串,并且该字符串可能会因其他选项而异,例如振动、亮度级别、屏幕亮度等...但是格式会是相同的...(设置值,设置值...)
根据您对这些设置的当前信息做出决定的最佳方法是什么? (即通过根据我拥有的当前上下文信息检查预定义字符串来返回 true 或 false)
因此,假设您拥有当前上下文信息...即当前音量级别、振动器设置、灯光级别、屏幕亮度等,并且您想将它与预定义的字符串(例如我上面写的)进行比较,
您会怎么做?
您会解析该字符串并检查每一种可能性吗?虽然可行,但听起来不太吸引人。
我可以使用决策树吗?如果是,有人可以告诉我该怎么做吗?
谢谢
If you have a string like this volume-7,notcontact-xxxx,not_lightlevel-1280.0,
and this string could vary with other options, like vibrate, light level, screen brightness etc...but the formatting would be the same...(setting-value,setting-value...)
What would be the best way to make a decision based on the current information you have on these settings? (i.e return true or false by checking the predefined string against the current contextual information I have)
So let's say you have the current contextual information...i.e the current volume level, vibrator setting, the light level, screen brightness, etc etc and you want to compare it against a pre-defined string such as the I wrote above,
how would you do it?
Would you parse the string and check for every single possibility? while doable, it doesn't sound very appealing..
Could I use decision trees? If yes, could someone tell me how I would go about it?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其解析为
HashMap
将是我的第一个想法。如果您事先知道所有键,您也可以使用 POJO。 (您仍然需要使用反射填充字段,但可以保证所有其他操作的编译时类型安全。)
(我可能完全误解了您的问题,但我找不到您描述的问题和决策树。)
Parsing it into a
HashMap
would be my first thought.You can also use a POJO if you know all the keys in advance. (You'll still have to populate the fields using reflection but you are guaranteed compile time type safety for all the other operations.)
(I might be completely misunderstanding your question, but I can't find any connection between the problem you described and decision trees.)