source: java/main/src/main/java/com/framsticks/util/Misc.java @ 193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
1package com.framsticks.util;
2
3// import org.apache.logging.log4j.Logger;
4
5/**
6 * Author: Piotr Śniegowski
7 */
8public class Misc {
9        // private static final Logger log =
10        //      LogManager.getLogger(Misc.class);
11
12        public static class WithType {
13                protected Object value;
14
15                /**
16                 * @param value
17                 */
18                public WithType(Object value) {
19                        this.value = value;
20                }
21
22                @Override
23                public String toString() {
24                        if (value == null) {
25                                return "null";
26                        }
27                        return value + "(" + value.getClass() + ")";
28                }
29        }
30
31        public static WithType withType(Object value) {
32                return new WithType(value);
33        }
34
35        public static boolean equals(Object a, Object b) {
36                // log.info("equality of {} ? {}", withType(a), withType(b));
37                if (a != null) {
38                        return (b != null && a.equals(b));
39                }
40                return b == null;
41        }
42
43        public static <T> T returnNotNull(T first, T second) {
44                if (first != null) {
45                        return first;
46                }
47                return second;
48        }
49
50        public static <T> T throwIfNull(T value) {
51                if (value == null) {
52                        throw new FramsticksException().msg("value should not be null");
53                }
54                return value;
55        }
56
57        public static void checkEquals(Object expected, Object found, String message, Object context) {
58                if (equals(expected, found)) {
59                        return;
60                }
61                FramsticksException e = new FramsticksException().msg(message).arg("expected", expected).arg("found", found);
62                if (context != null) {
63                        e.arg("in", context);
64                }
65                throw e;
66        }
67
68        public static Class<?> getClass(Object object) {
69                return (object != null ? object.getClass() : null);
70        }
71}
Note: See TracBrowser for help on using the repository browser.