Search Results

Search found 2563 results on 103 pages for 'collections'.

Page 20/103 | < Previous Page | 16 17 18 19 20 21 22 23 24 25 26 27  | Next Page >

  • Hibernate inserting into join table

    - by Karl
    I got several entities. Two of them got a many-to-many relation. When I do a bigger operation on these entities it fails with this exception: org.hibernate.exception.ConstraintViolationException: could not insert collection rows: I execute the operation i a @Transactional context. I don't do any explicit flushing i my daos. The flush is triggered by a query. In the queue are 15 elements (all of the same structure). one of them always fails (but it's always a different one (I checked) and always at a different position). Does anybody have a hint for me for what I might do wrong? My Mapping: @ManyToMany(targetEntity = CategoryImpl.class) protected Set<Category> categories = new HashSet<Category>();

    Read the article

  • Are upper bounds of indexed ranges always assumed to be exclusive?

    - by polygenelubricants
    So in Java, whenever an indexed range is given, the upper bound is almost always exclusive. From java.lang.String: substring(int beginIndex, int endIndex) Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1 From java.util.Arrays: copyOfRange(T[] original, int from, int to) from - the initial index of the range to be copied, inclusive to - the final index of the range to be copied, exclusive. From java.util.BitSet: set(int fromIndex, int toIndex) fromIndex - index of the first bit to be set. toIndex - index after the last bit to be set. As you can see, it does look like Java tries to make it a consistent convention that upper bounds are exclusive. My questions are: Is this the official authoritative recommendation? Are there notable violations that we should be wary of? Is there a name for this system? (ala "0-based" vs "1-based")

    Read the article

  • C++ vector of char array

    - by Stuart
    I am trying to write a program that has a vector of char arrays and am have some problems. char test [] = { 'a', 'b', 'c', 'd', 'e' }; vector<char[]> v; v.push_back(test); Sorry this has to be a char array because I need to be able to generate lists of chars as I am trying to get an output something like. a a a b a c a d a e b a b c Can anyone point me in the right direction? Thanks

    Read the article

  • How to detect if collection contain instance of specific type?

    - by KentZhou
    Suppose I create collection like Collection<IMyType> coll; Then I have many implelentations of IMyTypem like, T1, T2, T3... Then I want know if the collection coll contains a instance of type T1. So I want to write a method like public bool ContainType( <T>){...} here the param should be class type, not class instance. How to write code for this kind of issue?

    Read the article

  • Is HashMap in Java collision safe

    - by changed
    Hi I am developing a parser that needs to put key value pairs in hashmap. But a key can have multiple values which i can do in this way HashMap<String,ArrayList<String>> . But what happens if number of keys are very large and it start matching with other key's hashcode. Will that rewrite previous key's value ? thanks -devSunday

    Read the article

  • Accessing a struct collection property from within another collection

    - by paddyb
    I have a struct that I need to store in a collection. The struct has a property that returns a Dictionary. public struct Item { private IDictionary<string, string> values; public IDictionary<string, string> Values { get { return this.values ?? (this.values = new Dictionary<string, string>()); } } } public class ItemCollection : Collection<Item> {} When testing I've found that if I add the item to the collection and then try to access the dictionary the structs values property is never updated. var collection = new ItemCollection { new Item() }; // pre-loaded with an item collection[0].Values.Add("myKey", "myValue"); Trace.WriteLine(collection[0].Values["myKey"]); // KeyNotFoundException here However if I load up the item first and then add it to a collection the values field is maintained. var collection = new ItemCollection(); var item = new Item(); item.Values.Add("myKey", "myValue"); collection.Add(item); Trace.WriteLine(collection[0].Values["myKey"]); // ok I've already decided that a struct is the wrong option for this type, and when using a class the issue doesn't occur, but I'm curious what's different between the two methods. Can anybody explain what's happening?

    Read the article

  • How to delete duplicate/aggregate rows faster in a file using Java (no DB)

    - by S. Singh
    I have a 2GB big text file, it has 5 columns delimited by tab. A row will be called duplicate only if 4 out of 5 columns matches. Right now, I am doing dduping by first loading each coloumn in separate List , then iterating through lists, deleting the duplicate rows as it encountered and aggregating. The problem: it is taking more than 20 hours to process one file. I have 25 such files to process. Can anyone please share their experience, how they would go about doing such dduping? This dduping will be a throw away code. So, I was looking for some quick/dirty solution, to get job done as soon as possible. Here is my pseudo code (roughly) Iterate over the rows i=current_row_no. Iterate over the row no. i+1 to last_row if(col1 matches //find duplicate && col2 matches && col3 matches && col4 matches) { col5List.set(i,get col5); //aggregate } Duplicate example A and B will be duplicate A=(1,1,1,1,1), B=(1,1,1,1,2), C=(2,1,1,1,1) and output would be A=(1,1,1,1,1+2) C=(2,1,1,1,1) [notice that B has been kicked out]

    Read the article

  • how to selectively filter items in a collection

    - by Samuel
    I use the following snippet to filter the list of selected users, where isSelected is a boolean variable. Is there a simpler way (helper function) to populate the selectedUsers collection instead of writing the following lines of code. List<User> selectedUsers = new ArrayList<User>(0); for (User user : this.getUsers()) { if (user.isSelected()) { selectedUsers.add(user.getId()); } }

    Read the article

  • Java 7 API design best practice - return Array or return Collection

    - by Shengjie
    I know this question has be asked before generic comes out. Array does win out a bit given Array enforces the return type, it's more type-safe. But now, with latest JDK 7, every time when I design this type of APIs: public String[] getElements(String type) vs public List<String> getElements(String type) I am always struggling to think of some good reasons to return A Collection over An Array or another way around. What's the best practice when it comes to the case of choosing String[] or List as the API's return type? Or it's courses for horses. I don't have a special case in my mind, I am more looking for a generic pros/cons comparison.

    Read the article

  • What is the most popular generic collection data structure library for C?

    - by Tom Dalling
    I'm looking for a C library that provides generic collection data structures such as lists, associative arrays, sets, etc. The library should be stable and well tested. I'm basically looking for something better than the crappy C standard library. What C libraries fit this description? EDIT: I'd prefer that the library was cross-platform, but failing that, anything that works on Mac/Linux.

    Read the article

  • C# type safe and developer friendly list/collection technique

    - by Agile Noob
    I am populating a "Dictionary" with the results of an sp call. The key is the field name and the value is whatever value the sp returns for the field. This is all well and good but I'd like developers to have a predefined list of keys to access this list, for safety and documentation reasons. What I'd like to do is have something like an enum as a key for the dictionary so developers can safely access the list, but still have the ability to access the dictionary with a string key value. I am hoping to have a list of string values that I can access with an enum key AND a string key. Please make sure any suggestions are simple to implement, this is not the kind of thing I'm willing to build a lot of overhead to implement.

    Read the article

  • Use LINQ, to Sort and Filter items in a List<ReturnItem> collection, based on the values within a Li

    - by Daniel McPherson
    This is tricky to explain. We have a DataTable that contains a user configurable selection of columns, which are not known at compile time. Every column in the DataTable is of type String. We need to convert this DataTable into a strongly typed Collection of "ReturnItem" objects so that we can then sort and filter using LINQ for use in our application. We have made some progress as follows: We started with the basic DataTable. We then process the DataTable, creating a new "ReturnItem" object for each row This "ReturnItem" object has just two properties: ID ( string ) and Columns( List(object) ). The properties collection contains one entry for each column, representing a single DataRow. Each property is made Strongly Typed (int, string, datetime, etc). For example it would add a new "DateTime" object to the "ReturnItem" Columns List containing the value of the "Created" Datatable Column. The result is a List(ReturnItem) that we would then like to be able to Sort and Filter using LINQ based on the value in one of the properties, for example, sort on "Created" date. We have been using the LINQ Dynamic Query Library, which gets us so far, but it doesn't look like the way forward because we are using it over a List Collection of objects. Basically, my question boils down to: How can I use LINQ, to Sort and Filter items in a List(ReturnItem) collection, based on the values within a List(object) property which is part of the ReturnItem class?

    Read the article

  • Collection type generated by for with yield

    - by Jesper
    When I evaluate a for in Scala, I get an immutable IndexedSeq (a collection with array-like performance characteristics, such as efficient random access): scala> val s = for (i <- 0 to 9) yield math.random + i s: scala.collection.immutable.IndexedSeq[Double] = Vector(0.6127056766832756, 1.7137598183155291, ... Does a for with a yield always return an IndexedSeq, or can it also return some other type of collection class (a LinearSeq, for example)? If it can also return something else, then what determines the return type, and how can I influence it? I'm using Scala 2.8.0.RC3.

    Read the article

  • How to create collection object in vbscript?

    - by Onnesh
    what should be the parameter for create object the following code dim a set a=CreateObject("Collection") //getting a runtime error saying ActiveX //component can't create object: 'Collection a.add(CreateObject("Collection")) a.Items(0).Add(1) MsgBox(a.Items(0).count) MsgBox(a.Items(0).Item(0))

    Read the article

  • Connection and Collection Interfaces in Java

    - by Bhupi
    Which class implements all the Connection Interfaces which are in javax.microedition.io package and how? And in the same way which class implements the some of Collection interfaces like Iterator interface. I saw a code: - Iterator it; ArrayList list = new ArrayList(); it = list.iterator(); The iterator() return type is "Iterator" which is an interface. Please tell me what this code is doing is it returning an object of type Iterator? but as far as I know, interface can't be initialized.

    Read the article

  • Bind to a collection's view and just call ToString() in WPF

    - by womp
    I'm binding a GridView to a collection of objects that look like this: public class Transaction { public string PersonName { get; set; } public DateTime TransactionDate { get; set; } public MoneyCollection TransactedMoney { get; set;} } MoneyCollection simply inherits from ObservableCollection<T>, and is a collection of MyMoney type object. In my GridView, I just want to bind a column to the MoneyCollection's ToString() method. However, binding it directly to the TransactedMoney property makes every entry display the text "(Collection)", and the ToString() method is never called. Note that I do not want to bind to the items in MoneyCollection, I want to bind directly to the property itself and just call ToString() on it. I understand that it is binding to the collection's default view. So my question is - how can I make it bind to the collection in such a way that it calls the ToString() method on it? This is my first WPF project, so I know this might be a bit noobish, but pointers would be very welcome.

    Read the article

  • Custom ASP.net UserControl List<T> Property, having trouble setting declaratively

    - by Chris McCall
    I'm developing a custom UserControl to inject JQuery hotkeys into a page declaratively on the server side. Here's the control (the important parts anyway): [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal), DefaultProperty("HotKeys"), ParseChildren(true, "HotKeys"), ToolboxData("<{0}:HotKeysControl runat=\"server\"> </{0}:HotKeysControl>")] public partial class HotKeysControl : System.Web.UI.WebControls.WebControl { private string crlf = Environment.NewLine; public List<HotKey> _HotKeys; public HotKeysControl() { if (_HotKeys == null) { _HotKeys = new List<HotKey>(); } // if I uncomment this line, script is injected into the page // _HotKeys.Add(new HotKey("ctrl+r","thisControl")); } [ Category("Behavior"), Description("The hotkeys collection"), DesignerSerializationVisibility( DesignerSerializationVisibility.Content), Editor(typeof(HotKeyCollectionEditor), typeof(UITypeEditor)), PersistenceMode(PersistenceMode.InnerDefaultProperty) ] public List<HotKey> HotKeys { set { _HotKeys = value; } get { return _HotKeys; } } Here's the .aspx code: <%@ Register Assembly="MyCompany.ProductName.WebControls" Namespace="MyCompany.ProductName.WebControls" TagPrefix="uc" %> ... <uc:HotKeysControl ID="theHotkeys" runat="server" Visible="false"> <uc:HotKey ControlName="firstControl" KeyCode="ctrl+1" /> <uc:HotKey ControlName="thirdControl" KeyCode="ctrl+2" /> </uc:HotKeysControl> Nothing happens, as if no HotKeys objects are being added to the property collection. What Am I doing wrong? If I uncomment out the line above and "manually" add items, it works. It's something about how I'm declaratively adding hotkeys to the page. Any ideas?

    Read the article

  • Can I have a set containing identical elements?

    - by Roman
    It is convenient for me to use a set. I like how I can "add" ("remove") an element to (from) the set. It is also convenient to check if a given element is in the set. The only problem, I found out that I cannot add a new element to a set if the set has already such an element. Is it possible to have "sets" which can contain several identical elements.

    Read the article

  • How to pop items from a collection in Java?

    - by Tom Brito
    Is there a method in JDK or apache commons to "pop" a list of elements from a java.util.List? I mean, remove the list of elements and return it, like this method: public Collection pop(Collection elementsToPop, Collection elements) { Collection popped = new ArrayList(); for (Object object : elementsToPop) { if (elements.contains(object)) { elements.remove(object); popped.add(object); } } return popped; }

    Read the article

< Previous Page | 16 17 18 19 20 21 22 23 24 25 26 27  | Next Page >