1 21 22 package org.opensubsystems.patterns.listdata.data; 23 24 import java.io.Serializable ; 25 import java.sql.Timestamp ; 26 import java.util.HashMap ; 27 import java.util.Map ; 28 29 37 public class DataCondition implements Serializable 38 { 39 41 44 public static final int NO_ATTRIBUTE = 0; 45 46 49 public static final int NO_OPERAND = 0; 50 51 54 public static final int OPERAND_EQUALS = 1; 55 56 65 public static final int OPERAND_IN = 2; 66 67 76 public static final int OPERAND_NOT_IN = 3; 77 78 82 public static final int OPERAND_NOT_EQUALS = 4; 83 84 88 public static final int OPERAND_GREATER = 5; 89 90 94 public static final int OPERAND_GREATER_EQUALS = 6; 95 96 100 public static final int OPERAND_LESS = 7; 101 102 106 public static final int OPERAND_LESS_EQUALS = 8; 107 108 112 public static final int OPERAND_LIKE_CASEUNSENSITIVE = 9; 113 114 118 public static final int OPERAND_LIKE_CASESENSITIVE = 10; 119 120 131 public static final int OPERAND_SQL_QUERY = 11; 132 133 137 public static final int OPERAND_EQUALS_OR_NULL = 12; 138 139 143 public static final int OPERAND_NOT_LIKE_CASEUNSENSITIVE = 13; 144 145 149 public static final int OPERAND_NOT_LIKE_CASESENSITIVE = 14; 150 151 155 public static final int OPERAND_STARTS_CASEUNSENSITIVE = 15; 156 157 161 public static final int OPERAND_STARTS_CASESENSITIVE = 16; 162 163 167 public static final int OPERAND_NOT_STARTS_CASEUNSENSITIVE = 17; 168 169 173 public static final int OPERAND_NOT_STARTS_CASESENSITIVE = 18; 174 175 179 public static final int OPERAND_ENDS_CASEUNSENSITIVE = 19; 180 181 185 public static final int OPERAND_ENDS_CASESENSITIVE = 20; 186 187 191 public static final int OPERAND_NOT_ENDS_CASEUNSENSITIVE = 21; 192 193 197 public static final int OPERAND_NOT_ENDS_CASESENSITIVE = 22; 198 199 203 public static final int OPERAND_EQUALS_CASEUNSENSITIVE = 23; 204 205 209 public static final int OPERAND_EQUALS_CASESENSITIVE = 24; 210 211 215 public static final int OPERAND_NOT_EQUALS_CASEUNSENSITIVE = 25; 216 217 221 public static final int OPERAND_NOT_EQUALS_CASESENSITIVE = 26; 222 223 226 public static final int DATA_CODE_FLAG_YES = 1; 227 228 231 public static final Integer DATA_CODE_FLAG_YES_OBJ = new Integer (DATA_CODE_FLAG_YES); 232 233 236 public static final int DATA_CODE_FLAG_NO = 0; 237 238 241 public static final Integer DATA_CODE_FLAG_NO_OBJ = new Integer (DATA_CODE_FLAG_NO); 242 243 246 249 public static final int VALUE_TYPE_UNKNOWN = 0; 250 251 254 public static final int VALUE_TYPE_ID = 1; 255 256 259 public static final int VALUE_TYPE_BOOLEAN = 2; 260 261 264 public static final int VALUE_TYPE_INTEGER = 3; 265 266 269 public static final int VALUE_TYPE_DOUBLE = 4; 270 271 274 public static final int VALUE_TYPE_STRING = 5; 275 276 279 public static final int VALUE_TYPE_TIMESTAMP = 6; 280 281 283 286 private static Map s_mapYesNo = new HashMap (4); 287 288 290 293 private static final long serialVersionUID = 8522583231285548064L; 294 295 299 protected int m_iAttribute; 300 301 305 protected int m_iOperation; 306 307 310 protected Object m_objValue; 311 312 315 protected int m_iValueType; 316 317 323 protected Object m_objOriginalValue; 324 325 327 static 328 { 329 s_mapYesNo.put("YES", new Integer (1)); 330 s_mapYesNo.put("TRUE", new Integer (1)); 331 s_mapYesNo.put("NO", new Integer (0)); 332 s_mapYesNo.put("FALSE", new Integer (0)); 333 } 334 335 338 public DataCondition() 339 { 340 this(DataCondition.NO_ATTRIBUTE, DataCondition.NO_OPERAND, 341 null, VALUE_TYPE_STRING); 342 } 343 344 359 public DataCondition( 360 int attribute, 361 int operation, 362 Object value, 363 int valueType 364 ) 365 { 366 this(attribute, operation, value, valueType, value); 367 } 368 369 385 public DataCondition( 386 int attribute, 387 int operation, 388 Object value, 389 int valueType, 390 Object originalValue 391 ) 392 { 393 m_iAttribute = attribute; 394 m_iOperation = operation; 395 m_objValue = value; 396 m_iValueType = valueType; 397 m_objOriginalValue = originalValue; 398 } 399 400 403 public int getAttribute() 404 { 405 return m_iAttribute; 406 } 407 408 411 public int getOperation() 412 { 413 return m_iOperation; 414 } 415 416 419 public Object getValue() 420 { 421 return m_objValue; 422 } 423 424 427 public void setValue( 428 Object objValue 429 ) 430 { 431 m_objValue = objValue; 432 } 433 434 437 public int getValueType() 438 { 439 return m_iValueType; 440 } 441 442 445 public Object getOriginalValue() 446 { 447 return m_objOriginalValue; 448 } 449 450 453 public void setOriginalValue( 454 Object objOriginalValue 455 ) 456 { 457 m_objOriginalValue = objOriginalValue; 458 } 459 460 463 public String getValueString() 464 { 465 StringBuffer sbReturn = new StringBuffer (); 466 if (m_objValue != null) 467 { 468 469 if (m_iOperation != DataCondition.OPERAND_IN 470 && m_iOperation != DataCondition.OPERAND_NOT_IN) 471 { 472 switch (m_iValueType) 474 { 475 case (DataCondition.VALUE_TYPE_ID) : 476 { 477 sbReturn.append(((Integer ) m_objValue).intValue()); 478 break; 479 } 480 case (DataCondition.VALUE_TYPE_BOOLEAN) : 481 { 482 sbReturn.append(((Boolean ) m_objValue).booleanValue()); 483 break; 484 } 485 case (DataCondition.VALUE_TYPE_INTEGER) : 486 { 487 sbReturn.append(((Integer ) m_objValue).intValue()); 488 break; 489 } 490 case (DataCondition.VALUE_TYPE_DOUBLE) : 491 { 492 sbReturn.append(((Double ) m_objValue).doubleValue()); 493 break; 494 } 495 case (DataCondition.VALUE_TYPE_STRING) : 496 { 497 sbReturn.append(m_objValue); 498 break; 499 } 500 case (DataCondition.VALUE_TYPE_TIMESTAMP) : 501 { 502 sbReturn.append(((Timestamp ) m_objValue).getTime()); 503 break; 504 } 505 default : 506 { 507 assert false : "Not supported data condition value type."; 508 } 509 } 510 } 511 else 512 { 513 Object [] arrObject = (Object []) m_objValue; 515 Object oHelp; 516 for (int iCounter = 0; iCounter < arrObject.length; iCounter++) 517 { 518 oHelp = arrObject[iCounter]; 519 if (sbReturn.length() > 0) 520 { 521 sbReturn.append(","); 522 } 523 switch (m_iValueType) 524 { 525 case (DataCondition.VALUE_TYPE_ID) : 526 { 527 sbReturn.append(((Integer ) oHelp).intValue()); 528 break; 529 } 530 case (DataCondition.VALUE_TYPE_BOOLEAN) : 531 { 532 sbReturn.append(((Boolean ) oHelp).booleanValue()); 533 break; 534 } 535 case (DataCondition.VALUE_TYPE_INTEGER) : 536 { 537 sbReturn.append(((Integer ) oHelp).intValue()); 538 break; 539 } 540 case (DataCondition.VALUE_TYPE_DOUBLE) : 541 { 542 sbReturn.append(((Double ) oHelp).doubleValue()); 543 break; 544 } 545 case (DataCondition.VALUE_TYPE_STRING) : 546 { 547 sbReturn.append(oHelp); 548 break; 549 } 550 case (DataCondition.VALUE_TYPE_TIMESTAMP) : 551 { 552 sbReturn.append(((Timestamp ) oHelp).getTime()); 553 break; 554 } 555 default : 556 { 557 assert false : "Not supported data condition value type."; 558 } 559 } 560 } 561 } 562 } 563 return sbReturn.toString(); 564 } 565 566 569 public String getOriginalValueString() 570 { 571 StringBuffer sbReturn = new StringBuffer (); 572 if (m_objOriginalValue != null) 573 { 574 575 if (m_iOperation != DataCondition.OPERAND_IN 576 && m_iOperation != DataCondition.OPERAND_NOT_IN) 577 { 578 switch (m_iValueType) 580 { 581 case (DataCondition.VALUE_TYPE_ID) : 582 { 583 sbReturn.append(((Integer ) m_objOriginalValue).intValue()); 584 break; 585 } 586 case (DataCondition.VALUE_TYPE_BOOLEAN) : 587 { 588 sbReturn.append(((Boolean ) m_objOriginalValue).booleanValue()); 589 break; 590 } 591 case (DataCondition.VALUE_TYPE_INTEGER) : 592 { 593 sbReturn.append(((Integer ) m_objOriginalValue).intValue()); 594 break; 595 } 596 case (DataCondition.VALUE_TYPE_DOUBLE) : 597 { 598 sbReturn.append(((Double ) m_objOriginalValue).doubleValue()); 599 break; 600 } 601 case (DataCondition.VALUE_TYPE_STRING) : 602 { 603 sbReturn.append(m_objOriginalValue); 604 break; 605 } 606 case (DataCondition.VALUE_TYPE_TIMESTAMP) : 607 { 608 sbReturn.append(((Timestamp ) m_objOriginalValue).getTime()); 609 break; 610 } 611 default : 612 { 613 assert false : "Not supported data condition value type."; 614 } 615 } 616 } 617 else 618 { 619 Object [] arrObject = (Object []) m_objOriginalValue; 621 Object oHelp; 622 for (int iCounter = 0; iCounter < arrObject.length; iCounter++) 623 { 624 oHelp = arrObject[iCounter]; 625 if (sbReturn.length() > 0) 626 { 627 sbReturn.append(","); 628 } 629 switch (m_iValueType) 630 { 631 case (DataCondition.VALUE_TYPE_ID) : 632 { 633 sbReturn.append(((Integer ) oHelp).intValue()); 634 break; 635 } 636 case (DataCondition.VALUE_TYPE_BOOLEAN) : 637 { 638 sbReturn.append(((Boolean ) oHelp).booleanValue()); 639 break; 640 } 641 case (DataCondition.VALUE_TYPE_INTEGER) : 642 { 643 sbReturn.append(((Integer ) oHelp).intValue()); 644 break; 645 } 646 case (DataCondition.VALUE_TYPE_DOUBLE) : 647 { 648 sbReturn.append(((Double ) oHelp).doubleValue()); 649 break; 650 } 651 case (DataCondition.VALUE_TYPE_STRING) : 652 { 653 sbReturn.append(oHelp); 654 break; 655 } 656 case (DataCondition.VALUE_TYPE_TIMESTAMP) : 657 { 658 sbReturn.append(((Timestamp ) oHelp).getTime()); 659 break; 660 } 661 default : 662 { 663 assert false : "Not supported data condition value type."; 664 } 665 } 666 } 667 } 668 } 669 return sbReturn.toString(); 670 } 671 672 675 public static Map getYesNoMap( 676 ) 677 { 678 return s_mapYesNo; 679 } 680 } 681 | Popular Tags |