1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_SORTING_MAP_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_SORTING_MAP_H
18 
19 #include "notification_sorting.h"
20 #include "parcel.h"
21 
22 namespace OHOS {
23 namespace Notification {
24 class NotificationSortingMap final : public Parcelable {
25 public:
26     NotificationSortingMap();
27 
28     ~NotificationSortingMap();
29 
30     /**
31      * @brief A constructor used to create a NotificationSortingMap instance by copying parameters from an existing one.
32      *
33      * @param sortingList Indicates the NotificationSortingMap object.
34      */
35     NotificationSortingMap(const std::vector<NotificationSorting> &sortingList);
36 
37     /**
38      * @brief Obtains the list of sorted hash codes.
39      *
40      * @return Returns the list of sorted hash codes.
41      */
GetKey()42     inline std::vector<std::string> GetKey()
43     {
44         return sortedKey_;
45     }
46 
47     /**
48      * @brief Obtains NotificationSorting based on the hash codes.
49      *
50      * @param key Indicates the hash codes obtained by using getkey().
51      * @param sorting Indicates the sorting information about the hash codes.
52      * @return Returns true if succeed; returns false otherwise.
53      */
54     bool GetNotificationSorting(const std::string &key, NotificationSorting &sorting) const;
55 
56     /**
57      * @brief Marshals a NotificationSortingMap object into a Parcel.
58      *
59      * @param parcel Indicates the Parcel object for marshalling.
60      * @return Returns true if the marshalling is successful; returns false otherwise.
61      */
62     bool Marshalling(Parcel &parcel) const override;
63 
64     /**
65      * @brief Unmarshals a NotificationSortingMap object from a Parcel.
66      *
67      * @param parcel Indicates the Parcel object for unmarshalling.
68      * @return Returns the NotificationSortingMap object.
69      */
70     static NotificationSortingMap *Unmarshalling(Parcel &parcel);
71 
72     /**
73      * @brief Dumps sorting map info
74      *
75      * @return Returns sorting map info to string.
76      */
77     std::string Dump() const;
78 
79 private:
80     void SetKey(const std::string &key);
81     void SetNotificationSorting(const std::vector<NotificationSorting> &sortingList);
82 
83 private:
84     std::vector<std::string> sortedKey_ {};
85     std::map<std::string, NotificationSorting> sortings_ {};
86 };
87 }  // namespace Notification
88 }  // namespace OHOS
89 
90 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_SORTING_MAP_H