|  | 
|  | 1 | +/* | 
|  | 2 | + * Copyright 2025 Google LLC | 
|  | 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.google.firebase.remoteconfig; | 
|  | 18 | + | 
|  | 19 | +import static com.google.common.base.Preconditions.checkArgument; | 
|  | 20 | +import static com.google.common.base.Preconditions.checkNotNull; | 
|  | 21 | + | 
|  | 22 | +import com.google.common.collect.ImmutableList; | 
|  | 23 | +import com.google.firebase.internal.NonNull; | 
|  | 24 | +import com.google.firebase.remoteconfig.internal.ServerTemplateResponse.AndConditionResponse; | 
|  | 25 | +import com.google.firebase.remoteconfig.internal.ServerTemplateResponse.OneOfConditionResponse; | 
|  | 26 | + | 
|  | 27 | +import java.util.List; | 
|  | 28 | +import java.util.stream.Collectors; | 
|  | 29 | + | 
|  | 30 | +final class AndCondition { | 
|  | 31 | +  private final ImmutableList<OneOfCondition> conditions; | 
|  | 32 | + | 
|  | 33 | +  AndCondition(@NonNull List<OneOfCondition> conditions) { | 
|  | 34 | +    checkNotNull(conditions, "List of conditions for AND operation must not be null."); | 
|  | 35 | +    checkArgument(!conditions.isEmpty(),  | 
|  | 36 | +        "List of conditions for AND operation must not be empty."); | 
|  | 37 | +    this.conditions = ImmutableList.copyOf(conditions); | 
|  | 38 | +  } | 
|  | 39 | + | 
|  | 40 | +  AndCondition(AndConditionResponse andConditionResponse) { | 
|  | 41 | +    List<OneOfConditionResponse> conditionList = andConditionResponse.getConditions(); | 
|  | 42 | +    checkNotNull(conditionList, "List of conditions for AND operation must not be null."); | 
|  | 43 | +    checkArgument(!conditionList.isEmpty(),  | 
|  | 44 | +        "List of conditions for AND operation must not be empty"); | 
|  | 45 | +    this.conditions = conditionList.stream() | 
|  | 46 | +                                  .map(OneOfCondition::new)  | 
|  | 47 | +                                  .collect(ImmutableList.toImmutableList()); | 
|  | 48 | +  } | 
|  | 49 | + | 
|  | 50 | +  @NonNull | 
|  | 51 | +  ImmutableList<OneOfCondition> getConditions() { | 
|  | 52 | +    return conditions; | 
|  | 53 | +  } | 
|  | 54 | + | 
|  | 55 | +  AndConditionResponse toAndConditionResponse() { | 
|  | 56 | +    return new AndConditionResponse() | 
|  | 57 | +                   .setConditions(this.conditions.stream() | 
|  | 58 | +                                                 .map(OneOfCondition::toOneOfConditionResponse) | 
|  | 59 | +                                                 .collect(Collectors.toList()));     | 
|  | 60 | +  } | 
|  | 61 | +} | 
0 commit comments