org.gradoop.flink.algorithms.fsm.pojos.Intersection.java Source code

Java tutorial

Introduction

Here is the source code for org.gradoop.flink.algorithms.fsm.pojos.Intersection.java

Source

/*
 * This file is part of Gradoop.
 *
 * Gradoop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Gradoop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Gradoop. If not, see <http://www.gnu.org/licenses/>.
 */

package org.gradoop.flink.algorithms.fsm.pojos;

import com.google.common.collect.Sets;

import java.util.Set;
import java.util.TreeSet;

/**
 * Represents the intersection of two integer sets.
 */
public class Intersection {

    /**
     * Edge ids
     */
    private final TreeSet<Integer> ids;

    /**
     * Constructor.
     *
     * @param first first integer set
     * @param second first integer set
     */
    public Intersection(Set<Integer> first, Set<Integer> second) {
        this.ids = Sets.newTreeSet(first);
        this.ids.addAll(second);
    }

    /**
     * Returns the number of intersecting numbers.
     *
     * @return intersection size
     */
    public int size() {
        return ids.size();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Intersection that = (Intersection) o;

        return ids != null ? ids.equals(that.ids) : that.ids == null;
    }

    @Override
    public int hashCode() {
        return ids.hashCode();
    }

    @Override
    public String toString() {
        return ids.toString();
    }
}