@Override public Command getCommand() { // edit command final ArrayList<Command> changes = new ArrayList<>(); super.addEditCommands.accept(changes); if (productOwnerProperty().get() != modelWrapper.get().getProductOwner()) { changes.add( new EditCommand<>(modelWrapper.get(), "productOwner", productOwnerProperty().get())); } if (scrumMasterProperty().get() != modelWrapper.get().getScrumMaster()) { changes.add( new EditCommand<>(modelWrapper.get(), "scrumMaster", scrumMasterProperty().get())); } if (!(teamMembersProperty().get().containsAll(modelWrapper.get().getTeamMembers()) && modelWrapper.get().getTeamMembers().containsAll(teamMembersProperty().get()))) { // BEWARE: magic ArrayList<Person> teamMembers = new ArrayList<>(); teamMembers.addAll(teamMembersProperty().get()); changes.add(new EditCommand<>(modelWrapper.get(), "teamMembers", teamMembers)); } if (!(devTeamProperty().get().containsAll(modelWrapper.get().getDevTeam()) && modelWrapper.get().getDevTeam().containsAll(devTeamProperty().get()))) { // BEWARE: magic ArrayList<Person> devTeam = new ArrayList<>(); devTeam.addAll(devTeamProperty().get()); changes.add(new EditCommand<>(modelWrapper.get(), "devTeam", devTeam)); } final ArrayList<Person> newMembers = new ArrayList<>(teamMembersProperty().get()); newMembers.removeAll(modelWrapper.get().observableTeamMembers()); final ArrayList<Person> oldMembers = new ArrayList<>(modelWrapper.get().observableTeamMembers()); oldMembers.removeAll(teamMembersProperty().get()); // Loop through all the new members and add a command to set their team // Set the person's team field to this team changes.addAll( newMembers .stream() .map(person -> new EditCommand<>(person, "team", modelWrapper.get())) .collect(Collectors.toList())); // Loop through all the old members and add a command to remove their team // Set the person's team field to null, since they're no longer in the team changes.addAll( oldMembers .stream() .map(person -> new EditCommand<>(person, "team", null)) .collect(Collectors.toList())); return new CompoundCommand("Edit Team", changes); }
@Override public void sendMessage(Message message) throws MessagingException { ArrayList<Address> addresses = new ArrayList<Address>(); { addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.TO))); addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.CC))); addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.BCC))); } message.setRecipients(RecipientType.BCC, null); HashMap<String, ArrayList<String>> charsetAddressesMap = new HashMap<String, ArrayList<String>>(); for (Address address : addresses) { String addressString = address.getAddress(); String charset = MimeUtility.getCharsetFromAddress(addressString); ArrayList<String> addressesOfCharset = charsetAddressesMap.get(charset); if (addressesOfCharset == null) { addressesOfCharset = new ArrayList<String>(); charsetAddressesMap.put(charset, addressesOfCharset); } addressesOfCharset.add(addressString); } for (Map.Entry<String, ArrayList<String>> charsetAddressesMapEntry : charsetAddressesMap.entrySet()) { String charset = charsetAddressesMapEntry.getKey(); ArrayList<String> addressesOfCharset = charsetAddressesMapEntry.getValue(); message.setCharset(charset); sendMessageTo(addressesOfCharset, message); } }
public Astar( long startId, long endId, DBHelper db, Map<Long, Node> nodes, LinkedList<Segment> segments, LinkedList<CostFunction> costs) { this.db = db; this.nodes = nodes; this.segments = segments; this.costs = costs; this.db.Connect(); this.fakeNodes.put(startId, new FakeNode(this.nodes.get(startId))); this.fakeNodes.put(endId, new FakeNode(this.nodes.get(endId))); this.startNode = this.fakeNodes.get(startId); this.endNode = this.fakeNodes.get(endId); this.startNode.g_scores = 0; ArrayList<Segment> fakeStart = createFalseSegments(startNode.node, true); ArrayList<Segment> fakeEnd = createFalseSegments(endNode.node, false); if (fakeStart != null) { fakeSegments.addAll(fakeStart); } if (fakeEnd != null) { fakeSegments.addAll(fakeEnd); } /*if(!fakeSegments.isEmpty()) { segments.addAll(fakeSegments); if(!fakeCosts.isEmpty()){ costs.addAll(fakeCosts); } }*/ }
public List<TokenHook> compile() throws InvalidOperationException { if (this.compiled) { throw new IllegalStateException("XMLEditableString already compiled"); } if (tokenMask != null) { for (int[] positions : this.tokenMask) { int startPosition = positions[0]; int length = positions[1]; TokenHook hook = new TokenHook(startPosition, length, TokenHook.TokenType.Word); hook.processedString = this.currentString.substring(startPosition, startPosition + length); this.tokens.add(hook); } } this.reverseChangeLog(); this.compiled = true; ArrayList<TokenHook> hooks = new ArrayList<>(this.tokens.size() + this.xml.size()); hooks.addAll(this.tokens); hooks.addAll(this.xml); Collections.sort(hooks, (t1, t2) -> t1.startIndex - t2.startIndex); return hooks; }
@NotNull public static Collection<PsiFileSystemItem> getAbsoluteTopLevelDirLocations( final @NotNull PsiFile file) { final VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile == null) { return Collections.emptyList(); } final Project project = file.getProject(); PsiDirectory parent = file.getParent(); final Module module = ModuleUtil.findModuleForPsiElement(parent == null ? file : parent); if (module == null) { return Collections.emptyList(); } final FileReferenceHelper[] helpers = FileReferenceHelperRegistrar.getHelpers(); final ArrayList<PsiFileSystemItem> list = new ArrayList<PsiFileSystemItem>(); for (FileReferenceHelper helper : helpers) { if (helper.isMine(project, virtualFile)) { final Collection<PsiFileSystemItem> roots = helper.getRoots(module); for (PsiFileSystemItem root : roots) { LOG.assertTrue(root != null, "Helper " + helper + " produced a null root for " + file); } list.addAll(roots); } } if (list.size() == 0) { list.addAll(FileReferenceHelperRegistrar.getNotNullHelper(file).getRoots(module)); } return list; }
@NotNull @Override public Collection<PsiReference> findReferences(final PsiElement element) { if (element instanceof GrField) { ArrayList<PsiReference> refs = new ArrayList<PsiReference>(); GrField field = (GrField) element; PsiMethod setter = GroovyPropertyUtils.findSetterForField(field); GlobalSearchScope projectScope = GlobalSearchScope.projectScope(element.getProject()); if (setter != null && setter instanceof GrAccessorMethod) { refs.addAll( RenameAliasedUsagesUtil.filterAliasedRefs( MethodReferencesSearch.search(setter, projectScope, true).findAll(), setter)); } GrAccessorMethod[] getters = field.getGetters(); for (GrAccessorMethod getter : getters) { refs.addAll( RenameAliasedUsagesUtil.filterAliasedRefs( MethodReferencesSearch.search(getter, projectScope, true).findAll(), getter)); } refs.addAll( RenameAliasedUsagesUtil.filterAliasedRefs( ReferencesSearch.search(field, projectScope, true).findAll(), field)); return refs; } return super.findReferences(element); }
public static void main(String args[]) { int N; Scanner in = new Scanner(System.in); N = in.nextInt(); int arr[] = new int[N]; ArrayList even = new ArrayList(); ArrayList odd = new ArrayList(); ArrayList list = new ArrayList(); for (int i = 0; i < N; i++) { arr[i] = in.nextInt(); } int evenSum = 0; int oddSum = 0; for (int i = 0; i < N; i++) { if (arr[i] % 2 == 0) { even.add(arr[i]); evenSum = evenSum + arr[i]; } else { odd.add(arr[i]); oddSum = oddSum + arr[i]; } } even.add(evenSum); odd.add(oddSum); Collections.sort(even); Collections.sort(odd); list.addAll(even); list.addAll(odd); Iterator itr = list.iterator(); while (itr.hasNext()) { System.out.println(itr.next()); } }
public static ArrayList<Integer> QSort(ArrayList<Integer> L) { Random r = new Random(); if (L.size() <= 1) { return L; } else { int pivot = r.nextInt(L.size()); ArrayList<Integer> lower = new ArrayList(pivot); // holds indices 0--> one before pivot ArrayList<Integer> upper = new ArrayList( L.size() - pivot); // holds pivot --> end. basically string slicing in python int pivotInt = L.get(pivot); for (int i = 0; i < L.size(); i++) { if (i != pivot) { // dont put pivot back into list if (L.get(i) < pivotInt) { lower.add(L.get(i)); } else { upper.add(L.get(i)); } } } lower = QSort(lower); upper = QSort(upper); // System.out.println(lower); // System.out.println(upper); ArrayList<Integer> ans = new ArrayList<Integer>(); ans.addAll(lower); ans.add(pivotInt); ans.addAll(upper); // builtin way to concatenate arraylists. return ans; } }
private void attachOrphanRoadsToNearestPath(List<Path> paths) { findOrphanRoads(); ArrayList<Road> orRoads = new ArrayList<Road>(); orRoads.addAll(orphanRoads); while (!orphanRoads.isEmpty()) { for (Road road : orRoads) { boolean isAdded = false; for (Road connectedRoad : roadHelper.getConnectedRoads(road.getID())) { EntityID rPathId = roadHelper.getPathId(connectedRoad.getID()); if (rPathId != null) { isAdded = true; addToPath(road, rPathId, paths); orphanRoads.remove(road); break; } } if (!isAdded) { Path nearestPath = getNearestPath(road, paths); if (nearestPath != null) { adding(road, nearestPath); orphanRoads.remove(road); } } } if (orphanRoads.size() == orRoads.size()) break; orRoads.clear(); orRoads.addAll(orphanRoads); } }
/** * Creates a java process that executes the given main class and waits for the process to * terminate. * * @return a {@link ProcessOutputReader} that can be used to get the exit code and stdout+stderr * of the terminated process. */ public static ProcessOutputReader fg(Class main, String[] vmArgs, String[] mainArgs) throws IOException { File javabindir = new File(System.getProperty("java.home"), "bin"); File javaexe = new File(javabindir, "java"); int bits = Integer.getInteger("sun.arch.data.model", 0).intValue(); String vmKindArg = (bits == 64) ? "-d64" : null; ArrayList argList = new ArrayList(); argList.add(javaexe.getPath()); if (vmKindArg != null) { argList.add(vmKindArg); } // argList.add("-Dgemfire.systemDirectory=" + // GemFireConnectionFactory.getDefaultSystemDirectory()); argList.add("-Djava.class.path=" + System.getProperty("java.class.path")); argList.add("-Djava.library.path=" + System.getProperty("java.library.path")); if (vmArgs != null) { argList.addAll(Arrays.asList(vmArgs)); } argList.add(main.getName()); if (mainArgs != null) { argList.addAll(Arrays.asList(mainArgs)); } String[] cmd = (String[]) argList.toArray(new String[argList.size()]); return new ProcessOutputReader(Runtime.getRuntime().exec(cmd)); }
/** * Return certificates for signed bundle, otherwise null. * * @return An array of certificates or null. */ public ArrayList getCertificateChains(boolean onlyTrusted) { if (checkCerts) { Certificate[] c = archive.getCertificates(); checkCerts = false; if (c != null) { ArrayList failed = new ArrayList(); untrustedCerts = Util.getCertificateChains(c, failed); if (!failed.isEmpty()) { // NYI, log Bundle archive has invalid certificates untrustedCerts = null; } } } ArrayList res = trustedCerts; if (!onlyTrusted && untrustedCerts != null) { if (res == null) { res = untrustedCerts; } else { res = new ArrayList(trustedCerts.size() + untrustedCerts.size()); res.addAll(trustedCerts); res.addAll(untrustedCerts); } } return res; }
protected synchronized String getProcedureName(Connection dConn, Connection gConn) { /// avoid #42569 ResultSet rs = null; try { rs = gConn.getMetaData().getProcedures(null, null, null); List procNames = ResultSetHelper.asList(rs, false); Log.getLogWriter().info("procedure names are " + ResultSetHelper.listToString(procNames)); rs.close(); } catch (SQLException se) { SQLHelper.handleSQLException(se); } try { rs = gConn.getMetaData().getFunctions(null, null, null); } catch (SQLException se) { SQLHelper.handleSQLException(se); } List funcNames = ResultSetHelper.asList(rs, false); Log.getLogWriter().info("function names are " + ResultSetHelper.listToString(funcNames)); if (procedureNames == null) { ArrayList<String> procs = new ArrayList<String>(); procs.addAll(ProcedureDDLStmt.modifyProcNameList); procs.addAll(ProcedureDDLStmt.nonModifyProcNameList); procedureNames = new ArrayList<String>(procs); } return procedureNames.get(SQLTest.random.nextInt(procedureNames.size())); }
// Generates a new polygon by dragging a polygon by a vector and taking all the points it // touched. public static Polygon stroke(double x, double y, Polygon poly) { Polygon polyTrans = mul(Mat.translation(x, y), poly); ArrayList<Mat> vertices = new ArrayList<Mat>(); ArrayList<TreeSet<Integer>> edgesTo = new ArrayList<TreeSet<Integer>>(); int size = poly.vertices.size(); // The list of possible vertices of the extrusion vertices.addAll(poly.vertices); vertices.addAll(polyTrans.vertices); // pre-compute some information that will make it easy to find the actual perimeter of the // extrusion for (int i = 0; i < 2 * size; i++) { edgesTo.add(new TreeSet<Integer>()); } for (int i = 0; i < size; i++) { edgesTo.get(i).add(new Integer((i + 1) % size)); edgesTo.get((i + 1) % size).add(new Integer(i)); edgesTo.get(i + size).add(new Integer(((i + 1) % size) + size)); edgesTo.get(((i + 1) % size) + size).add(new Integer(i + size)); edgesTo.get(i).add(new Integer(i + size)); edgesTo.get(i + size).add(new Integer(i)); } return perimeter(vertices, edgesTo); }
@Override public void writeExternal(Element rootElement) throws WriteExternalException { LOG.assertTrue(!isDisposed(), "Already disposed!"); Element element = new Element(ELEMENT); if (myName != null) { element.setAttribute(LIBRARY_NAME_ATTR, myName); } if (myKind != null) { element.setAttribute(LIBRARY_TYPE_ATTR, myKind.getKindId()); final Object state = myProperties.getState(); if (state != null) { final Element propertiesElement = XmlSerializer.serialize(state, SERIALIZATION_FILTERS); if (propertiesElement != null && (!propertiesElement.getContent().isEmpty() || !propertiesElement.getAttributes().isEmpty())) { element.addContent(propertiesElement.setName(PROPERTIES_ELEMENT)); } } } ArrayList<OrderRootType> storableRootTypes = new ArrayList<OrderRootType>(); storableRootTypes.addAll(Arrays.asList(OrderRootType.getAllTypes())); if (myKind != null) { storableRootTypes.addAll(Arrays.asList(myKind.getAdditionalRootTypes())); } for (OrderRootType rootType : sortRootTypes(storableRootTypes)) { final VirtualFilePointerContainer roots = myRoots.get(rootType); if (roots.size() == 0 && rootType.skipWriteIfEmpty()) continue; // compatibility iml/ipr final Element rootTypeElement = new Element(rootType.name()); roots.writeExternal(rootTypeElement, ROOT_PATH_ELEMENT); element.addContent(rootTypeElement); } myJarDirectories.writeExternal(element); rootElement.addContent(element); }
/* Scan the files in the new directory, and store them in the filelist. * Update the UI by refreshing the list adapter. */ private void loadDirectory(String newdirectory) { if (newdirectory.equals("../")) { try { directory = new File(directory).getParent(); } catch (Exception e) { } } else { directory = newdirectory; } SharedPreferences.Editor editor = getPreferences(0).edit(); editor.putString("lastBrowsedDirectory", directory); editor.commit(); directoryView.setText(directory); filelist = new ArrayList<FileUri>(); ArrayList<FileUri> sortedDirs = new ArrayList<FileUri>(); ArrayList<FileUri> sortedFiles = new ArrayList<FileUri>(); if (!newdirectory.equals(rootdir)) { String parentDirectory = new File(directory).getParent() + "/"; Uri uri = Uri.parse("file://" + parentDirectory); sortedDirs.add(new FileUri(uri, parentDirectory)); } try { File dir = new File(directory); File[] files = dir.listFiles(); if (files != null) { for (File file : files) { if (file == null) { continue; } String filename = file.getName(); if (file.isDirectory()) { Uri uri = Uri.parse("file://" + file.getAbsolutePath() + "/"); FileUri fileuri = new FileUri(uri, uri.getPath()); sortedDirs.add(fileuri); } else if (filename.endsWith(".mid") || filename.endsWith(".MID") || filename.endsWith(".midi") || filename.endsWith(".MIDI")) { Uri uri = Uri.parse("file://" + file.getAbsolutePath()); FileUri fileuri = new FileUri(uri, uri.getLastPathSegment()); sortedFiles.add(fileuri); } } } } catch (Exception e) { } if (sortedDirs.size() > 0) { Collections.sort(sortedDirs, sortedDirs.get(0)); } if (sortedFiles.size() > 0) { Collections.sort(sortedFiles, sortedFiles.get(0)); } filelist.addAll(sortedDirs); filelist.addAll(sortedFiles); adapter = new IconArrayAdapter<FileUri>(this, android.R.layout.simple_list_item_1, filelist); this.setListAdapter(adapter); }
/** The union of an OclSet and an OclBag is an OclBag. */ public OclBag union(OclBag bag) { if (isUndefined()) return new OclBag(0, getUndefinedReason()); if (bag.isUndefined()) return bag; ArrayList list = new ArrayList(collection.size() + bag.collection.size()); list.addAll(collection); list.addAll(bag.collection); return new OclBag(list); }
public void buildPopulationBox() { rebuilding = true; populationBox.removeAll(); peopleList = new ArrayList<Object>(); famList = new ArrayList<Family>(); peopleList.addAll(ctxt.individualCensus); String plur = (peopleList.size() == 1 ? "" : "s"); populationBox.setLayout(new BoxLayout(populationBox, BoxLayout.PAGE_AXIS)); populationBox.setBorder( BorderFactory.createTitledBorder( BorderFactory.createLineBorder(Color.blue), "Current Population")); populationBox.setAlignmentX(0.5f); populationBox.add(Box.createRigidArea(new Dimension(8, 0))); indivLabel = new JLabel("Contains " + peopleList.size() + " Individual" + plur); indivLabel.setAlignmentX(0.5f); populationBox.add(indivLabel); if (peopleList.size() > 0) { JPanel indivBtnBox = new JPanel(); indivBtnBox.setLayout(new BoxLayout(indivBtnBox, BoxLayout.LINE_AXIS)); Dimension sizer2 = new Dimension(350, 50); String[] indMenu = genIndMenu(peopleList); indPick = new JComboBox(indMenu); indPick.addActionListener(listener); indPick.setActionCommand("view/edit person"); indPick.setMinimumSize(sizer2); indPick.setMaximumSize(sizer2); indPick.setBorder( BorderFactory.createTitledBorder( BorderFactory.createLineBorder(Color.blue), "View/Edit Person")); indivBtnBox.add(indPick); populationBox.add(indivBtnBox); } // end of if-any-people-exist famList.addAll(ctxt.familyCensus); // end of filtering deleted records plur = (famList.size() == 1 ? "y" : "ies"); famLabel = new JLabel("Contains " + famList.size() + " Famil" + plur); famLabel.setAlignmentX(0.5f); populationBox.add(Box.createRigidArea(new Dimension(0, 4))); populationBox.add(famLabel); if (famList.size() > 0) { JPanel famBtnBox = new JPanel(); famBtnBox.setLayout(new BoxLayout(famBtnBox, BoxLayout.LINE_AXIS)); Dimension sizer2 = new Dimension(350, 50); String[] famMenu = genFamMenu(famList); famPick = new JComboBox(famMenu); famPick.addActionListener(listener); famPick.setActionCommand("view/edit family"); famPick.setMinimumSize(sizer2); famPick.setMaximumSize(sizer2); famPick.setBorder( BorderFactory.createTitledBorder( BorderFactory.createLineBorder(Color.blue), "View/Edit Family")); famBtnBox.add(famPick); populationBox.add(famBtnBox); } // end of if-any-families-exist rebuilding = false; } // end of method buildPopulationBox
public void putAll(K key, Collection<O> values) { ArrayList<O> recs = hashtable.get(key); if (recs == null) { recs = new ArrayList<O>(listInitialCapacity == -1 ? 1 : listInitialCapacity); recs.addAll(values); hashtable.put(key, recs); } else { recs.addAll(values); } }
/** * Returns an iterator over active and initializing shards. Making sure though that its random * within the active shards, and initializing shards are the last to iterate through. */ public ShardIterator activeInitializingShardsIt(int seed) { if (allInitializingShards.isEmpty()) { return new PlainShardIterator(shardId, shuffler.shuffle(activeShards, seed)); } ArrayList<ShardRouting> ordered = new ArrayList<>(activeShards.size() + allInitializingShards.size()); ordered.addAll(shuffler.shuffle(activeShards, seed)); ordered.addAll(allInitializingShards); return new PlainShardIterator(shardId, ordered); }
static ArrayList<BSA> getBSAs() { loadResourceLoadOrder(); loadPluginLoadOrder(); deleteOverlap(); ArrayList<BSA> order = new ArrayList<>(resourceLoadOrder.size() + pluginLoadOrder.size()); order.addAll(resourceLoadOrder); order.addAll(pluginLoadOrder.values()); return order; }
/* Recursive, returns an array list * containing this node and all child nodes */ public ArrayList<avPair> enumeratePairs() { ArrayList<avPair> myAV = new ArrayList<avPair>(); if (leaf) { myAV.add(this); return myAV; } else { myAV.add(this); myAV.addAll(leftChild.enumeratePairs()); myAV.addAll(rightChild.enumeratePairs()); return myAV; } }
/** * getEquippedEnchantedCreatures. * * @param cards a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object. */ public static ArrayList<Card> getEquippedEnchantedCreatures(ArrayList<Card> cards) { ArrayList<Card> ret = new ArrayList<Card>(); for (Card c : cards) { if (c.isCreature() && (c.isEquipped() || c.isEnchanted())) { if (c.isEquipped()) ret.addAll(c.getEquippedBy()); if (c.isEnchanted()) ret.addAll(c.getEnchantedBy()); ret.add(c); } } return ret; }
public ArrayList<Integer> preorderTraversal_Recur(TreeNode root) { ArrayList<Integer> result = new ArrayList<Integer>(); if (root != null) { result.add(root.val); if (root.left != null) { result.addAll(preorderTraversal_Recur(root.left)); } if (root.right != null) { result.addAll(preorderTraversal_Recur(root.right)); } } return result; }
public List<Integer> inorderTraversal(TreeNode root) { ArrayList<Integer> answer = new ArrayList<>(); if (root == null) { return answer; } if (root.left != null) { answer.addAll(inorderTraversal(root.left)); } answer.add(root.val); if (root.right != null) { answer.addAll(inorderTraversal(root.right)); } return answer; }
/** * @param root: The root of binary tree. * @return: Preorder in ArrayList which contains node values. */ public ArrayList<Integer> preorderTraversal(TreeNode root) { // write your code here ArrayList<Integer> preoder = new ArrayList<Integer>(); if (root == null) { return preoder; } preoder.add(root.val); preoder.addAll(preorderTraversal(root.left)); preoder.addAll(preorderTraversal(root.right)); return preoder; }
public static boolean callCheat(ArrayList<Card> caller) { // If the last person cheated if (lastPlayerCheated) { // gives the person who cheated the card lastPlayerHand.addAll(pile); pile.clear(); return true; } else { // If the last person did not cheat // Gives the cards to the caller caller.addAll(pile); pile.clear(); return false; } }
public static SafeDeleteProcessor createInstance( Project project, @Nullable Runnable prepareSuccessfulCallBack, PsiElement[] elementsToDelete, boolean isSearchInComments, boolean isSearchNonJava, boolean askForAccessors) { ArrayList<PsiElement> elements = new ArrayList<PsiElement>(Arrays.asList(elementsToDelete)); HashSet<PsiElement> elementsToDeleteSet = new HashSet<PsiElement>(Arrays.asList(elementsToDelete)); for (PsiElement psiElement : elementsToDelete) { for (SafeDeleteProcessorDelegate delegate : Extensions.getExtensions(SafeDeleteProcessorDelegate.EP_NAME)) { if (delegate.handlesElement(psiElement)) { Collection<PsiElement> addedElements = delegate.getAdditionalElementsToDelete( psiElement, elementsToDeleteSet, askForAccessors); if (addedElements != null) { elements.addAll(addedElements); } break; } } } return new SafeDeleteProcessor( project, prepareSuccessfulCallBack, PsiUtilCore.toPsiElementArray(elements), isSearchInComments, isSearchNonJava); }
private String[] splitAndRemoveEmpty(String[] sts, String splitSeparator) { ArrayList<String> result = new ArrayList<String>(); for (String st : sts) { result.addAll(Arrays.asList(splitAndRemoveEmpty(st, splitSeparator))); } return result.toArray(new String[result.size()]); }
@NotNull public UsageInfo[] findUsages() { myRenamers.clear(); ArrayList<UsageInfo> result = new ArrayList<UsageInfo>(); List<PsiElement> elements = new ArrayList<PsiElement>(myAllRenames.keySet()); //noinspection ForLoopReplaceableByForEach for (int i = 0; i < elements.size(); i++) { PsiElement element = elements.get(i); final String newName = myAllRenames.get(element); final UsageInfo[] usages = RenameUtil.findUsages( element, newName, mySearchInComments, mySearchTextOccurrences, myAllRenames); final List<UsageInfo> usagesList = Arrays.asList(usages); result.addAll(usagesList); for (AutomaticRenamerFactory factory : myRenamerFactories) { if (factory.isApplicable(element)) { myRenamers.add(factory.createRenamer(element, newName, usagesList)); } } for (AutomaticRenamerFactory factory : Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) { if (factory.getOptionName() == null && factory.isApplicable(element)) { myRenamers.add(factory.createRenamer(element, newName, usagesList)); } } } UsageInfo[] usageInfos = result.toArray(new UsageInfo[result.size()]); usageInfos = UsageViewUtil.removeDuplicatedUsages(usageInfos); return usageInfos; }
private static List<XmlElementDescriptor> computeRequiredSubTags(XmlElementsGroup group) { if (group.getMinOccurs() < 1) return Collections.emptyList(); switch (group.getGroupType()) { case LEAF: XmlElementDescriptor descriptor = group.getLeafDescriptor(); return descriptor == null ? Collections.<XmlElementDescriptor>emptyList() : Collections.singletonList(descriptor); case CHOICE: LinkedHashSet<XmlElementDescriptor> set = null; for (XmlElementsGroup subGroup : group.getSubGroups()) { List<XmlElementDescriptor> descriptors = computeRequiredSubTags(subGroup); if (set == null) { set = new LinkedHashSet<XmlElementDescriptor>(descriptors); } else { set.retainAll(descriptors); } } if (set == null || set.isEmpty()) { return Collections.singletonList(null); // placeholder for smart completion } return new ArrayList<XmlElementDescriptor>(set); default: ArrayList<XmlElementDescriptor> list = new ArrayList<XmlElementDescriptor>(); for (XmlElementsGroup subGroup : group.getSubGroups()) { list.addAll(computeRequiredSubTags(subGroup)); } return list; } }