当前位置: 首页>>代码示例>>Python>>正文


Python String.valueOf方法代码示例

本文整理汇总了Python中java.lang.String.valueOf方法的典型用法代码示例。如果您正苦于以下问题:Python String.valueOf方法的具体用法?Python String.valueOf怎么用?Python String.valueOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.String的用法示例。


在下文中一共展示了String.valueOf方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_null_pointer_exception

# 需要导入模块: from java.lang import String [as 别名]
# 或者: from java.lang.String import valueOf [as 别名]
 def test_null_pointer_exception(self):
     try:
         # throws http://stackoverflow.com/questions/3131865/why-does-string-valueofnull-throw-a-nullpointerexception
         String.valueOf(None)
     except Exception as ex:
         # because it's not a checked exception, mapped exceptions doesn't apply here (all Runtime)            
         self.assertIn('java.lang.NullPointerException', str(ex.message))
开发者ID:bsteffensmeier,项目名称:jep,代码行数:9,代码来源:test_exceptions.py

示例2: test_null_pointer_exception

# 需要导入模块: from java.lang import String [as 别名]
# 或者: from java.lang.String import valueOf [as 别名]
 def test_null_pointer_exception(self):
     try:
         # throws http://stackoverflow.com/questions/3131865/why-does-string-valueofnull-throw-a-nullpointerexception
         String.valueOf(None)
     except Exception as ex:
         # because it's not a checked exception, mapped exceptions doesn't apply here (all Runtime)
         if not jep.USE_MAPPED_EXCEPTIONS:
             self.assertEquals(ex.java_name, 'java.lang.NullPointerException')
开发者ID:Kroisse,项目名称:jep,代码行数:10,代码来源:test_exceptions.py

示例3: test_call_static_methods

# 需要导入模块: from java.lang import String [as 别名]
# 或者: from java.lang.String import valueOf [as 别名]
 def test_call_static_methods(self):
     s1 = String.valueOf(['1', '2', '3'])
     s2 = String.valueOf('123')
     s3 = String.valueOf(123)
     s4 = String.valueOf(123)
     s5 = String.valueOf(['0', '1', '2', '3', 'a', 'b'], 1, 3)
     self.assertEqual(s1, s2)
     self.assertEqual(s1, s3)
     self.assertEqual(s1, s4)
     self.assertEqual(s1, s5)
开发者ID:isaiah,项目名称:jython3,代码行数:12,代码来源:test_jbasic.py

示例4: getImageIdNames

# 需要导入模块: from java.lang import String [as 别名]
# 或者: from java.lang.String import valueOf [as 别名]
def getImageIdNames(gateway, datasetId):
    
    browse = gateway.getFacility(BrowseFacility)
    user = gateway.getLoggedInUser()
    print(user)
    defaultgroup = user.getGroupId()
    
    ctx = SecurityContext(groupId)
    print(ctx)
    ids = ArrayList(1)
    val = Long(datasetId)
    ids.add(val)
    images = browse.getImagesForDatasets(ctx, ids)
    j = images.iterator()
    imageIds = []
    imageNames = []
    while j.hasNext():
        image = j.next()
        imageIds.append(String.valueOf(image.getId()))
        imageNames.append(String.valueOf(image.getName()))
    
    return imageIds, imageNames, defaultgroup
开发者ID:erickmartins,项目名称:ImageJ_Macros,代码行数:24,代码来源:concat_stacks_janelia.py

示例5: abs

# 需要导入模块: from java.lang import String [as 别名]
# 或者: from java.lang.String import valueOf [as 别名]
from java.lang.Math import abs
assert abs(-2.) == 2., 'Python float to Java double'
assert abs(-2) == 2l, 'Python int to Java long'
assert abs(-2l) == 2l, 'Python long to Java long'

try: abs(-123456789123456789123l)
except TypeError: pass

print 'strings'
from java.lang import Integer, String

assert Integer.valueOf('42') == 42, 'Python string to Java string'

print 'arrays'
chars = ['a', 'b', 'c']
assert String.valueOf(chars) == 'abc', 'char array'

print 'Enumerations'
from java.util import Vector

vec = Vector()
items = range(10)
for i in items:
    vec.addElement(i)

expected = 0
for i in vec:
    assert i == expected, 'testing __iter__ on java.util.Vector'
    expected = expected+1

expected = 0
开发者ID:Alex-CS,项目名称:sonify,代码行数:33,代码来源:test_jbasic.py

示例6: sendJournalMessage

