问题描述
假设我想在我的集合中找到指向元素 X 的指针。我会这样做:
set<int>S;
int x;
cin>>x;
//insert elements
set<int>iterator :: it = S.find(x);
我现在如何在我的集合中找到 x 之后的元素?例如,如果我的集合是 :1 、 2 、 3 并且 x 是 2 ,我想打印 3。这似乎不起作用:>
cout<<*(it+1);
它说不匹配运算符“+”。谢谢!
解决方法
而不是这个:
Task.WhenAll
这个:
private static final ConcurrentMap<String,ModuleDescription> cache = Maps.newConcurrentMap();
public void loadModules() {
for (File file : Objects.requireNonNull(Main.getInstance().getDataFolder().listFiles())) {
if (!file.getName().substring(file.getName().lastIndexOf(".")).equalsIgnoreCase(".jar")) {
return;
}
registerModule(file);
URLClassLoader loader = null;
try {
loader = new URLClassLoader(new URL[] { file.toURI().toURL() });
Class<?> jarClass = loader.loadClass(cache.get(file.getName()).main);
Method method = jarClass.getMethod("initialise");
Object instance = jarClass.newInstance();
method.invoke(instance);
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | MalformedURLException e) {
e.printStackTrace();
} finally {
if (loader != null) {
try {
loader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
public void stopModules() {
for (String module : cache.keySet()) {
File file = new File(Main.getInstance().getDataFolder() + "/" + module);
URLClassLoader loader = null;
try {
loader = new URLClassLoader(new URL[] { file.toURI().toURL() });
Class<?> jarClass = loader.loadClass(cache.get(file.getName()).main);
Method method = jarClass.getMethod("shutdown");
Object instance = jarClass.newInstance();
method.invoke(instance);
} catch (MalformedURLException | ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
e.printStackTrace();
} finally {
if (loader != null) {
try {
loader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
public void registerModule(File file) {
JarFile jarFile = null;
InputStream inputStream = null;
try {
jarFile = new JarFile(file);
JarEntry jarEntry = jarFile.getJarEntry("module.yml");
if (jarEntry == null) {
System.out.println("The file \"" + file.getName() + "\" is missing the \"module.yml\"!");
return;
}
inputStream = jarFile.getInputStream(jarEntry);
Map<String,Map<String,String>> values = new Yaml().load(inputStream);
ModuleDescription description = new ModuleDescription();
if (values.containsKey("name")) {
description.name = "" + values.get("name");
System.out.println("name: " + description.name);
}
if (values.containsKey("main")) {
description.main = "" + values.get("main");
System.out.println("main: " + description.main);
}
if (description.name == null || description.main == null) {
System.out.println("The \"module.yml\" is missing needed information's!");
return;
}
if (values.containsKey("version")) {
description.version = "" + values.get("version");
}
if (values.containsKey("author")) {
description.author = "" + values.get("author");
}
if (values.containsKey("description")) {
description.description = "" + values.get("description");
}
cache.put(file.getName(),description);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (jarFile != null) {
try {
jarFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}