Browsing 7239 questions and answers with Jon Skeet

JodaTime: Get DateTimeZone with offset xyz compared to utc

I want to use org.joda.time.DateTime. It need the following params: DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int...
Jon Skeet
people
quotationmark

If you know the offset, you can use DateTimeZone.forOffsetMillis to create a fixed-offset time zone. That won't necessarily be the real time zone, but the offset alone isn't enough information to tell you the real time zone. more 11/25/2014 12:58:18 PM

people

Parsing with XPath a xml document. Why add a <xml tag as a header> in the result?

I searched on google first and I found many result about how to parse with xpath a xml document. I have parse it but a want to convert a NODELIST in String and I have created a...
Jon Skeet
people
quotationmark

You can configure the transformer not to output the XML declaration, before you call transform: serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); more 11/25/2014 11:45:35 AM

people

c# mock object with private constructor, initialized via a static factory method

I am testing the following controller: public class MyController : ApiController { private readonly IUserManager _users; private int num = 0; public...
Jon Skeet
people
quotationmark

You don't need to mock User - you can use the real User class. You only need to mock (or fake) IUserManager. Your mock/fake IUserManager can use User.CreateUser to create the User objects to be returned to your controller. Unless the User... more 11/25/2014 10:09:15 AM

people

How do I check if a value is assigned to an int in c#?

int x might not have an assignment. How do I detect that? What value does int hold when it is unassigned? This gives me a warning in Visual Studio: public SomeMethod(int x) { ...
Jon Skeet
people
quotationmark

int x might not have an assignment. That's simply not true. In your case, x is a parameter - it's "definitely assigned" from the start of the method, in specification terminology. When someone calls the method, they have to provide a... more 11/25/2014 9:05:48 AM

people

Password encryption deycrption UTF8 Encoding String conversion doesn't work

I wanna save a password encrypted in a local database (on windows phone). For that I first have to encrypt the password with this. byte[] passwordInByte =...
Jon Skeet
people
quotationmark

Just don't do this: return UTF8Encoding.UTF8.GetString(protectedPasswordByte, 0, protectedPasswordByte.Length); Firstly, I'd strongly advise using Encoding.UTF8 instead of UTF8Encoding.UTF8, for clarity. That won't fix the problem, but... more 11/25/2014 7:25:20 AM

people

What's wrong with my use of C# generics?

My code gives me error "cannot convert implicitly between int and T" public class Vector3D<T> { public T x; public T y; public T z; Vector3D() { ...
Jon Skeet
people
quotationmark

There's no implicit conversion available from the literal 0 to T. For example, T could be string, or TextField... You may well want to limit your vector to struct types: public class Vector3D<T> where T : struct ... but even so,... more 11/25/2014 7:15:38 AM

people

Using for loops with deleting elements from array

Hi I'm creating a program that holds three arrays one for the persons last name, one for the points scored and one for the player number, now I've got all the arrays and...
Jon Skeet
people
quotationmark

I would strongly suggest that you revisit your design entirely: Avoid multiple "parallel" collections like this. Instead, have a single collection of type Player, where Player is a new class consisting of a player number, a last name,... more 11/25/2014 6:54:45 AM

people

How to use Umalqura calendar in java 8 with java.util.Date

we hear those days that java8 will includes Umalqura calendar APi which manages Hijri Date . Where to find a sample that convert Date To Hijri ? Indeed , i find this code...
Jon Skeet
people
quotationmark

You can convert from a LocalDate - how you get that is up to you. For example: // Avoid using java.util.Date unless you really have to. // Stick to java.time.* if possible Date date = ...; Instant instant =... more 11/25/2014 6:49:26 AM

people

Using LINQ to select a byte array

I'm having some trouble selecting a byte[] from inside of a list of objects model is setup as: public class container{ public byte[] image{ get;set; } //some other...
Jon Skeet
people
quotationmark

You don't want SelectMany for the image property - that's going to give a sequence of bytes. For each list of containers, you want to transform that to a list of byte arrays, i.e. innerList => innerList.Select(c =>... more 11/24/2014 8:10:42 PM

people

Initialize ArrayList<ArrayList<Integer>>

I met a problem as follow: When I initialize a ArrayList<ArrayList<Integer>>, the codes are: ArrayList<ArrayList<Integer>> group = new...
Jon Skeet
people
quotationmark

Arrays.asList doesn't return a java.util.ArrayList. It does return an instance of a class called ArrayList, coincidentally - but that's not java.util.ArrayList. Unless you need this to really be an... more 11/24/2014 7:52:17 PM

people