Java Utililty Methods Number Sum

List of utility methods to do Number Sum

Description

The list of methods to do Number Sum are organized into topic(s).

Method

intsumHash(int hash, String element)
sum Hash
return hash * 31 + element.hashCode();
intsumHash(int leftHash, int rightHash)
Sums the hash of the left and the right children

May be used only when calculating a non-leaf node's hash code from its children's hashes.

return leftHash + rightHash;
intsumIf(final Integer number, final Integer sum, final Boolean condition)
sum If
int result = number != null ? number : 0;
if (Boolean.TRUE.equals(condition) && sum != null) {
    result += sum;
return result;
booleansumIsMod10(int sum)
sum Is Mod
return ((sum % 10) == 0);
intsumLange(int _a, int _b)
sum Lange
int a = _a;
int b = _b;
if (_a > _b) {
    b = _a;
    a = _b;
return (a + b) * (b - a + 1) / 2;
doublesumLogProb(double a, double b)
Returns Math.log(Math.exp(a) + Math.exp(b)).
if (a == Double.NEGATIVE_INFINITY) {
    if (b == Double.NEGATIVE_INFINITY)
        return Double.NEGATIVE_INFINITY;
    return b;
} else if (b == Double.NEGATIVE_INFINITY)
    return a;
else if (a > b)
    return a + Math.log(1 + Math.exp(b - a));
...
Stringsummarize(String longString, int limit)
summarize
String s = longString;
if (s.indexOf("<p>") > -1)
    s = s.substring(0, s.indexOf("<p>"));
if (s.indexOf("\n") > -1)
    s = s.substring(0, s.indexOf("\n"));
return s.length() > limit ? s.substring(0, limit) + "..." : s;
StringsummarizeCigarString(String cigarString)
summarize Cigar String
StringBuilder summarizedCigarString = new StringBuilder();
if (cigarString.length() > 0) {
    int numberOfRepeats = 1;
    char currentlyRepeatingChar = cigarString.charAt(0);
    for (int i = 1; i < cigarString.length(); i++) {
        char currentChar = cigarString.charAt(i);
        if (currentlyRepeatingChar == currentChar) {
            numberOfRepeats++;
...
Stringsummary(String text)
summary
if (text == null) {
    return "null";
return text.substring(0, Math.min(10, text.length()));
intsummatory(int value)
Summatory.
int summatoryValue = 0;
for (int i = 0; i <= value; i++)
    summatoryValue += i;
return summatoryValue;