public class

NetworkState

extends java.lang.Object

 java.lang.Object

↳androidx.work.impl.constraints.NetworkState

Overview

Stores information about network state.

Summary

Constructors
publicNetworkState(boolean isConnected, boolean isValidated, boolean isMetered, boolean isNotRoaming)

Methods
public booleanequals(java.lang.Object o)

public inthashCode()

public booleanisConnected()

Determines if the network is connected.

public booleanisMetered()

Determines if the network is metered.

public booleanisNotRoaming()

Determines if the network is not roaming.

public booleanisValidated()

Determines if the network is validated - has a working Internet connection.

public java.lang.StringtoString()

from java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait

Constructors

public NetworkState(boolean isConnected, boolean isValidated, boolean isMetered, boolean isNotRoaming)

Methods

public boolean isConnected()

Determines if the network is connected.

Returns:

true if the network is connected.

public boolean isValidated()

Determines if the network is validated - has a working Internet connection.

Returns:

true if the network is validated.

public boolean isMetered()

Determines if the network is metered.

Returns:

true if the network is metered.

public boolean isNotRoaming()

Determines if the network is not roaming.

Returns:

true if the network is not roaming.

public boolean equals(java.lang.Object o)

public int hashCode()

public java.lang.String toString()

Source

/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.work.impl.constraints;

import androidx.annotation.NonNull;

/**
 * Stores information about network state.
 */
public class NetworkState {

    private boolean mIsConnected;
    private boolean mIsValidated;
    private boolean mIsMetered;
    private boolean mIsNotRoaming;

    public NetworkState(boolean isConnected, boolean isValidated, boolean isMetered,
                        boolean isNotRoaming) {
        mIsConnected = isConnected;
        mIsValidated = isValidated;
        mIsMetered = isMetered;
        mIsNotRoaming = isNotRoaming;
    }

    /**
     * Determines if the network is connected.
     *
     * @return {@code true} if the network is connected.
     */
    public boolean isConnected() {
        return mIsConnected;
    }

    /**
     * Determines if the network is validated - has a working Internet connection.
     *
     * @return {@code true} if the network is validated.
     */
    public boolean isValidated() {
        return mIsValidated;
    }

    /**
     * Determines if the network is metered.
     *
     * @return {@code true} if the network is metered.
     */
    public boolean isMetered() {
        return mIsMetered;
    }

    /**
     * Determines if the network is not roaming.
     *
     * @return {@code true} if the network is not roaming.
     */
    public boolean isNotRoaming() {
        return mIsNotRoaming;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof NetworkState)) {
            return false;
        }
        NetworkState other = (NetworkState) o;
        return this.mIsConnected == other.mIsConnected
                && this.mIsValidated == other.mIsValidated
                && this.mIsMetered == other.mIsMetered
                && this.mIsNotRoaming == other.mIsNotRoaming;
    }

    @Override
    public int hashCode() {
        int result = 0x0000;
        if (mIsConnected) result += 0x0001;
        if (mIsValidated) result += 0x0010;
        if (mIsMetered) result += 0x0100;
        if (mIsNotRoaming) result += 0x1000;
        return result;
    }

    @NonNull
    @Override
    public String toString() {
        return String.format("[ Connected=%b Validated=%b Metered=%b NotRoaming=%b ]",
                mIsConnected, mIsValidated, mIsMetered, mIsNotRoaming);
    }
}