Googleからchromeのrpmをダウンロードしてインストールしようとしても,Fedora18ではMissing Security Signaturesというエラーが出てインストールできない.
仕方がないので以下のサイトからrpmをrpmコマンドから直にダウンロードしてインストールする.
rpm -ivh https://dl.google.com/linux/direct/google-chrome-stable_current_i386.rpm
rpm -ivh https://dl.google.com/linux/direct/google-chrome-stable_current_i386.rpm
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
void ShowIntVal(void* param);
void ShowValFromVector(void* param);
void (*pShowValFunc)(void* param);
int main() {
// int val
pShowValFunc = ShowIntVal;
int val = 32;
pShowValFunc((void*)&val);
vector<int> v;
v.push_back(-20);
v.push_back(-2000);
pShowValFunc = ShowValFromVector;
pShowValFunc((void*)&v);
return EXIT_SUCCESS;
}
void ShowIntVal(void* param){
int* pIntVal = static_cast<int*>(param);
cout << "ShowIntVal:" << *pIntVal << endl;
}
void ShowValFromVector(void* param){
vector<int> *pV = static_cast<vector<int>*>(param);
vector<int>::iterator iter;
cout << "ShowValFromVector:";
for( iter = pV->begin(); iter != pV->end();iter++)
cout << *iter << ' ';
cout << endl;
}
#include <iostream>
#include <ctime>
using namespace std;
class IDGenerator;
class IDGenerator {
private:
int max;
IDGenerator(long,int);
public:
static IDGenerator& GetInstance(long,int);
~IDGenerator();
int Next();
};
IDGenerator::IDGenerator(long seed,int maxVal):max(maxVal) {
srand(seed);
}
IDGenerator::~IDGenerator(){}
IDGenerator& IDGenerator::GetInstance(long seed,int maxVal){
static IDGenerator gen(seed,maxVal);
return gen;
}
int IDGenerator::Next() {
return rand() % max;
}
int main() {
IDGenerator idGen = IDGenerator::GetInstance(time(NULL),100);
for(int i = 0;i < 20;i++ ) {
cout << idGen.Next() << " ";
}
return EXIT_SUCCESS;
}
#include <cstdio>
#include <string>
using namespace std;
class Base {
protected:
int fieldA;
public:
Base() { fieldA = 0;};
virtual void ShowField(const string* prefix ) { printf("%s-%d\n", prefix->c_str(), fieldA); }
};
class Child: public Base {
public:
Child();
void ShowField(const string* prefix);
};
Child::Child(): Base() {
printf("Child created.\n");
}
void Child::ShowField(const string* prefix) {
Base::ShowField( prefix );
string* p = const_cast<string*>(prefix);
*p = "--the jail breaker--";
}
class Stranger {
public:
Stranger() {}
};
int main() {
// static_cast
double d = 50.0;
printf( "staticcast - %d\n", static_cast<int>(d) );
// const_cast
Child c;
string str = "abc";
c.ShowField(&str);
printf("%s\n",str.c_str());
// dynamic_cast
Stranger *pS = dynamic_cast<Stranger*>(&c);
if( pS == NULL )
printf("downcast failed as per the pS content");
return 0;
}
staticcast - 50 Child created. abc-0 --the jail breaker-- downcast failed as per the pS content
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
using namespace std;
class TradeInfo
{
protected:
string tradeId;
int eventId;
public:
TradeInfo() {}
virtual ~TradeInfo() {}
TradeInfo(const TradeInfo& info) {
tradeId = info.tradeId;
eventId = info.eventId;
}
TradeInfo& operator =(const TradeInfo& info) {
TradeInfo in;
in.tradeId = info.tradeId;
in.eventId = info.eventId;
return in;
}
string GetTradeId() { return tradeId; }
int GetEventId() { return eventId; }
void SetTradeId(string str) { tradeId = str; }
void SetEventid(int evt) { eventId = evt; }
void dump() {
cout << "TradeId-" << tradeId << ",EventId-" << eventId << endl;
}
};
TradeInfo GenerateTradeInfo(string str,int eventId) {
TradeInfo t;
t.SetTradeId(str);
t.SetEventid(eventId);
return t;
}
int main() {
vector<TradeInfo> v;
v.push_back(GenerateTradeInfo("abc",1));
TradeInfo t = v.at(0);
t.dump();
return EXIT_SUCCESS;
}
#include <iostream>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
using namespace std;
class Parent {
protected:
vector<int> v;
public:
Parent(){ cout << "constructor" << endl; }
virtual ~Parent() { cout << "Destructor" << endl; }
virtual void push_back(int a){ v.push_back(a); }
//virtual void push_back(int a){ v.push_back(a); }
virtual int get(int idx){ return v.at(idx); }
};
class Child: public Parent {
private:
string decoration;
public:
Child(string decorationVal="empty") { decoration = decorationVal; }
int get(int idx){ cout << "**" << decoration << "**" << endl; return v.at(idx); }
};
int main() {
Parent *p = new Child(string("takoneko"));
p->push_back(32);
p->push_back(16);
cout << p->get(0) << endl;
return 0;
}
public class Deadlock {
Object critA = new Object();
Object critB = new Object();
int a;
int b;
public void start() throws Exception {
a = 100;
b = 50;
Thread a = new Thread( new CriticalSectionLogic(), "A" );
Thread b = new Thread( new CriticalSectionLogic(), "B" );
a.start();
Thread.sleep( 100 );
b.start();
}
/**
* @param args
*/
public static void main(String[] args) throws Exception {
Deadlock d = new Deadlock();
d.start();
}
public void criticalSectionA( String name ) throws Exception {
synchronized( critA ) {
System.out.printf( "%s entering into CSA\n", name );
synchronized( critB ) {
Thread.sleep( 100 );
b += a;
}
a = 0;
System.out.printf( "%s exitting into CSA\n", name );
}
}
public void criticalSectionB( String name ) throws Exception {
synchronized( critB ) {
System.out.printf( "%s entering into CSB\n", name );
synchronized( critA ) {
a += b;
}
b = 0;
System.out.printf( "%s exitting into CSB\n", name );
}
}
class CriticalSectionLogic implements Runnable {
public void run() {
String name = Thread.currentThread().getName();
System.out.printf( "Thread %s starting..\n", name );
try {
if( name.equals( "A" ) ) {
criticalSectionA( name );
criticalSectionB( name );
}
else {
criticalSectionB( name );
criticalSectionA( name );
}
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
}
Thread A starting.. A entering into CSA Thread B starting.. A exitting into CSA B entering into CSB B exitting into CSB B entering into CSA A entering into CSB
@Test(expected=Exception.class)
public void testCompositeMap() {
CompositeMap compo = new CompositeMap( initMap(), initMap2() );
assertThat( compo.size(), is( 10 ) );
compo = new CompositeMap( initMap(), initMap() );
}
private Map<Integer,String> initMap() {
Map<Integer,String> m = new HashMap<Integer,String>();
m.put( 1, "NewYork" );
m.put( 2, "Tokyo" );
m.put( 3, "Bangalore" );
m.put( 4, "London" );
m.put( 5, "Paris" );
return m;
}
private Map<Integer,String> initMap2() {
Map<Integer,String> m = new HashMap<Integer,String>();
m.put( 6, "Hongkong" );
m.put( 7, "Seoul" );
m.put( 8, "Cairo" );
m.put( 9, "AllenTown" );
m.put( 10, "GeorgeTown" );
return m;
}
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.apache.commons.collections.FastArrayList;
import org.apache.commons.lang3.time.StopWatch;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
public class FastListTest implements Runnable {
List<String> list = null;
@Before
public void init() {
list = initFastList();
}
@Test
public void testFastList() throws InterruptedException {
ExecutorService service = Executors.newFixedThreadPool( 30 );
StopWatch watch = new StopWatch();
watch.start();
for( int i = 0;i < 100;i++ ) {
service.submit( this );
}
service.shutdown();
service.awaitTermination( 10000L, TimeUnit.HOURS );
System.out.println( "FAST - " + watch.getTime() );
watch.reset();
list = initArrayList();
service = Executors.newFixedThreadPool( 30 );
watch.start();
for( int i = 0;i < 100;i++ ) {
service.submit( this );
}
service.shutdown();
service.awaitTermination( 10000L, TimeUnit.HOURS );
System.out.println( "NONFAST - " + watch.getTime() );
}
private FastArrayList initFastList() {
// slow mode first
FastArrayList list = new FastArrayList();
list.add( "a" );
// switching to fast mode
list.setFast( true );
return list;
}
private List<String> initArrayList() {
// slow mode first
List<String> list = new ArrayList<String>();
list.add( "a" );
// switching to fast mode
return list;
}
public void run() {
// access to random node
list.get( 0 );
}
}
import java.util.Comparator;
import org.apache.commons.collections.ArrayStack;
import org.apache.commons.collections.Buffer;
import org.apache.commons.collections.buffer.PriorityBuffer;
import org.apache.commons.collections.buffer.UnboundedFifoBuffer;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
public class CollectionsTest {
@Test
public void testBuffer() {
// Queue - FIFO
Buffer buffer = new UnboundedFifoBuffer();
injectTestValue( buffer );
assertThat( (String)buffer.get(), is( "1st" ) );
assertThat( (String)buffer.remove(), is( "1st" ) );
assertThat( (String)buffer.remove(), is( "2nd" ) );
assertThat( (String)buffer.remove(), is( "3rd" ) );
// Stack - LIFO
buffer = new ArrayStack();
injectTestValue( buffer );
assertThat( (String)buffer.get(), is( "3rd" ) );
assertThat( (String)buffer.remove(), is( "3rd" ) );
assertThat( (String)buffer.remove(), is( "2nd" ) );
assertThat( (String)buffer.remove(), is( "1st" ) );
// BinaryHeap
// ascending
buffer = new PriorityBuffer( true, new StringLengthComparator<String>() );
injectTestValueForPriorityBuffer( buffer );
assertThat( (String)buffer.remove(), is( "/usr" ) );
assertThat( (String)buffer.remove(), is( "/usr/local" ) );
assertThat( (String)buffer.remove(), is( "/usr/local/bin" ) );
// descending
buffer = new PriorityBuffer( false, new StringLengthComparator<String>() );
injectTestValueForPriorityBuffer( buffer );
assertThat( (String)buffer.remove(), is( "/usr/local/bin" ) );
assertThat( (String)buffer.remove(), is( "/usr/local" ) );
assertThat( (String)buffer.remove(), is( "/usr" ) );
}
private void injectTestValue( Buffer buffer ) {
buffer.add( "1st" );
buffer.add( "2nd" );
buffer.add( "3rd" );
}
private void injectTestValueForPriorityBuffer( Buffer buffer ) {
buffer.add( "/usr" );
buffer.add( "/usr/local" );
buffer.add( "/usr/local/bin" );
}
}
class StringLengthComparator<String> implements Comparator<String> {
public int compare( String arg0, String arg1 ) {
if( ((java.lang.String) arg0).length() > ((java.lang.String) arg1).length() )
return 1;
else if( ((java.lang.String) arg0).length() == ((java.lang.String) arg1).length() )
return 0;
else
return -1;
}
}
@Test
public void testBidiMap() {
BidiMap bidiMap = new TreeBidiMap( initMap() );
assertThat( (String)bidiMap.remove( 4 ), is( "London" ) );
assertThat( ((Integer)bidiMap.removeValue( "NewYork" )).intValue(), is( 1 ) );
assertThat( bidiMap.size(), is( 3 ) );
}
private Map<Integer,String> initMap() {
Map<Integer,String> m = new HashMap<Integer,String>();
m.put( 1, "NewYork" );
m.put( 2, "Tokyo" );
m.put( 3, "Bangalore" );
m.put( 4, "London" );
m.put( 5, "Paris" );
return m;
}
@Test
public void testBag() {
Bag bag = new HashBag();
bag.add( 4, 6 );
bag.remove( 4, 3 );
assertThat( bag.getCount( 4 ), is( 3 ) );
Iterator iter = bag.iterator();
while( iter.hasNext() ) {
System.out.println( System.identityHashCode( iter.next() ) );
}
}
@Test
public void testMapIteration() {
Map<Integer,String> map = initMap();
Iterator<Entry<Integer,String>> entSet = map.entrySet().iterator();
while( entSet.hasNext() ) {
Entry<Integer,String> e = entSet.next();
System.out.printf( "%d-%s\n", e.getKey(), e.getValue() );
}
}
private Map<Integer,String> initMap() {
Map<Integer,String> m = new HashMap<Integer,String>();
m.put( 1, "NewYork" );
m.put( 2, "Tokyo" );
m.put( 3, "Bangalore" );
m.put( 4, "London" );
m.put( 5, "Paris" );
return m;
}
/**
* Order not stable. Result is like ..
* <pre>
* 2Tokyo
* 4London
* 1NewYork
* 3Bangalore
* 5Paris
* </pre>
*/
@Test
public void testIterableMap() {
IterableMap map = new HashedMap( initMap() );
MapIterator iter = map.mapIterator();
String val = null;
int key = 0;
while( iter.hasNext() ) {
iter.next();
key = ((Integer)iter.getKey()).intValue();
val = (String)iter.getValue();
System.out.printf("%d%s\n",key, val);
}
}
private Map<Integer,String> initMap() {
Map<Integer,String> m = new HashMap<Integer,String>();
m.put( 1, "NewYork" );
m.put( 2, "Tokyo" );
m.put( 3, "Bangalore" );
m.put( 4, "London" );
m.put( 5, "Paris" );
return m;
}
@SuppressWarnings("unchecked")
@Test
public void testOrderedMap() {
OrderedMap map = new LinkedMap( initMap() );
MapIterator iter = map.mapIterator();
String val = null;
int key = 0;
while( iter.hasNext() ) {
iter.next();
key = ((Integer)iter.getKey()).intValue();
val = (String)iter.getValue();
System.out.println(key + val);
}
map.clear();
map.put( 1, "Metuchen" );
map.put( 3, "Kosciuszko" );
map.put( 2, "Kitami" );
map.put( 5, "Tripoli" );
map.put( 4, "Serangoon" );
assertThat( ((Integer)map.firstKey()).intValue(), is( 1 ) );
assertThat( (String)map.get(map.firstKey()), is( "Metuchen" ) );
assertThat( ((Integer)map.nextKey(3)).intValue(), is( 2 ) );
assertThat( (String)map.get(map.nextKey(3)), is( "Kitami" ) );
}
private Map<Integer,String> initMap() {
Map<Integer,String> m = new HashMap<Integer,String>();
m.put( 1, "NewYork" );
m.put( 2, "Tokyo" );
m.put( 3, "Bangalore" );
m.put( 4, "London" );
m.put( 5, "Paris" );
return m;
}
#include <iostream>
#include <cstdlib>
using namespace std;
static char arrA[] = { 'A','B','B','E','G', 'K', 'U' };
static char arrB[] = { 'C','D','E','F','G', 'K', 'V','Z' };
void dump(char* arr, int size){
for(int i = 0;i < size;i++){
cout << arr[i] << ' ';
}
cout << endl;
}
void my_bsearch(char arr[], char target, int* idx){
cout << "bsearching.." << endl;
int min = 0;
int max = sizeof(arrB)/sizeof(char) - 1;
char midVal;
while(min <= max){
midVal = arrB[(min + max) / 2];
cout << target << ',' << min << ',' << max << ',' << midVal << ',' << (min + max)/2 << endl;
if(midVal == target) {
arr[*idx] = midVal;
*idx += 1;
return;
}
else if(midVal < target)
min = (min + max)/2 + 1;
else
max = (min + max)/2 - 1;
}
}
int main() {
char ansArr[100];
int delta = 0;
int idx = 0;
for(int i = 0;i < sizeof(arrA)/sizeof(char);i++){
my_bsearch(ansArr, arrA[i], &idx);
}
cout << "idx.." << idx << endl;
dump(ansArr, idx);
return EXIT_SUCCESS;
}
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import org.apache.commons.lang3.time.DateUtils;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
public class DateUtilTest {
private Date date;
@Before
public void init() {
Calendar cal = Calendar.getInstance();
cal.set( Calendar.YEAR, 1980 );
cal.set( Calendar.MONTH, 0 );
cal.set( Calendar.DAY_OF_MONTH, 2 );
cal.set( Calendar.HOUR_OF_DAY, 5 );
cal.set( Calendar.MINUTE, 20 );
cal.set( Calendar.SECOND, 30 );
cal.set( Calendar.MILLISECOND, 790 );
date = cal.getTime();
}
@Test
public void testAddAndSubtract() {
Calendar cal = Calendar.getInstance();
cal.setTime( DateUtils.addDays( date, 4 ) );
assertThat( cal.get( Calendar.DAY_OF_MONTH ), is( 6 ) );
cal = Calendar.getInstance();
cal.setTime( DateUtils.addHours( date, 5 ) );
assertThat( cal.get( Calendar.HOUR_OF_DAY ), is( 10 ) );
cal = DateUtils.toCalendar( DateUtils.addMilliseconds( date, 25 ) );
assertThat( cal.get( Calendar.MILLISECOND ), is( 815 ) );
// subtract
cal = DateUtils.toCalendar( DateUtils.addYears( date, -10 ) );
assertThat( cal.get( Calendar.YEAR ), is( 1970 ) );
// truncate
assertThat( DateUtils.truncate( date, Calendar.DAY_OF_MONTH ).toString(), is( "Wed Jan 02 00:00:00 EST 1980" ) );
}
@Test
public void testIterator() {
Iterator<Calendar> iter = DateUtils.iterator( date, DateUtils.RANGE_MONTH_SUNDAY );
int i = 0;
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd" );
while( iter.hasNext() ) {
if( ++i == 10 ) break;
System.out.print( sdf.format(iter.next().getTime()) + " ");
}
}
}
#include <cstdio>
#include <cstdlib>
int arrVal[] = {1,6,21,25,28,28,31,45,51,53,62,64,85};
int search_linear(int val) {
int st = 0;
int mid;
int end = 0;
int t;
while(true) {
// simulate out of index exception
try {
if( end >= (sizeof(arrVal) / sizeof(int)) )
throw "out of index access";
t = arrVal[end];
printf("t=%d,end=%d,val=%d,idx=%d\n",t,end,val,end);
if( t == val )
return end;
else if( t > val )
break;
} catch( char* str ) {
printf("exception:%s.\n", str );
break;
}
end++;
}
// now we know the end index of the "unbounded array.". Do the bsearch!
while( st <= end ) {
mid = (st + end) / 2;
printf("st=%d,end=%d,mid=%d,val=%d,midval=%d\n",st,end,mid,val,arrVal[mid]);
if( arrVal[mid] == val)
return mid;
else if( arrVal[mid] > val )
end = mid - 1;
else
st = mid + 1;
}
return -1;
}
int main() {
printf("%d ? %d\n",64,search(64));
printf("%d ? %d\n",25,search(25));
printf("%d ? %d\n",6,search(6));
printf("%d ? %d\n",19,search(19));
printf("%d ? %d\n",53,search(53));
printf("%d ? %d\n",85,search(85));
return EXIT_SUCCESS;
}
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
#define INTARRAY_MAX 10
int search(vector<pair<int,int>> v, int target) {
int st = 0;
int end = v.size() - 1;
int mid;
while( st < end ) {
mid = (st + end) / 2;
cout << st << ',' << end << ',' << mid << ',' << v.at(mid).second << endl;
if( v.at(mid).second == target )
return mid;
else if( v.at(mid).second > target )
end = mid - 1;
else
st = mid + 1;
}
return -1;
}
int main() {
vector<pair<int,int>> v;
int arrVal[] = { 0,1,3,15,18,26,38,45,50,62};
for( int i = 0;i < INTARRAY_MAX;i++ )
v.push_back(make_pair(i, arrVal[i] ));
cout << "find? " << search(v, 1) << endl;
cout << "find? " << search(v, 5) << endl;
return EXIT_SUCCESS;
}
0,9,4,18 0,3,1,1 find? 1 0,9,4,18 0,3,1,1 2,3,2,3 find? -1O(log2N)の平均又は最悪計算量で終えることできるのでデータ量が多くても大丈夫.(最もここではソートのコストは考慮に入れていない.)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define INTARRAY_MAX 10
int* gen_rand_intarray(int* arr, int size) {
for(int i = 0;i < size;i++){
*arr = rand() % size;
printf("%d\n",*arr);
arr++;
}
return arr;
}
int main() {
srand(time(NULL));
int* arr = (int*)malloc(INTARRAY_MAX*sizeof(int));
gen_rand_intarray(arr,INTARRAY_MAX);
for( int i = 0;i < INTARRAY_MAX;i++ ) {
printf("%i - %d[@%d]\n",i,*arr,arr);
arr++;
}
return EXIT_SUCCESS;
}
では要素の重複はゆるさないよ,となったら?リストからセットにデータを移し替えればおのずと重複要素は消えるが,整数列長は縮む可能性があるので解として不適な可能性がある.#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define INTARRAY_MAX 10
int main() {
srand(time(NULL));
int r,t;
int arr2[INTARRAY_MAX];
for(int i = 0;i < sizeof(arr2)/sizeof(int);i++)
arr2[i] = i;
for(int i = 0;i < INTARRAY_MAX;i++) {
r = rand() % INTARRAY_MAX;
t = arr2[r];
arr2[r] = arr2[i];
arr2[i] = t;
}
for(int i = 0;i < INTARRAY_MAX;i++)
printf("%d ", arr2[i]);
char ch;
scanf(&ch);
return EXIT_SUCCESS;
}
#include <iostream>
#include <vector>
#include <algorithm>
#define INTARRAY_MAX 10
int main() {
std::vector<int> v;
for( int i = 0;i < INTARRAY_MAX;i++ )
v.push_back(i);
std::random_shuffle(v.begin(),v.end());
for(std::vector<int>::iterator it = v.begin();it != v.end();++it)
std::cout << *it << ' ';
std::cout << std::endl;
return EXIT_SUCCESS;
}
import java.util.Date;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
public class Trade {
private String tradeId;
private String eventId;
private Date settleDate;
private Date tradeDate;
private int counterPartyId;
public Trade( String tradeId, String eventId, Date settleDate, Date tradeDate, int counterPartyId ) {
this.tradeId = tradeId;
this.eventId = eventId;
this.settleDate = settleDate;
this.tradeDate = tradeDate;
this.counterPartyId = counterPartyId;
}
public boolean equals( Object obj ) {
boolean result = false;
if( obj instanceof Trade ) {
Trade other = (Trade)obj;
result = new EqualsBuilder().append( tradeId, other.getTradeId() )
.append( eventId, other.eventId )
.isEquals();
}
return result;
}
public int hashCode() {
return new HashCodeBuilder().append( tradeId )
.append( eventId ).toHashCode();
}
public String getTradeId() { return tradeId; }
public String getEventId() { return eventId; }
public Date getSettleDate() { return settleDate; }
public Date getTradeDate() { return tradeDate; }
public int getCounterPartyId() { return counterPartyId; }
}
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.junit.Test;
import static org.junit.Assert.*;
public class BuilderSampleTest {
@Test
public void testEqualsAndHashCode() throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd" );
Trade trd1 = new Trade( "TRD123", "21-123221", sdf.parse( "2012/03/04" ), sdf.parse( "2012/04/04" ), 565000 );
Trade trd2 = new Trade( "TRD238", "21-123250", sdf.parse( "2012/03/05" ), sdf.parse( "2012/04/04" ), 565000 );
Trade trd3 = new Trade( "TRD123", "21-123250", sdf.parse( "2012/03/05" ), sdf.parse( "2012/04/09" ), 565300 );
Trade trd4 = new Trade( "TRD126", "21-123221", sdf.parse( "2012/03/04" ), sdf.parse( "2012/04/04" ), 565000 );
Trade trd5 = new Trade( "TRD123", "21-123221", sdf.parse( "2012/03/04" ), sdf.parse( "2012/04/04" ), 565000 );
Trade trd6 = new Trade( "TRD123", "21-123221", sdf.parse( "2012/05/04" ), sdf.parse( "2012/06/04" ), 620000 );
// trd1 and trd2 - composite primary key different
assertTrue( !trd1.equals( trd2 ) );
// trd1 and trd3 - composite primary key different
assertTrue( !trd1.equals( trd3 ) );
// trd1 and trd4 - composite primary key different
assertTrue( !trd1.equals( trd4 ) );
// trd1 and trd5 - both composite primary key and non-key fields are same. Of course.
assertTrue( trd1.equals( trd5 ) );
// trd1 and trd6 - composite primary key is same but non-key fields are different - WHAT?!
assertTrue( trd1.equals( trd6 ) );
// trd1 and non-Trade object
assertTrue( !trd1.equals( new String() ) );
}
}