/**
 *
 * Copyright (c) 2006-2016, Speedment, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); You may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.speedment.internal.util;

import static com.speedment.util.StaticClassUtil.instanceNotAllowed;
import java.util.prefs.Preferences;

/**
 *
 * @author Emil Forslund
 */
public final class EmailUtil {
    
    private final static String FIELD_NAME = "user_mail";
    private final static String DEFAULT_EMAIL = "no-mail-specified";
    private final static Preferences PREFERENCES = Preferences.userNodeForPackage(EmailUtil.class);
    
    public static boolean hasEmail() {
        return !DEFAULT_EMAIL.equals(PREFERENCES.get(FIELD_NAME, DEFAULT_EMAIL));
    }
    
    public static String getEmail() {
        return PREFERENCES.get(FIELD_NAME, DEFAULT_EMAIL);
    }
    
    public static void setEmail(String email) {
        PREFERENCES.put(FIELD_NAME, email == null ? DEFAULT_EMAIL : email);
    }
    
    private EmailUtil() {
        instanceNotAllowed(getClass());
    }
}
@@ -731,16 +731,91 @@
 llowed;%0A
+import static java.util.Objects.requireNonNull;%0Aimport java.util.Optional;%0A
 import j
@@ -910,20 +910,16 @@
 lUtil %7B%0A
-    
 %0A    pri
@@ -1138,20 +1138,16 @@
 class);%0A
-    
 %0A    pub
@@ -1190,88 +1190,253 @@
     
-return !DEFAULT_EMAIL.equals(PREFERENCES.get(FIELD_NAME, DEFAULT_EMAIL))
+final String storedEmail = PREFERENCES.get(FIELD_NAME, null);%0A        if (storedEmail == null) %7B%0A            return false;%0A        %7D%0A        if (DEFAULT_EMAIL.equals(storedEmail)) %7B%0A            return false;%0A        %7D%0A        return true
 ;%0A    %7D%0A
     
@@ -1423,36 +1423,32 @@
 urn true;%0A    %7D%0A
-    
 %0A    public stat
@@ -1485,16 +1485,49 @@
  return 
+Optional.ofNullable(%0A            
 PREFEREN
@@ -1546,16 +1546,39 @@
 D_NAME, 
+null)%0A        ).orElse(
 DEFAULT_
@@ -1595,128 +1595,209 @@
   %7D%0A
+%0A
     
-%0A    public static void setEmail(String email) %7B%0A        PREFERENCES.put(FIELD_NAME, email == null ? DEFAULT_EMAIL :
+public static void removeEmail() %7B%0A        PREFERENCES.remove(FIELD_NAME);%0A    %7D%0A%0A    public static void setEmail(String email) %7B%0A        requireNonNull(email);%0A        PREFERENCES.put(FIELD_NAME,
  ema
@@ -1807,20 +1807,16 @@
 ;%0A    %7D%0A
-    
 %0A    pri
@@ -1881,8 +1881,9 @@
 %0A    %7D%0A%7D
+%0A

Fix EmailUtil potential issues