CN110795169A - Method and related device for acquiring data - Google Patents

Method and related device for acquiring data Download PDF

Info

Publication number
CN110795169A
CN110795169A CN201810872145.9A CN201810872145A CN110795169A CN 110795169 A CN110795169 A CN 110795169A CN 201810872145 A CN201810872145 A CN 201810872145A CN 110795169 A CN110795169 A CN 110795169A
Authority
CN
China
Prior art keywords
function
data
information
pkbean
type
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.)
Granted
Application number
CN201810872145.9A
Other languages
Chinese (zh)
Other versions
CN110795169B (en
Inventor
张磊
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Douyu Network Technology Co Ltd
Original Assignee
Wuhan Douyu Network Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Wuhan Douyu Network Technology Co Ltd filed Critical Wuhan Douyu Network Technology Co Ltd
Priority to CN201810872145.9A priority Critical patent/CN110795169B/en
Publication of CN110795169A publication Critical patent/CN110795169A/en
Application granted granted Critical
Publication of CN110795169B publication Critical patent/CN110795169B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4488Object-oriented
    • G06F9/449Object-oriented method invocation or resolution

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; performing a conversion process through a toString () function, wherein the toString () function is used for converting the data information in the allInfos into an object of a String type; tostring () function in PKBean-like is called.

Description

Method and related device for acquiring data
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 a method 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 C + + messages.
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 a 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; and if so, 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 ═ entry getkey () function to convert a type of key information in the key-value pair information entry into the String type; getvalue () function is called to obtain value information in the key-value pair information entry and convert the type of the value information into int type.
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 to insert 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 end (length) function in the builder object, inserting value information (length) of the length data into the builder object, so that the data in the builder object is composed of the following components: PKBean { width ═ length }; calling 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 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.
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 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 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 allInfos 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 voidsetLength (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; and if so, 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 ═ entry getkey () function to convert a type of key information in the key-value pair information entry into the String type; getvalue () function is called to obtain value information in the key-value pair information entry and convert the type of the value information into int type.
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 to insert 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 end (length) function in the builder object, inserting value information (length) of the length data into the builder object, so that the data in the builder object is composed of the following components: PKBean { width ═ length }; calling 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 C + + messages.
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 practiced otherwise than as specifically 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 function definitions are 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 server and the information does not need to be transferred to the C + + server, and in order to screen out 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 designing the above function, a parameter information isargment is added to the set function, and the parameter information is a bootean boolean variable information for indicating whether to add the parameter information to the global variable allinfo. It will be appreciated that this operational flow needs to be performed in all set-series functions.
Assigning the function parameter to the variable width by calling the this width function, and then judging the value information of the isargment, if the isargment is false, the parameter information does not need to be stored, and the parameter information does not need to be transmitted to C + + at the moment, so that the parameter can be captured; if equal, it indicates that the parameter is the parameter information that needs to be transferred in C + +, so it needs to store the parameter information into the allinfo set by calling the allinfo. Similarly, if isArgment in other set functions is false, 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 similar PKBean 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, description will be given for implementation of the set function.
In the embodiment of the invention, a maintenance variable Map < String and Object > allinfo of global data is defined in the PKBean-like, 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.width ═ width, wherein this.width represents the global variable width, and the width on the right side of the equal sign represents the parameter width.
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 Object-oriented characteristic, various types of data in the class PKBean can be stored in the set 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 application, the corresponding getWidth function may return the content information of the global variable width by calling the existing return this.
104. Performing a conversion flow through a toString () function;
105. tostring () function in PKBean-like is called to get C + + messages according to the objects of String type.
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 the allinfo set in a traversal manner and spliced. Alternatively, in practical application, the splicing method may be that value information of the width is obtained by calling an allinfo. 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, the result shows that the product is not; 4) if it is true, a key value pair information entry is first acquired by 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 int value () function is called to obtain its value information and to force the type of the obtained value information to be converted into data of one int type. 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 separator is added first by calling the builder. allowed (",") 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 5, after the whole data information is completely encapsulated in the builder object, calling a builder _ testring () function to convert the data in the builder object into a String type object builder String, and then calling a return builder String function to return the builder String.
Therefore, in the subsequent use 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 can be 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 (newArrayList < String >); 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, addition may also be performed in a similar manner, and details are not described here; 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, the listTarget size () function is called. If the return value of the listtarget.size () function is 0, it represents that all element information is already contained, and if the return value of the listtarget.size () function is greater than 0, it represents that there is some information that is not removed from the listTarget object, i.e. part of information content is missing in the allinfo set, which indicates that the allinfo set lacks content, and a conversion process (tosting ()) cannot be performed, so a 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 MyBuilder object by calling this, where this represents the internal MyBuilder class of PKBean, that is, the information is stored in the object of MyBuilder class. And directly returning the object of the MyBuilder type 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 for width, and a MyBuilder object is returned. Since the returned MyBuilder type object this is, 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 definition is as follows: the method comprises the steps that a public PKBean is built () { }, the builder function returns an object of a PKBean type, and a conversion process of converting a MyBuilder class into a PKBean class is realized in the builder function, wherein the specific conversion process is that a PKBean object is constructed by calling a PKBean construction function, for example, a pkBean object is obtained by calling a PKBean () function, and then a pkBean is. 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 the above description, 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 class 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 isargement, the parameter isargement is a boolean type, the parameter isargement is used to indicate whether to add parameter information to allInfos, and the allInfos is used to indicate a set that stores various types of data in the PKBean-like;
the defining unit 201 is further configured to design a maintenance variable Map < String > allinfo of global data using a Map data structure in the PKBean-like, 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 allInfos 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 end 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 Iterator type; calling a mliterator-hasNext () function in the object mliterator to judge whether the allInfo has elements; and if so, 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 ═ entry getkey () function to convert a type of key information in the key-value pair information entry into the String type; getvalue () function is called to obtain value information in the key-value pair information entry and convert the type of the value information into int type.
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 to insert 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 end (length) function in the builder object, inserting value information (length) of the length data into the builder object, so that the data in the builder object is composed of the following components: PKBean { width ═ 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 isArgment); public void end 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 a mliterator-hasNext () function in the object mliterator to judge whether the allInfo has elements; and if so, 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 ═ entry getkey () function to convert a type of key information in the key-value pair information entry into the String type; getvalue () function is called to obtain value information in the key-value pair information entry and convert the type of the value information into int type.
Optionally, in a possible embodiment, the processor 320 is specifically configured to: calling an ap (width) function in the builder object to insert 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 }; calling a builder () function in the builder object to add a delimiter; calling an end (length) function in the builder object, inserting value information (length) of the length data into the builder object, so that the data in the builder object is composed of the following components: PKBean { width ═ 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 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 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 computer program 411 is specifically adapted 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 adapted to implement the following steps when being executed by a processor: 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; and if so, 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 ═ entry getkey () function to convert a type of key information in the key-value pair information entry into the String type; getvalue () function is called to obtain value information in the key-value pair information entry and convert the type of the value information into int type.
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 to insert 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 end (length) function in the builder object, inserting value information (length) of the length data into the builder object, so that the data in the builder object is composed of the following components: PKBean { width ═ 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 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.
It should be noted that, in the foregoing embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to relevant descriptions of other embodiments for parts that are 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 preferred embodiments and all such alterations and modifications as 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;
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 an integer 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 a mliterator-hasNext () function in the object mliterator to judge whether the allInfo has elements;
and if so, 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 ═ entry getkey () function to convert a type of key information in the key-value pair information entry into the String type;
getvalue () function is called to obtain value information in the key-value pair information entry and convert the type of the value information into int type.
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 to insert 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 end (length) function in the builder object, inserting value information (length) of the length data into the builder object, so that the data in the builder object is composed of the following components: PKBean { width ═ 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 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 allInfos 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.
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.
CN201810872145.9A 2018-08-02 2018-08-02 Method and related device for acquiring data Active CN110795169B (en)

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 true CN110795169A (en) 2020-02-14
CN110795169B 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 (6)

* Cited by examiner, † Cited by third party
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
US20030055820A1 (en) * 2001-07-30 2003-03-20 Aigen Michael L. Process for generating enterprise java bean components from an SQL database
CN1513145A (en) * 2001-06-07 2004-07-14 �Ҵ���˾ System and method of mapping between software objects and structure languige 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
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
US20130139134A1 (en) * 2011-08-10 2013-05-30 International Business Machines Corporation Serialization of pre-initialized objects

Patent Citations (6)

* Cited by examiner, † Cited by third party
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
CN1513145A (en) * 2001-06-07 2004-07-14 �Ҵ���˾ System and method of mapping between software objects and structure languige 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
US20030055820A1 (en) * 2001-07-30 2003-03-20 Aigen Michael L. 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
US20130139134A1 (en) * 2011-08-10 2013-05-30 International Business Machines Corporation Serialization of pre-initialized objects

Non-Patent Citations (6)

* Cited by examiner, † Cited by third party
Title
YING YI: "How to convert javabean to post param string?", 《HTTPS://STACKOVERFLOW.COM/QUESTIONS/39145419/HOW-TO-CONVERT-JAVABEAN-TO-POST-PARAM-STRING》 *
人,总要有点追求的: "javaBean与Map<String,Object>互转", 《HTTPS://WWW.CNBLOGS.COM/ZHILU-DOC/P/7078279.HTML》 *
尹元元等: "一种基于Annotation构造JSON对象的方法", 《中国科技信息》 *
张扬嵩: "泛型和JSON简化数据访问处理技巧", 《电脑编程技巧与维护》 *
胡建国等: "基于大量文本信息过滤系统的实现", 《成都信息工程学院学报》 *
马俊昌: "《Java编程的逻辑》", 31 January 2018, 机械工业出版社 *

Also Published As

Publication number Publication date
CN110795169B (en) 2022-11-11

Similar Documents

Publication Publication Date Title
CN106919509B (en) Client generation method and device and electronic equipment
CN110275831B (en) Mock data verification method and device of protocol interface
CN110007902A (en) The method and device of business processing flow configuration
CN110058864B (en) Micro-service deployment method and device
CN110069259B (en) ID L file-based parsing method and device, electronic equipment and storage medium
CN107704382A (en) Towards Python function call path generating method and system
CN109343968B (en) Method and related device for acquiring data
CN111343181B (en) Message processing method and system, data pool and computer readable storage medium
CN110007926B (en) Language conversion method and device
CN112037061A (en) Processing method and device for transactions in block chain, electronic equipment and storage medium
CN110659905A (en) Transaction verification method, device, terminal equipment and storage medium
CN111078573A (en) Test message generation method and device
CN113923268B (en) Resolution method, device and storage medium for multi-version communication protocol
CN110795168B (en) Method for acquiring data and related device
CN110795169B (en) Method and related device for acquiring data
CN117370203A (en) Automatic test method, system, electronic equipment and storage medium
CN110795098B (en) Method and related device for acquiring data
CN110554857A (en) JavaBean generation method, device and system and readable storage medium
CN107783760B (en) Visual development method for protection device based on functional component
CN116594717A (en) Class loading isolation method, device, equipment and medium
CN113608746B (en) Code conversion processing method, device, computer equipment and storage medium
CN106802805B (en) Application service management method and device suitable for server management
CN112134900B (en) Data message processing method and device
CN110008035B (en) Data interface extension method, data processing method, device and equipment
CN113448870A (en) Intelligent contract reentry defect detection method based on dynamic execution information analysis

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