1 /* 2 * Copyright (C) 2023 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.queryable.info; 18 19 import com.android.bedstead.nene.annotations.Nullable; 20 21 import java.io.Serializable; 22 23 /** 24 * Wrapper for information about a Metadata. 25 */ 26 public final class MetadataInfo implements Serializable { 27 28 private static final long serialVersionUID = 1; 29 30 private final String mKey; 31 private final MetadataValue mValue; 32 private ResourceInfo mResource; 33 34 /** Return a new builder for {@link MetadataInfo}. */ builder()35 public static MetadataInfo.Builder builder() { 36 return new MetadataInfo.Builder(); 37 } 38 MetadataInfo(String key, MetadataValue value, ResourceInfo resource)39 private MetadataInfo(String key, MetadataValue value, ResourceInfo resource) { 40 mKey = key; 41 mValue = value; 42 mResource = resource; 43 } 44 45 /** Get key of the metadata tag. */ key()46 public String key() { 47 return mKey; 48 } 49 50 /** Get value of the metadata tag. */ 51 @Nullable value()52 public MetadataValue value() { 53 return mValue; 54 } 55 56 /** Get resource of the metadata tag. */ 57 @Nullable resource()58 public ResourceInfo resource() { 59 return mResource; 60 } 61 62 /** Set resource of {@link MetadataInfo}. */ setResource(ResourceInfo resource)63 public void setResource(ResourceInfo resource) { 64 mResource = resource; 65 } 66 67 @Override toString()68 public String toString() { 69 return "Metadata{" 70 + "key=" + mKey 71 + ", value=" + (mValue == null ? "null" : mValue.asString()) 72 + ", resource=" + (mResource == null ? "null" : mResource.asString()) 73 + "}"; 74 } 75 76 /** Builder for {@link MetadataInfo}. */ 77 public static final class Builder { 78 String mKey; 79 MetadataValue mValue; 80 ResourceInfo mResource; 81 82 /** Set the key with the key provided. */ key(String key)83 public MetadataInfo.Builder key(String key) { 84 mKey = key; 85 return this; 86 } 87 88 /** Set the value with the value provided. */ value(MetadataValue value)89 public MetadataInfo.Builder value(MetadataValue value) { 90 mValue = value; 91 return this; 92 } 93 94 /** Set the resource with the resource provided. */ resource(ResourceInfo resource)95 public MetadataInfo.Builder resource(ResourceInfo resource) { 96 mResource = resource; 97 return this; 98 } 99 100 /** Build the {@link MetadataInfo}*/ build()101 public MetadataInfo build() { 102 return new MetadataInfo(mKey, mValue, mResource); 103 } 104 } 105 } 106