Removing vector elements
hi there
i have a vector, that has the contents of a directory as elements. in the post proccessing phase i trie to remove all elements that are .java files or are class files that end with Options.class or Options$1.class.
i use this code
for(int i=0; i < plugins.size(); i++) {
theFilename = plugins.elementAt(i).toString();
System.out.println("TheFilename: "+theFilename);
if(theFilename.endsWith(".java") ||
theFilename.endsWith("Options.class") ||
theFilename.endsWith("Options$1.class")) {
System.out.println("Removed: "+theFilename);
plugins.remove(theFilename);
}the problem is, that that code always leaves one element in the vector, that should be sorted out by this loop. anyone an idea ?
- rebel
Hi jaylogan again,
i read your second answer. I use the methods of the file-class. So it seems better to paste the whole method in here. note, the for loop, that removes filenames is twice there. after first test i found ou, that the second loop is removing the last filename that should not be in the list. that worked as long i had only one plugin in the plugin directory. when i added a second plugin the double for-loop was not working anymore. there is still an element left that should not be in the list.
sourcecode:
public void createPluginList() {
String theFilename;
String plugInDir = getCurrDir()+File.separator+"plugins";
File dir = new File(plugInDir);
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String theName) {
return theName.startsWith("Pi");
String[] contents = dir.list(filter);
if (contents == null) {
// Either dir does not exist or is not a directory
} else {
for (int i=0; i < contents.length; i++) {
plugins.addElement(contents);
System.out.println("------------");
for(int i=0; i<plugins.size(); i++) {
System.out.println(plugins.elementAt(i).toString());
System.out.println("------------");
for(int i=0; i < plugins.size(); i++) {
theFilename = plugins.elementAt(i).toString();
System.out.println("TheFilename: "+theFilename);
if(theFilename.endsWith(".java") ||
theFilename.endsWith("ptions.class") ||
theFilename.endsWith("ptions$1.class")) {
System.out.println("Removed: "+theFilename);
plugins.remove(theFilename);
System.out.println("------------");
for(int i=0; i < plugins.size(); i++) { // I dont know why i have to run this
theFilename = plugins.elementAt(i).toString(); // a second time, but only then
System.out.println("TheFilename: "+theFilename); // it works
if(theFilename.endsWith(".java") ||
theFilename.endsWith("Options.class") ||
theFilename.endsWith("Options$1.class")) {
System.out.println("Removed: "+theFilename);
plugins.remove(theFilename);
System.out.println("------------");
for(int i=0; i<plugins.size(); i++) {
System.out.println(plugins.elementAt(i).toString());
-rebel
Similar Messages
-
Kill a thread and remove the element from the vector
Hi All
I have attached each Vector element to a thread which I later want to kill and remove that element from the Vector.
Thread.join(milliseconds) allows this functionality to let the thread die after n milliseconds.
However, I want to delete this element from the Vector now.
Can someone please throw some light on this?
Here the code I have written for this:
try
System.out.println(counter);
int xCoord = generator.irand(25,200); // X-coord of AP
int yCoord = generator.irand(25,200); // Y coord of AP
listMN.addElement(new MobileNode((int)mnId,new Point2D.Double(xCoord,yCoord)));
listMNcoords.addElement(new Point2D.Double(xCoord,yCoord));
for(int i=0;i<vnuBS.returnBSList().size();i++)
if(vnuBS.returnBSListCoords().get(i).contains(xCoord,yCoord)&&(vnuBS.returnBSList().get(i).getChannelCounter()<=3)&&(vnuBS.returnBSList().get(i).getChannelCounter()>0))
double c = exponential() * 10000;
long timeToService = (long)c;
System.out.println("BS "+vnuBS.returnBSList().get(i).id+" is connected to MN ");
vnuBS.returnBSList().get(i).reduceChannelCounter();
System.out.println("Channel Counter Value Now: "+vnuBS.returnBSList().get(i).getChannelCounter());
mobileNodesThread.addElement(new Thread(listMN.elementAt(mobileNodeCounter)));
mobileNodesThread.elementAt(mobileNodeCounter).setName(mobileNodeCounter+"");
mobileNodesThread.elementAt(mobileNodeCounter).start();
mobileNodesThread.elementAt(mobileNodeCounter).join(100);
// System.out.println("Died");// thread dies after join(t) milliseconds.
System.out.println("ListMN getting generated : " + mobileNodesThread.get(mobileNodeCounter));
else if(vnuBS.returnBSListCoords().get(i).contains(xCoord,yCoord)&&(vnuBS.returnBSList().get(i).getChannelCounter()<=0))
listMN.remove(this.listMN.lastElement()); //dropcall
System.out.println("Removed "+mnId);
removeCounter++;
mnId = mnId--;
mobileNodeCounter--;
mnId = mnId+1;
Thanks a lot.I'm not sure if what you are trying to accomplish is correctly implemented.
The method join does not kill the thread. It will wait for the specified time for the thread to exit. If you want the thread to run for a specified ammount of time, develop the run method of that thread with that in mind. Do not try to kill it from the outside, but let it terminate itself (gracefull termination).
Now for your question regarding the vector (you should probably be using ArrayList nowadays): I would implement the observer pattern for this job. Make the threads post an event on the interface when they are done, let the main thread register itself with the threads and synchronize the method that handles the events. In that method you can remove the object from your list.
I'm not sure if you want to use thread anyhow, could you tell us what it is that you are trying to accomplish? -
Hi all!
I have a problem about an xml. I have to eliminate redundancy
So from this xml:
<xml1>
<Property>
<Parameters1>
<Param>
<name>A</name>
<prop></prop> <!--this doesn't matter-->
</Param>
<Param>
<name>B</name>
<prop></prop> <!--this doesn't matter-->
</Param>
<Param>
<name>C</name>
<prop></prop> <!--this doesn't matter-->
</Param>
</Parameters1>
<Parameters2>
<Param>
<name>A</name>
<prop></prop> <!--this doesn't matter-->
</Param>
<Param>
<name>C</name>
<prop></prop> <!--this doesn't matter-->
</Param>
<Param>
<name>D</name>
<prop></prop> <!--this doesn't matter-->
</Param>
</Parameters2>
</Property>
</xml1>
I want to obtain this xml:
<xml2>
<Property>
<Parameters1>
<Param>
<name>A</name>
<prop></prop> <!--this doesn't matter-->
</Param>
<Param>
<name>B</name>
<prop></prop> <!--this doesn't matter-->
</Param>
<Param>
<name>C</name>
<prop></prop> <!--this doesn't matter-->
</Param>
</Parameters1>
<Parameters2>
<!--Parameters A and C are missing-->
<Param>
<name>D</name>
<prop></prop> <!--this doesn't matter-->
</Param>
</Parameters2>
</Property>
</xml2>
There are just parameters without repeting.
My code until now is:
private String numeParam;
private Vector elParam = new Vector();
for (int i=0;i<rootlist2.getLength();i++)
Element element2 = (Element)rootlist2.item(i); // rootlist is my doc xml
if (element2.getLocalName()==Property)
NodeList childrenName2 = element2.getChildNodes();
for (j=0;j<childrenName2.getLength();j++)
Element elemm = (Element)childrenName2.item(j);
if ((elemm.getLocalName() == "Parameters1")||(elemm.getLocalName() == "Parameters2"))
NodeList param = elemm.getChildNodes();
for(int y=0;y<param.getLength();y++)
bn=true;
bas=true;
Element childInProperty2 = (Element)param.item(m2); // acesta e de sters
if (childInProperty2.getLocalName() == Param)
NodeList tlist =childInProperty2.getChildNodes();
for (int y = 0;y<tlist.length();y++)
Element childInPUParam2 = (Element)tlist.item(y);
if (childInPUParam2.getLocalName()== "name")
numeParam = childInPUParam2.getTextContent();
bas=false;
if (bas==false)
if (!elParam.contains(numeParam))
elParam.addElement(numeParam);
if (elParam.contains(numeParam))
bn=false;
break;
} end if
} // end for
if (bn==false)
ba = false;
if (bn==false)
System.out.println("C");
ba = false;
elParam.clear();
this is working I a kind of way, but this remove some elements that is not god. I wonder... Is like elParam contains some strings but, after me is imposible.
Thanks allWhy don't you use XPath? Anyway.
-> Get a List of the documents Node
-> Get a List of all children
You have to check each Node:
-> if the node is not null
-> if the node's name is not null
-> if the node's content is not null
-> if the node's name is equals (<name>)
If the Node-Element is found, store it in a Collection (the reference of the node object).
Later you could iterate the collection and remove all Nodes from the Document.
Afterwards you can transfer the document to a xml file.
btw: if you use XPath you have to be sure to use at least Java 1.5
Regards,
Florian -
Using JDOM, does anyone know of a way to remove an element? Thanks,
chrisFound the answer. removeChild() gets the job done.
-
I am not able to remove an element of my side bar of the finder
I am not able to remove an element of my side bar of the finder
Try holding down the COMMAND key while dragging the element to the desktop.
-
need help how to remove empty elements in an array?
Hi jeyanthi,
if you want to delete somthing from a txt file, you have also first to read the data, remove the part you want and to write the new data into the file. So i think you can do it with the array version. For example something like this:
Mike
Message Edited by MikeS81 on 06-09-2008 09:32 AM
Attachments:
Unbenannt1.PNG 6 KB -
Thread FAQ:findind removed collection elements
Hi All
i have two threads and one collection with some elements ,The problem is one removed some elements in collections now i want to find out elements removed by thread one with thread twoWell they're not in the collection any more, are they? so the thread that removed them will have to remember them somewhere, or else the other thread will need a copy of the original collection.
It's not a Thread FAQ question. Any two classes that used the collection would have the same issue. -
if i create a vector called aList,
and it had 2 elements "peter" and "june"
and i create a new array >>String[] name = new String[5];
how to use this method
copyInto(Object[] anArray)
Copies the components of this vector into the specified array.
to copy the 2 elements in aList vector to my name[1]?if i create a vector called aList,
and it had 2 elements "peter" and "june"
and i create a new array >>String[] name = new
String[5];
how to use this method
copyInto(Object[] anArray)
Copies the components of this vector into
ctor into the specified array.
to copy the 2 elements in aList vector to my name[1]?A confusing question: you want to put two Vector elements into one array element? Can't put ten pounds of @%^@%^@^ in a five pound bag, can you?
If you really want two Vector elements to be stored in one array element you'll have to combine them in some way. String concatenation will do.
If you mean you'd like to copy all the Vector elements into the array, you'll have to do something like this:
Vector aList = new Vector();
// add some elements to aList
int numNames = aList.size();
String [] names = new String[numNames];
for (int i = 0; i < numNames; ++i)
names[i] = (String)aList.get(i);MOD -
Removing specific element from a list
Hello, I'm very new to java, and to programming in general.
I'm trying to write a secret santa app for my family for christmas. Essentially the idea is that 7 names are put into a list, and each time a name is "pulled" (i.e. randomly assigned to a name /= itself) it will be removed from the list of available names to assign.
String[] nList = { name2, name3, name4, name5, name6, name7 }; // store names for random use
Random r = new Random();
name1assign = nList[r.nextInt(nList.length)];
String[] nList2 = { name1, name3, name4, name5, name6, name7 };
name2assign = nList2[r.nextInt(nList2.length)];
My goal for this is to take the string that is equal to name1assign, and remove an element with that string from nList2.
Can anyone give me some advice in this matter?
Thanks.Sometimes a null value is used to indicate an 'empty' array element, but it would be better to try collections instead.
You could use an ArrayList instead of an array. This has methods to remove items by index or value.
An ArrayList also works with Collections.shuffle, which allows you to simply iterate over the list and not deal with random or removing elements at all. -
How to manually remove Photoshop Elements 4.0 from Windows
My uninstaller for Photoshop Elements 4.0 in Add or Remove programs fails with the message - "This action is only valid for products that are currently installed." The program folder still resides on my harddrive. The program itself neither runs nor will it allow me to delete the program files' Photoshop Elements 4.0 folder that contains the executable and dll files from my harddrive. I need a manual uninstall proceedure.
Have you got the disc? If so, you might try installing it again then an uninstall.
Failing that...
Here's the Adobe tech doc on removing Photoshop Elements 5. I would assume it would be the same procedure.
http://kb2.adobe.com/cps/333/333201.html -
If I'm copying text and/or vector elements from Indesign to Photoshop how come their pixel sizes change even though I opened the same sized document and my indesign file is a web file?
>my indesign file is a web file
Pardon?
Or do you mean that, when you created a new document, you choose Web as intent maybe? -
I was cleaning up the programs on my hard drive and removed Photoshop Elements 9 and 10. I used Revo Uninstaller Pro to remove all the left over files and registry entries. Revo also removed parts of my version 12. I re-downloaded the demo version again as I already have the serial number. When I run the install program files my only choice is to remove version 12 and I'm not able to install
Try this,
Run the cleaner tool. clean the product(if you see).
Use the CC Cleaner Tool to solve installation problems | CC, CS3-CS6
Then Rename/delete all the Adobe folders.
The locations are: 64 bit computer.
C:\Program Files (x86)\Common Files\Adobe.
32 bit computer.
C:\Program Files \Common Files\Adobe.
C:\ProgramData\Adobe.
You also have Adobe folders in :
C:\Users\[user name]\AppData\Local\Adobe
C:\Users\[user name]\AppData\Locallow\Adobe
C:\Users\[user name]\AppData\Roaming\Adobe\OOBE
Then Re-install the product. -
How to remove photoshop elements 3 from being the default program to open photos
how to remove photoshop elements 3 from being the default program to open photos in iMac 10.6.8; want to use Preview 5.0.3 as before. Somehow I clicked an "ok" to a question asking if I wanted photoshop e 3 to be the default program (NOOOO - too slow, too cumbersome just for viewing pix) What was I thinking????
This might help just found googling http://www.bittbox.com/os-x/how-to-set-the-default-program-to-open-a-certain-type-of-file- in-mac-os-x
Try once please.
Thanks,
Garry -
I have photoshop elements 13 and want to remove photoshop elements 10 first. When I try to remove 10 I get error 1316 , specified account already exests and will not remove. I have windows 7
Exit Code: 6, Exit Code: 7 Installation Errors - http://helpx.adobe.com/creative-suite/kb/errors-exit-code-6-exit.html
Troubleshoot with install logs | CS5, CS5.5, CS6 - http://helpx.adobe.com/creative-suite/kb/troubleshoot-install-logs-cs5-cs5.html for information on how to review your installation logs -
Ho to remove duplicate element in the List ?
It seem to be very basic, but it not working, even I try different way.
This my List [10, 10, 11, 11, 12, 12, 13, 13, 14, 14],
now to remove duplicate elements to have at the end [10, 11, 12, 13, 14]
my code seem to be perfect but...
for(int i = 0; i < listA.size(); i++){
if(i%2 == 0){
System.out.println("ce i est un nombre pair "+i);
listA.remove(i);
System.out.println(listA);senore100 wrote:
The problem is that every single time an element is removed, the whole ArrayList is re-shuffled, with all the elements to the right moved to the left on spot. That's why.Yes, that's right. However if you had used an Iterator over the list, you could easily have removed every other element. It's only when you use an array index that you run into this (very common) problem.
Maybe you are looking for
-
Started a Itunes software update this morning which didn't work. Now Itunes will not open at all. I get the following message."The program can't state becasue MSVCR80.dll is missing from your computer."
-
How do I dynamically open a VI and load values into its connector pane?
I'm trying to open a VI as a prompt to another VI without opening the second VI's front panel until the user clicks OK in the first window. The second VI takes inputs from the first thru its connector pane. How do I dynamically open the second VI?
-
Time Machine Backup Is Too Large For Backup Disc NOT
Hi, I have not been able to locate anything to help me with a time machine/time capsule issue I am experiencing. I have a 750 GB internal and a 1tb capsule. I have been using it to back up for well over a year with no real troubles. About three month
-
Strange audi sync problem & different, stranger video sync issu in sequence
I have two strange occurances with one particular set of media that was downloaded from the same original source mini-dv (recording in dvcam) tape. I have not found the same issue on any other footage. 1) when the media is imported into FCP, the audi
-
Using JTA enabled connection in a JSP/servlet without transaction
Can we use a JTA enabled connection in a JSP/servlet without any transaction? Thanks