List with multiple Iterators - result predictible?
Hi,
I have a situation where a list is used by two Iterators:
List a;
Iterator i1 = a.iterator();
while (i1.hasNext()) {
Object o1 = i1.next();
Iterator i2 = a.iterator();
while (i2.hasNext()) {
Object o2 = i2.next();
// do something to "o2" - modify or remove through i2.remove()
I have seen other discussions, but my impression is it's mostly "Hash" or "Tree" that has a un-predictible result, or even clearer - fast-failing. For a List, it seems to me what would happen is quite certain (e.g. if the inner iterator removes an object, that object would be gone from the collection, but the outer iterator would still hold a reference to it, thus still be able to access it). However, in Java API, Iterator.remove() method has notes saying it's "unspecified" for all modifications unless using that particular method correctly.
I think this is designed on purpose, but don't know why. Any thoughts?
Thanks,
An Iterator.delete() has the spec:
public void remove()
Removes from the underlying collection the last element returned by the iterator (optional operation). This method can be called only once per call to next. The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.
So when in your example the second iterator modifies the underlying collection it breaks the first instance iterator behavior which has then an unpredictable result.
Using a List.iterator() seems to change nothing :
public Iterator iterator()
Returns an iterator over the elements in this list in proper sequence.
Specified by:
iterator in interface Collection
Returns:
an iterator over the elements in this list in proper sequence.
So you code isn't garanty to run as you quote it running. The i2 is safe not i1 if you use i2.remove().
I did this test:
List v1 = new Vector();
v1.add("1");
v1.add("2");
v1.add("3");
Iterator i1 = v1.iterator();
while (i1.hasNext()) {
Object o1 = i1.next(); // At second iteration I got a ConcurrentModificationException here.
Iterator i2 = v1.iterator();
while (i2.hasNext()) {
i2.next();
i2.remove();
System.out.println(o1);
That's a typical unexpected results because hasNext() answered true but next() failed.
Now if your question is why this spec, I dunno, I could only guess that the purpose of Iterator generic interface is to allow to have efficient implementation at price of non concurent modification access.
Similar Messages
-
How to select value from list with multiple selections ?
HI,
i have a list with multiple selections where i show email address retrieved from database.
what i want to do is to send the selected email address to the invoiceedit.jsp.
please look at the following code which gives you the better idea.
<td class='smalltext'><select name="email" size="3" multiple="multiple">
<%
Connection conn = null;
Statement stmt = null;
Statement stmt_contactperson = null;
Statement stmt_address = null;
try{
conn = getREConnection();
stmt = conn.createStatement();
ResultSet rs = null;
rs = stmt.executeQuery("SELECT PROPERTYID, VALUE FROM PROPERTIES WHERE ENTITYID="+ g_strGroupID+" AND NAME = 'invoice_default_email'");
int numofrows = 0;
while(rs.next())
%>
<option value="<%= rs.getString("VALUE") %>" selected="selected"> <%= rs.getString("VALUE") %> </option>
<%
}//end of while
%>
</select>
<a href="invoiceedit.jsp?entityid=<%=g_strGroupID%>&add=1"><font color="#000000">Add</font></a>
<a href="invoiceedit.jsp?entityid=<%=g_strGroupID%>&email_to="><font color="#000000"> Edit</font></a> </td>thanksUse a form button instead of a link so that you can send it as a request parameter to the server. In the server side just use HttpServletRequest#getParameterValues() to obtain all values for the given parameter name. If you really need a link rather than a button, then use Javascript to submit the form on click of the link.
That said, your design is bad. Java code belongs in Java classes, not in JSP files. Database access logic belongs in a DAO class. Business and controlling logic belongs in a Servlet class. Only presentation logic belongs in the JSP file. Avoid scriptlets as much as possible and use JSP EL and/or JSTL instead. -
[svn:fx-trunk] 10943: Fix to dragging from List with multiple-selection
Revision: 10943
Author: [email protected]
Date: 2009-10-08 15:46:27 -0700 (Thu, 08 Oct 2009)
Log Message:
Fix to dragging from List with multiple-selection
- The fix is to postpone the selection commit until we make sure the user has not started a drag gesture.
- Exclude the dragEnabled, dropEnabled, dragMoveEnabled properties for DropDownList
QE notes: None
Doc notes: None
Bugs: None
Reviewer: Deepa
Tests run: checkintests, mustella List, DropDownList
Is noteworthy for integration: No
Modified Paths:
flex/sdk/trunk/frameworks/projects/spark/src/spark/components/DropDownList.as
flex/sdk/trunk/frameworks/projects/spark/src/spark/components/List.as -
Creating Select List with multiple columns
I want to create a select list with multiple columns. I followed the demo application model described in the by Denes Kubicek (Currently my reference for APEX !!)
The code is as follows:
CREATE OR REPLACE FUNCTION getcrops(p_cropid IN NUMBER)
RETURN VARCHAR2
IS
v_cropid VARCHAR2 (400);
v_fcode VARCHAR2 (400);
v_product VARCHAR2 (400);
v_var VARCHAR2 (400);
v_fname VARCHAR2 (400);
v_acres VARCHAR2 (400);
v_style_start VARCHAR2 (400);
v_style_end VARCHAR2 (400);
v_return VARCHAR2 (400);
BEGIN
FOR c IN (select "CROP"."CROPID" as "CROP ID",
"CROP"."FIELDCODE" as "FIELD CODE",
"CARROTPRODUCTLIST"."CARROTPRODUCTNAME" as "PRODUCT",
"VARIETYLIST"."VARIETYNAME" as "VARIETY",
"FIELD"."FIELDNAME" as "FIELD NAME",
"CROP"."SIZEINACRES" as "ACRES"
from "FIELD" "FIELD",
"CARROTPRODUCTLIST" "CARROTPRODUCTLIST",
"VARIETYLIST" "VARIETYLIST",
"CROP" "CROP"
where "CROP"."CARROTPRODUCTTYPE"="CARROTPRODUCTLIST"."CARROTPRODUCTID"
and "CROP"."VARIETYID"="VARIETYLIST"."VARIETYLISTID"
and "CROP"."FIELDID"="FIELD"."FIELDID")
LOOP
v_cropid := TO_CHAR (c.'CROP ID', 'FML999G999G999G999G990');
v_fcode := c.'FIELD CODE';
v_product := c.'PRODUCT';
v_var := c.'VARIETY';
v_fname :=c.'FIELD NAME';
v_acres :=c.'ACRES';
FOR i IN 1 .. 12 - LENGTH (c."CROP ID")
LOOP
v_cropid := v_cropid || ' ';
END LOOP;
FOR i IN 1 .. 12 - LENGTH (c.'FIELD CODE')
LOOP
v_fcode := v_fcode || ' ';
END LOOP;
FOR i IN 1 .. 12 - LENGTH (c.'PRODUCT')
LOOP
v_product := v_product || ' ';
END LOOP;
FOR i IN 1 .. 12 - LENGTH (c.'VARIETY')
LOOP
v_var := v_var || ' ';
END LOOP;
FOR i IN 1 .. 12 - LENGTH (c.'FIELD NAME')
LOOP
v_fname := v_fname || ' ';
END LOOP;
FOR i IN 1 .. 12 - LENGTH (c.'ACRES')
LOOP
v_acres := v_acres || ' ';
END LOOP;
v_return := v_cropid || v_fcode || v_product || v_var || v_fname || v_acres;
END LOOP;
RETURN v_return;
END;
I created this anonymous Pl/SQL function at a application level ..Then I followed up to create a select list with a function inside. However I could not create select list with the command suggested in the demo which is
select getcrops(cropid) d, cropid r from crop;
APEX (2.1) returns a error message. What am I missing ? Should the function be called from somewhere else after creating a regular select list..? Where the functions (Pl/SQL) should be ideally stored for application level access..? and for across application level access ? How can I check the function works good. Help is appreciated.Still really one column.
If they need to be independent then you've got to have three selection lists.
% -
Selection list with multiple columns
How can i create a selection list with multiple columns?
Still really one column.
If they need to be independent then you've got to have three selection lists.
% -
Select list with multiple columns
I want to create a select list with multiple column option. What are the options. Any developments in apex 3.0.1 ? Thanks in advance. I tried the tutorials by Kubicek.
I am kind of stuck to see the function entry inside LOV definition returns a error.Still really one column.
If they need to be independent then you've got to have three selection lists.
% -
Hi,
Is it possible can we have a List with multiple Object (CustomerVO, OrderVO and AddressVO) in a single List? If so how we will define the generics for that List?
Please clarify.
Thanks.797836 wrote:
Guys, am I correct? Please clarify.If it works, it is correct. So try it.
I was more thinking along the line of this though according to what you described in your initial post:
Class ParentVO{
private CustomerVO customer;
private OrderVO order;
private AddressVO address;
// with getters and setters
}That way you don't need any list at all, if you only want to have access to these three objects. Just slap them in a ParentVO and use that.
Looking at it again I wonder if the ParentVO is needed even, there is a strong relationship between these three objects. An order has a customer and a customer has an address / an order has a billing/shipping address... -
Hello;
I seek a code to implement a list with multiple selection for a browser Web (HTML is imited).
I have a list containing of the years, the user can select one or several years and I created dynamically a array : for each year a column.
Thank you;Look at JList.
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JList.html
� {� -
hello all ,
how to create a list with multiple columns ? can anyone share some examples or code snippetsWhat I would usually do is create a movieclip/sprite that contains a row with every column in it (each column being a textfield). Then pile up the rows one atop the other (using Actionscript) as they are populated with data.
-
How can I create a XMP List with multiple selection
Hello,
I try to build my own XMP custom panel. Herefore I need a couple of lists with the possibility for multiple selections (e.g. the choice for one language or multiple languages).
But how is it possible to integrate a list into a panel? There is no XMPList inside the custom folder. I have experimented with the standard mx:list and an array collection for data binding into the list. But how can I write the user selection into an XMP field? Example: In the List the user choose three languages (DE, EN, FR). Is it possible to collect the choice into a string and to write the result into an XMP standard field (e.g. dc:description)?
A further question is, if it's possible to use the "HTTPService" to bind an external xml-file with the languages and other informations into the panel or is it only possible to work with an array collection inside the code?
Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<fi:XMPForm
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:fi="com.adobe.xmp.components.*" width="100%" height="100%"
xmlns:Iptc4xmpCore ="http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/"
label="XMP-Custom Panel"
initialize="ds.send()"
>
<!-- Each namespace prefix that is used within an xmpPath-attribute,
MUST BE registered at the top of EACH panel where it is referenced -->
<fi:XMPNamespaces>
<fi:XMPNamespace prefix="dc" value="http://purl.org/dc/elements/1.1/"/>
</fi:XMPNamespaces>
<fi:XMPForm>
<mx:HBox width="100%" height="26" verticalAlign="middle">
<mx:HRule width="50%"/>
<mx:Label text="Allgemeine Metadaten" fontSize="12" fontWeight="bold"/>
<fi:XMPSeparator width="50%"/>
</mx:HBox>
<fi:XMPFormItem
label="Titel"
labelTooltip="$$$/xmp/sdk/custompanels/Test/TitleToolTip=Dateiname" fontSize="11" width="100%">
<fi:XMPTextInput xmpPath="dc:title" xmpType="Localized" width="100%"/>
</fi:XMPFormItem>
<fi:XMPFormItem
label="Titel"
labelTooltip="$$$/xmp/sdk/custompanels/Test/TitleToolTip=Dateiname" fontSize="11" width="100%">
<fi:XMPTextInput xmpPath="dc:title" xmpType="Localized" width="100%"/>
</fi:XMPFormItem>
<fi:XMPFormItem
label="Druckkennzeichen"
labelTooltip="$$$/xmp/sdk/custompanels/Test/TitleToolTip=Dateiname" fontSize="11" width="100%">
<fi:XMPTextInput xmpPath="dc:title" xmpType="Localized" width="100%"/>
</fi:XMPFormItem>
<fi:XMPFormItem
label="Verfasser"
labelTooltip="$$$/xmp/sdk/custompanels/Test/TitleToolTip=Erzeuger des Dokumentes" fontSize="11" width="100%">
<fi:XMPComboBox xmpPath="dc:creator" width="100%"/>
</fi:XMPFormItem>
<fi:XMPFormItem
label="Versionsnummer"
labelTooltip="$$$/xmp/sdk/custompanels/Test/TitleToolTip=Dateiname" fontSize="11" width="100%">
<fi:XMPComboBox xmpPath="dc:creator" width="100%"/>
</fi:XMPFormItem>
<mx:HBox width="100%" height="26" verticalAlign="middle">
<mx:HRule width="50%"/>
<mx:Label text="Enthaltene Sprachen" fontSize="12" fontWeight="bold"/>
<fi:XMPSeparator width="50%"/>
</mx:HBox>
<!-- Beginn der Auswahl-Liste für die Sprachen -->
<mx:Script>
<![CDATA[
import flash.events.MouseEvent;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
private const NL:String = "\r";
// A data provider created by using ActionScript
[Bindable]
private var subscriptions:ArrayCollection =
new ArrayCollection
{data:0, label:"Deutsch"},
{data:1, label:"Englisch"},
{data:2, label:"Französisch"},
{data:3, label:"Italienisch"}
[Bindable]
private var market:ArrayCollection =
new ArrayCollection
{data:0, label:"(Bitte Marktversion auswählen)"},
{data:1, label:"Marktversion Deutsch (M_DE)"},
{data:2, label:"Marktversion Englisch (M_EN)"},
{data:3, label:"Marktversion Frankreich (M_FR)"},
{data:4, label:"Marktversion Italien (M_IT)"}
[Bindable]
private var documenttyp:ArrayCollection =
new ArrayCollection
{data:0, label:"(Bitte Dokumenttyp auswählen)"},
{data:1, label:"Gebrauchsanweisung"},
{data:2, label:"Ersatzteilkatalog"},
{data:3, label:"Service-Anleitung"},
{data:4, label:"Etikett"}
]]>
</mx:Script>
<fi:XMPFormItem label="Sprachauswahl" width="100%">
<mx:List
id="userSubscriptions" rowCount="4"
allowMultipleSelection="true" width="100%"
dataProvider="{subscriptions}"
/>
</fi:XMPFormItem>
<mx:Text text="* Mehrfachauswahl möglich." fontWeight="normal" fontSize="10"/>
<!-- Ende der Liste für die Auswahl von Sprachen -->
<fi:XMPFormItem
label="Marktvariante"
labelTooltip="$$$/xmp/sdk/custompanels/Test/TitleToolTip=Dateiname" fontSize="11" width="100%">
<fi:XMPComboBox xmpPath="dc:creator" width="100%" dataProvider="{market}"/>
</fi:XMPFormItem>
<fi:XMPFormItem
label="Dokumenttyp"
labelTooltip="$$$/xmp/sdk/custompanels/Test/TitleToolTip=Dateiname" fontSize="11" width="100%">
<fi:XMPComboBox xmpPath="dc:creator" width="100%" dataProvider="{documenttyp}"/>
</fi:XMPFormItem>
<fi:XMPFormItem
label="Stichworte"
labelTooltip="$$$/xmp/sdk/custompanels/Test/TitleToolTip=Erzeuger des Dokumentes" fontSize="11" width="100%">
<fi:XMPTextArea/>
</fi:XMPFormItem>
<mx:HBox width="100%" height="26" verticalAlign="middle">
<mx:HRule width="50%"/>
<mx:Label text="Metadaten Photoshop" fontSize="12" fontWeight="bold"/>
<fi:XMPSeparator width="50%"/>
</mx:HBox>
<fi:XMPFormItem
label="Originalname FA"
labelTooltip="$$$/xmp/sdk/custompanels/Test/TitleToolTip=Dateiname" fontSize="11" width="100%" id="PS1">
<fi:XMPTextInput xmpPath="dc:title" xmpType="Localized" width="100%"/>
</fi:XMPFormItem>
<fi:XMPFormItem
label="Fotoauftragsnummer"
labelTooltip="$$$/xmp/sdk/custompanels/Test/TitleToolTip=Dateiname" fontSize="11" width="100%" id="PS2">
<fi:XMPTextInput xmpPath="dc:title" xmpType="Localized" width="100%"/>
</fi:XMPFormItem>
<fi:XMPFormItem
label="Interne Anmerkungen"
labelTooltip="$$$/xmp/sdk/custompanels/Test/TitleToolTip=Erzeuger des Dokumentes" fontSize="11" width="100%" id="PS3">
<fi:XMPTextArea/>
</fi:XMPFormItem>
<mx:Text text="* hier steht eine kleine Erläuterung" fontWeight="normal" fontSize="10"/>
</fi:XMPForm>
</fi:XMPForm>
Any suggestions?
Thank you in advance.
MarkusHi Markus,
the FileInfo SDK does not offer a ready-made list component allowing for multi-selection.
So you would need to implement one using the FileInfo SDK API. Your component "XMPList" would inherit from mx:list and would need to implement the XMPRead and XMPWrite events and talk to the XMP using the IXMPAccess interface within those event handlers.
Please have a look at the Programmer's Guide, section "XMP Flex components" and at the API description available in "docs" for further guidanc.
Hope this helps
Kind Regards
Jörg
Adobe XMP -
Applescript list with multiple selections
Hello guys, i have h big problem...
i was trying the multiple selections part by the command list, but if i select 2- and more it does nothing (i'm using if x is y then *linebreake* else if ...)
so i tried another way script:
tell application "Finder"
--get folders of me--
set a to get name of folders of folder "Contents:Resources:Versionen" of (path to me) --in this folder i got folders named {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}--
set b to choose from list a with prompt "Choose your Minecraft Version!" with multiple selections allowed
--next step--
count b
set c to result
repeat c times --with this part i wanted to handle every selected folder as an individual to duplicate it somewere else
set ab to b * -1
duplicate folder ab to folder (choose folder)
end repeat
end tell
thanks for helping meThe following script (tested under OS X 10.8.2) should do what you are asking for:
tell application "Finder"
set theSourceFolder to folder "Contents:Resources:Versionen" of (path to me)
set theFolderNames to get name of folders of theSourceFolder
set theChosenNames to choose from list theFolderNames with prompt "Choose your Minecraft Version!" with multiple selections allowed
if result is false then return
set theDestinationFolder to choose folder
repeat with thisName in theChosenNames
duplicate folder thisName of theSourceFolder to theDestinationFolder with replacing
end repeat
end tell
Message was edited by: Pierre L. -
ABAP list with multiple headers
Hi experts,
i have to display a table with multiple headers. Example:
Header 1 = Sales order header
Header 2 = Sales order items
It's possible to create an ABAP list with 2 headers?
Thanks in advance.Hi Dan,
FYI .
[ALV Grid with Multiple Headers;
Regards
Abhii -
How to make an editable bulleted list with multiple lines and custom bullets?
How do I create an editable bulleted list in Acrobat Pro? I've figured out how to add text fields with multiple lines, and how to add a list box, but I don't see the check box for multiple lines in the list box or how to add bullet points. Can someone please give me step by step instructions? Also is it possible to use custom bullet points?
Is it a text field or a list box field? The two are not the same...
The bullets are something that the user will have to enter manually (into a text field, they can only select values in a list-box).
They can use any unicode character, or special characters if the font used for that field allows for it. You can't use images for the bullets, if that's what you mean. -
Extended access list with multiple ports
Hello All,
I have a problem with my Cisco Catalyst 4503-E when i try to configure an extended access lists with multipleports.
I receive the following message:
The informations of my Switch are the following:
Cisco IOS Software, Catalyst 4500 L3 Switch Software (cat4500-IPBASE-M), Version
12.2(52)SG, RELEASE SOFTWARE (fc1)
Please help me to resolve this problem.
Best regards.Thank you Alex for your response.
Yes, this is an example:
permit tcp 192.168.1.0 0.0.0.255 host 192.168.2.1 eq 135 389 636 445 3268 3269 domain 88
I have more ACLs and each ACL contains more conditions with multiples Por -
In my project I am using SharePoint Online 2013 and there is a custom list with two content types. While creating a new item in that list, can we show the content type drop down list along with other columns? While editing an item I am able to view the content
type dropdown in the edit form associated with the list. Can we enable the same for the default newform as well?In my project I am using SharePoint Online 2013 and there is a custom list with two content types. While creating a new item in that list, can we show the content type drop down list along with other columns? While editing an item I am able to view the content
type dropdown in the edit form associated with the list. Can we enable the same for the default newform as well?
Maybe you are looking for
-
Hi SRM Gurus I have the following requirement in SRM,Please tell me how to modify the SRM shipping cart Modify SRM Functionality 1. Modify the SRM functionality to support an embedded form requiring additional informations like Material Descri
-
how does an database implement index to accelerate findings of like where name>"b" and name<"f" and location>"r" and location<"t" in disk files? e.g I have a file,which can't fit into memory ,contains records of a corporation employee info in fomat l
-
Failed in downloading files printed CreatePDF
The CreatePDF started failing in downloading files printed from Quick Books. Why is that? How can I fix it?
-
What I have is a field that I want 5 acceptable entries, and only those entries able to be submitted. So if the acceptable entry is dog and someone enters cat, I want to force an error. Anyone want to show me how easy it is?
-
After update to ff10 widnows lose focus when migrating to a different window. tried all possible options and still the same even after recent update to 11. Any suggestions?