Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ComptimusPrime
Jan 23, 2006
Computer Transformer

thegasman2000 posted:

I have been given a nice problem to solve and have no idea what I am going to do... I need to us the JustGiving Javascript API to enable functionality to a flash app. Is there a way for me to utilise JS in actionscript 3? Here is a link to the API if anyone fancies a look. https://api.justgiving.com/docs

The project is for a major charity who have zero technical people to help me out, so its goon power or nothing.

Perhaps you will have more luck asking about this in the JavaScript thread.

Adbot
ADBOT LOVES YOU

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:

ComptimusPrime posted:

Perhaps you will have more luck asking about this in the JavaScript thread.

yep that makes sense!

My Rhythmic Crotch
Jan 13, 2011

I apologize ahead of time if this has already been asked or is really obvious...

Is there such thing as an "analyzer" for spring XML files? What I mean is some tool, framework, scripts or something that can compare a given set of XML files against a codebase to check for missed or duplicate entries that would probably result in the application crashing.

pigdog
Apr 23, 2004

by Smythe
Spring configuration isn't confined to XML files for some time now. If you can, then you could just instantiate your app by, say, trying to run some of Spring's own testing framework against it. It's quite useful to invest the time to understand and get your app or parts of your app up and running in Spring's own test harnesses, anyway.

My Rhythmic Crotch
Jan 13, 2011

Unfortunately I don't have the luxury of getting rid of XML files in this case.

What I am trying to do is find a way to ease the process of upgrading hundreds (or thousands) of XML files when a new version of an application drops. The current way it's done is:

1 - Install new version of application, use original version of XML config
2 - Launch app
3 - It crashes
4 - Read error logs and correct missing or broken parameter in XML
5 - Goto 2

Repeat that for a few days or so until finally everything works.

I'm not familiar with the Spring framework, I just have the lovely task of upgrading our XML config when a new version drops. So any ideas or hints to avoid the brute force way above will be appreciated.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

My Rhythmic Crotch posted:

Unfortunately I don't have the luxury of getting rid of XML files in this case.

What I am trying to do is find a way to ease the process of upgrading hundreds (or thousands) of XML files when a new version of an application drops. The current way it's done is:

1 - Install new version of application, use original version of XML config
2 - Launch app
3 - It crashes
4 - Read error logs and correct missing or broken parameter in XML
5 - Goto 2

Repeat that for a few days or so until finally everything works.

I'm not familiar with the Spring framework, I just have the lovely task of upgrading our XML config when a new version drops. So any ideas or hints to avoid the brute force way above will be appreciated.

I don't think there exists a tool other than Spring itself which will simply verify if a given codebase will operate with another given set of Spring XML bean configs. In fact I think (but have not proven at all) that it's impossible to do this 100% without running the program.

