Objective
Many times it takes two variables for the data to be model/javabean, but it is troublesome to write a model/javabean for two variables, and the type fixed reusability is low. Like what:
1. Avatar for grid display-name requires a gridbean of string-string type
2. The date selector item requires a gridpickeritembean of type boolean-string
3.Http Request class parameter requires a parameter of type String-object
。。。
Is there any way you can do without writing a bunch of custom model/javabean?
With Map<k, v> or set?
Many places (such as data listings in adapter) require serialization, and map (including Linkedhashmap) and set (including Linkedhashset) do not have a get (int index) method, which does not meet the requirements.
As you know, the list supports serialization, there is a get (int index) method, plus entry<k, v> inside the K, V are all custom types, so with list<entry<k, v>> both support serialization, You can also store two variables of any type.
Using the entry in the SDK?
3 types of entry are available in the SDK
Dropboxmanager.entry only these kinds of constructor, obviously can not meet the demand
Keystrore.entry can not access data, obviously can not meet the demand
Map.entry has only one constructor and must be constructed with several abstract methods in it, too cumbersome to use, and not Setkey
So I wrote a entry<k, v> to solve the above problems.
Zblibrary Universal Entry<k, v> method of Use
Just modify the entry<k, the K and V in v> are any type you need, and the other is the same as the normal Model/javabean.
Take the above 3 Model/javabean usage scenarios as an example:
First put entry<k, v> into the project, and then
Delete Gridbean, Gridbean in other classes are all changed to Entry<string, string>
Delete Gridpickeritembean, Gridbean in other classes are all changed to Entry<boolean, string>
Delete parameter, parameter in other classes are all changed to Entry<string, object>
If you do not want to delete the original Model/javabean, you can also simplify the original Model/javabean by inheriting entry<k, v>:
Gridbean extends Entry<string, string>
Gridpickeritembean extends Entry<boolean, string>
Parameter extends Entry<string, object>
Entry<k, v> (Welcome to star, welcome fork)
Https://github.com/TommyLemon/Android-ZBLibrary/blob/master/ZBLibrary (ADT)/zblibrary/src/zuo/biao/library/bean /entry.java
Omnipotent entry, two variables of the Model/javabean no longer have to write!