OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
Line 14... Line 14...
14
 package org.openconcerto.utils;
14
 package org.openconcerto.utils;
15
 
15
 
16
import java.io.PrintWriter;
16
import java.io.PrintWriter;
17
import java.io.StringWriter;
17
import java.io.StringWriter;
18
import java.lang.reflect.Constructor;
18
import java.lang.reflect.Constructor;
-
 
19
import java.math.BigDecimal;
-
 
20
import java.util.Objects;
-
 
21
import java.util.function.BiPredicate;
19
 
22
 
20
/**
23
/**
21
 * Utilitaires pour les exceptions.
24
 * Utilitaires pour les exceptions.
22
 * 
25
 * 
23
 * @author Sylvain CUAZ 25 nov. 2004
26
 * @author Sylvain CUAZ 25 nov. 2004
Line 90... Line 93...
90
        }
93
        }
91
        if (pw.checkError())
94
        if (pw.checkError())
92
            Log.get().warning("Error while writing " + cause);
95
            Log.get().warning("Error while writing " + cause);
93
        return res.toString();
96
        return res.toString();
94
    }
97
    }
-
 
98
 
-
 
99
    static public void requireEquals(final BigDecimal a, final BigDecimal b, final String msg) {
-
 
100
        require((bd1, bd2) -> bd1.compareTo(bd2) == 0, a, b, msg);
-
 
101
    }
-
 
102
 
-
 
103
    static public void requireEquals(final Object a, final Object b, final String msg) {
-
 
104
        require(Objects::equals, a, b, msg);
-
 
105
    }
-
 
106
 
-
 
107
    static public <T> void require(final BiPredicate<T, T> pred, final T a, final T b, final String msg) {
-
 
108
        if (!pred.test(a, b))
-
 
109
            throw new IllegalArgumentException(msg + ", expected " + a + " but got " + b);
-
 
110
    }
-
 
111
 
-
 
112
    static public void requireSame(final Object a, final Object b, final String msg) {
-
 
113
        if (a != b)
-
 
114
            throw new IllegalArgumentException(msg + ", expected same reference to " + a + " but got " + b);
-
 
115
    }
-
 
116
 
-
 
117
    static public void requireEquals(final int a, final int b, final String msg) {
-
 
118
        if (a != b)
-
 
119
            throw new IllegalArgumentException(msg + ", expected " + a + " but got " + b);
-
 
120
    }
95
}
121
}