List of usage examples for com.google.common.collect BiMap size
int size();
From source file:org.eclipse.sirius.common.tools.api.editing.FileStatusPrecommitListener.java
/** * {@inheritDoc}//from w w w.j a v a 2 s. c o m */ @Override public Command transactionAboutToCommit(final ResourceSetChangeEvent event) throws RollbackException { final boolean defensiveEditValidation = Platform.getPreferencesService().getBoolean( "org.eclipse.sirius.common.ui", CommonPreferencesConstants.PREF_DEFENSIVE_EDIT_VALIDATION, true, //$NON-NLS-1$ null); final Command cmd = super.transactionAboutToCommit(event); if (defensiveEditValidation) { final Set<Resource> changedRes = Sets.newLinkedHashSet(); if (!event.getTransaction().isReadOnly()) { for (org.eclipse.emf.common.notify.Notification notif : Iterables.filter(event.getNotifications(), org.eclipse.emf.common.notify.Notification.class)) { if (notif.getNotifier() instanceof EObject) { final Resource res = ((EObject) notif.getNotifier()).eResource(); if (resourceChange(res, notif)) { changedRes.add(res); } } } } final BiMap<IFile, Resource> files2Validate = HashBiMap.create(); final Iterator<Resource> it = changedRes.iterator(); while (it.hasNext()) { final Resource nextResource = it.next(); final IFile file = WorkspaceSynchronizer.getFile(nextResource); if (file != null && file.isReadOnly()) { files2Validate.put(file, nextResource); } } if (!files2Validate.isEmpty()) { final RollbackException cancelException = new RollbackException( new Status(IStatus.CANCEL, DslCommonPlugin.PLUGIN_ID, Messages.FileStatusPrecommitListener_fileModificationValidationStatus)); final MultiStatus status = new MultiStatus(DslCommonPlugin.PLUGIN_ID, IStatus.ERROR, Messages.FileStatusPrecommitListener_fileModificationValidationStatus, cancelException); if (fileModificationValidators.isEmpty()) { // No extension found, use the default process. status.add(ResourcesPlugin.getWorkspace().validateEdit( files2Validate.keySet().toArray(new IFile[files2Validate.size()]), IWorkspace.VALIDATE_PROMPT)); } else { for (final IFileModificationValidator fileModificationValidator : fileModificationValidators) { final IStatus validationStatus = fileModificationValidator .validateEdit(files2Validate.keySet()); if (validationStatus != null) { status.add(validationStatus); } } } if (!status.isOK()) { throw cancelException; } } } return cmd; }
From source file:org.eclipse.tracecompass.tmf.ui.views.timegraph.TimeGraphFindDialog.java
/** * Returns the index of the entry that match the specified search string, or * <code>-1</code> if the string can not be found when searching using the * given options.//from w w w .j a va2s .c o m * * @param findString * the string to search for * @param startIndex * the index at which to start the search * @param items * The map of items in the time graph view * @param options * The options use for the search * @return the index of the find entry following the options or * <code>-1</code> if nothing found */ private int findNext(String findString, int startIndex, BiMap<ITimeGraphEntry, Integer> items, SearchOptions options) { int index; if (options.forwardSearch) { index = startIndex == items.size() - 1 ? -1 : findNext(startIndex + 1, findString, items, options); } else { index = startIndex == 0 ? -1 : findNext(startIndex - 1, findString, items, options); } if (index == -1) { if (okToUse(getShell())) { getShell().getDisplay().beep(); } if (options.wrapSearch) { statusMessage(Messages.TimeGraphFindDialog_StatusWrappedLabel); index = findNext(-1, findString, items, options); } } return index; }
From source file:org.apache.hadoop.security.ShellBasedIdMapping.java
/** * Get the list of users or groups returned by the specified command, * and save them in the corresponding map. * @throws IOException //from ww w.j a va2s . c o m */ @VisibleForTesting public static boolean updateMapInternal(BiMap<Integer, String> map, String mapName, String command, String regex, Map<Integer, Integer> staticMapping) throws IOException { boolean updated = false; BufferedReader br = null; try { Process process = Runtime.getRuntime().exec(new String[] { "bash", "-c", command }); br = new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.defaultCharset())); String line = null; while ((line = br.readLine()) != null) { String[] nameId = line.split(regex); if ((nameId == null) || (nameId.length != 2)) { throw new IOException("Can't parse " + mapName + " list entry:" + line); } LOG.debug("add to " + mapName + "map:" + nameId[0] + " id:" + nameId[1]); // HDFS can't differentiate duplicate names with simple authentication final Integer key = staticMapping.get(parseId(nameId[1])); final String value = nameId[0]; if (map.containsKey(key)) { final String prevValue = map.get(key); if (value.equals(prevValue)) { // silently ignore equivalent entries continue; } reportDuplicateEntry("Got multiple names associated with the same id: ", key, value, key, prevValue); continue; } if (map.containsValue(value)) { final Integer prevKey = map.inverse().get(value); reportDuplicateEntry("Got multiple ids associated with the same name: ", key, value, prevKey, value); continue; } map.put(key, value); updated = true; } LOG.debug("Updated " + mapName + " map size: " + map.size()); } catch (IOException e) { LOG.error("Can't update " + mapName + " map"); throw e; } finally { if (br != null) { try { br.close(); } catch (IOException e1) { LOG.error("Can't close BufferedReader of command result", e1); } } } return updated; }
From source file:org.eclipse.tracecompass.tmf.ui.views.timegraph.TimeGraphFindDialog.java
private int findNext(int startIndex, String findString, BiMap<ITimeGraphEntry, Integer> items, SearchOptions options) {/*from w ww . j a v a2 s.co m*/ if (fFindTarget != null) { if (findString == null || findString.length() == 0) { return -1; } final @NonNull Pattern pattern = getPattern(findString, options); int index = adjustIndex(startIndex, items.size(), options.forwardSearch); BiMap<Integer, ITimeGraphEntry> entries = items.inverse(); while (index >= 0 && index < entries.size()) { final @Nullable ITimeGraphEntry entry = entries.get(index); if (entry != null && entry.matches(pattern)) { return index; } index = options.forwardSearch ? ++index : --index; } } return -1; }