Search Results

Search found 53 results on 3 pages for 'nazgulled'.

Page 2/3 | < Previous Page | 1 2 3  | Next Page >

  • Question about the Cloneable interface and the exception that should be thrown

    - by Nazgulled
    Hi, The Java documentation says: A class implements the Cloneable interface to indicate to the Object.clone() method that it is legal for that method to make a field-for-field copy of instances of that class. Invoking Object's clone method on an instance that does not implement the Cloneable interface results in the exception CloneNotSupportedException being thrown. By convention, classes that implement this interface should override Object.clone (which is protected) with a public method. See Object.clone() for details on overriding this method. Note that this interface does not contain the clone method. Therefore, it is not possible to clone an object merely by virtue of the fact that it implements this interface. Even if the clone method is invoked reflectively, there is no guarantee that it will succeed. And I have this UserProfile class: public class UserProfile implements Cloneable { private String name; private int ssn; private String address; public UserProfile(String name, int ssn, String address) { this.name = name; this.ssn = ssn; this.address = address; } public UserProfile(UserProfile user) { this.name = user.getName(); this.ssn = user.getSSN(); this.address = user.getAddress(); } // get methods here... @Override public UserProfile clone() { return new UserProfile(this); } } And for testing porpuses, I do this in main(): UserProfile up1 = new UserProfile("User", 123, "Street"); UserProfile up2 = up1.clone(); So far, no problems compiling/running. Now, per my understanding of the documentation, removing implements Cloneable from the UserProfile class should throw an exception in up1.clone() call, but it doesn't. I've read around here that the Cloneable interface is broken but I don't really know what that means. Am I missing something?

    Read the article

  • Block element, horizontal center aligned and minimum width possible

    - by Nazgulled
    Hi, I'm trying to have this block element to be horizontally aligned in the middle but at the same time I would like the width to be the minimum possible for the contents inside. But I don't think it's possible or I'm not able to do it myself... a#button-link { background: url("images/button-link.png") no-repeat scroll center left; margin: 12px auto 0 auto; display: block; width: 125px; height: 32px; line-height: 32px; padding-left: 35px; font-weight: bold; } This is my current code... The idea behind this is that the text for that tag could be slightly bigger or smaller depending on the user language and how much characters the same sentence has for that specific user's language. There's no way I can control but I still would like to have this element horizontally aligned to center. Is this possible with CSS?

    Read the article

  • How to optimize Dijkstra algorithm for a single shortest path between 2 nodes?

    - by Nazgulled
    Hi, I was trying to understand this implementation in C of the Dijkstra algorithm and at the same time modify it so that only the shortest path between 2 specific nodes (source and destination) is found. However, I don't know exactly what do to. The way I see it, there's nothing much to do, I can't seem to change d[] or prev[] cause those arrays aggregate some important data for the shortest path calculation. The only thing I can think of is stopping the algorithm when the path is found, that is, break the cycle when mini = destination when it's being marked as visited. Is there anything else I could do to make it better or is that enough? P.S: I just noticed that the for loops start at 1 until <=, why can't it start at 0 and go until <?

    Read the article

  • How to colorize section headings in LaTeX like this?

    - by Nazgulled
    Hi, Accidently I created this nice colored effect on my LaTeX TOC: http://i43.tinypic.com/o5aptl.png Which I like and want to keep, I created this effect like this: \definecolor{Section1}{rgb}{0.09,0.21,0.36} \section{\color{Section1}Introdução} However, as you can see on the TOC sidebar, there was a nasty side effect. I tried to fix it like this: \section[Introdução]{\color{Section1}Introdução} But didn't work, the sidebar TOC was fixed but on the TOC list, the blue color was gone and was now red instead (default for clickable TOC heading links) I also tried: {\color{Section1}\section{Introdução}} But the effect was the same, fixed TOC but no color on the TOC list. Any suggestions?

    Read the article

  • Problem measuring N times the execution time of a code block

    - by Nazgulled
    EDIT: I just found my problem after writing this long post explaining every little detail... If someone can give me a good answer on what I'm doing wrong and how can I get the execution time in seconds (using a float with 5 decimal places or so), I'll mark that as accepted. Hint: The problem was on how I interpreted the clock_getttime() man page. Hi, Let's say I have a function named myOperation that I need to measure the execution time of. To measure it, I'm using clock_gettime() as it was recommend here in one of the comments. My teacher recommends us to measure it N times so we can get an average, standard deviation and median for the final report. He also recommends us to execute myOperation M times instead of just one. If myOperation is a very fast operation, measuring it M times allow us to get a sense of the "real time" it takes; cause the clock being used might not have the required precision to measure such operation. So, execution myOperation only one time or M times really depends if the operation itself takes long enough for the clock precision we are using. I'm having trouble dealing with that M times execution. Increasing M decreases (a lot) the final average value. Which doesn't make sense to me. It's like this, on average you take 3 to 5 seconds to travel from point A to B. But then you go from A to B and back to A 5 times (which makes it 10 times, cause A to B is the same as B to A) and you measure that. Than you divide by 10, the average you get is supposed to be the same average you take traveling from point A to B, which is 3 to 5 seconds. This is what I want my code to do, but it's not working. If I keep increasing the number of times I go from A to B and back A, the average will be lower and lower each time, it makes no sense to me. Enough theory, here's my code: #include <stdio.h> #include <time.h> #define MEASUREMENTS 1 #define OPERATIONS 1 typedef struct timespec TimeClock; TimeClock diffTimeClock(TimeClock start, TimeClock end) { TimeClock aux; if((end.tv_nsec - start.tv_nsec) < 0) { aux.tv_sec = end.tv_sec - start.tv_sec - 1; aux.tv_nsec = 1E9 + end.tv_nsec - start.tv_nsec; } else { aux.tv_sec = end.tv_sec - start.tv_sec; aux.tv_nsec = end.tv_nsec - start.tv_nsec; } return aux; } int main(void) { TimeClock sTime, eTime, dTime; int i, j; for(i = 0; i < MEASUREMENTS; i++) { printf(" » MEASURE %02d\n", i+1); clock_gettime(CLOCK_REALTIME, &sTime); for(j = 0; j < OPERATIONS; j++) { myOperation(); } clock_gettime(CLOCK_REALTIME, &eTime); dTime = diffTimeClock(sTime, eTime); printf(" - NSEC (TOTAL): %ld\n", dTime.tv_nsec); printf(" - NSEC (OP): %ld\n\n", dTime.tv_nsec / OPERATIONS); } return 0; } Notes: The above diffTimeClock function is from this blog post. I replaced my real operation with myOperation() because it doesn't make any sense to post my real functions as I would have to post long blocks of code, you can easily code a myOperation() with whatever you like to compile the code if you wish. As you can see, OPERATIONS = 1 and the results are: » MEASURE 01 - NSEC (TOTAL): 27456580 - NSEC (OP): 27456580 For OPERATIONS = 100 the results are: » MEASURE 01 - NSEC (TOTAL): 218929736 - NSEC (OP): 2189297 For OPERATIONS = 1000 the results are: » MEASURE 01 - NSEC (TOTAL): 862834890 - NSEC (OP): 862834 For OPERATIONS = 10000 the results are: » MEASURE 01 - NSEC (TOTAL): 574133641 - NSEC (OP): 57413 Now, I'm not a math wiz, far from it actually, but this doesn't make any sense to me whatsoever. I've already talked about this with a friend that's on this project with me and he also can't understand the differences. I don't understand why the value is getting lower and lower when I increase OPERATIONS. The operation itself should take the same time (on average of course, not the exact same time), no matter how many times I execute it. You could tell me that that actually depends on the operation itself, the data being read and that some data could already be in the cache and bla bla, but I don't think that's the problem. In my case, myOperation is reading 5000 lines of text from an CSV file, separating the values by ; and inserting those values into a data structure. For each iteration, I'm destroying the data structure and initializing it again. Now that I think of it, I also that think that there's a problem measuring time with clock_gettime(), maybe I'm not using it right. I mean, look at the last example, where OPERATIONS = 10000. The total time it took was 574133641ns, which would be roughly 0,5s; that's impossible, it took a couple of minutes as I couldn't stand looking at the screen waiting and went to eat something.

    Read the article

  • How should I change my Graph structure (very slow insertion)?

    - by Nazgulled
    Hi, This program I'm doing is about a social network, which means there are users and their profiles. The profiles structure is UserProfile. Now, there are various possible Graph implementations and I don't think I'm using the best one. I have a Graph structure and inside, there's a pointer to a linked list of type Vertex. Each Vertex element has a value, a pointer to the next Vertex and a pointer to a linked list of type Edge. Each Edge element has a value (so I can define weights and whatever it's needed), a pointer to the next Edge and a pointer to the Vertex owner. I have a 2 sample files with data to process (in CSV style) and insert into the Graph. The first one is the user data (one user per line); the second one is the user relations (for the graph). The first file is quickly inserted into the graph cause I always insert at the head and there's like ~18000 users. The second file takes ages but I still insert the edges at the head. The file has about ~520000 lines of user relations and takes between 13-15mins to insert into the Graph. I made a quick test and reading the data is pretty quickly, instantaneously really. The problem is in the insertion. This problem exists because I have a Graph implemented with linked lists for the vertices. Every time I need to insert a relation, I need to lookup for 2 vertices, so I can link them together. This is the problem... Doing this for ~520000 relations, takes a while. How should I solve this? Solution 1) Some people recommended me to implement the Graph (the vertices part) as an array instead of a linked list. This way I have direct access to every vertex and the insertion is probably going to drop considerably. But, I don't like the idea of allocating an array with [18000] elements. How practically is this? My sample data has ~18000, but what if I need much less or much more? The linked list approach has that flexibility, I can have whatever size I want as long as there's memory for it. But the array doesn't, how am I going to handle such situation? What are your suggestions? Using linked lists is good for space complexity but bad for time complexity. And using an array is good for time complexity but bad for space complexity. Any thoughts about this solution? Solution 2) This project also demands that I have some sort of data structures that allows quick lookup based on a name index and an ID index. For this I decided to use Hash Tables. My tables are implemented with separate chaining as collision resolution and when a load factor of 0.70 is reach, I normally recreate the table. I base the next table size on this http://planetmath.org/encyclopedia/GoodHashTablePrimes.html. Currently, both Hash Tables hold a pointer to the UserProfile instead of duplication the user profile itself. That would be stupid, changing data would require 3 changes and it's really dumb to do it that way. So I just save the pointer to the UserProfile. The same user profile pointer is also saved as value in each Graph Vertex. So, I have 3 data structures, one Graph and two Hash Tables and every single one of them point to the same exact UserProfile. The Graph structure will serve the purpose of finding the shortest path and stuff like that while the Hash Tables serve as quick index by name and ID. What I'm thinking to solve my Graph problem is to, instead of having the Hash Tables value point to the UserProfile, I point it to the corresponding Vertex. It's still a pointer, no more and no less space is used, I just change what I point to. Like this, I can easily and quickly lookup for each Vertex I need and link them together. This will insert the ~520000 relations pretty quickly. I thought of this solution because I already have the Hash Tables and I need to have them, then, why not take advantage of them for indexing the Graph vertices instead of the user profile? It's basically the same thing, I can still access the UserProfile pretty quickly, just go to the Vertex and then to the UserProfile. But, do you see any cons on this second solution against the first one? Or only pros that overpower the pros and cons on the first solution? Other Solution) If you have any other solution, I'm all ears. But please explain the pros and cons of that solution over the previous 2. I really don't have much time to be wasting with this right now, I need to move on with this project, so, if I'm doing to do such a change, I need to understand exactly what to change and if that's really the way to go. Hopefully no one fell asleep reading this and closed the browser, sorry for the big testament. But I really need to decide what to do about this and I really need to make a change. P.S: When answering my proposed solutions, please enumerate them as I did so I know exactly what are you talking about and don't confuse my self more than I already am.

    Read the article

  • Suggestions of the easiest algorithms for some Graph operations

    - by Nazgulled
    Hi, The deadline for this project is closing in very quickly and I don't have much time to deal with what it's left. So, instead of looking for the best (and probably more complicated/time consuming) algorithms, I'm looking for the easiest algorithms to implement a few operations on a Graph structure. The operations I'll need to do is as follows: List all users in the graph network given a distance X List all users in the graph network given a distance X and the type of relation Calculate the shortest path between 2 users on the graph network given a type of relation Calculate the maximum distance between 2 users on the graph network Calculate the most distant connected users on the graph network A few notes about my Graph implementation: The edge node has 2 properties, one is of type char and another int. They represent the type of relation and weight, respectively. The Graph is implemented with linked lists, for both the vertices and edges. I mean, each vertex points to the next one and each vertex also points to the head of a different linked list, the edges for that specific vertex. What I know about what I need to do: I don't know if this is the easiest as I said above, but for the shortest path between 2 users, I believe the Dijkstra algorithm is what people seem to recommend pretty often so I think I'm going with that. I've been searching and searching and I'm finding it hard to implement this algorithm, does anyone know of any tutorial or something easy to understand so I can implement this algorithm myself? If possible, with C source code examples, it would help a lot. I see many examples with math notations but that just confuses me even more. Do you think it would help if I "converted" the graph to an adjacency matrix to represent the links weight and relation type? Would it be easier to perform the algorithm on that instead of the linked lists? I could easily implement a function to do that conversion when needed. I'm saying this because I got the feeling it would be easier after reading a couple of pages about the subject, but I could be wrong. I don't have any ideas about the other 4 operations, suggestions?

    Read the article

  • Really annoying bug with Topmost property in Windows Forms

    - by Nazgulled
    Hi, I have this Windows Forms application where it sits in the notification area. Clicking on the icon brings it up front, clicking it again (or clicking on the app X icon) sends it back. This is the type of app that having the window always on top is important when it's displayed by clicking the icon, but it's optional. Right-clicking the icon brings up a context menu where one can select to enable the "always on top" option or not. When the application first starts up, the app settings are read from an XML file and I'm 99% that this is working as it should, the Topmost properly is properly read (and written). After some time (minutes, hours, days, whatever, I normally hibernate and rarely shutdown) the Topmost stops working. I don't change the option, I don't think anything is changing the option but I click the notification area icon and app is not brought up front. It shows up (it displays on Alt+Tab) but it's on the background, it's not topmost as it should. I bring up the context menu, disable the option (cause it's enabled) and enable it back and it starts to work after that. The app is now topmost. However, it can lose this ability anytime after while. I can't understand why this happens and how this happens. Does anyone have any idea why? If not, any idea how could I try to debug such behavior?

    Read the article

  • How to perform different operations within Observer's update() in Java?

    - by Nazgulled
    I just started playing with Observable, Observer and it's update() method and I can't understand what should I do when different actions call notifyObservers(). I mean, my Observable class has a few different methods that call setChanged() and notifyObservers() in the end. Depending on the called method, some part of the UI (Swing) needs to be updated. However, there is only one update() method implemented in the Observer class. I though of passing something to the notifyObservers() method and then I can check the argument on update() but it doesn't seem feel like a good way to do it. Even if it did, what should I pass? A string with a short description of the action/method? And int, like an action/method code? Something else? What's the best way to handle this situation?

    Read the article

  • Hash Table: Should I increase the element count on collisions?

    - by Nazgulled
    Hi, Right now my hash tables count the number of every element inserted into the hash table. I use this count, with the total hash table size, to calculate the load factor and when it reaches like 70%, I rehash it. I was thinking that maybe I should only count the inserted elements with fills an empty slot instead of all of them. Cause the collision method I'm using is separate chaining. The factor load keeps increasing but if there can be a few collisions leaving lots of empty slots on the hash table. You are probably thinking that if I have that many collisions, maybe I'm not using the best hashing method. But that's not the point, I'm using one of the know hashing algorithms out there, I tested 3 of them on my sample data and selected the one who produced less collisions. My question still remains. Should I keep counting every element inserted, or just the ones that fill an empty slot in the Hash Table?

    Read the article

  • Nested hyperlinks in XHTML 1.1 document

    - by Nazgulled
    Hi, I'm doing a simple widget for WordPress that fetches the most recent tweets from the RSS feed provided by Twitter. This widget parses any link posted on a tweet, it also parses mentions (ie: @username) and trending topics (ie: #nowplaying). For these 3 situations, it creates links pointing to some Twitter feature. For instance: "Hi @UserA, check out the song Foo from FooBar that I'm listening, it's awesome. #nowplaying" And it will parse into this: Hi <a href="http://twitter.com/UserA">@UserA</a>, check out the song Foo from FooBar that I'm listening, it's awesome. <a href="http://twitter.com/#search?q=nowplaying">#nowplaying</a> Now now I need to add a global link to the whole message, like this: <a href="http://twitter.com/UserA/statuses/1234567890"> Hi <a href="http://twitter.com/UserA">@UserA</a>, check out the song Foo from FooBar that I'm listening, it's awesome. <a href="http://twitter.com/#search?q=nowplaying">#nowplaying</a> </a> But this code does not validate and it doesn't work anyways (the browsers don't really seem to know what to do with it). Any suggestions how could I fix this?

    Read the article

  • Question about gets and sets and when to use super classes

    - by Nazgulled
    Hi, I have the following get method: public List<PersonalMessage> getMessagesList() { List<PersonalMessage> newList = new ArrayList<PersonalMessage>(); for(PersonalMessage pMessage : this.listMessages) { newList.add(pMessage.clone()); } return newList; } And you can see that if I need to change the implementation from ArrayList to something else, I can easily do it and I just have to change the initialization of newList and all other code that depends on what getMessageList() returns will still work. Then I have this set method: public void setMessagesList(ArrayList<PersonalMessage> listMessages) { this.listMessages = listMessages; } My question is, should I use List instead of `ArrayList in the method signature? I have decided to use ArrayList because this way I can force the implementation I want, otherwise there could be a mess with different types of lists here and there. But I'm not sure if this is the way to go...

    Read the article

  • How can I partial compare two strings in C?

    - by Nazgulled
    Hi, Let's say I have the following content: Lorem Ipsum is simply dummy text of the printing and typesetting industry. How do I search for dummy or dummy text in that string using C? Is there any easy way to do it or only with strong string manipulation? All I need is to search for it and return a boolean with the result.

    Read the article

  • Google Code + SVN or GitHub + Git

    - by Nazgulled
    Let me start by telling you that I never used anything besides SVN and I'm also a Windows user. I have a couple of simple projects that are open-source, others are on there way when I'm happy enough to release their source code but either way, I was thinking of using Google Code and SVN to share the source code of my projects instead of providing a link to the source on my website. This as always been a pain cause I had to update the binaries and the code every time I released a new version. This would also help me out to have a backup of my code some where instead of just my local machine (I used to have a local Subversion server running). What I want from a service like this is very simple... I just want a place to store my source code that people can download if they want, allows me to control revisions and provide a simple and easy issue system so people can submit bugs and stuff like that. I guess both of them have this. But I don't want to host any binaries in their websites, I want this to be hosted on my website so I can control download statistics with my own scripts, I also don't have the need for wiki pages as I prefer to have all the documentation in my own website. Does anyone of this services provide a way to "disable" features like wiki and downloads and don't show them at all for my project(s)? Now, I'm sure there are lots of pros and cons about using Google Code with SVN and GitHub with Git (of course) but here's what it's important for me on each one and why I like them: Google Code: As with any Google page, the complexity is almost non-existent Everyone (or almost) as a Google account and this is nice if people want to report problems using the issues system GitHub: May (or may not) be a little more complex (not a problem for me though) than Google's pages but... ...has a much prettier interface than Google's service It needs people to be registered on GitHub to post about issues I like the fact that with Git, you have your own revisions locally (can I use TortoiseGit for this or?) Basically that's it, not much I know... What other, most common, pros and cons can you tell me about each site/software? Keep in mind that my projects are simple, I'm probably the only one who will ever develop these projects on these repositories (or maybe not, for now I will)

    Read the article

  • Strange issue with fixed form border styles in Vista

    - by Nazgulled
    My previous post about this issue didn't got too many answers and it was kinda specific and hard to understand. I think I've managed to understand the problem better and I now believe it to be a Vista issue... The problem lies on all types of fixed border styles like FixedDialog, Fixed3D, FixedSingle and FixedToolWindow. It does not happen on the sizable ones. This problem, like I said, it also happens only on Vista. Let's say you have a form with any of the fixed border styles and set the starting location to 0,0. What you want here is for the form to be snapped to the top left corner of the screen. This works just fine if the form border style is one of the sizable options, if it's fixed, well, the form will be a little bit outside of the screen working area both to the left and top. What's more strange about this is that the form location does not change, it sill is 0,0, but a few pixels of the form are still drawn outside of the working screen area. I tested this on XP and it didn't happen, the problem is Vista specific. On XP, the only difference was the border size that change a bit between any of the styles. But the form was always perfectly snapped to position 0,0. If possible, without finding how many pixels are being drawn outside of the working area and then add that to the form location, is there a possible way to fix or workaround this?

    Read the article

  • How and when to log account access login with PHP?

    - by Nazgulled
    I want to implement a basic login system in some PHP app where no cookies will be involved. I mean, the user closes the browser and the login expires, it will remain active during the browser session (or if the user explicitly logs out) otherwise. I want to log all this activity and I'm thinking that every time the user refreshes the page, opens a different link or logs out, I record that time as the last access made by that user, overwriting the previous access log. But my problem is when and how should I insert another record into the database instead of overwriting the last one? Should I just define a timeout and if the last access was made above that timeout, another log should be inserted into the database? Should the session expire too after that timeout? Or is there a better way? Ideally, I would like to log the "log out action" when the browser was closed, but I don't think there's a way to detect that is there? Suggestions?

    Read the article

  • How should I join these 3 SQL queries in Oracle?

    - by Nazgulled
    I have these 3 queries: SELECT title, year, MovieGenres(m.mid) genres, MovieDirectors(m.mid) directors, MovieWriters(m.mid) writers, synopsis, poster_url FROM movies m WHERE m.mid = 1; SELECT AVG(rating) FROM movie_ratings WHERE mid = 1; SELECT COUNT(rating) FROM movie_ratings WHERE mid = 1; And I need to join them into a single query. I was able to do it like this: SELECT title, year, MovieGenres(m.mid) genres, MovieDirectors(m.mid) directors, MovieWriters(m.mid) writers, synopsis, poster_url, AVG(rating) average, COUNT(rating) count FROM movies m INNER JOIN movie_ratings mr ON m.mid = mr.mid WHERE m.mid = 1 GROUP BY title, year, MovieGenres(m.mid), MovieDirectors(m.mid), MovieWriters(m.mid), synopsis, poster_url; But I don't really like that "huge" GROUP BY, is there a simpler way to do it?

    Read the article

  • Any big difference between using contains or loop through a list?

    - by Nazgulled
    Hi, Performance wise, is there really a big difference between using: ArrayList.contains(o) vs foreach|iterator LinkedList.contains(o) vs foreach|iterator HashMap.(containsKey|containsValue) vs foreach|iterator TreeMap.(containsKey|containsValue) vs foreach|iterator Of course, for the foreach|iterator loops, I'll have to explicitly compare the methods and return true or false accordingly. The object I'm comparing is an object where equals() and hashcode() are both properly overridden.

    Read the article

  • How to initialize List<E> in empty class constructor?

    - by Nazgulled
    Hi, The following code obviously doesn't work because List<E> is abstract: public class MyList { private List<E> list; public MyList() { this.list = new List<E>(); } } How can I initialize MyList class with an empty constructor if I need the list variable to be a LinkedList or a ArrayList depending on my needs?

    Read the article

  • Help with abstract class in Java with private variable of type List<E>

    - by Nazgulled
    Hi, It's been two years since I last coded something in Java so my coding skills are bit rusty. I need to save data (an user profile) in different data structures, ArrayList and LinkedList, and they both come from List. I want to avoid code duplication where I can and I also want to follow good Java practices. For that, I'm trying to create an abstract class where the private variables will be of type List<E> and then create 2 sub-classes depending on the type of variable. Thing is, I don't know if I'm doing this correctly, you can take a look at my code: Class: DBList import java.util.List; public abstract class DBList { private List<UserProfile> listName; private List<UserProfile> listSSN; public List<UserProfile> getListName() { return this.listName; } public List<UserProfile> getListSSN() { return this.listSSN; } public void setListName(List<UserProfile> listName) { this.listName = listName; } public void setListSSN(List<UserProfile> listSSN) { this.listSSN = listSSN; } } Class: DBListArray import java.util.ArrayList; public class DBListArray extends DBList { public DBListArray() { super.setListName(new ArrayList<UserProfile>()); super.setListSSN(new ArrayList<UserProfile>()); } public DBListArray(ArrayList<UserProfile> listName, ArrayList<UserProfile> listSSN) { super.setListName(listName); super.setListSSN(listSSN); } public DBListArray(DBListArray dbListArray) { super.setListName(dbListArray.getListName()); super.setListSSN(dbListArray.getListSSN()); } } Class: DBListLinked import java.util.LinkedList; public class DBListLinked extends DBList { public DBListLinked() { super.setListName(new LinkedList<UserProfile>()); super.setListSSN(new LinkedList<UserProfile>()); } public DBListLinked(LinkedList<UserProfile> listName, LinkedList<UserProfile> listSSN) { super.setListName(listName); super.setListSSN(listSSN); } public DBListLinked(DBListLinked dbListLinked) { super.setListName(dbListLinked.getListName()); super.setListSSN(dbListLinked.getListSSN()); } } 1) Does any of this make any sense? What am I doing wrong? Do you have any recommendations? 2) It would make more sense for me to have the constructors in DBList and calling them (with super()) in the subclasses but I can't do that because I can't initialize a variable with new List<E>(). 3) I was thought to do deep copies whenever possible and for that I always override the clone() method of my classes and code it accordingly. But those classes never had any lists, sets or maps on them, they only had strings, ints, floats. How do I do deep copies in this situation?

    Read the article

  • Initial state of autoCreateRowSorter in Swing JTable

    - by Nazgulled
    I have this JTable on my Swing app with the autoCreateRowSorter enabled. My table only has 3 columns, two strings and one int, it works well for all of them when I click the column headers. However, I'm looking for way to do it programatically. I wanted to set the "initial state" for this table. With the Windows look and feel, the column header (when sorted) has a little arrow showing the sort order. But at startup that doesn't show, I have to do one initial click. How can I do that by code?

    Read the article

  • Data persistance with BufferedReader and PrintWriter?

    - by Nazgulled
    I have this simple application with a couple of classes which are all related. There's one, the main one, for which there is only one instance of. I need to save save and load that using a text stream. My instructor requirement is BufferedReader to load the stream and PrintWriter to save it. But is this even possible? To persist a data object/class with a text stream? I know how to do it with and object, using serialization. But I don't see how am I supposed to do it using text streams. Suggestions?

    Read the article

  • What's the purpuse behind wildcards and how are they different from generics?

    - by Nazgulled
    Hi, I never heard about wildcars until a few days ago and after reading my teacher's Java book, I'm still not sure about what's it for and wwhy would I need to use it. Let's say I have a super class Animal and few sub classes like Dog, Cat, Parrot, etc... Now I need to have a list of animals, my first thought would be something like: List<Animal> listAnimals Instead, my colleagues are recommending something like: List<? extends Animal> listAnimals Why should I use wildcards instead of simple generics? Let's say I need to have a get/set method, should I use the former or the later? How are they so different?

    Read the article

  • What's my best approach on this simple hierarchy Java Problem?

    - by Nazgulled
    First, I'm sorry for the question title but I can't think of a better one to describe my problem. Feel free to change it :) Let's say I have this abstract class Box which implements a couple of constructors, methods and whatever on some private variables. Then I have a couple of sub classes like BoxA and BoxB. Both of these implement extra things. Now I have another abstract class Shape and a few sub classes like Square and Circle. For both BoxA and BoxB I need to have a list of Shape objects but I need to make sure that only Square objects go into BoxA's list and only Circle objects go into BoxB's list. For that list (on each box), I need to have a get() and set() method and also a addShape() and removeShape() methods. Another important thing to know is that for each box created, either BoxA or BoxB, each respectively Shape list is exactly the same. Let's say I create a list of Square's named ls and two BoxA objects named boxA1 and boxA2. No matter what, both boxA1 and boxA2 must have the same ls list. This is my idea: public abstract class Box { // private instance variables public Box() { // constructor stuff } // public instance methods } public class BoxA extends Box { // private instance variables private static List<Shape> list; public BoxA() { // constructor stuff } // public instance methods public static List<Square> getList() { List<Square> aux = new ArrayList<Square>(); for(Square s : list.values()) { aux.add(s.clone()); // I know what I'm doing with this clone, don't worry about it } return aux; } public static void setList(List<Square> newList) { list = new ArrayList<Square>(newList); } public static void addShape(Square s) { list.add(s); } public static void removeShape(Square s) { list.remove(list.indexOf(s)); } } As the list needs to be the same for that type of object, I declared as static and all methods that work with that list are also static. Now, for BoxB the class would be almost the same regarding the list stuff. I would only replace Square by Triangle and the problem was solved. So, for each BoxA object created, the list would be only one and the same for each BoxB object created, but a different type of list of course. So, what's my problem you ask? Well, I don't like the code... The getList(), setList(), addShape() and removeShape() methods are basically repeated for BoxA and BoxB, only the type of the objects that the list will hold is different. I can't think of way to do it in the super class Box instead. Doing it statically too, using Shape instead of Square and Triangle, wouldn't work because the list would be only one and I need it to be only one but for each sub class of Box. How could I do this differently and better? P.S: I could not describe my real example because I don't know the correct words in English for the stuff I'm doing, so I just used a box and shapes example, but it's basically the same.

    Read the article

< Previous Page | 1 2 3  | Next Page >