List of usage examples for java.util Deque clear
void clear();
From source file:net.dv8tion.jda.core.entities.impl.ReceivedMessage.java
@Override public String getContentStripped() { if (strippedContent != null) return strippedContent; synchronized (mutex) { if (strippedContent != null) return strippedContent; String tmp = getContentDisplay(); //all the formatting keys to keep track of String[] keys = new String[] { "*", "_", "`", "~~" }; //find all tokens (formatting strings described above) TreeSet<FormatToken> tokens = new TreeSet<>(Comparator.comparingInt(t -> t.start)); for (String key : keys) { Matcher matcher = Pattern.compile(Pattern.quote(key)).matcher(tmp); while (matcher.find()) tokens.add(new FormatToken(key, matcher.start())); }//from w w w.ja v a 2s. c o m //iterate over all tokens, find all matching pairs, and add them to the list toRemove Deque<FormatToken> stack = new ArrayDeque<>(); List<FormatToken> toRemove = new ArrayList<>(); boolean inBlock = false; for (FormatToken token : tokens) { if (stack.isEmpty() || !stack.peek().format.equals(token.format) || stack.peek().start + token.format.length() == token.start) { //we are at opening tag if (!inBlock) { //we are outside of block -> handle normally if (token.format.equals("`")) { //block start... invalidate all previous tags stack.clear(); inBlock = true; } stack.push(token); } else if (token.format.equals("`")) { //we are inside of a block -> handle only block tag stack.push(token); } } else if (!stack.isEmpty()) { //we found a matching close-tag toRemove.add(stack.pop()); toRemove.add(token); if (token.format.equals("`") && stack.isEmpty()) //close tag closed the block inBlock = false; } } //sort tags to remove by their start-index and iteratively build the remaining string toRemove.sort(Comparator.comparingInt(t -> t.start)); StringBuilder out = new StringBuilder(); int currIndex = 0; for (FormatToken formatToken : toRemove) { if (currIndex < formatToken.start) out.append(tmp.substring(currIndex, formatToken.start)); currIndex = formatToken.start + formatToken.format.length(); } if (currIndex < tmp.length()) out.append(tmp.substring(currIndex)); //return the stripped text, escape all remaining formatting characters (did not have matching // open/close before or were left/right of block return strippedContent = out.toString().replace("*", "\\*").replace("_", "\\_").replace("~", "\\~"); } }
From source file:org.azrul.langkuik.Langkuik.java
public void initLangkuik(final EntityManagerFactory emf, final UI ui, final RelationManagerFactory relationManagerFactory, List<Class<?>> customTypeInterfaces) { List<Class<?>> rootClasses = new ArrayList<>(); for (ManagedType<?> entity : emf.getMetamodel().getManagedTypes()) { Class<?> clazz = entity.getJavaType(); if (clazz.getAnnotation(WebEntity.class).isRoot() == true) { rootClasses.add(clazz);/*from www . ja v a2 s .c o m*/ } } //Manage custom type if (customTypeInterfaces == null) { customTypeInterfaces = new ArrayList<>(); } //add system level custom type customTypeInterfaces.add(AttachmentCustomType.class); //create DAOs for custom types final List<DataAccessObject<?>> customTypeDaos = new ArrayList<>(); for (Class<?> clazz : customTypeInterfaces) { customTypeDaos.add(new HibernateGenericDAO(emf, clazz)); } //Setup page VerticalLayout main = new VerticalLayout(); VerticalLayout content = new VerticalLayout(); final Navigator navigator = new Navigator(ui, content); final HorizontalLayout breadcrumb = new HorizontalLayout(); MenuBar menubar = new MenuBar(); menubar.setId("MENUBAR"); main.addComponent(menubar); main.addComponent(breadcrumb); main.addComponent(content); final Deque<History> history = new ArrayDeque<>(); final Configuration config = Configuration.getInstance(); history.push(new History("START", "Start")); StartView startView = new StartView(history, breadcrumb); navigator.addView("START", startView); MenuBar.MenuItem create = menubar.addItem("Create", null); MenuBar.MenuItem view = menubar.addItem("View", null); final PageParameter pageParameter = new PageParameter(customTypeDaos, emf, relationManagerFactory, history, config, breadcrumb); for (final Class rootClass : rootClasses) { final WebEntity myObject = (WebEntity) rootClass.getAnnotation(WebEntity.class); final DataAccessObject<?> dao = new HibernateGenericDAO<>(emf, rootClass); create.addItem("New " + myObject.name(), new MenuBar.Command() { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { Object object = dao.createNew(true); BeanView<Object, ?> createNewView = new BeanView<>(object, null, null, pageParameter); String targetView = "CREATE_NEW_APPLICATION_" + UUID.randomUUID().toString(); navigator.addView(targetView, (View) createNewView); history.clear(); history.push(new History("START", "Start")); History his = new History(targetView, "Create new " + myObject.name()); history.push(his); navigator.navigateTo(targetView); } }); view.addItem("View " + myObject.name(), new MenuBar.Command() { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { PlainTableView<?> seeApplicationView = new PlainTableView<>(rootClass, pageParameter); String targetView = "VIEW_APPLICATION_" + UUID.randomUUID().toString(); navigator.addView(targetView, (View) seeApplicationView); history.clear(); history.push(new History("START", "Start")); History his = new History(targetView, "View " + myObject.name()); history.push(his); navigator.navigateTo(targetView); } }); } menubar.addItem("Logout", null).addItem("Logout", new MenuBar.Command() { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { ConfirmDialog.show(ui, "Please Confirm:", "Are you really sure you want to log out?", "I am", "Not quite", new ConfirmDialog.Listener() { @Override public void onClose(ConfirmDialog dialog) { if (dialog.isConfirmed()) { HttpServletRequest req = (HttpServletRequest) VaadinService.getCurrentRequest(); HttpServletResponse resp = (HttpServletResponse) VaadinService .getCurrentResponse(); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); SecurityContextLogoutHandler ctxLogOut = new SecurityContextLogoutHandler(); ctxLogOut.logout(req, resp, auth); } } }); } }); navigator.navigateTo("START"); ui.setContent(main); }
From source file:org.jasig.resource.aggr.ResourcesAggregatorImpl.java
/** * Iterate over the list of {@link BasicInclude} sub-classes using the {@link AggregatorCallback#willAggregate(BasicInclude, BasicInclude)} * and {@link AggregatorCallback#aggregate(Deque)} to generate an aggregated list of {@link BasicInclude} sub-classes. */// ww w.jav a 2s. co m protected <T extends BasicInclude> List<T> aggregateBasicIncludes(List<T> original, AggregatorCallback<T> callback) throws IOException { final List<T> result = new LinkedList<T>(); final Deque<T> currentAggregateList = new LinkedList<T>(); for (final T originalElement : original) { // handle first loop iteration if (currentAggregateList.isEmpty()) { currentAggregateList.add(originalElement); } else { // test if 'originalElement' will aggregate with head element in currentAggregate final T baseElement = currentAggregateList.getFirst(); if (callback.willAggregate(originalElement, baseElement)) { // matches current criteria, add to currentAggregate currentAggregateList.add(originalElement); } else { // doesn't match criteria // generate new single aggregate from currentAggregateList final T aggregate = callback.aggregate(currentAggregateList); if (null != aggregate) { // push result result.add(aggregate); } else { this.logger .warn("Generated 0 byte aggregate from: " + generatePathList(currentAggregateList)); } // zero out currentAggregateList currentAggregateList.clear(); // add originalElement to empty list currentAggregateList.add(originalElement); } } } // flush the currentAggregateList if (currentAggregateList.size() > 0) { final T aggregate = callback.aggregate(currentAggregateList); if (null != aggregate) { result.add(aggregate); } else { this.logger.warn("Generated 0 byte aggregate from: " + generatePathList(currentAggregateList)); } } return result; }
From source file:org.lilyproject.indexer.engine.ValueEvaluator.java
private List<String> extractContent(String table, List<IndexValue> indexValues, LRepository repository) { // At this point we can be sure the value will be a blob, this is // validated during // the construction of the indexer conf. List<String> result = new ArrayList<String>(indexValues.size()); Deque<Integer> indexes = new ArrayDeque<Integer>(); for (IndexValue indexValue : indexValues) { indexes.clear(); if (indexValue.listIndex != null) { indexes.addLast(indexValue.listIndex); }//from ww w . j a va 2s .co m extractContent(table, indexValue.value, indexes, indexValue.record, indexValue.fieldType, result, repository); } return result.isEmpty() ? null : result; }