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.ecm.platform.importer.mqueues.mqueues; 020 021/** 022 * A tuple to store MQueue name and the partition index. 023 * 024 * @since 9.2 025 */ 026public class MQPartition { 027 private final String name; 028 private final int partition; 029 030 public MQPartition(String name, int partition) { 031 this.name = name; 032 this.partition = partition; 033 } 034 035 /** 036 * Returns the MQueue's name 037 */ 038 public String name() { 039 return name; 040 } 041 042 /** 043 * Returns the partition index. 044 */ 045 public int partition() { 046 return partition; 047 } 048 049 @Override 050 public boolean equals(Object o) { 051 if (this == o) return true; 052 if (o == null || getClass() != o.getClass()) return false; 053 054 MQPartition that = (MQPartition) o; 055 056 if (partition != that.partition) return false; 057 return name != null ? name.equals(that.name) : that.name == null; 058 } 059 060 @Override 061 public int hashCode() { 062 int result = name != null ? name.hashCode() : 0; 063 result = 31 * result + partition; 064 return result; 065 } 066 067 @Override 068 public String toString() { 069 return String.format("%s-%02d", name, partition); 070 } 071 072 public static MQPartition of(String name, int partition) { 073 return new MQPartition(name, partition); 074 } 075}