-
Notifications
You must be signed in to change notification settings - Fork 0
/
IPFSPackageCenter.java
33 lines (29 loc) · 1.12 KB
/
IPFSPackageCenter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.ArrayList;
import java.util.Random;
public class IPFSPackageCenter {
/**
* This class for peers add packages and get randomly packages from
* our central IPFS file storage repo, actually we want to develop
* a distributed package manager for peers,
* but we don't forget all the packages need a storage area
*/
public static ArrayList<MetaPackage> allPackages = new ArrayList<>(); // Static list to store all packages
// Method to add package to the list
public static void addPackage(MetaPackage packageToAdd) {
allPackages.add(packageToAdd);
}
// Method to randomly select and send a package from the list
public static MetaPackage sendRandomPackage() {
if (allPackages.size() > 0) {
Random random = new Random();
int randomPackageIndex = random.nextInt(allPackages.size());
return allPackages.get(randomPackageIndex);
} else {
// Return null if there are no packages in the list
return null;
}
}
public static Integer getSize() {
return allPackages.size();
}
}