Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have one scenario, where I have to update the record record, If the record is present in database with the effective and expire date splits logic.
For example the below record is already available in Database.
Item tax effectiveStartDate effectiveEndDate
1 5% 17-04-2017 31-12-2047
Now I want to update the record with the given effective start date and tax percentage.
For example I have given two dates with 6% of tax then I need to update the record if it is present. The following are the inputs:
effective start date: 17-04-2017;
effective end date: 31-12-2047`;
item : 1
tax : 6 %
Now record is already present, now what I want is , I have to adjust effective date and expire dates, 20-05-2017 and 31-12-2019.the output of should be like the following:
Item tax effectiveStartDate effectiveEndDate
1 5% 17-04-2017 19-05-2017
1 6% 20-05-2017 31-12-2047
If again I have given some other dates it should be adjusted like above. In my POC I am using spring MVC with JDBC template I am using. Can someone help me on this logic?
As I understand, if you get other tax value (10% f.e.) to Item 1, you will have to update all entries in the database, isn't it?
If that's the problem, try getting all of them in a List and doing something like:
//get all from DB
for(YourObject obj : List){
if(obj.effectiveFinalDate<newObject.effectiveStartDate){
obj.effectiveFinalDate = newObject.effectiveStartDate;
}
if(obj.effectiveStartDate>newObject.effectiveFinalDate){
obj.effectiveStartDate = newObject.effectiveFinalDate;
}
}
//persist all
I am not sure at all about what do you want exactly, but I guess it will be something similar to this
EDIT: if you want to set dates to a day more or less, look documentation, it depends on what Object you use as date
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a test case where I need to go to Jewelry section and select the price range filter of $700.00 - $3000.00. After selecting the range I can see 1 product priced at $2100.00. Now, My question is how do I check using assert that the product price $2100 is between $700 - $3000? Do I need to get rid the $ signed? as actual result will contain $ signed while comparing with expected.
Please help?
Thanks in advance
It is very simple in Java
assertThat(mynum).isBetween(min, max);
Or
assertTrue(min <= mynum && mynum <= max);
Yes, you need to get rid of the $ sign, that's useless and as said in the comments, Java (and probably no other programming language) has a specific money type.
You can use Regex for that
"[0-9]+"
And for the assert, it's as simple as adding two conditions inside
assertTrue(price > 700 && price < 3000);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
So, I'm trying to calculate a list of number to eventually sort, so I only want the final result of this for loop.
for (int anno=startyear; TimePeriod>=anno;anno++) {
System.out.println(anno);
}
Where anno = 1995 and I am counting to the current day, I end up getting a result that slowly counts up, where it first counts at 1995, then it counts 1995 and then 1996, and so on.
How do I only get the end result for use in my program? The result that would simply be 1995-2014. Not the repeats.
edit: Forgot to mention I need every number in between 1995-2014 as well
You shouldn't need a loop for this, assuming your TimePeriod variable equals 2014 then just do the following to print out the desired result:
System.out.println(startyear+"-"+TimePeriod);
That will print out:
1995-2014
You already know the final value: it's TimePeriod. If that's all you need, just use that and get rid of the loop:
System.out.printf("%d-%d", startyear, TimePeriod);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Is there any possible way to do this:
if ( 5 AM < now < 11:30 AM )
{
if the user didn't click a specific button, at this specific time, then:
x=0;
}
You can use the time libraries, depending on your minimum API level, to get the times. You can look closer into the documentation to get a better idea of how to use it. Both the code snippets I have below are very similar.
http://developer.android.com/reference/android/text/format/Time.html
I would try using these two functions (copied and pasted from Android Documentation)
public boolean after (Time that)
//Added in API level 3
//Returns true if the time represented by this Time object occurs after the given time.
//Parameters --
//that a given Time object to compare against
//Returns --
//true if this time is greater than the given time
Similar to previous statement
public boolean before (Time that)
//Added in API level 3
//Return true if the time represented by this Time object occurs before the given time.
//Returns --
//true if this time is less than the given time
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have been storing date records (Date().getTime()) in an SQLite database with an Integer type. I realize now that Date().getTime() is returning Long values, not Integer.
Is there any way I can rescue the date data that is already stored in the database? Going forward I can reduce the resolution of the time, to make it fit into an integer. (ie. divide by 1000, and cast to int)
I expect that forcing a long value into an integer space has truncated the most significant digits - which might work in my favour, as the dates in question have all occurred within the past 6 months, so can probably be calculated.
question
so, how exactly would the long representation of today's date map onto an integer, and how might I use that knowledge (combined with the restricted time range) to build these integers back into their original long values?
Any suggestions?
Turns out the SQLite database integer type is perfectly capable of storing long values. So the data rescue was unnecessary in the end.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need to store certain id's , and check if one exists there.
Either i can use concatenated string or array/List, which of them is a better and faster way.
This is how actually data is organized :
Year 1
Month 1
Day 1
Day 2
Day 3
Month 2
Day 6
Day 2
Day 3
Year 2
Month 3
Day 1
Day 3
Day 7
Month 6
Day 6
Day 2
Day 3
I would definitely use a collection of some form. If you only care about containment, you should use a Set<String> of some kind (e.g. HashSet<String> or LinkedHashSet<String>, which will both give O(1) complexity unless you have a significant number of hash collisions) but for goodness' sake don't use a concatenated string.
Your data isn't naturally a concatenated string - it's a collection of strings. Always keep your data in the most natural representation unless you have really good evidence that some alternative form (such as a single string) will bring you a meaningful benefit. Keeping your data in a natural representation almost always leads to clearer code which is easier to work with - and easier to optimize later, when you've found where the real bottlenecks are.
Create a HashSet a use contains method. String or ArrayList will have O(n) complexity where as HashSet will be O(1) complexity.