Omnipotent entry, two variables of the Model/javabean no longer have to write!

Source: Internet
Author: User

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

    1. Delete Gridbean, Gridbean in other classes are all changed to Entry<string, string>

    2. Delete Gridpickeritembean, Gridbean in other classes are all changed to Entry<boolean, string>

    3. 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>:

    1. Gridbean extends Entry<string, string>

    2. Gridpickeritembean extends Entry<boolean, string>

    3. 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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.