001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.reef.wake.examples.join; 020 021/** 022 * A tuple event consisting key and value pair. 023 */ 024public class TupleEvent implements Comparable<TupleEvent> { 025 private final int key; 026 private final String val; 027 028 public TupleEvent(final int key, final String val) { 029 this.key = key; 030 this.val = val; 031 } 032 033 @Override 034 public boolean equals(final Object o) { 035 if (this == o) { 036 return true; 037 } 038 if (o == null || getClass() != o.getClass()) { 039 return false; 040 } 041 042 TupleEvent that = (TupleEvent) o; 043 044 if (key != that.key) { 045 return false; 046 } 047 return val != null ? val.equals(that.val) : that.val == null; 048 049 } 050 051 @Override 052 public int hashCode() { 053 int result = key; 054 result = 31 * result + (val != null ? val.hashCode() : 0); 055 return result; 056 } 057 058 @Override 059 public int compareTo(final TupleEvent o) { 060 final int keycmp = Integer.compare(key, o.key); 061 if (keycmp != 0) { 062 return keycmp; 063 } 064 return val.compareTo(o.val); 065 } 066 067 @Override 068 public String toString() { 069 return "(" + key + ", " + val + ")"; 070 } 071 072}