Browsing 7239 questions and answers with Jon Skeet

Java order TreeMap by value descending using Collections.reverseOrder()

I'd like to sort an existing TreeMap (or copy the values from a Map into a TreeMap, doesn't matter) in an descending order, sorted by value (Doubles). I know there are a lot of...
Jon Skeet
people
quotationmark

You can use the fact that a LinkedHashMap will retain insertion order - so specify a supplier in the toMap call so that it will create a LinkedHashMap appropriately: .collect(Collectors.toMap( Map.Entry::getKey, ... more 12/10/2015 1:49:47 PM

people

Run a .jar file on Unix always resolves in a NoClassDefFoundError Exception

I am working on a little java program which I want to run on a unix machine. First, I compiled the .java file without any errors. javac CallACMDFromJAVA.java Then my .class...
Jon Skeet
people
quotationmark

Your class is apparently in a package serviceCall. Ideally, you should make your source directory structure match the package structure, so you have the source file in a directory called serviceCall. Even without that, if you compile it... more 12/10/2015 1:21:42 PM

people

Parsing JSON Object with variable properties into strongly typed object

{ "Profile": { "dProperty1": { "a": "value", "b": "value", "c": "value", "d": "value", "e": "value" }, "dProperty2": { ...
Jon Skeet
people
quotationmark

I would parse the whole tree as a JObject, and then call ToObject<> on appropriate sub-objects. Sample code: using System; using System.IO; using System.Linq; using Newtonsoft.Json.Linq; class Example { public string Name {... more 12/10/2015 1:07:45 PM

people

Include concatenation operator ( + ) with in the string in java

I am encrypting a text containing User Information in java using "AES" algorithm and appending it to the url,(which will be sent to the customer to have access to the...
Jon Skeet
people
quotationmark

But the problem i am facing is , since the encrypted text include "+" ,Java i treating it as a concatenation operator That sounds very, very unlikely to me. It wouldn't explain why you're getting a space, either. Instead, this sounds... more 12/10/2015 10:43:06 AM

people

Tomcat 8 MySQL at most 8 connections seen in MySQL Workbench from each tomcat instace

Problem: JDBC connection pool does not seem to have the desired number of initial connections. It also does not grow to the maximum allowed (at most 8 connections appear to be...
Jon Skeet
people
quotationmark

It sounds like you just need to set the maxTotal configuration option too, e.g. maxTotal="50" I say this based on the DBCP configuration documentation: Parameter: maxTotal Default: 8 Description: The maximum number of active... more 12/10/2015 10:31:58 AM

people

XML XElement and loops

Please help me to fix the piece of code that results in this xml output. The elements called "Frequency" and "ScheduleType" are all being stuck under the first element of...
Jon Skeet
people
quotationmark

This statement is the problem: test.Element("NBUConfig") .Element("Policies") .Elements("Policy").Last() .Elements("Schedules").Last() .Element("Schedule") .Add(new XElement(("SchedulesStuff"), (scount))); You're... more 12/10/2015 9:37:20 AM

people

Create dynamic object with public properties

I am trying to create an object that is created inline but i want to acces the properties i create inside like the folowing: object x = new { text = "one", text2 = "two" }; if...
Jon Skeet
people
quotationmark

Use var as the type of your variable instead: var x = new { text = "one", text2 = "two" }; Console.WriteLine(x.text); // Fine, and suggested by Intellisense Console.WriteLine(x.text1); // Compile-time error Note that this isn't really... more 12/10/2015 9:09:58 AM

people

Separate functions into validation and implementation? Why?

I was reading a C# book in which the author (some dude named Jon Skeet) implements a Where function like public static IEnumerable<T> Where<T> ( this...
Jon Skeet
people
quotationmark

The reason is that the iterator block is always lazy. Unless you call GetEnumerator() and then MoveNext(), the code in the method won't get executed. In other words, consider this call to your "equivalent" method: var ignored =... more 12/9/2015 7:04:12 PM

people

ObjectInputStream End of file exception ignores print statements

I'm reading a file from a Google glass device to a PC through a java socket. The rest of my code is being ignored due to an eof exception thrown by a catch statement. An ideas how...
Jon Skeet
people
quotationmark

The output you've shown indicates that this line is working: System.out.println("infrom: " + inFromServer.readObject() + "\n"); And this line is throwing an exception: System.out.println("infrom bytes: " + inFromServer.readByte() +... more 12/9/2015 5:03:53 PM

people

How can singleton hamper testability

I read that singletons is bad for testability. Can you elaborate on this. Can't a singleton be mocked? They write due to tight coupling but I can't see to seem why.
Jon Skeet
people
quotationmark

It depends on how you're using the singleton and whether that singleton implements an interface. If the fact that it's a singleton is an implementation detail, then that's probably okay. If you're using its singleton nature in the code you... more 12/9/2015 11:17:24 AM

people