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

Method and related device for acquiring data Download PDF

Info

Publication number
CN110795098B
CN110795098B CN201810872877.8A CN201810872877A CN110795098B CN 110795098 B CN110795098 B CN 110795098B CN 201810872877 A CN201810872877 A CN 201810872877A CN 110795098 B CN110795098 B CN 110795098B
Authority
CN
China
Prior art keywords
function
pkbean
class
data
information
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
Application number
CN201810872877.8A
Other languages
Chinese (zh)
Other versions
CN110795098A (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 CN201810872877.8A priority Critical patent/CN110795098B/en
Publication of CN110795098A publication Critical patent/CN110795098A/en
Application granted granted Critical
Publication of CN110795098B publication Critical patent/CN110795098B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)
  • Machine Translation (AREA)

Abstract

The embodiment of the invention discloses a method and a related device for acquiring data, which are used for effectively improving the construction efficiency of C + + messages, reducing the acquisition difficulty and splicing difficulty of the data and greatly improving the efficiency of acquiring the C + + messages. The method provided by the embodiment of the invention comprises the following steps: defining target data in a PKBean class of a data Bean object; defining a static MyBuilder class in a PKBean class, wherein data defined in the MyBuilder class is the same as target data defined in the PKBean class; setting a set function and a get function for target data in the MyBuilder-like 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; defining a builder function in the similar MyBuilder to obtain a PKBean-like parameter object; carrying out a conversion process through a toString () function, wherein the toString () function is used for converting the PKBean-like parameter object in the allInfo into a String type object; tostring () function in the PKbean-like is called to obtain C + + message according to the object conversion of String type.

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 method for splicing sending parameters one by one in a manual mode in a traditional scheme, how to quickly and effectively construct a parameter list sent to a 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 effectively improving the construction efficiency of C + + messages, reducing the acquisition difficulty and splicing difficulty of the data and greatly improving the efficiency of acquiring the C + + messages.
A first aspect of an embodiment of the present invention provides a method for acquiring data, including: defining target data in a PKBean class of a data Bean object, wherein the target data is a private type; defining a static MyBuilder class in the PKBean class, wherein data defined in the MyBuilder class is the same as target data defined in the PKBean class; setting a set function and a get function for the target data in the class MyBuilder, wherein the type of a return value of the set function is the type of the class MyBuilder; 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; defining a builder function in the class MyBuilder to obtain a parameter object of the class PKBean, wherein the builder function is used for converting the class MyBuilder into the class PKBean; performing a conversion process through a toString () function, wherein the toString () function is used for converting the PKBean-like parameter object in the allInfo into a String type object; and calling a pkbean.tostring () function in the PKbean-like function to obtain the C + + message according to the object conversion of the String type.
In a possible embodiment, the function of setting a set function on the target data in the MyBuilder class includes: the function of the set function is set as follows: public MyBuilder setWidth (int Width); public MyBuilder setLength (int length); the Public is used for indicating that the access right of the set function is Public, and the int indicates a rounding function.
In a possible embodiment, the defining a builder function in the class MyBuilder to obtain the parameter object of the class PKBean includes: calling the structuring function of the PKBean-like object to construct a PKBean object; and calling a PKBean = this.
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.
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; get the value information in the key-value pair information entry by calling int value = (Integer) entry () function, and convert the type of the value information into int type.
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; defining a static MyBuilder class in the PKBean class, wherein data defined in the MyBuilder class is the same as target data defined in the PKBean class; a setting unit, configured to set a set function and a get function for the target data in the class mybuild, where a return value of the set function is of the class mybuild; 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; the definition unit is further configured to define a builder function in the class MyBuilder to obtain a parameter object of the class PKBean, where the builder function is used to convert the class MyBuilder into the class PKBean; a converting unit, configured to perform a conversion process through a toString () function, where the toString () function is used to convert the parameter object of the PKBean-like 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 object conversion 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 MyBuilder setWidth (int Width); public MyBuilder setLength (int length); the Public is used for indicating that the access right of the set function is Public, and the int indicates a rounding function.
In a possible embodiment, the setting unit is specifically configured to: calling the structuring function of the PKBean-like object to construct a PKBean object; and calling a PKBean = this.
In a possible embodiment, the definition unit 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 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-pend (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; invoking int value = (Integer) entry.
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 as described in any one of the above 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;
defining a static MyBuilder class in the PKBean class, wherein data defined in the MyBuilder class is the same as target data defined in the PKBean class;
setting a set function and a get function for the target data in the MyBuilder-like, wherein the type of a return value of the set function is the type of the MyBuilder-like;
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;
defining a builder function in the class MyBuilder to obtain a parameter object of the class PKBean, wherein the builder function is used for converting the class MyBuilder into the class PKBean;
performing a conversion process through a toString () function, wherein the toString () function is used for converting the PKBean-like parameter object in the allInfo into a String type object;
and calling a pkbean.tostring () function in the PKbean-like function to obtain the C + + message according to the object conversion of the String type. In the embodiment of the invention, the construction efficiency of the C + + message can be effectively improved, the acquisition difficulty and the splicing difficulty of data can be reduced, and the acquisition efficiency of the C + + message 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 for acquiring data and a rapid development framework, which are used for effectively improving the construction efficiency of C + + messages, reducing the acquisition difficulty and splicing difficulty of data and greatly improving the efficiency of C + + message acquisition.
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. Moreover, 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-like. 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. Defining static MyBuilder-like in PKBean-like;
it should be noted that, performing a series of set functions through the object of the PKBean class leads to the need to perform multiple passes on the object of the PKBean class, and finally, the final conversion is realized through the toString function of the object of the PKBean class. In order to solve the above problem, an embodiment of the present invention provides a method for quickly constructing an object, and a specific implementation manner includes the following steps:
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 the MyBuilder is an internal class of a PKBean class and is a static class with public authority, wherein field information defined in the MyBuilder is completely consistent with field information included in the PKBean. For example, the PKBean class contains two pieces of field information of int width and int length, and then two pieces of field information of int width and int length are defined in the internal class of MyBuilder as well.
103. Setting a set function and a get function for target data in the MyBuilder-like data;
the function of the set function is set in the internal MyBuilder, and the specific setting method is as follows:
public MyBuilder setWidth(int width);
public MyBuilder setLength(int length);
here, public indicates that the access right of the set function is Public, and int indicates the rounding function.
It should be noted that the setting method has a maximum characteristic that the return value type is the type of the internal type MyBuilder, and the design can conveniently continue to set a message after the setting is completed.
In addition, in practical application, the function of the corresponding get function may be set in an existing manner, for example, the set get width function may return the content information of the global variable width by calling an existing return this.
104. Storing parameter information used for setting global variables in the set function in allInfo according to a Map data structure;
after the set function is set, storing parameter information used for setting a global variable in the set function in allInfos according to a Map data structure, specifically, storing the width information in an internal class MyBuilder object by calling a this = width function in a public MyBuilder (int width) function, where this represents an internal class MyBuilder class of PKBean, that is, storing information in an 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 MyBuilder type object this is returned, the design has the advantage that after one piece of information is set, another piece of information can be set.
105. Defining a builder function in the similar MyBuilder to obtain a PKBean-like parameter object;
defining a builder function in the MyBuilder class, wherein the specific function definition is as follows:
public PKBean build(){};
it should be noted that the builder function returns an object of a PKBean type, and a conversion process of converting the MyBuilder class into the PKBean class is implemented in the builder function, where the specific conversion process is to construct a PKBean object by calling a constructor of the PKBean, 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 the above description, so that a PKBean object is obtained.
106. Performing a conversion flow through a toString () function;
107. 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 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 stripbuilder type, so that generation of garbage variables in the conversion process can be reduced, and 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. 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。
and 3, adding the data information in the allinfo to the builder object, and packaging the data 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 information is completely assembled, adding an end character, wherein the specific method for adding the end character is to add the end character by calling a builder. Appended (") function in the builder object, so that the whole data information adding process 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 toString () function may 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 part of data to be lost, 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, 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.
In addition, the embodiment shown in fig. 1 implements the flow of data conversion, but there is a problem that when there are multiple field information width and length in the PKBean-like, the conversion process automatically converts all data information. In practical applications, however, 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 the embodiment shown in fig. 1 cannot meet the requirement because the embodiment shown in fig. 1 performs all conversion processing on all the information. In view of this, the embodiment of the present invention provides a design method capable of changing the number of input parameters, 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 set width (int width, boolean isangument); 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 used 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; 2) 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 is the parameter information which does not need to be transferred to C + + at this time, 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 isArgument = = 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; 3) 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 the key value is true, a key value pair information entry is obtained through a map.entry = (map.entry) it.next () function, then key information is obtained by calling a String key = (String) entry.getkey () function, and the obtained key information mandatory type is converted into String type data. Similarly, the value information thereof is acquired by calling int value = (Integer) entry. Thus, the key-value pair information can be obtained; 5) Similar to the embodiment shown in fig. 1, the above-mentioned key value pair information is constructed into a C + + parameter object through the builder object, so that a target function that part of parameters need to be transferred in PKBean and part of parameters do not need to be transferred can be realized.
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; defining a static MyBuilder class in the PKBean class, wherein data defined in the MyBuilder class is the same as target data defined in the PKBean class;
a setting unit 202, configured to set a set function and a get function for the target data in the class MyBuilder, where a type of a return value of the set function is a type of the class MyBuilder; 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;
the defining unit 201 is further configured to define a builder function in the class MyBuilder to obtain a parameter object of the class PKBean, where the builder function is used to convert the class MyBuilder into the class PKBean;
a converting unit 203, configured to perform a conversion process through a toString () function, where the toString () function is used to convert the parameter object of the PKBean-like in the allInfos into an object of a String type;
a calling unit 204, configured to call a pkbean.tostring () function in the PKBean-like function, so as to obtain the C + + message according to the object conversion 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 MyBuilder setWidth (int Width); public MyBuilder setLength (int length); the Public is used for indicating that the access right of the set function is Public, and the int indicates a rounding function.
Optionally, in some possible implementation manners, the setting unit 202 is specifically configured to: calling the structuring function of the PKBean-like object to construct a PKBean object; and calling a PKBean = this.
Optionally, in some possible implementations, the defining unit 201 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 possible embodiment, the conversion unit 203 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 203 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 203 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 the value information in the key-value pair information entry by calling int value = (Integer) entry () function, and convert the type of the value information into int type.
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; defining a static MyBuilder class in the PKBean class, wherein data defined in the MyBuilder class is the same as target data defined in the PKBean class; setting a set function and a get function for the target data in the class MyBuilder, wherein the type of a return value of the set function is the type of the class MyBuilder; 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; defining a builder function in the class MyBuilder to obtain a parameter object of the class PKBean, wherein the builder function is used for converting the class MyBuilder into the class PKBean; performing a conversion process through a toString () function, wherein the toString () function is used for converting the parameter object of the PKBean-like in the allInfo into an object of a String type; and calling a pkbean.tostring () function in the PKbean-like function to obtain the C + + message according to the object conversion of the String type.
Optionally, in a possible embodiment, the processor 320 is specifically configured to: the function of the set function is set as follows: public MyBuilder setWidth (int Width); public MyBuilder setLength (int length); the Public is used for indicating that the access right of the set function is Public, and the int indicates a rounding function.
Optionally, in a possible embodiment, the processor 320 is specifically configured to: calling the structuring function of the PKBean-like object to construct a PKBean object; and calling a PKBean = this.
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.
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; 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 the value information in the key-value pair information entry by calling int value = (Integer) entry () function, and convert the type of the value information into int type.
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 an embodiment of 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; defining a static MyBuilder class in the PKBean class, wherein data defined in the MyBuilder class is the same as target data defined in the PKBean class; setting a set function and a get function for the target data in the MyBuilder-like, wherein the type of a return value of the set function is the type of the MyBuilder-like; 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; defining a builder function in the class MyBuilder to obtain a parameter object of the class PKBean, wherein the builder function is used for converting the class MyBuilder into the class PKBean; performing a conversion process through a toString () function, wherein the toString () function is used for converting the parameter object of the PKBean-like in the allInfo into an object of a String type; and calling a pkbean.tostring () function in the PKbean-like function to obtain the C + + message according to the object conversion of the String type.
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 MyBuilder setWidth (int Width); public MyBuilder setLength (int length); the Public is used for indicating that the access right of the set function is Public, and the int indicates a rounding function.
Optionally, in a possible embodiment, the computer program 411 is specifically adapted to implement the following steps when being executed by a processor: calling a construction function of the PKBean-like to construct a PKBean object; and calling a PKBean = this.
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 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.
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; 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 the value information in the key-value pair information entry by calling int value = (Integer) entry () function, and convert the type of the value information into int type.
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 (9)

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;
defining a static MyBuilder class in the PKBean class, wherein data defined in the MyBuilder class is the same as target data defined in the PKBean class;
setting a set function and a get function for the target data in the MyBuilder-like, wherein the type of a return value of the set function is the type of the MyBuilder-like;
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;
defining a builder function in the class MyBuilder to obtain a parameter object of the class PKBean, wherein the builder function is used for converting the class MyBuilder into the class PKBean;
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 PKBean-like parameter object in the allInfo into a String type object;
and calling a pkbean.tostring () function in the PKbean-like function to obtain the C + + message according to the object conversion of the String type.
2. The method according to claim 1, wherein the function of setting a set function on the target data in the MyBuilder-like class comprises:
the function of the set function is set as follows:
Public MyBuilder setWidth(int width);
Public MyBuilder setLength(int length);
the Public is used for indicating that the access right of the set function is Public, and the int indicates a rounding function.
3. The method of claim 2, wherein defining a builder function in the MyBuilder class to obtain the PKBean-like parameter object comprises:
calling the structuring function of the PKBean-like object to construct a PKBean object;
and calling a PKBean = this.
4. The method according to any one of claims 1 to 3, 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.
5. The method of claim 4, wherein the converting process by 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.
6. The method as claimed in claim 5, 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.
7. The method according to claim 5, 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 the value information in the key-value pair information entry by calling int value = (Integer) entry () function, and convert the type of the value information into int type.
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; defining a static MyBuilder class in the PKBean class, wherein data defined in the MyBuilder class is the same as target data defined in the PKBean class;
a setting unit, configured to set a set function and a get function for the target data in the class mybuild, where a return value of the set function is of the class mybuild; 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;
the definition unit is further configured to define a builder function in the class MyBuilder to obtain a parameter object of the class PKBean, where the builder function is used to convert the class MyBuilder into the class PKBean;
the conversion unit is used for obtaining a check parameter return value for checking the integrity of the allInfo set data, 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, indicating that the allInfo set lacks content, stopping conversion and throwing an exception 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 parameter object of the PKBean-like object 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 object conversion 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.
CN201810872877.8A 2018-08-02 2018-08-02 Method and related device for acquiring data Active CN110795098B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810872877.8A CN110795098B (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
CN201810872877.8A CN110795098B (en) 2018-08-02 2018-08-02 Method and related device for acquiring data

Publications (2)

Publication Number Publication Date
CN110795098A CN110795098A (en) 2020-02-14
CN110795098B true CN110795098B (en) 2022-11-11

Family

ID=69425984

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810872877.8A Active CN110795098B (en) 2018-08-02 2018-08-02 Method and related device for acquiring data

Country Status (1)

Country Link
CN (1) CN110795098B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105528219A (en) * 2016-01-29 2016-04-27 浪潮电子信息产业股份有限公司 Dynamic packaging method for response under REST style framework
CN107861728A (en) * 2017-10-25 2018-03-30 深圳四方精创资讯股份有限公司 Method from traditional program language to modern procedures language conversion and its system for
CN108334314A (en) * 2018-01-08 2018-07-27 武汉斗鱼网络科技有限公司 Automatic conversion object method, storage medium, electronic equipment and system in modularization

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105528219A (en) * 2016-01-29 2016-04-27 浪潮电子信息产业股份有限公司 Dynamic packaging method for response under REST style framework
CN107861728A (en) * 2017-10-25 2018-03-30 深圳四方精创资讯股份有限公司 Method from traditional program language to modern procedures language conversion and its system for
CN108334314A (en) * 2018-01-08 2018-07-27 武汉斗鱼网络科技有限公司 Automatic conversion object method, storage medium, electronic equipment and system in modularization

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
How to convert javabean to post param string?;Ying Yi;《https://stackoverflow.com/questions/39145419/how-to-convert》;20160825;第1-4页 *
javaBean与Map<String,Object>互转;人,总要有点追求的;《https://www.cnblogs.com/zhilu-doc/p/7078279.html》;20170625;第1-5页 *
Java算法JSON Bean相互转化及JSON生成实体类;周文凯;《https://blog.csdn.net/xuehuayous/article/details/50495677》;20160111;第1-10页 *

Also Published As

Publication number Publication date
CN110795098A (en) 2020-02-14

Similar Documents

Publication Publication Date Title
CN110007902A (en) The method and device of business processing flow configuration
WO2017165249A1 (en) Converting visual diagrams into code
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
CN111679979B (en) Destructive testing method and device
CN104866764B (en) A kind of Android phone malware detection method based on object reference figure
CN109343968B (en) Method and related device for acquiring data
CN110659905A (en) Transaction verification method, device, terminal equipment and storage medium
CN111078573A (en) Test message generation method and device
CN110598419B (en) Block chain client vulnerability mining method, device, equipment and storage medium
CN113923268B (en) Resolution method, device and storage medium for multi-version communication protocol
CN105824647A (en) Form page generating method and device
CN110795098B (en) Method and related device for acquiring data
CN110795169B (en) Method and related device for acquiring data
CN110795168B (en) Method for acquiring data and related device
CN117370203A (en) Automatic test method, system, electronic equipment and storage medium
CN117234520A (en) Prefabrication generation method, equipment and medium based on Unity
CN116821119A (en) Method, device and server for generating message analysis code
CN117950669A (en) Hot patch generation method and device, electronic equipment and storage medium
CN109426720B (en) Interface parameter verification method and related device
CN111638905A (en) Version number generation method and device, electronic equipment and readable storage medium
CN108491190A (en) Similar integral structural information acquisition methods, device and electronic equipment
CN113792247B (en) Method, apparatus, device and medium for generating functional flow chart based on code characteristics
CN115250231B (en) Application configuration method and device
CN113590134B (en) Project generation method and device

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