Browsing 7239 questions and answers with Jon Skeet

Storing DaysOfWeek as single integer in sqlite database using enum/bitwise Java

Here's what I'm trying to do. I have a field that encompasses multiple days per week. (E.g. it can store MONDAY or MONDAY | TUESDAY, or WEDNESDAY | FRIDAY) - basically any...
Jon Skeet
people
quotationmark

Your enum is of individual days of the week - a variable of type DayOfWeek should only be expected to refer to a single day. If you're trying to store multiple values, you should look at an EnumSet: EnumSet<DayOfWeek> days =... more 3/5/2014 5:30:30 PM

people

The best way to read binary data from .dat file and reverse a binary value C#

I have a .dat file with formatted in binary. This .dat file contains a blacklisted value with presented ones as true and zeroes as false. When opened with notepad or notepad++, I...
Jon Skeet
people
quotationmark

It sounds like you just want to read the file as a byte array and reverse the bit order for each byte. byte[] data = File.ReadAllBytes("file.dat"); for (int i = 0; i < data.Length; i++) { data[i] = ReverseBits(data[i]); } // Now... more 3/5/2014 5:19:33 PM

people

Best practive for JUnit package naming?

I was trying to find some best practice for naming Java package for testing. I would be thinking something along: Tests on: com.example.MyClass should be...
Jon Skeet
people
quotationmark

Typically I put the test classes in the same package, but under a different source root. Aside from anything else, this allows you to test members (and indeed classes) which have default visibility. Sometimes I'll even make methods which... more 3/5/2014 4:50:51 PM

people

Is this raw type assignment type safe? List<T> = new ArrayList();

I have some code like this: @SuppressWarnings({"unchecked", "rawtypes"}) List<String> theList = new ArrayList(); Is this type-safe? I think it is safe because I don't...
Jon Skeet
people
quotationmark

The first is type-safe because the list is empty, but still not advised. There's no benefit in using a raw type here. Better to design away from a warning than suppress it. The second is definitely not type-safe, as theList may be a... more 3/5/2014 4:21:27 PM

people

new to android understanding the use of OutputStreamWriter in web service calls

I have been going over the following tutorial and came across this code which I do not understand the purpose of: URLConnection conn = url.openConnection(); ...
Jon Skeet
people
quotationmark

It's writing it to the output stream of the URLConnection - which is basically used for the body of an HTTP request (assuming it's an HTTP URL, of course). more 3/5/2014 3:17:15 PM

people

Dispose vs. Iterator blocks

These two questions almost answer my own question, but not quite. Consider this a follow-up question to these. Do I need to consider disposing of any IEnumerable<T> I...
Jon Skeet
people
quotationmark

If you want to dispose of the IEnumerable<T>, you need to do that yourself with a using statement (or manual try/finally). A foreach loop does not dispose of the IEnumerable<T> automatically - only the iterator it returns. So,... more 3/5/2014 3:13:39 PM

people

Need an explanation about my missing code output

I'm currently in learning process of C# and I need an explanation. It's probably logical and simple for someone more experienced, but I thought code should work this way and it...
Jon Skeet
people
quotationmark

You're calling GetEnumerator in the else block, but that's not going to automatically yield anything. It would be nice if you could have something like: // This doesn't actually work! yield all carArray; ... but there's no such... more 3/5/2014 2:46:05 PM

people

Lambda expression select and add

I am trying to select and add to list using lambda.can some body help me where I am making mistake.Below code gives me compile error. string Param =...
Jon Skeet
people
quotationmark

It's not clear why you're trying to use Select for this, but it's not working because List<T>.Add has a void return method, and the lambda expression you use in a projection has to return the value you're projecting to. I suggest you... more 3/5/2014 2:39:57 PM

people

Can I retrieve a key stored in a Hashset in java in some way?

I am trying to perform bi directional A star search, where in I encountered this issue. Suppose I have an object A in a hashset H. Suppose there is another object B, such that...
Jon Skeet
people
quotationmark

I don't believe there's any way of doing this efficiently using HashSet<E>. (You could list all the keys and check them for equality, of course.) However, although the HashMap approach would be irritating, it wouldn't actually take... more 3/5/2014 1:43:41 PM

people

Change .Net Array bounds

I pass data from one third-party lib to another one. Given an object[,] with lower bounds {0,0}, I need to make object[,] with lower bounds {1,1}. Is there a way to perform this...
Jon Skeet
people
quotationmark

Is there a way to perform this convertion without creating new array and copying all the data? No. You can't change the size or bounds of an array once it has been created. more 3/5/2014 1:36:29 PM

people