Browsing 15836 questions and answers with Jon Skeet

How to Sort a list of strings and find the 1000 most common values in java

In java (either using external libraries or not) I need to take a list of approximately 500,000 values and find the most frequently occurring (mode) 1000. Doing my best to keep...
Jon Skeet
people
quotationmark

I'd separate this into three phases: Count word occurrences (e.g. by using a HashMap<String, Integer>) Sort the results (e.g. by converting the map into a list of entries and ordering by value descending) Output the top 1000... more 7/19/2017 3:34:55 PM

people

JObject contains a C# keyword how to access it?

I am using the JQuery QueryBuilder plugin on my site, which compiles it's data into JSON. On the server side code, I take the JSON that is returned from the plugin and parse it...
Jon Skeet
people
quotationmark

You can use @ to use a keyword as an identifier, so this should work: string _operator = item.@operator; Alternatively, you may well find that indexer access would be fine: string _operator = item["operator"]; more 7/19/2017 3:06:19 PM

people

Add the XAttribute to XElement if attribute exists in the element

Need to add XAttribute newatt = new XAttribute("TAG", value); to XElement elem, but the elem could already contain the attribute with the name "TAG", so the elem.Add(newatt);...
Jon Skeet
people
quotationmark

You don't need to check whether the attribute already exists before using SetAttributeValue. Just: // Unconditional elem.SetAttributeValue("TAG", value); (There's no point even creating the XAttribute yourself.) From the... more 7/19/2017 10:39:54 AM

people

Need help understand VB conditional logic and find equivalent in java

I have a legacy project in Visual basic that needs to be converted to java. I cant understand the following line... If lastSendToggle And 128 Then ... where lastSendToggle is...
Jon Skeet
people
quotationmark

The operation x & 128 will never result in 1 for any value of x, because it's a bitwise operation. It will always either be 128 or 0, depending on whether that bit is set in x or not. (Note that 128 decimal = 10000000 binary, so... more 7/19/2017 10:27:13 AM

people

Is LocalDateTimeDeserializer from jsr310 deserializing zulu dates correctly?

I have an angular/spring boot application, on client side I'm using a primeng calendar input component, which takes the local date and converts it to UTC zoned date-time. I then...
Jon Skeet
people
quotationmark

No, it's doing the right thing IMO. A LocalDateTime isn't "local to the server", it's "not in any specific time zone". If you've got a text value which indicates a date/time and any sort of time zone indicator (e.g. an offset from UTC or... more 7/18/2017 11:05:12 AM

people

Get index of value in hashset C#

Is it possible to retrieve index of value in HashSet ? I have a hashset: HashSet<int> allE = mesh.GetAllNGonEdges(nGonTV); And I would like to retrieve index of value...
Jon Skeet
people
quotationmark

The "index" is meaningless in a HashSet - it's not guaranteed to be the same as the insertion order, and it can change over time as you add and remove entries (in non-guaranteed ways, e.g. if you add a new entry it could end up in the... more 7/18/2017 9:03:51 AM

people

Why is the date format different for the same culture on different computers or OS?

I have problem with date formate while hosting site which is developed using C# .net MVC . In my development machine(OS:Windows 7, .net Framework 4.5) date formate for...
Jon Skeet
people
quotationmark

Why format is different in different machine for same culture? Because formats are updated over time, in different OS releases and in patches/hotfixes. .NET is fetching the format from the OS (I believe, anyway), so it's the OS that's... more 7/18/2017 8:55:16 AM

people

DynamicInvoke throws Parameter count mismatch

I'm lost and feel I may be going crazy. In the below code, TestGetCountry() works just fine but TestGetState() throws the "Parameter count mismatch" exception. I'm lost as to why...
Jon Skeet
people
quotationmark

string[] is convertible to object, so this line: string actual = (string) action.DynamicInvoke(args); ... is invoking the delegate with two arguments. You want this: string actual = (string) action.DynamicInvoke((object) args); ...... more 7/17/2017 4:31:59 PM

people

Limit inheritance of intermediate abstract class

I have an abstract class, CreatureBehaviour, that provides a TakeTurn method. The goal of this is to decide what the creature should do, and it should provide its response via...
Jon Skeet
people
quotationmark

There's nothing you could do for this in a "normal" way, but there's one option you could consider... If you give your CreatureBehavior class just a private constructor, then nest PlayerBehavior and NonPlayerBehavior within that class,... more 7/16/2017 7:18:26 PM

people

C# equivalent of { }.Contains() in VB

I'm working on a VB = C# translator, and I've run across some VB code that I'm not sure has a direct translation to C#. In VB you can do something like If {"a", "b",...
Jon Skeet
people
quotationmark

If all the array elements will be the same type, or if they're different types but in a way that satifies type inference, you can use an implicitly typed array - like var but for arrays, basically: if (new[] { "a", "b", "b"... more 7/15/2017 7:53:48 AM

people