Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure are shown in the drawings, it is to be understood that the present disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but rather are provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the disclosure are for illustration purposes only and are not intended to limit the scope of the disclosure.
It should be understood that the various steps recited in the method embodiments of the present disclosure may be performed in a different order, and/or performed in parallel. Moreover, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the present disclosure is not limited in this respect.
The term "include" and variations thereof as used herein are open-ended, i.e., "including but not limited to". The term "based on" is "based, at least in part, on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions for other terms will be given in the following description.
It should be noted that the terms "first", "second", and the like in the present disclosure are only used for distinguishing different devices, modules or units, and are not used for limiting the devices, modules or units to be determined as different devices, modules or units, and are not used for limiting the sequence or interdependence relationship of the functions executed by the devices, modules or units.
It is noted that references to "a", "an", and "the" modifications in this disclosure are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that "one or more" may be used unless the context clearly dictates otherwise.
The names of messages or information exchanged between devices in the embodiments of the present disclosure are for illustrative purposes only, and are not intended to limit the scope of the messages or information.
An embodiment of the present disclosure provides a collection management method for implementation classes, as shown in fig. 1, the method may include:
step S110, marking the implementation class of the interface through the first annotation.
Step S120, the container class of the interface is marked by the second annotation.
An Interface, namely Interface, is one of important concepts in Java and is a collection of abstract methods, the Interface is usually declared by Interface, the Interface cannot be directly instantiated, but the Interface can point to its implementation class object. The interface defines a specification, and the implementation classes determine how the specification operates, that is, the specific implementation method of the interface. For example, an interface a defines an "eat" method, the implementation class is a specific implementation given to "eat", for example, a1 and a2 implement the a interface, a1 is "eat", a2 is "eat", a1 and a2 are implementation classes of the interface a, when the "eat" method needs to be called, the implementation class of the interface a is called, that is, an a1 is instantiated (new), and if all "eat" methods need to be called, the interface a is called, and the calling of all the implementation classes of the interface a is realized through the interface a.
The container class is a management class, and is used for managing all implementation classes of the interface, one container class corresponds to one interface, and in order to collect (i.e., manage) all implementation classes of the interface, for each implementation class that needs to be called, a first annotation mark may be used, and at this time, based on the annotation, it may be known which interface implementation class each implementation class is; similarly, for each container class, it is possible to know which interface implementation class needs to be called based on the annotation through the second annotation tag.
The embodiment of the present disclosure is not limited to the implementation manner in which the implementation class of the interface is marked by the first annotation and the container class of the interface is marked by the second annotation. For example, when the implementation class of the interface is marked by the first annotation, the implementation class of the interface can be marked by adopting an @ Register annotation, an @ IntKeyRegister or an @ StringKeyRegister annotation; when the container class of the interface is marked by the second annotation, the container class of the interface can be marked by means of the @ Plunder annotation.
And step S120, filling the implementation class of the interface into the container class of the interface based on the first annotation and the second annotation during compiling.
In practical application, because the implementation class labels the corresponding interface through the first annotation, and the container class labels the corresponding interface through the second annotation, it can be known through the first annotation and the second annotation which implementation class should be collected by which container class, and if the interfaces marked by the implementation class and the container class are the same interface, the container class can collect all the implementation classes of the corresponding interface based on the first annotation and the second annotation during compiling.
In an example, for an implementation class testimpal of a List storage type, which is an implementation class of an ITest interface, the implementation class may be marked by an @ Register annotation, where the specific marking mode may be:
@Register(target=ITest.class)
public class TestImpl implements ITest{
}
further, since the container class Testmanager needs to collect all implementation classes of the Test interface, the container class Testmanager corresponding to the ITest interface may be marked by the @ plonder annotation, and the specific marking method may be:
@Plunder(target=ITest.class)
public class TestManager{
}
correspondingly, after the implementation class marking of the container class corresponding to ITest, the implementation class marked as ITest can be filled into the container class marked as ITest during compiling.
In the embodiment of the disclosure, the implementation class and the container class of the interface may be respectively marked by the first annotation and the second annotation, and then during compilation, since the first annotation marks the interface to which the implementation class belongs and the second annotation marks the implementation class of which interface the container class is used for collecting, decoupling between the implementation class and the container class is realized, and further during compilation, based on the first annotation and the second annotation, the implementation class is filled into the container class, and it is not necessary to manually add the corresponding implementation class or add the corresponding implementation class in the constructor of the container class, thereby reducing maintenance cost.
In the embodiment of the present disclosure, for any implementation class, the implementation class is a List (List) storage type implementation class or a KV storage type implementation class stored in a mapping table in a key-value (K-V) storage manner, where K is an identifier of the implementation class and V is an instance of the implementation class;
marking the implementation class of the interface by the first annotation comprises:
the implementation class of the interface is tagged with a first annotation corresponding to the storage type of the implementation class.
In practical application, there are two storage modes for the implementation classes, and for any implementation class, the storage type of the implementation class may be stored in a List mode or a K-V storage mode. Further, when the implementation class is stored in different storage types, when the implementation class of the interface is marked by the first annotation, the implementation class of the interface may be marked by the first annotation corresponding to the storage type of the implementation class.
For example, when the storage type of the implementation class is a List storage manner, the implementation class of the interface may be marked with a first annotation corresponding to the List storage manner, for example, the implementation class of the interface may be marked with an @ Register annotation; when the storage type of the implementation class is the KV storage type, the implementation class of the interface may be marked with a first annotation corresponding to the KV storage type, for example, the implementation class of the interface is marked with an @ StringKeyRegister (String type key) annotation or an @ IntKeyRegister (Int type key) annotation.
In an embodiment of the present disclosure, the method further includes:
declaring a storage space and an initialization function of the container class;
at compile time, based on the first annotation and the second annotation, populating an implementation class of the interface into a container class of the interface, including:
determining a corresponding relation between the implementation class and the container class based on the first annotation and the second annotation;
and at the time of compiling, filling the implementation class into the storage space of the container class by calling the initialization function based on the corresponding relation.
In practical application, the data storage type of the storage space corresponds to the storage type of the implementation class stored in the space, when the storage type of the implementation class stored in the storage space is a List storage type, the data storage type of the storage space should also be a List storage type, and when the storage type of the implementation class stored in the storage space is a KV storage type, the data storage type of the storage space should also be a KV storage type.
Further, the storage space and the initialization function of the container class may be declared, wherein, when the storage space of the container class is declared, the declared manner needs to correspond to the storage type of the storage space. For example, when the storage type of the storage space is a List storage type, the manner of declaring the storage space of the container class may be to tag the container class with an @ List container annotation (corresponding to the List storage type) and tag the initialization function of the container with an @ List storage annotation (corresponding to the List storage type), which may specifically be:
@ListContainer
private List<ITest>list=new ArrayList<>();
@ListStorage
private void initList(){
//support this way
//list=new ArrayList<>();
when the storage type of the storage space is the KV storage type, the method of declaring the storage space of the container type may be: private Map < String, ITestMap > Map ═ new HashMap < > (>) which corresponds to KV store type; when an initialization function of a container class is declared, a private void initList () can be adopted; public ITestMap getTestMap (String value).
Further, when the implementation classes of the interface are filled into the container classes during compiling, the corresponding relationship between the implementation classes and the container classes may be determined based on the first annotation and the second annotation, that is, which implementation class is collected by which container class is determined, that is, which implementation class is filled into which container class is determined; further, in practical applications, the storage space of the container class may be visually understood as a bottle, and the initialization function of the container class may be understood as an inlet of the bottle, where the implementation class is collected into the bottle through the inlet of the bottle, that is, the implementation class is collected into the storage space of the container class through the initialization function.
In an embodiment of the present disclosure, the method further includes:
marking the storage space of the container class through the third annotation, and marking the initialization function of the container class through the fourth annotation;
the third annotation marks the data storage type of the storage space, and the fourth annotation marks the initialization function for filling the implementation class of the interface into the storage space.
In practical applications, since the data storage type of the storage space of the container class corresponds to the storage type of the implementation class stored in the space, the storage type of the implementation class includes a List storage type and a KV storage type, at this time, the data storage type of the storage space of the container class also includes a List storage type and a KV storage type, and in order to know the storage type of the storage space of the container class, at this time, the storage space of the container class may be marked in a third annotation manner. For example, when the storage type of the storage space of the container class is a List storage type, the storage space of the container class may be marked with an @ List container annotation, and when the storage type of the storage space of the container class is a KV storage type, the storage space of the container class may be marked with an @ KvContainer annotation.
Furthermore, a fourth annotation may be used to mark the initialization function of the container class, where the fourth annotation indicates that the initialization function is used to fill the implementation class of the interface into the storage space, and when the storage type of the storage space of the container class is different, the marking manner of the fourth annotation also differs, for example, when the storage type is a List storage type, the fourth annotation may use @ List storage, and when the storage type is a KV storage type, the fourth annotation may use @ KvStorage.
In the embodiment of the present disclosure, when compiling, the populating the implementation class of the interface into the container class of the interface includes:
if the implementation class of the interface is the implementation class of the List storage type, filling the instance of the implementation class into the storage space of the container class;
and if the implementation class of the interface is the KV storage type implementation class, filling K of the implementation class in the mapping table into the storage space of the container class.
In practical applications, when the implementation classes of the interface are different storage types, the way of filling the implementation classes into the storage space of the container class by calling the initialization function at the time of compilation is also different. For example, when the implementation class of the interface is an implementation class of a List storage type, an instance of the implementation class (i.e., new one object of the implementation class) may be generated by calling a corresponding initialization function, and then the instance of the implementation class is directly filled into a storage space of a corresponding container class; when the implementation class of the interface is an implementation class of the KV storage type, at this time, K corresponding to the implementation class (that is, an object of the implementation class) in the mapping table may be determined, and then K corresponding to the implementation class is filled in the storage space of the container class by calling a corresponding initialization function.
In the embodiment of the present disclosure, for the implementation class of the List storage type, if the constructor of the implementation class is a private function, when the container class of the interface is marked by the second annotation, the method further includes;
declaring an instance obtaining function of the implementation class, and marking the instance obtaining function through a fifth annotation, wherein the fifth annotation marks the implementation class as a singleton implementation class;
filling the instance of the implementation class into the storage space of the container class by calling an initialization function, comprising:
and filling the storage space of the container class with an instance class acquisition function of the implementation class by calling the initialization function.
In practical application, the construction function of the implementation class can be divided into a private function and a public function, and the implementation class can be divided into a singleton implementation class and a non-singleton implementation class, wherein the singleton implementation class can be instantiated for only one time to generate one instance, while the non-singleton implementation class can be instantiated for multiple times to generate multiple instances.
Further, for the implementation class of the List storage type, if the construction function of the implementation class is a private function, when the container class of the interface is marked by the second annotation, an instance obtaining function (e.g. gettingence ()) of the implementation class needs to be declared, and the implementation class is marked as a singleton implementation class by adopting a fifth annotation manner. Correspondingly, when the implementation class instance is filled into the storage space of the container class by calling the initialization function, the implementation class obtaining function of the implementation class can be filled into the storage space of the container class.
In this embodiment of the present disclosure, for an implementation class of the KV storage type, if the implementation class can be instantiated only once, marking an initialization function of the container class by a fourth annotation includes:
if the implementation class is a singleton implementation class, marking the initialization function of the container class through a fourth annotation, and transmitting a first annotation parameter during marking, wherein the first annotation parameter marks that the implementation class is the singleton implementation class;
if the implementation class is a non-singleton implementation class, the initialization function of the container class is marked through the fourth annotation, and a second annotation parameter is transmitted during marking, wherein the second annotation parameter indicates that the implementation class can only be instantiated once.
In practical application, for a KV type container class, when the @ Plunder annotation is used for marking, a code woven into the KV type container function under the @ Plunder annotation will recreate an instance every time the container function is called, but the instance often does not meet the business requirements of people, and the registered class (namely the implementation class) is single instance in most scenes. And whether the implementation class has two control angles on a single instance or not is the container class for control, and is the registered class for control.
The registered class control means that the registered class itself is an externally provided singleton, so that when the class is implemented by the @ KeyStorage annotation mark, the first annotation parameter isSingleton ═ false can be input: and the registered class is not a single case provided outside and needs to be marked and modified by the user. If @ KvContainer annotation is used to tag the container class, then a second annotation parameter isSingleton value true may be passed in when the initialization function of the container class is tagged with @ KeyStorage, indicating that the implementation class can only be instantiated once.
In this embodiment of the present disclosure, for an implementation class of a KV storage type, if the implementation class can be instantiated only once, during compilation, filling K of the implementation class in a mapping table into a storage space of a container class includes:
during compiling, the initialization function is called to obtain K of the implementation class in the mapping table, V of the implementation class is generated, and the K and the V of the implementation class are filled into a storage space of the container class.
In practical application, for the implementation class of the KV storage type, the implementation class can be instantiated only once, at this time, after obtaining the K of the implementation class in the mapping table based on calling the initialization function, the V of the implementation class can be generated, then the K and V of the implementation class are filled into the storage space of the container class, at this time, the K and V mapping relationship of the implementation class is stored in the storage space, and accordingly, the V of the implementation class can be obtained based on the K of the implementation class.
In an embodiment of the present disclosure, the method further includes:
when a call request aiming at a container class with a storage space of a List storage type is received, calling the instances of the implementation classes in the storage space of the container class based on the call request;
when a call request aiming at a container class with a storage space of a K-V storage type is received, searching a corresponding V in the storage space of the container class based on the K contained in the call request, calling the searched V if the corresponding V is found, and generating and calling an implementation class example corresponding to the K if the corresponding V is not found.
In practical applications, when the implementation class of the container class needs to be called, a call request of the container class may be received, and then the implementation class in the storage space of the container class is called based on the call request of the received container class. When the storage types of the storage spaces are different, the modes of calling the implementation classes in the storage spaces of the container classes are also different.
When a call request for a container class with a List storage type storage space is received, instances of all implementation classes in the storage space of the container class can be called, that is, all the instances of the implementation classes in the storage space of the container class are called; when a call request for a container class with a storage space of the KV storage type is received, at this time, the call request further includes a K of an implementation class to be called, at this time, a corresponding V may be searched in the storage space of the container class based on the K included in the call request, if a V corresponding to the included K is found, the found V is called, and if a V corresponding to the included K is not found, an instance of the implementation class corresponding to the K may be generated and called at this time.
In addition, when the storage type is a KV storage type, if K is a variable, the variable may be marked in an @ Key annotation manner, but it should be noted that different values in the variable must be stored in a list manner.
Based on the same principle as the method shown in fig. 1, an embodiment of the present disclosure also provides a collection management device 30 of an implementation class, as shown in fig. 2, the collection management device 30 of the implementation class may include a marking module 310 and a filling module 320, where:
a marking module 310, configured to mark an implementation class of the interface with a first annotation, and mark a container class of the interface with a second annotation;
and a filling module 320 for filling the implementation class of the interface into the container class of the interface based on the first annotation and the second annotation at compile time.
In an optional embodiment of the present disclosure, for any implementation class, the implementation class is a List storage type implementation class or a KV storage type implementation class stored in a mapping table in a K-V storage manner, where K is an identifier of the implementation class and V is an instance of the implementation class;
when the marking module marks the implementation class of the interface through the first annotation, the marking module is specifically configured to:
the implementation class of the interface is tagged with a first annotation corresponding to the storage type of the implementation class.
In an optional embodiment of the present disclosure, the apparatus further comprises a declaration module configured to:
declaring a storage space and an initialization function of the container class;
when the filling module is compiled, based on the first annotation and the second annotation, when the implementation class of the interface is filled into the container class of the interface, the filling module is specifically configured to:
determining a corresponding relation between the implementation class and the container class based on the first annotation and the second annotation;
and at the time of compiling, filling the implementation class into the storage space of the container class by calling the initialization function based on the corresponding relation.
In an alternative embodiment of the disclosure, the marking module is further configured to:
marking the storage space of the container class through the third annotation, and marking the initialization function of the container class through the fourth annotation;
the third annotation marks the data storage type of the storage space, and the fourth annotation marks the initialization function for filling the implementation class of the interface into the storage space.
In an alternative embodiment of the present disclosure, the filling module, when compiling, is specifically configured to:
if the implementation class of the interface is the implementation class of the List storage type, filling the instance of the implementation class into the storage space of the container class;
and if the implementation class of the interface is the KV storage type implementation class, filling the K of the implementation class in the mapping table into the storage space of the container class.
In an optional embodiment of the present disclosure, for the implementation class of the List storage type, if the constructor of the implementation class is a private function, the tagged module is further configured to tag the container class of the interface with the second annotation;
declaring an instance obtaining function of the implementation class, and marking the instance obtaining function through a fifth annotation, wherein the fifth annotation marks the implementation class as a singleton implementation class;
when the filling module fills the instance of the implementation class into the storage space of the container class by calling the initialization function, the filling module is specifically configured to:
and filling the implementation class acquisition function of the implementation class into the storage space of the container class by calling the initialization function.
In an optional embodiment of the present disclosure, for the implementation class of the KV storage type, if the implementation class can be instantiated only once, when the marking module marks the initialization function of the container class through the fourth annotation, the marking module is specifically configured to:
if the implementation class is a singleton implementation class, marking the initialization function of the container class through a fourth annotation, and transmitting a first annotation parameter during marking, wherein the first annotation parameter marks that the implementation class is the singleton implementation class;
if the implementation class is a non-singleton implementation class, the initialization function of the container class is marked through the fourth annotation, and a second annotation parameter is transmitted during marking, wherein the second annotation parameter indicates that the implementation class can only be instantiated once.
In an optional embodiment of the present disclosure, for an implementation class of the KV storage type, if the implementation class can be instantiated only once, when the filling module fills the K of the implementation class in the mapping table into the storage space of the container class during compiling, the filling module is specifically configured to:
during compiling, the initialization function is called to obtain K of the implementation class in the mapping table, V of the implementation class is generated, and the K and the V of the implementation class are filled into a storage space of the container class.
In an optional embodiment of the present disclosure, the apparatus further includes a calling module, configured to:
when a call request aiming at a container class with a storage space of a List storage type is received, calling the instances of the implementation classes in the storage space of the container class based on the call request;
when a call request aiming at a container class with a storage space of a K-V storage type is received, searching a corresponding V in the storage space of the container class based on the K contained in the call request, calling the searched V if the corresponding V is found, and generating and calling an implementation class example corresponding to the K if the corresponding V is not found.
The implementation class collection management device of the embodiment of the present disclosure may execute a collection management method of an implementation class provided in the embodiment of the present disclosure, and the implementation principles thereof are similar, actions performed by each module in the collection management device of an implementation class in each embodiment of the present disclosure correspond to steps in the collection management method of an implementation class in each embodiment of the present disclosure, and for detailed functional description of each module of the collection management device of an implementation class, reference may be specifically made to the description in the corresponding collection management method of an implementation class shown in the foregoing, and details are not repeated here.
Based on the same principle as the method shown in the embodiments of the present disclosure, embodiments of the present disclosure also provide an electronic device, which may include but is not limited to: a processor and a memory; a memory for storing computer operating instructions; and the processor is used for executing the method shown in the embodiment by calling the computer operation instruction.
Based on the same principle as the method shown in the embodiment of the present disclosure, an embodiment of the present disclosure further provides a computer-readable storage medium, where at least one instruction, at least one program, a code set, or an instruction set is stored in the computer-readable storage medium, and the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by a processor to implement the method shown in the embodiment, which is not described herein again.
Referring now to FIG. 3, a block diagram of an electronic device 600 suitable for use in implementing embodiments of the present disclosure is shown. The terminal device in the embodiments of the present disclosure may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a stationary terminal such as a digital TV, a desktop computer, and the like. The electronic device shown in fig. 3 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
The electronic device includes: a memory and a processor, wherein the processor may be referred to as the processing device 601 hereinafter, and the memory may include at least one of a Read Only Memory (ROM)602, a Random Access Memory (RAM)603 and a storage device 608 hereinafter, which are specifically shown as follows:
as shown in fig. 3, electronic device 600 may include a processing means (e.g., central processing unit, graphics processor, etc.) 601 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage means 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data necessary for the operation of the electronic apparatus 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
Generally, the following devices may be connected to the I/O interface 605: input devices 606 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices 607 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 608 including, for example, tape, hard disk, etc.; and a communication device 609. The communication means 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. While fig. 3 illustrates an electronic device 600 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a non-transitory computer readable medium, the computer program containing program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication means 609, or may be installed from the storage means 608, or may be installed from the ROM 602. The computer program, when executed by the processing device 601, performs the above-described functions defined in the methods of the embodiments of the present disclosure.
It should be noted that the computer readable medium in the present disclosure can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
In some embodiments, the clients, servers may communicate using any currently known or future developed network Protocol, such as HTTP (HyperText Transfer Protocol), and may interconnect with any form or medium of digital data communication (e.g., a communications network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed network.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
Computer program code for carrying out operations for the present disclosure may be written in any combination of one or more programming languages, including but not limited to an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules or units described in the embodiments of the present disclosure may be implemented by software or hardware. Wherein the designation of a module or unit does not in some cases constitute a limitation of the unit itself.
The functions described herein above may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), systems on a chip (SOCs), Complex Programmable Logic Devices (CPLDs), and the like.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
According to one or more embodiments of the present disclosure, [ example a1 ] there is provided a collection management method of an implementation class, comprising:
marking the implementation class of the interface through the first annotation;
marking the container class of the interface with a second annotation;
at compile time, the implementation class of the interface is populated into a container class of the interface based on the first annotation and the second annotation.
A2, the method according to claim a1, wherein for any implementation class, the implementation class is a List storage type implementation class or a KV storage type implementation class stored in a mapping table in a key value K-V storage manner, where K is an identifier of the implementation class and V is an instance of the implementation class;
marking the implementation class of the interface by the first annotation comprises:
the implementation class of the interface is tagged with a first annotation corresponding to the storage type of the implementation class.
A3, the method according to A2, the method further comprising:
declaring a storage space and an initialization function of the container class;
at compile time, based on the first annotation and the second annotation, populating an implementation class of the interface into a container class of the interface, including:
determining a corresponding relation between the implementation class and the container class based on the first annotation and the second annotation;
and at the time of compiling, filling the implementation class into the storage space of the container class by calling the initialization function based on the corresponding relation.
A4, the method according to A3, the method further comprising:
marking the storage space of the container class through the third annotation, and marking the initialization function of the container class through the fourth annotation;
the third annotation marks the data storage type of the storage space, and the fourth annotation marks the initialization function for filling the implementation class of the interface into the storage space.
A5, according to the method of A3, when compiling, filling the implementation class of the interface into the container class of the interface, including:
if the implementation class of the interface is the implementation class of the List storage type, filling the instance of the implementation class into the storage space of the container class;
and if the implementation class of the interface is the KV storage type implementation class, filling K of the implementation class in the mapping table into the storage space of the container class.
A6, for the implementation class of the List storage type according to the method of A5, if the constructor of the implementation class is a private function, when the container class of the interface is marked by a second annotation, the method further comprises;
declaring an instance obtaining function of the implementation class, and marking the instance obtaining function through a fifth annotation, wherein the fifth annotation marks the implementation class as a singleton implementation class;
filling the instance of the implementation class into the storage space of the container class by calling an initialization function, comprising:
and filling the instance obtaining function of the implementation class into the storage space of the container class by calling the initialization function.
A7, according to the method of a5, for the implementation class of the KV storage type, if the implementation class can be instantiated only once, marking the initialization function of the container class by a fourth annotation, including:
if the implementation class is a singleton implementation class, marking the initialization function of the container class through a fourth annotation, and transmitting a first annotation parameter during marking, wherein the first annotation parameter marks that the implementation class is the singleton implementation class;
if the implementation class is a non-singleton implementation class, the initialization function of the container class is marked through the fourth annotation, and a second annotation parameter is transmitted during marking, wherein the second annotation parameter indicates that the implementation class can only be instantiated once.
A8, according to the method of a7, for the implementation class of the KV storage type, if the implementation class can be instantiated only once, during compilation, filling K of the implementation class in the mapping table into the storage space of the container class, including:
during compiling, the initialization function is called to obtain K of the implementation class in the mapping table, V of the implementation class is generated, and the K and the V of the implementation class are filled into a storage space of the container class.
A9, the method according to A8, the method further comprising:
when a call request aiming at a container class with a storage space of a List storage type is received, calling the instances of the implementation classes in the storage space of the container class based on the call request;
when a call request aiming at a container class with a storage space of a K-V storage type is received, searching a corresponding V in the storage space of the container class based on the K contained in the call request, calling the searched V if the corresponding V is found, and generating and calling an implementation class example corresponding to the K if the corresponding V is not found.
According to one or more embodiments of the present disclosure, [ example B1 ] there is provided a collection management apparatus of an implementation class, including:
the marking module is used for marking the implementation class of the interface through the first annotation and marking the container class of the interface through the second annotation;
and the filling module is used for filling the implementation class of the interface into the container class of the interface based on the first annotation and the second annotation during compiling.
B2, the apparatus according to claim B1, wherein for any implementation class, the implementation class is a List storage type implementation class or a KV storage type implementation class stored in a mapping table in a K-V storage manner using key values, where K is an identifier of the implementation class and V is an instance of the implementation class;
when the marking module marks the implementation class of the interface through the first annotation, the marking module is specifically configured to:
the implementation class of the interface is tagged with a first annotation corresponding to the storage type of the implementation class.
B3, the apparatus according to B2, the apparatus further comprising a declaration module for:
declaring a storage space and an initialization function of the container class;
when the filling module is compiled, based on the first annotation and the second annotation, when the implementation class of the interface is filled into the container class of the interface, the filling module is specifically configured to:
determining a corresponding relation between the implementation class and the container class based on the first annotation and the second annotation;
and at the time of compiling, filling the implementation class into the storage space of the container class by calling the initialization function based on the corresponding relation.
B4, the apparatus according to B3, the marking module further for:
marking the storage space of the container class through the third annotation, and marking the initialization function of the container class through the fourth annotation;
the third annotation marks the data storage type of the storage space, and the fourth annotation marks the initialization function for filling the implementation class of the interface into the storage space.
B5, according to the apparatus of B3, when the filling module fills the implementation class of the interface into the container class of the interface during compiling, the filling module is specifically configured to:
if the implementation class of the interface is the implementation class of the List storage type, filling the instance of the implementation class into the storage space of the container class;
and if the implementation class of the interface is the KV storage type implementation class, filling K of the implementation class in the mapping table into the storage space of the container class.
B6, according to the apparatus of B5, for the implementation class of the List storage type, if the constructor of the implementation class is a private function, the tagged module is further configured to tag the container class of the interface with the second annotation;
declaring an instance obtaining function of the implementation class, and marking the instance obtaining function through a fifth annotation, wherein the fifth annotation marks the implementation class as a singleton implementation class;
when the filling module fills the instance of the implementation class into the storage space of the container class by calling the initialization function, the filling module is specifically configured to:
and filling the instance obtaining function of the implementation class into the storage space of the container class by calling the initialization function.
B7, according to the apparatus of B5, for the implementation class of the KV storage type, if the implementation class can be instantiated only once, the marking module is specifically configured to, when marking the initialization function of the container class by the fourth annotation:
if the implementation class is a singleton implementation class, marking the initialization function of the container class through a fourth annotation, and transmitting a first annotation parameter during marking, wherein the first annotation parameter marks that the implementation class is the singleton implementation class;
if the implementation class is a non-singleton implementation class, the initialization function of the container class is marked through the fourth annotation, and a second annotation parameter is transmitted during marking, wherein the second annotation parameter indicates that the implementation class can only be instantiated once.
B8, according to the apparatus of B7, for the implementation class of the KV storage type, if the implementation class can be instantiated only once, when the filling module fills the K of the implementation class in the mapping table into the storage space of the container class during compilation, it is specifically configured to:
during compiling, the initialization function is called to obtain K of the implementation class in the mapping table, V of the implementation class is generated, and the K and the V of the implementation class are filled into a storage space of the container class.
B9, the apparatus according to B8, the apparatus further comprising a calling module for:
when a call request aiming at a container class with a storage space of a List storage type is received, calling the instances of the implementation classes in the storage space of the container class based on the call request;
when a call request aiming at a container class with a storage space of a K-V storage type is received, searching a corresponding V in the storage space of the container class based on the K contained in the call request, calling the searched V if the corresponding V is found, and generating and calling an implementation class example corresponding to the K if the corresponding V is not found.
According to one or more embodiments of the present disclosure, [ example C1 ] there is provided an electronic device comprising:
a processor and a memory;
a memory for storing computer operating instructions;
a processor for executing the method of any one of A1-A9 by calling computer operation instructions.
According to one or more embodiments of the present disclosure, [ example D1 ] there is provided a computer readable medium having stored thereon at least one instruction, at least one program, set of codes, or set of instructions, which is loaded and executed by a processor to implement the method of any one of a1 to a 9.
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the disclosure herein is not limited to the particular combination of features described above, but also encompasses other embodiments in which any combination of the features described above or their equivalents does not depart from the spirit of the disclosure. For example, the above features and (but not limited to) the features disclosed in this disclosure having similar functions are replaced with each other to form the technical solution.
Further, while operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limitations on the scope of the disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.