1 /* 2 * Copyright (C) 2024 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.statementservice.retriever; 18 19 import android.annotation.Nullable; 20 21 import java.util.Map; 22 23 /** 24 * A immutable value type representing a dynamic app link component 25 */ 26 public final class DynamicAppLinkComponent { 27 private final boolean mExclude; 28 private final String mFragment; 29 private final String mPath; 30 private final Map<String, String> mQuery; 31 private final String mComments; 32 DynamicAppLinkComponent(boolean exclude, String fragment, String path, Map<String, String> query, String comments)33 private DynamicAppLinkComponent(boolean exclude, String fragment, String path, 34 Map<String, String> query, String comments) { 35 mExclude = exclude; 36 mFragment = fragment; 37 mPath = path; 38 mQuery = query; 39 mComments = comments; 40 } 41 42 /** 43 * Returns true or false indicating whether this rule should be a exclusion rule. 44 */ getExclude()45 public boolean getExclude() { 46 return mExclude; 47 } 48 49 /** 50 * Returns a optional pattern string for matching URL fragments. 51 */ 52 @Nullable getFragment()53 public String getFragment() { 54 return mFragment; 55 } 56 57 /** 58 * Returns a optional pattern string for matching URL paths. 59 */ 60 @Nullable getPath()61 public String getPath() { 62 return mPath; 63 } 64 65 /** 66 * Returns a optional pattern string for matching a single key-value pair in the URL query 67 * params. 68 */ 69 @Nullable getQuery()70 public Map<String, String> getQuery() { 71 return mQuery; 72 } 73 74 /** 75 * Returns a optional comment string for this component. 76 */ 77 @Nullable getComments()78 public String getComments() { 79 return mComments; 80 } 81 82 /** 83 * Creates a new DynamicAppLinkComponent object. 84 */ create(boolean exclude, String fragment, String path, Map<String, String> query, String comments)85 public static DynamicAppLinkComponent create(boolean exclude, String fragment, String path, 86 Map<String, String> query, String comments) { 87 return new DynamicAppLinkComponent(exclude, fragment, path, query, comments); 88 } 89 90 @Override equals(Object o)91 public boolean equals(Object o) { 92 if (this == o) { 93 return true; 94 } 95 if (o == null || getClass() != o.getClass()) { 96 return false; 97 } 98 99 DynamicAppLinkComponent rule = (DynamicAppLinkComponent) o; 100 101 if (mExclude != rule.mExclude) { 102 return false; 103 } 104 if (!mFragment.equals(rule.mFragment)) { 105 return false; 106 } 107 if (!mPath.equals(rule.mPath)) { 108 return false; 109 } 110 if (!mQuery.equals(rule.mQuery)) { 111 return false; 112 } 113 if (!mComments.equals(rule.mComments)) { 114 return false; 115 } 116 117 return true; 118 } 119 120 @Override hashCode()121 public int hashCode() { 122 int result = Boolean.hashCode(mExclude); 123 result = 31 * result + mFragment.hashCode(); 124 result = 31 * result + mPath.hashCode(); 125 result = 31 * result + mQuery.hashCode(); 126 result = 31 * result + mComments.hashCode(); 127 return result; 128 } 129 130 @Override toString()131 public String toString() { 132 StringBuilder statement = new StringBuilder(); 133 statement.append("DynamicAppLinkComponent: "); 134 statement.append(mExclude); 135 statement.append(", "); 136 statement.append(mFragment); 137 statement.append(", "); 138 statement.append(mPath); 139 statement.append(", "); 140 statement.append(mQuery); 141 statement.append(", "); 142 statement.append(mComments); 143 return statement.toString(); 144 } 145 } 146