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

Method and related device for acquiring data Download PDF

Info

Publication number
CN110795098A
CN110795098A CN201810872877.8A CN201810872877A CN110795098A CN 110795098 A CN110795098 A CN 110795098A CN 201810872877 A CN201810872877 A CN 201810872877A CN 110795098 A CN110795098 A CN 110795098A
Authority
CN
China
Prior art keywords
function
pkbean
class
mybuilder
data
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
CN201810872877.8A
Other languages
Chinese (zh)
Other versions
CN110795098B (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 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 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 a possible embodiment, the function of setting a set function for the target data in the MyBuilder class includes: the function of the set function is set as follows: public MyBuilder setWidth (intWidth); 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 function to store the information of the width object in the MyBuilder class into a width field of the PKBean object to obtain the PKBean-like parameter object.
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; 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 the type of the value information is converted 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; the setting unit is used for setting a set function and a get function for the target data in the MyBuilder-like, and 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; 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 (intength); 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 function to store the information of the width object in the MyBuilder class into a width field of the PKBean object to obtain the PKBean-like parameter object.
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 (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 the type of the value information is converted into int type.
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;
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. 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. 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 type MyBuilder object by calling the same-width function in a public MyBuilder set width (int width) function, and it should be noted that this represents an internal type MyBuilder class of PKBean, that is, storing the information in the MyBuilder class object. 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 () 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 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。
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 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.
In addition, the embodiment shown in fig. 1 realizes the flow of data conversion, but there is a problem that when there are a plurality of field information width and length in a PKBean-like, the conversion process will automatically convert 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 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 isArgment); public void length (int length, Boolean isrestriction), when designing the above function, a parameter information isrestriction is added in 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 is equal to false, the parameter information does not need to be stored, and the parameter is parameter information which does not need to be transmitted to C + + at the moment, so that the capture processing can be carried out; 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; 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 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. 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 MyBuildersetLength (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 function to store the information of the width object in the MyBuilder class into a width field of the PKBean object to obtain the PKBean-like parameter object.
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; 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 203 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 the type of the value information is converted 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 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.
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 MyBuildersetLength (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 function to store the information of the width object in the MyBuilder class into a width field of the PKBean object to obtain the PKBean-like parameter object.
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; 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 the type of the value information is converted 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 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 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.
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 (intWidth); 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 the structuring function of the PKBean-like object to construct a PKBean object; and calling a PKBean function to store the information of the width object in the MyBuilder class into a width field of the PKBean object to obtain the PKBean-like parameter object.
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; 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 the type of the value information is converted 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 (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;
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.
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 the builder function in the class MyBuilder 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 function to store the information of the width object in the MyBuilder class into a width field of the PKBean object to obtain the PKBean-like parameter object.
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 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.
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 ═ 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 the type of the value information is converted 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;
the setting unit is used for setting a set function and a get function for the target data in the MyBuilder-like, and 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;
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.
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.
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 true CN110795098A (en) 2020-02-14
CN110795098B 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 encapsulation method for response under REST frame
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 encapsulation method for response under REST frame
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
YING YI: "How to convert javabean to post param string?", 《HTTPS://STACKOVERFLOW.COM/QUESTIONS/39145419/HOW-TO-CONVERT》 *
人,总要有点追求的: "javaBean与Map<String,Object>互转", 《HTTPS://WWW.CNBLOGS.COM/ZHILU-DOC/P/7078279.HTML》 *
周文凯: "Java算法JSON Bean相互转化及JSON生成实体类", 《HTTPS://BLOG.CSDN.NET/XUEHUAYOUS/ARTICLE/DETAILS/50495677》 *

Also Published As

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

Similar Documents

Publication Publication Date Title
CN106919509B (en) Client generation method and device and electronic equipment
CN110007902A (en) The method and device of business processing flow configuration
EP3912074B1 (en) Generating a synchronous digital circuit from a source code construct defining a function call
CN108469955B (en) Annotation-based Android injection framework implementation method
CN107704382A (en) Towards Python function call path generating method and system
CN110633200A (en) Method and device for testing intelligent contracts
CN111679979B (en) Destructive testing method and device
CN109343968B (en) Method and related device for acquiring data
CN111343181A (en) Message processing method and system, data pool and computer readable 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
CN111290996A (en) Document format conversion method, device, equipment and readable storage medium
CN110795098B (en) Method and related device for acquiring data
CN117370203A (en) Automatic test method, system, electronic equipment and storage medium
CN110795168B (en) Method for acquiring data and related device
CN110795169B (en) Method and related device for acquiring data
CN110941655A (en) Data format conversion method and device
CN106802805B (en) Application service management method and device suitable for server management
CN117234590B (en) Instruction set generation method, device, medium and equipment
CN113792247B (en) Method, apparatus, device and medium for generating functional flow chart based on code characteristics
CN115250231B (en) Application configuration method and device
CN109189368B (en) Method and framework for constructing rapid development framework based on MVP framework
CN110990050B (en) Model attribute value printing control method, device, medium and equipment
CN113986346A (en) Analysis method and device for Dubbo interface implementation class

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