001/*
002 * Copyright (c) 2007-2017 Xplenty, Inc. All Rights Reserved.
003 *
004 * Project and contact information: http://www.cascading.org/
005 *
006 * This file is part of the Cascading project.
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *     http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020
021package cascading.flow.planner;
022
023import java.io.Serializable;
024
025/**
026 *
027 */
028public class PlatformInfo implements Serializable, Comparable<PlatformInfo>
029  {
030  public static final PlatformInfo NULL = new PlatformInfo( null, null, null );
031
032  public final String name;
033  public final String vendor;
034  public final String version;
035
036  public PlatformInfo( String name, String vendor, String version )
037    {
038    this.name = name;
039    this.vendor = vendor;
040    this.version = version;
041    }
042
043  @Override
044  public int compareTo( PlatformInfo other )
045    {
046    if( other == null )
047      return 1;
048
049    return this.toString().compareTo( other.toString() );
050    }
051
052  @Override
053  public boolean equals( Object object )
054    {
055    if( this == object )
056      return true;
057    if( object == null || getClass() != object.getClass() )
058      return false;
059
060    PlatformInfo that = (PlatformInfo) object;
061
062    if( name != null ? !name.equals( that.name ) : that.name != null )
063      return false;
064    if( vendor != null ? !vendor.equals( that.vendor ) : that.vendor != null )
065      return false;
066    if( version != null ? !version.equals( that.version ) : that.version != null )
067      return false;
068
069    return true;
070    }
071
072  @Override
073  public int hashCode()
074    {
075    int result = name != null ? name.hashCode() : 0;
076    result = 31 * result + ( vendor != null ? vendor.hashCode() : 0 );
077    result = 31 * result + ( version != null ? version.hashCode() : 0 );
078    return result;
079    }
080
081  @Override
082  public String toString()
083    {
084    final StringBuilder sb = new StringBuilder();
085
086    if( name == null )
087      sb.append( "UNKNOWN" ).append( ':' );
088    else
089      sb.append( name ).append( ':' );
090
091    if( version != null )
092      sb.append( version ).append( ':' );
093
094    if( vendor != null )
095      sb.append( vendor );
096
097    return sb.toString();
098    }
099  }