2016-08-01 20 views
0

你好Groovy的專家分配頂部的變量,找到一個集合中的值,並使用Groovy

我使用下面的命令來獲取所有的ODI Dataservers。

def PSchema=DServer.getPhysicalSchemas(); 

當我打印PSchema變量時,我得到以下值。

[oracle.odi.domain.topology.OdiPhysicalSchema ABC.X1, oracle.odi.domain.topology.OdiPhysicalSchema ABC.X2] 

我想實現我在這裏會路過X1或運行期間X2 ...
然後我想驗證與PSchema結果,並打印該值以下值:

oracle.odi.domain.topology.OdiPhysicalSchema ABC.X2 

我嘗試使用以下選項:

def PSchema44 = PSchema11.findIndexValues { it =~ /(X1)/ } 
def pl=PSchema11.collect{if(it.contains ('X1)){return it}} 

我嘗試了LO OP檢查是否值越來越正確打印..result是好的:

for (item in PSchema11) 
{ 
    println item 
} 
+0

收集的正確語法應該是'def pl = PSchema11.collect {it.contains('X1')}' 你試過嗎? – OsaSoft

+0

收到以下錯誤** groovy.lang.MissingMethodException:沒有方法的簽名:oracle.odi.domain.topology.OdiPhysicalSchema.contains()適用於參數類型:(java.lang.String)values:[X1] 可能的解決方案:toString(),toString(),toString(),notify()** – Ananda

+0

查看文檔,看起來像'getPhysicalSchemas()'返回 IPhysicalSchemas的一個不可修改的集合 您究竟想要達到什麼目的?如果我理解正確,您在運行時傳遞X1或X2,並且想從getPhysicalSchemas()'返回的集合中選擇傳遞的值? – OsaSoft

回答

1

假設「X1」和「X2」是物理架構的名字,你應該能夠做這樣的事情:

def phys = "X1" 
def pSchemas = dServer.getPhysicalSchemas() 
def schema = pSchemas.find{it.schemaName == phys} 

另外我想你是Groovy的新手,我建議你閱讀語法和命名約定。例如,變量名應該總是以小寫字母開頭

+0

非常感謝!如果您有任何問題,您可以請建議標準命名約定! – Ananda

+0

對於一些常規風格的約定,請參閱http://groovy-lang.org/style-guide.html。至於命名約定,幾乎與Java命名約定相同,請參見http://www.javatpoint。COM/Java的命名約定 – OsaSoft

相關問題