List of usage examples for java.util Queue addAll
boolean addAll(Collection<? extends E> c);
From source file:org.polymap.model2.engine.EntityRepositoryImpl.java
public EntityRepositoryImpl(final Configuration config) { this.config = config; // init store getStore().init(new StoreRuntimeContextImpl()); // init infos log.debug("Initialializing Composite types:"); Queue<Class<? extends Composite>> queue = new LinkedList(); queue.addAll(Arrays.asList(config.entities.get())); while (!queue.isEmpty()) { Class<? extends Composite> type = queue.poll(); if (!infos.containsKey(type)) { log.debug(" Composite type: " + type); CompositeInfoImpl info = new CompositeInfoImpl(type); infos.put(type, info);/*from w w w .ja v a 2 s. c om*/ // init static TYPE variable try { Field field = type.getDeclaredField("TYPE"); field.setAccessible(true); field.set(null, Expressions.template(type, this)); } catch (NoSuchFieldException e) { } catch (SecurityException | IllegalAccessException e) { throw new ModelRuntimeException(e); } // mixins queue.addAll(info.getMixins()); // Composite properties for (PropertyInfo propInfo : info.getProperties()) { if (Composite.class.isAssignableFrom(propInfo.getType())) { queue.offer(propInfo.getType()); } } } } }
From source file:org.apache.hadoop.corona.PoolSchedulable.java
/** * Get the queue of sessions in the pool sorted by comparator * @param comparator the comparator to use when sorting sessions * @return the queue of the sessions sorted by a given comparator *//*from w ww.j av a 2s. c o m*/ public Queue<SessionSchedulable> createSessionQueue(ScheduleComparator comparator) { int initCapacity = snapshotSessions.size() == 0 ? 1 : snapshotSessions.size(); Queue<SessionSchedulable> sessionQueue = new PriorityQueue<SessionSchedulable>(initCapacity, comparator); sessionQueue.addAll(snapshotSessions); return sessionQueue; }
From source file:com.shollmann.igcparser.ui.activity.IGCFilesActivity.java
private List<IGCFile> getListIGCFiles(File parentDir) { List<IGCFile> inFiles = new ArrayList<>(); Queue<File> files = new LinkedList<>(); try {/*from w w w .j av a 2 s . c o m*/ files.addAll(Arrays.asList(parentDir.listFiles())); while (!files.isEmpty()) { File file = files.remove(); if (!Utilities.isUnlikelyIGCFolder(file)) { if (file != null && file.isDirectory()) { files.addAll(Arrays.asList(file.listFiles())); } else if (file != null && (file.getName().toLowerCase().endsWith(".igc"))) { inFiles.add(Parser.quickParse(Uri.parse(file.getAbsolutePath()))); } } } Collections.sort(inFiles, Comparators.compareByDate); } catch (Throwable t) { final String message = "Couldn't open files"; Crashlytics.log(message); Crashlytics.logException(t); Logger.logError(message); } return inFiles; }
From source file:org.apache.marmotta.ldclient.services.provider.AbstractHttpProvider.java
/** * Retrieve the data for a resource using the given http client and endpoint definition. The service is * supposed to manage the connection handling itself. See {@link AbstractHttpProvider} * for a generic implementation of this method. * * * * @param resource the resource to be retrieved * @param endpoint the endpoint definition * @return a completely specified client response, including expiry information and the set of triples */// w w w . ja va2s .c o m @Override public ClientResponse retrieveResource(String resource, LDClientService client, Endpoint endpoint) throws DataRetrievalException { try { String contentType; if (endpoint != null && endpoint.getContentTypes().size() > 0) { contentType = CollectionUtils.fold(endpoint.getContentTypes(), new CollectionUtils.StringSerializer<ContentType>() { @Override public String serialize(ContentType contentType) { return contentType.toString("q"); } }, ","); } else { contentType = CollectionUtils.fold(Arrays.asList(listMimeTypes()), ","); } long defaultExpires = client.getClientConfiguration().getDefaultExpiry(); if (endpoint != null && endpoint.getDefaultExpiry() != null) { defaultExpires = endpoint.getDefaultExpiry(); } final ResponseHandler handler = new ResponseHandler(resource, endpoint); // a queue for queuing the request URLs needed to build the query response Queue<String> requestUrls = new LinkedList<String>(); requestUrls.addAll(buildRequestUrl(resource, endpoint)); Set<String> visited = new HashSet<String>(); String requestUrl = requestUrls.poll(); while (requestUrl != null) { if (!visited.contains(requestUrl)) { HttpGet get = new HttpGet(requestUrl); try { get.setHeader("Accept", contentType); get.setHeader("Accept-Language", "*"); // PoolParty compatibility log.info("retrieving resource data for {} from '{}' endpoint, request URI is <{}>", new Object[] { resource, getName(), get.getURI().toASCIIString() }); handler.requestUrl = requestUrl; List<String> additionalRequestUrls = client.getClient().execute(get, handler); requestUrls.addAll(additionalRequestUrls); visited.add(requestUrl); } finally { get.releaseConnection(); } } requestUrl = requestUrls.poll(); } Date expiresDate = handler.expiresDate; if (expiresDate == null) { expiresDate = new Date(System.currentTimeMillis() + defaultExpires * 1000); } long min_expires = System.currentTimeMillis() + client.getClientConfiguration().getMinimumExpiry() * 1000; if (expiresDate.getTime() < min_expires) { log.info( "expiry time returned by request lower than minimum expiration time; using minimum time instead"); expiresDate = new Date(min_expires); } if (log.isInfoEnabled()) { log.info("retrieved {} triples for resource {}; expiry date: {}", new Object[] { handler.triples.size(), resource, expiresDate }); } ClientResponse result = new ClientResponse(handler.httpStatus, handler.triples); result.setExpires(expiresDate); return result; } catch (RepositoryException e) { log.error("error while initialising Sesame repository; classpath problem?", e); throw new DataRetrievalException("error while initialising Sesame repository; classpath problem?", e); } catch (ClientProtocolException e) { log.error("HTTP client error while trying to retrieve resource {}: {}", resource, e.getMessage()); throw new DataRetrievalException("I/O error while trying to retrieve resource " + resource, e); } catch (IOException e) { log.error("I/O error while trying to retrieve resource {}: {}", resource, e.getMessage()); throw new DataRetrievalException("I/O error while trying to retrieve resource " + resource, e); } catch (RuntimeException ex) { log.error("Unknown error while trying to retrieve resource {}: {}", resource, ex.getMessage()); throw new DataRetrievalException("Unknown error while trying to retrieve resource " + resource, ex); } }
From source file:com.tasktop.c2c.server.configuration.service.TemplateProcessingConfigurator.java
@Override public void configure(ProjectServiceConfiguration configuration) { File hudsonHomeDir = new File(targetBaseLocation, (perOrg ? configuration.getOrganizationIdentifier() : configuration.getProjectIdentifier())); if (hudsonHomeDir.exists()) { LOG.warn("Hudson home already apears to exist: " + hudsonHomeDir.getAbsolutePath()); } else {// w w w. ja va 2 s. c o m // If we're here, the destination directory doesn't exist. Create it now. LOG.info("Creating new Hudson home: " + hudsonHomeDir.getAbsolutePath()); hudsonHomeDir.mkdirs(); } Queue<File> fileQueue = new LinkedList<File>(); Map<String, String> props = new HashMap<String, String>(configuration.getProperties()); fileQueue.add(new File(templateBaseLocation)); while (!fileQueue.isEmpty()) { File currentFile = fileQueue.poll(); if (currentFile.isDirectory()) { fileQueue.addAll(Arrays.asList(currentFile.listFiles())); createOrEnsureTargetDirectory(currentFile, configuration); } else { try { applyTemplateFileToTarget(props, currentFile, configuration); } catch (IOException e) { throw new RuntimeException(e); } } } }
From source file:org.kuali.rice.krad.uif.element.ValidationMessages.java
/** * Adds all group keys of this component (starting from this component itself) by calling getKeys on each of * its nested group's ValidationMessages and adding them to the list. * * @param keyList/*from w w w . j av a2 s. com*/ * @param component */ protected void addNestedGroupKeys(Collection<String> keyList, Component component) { @SuppressWarnings("unchecked") Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class); try { elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(component).values()); while (!elementQueue.isEmpty()) { LifecycleElement element = elementQueue.poll(); ValidationMessages ef = null; if (element instanceof ContainerBase) { ef = ((ContainerBase) element).getValidationMessages(); } else if (element instanceof FieldGroup) { ef = ((FieldGroup) element).getGroup().getValidationMessages(); } if (ef != null) { keyList.addAll(ef.getKeys((Component) element)); } elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(element).values()); } } finally { elementQueue.clear(); RecycleUtils.recycle(elementQueue); } }
From source file:org.sakaiproject.nakamura.files.pool.ExportIMSCP.java
private File getZipFile(Manifest manifest, Content content, String poolId, ContentManager contentManager) throws JSONException, IOException, StorageClientException, AccessDeniedException { String resourcesDir = "resources/"; String filename = (String) content.getProperty(FilesConstants.POOLED_CONTENT_FILENAME); filename = filename.replaceAll("/", "_"); File f = File.createTempFile(filename, ".zip"); f.deleteOnExit();/* w w w . j a v a2s . c o m*/ ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(f)); List<org.sakaiproject.nakamura.cp.Resource> resources = manifest.getResources().getResources(); if (resources == null) { return null; } for (org.sakaiproject.nakamura.cp.Resource resource : resources) { Item item = new Item(); Queue<Item> items = new LinkedList<Item>(); items.addAll(manifest.getOrganizations().getOrganizations().get(0).getItems()); while (!items.isEmpty()) { Item i = items.poll(); if (i.getIdentifierRef() != null && i.getIdentifierRef().equals(resource.getIdentifier())) { item = i; break; } if (i.hasSubItems()) { items.addAll(i.getItems()); } } String title = resource.getIdentifier() + ".html"; String originTitle = title; if (item.getTitle() != null && item.getTitle().length() != 0) { originTitle = item.getTitle() + ".html"; } String page = collectPageContent(content, resource.getIdentifier(), contentManager); page = handlePage(page, contentManager, poolId, zos); page = "<html><head><title>" + originTitle + "</title></head><body>" + page + "</body></html>"; InputStream input = new ByteArrayInputStream(page.getBytes()); ZipEntry zae = new ZipEntry(resourcesDir + title); zos.putNextEntry(zae); IOUtils.copy(input, zos); } String xml = manifest.generateXML(); InputStream input = new ByteArrayInputStream(xml.getBytes()); ZipEntry zae = new ZipEntry("imsmanifest.xml"); zos.putNextEntry(zae); IOUtils.copy(input, zos); zos.close(); return f; }
From source file:net.sf.nmedit.nomad.core.menulayout.MLEntry.java
public Iterator<MLEntry> bfsIterator() { return new BFSIterator<MLEntry>(this) { @Override/*w ww . j a v a 2 s.c o m*/ protected void enqueueChildren(Queue<MLEntry> queue, MLEntry parent) { List<MLEntry> l = parent.entryList; if (l != null) queue.addAll(l); } }; }
From source file:org.polymap.core.runtime.event.AnnotatedEventListener.java
/** * //www. j a va 2s .c o m */ public AnnotatedEventListener(Object handler, Integer mapKey, EventFilter... filters) { assert handler != null; assert filters != null; this.handlerRef = new WeakReference(handler); this.handlerClass = handler.getClass(); this.mapKey = mapKey; // find annotated methods Queue<Class> types = new ArrayDeque(16); types.add(handler.getClass()); while (!types.isEmpty()) { Class type = types.remove(); if (type.getSuperclass() != null) { types.add(type.getSuperclass()); } types.addAll(Arrays.asList(type.getInterfaces())); for (Method m : type.getDeclaredMethods()) { EventHandler annotation = m.getAnnotation(EventHandler.class); if (annotation != null) { m.setAccessible(true); // annotated method AnnotatedMethod am = annotation.delay() > 0 ? new DeferredAnnotatedMethod(m, annotation) : new AnnotatedMethod(m, annotation); EventListener listener = am; // display thread; if (annotation.display()) { // if this is NOT the delegate of the DeferringListener then // check DeferringListener#SessionUICallbackCounter listener = new DisplayingListener(listener); } // deferred // XXX There is a race cond. between the UIThread and the event thread; if the UIThread // completes the current request before all display events are handled then the UI // is not updated until next user request; DeferringListener handles this by activating // UICallBack, improving behaviour - but not really solving in all cases; after 500ms we // are quite sure that no more events are pending and UI callback can turned off // currenty COMMENTED OUT! see EventManger#SessionEventDispatcher if (annotation.delay() > 0 /*|| annotation.display()*/) { int delay = annotation.delay() > 0 ? annotation.delay() : 500; listener = new TimerDeferringListener(listener, delay, 10000); } // filters listener = new FilteringListener(listener, ObjectArrays.concat(am.filters, filters, EventFilter.class)); // session context; first in chain so that all listener/filters // get the proper context SessionContext session = SessionContext.current(); if (session != null) { listener = new SessioningListener(listener, mapKey, session, handlerClass); } methods.add(listener); } } } if (methods.isEmpty()) { throw new IllegalArgumentException("No EventHandler annotation found in: " + handler.getClass()); } }
From source file:edu.uci.ics.hyracks.api.rewriter.ActivityClusterGraphRewriter.java
/** * One super activity swallows another existing super activity. * /*from w w w .ja va 2s . c o m*/ * @param superActivities * the map from activity id to current super activities * @param toBeExpendedMap * the map from an existing super activity to its BFS expansion queue of the original activities * @param invertedActivitySuperActivityMap * the map from the original activities to their hosted super activities * @param superActivity * the "swallowing" super activity * @param superActivityId * the activity id for the "swallowing" super activity, which is also the first added acitivty's id in the super activity * @param existingSuperActivity * an existing super activity which is to be swallowed by the "swallowing" super activity */ private void swallowExistingSuperActivity(Map<ActivityId, SuperActivity> superActivities, Map<ActivityId, Queue<IActivity>> toBeExpendedMap, Map<IActivity, SuperActivity> invertedActivitySuperActivityMap, SuperActivity superActivity, ActivityId superActivityId, SuperActivity existingSuperActivity) { ActivityId existingSuperActivityId = existingSuperActivity.getActivityId(); superActivities.remove(existingSuperActivityId); for (Entry<ActivityId, IActivity> existingEntry : existingSuperActivity.getActivityMap().entrySet()) { IActivity existingActivity = existingEntry.getValue(); superActivity.addActivity(existingActivity); invertedActivitySuperActivityMap.put(existingActivity, superActivity); } Queue<IActivity> tbeQueue = toBeExpendedMap.get(superActivityId); Queue<IActivity> existingTbeQueque = toBeExpendedMap.remove(existingSuperActivityId); if (existingTbeQueque != null) { tbeQueue.addAll(existingTbeQueque); } }