org.usergrid.mq.QueueSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of usergrid-core Show documentation
Show all versions of usergrid-core Show documentation
Core services for Usergrid system.
/*******************************************************************************
* Copyright 2012 Apigee Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.usergrid.mq;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import javax.xml.bind.annotation.XmlRootElement;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
@XmlRootElement
public class QueueSet {
List queues = new ArrayList();
boolean more;
public QueueSet() {
}
public List getQueues() {
return queues;
}
public void setQueues(List queues) {
if (queues == null) {
queues = new ArrayList();
}
this.queues = queues;
}
public QueueSet addQueue(String queuePath, UUID queueId) {
QueueInfo queue = new QueueInfo(queuePath, queueId);
queues.add(queue);
return this;
}
public boolean isMore() {
return more;
}
public void setMore(boolean more) {
this.more = more;
}
public boolean hasMore() {
return more;
}
public int size() {
return queues.size();
}
@XmlRootElement
public static class QueueInfo {
String path;
UUID uuid;
public QueueInfo() {
}
public QueueInfo(String path, UUID uuid) {
this.path = path;
this.uuid = uuid;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + ((path == null) ? 0 : path.hashCode());
result = (prime * result) + ((uuid == null) ? 0 : uuid.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
QueueInfo other = (QueueInfo) obj;
if (path == null) {
if (other.path != null) {
return false;
}
} else if (!path.equals(other.path)) {
return false;
}
if (uuid == null) {
if (other.uuid != null) {
return false;
}
} else if (!uuid.equals(other.uuid)) {
return false;
}
return true;
}
@Override
public String toString() {
return "QueueInfo [path=" + path + ", uuid=" + uuid + "]";
}
}
public void setCursorToLastResult() {
// TODO Auto-generated method stub
}
@JsonSerialize(include = Inclusion.NON_NULL)
public Object getCursor() {
// TODO Auto-generated method stub
return null;
}
public void and(QueueSet r) {
Set oldSet = new HashSet(queues);
List newList = new ArrayList();
for (QueueInfo q : r.getQueues()) {
if (oldSet.contains(q)) {
newList.add(q);
}
}
queues = newList;
}
}