Browsing 7239 questions and answers with Jon Skeet

How to convert org.joda.time.DateTime to com.mindfusion.common.DateTime

I have problem with a java project. I have to convert a String to com.mindfusion.common.DateTime, all I managed to do is to convert it to org.joda.time.DateTime using the...
Jon Skeet
people
quotationmark

It looks like you just want to call the constructor specifying all the various fields: a.setStartTime(new com.mindfusion.common.DateTime( d2.getYear(), d2.getMonthOfYear(), d2.getDayOfMonth(), d2.getHourOfDay(),... more 6/28/2016 11:00:22 AM

people

issue with DecimalFormat in java

I am facing issue in below code - int precision = 3; String value1 = "2.0425"; String value2 = "2.1425"; DecimalFormat dfForm = new...
Jon Skeet
people
quotationmark

From the docs for DecimalFormat: DecimalFormat provides rounding modes defined in RoundingMode for formatting. By default, it uses RoundingMode.HALF_EVEN. It sounds like you just... more 6/28/2016 10:40:22 AM

people

C# arbitrary cast

The following won't compile. It feels like it should. I'm wondering if there is a way around the problem. If possible, I'd prefer to avoid requiring anything to descend from...
Jon Skeet
people
quotationmark

// But that's crazy as we are inside if (dp is D) That doesn't make any difference. There's nothing in the C# specification which says that the validity of a cast can depend on whether you've already checked something. Basically, you... more 6/28/2016 8:50:55 AM

people

does array indexes affects performance/memory usage if they has no value

I'm new to Java and I've been wondering lately about memory consumption of huge, but partly empty array like in this case: I need array of unknown size- it can be 300k of...
Jon Skeet
people
quotationmark

How the size of array matters in case of performance when, say only 0,1% of that array is used vs 100% array usage? There's no such thing as an "empty array of X int values". Every element will have a value - it'll just be 0 by... more 6/26/2016 1:28:26 PM

people

How do I determine the number of unique derived types in an array?

I have the following classes Customer Class abstract class Customer { public int id; public string name; public double balance; } class NormalCustomer class...
Jon Skeet
people
quotationmark

I agree with Aleksey's answer - but if you want alternatives: // Result is a sequence of Type/Count objects var groupedByActualType = customers.GroupBy( x => x.GetType(), (type, values) => new { Type = type, Count =... more 6/26/2016 1:24:39 PM

people

Java Epoch Date for Google SpreadSheet

I tried to add date on Google spreadsheet. To add date we have convert date in epoch. For Spreadsheet epoch Google Sheets uses a form of epoch date that is commonly used in...
Jon Skeet
people
quotationmark

One option would be to take the "milliseconds since the Unix epoch" value (e.g. with Date.getTime()), offset that to get "milliseconds since the Sheets epoch" and then perform a floating point division by 24 hours. Something like this: //... more 6/24/2016 2:35:23 PM

people

Declaring an variable of class type without initializing it

I read somewhere, while reading about the System.out.print that in the System class, there is a declaration of 'out' as a PrintStream class type static variable as follows: public...
Jon Skeet
people
quotationmark

This invoked a question in me that what exactly happens if we just declare a variable of a certain class type and not initialize it by not calling any constructor? Then like any other field, it starts off with its default value -... more 6/24/2016 8:55:26 AM

people

Google Sheet API V4(Java) append Date in cells

I am tried to add date in cells but sheet automatically store value in string with single quote ('). For Store value in date , We also try to add userEnteredFormat but it didn't...
Jon Skeet
people
quotationmark

To provide an example of what Sam's answer means, if you just want to create a date value using AppendCellsRequest, you can create the cell like this: CellData cell = new CellData(); cell.setUserEnteredValue(new... more 6/23/2016 1:45:59 PM

people

Making method shorter when adding properties

I have two arrays with button-objects: this.rightButtons = new JButton[MAX_RBUTTONS]; this.wrongButtons = new JButton[MAX_WBUTTONS]; And I add properties (color, etc.) to each...
Jon Skeet
people
quotationmark

Yes, it's very simple - everything about the button is the same apart from where you're storing it. So create it, then store it: private void preferences(String buttonType, int num) { JButton button = new JButton(""); ... more 6/23/2016 12:00:48 PM

people

c# I need to perform this SQL Select to LINQ

I have this Select: SELECT (MyFields) FROM table1 T1 INNER JOIN table2 t2 ON t2.ID_t2 = T1.ID_T1 INNER JOIN table3 t3 on t3.ID_t3=T1.ID_T1 and...
Jon Skeet
people
quotationmark

Well I'd start by changing the join on table 3 in the C# - use an anonymous type to join on multiple fields: join t3 in table3 on new { Id = t1.ID_T1, X = t2.AnotherT2Field.Substring(0, 5) } equals new { Id = t3.ID_T3, X =... more 6/23/2016 11:35:02 AM

people