List of usage examples for com.google.common.collect Iterables indexOf
public static <T> int indexOf(Iterable<T> iterable, Predicate<? super T> predicate)
From source file:org.obeonetwork.m2doc.generator.TableClientProcessor.java
/** * Fill a newly created word table with the data from an MTable. * /*from w ww. j a v a2s . co m*/ * @param table * The newly created word table * @param mtable * The MTable that describes the data and styles to insert */ private void fillTable(XWPFTable table, MTable mtable) { XWPFTableRow headerRow = table.getRow(0); initializeEmptyTableCell(headerRow.getCell(0), null, null); Iterable<? extends MColumn> mcolumns = mtable.getColumns(); for (MColumn mcol : mcolumns) { XWPFTableCell cell; cell = headerRow.addNewTableCell(); initializeEmptyTableCell(cell, null, null); setCellContent(cell, mcol.getLabel(), null); } for (MRow mrow : mtable.getRows()) { XWPFTableRow row = table.createRow(); List<XWPFTableCell> cells = row.getTableCells(); for (int i = 0; i < cells.size(); i++) { XWPFTableCell cell = cells.get(i); // Make sure empty cells are empty and have the right style if (i > 0) { initializeEmptyTableCell(cell, mrow, Iterables.get(mtable.getColumns(), i - 1)); } else { initializeEmptyTableCell(cell, null, null); } } XWPFTableCell cell0 = row.getCell(0); setCellContent(cell0, mrow.getLabel(), null); for (MCell mcell : mrow.getCells()) { MColumn mcol = mcell.getColumn(); if (mcol != null) { XWPFTableCell cell = row.getCell(Iterables.indexOf(mcolumns, Predicates.equalTo(mcol)) + 1); setCellContent(cell, mcell.getLabel(), mcell.getStyle()); } } } }
From source file:org.gradle.plugins.ide.eclipse.EclipsePlugin.java
private void configureEclipseProject(final Project project, final EclipseModel model) { maybeAddTask(project, this, ECLIPSE_PROJECT_TASK_NAME, GenerateEclipseProject.class, new Action<GenerateEclipseProject>() { @Override/*from w w w . ja v a2s. c o m*/ public void execute(GenerateEclipseProject task) { final EclipseProject projectModel = task.getProjectModel(); //task properties: task.setDescription("Generates the Eclipse project file."); task.setInputFile(project.file(".project")); task.setOutputFile(project.file(".project")); //model: model.setProject(projectModel); projectModel.setName(project.getName()); final ConventionMapping convention = ((IConventionAware) projectModel) .getConventionMapping(); convention.map("comment", new Callable<String>() { @Override public String call() { return project.getDescription(); } }); project.getPlugins().withType(JavaBasePlugin.class, new Action<JavaBasePlugin>() { @Override public void execute(JavaBasePlugin javaBasePlugin) { if (!project.getPlugins().hasPlugin(EarPlugin.class)) { projectModel.buildCommand("org.eclipse.jdt.core.javabuilder"); } projectModel.natures("org.eclipse.jdt.core.javanature"); convention.map("linkedResources", new Callable<Set<Link>>() { @Override public Set<Link> call() { return new LinkedResourcesCreator().links(project); } }); } }); project.getPlugins().withType(GroovyBasePlugin.class, new Action<GroovyBasePlugin>() { @Override public void execute(GroovyBasePlugin groovyBasePlugin) { projectModel.getNatures().add( projectModel.getNatures().indexOf("org.eclipse.jdt.core.javanature"), "org.eclipse.jdt.groovy.core.groovyNature"); } }); project.getPlugins().withType(ScalaBasePlugin.class, new Action<ScalaBasePlugin>() { @Override public void execute(ScalaBasePlugin scalaBasePlugin) { projectModel.getBuildCommands().set(Iterables .indexOf(projectModel.getBuildCommands(), new Predicate<BuildCommand>() { @Override public boolean apply(BuildCommand buildCommand) { return buildCommand.getName() .equals("org.eclipse.jdt.core.javabuilder"); } }), new BuildCommand("org.scala-ide.sdt.core.scalabuilder")); projectModel.getNatures().add( projectModel.getNatures().indexOf("org.eclipse.jdt.core.javanature"), "org.scala-ide.sdt.core.scalanature"); } }); } }); }
From source file:clocker.docker.location.DockerContainerLocation.java
private void parseDockerCallback(String commandString) { List<String> tokens = DockerCallbacks.PARSER.splitToList(commandString); int callback = Iterables.indexOf(tokens, Predicates.equalTo(DockerCallbacks.DOCKER_HOST_CALLBACK)); if (callback == -1) { LOG.warn("Could not find callback token: {}", commandString); throw new IllegalStateException("Cannot find callback token in command line"); }/*from ww w . j a v a 2 s . c o m*/ String command = tokens.get(callback + 1); LOG.info("Executing callback for {}: {}", getOwner(), command); if (DockerCallbacks.COMMIT.equalsIgnoreCase(command)) { String containerId = getOwner().getContainerId(); String imageName = getOwner().sensors().get(DockerContainer.DOCKER_IMAGE_NAME); String output = getOwner().getDockerHost() .runDockerCommandTimeout(format("commit %s %s", containerId, imageName), Duration.minutes(20)); String imageId = DockerUtils.checkId(output); getOwner().getRunningEntity().sensors().set(DockerContainer.DOCKER_IMAGE_ID, imageId); getOwner().sensors().set(DockerContainer.DOCKER_IMAGE_ID, imageId); getOwner().getDockerHost().getDynamicLocation().markImage(imageName); } else if (DockerCallbacks.PUSH.equalsIgnoreCase(command)) { // FIXME this doesn't work yet String imageName = getOwner().sensors().get(DockerContainer.DOCKER_IMAGE_NAME); getOwner().getDockerHost().runDockerCommand(format("push %s", imageName)); } else { LOG.warn("Unknown Docker host command: {}", command); } }
From source file:com.microsoft.intellij.helpers.activityConfiguration.office365CustomWizardParameter.Office365ConfigForm.java
private void fillApps(final String selectedAppId) { final Office365ConfigForm office365ConfigForm = this; ApplicationManager.getApplication().invokeAndWait(new Runnable() { @Override//from w w w.j a v a 2s .c o m public void run() { cmbApps.setRenderer(new StringComboBoxItemRenderer()); cmbApps.setModel(new DefaultComboBoxModel(new String[] { "(loading...)" })); cmbApps.setEnabled(false); ReadOnlyCellTableModel messageTableModel = new ReadOnlyCellTableModel(); messageTableModel.addColumn("Message"); Vector<String> vector = new Vector<String>(); vector.add("(loading... )"); messageTableModel.addRow(vector); tblAppPermissions.setModel(messageTableModel); } }, ModalityState.any()); final Office365Manager manager = Office365ManagerImpl.getManager(); try { if (!manager.authenticated()) { manager.authenticate(); // if we still don't have an authentication token then the // user has cancelled out of login; so we cancel out of this // wizard if (!manager.authenticated()) { ApplicationManager.getApplication().invokeAndWait(new Runnable() { @Override public void run() { office365ConfigForm.close(DialogWrapper.CANCEL_EXIT_CODE); } }, ModalityState.any()); return; } } Futures.addCallback(manager.getApplicationList(), new FutureCallback<List<Application>>() { @Override public void onSuccess(final List<Application> applications) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { if (applications.size() > 0) { cmbApps.setRenderer(new ListCellRendererWrapper<Application>() { @Override public void customize(JList jList, Application application, int i, boolean b, boolean b2) { setText(application.getdisplayName()); } }); cmbApps.setModel(new DefaultComboBoxModel(applications.toArray())); cmbApps.setEnabled(true); int selectedIndex = 0; if (!StringHelper.isNullOrWhiteSpace(selectedAppId)) { selectedIndex = Iterables.indexOf(applications, new Predicate<Application>() { @Override public boolean apply(Application application) { return application.getappId().equals(selectedAppId); } }); } cmbApps.setSelectedIndex(Math.max(0, selectedIndex)); } else { cmbApps.setRenderer(new StringComboBoxItemRenderer()); cmbApps.setModel(new DefaultComboBoxModel(new String[] { "No apps configured)" })); cmbApps.setEnabled(false); ReadOnlyCellTableModel messageTableModel = new ReadOnlyCellTableModel(); messageTableModel.addColumn("Message"); Vector<String> vector = new Vector<String>(); vector.add("There are no applications configured."); messageTableModel.addRow(vector); tblAppPermissions.setModel(messageTableModel); //tblAppPermissions.setEnabled(false); } } }, ModalityState.any()); } @Override public void onFailure(final Throwable throwable) { ApplicationManager.getApplication().invokeAndWait(new Runnable() { @Override public void run() { DefaultLoader.getUIHelper().showException( "An error occurred while attempting to fetch the " + "list of applications.", throwable, "Microsoft Cloud Services For Android - Error Fetching Applications", false, true); } }, ModalityState.any()); } }); } catch (Throwable throwable) { DefaultLoader.getUIHelper().showException( "An error occurred while attempting to authenticate with Office 365.", throwable, "Microsoft Cloud Services For Android - Error Authenticating O365", false, true); } }
From source file:de.iteratec.iteraplan.businesslogic.service.AbstractHierarchicalBuildingBlockService.java
/**{@inheritDoc}**/ public boolean saveReorderMove(final Integer sourceId, final Integer destId, boolean insertAfter) { E sourceEntity = getDao().loadObjectById(sourceId); E destEntity = getDao().loadObjectById(destId); if (sourceEntity == null || destEntity == null) { LOGGER.error("Can't read source and/or destination element for reordering."); // TODO throw new IteraplanBusinessException(); return false; }//from w w w.j a v a2 s .co m // get all children of destination entity's parent, including the destination entity itself (sorted by position) E destParent = destEntity.getParent(); List<E> allDestChildren = destParent.getChildrenAsList(); // TODO verify if there is no need to use a comparator because hibernate sorts by position by default // using the comparator leads to NPEs if the BB is newly created // Collections.sort(allDestChildren, new ByPositionComparator()); // get all children of source entity's parent, and remove the source entity from this collection. E sourceParent = sourceEntity.getParent(); sourceEntity.removeFromParent(sourceParent); int destIndex = Iterables.indexOf(allDestChildren, new Predicate<E>() { public boolean apply(E input) { return input.getId().equals(destId); } }); if (destIndex < 0) { LOGGER.error("Can't determine index of destination for reordering."); // TODO throw new IteraplanBusinessException(); return false; } int insertAt = destIndex + (insertAfter ? 1 : 0); LOGGER.debug("Insert <" + sourceEntity.getNonHierarchicalName() + "> after <" + destEntity.getNonHierarchicalName() + "> at index: " + insertAt); if (insertAt >= allDestChildren.size()) { allDestChildren.add(sourceEntity); } else { allDestChildren.add(insertAt, sourceEntity); } sourceEntity.setParent(destParent); saveOrUpdate(sourceParent); if (!sourceParent.equals(destParent)) { saveOrUpdate(destParent); } return true; }
From source file:org.polymap.core.mapeditor.MapEditor.java
/** * Fills the {@link #olwidget} with the internal servers of the * {@link #renderManager}.//from w ww . j a va2 s .co m */ void addLayer(RenderLayerDescriptor descriptor) { assert descriptor != null; assert !layers.containsKey(descriptor); WMSLayer olayer = new WMSLayer(descriptor.title(), descriptor.servicePath, descriptor.layer.getRenderKey()); olayer.setFormat("image/png"); olayer.setVisibility(true); olayer.setIsBaseLayer(false); int tileSize = descriptor.layer.getTileSize(); if (tileSize > 0) { olayer.setTileSize(new Size(tileSize, tileSize)); } else { olayer.setSingleTile(true); } olayer.setBuffer(0); olayer.setOpacity(((double) descriptor.opacity) / 100); olayer.setTransitionEffect(Layer.TRANSITION_RESIZE); layers.put(descriptor, olayer); olwidget.getMap().addLayer(olayer); int layerIndex = Iterables.indexOf(layers.keySet(), Predicates.equalTo(descriptor)); olwidget.getMap().setLayerIndex(olayer, layerIndex); //overview.addLayer( olLayer ); if (overview != null) { overview.addLayer(descriptor); } }
From source file:com.smoketurner.notification.application.store.NotificationStore.java
/** * Returns the index in notifications that matches the given ID or is the * parent of a child notification, or -1 if the notification was not found. * * @param notifications// ww w . j ava2 s .com * Notifications to search through * @param id * Notification ID to find * @return the position of the notification or -1 if not found */ public static int indexOf(@Nonnull final Iterable<Notification> notifications, final long id) { return Iterables.indexOf(notifications, notification -> { // first check that the ID matches final Optional<Long> notificationId = notification.getId(); if (!notificationId.isPresent()) { return false; } else if (notificationId.get() == id) { return true; } // then check to see if the notification is included in any rolled // up notifications final Collection<Notification> children = notification.getNotifications() .orElse(Collections.emptyList()); if (children.isEmpty()) { return false; } return indexOf(children, id) != -1; }); }
From source file:net.grappendorf.doitlater.TaskListActivity.java
private void updateTaskItem(final String taskId) { ((DoItLaterApplication) getApplication()).getTaskManager().getTask(taskList.getId(), taskId, this, new Handler() { @Override/*from w ww. j a v a 2s . c om*/ @SuppressWarnings("unchecked") public void handleMessage(Message msg) { if (msg.obj != null) { Task task = (Task) msg.obj; int taskIndex = Iterables.indexOf(tasks, new Predicate<Task>() { @Override public boolean apply(@Nullable Task task) { return task != null && task.getId().equals(taskId); } }); if (taskIndex >= 0) { tasks.set(taskIndex, task); ((ArrayAdapter<Task>) getListAdapter()).notifyDataSetChanged(); } } } }); }
From source file:com.microsoftopentechnologies.intellij.wizards.activityConfiguration.Office365Step.java
private void fillApps(final String selectedAppId) { ApplicationManager.getApplication().invokeAndWait(new Runnable() { @Override//from w w w . j a v a 2 s . c o m public void run() { cmbApps.setRenderer(new StringComboBoxItemRenderer()); cmbApps.setModel(new DefaultComboBoxModel(new String[] { "(loading...)" })); cmbApps.setEnabled(false); ReadOnlyCellTableModel messageTableModel = new ReadOnlyCellTableModel(); messageTableModel.addColumn("Message"); Vector<String> vector = new Vector<String>(); vector.add("(loading... )"); messageTableModel.addRow(vector); tblAppPermissions.setModel(messageTableModel); } }, ModalityState.any()); final Office365Manager manager = Office365RestAPIManager.getManager(); try { if (!manager.authenticated()) { manager.authenticate(); // if we still don't have an authentication token then the // user has cancelled out of login; so we cancel out of this // wizard if (manager.getAuthenticationToken() == null) { ApplicationManager.getApplication().invokeAndWait(new Runnable() { @Override public void run() { model.cancel(); } }, ModalityState.any()); return; } } Futures.addCallback(manager.getApplicationList(), new FutureCallback<List<Application>>() { @Override public void onSuccess(final List<Application> applications) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { if (applications.size() > 0) { cmbApps.setRenderer(new ListCellRendererWrapper<Application>() { @Override public void customize(JList jList, Application application, int i, boolean b, boolean b2) { setText(application.getdisplayName()); } }); cmbApps.setModel(new DefaultComboBoxModel(applications.toArray())); cmbApps.setEnabled(true); int selectedIndex = 0; if (!StringHelper.isNullOrWhiteSpace(selectedAppId)) { selectedIndex = Iterables.indexOf(applications, new Predicate<Application>() { @Override public boolean apply(Application application) { return application.getappId().equals(selectedAppId); } }); } cmbApps.setSelectedIndex(Math.max(0, selectedIndex)); } else { cmbApps.setRenderer(new StringComboBoxItemRenderer()); cmbApps.setModel(new DefaultComboBoxModel(new String[] { "No apps configured)" })); cmbApps.setEnabled(false); ReadOnlyCellTableModel messageTableModel = new ReadOnlyCellTableModel(); messageTableModel.addColumn("Message"); Vector<String> vector = new Vector<String>(); vector.add("There are no applications configured."); messageTableModel.addRow(vector); tblAppPermissions.setModel(messageTableModel); //tblAppPermissions.setEnabled(false); } } }, ModalityState.any()); } @Override public void onFailure(final Throwable throwable) { ApplicationManager.getApplication().invokeAndWait(new Runnable() { @Override public void run() { UIHelper.showException("An error occurred while fetching the list of applications.", throwable); } }, ModalityState.any()); } }); } catch (Throwable throwable) { UIHelper.showException("An error occurred while trying to authenticate with Office 365", throwable); return; } }
From source file:org.renjin.primitives.Attributes.java
@Internal public static SEXP inherits(SEXP exp, StringVector what, boolean which) { if (!which) { return new LogicalArrayVector(inherits(exp, what)); }/*from ww w .j a va 2 s . c om*/ StringVector classes = getClass(exp); int result[] = new int[what.length()]; for (int i = 0; i != what.length(); ++i) { result[i] = Iterables.indexOf(classes, Predicates.equalTo(what.getElementAsString(i))) + 1; } return new IntArrayVector(result); }