List of usage examples for java.util Collection contains
boolean contains(Object o);
From source file:com.sworddance.util.CUtilities.java
public static <T> boolean addAllIfNotContains(Collection<T> collection, Collection<T> values) { boolean collectionChanged = false; if (collection != null) { for (T value : NotNullIterator.<T>newNotNullIterator(values)) { if (!collection.contains(value)) { collectionChanged |= collection.add(value); }/*w ww . jav a2 s.com*/ } } return collectionChanged; }
From source file:com.thinkmore.framework.orm.hibernate.HibernateWebUtils.java
/** * ?ID?,???.//from w w w . jav a2s. c o m * * ??????id,??????id?????. * ???id??,??id??. * ?ID, ??cascade-save-or-update. * * @param srcObjects ??,. * @param checkedIds ?,ID. * @param clazz ? * @param idName ?? */ public static <T, ID> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<ID> checkedIds, final Class<T> clazz, final String idName) { //? Assert.notNull(srcObjects, "scrObjects?"); Assert.hasText(idName, "idName?"); Assert.notNull(clazz, "clazz?"); //?,???. if (checkedIds == null) { srcObjects.clear(); return; } //????,id?ID?,. //?,???id,?id???id. Iterator<T> srcIterator = srcObjects.iterator(); try { while (srcIterator.hasNext()) { T element = srcIterator.next(); Object id; id = PropertyUtils.getProperty(element, idName); if (!checkedIds.contains(id)) { srcIterator.remove(); } else { checkedIds.remove(id); } } //ID??id????,,id??. for (ID id : checkedIds) { T obj = clazz.newInstance(); PropertyUtils.setProperty(obj, idName, id); srcObjects.add(obj); } } catch (Exception e) { throw ReflectionUtil.convertReflectionExceptionToUnchecked(e); } }
From source file:jp.ac.tokushima_u.is.ll.common.orm.hibernate.HibernateWebUtils.java
/** * ?ID?,???.//from w w w. ja va2 s. c o m * * ??????id,??????id?????. * ???id??,??id??. * ?ID, ??cascade-save-or-update. * * @param srcObjects ??,. * @param checkedIds ?,ID. * @param clazz ? * @param idName ?? */ public static <T, ID> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<ID> checkedIds, final Class<T> clazz, final String idName) { //? Assert.notNull(srcObjects, "scrObjects?"); Assert.hasText(idName, "idName?"); Assert.notNull(clazz, "clazz?"); //?,???. if (checkedIds == null) { srcObjects.clear(); return; } //????,id?ID?,. //?,???id,?id???ID. Iterator<T> srcIterator = srcObjects.iterator(); try { while (srcIterator.hasNext()) { T element = srcIterator.next(); Object id; id = PropertyUtils.getProperty(element, idName); if (!checkedIds.contains(id)) { srcIterator.remove(); } else { checkedIds.remove(id); } } //ID??id????,,id??. for (ID id : checkedIds) { T obj = clazz.newInstance(); PropertyUtils.setProperty(obj, idName, id); srcObjects.add(obj); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } }
From source file:Main.java
/** * //from w w w. j a va2 s . com * @param is * @param os * @param elementNames * @throws XMLStreamException * @throws FactoryConfigurationError * @throws UnsupportedEncodingException */ public static void stripElements(final InputStream is, final OutputStream os, final Collection<String> elementNames) throws XMLStreamException, UnsupportedEncodingException, FactoryConfigurationError { final XMLEventReader xmlEventReader = XMLInputFactory.newInstance() .createXMLEventReader(new InputStreamReader(is, Charset.defaultCharset().name())); final XMLEventWriter xmlEventWriter = XMLOutputFactory.newInstance().createXMLEventWriter(os); String elementName = null; while (xmlEventReader.peek() != null) { final XMLEvent event = (XMLEvent) xmlEventReader.next(); switch (event.getEventType()) { case XMLStreamConstants.START_DOCUMENT: case XMLStreamConstants.END_DOCUMENT: { // Ignore. break; } case XMLStreamConstants.START_ELEMENT: { final StartElement startElement = event.asStartElement(); final QName name = startElement.getName(); if (elementNames.contains(name.getLocalPart())) { elementName = name.getLocalPart(); } if (elementName == null) { xmlEventWriter.add(event); } break; } case XMLStreamConstants.END_ELEMENT: { final EndElement endElement = event.asEndElement(); final QName name = endElement.getName(); if (elementName == null) { xmlEventWriter.add(event); } else if (elementName.equals(name.getLocalPart())) { elementName = null; } break; } default: { if (elementName == null) { xmlEventWriter.add(event); } } } } xmlEventWriter.flush(); }
From source file:com.xyz.util.WebDataUtil.java
/** * ?ID?,???.//ww w. j a va 2 s.c o m * * ??????id,??????id?????. * ???id?ID?,?ID?id??. * * @param srcObjects ?? * @param checkedIds ID? * @param clazz ? * @param idName ?? */ public static <T, ID> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<ID> checkedIds, final Class<T> clazz, final String idName) { //? Assert.notNull(srcObjects, "scrObjects?"); Assert.hasText(idName, "idName?"); Assert.notNull(clazz, "clazz?"); //ID?,???. if (checkedIds == null) { srcObjects.clear(); return; } //????,id?ID?,. //?,ID???id,ID?id???ID. Iterator<T> srcIterator = srcObjects.iterator(); try { while (srcIterator.hasNext()) { T element = srcIterator.next(); Object id; id = PropertyUtils.getProperty(element, idName); if (!checkedIds.contains(id)) { srcIterator.remove(); } else { checkedIds.remove(id); } } //ID??id????,,id??. for (ID id : checkedIds) { T obj = clazz.newInstance(); PropertyUtils.setProperty(obj, idName, id); srcObjects.add(obj); } } catch (Exception e) { throw ReflectionUtil.convertToUncheckedException(e); } }
From source file:net.eusashead.spring.gaecache.GaeCacheManagerTest.java
@Test public void testAddMockCache() { GaeCacheManager manager = new GaeCacheManager(); GaeCache cache = Mockito.mock(GaeCache.class); Mockito.when(cache.getName()).thenReturn("cache"); manager.addCache(cache);//ww w .j av a 2 s .c om Collection<String> names = manager.getCacheNames(); Assert.assertTrue(names.contains("cache")); Cache get = manager.getCache("cache"); Assert.assertNotNull(get); Assert.assertEquals(cache, get); }
From source file:com.afeng.common.dao.orm.HibernateWebUtils.java
/** * ?ID?,???.// www .j a va2 s . c o m * <p/> * ??????id,??????id?????. * ???id??,??id??. * ?ID, ??cascade-save-or-update. * * @param srcObjects ??,. * @param checkedIds ?,ID. * @param clazz ? * @param idName ?? */ public static <T, ID> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<ID> checkedIds, final Class<T> clazz, final String idName) { //? Assert.notNull(srcObjects, "scrObjects?"); Assert.hasText(idName, "idName?"); Assert.notNull(clazz, "clazz?"); //?,???. if (checkedIds == null) { srcObjects.clear(); return; } //????,id?ID?,. //?,???id,?id???id. Iterator<T> srcIterator = srcObjects.iterator(); try { while (srcIterator.hasNext()) { T element = srcIterator.next(); Object id; id = PropertyUtils.getProperty(element, idName); if (!checkedIds.contains(id)) { srcIterator.remove(); } else { checkedIds.remove(id); } } //ID??id????,,id??. for (ID id : checkedIds) { T obj = clazz.newInstance(); PropertyUtils.setProperty(obj, idName, id); srcObjects.add(obj); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } }
From source file:freightKt.KTFreight_v3.java
static void generateRoadPricingCalculator(final Builder netBuilder, final Config config, final Carriers carriers) { ConfigUtils.addOrGetModule(config, RoadPricingConfigGroup.GROUP_NAME, RoadPricingConfigGroup.class); final RoadPricingSchemeImpl scheme = new RoadPricingSchemeImpl(); RoadPricingReaderXMLv1 rpReader = new RoadPricingReaderXMLv1(scheme); try {//from w ww. j ava 2 s. co m RoadPricingConfigGroup rpConfig = (RoadPricingConfigGroup) config .getModule(RoadPricingConfigGroup.GROUP_NAME); rpConfig.setTollLinksFile(TOLLFILE); rpReader.parse(rpConfig.getTollLinksFile()); } catch (Exception e) { throw new RuntimeException(e); } Collection<Id<VehicleType>> vehTypesAddedToRPS = new ArrayList<Id<VehicleType>>(); //keine Einschrnkung eingegeben -> alle bemauten if (onlyTollVehTypes == null) { for (Carrier c : carriers.getCarriers().values()) { for (CarrierVehicle v : c.getCarrierCapabilities().getCarrierVehicles()) { Id<VehicleType> typeId = v.getVehicleType().getId(); if (!vehTypesAddedToRPS.contains(typeId)) { vehTypesAddedToRPS.add(typeId); rpCalculator.addPricingScheme(typeId, scheme); } } } } else { for (Carrier c : carriers.getCarriers().values()) { for (CarrierVehicle v : c.getCarrierCapabilities().getCarrierVehicles()) { Id<VehicleType> typeId = v.getVehicleType().getId(); if (onlyTollVehTypes.contains(typeId.toString()) & !vehTypesAddedToRPS.contains(typeId)) { vehTypesAddedToRPS.add(typeId); rpCalculator.addPricingScheme(typeId, scheme); } } } } netBuilder.setRoadPricingCalculator(rpCalculator); rpscheme = scheme; //Writing Info for (Id<VehicleType> vehTypId : rpCalculator.getSchemes().keySet()) { textInfofile.writeTextLineToFile(vehTypId.toString()); textInfofile.writeTextLineToFile(rpCalculator.getPricingSchemes(vehTypId).toString()); } }
From source file:org.deeplearning4j.spark.models.embeddings.glove.GloveTest.java
@Test public void testGlove() throws Exception { Glove glove = new Glove(true, 5, 100); JavaRDD<String> corpus = sc.textFile(new ClassPathResource("raw_sentences.txt").getFile().getAbsolutePath()) .map(new Function<String, String>() { @Override//from w w w. j a v a2s . co m public String call(String s) throws Exception { return s.toLowerCase(); } }).cache(); Pair<VocabCache, GloveWeightLookupTable> table = glove.train(corpus); WordVectors vectors = WordVectorSerializer .fromPair(new Pair<>((WeightLookupTable) table.getSecond(), table.getFirst())); Collection<String> words = vectors.wordsNearest("day", 20); assertTrue(words.contains("week")); }
From source file:com.orange.clara.cloud.servicedbdumper.security.AccessManager.java
public boolean isUserIsAdmin() { SecurityContext context = this.getSecurityContextHolder(); if (context == null) { return false; }// ww w . j a va 2 s .co m Authentication authentication = context.getAuthentication(); if (authentication == null) { return false; } Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities(); return authorities.contains(new SimpleGrantedAuthority(AUTHORIZED_AUTHORITY)); }