Array Splice problems...
Hi i am loading in xml into Flash
<question ID="n3.1a" level="3" />
<question ID="n3.2b" level="3" /> ... etc all the way
to n3.12b
So what i am trying to do is to Splice the array into 2 parts
all the questions ID's that are A and all that are B for for
example an array with:
level3a_Array = [n3.1a,n3.2a,n3.3a,n3.4a]
level3b_Array = [n3.1b,n3.2b,n3.3b,n3.4b]
but i am having problems with the code below trying to splice
them, so any help would be great!!!
var diagnosticXml:XML = new XML();
diagnosticXml.ignoreWhite = true;
diagnosticXml.load("databank/databank.xml");
diagnosticXml.onLoad = function(success:Boolean){
if(success){
aLevel = diagnosticXml.firstChild.childNodes;
lev3Array = aLevel[0].childNodes;
for(var a=12; a>0; a--){
var level_3:Number = _root.aLevel[0].childNodes.length;
_root.aLevel[0].childNodes.splice(0, 1);
lev3B_Array = _root.aLevel[0].childNodes.splice(0, 1);
trace("lev3Array: "+ lev3Array);
}
intialize both arrays and then push every other node into
your arrays.
Similar Messages
-
Associative Array (Object) problems
Here is the function i'm dealing with
i'm reading in a delimited string and using indexed arrays to
break them up and assign the keys and values to an associative
array in a loop.
i'm using variables in the loop and the array loads as
expected in the loop
but outside the loop, the only key is the variable name and
the value is undefined
this is true using dot or array notation, as well as literal
strings for the keys
any help is appreciated
watchSuspendData = function (id, oldval, newval):String {
//the incoming suspendData string is delimited by the
semicolon;
//newval is: firstValue=Yes;captivateKey=1
var listSuspendData:Array = newval.split(";"); // convert it
to a list of key/value pairs
if (listSuspendData.length > 0){
//line 123: listSuspendData.length is: 2
for (i=0; i < listSuspendData.length; i++){ //for each
key/value pair
var keyValArray:Array = new Array();
var myNameValue:String = listSuspendData
//line 127: listSuspendData is: firstValue=Yes
keyValArray = myNameValue.split("="); // split 'em on the
equal sign
var myKey:String = keyValArray[0];
var myVal:String = keyValArray[1];
//keyValArray[0] is: firstValue
//keyValArray[1] is: Yes
// store the key and the value in associative array
suspendDataArray.myKey = myVal;
trace("line 134: suspendDataArray is: " +
suspendDataArray.myKey);
// trace is line 134: suspendDataArray is: Yes on the first
pass and 1 on the second
//the below loop always returns one array key: myKey and the
value as undefined
for(x in suspendDataArray){
trace("x is: " + x); //x is: myKey
trace("the val is: " + suspendDataArray.x); //the val is:
undefined
} //end for
return newval;on lines 12-13 i assign the key=value pair to string
variables
then on lines 17-18 i assign those values to the associative
array using dot notation
the trace seems to work there
the problem is that when the procedure exits the for loop,
the associative array only has one key (myKey) and no value
(undefined)
all the documentation i've read shows using these types of
arrays with either non-quoted property names like:
myAssocArray.myKey = "somevalue";
or
myAssocArray[myKey] = "somevalue";
i tried assigning the key/value pairs directly from the
indexed arrays, but the result was always undefined
like this:
suspendDataArray.keyValArray[0] = keyValArray[1]
or
suspendDataArray[keyValArray[0]] = keyValArray[1]
i even tried building a string in the loop and trying to
assign all the pairs at once using the curly brace
this is pretty wierd behavior for actionscript or i'm missing
something basic here
thanks for looking -
Spreadsheet to array memory problems
I'm trying to read a large .csv file (329 MB) and display a user selected column of data on a graph. I have a standalone executable that does this wonderfully, however, I cannot contact the developer of this application to ask questions. I just have the standalone executable, no code. So I'm trying to write my own application with a slight modification. The problem is I run out of memory for LabVIEW.
In the standalone execution the memory usage is as follows:
515 MB - baseline memory usage
523 MB - application starts
1.25 GB - open 329 MB .csv file
1.5 GB - open additional 63.6 MB .csv file
Data from the first column is displayed on a graph. Memory usage does not seem to change at all when I'm selection columns from either file for plotting on the graph. CPU usage is also minimal when selecting columns; at most an occasional spike of 20%.
In my application the memory usage is as follows:
515 MB - baseline memory usage
587 MB - LabVIEW starts
598 MB - application starts
657 MB - open 63.6 MB .csv file
1.10 GB - convert spreadsheet string to 2D array
2.04 GB - replace 1st row
and then LabVIEW runs out of memory. I've enclose the subVI that actually reads the .csv file and converts it to a 2D array. Why is LabVIEW running out of memory for my application and not the standalone application? Theories?
Attachments:
ExtractPortion.vi 33 KBHey all,
The in place element structure should be relatively straightforward, once you understand the concept behind it, which is that it keeps everything in the same memory location and does think about resizing it. Thus, deleting items in an in place structure would not function. Replacing items should however, as discussed in this help document: http://zone.ni.com/reference/en-XX/help/371361G-01/glang/in_place_element_structure/ and as shown here:
I tried to reproduce your issue, but I managed to make both notepad and word crash in the production of a large enough CSV file. My recommendation is go ahead and split the file up if at all possible. Since you said the code fails on the delete node, you could also simply use the array subset function to pull out all but the line you want to delete, rather than asking labview to give you a second memory location. On the other hand, on my computer the problem occurs at the VI which converts to a spreadsheet string--however, if I set .csv to false (meaning that VI does not have to convert to a float) it does not have a problem. My suggestion would be to convert it to a string first, then use the in place element structure to convert items one by one to the %f format, rather than %s. This is especially true since you are converting string to %f and then back to string (because you selected a 2-d string array as your output).
Thanks, -
hi
i am having problems with my array declarations
import java.io.*;
public class bubbleSort4{
public static void main (String []args) throws IOException{
BufferedReader input=new BufferedReader (new FileReader("numbers.txt"));
for (int blah=0; blah<0; blah+=1 ){
int array1[];
array1[blah]=Integer.parseInt(input.readLine());
}//end of for
input.close();
bubbleSort4(array1);
}//end of main
public static void bubbleSort4(int[] array1) {
int newLowest = 0; // index of first comparison
int newHighest = array1.length-1; // index of last comparison
while (newLowest < newHighest) {
int highest = newHighest;
int lowest = newLowest;
newLowest = array1.length; // start higher than any legal index
for (int i=lowest; i<highest; i++) {
if (array1[i] > array1[i+1]) {
// exchange elements
int temp = array1; array1[i] = array1[i+1]; array1[i+1] = temp;
if (i<newLowest) {
newLowest = i-1;
if (newLowest < 0) {
newLowest = 0;
}//end of if
} else if (i>newHighest) {
newHighest = i+1;
}//end of else if
}//end of if
}//end of for
}//end of while
}//end method bubbleSort4
}//end of class
i get the error where i call the bubbleSort4 method with the array1 in brakets, it says that it doesnt recognize the variable. i know thats because i declared it in the for loop, but when i declare the array outside the for loop, it says that it was not initialized when i use it in the for loop. a vicious cycle. lol. so please, someone help....int array1[];you must initilize the array1
example :
int [] array1 = null;or
int [] array1 = new int [10];
for (int blah=0; blah<0; blah+=1 ){the codes will never go into the above for loop since
blah always >= 0; -
Array index problem in formula node
dear friend
I'm trying to use formula node to solve a problem because I make this program using c at the begining.
It runs perfectly in turbo c, but somehow it doesn't work in the formula node.
I try to debug my source code, and I find that the formula node seems can't read the true value in
the array.
Here is the code in the formula node.
int32 i,j,k;
for ( i = 0 ; i < sopa; i++ )
j = 1;
ep[i][0] = pa[i];
ep[i][1] = np[ep[i][0]][0];
while ( ep[i][j-1] != exit )
for ( k = 0 ; k < sonp ; k++ )
if ( np[ep[i][j-1]][k] != -1 && (pc[ep[i][j-1]][ep[i][j]] + pc[ep[i][j]][exit] >= pc[ep[i][j-1]][np[ep[i][j-1]][k]] + pc[np[ep[i][j-1]][k]][exit] ) && (pc[ep[i][j-1]][np[ep[i][j-1]][k]] == org[ep[i][j-1]][np[ep[i][j-1]][k]] ))
ep[i][j] = np[ep[i][j-1]][k];
j++;
This is the part that I think the problem might be.
if ( np[ep[i][j-1]][k] != -1 && (pc[ep[i][j-1]][ep[i][j]] + pc[ep[i][j]][exit] >= pc[ep[i][j-1]][np[ep[i][j-1]][k]] + pc[np[ep[i][j-1]][k]][exit] ) && (pc[ep[i][j-1]][np[ep[i][j-1]][k]] == org[ep[i][j-1]][np[ep[i][j-1]][k]] ))
ep[i][j] = np[ep[i][j-1]][k];
I state that "np[ep[i][j-1]][k] != -1" but I do get the value -1 in the array "ep".
Could someone tell me why I get -1 in the array?
I hope I can finally do it all by labview not using formula node,but array like "pc[ep[i][j-1]][np[ep[i][j-1]][k]] "
seems very hard to wire in labview. Could someone give me some good advices of doing this?
Thanks for your helpaltenbach 已寫:
normanshi wrote:
ep[i][0] = pa[i]; (A)
ep[i][1] = np[ep[i][0]][0]; (B)
... if ( np[ep[i][j-1]][k] != -1 && ... ) (C)
ep[i][j] = np[ep[i][j-1]][k]; (D)
I state that "np[ep[i][j-1]][k] != -1" but I do get the value -1 in the array "ep".
Could someone tell me why I get -1 in the array?
I hope I can finally do it all by labview not using formula node,but array like "pc[ep[i][j-1]][np[ep[i][j-1]][k]] "
seems very hard to wire in labview. Could someone give me some good advices of doing this?
There are many possible scenarios to get a -1 in the ep output. For example if the -1 gets already written in step (A) or (B) at a certain index, and that index does not get overwritten in step (D). You are indexing all over the place! Is there some bounds checking on the array contents? What are typical inputs and array sizes?
I'm sure about that the -1 doesn't get already written in step (A) or (B) because ep[i][0] and ep[i][1] is fine. What really makes me confuse is that sometimes ep array has the value like this.
That means it does overwritten some value in step (D). The -1 should never be written into it because I have already state that np[ep[i][j-1]][k] != -1. Somehow I still get -1,and this is really strange! I'm indexing all over the place becuase I can't figure out a better way to achieve my requirement.
I think I should briefly tell you what I'm trying to do. In this program,I input some values which means the distance from one point to another. Then I use floyd's all pairs shortest-path algorithm to find all the shortest distance. Finally I want to find out the "shortest path". I mean like from point 4 to point 0,the shortest path might be like 4 -> 2 -> 1 -> 0, and what the formula node part do is trying to find out this "shortest path". Maybe you can give me some better advice of doing this, I have been thinking a better way to do it for about two months. I think I'm really not good at this.
I try to do it all by labview ,but again I get a strange problem. This time the ep[i][j-1] doesn't get the correct value. In the first time i=0 j-1=0 ep[i][j-1] = 1,but the second time i = 0 j-1 = 1 ep[i][j-1] = 0. This makes the "ep[i][j-1]!=exit" get the incorrect boolean value. The ep[i][j-1] should be 2,not 0. I try to use highlight to find if I make any mistake, but I can't one.This is the input and I put the labview program in attached file (temp4.vi).
Could you help me find out why this happened?
Thanks for your help altenbach!
由 normanshi 在 08-19-2006 10:06 PM 上編輯的訊息
Attachments:
temp4.vi 191 KB
ep.jpg 10 KB
input.jpg 9 KB -
Control Array Access Problem while loading panel on 2 Tabs
I am using LabWindows CVI 10.0. My intention is to programmatically disable a control array in a panel.
Problem:
I am loading a panel with control array in TabControl pages - Tab0 and Tab1.
Error occurs, While programmatically accessing through below functions.
GetCtrlArrayFromResourceID( Tab0_panel, CTRLARRAY) - Able to get resource ID.
GetCtrlArrayFromResourceID( Tab1_panel, CTRLARRAY) - Not able to get resource ID.
Its giving error as Resource ID not found in UIR.
Error picture i have attached below for reference.
Please give some suggestions.
Solved!
Go to Solution.
Attachments:
Error.PNG 7 KBOk, if you didn't use it so far you should use it now : If you are accessing controls on a tab panel you have to use the correct panel handle using the function GetPanelHandleFromTabPage, you can not simply use the constant defined in your UIR.
Have a look at the example TabExample.cws for an example of this function. -
JRockit 1.4.2 array clone problem
JRockit 1.4.2 throws an IllegalAccessError on array cloning code produced by javac
-target 1.4.2. This seems to be the same problem as Sun's bug #4750641 (fixed
as of 1.4.1_01). JRockit 8.1 works okay. The problem also occurs with code produced
by a current version of IBM's jikes compiler.
To reproduce:
public class a {
public static void main(String[] args) {
new int[10].clone();
When compiled with "javac a.java", it works okay. When compiled with "javac -target
1.4.2 a.java", JRockit throws an IllegalAccessError.I can confirm this problem. We are working on a fix for the next service
pack. Thanks for the bug-report!
Regards,
/Staffan
Nathan Bronson wrote:
JRockit 1.4.2 throws an IllegalAccessError on array cloning code produced by javac
-target 1.4.2. This seems to be the same problem as Sun's bug #4750641 (fixed
as of 1.4.1_01). JRockit 8.1 works okay. The problem also occurs with code produced
by a current version of IBM's jikes compiler.
To reproduce:
public class a {
public static void main(String[] args) {
new int[10].clone();
When compiled with "javac a.java", it works okay. When compiled with "javac -target
1.4.2 a.java", JRockit throws an IllegalAccessError. -
ARRAY COPY DOESN'T WORK. DO NOT ATTEMPT TO USE IT IN YOUR REPLY TO THIS TOPIC. array copy says that you need the same type of object in the arrays. I'm making a method in a class called SUPERARRAYUTIL where this isn't the case. They all extend from a class i made called SUPERARRAY (in javacase caps tho, i just like to use upper case), but that doesnt help me. I'm short on time and i want to post this right now, so i won have any code right away but here is how i'm gonna do it:
1) Static method takes parameters superArray array, superArray newelements, and int start
2) Make a temp array that would be big enough to fit array, and the newelements at postion start in array
3) copy over array using a for loop, starting at 0 in temp.
4) copy over newelements using a for loop, starting at start in temp.
Then i will make non-static methods for superArrayUtil that will use the static methods in superArrayUtil. I will also make a method like System.arraycopy but will call a method called cut to trim the array of new elements and then call this arraycopy to copy it into the dest array, and then another non-static method for that method too.
Basically i just need ideas or comments cause so far i ran into some weird problems or any suggestions if there's a better way to copy arrays in the general way of array1 into array2 at a starting position.Deo_Favente wrote:
ARRAY COPY DOESN'T WORK.
YES. YES IT DOES. WHY DO YOU THINK THAT IT DOESNT WORK? WHY DON'T YOU POST WHATEVER CODE THAT YOU DO HAVE THAT IS CAUSING YOU PROBLEMS AND THEN MAYBE WE COULD WORK WITH IT. I THINK THAT'S A BETTER IDEA PERSONALLY, AT LEAST OPPOSED TO WHAT YOU DID HERE._+ -
Beginner : Array , String Problems continue.
Hi everybody I am so New in Java or rather not really able to understand Java yet.
I have assignment where I do not know how to think anymore..is probably very easy to those who understand programming but sadly I do not.
Program should do:
1. assign any amount of different strings.
2. user is giving any letter he/she wants and program to find it among given strings.
If searched letter is in any string/ strings , only these strings or string are printed.
3. If in given strings is not searched letter, program has to say it, for ex: there is not letter you search for.
As long as now I have only, strings assigning to array. So there are strings in array but I do not know how to write code where I can find given letter by user.
I just do not know how I should think(anymore at all ;)) here. I am really frustrated and desperate, how to understand this?? Once and for all!!!
I was thinking maybe I should use ArrayList? but how...or Can it be done both ways with Array or with ArrayList?
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("How many strings ?");
int antal= scan.nextInt();
String [] str = new String[antal];
String string = null;
int x;
scan.nextLine();
for( x=0;x<str.length;x++){
System.out.print("String "+(x+1)+": ");
string= scan.nextLine();
str[x]= string;
System.out.print("Write a letter you wish to find :");
String letter = scan.nextLine();
char check = letter.charAt(0);
//somthing in here ....Thank you very, very much for helping me, this is the first forum where I am getting any answers at all. Thanks guys!
Yes, that is true I have a problem to "see" things in code..I feel " lost in translation " :)...Sometimes I think I understand code and than suddenly code does total different thing than I thought. I have to pass 2 exams of Java basic and bit advance level of Java , all seems very dark now..but I have a hope that I at least pass those exams. Of course it could be fantastic to start understand Java (or any other computer language) and be able to code one day for real. To be honest, I envy you that you can understand Java. When, all code works is so cool and fun! ok, Back to code...
So I read your tips and advices , thanks.
Here is another problem, with help of indexOf(char) I got index for character I searched, fine.
The way i wrote the code I got separate answer for each string(check in code). What I need to have is, separate printed strings where given character is found and nothing else should be printed. Later, I need just one general comment ,only in case if character is NOT found in given strings.
import java.util.*;
public class upp9 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("How many strings ?");
int antal= scan.nextInt();
String [] str = new String[antal];
int x;
scan.nextLine();
for( x=0;x<str.length;x++){
System.out.print("String "+(x+1)+": ");
str[x]= scan.nextLine();
System.out.print("Write a letter you wish to find :");
String letter = scan.nextLine();
char check = letter.charAt(0);
for( x=0;x<str.length;x++){
str[x].indexOf(check);
// System.out.println("String "+(x+1)+" "+str[x].indexOf(check));
if((str[x].indexOf(check))>=0)
System.out.println("String "+(x+1)+" "+str[x]);
else
System.out.println("Nothing in this string");
System.out.println();
}is printed.
How many strings ?4
String 1: hello
String 2: other
String 3: alex
String 4: batman
Write a letter you wish to find :a
Nothing in this string
Nothing in this string
String 3 alex
String 4 batmanI should get printed (with other code)...where I don't know how to think here? what code I should use?, what I can what I can not do here...hmmm
//in case found
How many strings ?4
String 1: hello
String 2: other
String 3: alex
String 4: batman
Write a letter you wish to find :a
String 3 alex
String 4 batmanor....
//in case NOT found
How many strings ?4
String 1: hello
String 2: other
String 3: alex
String 4: batman
Write a letter you wish to find : j
Not found -
HI everyone I am looking for some help on an array problem.
I am reading in a text file that is in a line by line format eg.
apple
orange
pear
etc
The problem is that I want my array to increment each line. However each time a new line is read from the text file the array postion goes back to zero. Im assuming theres something wrong with my loop. Somebody please help!!!
String line;
String[] words;
int i;
try {
BufferedReader reader = new BufferedReader(new FileReader("wordlist.txt"));
while((line = reader.readLine()) != null){
words = line.split(" ");
for(i = 0; i < words.length; i++){
Arrays.sort(words);
//System.out.println(words);
if(findWord.equals(words[i])) {
Cap = "the word was found at position " + Arrays.binarySearch(words, words[i]);
test=true;
checkString();
reader.close();
I I read in
apple orange pear
carrot cucumber tomato
then apple[0] orange[1] pear[2]
but then this resets to 0 on new line i.e
carrot[0] cucumber[1] tomato[2]Correct me if Im wrong but I think I have created the
array out side the loop.Your original code declares the array outsid of the loop, but it doesn't create it. It just allocates a reference variable that will point to the aray.
Inside the loop, where you do words = split you're creating a new array each time. (And like I said, if there's only one word on a line, you don't need to spilt.)
As for putting the next
lines word into the array on each loop pass I do not
understand how to do this. Any help would be
appreciated?
for (int ix = 0; ix < numLines; ix++) {
arrar[ix] = the line that you just read
} Of course, if you're using the standard while (line != null) for loop control, then you can just skip the for part and create an index variable that you increment inside the body of the loop. -
How to flatten an array splice?
var foo:Array = [1, 2, 3 ];
var bar:Array = [9,10 ];
foo.splice(2, 0, bar) == [1,2,[9,10],3]
How can i splice in bar so i get a single flat result
[1,2,9,10,3]?
I know i could loop over bar and splice in each individual
member into foo, but is there a more efficient option?
Thank you.I'm not sure if this is more execution-time efficient, but
code-wise it's more succinct.
foo.splice.apply(foo, [2, 0].concat(bar)); -
Hi
Here's the situation, when replacing our broken raid drive it rebuilt the array, having rebuilt, it somehow messed up all the resource forks for the os9 files stored on it. We do have all the data backed up on tape but the backup system is windows based and failed to backup the resource forks as they weren't unix files.
Our main problem is quark files, I can open them on my mac using quark 6 as it's osx based, but I'm the only one in the company who has quark 6, is there any way of re-cxreating the resource forks so that they can be read by quark 4? Is there a nifty 3rd party piece of software that will scan a volume and rebuild all the resource forks for the os9 files - or am I just clutching at an impossible dream!!!!Think I've fixed it.
By adding a physical extention (.qxd) to the end of the quark file then opening it from within quark and not via double-clicking, it opens, once you save it from here the file is fine and the same as it was before.
For some reason, even with the .qxd extention it won't open in quark by double-clicking, only through the file menu. Also it won't work if you try this on an osx machine, only if you're booted in os9.
weird but it works. -
I'm sure this is a stupid question, but I'm not immensly knowledgeable about all the ins and outs of Java yet.
I have 2 arrays of 81 elements, one known as groups and one as tempGrps. I used the System.arraycopy(groups,0,tempGrps,0,81) to copy groups to tempGrps. The problem I am encountering is that when groups is modified after the arraycopy, the same modifications are made to tempGrps. I have a small routine in place that checks the contents of tempGrps. When the arraycopy command is in place, tempGrps has the modifications that are made to groups also made to it. When the command is not there, tempGrps remains empty(this was tested to make sure I wasn't somehow modifying it somewhere else). What is going on here? The entire reason for the tempGrps array was to hold a temporary backup of the groups array.Could you explain this please? I mean, when I say
MyObject = new
MyObject(objectToCopy);How do I end up with
the wrong type of Object?Easily: When objectToCopy is a MyCustomObject that is
derived from MyObject.I think I see what you're saying - though, by explicitly saying that (woops, forgot the reference name there) myObject is of type MyObject, it's obvious you wanted a MyObject out of that ctor call, and since MyCustomObject is a MyObject then I think it's a stretch to say you get the wrong object type back.
>
Disclaimer: I haven't really read the article yet and
don't feel strongly for either side of the argument,
that's just one problem I've spotted. -
Associative array related problem
Hi All,
When I am trying to use assotiative array in a select statement I recieve the following error:
ORA-06550: line 9, column 22:
PLS-00201: identifier 'COL1' must be declared
ORA-06550: line 9, column 22:
PLS-00201: identifier 'COL1' must be declared
ORA-06550: line 9, column 10:
PL/SQL: ORA-00904: : invalid identifier
ORA-06550: line 9, column 3:
PL/SQL: SQL Statement ignored
Here is the example
--create table MyTable (col1 varchar2(255), col2 varchar2(255))
declare
type m_ttMyTable
is table of MyTable%rowtype index by MyTable.col1%type;
m_tMyTable m_ttMyTable;
m_sCol2 varchar2(255);
begin
select m_tMyTable (col1).col2 /* works with ocntant: select m_tMyTable */('col1').col2
into m_sCol2
from MyTable
where rownum = 1;
end;
--drop table MyTableAny ideas how to workaround this?
ThanksThe only collection types SQL can query are ones defined in SQL using CREATE TYPE. That excludes associative arrays, as they are PL/SQL-only constructs. I'd recommend a nested table collection.
Some more suggestions:
www.williamrobertson.net/documents/collection-types.html -
Hashmap and array list problems
This is an assignment I have to do and I do NOT expect anyone to do the coding for me. I am just looking for some direction as I have no clue where to go from here. Any guidance would be very welcomed.
We were given code that used just an Array lisThis is an assignment I have to do and I do NOT expect anyone to do the coding for me. I am just looking for some direction as I have no clue where to go next. Any guidance would be very welcomed.
We were given code and told to "Modify the MailServer so that it uses a HashMap to store MailItems. The keys to the HashMap should be the names of the recipients, and each value should be an ArrayList containing all the MailItems stored for that recipient. " Originally it was just an ArrayList named messages. There is also a MailClient and MailItem class.
I think I can post the messages using the HashMap now, but can't test it. I get a compiler error saying else without if even though I have an if statement. Even if I can compile, I need to make sure I am on the right track with the getNextMailItem method. It is the one I am stuck on and if I can get it to work, I can probably modify the other methods.
I would really appreciate feedback on that one method.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
public class MailServer
// Storage for the arbitrary number of messages to be stored
// on the server.
private HashMap messages;
private ArrayList list;
private MailItem item;
* Construct a mail server.
public MailServer()
messages = new HashMap();
list = new ArrayList();
* Return the next message for who. Return null if there
* are none.
* @param who The user requesting their next message.
public MailItem getNextMailItem(String who)
Iterator it = list.iterator();
while(it.hasNext())
MailItem item = (MailItem)it.next();
if(messages.containsKey(who));
return item;
else
return null;
* Add the given message to the message list.
* @param item The mail item to be stored on the server.
public void post(String name, MailItem item)
if(messages.containsKey(name))
list = (ArrayList) messages.get(name);
else {
list = new ArrayList();
list.add(item);
messages.put(name, list);
}[The way I understand this is that MailItems are stored in per user ArrayLists, and that the ArrayLists are stored in the HashMap, and use the username as a key,
HashMap messages = new HashMap();
//ArrayList userMailItems = new ArrayList(); this should not be declared here, only the messages mapso given a User name, you need to get the list of mail items for that user out of the hashMap, and then return the next MailItem from the list. So given that, you don't even need to Iterate over the list:
public MailItem getNextMailItem(String who)
ArrayList list = (ArrayList)messages.get(who);
if(list == null || list.size() == 0)
return null;
//now we get the next item from the list, we can call remove, since it returns the object we are removing.
MailItem item = (MailItem)list.remove(0);
return item;
}
Maybe you are looking for
-
Passing variable into pdf document
I have created a pdf document that I want to share with my marketing team. However, in the document I want the url to be dynamic and show that individual's url. For example, if my domain is www.xyz123abc.com In the pdf, I want to setup the url i
-
安装Firefox4后,访问带有在线音乐播放器的页面时,提示"插件Windows Media Player Plug-in Dynamic Link Library已崩溃了",插件版本(3.0.2.629)已经是最新版,如何解决?谢谢!
-
How to display the dataset field values in my ssrs bar chart report ?
HI i have a Bar Chart report in that i want to display the dataset one field values in my x-axis of my ssrs report? so how should i display those values into my bar chart report? consider i want to display the Every Qtrly details in my x-axis so how
-
Since the 10.6.2 update, when I do a reastart or cold startup on my 13" MacBook Pro, everything looks normal, desktop appears, menu bar with Finder appears, but then for 2 or 3 minutes, I can't do anything. I keep my Dock, hidden, and it won't slide
-
Missing Attendance Query.
HI, I have two tables 1. attendance 2. Emp In attendance table i have the following colums Emp_no ,date,Present_flag In emp table emp_no How to find the missing attendance...... for eg: if i pass 01-JUN-10 to 30-JUN-10 as parameter i need to get emp_