473,699 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to check if an object already exists

oll3i
679 Contributor
how to check if an object already exists and return reference to that object
Apr 5 '07
59 32832
oll3i
679 Contributor
nazwa is a string and yes i used equals(nazwa.eq uals(k.nazwa)) in the equals method
Apr 7 '07 #31
oll3i
679 Contributor
but now what to do with the buttons problem
Apr 7 '07 #32
JosAH
11,448 Recognized Expert MVP
but now what to do with the buttons problem
I don't know; for starters: are both ActionListeners registered with those Buttons
using the same List? Add a lot of System.out.prin tln(...) debug statements and
see what happens.

kind regards,

Jos

ps. does your equals() and hashCode() methods work correctly now?
Apr 7 '07 #33
oll3i
679 Contributor
thank u a lot lot lot yes they do :)
Apr 7 '07 #34
oll3i
679 Contributor
i did use lots of System.out.prin t() but the prob is that what's created by one button is not seen by the other button code and where to look 4 solution of that?
Apr 7 '07 #35
JosAH
11,448 Recognized Expert MVP
i did use lots of System.out.prin t() but the prob is that what's created by one button is not seen by the other button code and where to look 4 solution of that?
Are both ActionListeners using the same List in which you added your Klient
objects? Print out both lists everytime you access them and see what's in
them. (they both should be two references to one List).

kind regards,

Jos

ps. a List can print itself quite nicely because it overrides the toString() method.
Apr 7 '07 #36
oll3i
679 Contributor
i walked through the list and i know that the client is in that list but when i do
int index = klienci.indexOf (klient); it returns false
Apr 7 '07 #37
JosAH
11,448 Recognized Expert MVP
i walked through the list and i know that the client is in that list but when i do
int index = klienci.indexOf (klient); it returns false
Can't be, the indexOf() method returns an int; -1 possibly if no object was found.
I think you have to recheck your equals() method and your hashCode() method.
Print out what your equals() method has to say about every comparison.

kind regards,

Jos
Apr 7 '07 #38
oll3i
679 Contributor
that was with contains sorry so it returns -1

but
Klient k1 = new Klient("Jan",20 0);
Klient k2 = new Klient ("Jan",200);

System.out.prin t(k1.equals(k2) );


returns true


int index = klienci.indexOf (klient);

if(index != -1) {
klient = klienci.get(ind ex);
}
else {
// 'klient' is not in the list 'klienci'
}
Apr 7 '07 #39
JosAH
11,448 Recognized Expert MVP
that was with contains sorry so it returns -1

but
Klient k1 = new Klient("Jan",20 0);
Klient k2 = new Klient ("Jan",200);

System.out.prin t(k1.equals(k2) );


returns true


int index = klienci.indexOf (klient);

if(index != -1) {
klient = klienci.get(ind ex);
}
else {
// 'klient' is not in the list 'klienci'
}
You did do a 'klienci.add(k1 )' or 'klienci.add(k2 )' did you? If so, can you show
your equals method just to be sure? Add a System.out.prin tln() to your equals()
method to see if it is called by your List.

kind regards,

Jos
Apr 7 '07 #40

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2460
by: lawrence | last post by:
How dangerous or stupid is it for an object to have a reference to the object which contains it? If I have a class called $controllerForAll which has an arrray of all the objects that exist, what happens if one of those objects, when it is created, takes a reference to the object that contains it? Do bad things happen? class McShow {
2
11856
by: Jonathan | last post by:
I am looking for a simple way to check if a database table exists. I keep getting advice to use "Try.. Catch" and other error handling methods, but I obviously don't want to have to display an error message and stop the process every time someone loads the script after the table is created because that would mean the page could only ever run once which of course not the solution I was looking for. I simply want to know how I can check...
2
6030
by: Mike | last post by:
I´ve got a number of SPAN elements named "mySpan1", "mySpan2", "mySpan3" etc, and want to set their "style.display" to "inline". This works (only needs to work on IE5.5+): for (var x = 1; x < 20; x++) { document.all('mySpan'+x).style.display = "inline"; } But I don´t know how many SPAN elements there are, so I need to set x to a
9
7251
by: Carl Fenley | last post by:
I am successfully adding stored procedures to an Access database. However, I need to be able to check if the stored procedure of the same name already exists. Is there a way to do this other than waiting for the OleDbException caused when adding one that already exists? Here is the code snippet: Private Sub CreateStoredProcedures()
4
3012
by: jes | last post by:
hi, i have an open & delete btn. onclick of open as visio drawing opens in visio & onclick of delete the drawing gets deleted from the filesystem. The problem is i am unable to perform these actions if the file is already opened in another instance of visio. how do i check if it's already opened and then throw an error msg? thanks
14
46240
by: John Salerno | last post by:
What is the best way to check if a file already exists in the current directory? I saw os.path.isfile(), but I'm not sure if that does more than what I need. I just want to check if a file of a certain name exists before the user creates a new file of that name. Thanks.
3
11044
by: byeung | last post by:
Hi, I am trying to check if a particular record already exists in an Access database through Excel vba code. Through code obtained at another forum, I got the following: *********************************************************************** Sub TheButton()
2
35085
by: Larry | last post by:
Thanks in advance. what is the C# equivalent of the VB.net IsNothing(object) function? just trying to check to see if an object instance already exists. does someone have an example? *** Sent via Developersdex http://www.developersdex.com ***
0
6453
by: bharathreddy | last post by:
This article will explain you how to check weather a column already exists in a table before you add the column to the table using alter command. Using the system tables you can check to see weather a column already belongs to a specific table. SYSCOLUMNS is the system table which stores all the table columns information, from this column you can check weather a specific column exists in a specific table. ...
0
8706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8630
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9055
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8944
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8899
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7786
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4638
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2364
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.