org.clebi.subscribers.model.Email.java Source code

Java tutorial

Introduction

Here is the source code for org.clebi.subscribers.model.Email.java

Source

// Copyright 2016 Clment Bizeau
//
// 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 org.clebi.subscribers.model;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.validator.routines.EmailValidator;
import org.clebi.subscribers.validation.Validator;

@Data
@AllArgsConstructor(access = AccessLevel.PUBLIC)
public class Email implements Validator, CharSequence {

    private String email;

    @Override
    public boolean isValid() {
        return EmailValidator.getInstance().isValid(email);
    }

    @Override
    public int length() {
        return email.length();
    }

    @Override
    public char charAt(int index) {
        return email.charAt(index);
    }

    @Override
    public CharSequence subSequence(int start, int end) {
        return email.subSequence(start, end);
    }

    @Override
    public String toString() {
        return email;
    }
}