本文整理汇总了Python中java.util.HashSet.add方法的典型用法代码示例。如果您正苦于以下问题:Python HashSet.add方法的具体用法?Python HashSet.add怎么用?Python HashSet.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.HashSet
的用法示例。
在下文中一共展示了HashSet.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from java.util import HashSet [as 别名]
# 或者: from java.util.HashSet import add [as 别名]
def __init__(self, client_addr, server_addr, operations_map, is_simulator=False):
self.client_addr = client_addr
self.server_addr = server_addr
self.is_simulator = is_simulator
self.operations = dict(operations_map)
self.operations["help"] = "help <optional command>"
self.operations["login"] = "login username"
self.operations["logout"] = "logout"
self.operations["echo"] = "echo text"
self.operations["exit"] = "exit"
self.aux_commands = {"help", "login", "logout", "echo", "exit"}
self.op_commands = set(operations_map.keySet())
self.all_commands = set(self.op_commands)
self.all_commands.update(self.aux_commands)
all_commands_set = HashSet()
for x in self.all_commands:
all_commands_set.add(x)
try:
self.console = ConsoleReader()
self.console.addCompleter(StringsCompleter(all_commands_set))
self.console.setPrompt("prompt> ")
except IOException as err:
err.printStackTrace()
示例2: getBestVariable
# 需要导入模块: from java.util import HashSet [as 别名]
# 或者: from java.util.HashSet import add [as 别名]
def getBestVariable(self, functionalSentence, functionInfo):
""" generated source for method getBestVariable """
# If all the variables that can be set by the functional sentence are in
# the varOrdering, we return null. Otherwise, we return one of
# those with the largest domain.
# The FunctionInfo is sentence-independent, so we need the context
# of the sentence (which has variables in it).
tuple_ = GdlUtils.getTupleFromSentence(functionalSentence)
dependentSlots = functionInfo.getDependentSlots()
if len(tuple_) != len(dependentSlots):
raise RuntimeException("Mismatched sentence " + functionalSentence + " and constant form " + functionInfo)
candidateVars = HashSet()
i = 0
while i < len(tuple_):
if isinstance(term, (GdlVariable, )) and dependentSlots.get(i) and not self.varOrdering.contains(term) and self.varsToAssign.contains(term):
candidateVars.add(term)
i += 1
# Now we look at the domains, trying to find the largest
bestVar = None
bestDomainSize = 0
for var in candidateVars:
if domainSize > bestDomainSize:
bestVar = var
bestDomainSize = domainSize
return bestVar
示例3: save_and_get_complex
# 需要导入模块: from java.util import HashSet [as 别名]
# 或者: from java.util.HashSet import add [as 别名]
def save_and_get_complex():
'''Test saving entities containing mapped collection properties'''
entity1 = TestEntities.ComplexEntity()
entity1.setId("complex1")
strings = ArrayList()
strings.add("one")
strings.add("two")
entity1.setStringList(strings)
ints = HashSet()
ints.add(1)
ints.add(2)
entity1.setIntSet(ints)
extended = HashMap()
extended.put("prop1", "one")
extended.put("prop2", "two")
entity1.setExtendedProps(extended)
service = EntityService(TestEntities.ComplexEntity)
service.save(entity1)
entity2 = service.get("complex1")
assertNotNull(entity2)
assertEquals(entity2.getId(), entity1.getId())
assertTrue(entity2.getStringList().contains("one"))
assertTrue(entity2.getStringList().contains("two"))
assertTrue(entity2.getIntSet().contains(java.lang.Long(1)))
assertTrue(entity2.getIntSet().contains(java.lang.Long(2)))
assertNotNull(entity2.getExtendedProps())
assertEquals(entity2.getExtendedProps().get("prop1"), "one")
assertEquals(entity2.getExtendedProps().get("prop2"), "two")
示例4: solveTurns
# 需要导入模块: from java.util import HashSet [as 别名]
# 或者: from java.util.HashSet import add [as 别名]
def solveTurns(self, model):
""" generated source for method solveTurns """
# Before we can do anything else, we need a topological ordering on our forms
ordering = getTopologicalOrdering(model.getIndependentSentenceForms(), model.getDependencyGraph())
ordering.retainAll(self.formsControlledByFlow)
# Let's add function info to the consideration...
functionInfoMap = HashMap()
for form in constantForms:
functionInfoMap.put(form, FunctionInfoImpl.create(form, self.constantChecker))
# First we set the "true" values, then we get the forms controlled by the flow...
# Use "init" values
trueFlowSentences = HashSet()
for form in constantForms:
if form.__name__ == self.INIT:
for initSentence in constantChecker.getTrueSentences(form):
trueFlowSentences.add(trueSentence)
# Go through ordering, adding to trueFlowSentences
addSentenceForms(ordering, trueFlowSentences, model, functionInfoMap)
self.sentencesTrueByTurn.add(trueFlowSentences)
while True:
# Now we use the "next" values from the previous turn
trueFlowSentences = HashSet()
for sentence in sentencesPreviouslyTrue:
if sentence.__name__ == self.NEXT:
trueFlowSentences.add(trueSentence)
addSentenceForms(ordering, trueFlowSentences, model, functionInfoMap)
# Test if this turn's flow is the same as an earlier one
while i < len(self.sentencesTrueByTurn):
if prevSet == trueFlowSentences:
# Complete the loop
self.turnAfterLast = i
break
i += 1
self.sentencesTrueByTurn.add(trueFlowSentences)
示例5: recordPropositions
# 需要导入模块: from java.util import HashSet [as 别名]
# 或者: from java.util.HashSet import add [as 别名]
def recordPropositions(self):
""" generated source for method recordPropositions """
propositions = HashSet()
for component in components:
if isinstance(component, (Proposition, )):
propositions.add(component)
return propositions
示例6: CyclicTypeRecorder
# 需要导入模块: from java.util import HashSet [as 别名]
# 或者: from java.util.HashSet import add [as 别名]
class CyclicTypeRecorder(object):
def __init__(self):
self.count = 0
self.elements = HashMap()
self.used = HashSet()
def push(self, t):
self.count += 1
self.elements[t] = self.count
return self.count
def pop(self, t):
del self.elements[t]
if t in self.used:
self.used.remove(t)
def visit(self, t):
i = self.elements.get(t)
if i is not None:
self.used.add(t)
return i
def isUsed(self, t):
return t in self.used
示例7: handleQuery
# 需要导入模块: from java.util import HashSet [as 别名]
# 或者: from java.util.HashSet import add [as 别名]
def handleQuery(self, query, fieldName, formatStr):
out = ByteArrayOutputStream()
req = SearchRequest(query)
req.setParam("fq", 'item_type:"object"')
req.setParam("fq", 'workflow_id:"dataset"')
req.setParam("rows", "1000")
self.indexer.search(req, out)
res = SolrResult(ByteArrayInputStream(out.toByteArray()))
hits = HashSet()
if (res.getNumFound() > 0):
results = res.getResults()
for searchRes in results:
searchResList = searchRes.getList(fieldName)
if (searchResList.isEmpty()==False):
for hit in searchResList:
if self.term is not None:
if hit.find(self.term) != -1:
hits.add(hit)
else:
hits.add(hit)
self.writer.print("[")
hitnum = 0
for hit in hits:
if (hitnum > 0):
self.writer.print(","+formatStr % {"hit":hit})
else:
self.writer.print(formatStr % {"hit":hit})
hitnum += 1
self.writer.print("]")
else:
self.writer.println("[\"\"]")
self.writer.close()
示例8: handleGrantNumber
# 需要导入模块: from java.util import HashSet [as 别名]
# 或者: from java.util.HashSet import add [as 别名]
def handleGrantNumber(self):
out = ByteArrayOutputStream()
req = SearchRequest("grant_numbers:%s*" % self.term)
req.setParam("fq", 'item_type:"object"')
req.setParam("fq", 'workflow_id:"dataset"')
req.setParam("rows", "1000")
self.indexer.search(req, out)
res = SolrResult(ByteArrayInputStream(out.toByteArray()))
hits = HashSet()
if (res.getNumFound() > 0):
creatorResults = res.getResults()
for creatorRes in creatorResults:
creatorList = creatorRes.getList("grant_numbers")
if (creatorList.isEmpty()==False):
for hit in creatorList:
hits.add(hit)
self.writer.print("[")
hitnum = 0
for hit in hits:
if (hitnum > 0):
self.writer.print(",\"%s\"" % hit)
else:
self.writer.print("\"%s\"" % hit)
hitnum += 1
self.writer.print("]")
else:
self.writer.println("[\"\"]")
self.writer.close()
示例9: handleWorkflowStep
# 需要导入模块: from java.util import HashSet [as 别名]
# 或者: from java.util.HashSet import add [as 别名]
def handleWorkflowStep(self):
out = ByteArrayOutputStream()
req = SearchRequest("workflow_step_label:[* TO *]" )
req.setParam("fq", 'item_type:"object"')
req.setParam("fq", 'workflow_id:"dataset"')
req.setParam("rows", "1000")
self.indexer.search(req, out)
res = SolrResult(ByteArrayInputStream(out.toByteArray()))
hits = HashSet()
if (res.getNumFound() > 0):
recordTypeResults = res.getResults()
for recordTypeResult in recordTypeResults:
recordTypeList = recordTypeResult.getList("workflow_step_label")
if (recordTypeList.isEmpty()==False):
for hit in recordTypeList:
hits.add(hit)
self.writer.println("[")
hitnum = 0
for hit in hits:
if (hitnum > 0):
self.writer.println(",{\"value\": \"%s\",\n\"label\": \"%s\"}" % (hit,hit))
else:
self.writer.println("{\"value\": \"%s\",\n\"label\": \"%s\"}" % (hit,hit))
hitnum += 1
self.writer.println("]")
else:
self.writer.println("[\"\"]")
self.writer.close()
示例10: getNodeObjects
# 需要导入模块: from java.util import HashSet [as 别名]
# 或者: from java.util.HashSet import add [as 别名]
def getNodeObjects(api, filters):
found = 0
ndMap = {}
ndSet = HashSet()
lanSwitchCapability = "com.hp.nnm.capability.node.lanswitching"
ipForwardingCapability = "com.hp.nnm.capability.node.ipforwarding"
try:
ndStub = api.getStub(NnmServicesEnum().Node)
for filter in filters:
allNodesArray = ndStub.getNodes(filter)
allNodes = allNodesArray.getItem()
if allNodes != None:
found = 1
logger.debug("Retrieved %s Node Objects" % (len(allNodes)))
for i in range(len(allNodes)):
if (notNull(allNodes[i].getId())
and notNull(allNodes[i].getName())
and notNull(allNodes[i].getCreated()) and notNull(allNodes[i].getModified())):
## Don't add duplicate Nodes
if ndSet.contains(allNodes[i].getId()):
continue
else:
ndSet.add(allNodes[i].getId())
# The capabilities com.hp.nnm.capability.node.lanswitching and
# com.hp.nnm.capability.node.ipforwarding have replaced isLanSwitch and isIPv4Router respectively.
isLanSwitch = 0
isRouter = 0
caps = allNodes[i].getCapabilities()
if (notNull(caps)):
for cap in caps:
key = cap.getKey().strip()
if (key == lanSwitchCapability):
isLanSwitch = 1
if (key == ipForwardingCapability):
isRouter = 1
ndMap[allNodes[i].getId()] = UNode(allNodes[i].getId(), allNodes[i].getName(), isRouter,
isLanSwitch, allNodes[i].getSystemName(), allNodes[i].getSystemContact(),
allNodes[i].getSystemDescription(), allNodes[i].getSystemLocation(), allNodes[i].getSystemObjectId(),
allNodes[i].getLongName(), allNodes[i].getSnmpVersion(), allNodes[i].getDeviceModel(),
allNodes[i].getDeviceVendor(), allNodes[i].getDeviceFamily(), allNodes[i].getDeviceDescription(),
allNodes[i].getDeviceCategory(), '', '')
else:
break
except:
stacktrace = traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])
errMsg = 'Exception:\n %s' % stacktrace
logger.error(errMsg)
api.Framework.reportWarning(errMsg)
if found:
logger.debug('Created a dictionary of %d Node objects' % (len(ndMap)))
else:
errMsg = 'Did not find any Node objects'
logger.debug(errMsg)
api.Framework.reportWarning(errMsg)
return ndMap
示例11: containers
# 需要导入模块: from java.util import HashSet [as 别名]
# 或者: from java.util.HashSet import add [as 别名]
def containers():
result = HashSet()
for _delta in specification.deltas:
depl = _delta.deployedOrPrevious
current_container = depl.container
if depl.type in ("soa.CompositeSOADeployable","soa.Composite") and current_container.type in ("wls.Server",'wls.Cluster'):
result.add(current_container)
return result
示例12: getStateFromBase
# 需要导入模块: from java.util import HashSet [as 别名]
# 或者: from java.util.HashSet import add [as 别名]
def getStateFromBase(self):
""" generated source for method getStateFromBase """
contents = HashSet()
for p in propNet.getBasePropositions().values():
p.setValue(p.getSingleInput().getValue())
if p.getValue():
contents.add(p.__name__)
return MachineState(contents)
示例13: deployeds
# 需要导入模块: from java.util import HashSet [as 别名]
# 或者: from java.util.HashSet import add [as 别名]
def deployeds():
result = HashSet()
for _delta in deltas.deltas:
depl = _delta.deployedOrPrevious
current_container = depl.container
if _delta.operation != "NOOP" and depl.type == "soa.ExtensionLibrary" and current_container.type in ("wls.SOAServer",'wls.SOACluster'):
result.add(depl)
return result
示例14: getUncachedGameKeys
# 需要导入模块: from java.util import HashSet [as 别名]
# 或者: from java.util.HashSet import add [as 别名]
def getUncachedGameKeys(self):
""" generated source for method getUncachedGameKeys """
theKeys = HashSet()
for game in File("games/test").listFiles():
if not game.__name__.endsWith(".kif"):
continue
theKeys.add(game.__name__.replace(".kif", ""))
return theKeys
示例15: containers
# 需要导入模块: from java.util import HashSet [as 别名]
# 或者: from java.util.HashSet import add [as 别名]
def containers():
result = HashSet()
for delta in deltas.deltas:
deployed = delta.deployedOrPrevious
current_container = deployed.container
if delta.operation != "NOOP" and current_container.type == "wlp.Server" and current_container.rebootServer is True:
result.add(current_container)
return result