本文整理了Java中java.util.HashSet.clone()
方法的一些代码示例,展示了HashSet.clone()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashSet.clone()
方法的具体详情如下:
包路径:java.util.HashSet
类名称:HashSet
方法名:clone
[英]Returns a new HashSet with the same elements and size as this HashSet.
[中]返回与此哈希集具有相同元素和大小的新哈希集。
代码示例来源:origin: org.apache.ant/ant
/**
* @return A copy of the CheckedNamespace.
*/
private synchronized Set<String> getCheckedNamespace() {
@SuppressWarnings("unchecked")
final Set<String> result = (Set<String>) checkedNamespaces.clone();
return result;
}
代码示例来源:origin: org.freemarker/freemarker
Collection getSuspendedEnvironments() {
return (Collection) suspendedEnvironments.clone();
}
代码示例来源:origin: apache/zookeeper
@SuppressWarnings("unchecked")
public Set<String> getEphemerals(long sessionId) {
HashSet<String> retv = ephemerals.get(sessionId);
if (retv == null) {
return new HashSet<String>();
}
Set<String> cloned = null;
synchronized (retv) {
cloned = (HashSet<String>) retv.clone();
}
return cloned;
}
代码示例来源:origin: org.apache.zookeeper/zookeeper
@SuppressWarnings("unchecked")
public HashSet<String> getEphemerals(long sessionId) {
HashSet<String> retv = ephemerals.get(sessionId);
if (retv == null) {
return new HashSet<String>();
}
HashSet<String> cloned = null;
synchronized (retv) {
cloned = (HashSet<String>) retv.clone();
}
return cloned;
}
代码示例来源:origin: org.apache.zookeeper/zookeeper
@SuppressWarnings("unchecked")
public HashSet<String> getEphemerals(long sessionId) {
HashSet<String> retv = ephemerals.get(sessionId);
if (retv == null) {
return new HashSet<String>();
}
HashSet<String> cloned = null;
synchronized(retv) {
cloned = (HashSet<String>) retv.clone();
}
return cloned;
}
代码示例来源:origin: stanfordnlp/CoreNLP
private static <T> boolean equalSets(Set<T> set1, Set<T> set2) {
boolean isEqual = true;
if (set1.size() != set2.size()) {
System.out.println("sizes different: " + set1.size() + " vs. " + set2.size());
isEqual = false;
}
Set<T> newSet1 = (Set<T>) ((HashSet<T>) set1).clone();
newSet1.removeAll(set2);
if (newSet1.size() > 0) {
isEqual = false;
System.out.println("set1 left with: " + newSet1);
}
Set<T> newSet2 = (Set<T>) ((HashSet<T>) set2).clone();
newSet2.removeAll(set1);
if (newSet2.size() > 0) {
isEqual = false;
System.out.println("set2 left with: " + newSet2);
}
return isEqual;
}
代码示例来源:origin: apache/hive
@Override
public void copyToNewInstance(Object newInstance) throws UDFArgumentException {
super.copyToNewInstance(newInstance); // Asserts the class invariant. (Same types.)
GenericUDFInFile that = (GenericUDFInFile)newInstance;
if (that != this) {
that.set = (this.set == null ? null : (HashSet<String>)this.set.clone());
that.strObjectInspector = this.strObjectInspector;
that.fileObjectInspector = this.fileObjectInspector;
}
}
代码示例来源:origin: robovm/robovm
/**
* Returns a new {@code AttributedIterator} with the same source string,
* begin, end, and current index as this attributed iterator.
*
* @return a shallow copy of this attributed iterator.
* @see java.lang.Cloneable
*/
@Override
@SuppressWarnings("unchecked")
public Object clone() {
try {
AttributedIterator clone = (AttributedIterator) super.clone();
if (attributesAllowed != null) {
clone.attributesAllowed = (HashSet<Attribute>) attributesAllowed
.clone();
}
return clone;
} catch (CloneNotSupportedException e) {
throw new AssertionError(e);
}
}
代码示例来源:origin: pinterest/secor
public void deleteTopicPartitionGroup(TopicPartitionGroup topicPartitioGroup) throws IOException {
HashSet<LogFilePath> paths = mFiles.get(topicPartitioGroup);
if (paths == null) {
return;
}
HashSet<LogFilePath> clonedPaths = (HashSet<LogFilePath>) paths.clone();
for (LogFilePath path : clonedPaths) {
deletePath(path);
}
}
代码示例来源:origin: apache/drill
@Override
public void copyToNewInstance(Object newInstance) throws UDFArgumentException {
super.copyToNewInstance(newInstance); // Asserts the class invariant. (Same types.)
GenericUDFInFile that = (GenericUDFInFile)newInstance;
if (that != this) {
that.set = (this.set == null ? null : (HashSet<String>)this.set.clone());
that.strObjectInspector = this.strObjectInspector;
that.fileObjectInspector = this.fileObjectInspector;
}
}
代码示例来源:origin: Sable/soot
CriticalSection(CriticalSection tn) {
super(tn);
this.IDNum = tn.IDNum;
this.nestLevel = tn.nestLevel;
this.origLock = tn.origLock;
this.read = new CodeBlockRWSet();
this.read.union(tn.read);
this.write = new CodeBlockRWSet();
this.write.union(tn.write);
this.invokes = (HashSet<Unit>) tn.invokes.clone();
this.units = (HashSet<Unit>) tn.units.clone();
this.unitToRWSet = (HashMap<Unit, CodeBlockRWSet>) tn.unitToRWSet.clone();
this.unitToUses = (HashMap<Unit, List>) tn.unitToUses.clone();
this.wholeMethod = tn.wholeMethod;
this.method = tn.method;
this.setNumber = tn.setNumber;
this.group = tn.group;
this.edges = (HashSet<CriticalSectionDataDependency>) tn.edges.clone();
this.waits = (HashSet<Unit>) tn.waits.clone();
this.notifys = (HashSet<Unit>) tn.notifys.clone();
this.transitiveTargets
= (HashSet<MethodOrMethodContext>) (tn.transitiveTargets == null ? null : tn.transitiveTargets.clone());
this.lockObject = tn.lockObject;
this.lockObjectArrayIndex = tn.lockObjectArrayIndex;
this.lockset = tn.lockset;
}
代码示例来源:origin: org.apache.zookeeper/zookeeper
/**
* clear all the connections in the selector
*
*/
@Override
@SuppressWarnings("unchecked")
synchronized public void closeAll() {
selector.wakeup();
HashSet<NIOServerCnxn> cnxns;
synchronized (this.cnxns) {
cnxns = (HashSet<NIOServerCnxn>)this.cnxns.clone();
}
// got to clear all the connections that we have in the selector
for (NIOServerCnxn cnxn: cnxns) {
try {
// don't hold this.cnxns lock as deadlock may occur
cnxn.close();
} catch (Exception e) {
LOG.warn("Ignoring exception closing cnxn sessionid 0x"
+ Long.toHexString(cnxn.sessionId), e);
}
}
}
代码示例来源:origin: org.netbeans.api/org-openide-util
/** Notify all waiters that this task has finished.
* @see #run
*/
protected final void notifyFinished() {
Iterator it;
synchronized (this) {
finished = true;
RequestProcessor.logger().log(Level.FINE, "notifyFinished: {0}", this); // NOI18N
notifyAll();
// fire the listeners
if (list == null) {
return;
}
it = ((HashSet) list.clone()).iterator();
}
while (it.hasNext()) {
TaskListener l = (TaskListener) it.next();
l.taskFinished(this);
}
}
代码示例来源:origin: org.apache.zookeeper/zookeeper
@SuppressWarnings("unchecked")
@Override
public void commandRun() {
if (!isZKServerRunning()) {
pw.println(ZK_NOT_SERVING);
} else {
// clone should be faster than iteration
// ie give up the cnxns lock faster
HashSet<NIOServerCnxn> cnxns;
synchronized (factory.cnxns) {
cnxns = (HashSet<NIOServerCnxn>) factory.cnxns.clone();
}
for (NIOServerCnxn c : cnxns) {
c.dumpConnectionInfo(pw, false);
pw.println();
}
pw.println();
}
}
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
@SuppressWarnings("unchecked")
@Override
public RoutingRequest clone() {
try {
RoutingRequest clone = (RoutingRequest) super.clone();
clone.bannedRoutes = bannedRoutes.clone();
clone.bannedTrips = (HashMap<FeedScopedId, BannedStopSet>) bannedTrips.clone();
clone.bannedStops = bannedStops.clone();
clone.bannedStopsHard = bannedStopsHard.clone();
clone.whiteListedAgencies = (HashSet<String>) whiteListedAgencies.clone();
clone.whiteListedRoutes = whiteListedRoutes.clone();
clone.preferredAgencies = (HashSet<String>) preferredAgencies.clone();
clone.preferredRoutes = preferredRoutes.clone();
if (this.bikeWalkingOptions != this)
clone.bikeWalkingOptions = this.bikeWalkingOptions.clone();
else
clone.bikeWalkingOptions = clone;
return clone;
} catch (CloneNotSupportedException e) {
/* this will never happen since our super is the cloneable object */
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.apache.zookeeper/zookeeper
synchronized(factory.cnxns){
cnxnset = (HashSet<NIOServerCnxn>)factory
.cnxns.clone();
代码示例来源:origin: h2oai/h2o-2
HashSet<H2ONode> nodes = (HashSet<H2ONode>)H2O.STATIC_H2OS.clone();
nodes.addAll(Paxos.PROPOSED.values());
bb.mark();
代码示例来源:origin: opentripplanner/OpenTripPlanner
/**
* Safely add a vertex to this area. This creates edges to all other vertices unless those edges would cross one of the original edges.
*/
public void addVertex(IntersectionVertex newVertex, Graph graph) {
GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
if (edges.size() == 0) {
throw new RuntimeException("Can't add a vertex to an empty area");
}
@SuppressWarnings("unchecked")
HashSet<IntersectionVertex> verticesCopy = (HashSet<IntersectionVertex>) vertices.clone();
VERTEX: for (IntersectionVertex v : verticesCopy) {
LineString newGeometry = geometryFactory.createLineString(new Coordinate[] {
newVertex.getCoordinate(), v.getCoordinate() });
// ensure that new edge does not leave the bounds of the original area, or
// fall into any holes
if (!originalEdges.union(originalEdges.getBoundary()).contains(newGeometry)) {
continue VERTEX;
}
// check to see if this splits multiple NamedAreas. This code is rather similar to
// code in OSMGBI, but the data structures are different
createSegments(newVertex, v, areas, graph);
}
vertices.add(newVertex);
}
代码示例来源:origin: jamesagnew/hapi-fhir
@SuppressWarnings("unchecked")
@Override
public IParser setDontStripVersionsFromReferencesAtPaths(Collection<String> thePaths) {
if (thePaths == null) {
myDontStripVersionsFromReferencesAtPaths = Collections.emptySet();
} else if (thePaths instanceof HashSet) {
myDontStripVersionsFromReferencesAtPaths = (Set<String>) ((HashSet<String>) thePaths).clone();
} else {
myDontStripVersionsFromReferencesAtPaths = new HashSet<>(thePaths);
}
return this;
}
代码示例来源:origin: org.dom4j/dom4j
/**
* A clone of the Set of elements that can have their close-tags omitted. By
* default it should be "AREA", "BASE", "BR", "COL", "HR", "IMG", "INPUT",
* "LINK", "META", "P", "PARAM"
*
* @return A clone of the Set.
*/
public Set<String> getOmitElementCloseSet() {
return (Set<String>) (internalGetOmitElementCloseSet().clone());
}
内容来源于网络,如有侵权,请联系作者删除!