List of usage examples for java.util List indexOf
int indexOf(Object o);
From source file:com.eyeq.pivot4j.ui.impl.TableHeaderNode.java
/** * @param collector/*from w w w.j a v a 2s. c o m*/ */ void addMemberProperties() { if (getReference().getAxis() != Axis.ROWS) { return; } List<TreeNode<TableAxisContext>> children = null; if (getMember() != null) { List<Level> levels = getReference().getLevels(getHierarchy()); int index = levels.indexOf(getMember().getLevel()); int endIndex = getReference().getPivotRenderer().getShowParentMembers() ? index + 1 : levels.size(); List<Level> lowerLevels = levels.subList(index, endIndex); for (Level level : lowerLevels) { List<Property> properties = getReference().getProperties(level); if (!properties.isEmpty()) { children = new ArrayList<TreeNode<TableAxisContext>>(getChildren()); clear(); TableHeaderNode parentNode = this; for (Property prop : properties) { TableHeaderNode propertyNode = new TableHeaderNode(getReference()); propertyNode.setPosition(position); propertyNode.setHierarchy(getHierarchy()); propertyNode.setMember(getMember()); propertyNode.setProperty(prop); parentNode.addChild(propertyNode); parentNode = propertyNode; } for (TreeNode<TableAxisContext> child : children) { parentNode.addChild(child); } } } } if (children == null) { children = getChildren(); } for (TreeNode<TableAxisContext> child : children) { TableHeaderNode nodeChild = (TableHeaderNode) child; nodeChild.addMemberProperties(); } }
From source file:com.google.dart.java2dart.SyntaxTranslator.java
/** * Replaces "node" with "replacement" in parent of "node". */// ww w . j ava 2 s. c om public static void replaceNode(ASTNode parent, ASTNode node, ASTNode replacement) { Class<? extends ASTNode> parentClass = parent.getClass(); // try get/set methods try { for (Method getMethod : parentClass.getMethods()) { String getName = getMethod.getName(); if (getName.startsWith("get") && getMethod.getParameterTypes().length == 0 && getMethod.invoke(parent) == node) { String setName = "set" + getName.substring(3); Method setMethod = parentClass.getMethod(setName, getMethod.getReturnType()); setMethod.invoke(parent, replacement); return; } } } catch (Throwable e) { ExecutionUtils.propagate(e); } // special cases if (parent instanceof ListLiteral) { List<Expression> elements = ((ListLiteral) parent).getElements(); int index = elements.indexOf(node); if (index != -1) { elements.set(index, (Expression) replacement); return; } } if (parent instanceof ArgumentList) { List<Expression> arguments = ((ArgumentList) parent).getArguments(); int index = arguments.indexOf(node); if (index != -1) { arguments.set(index, (Expression) replacement); return; } } if (parent instanceof TypeArgumentList) { List<TypeName> arguments = ((TypeArgumentList) parent).getArguments(); int index = arguments.indexOf(node); if (index != -1) { arguments.set(index, (TypeName) replacement); return; } } // not found throw new UnsupportedOperationException("" + parentClass); }
From source file:com.jiwhiz.domain.account.impl.ConnectionRepositoryImpl.java
public MultiValueMap<String, Connection<?>> findConnectionsToUsers( MultiValueMap<String, String> providerUsers) { if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); }//from w w w . ja v a 2s . c om MultiValueMap<String, Connection<?>> connectionsForUsers = new LinkedMultiValueMap<String, Connection<?>>(); for (Iterator<Entry<String, List<String>>> it = providerUsers.entrySet().iterator(); it.hasNext();) { Entry<String, List<String>> entry = it.next(); String providerId = entry.getKey(); List<String> providerUserIds = entry.getValue(); List<UserSocialConnection> userSocialConnections = userSocialConnectionRepository .findByProviderIdAndProviderUserIdIn(providerId, providerUserIds); List<Connection<?>> connections = new ArrayList<Connection<?>>(providerUserIds.size()); for (int i = 0; i < providerUserIds.size(); i++) { connections.add(null); } connectionsForUsers.put(providerId, connections); for (UserSocialConnection userSocialConnection : userSocialConnections) { String providerUserId = userSocialConnection.getProviderUserId(); int connectionIndex = providerUserIds.indexOf(providerUserId); connections.set(connectionIndex, buildConnection(userSocialConnection)); } } return connectionsForUsers; }
From source file:nl.opengeogroep.filesetsync.client.FilesetSyncer.java
private void deleteLocalFiles() { if (Shutdown.isHappening()) { return;/* w w w. jav a2s .c o m*/ } if (fs.getRegexp() != null) { // XXX only delete local files matching regexp, for now don't delete // anything return; } if (fileList.size() == 1 && fileList.get(0).getType() == TYPE_FILE) { return; } for (List<FileRecord> dirList : new FileRecordListDirectoryIterator(fileList)) { Iterator<FileRecord> it = dirList.iterator(); FileRecord dir = it.next(); File localDir = new File(fs.getLocal() + File.separator + dir.getName()); if (!localDir.exists()) { continue; } List<String> toDelete = new ArrayList(Arrays.asList(localDir.list())); while (it.hasNext()) { FileRecord fr = it.next(); String name = dir.getName().equals(".") ? fr.getName() : fr.getName().substring(dir.getName().length() + 1); if (toDelete.indexOf(name) != -1) { // Don't delete this file -- may need to be overwritten though try { // But if is not the same type, do delete it char localType = new File(localDir.getCanonicalPath() + File.separator + name).isDirectory() ? 'd' : 'f'; if (localType == fr.getType()) { toDelete.remove(name); } } catch (IOException ex) { } } } for (String deleteIt : toDelete) { if (Shutdown.isHappening()) { return; } File f = new File(localDir + File.separator + deleteIt); try { if (f.isDirectory()) { log.info("rmdirs " + f.getCanonicalPath()); FileUtils.deleteDirectory(f); } else { log.info("delete " + f.getCanonicalPath()); f.delete(); } } catch (Exception e) { log.error("Exception deleting file " + f + ": " + ExceptionUtils.getMessage(e)); } } } }
From source file:jmri.InstanceManager.java
/** * Remove an object of a particular type that had earlier been registered * with {@link #store}. If item was previously registered, this will remove * item and fire an indexed property change event for the property matching * the output of {@link #getListPropertyName(java.lang.Class)} for type. * * @param <T> The type of the class * @param item The object of type T to be deregistered * @param type The class Object for the item's type *//*from w w w . ja v a 2 s . c o m*/ public <T> void remove(@Nonnull T item, @Nonnull Class<T> type) { log.debug("Remove item type {}", type.getName()); List<T> l = getList(type); int index = l.indexOf(item); if (index != -1) { // -1 means items was not in list, and therefor, not registered l.remove(item); if (item instanceof Disposable) { dispose((Disposable) item); } } // if removing last item, re-initialize later if (l.isEmpty()) { setInitializationState(type, InitializationState.NOTSET); } if (index != -1) { // -1 means items was not in list, and therefor, not registered // fire property change last pcs.fireIndexedPropertyChange(getListPropertyName(type), index, item, null); } }
From source file:CSVTools.CsvToolsApi.java
public List<String> replaceReservedKeyWords(List<String> header) { List<String> reservedKeyWords = new ArrayList<String>(); reservedKeyWords.add("release"); for (String currentHeader : header) { if (reservedKeyWords.contains(currentHeader.toLowerCase().trim())) { this.logger.info("Reserved keyword found"); int index = header.indexOf(currentHeader); // replace the header with backticks header.set(index, ("`" + currentHeader + "`")); }/*w ww. j a v a 2 s .c om*/ } return header; }
From source file:com.jiwhiz.domain.account.impl.MongoConnectionRepositoryImpl.java
public MultiValueMap<String, Connection<?>> findConnectionsToUsers( MultiValueMap<String, String> providerUsers) { if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); }/*from w w w . j a v a 2 s. c o m*/ MultiValueMap<String, Connection<?>> connectionsForUsers = new LinkedMultiValueMap<String, Connection<?>>(); for (Iterator<Entry<String, List<String>>> it = providerUsers.entrySet().iterator(); it.hasNext();) { Entry<String, List<String>> entry = it.next(); String providerId = entry.getKey(); List<String> providerUserIds = entry.getValue(); List<UserSocialConnection> userSocialConnections = this.userSocialConnectionRepository .findByProviderIdAndProviderUserIdIn(providerId, providerUserIds); List<Connection<?>> connections = new ArrayList<Connection<?>>(providerUserIds.size()); for (int i = 0; i < providerUserIds.size(); i++) { connections.add(null); } connectionsForUsers.put(providerId, connections); for (UserSocialConnection userSocialConnection : userSocialConnections) { String providerUserId = userSocialConnection.getProviderUserId(); int connectionIndex = providerUserIds.indexOf(providerUserId); connections.set(connectionIndex, buildConnection(userSocialConnection)); } } return connectionsForUsers; }
From source file:com.google.gdt.eclipse.designer.mobile.preferences.device.DevicesPreferencePage.java
/** * Updates buttons according to selection in {@link #m_viewer}. *///from ww w . j a v a 2 s. com private void updateButtons() { List<Object> selection = getSelectedElements(); m_addEntryButton.setEnabled(!selection.isEmpty()); m_editButton.setEnabled(selection.size() == 1); m_removeButton.setEnabled(!selection.isEmpty()); // move up/down List<CategoryInfo> categories = DeviceManager.getCategories(); { boolean upEnabled = !selection.isEmpty(); boolean downEnabled = !selection.isEmpty(); for (Object element : selection) { if (element instanceof CategoryInfo) { upEnabled &= categories.indexOf(element) != 0; downEnabled &= categories.indexOf(element) != categories.size() - 1; } else if (element instanceof DeviceInfo) { DeviceInfo device = (DeviceInfo) element; List<DeviceInfo> devices = device.getCategory().getDevices(); m_editButton.setEnabled(m_editButton.isEnabled() && !device.isContributed()); upEnabled &= devices.indexOf(device) != 0; downEnabled &= devices.indexOf(device) != devices.size() - 1; } } m_moveUpButton.setEnabled(upEnabled); m_moveDownButton.setEnabled(downEnabled); } }
From source file:de.hska.ld.content.service.impl.DocumentServiceImpl.java
@Override @Transactional(readOnly = true)//from w ww .j a va 2s .c om public Access getCurrentUserPermissions(Long documentId, String permissions) { Document document = findById(documentId); if (document == null) { throw new NotFoundException("documentId"); } if (document.getCreator().equals(Core.currentUser())) { return null; } List<Access> accessList = getUsersByPermissions(documentId, permissions); Access tempAccess = new Access(); tempAccess.setUser(Core.currentUser()); int idx = accessList.indexOf(tempAccess); if (idx != -1) { return accessList.get(idx); } else { return null; } }
From source file:io.druid.segment.IndexMaker.java
private static Iterable<Rowboat> makeRowIterable(final List<IndexableAdapter> adapters, final List<String> mergedDimensions, final List<String> mergedMetrics, final ArrayList<Map<String, IntBuffer>> dimConversions, final Function<ArrayList<Iterable<Rowboat>>, Iterable<Rowboat>> rowMergerFn) { ArrayList<Iterable<Rowboat>> boats = Lists.newArrayListWithCapacity(adapters.size()); for (int i = 0; i < adapters.size(); ++i) { final IndexableAdapter adapter = adapters.get(i); final int[] dimLookup = new int[mergedDimensions.size()]; int count = 0; for (String dim : adapter.getDimensionNames()) { dimLookup[count] = mergedDimensions.indexOf(dim); count++;// w ww. ja v a 2 s . c om } final int[] metricLookup = new int[mergedMetrics.size()]; count = 0; for (String metric : adapter.getMetricNames()) { metricLookup[count] = mergedMetrics.indexOf(metric); count++; } boats.add(new MMappedIndexRowIterable( Iterables.transform(adapters.get(i).getRows(), new Function<Rowboat, Rowboat>() { @Override public Rowboat apply(Rowboat input) { int[][] newDims = new int[mergedDimensions.size()][]; int j = 0; for (int[] dim : input.getDims()) { newDims[dimLookup[j]] = dim; j++; } Object[] newMetrics = new Object[mergedMetrics.size()]; j = 0; for (Object met : input.getMetrics()) { newMetrics[metricLookup[j]] = met; j++; } return new Rowboat(input.getTimestamp(), newDims, newMetrics, input.getRowNum()); } }), mergedDimensions, dimConversions.get(i), i)); } return rowMergerFn.apply(boats); }