Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p>Some examples (inspired by the Java Enum Tutorial):</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY } def tellItLikeItIs(Day day) { switch (day) { case Day.MONDAY: println "Mondays are bad." break case Day.FRIDAY: println "Fridays are better." break case Day.SATURDAY: case Day.SUNDAY: println "Weekends are best." break default: println "Midweek days are so-so." break } } tellItLikeItIs(Day.MONDAY) // => Mondays are bad. tellItLikeItIs(Day.WEDNESDAY) // => Midweek days are so-so. tellItLikeItIs(Day.FRIDAY) // => Fridays are better. tellItLikeItIs(Day.SATURDAY) // => Weekends are best. </pre></td></tr></table><p>Or with a bit of refactoring, you could write the switch like this:</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>def today = Day.SATURDAY switch (today) { // Saturday or Sunday case [ Day.SATURDAY, Day.SUNDAY ]: println "Weekends are cool" break // a day between Monday and Friday case Day.MONDAY..Day.FRIDAY: println "Boring work day" break default: println "Are you sure this is a valid day?" } </pre></td></tr></table><p>Here is a coin example:</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>enum Coin { penny(1), nickel(5), dime(10), quarter(25) Coin(int value) { this.value = value } private final int value public int value() { return value } } assert Coin.values().size() == 4 def pocketMoney = 2 * Coin.quarter.value() + 5 * Coin.dime.value() assert pocketMoney == 100 // another way to do above def coins = [ Coin.quarter ] * 2 + [ Coin.dime ] * 5 println coins // => [ quarter, quarter, dime, dime, dime, dime, dime ] println coins.sum{ it.value() } // => 100 </pre></td></tr></table><p>Here is a planet example:</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>enum Planet { MERCURY(3.303e+23, 2.4397e6), VENUS(4.869e+24, 6.0518e6), EARTH(5.976e+24, 6.37814e6), MARS(6.421e+23, 3.3972e6), JUPITER(1.9e+27, 7.1492e7), SATURN(5.688e+26, 6.0268e7), URANUS(8.686e+25, 2.5559e7), NEPTUNE(1.024e+26, 2.4746e7) private final double mass // in kilograms private final double radius // in metres Planet(double mass, double radius) { this.mass = mass this.radius = radius } private double mass() { return mass } private double radius() { return radius } // universal gravitational constant (m3 kg-1 s-2) public static final double G = 6.67300E-11 double surfaceGravity() { return G * mass / (radius * radius) } double surfaceWeight(double otherMass) { return otherMass * surfaceGravity() } } double earthWeight = 75.0 // kg double mass = earthWeight/Planet.EARTH.surfaceGravity() for (p in Planet.values()) { printf("Your weight on %s is %f%n", p, p.surfaceWeight(mass)) } // => // Your weight on MERCURY is 28.331821 // Your weight on VENUS is 67.874932 // Your weight on EARTH is 75.000000 // Your weight on MARS is 28.405289 // Your weight on JUPITER is 189.791814 // Your weight on SATURN is 79.951165 // Your weight on URANUS is 67.884540 // Your weight on NEPTUNE is 85.374605 </pre></td></tr></table>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced