com.mysql.cj.conf

## Class HostInfo

- java.lang.Object
- - com.mysql.cj.conf.HostInfo

All Implemented Interfaces:
  DatabaseUrlContainer

    public class HostInfo
    extends Object
    implements DatabaseUrlContainer

This class holds the following MySQL host information:

- host: an IP or host name.
- port: the port number or 0 if not known.
- user: the user name.
- password: the password.
- host properties: host specific connection arguments.

### Field Summary

Fields
`private String` `host`
`private static String` `HOST_PORT_SEPARATOR`
`private Map<String,String>` `hostProperties`
`static int` `NO_PORT`
`private DatabaseUrlContainer` `originalUrl`
`private String` `password`
`private int` `port`
`private String` `user`

### Constructor Summary

Constructors
Constructor and Description
`HostInfo()` Constructs an empty `HostInfo` instance.
`HostInfo(DatabaseUrlContainer url, String host, int port, String user, String password)` Constructs a `HostInfo` instance initialized with the provided host, port and user info.
`HostInfo(DatabaseUrlContainer url, String host, int port, String user, String password, Map<String,String> properties)` Constructs a `HostInfo` instance initialized with the provided host, port, user, password and connection arguments.

### Method Summary

All Methods Instance Methods Concrete Methods
`boolean` `equalHostPortPair(HostInfo hi)` Checks if this `HostInfo` has the same host and port pair as the given `HostInfo`.
`Properties` `exposeAsProperties()` Exposes this host info as a single properties instance.
`String` `getDatabase()` Shortcut to the database connection argument.
`String` `getDatabaseUrl()` Returns the original database URL that produced this host info.
`String` `getHost()` Returns the host.
`String` `getHostPortPair()` Returns a host:port representation of this host.
`Map<String,String>` `getHostProperties()` Returns the properties specific to this host.
`String` `getPassword()` Returns the password.
`int` `getPort()` Returns the port.
`String` `getProperty(String key)` Returns the connection argument for the given key.
`String` `getUser()` Returns the user name.
`String` `toString()` Returns a string representation of this object.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### NO_PORT

    public static final int NO_PORT

See Also:
  Constant Field Values

#### HOST_PORT_SEPARATOR

    private static final String HOST_PORT_SEPARATOR

See Also:
  Constant Field Values

#### originalUrl

    private final DatabaseUrlContainer originalUrl

#### host

    private final String host

#### port

    private final int port

#### user

    private final String user

#### password

    private final String password

#### hostProperties

    private final Map<String,String> hostProperties

### Constructor Detail

#### HostInfo

    public HostInfo()

Constructs an empty `HostInfo` instance.

#### HostInfo

    public HostInfo(DatabaseUrlContainer url,
                    String host,
                    int port,
                    String user,
                    String password)

Constructs a `HostInfo` instance initialized with the provided host, port and user info.

Parameters:
  `url` - a reference to the original database URL that produced this host info
  `host` - the host ip or name
  `port` - the port
  `user` - the user name
  `password` - the user's password

#### HostInfo

    public HostInfo(DatabaseUrlContainer url,
                    String host,
                    int port,
                    String user,
                    String password,
                    Map<String,String> properties)

Constructs a `HostInfo` instance initialized with the provided host, port, user, password and connection arguments.

Parameters:
  `url` - a reference to the original database URL that produced this host info
  `host` - the host ip or name
  `port` - the port
  `user` - the user name
  `password` - this user's password
  `properties` - a connection arguments map.

### Method Detail

#### getHost

    public String getHost()

Returns the host.

Returns:
  the host

#### getPort

    public int getPort()

Returns the port.

Returns:
  the port

#### getHostPortPair

    public String getHostPortPair()

Returns a host:port representation of this host.

Returns:
  the host:port representation of this host

#### getUser

    public String getUser()

Returns the user name.

Returns:
  the user name

#### getPassword

    public String getPassword()

Returns the password.

Returns:
  the password

#### getHostProperties

    public Map<String,String> getHostProperties()

Returns the properties specific to this host.

Returns:
  this host specific properties

#### getProperty

    public String getProperty(String key)

Returns the connection argument for the given key.

Parameters:
  `key` - key
Returns:
  the connection argument for the given key

#### getDatabase

    public String getDatabase()

Shortcut to the database connection argument.

Returns:
  the database name

#### exposeAsProperties

    public Properties exposeAsProperties()

Exposes this host info as a single properties instance. The values for host, port, user and password are added to the properties map with their standard keys.

Returns:
  a `Properties` instance containing the full host information.

#### getDatabaseUrl

    public String getDatabaseUrl()

Returns the original database URL that produced this host info.

Specified by:
  `getDatabaseUrl` in interface `DatabaseUrlContainer`
Returns:
  the original database URL

#### equalHostPortPair

    public boolean equalHostPortPair(HostInfo hi)

Checks if this `HostInfo` has the same host and port pair as the given `HostInfo`.

Parameters:
  `hi` - the `HostInfo` to compare with.
Returns:
  `true` if both objects have equal host and port pairs, `false` otherwise.

#### toString

    public String toString()

Returns a string representation of this object.

Overrides:
  `toString` in class `Object`
Returns:
  a string representation of this object

Copyright © 2016, 2023, Oracle and/or its affiliates.