简体   繁体   中英

Define data type depending on the argument passed in Java

So I'm trying to create my own data type for a project called ULS. ULS basically is a 100 < size < 500,000 list that holds 8 digit (integer) keys to different house listings.

Depending on the size of the list, since every list of houses can differ from city to city, I'm trying to implement different abstract data types depending on the size of the given list. See below:

    Algorithm setSmartThresholdULS(Size):
Input: Integer Size that defines the list size.
Ouput: Data structure implemented with the given size

Int Threshold <- 1000 

If Size is smaller than Threshold then
    setSmartThresholdULS(Size) extends AbstractHashMap<K,V>

Else if Size is greater than Threshold then
    setSmartThresholdULS(Size) extends AVLTreeMap<K,V>

This is only pseudocode, but how could I implement this syntactically correct? And is the code above even legal/valid?

Yes, one can create a different data structure depending on the situation. This is typically done with the factory pattern. No, it does not make any sense to use the data structure with worse scalability for the larger datasets.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM