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    public LogPartition getLogPartition() {
046        return LogPartition.of(name, partition);
047    }
048
049    @Override
050    public boolean equals(Object o) {
051        if (this == o)
052            return true;
053        if (o == null || getClass() != o.getClass())
054            return false;
055        LogPartitionGroup that = (LogPartitionGroup) o;
056        return partition == that.partition && (group != null ? group.equals(that.group) : that.group == null)
057                && (name != null ? name.equals(that.name) : that.name == null);
058    }
059
060    @Override
061    public int hashCode() {
062        int result = group != null ? group.hashCode() : 0;
063        result = 31 * result + (name != null ? name.hashCode() : 0);
064        result = 31 * result + partition;
065        return result;
066    }
067
068    @Override
069    public String toString() {
070        return String.format("%s:%s-%02d", group, name, partition);
071    }
072
073}