This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Original: http://mrhaki.blogspot.com.br/search/label/Groovy%3AGoodness | |
//Português: http://santograils.org/2015/06/12/descubra-os-novos-metodos-do-groovy-para-ordenacao-e-remocao-de-duplicacoes/ | |
@groovy.transform.Sortable | |
@groovy.transform.ToString | |
class User { | |
String username, email | |
} | |
def mrhaki1 = new User(username: 'mrhaki', email: 'mrhaki@localhost') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Veja o código em execução no groovy console: https://groovyconsole.appspot.com/script/5751247093104640 | |
"user_name".split('_').collect{it[0].toUpperCase()+it.substring(1)}.join() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
public class Losartana{ | |
public String getNome(Integer numero){ | |
return "${numero}º losartana de "; | |
} | |
} | |
Integer.metaClass.getMg{-> return "$delegate mg" } | |
Integer.metaClass.losartanas{ n -> return (1..delegate).collect{ new Losartana().getNome(it) + n }} | |
3.losartanas 5.mg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Plutãones | |
Um grupo de pesquisadores descobriram que foi realizada uma missão secreta para plutão em busca de vida e que os astronautas enviaram uma mensagem codificada para a nasa em uma lingua que foi denominada plutãones. | |
Após algumas análises, foi identificado que esta codificação segue os seguintes padrões: | |
1 - Cada palavra é separada por "syllabe textus" ou "ST" (silaba textual - ou seja, a separação não é pelo som e sim pelas vogais, desconsiderando as acentuadas); | |
2 - após cada ST é adicionado o sufixo pl somado com a última letra do ST em questão; | |
3 - No caso da palavra terminar com uma consoante ela não sofre alteração. | |
4 - Em contradição com a regra 3, toda consoante de final de palavra é considerada uma ST se for a ultima da frase. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Definição do problema: https://gist.github.com/jonatasemidio/8b95d2c666004065c53f | |
String.metaClass.getFirstIsVowel{-> return delegate[0] ==~ /[aeiou]/} | |
'plutãones'.replace(' ','&').collect{ if(it.firstIsVowel){return it+"#"}else{return it}}.join().split('#').collect{it+'pl'+it[-1]}.join().replace('&', ' ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.metaClass.findAll{println it.toString()} | |
class Dog{ String name; public String toString(){ return this.name } } | |
class Cat{ String name; public String toString(){ return this.name } } | |
class Cow{ String name; public String toString(){ return this.name } } | |
dog = new Dog(name: 'toto') | |
cat = new Dog(name: 'lili') | |
cow = new Dog(name: 'mumu') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Buyable { | |
def buy() | |
} | |
class SomeBuyableObject implements Buyable { | |
String foo | |
def buy() { //do stuff } | |
} | |
class AnotherBuyableObject implements Buyable { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.io.FileType | |
def generateTest(String dir, String projectName) { | |
createDirectories(dir+File.separator+projectName) | |
new File(dir).eachFileRecurse(FileType.FILES) { if(it.name.contains('.java')) buildTestClasses(it.toString(), projectName)} | |
} | |
def buildTestClasses(String completeFileName, String projectName){ | |
def selectedFile = new File(completeFileName) | |
def testClassFile = new File(createNameTestFile(completeFileName, projectName)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
O apresentador Ratinho precisa criar um quadro em seu programa chamado de "Teste de DNA". | |
Esse quadro será responsável por identificar quem é o pai da criança apresentada. | |
Basicamente será apresentado uma criança e dois possíveis pais. Onde o Ratinho será o responsável por descobrir o pai original. | |
Para isso o DNA coletado de cada possível pai será comparado com o DNA coletado do filho. | |
As 3 sequências de DNS serão informadas ao sistema que retornará com quem é o Pai. | |
Onde você será o responsável por contruir esse sistema seguindo as seguintes regras: | |
1 - O DNA com a maior pontuação (mais parecido) de compatibilidade será eleito o pai da vez; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d={'z':'q','q':'z','\n':'\n',' ':' ','a':'y','c':'e','b':'h','e':'o','d':'s','g':'v','f':'c','i':'d','h':'x','k':'i','j':'u','m':'l','l':'g','o':'k','n':'b','p':'r','s':'n','r':'t','u':'j','t':'w','w':'f','v':'p','y':'a','x':'m'} | |
inf=open('file.in') | |
l1=int(inf.readline()) | |
ouf=open('file.out','w') | |
def trans(l): | |
return ''.join(d[x] for x in l) | |
for i in range(l1): | |
ouf.write('Case #%s: %s'%(i+1, trans(inf.readline()))) |