Getting the Difference in JTables my algo is messed
Im trying to get the difference of two JTables...in other words if Table B has the rowdata of Table A, then Table C should not have it...Table C should have all the data in Table A - the data in Table B
heres my code:
//in a subclass of JTable
public Object[][] getDifferenceData(JTable table){
DefaultTableModel thisModel = (DefaultTableModel)this.getModel();
DefaultTableModel userModel = (DefaultTableModel)table.getModel();
int differenceRows = thisModel.getRowCount() - userModel.getRowCount();
Object[][] newData = new Object[differenceRows][2];
Object symbol = new Object();
Object description = new Object();
for (int i=0; i<differenceRows; i++){
for (int j=0; j<userModel.getRowCount()-1; j++){
if ((symbol = thisModel.getValueAt(i,0)) != userModel.getValueAt(j,0)){
//symbol in portfolio model != symbol in user portfolio
//so new difference table model should have it
description = thisModel.getValueAt(i,1);
newData[0] = symbol;
newData[i][1] = description;
return newData;
heres what im trying to do
1) new Data[][] is set to size bigger table row count - smaller tables
for all new row size
2)compare table A data in the current row and first column to all the rows/first column of table B
3) if the data is NOT the same, the copy that row data from Table A into a new 2D data vector to the appropriate row
4) return the new data[][] for new jtable creation
but what happens is that the difference table (C) contains the corrent number of rows...but it still contains the data found in table B, and the new table C is just table C with the right number of rows cut off
my algo is severly messed :)
any help would be appreciated..thanks
hey klepto,
your not using .equals() on the symbol Object, this means that all it is doing is seeing if they refer to the same instance of the object, not if the to instances have the same value.
The other problem is that you presume that the difference of the two collections is based on their respective size. What if they contain totaly different values? Then the total size would be the sum of both collections.
Lets presume that the symbol is a String. Then I would do the following:
//in a subclass of JTable
public Object[][] getDifferenceData(JTable table, DefaultTableModel thisModel, DefaultTableModel userModel){
Object[][] newData = null;
String symbolA = null;
String symbolB = null;
String description = null;
SymbolData symbolData = null;
Vector newList = new Vector();
int nbrRowsA = thisModel.getRowCount();
int nbrRowsB = userModel.getRowCount();
for(int i = 0; i < nbrRowsA; i++) {
symbolA = (String)thisModel.getValue(i, 0);
for(int j = 0; j < userModel.getRowCount() - 1; j++) {
symbolB = (string)userModel.getValue(i, 0);
if(!symbolA.equals(symbolB)){
description = (String)thisModel.getValueAt(i,1);
newList.add(new SymbolData(symbol, description));
if(newList.size() > 0) {
int size = newList.size();
newData = new String[size][2];
for(int i = 0; i < size; i++) {
symbolData = (SymbolData)newList.get(i);
newData[0] = symbolData.getSymbol();
newData[i][1] = symbolData.getDescription();
return newData;
class SymbolData {
String symbol;
String description;
MyDataClass(String symbol, String description) {
this.symbol = symbol;
this.description = description;
String getSymbol() {
return symbol;
String getDescription() {
return description;
String[] getData() {
String[] data = new String[2];
data[0] = symbol;
data[1] = description;
return data;
Hmm, that should do the job. Not the fastest code, I'm sure there
could be some improvements with the array handling. But it should
get you started.
Also I have not attempted to compile the above so I suspect you
will find problems (only on a good day do I get zero compile errors
when I first write something, good days are rare :-) ).
James.
Similar Messages
-
How to get the difference of two dates in years,months and days
Hi friends,
how to get the difference of two dates in years,months and days
for ex 2 years 3 months 13 days
select (sysdate-date_Start) from per_periods_of_service
thanksSomething like this...
SQL> ed
Wrote file afiedt.buf
1 with t as (select to_date('17-nov-2006','dd-mon-yyyy') as c_start_date, to_date('21-jan-2008','dd-mon-yyyy') as c_end_date from dual union all
2 select to_date('21-nov-2006','dd-mon-yyyy'), to_date('17-feb-2008','dd-mon-yyyy') from dual union all
3 select to_date('21-jun-2006','dd-mon-yyyy'), to_date('17-jul-2008','dd-mon-yyyy') from dual
4 )
5 -- end of test data
6 select c_start_date, c_end_date
7 ,trunc(months_between(c_end_date, c_start_date) / 12) as yrs
8 ,trunc(mod(months_between(c_end_date, c_start_date), 12)) as mnths
9 ,trunc(c_end_date - add_months(c_start_date, trunc(months_between(c_end_date, c_start_date)))) as dys
10* from t
SQL> /
C_START_D C_END_DAT YRS MNTHS DYS
17-NOV-06 21-JAN-08 1 2 4
21-NOV-06 17-FEB-08 1 2 27
21-JUN-06 17-JUL-08 2 0 26
SQL>But, don't forget that different months have different numbers of days, and leap years can effect it too. -
Query to get the difference between 2 totals from 2 different queries
I wanted to know if it is possible to get the difference between 2 totals from 2 different queries. I would explain with an example:
1st query - Select sum(homepass) from table 1
2nd query – select sum(homepass) from table2
Is it possible to display the difference like-
Select sum(homepass) from table 1 - sum(homepass) from table2
I know the above query would gives syntax error but is there a better way or a trick to get the above task accomplished from a single query.
I hope, my question is clear.
Please revert with the reply to my query.
Regardstomernitin wrote:
Try this one also:
WITH adtn1
AS
SELECT 110 val1 FROM dual UNION ALL
SELECT 100 FROM dual UNION ALL
SELECT 90 FROM dual UNION ALL
SELECT 10 FROM dual
adtn2
AS
SELECT 10 val2 FROM dual UNION ALL
SELECT 20 FROM dual UNION ALL
SELECT 30 FROM dual UNION ALL
SELECT 100 FROM dual
SELECT(Sum(a1.val1)-Sum(a2.val2)) Diff FROM adtn1 a1,adtn2 a2;
let me know if you still have any doubt.
Um.... I don't think so. Not with the cartesian join between a1 and 2. -
How to get the difference between two columns in a column group
Hi All,
My first time here and really new to programming. I would like to get the difference between 2 columns that are inside
a column group.
Here is my sample table below: The Column Group is PeriodNumber and can only choose 2. like 1 and 2.. I would like to have a third row which will simply calculate the difference between the amounts in PeriodNumber 1 and 2.
PeriodNumber
Account 1 2
1) Cash 10,000 15,000
2) Receivables 12,000 11,500
3) Equipment 5,000 5,500
Total Assets 27,000 32,000Hi yabgestopa,
From your description, you want to get the difference between two columns in a column group. After testing it in my environment, we can use custom code to achieve your requirement. For more details, you can refer to the following steps:
Copy the custom code below and paste it to your report. (Right-click report>Report Properties>Code)
Dim Shared Num1 As Integer
Dim shared Num2 As Integer
Public Function GetAmount(Amount as Integer, Type as String)
If Type = "1" Then
Num1=Amount
Else
Num2=Amount
End If
Return Amount
End Function
Public Function GetDif()
Return Num1-Num2
End function
Right-click the second column to insert a third column with Outside Group-Right.
Then use the expressions below in the matrix.
=Code.GetAmount(Fields!Amount.Value,Fields!PeriodNumber.Value)
=code.GetAmount(Sum(Fields!Amount.Value),Fields!PeriodNumber.Value)
=Code.GetDif()
The report looks like below.
If you have any questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Function module to get the difference of dates ..
Hi ,
Can somebody pls help me with the function module to get the difference between two dates?
I need to find the difference value and delete records if >1.
Thanks in advance.
Regds,
Leeza.Leeza,
When I tested the FM in my Program, it is <b>working</b>!!!!!
Note that the Two Input Dates are to be in the format of <b>DATS</b> type (Eg: <b>vimimv-dmibeg</b>).
U can want the Day which u have specified in the parameter I_DATUM_BIS (eg: 20050101) to be included for
the calculation , then put X in the parameter I_KZ_INCL_BIS.
Sample Code :
report zkam01.
data:
<b>sav_nlaufz like rf60v-nlaufz,
date1 type vimimv-dmibeg,
date2 type vimimv-dmiend.</b>
date1 = '20050101'.
date2 = '20051001'.
call function 'MONTHS_BETWEEN_TWO_DATES'
exporting
i_datum_von = date1
i_datum_bis = date2
i_kz_incl_bis = 'X'
importing
e_monate = sav_nlaufz.
write:
date1,
/ date2,
/ sav_nlaufz.
Please allot points if the problem is solved.
Thanks
Kam
Message was edited by: Kam -
Do we have a way to get the differences between xtext model before and after partial parse?
Do we have a way to get the differences between xtext model before and after partial parse?
As an example i have file contains 4 lines, xtext parsed this file and generated its model, then i made small modification in line number 3, so xtext partially parsed the file and generated another model.
The question is could we get the nodes that has been deleted from the model?
could we get the new nodes added to the model?
could we get the differences between the two models?Workflow {
bean = StandaloneSetup {
scanClassPath = true
platformUri = "${runtimeProject}/.."
// The following two lines can be removed, if Xbase is not used.
registerGeneratedEPackage = "org.eclipse.xtext.xbase.XbasePackage"
registerGenModelFile = "platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel"
component = ParseXextModel{
//Load the xtext model and keep the reference of the inmem model
component = DirectoryCleaner {
directory = "${runtimeProject}/src-gen"
component = DirectoryCleaner {
directory = "${runtimeProject}/model/generated"
component = DirectoryCleaner {
directory = "${runtimeProject}.ui/src-gen"
component = DirectoryCleaner {
directory = "${runtimeProject}.tests/src-gen"
component = Generator {
pathRtProject = runtimeProject
pathUiProject = "${runtimeProject}.ui"
pathTestProject = "${runtimeProject}.tests"
projectNameRt = projectName
projectNameUi = "${projectName}.ui"
encoding = encoding
language = auto-inject {
uri = grammarURI
// Java API to access grammar elements (required by several other fragments)
fragment = grammarAccess.GrammarAccessFragment auto-inject {}
// provides a compare view
fragment = compare.CompareFragment auto-inject {}
component = ParseXextModel{
//Load the xtext model again and keep the reference of the inmem model
component = CompareModel {
//Implement this using EMF Comapre to see the differnces between 2 models
} -
Getting the difference between 2 dates
Hi,
I am creating a Date object (using today;s day, month and year. hours and minutes come from a config file) and getting the difference between this date and the current date and time.
My code is as follows:
I am passing 07:30 into the method as the parameter aSstart_time.
Calendar newCalendar = Calendar.getInstance(Locale.UK);
SimpleDateFormat dtformat = new SimpleDateFormat("dd-MM-yy HH:mm");
int lIYear = newCalendar.get(newCalendar.YEAR);
int lIMonth = newCalendar.get(newCalendar.MONTH);
int lIDay = newCalendar.get(newCalendar.DAY_OF_MONTH);
String lSstartHrs = aSstart_time.substring(0,aSstart_time.indexOf(":"));
//System.out.println(">>>>>>>>> THE HOURS IS: " + lSstartHrs);
String lSstartMins = aSstart_time.substring(aSstart_time.indexOf(":")+1,aSstart_time.length());
//System.out.println(">>>>>>>>> THE MINS IS: " + lSstartMins);
java.util.Date ldStartTime = new java.util.Date(lIYear,lIMonth,lIDay, Integer.parseInt(lSstartHrs),Integer.parseInt(lSstartMins));
System.out.println("Year: " + lIYear);
System.out.println("Month: " + lIMonth);
System.out.println("Day: " + lIDay);
System.out.println("Hour: " + Integer.parseInt(lSstartHrs));
System.out.println("Min: " + Integer.parseInt(lSstartMins));
System.out.println("The number of milliseconds for current time is: " + newCalendar.getTime().getTime());
System.out.println("The number of milliseconds for 07:30 is: " + ldStartTime.getTime());
System.out.println("calendar time: " + dtformat.format(newCalendar.getTime()).toString());
System.out.println("created time: " + dtformat.format(ldStartTime).toString());
if(newCalendar.getTime().getTime() < ldStartTime.getTime()){
System.out.println("The current time is less than the config time (07:30)");
else{
System.out.println("The time is greater than 07:30");
}When I run this program at 10:06am I get the following output:
Year: 2006
Month: 1
Day: 15
Hour: 7
Min: 30
The number of milliseconds for current time is: 1139997962321
The number of milliseconds for 07:30 is: 61098132600000
calendar time: 15-02-06 10:06
created time: 15-02-06 07:30
The current time is less than the config time (07:30)
The Date.gettime() method should measure the number of milliseconds after 01-01-1970 so the number of milliseconds for the current time (10:06am) should be greater than the number of milliseconds for 07:30. A you can see in the above output this is not the case.
Anybody have any idea why this is happening. Am I using the .gettime() method for the correct purpose.
Any ideas or suggestions would be greatly appreciated.
ThanksIt is beacause Calendar use fully defined year as parameter, so Calendar.set(year + 1900, month, date, hrs, min) is (almost) equivalent to new Date(year, month, date, hrs, min)Example: int year = 85; // old way of specifying a year in a Date
int month = 3;
int date = 12;
int hrs = 12;
int min = 0;
Calendar cal = Calendar.getInstance();
cal.set(year + 1900, month, date, hrs, min);
Date d = new Date(year, month, date, hrs, min);
System.out.println(d);
System.out.println(cal.getTime());You will obtain the same date (except seconds and miliseconds in this case, as they probably won't be zero with Calendar.getInstance(); ) -
How to get the difference of two dates?
let's say i have a table named tblData and has 4 columns: data_RefNo, data_DateReported, data_TargetDate, data_Data
tblData returns 2 rows.
data_RefNo.............data_DateReported.............data_TargetDate........................data_Data
10000................10-20-2004 10:55:44 AM........10-20-2004 10:57:44 AM........Slow Response Time
10000................10-21-2004 10:55:44 AM........10-21-2004 11:55:44 AM........Bug Error
i just wana ask how to get the difference of the date_DateReported and date_TargetDate.
i tried this code but it didnot work
public Vector get_con_pf()
Vector vData = new Vector();
String query = "SELECT * FROM tblData WHERE data_RefNo= '"'10000'"'";
try
DBConnect db = new DBConnect();
db.openCon();
ResultSet rs = db.execute(query);
while (rs.next())
vData.addElement(DATEDIFF(mi, rs.getString("st_DateReported"), rs.getString("st_TargetFinishDate")));
db.closeCon();
catch (Exception e)
System.out.println("Error: " + e );
return vData;
i want to return the difference of the data_DateReported and date_TargetDate, i did this
vData.addElement(DATEDIFF(mi, rs.getString("st_DateReported"), rs.getString("st_TargetFinishDate")));but it didnot work.
How do i get that? because i want to return a vector.
the code must return the values:
2 for the 1st rows because the difference is only 2 minutes, and
60 for the 2nd row.ooops i tried this one:
query = "SELECT *, DATEDIFF(mi, data_DateReported, data_TargetDate) AS diff FROM tblData WHERE data_RefNo = '10000'";and it works.
hehehehe!!!!!!
problem solved! :) -
SUBSTRACTING 2 DATES TO GET THE DIFFERENCE IN MINUTES
Hi
I want to substract 2 dates and to get the difference in minutes. Can you help me with that ?
Thanksselect (sysdate - (sysdate - 10)) * 24 * 60 from dual
where
sysdate - date1
(sysdate -10) - date2
24 - number of hours per day
60 - number of minutes per hour
Is this what you need? -
Trying to Get the "Difference" Between Two Tracks
What I am trying to accomplish is this: I have an audio track of a voiceover with a music bed beneath it. I also have the bed music by itsself, without the voiceover. I want only the voice portion. Is there a way that I can "cancel out" the music portion or get the difference between the two tracks (just the voice portion)? It seems that there should be some means of doing this, but for the life of me I cannot figure out how to do it!
Any advice?If it's exactly the same music track, then as long as you line it up sample-accurate and the levels co-incide, you can do a simple subtractive process. You need both files available, trimmed to length. Open them both in Edit View, and copy one of them to the clipboard. Open the other, and select Mix-paste, and use the 'invert' option. That will effectively subtract one from the other, with the difference being your vocal.
Have to tell you though that the chances of getting this spot on are amazingly low... any errors at all leave you with bleed-through, about which you can do nothing. -
How to get the difference between these two dates
Hello Friends,
I need to get the difference between these two fields which store dates but with varchar2 data types
SELECT pac.segment1, pac.segment2 emp_no, pac.segment3 NAME,
pac.segment4 POSITION, pac.segment5 start_date, pac.segment6,
pac.segment7
FROM per_analysis_criteria pac, fnd_id_flex_structures_vl ffs
WHERE ffs.id_flex_structure_code = 'Employee Rejoin'
AND ffs.id_flex_num = pac.id_flex_num
AND TO_CHAR (TO_DATE (pac.segment7, 'YYYY/MM/DD HH24:MI:SS'))
- TO_CHAR (TO_DATE (pac.segment6, 'YYYY/MM/DD HH24:MI:SS')) > 1;
my query is something like this...
am trying to find the difference between the last two columns but with not much luck..
can some one suggest me a solution pleaseSELECT pac.segment1, pac.segment2 person_id, pac.segment3 NAME,
papf.employee_number, paaf.supervisor_id, pac.segment4 POSITION,
pac.segment5 start_date, pac.segment6, pac.segment7,
papf2.email_address,
( TO_DATE (TO_CHAR (pac.segment7), 'DD-MON-YYYY HH:MI:SS AM')
- TO_DATE (pac.segment6, 'DD-MON-YYYY HH:MI:SS AM')
+ 1
) difference,
POST.email_address
FROM per_analysis_criteria pac,
apps.fnd_id_flex_structures_vl ffs,
per_all_people_f papf,
per_all_assignments_f paaf,
per_all_people_f papf2,
(SELECT email_address, person_id
FROM per_all_people_f
WHERE person_id IN (
SELECT person_id
FROM per_all_assignments_f
WHERE position_id IN (SELECT position_id
FROM per_positions
WHERE NAME LIKE 'HR Manager.704.')
AND TRUNC (SYSDATE) BETWEEN effective_start_date
AND effective_end_date)
AND TRUNC (SYSDATE) BETWEEN effective_start_date AND effective_end_date
AND business_group_id = fnd_profile.VALUE ('PER_BUSINESS_GROUP_ID')) POST
WHERE ffs.id_flex_structure_code = 'Employee Rejoin'
AND TO_CHAR (papf.person_id) = pac.segment2
AND ffs.id_flex_num = pac.id_flex_num
AND TRUNC (SYSDATE) BETWEEN papf.effective_start_date
AND papf.effective_end_date
AND papf.current_employee_flag = 'Y'
AND papf.person_id = paaf.person_id
AND TRUNC (SYSDATE) BETWEEN paaf.effective_start_date
AND paaf.effective_end_date
AND papf.person_id = paaf.person_id
AND papf2.person_id = paaf.supervisor_id
AND paaf.primary_flag = 'Y'
AND TRUNC (SYSDATE) BETWEEN papf2.effective_start_date
AND papf2.effective_end_date
AND papf2.current_employee_flag = 'Y'
and ( TO_DATE(to_char(pac.segment7), 'DD-MON-YYYY HH:MI:SS AM')-TO_DATE (pac.segment6, 'DD-MON-YYYY HH:MI:SS AM')+1) >1
last line is giving me the error pls suggest a solution -
Need to get the difference between two period
Hi All,
I need to get the difference of two posting period like period is in format YYYYMM.
I need to subtract posting perid '200512' FROM '200601' how will be it possible.
Please suggest.
Thanks,
SandyHi,
YOu can also do like the following.
Determine you first day of first period and last day of second period.
data: first_day type datum,
last_day type datum,
days type i.
first_day = date from FM RKE_GET_FIRST_DAY_IN_PERIOD
last_day = date from FM RKE_GET_LAST_DAY_IN_PERIOD
days = last_day-first_day.
Thanks,
Ramakrishna -
Java code to get the difference between two dates in days
Hi ppl,
I need to write a user defined function to get the difference between two date nodes, in days.Please help me out
regards,
PrashanthHi,
have a look at those two:
(How do I calculate the difference between two dates?)
http://joda-time.sourceforge.net/faq.html
Calculating the Difference Between Two Datetime Stamps
http://www.xmission.com/~goodhill/dates/deltaDates.html
Get difference in days
http://javaalmanac.com/egs/java.util/CompDates.html
Regards,
michal -
How to get the difference between two HashMaps
i have two HashMaps
HashMap first = new HashMap<Integer,Object>();
HashMap second = new HashMap<Integer,Object>();
How to get the difference between one and two and put the result in the third
HashMap third = new HashMap<Integer,Object>();My bad, difference of course means removeAll():Map<Integer,Object> first = new HashMap<Integer,Object>();
Map<Integer,Object> second = new HashMap<Integer,Object>();
Map<Integer,Object> third = new HashMap<Integer, Object>(first);
third.keySet().removeAll(second.keySet());No loops needed. -
bought the HD season version of breaking bad, however I only need the regular @ 19.95. How can I change this and get the difference refunded?
When you purchase an HD video on a supported device or computer, only HD video will be downloaded. To download the SD version, you need to download the video again from your Purchased page. Conversely, if you purchase an HD video on an unsupported device, the SD version will be downloaded. Then, you will need to download the HD version from your Purchased page. Learn more about downloading previous purchases."
iTunes: Purchasing and viewing HD videos
Maybe you are looking for
-
How to convert cassette tape to macbook pro
hi i have a 2009 macbook pro and want to convert cassette tape of me giving a lecture to cd so I don't lose it. the cassette is 35 years old and still works well. my mbp does only has a headphone out jack outlet, not anything for input so I can't see
-
Order by clause doesn't work properly
Hello, I have developed a purchasing report and added it to the request group.The Order By clause (to_number(PO_HEADERS_ALL.SEGMENT1)) in my query gives the required ordering when the report runs in Reports Builder, and it doesn't when requested from
-
MySQL 5.1 Stored Procs and Views not showing, only tables.
Hi, I'm having problems getting stored procedures and views to show up in the Data Source Explorer of CR4E 2.0. I've checked the properties of the connection and the Default Stored Procedure Filter is disabled, so things should show Tables are showin
-
Lose draft after selecting Send for Review
I am running Contribute CS4 and CPS. We have approx 12 websites that we manage with Contribute, all PC's are running Windows XP. I recently sent a non-Contribute user a draft and noticed something very strange. After selecting the 'Send e-mail wit
-
Export data to excel from table
Hi experts, Scenario: I have a table which is mapped to a context node consisting of 6 attributes. Here I want to add a new button to the application to export all the data comming in the table to an excel sheet. How can i achieve this scenario. I ne