collections

Java Collections.shuffle() weird behaviour [closed]

风流意气都作罢 提交于 2019-12-23 01:59:49
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I am experiencing something weird. I have a big ArrayList of Long numbers. It contains about 200k numbers in ascending order. These numbers are always distinct; they are not necessarily consecutive, but some groups of them usually are. I want to extract a sorted sample of 5k from this list, so basically this is my

Java Collections.shuffle() weird behaviour [closed]

笑着哭i 提交于 2019-12-23 01:59:03
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I am experiencing something weird. I have a big ArrayList of Long numbers. It contains about 200k numbers in ascending order. These numbers are always distinct; they are not necessarily consecutive, but some groups of them usually are. I want to extract a sorted sample of 5k from this list, so basically this is my

C# Extension method for AddItem to IEnumerable<T>

心已入冬 提交于 2019-12-23 01:48:37
问题 What is the best way to add an item to IEnumerable collection using Extension method? 回答1: enumerable.Concat(new[]{ objToAdd }) 回答2: You cannot (directly). The purpose of the interface is to expose an enumerator. Edit : You would have to convert the IEnumerable to another type (like a List ) or concatenation to add, which would result not in adding to an existing IEnumerable , but concatenating to a new IEnumerable instead. The only option would be to test if the if it implements any of the

Create array (collection) of buttons from existing buttons

折月煮酒 提交于 2019-12-23 01:43:13
问题 is there a simple way of creating a button collection from the existing buttons on my form? (In c#). I have a series of buttons already on my form and I want to use an index to access them...e.g.: myButtonArray[0].ForeColor ...// Do something with it Can this be done? Edit: Can I set the array to have a generic OnClick event? And then determine which button in the array was clicked and, say, change its color? 回答1: You can do it the same way as for any other array. For example: Button[] array

Questions with different types of answer in NHibernate

本小妞迷上赌 提交于 2019-12-23 01:06:28
问题 I'm trying to find a tidy solution to a questionnaire problem. Let us say that I have a Questionnaire class which has a collection of Answer s, e.g. public class Questionnaire { public virtual ISet<Answer> Answers {get;set;} } Answers need to be of different types depending on the question, e.g. date of birth, marks out of ten, why do you think etc. My first thought was something like this: public class Question { public virtual QuestionType TypeOfQuestion {get;set;} public virtual string

How to nest collection routes?

妖精的绣舞 提交于 2019-12-22 18:24:08
问题 I use the following routes configuration in a Rails 3 application. # config/routes.rb MyApp::Application.routes.draw do resources :products do get 'statistics', on: :collection, controller: "statistics", action: "index" end end The StatisticController has two simple methods: # app/controllers/statistics_controller.rb class StatisticsController < ApplicationController def index @statistics = Statistic.chronologic render json: @statistics end def latest @statistic = Statistic.latest render json

Creating a custom collection that can be bound to a DataGrid

六月ゝ 毕业季﹏ 提交于 2019-12-22 17:47:21
问题 I work for an Architecture firm and I am creating a plug-in for a 3D modeling program to assist design. I have a Building class, and a Floor class. The building contains a reference to a FloorList collection of floors. I'm trying to figure out what to base the FloorList collection off of so that I can minimize the amount of work I need to do to create an interface to edit the collection. The Floor collection represents a series of building floors that are stacked on top of one another. Each

HashMap and garbage collection: do I need to call clear() before variable re-assignment?

℡╲_俬逩灬. 提交于 2019-12-22 13:58:40
问题 Maybe it's a silly question but I'm not sure about the garbage collection process. Consider this code: private HashMap<String, Parameter> configuration = new HashMap<String, Parameter>(); ... //add some items to configuration ... //now get another configuration HashMap<String, Parameter> parameters = new HashMap<String, Parameter>(); for (String parameterName : configurationParameterNameList) { parameters.put(parameterName, reader.readParameter(parameterName)); } //and reassign the variable

Check Duplicate File content using Java

女生的网名这么多〃 提交于 2019-12-22 13:57:28
问题 We have a 150 Gb data folder. Within that, file content is any format (doc, jpg, png, txt, etc). We need to check all file content against each other to check if there are is duplicate file content. If so, then print the file path name list. For that, first I used ArrayList<File> to store all files, then used FileUtils.contentEquals(file1, file2) method. When I try it for a small amount of files(Folder) it's working but for this 150Gb data folder, it's not showing any result. I think first

collection item() vs array []

倖福魔咒の 提交于 2019-12-22 13:53:13
问题 Apologies if this is a duplicate - it is not easy to search for. I have today come across TWO questions using someArrayOrCollection.item(i) instead of my preferred someArrayOrCollection[i] Example: parse XML attribute value using javascript var sTitle1 = item.getElementsByTagName("title").item(0).... where I would use var sTitle1 = item.getElementsByTagName("title")[0].... Last time I saw these where when only IE supported that notation. My first instinct when I see .item() is to correct it