001/*
002 * (C) Copyright 2017 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     bdelbosc
018 */
019package org.nuxeo.lib.stream.log.internals;
020
021import org.nuxeo.lib.stream.log.LogPartition;
022
023/**
024 * @since 9.3
025 */
026public class LogPartitionGroup {
027    public final String group;
028
029    public final String name;
030
031    public final int partition;
032
033    public LogPartitionGroup(String group, LogPartition mqp) {
034        this.group = group;
035        this.name = mqp.name();
036        this.partition = mqp.partition();
037    }
038
039    public LogPartitionGroup(String group, String name, int partition) {
040        this.group = group;
041        this.name = name;
042        this.partition = partition;
043    }
044
045    @Override
046    public boolean equals(Object o) {
047        if (this == o)
048            return true;
049        if (o == null || getClass() != o.getClass())
050            return false;
051        LogPartitionGroup that = (LogPartitionGroup) o;
052        return partition == that.partition && (group != null ? group.equals(that.group) : that.group == null)
053                && (name != null ? name.equals(that.name) : that.name == null);
054    }
055
056    @Override
057    public int hashCode() {
058        int result = group != null ? group.hashCode() : 0;
059        result = 31 * result + (name != null ? name.hashCode() : 0);
060        result = 31 * result + partition;
061        return result;
062    }
063
064    @Override
065    public String toString() {
066        return String.format("%s:%s-%02d", group, name, partition);
067    }
068
069}