# 需要导入模块: from java.lang import String [as 别名]
# 或者: from java.lang.String import valueOf [as 别名]
def sendJournalMessage(guid, sender, to, cc, bcc, domain, cloudDomain, mtaHost):    
    randomId = String.valueOf(Random(System.currentTimeMillis()).nextInt(1000000))    
    print 'Sending message ' + randomId + ' to journaling address ' + guid + '@' + cloudDomain
    
    try:
        props = System.getProperties()
        props.put("mail.smtp.host", mtaHost)
        props.put("mail.smtp.starttls.enable", "false")     

        session = Session.getDefaultInstance(props)
        session.setDebug(True)

        # create message envelope
        envelope = MimeMessage(session)
        envelope.setSentDate(Date(System.currentTimeMillis() - 2000))
        envelope.setSubject("Test Journal Envelope " + randomId)
        envelope.setFrom(InternetAddress(sender + "@" + domain))
        
        # alternating character sets
        if (int(randomId) % 2) == 0:
            envelope.setText(String('bullet \x95, euro sign \x80, latin F \x83, tilde \x98', 'windows-1252'), 'windows-1252')
        elif (int(randomId) % 3) == 0:
            envelope.setText('plain ascii text...', 'us-ascii')
        else:
            envelope.setText('bullet \xe2\x80\xa2, euro sign \xe2\x82\xac, latin F \xc6\x92, tilde \x7e', 'utf-8')

        if to is not None:
            for recipient in to:
                envelope.addRecipient(Message.RecipientType.TO, InternetAddress(recipient + "@" + domain))
        if cc is not None:
            for recipient in cc:
                envelope.addRecipient(Message.RecipientType.CC, InternetAddress(recipient + "@" + domain))
        if bcc is not None:
            for recipient in bcc:
                envelope.addRecipient(Message.RecipientType.BCC, InternetAddress(recipient + "@" + domain))
        
        # generate message-id
        envelope.saveChanges()
        
        # create journal envelope
        journalEnvelope = MimeMessage(session)
        journalEnvelope.setHeader("X-MS-Journal-Report", "")
        journalEnvelope.setSentDate(Date())
        journalEnvelope.setSubject(envelope.getSubject())                   
        journalEnvelope.setFrom(InternetAddress("[email protected]" + domain))            
        journalEnvelope.addRecipient(Message.RecipientType.TO, InternetAddress(guid + "@" + cloudDomain))
        
        # Sender: [email protected]
        # Subject: RE: Test - load CAtSInk
        # Message-Id: <[email protected]=
        # 1dev.com>
        # To: [email protected]
        # Cc: [email protected]
        # Bcc: [email protected]            
        journalReport = StringBuilder()
        journalReport.append("Sender: ").append(sender + "@" + domain).append("\r\n")
        journalReport.append("Subject: ").append(envelope.getSubject()).append("\r\n")
        journalReport.append("Message-Id: ").append(envelope.getMessageID()).append("\r\n")
        
        if to is not None:
            for recipient in to:
                journalReport.append("To: ").append(recipient + "@" + domain).append("\r\n")            
        if cc is not None:
            for recipient in cc:
                journalReport.append("Cc: ").append(recipient + "@" + domain).append("\r\n")                 
        if bcc is not None:
            for recipient in bcc:
                journalReport.append("Bcc: ").append(recipient + "@" + domain).append("\r\n")
        
        multipart = MimeMultipart()
        
        reportPart = MimeBodyPart()
        reportPart.setText(journalReport.toString(), "us-ascii")
        multipart.addBodyPart(reportPart)
        
        messagePart = MimeBodyPart()
        messagePart.setContent(envelope, "message/rfc822")
        multipart.addBodyPart(messagePart)

        journalEnvelope.setContent(multipart)
        
        try:
            Transport.send(journalEnvelope)
        except:
            print "Send failed, will try to propagate MTA configuration again..."            
            propagateMtaConfig()
            Transport.send(journalEnvelope)
        
        return True
    except:
        print 'Failed to send journaled message', randomId
        raise
开发者ID:piyush76,项目名称:EMS,代码行数:94,代码来源:cloud.py

示例7: test_arrays

# 需要导入模块: from java.lang import String [as 别名]
# 或者: from java.lang.String import valueOf [as 别名]
 def test_arrays(self):
     chars = ['a', 'b', 'c']
     self.assertEqual(String.valueOf(chars), 'abc', 'char array')
开发者ID:isaiah,项目名称:jython3,代码行数:5,代码来源:test_jbasic.py

示例8: Collection_Btree

