Convert single object to List
1 2 List<String> list = java.util.Arrays.asList("foo");
13469 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Philipp Meier http://fnogol.de/
1 2 List<String> list = java.util.Arrays.asList("foo");
1 public void setFocusTraversalPolicy(FocusTraversalPolicy policy)
1 setFocusCycleRoot(true)
1 2 container.setFocusTraversalPolicy(myCustomPolicy); 3 container.setFocusCycleRoot(true);
1 2 List<Date> listOfDates = Arrays.asList(arrayOfDates);
1 2 List<Date> listOfDates = Arrays.asList(new Date[]{date1, date2});
1 2 Date[] arrayOfDates = listOfDates.toArray(new Date[]{});
1 2 select dist, count(dist) 3 from (select round(pow(10,ceil(log(10,distance+0.0001)))) 4 as dist from cust\_with\_dist) as foo 5 group by dist
1 2 dist | count 3 ------+------- 4 0 | 142 5 10 | 235 6 100 | 111 7 1000 | 7
1 2 find /path/to/directory -type f -name '*.jar' -print0 | xargs -n1 -0i sh -c 'jar tf "{}" | grep -q query && echo "{}"'
1 2 find ~/soft/java/maven-repository -type f -name '*.jar' -print0 | xargs -n1 -0i sh -c 'jar tf "{}" | grep -q org.apache && echo "{}"'
1 2 public class BigDecimalFormatter extends NumberFormatter { 3 public Object stringToValue(String text) throws ParseException { 4 if("".equals(text.trim())) { 5 return null; 6 } 7 char ds = getDefaultLocaleDecimalSeparator(); 8 9 try { 10 String val = text; 11 if(ds != '.') { 12 val = val.replace(".", "").replace(ds, '.'); 13 } 14 return new BigDecimal(val); 15 } catch(NumberFormatException e) { 16 return null; 17 } 18 } 19 20 public String valueToString(Object value) throws ParseException { 21 return super.valueToString(value); 22 } 23 24 private char getDefaultLocaleDecimalSeparator() { 25 DecimalFormatSymbols symbols = new DecimalFormat("0").getDecimalFormatSymbols(); 26 char ds = symbols.getDecimalSeparator(); 27 return ds; 28 } 29 30 }
1 2 public class BigDecimalFormatterFactory extends JFormattedTextField.AbstractFormatterFactory { 3 public JFormattedTextField.AbstractFormatter getFormatter(JFormattedTextField tf) { 4 return new BigDecimalFormatter(); 5 } 6 }
1 2 bigdecimalfield.setFormatterFactory(new BigDecimalFormatterFactory());
1 2 JButton taskButton = new JButton(action); 3 taskButton.setBorder(BorderFactory.createEmptyBorder(2,2,2,2)); 4 taskButton.setHorizontalAlignment(JButton.LEADING); // optional 5 taskButton.setBorderPainted(false); 6 taskButton.setContentAreaFilled(false);
1 2 <form> 3 <input name="foo"> 4 <input type="submit" name="buttonAction.ok" value="submit"> 5 <input type="submit" name="buttonAction.cancel" value="cancel">
1 2 class FooAction implements Action { 3 private Map buttonAction = new HashMap(); 4 public Map getButtonAction() { return buttonAction; } 5 6 public String execute() { 7 if(buttonAction.containsKey("ok") { 8 // ok was pressed 9 } else if (buttonAction.containsKey("cancel") { 10 // cancel was 11 } else { 12 // no button was pressed (enter key?) 13 } 14 ... 15 } 16 }
1 2 private class RefreshAction extends AbstractAction { 3 4 private RefreshAction() { 5 super("Refresh\u2026"); 6 } 7 8 public void actionPerformed(ActionEvent e) { 9 ... 10 } 11 }
1 2 …