...I'll show myself out.
The Big Programming Thread - Page 598
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
Arnstein
Norway3381 Posts
...I'll show myself out. | ||
Blisse
Canada3710 Posts
On March 02 2015 20:47 Manit0u wrote: Well, the length variable is deceiving in this case because if length = 12 the generated password will have 16 characters... excellent time to use --I vs I-- here! | ||
Gowerly
United Kingdom916 Posts
Also, you probably want
Also
as you don't qualify the items that you are pushing into your list (as the list is a vector of characters anyway). | ||
Manit0u
Poland17202 Posts
Nono, post-decrement is exactly what I needed. What had to be changed was:
It seems that at some previous point the method was only generating 3 characters per iteration. It was later changed to generate 4 characters but someone forgot to change the number of iterations. Took me a while to get a hold of person who wrote it in the first place and get him to recall how and why did he did it this way... I've also made it convert division to integer since abs can be float and it could get silly (as in endless loop blowing out the stack) if someone wanted to generate an odd-length password. | ||
Blisse
Canada3710 Posts
On March 02 2015 21:18 Manit0u wrote: Nono, post-decrement is exactly what I needed. What had to be changed was:
It seems that at some previous point the method was only generating 3 characters per iteration. It was later changed to generate 4 characters but someone forgot to change the number of iterations. Took me a while to get a hold of person who wrote it in the first place and get him to recall how and why did he did it this way... I've also made it convert division to integer since abs can be float and it could get silly (as in endless loop blowing out the stack) if someone wanted to generate an odd-length password. whoops I was too excited to apply our new knowledge of post and pre increment decrement operators! 4 is right, 3 is wrong o: I feel like there's a much better way of doing this though lol | ||
Manit0u
Poland17202 Posts
On March 02 2015 21:26 Blisse wrote: whoops I was too excited to apply our new knowledge of post and pre increment decrement operators! 4 is right, 3 is wrong o: I feel like there's a much better way of doing this though lol Yeah, but this isn't my priority. Just "boyscouted" it while fixing something else entirely ![]() I still couldn't stand it and now this method looks like that (and returns proper length):
| ||
iaretehnoob
Sweden741 Posts
On March 02 2015 22:50 Manit0u wrote: Yeah, but this isn't my priority. Just "boyscouted" it while fixing something else entirely ![]() I still couldn't stand it and now this method looks like that (and returns proper length): What if someone wants an odd-length password? | ||
Manit0u
Poland17202 Posts
On March 02 2015 22:55 iaretehnoob wrote: What if someone wants an odd-length password? He'll get a password one character shorter. Not my problem really, I only made the code easier to understand, a bit more efficient (one loop instead of four), a bit more elegant, a bit more in line with what was originally intended and a bit safer (no more floats in loop conditions). Wasn't my job to create the algorithm or update it. | ||
sabas123
Netherlands3122 Posts
here is a good blog about game programming for the people who missed it. http://www.teamliquid.net/forum/general/382368-game-programming-primer#h.z3ke7fjrib1n | ||
netherh
United Kingdom333 Posts
On March 03 2015 04:15 sabas123 wrote: I recently saw a few posts on gamedev about entity based architecture in c++. I was wondering how I could make a custom component and then attach it to my entity. I would assume that the base enitity would just be a long int ref: http://gamedev.stackexchange.com/questions/31473/role-of-systems-in-entity-systems-architecture/31491#31491 I don't think that post actually describes the ideas involved in an entity system at all. It just describes one very specific approach. (What follows is a segue into my own theories, and may not be relevant / helpful, sorry about that). >.> I think the whole thing comes down to balancing lookup, iteration and sorting. If you use the heap for entities and (more importantly) components, you automatically get persistent handles (pointers!) that you can use for the lifetime of the object, and no lookup cost. This is really, really nice. It's something you shouldn't give up unless you have a really good reason. The downside of this is that it might be slow if you want to iterate over a whole bunch of the same component type: you're jumping all over the place in memory. However, this isn't an issue 99.99% of the time. The solution to this problem is to store your objects in contiguous memory (i.e. a vector / array). Your choices then become (from some notes I made a while ago):
Of these, the intrusive ID version is probably the best, but still: If speed is really an issue (it isn't), you're almost certainly better off refactoring the offending components into pure data stored in an appropriate aggregate component, rather than changing the component system itself. So here's a bunch of pseudo-code with what I'd basically do:
The type_index stuff is kind of a pain. You could restrict your objects to only one component of each type, but I don't think it's really necessary. You could perhaps also store components in a map or multi map, and remove the need for the GetType function. The main thing I see wrong with the post you linked at the start is that at some point you're going to want to write actual gameplay logic. For example... "an object has collided with this one -> check if it's the player, if so play an explosion sound, damage the player, apply a force to push them away". This requires access to a whole bunch of components or systems. That article says that components are basically just data, and can't interact at all, implying that you'll have to create a new system for almost everything. The components are also so fine grained (separate position and velocity!!) that I suspect you'll quickly become mired in a mess of combination problems and inter-dependencies masked by putting everything in yet another system. But anyway... to answer your question: I have no idea! I thought about it for a bit. I imagine you'd want an enum with all your bitmasks e.g.:
The entity could then contain a long unsigned , and you could do something like "entityMask |= PhysicsComponent;" when you add a component. But that's going to be a pain in the arse to maintain. You're also probably going to want each component type to have a GetType() function (similar to my own example) that returns the relevant mask type. This is already more irritating to maintain than my example above. You could try some weird automatic type registration, but that's waaay more complicated. Then you have the problem of where you store components. You'll end up doing basically what I did above, anyway. I don't see what you gain from systems looking for relevant components, apart from more complication. TLDR; Go back to that article, and tell the author to show some code or GTFO (but perhaps more politely). | ||
Vorenius
Denmark1979 Posts
I have a linked list based stack that I push and pop a bunch of numbers to, but the requirements then asks that they are printed out in the order they are added. So I googled for a function to reverse it found this here. void stack_reverse(struct node **top, struct node **top_next) No here's what I would think happens (excuse my paint): + Show Spoiler [before] + + Show Spoiler [What I would think would happen] + + Show Spoiler [what actually happens] + So basicly (*top_next)->ptr = (*top); makes the pointer point "in the other direction" (if that makes sense), but I can't see how the previous top (that becomes the bottom) is set to null. But when I run my code, that's what seem to happen. So basicly it IS working but I thought it shouldn't. For instance this loop where I print the stack out terminates, so at some point it does reach a null pointer:
Can someone explain how the '1'node->ptr gets set to null? | ||
Blitzkrieg0
United States13132 Posts
If the function ended up like "what you think" then you wouldn't be able to tell when the list ends and you'd have an infinite loop. | ||
Blisse
Canada3710 Posts
Don't re-use temporary variables Zero out pointers everytime a variable is initialized Name things well Reuse small pieces of code that are 100% guaranteed to work Avoid recursion if possible If your code isn't easily readable it'll probably have a bug If your algorithm is complex and not concise it'll probably have a bug | ||
Khalum
Austria831 Posts
| ||
BByte
Finland49 Posts
On March 03 2015 09:56 Blisse wrote: Tips for C data structures and methods.. Don't re-use temporary variables Zero out pointers everytime a variable is initialized Name things well Reuse small pieces of code that are 100% guaranteed to work Avoid recursion if possible If your code isn't easily readable it'll probably have a bug If your algorithm is complex and not concise it'll probably have a bug These are excellent tips for pretty much any language. Of course not every language has pointers, and extensive recursion use is fine in some languages, but the other points stand for every programming environment I can think of. | ||
Blisse
Canada3710 Posts
| ||
Manit0u
Poland17202 Posts
On March 02 2015 22:55 iaretehnoob wrote: What if someone wants an odd-length password? I just couldn't let it go...
| ||
Nesserev
Belgium2760 Posts
| ||
sabas123
Netherlands3122 Posts
On March 03 2015 08:11 netherh wrote:
this would be something like?
where <class T, class args> would be the class I want to add and the argument so of the constructor of that class? | ||
FFGenerations
7088 Posts
anyway , again i am trying to receive a response from a 3rd party API, put the response into an object , then print the object to screen so i can verify it (actually you can verify using breakline i bet but again thats fucking around for ages hoping something works and not getting anywhere) so this is what i have so far, and i have 1 (maybe) missing line that might make it work ......fingers crossed... Ann.java class that stores the xml data received from the 3rd party api. this was generated by using JAXB wizard on XSD scheme of a sample XML (2500 lines long ...i just paste some of it coz it wont let me paste 2500 lines lol) + Show Spoiler [(super long + truncated)] + // Generated on: 2015.03.03 at 05:12:35 PM GMT // package generated; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.xml.bind.JAXBElement; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementRef; import javax.xml.bind.annotation.XmlMixed; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlSchemaType; import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.XmlValue; import javax.xml.datatype.XMLGregorianCalendar; /** * <p>Java class for anonymous complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * <complexType> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="anime"> * <complexType> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="info" maxOccurs="unbounded" minOccurs="0"> * <complexType> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="img" minOccurs="0"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="src" type="{http://www.w3.org/2001/XMLSchema}anyURI" /> * <attribute name="width" type="{http://www.w3.org/2001/XMLSchema}short" /> * <attribute name="height" type="{http://www.w3.org/2001/XMLSchema}short" /> * </extension> * </simpleContent> * </complexType> * </element> * </sequence> * <attribute name="gid" type="{http://www.w3.org/2001/XMLSchema}long" /> * <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" /> * <attribute name="src" type="{http://www.w3.org/2001/XMLSchema}anyURI" /> * <attribute name="width" type="{http://www.w3.org/2001/XMLSchema}short" /> * <attribute name="height" type="{http://www.w3.org/2001/XMLSchema}short" /> * <attribute name="lang" type="{http://www.w3.org/2001/XMLSchema}string" /> * <attribute name="href" type="{http://www.w3.org/2001/XMLSchema}anyURI" /> * </restriction> * </complexContent> * </complexType> * </element> * <element name="ratings"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="nb_votes" type="{http://www.w3.org/2001/XMLSchema}short" /> * <attribute name="weighted_score" type="{http://www.w3.org/2001/XMLSchema}float" /> * <attribute name="bayesian_score" type="{http://www.w3.org/2001/XMLSchema}float" /> * </extension> * </simpleContent> * </complexType> * </element> * <element name="episode" maxOccurs="unbounded" minOccurs="0"> * <complexType> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="title"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="gid" type="{http://www.w3.org/2001/XMLSchema}long" /> * <attribute name="lang" type="{http://www.w3.org/2001/XMLSchema}string" /> * </extension> * </simpleContent> * </complexType> * </element> * </sequence> * <attribute name="num" type="{http://www.w3.org/2001/XMLSchema}byte" /> * </restriction> * </complexContent> * </complexType> * </element> * <element name="review" maxOccurs="unbounded" minOccurs="0"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="href" type="{http://www.w3.org/2001/XMLSchema}anyURI" /> * </extension> * </simpleContent> * </complexType> * </element> * <element name="release" maxOccurs="unbounded" minOccurs="0"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="date" type="{http://www.w3.org/2001/XMLSchema}date" /> * <attribute name="href" type="{http://www.w3.org/2001/XMLSchema}anyURI" /> * </extension> * </simpleContent> * </complexType> * </element> * <element name="news" maxOccurs="unbounded" minOccurs="0"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="datetime" type="{http://www.w3.org/2001/XMLSchema}dateTime" /> * <attribute name="href" type="{http://www.w3.org/2001/XMLSchema}anyURI" /> * </extension> * </simpleContent> * </complexType> * </element> * <element name="staff" maxOccurs="unbounded" minOccurs="0"> * <complexType> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="task" type="{http://www.w3.org/2001/XMLSchema}string"/> * <element name="person"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}int" /> * </extension> * </simpleContent> * </complexType> * </element> * </sequence> * <attribute name="gid" type="{http://www.w3.org/2001/XMLSchema}long" /> * </restriction> * </complexContent> * </complexType> * </element> * <element name="cast" maxOccurs="unbounded" minOccurs="0"> * <complexType> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="role" type="{http://www.w3.org/2001/XMLSchema}string"/> * <element name="person"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}int" /> * </extension> * </simpleContent> * </complexType> * </element> * </sequence> * <attribute name="gid" type="{http://www.w3.org/2001/XMLSchema}long" /> * <attribute name="lang" type="{http://www.w3.org/2001/XMLSchema}string" /> * </restriction> * </complexContent> * </complexType> * </element> * <element name="credit" maxOccurs="unbounded" minOccurs="0"> * <complexType> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="task" type="{http://www.w3.org/2001/XMLSchema}string"/> * <element name="company"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}short" /> * </extension> * </simpleContent> * </complexType> * </element> * </sequence> * <attribute name="gid" type="{http://www.w3.org/2001/XMLSchema}long" /> * </restriction> * </complexContent> * </complexType> * </element> * </sequence> * <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}short" /> * <attribute name="gid" type="{http://www.w3.org/2001/XMLSchema}int" /> * <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" /> * <attribute name="name" type="{http://www.w3.org/2001/XMLSchema}string" /> * <attribute name="precision" type="{http://www.w3.org/2001/XMLSchema}string" /> * <attribute name="generated-on" type="{http://www.w3.org/2001/XMLSchema}dateTime" /> * </restriction> * </complexContent> * </complexType> * </element> * </sequence> * </restriction> * </complexContent> * </complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "anime" }) @XmlRootElement(name = "ann") public class Ann { @XmlElement(required = true) protected Ann.Anime anime; /** * Gets the value of the anime property. * * @return * possible object is * {@link Ann.Anime } * */ public Ann.Anime getAnime() { return anime; } /** * Sets the value of the anime property. * * @param value * allowed object is * {@link Ann.Anime } * */ public void setAnime(Ann.Anime value) { this.anime = value; } /** * <p>Java class for anonymous complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * <complexType> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="info" maxOccurs="unbounded" minOccurs="0"> * <complexType> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="img" minOccurs="0"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="src" type="{http://www.w3.org/2001/XMLSchema}anyURI" /> * <attribute name="width" type="{http://www.w3.org/2001/XMLSchema}short" /> * <attribute name="height" type="{http://www.w3.org/2001/XMLSchema}short" /> * </extension> * </simpleContent> * </complexType> * </element> * </sequence> * <attribute name="gid" type="{http://www.w3.org/2001/XMLSchema}long" /> * <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" /> * <attribute name="src" type="{http://www.w3.org/2001/XMLSchema}anyURI" /> * <attribute name="width" type="{http://www.w3.org/2001/XMLSchema}short" /> * <attribute name="height" type="{http://www.w3.org/2001/XMLSchema}short" /> * <attribute name="lang" type="{http://www.w3.org/2001/XMLSchema}string" /> * <attribute name="href" type="{http://www.w3.org/2001/XMLSchema}anyURI" /> * </restriction> * </complexContent> * </complexType> * </element> * <element name="ratings"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="nb_votes" type="{http://www.w3.org/2001/XMLSchema}short" /> * <attribute name="weighted_score" type="{http://www.w3.org/2001/XMLSchema}float" /> * <attribute name="bayesian_score" type="{http://www.w3.org/2001/XMLSchema}float" /> * </extension> * </simpleContent> * </complexType> * </element> * <element name="episode" maxOccurs="unbounded" minOccurs="0"> * <complexType> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="title"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="gid" type="{http://www.w3.org/2001/XMLSchema}long" /> * <attribute name="lang" type="{http://www.w3.org/2001/XMLSchema}string" /> * </extension> * </simpleContent> * </complexType> * </element> * </sequence> * <attribute name="num" type="{http://www.w3.org/2001/XMLSchema}byte" /> * </restriction> * </complexContent> * </complexType> * </element> * <element name="review" maxOccurs="unbounded" minOccurs="0"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="href" type="{http://www.w3.org/2001/XMLSchema}anyURI" /> * </extension> * </simpleContent> * </complexType> * </element> * <element name="release" maxOccurs="unbounded" minOccurs="0"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="date" type="{http://www.w3.org/2001/XMLSchema}date" /> * <attribute name="href" type="{http://www.w3.org/2001/XMLSchema}anyURI" /> * </extension> * </simpleContent> * </complexType> * </element> * <element name="news" maxOccurs="unbounded" minOccurs="0"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="datetime" type="{http://www.w3.org/2001/XMLSchema}dateTime" /> * <attribute name="href" type="{http://www.w3.org/2001/XMLSchema}anyURI" /> * </extension> * </simpleContent> * </complexType> * </element> * <element name="staff" maxOccurs="unbounded" minOccurs="0"> * <complexType> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="task" type="{http://www.w3.org/2001/XMLSchema}string"/> * <element name="person"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}int" /> * </extension> * </simpleContent> * </complexType> * </element> * </sequence> * <attribute name="gid" type="{http://www.w3.org/2001/XMLSchema}long" /> * </restriction> * </complexContent> * </complexType> * </element> * <element name="cast" maxOccurs="unbounded" minOccurs="0"> * <complexType> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="role" type="{http://www.w3.org/2001/XMLSchema}string"/> * <element name="person"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}int" /> * </extension> * </simpleContent> * </complexType> * </element> * </sequence> * <attribute name="gid" type="{http://www.w3.org/2001/XMLSchema}long" /> * <attribute name="lang" type="{http://www.w3.org/2001/XMLSchema}string" /> * </restriction> * </complexContent> * </complexType> * </element> * <element name="credit" maxOccurs="unbounded" minOccurs="0"> * <complexType> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="task" type="{http://www.w3.org/2001/XMLSchema}string"/> * <element name="company"> * <complexType> * <simpleContent> * <extension base="<http://www.w3.org/2001/XMLSchema>string"> * <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}short" /> * </extension> * </simpleContent> * </complexType> * </element> * </sequence> * <attribute name="gid" type="{http://www.w3.org/2001/XMLSchema}long" /> * </restriction> * </complexContent> * </complexType> * </element> * </sequence> * <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}short" /> * <attribute name="gid" type="{http://www.w3.org/2001/XMLSchema}int" /> * <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" /> * <attribute name="name" type="{http://www.w3.org/2001/XMLSchema}string" /> * <attribute name="precision" type="{http://www.w3.org/2001/XMLSchema}string" /> * <attribute name="generated-on" type="{http://www.w3.org/2001/XMLSchema}dateTime" /> * </restriction> * </complexContent> * </complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "info", "ratings", "episode", "review", "release", "news", "staff", "cast", "credit" }) public static class Anime { protected List<Ann.Anime.Info> info; @XmlElement(required = true) protected Ann.Anime.Ratings ratings; protected List<Ann.Anime.Episode> episode; protected List<Ann.Anime.Review> review; protected List<Ann.Anime.Release> release; protected List<Ann.Anime.News> news; protected List<Ann.Anime.Staff> staff; protected List<Ann.Anime.Cast> cast; protected List<Ann.Anime.Credit> credit; @XmlAttribute(name = "id") protected Short id; @XmlAttribute(name = "gid") protected Integer gid; @XmlAttribute(name = "type") protected String type; @XmlAttribute(name = "name") protected String name; @XmlAttribute(name = "precision") protected String precision; @XmlAttribute(name = "generated-on") @XmlSchemaType(name = "dateTime") protected XMLGregorianCalendar generatedOn; /** * Gets the value of the info property. * * <p> * This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a <CODE>set</CODE> method for the info property. * * <p> * For example, to add a new item, do as follows: * <pre> * getInfo().add(newItem); * </pre> * * * <p> * Objects of the following type(s) are allowed in the list * {@link Ann.Anime.Info } * * */ public List<Ann.Anime.Info> getInfo() { if (info == null) { info = new ArrayList<Ann.Anime.Info>(); } ObjectFactory.java , this was generated alongside the Ann class ... not sure what it does, maybe i need to use it or maybe it was used by the system in generating the Ann and i dont need it anymore..... or maybe its used automatically in processing XML data to put it into the Ann class, in which case i DO need to use it somewhere (unless its used super-automatically) + Show Spoiler + // // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.5-2 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> // Any modifications to this file will be lost upon recompilation of the source schema. // Generated on: 2015.03.03 at 05:12:35 PM GMT // package generated; import javax.xml.bind.JAXBElement; import javax.xml.bind.annotation.XmlElementDecl; import javax.xml.bind.annotation.XmlRegistry; import javax.xml.namespace.QName; /** * This object contains factory methods for each * Java content interface and Java element interface * generated in the generated package. * <p>An ObjectFactory allows you to programatically * construct new instances of the Java representation * for XML content. The Java representation of XML * content can consist of schema derived interfaces * and classes representing the binding of schema * type definitions, element declarations and model * groups. Factory methods for each of these are * provided in this class. * */ @XmlRegistry public class ObjectFactory { private final static QName _AnnAnimeInfoImg_QNAME = new QName("", "img"); /** * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: generated * */ public ObjectFactory() { } /** * Create an instance of {@link Ann } * */ public Ann createAnn() { return new Ann(); } /** * Create an instance of {@link Ann.Anime } * */ public Ann.Anime createAnnAnime() { return new Ann.Anime(); } /** * Create an instance of {@link Ann.Anime.Credit } * */ public Ann.Anime.Credit createAnnAnimeCredit() { return new Ann.Anime.Credit(); } /** * Create an instance of {@link Ann.Anime.Cast } * */ public Ann.Anime.Cast createAnnAnimeCast() { return new Ann.Anime.Cast(); } /** * Create an instance of {@link Ann.Anime.Staff } * */ public Ann.Anime.Staff createAnnAnimeStaff() { return new Ann.Anime.Staff(); } /** * Create an instance of {@link Ann.Anime.Episode } * */ public Ann.Anime.Episode createAnnAnimeEpisode() { return new Ann.Anime.Episode(); } /** * Create an instance of {@link Ann.Anime.Info } * */ public Ann.Anime.Info createAnnAnimeInfo() { return new Ann.Anime.Info(); } /** * Create an instance of {@link Ann.Anime.Ratings } * */ public Ann.Anime.Ratings createAnnAnimeRatings() { return new Ann.Anime.Ratings(); } /** * Create an instance of {@link Ann.Anime.Review } * */ public Ann.Anime.Review createAnnAnimeReview() { return new Ann.Anime.Review(); } /** * Create an instance of {@link Ann.Anime.Release } * */ public Ann.Anime.Release createAnnAnimeRelease() { return new Ann.Anime.Release(); } /** * Create an instance of {@link Ann.Anime.News } * */ public Ann.Anime.News createAnnAnimeNews() { return new Ann.Anime.News(); } /** * Create an instance of {@link Ann.Anime.Credit.Company } * */ public Ann.Anime.Credit.Company createAnnAnimeCreditCompany() { return new Ann.Anime.Credit.Company(); } /** * Create an instance of {@link Ann.Anime.Cast.Person } * */ public Ann.Anime.Cast.Person createAnnAnimeCastPerson() { return new Ann.Anime.Cast.Person(); } /** * Create an instance of {@link Ann.Anime.Staff.Person } * */ public Ann.Anime.Staff.Person createAnnAnimeStaffPerson() { return new Ann.Anime.Staff.Person(); } /** * Create an instance of {@link Ann.Anime.Episode.Title } * */ public Ann.Anime.Episode.Title createAnnAnimeEpisodeTitle() { return new Ann.Anime.Episode.Title(); } /** * Create an instance of {@link Ann.Anime.Info.Img } * */ public Ann.Anime.Info.Img createAnnAnimeInfoImg() { return new Ann.Anime.Info.Img(); } /** * Create an instance of {@link JAXBElement }{@code <}{@link Ann.Anime.Info.Img }{@code >}} * */ @XmlElementDecl(namespace = "", name = "img", scope = Ann.Anime.Info.class) public JAXBElement<Ann.Anime.Info.Img> createAnnAnimeInfoImg(Ann.Anime.Info.Img value) { return new JAXBElement<Ann.Anime.Info.Img>(_AnnAnimeInfoImg_QNAME, Ann.Anime.Info.Img.class, Ann.Anime.Info.class, value); } } getservice.java, this gets the xml file from animenewsnetwork , it works in that you can print the response to a string but i dont know if it successfully parses the response into the Ann class like i have it right now. i think i should run it with a breakpoint and see if anything comes up there...... the thing is, i cant just "run" that file coz it says there's no Main file, so i went next to make a main file + Show Spoiler + /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package javaapplication4; import generated.Ann; import javax.annotation.PostConstruct; import javax.enterprise.context.ApplicationScoped; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; /** * * @author J */ @ApplicationScoped public class getservice { private Client client; private WebTarget target; @PostConstruct protected void init() { client = ClientBuilder.newClient(); //target = client.target("http://www.omdbapi.com"); target = client.target("http://cdn.animenewsnetwork.com/encyclopedia/api.xml"); } public Ann fetchMovie() { //return target.queryParam("anime", "4658") return target.queryParam("anime", "4658") .request(MediaType.TEXT_HTML) .header("Content-type", "text/html")//application_json or text_html or xml .get(Ann.class); } JavaAPplication4.java , ....i went to make this Main so it would run, i guess i dont need it if i can wrap the service in a Main function but im not sure if that will just tell me to fuck off, ill go try it right now. in the meantime, this is where i possibly want to call my service and print a result...... you can see the missing line here which doesnt do anything: String output = fetchMovie(Ann ann).getName(); + Show Spoiler + package javaapplication4; import generated.Ann; public class JavaApplication4 { public static void main(String[] args) { try { String output = fetchMovie(Ann ann).getName(); System.out.println(output); } catch (Exception e) { e.printStackTrace(); } } } thanksXD | ||
| ||