Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.HashSet;
import java.util.Iterator;

import java.util.Set;

public class Main {
    protected static Set unionEmail(Set excluded, String email) {
        String _sub = email.substring(email.indexOf('@') + 1);

        if (excluded.isEmpty()) {
            excluded.add(_sub);
            return excluded;
        } else {
            Set intersect = new HashSet();

            Iterator _iter = excluded.iterator();
            while (_iter.hasNext()) {
                String _excluded = (String) _iter.next();

                if (_sub.endsWith(_excluded)) {
                    intersect.add(_excluded);
                } else if (_excluded.endsWith(_sub)) {
                    intersect.add(_sub);
                } else {
                    intersect.add(_excluded);
                    intersect.add(_sub);
                }
            }

            return intersect;
        }
    }
}