# 需要导入模块: from java.lang import String [as 别名]
# 或者: from java.lang.String import valueOf [as 别名]
    def Collection_Btree(self, key):
        """
        """
        name = 'Collection_Btree'
        keyList = []
        for i in range(4):                    # Create 5 key
            keyList.append(key + str(i))
    
        bkeyBASE = "bkey_byteArry"

        eflag = String("EFLAG").getBytes()
        filter = ElementFlagFilter(ElementFlagFilter.CompOperands.Equal, String("EFLAG").getBytes()) 
        attr = CollectionAttributes()
        attr.setExpireTime(ExpireTime)
        
        # BopInsert + byte_array bkey
        for j in range(4):                        # 5 Key 
            for i in range(50):                   # Insert 50 bkey
                bk = bkeyBASE + str(j) + str(i)   # Uniq bkey
                bkey = String(String.valueOf(bk)).getBytes()                        ####____####
                future = self.client.asyncBopInsert(keyList[j], bkey, eflag, random.choice(workloads), attr)
                result = self.arcusGet(future, name=name)
                #print str(result)

        # Bop Bulk Insert (Piped Insert)
        elements = []
        for i in range(50):
            bk = bkeyBASE + str(0) + str(i) + "bulk"
            elements.append(Element(String(str(bk)).getBytes(), workloads[0], eflag)) ####____####
        future = self.client.asyncBopPipedInsertBulk(keyList[0], elements, CollectionAttributes())
        result = self.arcusGet(future, name=name)
        #print str(result)
        
        # BopGet Range + filter
        for j in range(4):                    
            bk = bkeyBASE + str(j) + str(0)  
            bk_to = bkeyBASE + str(j) + str(50) 
            bkey = String(String.valueOf(bk)).getBytes()
            bkey_to = String(String.valueOf(bk_to)).getBytes()           ####____####
            future = self.client.asyncBopGet(keyList[j], bkey, bkey_to, filter, 0, random.randint(20, 50), False, False)
            result = self.arcusGet(future, name=name)
            #print str(result)
        
	# BopGetBulk  // 20120319 Ad
        bk = bkeyBASE + str(0) + str(0)                                                                                                                                      
        bk_to = bkeyBASE + str(4) + str(50)                                                                                                                                  
        bkey = String(String.valueOf(bk)).getBytes()                                                                                                                         
        bkey_to = String(String.valueOf(bk_to)).getBytes()           ####____####                                                                                            
        future = self.client.asyncBopGetBulk(keyList, bkey, bkey_to, filter, 0, random.randint(20, 50))                                                         
        result = self.arcusGet(future, name=name)
	#for entry in result.entrySet():
	#	print str(entry.getKey())

	#	if entry.getValue().getElements() is not None:
	#		print "["
	#		for element in entry.getValue().getElements().entrySet():
	#			print "bkey=%s, value=%s" % (str(element.getKey()), str(element.getValue().getValue()))
	#		print "]"
	#	else:
	#		print "[elements=%s, response=%s]" % (entry.getValue().getElements(), entry.getValue().getCollectionResponse().getMessage())
	#print ""
	#print str(result)
	
        # BopEmpty Create
        future = self.client.asyncBopCreate(key, ElementValueType.STRING, CollectionAttributes())
        result = self.arcusGet(future, name=name)
        #print str(result)

        # BopSMGet
        bk = bkeyBASE + str(0) + str(0)  
        bk_to = bkeyBASE + str(4) + str(50) 
        bkey = String(String.valueOf(bk)).getBytes()             ####____####
        bkey_to = String(String.valueOf(bk_to)).getBytes()       ####____####
        future = self.client.asyncBopSortMergeGet(keyList, bkey, bkey_to, filter, 0, random.randint(20, 50))
        result = self.arcusGet(future, name=name)
        #print str(result)
        
        # BopUpdate  (eflag bitOP + value)
        key = keyList[0]
        eflagOffset = 0
        value = "ThisIsChangeValue"
        bitop = ElementFlagUpdate(eflagOffset, ElementFlagFilter.BitWiseOperands.AND, String("aflag").getBytes())
        for i in range(2):                      # 3 element update
            bk = bkeyBASE + str(0) + str(i)
            bkey = String(String.valueOf(bk)).getBytes()       ####____####
            future = self.client.asyncBopUpdate(key, bkey, bitop, value)       
            result = self.arcusGet(future, name=name)
            #print str(result)
        
        # SetAttr  (change Expire Time)
        attr.setExpireTime(100)
        future = self.client.asyncSetAttr(key, attr)
        result = self.arcusGet(future, name=name)
        #print str(result)

        # BopDelete          (eflag filter delete)
        for j in range(4):                     
            bk = bkeyBASE + str(j) + str(0)  
            bk_to = bkeyBASE + str(j) + str(10) 
            bkey = String(String.valueOf(bk)).getBytes() ####____####
