Home | History | Annotate | Download | only in impl
      1 /*
      2  * Copyright (C) 2018 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License
     15  */
     16 
     17 package com.android.voicemail.impl;
     18 
     19 import com.google.auto.value.AutoValue;
     20 import com.google.common.base.Optional;
     21 
     22 /**
     23  * Matches a {@link CarrierIdentifier}. Full equality check on CarrierIdentifiers is often unfit
     24  * because non-MVNO carriers usually just specify the {@link CarrierIdentifier#mccMnc()} while their
     25  * {@link CarrierIdentifier#gid1()} could be anything. This matcher ignore fields that are not
     26  * specified in the matcher.
     27  */
     28 @AutoValue
     29 public abstract class CarrierIdentifierMatcher {
     30 
     31   public abstract String mccMnc();
     32 
     33   public abstract Optional<String> gid1();
     34 
     35   public static Builder builder() {
     36     return new AutoValue_CarrierIdentifierMatcher.Builder();
     37   }
     38 
     39   /** Builder for the matcher */
     40   @AutoValue.Builder
     41   public abstract static class Builder {
     42     public abstract Builder setMccMnc(String mccMnc);
     43 
     44     public abstract Builder setGid1(String gid1);
     45 
     46     public abstract CarrierIdentifierMatcher build();
     47   }
     48 
     49   public boolean matches(CarrierIdentifier carrierIdentifier) {
     50     if (!mccMnc().equals(carrierIdentifier.mccMnc())) {
     51       return false;
     52     }
     53     if (gid1().isPresent()) {
     54       if (!gid1().get().equals(carrierIdentifier.gid1())) {
     55         return false;
     56       }
     57     }
     58     return true;
     59   }
     60 }
     61