1 /*
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 
17 package com.android.tools.appbundle.bundletool;
18 
19 import com.google.common.collect.ImmutableList;
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.zip.ZipEntry;
23 
24 /** Represents a single module inside App Bundle. */
25 public class BundleModule {
26 
27   private AppBundle parent;
28   private String name;
29   private List<ZipEntry> entries;
30 
BundleModule(String name, AppBundle parent, List<ZipEntry> entries)31   private BundleModule(String name, AppBundle parent, List<ZipEntry> entries) {
32     this.parent = parent;
33     this.name = name;
34     this.entries = entries;
35   }
36 
getName()37   public String getName() {
38     return name;
39   }
40 
getParent()41   public AppBundle getParent() {
42     return parent;
43   }
44 
getEntries()45   public List<ZipEntry> getEntries() {
46     return ImmutableList.copyOf(entries);
47   }
48 
49   /** Builder for BundleModule. */
50   public static class Builder {
51     private List<ZipEntry> entries;
52     private String name;
53     private AppBundle parent;
54 
Builder(String name, AppBundle parent)55     public Builder(String name, AppBundle parent) {
56       this.name = name;
57       this.parent = parent;
58       this.entries = new ArrayList<>();
59     }
60 
addZipEntry(ZipEntry entry)61     public Builder addZipEntry(ZipEntry entry) {
62       this.entries.add(entry);
63       return this;
64     }
65 
build()66     public BundleModule build() {
67       return new BundleModule(name, parent, entries);
68     }
69   }
70 }
71