List of usage examples for java.util Set remove
boolean remove(Object o);
From source file:com.github.sevntu.checkstyle.internal.ChecksTest.java
private static void validateEclipseCsMetaPropFile(File file, String pkg, Set<Class<?>> pkgModules) throws Exception { Assert.assertTrue("'checkstyle-metadata.properties' must exist in eclipsecs in inside " + pkg, file.exists());/*ww w. j a va 2s . c om*/ final Properties prop = new Properties(); prop.load(new FileInputStream(file)); final Set<Object> properties = new HashSet<>(Collections.list(prop.keys())); for (Class<?> module : pkgModules) { final String moduleName = module.getSimpleName(); Assert.assertTrue(moduleName + " requires a name in eclipsecs properties " + pkg, properties.remove(moduleName + ".name")); Assert.assertTrue(moduleName + " requires a desc in eclipsecs properties " + pkg, properties.remove(moduleName + ".desc")); final Set<String> moduleProperties = getFinalProperties(module); for (String moduleProperty : moduleProperties) { Assert.assertTrue( moduleName + " requires the property " + moduleProperty + " in eclipsecs properties " + pkg, properties.remove(moduleName + "." + moduleProperty)); } } for (Object property : properties) { Assert.fail("Unknown property found in eclipsecs properties " + pkg + ": " + property); } }
From source file:edu.umass.cs.utils.Util.java
public static Set<?> removeFromSetCopy(Set<?> set, Object element) { if (set != null && element != null) { Set<?> copy = new HashSet<>(set); copy.remove(element); return copy; }//from ww w . j a v a2 s .co m return set; }
From source file:com.asakusafw.directio.hive.parquet.DataModelMaterializer.java
private static List<Mapping> computeMappingByName(DataModelDescriptor target, MessageType source) { if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format("Mapping columns by their name: model={0}", //$NON-NLS-1$ target.getDataModelClass().getName())); }/*from w w w .j a va 2 s. c om*/ Set<PropertyDescriptor> rest = new LinkedHashSet<>(target.getPropertyDescriptors()); List<Mapping> mappings = new ArrayList<>(); for (ColumnDescriptor s : source.getColumns()) { String name = s.getPath()[0]; Type sType = source.getType(s.getPath()); PropertyDescriptor t = target.findPropertyDescriptor(name); if (t != null) { mappings.add(new Mapping(s, sType, t)); rest.remove(t); } else { mappings.add(new Mapping(s, sType, null)); } } for (PropertyDescriptor t : rest) { mappings.add(new Mapping(null, null, t)); } return mappings; }
From source file:models.NotificationMail.java
/** * Sends notification mails for the given event. * * @param event// www.j a v a 2s . c o m * @see <a href="https://github.com/nforge/yobi/blob/master/docs/technical/watch.md>watch.md</a> */ private static void sendNotification(NotificationEvent event) { Set<User> receivers = event.receivers; // Remove inactive users. Iterator<User> iterator = receivers.iterator(); while (iterator.hasNext()) { User user = iterator.next(); if (user.state != UserState.ACTIVE) { iterator.remove(); } } receivers.remove(User.anonymous); if (receivers.isEmpty()) { return; } HashMap<String, List<User>> usersByLang = new HashMap<>(); for (User receiver : receivers) { String lang = receiver.lang; if (lang == null) { lang = Locale.getDefault().getLanguage(); } if (usersByLang.containsKey(lang)) { usersByLang.get(lang).add(receiver); } else { usersByLang.put(lang, new ArrayList<>(Arrays.asList(receiver))); } } for (String langCode : usersByLang.keySet()) { final EventEmail email = new EventEmail(event); try { if (hideAddress) { email.setFrom(Config.getEmailFromSmtp(), event.getSender().name); email.addTo(Config.getEmailFromSmtp(), utils.Config.getSiteName()); } else { email.setFrom(event.getSender().email, event.getSender().name); } for (User receiver : usersByLang.get(langCode)) { if (hideAddress) { email.addBcc(receiver.email, receiver.name); } else { email.addTo(receiver.email, receiver.name); } } if (email.getToAddresses().isEmpty()) { continue; } Lang lang = Lang.apply(langCode); String message = event.getMessage(lang); String urlToView = event.getUrlToView(); String reference = Url.removeFragment(event.getUrlToView()); email.setSubject(event.title); Resource resource = event.getResource(); if (resource.getType() == ResourceType.ISSUE_COMMENT) { IssueComment issueComment = IssueComment.find.byId(Long.valueOf(resource.getId())); resource = issueComment.issue.asResource(); } email.setHtmlMsg(getHtmlMessage(lang, message, urlToView, resource)); email.setTextMsg(getPlainMessage(lang, message, Url.create(urlToView))); email.setCharset("utf-8"); email.addReferences(); email.setSentDate(event.created); Mailer.send(email); String escapedTitle = email.getSubject().replace("\"", "\\\""); String logEntry = String.format("\"%s\" %s", escapedTitle, email.getBccAddresses()); play.Logger.of("mail").info(logEntry); } catch (Exception e) { Logger.warn("Failed to send a notification: " + email + "\n" + ExceptionUtils.getStackTrace(e)); } } }
From source file:edu.umass.cs.utils.Util.java
public static Set<?> removeFromSet(Set<?> set, Object element) { if (set != null && element != null) set.remove(element); return set;// w w w . j av a 2 s .c o m }
From source file:com.erudika.para.core.CoreUtils.java
/** * Adds any number of tags to the set of tags. * @param tag a tag, must not be null or empty * @param objectTags the object tags//w w w .j av a 2s . co m * @return a new list of tags */ public static List<String> addTags(List<String> objectTags, String... tag) { if (tag != null && tag.length > 0) { Set<String> tagz; if (objectTags == null || objectTags.isEmpty()) { tagz = new HashSet<String>(); } else { tagz = new HashSet<String>(objectTags); } for (String t : tag) { if (!StringUtils.isBlank(t)) { tagz.add(Utils.noSpaces(Utils.stripAndTrim(t), "-")); } } tagz.remove(null); tagz.remove(""); return new ArrayList<String>(tagz); } return objectTags; }
From source file:edu.umass.cs.utils.Util.java
public static Object getOtherThanString(Set<?> set, Object exclude) { return new Object() { public String toString() { @SuppressWarnings({ "rawtypes", "unchecked" }) Set<?> copy = new HashSet(set); copy.remove(exclude); return copy.toString(); }//from ww w . j a v a 2 s .com }; }
From source file:com.huawei.streaming.cql.DriverContext.java
/** * classpathjar/*ww w . jav a 2s .c om*/ * * @param pathsToRemove jar * @throws IOException jar */ private static void removeFromClassPath(String[] pathsToRemove) throws IOException { Thread curThread = Thread.currentThread(); URLClassLoader loader = (URLClassLoader) curThread.getContextClassLoader(); Set<URL> newPath = new HashSet<URL>(Arrays.asList(loader.getURLs())); if (pathsToRemove != null) { for (String onestr : pathsToRemove) { if (StringUtils.indexOf(onestr, FILE_PREFIX) == 0) { onestr = StringUtils.substring(onestr, CQLConst.I_7); } URL oneurl = (new File(onestr)).toURI().toURL(); newPath.remove(oneurl); } } loader = new URLClassLoader(newPath.toArray(new URL[0])); curThread.setContextClassLoader(loader); }
From source file:net.minecraftforge.common.crafting.CraftingHelper.java
public static ShapedPrimer parseShaped(Object... recipe) { ShapedPrimer ret = new ShapedPrimer(); String shape = ""; int idx = 0;/* w ww.j av a 2s . co m*/ if (recipe[idx] instanceof Boolean) { ret.mirrored = (Boolean) recipe[idx]; if (recipe[idx + 1] instanceof Object[]) recipe = (Object[]) recipe[idx + 1]; else idx = 1; } if (recipe[idx] instanceof String[]) { String[] parts = ((String[]) recipe[idx++]); for (String s : parts) { ret.width = s.length(); shape += s; } ret.height = parts.length; } else { while (recipe[idx] instanceof String) { String s = (String) recipe[idx++]; shape += s; ret.width = s.length(); ret.height++; } } if (ret.width * ret.height != shape.length() || shape.length() == 0) { String err = "Invalid shaped recipe: "; for (Object tmp : recipe) { err += tmp + ", "; } throw new RuntimeException(err); } HashMap<Character, Ingredient> itemMap = Maps.newHashMap(); itemMap.put(' ', Ingredient.EMPTY); for (; idx < recipe.length; idx += 2) { Character chr = (Character) recipe[idx]; Object in = recipe[idx + 1]; Ingredient ing = CraftingHelper.getIngredient(in); if (' ' == chr.charValue()) throw new JsonSyntaxException("Invalid key entry: ' ' is a reserved symbol."); if (ing != null) { itemMap.put(chr, ing); } else { String err = "Invalid shaped ore recipe: "; for (Object tmp : recipe) { err += tmp + ", "; } throw new RuntimeException(err); } } ret.input = NonNullList.withSize(ret.width * ret.height, Ingredient.EMPTY); Set<Character> keys = Sets.newHashSet(itemMap.keySet()); keys.remove(' '); int x = 0; for (char chr : shape.toCharArray()) { Ingredient ing = itemMap.get(chr); if (ing == null) throw new IllegalArgumentException( "Pattern references symbol '" + chr + "' but it's not defined in the key"); ret.input.set(x++, ing); keys.remove(chr); } if (!keys.isEmpty()) throw new IllegalArgumentException("Key defines symbols that aren't used in pattern: " + keys); return ret; }
From source file:com.silverpeas.util.StringUtil.java
private static String reencode(byte[] data, Set<String> encodings, String declaredEncoding) throws UnsupportedEncodingException { if (!encodings.isEmpty()) { String encoding = encodings.iterator().next(); String value = new String(data, encoding); if (!checkEncoding(value)) { encodings.remove(encoding); return reencode(data, encodings, declaredEncoding); }/*from w w w . ja va2 s.co m*/ return encoding; } return declaredEncoding; }