w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
java garbage collection does a <(major collection:mark and sweep> every time it does a
I would try removing all the settings you have so that you have the absolute minimum and you are less likely to get a strange interaction between settings Try just -Xmx16g -XX:+UseConcMarkSweepGC and monitor it using jstat

Categories : Java

Create a collection of sub collection from a given Collection (Group By) in Java
Probably this is what you need until java 8 closures comes HashMap<Integer, DateTileGrid> dataGridMap = new HashMap<>(); for (Date date: dateList) { int year = date.getYear(); //Deprecated.. use something better DateTileGrid dataGrid = dataGridMap.get(year); if(dataGrid == null){ dataGrid = new DateTileGrid(); dataGrid.setCurrentYear(year); dataGrid.setDateTiles(new ArrayList<Date>()); dataGridMap.put(year, dataGrid); } dataGrid.getDateTiles().add(date); } //Here is your result ArrayList<DateTileGrid> result = new ArrayList<>(dataGridMap.values());

Categories : Java

Returning a Collection from a method that specifies that it returns Collection
Reason for the error The reason the exception is raised is because Collection<ParentClass> can have any object that extends ParentClass added to it. For example an instance of the following class could be added to it public class OtherChildClass extends ParentClass{ } But because the "real" collection is a Collection<ChildClass> this would raise an error. Or even if you added a ParentClass to it it would raise an error. All in all not good. Solution This can be solved however by using Collection<? extends ParentClass> in your type declaration. The meaning of this is that you are returning a Collection that is declared as containing some class that could be cast to ParentClass and is called contravariance. Such a collection cannot have new objects added to it (with the

Categories : Java

Hibernate deletes Lazy loaded many-to-many collection when a get call is made on the collection
I guess this is causing an issue private Set<Role> roles = new HashSet<Role>(0); @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinTable(name = "USERROLEMAP", joinColumns = { @JoinColumn(name = "USERID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "ROLEID", nullable = false, updatable = false) }) public Set<Role> getRoles() { return this.roles; } It should be private Set<Role> roles; @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinTable(name = "USERROLEMAP", joinColumns = { @JoinColumn(name = "USERID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "ROLEID", nullable = false, updatable = false) }) public Set<Role> getRoles() { if(roles

Categories : Java

Linq query to get filtred main collection and each list in result in that collection
This should be done in View Model (or Dto) layer, first, define your view models: public class RestaurantVM { public int Id { get; set; } public string Name { get; set; } public City City { get; set; } public List<MealVM> Meals { get; set; } } public class MealVM { public int Id { get; set; } public string Name { get; set; } public DateTime Date { get; set; } public int Price { get; set; } public int Number { get; set; } public int Kind { get; set; } } Then you can write LINQ like below: var restaurantVMs = db.Restaurants .Include(rest => rest.Meals) .Where(rest => rest.City.Name == city) .AsEnumerable() .Select(r => new RestaurantVM(){

Categories : C#

Convert scala.collection.immutable.Vector to java.util.Collection
You need to call asJavaCollection to do the conversion, this should work: import scala.collection.JavaConverters._ var attrDefs = Vector(new AttributeDefinition(), new AttributeDefinition()) request.setAttributeDefinitions(attrDefs.asJavaCollection) As an alternative, you can use import scala.collection.JavaConversions._ to not have to call asJavaCollection. However, I find that it makes what the code is doing more readable to call the method. Here's the alternate example: import scala.collection.JavaConversions._ var attrDefs = Vector(new AttributeDefinition(), new AttributeDefinition()) request.setAttributeDefinitions(attrDefs)

Categories : Java

Wrong collection.length when passing JSON array to Backbone Collection
If you dump one of the items returned by Google Spreadsheets, you will see that the data is nested in multiple objects, something like this { "id":{"$t":"https://spreadsheets.google.com/feeds/list/..."}, "updated":{"$t":"2013-07-30T12:01:24.000Z"}, "category":[{"scheme":"...","term":"..."}], "title":{"type":"text","$t":"ACIW"}, "content":{}, "link":[{"rel":"self","type":"application/atom+xml","href":"..."}] } In a Fiddle http://jsfiddle.net/nikoshr/kHBvY/ Note how the id property is wrapped in an object "id":{"$t":"https://spreadsheets.google.com/feeds/list/0AjbU8ta9j916dFdjSVg3YkNPUUJnWkZSWjBDWmZab3c/1/public/basic/cokwr"} Backbone collections don't allow duplicates and duplicates are determined based on their id. All your items are considered duplicates and

Categories : Javascript

Backbone.js - extending a model(in collection) using parse method not getting the updated collection
That is because the response in done is not a Collection. It is just an object from the response.. Log c which is an updated collection c.done(function(data){ console.log(c); //Will be the updated collection }) Also listening to the event is a cleaner approach than using promised methods. initialize: function() { this.$el.html(this.template); this.c = collection; this.listenTo(this.c, 'sync', this.logCollection); this.c.fetch(); //fetching the data }, logCollection: function() { console.log(this.c); // This will log the collection }

Categories : Jquery

Meteor.js: having multiple subscriptions on one collection enforce storage results in one local collection(Workarounds?)
If you want your client side collection to have a different name from the server side collection you can not just return a collection cursor. This can be done in the publish function though like this: Meteor.publish("details", function (id) { //details here matches the subscribe request var self = this; self.added( "details", id, collection.findOne({_id: id}); //details here tells the client which collection holds the data self.ready(); }); This will not be reactive but can be made that way by using observe as in the counts by room example at http://docs.meteor.com which is explained in detail here How does the messages-count example in Meteor docs work?. While this answers your question of how to get a specific name for a collection without having that collection on the serv

Categories : Meteor

linq query Unable to create a constant value collection within collection
Try this. This will remove the groups list from the LINQ query, but if your groupId is a Guid and a user can have multiple groups you will be sending a really big list of guids to the query. List<Group> groups = new UserBiz().Groups(AchaAuth.CurrentUserId); var groupsIds = groups.Select(i => i.GroupId).ToList(); var result = from HeadsupArticle article in ctx.HeadsupArticles where article.GroupId == item.GroupId && article.Active && (!article.DisplayFor || (article.DisplayFor && article.Groups.Any(g => g.GroupId == Guid.Empty || groupsIds.Contains(g.GroupId)

Categories : Linq

Removing from collection based on values from another collection - Lambda/Linq
Removal has to be done with foreach (as LINQ isn't supposed to alter collections), but other than that you can fetch unwanted brands and then items to remove from carlist1 with LINQ: var carlist2Brands = carlist2 .GroupBy(c => c.Brand) .Select(g => g.Key) .ToArray(); var carsToRemove = carlist1 .Where(c => carlist2Brands.Contains(c.Brand)) .ToArray(); foreach (var car in carsToRemove) { carlist1.Remove(car); }

Categories : C#

Can't bring content_id through to list of collection and then add to a collection ruby on rails
There is a RailsCast on how to properly do this : http://railscasts.com/episodes/163-self-referential-association Hope it helps someone out there!

Categories : Ruby On Rails

RequireJs Backbone error Collection is not a constructor when creating new Collection
Javascript is case sensitive the variable names used in the definition files are local to the definition, they won't be available when required (if you do things correctly and don't write on the global namespace), you define names for your modules, which probably will lead to problems down the road This means that CollectorCollection won't be available globally, and that in require(["collectorCollection"], function (collectorCollection) { } your collection is actually available as collectorCollection : note the lowercase c. So, your require call could be written as require(["backbone", "underscore", "collectorCollection", "collectorRouter"], function (Backbone, _, CollectorCollection, CollectorRouter) { var collectors = new CollectorCollection(); var router = n

Categories : Backbone Js

"Value does not fall in expected range" List collection and not in Observable collection
Only thing which bugs me out here is "RaisePropertyChanged" is used with ObservableCollection or at least you must inherit INotifyPropertyChanged interface. In your second implementation list is not getting "RaisePropertyChanged" method. Consider list declaration as: private List<User> _Users; public List<User> Users { get { return _Users; } set { _Users = value;} } I think this should resolve the error. But NOTE that doing so will not raise PropertyChanged event whenever the state of the object changes (Added, Removed, and Modified) to the point where you want to notify the underlying collection or container that the state has changed. For more info read: List vs ObservableCollection vs INotifyPropertyChanged in Silverlight

Categories : C#

Sorting an IEnumerable collection with a virtual field of that collection
My problem was occurring because I had not set initialized lazy loading and so the virtual properties were always being returned as nil. I overcame this problem by adding the following line of code to my ViewModel: this.dbcontext.Configuration.LazyLoadingEnabled = true; Within the View itself I also had a series of nested queries for some of the more complex models and had to add the following segment to the connection string: MultipleActiveResultSets=True";

Categories : Misc

How to watch for changes in collection objects inside custom collection
the item class has to implement INotifyPropertyChanged then you have two options: save the list (parent) in the child class (item) and on item propertychange you call a certain method or when you add an item to your list you add its NotifyPropertyChanged Event. I would go that way. List: public listclass() { this.ListChanged += new ListChangedEventHandler(listclass_ListChanged); } void listclass_ListChanged(object sender, ListChangedEventArgs e) { if (e.ListChangedType == ListChangedType.ItemAdded) { item item = this[e.NewIndex]; item.PropertyChanged += new PropertyChangedEventHandler(Item_PropertyChanged); } } void Item_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "propertyname") { } } item implements INo

Categories : C#

Include related data from second collection in collection.find
Don't use $regex unless its a direct (with the mongodb $regex) syntax. This should work: searchFoo = function(query) { var re = new RegExp(query, "i"); return FooCollection.find({ name: re }); }; as should this: searchFoo = function(query) { return FooCollection.find({ name: { $regex: query, $options: "i" } }); }; Additionally to link up your bar query do a transform instead of regex: FooCollection.find({name:"SOMENAME"}, {transform:function(doc) { if(doc.barId) doc.bar = FooCollection.findOne(doc.barId) return doc; }}); This should give you the result (after a fetch or if you parse through the cursor) [{ name: SOMENAME, barId: MONGO_ID, bar : { name: ANOTHERNAME} }] More information about transforms can be found in the meteor do

Categories : Meteor

How do you sort a parent collection and child collection of entities?
You can't sort inner collection (because you can't assign result of sorting to parent.Children property), but you can return anonymous objects with sorted parents and sorted children without including children in parent entity: return (from parent in m_Context.Parents orderby parent.Name select new { Parent = parent, Children = parent.Children.OrderBy(c => c.ChildInformation.Name) }).ToList(); Or retrieve parents and sort children in memory.

Categories : Misc

How to remove each item that appears in first collection from second collection using linq?
This does what you need var solution = list1.Except(list2); You can find more details about Except here, but the basic idea is: This method returns those elements in first that do not appear in second. It does not also return those elements in second that do not appear in first.

Categories : C#

How do I write a JPA query that checks if a collection has at least one item in another collection?
According to this answer, you can use Expression#in() method in this way, provided that you use a basic property as argument to the in expression: Join<User, Role> rolesJoin = user.join("roles"); List<Integer> rolesIds = new ArrayList(); for (Role role : roles) { rolesIds.add(role.getId()); } criteria.where(rolesJoin.get("id").in(rolesIds)); Hopefully there are also other ways to make it work, but I haven't found any other, yet.

Categories : Hibernate

Scala convert Iterable or collection.Seq to collection.immutable.Seq
Use the to method to convert between arbitrary collection types in Scala 2.10: scala> Array(1, 2, 3).toSeq res0: Seq[Int] = WrappedArray(1, 2, 3) scala> Array(1, 2, 3).to[collection.immutable.Seq] res1: scala.collection.immutable.Seq[Int] = Vector(1, 2, 3)

Categories : Scala

Cast Collection to Collection fail
Yes, you have to iterate and cast each member. The reason for this is that Collection<RootData> is not a superclass of Collection<SpecialData>. Actually I recommend this: Collection<SpecialData> collSpecData = //... Collection<RootData> collRootData = //empty constructor collRootData.addAll(collSpecData);

Categories : Java

mongodb - add column to one collection find based on value in another collection
In MongoDB, the simplest way is probably to handle this with application-side logic and not to try this in a single query. There are many ways to structure your data, but here's one possibility: user_document = { name : "User1", postsIhaveLiked : [ "post1", "post2" ... ] } post_document = { postID : "post1", content : "my awesome blog post" } With this structure, you would first query for the user's user_document. Then, for each post returned, you could check if the post's postID is in that user's "postsIhaveLiked" list. The main idea with this is that you get your data in two steps, not one. This is different from a join, but based on the same underlying idea of using one key (in this case, the postID) to relate two different pieces of data. In gene

Categories : Mongodb

Code optimization - Excel VBA Collection and collection sorting
To make your code clean and manageable, one of the way would be to think Object Oriented way and create Class Module in your VBA Excel. Example: Class Module Name : Anniversary Content: Public EmployeeName as string Public EmployeeDate as Date Public YearsInEY as string In your Module code, create new object for class and assign the values Dim oTodayAnniversary as new Anniversary oTodayAnniversary.EmployeeName = value oTodayAnniversary.EmployeeDate = value oTodayAnniversary.YearsInEY = value Use the above collection to print on new sheet. You can even create single collection, to populate all data, by adding a Enum flag to Anniversary Class module, which will identify the Category type.

Categories : Excel

How can I access other elements of a Collection when doing render: collection?
It can be done like this: = render :partial => "user", :collection => @users, :locals => { :users => @users} You will then have access to @users.

Categories : Ruby On Rails

Bind a collection inside a collection in WPF combobox
well if you need each ComboBoxItem to display a collection of strings, use an ItemsControl in the ItemTemplate of ComboBox. <ComboBox ItemsSource="{Binding work}"> <ComboBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text={Binding a} /> <TextBlock Text={Binding b} /> <ItemsControl ItemsSource="{Binding c}" /> </StackPanel> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox>

Categories : C#

Passing a collection of a subclass as collection of superclass
Your UserDefinedAction may be an Action, but a List<Subclass> is not a List<Superclass>. As you have defined it, your setOnCompleteAction method must take a List<Action>, so it cannot accept a List<UserDefinedAction>.

Categories : Java

Bind DropDownList to a collection in a collection of Objects
I'd just use a Linq Select to set up an anonymous object: dropDownList.DataSource = myObjectList .Select(item => new { Title = item.Properties["Title"] }) .ToList(); dropDownList.DataValueField = "Title";

Categories : C#

re-arranging a collection list based on another collection
Pipe your results through WITH and then order them. Then do the aggregation via RETURN as normal. START n=node(*) MATCH p=n-[r:LIKES]->items WITH n,r,items ORDER BY r.w DESC RETURN n,collect(r.w),collect(items.name);

Categories : Neo4j

Retrieve Backbone Collection from Model and keep it as a Collection
Instead of putting your collection into another model, you should put it in the according view: var ListView = new Backbone.View.extend({ initialize:function(){ this.Elements= new Elements(); // more stuff to go }, render:function(){ _.forEach(this.Elements, function(){ //Do rendering stuff of indivdual elements and get HTML }); //put HTML in the DOM } }); There is no need of a model containing a collection containing several models. Edit: And instead of putting your app into a Model, you should put it into a view.

Categories : Javascript

Nested collection created as array instead of collection
Look at the note about reverseRelation and using coffeescript (from: http://backbonerelational.org/#relations-reverseRelation): Note that if you define a relation (plus a reverseRelation) on a model, but don't actually create an instance of that model, it is possible initializeRelations will never get called, and the reverseRelation will not be initialized. This can happen when extend has been overridden, or redefined as in CoffeeScript. See setup. Then try using .setup as described here: http://backbonerelational.org/#RelationalModel-setup

Categories : Backbone Js

Extract particular elements from an existing Collection and put it into a new Collection
Well, if I understand the question correctly, you could do something like this: for(final Object[] result : results) myObjects.add((MyObject)result[0]); Or if you are using Java 8, you could try something like this: results.forEach(result -> myObjects.add((MyObject)result[0]));

Categories : Java

Backbone Collection inside Collection
The method is Available in the DesignModel and not in DesignCollection So when you call this method, it searches for the method inside the Collection which is not present that leads to the error. Also why do you want to bind the events using jQuery when you have an option of handing the same using Native Backbone events To solve this add the method to the collection define(['backbone', 'models/design'], function(Backbone, DesignModel){ var designCollection = Backbone.Collection.extend({ model: DesignModel, addElement: function(element, options) { return this.add(element, options); } }); return designCollection; });

Categories : Jquery

Collection was modified when adding to collection
Try this instead: var lsEvents = form.Event.Links.ToList(); foreach (var resource in form.Links) { resource.EventID = form.Event.ID; if (!assignedIds.Contains(resource.ResourceTypeID)) lsEvents.Add(resource); } foreach (var resource in form.Event.Links) { if (!selectedIds.Contains(resource.ResourceTypeID)) lsEvents.Remove(resource); } and Use lsEvents according to the requirement. This will fix your issue.

Categories : C#

How to update collection data for collection of ids?
You can use each_with_index in combination with update for this: ids.each_with_index do |id, index| User.update(id, :fruit_name, fruit_names[index]) end The above code assumes: ids = [1,2,3,4] fruit_names = ["a","b","c","d"] and that the indexes of those arrays match. Note that this will execute a query for each item in your ids array. If your ids array is very big this is not going to perform well.

Categories : Ruby On Rails

Backbone, get a Collection by collection ID (not RESTful)
When you construct the Collection, pass the id as parameter (by default, Collection do not have an id property while Model do). Then, override the url property of the Collection and pass a function: MyCollection = Backbone.Collection.extend({ initialize : function(models, options) { this.id = options.id; }, model : // Your Model class url: function() { return '/api/categories/?id=' + this.id; } }); // [] is the initial, empty set of models var coll = new MyCollection([], { id: 45 }); coll.fetch(); // the correct url will be called

Categories : Backbone Js

Better way to move MongoDB Collection to another Collection
You could use a MapReduce job for this. MapReduce allows you to specify a out-collection to store the results in. When you hava a map function which emits each document with its own _id as key and a reduce function which returns the first (and in this case only because _id's are unique) entry of the values array, the MapReduce is essentially a copy operation from the source-collection to the out-collection. Untested code: db.runCommand( { mapReduce: "mongo_collection", map: function(document) { emit(document._id, document); }, reduce: function(key, values) { return values[0]; }, out: { merge:"mongo_his_collection" } }

Categories : Mongodb

Reaching to Collection that each item of it is a Collection
I suspect you just want: var beds = rooms.SelectMany(room => room.Beds); (That's assuming there's a Beds property in Room. You're not using it in the original code snippet.) If the rooms were fetched without the bed details, you may need else - please let us know.

Categories : C#

Iterating over a collection without generating the collection first
Represent your collection as a generator object with methods to advance to next logical element, to get current element, and to compare current element with the end element. Then either use Boost Iterator Facade, http://www.boost.org/doc/libs/1_54_0/libs/iterator/doc/index.html#iterator-facade-and-adaptor (see their examples) or implement your own: http://www.cplusplus.com/reference/iterator/iterator/

Categories : C++

How to select a sub collection available in a list of collection
Use SelectMany to get all locations and Distinct to make them distinct: Dim distinctLocations = entityProvider.GetProducts(). SelectMany(Function(p) p.Locations). Distinct()

Categories : Dotnet



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.