1 package org.andromda.translation.ocl.validation;
2
3 import org.apache.commons.lang.BooleanUtils;
4
5
6
7
8
9 public final class OCLExpressions
10 {
11
12
13
14
15
16 public static boolean equal(
17 final Object first,
18 final Object second)
19 {
20 return (first == null) ? (second == null) : first.equals(second);
21 }
22
23
24
25
26
27
28 public static boolean equal(
29 final boolean first,
30 final boolean second)
31 {
32 return first == second;
33 }
34
35
36
37
38
39
40 public static boolean equal(
41 final int first,
42 final int second)
43 {
44 return first == second;
45 }
46
47
48
49
50
51
52 public static boolean equal(
53 final short first,
54 final short second)
55 {
56 return first == second;
57 }
58
59
60
61
62
63
64 public static boolean equal(
65 final byte first,
66 final byte second)
67 {
68 return first == second;
69 }
70
71
72
73
74
75
76 public static boolean equal(
77 final char first,
78 final char second)
79 {
80 return first == second;
81 }
82
83
84
85
86
87
88 public static boolean equal(
89 final float first,
90 final float second)
91 {
92 return first == second;
93 }
94
95
96
97
98
99
100 public static boolean equal(
101 final double first,
102 final double second)
103 {
104 return first == second;
105 }
106
107
108
109
110
111
112 public static boolean equal(
113 final long first,
114 final long second)
115 {
116 return first == second;
117 }
118
119
120
121
122
123
124 public static boolean equal(
125 final Object first,
126 final boolean second)
127 {
128 return (second) ? Boolean.TRUE.equals(first) || BooleanUtils.toBoolean(String.valueOf(first))
129 : Boolean.FALSE.equals(first) || !BooleanUtils.toBoolean(String.valueOf(first));
130 }
131
132
133
134
135
136
137 public static boolean equal(
138 final boolean first,
139 final Object second)
140 {
141 return equal(second, first);
142 }
143
144
145
146
147
148
149 public static boolean notEqual(
150 final Object first,
151 final Object second)
152 {
153 return first == null ? second != null : !first.equals(second);
154 }
155
156
157
158
159
160
161 public static boolean notEqual(
162 final boolean first,
163 final boolean second)
164 {
165 return first != second;
166 }
167
168
169
170
171
172
173 public static boolean equal(
174 final Object first,
175 final long second)
176 {
177 boolean equal = first instanceof Comparable;
178 if (equal)
179 {
180 final Comparable comparable = (Comparable) first;
181 if (comparable instanceof Integer)
182 {
183 equal = comparable.compareTo(Integer.valueOf((int) second)) > 0;
184 }
185 else
186 {
187 equal = comparable.equals(Long.valueOf(second));
188 }
189 }
190 return equal;
191 }
192
193
194
195
196
197
198 public static boolean equal(
199 final Object first,
200 final int second)
201 {
202 boolean equal = first instanceof Comparable;
203 if (equal)
204 {
205 final Comparable comparable = (Comparable) first;
206 equal = comparable.equals(Integer.valueOf(second));
207 }
208 return equal;
209 }
210
211
212
213
214
215
216 public static boolean notEqual(
217 final int first,
218 final int second)
219 {
220 return first != second;
221 }
222
223
224
225
226
227
228 public static boolean notEqual(
229 final short first,
230 final short second)
231 {
232 return first != second;
233 }
234
235
236
237
238
239
240 public static boolean notEqual(
241 final byte first,
242 final byte second)
243 {
244 return first != second;
245 }
246
247
248
249
250
251
252 public static boolean notEqual(
253 final char first,
254 final char second)
255 {
256 return first != second;
257 }
258
259
260
261
262
263
264 public static boolean notEqual(
265 final float first,
266 final float second)
267 {
268 return first != second;
269 }
270
271
272
273
274
275
276 public static boolean notEqual(
277 final double first,
278 final double second)
279 {
280 return first != second;
281 }
282
283
284
285
286
287
288 public static boolean notEqual(
289 final long first,
290 final long second)
291 {
292 return first != second;
293 }
294
295
296
297
298
299
300 public static boolean notEqual(
301 final Object first,
302 final boolean second)
303 {
304 return !equal(first, second);
305 }
306
307
308
309
310
311
312 public static boolean notEqual(
313 final boolean first,
314 final Object second)
315 {
316 return notEqual(second, first);
317 }
318
319
320
321
322
323
324 public static boolean less(
325 final Comparable first,
326 final Comparable second)
327 {
328 return first == null ? second == null : first.compareTo(second) < 0;
329 }
330
331
332
333
334
335
336 public static boolean less(
337 final int first,
338 final int second)
339 {
340 return first < second;
341 }
342
343
344
345
346
347
348 public static boolean less(
349 final short first,
350 final short second)
351 {
352 return first < second;
353 }
354
355
356
357
358
359
360 public static boolean less(
361 final byte first,
362 final byte second)
363 {
364 return first < second;
365 }
366
367
368
369
370
371
372 public static boolean less(
373 final char first,
374 final char second)
375 {
376 return first < second;
377 }
378
379
380
381
382
383
384 public static boolean less(
385 final float first,
386 final float second)
387 {
388 return first < second;
389 }
390
391
392
393
394
395
396 public static boolean less(
397 final double first,
398 final double second)
399 {
400 return first < second;
401 }
402
403
404
405
406
407
408 public static boolean less(
409 final long first,
410 final long second)
411 {
412 return first < second;
413 }
414
415
416
417
418
419
420 public static boolean lessOrEqual(
421 final Comparable first,
422 final Comparable second)
423 {
424 return first == null ? second == null : (first.compareTo(second) <= 0);
425 }
426
427
428
429
430
431
432 public static boolean lessOrEqual(
433 final Object first,
434 final Object second)
435 {
436 boolean lessOrEqual = first instanceof Comparable && second instanceof Comparable;
437 if (lessOrEqual)
438 {
439 lessOrEqual = lessOrEqual((Comparable) first, (Comparable) second);
440 }
441 return lessOrEqual;
442 }
443
444
445
446
447
448
449 public static boolean lessOrEqual(
450 final int first,
451 final int second)
452 {
453 return first <= second;
454 }
455
456
457
458
459
460
461 public static boolean lessOrEqual(
462 final short first,
463 final short second)
464 {
465 return first <= second;
466 }
467
468
469
470
471
472
473 public static boolean lessOrEqual(
474 final byte first,
475 final byte second)
476 {
477 return first <= second;
478 }
479
480
481
482
483
484
485 public static boolean lessOrEqual(
486 final char first,
487 final char second)
488 {
489 return first <= second;
490 }
491
492
493
494
495
496
497 public static boolean lessOrEqual(
498 final float first,
499 final float second)
500 {
501 return first <= second;
502 }
503
504
505
506
507
508
509 public static boolean lessOrEqual(
510 final Object first,
511 final float second)
512 {
513 boolean lessOrEqual = first instanceof Comparable;
514 if (lessOrEqual)
515 {
516 lessOrEqual = lessOrEqual((Comparable) first, Float.valueOf(second));
517 }
518 return lessOrEqual;
519 }
520
521
522
523
524
525
526 public static boolean lessOrEqual(
527 final float first,
528 final Object second)
529 {
530 boolean lessOrEqual = second instanceof Comparable;
531 if (lessOrEqual)
532 {
533 lessOrEqual = lessOrEqual(new Float(first), (Comparable) second);
534 }
535 return lessOrEqual;
536 }
537
538
539
540
541
542
543 public static boolean lessOrEqual(
544 final double first,
545 final double second)
546 {
547 return first <= second;
548 }
549
550
551
552
553
554
555 public static boolean lessOrEqual(
556 final Object first,
557 final double second)
558 {
559 boolean lessOrEqual = first instanceof Comparable;
560 if (lessOrEqual)
561 {
562 lessOrEqual = lessOrEqual((Comparable) first, Double.valueOf(second));
563 }
564 return lessOrEqual;
565 }
566
567
568
569
570
571
572 public static boolean lessOrEqual(
573 final double first,
574 final Object second)
575 {
576 boolean lessOrEqual = second instanceof Comparable;
577 if (lessOrEqual)
578 {
579 lessOrEqual = lessOrEqual(Double.valueOf(first), (Comparable) second);
580 }
581 return lessOrEqual;
582 }
583
584
585
586
587
588
589 public static boolean lessOrEqual(
590 final long first,
591 final long second)
592 {
593 return first <= second;
594 }
595
596
597
598
599
600
601 public static boolean lessOrEqual(
602 final Object first,
603 final long second)
604 {
605 boolean lessOrEqual = first instanceof Comparable;
606 if (lessOrEqual)
607 {
608 if (first instanceof Integer)
609 {
610 lessOrEqual = lessOrEqual((Comparable) first, Integer.valueOf((int) second));
611 }
612 else
613 {
614 lessOrEqual = lessOrEqual((Comparable) first, Long.valueOf(second));
615 }
616 }
617 return lessOrEqual;
618 }
619
620
621
622
623
624
625 public static boolean lessOrEqual(
626 final Object first,
627 final int second)
628 {
629 boolean lessOrEqual = first instanceof Comparable;
630 if (lessOrEqual)
631 {
632 lessOrEqual = lessOrEqual((Comparable) first, Integer.valueOf(second));
633 }
634 return lessOrEqual;
635 }
636
637
638
639
640
641
642 public static boolean lessOrEqual(
643 final Object first,
644 final short second)
645 {
646 boolean lessOrEqual = first instanceof Comparable;
647 if (lessOrEqual)
648 {
649 lessOrEqual = lessOrEqual((Comparable) first, Short.valueOf(second));
650 }
651 return lessOrEqual;
652 }
653
654
655
656
657
658
659 public static boolean lessOrEqual(
660 final long first,
661 final Object second)
662 {
663 boolean lessOrEqual = second instanceof Comparable;
664 if (lessOrEqual)
665 {
666 if (second instanceof Integer)
667 {
668 lessOrEqual = lessOrEqual(Integer.valueOf((int) first), (Comparable) second);
669 }
670 else
671 {
672 lessOrEqual = lessOrEqual(Long.valueOf(first), (Comparable) second);
673 }
674 }
675 return lessOrEqual;
676 }
677
678
679
680
681
682
683 public static boolean lessOrEqual(
684 final int first,
685 final Object second)
686 {
687 boolean lessOrEqual = second instanceof Comparable;
688 if (lessOrEqual)
689 {
690 lessOrEqual = lessOrEqual(new Integer(first), (Comparable) second);
691 }
692 return lessOrEqual;
693 }
694
695
696
697
698
699
700 public static boolean lessOrEqual(
701 final short first,
702 final Object second)
703 {
704 boolean lessOrEqual = second instanceof Comparable;
705 if (lessOrEqual)
706 {
707 lessOrEqual = lessOrEqual(new Short(first), (Comparable) second);
708 }
709 return lessOrEqual;
710 }
711
712
713
714
715
716
717 public static boolean greater(
718 final Comparable first,
719 final Comparable second)
720 {
721 return first == null ? second == null : first.compareTo(second) > 0;
722 }
723
724
725
726
727
728
729 public static boolean greater(
730 final Object first,
731 final long second)
732 {
733 boolean greater = first instanceof Comparable;
734 if (greater)
735 {
736 final Comparable comparable = (Comparable) first;
737 if (comparable instanceof Integer)
738 {
739 greater = comparable.compareTo(Integer.valueOf((int) second)) > 0;
740 } else
741 {
742 greater = comparable.compareTo(Long.valueOf(second)) > 0;
743 }
744 }
745 return greater;
746 }
747
748
749
750
751
752
753 public static boolean greater(
754 final Object first,
755 final int second)
756 {
757 boolean greater = first instanceof Comparable;
758 if (greater)
759 {
760 final Comparable comparable = (Comparable) first;
761 if (comparable instanceof Integer)
762 {
763 greater = comparable.compareTo(Integer.valueOf(second)) > 0;
764 } else
765 {
766 greater = comparable.compareTo(Long.valueOf(second)) > 0;
767 }
768 }
769 return greater;
770 }
771
772
773
774
775
776
777 public static boolean greater(
778 final byte first,
779 final byte second)
780 {
781 return first > second;
782 }
783
784
785
786
787
788
789 public static boolean greater(
790 final char first,
791 final char second)
792 {
793 return first > second;
794 }
795
796
797
798
799
800
801 public static boolean greater(
802 final float first,
803 final float second)
804 {
805 return first > second;
806 }
807
808
809
810
811
812
813 public static boolean greater(
814 final double first,
815 final double second)
816 {
817 return first > second;
818 }
819
820
821
822
823
824
825 public static boolean greater(
826 final long first,
827 final long second)
828 {
829 return first > second;
830 }
831
832
833
834
835
836
837 public static boolean greaterOrEqual(
838 final Comparable first,
839 final Comparable second)
840 {
841 return first == null ? second == null : first.compareTo(second) >= 0;
842 }
843
844
845
846
847
848
849 public static boolean greaterOrEqual(
850 final Object first,
851 final long second)
852 {
853 boolean greaterOrEqual = first instanceof Comparable;
854 if (greaterOrEqual)
855 {
856 if (first instanceof Integer)
857 {
858 greaterOrEqual = greaterOrEqual((Comparable) first, Integer.valueOf((int) second));
859 } else
860 {
861 greaterOrEqual = greaterOrEqual((Comparable) first, Long.valueOf(second));
862 }
863 }
864 return greaterOrEqual;
865 }
866
867
868
869
870
871
872 public static boolean greaterOrEqual(
873 final Object first,
874 final int second)
875 {
876 boolean greaterOrEqual = first instanceof Comparable;
877 if (greaterOrEqual)
878 {
879 greaterOrEqual = greaterOrEqual((Comparable) first, Integer.valueOf(second));
880 }
881 return greaterOrEqual;
882 }
883
884
885
886
887
888
889 public static boolean greaterOrEqual(
890 final Object first,
891 final short second)
892 {
893 boolean greaterOrEqual = first instanceof Comparable;
894 if (greaterOrEqual)
895 {
896 greaterOrEqual = greaterOrEqual((Comparable) first, Short.valueOf(second));
897 }
898 return greaterOrEqual;
899 }
900
901
902
903
904
905
906 public static boolean greaterOrEqual(
907 final long first,
908 final Object second)
909 {
910 boolean greaterOrEqual = second instanceof Comparable;
911 if (greaterOrEqual)
912 {
913 if (second instanceof Integer)
914 {
915 greaterOrEqual = greaterOrEqual(Integer.valueOf((int) first), (Integer) second);
916 } else
917 {
918 greaterOrEqual = greaterOrEqual(Long.valueOf(first), (Comparable) second);
919 }
920 }
921 return greaterOrEqual;
922 }
923
924
925
926
927
928
929 public static boolean greaterOrEqual(
930 final int first,
931 final Object second)
932 {
933 boolean greaterOrEqual = second instanceof Comparable;
934 if (greaterOrEqual)
935 {
936 greaterOrEqual = greaterOrEqual(Integer.valueOf(first), (Comparable) second);
937 }
938 return greaterOrEqual;
939 }
940
941
942
943
944
945
946 public static boolean greaterOrEqual(
947 final short first,
948 final Object second)
949 {
950 boolean greaterOrEqual = second instanceof Comparable;
951 if (greaterOrEqual)
952 {
953 greaterOrEqual = greaterOrEqual(Short.valueOf(first), (Comparable) second);
954 }
955 return greaterOrEqual;
956 }
957
958
959
960
961
962
963 public static boolean greaterOrEqual(
964 final Object first,
965 final Object second)
966 {
967 boolean greaterOrEqual = first instanceof Comparable && second instanceof Comparable;
968 if (greaterOrEqual)
969 {
970 greaterOrEqual = greaterOrEqual((Comparable) first, (Comparable) second);
971 }
972 return greaterOrEqual;
973 }
974
975
976
977
978
979
980 public static boolean greaterOrEqual(
981 final Object first,
982 final double second)
983 {
984 boolean greaterOrEqual = first instanceof Comparable;
985 if (greaterOrEqual)
986 {
987 greaterOrEqual = greaterOrEqual((Comparable) first, Double.valueOf(second));
988 }
989 return greaterOrEqual;
990 }
991
992
993
994
995
996
997 public static boolean greaterOrEqual(
998 final Object first,
999 final float second)
1000 {
1001 boolean greaterOrEqual = first instanceof Comparable;
1002 if (greaterOrEqual)
1003 {
1004 greaterOrEqual = greaterOrEqual((Comparable) first, Float.valueOf(second));
1005 }
1006 return greaterOrEqual;
1007 }
1008
1009
1010
1011
1012
1013
1014 public static boolean greaterOrEqual(
1015 final double first,
1016 final Object second)
1017 {
1018 boolean greaterOrEqual = second instanceof Comparable;
1019 if (greaterOrEqual)
1020 {
1021 greaterOrEqual = greaterOrEqual(new Double(first), (Comparable) second);
1022 }
1023 return greaterOrEqual;
1024 }
1025
1026
1027
1028
1029
1030
1031 public static boolean greaterOrEqual(
1032 final float first,
1033 final Object second)
1034 {
1035 boolean greaterOrEqual = second instanceof Comparable;
1036 if (greaterOrEqual)
1037 {
1038 greaterOrEqual = greaterOrEqual(new Float(first), (Comparable) second);
1039 }
1040 return greaterOrEqual;
1041 }
1042
1043
1044
1045
1046
1047
1048 public static boolean greaterOrEqual(
1049 final byte first,
1050 final byte second)
1051 {
1052 return first >= second;
1053 }
1054
1055
1056
1057
1058
1059
1060 public static boolean greaterOrEqual(
1061 final char first,
1062 final char second)
1063 {
1064 return first >= second;
1065 }
1066
1067
1068
1069
1070
1071
1072 public static boolean greaterOrEqual(
1073 final double first,
1074 final double second)
1075 {
1076 return first >= second;
1077 }
1078
1079
1080
1081
1082
1083
1084 public static boolean greaterOrEqual(
1085 final long first,
1086 final long second)
1087 {
1088 return first >= second;
1089 }
1090 }