blob: 0401a22759f9e364b2835f9c92f2cebe39802d4b [file] [log] [blame]
Justin Klaassen4d01eea2018-04-03 23:21:57 -04001/*
2 * Copyright (C) 2017 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
17package androidx.lifecycle;
18
19import androidx.annotation.RestrictTo;
20
21import java.util.HashMap;
22import java.util.Map;
23
24/**
25 * @hide
26 */
27@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
28public class MethodCallsLogger {
29 private Map<String, Integer> mCalledMethods = new HashMap<>();
30
31 /**
32 * @hide
33 */
34 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
35 public boolean approveCall(String name, int type) {
36 Integer nullableMask = mCalledMethods.get(name);
37 int mask = nullableMask != null ? nullableMask : 0;
38 boolean wasCalled = (mask & type) != 0;
39 mCalledMethods.put(name, mask | type);
40 return !wasCalled;
41 }
42}