That said if you import a project of that kind into STS or IntelliJ, it will start flipping out if you have broken (not missing, unless they're constructor args) parameters. I know IntelliJ will do type checks and some other nice verification.

Also you could have your beans implement InitializingBean's afterPropertiesSet() method and do sanity checks there, so at least you can catch missing / invalid properties to help improve the build/run/crash/debug cycle.

Sypher
Feb 4, 2003
I am pretty terrible at conveying what I am trying to accomplish; however, I will try my best:

I have an object 'occupant.' Occupant may enter a room; however, he can also leave the room(Thus, deleting said occupant from the room). Before he leaves, he must notify that he is leaving. How could I go about doing this?

in the leave method, I am just not sure how to return the object to a toString method, then set it to null.

code:

public class SmallRoom
{

	private Person occupant;
	private String roomName;
	
	public SmallRoom(String name)
	{
		roomName = name;
	}
	
	public boolean isEmpty()
	{
		// havent even started this one yet
		return true;
	}
	
	public boolean isOccupied()
	{
		if (occupant == null)
			return false;
		else
			return true;
	}
	
	public void enter(Person personEnter)
	{
		occupant = personEnter;
	}
	
	public Person leave()
	{	
		return occupant;
	}
	
	public String toString()
	{
		if (this.isOccupied())
			return ( roomName + " is occupied by " + occupant );
		else if (this.isEmpty())
			return (roomName + " is empty." );
			
		return roomName;
	}
	
}

There is the class in its current state. I am not asking you to fix it for me; however, I figured it would help show what is going on.

I just get so lost with objects and inheritance.. I am never going to get my degree. :smith:

ComptimusPrime
Jan 23, 2006
Computer Transformer
Think about using a temporary in that leave method.

pigdog
Apr 23, 2004

by Smythe

My Rhythmic Crotch posted:

What I am trying to do is find a way to ease the process of upgrading hundreds (or thousands) of XML files when a new version of an application drops. The current way it's done is:
Why would there be hundreds (thousands) of XML files?

quote:

I have an object 'occupant.' Occupant may enter a room; however, he can also leave the room(Thus, deleting said occupant from the room). Before he leaves, he must notify that he is leaving. How could I go about doing this?

in the leave method, I am just not sure how to return the object to a toString method, then set it to null.
Your class looks almost right. The question is, who do you suppose has the task of notifying, and whom? A room doesn't notify anyone, does it? In the real world, rooms are just a dumb spaces, made of bricks, who couldn't care less.

Some piece of code would have to be calling these enter() and leave() methods. Let's say it is God who indeed controls the way people and their rooms behave.

The SmallRoom and Person classes look like the Model part of the MVC pattern, the part which describes the properties and relations between concepts. Whereas God would be the Controller part, the code which creates, calls and manipulates them.

Usually, then, God would know where or whether he wants which people to go to which rooms. Rooms wouldn't, normally, have to notify him of it, because He knows best and He is the one setting them up as is.

Now, the rooms might require a spying device which would indeed notify someone else whenever God manipulates them. That doesn't necessarily happen too often, and I'm not quite sure if you really need it. Usually the rest of the code would just take it up with God.

ComptimusPrime
Jan 23, 2006
Computer Transformer
You're not even addressing his problem. You're suggesting a beefy architectural style to solve his inability to reason about how to both set the person to null and also return the person in the leave method.

pigdog
Apr 23, 2004

by Smythe
The problem is that he is confused.

Yes, the leave() could be implemented as
code:
public Person leave() {
   Person copyOfOccupant = occupant; 
   occupant = null; 
   return copyOfOccupant;
}
though better yet, have it simply set the occupant to null and return nothing. Add a getCurrentOccupant() method so that every method would do one thing. You could then also find out who the current occupant is, without making him leave, or making the field public.

code:
public Person getCurrentOccupant() {
    return occupant;
}

public void leave() {
    occupant = null;
}
I think it's not uncommon to be as confused when you start with OO programming. At least back in the I can remember I was, too. You're being taught that "objects are data and code which knows how to manipulate that data together" so you are like "whoa that's cool, lets put everything about SmallRooms and anything that has anything to do with SmallRooms together in SmallRoom", and then you're like "gently caress how do I communicate and react to other objects now, this is so confusing". :)

It's confusing because you'd be mixing the controller code, which would be the parts which create and destroy and manage and manipulate objects, into the objects that represent the data. Unlike what you might have first heard in a lecture, it's perfectly cool for some objects to not contain actionable code at all, except for simple setters/getters. The SmallRoom class works pretty fine as a model class that represents a room. It's important to remember that all code that works on it doesn't need to be contained in the SmallRoom class, but would fit better in, say, God or ApartmentBuildingManager class.

pigdog fucked around with this message at 08:11 on Apr 6, 2012

Sypher
Feb 4, 2003

ComptimusPrime posted:

Think about using a temporary in that leave method.

Wow, that was so easy! Thanks.

pigdog posted:

The problem is that he is confused.

Yes, the leave() could be implemented as
code:
public Person leave() {
   Person copyOfOccupant = occupant; 
   occupant = null; 
   return copyOfOccupant;
}
though better yet, have it simply set the occupant to null and return nothing. Add a getCurrentOccupant() method so that every method would do one thing. You could then also find out who the current occupant is, without making him leave, or making the field public.

code:
public Person getCurrentOccupant() {
    return occupant;
}

public void leave() {
    occupant = null;
}
I think it's not uncommon to be as confused when you start with OO programming. At least back in the I can remember I was, too. You're being taught that "objects are data and code which knows how to manipulate that data together" so you are like "whoa that's cool, lets put everything about SmallRooms and anything that has anything to do with SmallRooms together in SmallRoom", and then you're like "gently caress how do I communicate and react to other objects now, this is so confusing". :)

It's confusing because you'd be mixing the controller code, which would be the parts which create and destroy and manage and manipulate objects, into the objects that represent the data. Unlike what you might have first heard in a lecture, it's perfectly cool for some objects to not contain actionable code at all, except for simple setters/getters. The SmallRoom class works pretty fine as a model class that represents a room. It's important to remember that all code that works on it doesn't need to be contained in the SmallRoom class, but would fit better in, say, God or ApartmentBuildingManager class.


blergh, now the internet will think I didn't figure it out on my own; however, I did! :)

I agree that having a get method would make things a bit easier. However, I am unfortunately forced to follow the guidelines given by my professor. (SmallRoom must use only methods included).

Anyways, thanks for the help guys.

My Rhythmic Crotch
Jan 13, 2011

pigdog posted:

Why would there be hundreds (thousands) of XML files?
Because we have an incredibly large, elaborate product with scads of things to configure. Does it really make a difference?

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

pigdog posted:

though better yet, have it simply set the occupant to null and return nothing.
returning void is a sin (outside of static methods)

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Aleksei Vasiliev posted:

returning void is a sin (outside of static methods)

This sounds like stupid dogma to me. You're going to have to backup this claim with some examples.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
"So shall my word be that goeth forth out of my mouth: it shall not return unto me void, but it shall accomplish that which I please, and it shall prosper in the thing whereto I sent it." -Isaiah 55:11


if you don't have anything better to return, return the object itself, good for chaining a constructor and some setters, for example

Doctor w-rw-rw-
Jun 24, 2008

MEAT TREAT posted:

This sounds like stupid dogma to me. You're going to have to backup this claim with some examples.

Maybe referring to the use of the domain model pattern? Which, granted, I don't fully understand, and am not sure if I have a proper understanding of.

Here's my take: a parameterless function that is not static but which returns nothing presumably alters the internal state of an instance in a way that is totally opaque to someone inspecting it without source (or is completely useless). It also makes the object stateful, something which is best isolated rather than spread out, because it gets harder and harder to reason about classes and their behavior the more the lifecycle is distributed.

In this case I think SmallRoom should define a leave(Person person) method rather than leave() because the interface itself is limiting it to a single occupant, and if a third party, say, a bouncer, were to have power over ejecting people, you might want to give them an interface that allows them to do so without having to specify the type of establishment they were bouncing for, or give them full access to all of the establishment's functions, such as serveBooze(Person person) or something.

In any case, you might try:
code:
try {
    return occupant;
} finally {
    occupant = null;
}
to return the occupant then set it to null - if keeping a temporary reference isn't your thing. Also, the code that wrote:
code:
   Person copyOfOccupant = occupant; 
Is grossly misleading.That doesn't copy the occupant, it copies the reference, and is probably best named something like "tempOccupant" instead of "copyOfOccupant" as it's temporarily there to hold a reference.

EDIT: See for yourself what the try-finally block does. You can use it to do things after something is returned, though I wouldn't recommend making it something you do all the time.
code:

public class Test {
    static String x = "asdf";
    public static void main(String args[]) {
       System.out.println(x);
       System.out.println(test());
       System.out.println(x);
    }

    public static String test() {
        try {
            return x;
        } finally {
            x = "zxcv";
        }
    }
}
results in:
code:
% javac Test.java
% java Test
asdf
asdf
zxcv

Doctor w-rw-rw- fucked around with this message at 18:46 on Apr 6, 2012

pigdog
Apr 23, 2004

by Smythe

My Rhythmic Crotch posted:

Because we have an incredibly large, elaborate product with scads of things to configure. Does it really make a difference?
Well, you know better. If it would make it easier for you to configure them, then you might not have hundreds of them.

quote:

Here's my take: a parameterless function that is not static but which returns nothing presumably alters the internal state of an instance in a way that is totally opaque to someone inspecting it without source (or is completely useless). It also makes the object stateful, something which is best isolated rather than spread out, because it gets harder and harder to reason about classes and their behavior the more the lifecycle is distributed.
The state it alters may or may not be meaningful (as the OP said, the interface was defined by the professor), but it doesn't mean it's necessarily bad. Maybe altering the state in an opaque manner is exactly what you'd want to do. The caller may not necessarily know who lives in the room.

quote:

Is grossly misleading.That doesn't copy the occupant, it copies the reference, and is probably best named something like "tempOccupant" instead of "copyOfOccupant" as it's temporarily there to hold a reference.
Yes it copies the reference, but in this context it doesn't make a difference. There's no need to copy by value, anyway. If you think tempOccupant sounds better then that's fine.

quote:

EDIT: See for yourself what the try-finally block does. You can use it to do things after something is returned, though I wouldn't recommend making it something you do all the time.
Good idea.

Max Facetime
Apr 18, 2009

Aleksei Vasiliev posted:

if you don't have anything better to return, return the object itself, good for chaining a constructor and some setters, for example

I used think chaining mutators was a good idea, but the resulting method call chains are really hard to indent properly and a big pain to step into in a debugger.

Doctor w-rw-rw-
Jun 24, 2008

I am in posted:

I used think chaining mutators was a good idea, but the resulting method call chains are really hard to indent properly and a big pain to step into in a debugger.

It's good for builders, though. And the way Guice does it for module configurations is actually pretty nifty.

Paolomania
Apr 26, 2006

Doctor w-rw-rw- posted:

It's good for builders, though. And the way Guice does it for module configurations is actually pretty nifty.

I am going to spend way more time stepping into and out of that one line of code in a debugger than staring at those chain calls in quiet satisfaction despite the fact that it makes no difference to even the most brain-dead optimizing compiler.

Jo
Jan 24, 2005

:allears:
Soiled Meat
I'd like to have my program's assets stored inside the jar itself to avoid problems when someone has a strange working directory, and to make it easier to move the program around.

Simultaneously, I'd like to be able to avoid having to repack the jar every time I change a file. This compels me to leave the assets outside the jar in my assets folder.

Better put, if the loader finds a file in ./assets/, use that. Otherwise, load it from the <jar root>/assets/.

The solution I've heard to be universal is, `URL url = Main.class.getResource(filename);`, where filename is 'assets/mainmenu.png'. Is there a way which does not require code changes between 'outside' file references and in-jar file references?

Or do I have to do something like, 'if(new File(wat).exists()) {dance} else {load url from jar}'?

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Jo posted:

Or do I have to do something like, 'if(new File(wat).exists()) {dance} else {load url from jar}'?
This is more or less what I have done. Centralized file loading method that first attempts to load from the directory, then falls back to the JAR.

Thom Yorke raps
Nov 2, 2004


Do you have a build script that generates the jar? You should. If so why do you care?

Jo
Jan 24, 2005

:allears:
Soiled Meat

Aleksei Vasiliev posted:

This is more or less what I have done. Centralized file loading method that first attempts to load from the directory, then falls back to the JAR.

Many thanks. That's what I've got set up. :( I guess it's not _that_ ugly a solution.

Ranma posted:

Do you have a build script that generates the jar? You should. If so why do you care?

Some of the elements might be updated after the jar is created. I can create a self-contained Jar without issue, but if our graphics person is fiddling, I don't want her to have to open the jar, extract the image, and repack it. Even a three step process can be a pain in the butt if you're making lots of little tweaks.

Jo fucked around with this message at 17:55 on Apr 8, 2012

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Paolomania posted:

I am going to spend way more time stepping into and out of that one line of code in a debugger than staring at those chain calls in quiet satisfaction despite the fact that it makes no difference to even the most brain-dead optimizing compiler.

You really feel the need to step through, one at a time, a bunch of method calls that each just set a single property?

Max Facetime
Apr 18, 2009

Jabor posted:

You really feel the need to step through, one at a time, a bunch of method calls that each just set a single property?

The real "fun" part starts when you have chained method calls producing the arguments for your chained method calls. A simple thing like
code:
doc.add("<h1>" + title + "</h1>").add("<p>" + xmlEncode(lorem.getIpsum(15)) + "</p>");
in a debugger is going to feel like this:

code:
doc.add(new StringBuilder().append("<h1>").append(title).append("</h1>").toString()).add(new StringBuilder().append("<p>").append(xmlEncode(lorem.getIpsum(15))).append("</p>").toString());
E: lorem, not lorum.

Max Facetime fucked around with this message at 22:34 on Apr 8, 2012

1337JiveTurkey
Feb 17, 2005

Aleksei Vasiliev posted:

"So shall my word be that goeth forth out of my mouth: it shall not return unto me void, but it shall accomplish that which I please, and it shall prosper in the thing whereto I sent it." -Isaiah 55:11


if you don't have anything better to return, return the object itself, good for chaining a constructor and some setters, for example

I tried this with a set of builder objects which were covariant on the type of the object that they're building and that type had a deep inheritance hierarchy for historical reasons. I tried chaining for the hell of it and came up with something that started off like this and just got more insane:
code:
interface ChildBuilder<T extends ChildType, B extends ChildBuilder<T, B>> extends ParentBuilder<T, B> {
    B setFoo(String fooString);
}

Doctor w-rw-rw-
Jun 24, 2008

1337JiveTurkey posted:

I tried this with a set of builder objects which were covariant on the type of the object that they're building and that type had a deep inheritance hierarchy for historical reasons. I tried chaining for the hell of it and came up with something that started off like this and just got more insane:
code:
interface ChildBuilder<T extends ChildType, B extends ChildBuilder<T, B>> extends ParentBuilder<T, B> {
    B setFoo(String fooString);
}

Wow. That's horrible. I just meant that it makes sense for like, simple POJO builders, not for complex processes.

1337JiveTurkey
Feb 17, 2005

Doctor w-rw-rw- posted:

Wow. That's horrible. I just meant that it makes sense for like, simple POJO builders, not for complex processes.

The thing is that there wasn't anything all that complex conceptually about it, I just needed the builder methods to return the actual type of the builder itself instead of the type of the interface. Some sort of shorthand for self types that doesn't require adding dummy type parameters to the hierarchy would remove the majority of the crap. A syntax change to the language to support chaining void methods would also get around the problem since there's no type of a return value, just the type of the chained instance which can't change.

mister_gosh
May 24, 2002

I am having listener trouble with a Swing JTable.

I could post code, but the behavior is also seen here in step 1 (when you press the Launch button): http://docs.oracle.com/javase/tutorial/uiswing/components/table.html

The problem is, when you click in a field and start typing a new value, the java.awt.event.MouseAdapter or import java.awt.event.MouseEvent do not register an event/keep the new value unless you press Enter, click somewhere else in the body (not the header) of the table, press the tab key, etc.

So, if you type in a new value and then click on a header row, your value is wiped out. Also, if the parent JPanel is resized after entering a value, it wipes the data out.

I tested this out in MS Excel by entering data and then clicking on a header row, and Excel registers the change.

I tried a few different things, but I can't find an appropriate listener which registers this type of event (including TableColumnModelListener, TableModelListener, TableModelEvent).

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Try using a FocusListener if you want to detect when a particular table cell loses keyboard focus.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
code:
Map<String, String> myMap = new HashMap<String, String>(100);
What happens when the initialCapacity of 100 is exceeded, memory usage wise?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

fletcher posted:

code:
Map<String, String> myMap = new HashMap<String, String>(100);
What happens when the initialCapacity of 100 is exceeded, memory usage wise?

It doubles down. Check out the source:

code:
    void addEntry(int hash, K key, V value, int bucketIndex) {
	Entry<K,V> e = table[bucketIndex];
        table[bucketIndex] = new Entry<K,V>(hash, key, value, e);
        if (size++ >= threshold)
            resize(2 * table.length);
    }
Also the threshold is not the total capacity, the threshold is defined by the loadFactor * the capacity.

baquerd
Jul 2, 2007

by FactsAreUseless

fletcher posted:

code:
Map<String, String> myMap = new HashMap<String, String>(100);
What happens when the initialCapacity of 100 is exceeded, memory usage wise?

http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html posted:

When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the hash table is rehashed (that is, internal data structures are rebuilt) so that the hash table has approximately twice the number of buckets.

The array size double internally.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Interesting, thanks guys. So if there is a ton of poo poo stored in the HashMap, and you exceed that initial capacity...well that is no good right?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

fletcher posted:

Interesting, thanks guys. So if there is a ton of poo poo stored in the HashMap, and you exceed that initial capacity...well that is no good right?

It's no big deal really. If you absolutely know how large it should be you can preemptively size it correctly, but that screams premature optimization.

1337JiveTurkey
Feb 17, 2005

fletcher posted:

Interesting, thanks guys. So if there is a ton of poo poo stored in the HashMap, and you exceed that initial capacity...well that is no good right?

Unless it's all duplicates, the data being stored is going to generally be much more significant than the data structure itself in terms of size. Even if it's running on a 64-bit system, the incremental size increase from 128 to 256 buckets is 1kB. If you're really hard-pressed for space you could slightly increase the load factor but that will slow it down due to an increased risk of collisions.

pigdog
Apr 23, 2004

by Smythe
Came across this pretty nice article on Java anti-patterns for newbies and not-so-newbies alike.

Adbot
ADBOT LOVES YOU

iscis
Jan 8, 2007
im the coolest guy you know
I'm having trouble implementing some methods of a doubly linked list, if anyone could point me in the right direction I'd appreciate it.
code:
node class

public class p_02Node<T> {
	private T data;
	private p_02Node<T> next;
	private p_02Node<T> prev;
	p_02Node(){
		next=null;
		prev=null;
		data=null;
	}
	p_02Node(T data){
		this.data=data;
		next=null;
		prev=null;
	}
	p_02Node(T data, p_02Node<T> next, p_02Node<T> prev){
		this.data=data;
		this.next=next;
		this.prev=prev;
	}
	T getData(){
		return data;
	}
	public p_02Node<T> getNextNode(){
		return next;
	}
	public p_02Node<T> getPreviousNode(){
		return prev;
	}
	public void setNextNode(p_02Node<T> next){
		this.next=next;
	}
	public void setPreviousNode(p_02Node<T> prev){
		this.prev=prev;
	}
	public void setData(T data){
		this.data=data;
	}
}
and the linked list class
code:

public class p_02<T> extends p_02Node {
	private p_02Node<T> head;
	private p_02Node<T> tail;

	public boolean isEmpty() {
		return head == null;
	}

	public void addFront(T data) {
		p_02Node<T> newNode = new p_02Node<T>(data);
		if (head == null) {
			head = newNode;
			tail = newNode;
			newNode.setNextNode(null);
			newNode.setPreviousNode(null);
		} else {
			newNode.setNextNode(head);
			head.setPreviousNode(newNode);
			head = newNode;
		}
	}

	public void addRear(T data) {
		p_02Node<T> newNode = new p_02Node<T>(data);
		if (tail == null) {
			head = newNode;
			tail = newNode;
			newNode.setNextNode(null);
			newNode.setPreviousNode(null);
		} else {
			newNode.setPreviousNode(tail);
			tail.setNextNode(newNode);
			tail = newNode;
		}
	}

	public int getSize() {
		int count = 0;
		if (head == null)
			return count;
		else {
			p_02Node<T> temp = head;
			do {
				temp = temp.getNextNode();
				count++;
			} while (temp != tail);
		}
		return count;
	}

	public void add(T data, int position) {
		if (position < 0 || position == 0) {
			addFront(data);
		} else if (position > getSize() || position == getSize()) {
			addRear(data);
		} else {
			p_02Node<T> temp = head;
			p_02Node<T> newNode = new p_02Node<T>(data);
			for (int i = 0; i < position - 1; i++) {
				temp = temp.getNextNode();
			}
			newNode.setNextNode(temp.getNextNode());
			temp.getNextNode().setPreviousNode(newNode);
			temp.setNextNode(newNode);
			newNode.setPreviousNode(temp);
		}
	}
	public void clear(){
		p_02Node<T> current=head.getNextNode();
		while(current!=head){
			p_02Node<T> next=current.getNextNode();
			current=null;
		}
	}
	public p_02Node<T> get(int index){
		if(index<=0)
			return null;
		p_02Node<T> current=head.getNextNode();
		for(int i=1;i<index;i++){
			if(current.getNextNode()==null)
				return null;
			current=current.getNextNode();
		}
		return current.getData();
	}
	public p_02Node<T> set( int index, T element){
		
	}
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply