CN110795169B - Method and related device for acquiring data - Google Patents
Method and related device for acquiring data Download PDFInfo
- Publication number
- CN110795169B CN110795169B CN201810872145.9A CN201810872145A CN110795169B CN 110795169 B CN110795169 B CN 110795169B CN 201810872145 A CN201810872145 A CN 201810872145A CN 110795169 B CN110795169 B CN 110795169B
- Authority
- CN
- China
- Prior art keywords
- function
- data
- information
- pkbean
- allinfo
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/448—Execution paradigms, e.g. implementations of programming paradigms
- G06F9/4488—Object-oriented
- G06F9/449—Object-oriented method invocation or resolution
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Document Processing Apparatus (AREA)
Abstract
The embodiment of the invention discloses a method for acquiring data and a related device, comprising the following steps: defining target data in a PKBean class of a data Bean object; setting a set function and a get function for target data; using a Map data structure in the similar PKBean, designing a maintenance variable Map < String, object > allinfo of the global data; storing parameter information used for setting a global variable in the set function in allInfo according to a Map data structure, and returning content information of the global variable according to the get function; carrying out a conversion process through a toString () function, wherein the toString () function is used for converting the data information in the allInfos into a String type object; tostring () function in PKBean-like is called.
Description
Technical Field
The present invention relates to the field of development platforms, and in particular, to a method for acquiring data and a related apparatus.
Background
In the traditional scheme, the construction of the C + + message is realized by manually writing codes by a programmer and splicing the written codes one by one. Such an approach may make the whole concatenation flow complicated and difficult to process, and the process of acquiring and concatenating data may also take a lot of time, resulting in very inefficient construction of C + + messages. Therefore, in practical application, the traditional method for constructing the parameter list sent to the C + + bullet screen server also has the problems of long construction time and low construction efficiency.
Therefore, compared with a splicing method for realizing sending parameters one by one in a manual mode in the traditional scheme, how to quickly and effectively construct a parameter list sent to the C + + bullet screen server and screen out information which is not required to be transmitted to the C + + bullet screen server is an urgent problem to be solved.
Disclosure of Invention
The embodiment of the invention provides a method and a related device for acquiring data, which are used for screening information sent to a C + + server and improving the acquisition efficiency of a C + + message.
A first aspect of an embodiment of the present invention provides a method for acquiring data, where the method is used to acquire a C + + message in an Android system, and includes: defining target data in a PKBean class of a data Bean object, wherein the target data is a private type; setting a set function and a get function for the target data, wherein the set function comprises a parameter isargment, the parameter isargment is of a boolean bootean type, the parameter isargment is used for indicating whether parameter information is added into allInfos, and the allInfos is used for indicating a set for storing various types of data in the PKbean-like; using a Map data structure in the PKBean-like, designing a maintenance variable Map < String > Object > allinfo of global data, wherein the String is used for representing the name of stored data, and the Object is used for representing the information of the stored data; storing parameter information used for setting a global variable in the set function in the allInfo according to the Map data structure, and returning content information of the global variable according to the get function; performing a conversion process through a toString () function, wherein the toString () function is used for converting the data information in the allInfos into a String type object; and calling a pkbean.tostring () function in the PKbean-like function to acquire the C + + message according to the String type object.
In one possible embodiment, the function of setting a set function on the target data comprises: the function of the set function is set as follows: public void set width (int width, boolean isArgment); public void length (int length, boolean isArgment); the Public is used for representing that the access right of the set function is Public, the void is used for representing that the set function has no return value, and the int represents an integer function.
In one possible embodiment, the conversion flow by the toString () function includes: defining a builder object of a character string splicing class in the StringBuilder type; calling a function ap (PKBean { ") in the builder object to add name prefix information (PKBean {") in the builder object; acquiring key-value pair information of the data information in the allInfo; adding the key value pair information into the builder object, and packaging the key value pair information; and when the key value pair information is packaged in the builder object, converting the data in the builder object into the String type object.
In a possible embodiment, the obtaining key-value pair information of the data information in the allInfos includes: calling an allinfo.entrySet () function in the allInfo to obtain an entrySet of the entrySet type of the allInfo; invoking an entrySet. Iterator () function in the object entrySet to obtain an object mIterator of Iterator type; calling a mliterator-hasNext () function in the object mliterator to judge whether the allInfo has elements; if yes, calling a map.entry = (map.entry) it.next () function to obtain the key-value pair information entry.
In a possible embodiment, the converting the data in the builder object into the String type object includes: invoking a String key = (String) entry. Getkey () function to convert a type of key information in the key-value pair information entry into the String type; invoking int value = (Integer) entry.
In one possible embodiment, the target data includes width data of int type and height data of int type; adding the data information in the allinfo to the builder object, and encapsulating the data information, including: calling an ap (width =) function in the builder object, inserting value information width of the width data in the builder object, so that the data in the builder object is composed of the following components: PKBean { width = width value; calling a builder () function in the builder object to add a delimiter; an open ("length =") function in the builder object is called, the open (length value) function inserts value information length of the length data into the builder object, so that the data in the builder object is composed as follows: PKBean { width = width, length = length }; invoking a builder () function in the builder object to add an end character to realize the encapsulation of the data information.
In a possible embodiment, before the converting process by the toString () function, the method further comprises: defining a calibration set object listTarget in the PKBean-like model, wherein the listTarget is used for verifying data in the PKBean-like model; and determining that the allInfo comprises all data information according to the listTarget.
A second aspect of the embodiments of the present invention provides an obtaining apparatus, where the apparatus is configured to obtain a C + + message in an Android system, and the apparatus includes: the system comprises a defining unit, a data Bean object generating unit and a data processing unit, wherein the defining unit is used for defining target data in a PKbean of the data Bean object, and the target data is a private type; the setting unit is used for setting a set function and a get function for the target data, wherein the set function comprises a parameter isargment, the parameter isargment is of a Boolean boolean type, the parameter isargment is used for indicating whether parameter information is added into allInfos, and the allInfos is used for indicating a set for storing various types of data in the PKBean-like; the defining unit is further used for designing a maintenance variable Map < String > allinfo of global data by using a Map data structure in the PKBean-like, wherein the String is used for representing the name of the stored data, and the Object is used for representing the information of the stored data; the storage unit is used for storing the parameter information used for setting the global variable in the set function in the allInfo according to the Map data structure and returning the content information of the global variable according to the get function; a converting unit, configured to perform a conversion process through a toString () function, where the toString () function is used to convert the data information in the allinfo into a String-type object; a calling unit, configured to call a pkbean.tostring () function in the PKBean-like function, so as to obtain the C + + message according to the object of the String type.
In a possible embodiment, the setting unit is specifically configured to: the function of the set function is set as follows: public void set width (int width, boolean isArgment); public void length (int length, boolean isArgment).
In a possible embodiment, the conversion unit is specifically configured to: defining a builder object of a character string splicing class in the Stringbuilder type; calling a function ap (PKBean { ") in the builder object to add name prefix information (PKBean {") in the builder object; acquiring key-value pair information of the data information in the allInfo; adding the key value pair information into the builder object, and packaging the key value pair information; and when the key value pair information is packaged in the builder object, converting the data in the builder object into the String type object.
In a possible embodiment, the conversion unit is specifically configured to: calling an allinfo.entrySet () function in the allInfo to obtain an entrySet of the entrySet type of the allInfo; invoking an entrySet. Iterator () function in the object entrySet to obtain an object mIterator of Iterator type; calling a mliterator-hasNext () function in the object mliterator to judge whether the allInfo has elements; if yes, calling a map.entry = (map.entry) it.next () function to obtain the key-value pair information entry.
In a possible embodiment, the conversion unit is specifically configured to: invoking a String key = (String) entry. Getkey () function to convert a type of key information in the key-value pair information entry into the String type; get value information in the key-value pair information entry and convert the type of the value information to int type by calling int value = (Integer) entry.
In one possible embodiment, the target data includes width data of int type and height data of int type; the conversion unit is specifically configured to: calling an ap (width =) function in the builder object, inserting value information width of the width data in the builder object, so that the data in the builder object is composed of the following components: PKBean { width = width value; calling a builder () function in the builder object to add a delimiter; an open ("length =") function in the builder object is called, the open (length value) function inserts value information length of the length data into the builder object, so that the data in the builder object is composed as follows: PKBean { width = width, length = length }; invoking a builder () function in the builder object to add an end character to realize the encapsulation of the data information.
In a possible embodiment, the defining unit is further configured to define a listTarget of a calibration set in the class PKBean, where the listTarget is used to perform verification processing on data in the class PKBean; and the determining unit is used for determining that the allInfo comprises all data information according to the listTarget.
A third aspect of the present invention provides an electronic device, comprising a memory and a processor, wherein the processor is configured to implement the steps of the method for acquiring data according to any one of the above items when executing a computer management program stored in the memory.
A fourth aspect of the present invention provides a computer-readable storage medium having a computer management-like program stored thereon, characterized in that: the computer management like program when executed by a processor performs the steps of the method of obtaining data as described in any one of the above.
According to the technical scheme, the embodiment of the invention has the following advantages: defining target data in a PKBean class of a data Bean object, wherein the target data is a private type; setting a set function and a get function for the target data, wherein the set function comprises a parameter isargment, the parameter isargment is of a boolean bootean type, the parameter isargment is used for indicating whether parameter information is added into allInfos, and the allInfos is used for indicating a set for storing various types of data in the PKbean-like; using a Map data structure in the PKBean-like, designing a maintenance variable Map < String > Object > allinfo of global data, wherein the String is used for representing the name of stored data, and the Object is used for representing the information of the stored data; storing parameter information used for setting a global variable in the set function in the allInfo according to the Map data structure, and returning content information of the global variable according to the get function; performing a conversion process through a toString () function, wherein the toString () function is used for converting the data information in the allInfos into a String type object; and calling a pkbean.tostring () function in the PKbean-like function to acquire the C + + message according to the String type object. In the embodiment of the invention, the information sent to the C + + server is screened, so that the construction efficiency of the C + + message can be effectively improved, the data acquisition difficulty and the splicing difficulty can be reduced, and the C + + message acquisition efficiency is greatly improved.
Drawings
FIG. 1 is a flow chart of a possible method for obtaining data according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of a possible acquisition apparatus according to an embodiment of the present invention;
fig. 3 is a schematic diagram of a hardware structure of a possible electronic device according to an embodiment of the present invention;
fig. 4 is a schematic hardware structure diagram of a possible computer-readable storage medium according to an embodiment of the present invention.
Detailed Description
The embodiment of the invention provides a method and a related device for acquiring data, which are used for screening information sent to a C + + server and improving the acquisition efficiency of a C + + message.
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The terms "first," "second," "third," "fourth," and the like in the description and in the claims of the present application and in the drawings described above, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It will be appreciated that the data so used may be interchanged under appropriate circumstances such that the embodiments described herein may be implemented in other sequences than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
Referring to fig. 1, a flowchart of a method for acquiring data according to an embodiment of the present invention includes:
101. defining target data in a PKBean class of a data Bean object;
in the conventional scheme, the data carrier has a data acquisition process, and the data acquisition process is complex, so that the complexity of data acquisition in the conventional scheme is increased. In view of this, in this step, a new method for designing a data carrier will be described to simplify the data acquisition process, which is as follows:
in the Android development, data is usually stored in a data Bean object, so the data acquisition speed is the fastest if the designed data acquisition is in the Bean object. Based on this, the design of data bearers can be implemented in a PKBean-like of a data Bean object. It should be noted that several pieces of field information, such as width of int type and height data of int type, are included in the PKBean class. For convenience of description, in the embodiment of the present invention, only the use case including these two pieces of data is described, and if other types of field information or data are also included, the processing manner is similar to the manner of processing the width of the int type and the height data of the int type, and details are not described here again.
In the embodiment of the present invention, the target data may be the two data, that is, the width data of int type and the height data of int type, and the specific definition mode is as follows:
private int width;
private int height;
two local variables width and height are defined in the PKBean-like, the core of which is a private (private) type, and the parameter types of which are data of int integer type. Next, setWidth and getWidth function functions are set for the target data, and specific functions are defined as follows:
Public void setWidth(int width){}
Public int getWidth(){}
through the steps, the design of the data carrier is completed, and the data is finally stored through the defined memory variables width and height. The above description shows the design of the set function and get function of width, and the design of the function for height is similar to width, and is not repeated here.
102. Setting a set function and a get function for target data;
when the similar PKBean has a plurality of field information width and length, the conversion process automatically converts all data information. However, in practical applications, other relevant information may be stored in the PKBean-like object and the information does not need to be transferred to the C + + server, and in order to screen out the information that needs to be converted, in the embodiment of the present invention, a design method that can change the number of entries is provided, and a specific implementation method includes the following steps: 1) The redesign is performed when designing the set function, and the specific design method is as follows:
Public void setWidth(int width,Boolean isArgument);
Public void setLength(int length,Boolean isArgument);
the Public is used for indicating that the access right of the set function is Public, the void is used for indicating that the set function has no return value, and the int is used for indicating a rounding function.
When the function is designed, a parameter information isargment is added in the set function, and the parameter information is a bootean boolean variable information used for indicating whether the parameter information is added to the global variable allinfo. It will be appreciated that this operational flow needs to be performed in all set-series functions.
Assigning a function parameter to a variable width by calling a this = width function, and then judging the value information of isargment, wherein if isargment = = false, the parameter information does not need to be stored, and the parameter does not need to be transferred to C + + parameter information at the moment, so that the parameter can be captured; if isarget = = true, it indicates that the parameter is parameter information that needs to be transferred in C + +, so it needs to store the parameter information in the allinfo set by calling the allinfo. Similarly, if isArgment = = false in other set functions, the parameter is not stored in the allInfo set, otherwise the information is stored in the set allInfo. Through the design, the content in the set allInfo is the content information needing to be stored, and the content needing not to be stored cannot be stored in the set allInfo.
103. Using a Map data structure in the PKBean-like to design maintenance variables of global data;
it should be noted that Public void setWidth (int width) { } is a definition of a set function, and in this step, a description will be given of implementation of the set function.
In the embodiment of the invention, a maintenance variable Map < String of global data and Object > allinfo are defined in a PKBean-like function, when a caller calls a setWidth function, an assignment operation is firstly carried out on the global variable width through a variable of a statement this.
Wherein, a Map data structure is used to store data when designing the global set, wherein String represents the name of the stored data, and the generic Object type stores the specific information of the data. Since the Object type is an abstract class given to the top layer in Java and has the capability of receiving other types of data according to the characteristic of Object orientation, various types of data in the class PKBean can be stored in the collection allInfo. Put the information of the setting parameter to the global set allinfo by calling the method of the set allinfo, and similarly, the storage processing is carried out on the set functions of other parameters in a similar way, that is, the data is cached to the global variable allinfo in the data storage logic in the data PKBean.
In addition, in practical applications, the corresponding getWidth function may return content information of the global variable width by calling the existing return this.
104. Carrying out a conversion flow through a toString () function;
105. tostring () function in PKBean like is called to get C + + message according to the String type object.
It should be noted that, in the prior art, the conversion method of the data bearer defines a special function to implement the conversion logic, and then calls the function to implement the conversion function. However, this approach may add too many function functions and is relatively troublesome to implement and design, and in view of this, the embodiment of the present invention provides a design flow of a conversion method for a data bearer, which specifically includes the following steps:
step 1, the embodiment of the present invention performs a conversion process by means of a tosting () function of the system when being implemented, it should be noted that, when the tosting () function is designed, it is used for printing some log information, and it is rare to use the tosting () function to perform logic processing, but because the tosting () function returns content information of a character string, and data of a C + + transfer message is also character string information, it can perfectly match, and based on this, the embodiment of the present invention can directly implement a true conversion process in the tosting () function of the system and output the conversion process.
In addition, in step 103, all the information is already stored in the global set allinfo, so that the conversion process can be realized only by acquiring the data information in the allinfo when the conversion is needed.
Step 2, it needs to be noted that in order to improve the conversion efficiency in the conversion process, in the embodiment of the present invention, a stripbuilder character string splicing type builder is designed when the conversion process is implemented, and the whole information conversion process is implemented through a stripbuilder object of the type of the builder, so that the generation of garbage variables in the conversion process can be reduced, and the memory overhead in the conversion process can be effectively reduced.
Specifically, a name prefix information 'PKBean {' is added to the builder by calling an ap-pend ('PKBean {') function in the builder object, and then information is sequentially taken out from an allInfo set in a traversal mode and spliced. Optionally, in an actual application, the splicing method may be that value information of the width is obtained by calling an allinfo.get ("width") method, and for convenience of description, the obtained value information is marked as width value, and then a piece of data information is inserted into the builder object by calling an ap-pend ("width =") function in the builder object. After the above processing, the format of the data in the whole builder object is as follows:
PKBean{width=widthValue。
step 3, key value pair information of the data information in the allInfo is obtained;
it should be noted that, since the allinfo set does not include all field information in the PKBean class, when acquiring the information, it is necessary to acquire key and value information one by one, and a specific manner of acquiring the key and value is as follows: acquiring an entryseet object entryseet of an allinfo object by calling an allinfo.entryseet () function of the allinfo object, then calling an entryseet.iter () method in the entryseet object to acquire an iterer type object miterer, judging whether element information exists in the allinfo object by calling an iterer.hasnext () method in the miterer object, and if a true is returned, indicating that the element information exists; otherwise, no indication is given; 4) If it is true, first, a key value pair information entry is acquired through a map.entry = (map.entry) it.next () function, and then key information is acquired by calling a String key = (String) entry.getkey () function and the acquired key information mandatory type is converted into String type data. Similarly, the value information thereof is acquired by calling int value = (Integer) entry. This allows key-value pair information to be retrieved.
And 4, adding the key value pair information in the step 3 into the builder object, and packaging the key value pair information. The specific adding method is that a delimiter is added first by calling a builder.ap (",") function in the builder object, and then the information of length is added. It should be noted that the method for specifically adding the length information is similar to the method for adding the width information, and details are not described here.
And 4, when all the key value pair information is completely assembled in the builder object, adding an end character, wherein the specific method for adding the end character is to add the end character by calling a builder. Applied (") function in the builder object, so that the whole process for adding the key value pair information is completed. The data composition form in the builder object at this time is as follows:
PKBean{width=widthValue,length=lengthValue}。
and step 5, after the whole data information is completely encapsulated in the builder object, calling a builder _ tostring () function to convert the data in the builder object into a String type object builderStr, and then calling a return builderStr function to return the builderStr.
Therefore, in the subsequent using process, the final C + + message data can be obtained only by calling the pkbean.tostring () function of the pkbean object, so that the parameter information can be quickly obtained and the data is transferred.
In the embodiment of the invention, a parameter list sent to the C + + bullet screen server can be quickly and effectively constructed through the implementation of the scheme. Compared with a splicing method for realizing bullet screen sending parameters one by one in a manual mode in the traditional scheme, the efficiency of parameter splicing, the speed of parameter splicing and the like can be greatly improved.
It should be noted that, in the embodiment shown in fig. 1, the tosting () function would convert all data into parameter information required by C + +, but in the conversion process, set functions of some functions may not be called, that is, not all parameter information is set, which may cause partial data loss, thereby causing an exception to the service function. In view of this, the embodiment of the present invention adds a data checking function, which can effectively ensure the integrity of data, thereby avoiding the problem of data shortage. The specific implementation is as follows: 1) In order to verify field information in a PKBean object, a calibration set object listTarget is designed in the PKBean type object, and then the listTarget set object is initialized, wherein the specific initialization method is to initialize by calling a listTarget = new ArrayList < String > () function; 2) Then, a checkParam function is designed to realize the detection operation of the parameter information, and the specific function definition is as follows: public boilean checkParam () { }, it should be noted that, the checkParam function has no parameter and the factory parameter is a boilean boolean type variable, if the boilean boolean return value is true, it indicates that the check is passed, otherwise, it indicates that the check is not passed; 3) In the function checkParam, the listTarget is assigned, and a check object is added by calling a listtarget.add () function in the listTarget object, for example, if the widht information needs to be checked, the function listtarget.add ("width") can be realized by calling the listtarget.add function. It should be noted that, if length or other field information needs to be checked, the length or other field information may also be added in a similar manner, which is not described herein again; after the processing, the listTarget set contains all field information to be checked; 4) Traversing the allInfo set objects in the scheme, sequentially extracting field information in the allInfo set objects, and marking the extracted field information as item; 5) Judging whether the listTarget set contains the element information by calling a listtarget.contacts (item) function in the listTarget set object, and if so, removing the element information from the listTarget set by calling the listtarget.remove (item) function. If not, performing next cycle check; 6) When the whole allinfo set loop is finished, whether the listTarget object contains elements needs to be determined, specifically, a listTarget size () function is called. If the return value of the listtarget.size () function is 0, it means that all element information is already contained, and if the return value of the listtarget.size () function is greater than 0, it means that there is some information that is not removed from the listTarget object, i.e. part of information content is absent in the allinfo set, this time, it means that the allinfo set lacks content, and the conversion process (tosting ()) cannot be performed, so that false is returned; conversely, the value of listtarget. Size () is 0, return true; 7) Checking the check parameter of the scheme first inside the toString () function in the embodiment shown in fig. 1, and if true is returned, performing subsequent conversion operation; otherwise, the conversion is stopped and an exception is thrown to prompt the developer that the conversion fails.
The automatic parameter checking function can be realized through the design, and the integrity of information in the conversion process is ensured.
It should be noted that, in the implementation of the embodiment shown in fig. 1, a series of set functions are processed through the object of the PKBean class, which results in that the object of the PKBean class needs to be transferred in multiple places, and finally, the final conversion is implemented through the toString function of the object of the PKBean class. In order to solve the above problem, an embodiment of the present invention further provides a method for quickly constructing an object, and a specific implementation manner includes the following steps: 1) In order to realize the construction of data rapidly, a static MyBuilder class is designed in a PKBean class, and the specific definition method is as follows: public static class MyBuilder { }, it should be noted that this MyBuilder is an internal class of PKBean class and is a public authority static class, wherein the field information defined in this MyBuilder is completely consistent with the field information contained in PKBean. For example, in the embodiment shown in fig. 1, the PKBean class includes two pieces of field information, i.e., int width and int length, and then the two pieces of field information, i.e., int width and int length, are also defined in the internal class MyBuilder; 2) Two set methods are defined in the internal MyBuilder, and the specific definition method is as follows: public MyBuilder setWidth (int Width); public MyBuilder setLength (int length); it should be noted that the set method has the biggest characteristic that the return value type is the type of an internal MyBuilder, and the design can conveniently continue to set the message after setting a piece of information; 3) In the public MyBuilder setWidth (int width) function, the width information is stored in the internal type MyBuilder object by calling the this = width function, it should be noted that this represents the internal type MyBuilder class of PKBean, that is, the information is stored in the object of MyBuilder class. And directly returning the MyBuilder type object per se this by calling a rethrn this function after the storage is finished. Similarly, the design of the set function for length is similar to the set function of width, and a MyBuilder object is returned. Since the returned object this is of MyBuilder type, the design has the advantages that after one piece of information is set, another piece of information can be set; 4) Defining a builder function in the MyBuilder class, wherein the specific function is defined as follows: public PKBean built () { }, which returns a PKBean type object, and implements a conversion process of converting MyBuilder class into PKBean class in the builder function, wherein the specific conversion process is to construct a PKBean object by calling a PKBean constructor function, for example, obtaining a PKBean object by calling a PKBean = new PKBean () function, and then calling a PKBean. Storing the information of the widht object in the MyBuilder object into the widht field of the returned pkBean object, thus completing the conversion of field information; 5) Since the field information in the MyBuilder class and the field information in the PKBean class are identical in the initial design process, i.e., step 1), the MyBuilder class can be perfectly converted into the PKBean class object, and the conversion method of other fields is similar to that described above, so that a PKBean object is obtained. And then calling a pkbean.tostring () function in the pkbean object to convert the pkbean object into a parameter object required by C + +.
Embodiments of the present invention are described above from the perspective of a method of acquiring data, and embodiments of the present invention are described below from the perspective of an acquisition device.
Referring to fig. 2, fig. 2 is a schematic diagram of an embodiment of a possible obtaining apparatus according to an embodiment of the present invention, including:
a defining unit 201, configured to define target data in a PKBean of a data Bean object, where the target data is a private type;
a setting unit 202, configured to set a set function and a get function for the target data, where the set function includes a parameter isargment, the parameter isargment is a boolean type, the parameter isargment is used to indicate whether to add parameter information to an allinfo, and the allinfo is used to indicate a set for storing various types of data in the PKBean-like;
the defining unit 201 is further configured to use a Map data structure in the PKBean-like to design a maintenance variable Map < String > allinfo of global data, where the String is used to indicate a name of stored data, and the Object is used to indicate information of the stored data;
a storage unit 203, configured to store parameter information used for setting a global variable in the set function in the allinfo according to the Map data structure, and return content information of the global variable according to the get function;
a converting unit 204, configured to perform a conversion process through a toString () function, where the toString () function is used to convert the data information in the allinfo into a String-type object;
a calling unit 205, configured to call a pkbean.tostring () function in the PKBean-like function, so as to obtain the C + + message according to the object of the String type.
Optionally, in some possible implementation manners, the setting unit 202 is specifically configured to: the function of the set function is set as follows: public void set width (int width, boolean isArgment); public void segment length (int length, boolean isArgment); the Public is used for representing that the access right of the set function is Public, the void is used for representing that the set function has no return value, and the int represents an integer function.
Optionally, in some possible implementation manners, the conversion unit 204 is specifically configured to: defining a builder object of a character string splicing class in the Stringbuilder type; calling a function ap (PKBean { ") in the builder object to add name prefix information (PKBean {") in the builder object; acquiring key-value pair information of the data information in the allInfo; adding the key value pair information into the builder object, and packaging the key value pair information; and when the key value pair information is packaged in the builder object, converting the data in the builder object into the String type object.
In a possible embodiment, the conversion unit 204 is specifically configured to: calling an allinfo.entrySet () function in the allInfo to obtain an entrySet of the entrySet type of the allInfo; invoking an entrySet. Iterator () function in the object entrySet to obtain an object mIterator of an Iterator type; calling a mliterator-hasNext () function in the object mliterator to judge whether the allInfo has elements; if yes, calling a map.entry = (map.entry) it.next () function to obtain the key-value pair information entry.
In a possible embodiment, the conversion unit 204 is specifically configured to: invoking a String key = (String) entry. Getkey () function to convert a type of key information in the key-value pair information entry into the String type; invoking int value = (Integer) entry.
In one possible embodiment, the target data includes width data of int type and height data of int type; the conversion unit 204 is specifically configured to: calling an ap (width =) function in the builder object, inserting value information width of the width data in the builder object, so that the data in the builder object is composed of the following components: PKBean { width = width value; calling a builder () function in the builder object to add a delimiter; an open ("length =") function in the builder object is called, the open (length value) function inserts value information length of the length data into the builder object, so that the data in the builder object is composed as follows: PKBean { width = width, length = length }; calling a builder () function in the builder object to add an end character to realize the encapsulation of the data information.
Referring to fig. 3, fig. 3 is a schematic diagram of an embodiment of an electronic device according to an embodiment of the invention.
As shown in fig. 3, an embodiment of the present invention provides an electronic device, which includes a memory 310, a processor 320, and a computer program 311 stored in the memory 320 and executable on the processor 320, where the processor 320 executes the computer program 311 to implement the following steps: defining target data in a PKBean class of a data Bean object, wherein the target data is a private type; setting a set function and a get function for the target data, wherein the set function comprises a parameter isargment, the parameter isargment is of a boolean bootean type, the parameter isargment is used for indicating whether parameter information is added into allInfos, and the allInfos is used for indicating a set for storing various types of data in the PKbean-like; using a Map data structure in the PKBean-like, designing a maintenance variable Map < String > Object > allinfo of global data, wherein the String is used for representing the name of stored data, and the Object is used for representing the information of the stored data; storing parameter information used for setting a global variable in the set function in the allInfo according to the Map data structure, and returning content information of the global variable according to the get function; performing a conversion process through a toString () function, wherein the toString () function is used for converting the data information in the allInfos into a String type object; and calling a pkbean.tostring () function in the PKbean-like function to acquire the C + + message according to the String type object.
Optionally, in a possible embodiment, the processor 320 is specifically configured to: the function of the set function is set as follows: public void set width (int width, boolean isangument); public void length (int length, boolean isArgment); the Public is used for representing that the access right of the set function is Public, the void is used for representing that the set function has no return value, and the int represents an integer function.
Optionally, in a possible embodiment, the processor 320 is specifically configured to: defining a builder object of a character string splicing class in the Stringbuilder type; calling a function ap (PKBean { ") in the builder object to add name prefix information (PKBean {") in the builder object; acquiring key-value pair information of the data information in the allInfo; adding the key value pair information into the builder object, and packaging the key value pair information; and when the key value pair information is packaged in the builder object, converting the data in the builder object into the String type object.
Optionally, in a possible embodiment, the processor 320 is specifically configured to: calling an allinfo.entrySet () function in the allInfo to obtain an entrySet of the entrySet type of the allInfo; invoking an entrySet. Iterator () function in the object entrySet to obtain an object mIterator of Iterator type; calling an mIterator. HasNext () function in the object mIterator to judge whether the allInfo contains elements or not; if yes, calling a map.entry = (map.entry) it.next () function to obtain the key-value pair information entry.
Optionally, in a possible embodiment, the processor 320 is specifically configured to: invoking a String key = (String) entry. Getkey () function to convert a type of key information in the key-value pair information entry into the String type; get value information in the key-value pair information entry and convert the type of the value information to int type by calling int value = (Integer) entry.
Optionally, in a possible embodiment, the processor 320 is specifically configured to: calling an ap (width (=) in the builder object, inserting value information width of the width data in the builder object by an ap (width) function, so that the data in the builder object is composed as follows: PKBean { width = width value }; calling a builder () function in the builder object to add a delimiter; calling an option ("length =") in the builder object, inserting value information length value of the length data into the builder object by an option (length value) function, so that the data in the builder object is composed as follows: PKBean { width = width value, length = length value }; calling a builder () function in the builder object to add an end character to realize the encapsulation of the data information.
Optionally, in a possible embodiment, the processor 320 is further configured to: defining a calibration set object listTarget in the class PKBean, wherein the listTarget is used for verifying data in the class PKBean; and determining that the allInfo comprises all data information according to the listTarget.
In a specific implementation, when the processor 320 executes the computer program 311, any of the embodiments corresponding to fig. 1 may be implemented.
Since the electronic device described in this embodiment is a device used for implementing one of the obtaining apparatuses in this embodiment of the present invention, based on the method described in this embodiment of the present invention, a person skilled in the art can understand the specific implementation manner of the electronic device in this embodiment and various variations thereof, so that how to implement the method in this embodiment of the present invention by the electronic device is not described in detail herein, and as long as the person skilled in the art implements the device used for implementing the method in this embodiment of the present invention, the device used for implementing the method in this embodiment of the present invention belongs to the protection scope of the present invention.
Referring to fig. 4, fig. 4 is a schematic diagram illustrating an embodiment of a computer-readable storage medium according to the present invention.
As shown in fig. 4, the present embodiment provides a computer-readable storage medium 400, on which a computer program 411 is stored, the computer program 411 implementing the following steps when executed by a processor: defining target data in a PKBean class of a data Bean object, wherein the target data is a private type; setting a set function and a get function for the target data, wherein the set function comprises a parameter isargment, the parameter isargment is of a Boolean bolean type, the parameter isargment is used for indicating whether parameter information is added to allInfos, and the allInfos is used for indicating a set for storing various types of data in the PKBean-like; using a Map data structure in the PKBean-like, designing a maintenance variable Map < String > Object > allinfo of global data, wherein the String is used for representing the name of stored data, and the Object is used for representing the information of the stored data; storing parameter information used for setting a global variable in the set function in the allInfo according to the Map data structure, and returning content information of the global variable according to the get function; performing a conversion process through a toString () function, wherein the toString () function is used for converting the data information in the allInfos into a String type object; and calling a pkbean.tostring () function in the PKbean-like function to acquire the C + + message according to the String type object.
Optionally, in a possible embodiment, the computer program 411 is specifically configured to implement the following steps when being executed by a processor: the function of the set function is set as follows: public void set width (int width, boolean isArgment); public void length (int length, boolean isArgment); the Public is used for representing that the access right of the set function is Public, the void is used for representing that the set function has no return value, and the int represents an integer function.
Optionally, in a possible embodiment, the computer program 411 is specifically adapted to implement the following steps when being executed by a processor: defining a builder object of a character string splicing class in the Stringbuilder type; calling a function ap (PKBean { ") in the builder object to add name prefix information (PKBean {") in the builder object; acquiring key-value pair information of the data information in the allInfo; adding the key value pair information into the builder object, and packaging the key value pair information; and when the key value pair information is packaged in the builder object, converting the data in the builder object into the String type object.
Optionally, in a possible embodiment, the computer program 411 is specifically configured to implement the following steps when being executed by a processor: calling an allinfo.entrySet () function in the allInfo to obtain an object entrySet of an entrySet type of the allInfo; invoking an entrySet. Iterator () function in the object entrySet to obtain an object mIterator of Iterator type; calling a mliterator-hasNext () function in the object mliterator to judge whether the allInfo has elements; if yes, calling a map.entry = (map.entry) it.next () function to obtain the key-value pair information entry.
Optionally, in a possible embodiment, the computer program 411 is specifically adapted to implement the following steps when being executed by a processor: invoking a String key = (String) entry. Getkey () function to convert a type of key information in the key-value pair information entry into the String type; get value information in the key-value pair information entry and convert the type of the value information to int type by calling int value = (Integer) entry.
Optionally, in a possible embodiment, the computer program 411 is specifically adapted to implement the following steps when being executed by a processor: calling an ap (width =) function in the builder object, inserting value information width of the width data in the builder object, so that the data in the builder object is composed of the following components: PKBean { width = width value; calling a builder () function in the builder object to add a delimiter; an open ("length =") function in the builder object is called, the open (length value) function inserts value information length of the length data into the builder object, so that the data in the builder object is composed as follows: PKBean { width = width, length = length }; calling a builder () function in the builder object to add an end character to realize the encapsulation of the data information.
Optionally, in a possible embodiment, the computer program 411 is further configured to, when executed by the processor, implement the following steps: defining a calibration set object listTarget in the PKBean-like model, wherein the listTarget is used for verifying data in the PKBean-like model; and determining that the allInfo comprises all data information according to the listTarget.
It should be noted that, in the foregoing embodiments, the description of each embodiment has an emphasis, and reference may be made to the related description of other embodiments for a part that is not described in detail in a certain embodiment.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including the preferred embodiment and all changes and modifications that fall within the scope of the invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.
Claims (10)
1. A method for obtaining data, the method being used for obtaining a C + + message in an Android system, and comprising:
defining target data in a PKBean class of a data Bean object, wherein the target data is a private type;
setting a set function and a get function for the target data, wherein the set function comprises a parameter isargment, the parameter isargment is of a boolean bootean type, the parameter isargment is used for indicating whether parameter information is added into allInfos, and the allInfos is used for indicating a set for storing various types of data in the PKbean-like;
using a Map data structure in the PKBean-like, designing a maintenance variable Map < String > Object > allinfo of global data, wherein the String is used for representing the name of stored data, and the Object is used for representing the information of the stored data;
storing parameter information used for setting a global variable in the set function in the allInfo according to the Map data structure, and returning content information of the global variable according to the get function;
acquiring a check parameter return value for checking the integrity of the data of the allInfo set, if the check parameter return value is true, indicating that the allInfo set is complete, and executing subsequent conversion operation; if the return value of the check parameter is false, indicating that the allInfo set lacks content, stopping conversion and throwing an exception to prompt a developer that the conversion fails;
performing a conversion process through a toString () function, wherein the toString () function is used for converting the data information in the allInfos into a String type object;
and calling a pkbean.tostring () function in the PKbean-like function to acquire the C + + message according to the String type object.
2. The method of claim 1, wherein the function of setting a set function on the target data comprises:
the function of the set function is set as follows:
Public void setWidth(int width,Boolean isArgument);
Public void setLength(int length,Boolean isArgument);
the Public is used for representing that the access right of the set function is Public, the void is used for representing that the set function has no return value, and the int represents a rounding function.
3. The method of claim 2, wherein performing the conversion process via the toString () function comprises:
defining a builder object of a character string splicing class in the StringBuilder type;
calling a function ap (PKBean { ") in the builder object to add name prefix information (PKBean {") in the builder object;
acquiring key value pair information of the data information in the allInfo;
adding the key value pair information into the builder object, and packaging the key value pair information;
and when the key value pair information is packaged in the builder object, converting the data in the builder object into the String type object.
4. The method as claimed in claim 3, wherein said obtaining key-value pair information of data information in said alllnfo comprises:
calling an allinfo.entrySet () function in the allInfo to obtain an entrySet of the entrySet type of the allInfo;
invoking an entrySet. Iterator () function in the object entrySet to obtain an object mIterator of Iterator type;
calling an mIterator. HasNext () function in the object mIterator to judge whether the allInfo contains elements or not;
if yes, calling a map.entry = (map.entry) it.next () function to obtain the key-value pair information entry.
5. The method according to claim 4, wherein the converting the data in the builder object into the String type object comprises:
invoking a String key = (String) entry. Getkey () function to convert a type of key information in the key-value pair information entry into the String type;
get value information in the key-value pair information entry and convert the type of the value information to int type by calling int value = (Integer) entry.
6. The method of claim 5, wherein the target data comprises int-type width data and int-type height data;
adding the data information in the allinfo to the builder object, and encapsulating the data information, including:
calling an ap (width =) function in the builder object, inserting value information width of the width data in the builder object, so that the data in the builder object is composed of the following components: PKBean { width = width value;
calling a builder () function in the builder object to add a delimiter;
calling an option ("length =") in the builder object, inserting value information length value of the length data into the builder object by an option (length value) function, so that the data in the builder object is composed as follows: PKBean { width = width, length = length };
calling a builder () function in the builder object to add an end character to realize the encapsulation of the data information.
7. The method according to any one of claims 1 to 6, wherein before the conversion flow by the toString () function, the method further comprises:
defining a calibration set object listTarget in the class PKBean, wherein the listTarget is used for verifying data in the class PKBean;
and determining that the allInfo comprises all data information according to the listTarget.
8. An obtaining apparatus, configured to obtain a C + + message in an Android system, comprising:
the defining unit is used for defining target data in a PKBean class of a data Bean object, wherein the target data is a private type;
the setting unit is used for setting functions of a set function and a get function for the target data, the set function comprises a parameter isargment, the parameter isargment is of a Boolean boolean type, the parameter isargment is used for indicating whether parameter information is added to allInfos, and the allInfos is used for indicating a set for storing various types of data in the PKBean-like;
the defining unit is further used for designing a maintenance variable Map < String > allinfo of global data by using a Map data structure in the PKBean-like, wherein the String is used for representing the name of the stored data, and the Object is used for representing the information of the stored data;
the storage unit is used for storing the parameter information used for setting the global variable in the set function in the allInfo according to the Map data structure and returning the content information of the global variable according to the get function;
the conversion unit is used for obtaining a check parameter return value for checking the integrity of the data of the allinfo set, if the check parameter return value is true, the allinfo set is complete, and subsequent conversion operation is executed; if the return value of the check parameter is false, the allInfo set is indicated to lack content, the conversion is stopped, and an exception is thrown out to prompt a developer that the conversion fails;
the conversion unit is also used for performing a conversion process through a toString () function if the check parameter return value is true, wherein the toString () function is used for converting the data information in the allInfos into an object of a String type;
a calling unit, configured to call a pkbean.tostring () function in the PKBean-like function, so as to obtain the C + + message according to the String-type object.
9. A computer-readable storage medium comprising instructions that, when executed on a computer, cause the computer to perform the method of any of claims 1-7.
10. A computer program product comprising instructions which, when run on a computer, cause the computer to perform the method of any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810872145.9A CN110795169B (en) | 2018-08-02 | 2018-08-02 | Method and related device for acquiring data |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810872145.9A CN110795169B (en) | 2018-08-02 | 2018-08-02 | Method and related device for acquiring data |
Publications (2)
Publication Number | Publication Date |
---|---|
CN110795169A CN110795169A (en) | 2020-02-14 |
CN110795169B true CN110795169B (en) | 2022-11-11 |
Family
ID=69425077
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810872145.9A Active CN110795169B (en) | 2018-08-02 | 2018-08-02 | Method and related device for acquiring data |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110795169B (en) |
Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6434568B1 (en) * | 1999-08-31 | 2002-08-13 | Accenture Llp | Information services patterns in a netcentric environment |
Family Cites Families (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CA2349905A1 (en) * | 2001-06-07 | 2002-12-07 | Ibm Canada Limited-Ibm Canada Limitee | System and method of mapping between software objects and structured language element based documents |
US20040168124A1 (en) * | 2001-06-07 | 2004-08-26 | Michael Beisiegel | System and method of mapping between software objects & structured language element-based documents |
US7080361B2 (en) * | 2001-07-30 | 2006-07-18 | Lockheed Martin Corporation | Process for generating enterprise java bean components from an SQL database |
US7617504B1 (en) * | 2002-09-12 | 2009-11-10 | Sprint Communications Company L.P. | Computer method and system for integrating enterprise JavaBeans into non-Java environments |
CA2759516C (en) * | 2011-11-24 | 2019-12-31 | Ibm Canada Limited - Ibm Canada Limitee | Serialization of pre-initialized objects |
-
2018
- 2018-08-02 CN CN201810872145.9A patent/CN110795169B/en active Active
Patent Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6434568B1 (en) * | 1999-08-31 | 2002-08-13 | Accenture Llp | Information services patterns in a netcentric environment |
Also Published As
Publication number | Publication date |
---|---|
CN110795169A (en) | 2020-02-14 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110007902A (en) | The method and device of business processing flow configuration | |
CN107704382A (en) | Towards Python function call path generating method and system | |
CN110069259B (en) | ID L file-based parsing method and device, electronic equipment and storage medium | |
CN108469955B (en) | Annotation-based Android injection framework implementation method | |
CN108572911A (en) | Automate safety detecting method, device, electronic equipment and readable storage medium storing program for executing | |
CN109343968B (en) | Method and related device for acquiring data | |
CN104866764B (en) | A kind of Android phone malware detection method based on object reference figure | |
CN110007926B (en) | Language conversion method and device | |
CN110659905A (en) | Transaction verification method, device, terminal equipment and storage medium | |
CN106850650A (en) | The method and client games system of data are accessed for game client | |
CN117370203A (en) | Automatic test method, system, electronic equipment and storage medium | |
CN111078573A (en) | Test message generation method and device | |
CN113568604B (en) | Method and device for updating wind control strategy and computer readable storage medium | |
CN111240772A (en) | Data processing method and device based on block chain and storage medium | |
CN110795169B (en) | Method and related device for acquiring data | |
CN110795168B (en) | Method for acquiring data and related device | |
CN106802805B (en) | Application service management method and device suitable for server management | |
CN110795098B (en) | Method and related device for acquiring data | |
CN107783760B (en) | Visual development method for protection device based on functional component | |
CN110659022A (en) | Method for automatically calling Python script based on Java | |
CN112015436A (en) | Short message platform deployment method and device, computing equipment and computer storage medium | |
CN113608746B (en) | Code conversion processing method, device, computer equipment and storage medium | |
CN109684846A (en) | A kind of file extraction method and device | |
CN109343871A (en) | Method, apparatus, equipment and the storage medium that application program is packaged | |
CN110414021A (en) | Edge device event rules generation system, the device and method of industrial Internet of Things |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |