java.util.Collectionsjava.util.ArrayList



Project robovm/robovm in file ...a.org.robovm.compiler.target.LaunchParameters.java (2014-10-17)
@@ -17,16 +17,14 @@
 package org.robovm.compiler.target;
 
 import java.io.File;
-import java.util.Collections;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
 /**
- * @author niklas
- *
  */
 public class LaunchParameters {
-    private List<String> arguments = Collections.emptyList();
+    private List<String> arguments = new ArrayList<>();
     private Map<String, String> environment = null;
     private File workingDirectory = new File(".");
     private File stdoutFifo = null;
Project JetBrains/intellij-community in file ...src.com.intellij.lang.xml.XmlUnwrapDescriptor.java (2011-03-25)
@@ -25,15 +25,15 @@ import com.intellij.openapi.util.Pair;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiFile;
 import com.intellij.psi.util.PsiTreeUtil;
+import com.intellij.psi.xml.XmlChildRole;
 import com.intellij.psi.xml.XmlTag;
-import com.intellij.util.SmartList;
 
-import java.util.Collections;
+import java.util.ArrayList;
 import java.util.List;
 
 public class XmlUnwrapDescriptor implements UnwrapDescriptor {
   public List<Pair<PsiElement, Unwrapper>> collectUnwrappers(Project project, Editor editor, PsiFile file) {
-    List<Pair<PsiElement, Unwrapper>> result = new SmartList<Pair<PsiElement, Unwrapper>>();
+    List<Pair<PsiElement, Unwrapper>> result = new ArrayList<Pair<PsiElement, Unwrapper>>();
 
     int offset = editor.getCaretModel().getOffset();
     PsiElement e1 = file.findElementAt(offset);
@@ -49,7 +49,9 @@ public class XmlUnwrapDescriptor implements UnwrapDescriptor {
 
     PsiElement tag = PsiTreeUtil.getParentOfType(e1, XmlTag.class);
     while (tag != null) {
-      result.add(new Pair<PsiElement, Unwrapper>(tag, new XmlEnclosingTagUnwrapper()));
+      if (XmlChildRole.START_TAG_END_FINDER.findChild(tag.getNode()) != null) { // Exclude implicit tags suck as 'jsp:root'
+        result.add(new Pair<PsiElement, Unwrapper>(tag, new XmlEnclosingTagUnwrapper()));
+      }
       tag = PsiTreeUtil.getParentOfType(tag, XmlTag.class);
     }
 
Project JetBrains/intellij-community in file ...ea.src.git4idea.repo.GitFakeRepositoryManager.java (2012-11-27)
@@ -20,16 +20,27 @@ import com.intellij.openapi.vfs.VirtualFile;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.Collections;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
  * @author Kirill Likhodedov
  */
 public class GitFakeRepositoryManager implements GitRepositoryManager {
-  @Nullable
+
+  private final List<GitRepository> myRepositories = new ArrayList<GitRepository>();
+
+  public void add(GitRepository repository) {
+    myRepositories.add(repository);
+  }
+
   @Override
   public GitRepository getRepositoryForRoot(@Nullable VirtualFile root) {
+    for (GitRepository repository : myRepositories) {
+      if (repository.getRoot().equals(root)) {
+        return repository;
+      }
+    }
     return null;
   }
 
@@ -47,12 +58,12 @@ public class GitFakeRepositoryManager implements GitRepositoryManager {
   @NotNull
   @Override
   public List<GitRepository> getRepositories() {
-    return Collections.emptyList();
+    return new ArrayList<GitRepository>(myRepositories);
   }
 
   @Override
   public boolean moreThanOneRoot() {
-    return false;
+    return myRepositories.size() > 1;
   }
 
   @Override
Project SonarSource/sonarqube in file ...nar.duplications.internal.pmd.PmdBlockChunker.java (2014-07-25)
@@ -23,7 +23,7 @@ import com.google.common.collect.Lists;
 import org.sonar.duplications.block.Block;
 import org.sonar.duplications.block.ByteArray;
 
-import java.util.Collections;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -48,7 +48,10 @@ public class PmdBlockChunker {
     this.power = pow;
   }
 
-  public List<Block> chunk(String resourceId, List<TokensLine> fragments) {
+  /**
+   * @return ArrayList as we need a serializable object
+   */
+  public ArrayList<Block> chunk(String resourceId, List<TokensLine> fragments) {
     List<TokensLine> filtered = Lists.newArrayList();
     int i = 0;
     while (i < fragments.size()) {
@@ -66,10 +69,10 @@ public class PmdBlockChunker {
     fragments = filtered;
 
     if (fragments.size() < blockSize) {
-      return Collections.emptyList();
+      return Lists.newArrayList();
     }
     TokensLine[] fragmentsArr = fragments.toArray(new TokensLine[fragments.size()]);
-    List<Block> blocks = Lists.newArrayListWithCapacity(fragmentsArr.length - blockSize + 1);
+    ArrayList<Block> blocks = Lists.newArrayListWithCapacity(fragmentsArr.length - blockSize + 1);
     long hash = 0;
     int first = 0;
     int last = 0;
@@ -84,11 +87,11 @@ public class PmdBlockChunker {
       hash = hash * PRIME_BASE + lastFragment.getHashCode();
       // create block
       Block block = blockBuilder
-          .setBlockHash(new ByteArray(hash))
-          .setIndexInFile(first)
-          .setLines(firstFragment.getStartLine(), lastFragment.getEndLine())
-          .setUnit(firstFragment.getStartUnit(), lastFragment.getEndUnit())
-          .build();
+        .setBlockHash(new ByteArray(hash))
+        .setIndexInFile(first)
+        .setLines(firstFragment.getStartLine(), lastFragment.getEndLine())
+        .setUnit(firstFragment.getStartUnit(), lastFragment.getEndUnit())
+        .build();
       blocks.add(block);
       // remove first statement from hash
       hash -= power * firstFragment.getHashCode();
Project android/platform_frameworks_base in file ...java.android.telecomm.RemoteConnectionService.java (2014-08-23)
@@ -28,11 +28,11 @@ import com.android.internal.telecomm.IConnectionServiceAdapter;
 import com.android.internal.telecomm.IVideoProvider;
 import com.android.internal.telecomm.RemoteServiceCallback;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
-import java.util.Collections;
 import java.util.List;
 import java.util.UUID;
 
@@ -43,8 +43,11 @@ import java.util.UUID;
  */
 final class RemoteConnectionService {
 
-    private static final RemoteConnection
-            NULL_CONNECTION = new RemoteConnection("NULL", null, null);
+    private static final RemoteConnection NULL_CONNECTION =
+            new RemoteConnection("NULL", null, null);
+
+    private static final RemoteConference NULL_CONFERENCE =
+            new RemoteConference("NULL", null);
 
     private final IConnectionServiceAdapter mServantDelegate = new IConnectionServiceAdapter() {
         @Override
@@ -64,6 +67,13 @@ final class RemoteConnectionService {
                 connection.setCallerDisplayName(
                         parcel.getCallerDisplayName(),
                         parcel.getCallerDisplayNamePresentation());
+                List<RemoteConnection> conferenceable = new ArrayList<>();
+                for (String confId : parcel.getConferenceableConnectionIds()) {
+                    if (mConnectionById.containsKey(confId)) {
+                        conferenceable.add(mConnectionById.get(confId));
+                    }
+                }
+                connection.setConferenceableConnections(conferenceable);
                 // TODO: Do we need to support video providers for remote connections?
                 if (connection.getState() == Connection.STATE_DISCONNECTED) {
                     // ... then, if it was created in a disconnected state, that indicates
@@ -75,8 +85,13 @@ final class RemoteConnectionService {
 
         @Override
         public void setActive(String callId) {
-            findConnectionForAction(callId, "setActive")
-                    .setState(Connection.STATE_ACTIVE);
+            if (mConnectionById.containsKey(callId)) {
+                findConnectionForAction(callId, "setActive")
+                        .setState(Connection.STATE_ACTIVE);
+            } else {
+                findConferenceForAction(callId, "setActive")
+                        .setState(Connection.STATE_ACTIVE);
+            }
         }
 
         @Override
@@ -94,14 +109,24 @@ final class RemoteConnectionService {
         @Override
         public void setDisconnected(String callId, int disconnectCause,
                 String disconnectMessage) {
-            findConnectionForAction(callId, "setDisconnected")
-                    .setDisconnected(disconnectCause, disconnectMessage);
+            if (mConnectionById.containsKey(callId)) {
+                findConnectionForAction(callId, "setDisconnected")
+                        .setDisconnected(disconnectCause, disconnectMessage);
+            } else {
+                findConferenceForAction(callId, "setDisconnected")
+                        .setDisconnected(disconnectCause, disconnectMessage);
+            }
         }
 
         @Override
         public void setOnHold(String callId) {
-            findConnectionForAction(callId, "setOnHold")
-                    .setState(Connection.STATE_HOLDING);
+            if (mConnectionById.containsKey(callId)) {
+                findConnectionForAction(callId, "setOnHold")
+                        .setState(Connection.STATE_HOLDING);
+            } else {
+                findConferenceForAction(callId, "setOnHold")
+                        .setState(Connection.STATE_HOLDING);
+            }
         }
 
         @Override
@@ -112,24 +137,80 @@ final class RemoteConnectionService {
 
         @Override
         public void setCallCapabilities(String callId, int callCapabilities) {
-            findConnectionForAction("callId", "setCallCapabilities")
-                    .setCallCapabilities(callCapabilities);
+            if (mConnectionById.containsKey(callId)) {
+                findConnectionForAction(callId, "setCallCapabilities")
+                        .setCallCapabilities(callCapabilities);
+            } else {
+                findConferenceForAction(callId, "setCallCapabilities")
+                        .setCallCapabilities(callCapabilities);
+            }
         }
 
         @Override
         public void setIsConferenced(String callId, String conferenceCallId) {
-            // not supported for remote connections.
+            // Note: callId should not be null; conferenceCallId may be null
+            RemoteConnection connection =
+                    findConnectionForAction(callId, "setIsConferenced");
+            if (connection != NULL_CONNECTION) {
+                if (conferenceCallId == null) {
+                    // 'connection' is being split from its conference
+                    if (connection.getConference() != null) {
+                        connection.getConference().removeConnection(connection);
+                    }
+                } else {
+                    RemoteConference conference =
+                            findConferenceForAction(conferenceCallId, "setIsConferenced");
+                    if (conference != NULL_CONFERENCE) {
+                        conference.addConnection(connection);
+                    }
+                }
+            }
         }
 
         @Override
-        public void addConferenceCall(String callId, ParcelableConference parcelableConference) {
-            // not supported for remote connections.
+        public void addConferenceCall(
+                final String callId,
+                ParcelableConference parcel) {
+            RemoteConference conference = new RemoteConference(callId,
+                    mOutgoingConnectionServiceRpc);
+
+            for (String id : parcel.getConnectionIds()) {
+                RemoteConnection c = mConnectionById.get(id);
+                if (c != null) {
+                    conference.addConnection(c);
+                }
+            }
+
+            if (conference.getConnections().size() == 0) {
+                // A conference was created, but none of its connections are ones that have been
+                // created by, and therefore being tracked by, this remote connection service. It
+                // is of no interest to us.
+                return;
+            }
+
+            conference.setState(parcel.getState());
+            conference.setCallCapabilities(parcel.getCapabilities());
+            mConferenceById.put(callId, conference);
+            conference.addListener(new RemoteConference.Listener() {
+                @Override
+                public void onDestroyed(RemoteConference c) {
+                    mConferenceById.remove(callId);
+                    maybeDisconnectAdapter();
+                }
+            });
+
+            mOurConnectionServiceImpl.addRemoteConference(conference);
         }
 
         @Override
         public void removeCall(String callId) {
-            findConnectionForAction(callId, "removeCall")
-                    .setDestroyed();
+            if (mConnectionById.containsKey(callId)) {
+                findConnectionForAction(callId, "removeCall")
+                        .setDestroyed();
+            } else {
+                findConferenceForAction(callId, "removeCall")
+                        .setDestroyed();
+            }
         }
 
         @Override
@@ -193,13 +274,15 @@ final class RemoteConnectionService {
         @Override
         public final void setConferenceableConnections(
                 String callId, List<String> conferenceableConnectionIds) {
+            List<RemoteConnection> conferenceable = new ArrayList<>();
+            for (String id : conferenceableConnectionIds) {
+                if (mConnectionById.containsKey(id)) {
+                    conferenceable.add(mConnectionById.get(id));
+                }
+            }
 
-            // TODO: When we support more than 1 remote connection, this should
-            // loop through the incoming list of connection IDs and acquire the list
-            // of remote connections which correspond to the IDs. That list should
-            // be set onto the remote connections.
             findConnectionForAction(callId, "setConferenceableConnections")
-                    .setConferenceableConnections(Collections.<RemoteConnection>emptyList());
+                    .setConferenceableConnections(conferenceable);
         }
     };
 
@@ -212,24 +295,33 @@ final class RemoteConnectionService {
             for (RemoteConnection c : mConnectionById.values()) {
                 c.setDestroyed();
             }
+            for (RemoteConference c : mConferenceById.values()) {
+                c.setDestroyed();
+            }
             mConnectionById.clear();
+            mConferenceById.clear();
             mPendingConnections.clear();
-            mConnectionService.asBinder().unlinkToDeath(mDeathRecipient, 0);
+            mOutgoingConnectionServiceRpc.asBinder().unlinkToDeath(mDeathRecipient, 0);
         }
     };
 
-    private final IConnectionService mConnectionService;
+    private final IConnectionService mOutgoingConnectionServiceRpc;
+    private final ConnectionService mOurConnectionServiceImpl;
     private final Map<String, RemoteConnection> mConnectionById = new HashMap<>();
+    private final Map<String, RemoteConference> mConferenceById = new HashMap<>();
     private final Set<RemoteConnection> mPendingConnections = new HashSet<>();
 
-    RemoteConnectionService(IConnectionService connectionService) throws RemoteException {
-        mConnectionService = connectionService;
-        mConnectionService.asBinder().linkToDeath(mDeathRecipient, 0);
+    RemoteConnectionService(
+            IConnectionService outgoingConnectionServiceRpc,
+            ConnectionService ourConnectionServiceImpl) throws RemoteException {
+        mOutgoingConnectionServiceRpc = outgoingConnectionServiceRpc;
+        mOutgoingConnectionServiceRpc.asBinder().linkToDeath(mDeathRecipient, 0);
+        mOurConnectionServiceImpl = ourConnectionServiceImpl;
     }
 
     @Override
     public String toString() {
-        return "[RemoteCS - " + mConnectionService.asBinder().toString() + "]";
+        return "[RemoteCS - " + mOutgoingConnectionServiceRpc.asBinder().toString() + "]";
     }
 
     final RemoteConnection createRemoteConnection(
@@ -245,13 +337,13 @@ final class RemoteConnectionService {
                 request.getVideoState());
         try {
             if (mConnectionById.isEmpty()) {
-                mConnectionService.addConnectionServiceAdapter(mServant.getStub());
+                mOutgoingConnectionServiceRpc.addConnectionServiceAdapter(mServant.getStub());
             }
             RemoteConnection connection =
-                    new RemoteConnection(id, mConnectionService, newRequest);
+                    new RemoteConnection(id, mOutgoingConnectionServiceRpc, newRequest);
             mPendingConnections.add(connection);
             mConnectionById.put(id, connection);
-            mConnectionService.createConnection(
+            mOutgoingConnectionServiceRpc.createConnection(
                     connectionManagerPhoneAccount,
                     id,
                     newRequest,
@@ -260,12 +352,7 @@ final class RemoteConnectionService {
                 @Override
                 public void onDestroyed(RemoteConnection connection) {
                     mConnectionById.remove(id);
-                    if (mConnectionById.isEmpty()) {
-                        try {
-                            mConnectionService.removeConnectionServiceAdapter(mServant.getStub());
-                        } catch (RemoteException e) {
-                        }
-                    }
+                    maybeDisconnectAdapter();
                 }
             });
             return connection;
@@ -283,4 +370,22 @@ final class RemoteConnectionService {
         Log.w(this, "%s - Cannot find Connection %s", action, callId);
         return NULL_CONNECTION;
     }
+
+    private RemoteConference findConferenceForAction(
+            String callId, String action) {
+        if (mConferenceById.containsKey(callId)) {
+            return mConferenceById.get(callId);
+        }
+        Log.w(this, "%s - Cannot find Conference %s", action, callId);
+        return NULL_CONFERENCE;
+    }
+
+    private void maybeDisconnectAdapter() {
+        if (mConnectionById.isEmpty() && mConferenceById.isEmpty()) {
+            try {
+                mOutgoingConnectionServiceRpc.removeConnectionServiceAdapter(mServant.getStub());
+            } catch (RemoteException e) {
+            }
+        }
+    }
 }