Method and apparatus for modifying enumeration value, and computer device and readable storage medium
Dynamically modifying enumeration values in basic components through the reflection mechanism solves the problems of high enumeration value modification cost and poor versatility in the existing technology, and realizes flexible expansion and low-cost management of enumeration values.
Patent Information
- Application Number
- PCT/CN2023/125646
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-03-16
- Filing Date
- 2023-10-20
- Publication Date
- 2024-09-19
AI Technical Summary
Modification of enumeration values in the prior art usually requires modification of the source code or decompilation, resulting in high development costs, high maintenance costs, reduced versatility, and the risk of copyright disputes.
Use the reflection mechanism to dynamically modify the enumeration values in the basic components. By obtaining the specified enumeration class and operation, read and modify the original enumeration value, generate the changed enumeration class, and replace the original enumeration class based on the reflection mechanism to achieve Dynamic addition or deletion of enumeration values.
It realizes non-invasive modification of enumeration values, reduces development and maintenance costs, simplifies the management of enumeration values, and significantly improves the learning cost and scalability of enumeration values.
Smart Images

Figure CN2023125646_19092024_PF_FP_ABST
Abstract
Description
Method, device, computer equipment and readable storage medium for modifying enumeration values
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on March 16, 2023, with application number 202310290245.1, and invention name “Method, device, computer device and readable storage medium for modifying enumeration values”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of computer technology, and in particular to a method, apparatus, computer device, and readable storage medium for modifying an enumeration value. Background Art
[0003] Enumeration classes are often used in software project development. The enumeration values under the enumeration class are usually defined in the basic components, that is, "hard-coded". These pre-written enumeration values often do not meet or comply with the project implementation requirements during the project operation.
[0004] In the prior art, there are usually two ways to modify enumeration values. One is to modify the source code and recompile and package it. This requires the source code modification permission and packaging permission of the basic component, which will cause the enumeration values of the basic component to continue to increase and destroy the universality of the original enumeration. The other is to decompile and modify the source code and recompile and package it. This significantly increases development and maintenance costs and increases the complexity of packaging and deployment.
[0005] Application Contents
[0006] To solve the above problems, the embodiments of the present application provide a method, apparatus, computer device and readable storage medium for modifying enumeration values, which dynamically modify the enumeration values of the basic component enumeration type based on the reflection mechanism to achieve the effect of extending the enumeration.
[0007] In a first aspect, an embodiment of the present application provides a method for modifying an enumeration value, including:
[0008] During the operation of the target system, obtain the specified enumeration class and the specified enumeration operation;
[0009] Reading the original enumeration value under the specified enumeration class in the basic component of the target system;
[0010] Performing the specified enumeration operation on the original enumeration value to obtain a changed enumeration class;
[0011] Based on the reflection mechanism, the changed enumeration class is used to replace the specified enumeration class in the basic component.
[0012] In a second aspect, an embodiment of the present application further provides a device for modifying an enumeration value, the device comprising:
[0013] The acquisition unit is used to obtain the specified enumeration class and the specified enumeration operation;
[0014] A reading unit, used for reading the original enumeration value under the specified enumeration class in the basic component of the target system;
[0015] a changing unit, configured to perform the specified enumeration operation on the original enumeration value to obtain a changed enumeration class;
[0016] A replacement unit is used to replace the specified enumeration class in the basic component with the changed enumeration class based on a reflection mechanism.
[0017] In a third aspect, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the target tracking method when executing the computer program.
[0018] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and the computer program implements the above-mentioned target tracking method when instructed by a processor.
[0019] At least one of the above technical solutions adopted in the embodiments of the present application can achieve the following beneficial effects:
[0020] During the startup or operation of the target system, this application obtains the specified enumeration class and the specified enumeration operation, and reads the original enumeration values under the specified enumeration class in the basic component, and then performs the specified enumeration operation on the original enumeration value to obtain the changed enumeration class. Finally, based on the reflection mechanism, the changed enumeration class is used to replace the original specified enumeration class in the basic component. This application is based on the reflection mechanism to dynamically add or delete enumeration values under the enumeration class in the basic component, so that the newly added enumeration values required for the implementation project are dynamically added to the enumeration class of the basic component, and the unwanted enumeration values under the enumeration class of the basic component can also be removed, thereby achieving the effect of extending the enumeration value; this application adopts a non-invasive modification method, which has little damage to the source code of the basic component; it adopts a generic method, which can extend the enumeration values under any enumeration class; and it is simple and easy to use, which significantly reduces the learning cost, development cost, and maintenance cost of enumeration. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0022] FIG1 is a schematic flow chart showing a method for modifying an enumeration value according to an embodiment of the present application;
[0023] FIG2 is a schematic diagram showing a process of modifying an enumeration value according to another embodiment of the present application;
[0024] FIG3 shows a schematic structural diagram of an apparatus for modifying an enumeration value according to an embodiment of the present application;
[0025] FIG4 shows a schematic structural diagram of a computer device according to an embodiment of the present application. DETAILED DESCRIPTION
[0026] To make the purpose, technical solutions, and advantages of this application more clear, the technical solutions of this application will be clearly and completely described below in conjunction with the specific embodiments of this application and the corresponding drawings. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0027] In order to enable ordinary technicians in this field to more clearly understand the technical solutions provided by the embodiments of this application, the technical solution concept of this application is first explained.
[0028] In the prior art, there are generally two ways to modify enumeration values (also known as enumerations). The first is to modify the source code and recompile and repackage. For example, modifying the source code of a third-party library (which requires permission), adding or deleting enumeration values, and recompiling and repackaging. This method requires source code modification and packaging permissions for the underlying component, which will cause the enumeration values of the underlying component to continuously increase and undermine the universality of the original enumeration. The second method is to decompile and modify the source code, recompile and repackage. For example, decompiling the enumeration class file of a third-party library to obtain the Java source code, modifying the source code, recompiling it into a class file, and replacing the class file in the JAR package. This increases development and maintenance costs, increases the complexity of packaging and deployment, and also carries the risk of copyright disputes.
[0029] In response to the shortcomings of the prior art, the present application proposes a method for modifying an enumeration value. FIG1 shows a flow chart of a method for modifying an enumeration value according to an embodiment of the present application. As can be seen from FIG1 , the present application includes at least steps S110 to S140:
[0030] Step S110: During the operation of the target system, a specified enumeration class and a specified enumeration operation are obtained.
[0031] In the prior art, enumeration values are modified manually during the compilation or decompilation of the system or program source code. Unlike the prior art, the present application can dynamically modify enumeration values (also called enumerations) during the operation of the system or program.
[0032] The following is a brief description of the professional terms that appear in this application:
[0033] The above-mentioned "system or program" can be understood as a computer software that is a code written in a certain computer language (such as Java language) and follows certain grammatical rules and can realize certain functions.
[0034] The above-mentioned “operation” is relatively broad, including but not limited to system startup and during operation.
[0035] The "enumeration class" mentioned above is also called an "enumeration type". An enumeration class can contain one or more enumeration values, usually multiple, such as enum typeName{valueName1,valueName2,valueName3,......}num, where typeName is the enumeration class (or enumeration type), and valueName1,valueName2,valueName3,...... are multiple enumeration values under the enumeration class typeName. In actual scenarios, according to the business requirements of some systems or programs, each enumeration value has a serial number, and the serial numbers of different enumeration values are different and unique. The serial numbers of enumeration values can also be discontinuous, such as valueName1, valueName2, and valueName3 have serial numbers of 1, 2, and 3 respectively. Serial numbers are not required and can be set according to business needs.
[0036] In this application, the system or program whose enumeration value is to be modified is recorded as the target system. During the startup or operation of the target system, the staff (usually developers) can specify the modification of the pre-performed enumeration value. The specification is usually implemented in the form of code instructions in the background.
[0037] In some embodiments of the present application, it can be implemented through but not limited to a software maintenance server. A staff member can initiate a modification of an enumeration value on the software maintenance server and specify an enumeration class and an enumeration operation.
[0038] In the following embodiments, taking the specified enumeration class as week and the original enumeration values as Monday, Tuesday, Wednesday, Thursday, and Friday as an example, in the basic component, the form of the original enumeration class can be expressed as: enum week{Monday,Tuesday,Wednesday,Thursday,Friday}num.
[0039] After receiving the specified enumeration class and the specified enumeration operation, the software maintenance server enters the subsequent process.
[0040] Step S120: Read the original enumeration value under the specified enumeration class in the basic component of the target system.
[0041] After receiving the specified enumeration class, the software maintenance server parses it and obtains that the specified enumeration class is week. Then, the software maintenance server reads the enumeration value under the specified enumeration class from the basic component of the target system and records it as the original enumeration value. In this embodiment, the enumeration value read is: Monday, Tuesday, Wednesday, Thursday, Friday.
[0042] Step S130: performing the specified enumeration operation on the original enumeration value to obtain a changed enumeration class.
[0043] The software maintenance server parses the specified enumeration operation and obtains the specific operation of the specified enumeration operation. In this application, the specified enumeration operation includes but is not limited to: deleting the specified enumeration value and / or adding a new enumeration value; that is, in one modification of the enumeration value, the enumeration value can be deleted separately, the new enumeration value can be added separately, or the enumeration value can be deleted and the new enumeration value can be added at the same time.
[0044] If the specified enumeration operation is to delete the specified enumeration value, specifically to delete the enumeration value Monday, after performing the specified enumeration operation on the original enumeration value, the original enumeration value becomes Tuesday, Wednesday, Thursday, Friday, and the original enumeration value is restored to the original enumeration class to obtain the changed enumeration value, which is enum week{Tuesday,Wednesday,Thursday,Friday}num.
[0045] If the specified enumeration operation is to add a new enumeration value, specifically to add a new enumeration value Saturday, the new enumeration value is usually added after all the original enumeration values. In this application, after adding the new enumeration value Saturday, the original enumeration values become Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, and the original enumeration values are restored to the original enumeration class to obtain the changed enumeration value. The changed enumeration value is enum week{Monday,Tuesday,Wednesday,Thursday,Friday,Saturday}num.
[0046] In addition, if the original enumeration value has a serial number, the serial number is assigned to the newly added enumeration value in accordance with the principle that the serial numbers of different enumeration values are different and unique.
[0047] Step S140: Based on the reflection mechanism, the changed enumeration class is used to replace the specified enumeration class in the basic component.
[0048] Finally, based on the reflection mechanism, the changed enumeration class is used to replace the specified enumeration class in the basic component, so that the dynamic change of the enumeration value can be achieved.
[0049] Taking Java as an example, Java's reflection mechanism allows, at runtime, for any entity class, all properties and methods of that class to be known; for any object, any method and property to be called. This ability to dynamically obtain information and call object methods is known as Java's reflection mechanism. Therefore, through reflection, a modified enumeration class can be assigned to a specified enumeration class in a base component, replacing it and thus modifying the enumeration value.
[0050] As can be seen from the method shown in Figure 1, during the startup or operation of the target system, the present application obtains the specified enumeration class and the specified enumeration operation, and in the basic component, reads each original enumeration value under the specified enumeration class, and then performs the specified enumeration operation on the original enumeration value to obtain the changed enumeration class. Finally, based on the reflection mechanism, the changed enumeration class is used to replace the original specified enumeration class in the basic component. Based on the reflection mechanism, the present application dynamically adds or deletes the enumeration values under the enumeration class in the basic component, so that the newly added enumeration values required for the implementation project are dynamically added to the enumeration class of the basic component, and the unwanted enumeration values under the enumeration class of the basic component can also be removed, thereby achieving the effect of extending the enumeration value; the present application adopts a non-invasive modification method, which has little damage to the source code of the basic component; it adopts a generic method, which can extend the enumeration values under any enumeration class; and it is simple and easy to use, which significantly reduces the learning cost, development cost, and maintenance cost of enumeration.
[0051] In some embodiments of the present application, in the above method, during the operation of the target system, a specified enumeration class and a specified enumeration operation are obtained, including: during the operation of the target system, an enumeration value modification instruction is received and parsed to obtain a specified enumeration class and a specified enumeration operation, wherein the specified enumeration operation is to delete a specified enumeration value and / or add a new enumeration value; if the specified enumeration operation includes adding a new enumeration value, then the enumeration information of the new enumeration value is obtained, and the enumeration information includes at least: a name and a custom description.
[0052] In some embodiments, developers can submit enumeration value modification instructions to the software maintenance server through the development terminal. After receiving the enumeration value modification instructions, the software maintenance server parses them and obtains the specific information therein. The enumeration modification instructions include at least a specified enumeration class and a specified enumeration operation, wherein the specified enumeration operation includes but is not limited to deleting a specified enumeration value and / or adding a new enumeration value.
[0053] For a specified enumeration class, you can directly specify the enumeration class, such as the aforementioned week; if the specified enumeration operation is to delete the specified enumeration value, you can directly specify the enumeration value, such as the aforementioned Monday, or you can specify the sequence number of the enumeration value, such as 1; if the specified enumeration operation is to add a new enumeration value, you need to set the information of the new enumeration value. The enumeration information includes at least a name and a custom description, where the name is the aforementioned valueName1, such as Monday; the custom description is a field that can be stored in association with the enumeration value to describe the purpose or nature of the enumeration value.
[0054] In some embodiments of the present application, in the above method, performing the specified enumeration operation on the original enumeration value to obtain the changed enumeration class includes: constructing a list object containing the original enumeration value; performing the specified enumeration operation indicated by the enumeration value modification instruction on the original enumeration value in the list object; updating the list object according to the result of the specified enumeration operation; and converting the updated list object into an enumeration class to obtain the changed enumeration class.
[0055] In order to facilitate the execution of specified enumeration operations on the original enumeration value, after reading the original enumeration value, a List object (list object) containing the original enumeration value will be generated. The List object is a data structure. Usually, the List object is separated by commas and stores various data according to the index. Each position represents an element. Then, in the List object, the original enumeration value is modified, specifically by deletion or addition. As in the aforementioned embodiment, a List object of the enumeration class week can be constructed. The original enumeration value can be stored in the List object according to the index. In this application, the index can be but not limited to the serial number of each original enumeration value, such as the List object: Monday, Tuesday, Wednesday, Thursday, Friday.
[0056] Then, the specified enumeration operation indicated by the enumeration value modification instruction is executed on the List object, and the List object is updated according to the operation result. For example, the specified enumeration operation is to delete the enumeration value with sequence number 1 and add a new enumeration value at the same time.
[0057] Specifically, in some embodiments of the present application, the specified enumeration operation is to delete the specified enumeration value; the execution of the specified enumeration operation indicated by the enumeration value modification instruction on the original enumeration value in the list object includes: reading the target enumeration value specified by the enumeration value modification instruction in the list object; determining the serial number of the target enumeration value; and deleting the target enumeration value and the corresponding serial number.
[0058] That is to say, when the instruction to delete the specified enumeration value specifies the serial number of the enumeration value to be deleted, it is necessary to search in the List object to find the enumeration value corresponding to the serial number, record it as the target enumeration value, and then delete the enumeration value and the corresponding serial number. Taking the deletion of the enumeration value with serial number 1 as an example, the enumeration value with serial number 1 is found in the List object as Monday, and then its serial number and value are deleted at the same time. After deleting Monday, the updated List object is Tuesday, Wednesday, Thursday, and Friday.
[0059] In some embodiments of the present application, in the above method, the specified enumeration operation is to add a new enumeration value; the specified enumeration operation indicated by the enumeration value modification instruction is performed on the original enumeration value in the list object, including: determining the maximum sequence number of the enumeration value under the specified enumeration class; generating a target sequence number for the new enumeration value based on the maximum sequence number; generating the new enumeration value based on the name, custom description, and target sequence number based on the accessor of the constructor of the specified enumeration class; and adding the new enumeration value to the list object.
[0060] After deleting Monday, a new enumeration value is added. Assume that the original enumeration values of Monday, Tuesday, Wednesday, Thursday, and Friday are numbered 1, 2, 3, 4, and 5 respectively; after deleting Monday, the enumeration values contained in the List object are Tuesday, Wednesday, Thursday, and Friday. The sequence numbers of these enumeration values do not change and are still 2, 3, 4, and 5. When adding a new enumeration value, a sequence number is first assigned to the new enumeration value. The principle of assigning sequence numbers is that "sequence numbers of different enumeration values are different and unique". The original sequence numbers are usually continuous and arranged in order from small to large. Therefore, in this embodiment, the original sequence number can be determined. The maximum serial number in the enumeration value, and then assign a serial number to the new enumeration value based on the maximum serial number. If the serial number is assigned by the maximum serial number + 1, the target serial number assigned to the new enumeration value is 6; then the accessor of the enumeration class constructor is called, and the information of the new enumeration value contained in the new enumeration value instruction, including the name (such as Saturday) and the custom description, is passed into the accessor. The enumeration class constructor can generate a new enumeration value based on the name, custom description and target serial number of the new enumeration value, and then add the new enumeration value to the List object. That is, after adding Saturday, the updated List object is Tuesday, Wednesday, Thursday, Friday, and Saturday.
[0061] That is, after deleting the enumeration value numbered 1 and adding a new enumeration value (such as Saturday), the resulting List object is Tuesday, Wednesday, Thursday, Friday, and Saturday. Finally, the updated List object is restored back to the enumeration class form to obtain the modified enumeration class, for example, enum week{Tuesday,Wednesday,Thursday,Friday,Saturday}num.
[0062] In some embodiments of the present application, in the above method, based on the reflection mechanism, the changed enumeration class is used to replace the specified enumeration class in the basic component, including: obtaining the field accessor of the value attribute of the specified enumeration class, and private and final limiting the field accessor; through the field accessor, assigning the changed enumeration class to the value attribute of the specified enumeration class in an overriding form.
[0063] After obtaining the changed enumeration class, it is necessary to assign the changed enumeration class to the specified enumeration class in the basic component in an overwritten form.
[0064] Specifically, get the field accessor of the value attribute ($VALUES attribute) of the specified enumeration class. Usually, some restrictions are set by default in the field accessor. If you want to modify the $VALUES attribute of the specified enumeration class, you need to remove some of its restrictions. Specifically, you can forcibly remove the restrictions of private restrictions and final fields. After removing these two restrictions, the value attribute of the enumeration class can be modified.
[0065] By specifying the field accessor of the value property of the enumeration class, the changed enumeration class is assigned to the value property of the specified enumeration class in an overwritten form, which means that the specified enumeration class is replaced, thereby realizing the modification of the original enumeration value.
[0066] In some embodiments of the present application, the above method also includes: storing the read original enumeration value of the specified enumeration class in the enumeration cache; after the step of replacing the specified enumeration class in the basic component with the changed enumeration class based on the reflection mechanism, clearing the enumeration cache.
[0067] In the process of modifying the enumeration value, in order to achieve fast reading and writing of the enumeration value, a cache area is specially opened for the enumeration value, which is recorded as the enumeration cache. In actual scenarios, it is usually the cache of the enumeration Class, including but not limited to enumConstantDirectory and enumConstants. After reading the original enumeration value of the specified enumeration class, the original enumeration value can be stored in the enumeration cache. When the original enumeration value is needed later, it does not need to be read from the basic component, and can be read directly from the enumeration cache. After the modification of the enumeration value is completed, that is, after the step of replacing the specified enumeration class in the basic component with the changed enumeration class, the enumeration cache is cleared for next use, thereby significantly improving the efficiency of enumeration value modification.
[0068] FIG2 shows a schematic diagram of a process for modifying an enumeration value according to another embodiment of the present application. As can be seen from FIG2 , this embodiment includes:
[0069] During the operation of the target system, the enumeration value modification instruction is obtained and parsed to obtain the specified enumeration class and the specified enumeration operation. The specified enumeration operation includes deleting the specified enumeration value and adding a new enumeration value.
[0070] According to the specified enumeration class, read the original enumeration value under the specified enumeration class in the basic component of the target system, generate a List object containing the original enumeration value, and store it in the enumeration cache.
[0071] Traverse the generated List object and update the List object by deleting the specified enumeration value.
[0072] Determine the maximum serial number of the original enumeration value and generate the serial number of the new enumeration value by adding 1 to the maximum serial number; obtain the accessor of the constructor of the specified enumeration class, pass in the enumeration information (name, serial number, custom description) of the new enumeration value, generate the new enumeration value, and update the List object.
[0073] Convert the updated List object into the changed enumeration class.
[0074] Get the field accessor of the $VALUES property of the specified enumeration class, forcibly cancel the private and final restrictions, and assign the changed enumeration class to the $VALUES property of the specified enumeration class.
[0075] Clear the enumeration cache.
[0076] FIG3 shows a schematic diagram of the structure of an apparatus for modifying an enumeration value according to an embodiment of the present application. The apparatus for modifying an enumeration value may be deployed on a software maintenance server. As can be seen from FIG3 , the apparatus 300 includes:
[0077] An acquiring unit 310 is used to acquire a specified enumeration class and a specified enumeration operation;
[0078] The reading unit 320 is used to read the original enumeration value under the specified enumeration class in the basic component of the target system;
[0079] A changing unit 330 is configured to perform the specified enumeration operation on the original enumeration value to obtain a changed enumeration class;
[0080] The replacement unit 340 is configured to replace the specified enumeration class in the basic component with the changed enumeration class based on a reflection mechanism.
[0081] In some embodiments of the present application, in the above-mentioned device, the acquisition unit 310 is used to receive and parse the enumeration value modification instruction during the operation of the target system, and obtain the specified enumeration class and the specified enumeration operation, wherein the specified enumeration operation is to delete the specified enumeration value and / or add a new enumeration value; if the specified enumeration operation includes adding a new enumeration value, then the enumeration information of the new enumeration value is obtained, and the enumeration information at least includes: a name and a custom description.
[0082] In some embodiments of the present application, in the above-mentioned device, the changing unit 330 is used to construct a list object containing the original enumeration value; perform the specified enumeration operation indicated by the enumeration value modification instruction on the original enumeration value in the list object; update the list object according to the result of the specified enumeration operation; convert the updated list object into an enumeration class to obtain the changed enumeration class.
[0083] In some embodiments of the present application, in the above-mentioned device, the specified enumeration operation is to delete the specified enumeration value; the change unit 330 is used to read the target enumeration value specified by the enumeration value modification instruction in the list object; determine the serial number of the target enumeration value; and delete the target enumeration value and the corresponding serial number.
[0084] In some embodiments of the present application, in the above-mentioned device, the specified enumeration operation is to add a new enumeration value; the changing unit 330 is used to determine the maximum serial number of the enumeration value under the specified enumeration class; generate the target serial number of the new enumeration value based on the maximum serial number; based on the accessor of the constructor of the specified enumeration class, generate the new enumeration value according to the name, custom description, and the target serial number; and add the new enumeration value to the list object.
[0085] In some embodiments of the present application, in the above-mentioned device, the replacement unit 340 is used to obtain the field accessor of the value attribute of the specified enumeration class, and to set private and final limits on the field accessor; through the field accessor, the changed enumeration class is assigned to the value attribute of the specified enumeration class in an overwritten form.
[0086] In some embodiments of the present application, in the above-mentioned device, the acquisition unit 310 is further used to store the read original enumeration value of the specified enumeration class in the enumeration cache; after the step of replacing the specified enumeration class in the basic component with the changed enumeration class based on the reflection mechanism, the enumeration cache is cleared.
[0087] It should be noted that the enumeration value modification device of the present application can implement the aforementioned enumeration value modification method one by one, which will not be repeated here.
[0088] Figure 4 shows a schematic diagram of the structure of a computer device according to an embodiment of the present application. As shown in Figure 4, the computer device includes a processor, a memory, a network interface, and a database connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external client via a network connection. When the computer program is executed by the processor, the functions or steps of the method for modifying the enumeration value are implemented.
[0089] In one embodiment, the computer device provided by the present application includes a memory and a processor, the memory stores a database and a computer program that can be run on the processor, and the processor implements the aforementioned method when executing the computer program.
[0090] The method performed by the enumeration value modification device disclosed in the embodiment shown in FIG3 of the present application can be applied to a processor or implemented by a processor. During implementation, each step of the above method can be completed by hardware integrated logic circuits in the processor or by software instructions. The above processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The steps of the method disclosed in the embodiment of the present application can be directly embodied as being executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium mature in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above enumeration value modification method in combination with its hardware.
[0091] In one embodiment, a computer-readable storage medium is further provided, on which a computer program is stored. When the computer program is executed by a processor, the method for modifying the enumeration value is implemented.
[0092] It should be noted that the above functions or steps that can be implemented by the computer device or computer-readable storage medium can be found in the relevant descriptions in the aforementioned method embodiments. To avoid repetition, they will not be described one by one here.
[0093] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0094] Those skilled in the art will clearly understand that for the sake of convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0095] The above-described embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present application, and should all be included in the scope of protection of the present application.
Claims
1. A method for modifying an enumeration value, wherein: include: During the operation of the target system, obtain the specified enumeration class and the specified enumeration operation; Reading the original enumeration value under the specified enumeration class in the basic component of the target system; Perform the specified enumeration operation on the original enumeration value to obtain a changed enumeration class; Based on the reflection mechanism, the changed enumeration class is used to replace the specified enumeration class in the basic component.
2. The method according to claim 1, wherein: During the operation of the target system, obtain the specified enumeration class and the specified enumeration operation, including: During the operation of the target system, an enumeration value modification instruction is received and parsed to obtain a specified enumeration class and a specified enumeration operation, wherein the specified enumeration operation is to delete a specified enumeration value and / or add a new enumeration value; If the specified enumeration operation includes adding a new enumeration value, then the enumeration information of the new enumeration value is obtained, and the enumeration information at least includes: a name and a custom description.
3. The method according to claim 2, wherein: The performing the specified enumeration operation on the original enumeration value to obtain the changed enumeration class includes: Construct a list object containing the original enumeration value; Performing a specified enumeration operation indicated by the enumeration value modification instruction on the original enumeration value in the list object; According to the result of the specified enumeration operation, the list object is updated; The updated list object is converted into an enumeration class to obtain the changed enumeration class.
4. The method according to claim 3, wherein: The specified enumeration operation is to delete the specified enumeration value; The performing the specified enumeration operation indicated by the enumeration value modification instruction on the original enumeration value in the list object includes: Reading the target enumeration value specified by the enumeration value modification instruction in the list object; Determine the sequence number of the target enumeration value; Delete the target enumeration value and the corresponding sequence number.
5. The method according to claim 3, wherein: The specified enumeration operation is to add a new enumeration value; The performing the specified enumeration operation indicated by the enumeration value modification instruction on the original enumeration value in the list object includes: Determine the maximum serial number of the enumeration value under the specified enumeration class; Generate a target sequence number of the new enumeration value according to the maximum sequence number; Based on the accessor of the constructor of the specified enumeration class, generate the new enumeration value according to the name, the custom description, and the target sequence number; Add the new enumeration value to the list object.
6. The method according to claim 1, wherein: The step of replacing the designated enumeration class in the basic component with the changed enumeration class based on the reflection mechanism includes: Get the field accessor of the value attribute of the specified enumeration class, and make the field accessor private and final; Through the field accessor, the changed enumeration class is assigned to the specified The value property of the enumeration class.
7. The method according to claim 1, wherein: The method further comprises: The read original enumeration value of the specified enumeration class is stored in the enumeration cache; After the step of replacing the designated enumeration class in the basic component with the changed enumeration class based on the reflection mechanism, the enumeration cache is cleared.
8. A device for modifying an enumeration value, wherein: The device comprises: The acquisition unit is used to acquire the specified enumeration class and the specified enumeration operation; A reading unit, used for reading the original enumeration value under the specified enumeration class in the basic component of the target system; A changing unit, configured to perform the specified enumeration operation on the original enumeration value to obtain a changed enumeration class; A replacement unit is used to replace the specified enumeration class in the basic component with the changed enumeration class based on a reflection mechanism.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the following steps are implemented: During the operation of the target system, obtain the specified enumeration class and the specified enumeration operation; Reading the original enumeration value under the specified enumeration class in the basic component of the target system; Perform the specified enumeration operation on the original enumeration value to obtain a changed enumeration class; Based on the reflection mechanism, the changed enumeration class is used to replace the specified enumeration class in the basic component.
10. A computer-readable storage medium having a computer program stored thereon, wherein: When the computer program is executed by a processor, the following steps are implemented: During the operation of the target system, obtain the specified enumeration class and the specified enumeration operation; Reading the original enumeration value under the specified enumeration class in the basic component of the target system; Perform the specified enumeration operation on the original enumeration value to obtain a changed enumeration class; Based on the reflection mechanism, the changed enumeration class is used to replace the specified enumeration class in the basic component.
11. The computer-readable storage medium of claim 10, wherein: When the computer program is executed by a processor, the following steps are implemented: During the operation of the target system, an enumeration value modification instruction is received and parsed to obtain a specified enumeration class and a specified enumeration operation, wherein the specified enumeration operation is to delete a specified enumeration value and / or add a new enumeration value; If the specified enumeration operation includes adding a new enumeration value, then the enumeration information of the new enumeration value is obtained, and the enumeration information at least includes: a name and a custom description.
12. The computer-readable storage medium of claim 11, wherein: When the computer program is executed by a processor, the following steps are implemented: Construct a list object containing the original enumeration value; Performing a specified enumeration operation indicated by the enumeration value modification instruction on the original enumeration value in the list object; According to the result of the specified enumeration operation, the list object is updated; The updated list object is converted into an enumeration class to obtain the changed enumeration class.
13. The computer-readable storage medium of claim 12, wherein: When the computer program is executed by a processor, the following steps are implemented: When the specified enumeration operation is to delete the specified enumeration value, read the target enumeration value specified by the enumeration value modification instruction in the list object; determine the sequence number of the target enumeration value; Delete the target enumeration value and the corresponding sequence number.
14. The computer-readable storage medium of claim 12, wherein: When the computer program is executed by a processor, the following steps are implemented: When the specified enumeration operation is to add a new enumeration value, determine the maximum sequence number of the enumeration value under the specified enumeration class; Generate a target sequence number of the new enumeration value according to the maximum sequence number; Based on the accessor of the constructor of the specified enumeration class, generate the new enumeration value according to the name, the custom description, and the target sequence number; Add the new enumeration value to the list object.
15. The computer-readable storage medium of claim 10, wherein: When the computer program is executed by a processor, the following steps are implemented: Get the field accessor of the value attribute of the specified enumeration class, and make the field accessor private and final; The changed enumeration class is assigned to the value attribute of the specified enumeration class in an overwritten form through the field accessor.
16. The computer-readable storage medium of claim 10, wherein: When the computer program is executed by a processor, the following steps are implemented: The read original enumeration value of the specified enumeration class is stored in the enumeration cache; After the step of replacing the designated enumeration class in the basic component with the changed enumeration class based on the reflection mechanism, the enumeration cache is cleared.
17. A computer program product comprising a computer program, wherein: When the computer program is executed by a processor, the following steps are implemented: During the operation of the target system, obtain the specified enumeration class and the specified enumeration operation; Reading the original enumeration value under the specified enumeration class in the basic component of the target system; Perform the specified enumeration operation on the original enumeration value to obtain a changed enumeration class; Based on the reflection mechanism, the changed enumeration class is used to replace the specified enumeration class in the basic component.
18. The computer program product of claim 17, wherein: When the computer program is executed by a processor, the following steps are implemented: During the operation of the target system, an enumeration value modification instruction is received and parsed to obtain a specified enumeration class and a specified enumeration operation, wherein the specified enumeration operation is to delete a specified enumeration value and / or add a new enumeration value; If the specified enumeration operation includes adding a new enumeration value, then the enumeration information of the new enumeration value is obtained, and the enumeration information at least includes: a name and a custom description.
19. The computer program product of claim 18, wherein: When the computer program is executed by a processor, the following steps are implemented: Construct a list object containing the original enumeration value; Performing a specified enumeration operation indicated by the enumeration value modification instruction on the original enumeration value in the list object; According to the result of the specified enumeration operation, the list object is updated; The updated list object is converted into an enumeration class to obtain the changed enumeration class.
20. The computer program product of claim 19, wherein: When the computer program is executed by a processor, the following steps are implemented: When the specified enumeration operation is to delete the specified enumeration value, read the target enumeration value specified by the enumeration value modification instruction in the list object; Determine the sequence number of the target enumeration value; Delete the target enumeration value and the corresponding sequence number.
Citation Information
Patent Citations
Dynamic enumeration method
CN102436370A
Enumeration value modification method and device, computer equipment and readable storage medium
CN116483351A
Object-oriented enumerated type facility
US20040049764A1
