List of usage examples for java.util LinkedHashSet clear
void clear();
From source file:Main.java
public static void main(String[] args) { LinkedHashSet<Integer> lhashSet = new LinkedHashSet<Integer>(); lhashSet.add(new Integer("1")); lhashSet.add(new Integer("2")); lhashSet.add(new Integer("3")); System.out.println(lhashSet); lhashSet.clear(); System.out.println(lhashSet); System.out.println(lhashSet.isEmpty()); }
From source file:azkaban.utils.PropsUtils.java
public static Props resolveProps(Props props) { if (props == null) return null; Props resolvedProps = new Props(); LinkedHashSet<String> visitedVariables = new LinkedHashSet<String>(); for (String key : props.getKeySet()) { String value = props.get(key); visitedVariables.add(key);// ww w .j av a 2 s . c om String replacedValue = resolveVariableReplacement(value, props, visitedVariables); visitedVariables.clear(); resolvedProps.put(key, replacedValue); } for (String key : resolvedProps.getKeySet()) { String value = resolvedProps.get(key); String expressedValue = resolveVariableExpression(value); resolvedProps.put(key, expressedValue); } return resolvedProps; }
From source file:com.cenrise.test.azkaban.PropsUtils.java
public static Props resolveProps(final Props props) { if (props == null) { return null; }/*from w w w .j a va2s . c om*/ final Props resolvedProps = new Props(); final LinkedHashSet<String> visitedVariables = new LinkedHashSet<>(); for (final String key : props.getKeySet()) { String value = props.get(key); if (value == null) { logger.warn("Null value in props for key '" + key + "'. Replacing with empty string."); value = ""; } visitedVariables.add(key); final String replacedValue = resolveVariableReplacement(value, props, visitedVariables); visitedVariables.clear(); resolvedProps.put(key, replacedValue); } for (final String key : resolvedProps.getKeySet()) { final String value = resolvedProps.get(key); final String expressedValue = resolveVariableExpression(value); resolvedProps.put(key, expressedValue); } return resolvedProps; }
From source file:com.soulgalore.crawler.core.impl.DefaultCrawler.java
/** * Get the urls.//ww w.j a v a 2 s . c o m * * @param configuration how to perform the crawl * @return the result of the crawl */ public CrawlerResult getUrls(CrawlerConfiguration configuration) { final Map<String, String> requestHeaders = configuration.getRequestHeadersMap(); final HTMLPageResponse resp = verifyInput(configuration.getStartUrl(), configuration.getOnlyOnPath(), requestHeaders); int level = 0; final Set<CrawlerURL> allUrls = new LinkedHashSet<CrawlerURL>(); final Set<HTMLPageResponse> verifiedUrls = new LinkedHashSet<HTMLPageResponse>(); final Set<HTMLPageResponse> nonWorkingResponses = new LinkedHashSet<HTMLPageResponse>(); verifiedUrls.add(resp); final String host = resp.getPageUrl().getHost(); if (configuration.getMaxLevels() > 0) { // set the start url Set<CrawlerURL> nextToFetch = new LinkedHashSet<CrawlerURL>(); nextToFetch.add(resp.getPageUrl()); while (level < configuration.getMaxLevels()) { final Map<Future<HTMLPageResponse>, CrawlerURL> futures = new HashMap<Future<HTMLPageResponse>, CrawlerURL>( nextToFetch.size()); for (CrawlerURL testURL : nextToFetch) { futures.put(service.submit( new HTMLPageResponseCallable(testURL, responseFetcher, true, requestHeaders, false)), testURL); } nextToFetch = fetchNextLevelLinks(futures, allUrls, nonWorkingResponses, verifiedUrls, host, configuration.getOnlyOnPath(), configuration.getNotOnPath()); level++; } } else { allUrls.add(resp.getPageUrl()); } if (configuration.isVerifyUrls()) verifyUrls(allUrls, verifiedUrls, nonWorkingResponses, requestHeaders); LinkedHashSet<CrawlerURL> workingUrls = new LinkedHashSet<CrawlerURL>(); for (HTMLPageResponse workingResponses : verifiedUrls) { workingUrls.add(workingResponses.getPageUrl()); } // TODO find a better fix for this // wow, this is a hack to fix if the first URL is redirected, // then we want to keep that original start url if (workingUrls.size() >= 1) { List<CrawlerURL> list = new ArrayList<CrawlerURL>(workingUrls); list.add(0, new CrawlerURL(configuration.getStartUrl())); list.remove(1); workingUrls.clear(); workingUrls.addAll(list); } return new CrawlerResult(configuration.getStartUrl(), configuration.isVerifyUrls() ? workingUrls : allUrls, verifiedUrls, nonWorkingResponses); }
From source file:com.haulmont.cuba.gui.data.impl.CollectionPropertyDatasourceImpl.java
@SuppressWarnings("unchecked") public void replaceItem(T item) { checkNotNullArgument(item, "item is null"); Collection<T> collection = getCollection(); if (collection != null) { for (T t : collection) { if (t.equals(item)) { detachListener(t);//w w w.j a v a2 s . c o m if (collection instanceof List) { List list = (List) collection; int itemIdx = list.indexOf(t); list.set(itemIdx, item); } else if (collection instanceof LinkedHashSet) { LinkedHashSet set = (LinkedHashSet) collection; List list = new ArrayList(set); int itemIdx = list.indexOf(t); list.set(itemIdx, item); set.clear(); set.addAll(list); } else { collection.remove(t); collection.add(item); } attachListener(item); if (item.equals(this.item)) { this.item = item; } break; } } if (sortInfos != null) doSort(); fireCollectionChanged(Operation.UPDATE, Collections.singletonList(item)); } }
From source file:com.github.dozermapper.core.MappingProcessor.java
private Set<?> addToSet(Object srcObj, FieldMap fieldMap, Collection<?> srcCollectionValue, Object destObj) { // create a list here so we can keep track of which elements we have mapped, and remove all others if removeOrphans = true Set<Object> mappedElements = new HashSet<>(); LinkedHashSet<Object> result = new LinkedHashSet<>(); // don't want to create the set if it already exists. Object field = fieldMap.getDestValue(destObj); if (field != null) { result.addAll((Collection<?>) field); }/* www.j a v a2s. c o m*/ Object destValue; Class<?> destEntryType = null; Class<?> prevDestEntryType = null; for (Object srcValue : srcCollectionValue) { if (destEntryType == null || (fieldMap.getDestHintContainer() != null && fieldMap.getDestHintContainer().hasMoreThanOneHint())) { destEntryType = determineCollectionItemType(fieldMap, destObj, srcValue, prevDestEntryType); } CopyByReferenceContainer copyByReferences = globalConfiguration.getCopyByReferences(); if (srcValue != null && copyByReferences.contains(srcValue.getClass())) { destValue = srcValue; } else { destValue = mapOrRecurseObject(srcObj, srcValue, destEntryType, fieldMap, destObj); } prevDestEntryType = destEntryType; if (RelationshipType.NON_CUMULATIVE.equals(fieldMap.getRelationshipType()) && result.contains(destValue)) { List<Object> resultAsList = new ArrayList<>(result); int index = resultAsList.indexOf(destValue); // perform an update if complex type - can't map strings Object obj = resultAsList.get(index); // make sure it is not a String if (!obj.getClass().isAssignableFrom(String.class)) { mapToDestObject(null, srcValue, obj, false, fieldMap.getMapId()); mappedElements.add(obj); } } else { if (destValue != null || fieldMap.isDestMapNull()) { result.add(destValue); } mappedElements.add(destValue); } } // If remove orphans - we only want to keep the objects we've mapped from the src collection // so we'll clear result and replace all entries with the ones in mappedElements if (fieldMap.isRemoveOrphans()) { result.clear(); result.addAll(mappedElements); } if (field == null) { Class<? extends Set<?>> destSetType = (Class<? extends Set<?>>) fieldMap .getDestFieldType(destObj.getClass()); return CollectionUtils.createNewSet(destSetType, result); } else { // Bug #1822421 - Clear first so we don't end up with the removed orphans again ((Set) field).clear(); ((Set) field).addAll(result); return (Set<?>) field; } }
From source file:org.dozer.MappingProcessor.java
private Set<?> addToSet(Object srcObj, FieldMap fieldMap, Collection<?> srcCollectionValue, Object destObj) { // create a list here so we can keep track of which elements we have mapped, and remove all others if removeOrphans = true Set<Object> mappedElements = new HashSet<Object>(); LinkedHashSet<Object> result = new LinkedHashSet<Object>(); // don't want to create the set if it already exists. Object field = fieldMap.getDestValue(destObj); if (field != null) { result.addAll((Collection<?>) field); }//from w w w. java 2 s. com Object destValue; Class<?> destEntryType = null; Class<?> prevDestEntryType = null; for (Object srcValue : srcCollectionValue) { if (destEntryType == null || (fieldMap.getDestHintContainer() != null && fieldMap.getDestHintContainer().hasMoreThanOneHint())) { destEntryType = determineCollectionItemType(fieldMap, destObj, srcValue, prevDestEntryType); } CopyByReferenceContainer copyByReferences = globalConfiguration.getCopyByReferences(); if (srcValue != null && copyByReferences.contains(srcValue.getClass())) { destValue = srcValue; } else { destValue = mapOrRecurseObject(srcObj, srcValue, destEntryType, fieldMap, destObj); } prevDestEntryType = destEntryType; if (RelationshipType.NON_CUMULATIVE.equals(fieldMap.getRelationshipType()) && result.contains(destValue)) { List<Object> resultAsList = new ArrayList<Object>(result); int index = resultAsList.indexOf(destValue); // perform an update if complex type - can't map strings Object obj = resultAsList.get(index); // make sure it is not a String if (!obj.getClass().isAssignableFrom(String.class)) { mapToDestObject(null, srcValue, obj, false, null); mappedElements.add(obj); } } else { if (destValue != null || fieldMap.isDestMapNull()) { result.add(destValue); } mappedElements.add(destValue); } } // If remove orphans - we only want to keep the objects we've mapped from the src collection // so we'll clear result and replace all entries with the ones in mappedElements if (fieldMap.isRemoveOrphans()) { result.clear(); result.addAll(mappedElements); } if (field == null) { Class<? extends Set<?>> destSetType = (Class<? extends Set<?>>) fieldMap .getDestFieldType(destObj.getClass()); return CollectionUtils.createNewSet(destSetType, result); } else { // Bug #1822421 - Clear first so we don't end up with the removed orphans again ((Set) field).clear(); ((Set) field).addAll(result); return (Set<?>) field; } }
From source file:restaurant.dozer.custom.mapper.CustomMappingProcessor.java
private Set<?> addToSet(Object srcObj, FieldMap fieldMap, Collection<?> srcCollectionValue, Object destObj) { // create a list here so we can keep track of which elements we have // mapped, and remove all others if removeOrphans = true Set<Object> mappedElements = new HashSet<Object>(); LinkedHashSet<Object> result = new LinkedHashSet<Object>(); // don't want to create the set if it already exists. Object field = fieldMap.getDestValue(destObj); if (field != null) { result.addAll((Collection<?>) field); }/*from www.ja v a 2 s . c o m*/ Object destValue; Class<?> destEntryType = null; Class<?> prevDestEntryType = null; for (Object srcValue : srcCollectionValue) { if (destEntryType == null || (fieldMap.getDestHintContainer() != null && fieldMap.getDestHintContainer().hasMoreThanOneHint())) { destEntryType = determineCollectionItemType(fieldMap, destObj, srcValue, prevDestEntryType); } CopyByReferenceContainer copyByReferences = globalConfiguration.getCopyByReferences(); if (srcValue != null && copyByReferences.contains(srcValue.getClass())) { destValue = srcValue; } else { destValue = mapOrRecurseObject(srcObj, srcValue, destEntryType, fieldMap, destObj); } prevDestEntryType = destEntryType; if (RelationshipType.NON_CUMULATIVE.equals(fieldMap.getRelationshipType()) && result.contains(destValue)) { List<Object> resultAsList = new ArrayList<Object>(result); int index = resultAsList.indexOf(destValue); // perform an update if complex type - can't map strings Object obj = resultAsList.get(index); // make sure it is not a String if (!obj.getClass().isAssignableFrom(String.class)) { mapToDestObject(null, srcValue, obj, false, fieldMap.getMapId()); mappedElements.add(obj); } } else { if (destValue != null || fieldMap.isDestMapNull()) { result.add(destValue); } mappedElements.add(destValue); } } // If remove orphans - we only want to keep the objects we've mapped // from the src collection // so we'll clear result and replace all entries with the ones in // mappedElements if (fieldMap.isRemoveOrphans()) { result.clear(); result.addAll(mappedElements); } if (field == null) { Class<? extends Set<?>> destSetType = (Class<? extends Set<?>>) fieldMap .getDestFieldType(destObj.getClass()); return CollectionUtils.createNewSet(destSetType, result); } else { // Bug #1822421 - Clear first so we don't end up with the removed // orphans again ((Set) field).clear(); ((Set) field).addAll(result); return (Set<?>) field; } }