56 lines
1.4 KiB
Java
56 lines
1.4 KiB
Java
package net.mindoverflow.webmarker.utils;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class URLMap {
|
|
|
|
private static List<Integer> ids = new ArrayList<>();
|
|
private static List<String> urls = new ArrayList<>();
|
|
|
|
public static void saveUrl(int userId, String url)
|
|
{
|
|
ids.add(userId);
|
|
urls.add(url);
|
|
System.out.println();
|
|
System.out.println("Saved ID: " + userId + "; URL: " + url);
|
|
System.out.println("table is now:");
|
|
for(int pos = 0; pos < ids.size(); pos++)
|
|
{
|
|
System.out.println("ID = " + ids.get(pos) + "; URL = " + urls.get(pos));
|
|
}
|
|
System.out.println();
|
|
}
|
|
|
|
public static List<String> getUserUrls(int userId)
|
|
{
|
|
List<String>thisUserUrls = new ArrayList<>();
|
|
for(int pos = 0; pos < ids.size(); pos++)
|
|
{
|
|
if(userId == ids.get(pos))
|
|
{
|
|
thisUserUrls.add(urls.get(pos));
|
|
}
|
|
}
|
|
|
|
return thisUserUrls;
|
|
}
|
|
|
|
public static void dropUser(int userId)
|
|
{
|
|
List<Integer> newIds = new ArrayList<>();
|
|
List<String> newUrls = new ArrayList<>();
|
|
for(int pos = 0; pos < ids.size(); pos++)
|
|
{
|
|
if(ids.get(pos) != userId)
|
|
{
|
|
newIds.add(ids.get(pos));
|
|
newUrls.add(urls.get(pos));
|
|
}
|
|
}
|
|
|
|
ids = newIds;
|
|
urls = newUrls;
|
|
}
|
|
}
|