1 21 package com.db4o.test.types; 22 23 import com.db4o.test.*; 24 25 public class TEntry { 26 27 public Object key; 28 public Object value; 29 30 public TEntry(){ 31 } 32 33 public TEntry(Object key, Object value) { 34 this.key = key; 35 this.value = value; 36 } 37 38 public TEntry firstElement(){ 39 return new TEntry("first", "firstvalue"); 40 } 41 42 public TEntry lastElement(){ 43 return new TEntry(new ObjectSimplePublic("lastKey"), new ObjectSimplePublic("lastValue")); 44 } 45 46 public TEntry noElement(){ 47 return new TEntry("NO", "babe"); 48 } 49 50 public TEntry[] test(int ver){ 51 if(ver == 1){ 52 return new TEntry[]{ 53 firstElement(), 54 new TEntry(new Integer (111), new ObjectSimplePublic("111")), 55 new TEntry(new Long (9999111), new Double (0.4566)), 56 69 lastElement() 70 }; 71 } 72 return new TEntry[]{ 73 new TEntry(new Integer (222), new ObjectSimplePublic("111")), 74 new TEntry("222", "TrippleTwo"), 75 new TEntry(new ObjectSimplePublic("2222"), new ObjectSimplePublic("222")), 76 }; 77 } 78 79 public void compare(TEntry[] a_cmp, int oneOrTwo, boolean keysOnly){ 80 TEntry[] tests = test(oneOrTwo); 81 TEntry[] cmp = new TEntry[a_cmp.length]; 82 System.arraycopy(a_cmp,0, cmp, 0, a_cmp.length); 83 if(cmp == null){ 84 Regression.addError("Entry:argument is null"); 85 return; 86 } 87 if(cmp.length != tests.length){ 88 Regression.addError("Entry:arrays of different length"); 89 return; 90 } 91 for(int i = 0; i < tests.length; i ++){ 92 boolean found = false; 93 for(int j=0; j < cmp.length; j++){ 94 if(cmp[j] != null){ 95 if(tests[i].key.equals(cmp[j].key)){ 96 if(!keysOnly){ 97 if(! tests[i].value.equals(cmp[j].value)){ 98 Regression.addError("Entry:inequality"); 99 return; 100 } 101 } 102 cmp[j] = null; 103 found = true; 104 break; 105 } 106 } 107 } 108 if(! found){ 109 110 Regression.addError("element not found"); 111 } 112 } 113 } 114 } | Popular Tags |