#.........这里部分代码省略.........
开发者ID:jam2in,项目名称:arcus-misc,代码行数:103,代码来源:arcus1.6.2-integration.py

示例9: prompt

# 需要导入模块: from java.lang import String [as 别名]
# 或者: from java.lang.String import valueOf [as 别名]
  def prompt(self, tts, options=None):
      grammar = ''
      timeout = 30000  #milliseconds
      onTimeout  = None
      onChoices  = None
      onBadChoice  = None
      repeat = 0
      onError  = None
      onEvent  = None
      onHangup  = None
      ttsOrUrl = ''
      bargein = True
      choiceConfidence='0.3'
      choiceMode='any' # (dtmf|speech|any) - defaults to any
  
      #record parameters
      record = False
      beep = True
      silenceTimeout = 5000  # 5 seconds
      maxTime = 30000 # 30 seconds
      onSilenceTimeout = None
      onRecord = None

      recordURI = ''
      recordFormat = 'audio/wav'
      httpMethod = 'POST'

      if tts != None : #make sure the ttsOrUrl is at least an empty string before calling IncomingCall
        ttsOrUrl = tts 
      #print ttsOrUrl

      if options != None: 
        if "choices" in options : #make sure the grammar is at least an empty string before calling IncomingCall
          grammar = options["choices"] 
        if "onChoice" in options:
          onChoices = options["onChoice"]
        if "onBadChoice" in options:
          onBadChoice = options["onBadChoice"]
        if "timeout" in options: 
          timeout = _parseTime(options['timeout'])
        if "onTimeout" in options:
          onTimeout = options["onTimeout"]
        if "repeat" in options:
          repeat = int(options["repeat"])
          if repeat < 0:
             repeat = 0 
        if "onError" in options:
          onError = options["onError"]
        if "onEvent" in options:
          onEvent = options["onEvent"]
        if "onHangup" in options:
          onHangup = options["onHangup"]
        if "bargein" in options:
            bargein = options["bargein"]
        if "choiceConfidence" in options:
            choiceConfidence = String.valueOf(options["choiceConfidence"])
        if "choiceMode" in options:
            choiceMode = options["choiceMode"]

        #record
        if "record" in options:
            record = options["record"]
        if "beep" in options:
            beep = options["beep"]
        if "silenceTimeout" in options:
            silenceTimeout = _parseTime(options["silenceTimeout"])
        if "maxTime" in options:
            maxTime = _parseTime(options["maxTime"])
        if "onSilenceTimeout" in options:
            onSilenceTimeout = options["onSilenceTimeout"]
        if "onRecord" in options:
            onRecord = options["onRecord"]

        if "recordURI" in options:
            recordURI = options["recordURI"]
        if "recordFormat" in options:
            recordFormat = options["recordFormat"]
        if "httpMethod" in options:
            httpMethod = options["httpMethod"]
    
      event  = None

      for x in range(repeat+1):
        #print "timeout=%s repeat=%d x=%d" % (timeout, repeat, x)
        try:
          if record:
            result = self._call.promptWithRecord(ttsOrUrl, bargein, grammar, choiceConfidence, choiceMode, timeout, record, beep, maxTime, silenceTimeout, recordURI, recordFormat, httpMethod )
            event = TropoEvent("record", result.get('recordURL'), result.get('recordURL'))
            if onRecord != None:
               _handleCallBack(onRecord,event)
            if grammar != None and grammar != '': # both choice and record are enabled
               choice = TropoChoice(result.get('concept'),result.get('interpretation'),result.get('confidence'),result.get('xml'),result.get('utterance'))
               event = TropoEvent("choice", result.get('value'), result.get('recordURL'), choice)
               if onChoices != None:
                  _handleCallBack(onChoices,event)
          else:
            result = self._call.prompt(ttsOrUrl, bargein, grammar, choiceConfidence, choiceMode, timeout)
            choice = TropoChoice(result.get('concept'),result.get('interpretation'),result.get('confidence'),result.get('xml'),result.get('utterance'))
            event = TropoEvent("choice", result.get('value'), result.get('recordURL'), choice)
            if onChoices != None:
#.........这里部分代码省略.........
开发者ID:sanyaade,项目名称:tropo-servlet,代码行数:103,代码来源:tropo.py


注:本文中的java.lang.String.valueOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。