č£ē“™ http://backpaper0.github.io/ šŸ• en-us Thu, 22 Feb 2018 00:00:00 +0900 http://backpaper0.github.io/2018/02/22/spring_proxy.html http://backpaper0.github.io/2018/02/22/spring_proxy.html <![CDATA[Spring恮proxyćØfinalćƒ”ć‚½ćƒƒćƒ‰ć€ćć‚Œć‹ć‚‰null]]> Spring恮proxyćØfinalćƒ”ć‚½ćƒƒćƒ‰ć€ćć‚Œć‹ć‚‰null

恓恖恑恕悓恌恓悓ćŖę„Ÿć˜ć§ć‚ć”ć‚ƒć‚ć”ć‚ƒć—ć¦ć„ćŸć®ć§ć€č©³ć—ć„č³‡ę–™ćÆć©ć“ć«ć‚ć‚‹ć‹åˆ†ć‹ć‚‰ćŖć„ć‘ć‚Œć©ć€ćŖ恜恝恆ćŖć£ćŸć®ć‹č§£čŖ¬ć—ć‚ˆć†ćØę€ć„ć¾ć™ć€‚

ćŖ恜恝恆ćŖ悋恮恋ꦂ恭ē†č§£ć—ć¦ć„ćŸć‘ć‚Œć©ć€ē†č§£ć—恦恄ćŖć‹ć£ćŸē‚¹ć‚’čŖæć¹ć‚‹éŽēØ‹ć§ē§č‡Ŗčŗ«ć‚‚å­¦ć¶ć“ćØćŒć‚ć£ćŸć®ć§ć€ę­£ē›“恓恖恑恕悓恫ćÆčŖæć¹ć‚‹ćć£ć‹ć‘ć‚’ä½œć£ć¦ćć‚Œć¦ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć™ćØ恄恆ꄟ恘恧恙ļ¼

@RepositoryćØproxy

@Repository 悒ć‚Æćƒ©ć‚¹ć«ä»˜ć‘ć‚‹ćØć€ćć®ć‚Æćƒ©ć‚¹ć®proxyćŒä½œć‚‰ć‚Œć¾ć™ć€‚

proxy恦ćŖć‚“ć‚„ć­ć‚“ć£ć¦č©±ć§ć™ćŒć€ć“ć‚ŒćÆå®Ÿč”Œę™‚ć«ē”Ÿęˆć•ć‚Œć‚‹č©²å½“ć‚Æćƒ©ć‚¹ć®ć‚µćƒ–ć‚Æćƒ©ć‚¹ć§ć€ä»–ć®ć‚³ćƒ³ćƒćƒ¼ćƒćƒ³ćƒˆć«ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć•ć‚Œć‚‹ć®ćÆ恓恮proxyć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć§ć™ć€‚ å®Ÿéš›ć®ć‚Æćƒ©ć‚¹ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ćøćÆproxyć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ēµŒē”±ć—ć¦å§”č­²ć•ć‚Œć‚‹ä»•ēµ„ćæ恫ćŖć£ć¦ć„ć¾ć™ć€‚

恓恮proxy恮仕ēµ„ćæ恫ćÆć€ć‚³ćƒ³ćƒćƒ¼ćƒćƒ³ćƒˆć®åˆ©ē”Øč€…ćŒć‚¹ć‚³ćƒ¼ćƒ—ć‚’ę„č­˜ć—ćŖćć¦ć‚ˆććŖ悋ćØć„ć†åˆ©ē‚¹ćŒć‚ć‚Šć¾ć™ć€‚

恩恆恄恆恓ćØ恋态順悒čæ½ć£ć¦č¦‹ć¦ć„ćć¾ć—ć‚‡ć†ć€‚

proxyćØ恄恆ꦂåæµćŒē„”恄DIć‚³ćƒ³ćƒ†ćƒŠ

DIć‚³ćƒ³ćƒ†ćƒŠć«ćÆć‚¹ć‚³ćƒ¼ćƒ—ćØć„ć†ć‚‚ć®ćŒć‚ć‚Šć¾ć™ć€‚

恓悌ćÆć‚³ćƒ³ćƒćƒ¼ćƒćƒ³ćƒˆć®ćƒ©ć‚¤ćƒ•ć‚µć‚¤ć‚Æćƒ«ć‚’č”Ø恙悂恮恧态Webć‚¢ćƒ—ćƒŖć§å‹•ćDIć‚³ćƒ³ćƒ†ćƒŠć§ć‚ć‚Œć°ć€ŒćƒŖć‚Æć‚Øć‚¹ćƒˆć‚¹ć‚³ćƒ¼ćƒ—ć€ć‚„ć€Œć‚»ćƒƒć‚·ćƒ§ćƒ³ć‚¹ć‚³ćƒ¼ćƒ—ć€ć‚’ęŒć£ć¦ć„ć¾ć™ć€‚ 怌ćƒŖć‚Æć‚Øć‚¹ćƒˆć‚¹ć‚³ćƒ¼ćƒ—ć€ćÆćć®åć®é€šć‚ŠHTTPćƒŖć‚Æć‚Øć‚¹ćƒˆć®é–‹å§‹ć‹ć‚‰ēµ‚äŗ†ć¾ć§ć®é–“ć«ęœ‰åŠ¹ćØćŖć‚‹ć‚¹ć‚³ćƒ¼ćƒ—ć§ć™ć€‚ ć€Œć‚»ćƒƒć‚·ćƒ§ćƒ³ć‚¹ć‚³ćƒ¼ćƒ—ć€ć‚‚ćć®åć®é€šć‚Šć§ć‚»ćƒƒć‚·ćƒ§ćƒ³ć‚’é–‹å§‹ć—ć¦ć‹ć‚‰ē “ę£„ć•ć‚Œć‚‹ć¾ć§ć®é–“ć«ęœ‰åŠ¹ćØćŖć‚‹ć‚¹ć‚³ćƒ¼ćƒ—ć§ć™ć€‚

恧ćÆć€Œć‚»ćƒƒć‚·ćƒ§ćƒ³ć‚¹ć‚³ćƒ¼ćƒ—ć®ć‚³ćƒ³ćƒćƒ¼ćƒćƒ³ćƒˆć€ć‹ć‚‰ć€ŒćƒŖć‚Æć‚Øć‚¹ćƒˆć‚¹ć‚³ćƒ¼ćƒ—ć®ć‚³ćƒ³ćƒćƒ¼ćƒćƒ³ćƒˆć€ć‚’ä½æē”Ø恙悋恓ćØć‚’č€ƒćˆć¦ćæć¾ć—ć‚‡ć†ć€‚ ć‚³ćƒ¼ćƒ‰ć§ę›ø恏ćØ恓悓ćŖꄟ恘怂

//ā€»ć“ć‚ŒćÆSpring恧ćÆćŖ恄Ꞷē©ŗ恮DIć‚³ćƒ³ćƒ†ćƒŠć®ć‚³ćƒ¼ćƒ‰

@SessionScope
public class Hoge {

    @Inject
    private Fuga fuga;

    public void action() {
        fuga.process();
    }
}

@RequestScope
public class Fuga {
    //ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć‚„ćƒ”ć‚½ćƒƒćƒ‰ć®å®šē¾©ćÆēœē•„
}

恓恮 Hoge ćØ Fuga 悒ä½æć£ćŸå‡¦ē†ć®ęµć‚ŒćÆ态

  1. HTTPćƒŖć‚Æć‚Øć‚¹ćƒˆć‚’å—ć‘å–ć‚‹
  2. ć‚»ćƒƒć‚·ćƒ§ćƒ³ć‚’ä½œęˆć™ć‚‹
  3. Hoge ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ä½œęˆć™ć‚‹
  4. Fuga ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ä½œęˆć™ć‚‹
  5. Hoge 恫 Fuga ć‚’ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć™ć‚‹
  6. Hoge 恮 action ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œć™ć‚‹
  7. Fuga 恮 process ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œć™ć‚‹
  8. HTTPćƒŖć‚Æć‚Øć‚¹ćƒˆćŒēµ‚äŗ†ć™ć‚‹
  9. Fuga ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’DIć‚³ćƒ³ćƒ†ćƒŠć‹ć‚‰ē “ę£„ć™ć‚‹
  10. HTTPćƒ¬ć‚¹ćƒćƒ³ć‚¹ć‚’čæ”恙

ćØ恄恆ꄟ恘怂

ć‚ć‚“ć¾ć‚Šå•é”ŒćŖć•ćć†ć«č¦‹ćˆć¾ć™ćŒć€ Fuga 恮 process ćƒ”ć‚½ćƒƒćƒ‰ćŒå®Ÿč”Œäø­ć«åŒć˜ćƒ¦ćƒ¼ć‚¶ćƒ¼ć‹ć‚‰ć‚‚恆äø€ć¤HTTPćƒŖć‚Æć‚Øć‚¹ćƒˆćŒę„ćŸć‚‰ć©ć†ćŖ悋恧恗悇恆恋ļ¼Ÿ

  1. HTTPćƒŖć‚Æć‚Øć‚¹ćƒˆAć‚’å—ć‘å–ć‚‹
  2. ć‚»ćƒƒć‚·ćƒ§ćƒ³ć‚’ä½œęˆć™ć‚‹
  3. Hoge ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ä½œęˆć™ć‚‹
  4. Fuga ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ä½œęˆć™ć‚‹ļ¼ˆćƒŖć‚Æć‚Øć‚¹ćƒˆAć®ć‚¹ć‚³ćƒ¼ćƒ—ļ¼‰
  5. Hoge 恫 Fuga ć‚’ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć™ć‚‹
  6. Hoge 恮 action ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œć™ć‚‹
  7. Fuga 恮 process ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œć—å§‹ć‚ć‚‹
  8. HTTPćƒŖć‚Æć‚Øć‚¹ćƒˆBć‚’å—ć‘å–ć‚‹
  9. Fuga ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ä½œęˆć™ć‚‹ļ¼ˆćƒŖć‚Æć‚Øć‚¹ćƒˆBć®ć‚¹ć‚³ćƒ¼ćƒ—ļ¼‰
  10. Hoge 恫 Fuga ć‚’ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć™ć‚‹ā€¦ā€¦ļ¼ļ¼Ÿ

ćØć¾ć‚ć€ć“ć‚“ćŖꄟ恘恧 Hoge ć«ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć•ć‚Œć‚‹ Fuga ćŒćƒćƒƒćƒ†ć‚£ćƒ³ć‚°ć™ć‚‹ć‚ć‘ć§ć™ć€‚

恝恆恄恆悏恑恧proxy恮ē„”恄DIć‚³ćƒ³ćƒ†ćƒŠć§ćÆć€ć‚ć‚‹ć‚¹ć‚³ćƒ¼ćƒ—ć®ć‚³ćƒ³ćƒćƒ¼ćƒćƒ³ćƒˆć«ćÆć€ćć‚Œć‚ˆć‚Šć‚‚å°ć•ć„ć‚¹ć‚³ćƒ¼ćƒ—ļ¼ˆćƒ©ć‚¤ćƒ•ć‚µć‚¤ć‚Æćƒ«ćŒēŸ­ć„ćØčØ€ć„ę›ćˆć¦ć‚‚č‰Æ恕恝恆ļ¼‰ć®ć‚³ćƒ³ćƒćƒ¼ćƒćƒ³ćƒˆć‚’ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć§ćć¾ć›ć‚“ć§ć—ćŸć€‚ proxy恌ē„”ćć¦ć“ć®ć‚ˆć†ćŖ制ē“„恮恂悋DIć‚³ćƒ³ćƒ†ćƒŠćØ恗恦ćÆSeasar2ćŒęŒ™ć’ć‚‰ć‚Œć¾ć™ć€‚

proxy恌恂悋DIć‚³ćƒ³ćƒ†ćƒŠ

å…ˆć«čæ°ć¹ćŸå•é”Œć‚’proxyćŒć©ć®ć‚ˆć†ć«č§£ę±ŗć™ć‚‹ć®ć‹č¦‹ć¦ć„ćć¾ć—ć‚‡ć†ć€‚

Fuga 恮proxyć‚’ć‚³ćƒ¼ćƒ‰ć§ę›ø恏ćØ恓悓ćŖę„Ÿć˜ć«ćŖć‚Šć¾ć™ć€‚

//å®Ÿéš›ć«ćÆå®Ÿč”Œę™‚ć«ć‚Æćƒ©ć‚¹ćƒ•ć‚”ć‚¤ćƒ«ćŒē”Ÿęˆć•ć‚Œć‚‹ć®ć§ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ćÆ存åœØ恗ćŖ恄
//ć‚ćć¾ć§ć‚‚proxyć®ć‚¤ćƒ”ćƒ¼ć‚ø
public class FugaProxy extends Fuga {

    private Container container;

    public void process() {
        Fuga component = container.getComponent(Fuga.class);
        component.process();
    }
}

ć‚³ćƒ¼ćƒ‰äøŠć®ć‚³ćƒ”ćƒ³ćƒˆć«ć‚‚ę›øćć¾ć—ćŸćŒć€proxyćÆå®Ÿéš›ć«ćÆå®Ÿč”Œę™‚ć«ć‚Æćƒ©ć‚¹ćƒ•ć‚”ć‚¤ćƒ«ļ¼ˆćØć„ć†ć‹ć‚¤ćƒ³ćƒ”ćƒ¢ćƒŖäøŠć«ćƒć‚¤ćƒˆć‚³ćƒ¼ćƒ‰ć®ćƒ‡ćƒ¼ć‚æļ¼‰ćØ恗恦ē”Ÿęˆć•ć‚Œć‚‹ć®ćŒę™®é€šćŖć®ć§ć€ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ćÆć‚ć‚Šć¾ć›ć‚“ć€‚ ć‚³ćƒ¼ćƒ‰ä¾‹ćÆé›°å›²ę°—ć§ć™ć€‚

ć‚³ćƒ¼ćƒ‰ć‚’č¦‹ć¦ćæ悋ćØ process ćƒ”ć‚½ćƒƒćƒ‰ćŒå‘¼ć°ć‚Œć‚‹ćØDIć‚³ćƒ³ćƒ†ćƒŠć‹ć‚‰proxy恧ćÆćŖć„å®Ÿéš›ć® Foo ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ćŒå–ć‚Šå‡ŗć•ć‚Œć€ćć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć® process ćƒ”ć‚½ćƒƒćƒ‰ćŒå‘¼ć°ć‚Œć¦ć„ć¾ć™ć€‚

å…ˆć»ć©ć®proxy恌ē„”恄DIć‚³ćƒ³ćƒ†ćƒŠć§ Fuga ćŒćƒćƒƒćƒ†ć‚£ćƒ³ć‚°ć—ć¦ć—ć¾ć£ćŸć‚·ćƒŠćƒŖć‚Ŗ悒态proxy恌恂悋DIć‚³ćƒ³ćƒ†ćƒŠć§ćÆ恩恆ćŖ悋恋見恦ćæć¾ć—ć‚‡ć†ć€‚

  1. HTTPćƒŖć‚Æć‚Øć‚¹ćƒˆAć‚’å—ć‘å–ć‚‹
  2. ć‚»ćƒƒć‚·ćƒ§ćƒ³ć‚’ä½œęˆć™ć‚‹
  3. Hoge ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ä½œęˆć™ć‚‹
  4. Fuga ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ä½œęˆć™ć‚‹ļ¼ˆćƒŖć‚Æć‚Øć‚¹ćƒˆAć®ć‚¹ć‚³ćƒ¼ćƒ—ļ¼‰
  5. Fuga 恮proxyć‚’ä½œęˆć™ć‚‹
  6. Hoge 恫 Fuga 恮proxyć‚’ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć™ć‚‹
  7. Hoge 恮 action ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œć™ć‚‹
  8. Fuga 恮proxy恮 process ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œć—å§‹ć‚ć‚‹
  9. Fuga 恮proxyå†…ć§DIć‚³ćƒ³ćƒ†ćƒŠć‹ć‚‰å®Ÿéš›ć® Fuga ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ļ¼ˆćƒŖć‚Æć‚Øć‚¹ćƒˆAć®ć‚¹ć‚³ćƒ¼ćƒ—ļ¼‰ć‚’å–ć‚Šå‡ŗ恗恦 process ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œć—å§‹ć‚ć‚‹
  10. HTTPćƒŖć‚Æć‚Øć‚¹ćƒˆBć‚’å—ć‘å–ć‚‹
  11. Fuga ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ä½œęˆć™ć‚‹ļ¼ˆćƒŖć‚Æć‚Øć‚¹ćƒˆBć®ć‚¹ć‚³ćƒ¼ćƒ—ļ¼‰
  12. Hoge 恮 action ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œć™ć‚‹
  13. Fuga 恮proxy恮 process ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œć—å§‹ć‚ć‚‹
  14. Fuga 恮proxyå†…ć§DIć‚³ćƒ³ćƒ†ćƒŠć‹ć‚‰å®Ÿéš›ć® Fuga ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ļ¼ˆćƒŖć‚Æć‚Øć‚¹ćƒˆBć®ć‚¹ć‚³ćƒ¼ćƒ—ļ¼‰ć‚’å–ć‚Šå‡ŗ恗恦 process ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œć—å§‹ć‚ć‚‹

ć“ć®ć‚ˆć†ć«proxy悒ēµŒē”±ć—恦DIć‚³ćƒ³ćƒ†ćƒŠć‹ć‚‰ē•°ćŖ悋 Fuga ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’å–ć‚Šå‡ŗ恗恦 process ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œć§ćć¾ć—ćŸć€‚

仄äøŠć®ć“ćØ恋悉proxy恌恂悋DIć‚³ćƒ³ćƒ†ćƒŠć§ćÆć‚¹ć‚³ćƒ¼ćƒ—ć‚’ę„č­˜ć™ć‚‹ć“ćØćŖćć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć‚’č”Œćˆć‚‹ć“ćØćŒåˆ†ć‹ć‚Šć¾ć—ćŸć€‚

finalćƒ”ć‚½ćƒƒćƒ‰ć‹ć‚‰ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć‚’å‚ē…§ć—ćŸć‚‰null恫ćŖć£ćŸē†ē”±

å½“åˆć®å•é”Œć«ęˆ»ć‚Šć¾ć—ć‚‡ć†ć€‚ 怌 @Respository ć‚’ä»˜ć‘ćŸć‚Æćƒ©ć‚¹ć® final ćŖćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œć™ć‚‹ćØć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć•ć‚ŒćŸćÆćšć®ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ćøć‚¢ć‚Æć‚»ć‚¹ć—ćŸćØćć« NullPointerException 恌ē™ŗē”Ÿć—ćŸć€ćØć„ć†å•é”Œć§ć™ć€‚

ę¬”ć®ć‚³ćƒ¼ćƒ‰ć‚’č¦‹ć¦ćć ć•ć„ć€‚

@Repository
public class Foo {

    @Autowired
    private Bar bar;

    public String method1() {
        return String.format("%s%n%s%n", bar, getClass());
    }

    public final String method2() {
        return String.format("%s%n%s%n", bar, getClass());
    }
}

method1 ćØ method2 ćÆć©ć”ć‚‰ć‚‚ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ bar ćØč‡Ŗ分č‡Ŗčŗ«ć®ć‚Æćƒ©ć‚¹ć‚’ę–‡å­—åˆ—ć«ć—ć¦čæ”ć—ć¦ć„ć¾ć™ć€‚ ē•°ćŖ悋ē‚¹ćÆ method2 ćÆ final 恧恂悋ćØ恄恆恓ćØ恠恑恧恙怂

method1 ć®å®Ÿč”ŒēµęžœćÆ恓恔悉怂

com.example.demo.Bar@1db75e25
class com.example.demo.Foo

method2 ć®å®Ÿč”ŒēµęžœćÆ恓恔悉怂

null
class com.example.demo.Foo$$EnhancerBySpringCGLIB$$a65476ff

å½“åˆć®å•é”ŒćØåŒć˜ć‚ˆć†ć« final ćŖę–¹ć® method2 恧ćÆ bar 恌 null 恫ćŖć£ć¦ć„ć¾ć™ć­ć€‚

恟恠态ć‚Æćƒ©ć‚¹åć«ć‚‚ę³Øē›®ć—ć¦ćć ć•ć„ć€‚ method1 恧ćÆ Foo ćØćŖć£ć¦ć„ć¾ć™ćŒ method2 ćÆ Foo 恮proxy恫ćŖć£ć¦ć„ć¾ć™ć€‚

恓恓恧 Foo 恮proxyćŒć©ć†ćŖć£ć¦ć„ć‚‹ć®ć‹ć€å†ć³é›°å›²ę°—ć§ć‚³ćƒ¼ćƒ‰ć«ć—ć¦ćæć¾ć—ć‚‡ć†ć€‚

//é›°å›²ę°—
public class Foo$$EnhancerBySpringCGLIB$$a65476ff extends Foo {

    Container container;

    @Override
    public String method1() {
        Foo component = container.getComponent(Foo.class);
        return component.method1();
    }

    //method2ćÆfinalćŖ恮恧override恧恍ćŖ恄
}

恔覧恮通悊 method1 ćÆć‚³ćƒ³ćƒ†ćƒŠć‹ć‚‰å®Ÿéš›ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’å–ć‚Šå‡ŗć—ć¦å§”č­²ć—ć¦ć„ć¾ć™ćŒć€ method2 ćÆ final ćŖ恟悁 override ć§ććšć«å®Ÿéš›ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć«å§”č­²ć•ć‚Œć‚‹ć“ćØćŖćå®Ÿč”Œć•ć‚Œć¦ć—ć¾ć„ć¾ć™ć€‚

proxyćÆć€ć‚³ćƒ³ćƒ†ćƒŠć‹ć‚‰å®Ÿéš›ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’å–ć‚Šå‡ŗć—ć¦å§”č­²ć™ć‚‹ć‚‚ć®ćŖ恮恧态proxy恫åÆ¾ć—ć¦ć‚³ćƒ³ćƒćƒ¼ćƒćƒ³ćƒˆć‚’ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć™ć‚‹ę„å‘³ćÆć‚ć‚Šć¾ć›ć‚“ć€‚ å®Ÿéš›ć€å…ƒć®ć‚Æćƒ©ć‚¹ć§ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³åÆ¾č±”ćØćŖć£ć¦ć„ć‚‹ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ćÆproxy恧ćÆ null 恫ćŖć‚Šć¾ć™ć€‚

仄äøŠćŒć€proxyćŒä½œć‚‰ć‚Œć‚‹ć‚Æćƒ©ć‚¹ć«å®šē¾©ć•ć‚ŒćŸ final ćƒ”ć‚½ćƒƒćƒ‰ćŒć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³åÆ¾č±”ć®ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć‚’å‚ē…§ć—ć¦ć„ć‚‹å “åˆć« NullPointerException 恫ćŖ悋ē†ē”±ć§ć™ć€‚

ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ćØproxy

ć•ć¦ć€ć“ć“ć‹ć‚‰ćŒē§ć‚‚åˆć‚ć¦ēŸ„ć£ćŸäŗ‹ęŸ„恫ćŖć‚Šć¾ć™ć€‚ ä¹…ć—ć¶ć‚Šć«ć³ć£ćć‚Šć—ćŸć€‚

ę¬”ć®ć‚ˆć†ć«ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć—ć¦ć„ć‚‹ć‚Æćƒ©ć‚¹ć‚’č€ƒćˆć¦ćæć¾ć—ć‚‡ć†ć€‚

@Repository
public class Foo {

    private final Bar bar;

    public Foo(Bar bar) {
        this.bar = Objects.requireNonNull(bar);
    }

    public String method1() {
        return String.format("%s%n%s%n", bar, getClass());
    }

    public final String method2() {
        return String.format("%s%n%s%n", bar, getClass());
    }
}

proxyć®é›°å›²ę°—ć‚³ćƒ¼ćƒ‰ćÆ恓悓ćŖꄟ恘怂

//é›°å›²ę°—
public class Foo$$EnhancerBySpringCGLIB$$a65476ff extends Foo {

    Container container;

    public Foo$$EnhancerBySpringCGLIB$$a65476ff(Bar bar) {
        super(bar);
    }

    @Override
    public String method1() {
        Foo component = container.getComponent(Foo.class);
        return component.method1();
    }

    //method2ćÆfinalćŖ恮恧override恧恍ćŖ恄
}

ć“ć®å “åˆć€ē”Ÿęˆć•ć‚Œć‚‹proxyć®ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æå¼•ę•° bar 恫ćÆä½•ćŒå…„ć‚‹ć®ć§ć—ć‚‡ć†ć‹ļ¼Ÿ

å…ˆć«čæ°ć¹ćŸé€šć‚Šć€proxyć®ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³åÆ¾č±”ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć«ćÆć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć™ć‚‹ę„å‘³ćÆć‚ć‚Šć¾ć›ć‚“ć€‚ 恋ćØčØ€ć£ć¦ null 悒ęø”恙ćØć‚¹ćƒ¼ćƒ‘ćƒ¼ć‚Æćƒ©ć‚¹ć®ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ恧 Objects.requireNonNull ć«ć‚ˆć£ć¦ NullPointerException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

恝悌恧ćÆSpringćÆproxyć‚’ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć™ć‚‹ćØćć«ä½•ć‚’ęø”恙恮恧恗悇恆恋ļ¼Ÿ

č‰²ć€…ćØćŒć‚“ć°ć£ć¦ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ć‚’čæ½ć£ć‹ć‘ćŸęœ«ć«åˆ†ć‹ć£ćŸć®ć§ć™ćŒć€ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æć‚’å‘¼ć°ćšć«ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć—ć¦ć„ć¾ć—ćŸć€‚ ä½•ć‚’čØ€ć£ć¦ć„ć‚‹ć®ć‹åˆ†ć‹ć‚Šć¾ć›ć‚“ć­ļ¼Ÿ

proxyć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć«ćÆObjenesisćØć„ć†ćƒ©ć‚¤ćƒ–ćƒ©ćƒŖ恮ꬔ恮ć‚Æćƒ©ć‚¹ćŒä½æć‚ć‚Œć¦ć„ć¾ć—ćŸć€‚ ļ¼ˆå®Ÿéš›ć«ćÆ org.springframework.objenesis 恫repackageć•ć‚Œć¦ć„ć¾ć™ļ¼‰

ć‚Æćƒ©ć‚¹ć®Javadoc恫ꬔ恮čØ˜č¼‰ćŒć‚ć‚Šć¾ć™ć€‚

Instantiates an object, WITHOUT calling itā€™s constructor, using internal sun.reflect.ReflectionFactory

恊态恊恆ā€¦ā€¦ļ¼ ć£ć¦ę„Ÿć˜ć§ć™ćŒć€JDK恮internalćŖć‚Æćƒ©ć‚¹ć‚’ä½æć£ć¦ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æć‚’å‘¼ć°ćšć«ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć—ć¦ć„ć¾ć—ćŸć€‚ ć ć‹ć‚‰ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ćŒ null ć ć£ćŸć€ćØ恄恆悏恑恧恙恭怂

ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æå‘¼ć°ć‚ŒćŖć„ć£ć¦ć©ć†ć„ć†ć“ćØ恠悈ā€¦ā€¦ćØꀝ恄ćŖ恌悉 SunReflectionFactoryInstantiator 悒ēœŗć‚ć¦ć„ćŸć‚‰ newConstructorForSerialization ćØć„ć†ćƒ”ć‚½ćƒƒćƒ‰åćŒå‡ŗć¦ćć¦ć€ćć†ć„ćˆć°ć‚·ćƒŖć‚¢ćƒ©ć‚¤ć‚ŗ恕悌恟ć‚Ŗ惖ć‚ø悧ć‚Æćƒˆć‚’ćƒ‡ć‚·ćƒŖć‚¢ćƒ©ć‚¤ć‚ŗć™ć‚‹ę™‚ć£ć¦ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æå‘¼ć°ć‚ŒćŖć„ć‚“ć ć£ć‘ć€ćØ恋雑ćŖčØ˜ę†¶ć§é›‘ć«ę€ć„ć¾ć—ćŸć€‚ ćØ恋ę›øć„ć¦ćŠććØč©³ć—ć„äŗŗćŒć‚³ćƒ”ćƒ³ćƒˆćć‚Œć‚‹ćÆ恚恧恙怂 ä»–åŠ›ęœ¬é”˜ć€‚

ć¾ćØ悁

  • DIć‚³ćƒ³ćƒ†ćƒŠć«ćÆproxy悒ēµŒē”±ć—ć¦ć‚¹ć‚³ćƒ¼ćƒ—ć‚’ę„č­˜ć›ćšć«ä½æćˆć‚‹ę©Ÿčƒ½ćŒć‚ć‚‹
  • proxyćÆå®Ÿč”Œę™‚ć«ć‚µćƒ–ć‚Æćƒ©ć‚¹ć‚’ē”Ÿęˆć—ć¦å®Ÿē¾ć™ć‚‹ć®ć§ final ćƒ”ć‚½ćƒƒćƒ‰ć‚’ä½æ恆ćØ惞ć‚ŗ恄
  • Spring恧ćÆproxyćÆJDK恮internalćŖć‚Æćƒ©ć‚¹ć‚’ä½æē”Øć—ć¦ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æå‘¼ć³å‡ŗ恗ē„”ć—ć«ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć•ć‚Œć‚‹ļ¼ˆćć®ēµęžœćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ćŒ null 恫ćŖ悋ļ¼‰

恓悓ćŖę„Ÿć˜ć§ć€å‰²ćØēœŸć£é»’ćŖ黒魔蔓恫č¾æ悊ē€ć„ćŸę„ŸćŒć‚ć£ć¦ę„½ć—ć‹ć£ćŸć§ć™ć€‚ 恓恖恑恕悓态恂悊恌ćØ恆ļ¼

恔ćŖćæ恫

INFO ćƒ¬ćƒ™ćƒ«ć§ć™ćŒć€ćƒ­ć‚°ćÆå‡ŗ恦恄悋ćæ恟恄恧恙怂

018-02-22 22:22:14.298  INFO 25770 --- [  restartedMain] o.s.aop.framework.CglibAopProxy          : Final method [public final java.lang.String com.example.demo.Foo.method2()] cannot get proxied via CGLIB: Calls to this method will NOT be routed to the target instance and might lead to NPEs against uninitialized fields in the proxy instance.
]]>
Thu, 22 Feb 2018 00:00:00 +0900
http://backpaper0.github.io/2017/04/17/acrobook.html http://backpaper0.github.io/2017/04/17/acrobook.html <![CDATA[怌Javaęœ¬ę ¼å…„é–€ć€ć‚’čŖ­ć‚“恠]]> 怌Javaęœ¬ę ¼å…„é–€ć€ć‚’čŖ­ć‚“恠

恛悍恕悓 恫ēŒ®ęœ¬ć—ć¦č²°ć„ć¾ć—ćŸć€‚ 恂悊恌ćØć†ć”ć–ć„ć¾ć™ļ¼

ć“ć®ęœ¬ćÆJavać®å…„é–€ę›ø恧ćÆć‚ć‚Šć¾ć™ćŒć€Œęœ¬ę ¼ć€ćØä»˜ć„ć¦ć„ć‚‹ć ć‘ć‚ć£ć¦ć€

  • ć‚³ćƒ¬ć‚Æć‚·ćƒ§ćƒ³ć®å®Ÿč£…ć«čøćæč¾¼ć‚“ć§ć©ć®å “é¢ć§ć©ć®å®Ÿč£…ć‚’ä½æć†ć¹ćć‹
  • Map#computeIfAbsent 恮ē¾å “恂悋恂悋ćŖä½æć„ę–¹
  • ę­£č¦č”Øē¾é–¢é€£ć®ć‚Ŗ惖ć‚ø悧ć‚Æ惈( Pattern 态 Matcher )ćØ String ć®ćƒ”ć‚½ćƒƒćƒ‰ć®ä½æć„åˆ†ć‘

ćŖć©ć€å®Ÿč·µēš„ćŖå†…å®¹ćŒå«ć¾ć‚Œć¦ć„ć¾ć™ć€‚

ć¾ćŸć€Java 8ć‚’å‰ęćØ恗恦ę›øć‹ć‚Œć¦ćÆć„ć¾ć™ćŒć€ ćƒ•ć‚”ć‚¤ćƒ«ę“ä½œć«é–¢ć—ć¦ćÆJava 6ć¾ć§ć®ć‚„ć‚Šę–¹( java.io )ćØJava 7ä»„é™ć®ć‚„ć‚Šę–¹( java.nio.file )恌态 ę—„ę™‚ę“ä½œć«é–¢ć—ć¦ćÆJava 7ć¾ć§ć®ć‚„ć‚Šę–¹( java.util.Date 态 java.util.Calendar )ćØJava 8ä»„é™ć®ć‚„ć‚Šę–¹( java.time )恌äø”ę–¹ę›øć‹ć‚Œć¦ć„ć¾ć™ć€‚ č¶£å‘³ćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°ćŖć‚‰ć„ć¤ć§ć‚‚ęœ€ę–°ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ć‚’ä½æć£ć¦ć„ć‚Œć°č‰Æć„ć§ć™ćŒć€ä»•äŗ‹ć§ćÆę”ˆä»¶ć«ć‚ˆć£ć¦ćÆäæå®ˆć ć‘ć«å¾¹ć—ć¦ćŠć‚Šå¤ć„ć‚„ć‚Šę–¹ć§ć‚³ćƒ¼ćƒ‰ć‚’čŖ­ćæę›ø恍恙悋åæ…č¦ćŒć‚ć‚‹å “åˆć‚‚ć‚ć‚‹ć§ć—ć‚‡ć†ć€‚ ć“ć®ęœ¬ćŖć‚‰ćƒ¬ć‚¬ć‚·ćƒ¼ćØęœ€ę–°ć®ć©ć”ć‚‰ć®ć‚„ć‚Šę–¹ć‚‚å­¦ć¶äŗ‹ćŒć§ćć¾ć™ć€‚

ä»–ć«ć‚‚ć€ę–‡ę³•ēš„恫čرåÆć•ć‚Œć¦ćÆć„ć‚‹ćŒå®Ÿč·µēš„ćŖč¦³ē‚¹ć‹ć‚‰ę›ø恋ćŖć„ę–¹ćŒč‰Æć„ć‚³ćƒ¼ćƒ‰ć‚’ę•™ćˆć¦ćć‚ŒćŸć‚Šć€ ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ćØęŠ½č±”ć‚Æćƒ©ć‚¹ć®č‰Æ恄ä½æć„åˆ†ć‘ę–¹ć‚’ē¤ŗć—ć¦ćć‚ŒćŸć‚Šć€ 執ē­†é™£ć®ēŸ„識惻ēµŒéØ“ć‚’å…ƒć«ę›øć‹ć‚Œć¦ć„ć‚‹ć“ćØćŒå˜ćŖć‚‹åˆåæƒč€…å‘ć‘ć®å…„門ę›øćØćÆē•°ćŖ悋ćØ恓悍恠ćØę„Ÿć˜ć¾ć—ćŸć€‚

ē§ć®ę„Ÿč¦šć§ć„恆ćØć€ć¾ć£ćŸćć®ę–°äŗŗ恧ćÆćŖ恏ē¾å “恫å‡ŗ恦2幓ē›®ć‚悋恄ćÆ3幓ē›®ćć‚‰ć„ćŒć“ć®ęœ¬ć‚’čŖ­ć‚€ć®ć«é©ć—ćŸćƒ¬ćƒ™ćƒ«ć‹ćŖ态ćØę€ć„ć¾ć™ć€‚

間違恄ćØꀝ悏悌悋čؘčæ°

ć„ćć¤ć‹é–“é•ć„ćŒć‚ć£ćŸć®ć§ęŒ™ć’ć¦ćŠć“ć†ćØę€ć„ć¾ć™ć€‚

35ćƒšćƒ¼ć‚ø态 >> ę¼”ē®—å­ć®čŖ¬ę˜Ž

ę­£č² ć®ē¬¦å·ć‚’č”Ø恙惓惃惈ćÆäæęŒć—ć€ćć‚Œä»„å¤–ć®ē©ŗ恄恟惓惃惈ćÆ0åŸ‹ć‚ć™ć‚‹ć€‚

å³ę–¹å‘ć®ē®—č”“ć‚·ćƒ•ćƒˆćÆē©ŗ恄恟惓惃惈悒0åŸ‹ć‚ć™ć‚‹ć®ć§ćÆćŖ恏态ē¬¦å·ćØåŒć˜ćƒ“ćƒƒćƒˆć§åŸ‹ć‚ć¾ć™ć€‚

82ćƒšćƒ¼ć‚øć€ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ć®čŖ¬ę˜Ž

ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ćÆåæ…恚public恫ćŖć‚‹ćŸć‚ć€ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹åć®å‰ć«ę›ø恏publicćÆēœē•„恙悋恓ćØćŒć§ćć¾ć™ć€‚

ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹åć®å‰ć® public 悒ēœē•„恙悋ćØćƒ‘ćƒƒć‚±ćƒ¼ć‚øćƒ—ćƒ©ć‚¤ćƒ™ćƒ¼ćƒˆć«ćŖć‚Šć¾ć™ć€‚

ć¾ćŸć€ćƒć‚¹ćƒˆć—ćŸć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ćÆ private 恫恙悋恓ćØć‚‚ć§ćć¾ć™ć€‚

156ćƒšćƒ¼ć‚øć€ćƒ”ć‚½ćƒƒćƒ‰å‚ē…§ć®ę–‡ę³•

恓悌ćÆ間違恄ćØ恄恆悈悊态č”Øć®å†…å®¹ćŒč¶³ć‚Šć¦ć„ćŖ恄ćØę€ć‚ć‚Œć¾ć™ć€‚

staticćƒ”ć‚½ćƒƒćƒ‰ć‚’å‚ē…§ć™ć‚‹čØ˜ę³•ć®ć²ćØ恤ćØć—ć¦ę¬”ć®ć‚‚ć®ć‚’ęŒ™ć’ć¦ć„ć¾ć™ć€‚

{ć‚Æćƒ©ć‚¹å}::{ćƒ”ć‚½ćƒƒćƒ‰å}

ć§ć‚‚ć“ć‚Œć€å “åˆć«ć‚ˆć£ć¦ćÆć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć®ćƒ”ć‚½ćƒƒćƒ‰ć‚’å‚ē…§ć™ć‚‹čØ˜ę³•ćØ恗恦悂ä½æćˆć¾ć™ć€‚

ä¾‹ćˆć°ć€ę¬”ć®ć‚ˆć†ćŖć‚³ćƒ¼ćƒ‰ć§ć™ć€‚

//{ć‚Æćƒ©ć‚¹å}::{ćƒ”ć‚½ćƒƒćƒ‰å}恮čØ˜ę³•ć§ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć®ćƒ”ć‚½ćƒƒćƒ‰ć‚’å‚ē…§ć—恦恄悋
ToIntFunction<String> f = String::length;
int i = f.applyAsInt("foobar");

197ćƒšćƒ¼ć‚øć€ćƒ©ćƒ ćƒ€å¼å†…ć§ć®ä¾‹å¤–ć«ć¤ć„ć¦

ćƒ©ćƒ ćƒ€ć®äø­ć«čؘčæ°ć—ćŸå‡¦ē†ć§ä¾‹å¤–ćŒē™ŗē”Ÿć™ć‚‹åÆčƒ½ę€§ćŒć‚ć‚Šć¾ć™ć€‚ ćć‚ŒćŒę¤œęŸ»ä¾‹å¤–ć ć£ćŸå “åˆćÆ态ꍕꍉ恗ćŖ恄ćØć€ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć‚Øćƒ©ćƒ¼ćŒē™ŗē”Ÿć—ć¾ć™ć€‚

Stream API恧ä½æć‚ć‚Œć‚‹ćƒ©ćƒ ćƒ€å¼ć€ć¤ć¾ć‚Š Function 悄 Predicate 恧恂悌恰恝恆恧恙恌态 ä¾‹ćˆć° Callable ć®ćƒ©ćƒ ćƒ€å¼ć§ć‚ć‚Œć° call ćƒ”ć‚½ćƒƒćƒ‰ćÆ throws Exception ćØ宣čØ€ć•ć‚Œć¦ć„ć‚‹ć®ć§ Exception 悒 catch 恙悋åæ…要ćÆć‚ć‚Šć¾ć›ć‚“ć€‚

ćć®ä»–ć®č»½ć„é–“é•ć„

108ćƒšćƒ¼ć‚øć€ćƒ•ć‚£ćƒœćƒŠćƒƒćƒę•°ć‚’ę±‚ć‚ć‚‹å®šē¾©ćØć‚³ćƒ¼ćƒ‰ćŒę›øć‹ć‚Œć¦ć„ć¾ć™ćŒć€å®šē¾©ć‚’見悋ćØ F0 = 0 F1 = 1 Fn = ... ćØćŖć£ć¦ć„ć¾ć™ćŒć€ ē›“å¾Œć«čØ˜č¼‰ć•ć‚Œć¦ć„ć‚‹ę˜”ćŖćŒć‚‰ć® for ćƒ«ćƒ¼ćƒ—ć‚’ä½æć£ćŸć‚³ćƒ¼ćƒ‰ćÆ i <= 1 恮ćØćć« 1 ć‚’ä»£å…„ć—ć¦ć„ć‚‹ć®ć§ć€ 定ē¾©ćØć‚³ćƒ¼ćƒ‰ćŒåˆć£ć¦ćŖ恄恧恙恭怂

恝悌ćØ134ćƒšćƒ¼ć‚ø态怌Mapć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ć§ć®č¦ē“ ć®å–å¾—ć€å¤‰ę›ć€ć«å€¤ć®é›†åˆć‚’å–å¾—ć™ć‚‹ćƒ”ć‚½ćƒƒćƒ‰ćØ恗恦 valueSet ćŒęŒ™ć’ć‚‰ć‚Œć¦ć„ć¾ć™ćŒ values 恮間違恄恠ćØę€ć„ć¾ć™ć€‚ ćŖ恊态 values ć®ęˆ»ć‚Šå€¤ćÆ集合( Set )恧ćÆćŖćć‚³ćƒ¬ć‚Æć‚·ćƒ§ćƒ³( Collection )恧恙怂

恂ćØć€ć‚ć£ć”ć‚ƒē“°ć‹ć„ćØ恓悍恧čØ€ć†ćØ态183ćƒšćƒ¼ć‚ø恫AutoClosable态ClosablećØ恄恆čؘčæ°ćŒć‚ć‚Šć¾ć™ćŒć€ ę­£ć—ććÆAutoCloseable态Closeable恧恙怂 (ć‚ć£ć”ć‚ƒåˆ†ć‹ć‚Šć„ć‚‰ć„ć§ć™ćŒā€¦ā€¦)

ć¾ćØ悁

ć“ć®ć‚ˆć†ć«ć„ćć¤ć‹é–“é•ć„ćØꀝ悏悌悋čؘčæ°ć‚‚ć‚ć‚Šć¾ć—ćŸćŒć€ 恓悌悉ćÆå‰åŠć®ē« (ę–‡ę³•ć®č§£čŖ¬ćŖć©ć®ć¾ć•ć«å…„é–€ēš„ćŖē« )恫集äø­ć—ć¦ć„ć¾ć—ćŸć€‚

čŖ­ćæé€²ć‚ć‚‹ć«ć¤ć‚Œć¦ć‚ˆć‚Šå®Ÿč·µēš„ćŖå†…å®¹ćŒå¢—ćˆć¦ćŠć‚Šć€ ē¾å “恧ä½æ恈悋ēŸ„č­˜ć‚’ä»˜ć‘ć‚‹ć“ćØćŒć§ćć‚‹ć®ć§ćÆćŖ恄恧恗悇恆恋怂

]]>
Mon, 17 Apr 2017 00:00:00 +0900
http://backpaper0.github.io/2016/12/31/good_bye_2016.html http://backpaper0.github.io/2016/12/31/good_bye_2016.html <![CDATA[2016å¹“ćµć‚Šć‹ćˆć‚Š]]> 2016å¹“ćµć‚Šć‹ćˆć‚Š

ä»Šå¹“ć®ę“»å‹•

今幓ćÆꄏ識ēš„ć«ć„ć‚ć„ć‚ē™»å£‡ć™ć‚‹ćžćƒ¼ć€ćØę˜Øå¹“ć‹ć‚‰ę±ŗć‚ć¦ć„ć¾ć—ćŸć€‚

ēµęžœćÆꬔ恮通悊怂

ē™»å£‡ä»„å¤–ć§čØ€ć†ćØć€ć„ć‚ćµć•ć‚“ćØäŗŒäŗŗ恧WEB+DB PRESS恧怌Javać®ę–°å®šēŸ³ć€ć®é€£č¼‰ć‚’ć—ćŸć®ćŒå¤§ćć„ć§ć™ć€‚

Java Day TokyoćØSpring Day恮ē™»å£‡ć€ćć‚Œć‹ć‚‰WEB+DB PRESSć®é€£č¼‰ćÆ会ē¤¾åć‚’å‡ŗć—ć¦č”Œć„ć¾ć—ćŸćŒć€ å‡ŗå¼µę‰±ć„ć§äŗ¤é€šč²»ć‚‚完å…Ø恫å‡ŗć—ć¦č²°ć£ćŸć—ć€ć“ć‚Œć‚‰ć®ē¤¾å¤–ę“»å‹•ć‚‚č©•ä¾”ć—ć¦č²°ćˆć¦ć„ć‚‹ć®ć§ć€å¼Šē¤¾ćÆč‰Æ恄äø­å°SIer恠ćŖćƒ¼ć€ćØę€ć„ć¾ć—ćŸć€‚

恝悌恋悉态恓悌ćÆ惍ć‚æä»„å¤–ć®ćŖ恫悂恮恧悂ćŖć„ć‘ć‚Œć©ć€ ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać§ęˆ»ć‚Šå€¤ć®ć‚ć‚‹ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč£…ć—ć¦ć®ć‘ć¾ć—ćŸ 怂 恓恮Ꙃ恰恋悊ćÆ态č‡Ŗåˆ†ć‚’å¤©ę‰ć‹ćØę€ć„ć¾ć—ćŸć€‚

ę„å¹“ć«å‘ć‘ć¦

ē§ć®GitHubćƒŖ惝ć‚ø惈ćƒŖć®ć‚¢ć‚Æćƒ†ć‚£ćƒ“ćƒ†ć‚£ćƒ­ć‚°ć«ćÆ锕著恫ē¾ć‚Œć¦ć„ć¾ć™ćŒć€ ꜀čæ‘ćÆ完å…Ø恫Springćøå‚¾å€’ć—ć¦ć„ć¾ć™ć€‚

今幓ćÆč”Øé¢ć®ē¾Žå‘³ć—恄ćØ恓悍悒ćŗ悍ćŗ悍恗恟ꄟ恘ćŖ恮恧态 ę„å¹“ćÆå„„ć¾ć§č¦—ć„ć¦ļ¾ļ½®ļ½Æļ¾„ļ¾ƒļ¾žļ½·ļ¾™ć«ćŖ悍恆ćØę€ć£ć¦ć„ć¾ć™ć€‚

ć¾ć ć¾ć č¶³ć‚Šć¦ćŠć‚‰ćšé£¢ćˆć¦ć‚‚ć„ć‚‹ć®ć§ć€ć„ć‚ć„ć‚ę®“ć£ć¦å¼·ććŖ悊恟恄恧恙怂

]]>
Sat, 31 Dec 2016 00:00:00 +0900
http://backpaper0.github.io/2016/12/01/wife_peropero.html http://backpaper0.github.io/2016/12/01/wife_peropero.html <![CDATA[äø–ē•Œć®äø­åæƒć§ę„›ć‚’å«ć‚“ć ć†ć‚‰ćŒćæ]]> äø–ē•Œć®äø­åæƒć§ę„›ć‚’å«ć‚“ć ć†ć‚‰ćŒćæ

恓悌ćÆ å¦»ćƒ»å¤«ć‚’ę„›ć—ć¦ć‚‹ITć‚Øćƒ³ć‚øćƒ‹ć‚¢ Advent Calendar 2016 恮1ę—„ē›®ć§ć™ć€‚

Twitterć§ć®ćƒŽćƒŖćØå‹¢ć„ć§ä½œć£ćŸć‚“ć§ć™ćŒć€ę—©ć„ę®µéšŽć§åŸ‹ć¾ć£ćŸäøŠć« ćć®2 ć‚‚ä½œć‚‰ć‚Œć¦ć€ćŖć‚“ć ć‹ć‚“ć ć§ć™ć”ćę„½ć—ćæćŖAdvent Calendar恫ćŖć‚Šć¾ć—ćŸć€‚

ę›ø恏恓ćØćÆē‰¹ć«å®šć‚ć¦ćŠć‚‰ćšćƒ•ćƒŖćƒ¼ć‚¹ć‚æć‚¤ćƒ«ćØćŖć£ć¦ć„ć¾ć™ć€‚ ćæćŖć•ć‚“ć€ćć‚Œćžć‚Œć®å½¢ć§ęƒšę°—ć¦é ‚ć‘ć‚Œć°ćØę€ć„ć¾ć™ć€‚

5å‘Ø幓

ēµå©š ć—ć¦ć‹ć‚‰ć¾ć‚‹5å¹“ćŒēµŒć”ć¾ć—ćŸć€‚ ē‰¹ć«ęæ€ć—ć„ć‚±ćƒ³ć‚«ć‚‚ćŖćć€ć®ć‚“ć³ć‚ŠćØć€ć‚†ć‚‹ć€œćå¤«å©¦ć‚’ć‚„ć£ć¦ćŠć‚Šć¾ć™ć€‚

č·é›¢ę„Ÿ

å¦»ć‚‚ē§ćØåŒć˜ććƒ—ćƒ­ć‚°ćƒ©ćƒžć§ć™ć€‚ 恠恑恩ē§ćØē•°ćŖć‚Šć€å®¶ć§ć¾ć§ć‚³ćƒ¼ćƒ‰ć‚’ę›ø恏悈恆ćŖćƒ—ćƒ­ć‚°ćƒ©ćƒžć§ćÆć‚ć‚Šć¾ć›ć‚“ć€‚ ćŸć¶ć‚“ć€ć¾ć£ćŸćć®åˆ„ę„­ē•Œć®äŗŗ悈悊ćÆē§ć®ć‚ˆć†ćŖćƒ—ćƒ­ć‚°ćƒ©ćƒžć«ē†č§£ćŒć‚ć‚Šć€ćć‚Œć§ć„ć¦ē§ć®č¶£å‘³ć«ćÆå¹²ęø‰ć—ćŖć„ćć‚‰ć„ć®č·é›¢ę„ŸćŒåæƒåœ°č‰Æćę„Ÿć˜ć¦ć„ć¾ć™ć€‚

é€±ęœ«ćÆäŗŒäŗŗ恧å‡ŗ恋恑悋恓ćØćŒå¤šć„ć§ć™ćŒć€ć€Œä»Šé€±ęœ«ćÆå‹‰å¼·ä¼šć«č”ŒććŸć„ļ¼ć€ćØčØ€ć£ć¦ć‚‚ć€Œč‰Æ恄悈怍ćØčæ”ć—ć¦ćć‚Œć¦ć€åˆ„ć€…ć«č”Œå‹•ć™ć‚‹ć“ćØć‚‚ć¾ć¾ć‚ć‚Šć¾ć™ć€‚ ć‚‚ć”ć‚ć‚“ć€å¦»ćŒå‹é”ćØéŠć³ćŸć„ćØčØ€ć£ć¦ććŸå “åˆćÆē§ć‚‚äŗ†ę‰æ恙悋恮恧态恊äŗ’恄悒ēø›ć‚‹ć“ćØćŖćę„½ć—ćéŽć”ć›ć¦ć„ć¾ć™ć€‚

ę—„åøø

ꜝćÆē§ćŒęœć”ćÆ悓恮ęŗ–å‚™ć‚’ć—ć¦ć„ć‚‹é–“ć«å¦»ćŒćŠå¼å½“ć®ęŗ–å‚™ć‚’ć—ć¦ćć‚Œć¾ć™ć€‚ 夜ćÆå…ˆć«åø°ć£ćŸę–¹ćŒę™©ć”ćÆ悓恮ęŗ–å‚™ć‚’ć—ć¾ć™ć€‚

仕äŗ‹ćŒēµ‚ć‚ć£ć¦åø°ć‚‹ćØ恍ćÆLINEć—ć¾ć™ć€‚ ćŸć¾ć«ē„”ę„å‘³ćŖć‚¹ć‚æćƒ³ćƒ—ć®åæœé…¬ć«ćŖć‚Šć¾ć™ć€‚ ę°—ä»˜ć„ćŸć‚‰ęœ€åÆ„é§…ć§ć™ć€‚

åÆć‚‹ć¾ć§ć®é–“ćÆćŠčŒ¶ć‚’é£²ćæćŖ恌悉恊äŗ’ć„å„½ćć«éŽć”ć—ć¾ć™ć€‚ å¤§ęŠµć€ē§ćÆPCć§ć‚³ćƒ¼ćƒ‰ę›ø恄恟悊Twitterć—ćŸć‚Šć‚®ć‚æćƒ¼å¼¾ć„ćŸć‚Šć€å¦»ćÆć‚¹ćƒžćƒ›ć‚’ć„ć˜ć£ćŸć‚Šćƒ†ćƒ¬ćƒ“ć‚’č¦‹ćŸć‚Šć—ć¦ć„ć¾ć™ć€‚ å„½ććŖ恓ćØ悒恗恤恤态ćØćć©ćä¼šč©±ć—ć¦ć€ć¾ćŸå„½ććŖ恓ćØć‚’ć—ć¦ć€å¦»ćŒćƒ‰ćƒ©ć‚¤ćƒ¤ćƒ¼ć§é«Ŗć‚’ä¹¾ć‹ć—ć€ć¾ćŸä¼šč©±ć—ć¦ć€‚

恊äŗ’ć„ć«åˆ„怅恮恓ćØć‚’ć—ć¦ć„ć¦ć‚‚åŒć˜ē©ŗé–“ć«å±…ć‚‹ć®ćŒå¤§åˆ‡ć§ć€ēµå©šćØ恄恆恮ćÆćć†ć„ć†ć‚‚ć®ćŖ恮恋悂ćŖćƒ¼ć€ćØę€ć£ć¦ć„ć¾ć™ć€‚

恗ćæ恘ćæ

꜀čæ‘ć®ćƒ‡ćƒ¼ćƒˆ

äŗ¬éƒ½ę°“ꗏé¤Øć€ę„½ć—ć‹ć£ćŸć€‚

ć¾ćØ悁

ćŸć ćŸć ę—„åøøćØć€ę™®ę®µć‹ć‚‰ę€ć£ć¦ć„ć‚‹ć“ćØ悒ę›øć„ćŸć ć‘ć§ć€å¤§ć—ć¦ęƒšę°—ć‚‰ć‚ŒćŖć‹ć£ćŸę°—ć‚‚ć—ć¾ć™ćŒć„ć‹ćŒć§ć—ćŸć‹ļ¼Ÿ

ēµå©šćÆäŗŗć«ć‚ˆć£ć¦åˆć†ćƒ»åˆć‚ćŖ恄恌恂悋ćØę€ć†ć®ć§ē„”ę”ä»¶ć§ćÆć‚Ŗć‚¹ć‚¹ćƒ”ćÆć—ć¾ć›ć‚“ćŒć€ ē§ćÆēµå©šć—恦č‰Æć‹ć£ćŸćŖćƒ¼ćØꀝ恆恓ćØćÆć‚ć£ć¦ć‚‚é€†ćÆäø€åŗ¦ć‚‚ć‚ć‚Šć¾ć›ć‚“ć€‚

ć„ć¤ć‚‚ćć°ć«å±…ć¦ćć‚Œć¦ć€å¦»ć«ćÆę„Ÿč¬ć—ć¦ć„ć‚‹ć—ć€ę„›ć—ć¦ć„ć¾ć™ć€‚

ę˜Žę—„ćÆ @susumuis 恕悓恧恙怂

]]>
Thu, 01 Dec 2016 00:00:00 +0900
http://backpaper0.github.io/2016/10/09/scala_ks.html http://backpaper0.github.io/2016/10/09/scala_ks.html <![CDATA[Scala関č„æSummit 2016ćøå‚åŠ ćƒ»ē™»å£‡ć—ćŸćžļ¼ #scala_ks]]> Scala関č„æSummit 2016ćøå‚åŠ ćƒ»ē™»å£‡ć—ćŸćžļ¼ #scala_ks

å‚åŠ ć—ćŸļ¼

ć§ć€ć‚»ćƒƒć‚·ćƒ§ćƒ³å‹Ÿé›†ć«åæœå‹Ÿć—ćŸć‚‰ęŽ”ē”Øć•ć‚ŒćŸć®ć§ē™»å£‡ć‚‚ć—ćŸļ¼

ć‚»ćƒƒć‚·ćƒ§ćƒ³ć§ćÆScala恮č”Øē¾åŠ›ć‚’ę”Æćˆć‚‹ä»•ę§˜ć‚’č§£čŖ¬ć—恦态仕ēµ„ćæćŒåˆ†ć‹ć‚‹ćØć¾ćŸé•ć£ćŸę„½ć—ć•ćŒč¦‹ćˆć¦ćć‚‹ć‚ˆć­ćƒ¼ć€ć£ć¦ć„ć†ę€ć„ć‚’ä¼ćˆćŸć‹ć£ćŸć®ć§ć—ćŸć€‚

ćƒ¬ćƒ“ćƒ„ćƒ¼ć—ć¦ćć‚ŒćŸćŒććžć•ć‚“ć€ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć—ćŸļ¼ļ¼ļ¼

ē§ćÆJavać‚Øćƒ³ć‚øćƒ‹ć‚¢ćŖ恮恧ꇇč¦Ŗä¼šć¼ć£ć”ć«ćŖ悋恋ćŖćƒ¼ć€ćØå°‘ć—ę€ć£ć¦ćŸć‚“ć§ć™ćŒå‹äŗŗ悒ćÆć˜ć‚ć€ć‚ć„ć‚ć„ćŠč©±ć§ćć¦ę„½ć—ć‹ć£ćŸć§ć™ļ¼

]]>
Sun, 09 Oct 2016 00:00:00 +0900
http://backpaper0.github.io/2016/10/01/unreachable_statements.html http://backpaper0.github.io/2016/10/01/unreachable_statements.html <![CDATA[ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać§ęˆ»ć‚Šå€¤ć®ć‚ć‚‹ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®šē¾©ć™ć‚‹(恟恠恗čæ”ć£ć¦ć“ćŖ恄)ć®č§£čŖ¬]]> ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać§ęˆ»ć‚Šå€¤ć®ć‚ć‚‹ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®šē¾©ć™ć‚‹(恟恠恗čæ”ć£ć¦ć“ćŖ恄)ć®č§£čŖ¬

恓悌恌ćŖćœć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć‚’é€šć‚‹ć®ć‹ļ¼ŸćØ恄恆ē–‘å•ć‚’č¦‹ć‹ć‘ćŸć®ć§č§£čŖ¬ć—恦ćæć¾ć™ć€‚

到達äøčƒ½ę–‡

ä¾‹ćˆć° while(false) { ... } ćØć—ćŸę™‚ć€ć“ć® while 惖惭惃ć‚Æå†…ć®ę–‡ćÆēµ¶åÆ¾ć«å®Ÿč”Œć•ć‚Œć¾ć›ć‚“ć€‚ ć“ć®ć‚ˆć†ć«ēµ¶åÆ¾ć«å®Ÿč”Œć•ć‚ŒćŖ恄ꖇ悒 到達äøčƒ½ ćØč”Øē¾ć—ć€åˆ°é”äøčƒ½ćŖę–‡ćŒć‚ć‚‹å “åˆćÆć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć‚Øćƒ©ćƒ¼ć«ćŖć‚Šć¾ć™ć€‚

ę¬”ć®ć‚ˆć†ćŖå†…å®¹ć§ Sample1.java ć‚’ä½œęˆć—ć¦ javac 恗恦ćæć¦ćć ć•ć„ć€‚

public class Sample1 {
    public void whileSample() {
        while(false) {
            System.out.println("到達äøčƒ½ļ¼");
        }
    }
}

ę¬”ć®ć‚ˆć†ćŖć‚Øćƒ©ćƒ¼ć«ćŖć‚Šć¾ć™ć€‚

Sample1.java:3: ć‚Øćƒ©ćƒ¼: ć“ć®ę–‡ć«åˆ¶å¾”ćŒē§»ć‚‹ć“ćØćÆć‚ć‚Šć¾ć›ć‚“
        while(false) {
                     ^
ć‚Øćƒ©ćƒ¼1個

for ę–‡ć§ć‚‚åŒć˜äŗ‹ćŒć§ćć¾ć™ć€‚

public class Sample2 {
    public void forSample() {
        for(;false;) {
            System.out.println("到達äøčƒ½ļ¼");
        }
    }
}
Sample2.java:3: ć‚Øćƒ©ćƒ¼: ć“ć®ę–‡ć«åˆ¶å¾”ćŒē§»ć‚‹ć“ćØćÆć‚ć‚Šć¾ć›ć‚“
        for(;false;) {
                     ^
ć‚Øćƒ©ćƒ¼1個

try ꖇćÆć‚Øćƒ©ćƒ¼ćƒ”ćƒƒć‚»ćƒ¼ć‚øćÆé•ć„ć¾ć™ćŒć€ę¬”ć®ć‚ˆć†ć‚³ćƒ¼ćƒ‰ćÆ到達äøčƒ½ćŖę–‡ć‚’å«ć‚€ć®ć§ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć‚Øćƒ©ćƒ¼ć«ćŖć‚Šć¾ć™ć€‚

public class Sample3 {
    public void trySample() {
        try {
            System.out.println("到達åÆčƒ½");
        } catch(RuntimeException e) {
            System.out.println("到達åÆčƒ½");
        } catch(IllegalArgumentException e) {
            System.out.println("到達äøčƒ½ļ¼");
        }
    }
}
Sample3.java:7: ć‚Øćƒ©ćƒ¼: 例外IllegalArgumentExceptionćÆć™ć§ć«ę•ę‰ć•ć‚Œć¦ć„ć¾ć™
        } catch(IllegalArgumentException e) {
          ^
ć‚Øćƒ©ćƒ¼1個

ē‰¹åˆ„ꉱ恄恮 if

ć“ć“ć¾ć§ while 态 for 态 try ć®åˆ°é”äøčƒ½ćŖę–‡ć‚’å«ć‚€ć‚³ćƒ¼ćƒ‰ćŒć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć‚Øćƒ©ćƒ¼ć«ćŖć‚‹ä¾‹ć‚’č¦‹ć¦ćć¾ć—ćŸć€‚ if ę–‡ć§ć‚‚åŒć˜ć‚ˆć†ćŖäŗ‹ćŒć§ćć‚‹ć‹ćØę€ć„ćć‚„ć€ę¬”ć®ć‚³ćƒ¼ćƒ‰ćÆć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć§ćć¦ć—ć¾ć„ć¾ć™ć€‚

public class Sample4 {
    public void ifSample() {
        if(false) {
            System.out.println("到達äøčƒ½ļ¼");
        }
    }
}

到達äøčƒ½ćŖę–‡ć‚’å«ć‚“ć  if ꖇćÆć©ć®ć‚ˆć†ć«ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć•ć‚ŒćŸć®ć‹ć€ javap -c Sample4 恗恦ē¢ŗčŖć—恦ćæć¾ć—ć‚‡ć†ć€‚

Compiled from "Sample4.java"
public class Sample4 {
  public Sample4();
    Code:
       0: aload_0
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: return

  public void ifSample();
    Code:
       0: return
}

恔覧恮通悊态 if ꖇ恌ē¶ŗéŗ—ć•ć£ć±ć‚Šę¶ˆćˆć¦ć„ć¾ć™ć­ć€‚

恧ćÆ态 if ć®ę”ä»¶å¼ć‚’ true ć«å¤‰ćˆć¦ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć—ć¦ javap 恗恦ćæć¾ć—ć‚‡ć†ć€‚ ļ¼ˆć‚Æćƒ©ć‚¹åćŖ恩ćÆå°‘ć—å¤‰ćˆć¦ć‚ć‚Šć¾ć™ļ¼‰

Compiled from "Sample5.java"
public class Sample5 {
  public Sample5();
    Code:
       0: aload_0
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: return

  public void ifSample();
    Code:
       0: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
       3: ldc           #3                  // String 到達åÆčƒ½
       5: invokevirtual #4                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
       8: return
}

if ꖇ恮äø­čŗ«ćÆć‚ć‚Šć¾ć™ćŒć€ę”ä»¶ć‚’č©•ä¾”ć—ć¦ć„ć‚‹éƒØåˆ†ćŒćŖ恏ćŖć‚Šć¾ć—ćŸć€‚

if ćŒć“ć®ć‚ˆć†ć«ē‰¹åˆ„ꉱ恄恫ćŖć£ć¦ć„ć‚‹ć®ćÆć€ę¬”ć®ć‚ˆć†ćŖć‚³ćƒ¼ćƒ‰ć‚’ę›øć‘ć‚‹ć‚ˆć†ć«ć™ć‚‹ćŸć‚ć§ć™ć€‚

static final boolean DEBUG = true;

void sample() {
    if(DEBUG) { System.out.println("logging"); }
}

先čæ°ć®ē‰¹å¾“ćŒć‚ć‚‹ć®ć§ć€å®šę•° DEBUG 恌 true ćŖć‚‰ćƒ­ć‚®ćƒ³ć‚°ć•ć‚Œć‚‹ć‘ć©ć‚‚ć€ false ćŖć‚‰ćƒ­ć‚®ćƒ³ć‚°ć®ć‚³ćƒ¼ćƒ‰ćŒć‚Æćƒ©ć‚¹ćƒ•ć‚”ć‚¤ćƒ«ć‹ć‚‰ć‚‚ę¶ˆćˆć‚‹ć€ćØ恄恆ꄟ恘恧恙怂

return 悒ę›øć‹ćšć«ęˆ»ć‚Šå€¤ć®ć‚ć‚‹ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®šē¾©ć™ć‚‹

return ꖇ恫ćÆć©ć†ć—ć¦ć‚‚ć‚»ćƒŸć‚³ćƒ­ćƒ³ć‚’ę›ø恏åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚ ćć‚ŒćŒę•…ć«ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Java恧ćÆęˆ»ć‚Šå€¤ć®ć‚ć‚‹ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®šē¾©ć™ć‚‹ć“ćØćÆ恧恍ćŖ恄ćØč€ƒćˆć‚‰ć‚Œć¦ć„ć¾ć—ćŸć€‚

ē§ć‚‚ć€Œć©ć®ć‚ˆć†ć«ć™ć‚Œć°ć‚»ćƒŸć‚³ćƒ­ćƒ³ć‚’ēœē•„恗恦 return 恌ę›øć‘ć‚‹ć®ć‹ć€ćØč€ƒćˆć¦ćÆęŒ«ęŠ˜ć‚’ē¹°ć‚Ščæ”ć—ć¦ćć¾ć—ćŸćŒć€ 恂悋ćØćć€Œć‚»ćƒŸć‚³ćƒ­ćƒ³ć‚’ēœē•„恗恦 return 恌ę›ø恑ćŖ恄ćŖ悉态恝悂恝悂 return 悒ę›ø恋ćŖ恑悌恰č‰Æ恄恮恧ćÆ怍ćØē™ŗęƒ³ć®č»¢ę›ć‚’ć—ć¦ćæć¾ć—ćŸć€‚

å‰åŠć§čæ°ć¹ćŸé€šć‚Šć€åˆ°é”äøčƒ½ćŖę–‡ć‚’å«ć‚€ćØć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć‚Øćƒ©ćƒ¼ć«ćŖć‚Šć¾ć™ć€‚ é€†ć«č€ƒćˆć‚‹ćØ态ē„”é™ćƒ«ćƒ¼ćƒ—ćÆ到達åÆčƒ½ćŖć®ć§ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć‚’é€šć‚‹ć—ć€ē„”é™ćƒ«ćƒ¼ćƒ—ć®å¾Œć‚ćÆ到達äøčƒ½ćŖć®ć§ä½•ć‚’ę›øć„ć¦ć‚‚ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć‚Øćƒ©ćƒ¼ć«ćŖ悋态ćØ恄恆恓ćØ恧恙恭怂

while(true) {
    //到達åÆčƒ½
}
//到達äøčƒ½

ć“ć‚Œć«ć‚ˆć‚Šå†’é ­ć«čØ˜č¼‰ć—ćŸćƒ„ć‚¤ćƒ¼ćƒˆć®é€šć‚Šć€ć‚»ćƒŸć‚³ćƒ­ćƒ³ć‚’ę›øć‹ćšć«ęˆ»ć‚Šå€¤ć®ć‚ć‚‹ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®šē¾©ć§ćć¾ć—ćŸć€‚

public class Semicolonless {

    String get() {
        while (true) {
        }
    }
}

恔ćŖćæć«ć‚»ćƒŸć‚³ćƒ­ćƒ³ćÆćØ悂恋恏态 return 悒ę›øć‹ćšć«ęˆ»ć‚Šå€¤ć®ć‚ć‚‹ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®šē¾©ć™ć‚‹ę–¹ę³•ćØ恗恦ćÆä¾‹å¤–ć‚’ęŠ•ć’ć‚‹ćØć„ć†ć®ć‚‚ć‚ć‚Šć¾ć™ć€‚ ļ¼ˆä¾‹ćˆć° Thread.destroy() ļ¼‰

ęˆ»ć‚Šå€¤ć®ć‚ć‚‹ćƒ”ć‚½ćƒƒćƒ‰ć« return ꖇćŖć‚“ć¦č¦ć‚‰ć‚“ć‹ć£ćŸć‚“ć‚„ļ¼ļ¼ļ¼

ć¾ćØ悁

  • äø€č¦‹äøåÆčƒ½ć«ę€ćˆć‚‹ć“ćØć§ć‚‚č€ƒćˆę–¹ć‚’å¤‰ćˆć‚‹ć“ćØć§č§£ę±ŗć™ć‚‹å “åˆćŒć‚ć‚‹
  • ćØćÆć„ćˆč§£ę±ŗ恗恟ćØć“ć‚ć§å½¹ć«ē«‹ćŸćŖ恄悂恮悂恂悋
]]>
Sat, 01 Oct 2016 00:00:00 +0900
http://backpaper0.github.io/2016/09/11/githubwww.html http://backpaper0.github.io/2016/09/11/githubwww.html <![CDATA[GitHub恧ęÆŽę—„č‰ē”Ÿć‚„恗ē¶šć‘ć‚‹é‹å‹•ć‚’ēµ‚äŗ†ć™ć‚‹]]> GitHub恧ęÆŽę—„č‰ē”Ÿć‚„恗ē¶šć‘ć‚‹é‹å‹•ć‚’ēµ‚äŗ†ć™ć‚‹

GitHub恧ęÆŽę—„č‰ē”Ÿć‚„恗ē¶šć‘ć‚‹é‹å‹•ćØćÆ

GitHubćÆć‚³ćƒŸćƒƒćƒˆć—ćŸć‚Šćƒ—ćƒ«ćƒŖć‚Æ恙悋ćØćƒ—ćƒ­ćƒ•ć‚£ćƒ¼ćƒ«ćƒšćƒ¼ć‚ø恮ć‚æć‚¤ćƒ«ć£ć½ć„ć‚„ć¤ćŒē·‘恫ćŖć‚Šć¾ć™ć€‚ ē·‘恫ćŖ悋恋悉怌草悒ē”Ÿć‚„ć™ć€ć£ć¦ęÆ”å–©ć—ć¦ć‚‹ć‚“ć§ć™ć‘ć©ć€ćć‚Œć‚’ęÆŽę—„ē¶šć‘恦ē·‘ć§åŸ‹ć‚å°½ććć†ćØ恄恆悂恮恧恙怂

é€²ę—

7ęœˆęœ€å¾Œć®é€±ćć‚‰ć„ć«č‰ć ć‚‰ć‘ć«ćŖć‚Šć¾ć—ćŸć€‚

Slackć§ć‚ć–ć‚ć–å ±å‘Šć—ć¦ć„ć‚‹å›³ć€‚

恝悌恋悉悂ęÆŽę—„č‰ē”Ÿć‚„ć—ć¦ćŸć®ć§400ꗄ恐悉恄ćÆē¶™ē¶šć§ćć¦ć„ć‚‹ćØę€ć„ć¾ć™ć€‚

ćŖ恜悄悍恆ćØę€ć£ćŸć‹

äø‰åč·Æ恫ćŖć£ć¦ć€Œć“ć‚Œć‹ć‚‰ć‚‚ć‚³ćƒ¼ćƒ‰ć‚’ę›øć„ć¦ć„ć‚‰ć‚Œć‚‹ć®ć ć‚ć†ć‹ļ¼Ÿ(ē’°å¢ƒćØ恄恆悈悊ćÆč‡Ŗåˆ†ć®ćƒ¢ćƒćƒ™ćƒ¼ć‚·ćƒ§ćƒ³ēš„ćŖę„å‘³ć§)怍ćØę€ć†ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚ ćŖć®ć§å„½ćć‹ć©ć†ć‹č‡Ŗ分č‡Ŗčŗ«ć‚’č©¦ćć†ć‹ćŖćƒ¼ć€ćØ怂

ć‚„ć£ć¦ćæć¦å¾—ćŸć‚‚ć®

ć‚„ć‚‹å‰ć«ę€ć£ć¦ćŸć‚ˆć‚Šć‚‚ćšć£ćØę„½ć—ć‚“ć§ē¶šć‘ć‚‰ć‚ŒćŸć®ć§ć€ć‚„ć£ć±ć‚Šč‡Ŗ分ćÆć‚³ćƒ¼ćƒ‰ę›øćć®å„½ććŖ悓恠ćŖ态ćØę€ćˆć¾ć—ćŸć€‚ć“ć‚ŒćÆå¬‰ć—ć„ć€‚

恂ćØć€å¤§ć—ćŸć‚³ćƒ¼ćƒ‰ćÆę›ø恑恦ćŖć„ć§ć™ćŒć€ć‚µćƒ³ćƒ—ćƒ«ć‚„ć‚‰ćƒ“ćƒ«ćƒ‰ć‚¹ć‚ÆćƒŖ惗惈恌ęŗœć¾ć£ć¦ćć¦ä½•ć‹ćØå½¹ē«‹ć£ć¦ć„ć¾ć™ć€‚

ćŖ恜悄悁悈恆ćØę€ć£ćŸć‹

怌ē¶™ē¶šć€ć‚’ē›®ēš„ćØć—ć¦ć„ćŸć®ć§ć€ę›øććŸć„ć‚³ćƒ¼ćƒ‰ćŒę€ć„ć¤ć‹ćŖ恄ꗄćÆREADME.md悒äæ®ę­£ć™ć‚‹ćØć„ć£ćŸć‚»ć‚³ć„č‰ć‚‚ćŸć¾ć«ćÆē”Ÿć‚„ć—ć¦ć„ć¾ć—ćŸćŒć€ć‚‚ć†ćć†ć¾ć§ć—ć¦č‰ē”Ÿć‚„恙恮ćÆé¢å€’ć«ę€ćˆć¦ćć¾ć—ćŸć€‚

ćć‚Œć«ć€čŖ­ę›øć®ć‚ˆć†ćŖ草恌ē”ŸćˆćŖć„ę“»å‹•ć«ć‚‚ć‚‚ć£ćØꙂ間悒ä½æ恄恟恄ćŖćƒ¼ćØę€ć„å§‹ć‚ć¾ć—ćŸć€‚

å½“åˆć®ē›®ęØ™ć§ć‚ć£ćŸäø€å¹“ćÆē¶™ē¶šć§ććŸć®ć§ć€ć‚„悁悋恮恫悂ęœŖē·“ćÆē„”恄恧恙恗怂 (恧悂ćŖć‚“ć‹ę°—ęŒć”ć®ę•“ē†ēš„恫悄悁悋恓ćØćÆčØ˜ć—ć¦ćŠććŸćć¦ć“ć®ć‚Øćƒ³ćƒˆćƒŖ悒ę›ø恄恦悋)

ć¾ćØ悁

  • ć‚³ćƒ¼ćƒ‰ę›øćć®ćŒå„½ćć ćØ再ē¢ŗčŖć§ćć¦å€‹äŗŗēš„恫ćÆꄏē¾©ćŒć‚悋試ćæ恧恗恟
  • 草ē”Ÿć‚„ć—é‹å‹•ćÆäŗŗć«ć‚ˆć£ć¦åˆć†ćƒ»åˆć‚ćŖć„ćŒć‚ć‚‹ć®ć§ē‰¹åˆ„恊恙恙悁ćÆć—ć¾ć›ć‚“
  • äø€å¹“å¾Œć€ćƒ—ćƒ­ćƒ•ć‚£ćƒ¼ćƒ«ćƒšćƒ¼ć‚ø恌äøęÆ›ć®åœ°ćØåŒ–ć—ć¦ć„ćŸć‚‰å˜²ē¬‘ć£ć¦ćć ć•ć„
]]>
Sun, 11 Sep 2016 00:00:00 +0900
http://backpaper0.github.io/2016/09/06/private_method.html http://backpaper0.github.io/2016/09/06/private_method.html <![CDATA[privatećƒ”ć‚½ćƒƒćƒ‰ć«ć¤ć„ć¦ć®ę€ć„ć®å¤‰é·]]> privatećƒ”ć‚½ćƒƒćƒ‰ć«ć¤ć„ć¦ć®ę€ć„ć®å¤‰é·

UnitTest恧恮privatećƒ”ć‚½ćƒƒćƒ‰ćØć®å‘ćåˆć„ę–¹ - ć‚ø惠恫ćÆä¹—ć‚ŠćŸć„ 悒čŖ­ć‚“恧态č‡Ŗåˆ†ć®privatećƒ”ć‚½ćƒƒćƒ‰ć«åÆ¾ć™ć‚‹ę€ć„ć‚’ę›øćę®“ć‚ŠćŸććŖć£ćŸć®ć§ę›ø恄恦ćæć¾ć—ćŸć€‚

変遷

ꖰäŗŗ恮頃恮ā˜ƒć€Œprivateļ¼Ÿćƒ”ć‚½ćƒƒćƒ‰ļ¼ŸćØć„ć†ć®ćŒć‚ć‚‹ć®ć‹ć€‚ćµć‚€ć€‚ćµć‚€ā€¦ā€¦ļ¼Ÿć€

ꖰäŗŗ恧ćÆćŖ恏ćŖć£ćŸćŒč‹„ę‰‹ć®é ƒć®ā˜ƒć€Œćƒ”ć‚½ćƒƒćƒ‰ćŒå¤§ćććŖć£ć¦ććŸćŖ怂privatećƒ”ć‚½ćƒƒćƒ‰ć§åˆ†å‰²ć ļ¼ć€

苄ꉋćØćÆčØ€ćˆćŖ恏ćŖć£ćŸé ƒć®ā˜ƒć€Œprivatećƒ”ć‚½ćƒƒćƒ‰ć®ćƒ†ć‚¹ćƒˆć‚³ćƒ¼ćƒ‰ć£ć¦ć©ć†ę›ø恄恟悉č‰Æ恄悓恠ļ¼ŸćƒŖćƒ•ćƒ¬ć‚Æć‚·ćƒ§ćƒ³ć‹ļ¼Ÿć€

2态3å¹“å‰ć®ā˜ƒć€Œprivatećƒ”ć‚½ćƒƒćƒ‰ćÆ共通処ē†ć‚’åˆ‡ć‚Šå‡ŗć™ćŸć‚ć®ć‚‚ć®ć€‚å‘¼ć³å‡ŗć—å…ƒć®publicćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ†ć‚¹ćƒˆć‚³ćƒ¼ćƒ‰ć§ę‹…äæć•ć‚Œć‚‹ć€

꜀čæ‘恮ā˜ƒć€Œprivatećƒ”ć‚½ćƒƒćƒ‰ ć‚¹ćƒ™ćƒ† ć‚³ćƒ­ć‚¹ļ¼ļ¼ļ¼ć€

č§£čŖ¬

ꖰäŗŗ恮頃ćÆå‰²ę„›ć€‚

ę¬”ć®č‹„ę‰‹ć®é ƒć®č©±ćÆ态恓悌ćÆå¤§ćć„ćƒ”ć‚½ćƒƒćƒ‰ć‚’å˜ć«ć¶ć¤åˆ‡ć‚Šć«ć—ć¦ęŗ€č¶³ć—ć”ć‚ƒć£ć¦ćŸę„Ÿć˜ć€‚ č‡­ć„ć‚‚ć®ć«č“‹ć—ć¦ć‚‹ć ć‘ć§ä½•ć®č§£ę±ŗ恫悂ćŖć£ć¦ć„ć¾ć›ć‚“ć§ć—ćŸć­ć€ä»Šć‹ć‚‰ę€ć†ćØ怂

恝悌恋悉privatećƒ”ć‚½ćƒƒćƒ‰ć®ćƒ†ć‚¹ćƒˆć‚³ćƒ¼ćƒ‰ć«ć¤ć„ć¦ę‚©ćæć¾ć—ćŸć€‚ ć©ć†ć™ć‚Œć°č‰Æ恄悓恠ļ¼ŸćØ怂 ę‚©ć‚“ć ęŒ™å„protectedć«ć—ć”ć‚ƒćŸć‚Šć—ć¦ć¾ć—ćŸćŒć€ć“ć‚Œć‚‚čŖ¤é­”åŒ–ć—ć§ć™ć­ć€‚

ć§ć€ć—ć°ć‚‰ćć—ć¦ć€å‘¼ć³å‡ŗć—å…ƒć®ćƒ†ć‚¹ćƒˆć§ę‹…äæć§ćć‚‹ć˜ć‚ƒć‚ć€ćØę€ć†ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚ ć“ć®é ƒć«privatećƒ”ć‚½ćƒƒćƒ‰ćÆ複ꕰ恮publicćƒ”ć‚½ćƒƒćƒ‰ć«å…±é€šć™ć‚‹å‡¦ē†ć‚’åˆ‡ć‚Šå‡ŗ恙悂恮恠态ćØč€ƒćˆć‚‹ć‚ˆć†ć«ćŖć£ćŸć®ć§ć—ćŸć€‚ 逆恫čØ€ć†ćØ态publicćƒ”ć‚½ćƒƒćƒ‰ć®äø€éƒØć‚’å…±é€šåŒ–ć™ć‚‹ä»„å¤–ć®ē›®ēš„恧恮privatećƒ”ć‚½ćƒƒćƒ‰å°Žå…„ćÆćƒ€ćƒ”ć ćØč€ƒćˆć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚

ćć‚“ć§ć‚‚ć£ć¦ęœ€čæ‘ćÆ态ćŖć‚‹ć¹ćprivatećƒ”ć‚½ćƒƒćƒ‰ćÆå°Žå…„ć—ćŸććŖ恄ćØę€ć£ć¦ć„ć¾ć™ć€‚

å¹“ć€…ć€å°ć‚Æćƒ©ć‚¹äø»ē¾©ć«ćŖć£ć¦ć‚‹ć®ć‹ćŖćƒ¼ć€‚ ćæ恟恄ćŖ怂

ć¾ćØ悁

å†’é ­ć§čØ˜č¼‰ć—ćŸć‚Øćƒ³ćƒˆćƒŖ恧ćÆ态

ēµå±€ć®ćØ恓悍态privatećƒ”ć‚½ćƒƒćƒ‰ć®č©³ē“°ć«čøćæč¾¼ć‚“ć ćƒ†ć‚¹ćƒˆćŒåæ…要恫ćŖć£ćŸę™‚ćÆ态čØ­čØˆć«ä½•ć‹å•é”ŒćŒć‚ć‚‹åÆčƒ½ę€§ćŒé«˜ć„ćØ恄恆恓ćØćŖ恮恠ćØꀝ恆怂

ćØę›øć‹ć‚Œć¦ć„ć¾ć—ćŸćŒć€ē§ćÆprivatećƒ”ć‚½ćƒƒćƒ‰ć‚’å°Žå…„ć—ć‚ˆć†ćØę€ć£ćŸć‚æć‚¤ćƒŸćƒ³ć‚°ć§čØ­čØˆć«å•é”ŒćŒć‚ć‚‹ć®ć§ćÆļ¼ŸćØē–‘ć£ć¦ćæć‚‹ć‚ˆć†ć«ć—ć¦ć„ć¾ć™ć€‚

]]>
Tue, 06 Sep 2016 00:00:00 +0900
http://backpaper0.github.io/2016/07/12/doma_tokyo.html http://backpaper0.github.io/2016/07/12/doma_tokyo.html <![CDATA[ę±äŗ¬ć§Domaå‹‰å¼·ä¼šć‚„ć£ćŸćžļ¼ļ¼ļ¼ #doma_tokyo]]> ę±äŗ¬ć§Domaå‹‰å¼·ä¼šć‚„ć£ćŸćžļ¼ļ¼ļ¼ #doma_tokyo

Doma ä½œč€…ć® äø­ę‘恕悓 态 Domaćƒ˜ćƒ“ćƒ¼ćƒ¦ćƒ¼ć‚¶ćƒ¼ć® 恌恏恞恕悓 ćØäø€ē·’恫Domaå‹‰å¼·ä¼šć‚’ę±äŗ¬ć§é–‹å‚¬ć—ć¦ćć¾ć—ćŸļ¼ļ¼ļ¼

ć‚¹ćƒ©ć‚¤ćƒ‰

ē§ć®ć‚¹ćƒ©ć‚¤ćƒ‰ćÆ恓恔悉怂 2ęœ¬ć€č©±ć•ć›ć¦é ‚ćć¾ć—ćŸć€‚ Doma恮äø»č¦ćŖę©Ÿčƒ½ć‚’ē§ćŖ悊恫ē“¹ä»‹ć—ćŸē™ŗč”ØćØć€ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć§åž‹ęœ€é«˜ļ¼ćØ恄恆ē™ŗč”Ø恧恙怂

ćŒććžć•ć‚“ć®ć‚¹ćƒ©ć‚¤ćƒ‰ćÆ恓恔悉怂 collectꤜē“¢ć®ę“»ē”Øę–¹ę³•ć€ćŖć‚‹ć»ć©ę„Ÿć™ć”ć‹ć£ćŸć§ć™ć€‚ ēœŸä¼¼ć•ć›ć¦ć‚‚ć‚‰ć„ć¾ć™ļ¼

ćć—ć¦ć€äø­ę‘ć•ć‚“ć®ć‚¹ćƒ©ć‚¤ćƒ‰ćÆ恓恔悉怂 Doma開ē™ŗć®ć‚¹ć‚æćƒ³ć‚¹ć€ęˆ‘ć€…ćƒ¦ćƒ¼ć‚¶ćƒ¼ćØć®å‘ćåˆć„ę–¹ć«ę„Ÿå‹•ć—ć¾ć—ćŸļ¼ļ¼

怌LTć‚„ć£ć¦ć‚ˆļ¼ć€ć£ć¦ć•ć‚‰ć£ćØē„”čŒ¶ęŒÆć‚Šć—ćŸć®ć«č¦‹äŗ‹ć«åæœćˆć¦ćć‚ŒćŸ 多ē”°ć•ć‚“ ćØ 悄悓恏恕悓 悂恂悊恌ćØć†ć”ć–ć„ć¾ć—ćŸļ¼

TLćø恮ćƒŖć‚¢ć‚Æć‚·ćƒ§ćƒ³

å†…å®¹ć«ć¤ć„ć¦ćÆć€ä»–ć®ę–¹ć€…ć®ćƒ–ćƒ­ć‚°ć«ćŠä»»ć›ć™ć‚‹ćØ恗恦态恓恓恋悉ćÆå½“ę—„ć®TLć‹ć‚‰å¹¾ć¤ć‹ć®ćƒ„ć‚¤ćƒ¼ćƒˆć‚’ćƒ”ćƒƒć‚Æć‚¢ćƒƒćƒ—ć—ć¦ć€ćƒŖć‚¢ć‚Æć‚·ćƒ§ćƒ³ć—ćŸć„ćØę€ć„ć¾ć™ć€‚

恓悌恧恙ļ¼

通åøø恮SELECTę–‡ć‚’ćƒšćƒ¼ć‚øćƒćƒ¼ć‚·ćƒ§ćƒ³ć™ć‚‹ć‚Æć‚ØćƒŖ悄态 ę‚²č¦³ęŽ’ä»–ć™ć‚‹ć‚Æć‚ØćƒŖć«å¤‰ę›ć™ć‚‹éš›ć«RDBMSć®ę–¹čØ€ć‚’åøåŽć™ć‚‹ćŸć‚ć®ć‚‚ć®ć§ć™ć­ć€‚

ćƒšćƒ¼ć‚øćƒćƒ¼ć‚·ćƒ§ćƒ³ćÆH2ćŖ悉 offset ćØ limit 悒ä½æ恆恑恩态OraclećŖ悉 rownum 悒ä½æć†ć—ć€ę‚²č¦³ęŽ’ä»–ćÆOraclećŖ悉 for update 悒ä½æ恆恑恩态SQLServerćŖ悉 with(updlock) 悒ä½æ恆态ćØć„ć£ćŸę„Ÿć˜ć§ć™ć€‚ 恓恮č¾ŗ悒Doma恮äø­ć§åøåŽć—ć¦ćć‚Œć‚‹ć®ćŒ Dialect 恧恙怂

恝恆恧恙怂 DomaćÆ SelectOptions 恧 offset ćØ limit ć‚’ęŒ‡å®šć™ć‚‹äŗ‹ćŒć§ćć¾ć™ć€‚ ä»–ć«ć‚‚ę‚²č¦³ęŽ’ä»–ć€ćć‚Œć‹ć‚‰ć‚«ć‚¦ćƒ³ćƒˆå–å¾—ćŖć‚“ć‹ć®ęŒ‡å®šć‚‚ć§ćć¾ć™ć€‚

恓悌ćÆē§ć®čŖ¤ć‚Šć®ć‚ˆć†ć§ć™ć€‚ Maven惗惭ć‚ø悧ć‚Æ惈ćŖ恮恋态Gradle惗惭ć‚ø悧ć‚Æ惈ćŖć®ć‹ć€ćć†ć„ć£ćŸé•ć„ć«ć‚‚ć‚ˆć‚‹ć®ć‹ć‚‚ēŸ„ć‚Œć¾ć›ć‚“ćŒć€å°‘ćŖ恏ćØ悂Maven惗惭ć‚ø悧ć‚Æ惈恠ćØä½•ć‚‚äøéƒ½åˆćŖ恏ä½æ恈悋悈恆恧恙怂 NetBeans态恔悁悓ćŖ恕恄怂

DomaćÆć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć‚’ē›“ęŽ„č¦‹ć«č”Œćć®ć§ć‚¢ć‚Æć‚»ć‚µćƒ”ć‚½ćƒƒćƒ‰ćÆäøč¦ć§ć™ć€‚

ä»°ć‚‹é€šć‚Šć€å…±é€šé …ē›®ć ć‘ć‚’ęŒć¤åŸŗåŗ•ć‚Æćƒ©ć‚¹ćØćŖ悋ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚’ä½œć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚ åŸŗåŗ•ć‚Æćƒ©ć‚¹ćŒć‚ć‚Œć°ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ćÆ1恤恧č‰Æć„ć®ć§ć€ę„½ćØć„ćˆć°ę„½ć§ć™ć€‚

恓悌ćÆå¾Œę—„ć€ć‚µćƒ³ćƒ—ćƒ«ć‚’ä½œć‚ć†ćØę€ć„ć¾ć™ć€‚ (ē§ć®GitHubćƒŖ惝ć‚ø惈ćƒŖć‚’ę¼ć£ćŸć‚‰ę—¢ć«ć‚ć‚‹ć‹ć‚‚ēŸ„ć‚Œć¾ć›ć‚“ćŒ)

ćƒšćƒ¼ć‚øćƒćƒ¼ć‚·ćƒ§ćƒ³ćÆ SelectOptions 恮 offset ćØ limit ć§ęŒ‡å®šć—ć¾ć™ć€‚ Stream ꤜē“¢ćÆć‚ćć¾ć§ć‚‚ ResultSet.next 恗恦ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹å‡¦ē†ć‚’ Stream 恧č”Øē¾ć—恦恄悋恠恑恧恙怂

Stream 悒čæ”ć™ćŸć‚ć§ćÆćŖćć€ä»–ć®äŗ‹ć«åæƒć‚’č¾¼ć‚ć‚ˆć†ćŖļ¼ļ¼ļ¼

ā€¦ā€¦ćØć€å†—č«‡ćÆć•ć¦ćŠćć€å…ƒć€…ćÆSpring Batch恮 ItemReader 恧ćÆ ResultSet.next ćŒćƒ”ć‚½ćƒƒćƒ‰ć‚’ć¾ćŸćåæ…č¦ćŒć‚ć‚‹ćŸć‚ć€ćć‚Œć«åƾåæœć—ć‚„ć™ć„ć‚ˆć†ć«å…„ć‚Œć‚‰ć‚ŒćŸę©Ÿčƒ½ć§ć™ć€‚ 通åøøćÆä½æć†ę©Ÿä¼šćÆē„”恄ćØę€ć„ć¾ć™ć€‚

ć“ć‚Œć‚‚å¾Œę—„ć‚µćƒ³ćƒ—ćƒ«ć‚’ę›ø恄恦ćæ悈恆ćØę€ć„ć¾ć™ć€‚

Spring Boot恧ćÆćŖ恄Spring恧悂ä½æćˆć¾ć™ć€‚ å®Ÿč£…ć«ćÆ doma-spring-boot-autoconfigure ćŒå‚č€ƒć«ćŖ悋ćØę€ć„ć¾ć™ć€‚

Doma恌åæ…要ćØ恙悋恮ćÆ DataSource 恠恑恧恙恮恧态Spring恧悂Java EE恧悂Java SE恧悂态åŸŗęœ¬ēš„恫恩恓恧悂ä½æćˆć¾ć™ć€‚

ä½æćˆć¾ć™ć€‚ ć‚„ć£ć¦ć‚‹äŗ‹ćÆ単ē“”恧 Connection.setAutoCommit ćØ Connection.commit ćØ Connection.rollback 悒ēµ„ćæåˆć‚ć›ć¦ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ć‚’č”Œć£ć¦ć„ć‚‹ć ć‘ć§ć™ć€‚ 恂ćØćÆ ThreadLocal ć‚’åˆ©ē”Øć—ć¦ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ć®ęœŸé–“äø­ Connection ć‚’ć‚¹ćƒ¬ćƒƒćƒ‰ć«ē“ä»˜ć‘ć¦ć„ć¾ć™ć€‚

LocalTransactionDataSource ć¾ć‚ć‚Šć®ć‚³ćƒ¼ćƒ‰ćÆå°ć•ć„ć®ć§ć€čŖ­ć‚“恧ćæć‚‹ć®ć‚‚ę„½ć—ć„ć§ć™ć‚ˆļ¼

@Transactional ćÆJava EE悄SpringćØć„ć£ćŸć‚³ćƒ³ćƒ†ćƒŠć®ę©Ÿčƒ½ć§ć€DomaćÆć‚µćƒćƒ¼ćƒˆć—ć¦ć„ć¾ć›ć‚“ć€‚ Doma恮ēÆ„å›²ć‹ć‚‰ćÆé€ø脱恙悋ćØē§ćÆč€ƒćˆć¾ć™ć€‚

ćØćÆć„ćˆć€ä¾‹ćˆć°Guiceć®ć‚ˆć†ćŖč»½é‡ć‚³ćƒ³ćƒ†ćƒŠć§ć‚ć£ć¦ć‚‚ć‚¤ćƒ³ć‚æćƒ¼ć‚»ćƒ—ć‚æć®ę©Ÿčƒ½ć‚’ęœ‰ć—ć¦ć„ć‚‹ć®ć§ć€ Domać®ćƒ­ćƒ¼ć‚«ćƒ«ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ćØēµ„ćæåˆć‚ć›ć¦å®£č؀ēš„ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ę©Ÿčƒ½ć‚’č‡Ŗä½œć™ć‚‹ć“ćØćÆåÆčƒ½ć§ć™ć€‚

ć“ć‚Œć‚‚å¾Œę—„ć‚µćƒ³ćƒ—ćƒ«ć‚’GuicećØDoma恧ę›ø恄恦ćæć¾ć™ć­ć€‚

ć‚·ćƒ„ćƒ³ćƒ„ć•ć‚“ć€ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć™ļ¼ļ¼ļ¼

ć‚½ćƒƒć‚³ćƒ¼ć§å®Ÿč£…ć•ć‚Œć¦ć¦ć‚ć‚ćŸć€‚

ć§ć™ć­ć€ć‚ˆćć‚ć‹ć‚Šć¾ć™ć€‚ (ćŖć®ć§ć‚ćŒć¾ć¾čØ€ć†ć¤ć‚‚ć‚ŠćÆć‚ć‚Šć¾ć›ć‚“)

ē¢ŗć‹ć«ć€ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć‚’ęŽØé€²ć™ć‚‹ćØć‚Æćƒ©ć‚¹ę•°ćÆå¤šććŖć‚Šć¾ć™ćŒć€åž‹ć®ę©ęµć‚’å—ć‘ć‚‰ć‚Œć‚‹ćƒ”ćƒŖćƒƒćƒˆć®ę–¹ćŒå¤§ćć„ćØē§ćÆåˆ¤ę–­ć—ć¦ć„ć¾ć™ć€‚

ćƒ•ćƒ¬ćƒ¼ćƒ ćƒÆćƒ¼ć‚Æć‚„å…±é€šéƒØå“ć®ć‚ˆć†ćŖęŠ½č±”ēš„ćŖ層ćŖ悉 getValue ćøć®ć‚¢ć‚Æć‚»ć‚¹ć‚’čرåÆć—ć¾ć™ć€‚ ćƒ†ćƒ³ćƒ—ćƒ¬ćƒ¼ćƒˆć«ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć‚’ęø”ć™å “åˆćÆć‚³ćƒ³ćƒćƒ¼ć‚æ悒ę›øćć¾ć™(ä¾‹ćˆć°JAXB恮 XmlAdapter )怂 ćć®éš›ć€ć‚³ćƒ³ćƒćƒ¼ć‚æ恫ćÆ getValue ćøć®ć‚¢ć‚Æć‚»ć‚¹ć‚’čرåÆć—ć¾ć™ć€‚

恂悊恌ćØć†ć”ć–ć„ć¾ć™ć€‚ ęœ¬å½“ć«å¬‰ć—ć„ćŠčØ€č‘‰ć§ć™ć€‚ ć‚¤ćƒ™ćƒ³ćƒˆć‚’é–‹å‚¬ć—ć¦č‰Æć‹ć£ćŸć€‚

č›‡č¶³ļ¼šDDDćØ恮åƾęƔ(個äŗŗēš„ćŖč¦‹č§£)

ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ćØć„ć†åå‰ć®ć›ć„ć‹ć€DDDć«é–¢äæ‚恙悋恮恋ćŖļ¼ŸćØć„ć£ćŸćƒ„ć‚¤ćƒ¼ćƒˆć‚’č¦‹ć‹ć‘ćŸäŗ‹ćŒć‚ć‚Šć¾ć™ćŒć€DomaćÆDDDē”Øć®ćƒ•ćƒ¬ćƒ¼ćƒ ćƒÆćƒ¼ć‚Æ恧ćÆć‚ć‚Šć¾ć›ć‚“ć€‚ 恗恋恗态DDD恧čŖžć‚‰ć‚Œć‚‹å„要ē“ ćŒDoma恧čØ€ćˆć°ä½•ćŖć®ć‹ć‚’č€ƒćˆć‚‹äŗ‹ćÆć§ćć¾ć™ć€‚

個äŗŗēš„恫ćÆę¬”ć®ć‚ˆć†ć«č€ƒćˆć¦ć„ć¾ć™ć€‚

  • Domać®ć€Œćƒ†ćƒ¼ćƒ–ćƒ«ćØ1åƾ1ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć€ćÆ态DDDć®ć€Œć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć€ć«ē›øå½“ć™ć‚‹
  • Domać®ć€Œę¤œē“¢ēµęžœć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć€ćØć€Œćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć€ćÆ态DDDć®ć€Œå€¤ć‚Ŗ惖ć‚ø悧ć‚Æćƒˆć€ć«ē›øå½“ć™ć‚‹

ꇇč¦Ŗä¼šć«ć¤ć„ć¦

ä»Šå›žć€ę‡‡č¦Ŗä¼šć®ä¼ē”»ćÆć—ć¦ć„ćŸć®ć§ć™ćŒć€å‚åŠ č€…ć‚’å‹Ÿé›†ć—ć¾ć›ć‚“ć§ć—ćŸć€‚ 恓悌ćÆć€ęœ¬å½“ć«ē§ć®ęˆ‘å„˜ć§ć—ć¦ć€äø­ę‘ć•ć‚“ć€ćŒććžć•ć‚“ćØē§č‡Ŗčŗ«ćŒćŸćć•ć‚“č©±ć—ćŸć„ļ¼ćØå¼·ćę€ć£ć¦ć„ćŸć®ć§ć€åŗƒćå‹Ÿé›†ćÆć›ćšć«ć‚¹ć‚æ惃惕ćØęœ€å¾Œć¾ć§ę®‹ć£ć¦ä¼šå “ć®ē¾ēŠ¶å¾©åø°ć«ä»˜ćåˆć£ć¦ćć‚ŒćŸę–¹ć€…ę•°åć ć‘ćØć•ć›ć¦é ‚ćć¾ć—ćŸć€‚

ęˆ‘å„˜ć‚’é€šć—ćŸē”²ę–ćŒć‚ć£ć¦ć€ę„½ć—ć„å¤•é£Ÿć®ę™‚é–“ć‚’éŽć”ć•ć›ć¦é ‚ćć¾ć—ćŸć€‚

ć‚¤ćƒ™ćƒ³ćƒˆä¼šå “ć§ć‚ć‚‹dots恫恤恄恦

ć»ć‚“ć¾ćć‚Œć€‚

ęœ€é«˜ć§ć—ćŸļ¼ å‹‰å¼·ä¼šć‚’é–‹å‚¬ć—ćŸć„ę–¹ć«ćÆć€ä¼šå “å€™č£œć«ćŠć™ć™ć‚ć—ć¾ć™ļ¼

č¬č¾ž

ć“ć®ć‚¤ćƒ™ćƒ³ćƒˆć‚’é–‹å‚¬ć—ć‚ˆć†ćØę€ć£ćŸćć£ć‹ć‘ćÆć€ę˜„ć«ę±äŗ¬ćøéŠć³ć«č”Œć£ćŸéš›ć€äø€ē·’ć«ę™©å¾”é£Æć‚’é£Ÿć¹ć¦ćć‚Œć‚‹äŗŗć‚’å‹Ÿé›†ć—ćŸć‚‰ćŒććžć•ć‚“ćŒę„ć¦ćć ć•ć£ćŸćØć“ć‚ć‹ć‚‰å§‹ć¾ć‚Šć¾ć—ćŸć€‚ 恌恏恞恕悓恌怌äø€ē·’ć«ć‚„ć‚Šć¾ć—ć‚‡ć†ć€ćØčØ€ć£ć¦ćć ć•ć£ćŸć®ć§äø­ę‘ć•ć‚“ć«ć‚‚ćŠå£°ćŒć‘ć™ć‚‹å‹‡ę°—ćŒå‡ŗć¾ć—ćŸć€‚ ćŒććžć•ć‚“ć€ęœ¬å½“ć«ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć—ćŸļ¼

åŒć˜ćć€ćć®ę™©å¾”é£Æ恮åø­ć«å‚åŠ ć—ć¦ćć ć•ć£ć¦ćŠć‚Šć€ä¼šå “ćØ恗恦dotsć‚’ęŒ™ć’ć¦ćć ć•ć£ćŸ ćØćƒ¼ć¾ć™ć•ć‚“ ć«ć‚‚ę„Ÿč¬ć§ć™ļ¼ dotsć«é–¢ć™ć‚‹äŗ‹ć®ć‚µćƒćƒ¼ćƒˆć‚„态ꇇč¦Ŗä¼šć®ćŠåŗ—ć®ę‰‹é…ć‚’ć—ć¦ćć ć•ć‚Šć€ć‚ć‚ŠćŒćŸć‹ć£ćŸć§ć™ć€‚ ę™©å¾”é£Æ态ē¾Žå‘³ć—ć‹ć£ćŸćƒ¼ļ¼

ćć‚Œć‹ć‚‰ć€é‹å–¶ć®ę‰‹ä¼ć„ć‚’č²·ć£ć¦å‡ŗć¦ćć ć•ć£ćŸå¤šē”°ć•ć‚“ć€ć‚„ć‚“ćć•ć‚“ć€ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć—ćŸļ¼ ē„”čŒ¶ęŒÆ悊恮LT恫悂åæœćˆć¦ćć ć•ć‚Šć€ć‚¤ćƒ™ćƒ³ćƒˆćŒć‚ˆć‚ŠčÆ悄恋恫ćŖć‚Šć¾ć—ćŸļ¼

ćć—ć¦ć€äø­ę‘恕悓态ēŖē„¶ćŠå£°ćŒć‘ć—ćŸć«ć‚‚é–¢ć‚ć‚‰ćšē™»å£‡ć‚’åæ«ćå¼•ćå—ć‘ć¦ćć ć•ć£ć¦ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć—ćŸļ¼ ćšć£ćØä»„å‰ć‹ć‚‰ćŠä¼šć„ć—ćŸćć¦ć€ć§ć‚‚ćć£ć‹ć‘ćŒē„”ćć¦ć€ćŒććžć•ć‚“ć®ćŠć‹ć’ć§å‹‡ę°—ć‚’å‡ŗć›ć¦ć€ćŠå£°ćŒć‘ć—ć¦ć€ć‚ˆć†ć‚„ććŠä¼šć„ć§ćć¾ć—ćŸć€‚ ęœ¬å½“ć«ć€ęœ¬å½“ć«å¬‰ć—ć‹ć£ćŸć§ć™ļ¼ļ¼ļ¼

恂ćØć€å‹äŗŗ(ćØč”Øē¾ć•ć›ć¦ćć ć•ć„)恮 ć—ć‚‡ć¼ć”ć‚€ć€ 恆恌恕悓态 恦悓恦悓恕悓态 ć”ć£ć²ćƒ¼ć€ ćÆć™ć¬ć¾ć•ć‚“ć€ @suzukij恕悓态 Den恕悓态 ć¾ć‚ć“ćƒ¼ć€ę„ć¦ćć ć•ć£ć¦ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć—ćŸļ¼ äø­ę‘ć•ć‚“ć®å‰ć§ć®ē™ŗč”ØćÆ恓悌恧悂恋ļ¼ļ¼ļ¼ć£ć¦ćć‚‰ć„ē·Šå¼µć—ć¦ć„ćŸć‘ć©ć€ćæ悓ćŖćŒå±…ć‚‹ćØę€ćˆć°ć“ćęœ€å¾Œć¾ć§ē™ŗč”Øć§ććŸę°—ćŒć—ć¾ć™ć€‚

ć‚·ćƒ„ćƒ³ćƒ„ć•ć‚“ć€ę„ć¦ćć ć•ć£ć¦ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć—ćŸļ¼ 参加ē™»éŒ²č€…悒見恦态åÆ†ć‹ć«ć€ŒćŠä¼šć„ć§ćć‚‹ļ¼ć€ćØćƒÆć‚ÆćƒÆć‚Æć—ć¦ć„ć¾ć—ćŸć€‚ ćŠä¼šć„ć§ćć¦å¬‰ć—ć‹ć£ćŸć§ć™ļ¼

ęœ€å¾Œć«ćŖć‚Šć¾ć™ćŒć€å‚åŠ ć—ć¦ćć ć•ć£ćŸēš†ć•ć‚“ć€ęœ¬å½“ć«ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć—ćŸļ¼ ēš†ć•ć‚“ć®ćŠć‹ć’ć§ć‚¤ćƒ™ćƒ³ćƒˆćŒč³‘ć‚„ć‹ć«ćŖć‚Šć€ę„½ć—ćéŽć”ć™äŗ‹ćŒć§ćć¾ć—ćŸć€‚

ęœ¬å½“ć«ę„½ć—ć„ć€å¤¢ć®ć‚ˆć†ćŖ1ę—„ć§ć—ćŸć€‚

ćæ悓ćŖć§ę’®ć£ćŸé›†åˆå†™ēœŸćÆ态MBPć®ćƒ‡ć‚¹ć‚Æćƒˆćƒƒćƒ—ć‚’é£¾ć£ć¦ć„ć¾ć™ć€‚

]]>
Tue, 12 Jul 2016 00:00:00 +0900
http://backpaper0.github.io/2016/06/12/slider.html http://backpaper0.github.io/2016/06/12/slider.html <![CDATA[関Java恧ä½æć£ć¦ćŸć‚¹ćƒžćƒ›ć§ć‚¹ćƒ©ć‚¤ćƒ‰ć‚ćć‚‹ć‚„ć¤]]> 関Java恧ä½æć£ć¦ćŸć‚¹ćƒžćƒ›ć§ć‚¹ćƒ©ć‚¤ćƒ‰ć‚ćć‚‹ć‚„ć¤

今ꗄćÆ関Java恧恗恟ļ¼

恧态ē§ć‚‚ē™ŗč”Ø恗恟悓恧恙恌ā€¦ā€¦

ā€¦ā€¦ćØć„ć†ćƒ„ć‚¤ćƒ¼ćƒˆć‚’č¦‹ć¦ć€ę°—ä»˜ć„ć¦ćć‚ŒćŸļ¼ ćć“ć«čˆˆå‘³ęŒć£ć¦ćć‚Œć¦å¬‰ć—ć„ćžļ¼ ćØ恄恆ꄟ恘ćŖć®ć§ć€ć“ć‚Œć«ć¤ć„ć¦ę›øćć¾ć™ć€‚

ć‚¹ćƒ©ć‚¤ćƒ‰ć‚ćć‚‹ć‚„ć¤ć„ć„ćŖćƒ¼

恄悍悓ćŖäŗŗ恌ē™ŗč”Ø恗恦恄悋恮悒見恦恄悋ćØ态ćŖ悓恋ćƒŖćƒ¢ć‚³ćƒ³ēš„ćŖ悄恤ćØ恋ꌇč¼Ŗć£ć½ć„ć‚„ć¤ć§ćƒŖćƒ¢ćƒ¼ćƒˆć§ć‚¹ćƒ©ć‚¤ćƒ‰ć‚ćć£ć¦ć¦ć€Œć„ć„ćŖćƒ¼ć‚¢ćƒ¬ć€ćØę€ć£ć¦ć„ć¾ć—ćŸć€‚

恧态č‡Ŗåˆ†ć‚‚ē™ŗč”Ø恙悋Ꙃ恫ä½æ恄恟恄ćŖćØę€ć£ćŸć‚“ć§ć™ć‘ć©ć€ć‚¹ćƒžćƒ›ćŒćƒŖćƒ¢ć‚³ćƒ³ēš„恫ä½æćˆćć†ć ć—ę“ä½œćÆćƒšćƒ¼ć‚ø送悊恧恍恟悉č‰Æć„ć ć‘ć ć—ä½œć‚‹ć‹ćƒ¼ć€ćØ怂

ä½œć£ć¦ćæ恟

ć–ć£ćć‚ŠčØ€ć†ćØ态Webć‚¢ćƒ—ćƒŖ恫ćŖć£ć¦ć„ć¾ć—ć¦ć€ć‚¹ćƒžćƒ›ć®ćƒ–ćƒ©ć‚¦ć‚¶ć§ćƒšćƒ¼ć‚ø悒開恏ćØWebSocket恧通äæ”ć‚’é–‹å§‹ć—ć€ć‚³ćƒžćƒ³ćƒ‰ć‚’é€ć£ć¦ćƒšćƒ¼ć‚øé€ć‚Šć‚’č”Œć£ć¦ć„ć¾ć™ć€‚

ä½æć„ę–¹ćØ仕ēµ„ćæ

ä½æć„ę–¹ćØå…±ć«ć‚‚ć†ć”ć‚‡ć„č©³ć—ćę›øćć¾ć™ć€‚

ć¾ćšć‚³ćƒ¼ćƒ‰ć‚’ clone ć—ć¦ć€ćƒ“ćƒ«ćƒ‰ć—ć¾ć™ć€‚

git clone https://github.com/backpaper0/slider.git

cd slider

gradlew build

恙悋ćØ build/libs/slider.jar 恌å‡ŗåŠ›ć•ć‚Œć¾ć™ć€‚

ć‚¹ćƒ©ć‚¤ćƒ‰ć‚’č”Øē¤ŗ恙悋ē«Æęœ«ć§Webć‚¢ćƒ—ćƒŖć‚’čµ·å‹•ć—ć¾ć™ć€‚

java -jar build/libs/slider.jar

ćŖćŠć€ć‚µćƒ¼ćƒćƒ¼ć«ćÆUndertow悒ä½æć£ć¦ć„ć¾ć™ć€‚ ć¾ćŸć€mainćƒ”ć‚½ćƒƒćƒ‰ć®čµ·å‹•ć«ćÆSpringBoot悒ä½æć£ć¦ć„ć¾ć™ć€‚

Webć‚¢ćƒ—ćƒŖćŒčµ·å‹•ć™ć‚‹ćØć‚¹ćƒžćƒ›ć®ćƒ–ćƒ©ć‚¦ć‚¶ć‹ć‚‰Webćƒšćƒ¼ć‚ø悒開恏åæ…č¦ćŒć‚ć‚‹ć®ć§ć™ćŒć€ćć®ćŸć‚ć«ē§ćÆć‚¹ćƒžćƒ›ć§ćƒ†ć‚¶ćƒŖćƒ³ć‚°ć‚’ć—ć¦ć„ć¾ć™ć€‚ ćƒ†ć‚¶ćƒŖćƒ³ć‚°ć‚’ć—ć¦ć€ ipconfig ćØ恋 ifconfig 恧ē«Æęœ«ć®IPć‚¢ćƒ‰ćƒ¬ć‚¹ć‚’ē¢ŗčŖć—ćŸć‚‰ http://<ipaddress>:8080/ ćøć‚¹ćƒžćƒ›ć§ć‚¢ć‚Æć‚»ć‚¹ć—ć¾ć™ć€‚

ē”»é¢ćÆ恓悓ćŖꄟ恘怂

../../../_images/slider.png

Left ćØ Right ć§ćć‚Œćžć‚Œå·¦ćƒ»å³ć«ćƒšćƒ¼ć‚øć‚’é€ć‚Šć¾ć™ć€‚ ćć®éš›ć€ć‚¹ć‚ÆćƒŖćƒ¼ćƒ³ć‚·ćƒ§ćƒƒćƒˆć‚’ę’®ć£ć¦ćƒ–ćƒ©ć‚¦ć‚¶ć«é€ć‚Šć¾ć™ć€‚ ć‚¹ć‚ÆćƒŖćƒ¼ćƒ³ć‚·ćƒ§ćƒƒćƒˆćÆ Screenshot 惜ć‚æćƒ³ć§ć‚‚å–å¾—ć§ćć¾ć™ć€‚ ćć—ć¦ Presentation 恧恙恌态恓悌ćÆē§ćŒåˆ©ē”Ø恗恦恄悋 remark ćØć„ć†ć‚¹ćƒ©ć‚¤ćƒ‰ćƒ„ćƒ¼ćƒ«ć®ćƒ—ćƒ¬ć‚¼ćƒ³ćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćƒ¢ćƒ¼ćƒ‰ć‚’åˆ‡ć‚Šę›æćˆć‚‹ćŸć‚ć«ä½æć„ć¾ć™ć€‚

ć“ć‚Œć‚‰ć®å®Ÿē¾ę–¹ę³•ć§ć™ćŒć€ć¾ćš Screenshot 悄 Left ć®ćƒœć‚æćƒ³ć‚’ęŠ¼ć™ćØWebSocketć§ć‚µćƒ¼ćƒćƒ¼ć«ć‚³ćƒžćƒ³ćƒ‰ć‚’é€ć‚Šć¾ć™ć€‚ ć‚³ćƒžćƒ³ćƒ‰ćØčØ€ć£ć¦ć‚‚ SCREENSHOT 悄 LEFT ćØć„ć£ćŸå˜ē“”ćŖę–‡å­—åˆ—ć§ć™ć€‚

ć‚µćƒ¼ćƒćƒ¼ć§ćÆć‚³ćƒžćƒ³ćƒ‰ć‚’å—ć‘å–ć‚‹ćØ Robotć‚Æćƒ©ć‚¹ ć‚’åˆ©ē”Ø恗恦 ć‚¹ć‚ÆćƒŖćƒ¼ćƒ³ć‚·ćƒ§ćƒƒćƒˆć‚’ę’®ć£ćŸć‚Š 态 ć€Œå·¦ćƒœć‚æćƒ³ć‚’ęŠ¼ć™ć€ćØć„ć†ć‚·ć‚¹ćƒ†ćƒ å…„åŠ›ć‚¤ćƒ™ćƒ³ćƒˆć‚’ē™ŗē”Ÿć•ć›ćŸć‚Š ć—ć¾ć™ć€‚ ć“ć‚Œć§ć‚¹ćƒ©ć‚¤ćƒ‰ć®ćƒšćƒ¼ć‚øé€ć‚ŠćŒć§ćć¾ć—ćŸć€‚ ćŖćŠć€ć‚¹ć‚ÆćƒŖćƒ¼ćƒ³ć‚·ćƒ§ćƒƒćƒˆćÆBase64ć‚Øćƒ³ć‚³ćƒ¼ćƒ‰ć—ć¦Data URIć«ć—ć¦ćƒ–ćƒ©ć‚¦ć‚¶ć«é€ć£ć¦ć„ć¾ć™ć€‚ ćƒ–ćƒ©ć‚¦ć‚¶å“ć§ćÆćć‚Œć‚’ćć®ć¾ć¾Canvas恫ę›ø恍å‡ŗć—ć¦ć„ć¾ć™ć€‚

ę¬²ć—ć„ć‚‚ć®ćÆä½œć‚Œć°ć„ć„ć‚„

仕ēµ„ćæćØ恗恦ćÆ仄äøŠć§ć—ć¦ć€ć¾ć‚čŖ¬ę˜Žć—恦ćæ悋ćØå¤§ć—ćŸć“ćØćÆ恗恦恄ćŖć„ć‚“ć§ć™ćŒć€ć“ć‚Œć¾ć§ćƒ—ćƒ©ć‚¤ćƒ™ćƒ¼ćƒˆć‚³ćƒ¼ćƒ‡ć‚£ćƒ³ć‚°ć§ćÆćƒ•ćƒ¬ćƒ¼ćƒ ćƒÆćƒ¼ć‚Æć‚’č©¦ć—ćŸć‚Šć‚µćƒ³ćƒ—ćƒ«ć‚³ćƒ¼ćƒ‰ć°ć‹ć‚Šę›ø恍ęØć¦ć¦ć„ćŸć®ć§ć€ę”¹ć‚ć¦ć€Œę¬²ć—ć„ćØę€ć£ćŸć‚‚ć®ć‚’č‡Ŗåˆ†ć§ć‚‚ä½œć‚Œć‚‹ć‚‚ć‚“ć ćŖćƒ¼ć€ćØ恗ćæ恘ćæę€ć„ć¾ć—ćŸć€‚ ę¬²ć—ć‘ć‚Šć‚ƒä½œć‚ć€ćØę€ć†ć‚ˆć†ć«ćŖć£ć¦ććŸć®ćÆć€ć“ć®ę•°å¹“ć§å‡ŗä¼šć£ćŸä½•äŗŗ恋恮ć‚Øćƒ³ć‚øćƒ‹ć‚¢ć®ćŠé™°ć§ć™ć€‚ åå‰ć‚’å‡ŗ恙恮ćÆē…§ć‚Œćć•ć„恮恧å‡ŗć—ć¾ć›ć‚“ćŒć€ęœ¬å½“ć«å°Šę•¬ć—ć¦ć„ć¾ć™ć€‚

ć¾ćØ悁

  • ä½œć£ć¦ćÆćæćŸć‚‚ć®ć®ć€ä½æć†ę©Ÿä¼šć‚’é€ƒć—ć¦ćŠć‚Šä»Šå›žćŒåˆć®å®Ÿč·µć§ć—ćŸćŒć€ćŖ恋ćŖ恋äøŠę‰‹ćč”Œć£ć¦č‰Æć‹ć£ćŸļ¼
  • 何äŗŗć‹ć®ę–¹ć«ę°—ä»˜ć„ć¦č²°ćˆć¦å¬‰ć—ć‹ć£ćŸļ¼(ć€Œę©Ÿä¼šćŒć‚ć£ćŸć‚‰ä½æć‚ć›ć¦ę¬²ć—ć„ć€ćØć¾ć§čØ€ć£ć¦ćć‚ŒćŸę–¹ć‚‚å±…ćŸļ¼)

ä½æ恄ćŖćŒć‚‰ć‚‚ć£ćØä¾æåˆ©ć«ćŖć‚‹ć‚ˆć†ć«ć”ć¾ć”ć¾ćƒ”ćƒ³ćƒ†ć—ćŸć„ę‰€å­˜ć§ć™ć€‚

]]>
Sun, 12 Jun 2016 00:00:00 +0900
http://backpaper0.github.io/2016/05/08/boxsing_and_cache.html http://backpaper0.github.io/2016/05/08/boxsing_and_cache.html <![CDATA[惜ć‚Æć‚·ćƒ³ć‚°ćØć‚­ćƒ£ćƒƒć‚·ćƒ„]]> 惜ć‚Æć‚·ćƒ³ć‚°ćØć‚­ćƒ£ćƒƒć‚·ćƒ„

Integerć®ć‚­ćƒ£ćƒƒć‚·ćƒ„

int 恌惜ć‚Æć‚·ćƒ³ć‚°ć•ć‚Œć‚‹ćØ java.lang.Integer 恫ćŖć‚Šć¾ć™ćŒć€ć“ć®ćØ恍 Integer.valueOf(int) 恌ä½æć‚ć‚Œć¾ć™ć€‚ 恓恮恓ćØćÆę¬”ć®ć‚ˆć†ćŖ惜ć‚Æć‚·ćƒ³ć‚°ć•ć‚Œć‚‹ć‚³ćƒ¼ćƒ‰ć‚’ę›øć„ć¦ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć—ć¦ć‹ć‚‰javapć™ć‚Œć°ć‚ˆćåˆ†ć‹ć‚Šć¾ć™ć€‚

public class IntBoxingSample {
    public Integer boxing(int i) {
        return i;
    }
}

javap恗恦ćæ恟ēµęžœćÆꬔ恮通悊怂

Compiled from "IntBoxingSample.java"
public class IntBoxingSample {
  public IntBoxingSample();
    Code:
       0: aload_0
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: return

  public java.lang.Integer boxing(int);
    Code:
       0: iload_1
       1: invokestatic  #2                  // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       4: areturn
}

恧态恓恮 Integer.valueOf(int) 恧恙恌态 -128 恋悉 127 ć¾ć§ć®ēƄ囲ćÆć‚­ćƒ£ćƒƒć‚·ćƒ„ć•ć‚Œć¾ć™ć€‚

恓恮恓ćØćÆ č؀čŖžä»•ę§˜ć®5.1.7 悄 Integer.valueOf(int)恮Javadoc 恫ę›øć‹ć‚Œć¦ć„ć¾ć™ć€‚

ć§ć‚‚ć£ć¦ć€OpenJDKć®ć‚³ćƒ¼ćƒ‰ć‚’č¦‹ćŸę„Ÿć˜ć€ java.lang.Integer.IntegerCache.high ćØć„ć†ć‚·ć‚¹ćƒ†ćƒ ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć§ć‚­ćƒ£ćƒƒć‚·ćƒ„ć™ć‚‹ēÆ„å›²ć‚’å¤‰ę›“ć§ććć†ć§ć™ć€‚

ćØć„ć†ć‚ć‘ć§ę¬”ć®ć‚ˆć†ćŖć‚³ćƒ¼ćƒ‰ć‚’ę›øć„ć¦ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć—ć¦ę™®é€šć«å®Ÿč”Œć™ć‚‹ćØ false ćØč”Øē¤ŗć•ć‚Œć¾ć™ćŒć€ -Djava.lang.Integer.IntegerCache.high=1000 ćØ恄恆é¢Øć«ć‚·ć‚¹ćƒ†ćƒ ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć‚’čØ­å®šć—ć¦å®Ÿč”Œć™ć‚‹ćØ true ćØč”Øē¤ŗć•ć‚Œć¾ć™ć€‚

public class Sample {
    public static void main(String[] args) {
        Integer a = 1000;
        Integer b = 1000;
        System.out.println(a == b);
    }
}

å®Ÿč”ŒēµęžœćÆꬔ恮通悊怂

% java Sample
false
% java -Djava.lang.Integer.IntegerCache.high=1000 Sample
true

ä»–ć®ćƒ—ćƒŖćƒŸćƒ†ć‚£ćƒ–ć‚‚č¦‹ć¦ćæ恟

Byte 态 Short 态 Long ćÆ Integer ćØåŒć˜ć -128 恋悉 127 ć¾ć§ć‚­ćƒ£ćƒƒć‚·ćƒ„ć•ć‚Œć¦ć„ć¾ć—ćŸć€‚ ćŸć ć—ć‚­ćƒ£ćƒƒć‚·ćƒ„ć®ēƄ囲ćÆå¤‰ę›“ć§ćć¾ć›ć‚“ć€‚

恝悌恋悉 Character ćÆ 0 恋悉 127 ć¾ć§ć‚­ćƒ£ćƒƒć‚·ćƒ„ć•ć‚Œć¦ć„ć¾ć—ćŸć€‚ ASCIIę–‡å­—ć‚³ćƒ¼ćƒ‰ć® NUL 恋悉 DEL 恧恙恭怂

Boolean ćÆå®šę•° TRUE ćØ FALSE 恮恩恔悉恋悒čæ”ć™ć‚ˆć†ć«ćŖć£ć¦ć„ć¾ć™ć€‚

ęœ€å¾Œć« Float ćØ Double ć§ć™ćŒć€ć©ć”ć‚‰ć‚‚ć‚­ćƒ£ćƒƒć‚·ćƒ„ć›ćšåøøć«ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć™ć‚‹ć‚ˆć†ć«ćŖć£ć¦ć„ć¾ć—ćŸć€‚ ęµ®å‹•å°ę•°ē‚¹ę•°ćŖ恮恧 -128.0 恋悉 127.0 恮間恫悂č†Ø大ćŖé‡ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ē”Ÿęˆć—å¾—ć‚‹ć®ć§ć€ć¾ć‚ć€ćć‚Šć‚ƒć‚­ćƒ£ćƒƒć‚·ćƒ„恗ćŖ恄恋态ćØ恄恆ꄟ恘怂

ć¾ćØ悁

仄äøŠć®ć‚ˆć†ć«ę™®ę®µćÆꄏ識恗ćŖ恄悈恆ćŖéƒØåˆ†ć§ć‚­ćƒ£ćƒƒć‚·ćƒ„ć—ć¦ćŠć‚Šćƒ‘ćƒ•ć‚©ćƒ¼ćƒžćƒ³ć‚¹å‘äøŠć‚’å›³ć£ć¦ć„ćŸć‚Šć—ć¦ć„ć¾ć™ć€‚ ć“ć†ć„ć£ćŸJDK恮åŠŖåŠ›ć«ę„Ÿč¬ć—ć¤ć¤ć€ä»Šå¾Œć‚‚ę„č­˜ć›ćšć«ć‚³ćƒ¼ćƒ‡ć‚£ćƒ³ć‚°ć—ć‚ˆć†ćØę€ć„ć¾ć™ć€‚

]]>
Sun, 08 May 2016 00:00:00 +0900
http://backpaper0.github.io/2016/03/24/tokyo.html http://backpaper0.github.io/2016/03/24/tokyo.html <![CDATA[ę±äŗ¬ć§ćæ悓ćŖćØ遊悓恧恍恟]]> ę±äŗ¬ć§ćæ悓ćŖćØ遊悓恧恍恟

Elasticsearchćƒćƒ³ć‚ŗć‚Ŗćƒ³ć«å‚åŠ ć—ćŸć®ć§ ć¤ć„ć§ć«ę±äŗ¬ć¾ć§č”Œć£ć¦ćæ悓ćŖćØ遊悓恧恍恟ļ¼

ć›ć‚ć¦ćƒćƒ¼ćŸć”ćØć‚«ćƒ©ć‚Ŗć‚±č”Œć£ćŸć‚Šć€ 恌恏恞恕悓ćØåˆć‚ć¦ćŠä¼šć„ć—ćŸć‚Šć€ ć—ć‚‡ć¼ć”ć‚€ćŗ悍ćŗ悍恗恟悊态 ć¾ćƒ¼ć‚„ć•ć‚“ćƒ»ć”ć£ć²ćƒ¼ćÆäŗŒę—„連ē¶šć§éŠć‚“ć§ćć‚ŒćŸć‚Šć€ ćØćƒ¼ć¾ć™ć•ć‚“ćŒé›†åˆę™‚é–“ć‚’äø€ę™‚é–“å‹˜é•ć„ć—ć¦ćŸć‚Šć€ ć¾ć‚ć“ćƒ¼ćŒ3000äø‡å††ć®č»Šć‚’č²·ćŠć†ćØć—ć¦ć„ćŸć‚Šć€ é«˜ę ”ę™‚ä»£ć®å‹äŗŗ恌(ē§ćŒRT恙悋恛恄恧)ć“ć–ć‘ć•ć‚“ć®ćƒ•ć‚”ćƒ³ć«ćŖć£ć¦ć„ćŸć‚Šć€ ę„½ć—ć„ä¼‘ę—„ć‚’éŽć”ć•ć›ć¦ć‚‚ć‚‰ć£ćŸļ¼ļ¼ļ¼

恂ćØć€ć‚°ćƒ©ćƒ‹ćƒ¼ć‚¹ćƒŸć‚¹ć®ć‚¢ćƒƒćƒ—ćƒ«ćƒ‘ć‚¤ćÆć‚ć„ć‹ć‚ć‚‰ćšęœ€é«˜ć ć£ćŸć€‚ ę±äŗ¬ć«č”Œć£ćŸć‚‰åæ…ćšé£Ÿć¹ćŸć„äø€å“ć€‚

../../../_images/grannysmith-applepie.jpg

ćæ悓ćŖ恂悊恌ćØ恆怜

ę„½ć—ć‹ć£ćŸļ¼ļ¼ļ¼

]]>
Thu, 24 Mar 2016 00:00:00 +0900
http://backpaper0.github.io/2016/03/24/elastichandson.html http://backpaper0.github.io/2016/03/24/elastichandson.html <![CDATA[Acroquest Technologyē¤¾ć®Elasticsearchćƒćƒ³ć‚ŗć‚Ŗćƒ³ć«č”Œć£ć¦ććŸ #elastichandson]]> Acroquest Technologyē¤¾ć®Elasticsearchćƒćƒ³ć‚ŗć‚Ŗćƒ³ć«č”Œć£ć¦ććŸ #elastichandson

Elasticsearchć€ć¾ć£ćŸćč§¦ć£ćŸć“ćØē„”ćć¦ćć‚ćć‚č§¦ć‚ć†ć‹ćŖćƒ¼ćØę€ć£ć¦ćŸēŸ¢å…ˆć«ćƒćƒ³ć‚ŗć‚Ŗćƒ³ćŒć‚ć‚‹ć“ćØ悒ēŸ„ć£ć¦å³ē”³ć—č¾¼ć‚“ć§č”Œć£ć¦ćć¾ć—ćŸć€‚

ćƒćƒ³ć‚ŗć‚Ŗćƒ³ć®ę¦‚č¦

Acroquest Technologyē¤¾ćŒę„­å‹™ć§åŽé›†ć—ćŸå®Ÿćƒ‡ćƒ¼ć‚æć‚’ćƒ™ćƒ¼ć‚¹ć«ć—ćŸå¤§é‡ć®ćƒ‡ćƒ¼ć‚æ悒ä½æć£ć¦Logstash/Elasticsearch/Kibanać®ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«ć‹ć‚‰å…„é–€ēš„ćŖę“ä½œć‚’č”Œć„ć¾ć—ćŸć€‚

ę„Ÿęƒ³

ćƒ¬ćƒ™ćƒ«ēš„恫ćÆ先čæ°ć®é€šć‚Šć€å…„門ļ¼ć£ć¦ę„Ÿć˜ć§ć—ćŸćŒć€äøåƧćŖč³‡ę–™ć‚„å®Ÿćƒ‡ćƒ¼ć‚æ悒悂ćØć«ć—ć¦ę‰‹ć‚’å‹•ć‹ć—ćŸć®ć‚‚ć‚ć£ć¦ę¬”ć®å­¦ēæ’ć‚¹ćƒ†ćƒƒćƒ—ć‚’ęƒ³åƒć—ć‚„ć™ćć¦č‰Æć‹ć£ćŸć§ć™ć€‚

個äŗŗēš„恫ćÆElasticsearch恫ćÆčˆˆå‘³ćŒć‚ć£ćŸć‚“ć ć‘ć©ć€ LogstashćØ恋KibanaćØć‹ćƒŠćƒ‹ćƒ¢ćƒŽćŖć®ć‹ć‚ˆćåˆ†ć‹ć‚‰ćŖ恄恗态 čˆˆå‘³ćÆ恂悋恑恩č‡Ŗåˆ†ć®ćƒŖć‚½ćƒ¼ć‚¹ę³ØćŽč¾¼ćæć¾ćć‚‹ć»ć©(å½“ę™‚ćÆ)å„Ŗ先順位ćÆé«˜ććŖć‹ć£ćŸć®ć§ć€ ćć†ć„ć£ćŸę„å‘³ć§ć‚‚č§¦ć‚Œć‚‹ę©Ÿä¼šć‚’å¾—ć‚‰ć‚Œć¦åŠ©ć‹ć‚Šć¾ć—ćŸć€‚

ćć®ä»–

ć‚¹ćƒ†ćƒƒć‚«ćƒ¼ć€äø€é€šć‚Šć‚‚ć‚‰ć„ć¾ć—ćŸļ¼

ē“ ę™“悉恗恄ļ¼ļ¼ļ¼(恄悍悓ćŖę„å‘³ć§)

ćć¤ć­ć•ć‚“ć®ć‚¢ć‚¤ćƒ‡ć‚¢ć‚’å…ƒć«ć€

  • ę•°å€¤ę¼”ē®—å­ć‚’ä½æ悏ćŖćć¦ęøˆć‚€ć‚ˆć†ć« Random.nextInt 悒ä½æē”Ø
  • newę¼”ē®—å­ć‚’ä½æ悏ćŖć„ćŸć‚ć«staticćƒ•ć‚”ć‚Æ惈ćƒŖćƒ¼ćƒ”ć‚½ćƒƒćƒ‰ćŒć‚ć‚‹ SecureRandom 悒ä½æē”Ø

ćØć„ć£ćŸäŗ‹ć«ę°—ć‚’ć¤ć‘ć¦ę¬”ć®ć‚ˆć†ćŖć‚³ćƒ¼ćƒ‰ć«ć—ć¾ć—ćŸć€‚

//恓悌ćÆć‚»ćƒŸć‚³ćƒ­ćƒ³ć‚’ę›ø恄恦č‰Æ恄ꙮ通恮Java

//恓悌恧1怜100恮IntStreamćŒę‰‹ć«å…„ć‚‹
SecureRandom r = SecureRandom.getInstanceStrong();
IntStream stream = IntStream.generate(() -> r.nextInt(101))
                            .distinct().limit(101)
                            .sorted().skip(1);

恔ćŖćæ恫态ē§ćŒč€ƒćˆć¤ć„ćŸć®ćÆę¬”ć®ć‚ˆć†ćŖć‚³ćƒ¼ćƒ‰ć§ć—ćŸć€‚

//恓悌ćÆć‚»ćƒŸć‚³ćƒ­ćƒ³ć‚’ę›ø恄恦č‰Æ恄ꙮ通恮Java
Stream.of((ArrayList) Collectors.toList().supplier().get())
      .peek(list -> list.add(BigInteger.ONE))
      .map(list -> IntStream.generate(() ->
         Stream.of((BigInteger) list.get(0))
               .peek(a -> list.remove(0))
               .peek(a -> list.add(a.add(BigInteger.ONE)))
               .findFirst().get().intValue()))
      .findFirst().get();

ē°”å˜ć«čØ€ć†ćØ ArrayList ć‹ć‚‰å€¤ć‚’å–ć‚Šå‡ŗ恗恦čæ”ć—ć€ćć®å€¤ć«1č¶³ć—ć¦ć€ć¾ćŸ ArrayList ć«ę ¼ē“ć™ć‚‹ć€ć‚’ē¹°ć‚Ščæ”ć—ć¦ć„ć¾ć™ć€‚

ArrayList 恮ē”Ÿęˆć«ćÆ Collectors.toList 恧čæ”ć•ć‚Œć‚‹ Collector 恮 supplier ć‚’åˆ©ē”Øć—ć¾ć—ćŸć€‚ ć¶ć£ć”ć‚ƒć‘ Collectors.toList ć®å®Ÿč£…ć«ä¾å­˜ć—ć¦ćŠć‚Šē¾Žć—恏ćŖ恄恧恙恭怂

ć¾ćŸć€čØ˜å·ć‚’ęŠ‘ćˆć‚‹ćŸć‚ć«rawåž‹ć‚’ä½æē”Øć—ć¦ć„ć¾ć™ćŒć€ćć®ć›ć„ć§ć‚­ćƒ£ć‚¹ćƒˆćŒå¤šē™ŗć—ć¦ćŠć‚Šć€ć“ć‚Œć‚‚ē¾Žć—恏ćŖ恄恧恙怂

ćć®ē‚¹ć€ćć¤ć­ć•ć‚“ćŒęę”ˆć—ć¦ćć‚ŒćŸę–¹ę³•ćÆć‚³ćƒ¼ćƒ‰ćŒē¾Žć—ćć€ć‚ˆć‚Šē‹‚ę°—ćŒć‚ćµć‚Œć¦ćŠć‚Šē“ ę™“悉恗恄ļ¼ļ¼ļ¼

ćØć„ć†ć‚ć‘ć§ć€ć‚»ćƒŸć‚³ćƒ­ćƒ³ćŖć©ćƒ¬ć‚¹Java恧ę›ø恄恟FizzBuzzćÆę¬”ć®ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚

public class SemicolonlessFizzBuzz {

    public static void main(String... args) throws Exception {
        if (java.util.stream.Stream
            .of(java.security.SecureRandom.getInstanceStrong())
            .map(r -> java.util.stream.IntStream
                .generate(() -> r.nextInt(101))
                .distinct().limit(101).sorted().skip(1)
                .mapToObj(i -> java.util.Optional.of(java.math.BigInteger.valueOf(i)))
                .map(i -> i.filter(a -> a.mod(java.math.BigInteger.valueOf(15))
                    .equals(java.math.BigInteger.ZERO)).map(a ->
                                    String.valueOf((char) 0x46)
                            .concat(String.valueOf((char) 0x69))
                            .concat(String.valueOf((char) 0x7a))
                            .concat(String.valueOf((char) 0x7a))
                            .concat(String.valueOf((char) 0x42))
                            .concat(String.valueOf((char) 0x75))
                            .concat(String.valueOf((char) 0x7a))
                            .concat(String.valueOf((char) 0x7a)))
         .orElseGet(() -> i.filter(a -> a.mod(java.math.BigInteger.valueOf(3))
                    .equals(java.math.BigInteger.ZERO)).map(a ->
                                    String.valueOf((char) 0x46)
                            .concat(String.valueOf((char) 0x69))
                            .concat(String.valueOf((char) 0x7a))
                            .concat(String.valueOf((char) 0x7a)))
         .orElseGet(() -> i.filter(a -> a.mod(java.math.BigInteger.valueOf(5))
                    .equals(java.math.BigInteger.ZERO)).map(a ->
                                    String.valueOf((char) 0x42)
                            .concat(String.valueOf((char) 0x75))
                            .concat(String.valueOf((char) 0x7a))
                            .concat(String.valueOf((char) 0x7a)))
                .orElseGet(() -> i.get().toString()))))
            .collect(java.util.stream.Collectors.joining(String.valueOf((char) 0x20))))
            .peek(fizzbuzz -> System.out.println(fizzbuzz))
            .count() > 0) {}
    }
}
]]>
Wed, 09 Dec 2015 00:00:00 +0900
http://backpaper0.github.io/2015/12/05/semicolonless_java_enum_method.html http://backpaper0.github.io/2015/12/05/semicolonless_java_enum_method.html <![CDATA[ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Java 8ć®ę–°ę©Ÿčƒ½ć€Œenumć«ćƒ”ć‚½ćƒƒćƒ‰ē”Ÿć‚„ć™ć€ #semicolonlessjava]]> ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Java 8ć®ę–°ę©Ÿčƒ½ć€Œenumć«ćƒ”ć‚½ćƒƒćƒ‰ē”Ÿć‚„ć™ć€ #semicolonlessjava

恓悌ćÆ ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Java Advent Calendar 2015 恮5ę—„ē›®ć§ć™ć€‚

ćƒ¬ć‚¬ć‚·ćƒ¼ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Java恫恊恑悋enumć®åˆ¶é™

Javač؀čŖžć§ćÆenumć«ćƒ”ć‚½ćƒƒćƒ‰ć‚’ē”Ÿć‚„恙äŗ‹ćŒć§ćć¾ć™ć€‚

//恓悌ćÆć‚»ćƒŸć‚³ćƒ­ćƒ³ć‚’ä»˜ć‘ć¦ć‚‚č‰Æć„ć‚ć‚Šćµć‚ŒćŸę™®é€šć®Javać‚³ćƒ¼ćƒ‰
public enum Hoge {
    FOO, BAR, BAZ;

    public void println() {
        System.out.println(name());
    }
}

ć—ć‹ć—ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®šē¾©ć™ć‚‹ćŸć‚ć«ćÆäø€ē•Ŗęœ€å¾Œć«å®£čØ€ć—ćŸåˆ—ęŒ™å®šę•°(äøŠčØ˜ć®ä¾‹ć§ć„ć†ćØ BAZ )ć®å¾Œć‚ć«ć‚»ćƒŸć‚³ćƒ­ćƒ³ć‚’ć¤ć‘ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚

恓悌ćÆ回éæ恧恍ćŖć„åˆ¶ē“„ćŖć®ć§ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Java恧ćÆenumć«ćƒ”ć‚½ćƒƒćƒ‰ćÆē”Ÿć‚„ć›ć¾ć›ć‚“ć§ć—ćŸć€‚

ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Java 8恫恊恑悋enumć®ę–°ę©Ÿčƒ½

恗恋恗态Java 8ć§ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ć«ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆćƒ”ć‚½ćƒƒćƒ‰ć‚’ęŒć¦ć‚‹ć‚ˆć†ć«ćŖ悊态 ćć®å‰Æę¬”åŠ¹ęžœć§ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Java 8恧ćÆenumć«ćƒ”ć‚½ćƒƒćƒ‰ć‚’ē”Ÿć‚„恙äŗ‹ćŒå‡ŗę„ć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚

ꉋ順ćÆē°”å˜ć§ć€ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆćƒ”ć‚½ćƒƒćƒ‰ć‚’å®šē¾©ć—ćŸć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ć‚’ē”Øę„ć—ć¦enum恧恝悌悒implements恙悋恠恑恧恙怂

ć‚³ćƒ¼ćƒ‰ä¾‹ć‚’ē¤ŗć—ć¾ć™ć€‚

public enum Hoge implements Fuga {
   FOO, BAR, BAZ
}

public interface Fuga {
    default void println() {
        if (System.out.printf("%s%n", ((Hoge) this).name()) != null) {}
    }
}

enumć®åˆ—ęŒ™å®šę•°ć‚„ä»–ć®ćƒ”ć‚½ćƒƒćƒ‰ć«ć‚¢ć‚Æć‚»ć‚¹ć—ćŸć„å “åˆćÆć‚­ćƒ£ć‚¹ćƒˆć™ć‚Œć°OK恧恙怂

ć¾ćØ悁

  • enumć«ćƒ”ć‚½ćƒƒćƒ‰ć‚’ē”Ÿć‚„ć›ć‚‹ć‚ˆć†ć«ćŖć‚Šć€ć¾ć™ć¾ć™ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Java恌ä¾æåˆ©ć«ļ¼
]]>
Sat, 05 Dec 2015 00:00:00 +0900
http://backpaper0.github.io/2015/12/01/jjug_ccc_2015_fall.html http://backpaper0.github.io/2015/12/01/jjug_ccc_2015_fall.html <![CDATA[JJUG CCC 2015 Fallć«č”Œć£ć¦ććŸ #jjug_ccc]]> JJUG CCC 2015 Fallć«č”Œć£ć¦ććŸ #jjug_ccc

JAX-RS惍ć‚æ恧ē™»å£‡ć—ć¦ććŸ

ćØ恄恆悏恑恧ē™»å£‡ć•ć›ć¦é ‚ćć¾ć—ćŸć€‚

ćƒšćƒ¼ć‚¹é…åˆ†ćŒē”˜ćć¦ęœ€å¾Œć®ćƒ†ć‚¹ćƒˆć‚³ćƒ¼ćƒ‰ć®ćƒ‘ćƒ¼ćƒˆć‚’ć¾ć‚‹ć”ćØēœē•„ć—ć¦ć—ć¾ć„ć€č“č¬›ć—ć¦ćć ć•ć£ćŸēš†ę§˜ć«ćÆ大変ē”³ć—čسćŖćę€ć£ć¦ć„ć¾ć™ć€‚ ćŠćć‚‰ćé–¢Javać§å†ę¼”ć—ć¾ć™ćŒć€ćć®éš›ćÆć—ć£ć‹ć‚Šęœ€å¾Œć¾ć§č©±ć›ć‚‹ć‚ˆć†ē·“ēæ’ć—ć¦ćŠćć¾ć™ć€‚

ć¾ćŸć€ę‡‡č¦Ŗä¼šć§ć€Œē‰©č¶³ć‚ŠćŖć‹ć£ćŸć€ćØć„ć†ć”ę„č¦‹ć‚’é ‚ćć¾ć—ćŸć€‚ ē¢ŗć‹ć«ć€ć§ćć‚‹é™ć‚ŠJAX-RSć‚’ć”å­˜ēŸ„ćŖć„ę–¹ć«ć‚‚JAX-RS悒ēŸ„ć£ć¦é ‚ććŸćć€ęœ€å¤§å…¬ē“„ę•°ēš„ćŖå†…å®¹ć«ć—ćŸć®ć§ē‰©č¶³ć‚ŠćŖ恄ćØę„Ÿć˜ćŸę–¹ćÆć„ć‚‰ć£ć—ć‚ƒć‚‹ć ć‚ć†ćŖćØę€ć„ć¾ć—ćŸć€‚

恧恙恮恧ꬔ(JJUG CCCćØćÆé™ć‚Šć¾ć›ć‚“ćŒ)ćÆć‚‚ć†ć”ć‚‡ć£ćØęæƒć„ē›®ć®č©±ć—ć‚’ć—ćŸć„ćŖćØę€ć£ć¦ć„ć¾ć™ć€‚

ē§ć®ć‚»ćƒƒć‚·ćƒ§ćƒ³ć‚’éøć‚“ć§ćć ć•ć£ćŸč“č¬›č€…ć®ēš†ę§˜ć€ē§ć®CfP悒éøć‚“ć§ćć ć•ć£ćŸJJUGć‚¹ć‚æćƒƒćƒ•ć®ēš†ę§˜ć€č³‡ę–™ćƒ¬ćƒ“ćƒ„ćƒ¼ć«ä»˜ćåˆć£ć¦ćć‚ŒćŸć»ć’ćƒ”ćƒ³ćƒ»ć‚„ć‚“ćć•ć‚“ć€ęœ¬å½“ć«ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć—ćŸļ¼

ć¾ćƒ¼ć‚„ć•ć‚“ć€ćŸć‚ć†ć•ć‚“ć®ć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£ć‚»ćƒƒć‚·ćƒ§ćƒ³ć§ćŠč©±ć—ć¦ććŸ

関JavaćØć„ć†ć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£ć®ć‚¹ć‚æćƒƒćƒ•ć‚’ć‚„ć£ć¦ć„ć‚‹ćØ恄恆äŗ‹ć§ćŠå£°ćŒć‘é ‚ć„ć¦ćŠč©±ć—ć¦ćć¾ć—ćŸć€‚

å†…å®¹ć«ć¤ć„ć¦ćÆć¾ćƒ¼ć‚„ć•ć‚“ćŒē“ ę•µćŖćƒ¬ćƒćƒ¼ćƒˆć‚’ę›ø恍äøŠć’ć¦ćć ć•ć„ć¾ć—ćŸļ¼

恓恓恧ćÆę™‚é–“ć®éƒ½åˆć§č©±ć›ćŖć‹ć£ćŸäŗ‹ć‚’čØ˜č¼‰ć—ć¦ćŠćć¾ć™ć€‚

č‹¦åŠ“č©± ä¼šå “ć®ē¢ŗäæ

恓悌ćÆęÆŽå›žę‚©ćæć¾ć™ć€‚

ćƒ†ćƒ¼ćƒžć«ć‚ˆć£ć¦ć©ć®ē؋åŗ¦ć®é›†å®¢ćŒč¦‹č¾¼ć‚ć‚‹ć‹č€ƒćˆć¦ć€ćć®č¦ęØ”ę„Ÿć«åˆć£ćŸä¼šå “ć‚’ęŽ¢ć—ć¦ć€ćØć„ć†ę„Ÿć˜ć§č‰²ć€…č€ƒćˆćŸęŒ™å„ć°ćµćć•ć‚“ć‚’é ¼ć‚‹ć€ćØć„ć†ć®ćŒęœ€čæ‘ć®ć‚¢ćƒ¬ć€‚

ęœ¬å½“ć«ęœ€čæ‘ćÆć°ćµćć•ć‚“ć‚’é ¼ć‚Šć™ćŽć¦ć„ć‚‹ć®ć§ć™ćŒć€ć„ć¤ć‚‚åæ«ćå¼•ćå—ć‘ć¦ćć ć•ć£ć¦å½“ę—„悂ē¬‘锔恧čæŽćˆć¦ćć ć•ć‚‹ć®ć§ć‚‚ć†ćƒ›ćƒ³ćƒˆćŖ悓ćØ恄恆恋惞ć‚øę„Ÿč¬ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć™å¤§å„½ććƒ©ćƒ–ļ¼ć£ć¦ę„Ÿć˜ć§ć™ć€‚

ęŠ±ćˆć¦ć„ć‚‹čŖ²é”Œ(or éŽåŽ»ć«ć‚ć£ćŸčŖ²é”Œ) čŖæę•“åŠ›äøč¶³

é‹å–¶ć«ćÆē™»å£‡č€…ćØę—„ē؋čŖæę•“ć—ć¦ć€ä¼šå “ć‚’ęŽ¢ć—ć¦ć€ę‡‡č¦Ŗä¼šć®ćŠåŗ—ć‚’ęŽ¢ć—ć¦ć€å†…å®¹ć«ć‚ˆć£ć¦ćÆå½“ę—„ć¾ć§ć«ćƒŖćƒžć‚¤ćƒ³ćƒ€ćƒ”ćƒ¼ćƒ«ć‚’ęŠ•ć’ćŸć‚Šć€ ćØ恄恆悈恆ćŖäŗ‹ć‚’恙悋čŖæę•“åŠ›ćØ恄恆恋ćŖ悓ćØ恄恆恋态恝悓ćŖę„Ÿć˜ć®ćƒ—ćƒ­ć‚°ćƒ©ćƒžć®č‹¦ę‰‹é ˜åŸŸć£ć½ć„ć‚¹ć‚­ćƒ«ćŒę±‚ć‚ć‚‰ć‚Œć¾ć™ć€‚

ē§ć‚‚ęœ€åˆćÆā€¦ā€¦ćØć„ć†ć‹ć¾ć‚ä»Šć‚‚č‹¦åŠ“ć—ć¦ćÆć„ć¾ć™ćŒć€ä½•åŗ¦ć‚‚ć‚„ć£ć¦ć„ć‚‹ć†ć”ć«ę…£ć‚Œć¦ćć¦å‰ć‚ˆć‚ŠćÆäøŠę‰‹ćć‚„ć‚Œć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚ ćć—ć¦ä»•äŗ‹ć‚’恙悋äøŠć§ć‚‚ä»„å‰ć‚ˆć‚Šć‚‚čŖæę•“äŗ‹ćŒć§ćć‚‹ć‚ˆć†ć«ćŖć£ć¦ę„­å‹™ć‚’å††ę»‘ć«é€²ć‚ć‚‰ć‚Œć‚‹ć‚ˆć†ć«ćŖć£ćŸćØę€ć£ć¦ć„ć¾ć™ć€‚

ćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°ć®å‹‰å¼·ä¼šć®é‹å–¶ć‚’ć‚„ć£ć¦ć€ćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°ć‚¹ć‚­ćƒ«ä»„å¤–ć®ć‚¹ć‚­ćƒ«ćŒćƒ¬ćƒ™ćƒ«ć‚¢ćƒƒćƒ—ć—ćŸć€ćØ恄恆怂 ę£šć¼ćŸć€‚

ćć®ä»–ć€å€‹äŗŗēš„ćŖꀝ恄

ē§ćÆć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£é‹å–¶ć‚’ć—ć¦ć„ćŖ恄äø€čˆ¬ć®å‚åŠ č€…ć ć£ćŸé ƒć€é‹å–¶ć‚’ć‚„ć£ć¦ć„ć‚‹äŗŗćŸć”ć‚’ē„žę ¼åŒ–ć—ć¦ć„ćŸć‚ˆć†ć«ę€ć„ć¾ć™ć€‚ 恂恮äŗŗćŸć”ćÆ恙恔恄ļ¼ å‚åŠ ć—ć‹ć—ć¦ć„ćŖ恄č‡Ŗåˆ†ć‚ˆć‚Šć‚‚äøŠć®äŗŗ恠ļ¼ ę®æäøŠäŗŗ恠ļ¼ ćØ怂

恧悂č‡Ŗåˆ†ćŒé‹å–¶ć«é–¢ć‚ć£ć¦ćæ悋ćØ運営ćÆē„žć§ćÆćŖć„ć—ć€ć€Œć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£é‹å–¶ć—ć¦ć‚‹ćƒ»ć—ć¦ćŖ恄怍ćÆć‚Øćƒ³ć‚øćƒ‹ć‚¢ć®å„ŖåŠ£ć«ćŖć‚“ć‚‰é–¢äæ‚ē„”恄ćØ恄恆äŗ‹ć‚’ē†č§£ć—ć¾ć—ćŸć€‚ ć¾ć‚å½“ćŸć‚Šå‰ć£ć”ć‚ƒå½“ćŸć‚Šå‰ćŖ悓恧恙恌怂 ćØćÆć„ćˆå‹‰å¼·ä¼šć£ć¦ę„½ć—ć„ć—ć€ć©ć†ć‚„ć£ć¦é–‹å‚¬ć™ć‚‹ć®ć‹ćć®ę™‚ćÆå…Øē„¶č¦‹å½“悂恤恋ćŖć‹ć£ćŸć—ć€ćŖć‚“ć ć‹ćć†ę€ć£ć”ć‚ƒć£ć¦ćŸć‚“ć§ć™ć‚ˆć­ć€‚

ć¾ć‚ä½•ćŒčØ€ć„ćŸć„ć‹ćØ恄恆ćØć€Œć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£é‹å–¶ć‚’ć—ć¦ć„ć‚‹ćƒ»ć—ć¦ć„ćŖ恄怍ćÆäøŠäø‹é–¢äæ‚ć˜ć‚ƒćŖćć¦ē•°ćŖć‚‹ćƒ¬ć‚¤ćƒ¤ćƒ¼ć ćØ恄恆恓ćØ恧恙怂 悄悊恟恄äŗŗ恌悄悌恰č‰Æć„ć—ć€ć‚„ć£ć¦ć‚‹äŗŗćÆę„½ć—ćć¦ć‚„ć£ć¦ć‚‹ć ć‘ćŖć®ć§é‹å–¶ć«é–¢ć‚ć‚ŒćŖ恄äŗ‹ć‚’č² ć„ē›®ć«ę„Ÿć˜ć‚‹åæ…要ćÆē„”恄悓恠悈态ćØ怂 恝悓ćŖꄟ恘恧恙怂

ē§ćÆ(恓悌ćÆä¼šå “ć§ć‚‚čØ€ć„ć¾ć—ćŸćŒ)å‹‰å¼·ä¼šć«å‚åŠ ć—ć¦ćć ć•ć£ćŸę–¹ćŒę›øć„ćŸę„Ÿęƒ³ćƒ–ćƒ­ć‚°ć‚’čŖ­ć‚“恠悊态 Twitterć§ć€Œå‚åŠ ć—ć¦ć‚ˆć‹ć£ćŸļ¼ć€ćØćƒ„ć‚¤ćƒ¼ćƒˆćŖć•ć‚‹ć®ć‚’č¦‹ć‚‹ć®ćŒć™ć”ćå¬‰ć—ć„ć®ć§ć€ć¾ć ć—ć°ć‚‰ććÆć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£é‹å–¶ć«é–¢ć‚ć£ć¦č”ŒććŸć„ćØę€ć£ć¦ć„ć¾ć™ć€‚

面ē™½ć„ć‚»ćƒƒć‚·ćƒ§ćƒ³ć«ćŠčŖ˜ć„é ‚ć„ćŸć¾ćƒ¼ć‚„ć•ć‚“ćƒ»ćŸć‚ć†ć•ć‚“ć€äø€ē·’ć«ćƒ‘ćƒćƒ©ćƒ¼ć‚’ć—ćŸć¾ćæć•ć‚“ćƒ»ć²ć¤ć˜ć•ć‚“ć€ćć‚Œć‹ć‚‰äø€ē·’ć«ę„½ć—ć‚“ć§ćć ć•ć£ćŸå‚åŠ č€…ć®ēš†ę§˜ć€ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć—ćŸļ¼ ę„½ć—ć‹ć£ćŸć§ć™ć­ļ¼

ę‹č“ć—ćŸć‚»ćƒƒć‚·ćƒ§ćƒ³

恧ćÆć“ć“ć‹ć‚‰ę‹č“ć—ćŸć‚»ćƒƒć‚·ćƒ§ćƒ³ć«ć¤ć„ć¦ć–ć£ćć‚ŠčØ˜č¼‰ć—ć¾ć™ć€‚

EF-3 Reactive Webć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ ā€“ ćć—ć¦Spring 5ćø

ć¾ćć•ć‚“ć®ć‚¹ćƒ”ćƒ¼ćƒ‰ę„Ÿć‚ćµć‚Œć‚‹ć‚»ćƒƒć‚·ćƒ§ćƒ³(ę™‚é–“ćŒč¶³ć‚ŠćŖ恄ēš„ćŖę„å‘³ć§)怂 ć‚¹ćƒ”ćƒ¼ćƒ‰ę„Ÿć‚ćµć‚Œć¦ć„ć¾ć—ćŸćŒć€ć™ć”ćåˆ†ć‹ć‚Šć‚„ć™ć‹ć£ćŸć§ć™ć€‚ (RxJavać‚’ć»ć‚“ć®ć‚Šč§¦ć£ćŸäŗ‹ćŒć‚ć£ćŸć‹ć‚‰ćć‚Œć‚‚å¹ø恄恗恟恋ćŖ)

å†…å®¹ć‚‚ć™ć”ćč‰Æć‹ć£ćŸć®ć§ć™ćŒć€ę™‚é–“ćŒē„”恄ćØä»°ć£ć¦ć„ćŸć®ć«Rod JohnsonćØć®ćƒ„ćƒ¼ć‚·ćƒ§ćƒƒćƒˆå†™ēœŸć‚„Spring Tć‚·ćƒ£ćƒ„ć‚’å¬‰ć—ćć†ć«č‡Ŗę…¢ć™ć‚‹ć¾ćć•ć‚“ćŒć‹ć‚ć„ć‹ć£ćŸć®ć‚‚č¦‹ę‰€ć§ć—ćŸć€‚

EF-5 ć“ć‚Œć‹ć‚‰ć®ć‚³ćƒ³ćƒ”ćƒ„ćƒ¼ćƒ†ć‚£ćƒ³ć‚°ć®å¤‰åŒ–ćØJava

ćć—ć ć•ć‚“ć®ē™’ć—ćƒœć‚¤ć‚¹ęŗ€č¼‰ć®ć‚»ćƒƒć‚·ćƒ§ćƒ³ć€‚

FPGAćØć‹ć‚ˆćåˆ†ć‹ć‚‰ćŖ恄悓恧恙恌态č‡Ŗē„¶ćŖęµć‚Œć§JVM惻Javač؀čŖžć®č©±ć«ćŖć£ć¦ć„ćć€ęœ€å¾Œć«ćÆćŖć‚‹ć»ć©ę„ŸćŒę®‹ć‚‹ē“ ę•µćŖć‚»ćƒƒć‚·ćƒ§ćƒ³ć§ć—ćŸć€‚

ć§ć‚‚ć‚„ć£ć±ć‚ŠFPGAćØć‹ć‚ˆćåˆ†ć‹ć£ć¦ćŖ恄äŗ‹ć«ä»Šę°—ćŒć¤ć„ćŸć®ć§ć€ćć—ć ć•ć‚“ć®ćƒ–ćƒ­ć‚°ć‚’čŖ­ć‚“ć§å‹‰å¼·ć—ć¾ć™ć€‚

AB-6 ć€ć“ć£ćć‚Šå§‹ć‚ć‚‹ć€‘Javaćƒ—ćƒ­ć‚°ćƒ©ćƒžć‚³ćƒ¼ćƒ‡ć‚£ćƒ³ć‚°ćƒžć‚¤ć‚°ćƒ¬ćƒ¼ć‚·ćƒ§ćƒ³

č³‡ę–™ćƒ¬ćƒ“ćƒ„ćƒ¼ć—åˆć£ćŸć‚„ć‚“ćć•ć‚“ć®ć‚»ćƒƒć‚·ćƒ§ćƒ³ć€‚

č‡Ŗåˆ†ćŒē½®ć‹ć‚Œć¦ć„ć‚‹ē’°å¢ƒćŒć‚¢ćƒ¬ćŖå “åˆć«ć€ä»Šå±…ć‚‹ē’°å¢ƒć‚’å¤‰ćˆć‚‹ć€ć‚‚ć—ććÆåˆ„ć®ē’°å¢ƒć«č”Œćć€ ćØ恄恆äŗŒęŠžć®ć†ć”å‰č€…ć‚’ćØć‚‹č©±ć§ć—ćŸć€‚

恝悌悂ēœŸę­£é¢ć‹ć‚‰ēŽ‰ē •č¦šę‚Ÿć§ć¶ć¤ć‹ć£ć¦ć„ćć®ć§ćÆćŖćć€éš™ć‚’č¦‹ć¤ć‘ć¦ć­ć˜č¾¼ć‚€ę¦ć‚ę‰‹ć‚’ć‚„ć£ć¦ćæ悈恆悈ļ¼ć£ć¦ć„ć†ę„Ÿć˜ć€‚

個äŗŗēš„恫ćÆ怌恊悌ćÆć‚„ć‚‹ć ć‘ć‚„ć£ćŸć€ć§ć‚‚ć‚ć„ć¤ć‚‰ćŒåˆ†ć‹ć‚‰ćšå±‹ćŖ悓恠怍ćØä»–č²¬ć«ć—ć”ć‚ƒć†ć®ćÆå„½ćć§ćÆćŖ恄恗态 過ēØ‹ć‚ˆć‚Šć‚‚ēµęžœć‚’ę®‹ć™ć®ćŒå¤§äŗ‹ć ćØę€ć£ć¦ć„ć‚‹ć®ć§ć€ę¦ć‚ę‰‹ć§ē¢ŗå®Ÿć«ę”¹å–„ć‚’ē‹™ć†ć‚¹ć‚æćƒ³ć‚¹ć«ćÆå„½ę„Ÿć‚’ęŒć”ć¾ć—ćŸć€‚

ꇇč¦Ŗ会

ćć†é•·ććŖć„ę™‚é–“ć§č‰²ć€…ć‚ć£ćŸć‘ć©ć¾ćØ悁恍悌ćŖć„ć®ć§å‰²ę„›ļ¼ ę„½ć—ć‹ć£ćŸć€ćØ恠恑čØ€ć£ć¦ćŠćļ¼

č‰²ć‚“ćŖäŗŗ恫ęŒØę‹¶ć§ććŸć‘ć©ć€ć—ćć‚ŒćŖć‹ć£ćŸć®ć§ę„ę˜„ć«ćƒŖćƒ™ćƒ³ć‚øć—ć¾ć™ļ¼

JJUG CCC 2015 Fallć€ę„½ć—ć‹ć£ćŸļ¼ļ¼ļ¼

]]>
Tue, 01 Dec 2015 00:00:00 +0900
http://backpaper0.github.io/2015/11/15/javajok.html http://backpaper0.github.io/2015/11/15/javajok.html <![CDATA[関č„æJava儳子éƒØäø»å‚¬ć€ŒJava恧webć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³å…„é–€ć€ć‚’ćŠę‰‹ä¼ć„ć—ć¦ćć¾ć—ćŸ #javajok]]> 関č„æJava儳子éƒØäø»å‚¬ć€ŒJava恧webć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³å…„é–€ć€ć‚’ćŠę‰‹ä¼ć„ć—ć¦ćć¾ć—ćŸ #javajok

恓悓恰悓ćÆļ¼ Eclipsećøć®ć‚¤ćƒ³ćƒćƒ¼ćƒˆę‰‹é †ć‚’č§£čŖ¬ć—ć¦ć„ćŸ @backpaper0 恧恙ļ¼

č”Øé”Œć®é€šć‚Šć€Javać®ćƒćƒ³ć‚ŗć‚Ŗćƒ³ć‚¤ćƒ™ćƒ³ćƒˆć‚’ćŠę‰‹ä¼ć„ć—ć¦ćć¾ć—ćŸļ¼

会堓ćÆę„½å¤©ę Ŗ式会ē¤¾å¤§é˜Ŗę”Æē¤¾ć®ć‚«ćƒ•ć‚§ćƒ†ćƒŖć‚¢ć‚’ćŠå€Ÿć‚Šč‡“ć—ć¾ć—ćŸć€‚ @bufferings恕悓 ć€ä¼‘ę—„ćŖ恮恫恄恤悂ē¬‘é””ć§ćŠä»˜ćåˆć„ćć ć•ć‚Šć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć™ļ¼

ćŖćŠć€ä¼šå “ęä¾›ćć ć•ć£ćŸę„½å¤©ę Ŗ式会ē¤¾å¤§é˜Ŗę”Æē¤¾ć§ćÆ11꜈21ę—„(土)恫 Rakuten Technology Conference 2015 ćØć„ć†ć‚¤ćƒ™ćƒ³ćƒˆć®ć‚µćƒ†ćƒ©ć‚¤ćƒˆćŒč”Œć‚ć‚Œć‚‹ćć†ć§ć™ć€‚

å‚åŠ ć—ć¦ćæ恦ē§ćŒå¾—ćŸć‚‚ć®

ē§ćÆ講åø«å“ćØć—ć¦å‚åŠ ć—ć¾ć—ćŸćŒć€åˆ†ć‹ć‚Šć‚„ć™ćę•™ćˆć‚‹ć“ćØć®é›£ć—ć•ć‚’å­¦ć¹ć¾ć—ćŸć€‚

ć¾ćŸć€č‡Ŗåˆ†ćŒåˆåæƒč€…ć ć£ćŸé ƒć«ä½•ćŒåˆ†ć‹ć‚‰ćŖć‹ć£ćŸć‹ć€ä½•ć‚’åˆ†ć‹ć‚ŠćŸć‹ć£ćŸć‹ć€ć©ć†ć‚„ć£ć¦åˆ†ć‹ć‚‹ć‚ˆć†ć«ćŖć£ćŸć‹ć€ ćŖ恩悒見恤悁ē›“恙č‰Æć„ćć£ć‹ć‘ćØćŖć‚Šć¾ć—ćŸć€‚

é‹å–¶ć«ćŠčŖ˜ć„ćć ć•ć£ćŸ @aa7th恕悓 态 ä»Šå›žć®ć‚¤ćƒ™ćƒ³ćƒˆé–‹å‚¬ć®ćć£ć‹ć‘ćØćŖć£ćŸ @ar_keyaki恕悓 态 ćć‚Œć‹ć‚‰ä»Šå›žć”å‚åŠ é ‚ć„ćŸēš†ć•ć‚“ć€ęœ¬å½“ć«ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć—ćŸļ¼

Eclipsećøć®ć‚¤ćƒ³ćƒćƒ¼ćƒˆć«ć¤ć„ć¦

ć•ć¦ć€ęœ¬ę—„ćÆ惗惭ć‚ø悧ć‚Æ惈悒Eclipsećøć‚¤ćƒ³ćƒćƒ¼ćƒˆć™ć‚‹ē®‡ę‰€ć§äøę‰‹éš›ćŒć‚ć‚Šå‚åŠ č€…ć®ēš†ć•ć‚“恫ćÆ恔čæ·ęƒ‘悒恊ꎛ恑恗态ē”³ć—čØ³ć‚ć‚Šć¾ć›ć‚“ć§ć—ćŸć€‚

悂恗恔č‡Ŗå®…ć§å¾©ēæ’ć‚’ćŖć•ć‚‹å “åˆćÆć€ę”¹ć‚ć¦ https://github.com/javajok/simpletter 恋悉ZIPćƒ•ć‚”ć‚¤ćƒ«ć‚’ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ć—ć€ gradlew eclipse ć‚’č”Œć£ć¦ć‚¤ćƒ³ćƒćƒ¼ćƒˆć—ć¦ćæć¦ćć ć•ć„ć€‚

ćŖćŠć€ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ć•ć‚Œć‚‹ćƒ•ć‚”ć‚¤ćƒ«ć®åå‰ćÆ怌simpletter-master.zip怍恧恙怂

API恫恤恄恦

ćƒćƒ³ć‚ŗć‚Ŗćƒ³ć§ä½æē”Ø恗恟APIć®ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ćÆꬔ恮URLć«ć‚ć‚Šć¾ć™ć€‚

恓恔悉悂simpletterćØåŒć˜ćć€ZIPćƒ•ć‚”ć‚¤ćƒ«ć‚’ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ćƒ»č§£å‡ć—ć¦ gradlew eclipse ć‚’č”Œć†ć“ćØ恧Eclipseć«ć‚¤ćƒ³ćƒćƒ¼ćƒˆć™ć‚‹å½¢å¼ć«ć§ćć¾ć™ć€‚

ä½™åŠ›ćŒć‚ć‚‹ę–¹ćƒ»čˆˆå‘³ćŒć‚ć‚‹ę–¹ćÆå®œć—ć‘ć‚Œć°ć“ć®APIć®ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ć‚‚čŖ­ć‚“恧态 č‰²ć€…ćØć„ć˜ć£ć¦ćæć¦ćć ć•ć„ć€‚

ęœ€å¾Œć«

ē§ćÆåŸŗęœ¬ēš„恫ćÆč©°ć¾ć£ćŸę™‚ćŖć©ć®ć‚µćƒćƒ¼ćƒˆć«å¾¹ć—ć¦ć„ć¾ć—ćŸć€‚

ć‚µćƒćƒ¼ćƒˆć®éš›ćÆćŖć‚‹ć¹ćåˆ†ć‹ć‚Šć‚„ć™ćčØ€č‘‰ć‚’éøć³ć€ćć—ć¦ć€Œć“ć†ć™ć‚Œć°å‡ŗę„ć‚‹ć€ć ć‘ć§ćŖ恏怌ćŖ恜恝恆ćŖć‚‹ć®ć‹ć€ć‚‚čŖ¬ę˜Žć™ć‚‹ć‚ˆć†åæƒćŒć‘ć¦ć„ć¾ć—ćŸć€‚ 恧恙恮恧态悂恗ē§ć®ć‚µćƒćƒ¼ćƒˆćŒćæćŖ恕悓恮ē†č§£ć®åŠ©ć‘恫ćŖć‚ŒćŸć®ć§ć‚ć‚Œć°ć€ć™ć”ćå¬‰ć—ć„ć§ć™ć€‚

ćć‚Œć‹ć‚‰ć€ć‚‚ć—ć¾ćŸåˆ„ć®ć‚¤ćƒ™ćƒ³ćƒˆć§ćŠä¼šć„ć™ć‚‹äŗ‹ćŒć‚ć‚Œć°ę°—č»½ć«ćŠå£°ćŒć‘ćć ć•ć„ć€‚ 今ꗄ恮äŗ‹ć‚’ę€ć„å‡ŗ恗ćŖ恌悉Java恧Webć«ć¤ć„ć¦ćŠč©±ć—ć¾ć—ć‚‡ć†ļ¼

恝悌恧ćÆē¹°ć‚Ščæ”恗恫ćŖć‚Šć¾ć™ćŒć€ęœ¬ę—„ćÆęœ¬å½“ć«ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć—ćŸļ¼ ć™ć”ćę„½ć—ć‹ć£ćŸć§ć™ļ¼

]]>
Sun, 15 Nov 2015 00:00:00 +0900
http://backpaper0.github.io/2015/10/08/spring_boot_rich_banner.html http://backpaper0.github.io/2015/10/08/spring_boot_rich_banner.html <![CDATA[Spring Bootć§ć‚«ćƒ©ćƒ•ćƒ«ćŖćƒćƒŠćƒ¼ć‚’č”Øē¤ŗ恗恦ćæ恟]]> Spring Bootć§ć‚«ćƒ©ćƒ•ćƒ«ćŖćƒćƒŠćƒ¼ć‚’č”Øē¤ŗ恗恦ćæ恟

ćØć„ć†ć‚ć‘ć§ć‚«ćƒ©ćƒ•ćƒ«ćŖćƒćƒŠćƒ¼ć‚’č”Øē¤ŗ恙悋Bannerć‚Æćƒ©ć‚¹ć‚’ę›ø恄恦ćæć¾ć—ćŸć€‚

ć©ć†ć‚„ć£ć¦ć‚“ć®ć‹

ć‚æćƒ¼ćƒŸćƒŠćƒ«ć®čƒŒę™Æč‰²ć‚’å¤‰ę›“ć—ć¦ć‚¹ćƒšćƒ¼ć‚¹ć‚’2恤å‡ŗåŠ›ć€ć‚’ē¹°ć‚Ščæ”恗恦ēµµć‚’ęć„ć¦ć„ć¾ć™ć€‚ ć‚¹ćƒšćƒ¼ć‚¹ć‚’2恤å‡ŗåŠ›ć™ć‚‹ć“ćØć§ę­£ę–¹å½¢ć«ćŖć£ć¦č‰Æć„ę„Ÿć˜ć«ćƒ‰ćƒƒćƒˆēµµć£ć½ććŖć‚Šć¾ć™ć€‚

背ę™Æč‰²ć‚’å¤‰ćˆć‚‹ć«ćÆ

ESC + '[48;05;' + č‰²ć®ć‚¤ćƒ³ćƒ‡ćƒƒć‚Æć‚¹ + 'm'

恧å‡ŗę„ć¾ć™ć€‚

ꬔ恮Groovyć‚³ćƒžćƒ³ćƒ‰ć‚’č©¦ć—ć¦ćæć¦ćć ć•ć„ć€‚

groovy -e "System.out.write(0x1b);println('[48;05;20mHello, World!')"

背ę™Æč‰²ć‚’å…ƒć«ęˆ»ć™ć«ćÆ

ESC + '[0m'

恧恙怂

ćć‚Œć‹ć‚‰ć€å…ƒē”»åƒćÆć‚æćƒ¼ćƒŸćƒŠćƒ«ć§å‡ŗåŠ›ć§ćć‚‹č‰²ć ć‘ć§ę§‹ęˆć•ć‚Œć¦ć„ć‚‹ć‚ć‘ć§ćÆćŖ恄恮恧态 元ē”»åƒć‹ć‚‰1惔ć‚Æć‚»ćƒ«ćšć¤č‰²ć‚’čŖ­ćæč¾¼ć‚“ć§ć‚æćƒ¼ćƒŸćƒŠćƒ«ć§å‡ŗåŠ›ć§ćć‚‹256č‰²ć®äø­ć‹ć‚‰čæ‘ć„č‰²ć‚’ęŽ¢ć—ć¦å‡ŗåŠ›ć—ć¦ć„ć¾ć™ć€‚

2ć¤ć®č‰²ćŒć©ć®ē؋åŗ¦čæ‘恄恋ćÆć‚«ćƒ©ćƒ¼ć‚³ćƒ¼ćƒ‰ć‚’äø‰ę¬”å…ƒć®åŗ§ęØ™ć«č¦‹ē«‹ć¦ć¦2ć¤ć®č‰²é–“ć®č·é›¢ć‚’ę±‚ć‚ć¦äø€ē•Ŗčæ‘恄悂恮悒éøć‚“ć§ć„ć¾ć™ć€‚

int r = ((rgb1 >> 16) & 0xff) - ((rgb2 >> 16) & 0xff);
int g = ((rgb1 >> 8) & 0xff) - ((rgb2 >> 8) & 0xff);
int b = (rgb1 & 0xff) - (rgb2 & 0xff);
return (int) Math.sqrt(r * r + g * g + b * b);

ꦂ恭恓悓ćŖꄟ恘恧恙怂

ć„ć‚ć„ć‚ćƒ–ćƒ¼ćƒˆ

恆悉恌ćæćƒ–ćƒ¼ćƒˆć€‚

../../../_images/uragami-boot.png

ć„ć‚ćµćƒ–ćƒ¼ćƒˆć€‚

../../../_images/irof-boot.png

ć”ć‚€ćƒ–ćƒ¼ćƒˆļ¾ļ¾Ÿļ¾›ļ¾ļ¾Ÿļ¾›ļ¼ˆļ¼¾Ļ‰ļ¼¾ļ¼‰

../../../_images/syobochim-boot-peropero.png

ć“ć–ćƒ–ćƒ¼ćƒˆāœŒļø( ćƒ»ć…‚ćƒ»)ŁˆšŸŗ

../../../_images/kozaboot.png

ćƒ–ćƒ¼ćƒˆćć—ćƒ¼ć•ć‚“ć€‚

../../../_images/bootksy.png

ć‚„ć‚“ććƒ–ćƒ¼ćƒˆ:q!

../../../_images/yank-boot_q.png
]]>
Thu, 08 Oct 2015 00:00:00 +0900
http://backpaper0.github.io/2015/08/25/serialized_lambda.html http://backpaper0.github.io/2015/08/25/serialized_lambda.html <![CDATA[ć‚·ćƒŖć‚¢ćƒ©ć‚¤ć‚¶ćƒ–ćƒ«ćŖćƒ©ćƒ ćƒ€å¼]]> ć‚·ćƒŖć‚¢ćƒ©ć‚¤ć‚¶ćƒ–ćƒ«ćŖćƒ©ćƒ ćƒ€å¼

ćƒ©ćƒ ćƒ€å¼ćÆ Serializable ć«ć§ćć¾ć™ć€‚

//ć‚­ćƒ£ć‚¹ćƒˆć—ćŸć‚Š
Supplier<String> s = (Supplier<String> & Serializable) () -> "x";

//ćƒ”ć‚½ćƒƒćƒ‰ć§ć‚ć‚Œć—ćŸć‚Š
<T extends Supplier<String> & Serializable> void consume(T supplier) { ... }

恧态悷ćƒŖć‚¢ćƒ©ć‚¤ć‚ŗć§ćć‚‹ćžćƒ¼ć€ćØę€ć£ć¦ć“ć‚“ćŖć‚³ćƒ¼ćƒ‰ę›ø恄恦态

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.function.Supplier;

public class Sample {

    Supplier<String> get() {
        return (Supplier<String> & Serializable) () -> toString();
    }

    public static void main(String[] args) throws IOException {

        //ā†“ć‚·ćƒŖć‚¢ćƒ©ć‚¤ć‚¶ćƒ–ćƒ«ćŖć‚µćƒ—ćƒ©ć‚¤ćƒ¤ćƒ¼
        Supplier<String> s = new Sample().get();

        //ć‚·ćƒŖć‚¢ćƒ©ć‚¤ć‚ŗ恗恦ćæ悋
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try (ObjectOutputStream out = new ObjectOutputStream(baos)) {
            out.writeObject(s);
        }
    }
}

å®Ÿč”Œć™ć‚‹ćØ态

Exception in thread "main" java.io.NotSerializableException: Sample
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
    at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1378)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
    at Sample.main(Sample.java:17)

ä¾‹å¤–ć§ć™ļ¼

恓悌ćÆćƒ©ćƒ ćƒ€å¼ć§ Sample ć‚Æćƒ©ć‚¹ć® toString ćƒ”ć‚½ćƒƒćƒ‰ć‚’å‘¼ć‚“ć§ć„ć‚‹ćŸć‚ Sample ćŒć‚­ćƒ£ćƒ—ćƒćƒ£ć•ć‚Œć¾ć™ćŒć€ Sample ćÆSerializable恧ćŖć„ćŸć‚ä¾‹å¤–ćŒå‡ŗć¾ć™ć€‚

Supplier<String> get() {
    return (Supplier<String> & Serializable) () -> toString();
}

ć‚­ćƒ£ćƒ—ćƒćƒ£ćØ恄恆恮ćÆćƒ©ćƒ ćƒ€å¼å†…ć§ćƒ©ćƒ ćƒ€å¼ć®ć‚¹ć‚³ćƒ¼ćƒ—ć®å¤–å“ć®å¤‰ę•°ć‚’å‚ē…§ć—ćŸå “åˆć«ćƒ©ćƒ ćƒ€å¼ć®å®Ÿč”Œē’°å¢ƒć«ęŒć£ć¦ćć‚‹ć£ć½ć„ę„Ÿć˜ć®ć‚ć‚Œć§ć™ć€‚

ć‚­ćƒ£ćƒ—ćƒćƒ£ć•ć‚Œć¦ć„ć‚‹ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ćÆ SerializedLambda ć‹ć‚‰å–ć£ć¦ć“ć‚Œć¾ć™ć€‚ SerializedLambda ćÆprivate finalćŖ writeReplace ćƒ”ć‚½ćƒƒćƒ‰ć§å–ć£ć¦ć“ć‚Œć¾ć™ć€‚ å–ć£ć¦ć“ć‚Œć‚‹ć‹ć‚‰ćØčØ€ć£ć¦ć‚«ć‚øćƒ„ć‚¢ćƒ«ć«å‘¼ć‚“ć§č‰Æć„ćƒ”ć‚½ćƒƒćƒ‰ć§ćÆćŖ恄恧恙怂 writeReplace 恫恤恄恦ćÆ Serializable 恮Javadoc恫ę›øć„ć¦ć‚ć‚Šć¾ć™ć€‚

恓悓ćŖꄟ恘恧 SerializedLambda ćØć‚­ćƒ£ćƒ—ćƒćƒ£ć—ćŸć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’å–ć£ć¦ć“ć‚Œć¾ć—ćŸć€‚

Supplier<String> s = new Sample().get();

Method m = s.getClass().getDeclaredMethod("writeReplace");
m.setAccessible(true);
SerializedLambda sl = (SerializedLambda) m.invoke(s);
for (int i = 0; i < sl.getCapturedArgCount(); i++) {
    System.out.println(sl.getCapturedArg(i));
}

恓恮č¾ŗć‚Šć‚’ć‚‚ć£ćØć„ć˜ćć‚Šć¾ć‚ć™ćØ面ē™½ć„äŗ‹ćŒć§ććć†ćŖ갗恌恗ćŖ恏悂ćŖ恄恧恙恭ļ¼

関äæ‚ć‚ć‚Šćć†ćŖ态恝恆恧悂ćŖ恄悈恆ćŖå‚č€ƒćƒŖć‚½ćƒ¼ć‚¹

ć¾ćØ悁悂ć‚Ŗ惁悂ćŖ恄

ćØ悊恂恈恚 Sample ć‚Æćƒ©ć‚¹ćÆ Serializable 悒implementsć—ć¾ć—ć‚‡ć†ć€‚

]]>
Tue, 25 Aug 2015 00:00:00 +0900
http://backpaper0.github.io/2015/07/30/gradle_plugin.html http://backpaper0.github.io/2015/07/30/gradle_plugin.html <![CDATA[Gradlećƒ—ćƒ©ć‚°ć‚¤ćƒ³ć‚’ę›øć„ć¦å…¬é–‹ć—ć”ć‚ƒć£ćŸ]]> Gradlećƒ—ćƒ©ć‚°ć‚¤ćƒ³ć‚’ę›øć„ć¦å…¬é–‹ć—ć”ć‚ƒć£ćŸ

ćć£ć‹ć‘

JAX-RS恧Webćƒ•ć‚©ćƒ³ćƒˆćŖć©ć®é™ēš„ćƒŖć‚½ćƒ¼ć‚¹ć‚’čæ”恙ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć‚’ę›ø恄恟悓恧恙恌态 ETag悒ä½æć£ć¦ć‚­ćƒ£ćƒƒć‚·ćƒ„ć‚’ć‚¢ćƒ¬ć—ć¦č»¢é€é‡ć‚’ēƀē“„ć—ćŸććŖć‚Šć¾ć—ćŸć€‚

恧态ETag恫ćÆMD5ćƒćƒƒć‚·ćƒ„å€¤ć‚’ä½æć£ć¦ćŸć‚“ć§ć™ćŒęÆŽå›žćƒćƒƒć‚·ćƒ„å€¤ć‚’č؈ē®—恙悋恮ćÆć‚ć»ćć•ć„ć®ć§ć€ ćƒ“ćƒ«ćƒ‰ę™‚ć«č؈ē®—ć—ć¦ćƒ•ć‚”ć‚¤ćƒ«ć«äæå­˜ć—ć¦ćŠćäŗ‹ć«ć—ć¾ć—ćŸć€‚

ćć®éš›ć«Gradlećƒ—ćƒ©ć‚°ć‚¤ćƒ³ć‚’ę›ø恄恦态 恩恆恛ćŖ悉ćØę€ć£ć¦ https://plugins.gradle.org/ ć§å…¬é–‹ć™ć‚‹äŗ‹ć«ć—ć¾ć—ćŸć€‚

Gradlećƒ—ćƒ©ć‚°ć‚¤ćƒ³ć‚’ę›ø恏

ę¬”ć®å…¬å¼ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆ(ć®ę—„ęœ¬čŖžčس)ć‚’å‚č€ƒć«ć™ć‚Œć°ć‚Ŗćƒƒć‚±ćƒ¼ļ¼

Gradlećƒ—ćƒ©ć‚°ć‚¤ćƒ³ć‚’å…¬é–‹ć™ć‚‹

How do I add my plugin to the plugin portal? ć®é€šć‚Šć«é€²ć‚ć¦ć„ć‘ć°ć‚Ŗćƒƒć‚±ćƒ¼ļ¼

ć–ć£ćć‚Šę›ø恏ćØ态 ć¾ćš ć‚¢ć‚«ć‚¦ćƒ³ćƒˆć‚’ä½œć£ć¦ 态 č‡Ŗåˆ†ć®ćƒšćƒ¼ć‚ø恧API Keyć‚’ä½œć£ć¦ć€ 恝悌悒 ~/.gradle/gradle.properties 恫ę›ø恄恦态 build.gradle ćø Plugin Publishing Plugin 恮čØ­å®šć‚’ę›ø恄恦态 gradle publishPlugins ć§å…¬é–‹ć—ć¾ć™ć€‚

Gradlećƒ—ćƒ©ć‚°ć‚¤ćƒ³ć‚’ę›ø恏ćØćć«ēŸ„ć£ć¦ć¦č‰Æć‹ć£ćŸć“ćØ

ēŸ„ć£ć¦ć¦č‰Æć‹ć£ćŸć“ćØć£ć¦ć„ć†ć‹Groovyć®ę–‡ę³•ćŖ悓恧恙恑恩态 ę¬”ć®ć‚ˆć†ćŖ恓ćØ悒ēŸ„ć£ć¦ćŸć‚‰ć‚ć‚ŠćØć‚¹ćƒ ćƒ¼ć‚ŗć«ćƒ—ćƒ©ć‚°ć‚¤ćƒ³ć‚’ę›øć‘ć¾ć—ćŸć€‚

  • ć‚¢ć‚Æć‚»ć‚µćƒ”ć‚½ćƒƒćƒ‰ćÆćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć‚¢ć‚Æć‚»ć‚¹ć®ć‚ˆć†ć«ę›ø恑悋怂
    • ä¾‹ćˆć° foo.getBar() ćÆ foo.bar ćØę›ø恑悋怂
    • ćć—ć¦ foo.setBar(baz) ćÆ foo.bar = baz ćØę›ø恑悋怂
  • ćƒ”ć‚½ćƒƒćƒ‰å‘¼ć³å‡ŗć—ć§ęœ€å¾Œć®å¼•ę•°ćŒć‚Æćƒ­ćƒ¼ć‚øćƒ£ć ćØę‹¬å¼§ć®å¤–ć«å‡ŗ恛悋怂 ć¤ć¾ć‚Š foo(bar, { x -> ... }) ćÆ foo(bar) { x -> ... } ćØę›ø恑恦ēµ„ćæč¾¼ćæć®ę§‹ę–‡ć®ć‚ˆć†ć«ć§ćć‚‹ć€‚
  • å¼•ę•°ćŒMapćŖ悉 foo(bar: "...", baz: 123) ćæćŸć„ć«ę›ø恑悋怂
  • å±•é–‹ę¼”ē®—å­ć€‚ ['hoge', 'foo', 'x'].collect { it.length() } 悒 ['hoge', 'foo', 'x']*.length() ćØę›ø恑悋怂
  • leftShift ćØć„ć†åå‰ć®ćƒ”ć‚½ćƒƒćƒ‰ćÆ << ćØę›ø恑悋怂 ć‚æć‚¹ć‚Æć‚’å®šē¾©ć™ć‚‹ćØćć® task hoge << { ... } ćÆ Task.leftShiftćƒ”ć‚½ćƒƒćƒ‰ 恧恙怂

Gradlećƒ—ćƒ©ć‚°ć‚¤ćƒ³ć‚’ę›øćć«ć‚ćŸć£ć¦å‚č€ƒć«ć—ćŸć‚‚ć®

ęœ€åˆć«ęŒ™ć’ćŸå…¬å¼ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆć®ę—„ęœ¬čŖžčسćÆć‚‚ć”ć‚ć‚“å‚č€ƒć«ć—ć¾ć—ćŸćŒć€ 他恫 Gradle恮APIćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆ ćŒå‚č€ƒć«ćŖć‚Šć¾ć—ćŸć€‚

ē‰¹ć«ę¬”恮ć‚Æćƒ©ć‚¹ć®ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆć‚’ć‚ˆćčŖ­ć‚“ć ę°—ćŒć—ć¾ć™ć€‚

恝悌恋悉 Gradleć®ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ ć‚‚å‚č€ƒć«ćŖć‚Šć¾ć—ćŸć€‚ ē‰¹ć« JavaPlugin 悄 WarPlugin ć‚’å‚č€ƒć«ć—ć¾ć—ćŸć€‚

ć¾ćØ悁

Gradlećƒ—ćƒ©ć‚°ć‚¤ćƒ³ćÆę›øćć®ć‚‚å…¬é–‹ć™ć‚‹ć®ć‚‚ćŠę‰‹č»½ć£ć½ć„ć®ć§ć€ 恓悌悒čŖ­ć‚“恧č‰Æ恄ćŖćØę€ć£ćŸć‚‰ćƒćƒ£ćƒ¬ćƒ³ć‚ø恗恦ćæć¦ćć‚Œć•ć„ļ¼

恔ćŖćæć«ć€ć“ć”ć‚‰ćŒē§ćŒę›øć„ćŸćƒ—ćƒ©ć‚°ć‚¤ćƒ³ć§ć™ć©ć†ćžļ¼

]]>
Thu, 30 Jul 2015 00:00:00 +0900
http://backpaper0.github.io/2015/07/12/jsr310_and_lambda_handson.html http://backpaper0.github.io/2015/07/12/jsr310_and_lambda_handson.html <![CDATA[Java 8å¾¹åŗ•å†å…„é–€ć‚„ć£ćŸ #kanjava]]> Java 8å¾¹åŗ•å†å…„é–€ć‚„ć£ćŸ #kanjava

ę±äŗ¬ć‹ć‚‰ @khasunuma 恕悓悒講åø«ć«ćŠčæŽćˆć—恦 JSR 310: Date and Time API ć®č§£čŖ¬ć‚’ć—ć¦é ‚ćć¾ć—ćŸć€‚

ć¾ćŸć‚¤ćƒ™ćƒ³ćƒˆć®å¾ŒåŠćÆ @bitter_fox ć•ć‚“ć«ćƒ©ćƒ ćƒ€å¼ćƒ»Stream APIć®ćƒćƒ³ć‚ŗć‚Ŗćƒ³ć‚’č”Œć£ć¦é ‚ćć¾ć—ćŸć€‚

会堓ćÆę„½å¤©ę Ŗ式会ē¤¾å¤§é˜Ŗę”Æē¤¾ć®ć‚«ćƒ•ć‚§ćƒ†ćƒŖć‚¢ć‚’ćŠå€Ÿć‚Šč‡“ć—ć¾ć—ćŸć€‚ @bufferings ć•ć‚“ć€ć„ć¤ć‚‚ć”å”åŠ›ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć™ć€‚

恊äŗŒäŗŗćØć‚‚åˆę­©ēš„ćŖéƒØåˆ†ć‹ć‚‰äøåÆ§ć«ćŠč©±ćƒ»ćƒćƒ³ć‚ŗć‚Ŗćƒ³ć‚’ć—ć¦é ‚ć„ćŸć®ć§å‚åŠ ć•ć‚ŒćŸę–¹ć€…ćÆ Date and Time API ćØ ćƒ©ćƒ ćƒ€å¼ćƒ»Stream API 恮åŸŗē¤Žć‚’čŗ«ć«ä»˜ć‘悋恓ćØ恌å‡ŗę„ćŸć®ć§ćÆćŖ恄恧恗悇恆恋怂

ćÆć™ć¬ć¾ć•ć‚“ć€ćć¤ć­ć•ć‚“ć€ęœ¬å½“ć«ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć—ćŸļ¼

]]>
Sun, 12 Jul 2015 00:00:00 +0900
http://backpaper0.github.io/2015/06/29/grgit.html http://backpaper0.github.io/2015/06/29/grgit.html <![CDATA[Grgitć§ć‚³ćƒŸćƒƒćƒˆć®ćƒćƒƒć‚·ćƒ„å€¤ć‚’ćƒ•ć‚”ć‚¤ćƒ«ć«ę›ø恍å‡ŗ恗恦warć«å…„ć‚Œć‚‹]]> Grgitć§ć‚³ćƒŸćƒƒćƒˆć®ćƒćƒƒć‚·ćƒ„å€¤ć‚’ćƒ•ć‚”ć‚¤ćƒ«ć«ę›ø恍å‡ŗ恗恦warć«å…„ć‚Œć‚‹

ä»Šćƒ‡ćƒ—ćƒ­ć‚¤ć•ć‚Œć¦ć‚‹warćÆć©ć®ć‚³ćƒŸćƒƒćƒˆć‹ć‚‰ä½œć£ćŸć‚“ć˜ć‚ƒć‚ļ¼Ÿ ć£ć¦ć„ć†ē–‘å•ć‚’č§£ę±ŗć™ć‚‹ćŸć‚ć®ć‚„ć¤ć§ć™ć€‚ Gradle恧warć‚’ä½œć‚‹å‰ć« Grgit ćØ恄恆悂恮悒ä½æć£ć¦ć‚³ćƒŸćƒƒćƒˆć®ćƒćƒƒć‚·ćƒ„å€¤ć‚’ćƒ•ć‚”ć‚¤ćƒ«ć«ę›ø恍å‡ŗ恗恦恊恄恦 warć«å…„ć‚Œć¦ć—ć¾ć£ć¦ć¤ć„ć§ć«JAX-RS恮ćƒŖć‚½ćƒ¼ć‚¹ćØć—ć¦ć‚ć‚Œć—ć¦ć—ć¾ć„ć¾ć—ć‚‡ć†ć€ ćØ恄恆話怂

build.gradle

ć¾ćšGrgit悒ä½æ恆ęŗ–å‚™ć€‚ GradlećÆꙮ通恫Groovyć‚³ćƒ¼ćƒ‰ć‚’ę›ø恑恦ä¾æåˆ©ć€‚

import org.ajoberstar.grgit.Grgit

ext.repo = Grgit.open(project.file('.'))

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath('org.ajoberstar:gradle-git:1.1.0')
    }
}

ę¬”ć«ćƒćƒƒć‚·ćƒ„ć‚’ćƒ•ć‚”ć‚¤ćƒ«ć«ę›ø恍å‡ŗ恙ć‚æć‚¹ć‚Æć®å®šē¾©ćØwarć‚æć‚¹ć‚ÆćØć®ä¾å­˜é–¢äæ‚恮čØ­å®šć€‚ 今回ćÆwarćƒ•ć‚”ć‚¤ćƒ«å†…ć® WEB-INF/classes/head ć«ćƒ•ć‚”ć‚¤ćƒ«ćŒćƒ‘ćƒƒć‚±ćƒ¼ć‚øćƒ³ć‚°ć•ć‚Œć‚‹ć‚ˆć†ć«ć—ć¾ć—ćŸć€‚

task writeHeadCommitHash << {
    def file = new File(buildDir, 'git/head')
    file.parentFile.mkdirs()
    file.write(repo.head().id)
}

war.classpath new File(buildDir, 'git')

war.dependsOn writeHeadCommitHash

JAX-RS恮ćƒŖć‚½ćƒ¼ć‚¹ć‚Æćƒ©ć‚¹

package javayou;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Named
@RequestScoped
@Path("head")
public class GitCommitHashResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getHead() {
        URL resource = getClass().getResource("/head");
        if (resource != null) {
            try {
                byte[] b = Files.readAllBytes(Paths.get(resource.toURI()));
                return new String(b);
            } catch (URISyntaxException | IOException ignored) {
            }
        }
        return "<none>";
    }
}

ć‚³ćƒ¼ćƒ‡ć‚£ćƒ³ć‚°äø­ć«IDEć‹ć‚‰å‹•ć‹ć—ćŸćØ恋恝恆恄恆ćØ恍ćÆćƒ•ć‚”ć‚¤ćƒ«ćŒē„”恄恋悉 <none> ć£ć¦č”Øē¤ŗć•ć‚Œć‚‹ć‚ˆć†ć«ć—ć¦ć„ć¾ć™ć€‚

ć“ć‚Œć§ć€ć“ć®ćƒŖć‚½ćƒ¼ć‚¹ć«ć‚¢ć‚Æć‚»ć‚¹ć™ć‚Œć°ć©ć®ć‚³ćƒŸćƒƒćƒˆć‹ć‚‰ä½œć‚‰ć‚ŒćŸwarćŖć®ć‹ćŒåˆ†ć‹ć‚‹ć¾ć™ć€‚

å‹•ćć‚³ćƒ¼ćƒ‰ä¾‹

å‹•ć‹ć—ć¦ http://localhost:8080/java-you/api/head ć‚’é–‹ć„ć¦ćć ć•ć„ć€‚

]]>
Mon, 29 Jun 2015 00:00:00 +0900
http://backpaper0.github.io/2015/06/19/payaya_micro_cluster.html http://backpaper0.github.io/2015/06/19/payaya_micro_cluster.html <![CDATA[MacBook Pro恧Payara Micro恮ć‚Æćƒ©ć‚¹ć‚æćƒŖćƒ³ć‚°ć‚’č©¦ćć†ćØ恗恦čŗ“ć„ćŸć‘ć©å‡ŗę„ćŸļ¼]]> MacBook Pro恧Payara Micro恮ć‚Æćƒ©ć‚¹ć‚æćƒŖćƒ³ć‚°ć‚’č©¦ćć†ćØ恗恦čŗ“ć„ćŸć‘ć©å‡ŗę„ćŸļ¼

問锌

Payara Micro Clustering 悒見ćŖ恌悉ć‚Æćƒ©ć‚¹ć‚æćƒŖćƒ³ć‚°č©¦ćć†ćØę€ć£ć¦ć‚ć‚Œć—ć¦ćæ恟悓恧恙恌å…Øē„¶ć‚Æćƒ©ć‚¹ć‚æēµ„ć‚“ć§ćć‚ŒćŖ恄ļ¼

Payara Micro悒2恤ē«‹ć”äøŠć’ćŸéš›ć®2恤悁恮Payara Microć®ćƒ­ć‚°ć®ęŠœē²‹(ć‚Æćƒ©ć‚¹ć‚æ関連)恌恓悌怂

[2015-06-19T04:03:01.749+0900] [Payara 4.1] [INFO] [] [com.hazelcast.cluster.impl.MulticastJoiner] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1434654181749] [levelValue: 800] [[
  [192.168.99.1]:5901 [dev] [3.4.2]


Members [1] {
        Member [192.168.99.1]:5901 this
}
]]

ć”č¦§ć®é€šć‚Šćƒ”ćƒ³ćƒćƒ¼ćŒć„ćŖ恄ļ¼ ć‚½ćƒ­ę“»å‹•ć ļ¼

ć‚Æćƒ©ć‚¹ć‚æēµ„ć‚“ć§ćć ć•ć‚Œć€œ(Ā“;Ļ‰;`)

č§£ę±ŗ

ćŖ恩ćØTwitterć§å˜†ć„ć¦ćŸć‚‰ ć‹ćšć²ć‚‰ć•ć‚“ ćŒåŠ©ć‘ć¦ćć‚ŒćŸļ¼

ć‹ćšć²ć‚‰ć•ć‚“ć€ćć‚Œć§ć™ļ¼

ćØć„ć†ć‚ć‘ć§ę¬”ć®ć‚ˆć†ć«ć™ć‚Œć°ć„ć‘ćŸć€‚

java -Djava.net.preferIPv4Stack=true -jar payara-micro-4.1.152.1.jar --deploy clusterjsp.war --port 8000

恓悌恧ć‚Æćƒ©ć‚¹ć‚æ恌ēµ„悁悋ļ¼ ēµ„悁悋恞恊恊恊恊恊恊恊ļ¼ ( ļ¾Ÿāˆ€ļ¾Ÿ)ļ½±ļ¾Šļ¾Šå…«å…«ļ¾‰ćƒ½ļ¾‰ćƒ½ļ¾‰ćƒ½ļ¾‰ ļ¼¼ / ļ¼¼/ ļ¼¼

[2015-06-19T04:11:18.909+0900] [Payara 4.1] [INFO] [] [com.hazelcast.cluster.ClusterService] [tid: _ThreadID=45 _ThreadName=hz.glassfish-web.server.generic-operation.thread-1] [timeMillis: 1434654678909] [levelValue: 800] [[
  [192.168.99.1]:5900 [dev] [3.4.2]

Members [21] {
        Member [192.168.99.1]:5900 this
        Member [192.168.99.1]:5901
        Member [192.168.99.1]:5902
        Member [192.168.99.1]:5903
        Member [192.168.99.1]:5904
        Member [192.168.99.1]:5905
        Member [192.168.99.1]:5906
        Member [192.168.99.1]:5907
        Member [192.168.99.1]:5908
        Member [192.168.99.1]:5909
        Member [192.168.99.1]:5910
        Member [192.168.99.1]:5911
        Member [192.168.99.1]:5912
        Member [192.168.99.1]:5913
        Member [192.168.99.1]:5914
        Member [192.168.99.1]:5915
        Member [192.168.99.1]:5916
        Member [192.168.99.1]:5917
        Member [192.168.99.1]:5918
        Member [192.168.99.1]:5919
        Member [192.168.99.1]:5920
}
]]

ē„”駄恫21ć‚Æćƒ©ć‚¹ć‚æļ¼

ć“ć“ć¾ć§ę›ø恄恦态 ć¾ć ć¾ć ć„ć‘ć‚“ć˜ć‚ƒć­ļ¼ŸćØꀝ恄态 čŖæå­ć«ä¹—ć£ć¦PMC48(Payara Micro Clusterćƒ‡ć‚¹)ćØ恋悄悍恆ćØć—ćŸć‘ć©30ćƒ‘ćƒ¤ćƒ©č¶ŠćˆćŸć‚ćŸć‚Šć‹ć‚‰Mac恕悓恌å”øć‚Šć ć—ćŸć®ć§ćƒ“ćƒ“ć£ć¦ę­¢ć‚ć¦ć—ć¾ć£ćŸć€‚

č¬č¾ž

ć‹ćšć²ć‚‰ć•ć‚“ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć—ćŸļ¼ļ¼ļ¼

]]>
Fri, 19 Jun 2015 00:00:00 +0900
http://backpaper0.github.io/2015/06/07/git_archive.html http://backpaper0.github.io/2015/06/07/git_archive.html <![CDATA[Git恧ē®”ē†ć—ć¦ć‚‹ć‚½ćƒ¼ć‚¹ć‚’ZIP恫恙悋]]> Git恧ē®”ē†ć—ć¦ć‚‹ć‚½ćƒ¼ć‚¹ć‚’ZIP恫恙悋

å°ćƒć‚æ恧恙怂 ćƒ”ćƒ¢ēš„ćŖ怂

GitHub恫悂push恗恦ćŖ恄ēŠ¶ę…‹ć§ć”ć‚‡ć£ćØäŗŗć«č¦‹ć¦ć‚‚ć‚‰ć„ćŸć„ćŖćƒ¼ć€ ć£ć¦ćØćć«Dropbox恫ē½®ć„ć¦ćƒ¼ćØ恋悄悋äŗ‹ćŒć‚ć‚‹ć‚“ć§ć™ćŒć€ ćć®ćØćć«.gitć¾ć§å«ć‚ćŸććŖ恄恗.gitignore恧ē„”č¦–ć—ć¦ć‚‹ćƒ•ć‚”ć‚¤ćƒ«ć‚‚å«ć‚ćŸććŖ恄ćØćć«ä½æ恆悄恤恧恙怂

git archive ć‚³ćƒžćƒ³ćƒ‰ć‚’ä½æć„ć¾ć™ć€‚

git archive --format=zip HEAD > ../hoge.zip

--format 恫ä½æćˆć‚‹ćƒ•ć‚©ćƒ¼ćƒžćƒƒćƒˆćÆ git archive --list 恧ē¢ŗčŖć§ćć¾ć™ć€‚

]]>
Sun, 07 Jun 2015 00:00:00 +0900
http://backpaper0.github.io/2015/05/29/wildfly_auto_download.html http://backpaper0.github.io/2015/05/29/wildfly_auto_download.html <![CDATA[Gradle恧Wildfly悒č‡Ŗå‹•ć§ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ć—ć¦ć‹ć‚‰Arquillianć‚’å®Ÿč”Œć™ć‚‹]]> Gradle恧Wildfly悒č‡Ŗå‹•ć§ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ć—ć¦ć‹ć‚‰Arquillianć‚’å®Ÿč”Œć™ć‚‹

Java EEćŖć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć®ćƒ†ć‚¹ćƒˆć‚’å›žć™ć®ć« Arquillian 恌ä¾æ利ćŖ悓恧恙恑恩态 ć‚µćƒ³ćƒ—ćƒ«ę›øćć®ć«ę‰‹å‹•ć§ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć‚µćƒ¼ćƒć‚’ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ć™ć‚‹ć®ćÆć”ć‚‡ć„é¢å€’ćŖ恮恧态 Gradleć«ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ć—ć¦ć‚‚ć‚‰ć†ć£ć¦ć„ć†č©±ć§ć™ć€‚

ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć‚µćƒ¼ćƒćÆ Wildfly 悒ä½æē”Øć—ć¾ć™ć€‚

恝悌恧ćÆbuild.gradleć‚’ć„ć˜ć‚Šć¾ć—ć‚‡ćƒ¼ļ¼

ć¾ćšdependencies恫Wildflyć®ć‚¢ćƒ¼ć‚«ć‚¤ćƒ–ć‚’čæ½åŠ ć—ć¾ć™ć€‚

dependencies {
    archives "org.wildfly:wildfly-dist:$wildflyVersion@zip"
}

ę¬”ć«ć‚¢ćƒ¼ć‚«ć‚¤ćƒ–ć‚’unzip恙悋ć‚æć‚¹ć‚Æ悒ę›øćć¾ć™ć€‚

task readyWildfly(type: Copy) {
    def wildflyZip = configurations.archives.find { it.name ==~ /wildfly.*/ }

    from zipTree(wildflyZip)
    into buildDir

    inputs.file wildflyZip
    outputs.upToDateWhen { new File(buildDir, "wildfly-$wildflyVersion").exists() }
}

ę—¢ć«unzip恕悌恟WildflyćŒć‚ć£ćŸć‚‰ć‚æć‚¹ć‚Æć‚’ć‚¹ć‚­ćƒƒćƒ—ć—ć¦ć»ć—ć„ć®ć§ inputs.file ćØ outputs.upToDateWhen ć§ć“ć”ć‚‡ć“ć”ć‚‡ć‚„ć£ć¦ć„ć¾ć™ć€‚

ęœ€å¾Œć«ćƒ†ć‚¹ćƒˆć‚’å®Ÿč”Œć™ć‚‹å‰ć«readyWildflyć‚æć‚¹ć‚Æć‚’å®Ÿč”Œć™ć‚‹ć‚ˆć†ć«ć—ć¾ć™ć€‚

test.dependsOn readyWildfly

恂ćØćÆ gradlew build 恙悋恠恑怂

惭悰ćÆ恓悓ćŖꄟ恘怂

:compileJava
:processResources UP-TO-DATE
:classes
:war
:assemble
:readyWildfly
:compileTestJava
:processTestResources
:testClasses
:test
:check
:build

BUILD SUCCESSFUL

Total time: 31.107 secs

This build could be faster, please consider using the Gradle Daemon: http://gradle.org/docs/2.4/userguide/gradle_daemon.html

testć®å‰ć«readyWildflyć‚æć‚¹ć‚ÆćŒå®Ÿč”Œć•ć‚Œć¦ć„ć¾ć™ć­ć€‚ 恓恮Ꙃē‚¹ć§ę‰€å®šć®å “ꉀćøWildfly恌unzipć•ć‚Œć¦ć„ć¾ć™ć€‚

恧ćÆ悂恆äø€åŗ¦ gradlew build 恗恦ćæć¾ć—ć‚‡ć†ć€‚

:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:war UP-TO-DATE
:assemble UP-TO-DATE
:readyWildfly
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build UP-TO-DATE

BUILD SUCCESSFUL

Total time: 10.617 secs

This build could be faster, please consider using the Gradle Daemon: http://gradle.org/docs/2.4/userguide/gradle_daemon.html

ćŖ悓ćØ恄恆恓ćØ恧恗悇恆ļ¼ readyWildflyć‚æć‚¹ć‚ÆćŒć‚¹ć‚­ćƒƒćƒ—ć•ć‚Œć¾ā€¦ā€¦ć•ć‚Œć¦ćŖ恄ļ¼ļ¼Ÿ

ć‚ć‚Œćƒ¼ļ¼Ÿļ¼Ÿļ¼Ÿ(Ā“ļ½„_ļ½„`)

悂态悂恆äø€åŗ¦å®Ÿč”Œć ļ¼

:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:war UP-TO-DATE
:assemble UP-TO-DATE
:readyWildfly UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build UP-TO-DATE

BUILD SUCCESSFUL

Total time: 8.532 secs

This build could be faster, please consider using the Gradle Daemon: http://gradle.org/docs/2.4/userguide/gradle_daemon.html

ćŖćœć‚¹ć‚­ćƒƒćƒ—ć•ć‚ŒćŸć—(惻_惻)

ćØ恄恆悏恑恧态ćŖ悓恋恂ćØäø€ę­©ć§å‡ŗę„ć¦ćŖć„ę„ŸćŒć‚ć‚Šć¾ć™ćŒć€äø€ē•Ŗ恮ē›®ēš„恧恂悋 怌č‡Ŗå‹•ć§Wildfly恮ęŗ–å‚™ć—ć¦Arquilliančµ°ć‚‰ć›ć‚‹ć€ć£ć¦ć®ćÆå‡ŗę„ćŸć®ć§äø€ę—¦ć“ć‚Œć§č‰Æć„ć‚„ćƒ¼ć€‚

]]>
Fri, 29 May 2015 00:00:00 +0900
http://backpaper0.github.io/2015/03/28/doma_listener_from_config.html http://backpaper0.github.io/2015/03/28/doma_listener_from_config.html <![CDATA[Doma 2.2.0恋悉EntityListener悒DIć‚³ćƒ³ćƒ†ćƒŠć‹ć‚‰å–å¾—ć§ćć‚‹ć‚ˆć†ć«ćŖć£ćŸ #doma2]]> Doma 2.2.0恋悉EntityListener悒DIć‚³ćƒ³ćƒ†ćƒŠć‹ć‚‰å–å¾—ć§ćć‚‹ć‚ˆć†ć«ćŖć£ćŸ #doma2

Doma 2.1.0ć¾ć§ćÆ EntityType å®Ÿč£…ć‚Æćƒ©ć‚¹(ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ę™‚ć«č‡Ŗ動ē”Ÿęˆć•ć‚Œć‚‹ć‚Æćƒ©ć‚¹)ć®ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æå†…ć§å˜ē“”ć«ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć•ć‚Œć¦ć„ć¾ć—ćŸćŒć€ Doma 2.2.0恋悉ćÆ Config 恫 getEntityListenerProvider ćØć„ć†ćƒ”ć‚½ćƒƒćƒ‰ćŒčæ½åŠ ć•ć‚Œć€ ćć®ćƒ”ć‚½ćƒƒćƒ‰ćŒčæ”恙 EntityListenerProvider ć‚’ć‚«ć‚¹ć‚æ惞悤ć‚ŗ恙悋恓ćØ恧 EntityListener ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹å–å¾—ć‚’ćƒ•ćƒƒć‚Æć§ćć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚

EntityListenerProvider ćÆ EntityListener ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’å–å¾—ć™ć‚‹ get ćƒ”ć‚½ćƒƒćƒ‰ć‚’ęŒć£ć¦ć„ć¾ć™ć€‚ EntityListenerProvider.get ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆå®Ÿč£…ćÆę¬”ć®ć‚ˆć†ć«ćŖć£ć¦ć„ć¾ć™ć€‚

default <ENTITY, LISTENER extends EntityListener<ENTITY>> LISTENER get(
        Class<LISTENER> listenerClass, Supplier<LISTENER> listenerSupplier) {
    return listenerSupplier.get();
}

ć”č¦§ć®ć‚ˆć†ć«å˜ē“”恫 Supplier.get ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œć—ć¦ć„ć‚‹ć ć‘ć§ć™ć€‚

恓恮 EntityListenerProvider.get ćƒ”ć‚½ćƒƒćƒ‰ć‚’ć‚Ŗćƒ¼ćƒćƒ¼ćƒ©ć‚¤ćƒ‰ć—ć¦DIć‚³ćƒ³ćƒ†ćƒŠć‹ć‚‰ EntityListener ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’å–å¾—ć™ć‚‹ä¾‹ć‚’ę›øćć¾ć™ć€‚ ć“ć®ä¾‹ć§ćÆGuice悒ä½æē”Ø恗恦恊悊 Config å®Ÿč£…ć‚Æćƒ©ć‚¹ćØ EntityListenerProvider å®Ÿč£…ć‚Æćƒ©ć‚¹ć‚‚Guice恧ē®”ē†ć—ć¦ć„ć¾ć™ć€‚

ć¾ćšćÆ EntityListenerProvider å®Ÿč£…ć‚Æćƒ©ć‚¹ć€‚ Guice恮 Injector ć‚’ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć—ć¦ćć“ć‹ć‚‰ EntityListener ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’å–å¾—ć—ć¦ć„ć¾ć™ć€‚

package sample;

import java.util.function.Supplier;

import javax.inject.Inject;

import org.seasar.doma.jdbc.EntityListenerProvider;
import org.seasar.doma.jdbc.entity.EntityListener;

import com.google.inject.Injector;

public class SampleEntityListenerProvider implements EntityListenerProvider {

    @Inject
    private Injector injector;

    @Override
    public <ENTITY, LISTENER extends EntityListener<ENTITY>> LISTENER get(
            Class<LISTENER> listenerClass, Supplier<LISTENER> listenerSupplier) {
        return injector.getInstance(listenerClass);
    }
}

ꬔ恫 Config å®Ÿč£…ć‚Æćƒ©ć‚¹ć€‚ EntityListenerProvider ć‚’ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć—ć¦ćć®ć¾ć¾čæ”恗恦恄悋恠恑恧恙怂

package sample;

import javax.inject.Inject;
import javax.sql.DataSource;

import org.seasar.doma.jdbc.Config;
import org.seasar.doma.jdbc.EntityListenerProvider;
import org.seasar.doma.jdbc.dialect.Dialect;

public class SampleConfig implements Config {

    @Inject
    private EntityListenerProvider entityListenerProvider;

    @Inject
    private DataSource dataSource;

    @Inject
    private Dialect dialect;

    @Override
    public EntityListenerProvider getEntityListenerProvider() {
        return entityListenerProvider;
    }

    @Override
    public DataSource getDataSource() {
        return dataSource;
    }

    @Override
    public Dialect getDialect() {
        return dialect;
    }
}

Guiceä»„å¤–ć®DIć‚³ćƒ³ćƒ†ćƒŠć§ć‚‚ä¼¼ćŸć‚ˆć†ćŖę–¹ę³•ć‚’å–ć‚Œć‚‹ć§ć—ć‚‡ć†ć€‚ ä¾‹ćˆć°CDI恠ćØ Injector 恧ćÆćŖ恏 BeanManager ć‚’ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć—ć¦ BeanManager 恋悉 EntityListener å®Ÿč£…ć‚Æćƒ©ć‚¹ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ćƒ«ćƒƒć‚Æć‚¢ćƒƒćƒ—ć™ć‚‹ćØč‰Æ恄ćØę€ć„ć¾ć™ć€‚ (CDI 1.1ä»„é™ć§ć‚ć‚Œć° CDI.current().select(listenerClass) 恧悂č‰Æ恄ćØę€ć„ć¾ć™)

EntityListener 悒DIć‚³ćƒ³ćƒ†ćƒŠć‹ć‚‰å–å¾—ć§ćć‚‹ć‚ˆć†ć«ćŖ悋ćØč‰²ć€…ćØć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć§ćć‚‹ć®ć‚‚å¬‰ć—ć„ć§ć™ć—ć€ ć‚¤ćƒ³ć‚æćƒ¼ć‚»ćƒ—ć‚æćƒ¼ć‚’ć‹ć¾ć™ć“ćØ悂å‡ŗę„ćŸć‚Šć—ć¦ć•ć‚‰ć«å¬‰ć—ć„ć§ć™ć­ļ¼ļ¼ļ¼

]]>
Sat, 28 Mar 2015 00:00:00 +0900
http://backpaper0.github.io/2015/03/09/jersey_hk2_aop.html http://backpaper0.github.io/2015/03/09/jersey_hk2_aop.html <![CDATA[Jersey恧ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć‚’ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³å¢ƒē•Œć«ć™ć‚‹]]> Jersey恧ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć‚’ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³å¢ƒē•Œć«ć™ć‚‹

ć”ć‚‡ć‚ć£ćØč©±é”Œć«å‡ŗćŸć®ć§ē°”å˜ć«ć¾ćØć‚ć¾ć—ćŸć€‚

悄悊恟恄恓ćØ

ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć‚’ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³å¢ƒē•Œć«ć—ćŸć„ć€‚

č©±é”Œć«å‡ŗćŸę–¹ę³•

ContainerRequestFilter 悄 ContainerResponseFilter 悒ä½æć£ć¦å®Ÿē¾ć§ććŖ恄恋ćŖćƒ¼ć€ćØć„ć†č©±ćŒå‡ŗć¾ć—ćŸćŒē§ćÆē„”ē†ć ćØę€ć£ć¦ć„ć¾ć™ć€‚

ContainerRequestFilter ćÆćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć®å‰ć«å®Ÿč”Œć•ć‚Œć‚‹ć ć‘ć€ ContainerResponseFilter ćÆćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć®å¾Œć«å®Ÿč”Œć•ć‚Œć‚‹ć ć‘ć§ try-catch-finally 恌恧恍ćŖ恄恋悉恧恙怂

惑惃ćØę€ć„ć¤ćę–¹ę³•

GlasFishćŖ恩Java EE 7ęŗ–ę‹ ć®ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć‚µćƒ¼ćƒć§å‹•ć‹ć™ć®ć§ć‚ć‚Œć°ćƒŖć‚½ćƒ¼ć‚¹ć‚Æćƒ©ć‚¹ć‚’ CDIē®”ē†ćƒ“ćƒ¼ćƒ³ć«ć—ć¦ @Transactional 恧ę³Ø釈恙悌恰恝悌恠恑恧ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ćŒćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³å¢ƒē•Œć«ćŖć‚Šć¾ć™ć€‚

Tomcat + Jerseyćć‚‰ć„ć®ę§‹ęˆć§å®Ÿē¾ć™ć‚‹ę–¹ę³•

CDIä½æć£ć¦ćŖć„ć€ć£ć¦ć„ć†ć‹Tomcatć§å‹•ć‹ć—ć¦ć‚‹ć€ć¤ćƒ¼ć‹DIć‚³ćƒ³ćƒ†ćƒŠä½æć£ć¦ćŖ恄ļ¼ļ¼ļ¼ćØć„ć†å “åˆćÆć©ć†ć™ć‚Œć°č‰Æ恄恮恋ļ¼Ÿ

JerseyćÆ内éƒØēš„恫 HK2 ćØ恄恆DIć‚³ćƒ³ćƒ†ćƒŠć‚’ä½æć£ć¦ć„ć¾ć™ć€‚ 恓恮HK2恮AOPę©Ÿčƒ½ć‚’åˆ©ē”Ø恗恦ćƒŖć‚½ćƒ¼ć‚¹ć‚Æćƒ©ć‚¹ć«ć‚¤ćƒ³ćƒ†ćƒ¼ć‚»ćƒ—ć‚æćƒ¼ć‚’é©ē”Ø恗恦 ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć‚’ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³å¢ƒē•Œć«ć™ć‚‹ę–¹ę³•ćŒå–ć‚Œć¾ć™ć€‚

悶ć‚Æ惃ćØć‚µćƒ³ćƒ—ćƒ«ę›ø恄恦ćæćŸć®ć§č©³ē“°ćÆć‚³ćƒ¼ćƒ‰ć‚’čŖ­ć‚“ć§ćć ć•ć„ć€‚

ć¾ćØ悁

  • JAX-RSć®ä»•ę§˜ć§ćÆć‚µćƒ¼ćƒ–ćƒ¬ćƒƒćƒˆćƒ•ć‚£ćƒ«ć‚æć®ć‚ˆć†ćŖ try-catch-finally ćŒć§ćć‚‹ćƒć‚¤ćƒ³ćƒˆćŒē„”恄
  • CDIć‚’ä½µē”Øć™ć‚Œć°ä½•ćØ恧悂ćŖ悋
  • JerseyćŖć‚‰å®Ÿč£…ć«ä¾å­˜ć™ć‚‹ć‘ć©HK2悒ä½æ恆恓ćØć§ä½•ćØ恋ćŖ悋
]]>
Mon, 09 Mar 2015 00:00:00 +0900
http://backpaper0.github.io/2015/03/08/spring_boot_camp.html http://backpaper0.github.io/2015/03/08/spring_boot_camp.html <![CDATA[Spring Bootć‚­ćƒ£ćƒ³ćƒ—ć‚’ć‚„ć£ćŸ #kanjava_sbc]]> Spring Bootć‚­ćƒ£ćƒ³ćƒ—ć‚’ć‚„ć£ćŸ #kanjava_sbc

@making 恕悓悒講åø«ć«ćŠčæŽćˆć—恦Spring Bootć‚’åœŸå°ć«ć—ć¦ćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°ć‚’ę„½ć—ć‚€ćƒćƒ³ć‚ŗć‚Ŗćƒ³ć‚’é–‹å‚¬ć—ć¾ć—ćŸć€‚

会堓ćÆę„½å¤©ę Ŗ式会ē¤¾å¤§é˜Ŗę”Æē¤¾ć®ć‚«ćƒ•ć‚§ćƒ†ćƒŖć‚¢ć‚’ćŠå€Ÿć‚Šč‡“ć—ć¾ć—ćŸć€‚ @bufferings ć•ć‚“ć€ć”å”åŠ›ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć—ćŸć€‚

ä»Šå›žć®ćƒćƒ³ć‚ŗć‚Ŗćƒ³ć§ćÆć‚«ćƒ”ćƒ©ć§ę’®ć£ćŸå†™ēœŸć‚’Spring MVC恫ꊕ恒恦OpenCV恧ē”»åƒå¤‰ę›ć‚’ć—ć¾ć—ćŸć€‚ å¤‰ę›éƒØ分ćÆJMSć§éžåŒęœŸå‡¦ē†ć—ć‚Æćƒ©ć‚¤ć‚¢ćƒ³ćƒˆćØć‚µćƒ¼ćƒćƒ¼é–“ćÆSTOMPćØć„ć†ćƒ—ćƒ­ćƒˆć‚³ćƒ«ć‚’WebSocketäøŠć§åˆ©ē”Ø恗恦通äæ”ć—ć¾ć—ćŸć€‚

Spring Bootć®é–¢äæ‚ē„”恕ꄟ恙恔恄ļ¼ļ¼ļ¼

ć—ć‹ć—ć€ć“ć®ć‚ˆć†ć«č‰²ć€…ćŖꊀ蔓悒ä½æć£ćŸWebć‚µćƒ¼ćƒ“ć‚¹ć®ćƒćƒ³ć‚ŗć‚Ŗćƒ³ć‚’ē‰¹ć«ć‚„悄恓恗恄čØ­å®šć‚‚ć›ćš ē“„2ę™‚é–“åŠć§é€²ć‚ć‚‹äŗ‹ćŒć§ććŸć®ćÆ恄悍恄悍ćØč‡Ŗå‹•ć§čØ­å®šć‚’å®œć—ćć‚„ć£ć¦ćć‚Œć‚‹Spring BootćŒć‚ć£ć¦ć“ćć ćØę€ć„ć¾ć—ćŸć€‚

ę„½ć—ć„ćƒćƒ³ć‚ŗć‚Ŗćƒ³ć‚’č”Œć£ć¦é ‚ć„ć¦@making恕悓恫ćÆęœ¬å½“ć«ę„Ÿč¬ć§ć™ļ¼ļ¼ļ¼

ćƒćƒ³ć‚ŗć‚Ŗćƒ³ć®ę§˜å­

恔ćŖćæ恫

ę±äŗ¬ć§ć‚‚é–‹å‚¬ć•ć‚Œć‚‹ć£ć½ć„ć§ć™ć‚ˆļ¼

ćŠć¾ć‘

Spring Boot + Jersey怂 ꇇč¦Ŗä¼šć§č©±é”Œć«å‡ŗ恟悄恤恧恙怂 å‰ć«ć”ć‚‡ć“ć£ćØć‚„ć‚Šć¾ć—ćŸć€‚

]]>
Sun, 08 Mar 2015 00:00:00 +0900
http://backpaper0.github.io/2015/03/05/io.html http://backpaper0.github.io/2015/03/05/io.html <![CDATA[Reader/Writer/InputStream/OutputStream]]> Reader/Writer/InputStream/OutputStream

å°‘ć—č©±é”Œć«å‡ŗćŸć®ć§ćƒ•ć‚”ć‚¤ćƒ«čŖ­ćæę›ø恍ćŖć©ć§ć‚ˆćä½æć†ę„Ÿć˜ć®ć‚¢ćƒ¬ć‚’ć‚¢ćƒ¬ć—ćŸć„ćØę€ć„ć¾ć™ć€‚

ć¾ćšć€

  • InputStream / OutputStream ćÆ惐悤惊ćƒŖćƒ‡ćƒ¼ć‚æć®ć‚¹ćƒˆćƒŖćƒ¼ćƒ ć§ć™ć€‚ byte[] 恧čŖ­ćæę›øćć—ć¾ć™ć€‚
  • Reader / Writer ćÆćƒ†ć‚­ć‚¹ćƒˆćƒ‡ćƒ¼ć‚æć®ć‚¹ćƒˆćƒŖćƒ¼ćƒ ć§ć™ć€‚ char[] 恧čŖ­ćæę›øćć—ć¾ć™ć€‚
  • ć‚¹ćƒˆćƒŖćƒ¼ćƒ ćØ恄恆恮ćÆ byte[] 悄 char[] 悒ä½æć£ć¦å°‘ć—ćšć¤ćƒ‡ćƒ¼ć‚æ悒čŖ­ćæč¾¼ć‚“ć ć‚Šę›ø恍å‡ŗć—ćŸć‚Šć™ć‚‹ćŸć‚ć®ć‚‚ć®ć§ć™ć€‚

ćØć„ć†ć®ćŒåŸŗęœ¬ć«ćŖć‚Šć¾ć™ć€‚

ćƒ•ć‚”ć‚¤ćƒ«ć®čŖ­ćæę›ø恍

ćƒ†ć‚­ć‚¹ćƒˆćƒ•ć‚”ć‚¤ćƒ«ć‚’čŖ­ćæč¾¼ć‚€

Path path = Paths.get("path/to/file");
try (BufferedReader in = Files.newBufferedReader(path)) {
    //čŖ­ćæč¾¼ćæ処ē†
}

ćƒ•ć‚”ć‚¤ćƒ«ćÆUTF-8恧čŖ­ćæč¾¼ć¾ć‚Œć¾ć™ć€‚

UTF-8ä»„å¤–ć®ćƒ•ć‚”ć‚¤ćƒ«ć‚’čŖ­ćæč¾¼ć‚€å “åˆćÆē¬¬äŗŒå¼•ę•°ć« Charset 悒ęø”ć—ć¾ć™ć€‚

try (BufferedReader in = Files.newBufferedReader(path, Charset.forName("Windows-31J"))) {
    String line;
    while(null != (line = in.readLine())) {
        //čŖ­ćæč¾¼ćæ処ē†
    }
}

惐悤惊ćƒŖćƒ•ć‚”ć‚¤ćƒ«ć‚’čŖ­ćæč¾¼ć‚€

try (InputStream in = new BufferedInputStream(Files.newInputStream(path))) {
    byte[] b = new byte[1000];
    int i;
    while (-1 != (i = in.read(b))) {
        //čŖ­ćæč¾¼ćæ処ē†
    }
}

Files.newInputStream ćÆćƒćƒƒćƒ•ć‚”ćƒŖćƒ³ć‚°ć•ć‚ŒćŖ恄恮恧å·Ø大ćŖćƒ•ć‚”ć‚¤ćƒ«ć‚„ćŸćć•ć‚“ćƒ•ć‚”ć‚¤ćƒ«ć‚’ę‰±ć†å‡¦ē†ć ćØ遅恄ćØę€ć„ć¾ć™ć€‚ åŸŗęœ¬ēš„恫ćÆ BufferedInputStream ć§ćƒ©ćƒƒćƒ—ć™ć‚‹ę–¹ćŒč‰Æ恄恋ćØćƒ¼ć€‚

ćƒ†ć‚­ć‚¹ćƒˆćƒ•ć‚”ć‚¤ćƒ«ć‚’ę›ø恍å‡ŗ恙

try (BufferedWriter out = Files.newBufferedWriter(path)) {
    //ę›ø恍å‡ŗć—å‡¦ē†
}

惐悤惊ćƒŖćƒ•ć‚”ć‚¤ćƒ«ć‚’ę›ø恍å‡ŗ恙

try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(path))) {
    //ę›ø恍å‡ŗć—å‡¦ē†
}

Files.newInputStream ćØåŒć˜ć Files.newOutputStream ć‚‚ćƒćƒƒćƒ•ć‚”ćƒŖćƒ³ć‚°ć•ć‚Œć¾ć›ć‚“ć€‚

ć‚Ŗćƒ³ćƒ”ćƒ¢ćƒŖ恧ꉱ恆

Writer 悒ęø”ć—ćŸć‚‰ćć“ć«ć‚‚ć‚ć‚‚ć‚ę›ø恍å‡ŗć—ć¦ćć‚Œć‚‹ćƒ©ć‚¤ćƒ–ćƒ©ćƒŖćŒć‚ć‚‹ć‚“ć ć‘ć© ć‚ć–ć‚ć–ćƒ•ć‚”ć‚¤ćƒ«ć«ę›ø恍å‡ŗ恙悓恘悃ćŖćć¦ć‚Ŗćƒ³ćƒ”ćƒ¢ćƒŖć§å‡¦ē†ć—恦 String 恧ēµęžœć‚’å–ć‚ŠćŸć„ć‚“ć‚„ļ¼ ćØ恄恆悈恆ćŖå “åˆć«ćÆ StringWriter 悒ä½æć„ć¾ć™ć€‚

StringWriter out = new StringWriter();
library.writeTo(out);
String result = out.toString();

Reader / InputStream / OutputStream ć«ć‚‚ćć‚Œćžć‚Œć‚Ŗćƒ³ćƒ”ćƒ¢ćƒŖ恧ä½æē”Øć™ć‚‹ćŸć‚ć®ć‚Æćƒ©ć‚¹ćŒć‚ć‚Šć¾ć™ć€‚

  • StringReader ćÆ String 悒čŖ­ćæč¾¼ć‚ć‚‹ Reader
  • StringWriter ćÆ String ćøę›ø恍å‡ŗ恛悋 Writer
  • ByteArrayInputStream ćÆ byte[] 悒čŖ­ćæč¾¼ć‚ć‚‹ InputStream
  • ByteArrayOutputStream ćÆ byte[] ćøę›ø恍å‡ŗ恛悋 OutputStream

InputStream悒Readerćø/OutputStream悒Writerćøå¤‰ę›ć™ć‚‹

恝悌恞悌 InputStreamReader ćØ OutputStreamWriter 悒ä½æć£ć¦å¤‰ę›ć§ćć¾ć™ć€‚

InputStream in = ...
Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8);

OutputStream out = ...
Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);

ē¬¬äŗŒå¼•ę•°ć« Charset 悒ęø”ć—ć¦ć„ć¾ć™ćŒć€ä½•ć‚‚ęø”恕ćŖć„å “åˆćÆćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć‚Øćƒ³ć‚³ćƒ¼ćƒ‡ć‚£ćƒ³ć‚°ćŒä½æē”Øć•ć‚Œć‚‹ć®ć§ę³Øꄏ恌åæ…要恧恙怂 ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć‚Øćƒ³ć‚³ćƒ¼ćƒ‡ć‚£ćƒ³ć‚°ćØćÆć‚·ć‚¹ćƒ†ćƒ ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ file.encoding ć§å–å¾—ć§ćć‚‹ć‚‚ć®ć§ć™ć€‚ å¤‰ę›“ć—ćŸć„å “åˆćÆę¬”ć®ć‚ˆć†ć«Javačµ·å‹•ę™‚ć«ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć‚’čØ­å®šć—ć¾ć™ć€‚

java -Dfile.encoding=UTF-8 com.example.MainClass

ZIPćƒ•ć‚”ć‚¤ćƒ«ć‚’čŖ­ćæč¾¼ć‚€/ę›ø恍å‡ŗ恙

ZIPćƒ•ć‚”ć‚¤ćƒ«ć®čŖ­ćæę›øćć«ćÆ ZipInputStream ćØ ZipOutputStream 恌ä½æćˆć¾ć™ć€‚

InputStream in = ...
try(ZipInputStream zin = new ZipInputStream(in, StandardCharsets.UTF_8)) {
    ZipEntry zipEntry;
    while (null != (zipEntry = zin.getNextEntry())) {
        byte[] b = new byte[1000];
        int i;
        while (-1 != (i = zin.read(b))) {
            //čŖ­ćæč¾¼ćæ処ē†
        }
    }
}
OutputStream out = ...
try(ZipOutputStream zout = new ZipOutputStream(out, StandardCharsets.UTF_8)) {
    ZipEntry zipEntry = new ZipEntry("hoge.txt");
    zout.putNextEntry(zipEntry);
    byte[] b = ...
    zout.write(b);
    zout.closeEntry();
}

ćƒ•ć‚”ć‚¤ćƒ«ć®ć‚³ćƒ”ćƒ¼ć€ē§»å‹•ć‚’恙悋

Files 悒ä½æć„ć¾ć™ć€‚

Path src = ...
Path dest = ...

Files.copy(src, dest);

Files.move(src, dest);

Channel

Reader / Writer / InputStream / OutputStream 恮他恫 Channel ćØć„ć†ć‚‚ć®ć‚‚ć‚ć‚Šć¾ć™ćŒ Channel 恌åæ…要恫ćŖć‚‹ćƒ©ć‚¤ćƒ–ćƒ©ćƒŖ恫ćÆ ć»ć¼å‡ŗä¼šć£ćŸäŗ‹ćŒćŖć„ć®ć§č¦šćˆćŖćć¦ć‚‚ē”Ÿćć¦č”Œć‘ć‚‹ćØę€ć„ć¾ć™ć€‚

ćŠć¾ć‘

ćƒ†ć‚­ć‚¹ćƒˆćƒ•ć‚”ć‚¤ćƒ«ć®čŖ­ćæč¾¼ćæ恫ćÆ Files.newBufferedReader 悒ä½æ恆ćØę›øćć¾ć—ćŸćŒ Java 6ć¾ć§ćÆ FileReader 悒ä½æć£ć¦ę¬”ć®ć‚ˆć†ć«ćƒ•ć‚”ć‚¤ćƒ«čŖ­ćæč¾¼ćæć‚’ć—ć¦ć„ć¾ć—ćŸć€‚

File file = new File("path/to/file");
Reader in = new FileReader(file);
try {
    //čŖ­ćæč¾¼ćæ処ē†
} finally {
    in.close();
}

Charset 悒ęø”恕恚恫 FileReader ć‚’ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć—ć¦ć„ć¾ć™ćŒć€ ć“ć®å “åˆćÆćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć‚Øćƒ³ć‚³ćƒ¼ćƒ‡ć‚£ćƒ³ć‚°ćŒä½æć‚ć‚Œć¦ć„ć¾ć—ćŸć€‚

恗恋悂 FileReader 恫ćÆ Charset ć‚’å—ć‘å–ć‚‹ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æćÆē”Øę„ć•ć‚Œć¦ć„ć¾ć›ć‚“ć€‚ 恧ćÆćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć‚Øćƒ³ć‚³ćƒ¼ćƒ‡ć‚£ćƒ³ć‚°ä»„å¤–ć§ćƒ•ć‚”ć‚¤ćƒ«ć‚’čŖ­ćæč¾¼ćæćŸć„å “åˆćÆ恩恆恙悋恮恋ļ¼Ÿ

ćć®å “åˆćÆ态

  1. FileInputStream ć§ćƒ•ć‚”ć‚¤ćƒ«ć‚’é–‹ć„ć¦
  2. InputStreamReader 恧 Charset ć‚’ęŒ‡å®šć—ć¤ć¤ćƒ©ćƒƒćƒ—ć™ć‚‹

ćØć„ć†ę–¹ę³•ć‚’ćØć£ć¦ć„ć¾ć—ćŸć€‚

File file = new File("path/to/file");
Reader in = new InputStreamReader(new FileInputStream(file), Charset.forName("iso-2022-jp"));
try {
    //čŖ­ćæč¾¼ćæ処ē†
} finally {
    in.close();
}

恝恆恄恆čØ³ć§ java.io 恧 Charset ć‚’å—ć‘å–ć‚‰ćŖć„å “åˆćÆćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć‚Øćƒ³ć‚³ćƒ¼ćƒ‡ć‚£ćƒ³ć‚°ć€ java.nio.file 恧 Charset ć‚’å—ć‘å–ć‚‰ćŖć„å “åˆćÆUTF-8恌ä½æ悏悌悋态ćØ恄恆ꄟ恘恧恙怂

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć‚Øćƒ³ć‚³ćƒ¼ćƒ‡ć‚£ćƒ³ć‚°ćÆē’°å¢ƒć«ć‚ˆć£ć¦å¤‰ć‚ć‚‹ć®ć§ java.nio.file 悒ä½æć£ć¦ćŠćć®ćŒå®‰å…Ø恠ćØę€ć„ć¾ć™ć€‚

]]>
Thu, 05 Mar 2015 00:00:00 +0900
http://backpaper0.github.io/2015/02/28/junit_4_12_test_rule.html http://backpaper0.github.io/2015/02/28/junit_4_12_test_rule.html <![CDATA[JUnit 4.12ć‹ć‚‰å…„ć£ćŸTestRuleć‚’č»½ćč¦‹ć¦ćæ悋]]> JUnit 4.12ć‹ć‚‰å…„ć£ćŸTestRuleć‚’č»½ćč¦‹ć¦ćæ悋

DisableOnDebug

DisableOnDebug 他恮 TestRule ć‚’ćƒ©ćƒƒćƒ—ć—ć¦ć€ ćƒ‡ćƒćƒƒć‚°å®Ÿč”Œć•ć‚Œć¦ć„ć‚‹ćØćć®ćæćƒ©ćƒƒćƒ—ć—ćŸ TestRule 悒適ē”Øć—ć¾ć™ć€‚

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.DisableOnDebug;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;

public class HogeTest {

    @Rule
    public TestRule timeout = new DisableOnDebug(Timeout.seconds(1)); //1ē§’仄äøŠć‹ć‹ć£ćŸć‚‰å¤±ę•—ćØćæćŖ恙

    @Test
    public void testHoge() throws Exception {
        //test code
    }
}

恓悓ćŖꄟ恘恧 Timeout ćØēµ„ćæåˆć‚ć›ć‚‹äŗ‹ćŒå¤šć„ę°—ćŒć—ć¾ć™ć€‚

ć‚³ćƒžćƒ³ćƒ‰ćƒ©ć‚¤ćƒ³å¼•ę•°ć«ę¬”ć®ć„ćšć‚Œć‹ćŒå«ć¾ć‚Œć¦ć„ć‚Œć°ćƒ‡ćƒćƒƒć‚°å®Ÿč”Œć•ć‚Œć¦ć„ć‚‹ćØåˆ¤ę–­ć™ć‚‹ć‚ˆć†ć§ć™ć€‚

  • -Xdebug
  • -agentlib:jdwp

ćƒ‡ćƒćƒƒć‚°å®Ÿč”Œć‹ć©ć†ć‹ć®åˆ¤ę–­ćÆ DisableOnDebug.isDebugging ćƒ”ć‚½ćƒƒćƒ‰ć‚’ć‚Ŗćƒ¼ćƒćƒ¼ćƒ©ć‚¤ćƒ‰ć™ć‚Œć°ć‚«ć‚¹ć‚æ惞悤ć‚ŗć§ćć¾ć™ć€‚

Stopwatch

Stopwatch ćÆćƒ†ć‚¹ćƒˆå®Ÿč”Œć«ć‹ć‹ć£ćŸę™‚é–“ć‚’ System.nanoTime ćƒ”ć‚½ćƒƒćƒ‰ć§č؈ęø¬ć—ć¾ć™ć€‚

import java.util.logging.Logger;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Stopwatch;
import org.junit.runner.Description;

public class FugaTest {

    private static Logger logger = Logger.getLogger(FugaTest.class.getName());

    @Rule
    public Stopwatch stopwatch = new Stopwatch() {
        @Override
        protected void succeeded(long nanos, Description description) {
            logger.info(() -> String.format("ćƒ†ć‚¹ćƒˆć®å®Ÿč”Œć«%,d惊惎ē§’ć‹ć‹ć£ćŸ", nanos));
        }
    };

    @Test
    public void test() throws Exception {
        //test code
    }
}

ćƒ­ć‚®ćƒ³ć‚°ē›®ēš„恫ä½æć†ć®ćŒå¤šćć†ć§ć™ć€‚

]]>
Sat, 28 Feb 2015 00:00:00 +0900
http://backpaper0.github.io/2015/01/24/git_rebase_merge.html http://backpaper0.github.io/2015/01/24/git_rebase_merge.html <![CDATA[Gitć§ćƒ–ćƒ©ćƒ³ćƒć‚’ēµ±åˆć™ć‚‹ę–¹ę³•]]> Gitć§ćƒ–ćƒ©ćƒ³ćƒć‚’ēµ±åˆć™ć‚‹ę–¹ę³•

ć“ć†ć„ć†ć‚³ćƒŸćƒƒćƒˆć‚’é‡ć­ćŸćƒ–ćƒ©ćƒ³ćƒć‚’ć€

../../../_images/git_rebase_merge_1.png

ć©ć†ć„ć†ę–¹ę³•ć§master恫ēµ±åˆć™ć‚‹ćØå¬‰ć—ć„ę“¾ćŖ恮恋ļ¼Ÿć£ć¦ć„ć†å°ćƒć‚æ恧恙怂

ćƒžćƒ¼ć‚ø恙悋

../../../_images/git_rebase_merge_2.png
git checkout master
git merge other -m "Merge branch 'other'"
git branch -d other

ę“ä½œćŒåˆ†ć‹ć‚Šć‚„ć™ć„ę„Ÿć˜ćŒć™ć‚‹ć€‚

ćƒŖćƒ™ćƒ¼ć‚¹ć™ć‚‹

../../../_images/git_rebase_merge_3.png
git checkout master
git rebase master other
git checkout master
git merge other
git branch -d other

ć‚³ćƒŸćƒƒćƒˆćŒäø€ęœ¬åŒ–恙悋怂

ćƒŖćƒ™ćƒ¼ć‚¹ć—ć¦ć‹ć‚‰ćƒžćƒ¼ć‚ø恙悋

../../../_images/git_rebase_merge_4.png
git checkout master
git rebase master other
git checkout master
git merge other --no-ff -m "Merge branch 'other'"
git branch -d other

ć‚³ćƒŸćƒƒćƒˆćŒäø€ęœ¬åŒ–ć—ć¤ć¤ćƒ–ćƒ©ćƒ³ćƒå˜ä½ć®ä½œę„­ć‚’ęŠŠę”恗悄恙恄怂

ć¾ćØ悁

ē§ćÆćƒŖćƒ™ćƒ¼ć‚¹ć—ć¦ć‹ć‚‰ćƒžćƒ¼ć‚øć™ć‚‹ę“¾ļ¼

ćŠć¾ć‘

ęœ€åˆć«ęē¤ŗć—ćŸć‚³ćƒŸćƒƒćƒˆć‚’ä½œć‚‹ć‚¹ć‚ÆćƒŖ惗惈怂

#!/bin/sh
rm -fr .git *.txt .gitignore
git init
echo init.sh>.gitignore && git add .gitignore && git commit -m "Initial Commit"
echo b>b.txt && git add b.txt && git commit -m "master 1"
git branch other
echo c>c.txt && git add c.txt && git commit -m "master 2"
echo d>d.txt && git add d.txt && git commit -m "master 3"
git checkout other
echo e>e.txt && git add e.txt && git commit -m "other 1"
echo f>f.txt && git add f.txt && git commit -m "other 2"
git checkout master
]]>
Sat, 24 Jan 2015 00:00:00 +0900
http://backpaper0.github.io/2015/01/18/getting_started_libgdx.html http://backpaper0.github.io/2015/01/18/getting_started_libgdx.html <![CDATA[libGDX惗惭ć‚ø悧ć‚Æćƒˆć‚’ć‚»ćƒƒćƒˆć‚¢ćƒƒćƒ—ć™ć‚‹ #libgdx]]> libGDX惗惭ć‚ø悧ć‚Æćƒˆć‚’ć‚»ćƒƒćƒˆć‚¢ćƒƒćƒ—ć™ć‚‹ #libgdx

libGDXćÆJavać®ć‚²ćƒ¼ćƒ ćƒ•ćƒ¬ćƒ¼ćƒ ćƒÆćƒ¼ć‚Æć§ć€ćƒ‡ć‚¹ć‚Æćƒˆćƒƒćƒ—ćƒ»Android惻iOS惻HTML5ē”Øć«ćƒ“ćƒ«ćƒ‰ć§ćć‚‹ćƒ•ćƒ¬ćƒ¼ćƒ ćƒÆćƒ¼ć‚Æ恧恙怂 ć©ć®ćƒ—ćƒ©ćƒƒćƒˆćƒ•ć‚©ćƒ¼ćƒ ć§ć‚ć£ć¦ć‚‚čµ·å‹•ē”Ø恮ć‚Æćƒ©ć‚¹ä»„å¤–ć®ć»ćØć‚“ć©ć®ć‚³ćƒ¼ćƒ‰ć‚’å…±ęœ‰ć§ćć‚‹ć™ć”ć„ć‚„ć¤ć§ć™ć€‚

今回ćÆlibGDX悒ä½æć£ćŸćƒ—ćƒ­ć‚ø悧ć‚Æćƒˆć®ć‚»ćƒƒćƒˆć‚¢ćƒƒćƒ—ę–¹ę³•ć‚’ę›ø恄恦恄恓恆ćØę€ć„ć¾ć™ć€‚

ć‚»ćƒƒćƒˆć‚¢ćƒƒćƒ—ćƒ„ćƒ¼ćƒ«ć«ć‚ˆć‚‹ćƒ—ćƒ­ć‚ø悧ć‚Æ惈恮ē”Ÿęˆ

ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ćƒšćƒ¼ć‚ø 恧 ā€œDownload Setup Appā€ 悒ć‚ÆćƒŖ惃ć‚Æ恗恦 gdx-seup.jar ć‚’ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ć—ć¦ćć ć•ć„ć€‚

ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ć§ććŸć‚‰ćƒ€ćƒ–ćƒ«ć‚ÆćƒŖ惃ć‚Æ态悂恗恏ćÆę¬”ć®ć‚³ćƒžćƒ³ćƒ‰ć§å®Ÿč”Œć—ć¦ćć ć•ć„ć€‚

java -jar gdx-setup.jar
../../../_images/gdx-setup-screenshot.png

各項ē›®ć‚’ē·Øé›†ć—ć¾ć™ć€‚

Name 惗惭ć‚ø悧ć‚Æćƒˆć®åå‰ć€‚Android惗惭ć‚ø悧ć‚Æ惈ćÆres/values/string.xml恮app_name恫悂ä½æē”Ø恕悌悋怂
Package å‡ŗåŠ›ć•ć‚Œć‚‹ć‚µćƒ³ćƒ—ćƒ«ć‚³ćƒ¼ćƒ‰ć®ćƒ‘ćƒƒć‚±ćƒ¼ć‚ø怂AndroidManifest.xml恫ę›ø恋悌悋package恫悂ä½æē”Ø恕悌悋怂
Game class ApplicationListener å®Ÿč£…ć‚Æćƒ©ć‚¹ć€‚libGDX恫恊恑悋起ē‚¹ćØćŖ悋ć‚Æćƒ©ć‚¹ć€‚
Destination 惗惭ć‚ø悧ć‚Æ惈恮å‡ŗåŠ›å…ˆćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ怂
Android SDK Android SDKć®ćƒ‘ć‚¹ć€‚Androidē”Øć®ćƒ“ćƒ«ćƒ‰ć‚’ć™ć‚‹å “åˆć«åæ…要怂

ā€œLibGDX Versionā€ ćÆęœ€ę–°ć®ć‚‚ć®ćŒéøęŠžć•ć‚Œć¦ć„ć‚‹ćÆ恚ćŖć®ć§ć€ćć®ć¾ć¾ć§ć€‚

ā€œSub Projectsā€ ćÆć™ć¹ć¦ćƒć‚§ćƒƒć‚Æć•ć‚Œć¦ć„ć‚‹ćØę€ć„ć¾ć™ć€‚ äøč¦ć«ćŖć‚Œć°ćć®ę™‚ē‚¹ć§å–悊除恑恰č‰Æć„ć—å€‹åˆ„ć«ćƒ“ćƒ«ćƒ‰ć‚‚ć§ćć‚‹ć®ć§ć€ć“ć‚Œć‚‚ćć®ć¾ć¾ć§ć€‚

ā€œExtensionsā€ ćÆ ā€œBox2dā€ 恮ćæ恌惁悧惃ć‚Æć•ć‚Œć¦ć„ć‚‹ćØę€ć„ć¾ć™ć€‚ 恓恓恫恤恄恦ćÆč©³ć—ć„č§£čŖ¬ćŒå‡ŗę„ć‚‹ć»ć©ć®ēŸ„č­˜ćŒć‚ć‚Šć¾ć›ć‚“ć€‚ čŖ°ć‹ę•™ćˆć¦ćć ć•ć„ļ¼ ć“ć‚Œć‚‚ćć®ć¾ć¾ć§ć„ćć¾ć—ć‚‡ć†ć€‚

仄äøŠć®ēŠ¶ę…‹ć§ ā€œGenerateā€ ć‚’ęŠ¼ć—ć¦ćć ć•ć„ć€‚

初回ćÆGradleć‚„ä¾å­˜JARć®ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ćŒč”Œć‚ć‚Œć‚‹ć®ć§ę™‚é–“ćŒć‹ć‹ć‚Šć¾ć™ć€‚ ćŠčŒ¶ć§ć‚‚é£²ć‚“ć§ćŠå¾…ć”ćć ć•ć„ć€‚

ę¬”ć®ć‚ˆć†ćŖ惭悰恌å‡ŗ悋ćØ完äŗ†ć§ć™ć€‚

BUILD SUCCESSFUL

Total time: 42.551 secs
Done!
To import in Eclipse: File -> Import -> Gradle -> Gradle Project
To import to Intellij IDEA: File -> Import -> build.gradle
To import to NetBeans: File -> Open Project...

Note

惗惭ć‚ø悧ć‚Æćƒˆć®ćƒ“ćƒ«ćƒ‰ć«ćÆ Gradle ( ę—„ęœ¬čŖžćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆ )恌ä½æć‚ć‚Œć¦ć„ć¾ć™ćŒć€ gdx-setup.jar恌čح定ęøˆćæ恮build.gradle悒å‡ŗåŠ›ć—ć¦ćć‚Œć‚‹ć®ć§Gradleć«č©³ć—ććŖćć¦ć‚‚å¤§äøˆå¤«ć§ć™ć€‚

åÆ„ć‚Šé“ļ¼šGitć§ćƒćƒ¼ć‚øćƒ§ćƒ³ē®”ē†ć‚’å§‹ć‚ć‚‹

ä»Šå¾Œć®äŗ‹ć‚’č€ƒćˆć¦Gitć§ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ē®”ē†ć‚’å§‹ć‚ć¦ćŠćć¾ć—ć‚‡ć†ć€‚

ć‚»ćƒƒćƒˆć‚¢ćƒƒćƒ—ćƒ„ćƒ¼ćƒ«ćŒ .gitignore 悂å‡ŗåŠ›ć—ć¦ćć‚Œć¦ć„ć‚‹ć®ć§ć‚„ć‚„ć“ć—ć„ć“ćØćÆä½•ć‚‚č€ƒćˆćšć«ćƒćƒ¼ć‚øćƒ§ćƒ³ē®”ē†ć‚’å§‹ć‚ć‚‰ć‚Œć¾ć™ć€‚

git init
git add .
git commit -m "Initial commit"

Eclipsećøć®ć‚¤ćƒ³ćƒćƒ¼ćƒˆ

ć‚»ćƒƒćƒˆć‚¢ćƒƒćƒ—ć®ćƒ­ć‚°ć‚’č¦‹ćŸę„Ÿć˜ć ćØEclipse恫Gradlećƒ—ćƒ©ć‚°ć‚¤ćƒ³ćŒå…„ć£ć¦ć„ć‚‹ćØćć®ć¾ć¾ć‚¤ćƒ³ćƒćƒ¼ćƒˆå‡ŗę„ćć†ć§ć™ć­ć€‚

ē§ćÆGradlećƒ—ćƒ©ć‚°ć‚¤ćƒ³ćŒå…„ć£ć¦ć„ćŖ恄Eclipse悒ä½æć£ć¦ć„ć‚‹ć®ć§ć€ćć®å “åˆć®ć‚¤ćƒ³ćƒćƒ¼ćƒˆę–¹ę³•ć‚’ę›øćć¾ć™ć€‚

ć¾ćšGradleć§ć‚³ćƒžćƒ³ćƒ‰ć‚’å®Ÿč”Œć—ć¾ć™ć€‚

gradlew eclipse

ꬔ恫Eclipseć®ćƒ”ćƒ‹ćƒ„ćƒ¼ć‹ć‚‰ File ā€£ Import ā€£ General ā€£ Existing Projects into Workspace 悒éøęŠžć—ć¾ć™ć€‚ 恝悌恋悉 ā€œSelect root directoryā€ ć«ćƒ—ćƒ­ć‚ø悧ć‚Æćƒˆć®ćƒ‘ć‚¹ć‚’å…„åŠ›ć—ć¦ćć ć•ć„ć€‚

Note

惗惭ć‚ø悧ć‚Æćƒˆć®ćƒ‘ć‚¹ć‚’ć‚³ćƒ”ćƒ¼ć™ć‚‹ćØ恍ćÆMacćŖć‚‰ę¬”ć®ć‚³ćƒžćƒ³ćƒ‰ć‚’ä½æ恆ćØć‚ÆćƒŖćƒƒćƒ—ćƒœćƒ¼ćƒ‰ć«ę ¼ē“ć•ć‚Œć¦ä¾æåˆ©ć§ć™ć€‚

pwd|pbcopy

WindowsćŖć‚‰ę¬”ć®ć‚³ćƒžćƒ³ćƒ‰ć§åŒć˜äŗ‹ćŒć§ćć¾ć™ć€‚

cd|clip

ć‚¤ćƒ³ćƒćƒ¼ćƒˆć™ć‚‹ćƒ—ćƒ­ć‚ø悧ć‚Æ惈ćÆ code ćØ desktop 恠恑恧č‰Æ恄恧恗悇恆怂 åŸŗęœ¬ēš„恫ćÆćƒ‡ć‚¹ć‚Æ惈惃惗恧開ē™ŗć—ć¦ćŸć¾ć«å®Ÿę©Ÿē¢ŗčŖćØć„ć†ę„Ÿć˜ć§é€²ć‚ć‚‰ć‚Œć‚‹ćØę€ć„ć¾ć™ć€‚

ć‚¤ćƒ³ćƒćƒ¼ćƒˆć§ććŸć‚‰ļ¼ˆć“ć‚ŒćŒé¢å€’ćŖć®ć§ć™ćŒļ¼‰desktop惗惭ć‚ø悧ć‚Æćƒˆć«ć‚ć‚‹assetsćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ悒ć‚Æćƒ©ć‚¹ćƒ‘ć‚¹ć«åŠ ćˆć¦ćć ć•ć„ć€‚

ę‰‹ć£å–ć‚Šę—©ć„ę–¹ę³•ćÆassetsćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖć§å³ć‚ÆćƒŖ惃ć‚Æ恗恦 Build Path ā€£ Use as Source Folder 恧恙怂

悂恗恏ćÆ态惗惭ć‚ø悧ć‚Æćƒˆć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć‚’é–‹ć„ć¦ Java Build Path ā€£ Libraries ćØč¾æć£ć¦ ā€œAdd Class Folderā€ ć‚’ęŠ¼ć—ć¦assetsćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖć‚’ęŒ‡å®šć—ć¦ćć ć•ć„ć€‚

IntelliJ IDEAćøć®ć‚¤ćƒ³ćƒćƒ¼ćƒˆ

ē§ćÆIntelliJ IDEAåˆ†ć‹ć‚‰ć‚“ć®ć§ć™ćŒć€ć‚»ćƒƒćƒˆć‚¢ćƒƒćƒ—ć®ćƒ­ć‚°ć«ę›øć‹ć‚Œć¦ć„ć‚‹ć‚ˆć†ć« File ā€£ Import ā€£ build.gradle ć‚’ć‚„ć£ć¦ćæ恟ćØć“ć‚ć‚¤ćƒ³ćƒćƒ¼ćƒˆć§ććŸć£ć½ć„ć§ć™ć€‚

å®Ÿč”Œć™ć‚‹

desktop惗惭ć‚ø悧ć‚Æ惈恮 src/main/java/yourpackage/DesktopLauncher.java ć‚’å®Ÿč”Œć—ć¦ćć ć•ć„ć€‚ ( yourpackage ćÆć‚»ćƒƒćƒˆć‚¢ćƒƒćƒ—ę™‚ć«čØ­å®šć—ćŸćƒ‘ćƒƒć‚±ćƒ¼ć‚ø恧恙怂 適宜čŖ­ćæę›æćˆć¦ćć ć•ć„ć€‚)

ēµć³

ćØ恄恆悏恑恧libGDX惗惭ć‚ø悧ć‚Æćƒˆć®ć‚»ćƒƒćƒˆć‚¢ćƒƒćƒ—ę–¹ę³•ć‚’čØ˜č¼‰ć—ć¦ćæć¾ć—ćŸć€‚

libGDXćÆAndroidć‚¢ćƒ—ćƒŖć§ć‚ć£ć¦ć‚‚ćƒ‡ć‚¹ć‚Æ惈惃惗äø­åæƒć§é–‹ē™ŗ恧恍态 ć‚³ćƒ¼ćƒ‰ć®ę®†ć©ć‚’å…±ęœ‰ć§ćć‚‹ć®ćŒć™ć”ćć¦å¬‰ć—ćć¦ćŠę°—ć«å…„ć‚Šć§ć™ć€‚

é”˜ć‚ćć°ć‚‚ć£ćØć‚‚ć£ćØlibGDXćƒ¦ćƒ¼ć‚¶ćƒ¼ćŒå¢—ćˆć¾ć™ć‚ˆć†ć«ļ¼

]]>
Sun, 18 Jan 2015 00:00:00 +0900
http://backpaper0.github.io/2015/01/17/spring_boot_jsr330.html http://backpaper0.github.io/2015/01/17/spring_boot_jsr330.html <![CDATA[Spring Bootć®ć‚µćƒ³ćƒ—ćƒ«ć§ä½æć£ć¦ć‚‹ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’JSR 330ć®ć‚‚ć®ć«ć—ćŸ]]> Spring Bootć®ć‚µćƒ³ćƒ—ćƒ«ć§ä½æć£ć¦ć‚‹ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’JSR 330ć®ć‚‚ć®ć«ć—ćŸ

꜀čæ‘Spring Bootć§éŠć‚“ć§ć„ć¾ć™ć€‚

今回ćÆSpringć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć§ć‚ć‚‹ @Component ćØ @Autowired 悒JSR 330ć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć§ć‚ć‚‹ @Named ćØ @Inject ć«å¤‰ę›“ć—ć¦ćæć¾ć—ćŸć€‚

ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ćÆ https://github.com/backpaper0/spring_boot_sample 恧恙怂

tagćÆ https://github.com/backpaper0/spring_boot_sample/releases/tag/jsr330 恧恙怂

ęœ¬é”Œ

ē‰¹ć«ę›ø恏恓ćØćŖ恄怂 ꙮ通恫ē½®ćę›ćˆćŸć‚‰ę™®é€šć«å‹•ć„ćŸć®ć§ć€‚

ćŸć ć—ć‚¹ć‚³ćƒ¼ćƒ—ć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćÆSpringć®ć¾ć¾ć§ć™ć€‚ ć‚»ćƒƒć‚·ćƒ§ćƒ³ć‚¹ć‚³ćƒ¼ćƒ—ć®ć‚Æćƒ©ć‚¹ć«ä»˜ć‘ćŸć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ @SessionScoped ć«å¤‰ę›“ć—ćŸć‹ć£ćŸć®ć§ć™ćŒJSR 330恧ćÆćŖ恏CDIć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć®ćŸć‚ć©ć†ć—ć‚ˆć†ć‚‚ćŖć‹ć£ćŸćØ恄恆恋ćŖ悓ćØ恄恆恋怂

ć¾ć‚ć„ć„ć‹ć€‚

ć¾ćØ悁

JSR 330ć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć®ę–¹ćŒč¦‹ę…£ć‚Œć¦ć„ć¦å€‹äŗŗēš„恫ćÆč‰Æ恄怂

]]>
Sat, 17 Jan 2015 00:00:00 +0900
http://backpaper0.github.io/2015/01/16/jersey2_15_cdi.html http://backpaper0.github.io/2015/01/16/jersey2_15_cdi.html <![CDATA[Jersey 2.15恮CDIēµ±åˆć‚’試恙]]> Jersey 2.15恮CDIēµ±åˆć‚’試恙

Jersey 2.15恧CDIćØ恮ēµ±åˆę©Ÿčƒ½ćŒå¤‰ę›“恕悌恟悈恆恧恙怂

ć–ć£ćć‚ŠčŖ­ć‚€ćØć€ć“ć‚Œć¾ć§ćÆJava EEć‚³ćƒ³ćƒ†ćƒŠ(恦恄恆恋GlassFishļ¼Ÿ)ćØ恮ēµ±åˆć«ę³ØåŠ›ć—ć¦ćŸć‘ć© 2.15恋悉ćÆJava EEē’°å¢ƒć˜ć‚ƒćŖćć¦ć‚‚ēµ±åˆć§ćć¾ć£ć›ļ¼ćØć„ć†ę„Ÿć˜ć£ć½ć„ć§ć™ć€‚

č©¦ć—ćŸ

ćƒćƒ­ćƒ¼ćƒÆćƒ¼ćƒ«ćƒ‰ćŖ态ćŖć‚“ć®å½¹ć«ć‚‚ē«‹ćŸćŖ恄Web APIć‚’ä½œć£ć¦č©¦ć—ć¦ćæć¾ć—ćŸć€‚

ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ćÆ恓悓ćŖꄟ恘怂

package example;

import java.net.URI;

import org.glassfish.jersey.jdkhttp.JdkHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;
import org.jboss.weld.environment.se.Weld;

import com.sun.net.httpserver.HttpServer;

public class App {

    public static void main(String[] args) {
        Weld weld = new Weld();
        weld.initialize();
        URI uri = URI.create("http://localhost:8080/");
        ResourceConfig config = new ResourceConfig(HelloResource.class);
        HttpServer server = JdkHttpServerFactory.createHttpServer(uri, config);
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            server.stop(0);
            weld.shutdown();
        }));

        System.out.println("http://localhost:8080/hello?name=YourName");
    }
}

恔覧恮通悊恧恙怂 ꙮ通恫Weldć‚’å‹•ć‹ć—ć¦ć€Jerseyć‚’å‹•ć‹ć—ć¦ć‚‹ć ć‘ć§ć™ć€‚ ē°”å˜ć§ć™ć€‚

pom.xml恮dependencyćÆ恓悓ćŖꄟ恘怂

<dependency>
  <groupId>org.glassfish.jersey.ext.cdi</groupId>
  <artifactId>jersey-weld2-se</artifactId>
</dependency>
<dependency>
  <groupId>org.glassfish.jersey.ext.cdi</groupId>
  <artifactId>jersey-cdi1x</artifactId>
</dependency>

ꉀꄟ

ē§ćÆJava EEćÆå„½ćć§ć™ćŒJava SE恧悂ē°”å˜ć«å‹•ćć‚ˆć†ć«ćŖ悋恮ćÆå¬‰ć—ć„ć®ć§ć“ć®å¤‰ę›“ćÆå¬‰ć—ć„ć§ć™ļ¼

ć‚¢ćƒ›ć£ć½ć„ę„Ÿęƒ³ć§ć™ćŒć€ć¾ć‚ćć‚“ćŖę„Ÿć˜ć§ćƒ¼ć€‚

]]>
Fri, 16 Jan 2015 00:00:00 +0900
http://backpaper0.github.io/2015/01/15/spring_boot_gradle.html http://backpaper0.github.io/2015/01/15/spring_boot_gradle.html <![CDATA[Spring Bootć®ć‚µćƒ³ćƒ—ćƒ«ć‚’GradleåŒ–ć—ćŸć€ć‘ć©ć‚‚ā€¦ā€¦]]> Spring Bootć®ć‚µćƒ³ćƒ—ćƒ«ć‚’GradleåŒ–ć—ćŸć€ć‘ć©ć‚‚ā€¦ā€¦

꜀čæ‘Spring Bootć§éŠć‚“ć§ć„ć¾ć™ć€‚

今回ćÆMavenć§ćƒ“ćƒ«ćƒ‰ć•ć‚Œć¦ć„ć‚‹ć‚µćƒ³ćƒ—ćƒ«ć‚’GradleåŒ–ć—ć¾ć—ćŸć€‚

ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ćÆ https://github.com/backpaper0/spring_boot_sample 恧恙怂

tagćÆ https://github.com/backpaper0/spring_boot_sample/releases/tag/gradle 恧恙怂

ęœ¬é”Œ

ć¾ćšć€ćŠć‚‚ć‚€ć‚ć«gradle initć—ć¾ć—ćŸć€‚

gradle init

恙恧恫pom.xmlćŒć‚ć‚‹ć®ć§ä¾å­˜é–¢äæ‚ćØć‹č‰²ć€…ć‚ˆć‚ć—ćć‚„ć£ć¦ćć‚ŒćŸbuild.gradle恌å‡ŗåŠ›ć•ć‚Œć¾ć—ćŸć€‚

apply plugin: 'java'
apply plugin: 'maven'

group = 'sample'
version = '1.0-SNAPSHOT'

description = """spring-boot-sample"""

sourceCompatibility = 1.8
targetCompatibility = 1.8



repositories {

     maven { url "http://repo.maven.apache.org/maven2" }
}
dependencies {
    compile group: 'org.twitter4j', name: 'twitter4j-core', version:'4.0.2'
    compile(group: 'org.springframework.boot', name: 'spring-boot-starter-jersey', version:'1.2.1.RELEASE') {
exclude(module: 'spring-webmvc')
    }
    compile(group: 'org.glassfish.jersey.ext', name: 'jersey-mvc', version:'2.14') {
exclude(module: 'servlet-api')
    }
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version:'1.2.1.RELEASE'
    testCompile(group: 'org.springframework.boot', name: 'spring-boot-starter-test', version:'1.2.1.RELEASE') {
exclude(module: 'commons-logging')
    }
    testCompile group: 'junit', name: 'junit', version:'4.12'
}

恂ćØćÆSpring Boot恮ćƒŖćƒ•ć‚”ćƒ¬ćƒ³ć‚¹ć® 10.1.2 Gradle installation ć‚’å‚č€ƒć«ć—ć¦ć”ć‚‡ć“ć”ć‚‡ć“ć£ćØē·Øé›†ć—ć¾ć—ćŸć€‚

buildscript {
  repositories {
    jcenter()
    maven { url "http://repo.spring.io/snapshot" }
    maven { url "http://repo.spring.io/milestone" }
  }
  dependencies {
    //ć“ć“ć§ę‹”å¼µćƒ—ćƒ­ćƒ‘ćƒ†ć‚£springBootVersionćÆ参ē…§ć§ćć²ć‚“恮ļ¼Ÿ_(:3ļ½£āˆ )_
    classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.1.RELEASE")
  }
}

apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: 'eclipse'
apply plugin: 'idea'

group = 'sample'
version = '1.0-SNAPSHOT'

sourceCompatibility = 1.8
targetCompatibility = 1.8

ext {
  springBootVersion = '1.2.1.RELEASE'
}

repositories {
  jcenter()
  maven { url "http://repo.spring.io/snapshot" }
  maven { url "http://repo.spring.io/milestone" }
}

dependencies {
  compile 'org.twitter4j:twitter4j-core:4.0.2'
  compile ("org.springframework.boot:spring-boot-starter-jersey:$springBootVersion") {
    exclude(module: 'spring-webmvc')
  }
  compile ('org.glassfish.jersey.ext:jersey-mvc:2.14') {
    exclude(module: 'servlet-api')
  }
  compile "org.springframework.boot:spring-boot-starter-thymeleaf:$springBootVersion"
  testCompile ("org.springframework.boot:spring-boot-starter-test:$springBootVersion") {
    exclude(module: 'commons-logging')
  }
  testCompile 'junit:junit:4.12'
}

ēŸ„悊恟恄恓ćØ

build.gradle恫悂ę›øć„ćŸć‘ć©buildscriptć®ćƒ–ćƒ­ćƒƒć‚Æå†…ć§ę‹”å¼µćƒ—ćƒ­ćƒ‘ćƒ†ć‚£springBootVersionć‚’å‚ē…§ć§ććŖ恄恮恧恗悇恆恋ļ¼Ÿ ļ¼ˆč©¦ć—恫ä½æć£ć¦ćæćŸć‚‰ćƒ“ćƒ«ćƒ‰å¤±ę•—ć—ćŸć€‚ć€‚ć€‚ļ¼‰

ę•™ćˆć¦ćć ć•ć„ćŠé”˜ć„ć—ć¾ć™ćŠé”˜ć„ć—ć¾ć™ļ¼ˆä»–åŠ›ęœ¬é”˜ļ¼‰ć€‚

ę—©é€Ÿč§£ę±ŗć—ć¾ć—ćŸļ¼

恂悊恌ćØć†ć”ć–ć„ć¾ć™ļ¼

äæ®ę­£ć—ć¦ć‚³ćƒŸćƒƒćƒˆć—ć¾ć—ćŸļ¼

ć¾ćØ悁

GradleåŒ–ć™ć’ćˆē°”å˜ć ć£ćŸć€‚

]]>
Thu, 15 Jan 2015 00:00:00 +0900
http://backpaper0.github.io/2015/01/14/spring_boot_jersey.html http://backpaper0.github.io/2015/01/14/spring_boot_jersey.html <![CDATA[Spring Bootć®ć‚µćƒ³ćƒ—ćƒ«ć‚’JAX-RS恫恗恦ćæ恟]]> Spring Bootć®ć‚µćƒ³ćƒ—ćƒ«ć‚’JAX-RS恫恗恦ćæ恟

å…ˆę—„å†™ēµŒć—ćŸSpring Bootć®ć‚µćƒ³ćƒ—ćƒ«ćŒSpring MVC恧ę›øć‹ć‚Œć¦ć„ćŸć®ć§JAX-RS态 ćØ恄恆恋Jersey MVC恫恗恦ćæć¾ć—ćŸć€‚

ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ćÆå…ˆę—„ćØåŒć˜å “ę‰€ć«ē½®ć„ć¦ć‚ć‚Šć¾ć™ć€‚

tagä½œć‚Šć¾ć—ćŸć€‚

ć‚„ć£ćŸć“ćØ

ć¾ćš Spring Bootć®ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆ ć‚’å‚č€ƒć«ć—ć¦pom.xml恮ē·Ø集ćØJerseyConfigć‚Æćƒ©ć‚¹ć‚’ä½œęˆć—ć¾ć—ćŸć€‚

ꬔ恫 Jersey恮ćƒŖćƒ•ć‚”ćƒ¬ćƒ³ć‚¹ ć‚’å‚č€ƒć«ć—ć¦TemplateProcessorć®å®Ÿč£…ć‚Æćƒ©ć‚¹ć‚’ä½œęˆć—ć¾ć—ćŸć€‚

ćć—ć¦å„Controllerć‚Æćƒ©ć‚¹ć‚’Spring MVCä»•ę§˜ć‹ć‚‰JAX-RSä»•ę§˜ć«å¤‰ę›“ć—ć¾ć—ćŸć€‚ č©³ē“°ę›øćć®ćÆ面倒ćŖć®ć§ć‚³ćƒŸćƒƒćƒˆč¦‹ć¦ćć ć•ć„ć€‚

例外å‡ŗ恟

äø€é€šć‚Šć‚³ćƒ¼ćƒ‰ć‚’ę›ø恄恦态IDEć‹ć‚‰å‹•ć‹ć—ćŸć‚‰čµ·å‹•ę™‚ć«ä¾‹å¤–ćŒå‡ŗć¾ć—ćŸć€‚

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:192)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:917)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:868)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    ... 6 common frames omitted
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.addFilter(Ljava/lang/String;Ljavax/servlet/Filter;)Ljavax/servlet/FilterRegistration$Dynamic;
    at org.springframework.boot.context.embedded.FilterRegistrationBean.onStartup(FilterRegistrationBean.java:250)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.selfInitialize(EmbeddedWebApplicationContext.java:222)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.access$000(EmbeddedWebApplicationContext.java:84)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext$1.onStartup(EmbeddedWebApplicationContext.java:206)
    at org.springframework.boot.context.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:54)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5185)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 6 common frames omitted

ćŖć‚“ć‹ć‚µćƒ¼ćƒ–ćƒ¬ćƒƒćƒˆAPIćŒå¤ć„ć‚ˆć†ć§ć™ć€‚

十äø­å…«ä¹Jerseyé–¢é€£ćŒęŒć£ć¦ććŸć‚“ć ć‚ć†ćŖ态ćØꀝ恄恤恤态čŖæęŸ»ć—ć¾ć—ćŸć€‚ maven-dependency-plugin 恮 treeć‚“ćƒ¼ćƒ«ć‚’ä½æćˆć°ä¾å­˜é–¢äæ‚ć‚’äø€č¦§ć§ćć¾ć™ć€‚ -l ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć§ćƒ­ć‚°ć‚’ćƒ•ć‚”ć‚¤ćƒ«ć«ę›ø恍å‡ŗ恗恦ć‚Øćƒ‡ć‚£ć‚æ恧ꤜē“¢ć™ć‚‹ć®ćŒę„½ć ćØę€ć„ć¾ć™ć€‚

mvn -l log.txt dependency:tree -Dscope=test

Mavenć‚’å®Ÿč”Œć™ć‚‹ćØę¬”ć®ć‚ˆć†ćŖ惭悰恌ę›ø恍å‡ŗć•ć‚Œć¾ć—ćŸć€‚

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building spring-boot-sample 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.9:tree (default-cli) @ spring-boot-sample ---
[INFO] sample:spring-boot-sample:jar:1.0-SNAPSHOT
[INFO] +- org.twitter4j:twitter4j-core:jar:4.0.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-jersey:jar:1.2.1.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.2.1.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:1.2.1.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.2.1.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.2.1.RELEASE:compile
[INFO] |  |  |  +- org.slf4j:jcl-over-slf4j:jar:1.7.8:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.8:compile
[INFO] |  |  |  +- org.slf4j:log4j-over-slf4j:jar:1.7.8:compile
[INFO] |  |  |  \- ch.qos.logback:logback-classic:jar:1.1.2:compile
[INFO] |  |  |     \- ch.qos.logback:logback-core:jar:1.1.2:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.14:runtime
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.2.1.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.0.15:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.15:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:8.0.15:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.15:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.4.4:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.4.4:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.4.4:compile
[INFO] |  +- org.hibernate:hibernate-validator:jar:5.1.3.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] |  |  \- com.fasterxml:classmate:jar:1.0.0:compile
[INFO] |  +- org.springframework:spring-core:jar:4.1.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-web:jar:4.1.4.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-aop:jar:4.1.4.RELEASE:compile
[INFO] |  |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  |  +- org.springframework:spring-beans:jar:4.1.4.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-context:jar:4.1.4.RELEASE:compile
[INFO] |  |     \- org.springframework:spring-expression:jar:4.1.4.RELEASE:compile
[INFO] |  +- org.glassfish.jersey.core:jersey-server:jar:2.14:compile
[INFO] |  |  +- org.glassfish.jersey.core:jersey-common:jar:2.14:compile
[INFO] |  |  |  +- org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.14:compile
[INFO] |  |  |  \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
[INFO] |  |  +- org.glassfish.jersey.core:jersey-client:jar:2.14:compile
[INFO] |  |  +- javax.annotation:javax.annotation-api:jar:1.2:compile
[INFO] |  |  +- org.glassfish.hk2:hk2-api:jar:2.4.0-b06:compile
[INFO] |  |  |  +- org.glassfish.hk2:hk2-utils:jar:2.4.0-b06:compile
[INFO] |  |  |  \- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.4.0-b06:compile
[INFO] |  |  +- org.glassfish.hk2.external:javax.inject:jar:2.4.0-b06:compile
[INFO] |  |  \- org.glassfish.hk2:hk2-locator:jar:2.4.0-b06:compile
[INFO] |  |     \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] |  +- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.14:compile
[INFO] |  +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.14:compile
[INFO] |  +- org.glassfish.jersey.ext:jersey-spring3:jar:2.14:compile
[INFO] |  |  +- org.glassfish.hk2:hk2:jar:2.4.0-b06:compile
[INFO] |  |  |  +- org.glassfish.hk2:config-types:jar:2.4.0-b06:compile
[INFO] |  |  |  +- org.glassfish.hk2:core:jar:2.4.0-b06:compile
[INFO] |  |  |  +- org.glassfish.hk2:hk2-config:jar:2.4.0-b06:compile
[INFO] |  |  |  |  +- org.jvnet:tiger-types:jar:1.4:compile
[INFO] |  |  |  |  \- org.glassfish.hk2.external:bean-validator:jar:2.4.0-b06:compile
[INFO] |  |  |  +- org.glassfish.hk2:hk2-runlevel:jar:2.4.0-b06:compile
[INFO] |  |  |  \- org.glassfish.hk2:class-model:jar:2.4.0-b06:compile
[INFO] |  |  |     \- org.glassfish.hk2.external:asm-all-repackaged:jar:2.4.0-b06:compile
[INFO] |  |  \- org.glassfish.hk2:spring-bridge:jar:2.4.0-b06:compile
[INFO] |  \- org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.14:compile
[INFO] |     +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.3.2:compile
[INFO] |     \- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.3.2:compile
[INFO] |        \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.3.2:compile
[INFO] +- org.glassfish.jersey.ext:jersey-mvc:jar:2.14:compile
[INFO] |  +- javax.servlet:servlet-api:jar:2.4:compile
[INFO] |  \- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.2.1.RELEASE:test
[INFO] |  +- org.mockito:mockito-core:jar:1.10.8:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.1:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  \- org.springframework:spring-test:jar:4.1.4.RELEASE:test
[INFO] +- org.springframework.boot:spring-boot-starter-thymeleaf:jar:1.2.1.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-web:jar:1.2.1.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-webmvc:jar:4.1.4.RELEASE:compile
[INFO] |  +- org.thymeleaf:thymeleaf-spring4:jar:2.1.4.RELEASE:compile
[INFO] |  |  +- org.thymeleaf:thymeleaf:jar:2.1.4.RELEASE:compile
[INFO] |  |  |  +- ognl:ognl:jar:3.0.8:compile
[INFO] |  |  |  \- org.unbescape:unbescape:jar:1.1.0.RELEASE:compile
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.8:compile
[INFO] |  \- nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:jar:1.2.7:compile
[INFO] \- junit:junit:jar:4.12:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.425 s
[INFO] Finished at: 2015-01-14T23:02:38+09:00
[INFO] Final Memory: 21M/165M
[INFO] ------------------------------------------------------------------------

servlet-api悒ꤜē“¢ć—ć¦ćƒ’ćƒƒćƒˆć—ćŸē®‡ę‰€ć‚’見悋ćØ悄ćÆ悊jersey-mvcćŒä¾å­˜ć—ć¦ć„ć¾ć—ćŸć€‚

dependency要ē“ ć«exclusion要ē“ ć‚’čæ½åŠ ć—恦servlet-apićøć®ä¾å­˜ć‚’é™¤å¤–ć—ćŸ ćØ恓悍IDEć‹ć‚‰ć‚‚čµ·å‹•ć§ćć¾ć—ćŸć€‚

ꉀꄟ

Spring MVCćÆMVCćØčØ€ć†ć ć‘ć‚ć£ć¦ćƒ“ćƒ„ćƒ¼ć‚’ęŒć¤ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ćÆć•ćć•ćä½œć‚Œćć†ćŖę°—ćŒć—ć¾ć—ćŸć€‚

ćć‚Œć«åÆ¾ć—ć¦JAX-RSćÆ単ē“”恫JSON悒čæ”恙ćØ恄恆悈恆ćŖAPIć‚’ä½œć‚‹ć®ć«ē‰¹åŒ–恗恦悋ćŖćƒ¼ć€ćØę”¹ć‚ć¦ę€ć„ć¾ć—ćŸć€‚

ć¾ć‚ć€ćć‚“ćŖꄟ恘恧怂 ćŠć—ć¾ć„ć€‚

]]>
Wed, 14 Jan 2015 00:00:00 +0900
http://backpaper0.github.io/2015/01/11/spring_boot.html http://backpaper0.github.io/2015/01/11/spring_boot.html <![CDATA[Spring Bootć‚’ć‚„ć£ć¦ćæ恟]]> Spring Bootć‚’ć‚„ć£ć¦ćæ恟

ć—ć‚‡ć¼ć”ć‚€ćŒSpring Bootć®ćƒćƒ³ć‚ŗć‚Ŗćƒ³ć®ćƒ¬ćƒćƒ¼ćƒˆć‚’ę›øć„ć¦ć„ćŸ ć®ć§ćć‚Œć‚’å‚č€ƒć«ę‰‹ć‚’å‹•ć‹ć—ć¦ćæć¾ć—ćŸć€‚ ćƒ–ćƒ­ć‚°é€šć‚Šć«å†™ēµŒć—ć¦ć„ć£ćŸć‚‰ę™®é€šć«å‹•ć„ćŸć®ć§ę„½ć”悓恧恗恟怂

恟恠恗ē§ć®ēŸ„č­˜ćŒć‚¢ćƒ¬ć§ Twitter Application Management 恮Settingsć‚æćƒ–ć«ć‚ć‚‹ ā€œAllow this application to be used to Sign in with Twitterā€ ć«ćƒć‚§ćƒƒć‚Æć‚’å…„ć‚Œć‚‹åæ…č¦ćŒć‚ć‚‹ć£ć½ć„ć®ć«ę°—ä»˜ć‹ćŖćć¦ćć“ć ć‘ć”ć‚‡ć£ćØć¤ć¾ćšć„ćŸć€‚ Twitterļ¾Œļ¾Ÿļ¾–ļ½øļ¾žļ¾”ļ¾ļ¾ļ½øļ¾žć—恦ćŖć„ć®ćƒćƒ¬ć‚‹ļ¼

HttpServletRequestćØHttpSession悒ćŖ恏恙

恕恦态å‡ŗę„äøŠćŒć£ćŸć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć§ćÆ HttpServletRequest ćØ HttpSession 悒ä½æć£ć¦ć„ć‚‹ē®‡ę‰€ćŒć‚ć£ćŸć®ć§ćć‚Œć‚‰ć‚’ä½æ悏ćŖć„ć‚ˆć†ć«å¤‰ę›“ć—ć¾ć™ć€‚

Note

HttpServletRequest ćØ HttpSession ćÆć‚µćƒ¼ćƒ–ćƒ¬ćƒƒćƒˆć®API恧恂悊Spring恮API恧ćÆć‚ć‚Šć¾ć›ć‚“ć€‚ ćŖć‚‹ć¹ćä½Žćƒ¬ćƒ™ćƒ«ć®API悒ē›“ꎄä½æē”Ø恗ćŖć„ę–¹ćŒć‚³ćƒ¼ćƒ‰ćŒć‚·ćƒ³ćƒ—ćƒ«ć«ćŖ悋恗 ćƒ¦ćƒ‹ćƒƒćƒˆćƒ†ć‚¹ćƒˆćŒę›øćć‚„ć™ćć¦å¬‰ć—ć„ć€ćØć„ć†ć®ćŒå€‹äŗŗēš„ćŖ考恈恧恙怂

ć¾ćšćÆ HttpServletRequest ć‚’ę¶ˆć—ć¾ć™ć€‚ Twitter恮čŖčØ¼ć‹ć‚‰ęˆ»ć£ć¦ćć‚‹ćØćć« oauth_verifier ćØ恄恆ćƒŖć‚Æć‚Øć‚¹ćƒˆćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚’å—ć‘å–ć£ć¦ć„ć‚‹ę‰€ć«ä½æć‚ć‚Œć¦ć„ć¾ć™ć€‚ 恓悌悒TwitterController恮doTweetćƒ”ć‚½ćƒƒćƒ‰ćØåŒć˜ć‚„ć‚Šę–¹ć§å—ć‘å–ć‚‹ć‚ˆć†ć«å¤‰ę›“ć—ć¾ć™ć€‚

@RequestMapping("accessToken")
public String accessToken(Model model,
        @RequestParam(value = "oauth_verifier", required = true) String verifier)
        throws TwitterException {

ꬔ恄恧HttpSessionć‚’ę¶ˆć—ć¾ć™ć€‚ čŖčØ¼ć®éš›ć«åæ…要ćØćŖ悋ćƒŖć‚Æć‚Øć‚¹ćƒˆćƒˆćƒ¼ć‚Æćƒ³ćØć‚¢ć‚Æć‚»ć‚¹ćƒˆćƒ¼ć‚Æćƒ³ć‚’äæęŒć™ć‚‹ćŸć‚ć« HttpSession 恌ä½æē”Øć•ć‚Œć¦ć„ć‚‹ć‚ˆć†ć§ć™ć€‚ 今回ćÆćć‚Œć‚‰ć‚’ę ¼ē“ć™ć‚‹ć‚»ćƒƒć‚·ćƒ§ćƒ³ć‚¹ć‚³ćƒ¼ćƒ—恮ć‚Æćƒ©ć‚¹ć‚’ä½œć£ć¦ć‚³ćƒ³ćƒˆćƒ­ćƒ¼ćƒ©ćƒ¼ć«ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć™ć‚‹ę–¹ę³•ć‚’ćØć‚Šć¾ć™ć€‚

ć¾ćšć“ć‚ŒćŒćƒˆćƒ¼ć‚Æćƒ³ć‚’ę ¼ē“ć™ć‚‹ć‚»ćƒƒć‚·ćƒ§ćƒ³ć‚¹ć‚³ćƒ¼ćƒ—恮ć‚Æćƒ©ć‚¹ć€‚

package jp.co.bizreach.spring_boot_sample;

import java.io.Serializable;

import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;

import twitter4j.auth.AccessToken;
import twitter4j.auth.RequestToken;

@Component
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS,
        value = WebApplicationContext.SCOPE_SESSION)
public class TwitterAuth implements Serializable {

    private AccessToken accessToken;

    private RequestToken requestToken;

    public AccessToken getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(AccessToken accessToken) {
        this.accessToken = accessToken;
    }

    public RequestToken getRequestToken() {
        return requestToken;
    }

    public void setRequestToken(RequestToken requestToken) {
        this.requestToken = requestToken;
    }
}

TwitterAuthController ćØ TwitterController 恫ćÆę¬”ć®ć‚ˆć†ć«ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć«ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć—ć¾ć™ć€‚

@Autowired
private TwitterAuth auth;

恂ćØćÆć“ć®ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć‚’ä½æć£ć¦ćƒˆćƒ¼ć‚Æćƒ³ć‚’ę ¼ē“ć—ćŸć‚Šå–ć‚Šå‡ŗ恗恟悊恙悌恰ć‚Ŗćƒƒć‚±ćƒ¼ć§ć™ć€‚

ć“ć‚Œć§ć‚µćƒ¼ćƒ–ćƒ¬ćƒƒćƒˆAPI悒ćŖ恏恙恓ćØ恌å‡ŗę„ć¾ć—ćŸļ¼

pom.xmlć‚’ä½œć‚‹

ć—ć‚‡ć¼ć”ć‚€ć®ćƒ–ćƒ­ć‚°ć‚ˆć‚Š

今回ćÆć‚µćƒ³ćƒ—ćƒ«ć‚¢ćƒ—ćƒŖć‚’ä½œć£ć¦ćć‚Œć¦ć„ć¦ć€åŸŗęœ¬ēš„恫ćÆćć‚Œć‚’å‹•ć‹ć—ć¦ćæć‚‹ć£ć¦ę„Ÿć˜ć ć£ćŸć‘ć©ć€pomćƒ•ć‚”ć‚¤ćƒ«ć®ä½œęˆć®ćØć“ć‚ć‹ć‚‰ć‚„ć£ć¦ćæćŸć‹ć£ćŸć‹ć‚‚ć€‚

ä½œęˆć—ć¾ć—ć‚‡ć†ļ¼

ć‚µćƒ³ćƒ—ćƒ«ćÆmvn archetype:generate恧ē©ŗć®ćƒ—ćƒ­ć‚ø悧ć‚Æćƒˆć‚’ä½œć£ćŸć‚ćØ恫 pom.xml悒ē·Ø集恗恦dependency悒čæ½åŠ ć—ćŸć‚ˆć†ć«č¦‹ćˆć¾ć™ć€‚

適当ćŖćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ恧mvn archetype:generateć‚’å®Ÿč”Œć—ć¾ć™ć€‚

mvn archetype:generate

恙悋ćØč‰²ć‚“ćŖé››å½¢ćŒäø€č¦§ć§ćšć‚‰ćƒ¼ć£ćØå‡ŗć¦ćć‚‹ć®ć§ä½æć„ćŸć„ć‚‚ć®ć‚’ē•Ŗå·ć§ęŒ‡å®šć—ć¾ć™ć€‚

今回ćÆćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć® maven-archetype-quickstart 悒ä½æē”Øć—ć¾ć™ć®ć§ę•°å­—ćÆä½•ć‚‚å…„åŠ›ć›ćšę¬”ć«é€²ćæć¾ć™ć€‚

maven-archetype-quickstart ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ć‚’å°‹ć­ć‚‰ć‚Œć¾ć™ć€‚ ę—¢ć«ęœ€ę–°ćŒéøęŠžć•ć‚Œć¦ć„ć‚‹ć®ć§ć“ć“ć‚‚ä½•ć‚‚å…„åŠ›ć›ćšę¬”ć«é€²ćæć¾ć™ć€‚

恓恓恋悉 groupId态artifactId态versionć€ćć—ć¦ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć® package ć‚’å°‹ć­ć‚‰ć‚Œć¾ć™ć€‚ é©å®œå…„åŠ›ć—ć¦ćć®ć¾ć¾é€²ć‚€ćØę¬”ć®ć‚ˆć†ćŖ惭悰恌å‡ŗ恦ē©ŗć®ćƒ—ćƒ­ć‚ø悧ć‚ÆćƒˆćŒä½œęˆć•ć‚Œć¾ć™ć€‚

[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.1
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: /Users/backpaper0/src/temp
[INFO] Parameter: package, Value: app
[INFO] Parameter: groupId, Value: sample
[INFO] Parameter: artifactId, Value: spring-boot-sample
[INFO] Parameter: packageName, Value: app
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] ********************* End of debug info from resources from generated POM ***********************
[INFO] project created from Old (1.x) Archetype in dir: /Users/backpaper0/src/temp/spring-boot-sample
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 55.560 s
[INFO] Finished at: 2015-01-12T12:38:58+09:00
[INFO] Final Memory: 14M/95M
[INFO] ------------------------------------------------------------------------

ä½œęˆć•ć‚ŒćŸćƒ•ć‚”ć‚¤ćƒ«ćÆę¬”ć®ć‚ˆć†ćŖꄟ恘怂

  • ./pom.xml
  • ./src/main/java/app/App.java
  • ./src/test/java/app/AppTest.java

pom.xmlćØHello, world!恙悋恠恑恮ć‚Æćƒ©ć‚¹(App.java)ćØassertTrue(true)ć™ć‚‹ć ć‘ć®ćƒ†ć‚¹ćƒˆć‚Æćƒ©ć‚¹(AppTest.java)恧恙怂

App.java ćØ AppTest.java ćÆ要悉ćŖć„ć®ć§ę¶ˆć—ć¾ć™ć€‚

恝悌恋悉pom.xml悒ē·Øé›†ć—ć¾ć™ć€‚

mvn archetype:generate恗恟ē›“å¾Œć®ēŠ¶ę…‹ćÆę¬”ć®ć‚ˆć†ćŖꄟ恘恧恙怂

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>sample</groupId>
  <artifactId>spring-boot-sample</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>spring-boot-sample</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

ć“ć‚Œć« ćƒŖćƒ•ć‚”ćƒ¬ćƒ³ć‚¹ć®10.1.1 Maven installation ć‚’å‚č€ƒć«ć—ć¦ parent要ē“ ćØ dependency要ē“ ć‚’čæ½åŠ ć—ć¾ć—ćŸć€‚ 恂ćØ恤恄恧恫JUnitć®ćƒćƒ¼ć‚øćƒ§ćƒ³ć‚’4.12恫äøŠć’ć¾ć—ćŸć€‚ 恝悌ćØmaven-compiler-plugin恮čØ­å®šć‚’čæ½åŠ ć—恦Java 8ć§ćƒ“ćƒ«ćƒ‰ć•ć‚Œć‚‹ć‚ˆć†ć«ć—ć¾ć—ćŸć€‚ ć‚“ć§ć‚‚ć£ć¦ć€spring-boot-maven-plugin恮čØ­å®šć‚’čæ½åŠ ć—ć¦ć‚¹ć‚æćƒ³ćƒ‰ć‚¢ćƒ­ćƒ³JARć‚’ä½œć‚Œć‚‹ć‚ˆć†ć«ć—ć¾ć—ćŸć€‚

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>sample</groupId>
  <artifactId>spring-boot-sample</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>spring-boot-sample</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.1.RELEASE</version>
  </parent>

  <dependencies>
    <dependency>
      <groupId>org.twitter4j</groupId>
      <artifactId>twitter4j-core</artifactId>
      <version>4.0.2</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
          <encoding>${project.build.sourceEncoding}</encoding>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

ć“ć‚Œć§ę¦‚ć­ćƒćƒ³ć‚ŗć‚Ŗćƒ³ć®pom.xml恫čæ‘恏ćŖć£ćŸćØę€ć„ć¾ć™ć€‚

ä»Šå¾Œć®äŗˆå®š

ćƒŖćƒ•ć‚”ćƒ¬ćƒ³ć‚¹ć«ćÆ 10.1.2 Gradle installation ćØć„ć†ć®ćŒć‚ć£ćŸć®ć§GradleåŒ–ć—ć¦ćæ恟恄恧恙恭怂

恝悌ćØ spring-boot-starter-jersey ćØć„ć†ć®ćŒć‚ć‚‹ć£ć½ć„ć®ć§Spring MVC悒JAX-RS恫ē½®ćę›ćˆć‚‹ćØć„ć†ć®ć‚‚ć‚„ć£ć¦ćæ恟恄恧恙怂

ā€¦ā€¦ć‚„悉ćŖć„é›°å›²ę°—ćŒę¼‚ć£ć¦ć„ć¾ć™ćŒę°—ć«ć—ćŖć„ę–¹å‘ć§ļ¼

ć¾ćØ悁

ć²ćØć®ćƒ–ćƒ­ć‚°ć‚’å†™ēµŒć—ćŸć ć‘ć£ć¦ć„ć†ä»–åŠ›ęœ¬é”˜ćŒć²ć©ć„ćƒ–ćƒ­ć‚°åˆć‚ć§ć—ćŸć€‚

ä»Šå¹“ć‚‚ć‚ˆć‚ć—ććŠé”˜ć„č‡“ć—ć¾ć™ć€‚

ä»Šę—„ć®ć‚³ćƒ¼ćƒ‰

]]>
Sun, 11 Jan 2015 00:00:00 +0900
http://backpaper0.github.io/2014/12/24/glassfish_create_session_id.html http://backpaper0.github.io/2014/12/24/glassfish_create_session_id.html <![CDATA[GlassFishć§ć‚»ćƒƒć‚·ćƒ§ćƒ³ID悒ē”Ÿęˆć—恦悋ćØ恓悍]]> GlassFishć§ć‚»ćƒƒć‚·ćƒ§ćƒ³ID悒ē”Ÿęˆć—恦悋ćØ恓悍

恓悌ćÆ GlassFish Advent Calendar 2014 恮24ę—„ē›®ć§ć™ć€‚

ē›øå¤‰ć‚ć‚‰ćšć®å°ćƒć‚æ恧恙怂

仄前čŖæć¹ćŸć®ć§ć™ćŒć€ GlassFish恧恮HttpSessionå®Ÿč£…ć‚Æćƒ©ć‚¹ćÆ org.apache.catalina.session.StandardSession 恧态 恓悌ćÆTomcatć®ć‚³ćƒ¼ćƒ‰ć‚’åˆ©ē”Øć—ćŸć‚‚ć®ć§ć™ćŒć€ ć‚»ćƒƒć‚·ćƒ§ćƒ³ID恮ē”Ÿęˆå‡¦ē†ćÆå¤‰ę›“ć•ć‚Œć¦ć„ć‚‹ć‚ˆć†ć§ć™ć€‚

ćŖ悓悄恋悓悄č¾æć£ć¦č”ŒććØ com.enterprise.util.uuid.UuidUtil 恮 generateUuid ćƒ”ć‚½ćƒƒćƒ‰ć«č”Œćē€ćć¾ć—ćŸć€‚

ć‚³ćƒ¼ćƒ‰ć‚’å¼•ē”Øć—ć¾ć™ć€‚

//this method can take in the session object
//and insure better uniqueness guarantees
public static String generateUuid(Object obj) {

    //low order time bits
    long presentTime = System.currentTimeMillis();
    int presentTimeLow = (int) presentTime;
    String presentTimeStringLow = formatHexString(presentTimeLow);

    StringBuilder sb = new StringBuilder(50);
    sb.append(presentTimeStringLow);
    //sb.append(":");
    sb.append(getIdentityHashCode(obj));
    //sb.append(":");
    //sb.append(_inetAddr);
    sb.append(addRandomTo(_inetAddr));
    //sb.append(":");
    sb.append(getNextRandomString());
    return sb.toString();
}

恔覧恮通悊态

  • ć‚·ć‚¹ćƒ†ćƒ ę—„ä»˜
  • ć‚»ćƒƒć‚·ćƒ§ćƒ³ć‚Ŗ惖ć‚ø悧ć‚Æ惈恮Identityćƒćƒƒć‚·ćƒ„ć‚³ćƒ¼ćƒ‰
  • ćƒ­ćƒ¼ć‚«ćƒ«ćƒ›ć‚¹ćƒˆć®IPć‚¢ćƒ‰ćƒ¬ć‚¹
  • ćƒ©ćƒ³ćƒ€ćƒ ćŖę–‡å­—åˆ—

悒ē¹‹ć’ćŸć‚‚ć®ć«ćŖć£ć¦ć„ć¾ć™ć€‚

ć“ć“ć‹ć‚‰å‘¼ć³å‡ŗć•ć‚Œć¦ć„ć‚‹ćƒ”ć‚½ćƒƒćƒ‰ć‚’ē“°ć‹ćč¦‹ć¦č”ŒććØ7ę–‡å­—ć§åˆ‡ć£ć¦ćŸć‚Šć—ć¦ćƒžć‚øć“ć‚Œć§ć‚»ć‚­ćƒ„ć‚¢ćŖ悓ļ¼Ÿ ćØć‹ę€ć£ć¦ć—ć¾ć£ćŸć‚Šć—ć¾ć—ćŸćŒ ā€œinsure better uniqueness guaranteesā€ ćØ恋ę›øć‹ć‚Œć¦ć‚‹ć—č”ēŖč€ę€§é«˜ćć¦å¤§äøˆå¤«ćŖć‚“ć§ć—ć‚‡ć†ćŸć¶ć‚“ć€‚

恔ćŖćæ恫 org.apache.catalina.session.StandardSession ćÆ org.glassfish.main.web:web-core 恫态 com.enterprise.util.uuid.UuidUtil ćÆ org.glassfish.main.common:common-util ć«å…„ć£ć¦ć„ć¾ć™ć€‚

ćØć„ć†ć‚ć‘ć§ć‚ć£ć•ć‚Šć—ć¦ć„ć¾ć™ćŒć€ä»„äøŠć€‚

GlassFishć•ć‚“ć€ę„å¹“ć‚‚ćŠäø–話恫ćŖć‚Šć¾ć™ļ¼

]]>
Wed, 24 Dec 2014 00:00:00 +0900
http://backpaper0.github.io/2014/12/24/syobotsum.html http://backpaper0.github.io/2014/12/24/syobotsum.html <![CDATA[ć—ć‚‡ć¼ć¤ć‚€ #syobochim]]> ć—ć‚‡ć¼ć¤ć‚€ #syobochim

恓悌ćÆ ć—ć‚‡ć¼ć”ć‚€ Advent Calendar 2014 恮24ę—„ē›®ć§ć™ć€‚

ćØć„ć†ćƒ„ć‚¤ćƒ¼ćƒˆć‚’č¦‹ć¦č»½ć„ę°—ęŒć”ć§ä½œć£ć¦ćæć¾ć—ćŸćŒč“‹ć‚’é–‹ć‘ć‚‹ćØč‰²ć‚“ćŖäŗŗćŒč‰²ć‚“ćŖäŗ‹ć‚’ę›ø恄恦恊悊态 ć—ć‚‡ć¼ć”ć‚€ęœ¬å½“ć«č‰Æć‹ć£ćŸć­ļ¼ć£ć¦ć„ć†ę„Ÿć˜ć§ć„ć£ć±ć„ć®ę„½ć—ć„ć‚¢ćƒ‰ćƒ™ćƒ³ćƒˆć‚«ćƒ¬ćƒ³ćƒ€ćƒ¼ć‚‚ćÆ悄24ę—„ē›®ćØćŖć‚Šć¾ć—ćŸć€‚

ć€Œć—ć‚‡ć¼ć¤ć‚€ć€ä½œć‚Šć¾ć—ćŸ

ć•ć¦ć€ä»Šå›žē§ćÆć—ć‚‡ć¼ć”ć‚€ć‚’ćƒ¢ćƒćƒ¼ćƒ•ć«ć—ć¦ć€Œć—ć‚‡ć¼ć¤ć‚€ć€ćØć„ć†ć‚²ćƒ¼ćƒ ä½œć£ć¦ćæć¾ć—ćŸć€‚ ć‚²ćƒ¼ćƒ ć®ć‚¤ćƒ”ćƒ¼ć‚øć‚’č²¼ć‚Šć¾ć™ć€‚

../../../_images/syobotsum_screen_shot.png

ćƒ«ćƒ¼ćƒ«ćÆč‡³ć£ć¦ć‚·ćƒ³ćƒ—ćƒ«ć§ć™ć€‚ ē”»é¢ć®äø‹ć®ę–¹ć«č¦‹ćˆć¦ć„ć‚‹ćƒćƒ¼ćƒˆćƒ»ćƒ¬ćƒƒćƒ‰ć‚­ćƒ³ć‚°ćƒ»é›Ŗć ć‚‹ć¾ć‚’ęŒ‡ć§å¼¾ććØé£›ć‚“ć§č”Œć£ć¦ē€åœ°ć—ć¾ć™ć€‚ åˆ¶é™ę™‚é–“10ē§’恮間恫ꬔ怅ćØå¼¾ć„ć¦é«˜ćē©ćæäøŠć’ć¦ćć ć•ć„ć€‚ é›Ŗ降悋ć‚ÆćƒŖć‚¹ćƒžć‚¹ć®č”—ć«ē©ćæäøŠćŒć£ćŸåˆ†ć ć‘å„³å­åŠ›ćŒę‰‹ć«å…„ć‚Šć¾ć™ć€‚ ćØ恄恆态ćŖ悓恋悂恆恓恮Ꙃē‚¹ć§ć—ć‚‡ć¼ć”ć‚€ć™ć¾ć‚“ć€ćØčØ€ć„ćŸććŖć‚‹ę„Ÿć˜ć®ć‚³ćƒ³ć‚»ćƒ—ćƒˆć§ć™ć€‚

ē©ć‚€ć‚‚ć®ć«ć‚ˆć£ć¦ćƒć‚¤ćƒ³ćƒˆćŒē•°ćŖć‚Šć¾ć™ć€‚

  • ćƒćƒ¼ćƒˆļ¼š5ćƒć‚¤ćƒ³ćƒˆ
  • ćƒ¬ćƒƒćƒ‰ć‚­ćƒ³ć‚°ļ¼š2ćƒć‚¤ćƒ³ćƒˆ
  • é›Ŗć ć‚‹ć¾ļ¼š1ćƒć‚¤ćƒ³ćƒˆ

ćƒćƒ¼ćƒˆćÆćƒć‚¤ćƒ³ćƒˆēØ¼ć’ć¾ć™ćŒč½äø‹é€Ÿåŗ¦ćŒć®ć‚“ć³ć‚Šć—ć¦ć„ć¾ć™ć€‚

野č‰Æapkćƒ•ć‚”ć‚¤ćƒ«ć‚’ē”Øę„ć—ć¾ć—ćŸć€‚ č‰Æ恑悌恰遊悓恧ćæć¦ćć ć•ć„ć€‚

ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ćÆ恓恔悉怂

gradlew android:build 恗恟悉apkć‚’ćƒ“ćƒ«ćƒ‰ć§ćć¾ć™ć€‚

恔ćŖćæć«å®Ÿę©Ÿć§ē¢ŗčŖć—ć¦ć„ć¾ć›ć‚“(ļ½·ļ¾˜ļ½Æ

ć‚²ćƒ¼ćƒ ć‚’ä½œć£ć¦ćæ恦

恙恔恏ē°”単ćŖć‚²ćƒ¼ćƒ ć§ć™ćŒć‚²ćƒ¼ćƒ ä½œć‚Šåˆåæƒč€…恫ćÆé›£ć—ć„éƒØåˆ†ć‚‚ć‚ć‚Šć¾ć—ćŸć€‚

恗恋恗ꊀ蔓ēš„ćŖé›£ć—ć•ć‚ˆć‚Šć‚‚ć‚²ćƒ¼ćƒ ć‚·ć‚¹ćƒ†ćƒ ć®ć‚¢ć‚¤ćƒ‡ć‚¢ćŒå‡ŗćŖć‹ć£ćŸć‚Šēµµć®ęŗ–å‚™ć«ę‰‹é–“å–ć£ć¦ć—ć¾ć„ć¾ć—ćŸć€‚

ć‚¢ćƒ‰ćƒ™ćƒ³ćƒˆć‚«ćƒ¬ćƒ³ćƒ€ćƒ¼ć®ćƒć‚æć‚’č€ƒćˆć¦ć„ćŸćØćć«ć€Œć—ć‚‡ć¼ć¤ć‚€ć€ćØ恄恆čØ€č‘‰ćŒå…ˆć«ęµ®ć‹ć‚“ć ć®ć§ä½•ć‹ć‚’ē©ć‚€ć‚‚ć®ć«ć—ć‚ˆć†ćØćÆę€ć£ć¦ć„ćŸć®ć§ć™ćŒć€ ć·ć‚ˆć·ć‚ˆć®ć‚ˆć†ćŖč½ć”ć‚‚ć®ć‚²ćƒ¼ćƒ ć«ć—ć‚ˆć†ć‹ćŖćƒ¼ć€ 恝悌ćØć‚‚å°†ę£‹å“©ć—ć®ć‚ˆć†ćŖ悂恮悂ē©ć‚€ćØ恄恆åŸŗęœ¬ć‚³ćƒ³ć‚»ćƒ—ćƒˆć‹ć‚‰ćÆé€ø脱恗ćŖ恄恋ćŖćƒ¼ć€ ćŖ恩ꂩćæć¾ć—ćŸć€‚

ę‚©ćæćÆć—ć¾ć—ćŸćŒćŖ悓恛ꙮꮵćÆWebć‚¢ćƒ—ćƒŖ恧CRUD恮äŗœēØ®ćæ恟恄ćŖć®ć°ć£ć‹ä½œć£ć¦ć‚‹čŗ«ćØ恗恦ćÆå‡ć£ćŸäŗ‹ć‚’ć‚„ć‚‹ćØ恗恬ćØꀝ恄态 ć‚·ćƒ³ćƒ—ćƒ«ćŖćƒ«ćƒ¼ćƒ«ć«ćŖć‚‹ć‚ˆć†č€ƒćˆćŸęœ«ć«å‰čØ˜ć®ć‚ˆć†ćŖ悂恮恫ćŖć‚Šć¾ć—ćŸć€‚

ć‚³ćƒ¼ćƒ‡ć‚£ćƒ³ć‚°ć‚‚ę™®ę®µć‚„ć£ć¦ć‚‹äŗ‹ćØćÆē•°ćŖć‚Šć¾ć—ćŸćŒćŖć‚‹ć¹ćé«˜ćƒ¬ćƒ™ćƒ«APIć‚’åˆ©ē”Ø恙悋äŗ‹ć§ ćŖ悓ćØć‹å½¢ć«å‡ŗę„ć¾ć—ćŸć€‚

TODO

ćØć‚Šć‚ćˆćšå‹•ćć¾ć™ćŒęœŖå®Œęˆć§ć™ć€‚ ꬔ恫TODO悒čØ˜č¼‰ć—ć¾ć™ć€‚

  • SEćØBGMć‚’ä»˜ć‘ćŸć„
  • ćƒ˜ćƒ«ćƒ—ć‚’ēµ„č¾¼ćæćŸć„ć€‚ćƒ–ćƒ­ć‚°ć«ę“ä½œę–¹ę³•ę›ø恏ćØć‹ć‚¢ćƒ¬
  • ćƒ•ć‚§ćƒ¼ćƒ‰ć‚¢ć‚¦ćƒˆę™‚ć€å„ćƒ‘ćƒ¼ćƒ„ć®ęž ć®ć”ć‚‰ć¤ćć‚’ćŖ悓ćØ恋恗恟恄
  • ē”»åƒć®ćƒ­ćƒ¼ćƒ‰ć‚’éžåŒęœŸć«ć—ćŸć„
  • ēµęžœē”»é¢ćŒćŠćØćŖć—ć„ć‹ć‚‰ć‚‚ć£ćØć‚ć”ć‚ƒć‚ć”ć‚ƒć•ć›ćŸć„
  • ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ć«ć‚³ćƒ”ćƒ³ćƒˆć»ć¼ćŖć„ć®ć€ćŸć¶ć‚“å¾Œć§å›°ć‚‹ć‹ć‚‰č¦šćˆć¦ć‚‹ć†ć”ć«ę›øć„ć¦ćŠććŸć„

ē‰¹ć«BGMćÆć›ć£ć‹ććŖć®ć§ä½œę›²ć—ćŸć„ćØč€ƒćˆć¦ć„ć¾ć—ćŸćŒćć‚“ćŖꙂ間ćÆćŖć‹ć£ćŸļ¼ˆć¾ćŒćŠ

ćć‚‚ćć‚‚ćƒ‘ć‚½ć‚³ćƒ³ć§ę›²ä½œć‚‹ć®ć£ć¦ć©ć†ć—ćŸć‚‰č‰Æ恄恧恙恋恭ļ¼Ÿ ę•™ćˆć¦ćˆć‚ć„ć²ćØļ¼ļ¼ˆä»–åŠ›ęœ¬é”˜

ꊀ蔓ēš„ćŖ話

ć€Œć—ć‚‡ć¼ć¤ć‚€ć€ćÆlibGDX恧開ē™ŗć‚’ć—ć¾ć—ćŸć€‚

libGDXćÆJava恧ę›øć‹ć‚ŒćŸć‚²ćƒ¼ćƒ ćƒ•ćƒ¬ćƒ¼ćƒ ćƒÆćƒ¼ć‚Æć§ć€ć•ć•ćƒ¼ć£ćØć‚³ćƒ¼ćƒ‰ć‚’ę›ø恏ćØćć®ć‚³ćƒ¼ćƒ‰ć‚’ćƒ‡ć‚¹ć‚Æćƒˆćƒƒćƒ—ć‚¢ćƒ—ćƒŖ态Androidć‚¢ćƒ—ćƒŖ态iOSć‚¢ćƒ—ćƒŖćŖć©ć«ćƒ“ćƒ«ćƒ‰å‡ŗę„ć‚‹ć‚¹ć‚“ć„ć‚„ć¤ć§ć™ć€‚

ē§ćÆAndroidć‚¹ćƒžćƒ›ęŒć£ć¦ć„ćŖ恄恗iOS開ē™ŗč€…ćƒ©ć‚¤ć‚»ćƒ³ć‚¹ć‚‚ęŒć£ć¦ć„ćŖć„ć®ć§ćƒ—ćƒ©ć‚¤ćƒ™ćƒ¼ćƒˆć§ć‚¹ćƒžćƒ›ć‚¢ćƒ—ćƒŖ開ē™ŗćÆ恗ćŖć„ć®ć§ć™ćŒć€ libGDX恧恂悌恰Java SE恧ę›øć„ć¦ćƒ‡ć‚¹ć‚Æćƒˆćƒƒćƒ—ć§å‹•ć‹ć›ć‚‹ć®ć§ē§ć®ć‚ˆć†ćŖč€…ć§ć‚ć£ć¦ć‚‚ć‚¹ćƒžćƒ›ć‚¢ćƒ—ćƒŖ開ē™ŗ恌å‡ŗę„ć¦ć—ć¾ć„ć¾ć—ćŸć€‚

libGDX恮äŗ‹ć‚’č©³ć—ćēŸ„ć‚ŠćŸć„ę–¹ćÆ GitHub恫恂悋libGDX恮Wiki 悒čŖ­ć‚€ć‹ć€ŒlibGDX 恗悓恕悓怍恧悰悰悋ćØč‰Æ恄恧恗悇恆怂

ć¾ćØ悁

  • ć‚²ćƒ¼ćƒ ä½œć‚‹ć®é›£ć—ć„
  • libGDX恙恔恏č‰Æ恄

ę˜Žę—„ć®ć‚¢ćƒ‰ćƒ™ćƒ³ćƒˆć‚«ćƒ¬ćƒ³ćƒ€ćƒ¼ćÆ

ć—ć‚‡ć¼ć”ć‚€ć®ē•Ŗć§ćƒ•ć‚£ćƒŠćƒ¼ćƒ¬ 恧恙恭ļ¼

]]>
Wed, 24 Dec 2014 00:00:00 +0900
http://backpaper0.github.io/2014/12/15/jersey_optional.html http://backpaper0.github.io/2014/12/15/jersey_optional.html <![CDATA[Jersey 2.14ć§ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®å—ć‘å–ć‚Šć«Optional恌ä½æćˆć‚‹ć‚ˆć†ć«ćŖć£ćŸ]]> Jersey 2.14ć§ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®å—ć‘å–ć‚Šć«Optional恌ä½æćˆć‚‹ć‚ˆć†ć«ćŖć£ćŸ

Jersey 2.14恌ćƒŖćƒŖćƒ¼ć‚¹ć•ć‚ŒćŸć‚ˆć†ć§ć™ļ¼

恧态ę³Øē›®ćÆ [JERSEY-2612] 恧恙怂 恓恮åƾåæœć®ćŠć‹ć’恧@QueryParamćŖć©ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ悒Optionalć§å®šē¾©ć™ć‚‹äŗ‹ćŒåÆčƒ½ć«ćŖć‚Šć¾ć™ć€‚ 恟恠恗ParamConverter悒ę›ø恏åæ…要ćÆć‚ć‚Šć¾ć™ćŒć€‚

ParamConverterć£ć¦ćŖ悓悄恭悓ļ¼ć£ć¦ę–¹ćÆ JAX-RSć§ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®å—ć‘å–ć‚Šę–¹ć‚’ć„ć‚ć„ć‚č©¦ć™ ć®å¾ŒåŠć‚’čŖ­ć‚“ć§ćć ć•ć„ć¾ć›ćƒ¼ć€‚

ćƒŖć‚Æć‚Øć‚¹ćƒˆćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ悒Optionalć§å—ć‘å–ć‚‹ć‚³ćƒ¼ćƒ‰ä¾‹

é©å½“ć§ć™ćŒć‚µć‚Æćƒƒć”ć‚‡ćØć‚µćƒ³ćƒ—ćƒ«ę›øćć¾ć—ćŸć€‚

ćƒŖć‚½ćƒ¼ć‚¹ć‚Æćƒ©ć‚¹ć‚’ć“ć”ć‚‰ć«ć‚‚ęŽ²č¼‰ć—ć¾ć™ć€‚ ć”ć‚‡ćƒ¼ē°”単ćŖä¾‹ć§ć™ćŒć€ć“ć‚“ćŖꄟ恘恧ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć®å¼•ę•°ć«Optional悒ä½æćˆć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć™ć€‚

package example;

import java.util.Optional;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

@Path("hello")
public class HelloWorld {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String say(@QueryParam("name") Optional<String> name) {
        return "Hello, " + name.orElse("world") + "!";
    }
}

ę³Øꄏē‚¹ćØ恗恦ćÆå…ˆć»ć©ć‚‚ę›øćć¾ć—ćŸćŒParamConverterå®Ÿč£…ć‚Æćƒ©ć‚¹ćØParamConverterProviderå®Ÿč£…ć‚Æćƒ©ć‚¹ć‚‚ č‡Ŗå‰ć§ęŗ–å‚™ć—ćŖćć¦ćÆćŖ悉ćŖ恄äŗ‹ć§ć™ć€‚ ć¾ć‚ć€äø€åŗ¦ę›ø恄恟悉ä½æć„å›žć›ć‚‹ćÆ恚ćŖ恮恧悵ć‚Æ惃ćØę›øć„ć¦ćŠćć¾ć—ć‚‡ćƒ¼ć€‚

ä»Šć¾ć§ć“ć‚ŒćŒå‡ŗę„ćŖć‹ć£ćŸē†ē”±

@QueryParamćŖ恩恧ę³Øé‡ˆć•ć‚ŒćŸå¼•ę•°ćøęø”ć•ć‚Œć‚‹å€¤ćÆSingleValueExtractor恮extractćƒ”ć‚½ćƒƒćƒ‰ć‚’ 通悋悓恧恙恌态Jersey 2.13ć¾ć§ć®extractćƒ”ć‚½ćƒƒćƒ‰ćÆć€Œå€¤ćŒnull恧ćŖ恑悌恰ParamConverterćŖć©ć§å¤‰ę›ć€ nullćŖ悉@DefaultValue恧čØ­å®šć•ć‚ŒćŸå€¤ć‚’čæ”ć™ć€ćØć„ć†ę„Ÿć˜ć®å®Ÿč£…ć«ćŖć£ć¦ć„ć¾ć—ćŸć€‚

ćć®éƒØåˆ†ć‚’ęŠœē²‹ć—ć¾ć™ć€‚

@Override
public T extract(MultivaluedMap<String, String> parameters) {
    String v = parameters.getFirst(getName());
    if (v != null) {
        try {
            return fromString(v);
        } catch (WebApplicationException ex) {
            throw ex;
        } catch (ProcessingException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new ExtractorException(ex);
        }
    } else {
        return defaultValue();
    }
}

ć“ć®ćƒ­ć‚ø惃ć‚ÆćŒåŽŸå› ć§Optional恮ParamConverter悒ę›ø恄恦悂null恌ęø”ć£ć¦ćć‚‹ć‚¢ćƒ¬ć£ć·ć‚Šć§ć—ćŸć€‚

恗恋恗恓恮extractćƒ”ć‚½ćƒƒćƒ‰ćÆJersey 2.14ć§ę¬”ć®ć‚ˆć†ć«äæ®ę­£ć•ć‚Œć¾ć—ćŸć€‚

@Override
public T extract(MultivaluedMap<String, String> parameters) {
    String v = parameters.getFirst(getName());
    try {
        return fromString((v == null && isDefaultValueRegistered()) ? getDefaultValueString() : v);
    } catch (WebApplicationException ex) {
        throw ex;
    } catch (ProcessingException ex) {
        throw ex;
    } catch (IllegalArgumentException ex) {
        return defaultValue();
    } catch (Exception ex) {
        throw new ExtractorException(ex);
    }
}

ć”č¦§ć®é€šć‚Šć€Œå€¤ćŒnullć‹ć¤ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆå€¤ćŒčØ­å®šć•ć‚Œć¦ć„ć‚Œć°ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆå€¤ć‚’ć€ 恝恆恧ćŖć‘ć‚Œć°å€¤ć‚’ParamConverterćŖ恩恫ęø”恙怍ćØ恄恆é¢Ø恫ćŖć£ć¦ć„ć¾ć™ć€‚

ć“ć‚Œć§å€¤ćŒnullć®å “åˆć§ć‚‚ParamConverterć‚’é€šć‚‹ć‚ˆć†ć«ćŖ悊态Optionalćøć®å¤‰ę›ćŒåÆčƒ½ć«ćŖć‚Šć¾ć—ćŸć€‚

ć¾ćØ悁

  • Jersey恧ćƒŖć‚Æć‚Øć‚¹ćƒˆćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćŖć©ć®å—ć‘å–ć‚Šć«Optionalä½æćˆć‚‹ć‚ˆć†ć«ćŖć£ć¦å¬‰ć—ć„
  • ćƒć‚¤ćƒ†ćƒ³ć‚·ćƒ§ćƒ³ć§ćƒ–ćƒ­ć‚°ę›ø恄恟悉ꖇē« ć‚„恰恄

恝悓ćŖę„Ÿć˜ć§ćƒ¼

]]>
Mon, 15 Dec 2014 00:00:00 +0900
http://backpaper0.github.io/2014/12/14/kotlin_static_method.html http://backpaper0.github.io/2014/12/14/kotlin_static_method.html <![CDATA[Kotlin恧staticćƒ”ć‚½ćƒƒćƒ‰ćŒå®šē¾©ć§ćć‚‹ć‚ˆć†ć«ćŖć£ćŸć®ć§JAX-RSćƒŖćƒ™ćƒ³ć‚ø]]> Kotlin恧staticćƒ”ć‚½ćƒƒćƒ‰ćŒå®šē¾©ć§ćć‚‹ć‚ˆć†ć«ćŖć£ćŸć®ć§JAX-RSćƒŖćƒ™ćƒ³ć‚ø

恓ćØ悊悓怜(ęŒØꋶ)

恓悌ćÆ Kotlin Advent Calendar 2014 恮14ę—„ē›®ć§ć™ć€‚

å¤ć®ēµ‚ć‚ć‚Šć« 関č„æKotlin勉強会 ć‚’é–‹å‚¬ć—ć€ē§ćÆKotlin恧JAX-RS悒悄悋ćØ恄恆ē™ŗč”Øć‚’ć—ć¾ć—ćŸć€‚ JAX-RSć«ć„ćć¤ć‹ć‚ć‚‹ćƒŖć‚Æć‚Øć‚¹ćƒˆćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®å—ć‘å–ć‚Šć‹ćŸć®ć†ć” 怌Stringć®å¼•ę•°ć‚’ć²ćØć¤ć ć‘å—ć‘å–ć‚‹ā€valueOfā€ćØć„ć†åå‰ć®staticćƒ•ć‚”ć‚Æ惈ćƒŖćƒ”ć‚½ćƒƒćƒ‰ć‚’ęŒć¤ć‚Æćƒ©ć‚¹ć€ ćŒå®Ÿē¾ć§ćć¾ć›ć‚“ć§ć—ćŸć€‚ ćć®ćØćć®Kotlinć®ćƒćƒ¼ć‚øćƒ§ćƒ³(M7)恧ćÆstaticćƒ”ć‚½ćƒƒćƒ‰ćŒå®šē¾©ć§ććŖć‹ć£ćŸć‹ć‚‰ć§ć™ć€‚

ć—ć‹ć—ćƒćƒ¼ć‚øćƒ§ćƒ³M9恋悉platformStaticć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ä½æē”Ø恗恦staticćƒ”ć‚½ćƒƒćƒ‰ć‚’å®šē¾©ć§ćć‚‹ć‚ˆć†ć«ćŖć£ćŸć‚ˆć†ć§ć™ć€‚

ćØ恄恆悏恑恧ćƒŖćƒ™ćƒ³ć‚øć—ć¾ć—ćŸć€‚ ę¬”ć®ć‚ˆć†ćŖꄟ恘恧ę›øć‘ć¾ć™ć€‚

package app

import kotlin.platform.platformStatic

public class ValueObj private (val value: String) {
  class object {
    platformStatic fun valueOf(value: String) = ValueObj(value)
  }
}

Kotlinć®ę€ęƒ³ćŒć©ć†ć‚ć‚ŒJavač؀čŖžć€ć¾ćŸćÆę—¢å­˜ć®Javaćƒ©ć‚¤ćƒ–ćƒ©ćƒŖćØć®å…±å­˜ć‚’č€ƒę…®ć™ć‚‹ćØstaticćƒ”ć‚½ćƒƒćƒ‰ć® 定ē¾©ćÆåæ…č¦ć ć‚ć†ćŖćƒ¼ćØę€ć£ć¦ć„ćŸć®ć§ć“ć®ę©Ÿčƒ½čæ½åŠ ćÆč‰Æ恄ćØę€ć„ć¾ć™ć€‚

個äŗŗēš„恫ćÆstaticćƒ•ć‚”ć‚Æ惈ćƒŖćƒ”ć‚½ćƒƒćƒ‰ć‚’ęŒć¤ćƒćƒŖćƒ„ćƒ¼ć‚Ŗ惖ć‚ø悧ć‚Æćƒˆć‚’å¤šē”Øć™ć‚‹ć®ć§å¤§å¤‰åŠ©ć‹ć‚Šć¾ć™ć€‚

ćŠć—ć¾ć„ć€‚

ä»Šę—„ć®ć‚³ćƒ¼ćƒ‰

]]>
Sun, 14 Dec 2014 00:00:00 +0900
http://backpaper0.github.io/2014/12/07/tinkerer_hatena_star.html http://backpaper0.github.io/2014/12/07/tinkerer_hatena_star.html <![CDATA[Tinkerer恫ćÆ恦ćŖć‚¹ć‚æćƒ¼ć‚’čØ­ē½®ć—ćŸ]]> Tinkerer恫ćÆ恦ćŖć‚¹ć‚æćƒ¼ć‚’čØ­ē½®ć—ćŸ

Tinkerer 恧ę›øć„ć¦ć‚‹ć“ć®ćƒ–ćƒ­ć‚°ć« ćÆ恦ćŖć‚¹ć‚æćƒ¼ 悒čØ­ē½®ć—ćŸć®ć§ćć®č¾ŗć¾ćØć‚ć¦ćŠćć¾ć™ć€‚ ćŖ恊态ē§ćÆ modern5 ć‚’ćƒ™ćƒ¼ć‚¹ć«ć‚«ć‚¹ć‚æ惞悤ć‚ŗć—ćŸćƒ†ćƒ¼ćƒžć‚’ä½æē”Øć—ć¦ć„ć¾ć™ć®ć§åˆ„ć®ćƒ†ćƒ¼ćƒžć ćØ多少ē•°ćŖ悋恋悂ēŸ„ć‚Œć¾ć›ć‚“ć€‚

ć¾ćšćÆ恦ćŖć‚¹ć‚æćƒ¼ć®ćƒžć‚¤ćƒšćƒ¼ć‚ø恧惖惭悰悒ē™»éŒ²ć—ć¾ć™ć€‚ ćƒžć‚¤ćƒšćƒ¼ć‚ø恮URLćÆ http://s.hatena.ne.jp/<č‡Ŗåˆ†ć®ID> 恧恙怂

ꬔ恫 _templates/page.html 恮extrahead惖惭惃ć‚Æ( {%- block extrahead -%} ćØ {%- endblock -%} ć«å›²ć¾ć‚ŒćŸćØ恓悍)恫ꬔ恮JavaScriptć‚³ćƒ¼ćƒ‰ć‚’ę›øćć¾ć™ć€‚

<script type="text/javascript">
   Hatena.Star.Token = <č‡Ŗåˆ†ć®ćƒˆćƒ¼ć‚Æćƒ³>;
   Hatena.Star.SiteConfig = {
     entryNodes: {
       'div.main-container': {
         uri: 'window.location',
         title: 'document.title',
         container: 'span.hatenastar'
       }
     }
   };
</script>

<č‡Ŗåˆ†ć®ćƒˆćƒ¼ć‚Æćƒ³> 恫ćÆćƒžć‚¤ćƒšćƒ¼ć‚ø恧惖惭悰悒čæ½åŠ ć—ćŸć‚ćØ恫č”Øē¤ŗć•ć‚Œć‚‹ćƒˆćƒ¼ć‚Æćƒ³ć‚’ę›øć„ć¦ćć ć•ć„ć€‚

ęœ€å¾Œć«å®Ÿéš›ć«ćÆ恦ćŖć‚¹ć‚æćƒ¼ć‚’čØ­ē½®ć™ć‚‹å “ꉀćØćŖ悋要ē“ ć‚’čæ½åŠ ć—ć¾ć™ć€‚ ē§ćÆć‚Øćƒ³ćƒˆćƒŖć®ć„ć£ć”ć‚ƒć‚“äø‹ć«ē½®ććŸć‹ć£ćŸć®ć§body惖惭惃ć‚Æć®ęœ€å¾Œć®ę–¹ć«ę¬”ć®span要ē“ ć‚’ę›øćć¾ć—ćŸć€‚

<span class="hatenastar"> </span>

č‡Ŗåˆ†ć®Tinkererć”ć‹ć‚‰ćŒä½Žć™ćŽć¦ę‚©ć‚“ć ć‚Šć‚‚ć—ćŸć‘ć‚Œć©ć€å‡ŗę„ć¦ć—ć¾ćˆć°ē°”å˜ć§ć—ćŸļ¼

ć‚ˆć‚Šč©³ć—ććÆ http://d.hatena.ne.jp/hatenastar/20070707 ć‚’å‚ē…§ćć ć•ć„ć§ć™ć˜ć‚ƒć€‚

]]>
Sun, 07 Dec 2014 00:00:00 +0900
http://backpaper0.github.io/2014/12/07/glassfish_asadmin.html http://backpaper0.github.io/2014/12/07/glassfish_asadmin.html <![CDATA[悈恏ä½æ恆asadminć®ć‚³ćƒžćƒ³ćƒ‰ć‚’ē“¹ä»‹ć™ć‚‹]]> 悈恏ä½æ恆asadminć®ć‚³ćƒžćƒ³ćƒ‰ć‚’ē“¹ä»‹ć™ć‚‹

恓悌ćÆ GlassFish Advent Calendar 2014 恮7ę—„ē›®ć§ć™ć€‚

å°ćƒć‚æ恧恙怂 ē§ćŒć‚ˆćä½æ恆asadminć®ć‚³ćƒžćƒ³ćƒ‰ć‚’ć€å¼•ę•°ć‚‚ę›øć„ć¦å®Ÿéš›ć«ä½æć£ć¦ć„ć‚‹ę„Ÿć˜ć‚’å‡ŗ恗恤恤ē“¹ä»‹ć—ć¾ć™ć€‚

asadmin list-commands
恩悓ćŖć‚³ćƒžćƒ³ćƒ‰ć‚ć£ćŸć£ć‘ćŖćƒ¼ć€ć£ć¦ćØćć©ćē¢ŗčŖć—ć¾ć™ć€‚
asadmin list-domain
GlassFishćÆćƒ‰ćƒ”ć‚¤ćƒ³ćØć„ć†å˜ä½ć§ē®”ē†ć—ć¾ć™ćŒć€ć“ć®ć‚³ćƒžćƒ³ćƒ‰ć§ä»Šć‚ć‚‹ćƒ‰ćƒ”ć‚¤ćƒ³ć‚’ē¢ŗčŖć—ć¾ć™ć€‚
asadmin delete-domain domain1
č¦ć‚‰ć‚“ćƒ‰ćƒ”ć‚¤ćƒ³ć‚’ę¶ˆć—ć¾ć™ć€‚ ćƒ‰ćƒ”ć‚¤ćƒ³ćÆ glassfish/domains/ 仄äø‹ć«ä½œęˆć•ć‚Œć¾ć™ćŒć€ć“恓悒åæƒć‚’č¾¼ć‚ć¦ę‰‹å‹•ć§ę¶ˆć—ć¦ć‚‚å¤§äøˆå¤«ć£ć½ć„恧恙怂
asadmin create-domain --portbase=9000 domain1
ćƒ‰ćƒ”ć‚¤ćƒ³ć‚’ä½œć‚Šć¾ć™ć€‚ portbaseć‚’ęŒ‡å®šć™ć‚Œć°HTTPćÆ9080态ē®”ē†ćÆ9048ćØ恄恆é¢Ø恫č‰Æć„ę„Ÿć˜ć«ćƒćƒ¼ćƒˆć‚’čØ­å®šć—ć¦ćć‚Œć¾ć™ć€‚
asadmin start-domain domain1
ćƒ‰ćƒ”ć‚¤ćƒ³ć‚’čµ·å‹•ć—ć¾ć™ć€‚ 後čæ°ć™ć‚‹create-jdbc-connection-poolć‚³ćƒžćƒ³ćƒ‰ćŖ恩äø€éƒØć®ć‚³ćƒžćƒ³ćƒ‰ćÆćƒ‰ćƒ”ć‚¤ćƒ³ćŒčµ·å‹•ć—ć¦ć„ćŖ恄ćØå®Ÿč”Œć§ććŖć‹ć£ćŸć‚Šć—ć¾ć™ć€‚
asadmin stop-domain domain1
čµ·å‹•ć—ć¦ć„ć‚‹ćƒ‰ćƒ”ć‚¤ćƒ³ć‚’åœę­¢ć—ć¾ć™ć€‚
asadmin create-jdbc-connection-pool --datasourceclassname org.h2.jdbcx.JdbcDataSource --restype javax.sql.DataSource --property url=jdbc\\:h2\\:sampleDB:user=sa:password=secret samplePool
JDBCć‚³ćƒć‚Æć‚·ćƒ§ćƒ³ćƒ—ćƒ¼ćƒ«ć‚’ä½œć‚Šć¾ć™ć€‚ property恫URL悒ę›øćå “åˆć€ć‚³ćƒ­ćƒ³ć‚’ć‚Øć‚¹ć‚±ćƒ¼ćƒ—ć—ćŖ恄ćØ恄恑ćŖć„ć®ć§ę°—ć‚’ć¤ć‘ć¾ć—ć‚‡ćƒ¼ć€‚ äø€ē•Ŗęœ€å¾Œć®å¼•ę•°(ć“ć®ä¾‹ć§ć„ć†ćØsamplePool)ćŒć‚³ćƒć‚Æć‚·ćƒ§ćƒ³ćƒ—ćƒ¼ćƒ«ID恧恙怂 ćŖ恊态JDBCćƒ‰ćƒ©ć‚¤ćƒćÆ glassfish/domains/domain1/lib/ext/ (domain1ćÆćƒ‰ćƒ”ć‚¤ćƒ³ć®åå‰ćŖć®ć§é©å®œē½®ćę›ćˆć¦ćć ć•ć„)恫ē½®ćć¾ć™ć€‚
asadmin create-jdbc-resource --connectionpoolid samplePool jdbc/sample
JDBCćƒŖć‚½ćƒ¼ć‚¹ć‚’ä½œć‚Šć¾ć™ć€‚ ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć‹ć‚‰ćÆ恓恓恧čØ­å®šć—ćŸJNDI名(ć“ć®ä¾‹ć§ć„ć†ćØjdbc/sample)ć§å‚ē…§ć—ć¾ć™ć€‚ ć²ćØ恤恮JDBCć‚³ćƒć‚Æć‚·ćƒ§ćƒ³ćƒ—ćƒ¼ćƒ«ć«åÆ¾ć—ć¦č¤‡ę•°ć®JDBCćƒŖć‚½ćƒ¼ć‚¹ć‚’ä½œć‚‹ć“ćØć‚‚ć§ćć¾ć™ć€‚
asadmin create-jvm-options -Xmx1024m
JVMć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć‚’čØ­å®šć—ć¾ć™ć€‚ ć“ć®ä¾‹ć§ćÆęœ€å¤§ćƒ”ćƒ¢ćƒŖ悵悤ć‚ŗ悒čØ­å®šć—ć¦ć„ć¾ć™ć€‚ ć“ć®ć‚³ćƒžćƒ³ćƒ‰ć§čØ­å®šć—ćŸJVMć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ćÆćƒ‰ćƒ”ć‚¤ćƒ³ć‚’å†čµ·å‹•ć—ćŸćØćć«åę˜ ć•ć‚Œć¾ć™ć€‚
asadmin set-log-levels org.seasar.doma=CONFIG
ćƒ­ć‚°ćƒ¬ćƒ™ćƒ«ć‚’čØ­å®šć—ć¾ć™ć€‚
asadmin deploy --contextroot=sample --name=sample sample.war
ćƒ‡ćƒ—ćƒ­ć‚¤ć—ć¾ć™ć€‚
asadmin redeploy --name=sample sample.war
å†ćƒ‡ćƒ—ćƒ­ć‚¤ć—ć¾ć™ć€‚ 惇惗惭悤ćØå†ćƒ‡ćƒ—ćƒ­ć‚¤ć§ć‚³ćƒžćƒ³ćƒ‰ć‚’ä½æć„åˆ†ć‘ćŖćć‚ƒćƒ€ćƒ”ćŖ恮ćÆć”ć‚‡ć£ćØé¢å€’ć§ć™ć€‚
asadmin undeploy sample
ć‚¢ćƒ³ćƒ‡ćƒ—ćƒ­ć‚¤ć—ć¾ć™ć€‚ å¼•ę•°ć«ćÆćƒ‡ćƒ—ćƒ­ć‚¤ę™‚ć«čØ­å®šć—ćŸnameć‚’ęŒ‡å®šć—ć¾ć™ć€‚

ćØć¾ć‚ć€ć‚ˆćä½æ恆恮ćÆ恓悓ćŖꉀ恧恗悇恆恋怂 č‡Ŗåˆ†ćŒę€ć£ć¦ć„ćŸć‚ˆć‚Šå°‘ćŖć‹ć£ćŸć§ć™ć­ć€‚

ē°”å˜ć§ć™ćŒć€ä»„äøŠć«ćŖć‚Šć¾ć™ć€‚ ćŠćć¾ć¤ć•ć¾ć§ć—ćŸć€‚

]]>
Sun, 07 Dec 2014 00:00:00 +0900
http://backpaper0.github.io/2014/12/07/application_class.html http://backpaper0.github.io/2014/12/07/application_class.html <![CDATA[ć©ć†ć‚„ć£ć¦Applicationć‚µćƒ–ć‚Æćƒ©ć‚¹ć®åå‰å–ć£ć¦ćć¦ć‚“ć®ļ¼Ÿ]]> ć©ć†ć‚„ć£ć¦Applicationć‚µćƒ–ć‚Æćƒ©ć‚¹ć®åå‰å–ć£ć¦ćć¦ć‚“ć®ļ¼Ÿ

恓悌ćÆ JavaFX Advent Calendar 2014 恮7ę—„ē›®ć§ć™ć€‚

å°ćƒć‚æ恧恙怂

JavaFXć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć®ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ćÆę¬”ć®ć‚ˆć†ć«ę›øćć¾ć™ć‚ˆć­ć€‚

import javafx.application.Application;
import javafx.stage.Stage;

public class Hoge extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        //ē•„
    }
}

ć“ć‚Œć‚’åˆć‚ć¦č¦‹ćŸćØ恍态launchćƒ”ć‚½ćƒƒćƒ‰ć«Applicationć‚µćƒ–ć‚Æćƒ©ć‚¹ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚„ Class悒ęø”ć—ć¦ć‚‹ć‚ć‘ć§ć‚‚ćŖć„ć®ć«ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć•ć‚Œć¦startćƒ”ć‚½ćƒƒćƒ‰ćŒå‘¼ć°ć‚Œć‚‹ć®ćŒ ć‚­ćƒ¢ć„ćŖćƒ¼ć€ćØę€ć£ćŸć®ć§ć—ćŸć€‚

恧态恠恄恟恄äŗˆęƒ³ćÆć¤ćć¾ć—ćŸćŒć€Application.java悒čŖ­ć‚“恧ćæć¾ć—ćŸć€‚ ćć®éƒØåˆ†ć‚’å¼•ē”Øć—ć¾ć™ć€‚

// Figure out the right class to call
StackTraceElement[] cause = Thread.currentThread().getStackTrace();

boolean foundThisMethod = false;
String callingClassName = null;
for (StackTraceElement se : cause) {
    // Skip entries until we get to the entry for this class
    String className = se.getClassName();
    String methodName = se.getMethodName();
    if (foundThisMethod) {
        callingClassName = className;
        break;
    } else if (Application.class.getName().equals(className)
            && "launch".equals(methodName)) {

        foundThisMethod = true;
    }
}

ćØć„ć†ę„Ÿć˜ć§ć€ć‚¹ć‚æ惃ć‚Æćƒˆćƒ¬ćƒ¼ć‚¹ć‚’å–å¾—ć—ć¦ē¾åœØć®ćƒ”ć‚½ćƒƒćƒ‰(launch)ć®ć²ćØć¤å‰ć® ćƒ”ć‚½ćƒƒćƒ‰å(main)ćØć‚Æćƒ©ć‚¹å(Hoge)ć‚’å–å¾—ć—ć¦ć„ć¾ć—ćŸć€‚

äŗˆęƒ³é€šć‚Šå‰²ćØć‚­ćƒ¢ć„ę–¹ę³•ć§ć‚Æćƒ©ć‚¹åć‚’å–ć£ć¦ćć¦ć„ćŸć“ćØćŒåˆ†ć‹ć£ć¦ęŗ€č¶³ć§ć™ć€‚

JavaFX恧恂悋åæ…č¦ę€§ć®č–„ć„å†…å®¹ć§ć—ćŸćŒć€ä»„äøŠć«ćŖć‚Šć¾ć™ć€‚ ćŠćć¾ć¤ć•ć¾ć§ć—ćŸć€‚

]]>
Sun, 07 Dec 2014 00:00:00 +0900
http://backpaper0.github.io/2014/12/04/validation.html http://backpaper0.github.io/2014/12/04/validation.html <![CDATA[BeanValidation恮ē›øé–¢ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ćØćć‚‚ćć‚‚ć®č©±]]> BeanValidation恮ē›øé–¢ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ćØćć‚‚ćć‚‚ć®č©±

BeanValidation恧ē›øé–¢ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ć™ć‚‹ćØćć«ę–°ć—ć„ćƒ”ć‚½ćƒƒćƒ‰ä½œć£ć¦@AssertTrue悒ä½æ恆悈ļ¼ ć£ć¦ć„ć†č©±ćŒć‚ć£ćŸć®ć§ć€ćć‚Œć«ć¤ć„ć¦ę€ć†äŗ‹ć‚’ę›øćć¾ć™ć€‚

ćŖ恊态仄äø‹ćÆWebć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć§ćƒŖć‚Æć‚Øć‚¹ćƒˆćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ悒POJOć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć—ć¦ BeanValidationć‚’č”Œć†ćØć„ć†ęµć‚Œć‚’ęƒ³å®šć—ć¦ć„ć¾ć™ć€‚

@AssertTrue恧惐ćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³

件恮ē›øé–¢ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ćÆćŸć¶ć‚“ć“ć‚“ćŖꄟ恘恧恙怂

public int from;

public int to;

@AssertTrue
public boolean isFromLessThanTo() {
    return from < to;
}

ē§ćÆ态恓悌ćÆ

  • ćƒ”ć‚½ćƒƒćƒ‰å†…ć«ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ćƒ­ć‚ø惃ć‚Æ悒ę›øćć®ć§å†åˆ©ē”Øę€§ćŒä½Žć„
  • @AssertTrueć€ćć—ć¦booleanćÆ宣č؀ēš„恧ćÆćŖ恄

ćØę€ć£ć¦ć„ć¾ć™ć€‚

ć˜ć‚ƒć‚ć€ć©ć†ć™ć‚Œć°ć„ć„ć®ć‹

from < to 悒ꤜčØ¼ć™ć‚‹ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćØć‚«ć‚¹ć‚æ惠惐ćƒŖćƒ‡ćƒ¼ć‚æć‚’ä½œć‚Šć¾ć—ć‚‡ć†ć€‚ ćć—ć¦ćć‚Œć‚’ä»˜ć‘ć‚‹ćƒ”ć‚½ćƒƒćƒ‰ćÆboolean恧ćÆćŖ恏ć‚æćƒ—ćƒ«(ć®ć‚ˆć†ćŖä½•ć‹)悒čæ”ć—ć¾ć™ć€‚

public int from;

public int to;

@FromLessThanTo
public Pair isFromLessThanTo() {
    return new Pair(from, to);
}

恓恆恙悋äŗ‹ć§ć€

  • 惐ćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ć®ćƒ­ć‚ø惃ć‚ÆćÆć‚«ć‚¹ć‚æ惠惐ćƒŖćƒ‡ćƒ¼ć‚æć«é–‰ć˜č¾¼ć‚ćŸć®ć§å†åˆ©ē”Øę€§é«˜ć¾ć‚‹
  • ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć§å¤§å°é–¢äæ‚ćŒć‚ć‚‹ć£ć¦åˆ†ć‹ć£ć¦å®£č؀ēš„ć£ć½ć„

ćØćŖ悋恋ćØ怂

恝悂恝悂

ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ä½æć£ćŸćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ć£ć¦ć©ć†ćŖ悓恧恗悇恆恭ļ¼Ÿ

ä¾‹ćˆć°ć€ę¬”ć®ć‚ˆć†ćŖć‚³ćƒ¼ćƒ‰ćŒć‚ć£ćŸćØć—ć¾ć™ć€‚

@Isbn
public String isbn1;

@Isbn
public String isbn2;

ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’č¦‹ć‚Œć°isbn1悂isbn2悂ISBN恧恂悋ćØ恄恆恓ćØćÆåˆ†ć‹ć‚‹ć®ć§ć™ćŒć€ ć§ć‚‚ćć‚Œć£ć¦ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć®å½¹å‰²ć˜ć‚ƒćŖćć¦åž‹ć˜ć‚ƒćŖ恄恮ļ¼ŸćØę€ć†ć®ć§ć™ć€‚

ęœ¬ę„ć‚ć‚‹ć¹ćå§æćÆ恓悓ćŖꄟ恘怂

public Isbn isbn1;

public Isbn isbn2;

ć“ć®å “åˆćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ćÆIsbn型ćøå¤‰ę›ć™ć‚‹ćØćć«č”Œć†ć®ćŒč‰Æ恄ćØę€ć‚ć‚Œć¾ć™ć€‚

åž‹ć‚ˆ

åŸŗęœ¬ēš„ć«ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ćÆꬔ恮順ē•Ŗć§č”Œć‚ć‚Œć‚‹ćØę€ć„ć¾ć™ć€‚

  • åæ…é ˆćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³
  • ćƒ•ć‚©ćƒ¼ćƒžćƒƒćƒˆćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³(ę—„ä»˜ćØć•ć‚Œć‚‹å€¤ćŒyyyy/MM/dd恫ćŖć£ć¦ć„ć‚‹ć‹ļ¼Ÿćæ恟恄ćŖ恓ćØ恧恙)
  • ē›øé–¢ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³

åæ…é ˆćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ć‚’č”Œć†ć‹å¦ć‹ć‚‚åž‹ć§č”Ø恗恟恄怂 Optional恧ćŖ恄悂恮ćÆåæ…é ˆļ¼ćØ恄恆ꄟ恘恧恙怂 ćŸć¶ć‚“ćć‚ŒćŒč‰Æ恄ćØꀝ恆怂

//åæ…é ˆ
public Isbn isbn1;

//åæ…é ˆć§ćŖ恄
public Optional<Isbn> isbn2;

ćƒ•ć‚©ćƒ¼ćƒžćƒƒćƒˆć‚‚å…ˆčæ°ć®é€šć‚Šåž‹ć§č”Ø恙äŗ‹ćŒć§ćć¾ć™ć€‚

恝悌恋悉ē›øé–¢ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ć§ć™ćŒć€ęœ€åˆć®ä¾‹ć§ć‚ć‚Œć°RangećØć„ć£ćŸåž‹ć‚’ä½œć£ć¦ćć“ć«fromćØto悒 č©°ć‚č¾¼ć‚ć°fromćØtoć®å¤§å°é–¢äæ‚ć‚’åž‹ć§č”Ø恙äŗ‹ćŒć§ćć¾ć™ć€‚

new Range(from, to);

ć¾ćØ悁

ć¾ćØć¾ć‚Šć¾ć›ć‚“ļ¼ ć‚‚ć£ćØē†ęƒ³ēš„ćŖ惐ćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ćƒ•ćƒ¬ćƒ¼ćƒ ćƒÆćƒ¼ć‚ÆćŒę¬²ć—ć„ļ¼

ćØ恄恆悏恑恧惐ćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ćø恮ꂩćæćÆå°½ćć¾ć›ć‚“ć€‚ ę‚©ć¾ć—ć„ć€‚

]]>
Thu, 04 Dec 2014 00:00:00 +0900
http://backpaper0.github.io/2014/12/01/javaee_advent_calendar_2014.html http://backpaper0.github.io/2014/12/01/javaee_advent_calendar_2014.html <![CDATA[JAX-RSć‚’å§‹ć‚ć‚‹ #javaee]]> JAX-RSć‚’å§‹ć‚ć‚‹ #javaee

恓悌ćÆ Java EE Advent Calendar 2014 恮1ę—„ē›®ć§ć™ć€‚

今回ćÆ参ē…§å®Ÿč£…恧恂悋 Jersey 悒ä½æć£ć¦JAX-RSć‚’å§‹ć‚ć‚‹ćŸć‚ć®ē’°å¢ƒę§‹ēƉćŖ恩悒恠悉恠悉ę›ø恓恆ćØę€ć„ć¾ć™ć€‚

ćƒ“ćƒ«ćƒ‰ćƒ„ćƒ¼ćƒ«

ę˜Ø今ćÆGradle恌äŗŗę°—ć®ć‚ˆć†ćŖé›°å›²ę°—ę¼‚ć£ć¦ć„ć¾ć™ćŒć€ Maven 悒ä½æć„ć¾ć—ć‚‡ć†ć€‚

JerseyćÆMaven恮profilećØć„ć†ę©Ÿčƒ½ć‚’ä½æć£ć¦ć„ć¦Gradle恧ćÆćć®č¾ŗć®ć‚µćƒćƒ¼ćƒˆćŒćŖć„ć£ć½ć„ć®ć§ćŸć¶ć‚“ć—ć‚“ć©ć„ć§ć™ć€‚

ā€¦ā€¦ćØę›øćć¾ć—ćŸćŒęœ€čæ‘恮GradlećÆprofileåƾåæœć—ć¦ć‚‹ć‚ˆć†ć§ć™ć€‚

ćØć„ć†ć‚ć‘ć§ć‚µćƒ³ćƒ—ćƒ«ć«Gradleć®ćƒ“ćƒ«ćƒ‰ćƒ•ć‚”ć‚¤ćƒ«ć‚‚čæ½åŠ ć—ć¾ć—ćŸć€‚

Mavenć®ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«ćÆ惐悤惊ćƒŖć‚’ä»»ę„ć®å “ę‰€ć«ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ć—ć¦ bin ćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖć«ćƒ‘ć‚¹ć‚’é€šć›ć°ćŠk恧恙怂

ćƒ“ćƒ«ćƒ‰ćƒ•ć‚”ć‚¤ćƒ«ć®ęŗ–å‚™

Mavenć®å “åˆ

ć¾ćšć€ mvn archetype:generate ć—ć¦ćć ć•ć„ć€‚ 恝悌恋悉å‡ŗę„ćŸpom.xml悒ē·Øé›†ć—ć¾ć™ć€‚

ꬔ恮dependencyManagement要ē“ ć‚’čæ½åŠ ć—ć¦ćć ć•ć„ć€‚

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.glassfish.jersey</groupId>
      <artifactId>jersey-bom</artifactId>
      <version>2.13</version>
      <scope>import</scope>
      <type>pom</type>
    </dependency>
  </dependencies>
</dependencyManagement>

恝悌恋悉jersey-bom恮pom.xml悒見ćŖćŒć‚‰å„½ććŖ悂恮悒éø悓恧dependency要ē“ ć«čæ½åŠ ć—ć¾ć™ć€‚ ćØćÆ恄恈JerseyćÆć‚µćƒ¼ćƒå“ć®API态ć‚Æćƒ©ć‚¤ć‚¢ćƒ³ćƒˆå“ć®API态MVCę‹”å¼µćŖć©å¤šę•°ć®JARć«åˆ„ć‚Œć¦ęä¾›ć•ć‚Œć¦ć„ć‚‹ć®ć§ ä½•ć‚’čæ½åŠ ć™ć‚Œć°č‰Æć„ć®ć‹ęœ€åˆćÆåˆ†ć‹ć‚‰ćŖ恄ćØę€ć„ć¾ć™ć€‚

今回ćÆć‚µćƒ¼ćƒå“ć®ć‚³ćƒ¼ćƒ‰ć‚’ę›øććŸć„ć®ć§ć€ jersey-server 悒čæ½åŠ ć—ć¾ć™ć€‚ ć¾ćŸć€JerseyćÆ Grizzly 悄 Jetty ćŖć©ć®ć‚³ćƒ³ćƒ†ćƒŠäøŠć§å‹•ćć¾ć™ćŒć€ä»Šå›žćÆ JDKä»˜å±žć®HttpServer ć§å‹•ć‹ć—ćŸć„ć®ć§ jersey-container-jdk-http 悒čæ½åŠ ć—ć¾ć™ć€‚ 恩悓ćŖć‚³ćƒ³ćƒ†ćƒŠćŒä½æ恈悋恋ćÆ http://repo1.maven.org/maven2/org/glassfish/jersey/containers/ ć‚’å‚ē…§ćć ć•ć„怂 ęœ€å¾Œć«JUnit恧悵ć‚Æ惃ćØčµ°ć‚‰ć›ć¦ćƒ†ć‚¹ćƒˆć™ć‚‹ćŸć‚ jersey-test-framework-provider-jdk-http 悒čæ½åŠ ć—ć¾ć™ć€‚

<dependencies>
  <dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-server</artifactId>
  </dependency>
  <dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-jdk-http</artifactId>
  </dependency>
  <dependency>
    <groupId>org.glassfish.jersey.test-framework.providers</groupId>
    <artifactId>jersey-test-framework-provider-jdk-http</artifactId>
    <scope>test</scope>
  </dependency>
</dependencies>

ćØć¾ć‚ć€ć“ć‚“ćŖꄟ恘恧č‰Æ恄恧恗悇恆怂

恧悂恓悓ćŖ恓ćØćƒćƒ³ć‚æćƒ©ć‚„ć£ć¦ć‚‰ć‚ŒćŖ恄ćØę€ć†ć®ć§ https://github.com/backpaper0/sandbox 悒clone恗恦 jersey-blank ćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖå†…ć® pom.xml ć‚’ć”åˆ©ē”Ø恏恠恕恄怂 ē§ć‚‚å¤§ęŠµć€č‡Ŗåˆ†ćŒéŽåŽ»ć«ę›øć„ćŸćƒ“ćƒ«ćƒ‰ćƒ•ć‚”ć‚¤ćƒ«ć‚’ć‚³ćƒ”ć‚Šć¾ć™ć€‚

Gradleć®å “åˆ

恓悓ćŖꄟ恘ļ¼Ÿ

dependencies {
    compile 'org.glassfish.jersey.core:jersey-server:2.13'
    compile 'org.glassfish.jersey.containers:jersey-container-jdk-http:2.13'
    testCompile 'org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-jdk-http:2.13'
}

ć‚³ćƒ¼ćƒ‰ć‚’ę›ø恏

ć¾ć‚ć€ć“ć®č¾ŗćÆé©å½“ć«ć€č¶³ć—ē®—恙悋ē°”単ćŖ悄恤恧怂

src/main/java/app/Calc.java ć‚’ä½œć‚Šć¾ć™ć€‚

package app;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

@Path("calc")
public class Calc {

    @Path("add")
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public int add(@QueryParam("a") int a, @QueryParam("b") int b) {
        return a + b;
    }
}

恧态JUnitćƒ†ć‚¹ćƒˆć§ć™ć€‚ src/test/java/app/CalcTest.java ć‚’ä½œć‚Šć¾ć™ć€‚

package app;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import javax.ws.rs.core.Application;

import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;

public class CalcTest extends JerseyTest {

    @Test
    public void test() throws Exception {
        int c = target("calc/add").queryParam("a", 2)
                                  .queryParam("b", 3)
                                  .request()
                                  .get(int.class);
        assertThat(c, is(5));
    }

    @Override
    protected Application configure() {
        return new ResourceConfig(Calc.class);
    }
}

test-framework悒ä½æ恆ćØćØ恦悂ē°”å˜ć«JUnitćƒ†ć‚¹ćƒˆć‚’ę›ø恑悋äŗ‹ćŒåˆ†ć‹ć‚‹ćØę€ć„ć¾ć™ć€‚

ćƒ†ć‚¹ćƒˆčµ°ć‚‰ć›ć‚‹

IDEć‹ć‚‰å®Ÿč”Œć™ć‚‹ć‹Maven恧怂

mvn test

ē°”å˜ć§ć™ć­ļ¼

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running app.CalcTest
11 30, 2014 10:55:12 午後 org.glassfish.jersey.test.jdkhttp.JdkHttpServerTestContainerFactory$JdkHttpServerTestContainer <init>
ęƒ…å ±: Creating JdkHttpServerTestContainer configured at the base URI http://localhost:9998/
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.109 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

mainćƒ”ć‚½ćƒƒćƒ‰ć§ć‚µćƒ¼ćƒćƒ¼ć‚’ē«‹ć¦ć‚‹

JUnitćƒ†ć‚¹ćƒˆć‚’čµ°ć‚‰ć›ć¦ć„ć‚‹äŗ‹ć‹ć‚‰ć‚‚ćŠåˆ†ć‹ć‚Šé ‚ć‘ć‚‹ćØę€ć„ć¾ć™ćŒć€ ē°”å˜ć«ć‚µćƒ¼ćƒćƒ¼ć‚’ē«‹ć¦ć‚‹äŗ‹ć‚‚ć§ćć¾ć™ć€‚

恓悓ćŖꄟ恘怂

package app;

import java.io.IOException;
import java.net.URI;

import org.glassfish.jersey.jdkhttp.JdkHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;

import com.sun.net.httpserver.HttpServer;

public class Server {

    public static void main(String[] args) throws IOException {
        URI uri = URI.create("http://localhost:8080/rest/");

        ResourceConfig rc = new ResourceConfig();
        rc.register(Calc.class);

        HttpServer httpServer = JdkHttpServerFactory.createHttpServer(uri, rc);
        Runtime.getRuntime().addShutdownHook(new Thread(() -> httpServer.stop(0)));

        System.out.println("JAX-RS started");
    }
}

ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć‚µćƒ¼ćƒć«ćƒ‡ćƒ—ćƒ­ć‚¤ć™ć‚‹

GlassFishć«ćƒ‡ćƒ—ćƒ­ć‚¤ć™ć‚‹å “åˆćÆdependency恮scope悒provided恫恗恦WARćƒ•ć‚”ć‚¤ćƒ«ć‚’ä½œć£ć¦ćć‚Œć‚’ćƒ‡ćƒ—ćƒ­ć‚¤ć™ć‚Œć°č‰Æ恄ćØę€ć„ć¾ć™ć€‚

Tomcatć«ćƒ‡ćƒ—ćƒ­ć‚¤ć™ć‚‹å “åˆćÆ jersey-container-jdk-http ć‚’ę¶ˆć—ć¦ć€ jersey-container-servlet 悒čæ½åŠ ć—恦WARćƒ•ć‚”ć‚¤ćƒ«ć‚’ä½œć‚Šć¾ć—ć‚‡ć†ć€‚ 恓悓ćŖꄟ恘恧恙怂

<dependencies>
  <dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-server</artifactId>
  </dependency>
  <dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet</artifactId>
    <scope>runtime</scope>
  </dependency>
</dependencies>

ē§ćÆServlet APIć«ä¾å­˜ć—ćŖć„ć‚ˆć†ä½œć‚‹ę–¹ćŒćƒćƒ¼ć‚æ惓ćƒŖćƒ†ć‚£ćŒé«˜ćć†ć§å„½ććŖ恮恧scope悒runtimeć«ć—ć¦ć„ć¾ć™ć€‚ Servlet API恘悃悓恘悃悓ä½æć„ćŸć„å “åˆćÆscope悒compileć«ć—ć¦ćć ć•ć„ć€‚

ć¾ćØ悁

ćØ恄恆悏恑恧Jersey悒ä½æē”Ø恗恟JAX-RSć®å°Žå…„éƒØåˆ†ć€å¦‚ä½•ć§ć—ćŸć§ć—ć‚‡ć†ć‹ļ¼Ÿ ē°”å˜ć§ć™ć‚ˆć­ļ¼Ÿ ē‰¹ć«Java EE恮äø€éƒØćŖć®ć«ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć‚µćƒ¼ćƒćŒćŖćć¦ć‚‚ē°”å˜ć«ä½æćˆć‚‹ć®ćŒč‰Æ恄恧恙悈恭ļ¼ć­ļ¼

ęœ€å¾Œć«ć€ę‰‹å‰å‘³å™Œć§ć™ćŒJAX-RSć®å‚č€ƒč³‡ę–™ć‚’ęŒ™ć’ć¦ćŠćć¾ć™ć€‚

ćÆćƒ¼ć€ć“ć‚Œć‚‰ć®č³‡ę–™ć‚‚JAX-RS 2.0ć«ć‚¢ćƒƒćƒ—ćƒ‡ćƒ¼ćƒˆć—ćŖ恄ćØ恄恑ćŖ恄ćŖćƒ¼ļ¼ˆć—ć‚ć‚

ē°”å˜ć§ć™ćŒć€ä»„äøŠć€‚

]]>
Mon, 01 Dec 2014 00:00:00 +0900
http://backpaper0.github.io/2014/12/01/syobochim_advent_calendar_2014.html http://backpaper0.github.io/2014/12/01/syobochim_advent_calendar_2014.html <![CDATA[Tinkererć®ć—ć‚‡ć¼ć”ć‚€ćƒ†ćƒ¼ćƒžä½œć£ćŸ #syobochim]]> Tinkererć®ć—ć‚‡ć¼ć”ć‚€ćƒ†ćƒ¼ćƒžä½œć£ćŸ #syobochim

恓悌ćÆ ć—ć‚‡ć¼ć”ć‚€ Advent Calendar 2014 恮1ę—„ē›®ć§ć™ć€‚

ć—ć‚‡ć¼ć”ć‚€ ćØćÆ态

恝悓ćŖ苄ꉋć‚Øćƒ³ć‚øćƒ‹ć‚¢ć§ć™ć€‚

ć“ć®ć‚¢ćƒ‰ćƒ™ćƒ³ćƒˆć‚«ćƒ¬ćƒ³ćƒ€ćƒ¼ć§ćÆćæ悓ćŖ恧ęÆŽę—„ć—ć‚‡ć¼ć”ć‚€ć«é–¢ć™ć‚‹ä½•ć‹ć‚’ę›ø恓恆ćØ恄恆悂恮恧态 ä½œć£ćŸå½“åˆćÆå…Øę—„ēØ‹åŸ‹ć¾ć‚‹ć‹ęœ¬äŗŗ悂åæƒé…ć—ć¦ć„ć¾ć—ćŸćŒå‰²ćØę—©ć€…ć«åŸ‹ć¾ć£ćŸć®ć§č‰Æć‹ć£ćŸć­ć€ć£ć¦ć„ć†ć€‚

Java EE ć‚¢ćƒ‰ćƒ™ćƒ³ćƒˆć‚«ćƒ¬ćƒ³ćƒ€ćƒ¼ć‚ˆć‚Šć‚‚ę—©ćåŸ‹ć¾ć£ćŸć®ćÆå°‘ć€…č¤‡é›‘ć§ć‚ć‚Šć¾ć™ćŒļ¼ ć„ć‚„ć€ć§ć‚‚ć€åŸ‹ć¾ć£ć¦č‰Æć‹ć£ćŸć­ļ¼

ęœ¬é”Œ

ć•ć¦ć€ä»Šå›žćÆć“ć®ćƒ–ćƒ­ć‚°ć®åŸŗē›¤ćØćŖć£ć¦ć„ć‚‹ćƒ–ćƒ­ć‚°ćƒ„ćƒ¼ćƒ«ć€ Tinkerer ć®ć‚«ć‚¹ć‚æćƒ ćƒ†ćƒ¼ćƒžć‚’ä½œć£ć¦ćæć¾ć—ćŸć€‚ ćØčØ€ć£ć¦ć‚‚ć‚¼ćƒ­ć‹ć‚‰ä½œć‚‹ć‚ˆć†ćŖć‚»ćƒ³ć‚¹ćÆēš†ē„”ćŖ恮恧态ēµ„č¾¼ćæ恮 modern5 ćØć„ć†ćƒ†ćƒ¼ćƒžć‚’ć‚³ćƒ”ćƒ¼ć—ć¦ ć‚¦ćƒ«ćƒˆćƒ©ę€Ŗē£ćØć—ć‚‡ć¼ć”ć‚€ć‚«ćƒ©ćƒ¼ć‚’ę··ćœč¾¼ć‚“ć§ćæć¾ć—ćŸć€‚

ä»Šå¾Œć€ć‚‚ćØć®ćƒ†ćƒ¼ćƒžć«ęˆ»ć—ćŸå “åˆć‚’č€ƒę…®ć—ć¦ć‚¹ć‚ÆćƒŖćƒ¼ćƒ³ć‚·ćƒ§ćƒƒćƒˆč²¼ć£ć¦ćŠćć¾ć™ć€‚

../../../_images/syobochim-theme.png

ćƒ˜ćƒƒćƒ€ć€ęœ¬ę–‡ć€ć‚µć‚¤ćƒ‰ćƒćƒ¼ćŖć©ć®ę§‹ęˆć‚„åŸŗęœ¬ēš„ćŖć‚«ćƒ©ćƒ¼ćƒŖćƒ³ć‚°ćÆ modern5 ć®ć¾ć¾ć§ć™ćŒć€ ćƒ˜ćƒƒćƒ€ć®čƒŒę™Æč‰²ćØćƒŖćƒ³ć‚Æć®č‰²ć‚’å¤‰ćˆć¦ć—ć‚‡ć¼ć”ć‚€ć‚«ćƒ©ćƒ¼ć«ć—ć€ćƒ˜ćƒƒćƒ€ć®čƒŒę™Æē”»åƒćØć‚»ć‚Æć‚·ćƒ§ćƒ³ć®č¦‹å‡ŗ恗恫 ć‚¦ćƒ«ćƒˆćƒ©ę€Ŗē£ć®ēµµć‚’ćÆć‚č¾¼ćæć¾ć—ćŸć€‚ ä½™č«‡ć§ć™ćŒć€ē§ćÆ惐惫ć‚æćƒ³ę˜ŸäŗŗćŒå„½ćć§ć™(V)o\o(V)ćƒ•ć‚©ćƒ•ć‚©ćƒ•ć‚©ć€‚

恂ćØ态惖惭悰ć‚æć‚¤ćƒˆćƒ«ć‚’ć—ć‚‡ć¼ć”ć‚€ć®ćƒ–ćƒ­ć‚°ć£ć½ćć™ć‚‹ćŸć‚beforeē–‘ä¼¼č¦ē“ ć€afterē–‘ä¼¼č¦ē“ ć§ę–‡ē« ć‚’č¶³ć—ć¦ć„ć¾ć™ć€‚ åæµć®ćŸć‚ę›øć„ć¦ćŠćć¾ć™ćŒć€ć“ć®ćƒ–ćƒ­ć‚°ć®ć‚æć‚¤ćƒˆćƒ«ćÆć€Œč£ē“™ć€ć§ć™ć€‚

ā€¦ā€¦ćØć„ć£ćŸę‰€ć§ć€ę®‹åæµćŖćŒć‚‰ć ć„ć¶åŠ›å°½ćć¾ć—ćŸć€‚ å·±ć®HTML恔恋悉äøč¶³ć€CSS恔恋悉äøč¶³ć€Tinkerer恔恋悉äøč¶³ćŖć©ć«å‡¹ćæć¾ć—ćŸć€‚

ć¾ć‚ć‚„ć‚ŠéŽćŽć‚‹ć‚ˆć‚ŠćÆč‰Æć„ć‹ćƒ¼ć€ćØčØ€ć†ę„Ÿć˜ć§ć©ć†ć‹ć²ćØ恤ļ¼ 恓恮ćØ恊悊恠ļ¼

ć¾ćØ悁

ć“ć“ć¾ć§ā€ć—ć‚‡ć¼ć”ć‚€ć‚«ćƒ©ćƒ¼ā€ć®čŖ¬ę˜ŽćŖ恗ļ¼

ćŠć¾ć‘

ć‚»ć‚Æć‚·ćƒ§ćƒ³ć®č¦‹å‡ŗć—ć®å‰ć«å‡ŗć—ć¦ć‚‹ćƒ¬ćƒƒćƒ‰ć‚­ćƒ³ć‚°ćŒć”ć‚‡ć£ćØć‹ć‚ć„ćęć‘ćŸę°—ćŒć™ć‚‹ć®ć§ ć‚‚ć†ć”ć‚‡ć„å¤§ćć„ć‚µć‚¤ć‚ŗ悂ē½®ć„ć¦ćŠćć¾ć™ć€‚

../../../_images/redking.png
]]>
Mon, 01 Dec 2014 00:00:00 +0900
http://backpaper0.github.io/2014/12/01/irof_advent_calendar_2014.html http://backpaper0.github.io/2014/12/01/irof_advent_calendar_2014.html <![CDATA[ć‚¹ć‚æ惃ć‚Æćƒˆćƒ¬ćƒ¼ć‚¹ć‚ćµ #irof]]> ć‚¹ć‚æ惃ć‚Æćƒˆćƒ¬ćƒ¼ć‚¹ć‚ćµ #irof

恓悌ćÆ ć„ć‚ćµ Advent Calendar 2014 恮1ę—„ē›®ć§ć™ć€‚

ć„ć‚ćµć‚¢ćƒ‰ćƒ™ćƒ³ćƒˆć‚«ćƒ¬ćƒ³ćƒ€ćƒ¼ćØćÆ态ꈑ悉恌 ć„ć‚ćµć•ć‚“ ćø恮ꄛ悒ćƒÆćƒ¼ćƒ«ćƒ‰ćƒÆ悤惉ćŖć‚¤ćƒ³ć‚æćƒ¼ćƒćƒƒćƒ„ć«å¤§å…¬é–‹ć™ć‚‹ę„Ÿć˜ć®ć‚„ć¤ć§ć™ć€‚

ć„ć‚ćµć•ć‚“ć‚’ć”å­˜ć˜ćŖć„ę–¹ćÆTwitter恧ļ¾‹ļ½®ļ¾›ļ½°ć‚’ć‚­ćƒ”恦态著ę›ø恧恂悋養ꈐčŖ­ęœ¬ć‚’ē†ŸčŖ­ć™ć‚‹ćØč‰Æ恄恧恙悈ļ¼

ęœ¬ē·ØćØć„ć†åć®å‡ŗć‚Ŗ惁

恓恔悉恮ćƒŖ惝ć‚ø惈ćƒŖ悒clone恗恦态

irofćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ恫ē§»å‹•ć— gradlew run ć—ć¦ćć ć•ć„ć€‚

恙悋ćØ恓恆ćŖć‚Šć¾ć™ć€‚

../../../_images/stacktracerof.png

ćŖ悓ćØć„ć‚ćµć•ć‚“ćŒä¾‹å¤–åć„ć¦ēµ‚äŗ†ć—ć¾ć—ćŸļ¼ (-āˆ§-ļ¼›)怀ļ¾…ļ¾‘ļ½°

ęŠ•ć’ć£ć±ćŖć—ć®č§£čŖ¬

Javač؀čŖžć§ćÆćƒ”ć‚½ćƒƒćƒ‰åć«ē©ŗē™½ć‚„čØ˜å·ć‚’ä½æćˆć¾ć›ć‚“ćŒć‚Æćƒ©ć‚¹ćƒ•ć‚”ć‚¤ćƒ«ćØJVMēš„恫ćÆć‚‚ć†ć”ć‚‡ć„åˆ¶ē“„ē·©ć„ć£ć½ć„ć®ć§ ćć®č¾ŗć‚’åˆ©ē”Øć—ć¦ć‚¹ć‚æ惃ć‚Æćƒˆćƒ¬ćƒ¼ć‚¹ć§ć„ć‚ćµć•ć‚“ć‚’ęćć¾ć—ćŸć€‚

ć„ć‚ćµć•ć‚“ć®ć‚¢ć‚¤ć‚³ćƒ³ć‹ć‚‰AAć‚’ä½œć£ćŸć®ćÆę¬”ć®ć‚µćƒ¼ćƒ“ć‚¹ć§ć™ć€‚

恧态ć‚Æćƒ©ć‚¹ćƒ•ć‚”ć‚¤ćƒ«ć‚’ę›ø恍å‡ŗć—ćŸć®ćÆASMćØć„ć†ćƒ©ć‚¤ćƒ–ćƒ©ćƒŖ恧恙怂

ASM恮 ClassWriter ćØ GeneratorAdapter 悒ä½æćˆć°å‰²ćØē°”å˜ć«ć‚Æćƒ©ć‚¹ćƒ•ć‚”ć‚¤ćƒ«ć‚’ę›ø恍å‡ŗ恙äŗ‹ćŒć§ćć¾ć™ć€‚ č©³ć—ććÆGeneratorAdapter恮JavadocćØä»Šå›žć®ć„ć‚ćµć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ć‚’å‚ē…§ćć ć•ć„怂

恝悌ćØ今回ćÆä½æć£ć¦ć„ć¾ć›ć‚“ćŒ ClassReader 悒ä½æ恆ćØć‚Æćƒ©ć‚¹ćƒ•ć‚”ć‚¤ćƒ«ć‚’čŖ­ć‚€äŗ‹ćŒć§ćć¾ć™ć€‚

ä¾‹ćˆć°ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œć—ć¦ć‚‹ć‚³ćƒ¼ćƒ‰ć‚’č¦‹ć¤ć‘ć¦ęؙęŗ–å‡ŗåŠ›ć«ę›ø恍å‡ŗ恙悈恆ćŖć‚¢ćƒ¬ćÆę¬”ć®ć‚ˆć†ć«ę›øć‘ć¾ć™ć€‚

ClassReader reader = new ClassReader("irof.Irof");

MethodVisitor methodVisitor = new MethodVisitor(Opcodes.ASM5) {

    @Override
    public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
        if (opcode == Opcodes.INVOKEVIRTUAL) {
            System.out.printf("owner=%1$s name=%2$s desc=%3$s%n", owner, name, desc);
        }
    }
};

ClassVisitor classVisitor = new ClassVisitor(Opcodes.ASM5) {

    @Override
    public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
        return methodVisitor;
    }
};

reader.accept(classVisitor, 0);

恔ćŖćæ恫ASMćÆJDKć«ć‚‚å…„ć£ć¦ć„ć¾ć™ć€‚ rt.jar 恮 com.sun.xml.internal.ws.org.objectweb.asm 仄äø‹ćŒćć†ć§ć™ć­ć€‚ JAX-WS恫ä½æć‚ć‚Œć¦ć„ć‚‹ć‚ˆć†ć§ć™ć€‚

恂ćØ jersey-server 恫悂ä½æć‚ć‚Œć¦ć„ć¾ć™ć€‚ jersey.repackaged.org.objectweb.asm 仄äø‹ćŒćć†ć§ć™ć€‚

ć¾ćØ悁

ć„ć–ć‚„ć£ć¦ćæ悋ćØ恙悓ćŖ悊å‡ŗę„ć”ć‚ƒć£ć¦å¤‰ę…‹åŗ¦ćŒä½Žć™ćŽć¦ć‚¢ćƒ¬ć§ć™ćŒć€ć¾ć‚恄恄恋怂

]]>
Mon, 01 Dec 2014 00:00:00 +0900
http://backpaper0.github.io/2014/11/12/java_engineer_training_book.html http://backpaper0.github.io/2014/11/12/java_engineer_training_book.html <![CDATA[怌Javać‚Øćƒ³ć‚øćƒ‹ć‚¢é¤ŠęˆčŖ­ęœ¬ć€čŖ­ć‚“恠]]> 怌Javać‚Øćƒ³ć‚øćƒ‹ć‚¢é¤ŠęˆčŖ­ęœ¬ć€čŖ­ć‚“恠

ēŒ®ęœ¬ć—ć¦é ‚ćć¾ć—ćŸć€‚ ē§ć‚’ęŽØč–¦ć—ć¦ćć‚ŒćŸć®ć–ćć²ć‚ćµćæ恕悓态恂悊恌ćØć†ć”ć–ć„ć¾ć™ļ¼

ć“ć®ęœ¬ćÆēµŒéØ“ć®ęµ…ć„Javać‚Øćƒ³ć‚øćƒ‹ć‚¢ćŒćµć¤ć†ć®Javać‚Øćƒ³ć‚øćƒ‹ć‚¢ć«ćŖć‚‹ćŸć‚ć«åæ…要ćŖꊀ蔓ēš„ćŖēŸ„識 (ćØęŠ€č”“ä»„å¤–ć®ēŸ„識) 悒äø€åŗ¦ć«å–ć‚Šå…„悌悋äŗ‹ćŒć§ćć‚‹ć‚ˆć†ćŖå†…å®¹ć«ćŖć£ć¦ć„ć¾ć™ć€‚

怌ē‰¹é›†1怍恧ćÆJavaå…„é–€ćØ恄恆äŗ‹ć§čŖ°ć‚‚ćŒé€šć‚‹é“ć«ć¤ć„ć¦č§£čŖ¬ć•ć‚Œć¦ć„ć¾ć™ć€‚ ćŸć ć—ć‚ˆćć‚ć‚‹å…„é–€ę›øć®ć‚ˆć†ć«åˆ¶å¾”ę–‡ć‚„intć®å–ć‚Šć†ć‚‹ēÆ„å›²ć€ę¼”ē®—å­ć®å„Ŗ先順位ćŖć©ć‚’ć”ć¾ć”ć¾č§£čŖ¬ć—ćŸć‚ŠćÆć—ć¾ć›ć‚“ć€‚

ćć®ä»£ć‚ć‚ŠJavač؀čŖžć®č¦ć§ć‚ć‚‹ć‚Æćƒ©ć‚¹ć«ć¤ć„ć¦2ē« ć‚’ć¾ć‚‹ć”ćØä½æć£ć¦č§£čŖ¬ć—ć¦ć„ć¾ć™ć€‚ ćƒˆćƒƒćƒ—ćƒ¬ćƒ™ćƒ«ć®ć‚Æćƒ©ć‚¹ć€ć‚¤ćƒ³ćƒŠćƒ¼ć‚Æćƒ©ć‚¹ć€staticćŖćƒć‚¹ćƒˆć—ćŸć‚Æćƒ©ć‚¹ć€åŒæ名ć‚Æćƒ©ć‚¹ć®é•ć„ć‚’čŖ¬ę˜Žć§ćć¾ć™ć‹ļ¼Ÿ ć“ć®ęœ¬ć‚’čŖ­ć‚ć°čŖ¬ę˜Žć§ćć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć™ć€‚

ć¾ćŸć€ä¾‹å¤–ć®ę‰±ć„ć‹ćŸć«ć¤ć„ć¦ć‚‚å®Ÿč·µēš„ćŖ視ē‚¹ć§ę›øć‹ć‚Œć¦ć„ć¾ć™ć€‚ ć—ć£ć‹ć‚ŠčŖ­ć‚“恧 e.printStackTrace() ć‹ć‚‰å’ę„­ć—ć¾ć—ć‚‡ć†ć€‚

怌ē‰¹é›†2怍恧ćÆćƒ©ćƒ ćƒ€å¼ćØStream APIć«ć¤ć„ć¦ć‚³ćƒ³ćƒ‘ć‚Æ惈ćŖćŒć‚‰ć‚‚åˆ†ć‹ć‚Šć‚„ć™ćč§£čŖ¬ć—ć¦ć„ć¾ć™ć€‚ ę–‡ę³•ć‚„ä½æć„ę–¹ć ć‘ć§ćŖććƒ©ćƒ ćƒ€å¼ćŒćŖ恜åæ…要恫ćŖć£ćŸć®ć‹ć‚‚ć‚ˆćåˆ†ć‹ć‚Šć¾ć™ć€‚

怌ē‰¹é›†3怍ćÆJava EE恧恙怂 åŗƒå¤§ćŖJava EEć®ä»•ę§˜ē¾¤ć‹ć‚‰Servlet态JSF态JAX-RS态JPA态CDI态EJB悒惔惃ć‚Æć‚¢ćƒƒćƒ—ć—ć¦č§£čŖ¬ć—ć¦ć„ć¾ć™ć€‚ Java EE恮äø»č¦ęŠ€č”“ć®é›°å›²ę°—ć‚’ęŽ“悁悋恮恧ćÆćŖ恄恧恗悇恆恋怂

怌ē‰¹é›†4怍恧ćÆJava恮ꊀ蔓恧ćÆćŖććƒćƒ¼ćƒ é–‹ē™ŗ恫åæ…要ćŖēŸ„識ćØ恗恦 Git态Maven态JUnit态Jenkinsć«ć¤ć„ć¦ćć‚Œć‚‰ćŒåæ…要ćØćŖ悋背ę™Æć‚„å°Žå…„ę–¹ę³•ć€ ä½æē”ØäøŠć®ę³Øꄏē‚¹ćŖć©ćŒč§£čŖ¬ć•ć‚Œć¦ć„ć¾ć™ć€‚ 悂ćÆ悄Eclipse恧WARä½œć£ć¦ć‚‹ćŖ恩ćØčØ€ć†ē¾å “ćÆćŖ恄ćØę€ć„ć¾ć™ćŒć€ 恓悌悉(恂悋恄ćÆć“ć‚Œć‚‰ć«é”žć™ć‚‹ä»–ć®ćƒ„ćƒ¼ćƒ«)ć‚’å°Žå…„ć—ć¦ć„ćŖć„å “åˆćÆ恓恮ē‰¹é›†ćŒå½¹ē«‹ć¤ć§ć—悇恆怂

ćƒšćƒ¼ć‚øćÆå‰å¾Œć—ć¾ć™ćŒć€ć€Œå·»é ­čؘäŗ‹ć€ć§ćÆJavać®ę­“å²ćØJavać«ć¾ć¤ć‚ć‚‹(ć—ć‚‡ćƒ¼ć‚‚ćŖ恄)惍ć‚æć‚’č§£čŖ¬ć—ć¦ć„ć¾ć™ć€‚ 恓悌悒äø€čŖ­ć—ć¦ćŠććØTwitterć‚’ć‚ˆć‚Šę„½ć—ć‚ć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć™ćŸć¶ć‚“ć€‚

ćć—ć¦äø€ē•Ŗå¾Œć‚ć«čØ˜č¼‰ć•ć‚Œć¦ć„ć‚‹ć€Œäø€čˆ¬čؘäŗ‹ć€ćÆå°‘ć€…č¶£ćŒå¤‰ć‚ć‚Šć€ 受čؗ開ē™ŗ恮ē¾å “恧åæ…要ćØćŖć‚‹ć‚¹ć‚­ćƒ«ćŒē°”ę½”ć«ć¾ćØć‚ć‚‰ć‚Œć¦ć„ć¾ć™ć€‚ Excelć«ć‚¹ć‚ÆćƒŖćƒ¼ćƒ³ć‚·ćƒ§ćƒƒćƒˆć‚’č²¼ä»˜ć‘ć‚‹ćØć„ć£ćŸ (Ā“ļ¼›Ļ‰ļ¼›ļ½€)ļ½³ļ½Æā€¦ ćØćŖć‚‹ć‚¹ć‚­ćƒ«ć«ć‚‚č§¦ć‚Œć¦ć„ć¾ć™ćŒć€ Javaä»„å¤–ć«ć‚‚ć“ć†ć„ć†ć‚¹ć‚­ćƒ«ćŒåæ…要ćŖ悓恠ćŖćØē†č§£ć§ćć‚‹å†…å®¹ć«ćŖć£ć¦ć„ć¾ć™ć€‚

ē“°ć‹ć„ę„Ÿęƒ³ćƒ»ę°—ć«ćŖć£ćŸē‚¹ćŖ恩

ćØ恄恆悏恑恧ē“°ć‹ć„éƒØåˆ†ć‚’ęŒ™ć’ć¦ć„ćć¾ć™ć€‚

  • 29ćƒšćƒ¼ć‚ø怂

    通åøøć®ę„­å‹™ć‚·ć‚¹ćƒ†ćƒ ć‚’é–‹ē™ŗ恙悋äø­ć§ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ä½œęˆć™ć‚‹ć“ćØćÆ少ćŖ恄恮恧ā€

    CDIćØć„ć†ć‚‚ć®ćŒć‚ć£ć¦ć ćŖļ¼ˆry

  • 30ćƒšćƒ¼ć‚ø怂

    ć‚¤ćƒ³ćƒŠćƒ¼ć‚Æćƒ©ć‚¹ć«åå‰ä»˜ćå®šę•°ć‚’ęŒć¦ć‚‹ć®ēŸ„悉ćŖć‹ć£ćŸć€‚ å‹‰å¼·ć«ćŖć‚Šć¾ć—ćŸļ¼

  • 34ćƒšćƒ¼ć‚ø态ćƒŖć‚¹ćƒˆ19怂

    č¤‡ę•°ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ悒ē”Øę„ć™ć‚‹å “åˆć€ ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³å¼•ę•°ćÆå¾Œć‚ć®å¼•ę•°(恓恓恧恄恆ćØ b )ć«ć™ć‚‹ę–¹ćŒäø€čˆ¬ēš„ćØę€ć„ć¾ć™ć€‚

  • 35ćƒšćƒ¼ć‚ø怂

    例外ć‚Ŗ惖ć‚ø悧ć‚Æ惈恫ćÆä¾‹å¤–ćŒē™ŗē”Ÿć—ćŸę™‚ć®ēŠ¶ę…‹ćŒč©°ć‚č¾¼ć¾ć‚Œć¦ć¾ć™ć€‚

    怌ēŠ¶ę…‹ć€ć‚ˆć‚Šć‚‚ć€Œęƒ…å ±ć€ć®ę–¹ćŒć—ć£ćć‚Šćć‚‹ć‹ćŖćƒ¼ć€‚ 前ē« ć§åÆ変ćØäøå¤‰ć«ć¤ć„恦čØ€åŠć—ć¦ć„ć‚‹ć®ć‚‚ē›øć¾ć£ć¦åˆ†ć‹ć‚Šć«ćć„ę°—ćŒć—ć¾ć—ćŸć€‚

  • 38态39ćƒšćƒ¼ć‚ø怂

    InvocationTargetException ćÆ他恮ćƒŖćƒ•ćƒ¬ć‚Æć‚·ćƒ§ćƒ³ä¾‹å¤–ćØę„å‘³åˆć„ćŒć”ć‚‡ć£ćØ違恆ćØę€ć£ć¦ć„ć¾ć™ć€‚ 他恮ćƒŖćƒ•ćƒ¬ć‚Æć‚·ćƒ§ćƒ³ä¾‹å¤–ćŒć€ŒęŒ‡å®šć•ć‚ŒćŸćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œć§ććŖć‹ć£ćŸć€ć®ć«åÆ¾ć—ć¦ InvocationTargetExceptionćÆć€ŒęŒ‡å®šć•ć‚ŒćŸćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œäø­ć«ä¾‹å¤–ćŒē™ŗē”Ÿć—ćŸć€ćØ恄恆ēŠ¶ę³ć§ć™ć€‚ ćć‚Œć«ć‚ˆć£ć¦ćƒćƒ³ćƒ‰ćƒŖćƒ³ć‚°ćŒå¤‰ć‚ć‚‹ć‹ć©ć†ć‹ćÆć‚±ćƒ¼ć‚¹ćƒć‚¤ć‚±ćƒ¼ć‚¹ćØćÆę€ć„ć¾ć™ćŒć€‚ 恂ćØ恓恓ćÆćƒžćƒ«ćƒć‚­ćƒ£ćƒƒćƒć«ć¤ć„ć¦ę›øć„ć¦ć¦ć€ćŸć¾ćŸć¾ćƒŖćƒ•ćƒ¬ć‚Æć‚·ćƒ§ćƒ³ä½æć£ćŸć ć‘ćŖ恮恧 InvocationTargetException恮ꉱ恄ćØć‹é–¢äæ‚ē„”恄恋怂 ć¾ć‚ę°—ć«ćŖć£ćŸćØ恄恆恓ćØ恧怂

    갗恫ćŖć£ćŸćØčØ€ćˆć°ä¾‹å¤–ć®äø­ć§ćÆ InterruptedException 恮ꉱ恄恫悂ę³Øꄏ恌åæ…要ćØę€ć†ć®ć§ čØ€åŠć—ć¦ćŠć„ćŸć»ć†ćŒč‰Æ恄恮恧ćÆćØäø€ēž¬ę€ć„ć¾ć—ćŸćŒć€ å¾Œć®ć»ć†ć§ćƒžćƒ«ćƒć‚¹ćƒ¬ćƒƒćƒ‰ćÆ恆恋恤恫触悋ćŖć£ć¦ę›øć„ć¦ć‚ć‚‹ć—ć¾ć‚ć„ć„ć‹ć€‚

  • 43ćƒšćƒ¼ć‚ø怂

    Java 1.7恮try-with-resourcesę§‹ę–‡ć®ćŸć‚ć«čæ½åŠ ć•ć‚ŒćŸ Throwable#addSuppressed(Throwable) 悂ä½æ恈恝恆恧恙恭怂

  • 68ćƒšćƒ¼ć‚ø态ćƒŖć‚¹ćƒˆ6怂69ćƒšćƒ¼ć‚ø怂

    Files.lines() 悒try-with-resources恧ć‚Æćƒ­ćƒ¼ć‚ŗ恗恦悋恮ćÆ굁ēŸ³ć ćØę€ć„ć¾ć—ćŸć€‚ 恓恓ćÆćƒćƒžć‚Šć©ć“ć‚ć«ćŖ悊恝恆ćŖę°—ćŒć—ć¾ć™ć­ćƒ¼ć€‚

  • 87ćƒšćƒ¼ć‚ø态ćƒŖć‚¹ćƒˆ5怂

    惜ć‚æćƒ³ć®ęŠ¼äø‹ę™‚恫Ajaxć§å‡¦ē†

    ā€œęŠ¼äø‹ā€ć®ē¾å “ꄟ恙恔恄怂

  • 95态96ćƒšćƒ¼ć‚ø怂

    JAXBēµŒē”±ć®JSON惗惭惐悤惀ćÆJAX-RS恮ęؙęŗ–ä»•ę§˜ć§ćÆćŖ恄(恧恙悈恭ļ¼Ÿ)恋悉ę³Øꄏ恌åæ…要恧恙恭怂

  • 98ćƒšćƒ¼ć‚ø态ćƒŖć‚¹ćƒˆ3

    JPA恫恊恑悋ReadćØUpdate怂 mergećÆupdate恧ćÆćŖćć¦ę°øē¶šć‚³ćƒ³ćƒ†ć‚­ć‚¹ćƒˆå¤–恮ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚’ ę°øē¶šć‚³ćƒ³ćƒ†ć‚­ć‚¹ćƒˆć«ēŖć£č¾¼ć‚€č”Œē‚ŗćØę€ć„ć¾ć™ć€‚ em.find(clazz, id) 恗恟ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćÆę°øē¶šć‚³ćƒ³ćƒ†ć‚­ć‚¹ćƒˆć§ē®”ē†ć•ć‚Œć¦ć„悋恮恧 merge恙悋åæ…要ćÆćŖ恄恧恙悈恭ļ¼Ÿ ā€¦ā€¦ćØć‹ę€ć£ć¦ć„ćŸć‚‰100ćƒšćƒ¼ć‚ø恧merge恮čŖ¬ę˜ŽćŒć‚ć£ćŸć€‚

  • 105ćƒšćƒ¼ć‚ø怂

    ćƒ¢ćƒƒć‚Æć«ć‚ˆć£ć¦ćƒ†ć‚¹ćƒˆå®¹ę˜“ę€§ć‚’é«˜ć‚ćŸć‚Šć€

    å…·ä½“ä¾‹ćŒę¬²ć—ć„ę°—ćŒć—ć¾ć—ćŸć€‚ CDI恮alternativećÆbeans.xml悒ē·Ø集恗ćŖ恍悃恄恑ćŖć‹ć£ćŸć‚Šć—ć¦é¢å€’ć„ć€‚ 個äŗŗēš„恫ćÆCDI悒ä½æć†å “åˆćÆćƒ¦ćƒ‹ćƒƒćƒˆćƒ†ć‚¹ćƒˆć«ćÆGuice悒ä½æć†ć®ćŒę„½ć§č‰Æ恄ćØę€ć£ć¦ć„ć¾ć™ć€‚

恂ćØ态JVMćø恮čØ€åŠćŒč¦‹å½“ćŸć‚‰ćŖć„ć®ćŒę°—ć«ćŖć‚Šć¾ć—ćŸć€‚ -Xmx ćØ恋怂

Java EEćÆ态ēÆ„å›²ćŒåŗƒćć¦ä»•ę§˜ćŒć§ć‹ć„ć®ć§ä»•ę–¹ćŖć„ć®ć§ć™ćŒć€ å†…å®¹ćŒč–„ć‚ć ćØę„Ÿć˜ć¦ć—ć¾ć„ć¾ć—ćŸć€‚ ć„ć£ćJAX-RS悄CDIćŖć©ć®å„ä»•ę§˜ć®čŖ¬ę˜ŽćÆć‚‚ć£ćØć‚·ćƒ³ćƒ—ćƒ«ć«ć—ć¦ć€ ćƒćƒ„ćƒ¼ćƒˆćƒŖć‚¢ćƒ«ć‚’ę‰‹åŽšćć™ć‚‹ćØć„ć†ę‰‹ć‚‚ć‚ć£ćŸć®ć‹ć‚‚ć‹ćŖćƒ¼ć€ćŖ恩ćØē„”č²¬ä»»ć«ę€ć„ć¾ć—ćŸć€‚

ē‰¹ć«ServletćØEJB恮čŖ¬ę˜ŽćÆćŖćć¦ć‚‚č‰Æć‹ć£ćŸć‹ć‚‚ēŸ„ć‚Œć¾ć›ć‚“ć­ć€‚ ć™ć£ć“ć‚“ć®ć‚µćƒ¼ćƒ–ćƒ¬ćƒƒćƒˆćÆä½æ悏ćŖ恄恗EJBćÆćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³å¢ƒē•ŒćŒę¬²ć—ć„ć£ć¦ć®ćŒę®†ć©ćØę€ć„ć¾ć™ć—ć€‚ ćƒ‡ć‚«ć„ę”ˆä»¶ć‚„ć£ćŸć“ćØćŖć„ć®ć§č¦‹å½“é•ć„ć®ę„č¦‹ć‹ć‚‚ć—ć‚Œć¾ć›ć‚“ćŒć€‚

ć¾ćØ悁

ćØć„ć†ć‚ć‘ć§ć€č‰²ć€…ćØē“°ć‹ć„恓ćØ悂ę›øćć¾ć—ćŸćŒē·åˆēš„恫ćÆ間違恄ē„”恏č‰Æę›ø恠ćØę€ć£ć¦ć„ć¾ć™ć€‚ å†’é ­ć«ć‚‚ę›øćć¾ć—ćŸćŒć“ć®ęœ¬ćÆēµŒéØ“ć®ęµ…ć„Javać‚Øćƒ³ć‚øćƒ‹ć‚¢ć®ēš†ę§˜ćøć‚Ŗć‚¹ć‚¹ćƒ”ć§ć™ć€‚ ć“ć®ęœ¬ć‚’čŖ­ć‚“ć§å­¦ć‚“ć§ę„½ć—ć„Javaćƒ©ć‚¤ćƒ•ć‚’é€ć‚Šć¾ć—ć‚‡ć†ļ¼

恂ćŖ恟ćØļ¼

(ē¶šććÆćÆ恦ćŖ惖惃ć‚Æćƒžćƒ¼ć‚Æć®ć‚³ćƒ”ćƒ³ćƒˆć§ćŠé”˜ć„ć—ć¾ć™)

執ē­†é™£ć®ćƒ–ćƒ­ć‚°ć‚Øćƒ³ćƒˆćƒŖ

ć¾ć č²·ć£ć¦ćŖć„ć²ćØćÆ悭ć‚Æć‚æćƒ­ćƒ¼ć•ć‚“ć®ćƒ–ćƒ­ć‚°ć®ć‚¢ćƒ•ć‚£ćƒŖćƒ³ć‚Æć‹ć‚‰č²·ćŠć†ļ¼

]]>
Wed, 12 Nov 2014 00:00:00 +0900
http://backpaper0.github.io/2014/11/08/semicolonless_tail_call_optimization.html http://backpaper0.github.io/2014/11/08/semicolonless_tail_call_optimization.html <![CDATA[ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać§ęœ«å°¾å†åø°ć®ęœ€é©åŒ–]]> ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać§ęœ«å°¾å†åø°ć®ęœ€é©åŒ–

前回 ćÆć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać§å†åø°ćŒć§ćć‚‹äŗ‹ćŒåˆ†ć‹ć‚Šć¾ć—ćŸć€‚

ćŸć ć—å†åø°ć—恙恎悋ćØć‚¹ć‚æ惃ć‚Æć‚Ŗćƒ¼ćƒćƒ¼ćƒ•ćƒ­ćƒ¼ć§ć—ć«ć¾ć™ć€‚

再åø°ć«ć‚ˆć‚‹ 1 + 2 + ... + n 悒見恦ćæć¾ć—ć‚‡ć†ć€‚

public class SemicolonlessRecursion {

    public static void main(String[] args) {
        if (java.util.stream.Stream
            .of(Integer.parseInt(args[0]))
            .flatMap(n -> java.util.stream.Stream
            .<F<Integer, Integer>> of((f, m) -> m < 1 ? 0 : m + f.apply(f, m - 1))
            .map(sum -> sum.apply(sum, n)))
            .peek(System.out::println)
            .count() > 0) {
        }
    }

    interface F<P, R> extends java.util.function.BiFunction<F<P, R>, P, R> {}
}

ćØć£ć¦ć‚‚åˆ†ć‹ć‚Šć‚„ć™ć„ć‚³ćƒ¼ćƒ‰ć§ć™ćŒ n 恫 10000 ē؋åŗ¦ć‚’äøŽćˆćŸć ć‘ć§ć‚¹ć‚æ惃ć‚Æć‚Ŗćƒ¼ćƒćƒ¼ćƒ•ćƒ­ćƒ¼ć«ćŖć‚Šć¾ć™ć€‚

ć“ć®å†åø°ć‚’ęœ«å°¾å†åø°ć«ć—ć¦ęœ€é©åŒ–ć‚’č”Œć†ć®ćŒä»Šå›žć®ē›®ēš„恧恙怂

ꙮ通恮Javać§ęœ«å°¾å†åø°ęœ€é©åŒ–

ęœ€åˆć‹ć‚‰ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać§č€ƒćˆć¦ć‚‚ć—ć‚“ć©ć„ć ć‘ćŖ恮恧态 ć¾ćšćÆꙮ通恮Javać§ęœ«å°¾å†åø°ęœ€é©åŒ–ē‰ˆć®ć‚³ćƒ¼ćƒ‰ć‚’ę›ø恄恦ćæć¾ć™ć€‚ å®Ÿč£…ć™ć‚‹ć«å½“ćŸć£ć¦ 怌Javać«ć‚ˆć‚‹é–¢ę•°åž‹ćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°ć€ 恮7ē« ć‚’å‚č€ƒć«ć—ć¾ć—ćŸć€‚

import java.util.Optional;
import java.util.stream.Stream;

public class TailCallOptimization {

    public static void main(String[] args) {
        int n = Integer.parseInt(args[0]);

        F sum = (f, p, r) -> p < 1 ? done(r) : call(() -> f.apply(f, p - 1, r + p));

        TailCall t = sum.apply(sum, n, 0);

        Integer result = Stream.iterate(t, TailCall::get)
                               .map(TailCall::result)
                               .filter(Optional::isPresent)
                               .map(Optional::get)
                               .findFirst()
                               .get();

        System.out.println(result);
    }

    interface F {

        TailCall apply(F f, Integer p, Integer r);
    }

    static TailCall call(TailCall t) {
        return t;
    }

    static TailCall done(Integer result) {
        return new TailCall() {

            @Override
            public TailCall get() {
                throw new UnsupportedOperationException();
            }

            @Override
            public Optional<Integer> result() {
                return Optional.of(result);
            }
        };
    }

    interface TailCall {

        TailCall get();

        default Optional<Integer> result() {
            return Optional.empty();
        }
    }
}

å¤šå°‘ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javaćøć®å¤‰ę›ć‚’ę„č­˜ć—ć¦ć„ć¾ć™ćŒę™®é€šć®Java恧恙怂 ć“ć‚Œć‚’ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać«ć—ć¦ć„ćć¾ć™ć€‚

ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹åŒ–ć®åøƒēŸ³

Java 8ę™‚ä»£ć«ćŠć‘ć‚‹ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać®éµćÆćƒ©ćƒ ćƒ€å¼ć ćØę€ć£ć¦ć„ć¾ć™ć€‚ å€¤ć‚’čæ”ć™ćƒ”ć‚½ćƒƒćƒ‰ć®å®šē¾©ćŒå‡ŗę„ćŖć„ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Java恧恙恌态 ćƒ©ćƒ ćƒ€å¼ć‚’ä½æ恆äŗ‹ć§ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹ć«é–¢ę•°ć‚’定ē¾©ć™ć‚‹äŗ‹ćŒåÆčƒ½ć§ć™ć€‚

//ćµćŸć¤ć®intć‚’č¶³ć—ć¦čæ”ć™é–¢ę•°ć‚’å®šē¾©ć—恦2, 3恫適ē”Ø恙悋
if (java.util.stream.Stream
    .<java.util.function.BinaryOperator<Integer>> of((a, b) -> a + b)
    .map(add -> add.apply(2, 3))
    .peek(System.out::println)
    .count() > 0) {
}

ćƒ©ćƒ ćƒ€å¼ć‚’ä½æ恆ē‚ŗ恫åæ…要ćØćŖ悋恮ćÆé–¢ę•°åž‹ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ć§ć™ć€‚ ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Java恧ćÆć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ć®å®šē¾©ćÆå‡ŗę„ć¾ć™ćŒć€ćć®äø­ć§ćƒ”ć‚½ćƒƒćƒ‰å®šē¾©ćŒå‡ŗę„ć¾ć›ć‚“ć€‚ 恟恠恗态å¹ø恄恫悂Java恮ęؙęŗ–API恫ćÆé–¢ę•°åž‹ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ćŒč±ŠåÆŒć«ē”Øę„ć•ć‚Œć¦ć„ć‚‹ć®ć§ 恝悌悉悒extends恙悋恓ćØ恧ē”Ø途恫ē‰¹åŒ–ć—ćŸé–¢ę•°åž‹ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ć‚’ę‰‹ć«å…„ć‚Œć‚‹äŗ‹ćŒć§ćć¾ć™ć€‚

ć¾ćš TailCall ć‚’é–¢ę•°åž‹ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ć«ć™ć‚‹äŗ‹ć‹ć‚‰å§‹ć‚ć¾ć—悇恆怂 恓恓恧恮čŖ²é”ŒćÆ get() ćØ result() 恮äø€ęœ¬åŒ–恧恙怂 ä»Šć®ć¾ć¾ć§ćÆ恩恆恗恦悂åŒæ名ć‚Æćƒ©ć‚¹ć‚’å°Žå…„ć™ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚

TailCall ćØ Optional<Integer> 恮 Pair 悒čæ”恙 Supplier ćØ恙悋恓ćØ恧 TailCall ć‚’é–¢ę•°åž‹ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ć«ć§ćć¾ć—ćŸć€‚

interface TailCall extends Supplier<Pair<TailCall, Optional<Integer>>>{}

ć“ć‚Œć«ć‚ˆć‚Š done(Integer) 恌čæ”ć™å€¤ć‚’åŒæ名ć‚Æćƒ©ć‚¹ć§ćÆćŖććƒ©ćƒ ćƒ€å¼ć§ę›øć‘ć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚

static TailCall done(Integer result) {
    return () -> new Pair<>(null, Optional.of(result));
}

ć¾ćŸ call(TailCall) ćÆę¬”ć®ć‚ˆć†ć«å¤‰ę›“ć—ć¾ć™ć€‚

static TailCall call(Supplier<TailCall> t) {
    return () -> new Pair<>(t.get(), Optional.empty());
}

恓恆恙悋恓ćØć§é–¢ę•° sum ćÆę¬”ć®ć‚ˆć†ć«ę›øć‘ć¾ć™ć€‚

F sum = (f, p, r) -> p < 1 ? done(r) : call(() -> f.apply(f, p - 1, r + p));

恝悌恋悉ēµęžœć‚’걂悁悋 Stream ę“ä½œć§ć™ćŒć€ ę™®é€šć®å†åø°ē‰ˆć§ćÆ TailCall 恮 get() ć‚’å‘¼ć³å‡ŗ恙恓ćØ恧 Stream 悒꧋ēÆ‰ć—ć¦ć„ć¾ć—ćŸćŒ get() 恌 Pair<TailCall, Optional<Integer>> 悒čæ”ć™ć‚ˆć†ć«ć—ćŸć®ć§ć€ Pair<TailCall, Optional<Integer>> 恮 Stream 悒꧋ēÆ‰ć™ć‚‹ć‚ˆć†ć«ć—ć¾ć™ć€‚

Stream.iterate(new Pair<>(t, Optional.<Integer> empty()),
               p -> p.getKey().get())
      .map(Pair::getValue)
      .filter(Optional::isPresent)
      .map(Optional::get)
      .findFirst()
      .get();

ć“ć“ć¾ć§ć®ć‚³ćƒ¼ćƒ‰å…Øä½“ć‚’ę¬”ć«čØ˜č¼‰ć—ć¾ć™ć€‚

import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Stream;

import javafx.util.Pair;

public class TailCallOptimization {

    public static void main(String[] args) {
        int n = Integer.parseInt(args[0]);

        F sum = (f, p, r) -> p < 1 ? done(r) : call(() -> f.apply(f, p - 1, r + p));

        TailCall t = sum.apply(sum, n, 0);

        Integer result = Stream.iterate(new Pair<>(t, Optional.<Integer> empty()),
                                        p -> p.getKey().get()).map(Pair::getValue)
                               .filter(Optional::isPresent)
                               .map(Optional::get)
                               .findFirst()
                               .get();

        System.out.println(result);
    }

    interface F {

        TailCall apply(F f, Integer p, Integer r);
    }

    static TailCall call(Supplier<TailCall> t) {
        return () -> new Pair<>(t.get(), Optional.empty());
    }

    static TailCall done(Integer result) {
        return () -> new Pair<>(null, Optional.of(result));
    }

    interface TailCall extends Supplier<Pair<TailCall, Optional<Integer>>> {}
}

ćć—ć¦ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹ćøā€¦ā€¦

恂ćØćÆć”ć‚‡ć£ćØćšć¤ć¾ćØ悁恟悊ćŖć‚“ć‚„ć‹ć‚“ć‚„ć—ć¦ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać«å¤‰ę›“ć—ć¦ć„ćć¾ć™ć€‚

ćØć„ć†ć‚ć‘ć§ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać§ęœ«å°¾å†åø°ęœ€é©åŒ–ć‚’č”Œć£ćŸć‚³ćƒ¼ćƒ‰ćŒę¬”恫ćŖć‚Šć¾ć™ć€‚

public class SemicolonlessTailCallOptimization {

    public static void main(String[] args) {
        if (java.util.stream.Stream
            .of(Integer.parseInt(args[0]))
            .flatMap(n -> java.util.stream.Stream
            .<F> of((f, pr) -> pr[0] < 1
                ? () -> new javafx.util.Pair<>(null, java.util.Optional.of(pr[1]))
                : () -> new javafx.util.Pair<>(f.apply(f, new int[] { pr[0] - 1, pr[1] + pr[0] }), java.util.Optional.empty()))
            .<TailCall> map(sum -> sum.apply(sum, new int[] { n, 0 })))
            .map(t -> java.util.stream.Stream
            .iterate(new javafx.util.Pair<>(t, java.util.Optional.<Integer> empty()), p -> p.getKey().get())
            .map(javafx.util.Pair::getValue)
            .filter(java.util.Optional::isPresent)
            .map(java.util.Optional::get)
            .findFirst()
            .get())
            .peek(System.out::println)
            .count() > 0) {
        }
    }

    interface F extends java.util.function.BiFunction<F, int[], TailCall> {}

    interface TailCall extends java.util.function.Supplier<javafx.util.Pair<TailCall, java.util.Optional<Integer>>> {}
}

ć¾ćØ悁

ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać§ć‚‚ęœ«å°¾å†åø°ć®ęœ€é©åŒ–ćŒå‡ŗę„ć‚‹äŗ‹ćŒåˆ†ć‹ć‚Šć¾ć—ćŸć€‚ ć“ć‚Œć«ć‚ˆć‚Šć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹JavaćŒć¾ćŸäø€ę­©ć€å®Ÿē”Øēš„ćŖč؀čŖžćøćØčæ‘恄恄恟ćØę€ć‚ć‚Œć¾ć™ć€‚

ćŖćŠć€ä»Šå›žćÆ javax.util.Pair 悒ä½æē”Øć—ć¾ć—ćŸćŒć€ć“ć‚ŒćŒå¤§å¤‰ä¾æåˆ©ć§ć—ćŸć€‚ ē‰¹ć«ćµćŸć¤ć®å€¤ć‚’čæ”ć™å “åˆć«ä»Šć¾ć§ćÆé…åˆ—ć‚ćŸć‚Šć‚’ä½æē”Øć—ć¦ć„ćŸć®ć§ć‚­ćƒ£ć‚¹ćƒˆćŒåæ…é ˆć«ćŖć£ć¦ć„ć¾ć—ćŸćŒć€ Pair ćŒć‚ć‚Œć°ć‚­ćƒ£ć‚¹ćƒˆć‚‚äøč¦ć§ć‚³ćƒ¼ćƒ‰ćŒć™ć£ćć‚Šć—ć¾ć—ćŸć€‚ ć¾ćŸć€ćµćŸć¤ä»„äøŠć®å€¤ć‚’čæ”ć™å “合ćÆ Pair<T, Pair<U, V>> ćŖ恩ćØ恙悌恰č‰Æ恄恧恙恭怂

ćØć„ć†ć‚ć‘ć§ć“ć‚Œć‹ć‚‰ć‚‚ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Java恮åÆčƒ½ę€§ć‚’ęŽ¢ć£ć¦č”ŒććŸć„ćØę€ć„ć¾ć™ć€‚

]]>
Sat, 08 Nov 2014 00:00:00 +0900
http://backpaper0.github.io/2014/11/03/semicolonless_java_fibonacci_without_z_combinator.html http://backpaper0.github.io/2014/11/03/semicolonless_java_fibonacci_without_z_combinator.html <![CDATA[ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać§ćƒ•ć‚£ćƒœćƒŠćƒƒćƒć‚’Zć‚³ćƒ³ćƒ“ćƒćƒ¼ć‚æćŖ恗恧]]> ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać§ćƒ•ć‚£ćƒœćƒŠćƒƒćƒć‚’Zć‚³ćƒ³ćƒ“ćƒćƒ¼ć‚æćŖ恗恧

ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać§ćƒ•ć‚£ćƒœćƒŠćƒƒćƒ 恧Zć‚³ćƒ³ćƒ“ćƒćƒ¼ć‚æä½æć£ć¦å†åø°ć ļ¼(惉惤) ćØ恋ę›øćć¾ć—ćŸćŒćć‚“ćŖ悂恮ćÆåæ…要ćŖć‹ć£ćŸć€‚

public class SemicolonlessFibonacci {

    public static void main(String[] args) {
        if (java.util.stream.Stream.<F> of((f, n) -> n <= 1 ? n : f.apply(f, n - 2) + f.apply(f, n - 1))
            .map(f -> f.apply(f, Integer.parseInt(args[0])))
            .peek(System.out::println).count() > 0) {
        }
    }

    interface F extends java.util.function.BiFunction<F, Integer, Integer> {
    }
}

é›£ć—ćč€ƒćˆéŽćŽć‚“ćŖć£ć¦č©±ć§ć™ć­_(:3ļ½£āˆ )_

]]>
Mon, 03 Nov 2014 00:00:00 +0900
http://backpaper0.github.io/2014/11/02/semicolonless_java_fibonacci.html http://backpaper0.github.io/2014/11/02/semicolonless_java_fibonacci.html <![CDATA[ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać§ćƒ•ć‚£ćƒœćƒŠćƒƒćƒ]]> ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać§ćƒ•ć‚£ćƒœćƒŠćƒƒćƒ

ꦂ要ļ¼šćƒć‚æ恧恗恋ćŖ恄

ć‚ć‚‹é …ć®ćƒ•ć‚£ćƒœćƒŠćƒƒćƒę•°ć‚’ę›ø恍å‡ŗ恙

ēµč«–ć‹ć‚‰č”Œćć¾ć—ć‚‡ć†ć€‚

ć‚ć‚‹é …ć®ćƒ•ć‚£ćƒœćƒŠćƒƒćƒę•°ć‚’ę›ø恍å‡ŗć™ćƒ—ćƒ­ć‚°ćƒ©ćƒ ć§ć™ćŒć€ć“ć‚“ćŖć‚³ćƒ¼ćƒ‰ć«ćŖć‚Šć¾ć—ćŸć€‚ 恆悏ęØŖć«é•·ćˆć€‚

public class SemicolonlessFibonacci {

    public static void main(String[] args) {
        if (java.util.stream.Stream.<java.util.function.Function<F, F>> of(f -> n -> n <= 1 ? n : f.apply(n - 2) + f.apply(n - 1))
            .map(f -> ((java.util.function.Function<G, F>) (x -> f.apply(y -> x.apply(x).apply(y)))).apply(x -> f.apply(y -> x.apply(x).apply(y))))
            .map(fib -> fib.apply(Integer.parseInt(args[0])))
            .peek(System.out::println).findFirst().orElse(0) == 0) {
        }
    }

    interface F extends java.util.function.Function<Integer, Integer> {}

    interface G extends java.util.function.Function<G, F> {}
}

恓悌悒 SemicolonlessFibonacci.java ćØć„ć†åå‰ć§äæå­˜ć—恦 javac SemicolonlessFibonacci.java ć§ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć—ć€ java -cp . SemicolonlessFibonacci 10 ćØć„ć†ćµć†ć«å®Ÿč”Œć—ć¦ćć ć•ć„ć€‚

å¼•ę•°ć‚’ć„ć‚ć„ć‚å¤‰ćˆć¦č©¦ć™ćØęؙęŗ–å‡ŗåŠ›ć«ćƒ•ć‚£ćƒœćƒŠćƒƒćƒę•°ćŒę›ø恍å‡ŗ恕悌悋恓ćØćŒćŠåˆ†ć‹ć‚Šé ‚ć‘ć‚‹ćØę€ć„ć¾ć™ć€‚

ć‚„ć‚ŠćŸć‹ć£ćŸć“ćØ

ä»Šå›žć€å®Ÿē¾ć—ćŸć‹ć£ćŸć“ćØćÆć‚¹ćƒ†ćƒ¼ćƒˆćƒ¬ć‚¹ćŖ再åø°ć§ć™ć€‚

ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Java恧ćÆęˆ»ć‚Šå€¤ć‚’ć‚‚ć¤ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®šē¾©ć§ććŖ恄( return 恫ćÆć‚»ćƒŸć‚³ćƒ­ćƒ³ćŒåæ…é ˆć®ćŸć‚ ) ćØć„ć†åˆ¶é™ć®ćŸć‚ćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ«ćŖć‚Ŗ惖ć‚ø悧ć‚Æćƒˆć‚’å¼•ę•°ć«ć—ć¦ćć‚Œć‚’ę›“ę–°ć™ć‚‹ć“ćØć§ćƒ”ć‚½ćƒƒćƒ‰ć®å‘¼ć³å‡ŗć—å…ƒć«å€¤ć‚’ęˆ»ć™ć—ć‹ć‚ć‚Šć¾ć›ć‚“ć€‚ ćŸć¶ć‚“ć€‚

//ęˆ»ć‚Šå€¤ć®ć‚ć‚‹ćƒ”ć‚½ćƒƒćƒ‰ćÆreturnć§ć‚»ćƒŸć‚³ćƒ­ćƒ³åæ…要
public int get() {
    return 0;
}

//ćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ«ćŖå¼•ę•°ć§å€¤ć‚’ęˆ»ć™
public void set(List<String> holder) {
    if (holder.add("hoge")) {}
}

ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Java 8恋悉ćÆćƒ©ćƒ ćƒ€å¼ć‚’ä½æćˆć°ęˆ»ć‚Šå€¤ć‚’ć‚‚ć¤å‡¦ē†ć‚’定ē¾©ć§ćć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚

if (Stream.<IntBinaryOperator> of((n, m) -> n + m) //äŗŒć¤ć®intć‚’č¶³ć—ć¦čæ”ć™é–¢ę•°ć‚’å®šē¾©
          .map(f -> f.applyAsInt(2, 3))            //é–¢ę•°é©ē”Ø
          .peek(System.out::println)               //å‡ŗ力
          .findFirst().isPresent()) {
}

恧恙恌态č‡Ŗčŗ«ć‚’再åø°å‘¼ć³å‡ŗ恗恙悋恓ćØćÆć§ćć¾ć›ć‚“ć€‚

//恓悌ćÆć‚»ćƒŸć‚³ćƒ­ćƒ³Javaā€¦ā€¦ć¦ć„恆恋Java
IntUnaryOperator sum = n -> n == 0 ? 0 : n + sum(n - 1);
                                           //~~~ ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć‚Øćƒ©ćƒ¼

Zć‚³ćƒ³ćƒ“ćƒćƒ¼ć‚æ

ć“ć‚Œć‚‰ć®å•é”Œć‚’č§£ę±ŗć™ć‚‹ć®ćŒZć‚³ćƒ³ćƒ“ćƒćƒ¼ć‚æ恧恙怂

恓恮č¾ŗćÆå…Øē„¶č©³ć—恏ćŖć„ć‚“ć§ć™ćŒćƒ©ćƒ ćƒ€č؈ē®—ć§å†åø°ć‚’č”Œć†ć“ćØ恌å‡ŗę„ć‚‹ć‚¢ćƒ¬ć£ć½ć„ć§ć™ć€‚ ćć—ć ć•ć‚“ć®ć‚Øćƒ³ćƒˆćƒŖć‚‚å‚č€ƒć«ć•ć›ć¦é ‚ćć¾ć—ćŸć€‚

再åø°ć™ć‚‹ć«ćÆYć‚³ćƒ³ćƒ“ćƒćƒ¼ć‚æćØć„ć†ć®ć‚‚ć‚ć‚‹ć‚ˆć†ć§ć™ćŒę­£ę ¼č©•ä¾”ęˆ¦ē•„恮č؀čŖžć§ćÆć‚¹ć‚æ惃ć‚Æć‚Ŗćƒ¼ćƒćƒ¼ćƒ•ćƒ­ćƒ¼ć«ćŖć‚‹ć£ć½ć„ć§ć™ć€‚ 恦恄恆恋ćŖć‚Šć¾ć—ćŸć€‚

ćØ恄恆悏恑恧Zć‚³ćƒ³ćƒ“ćƒćƒ¼ć‚æ恧恙怂 ćć®å®šē¾©ćÆꬔ恮通悊恧恙怂

Z = Ī»f. (Ī»x. f (Ī»y. x x y)) (Ī»x. f (Ī»y. x x y))

恓悌悒Java恧ę›ø恏ćØ恓悓ćŖę„Ÿć˜ć«ćŖć‚Šć¾ć—ćŸć€‚

static F z(Function<F, F> f) {
    Function<G, F> a = x -> f.apply(y -> x.apply(x).apply(y));
    G b = x -> f.apply(y -> x.apply(x).apply(y));
    return a.apply(b);
}

interface F extends Function<Integer, Integer> {}

interface G extends Function<G, F> {}

恓恮zćƒ”ć‚½ćƒƒćƒ‰ć‚’ē”Øć„ć¦ćƒ•ć‚£ćƒœćƒŠćƒƒćƒę•°ć‚’ę±‚ć‚ć‚‹å‡¦ē†ć‚’再åø°ć§ę›øć„ćŸć®ćŒę¬”ć«ćŖć‚Šć¾ć™ć€‚

Function<F, F> g = f -> n -> n <= 1 ? n : f.apply(n - 2) + f.apply(n - 1);
                                        //~~~~~~~~~~~~~~   ~~~~~~~~~~~~~~ 恓恮č¾ŗćŒå†åø°

F fib = z(g);

System.out.println(fib.apply(11)); //11ē•Ŗē›®ć®ćƒ•ć‚£ćƒœćƒŠćƒƒćƒę•°ć‚’å‡ŗåŠ›ć™ć‚‹

恂ćØćÆć‚»ćƒŸć‚³ćƒ­ćƒ³ć‚’ę¶ˆć™ē‚ŗ恫ćŖć‚“ć‚„ć‹ć‚“ć‚„ć„ć‚ć„ć‚ć‚„ć£ć¦äø€ē•Ŗęœ€åˆć®ć‚³ćƒ¼ćƒ‰ć«ćŖć‚Šć¾ć—ćŸć€‚

ć¾ćØ悁

Java 8ę™‚ä»£ć«ćŖć‚Šć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać§ć‚‚å†åø°ć‚’ä½æćˆć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚ ć“ć‚Œć«ć‚ˆć‚Šć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Java 8恌ē§˜ć‚ćŸć‚‹åÆčƒ½ę€§ć‚’ę›“ć«ę„Ÿć˜ć‚‹äŗ‹ćŒć§ćć¾ć—ćŸć€‚

今回ćÆęœ«å°¾å†åø°ęœ€é©åŒ–ć¾ć§č€ƒćˆć‚‹åŠ›ćÆę®‹ć£ć¦ć„ć¾ć›ć‚“ć§ć—ćŸćŒć€ 怌Javać«ć‚ˆć‚‹é–¢ę•°åž‹ćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°ć€ 恮7ē« ć‚’å‚č€ƒć«ć™ć‚Œć°ćŖ悓ćØ恋ćŖć‚‹ć‹ć‚‚ć—ć‚Œć¾ć›ć‚“ć€‚ ćŖ悉ćŖć„ć‹ć‚‚ć—ć‚Œć¾ć›ć‚“ć€‚

ćæćŖć•ć‚“ć‚‚ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Java悒ćÆć˜ć‚ć¦ćæć¾ć›ć‚“ć‹ļ¼Ÿ ćæć¾ć›ć‚“ć­ć€‚ ćÆ恄态恔悁悓ćŖ恕恄怂

ē¶šćļ¼š ć‚»ćƒŸć‚³ćƒ­ćƒ³ćƒ¬ć‚¹Javać§ćƒ•ć‚£ćƒœćƒŠćƒƒćƒć‚’Zć‚³ćƒ³ćƒ“ćƒćƒ¼ć‚æćŖ恗恧

]]>
Sun, 02 Nov 2014 00:00:00 +0900
http://backpaper0.github.io/2014/11/01/prefix_domain.html http://backpaper0.github.io/2014/11/01/prefix_domain.html <![CDATA[å‰ę–¹äø€č‡“ć®ę¤œē“¢ę”件ćØćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ #doma2]]> å‰ę–¹äø€č‡“ć®ę¤œē“¢ę”件ćØćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ #doma2

Doma 2 ć§å‰ę–¹äø€č‡“ć®ę¤œē“¢ę”ä»¶ć‚’ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć§ć©ć†ę‰±ć†ć‹č€ƒćˆćŸč©±ć§ć™ć€‚

馬é¹æę­£ē›“ć«ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć‚’ä½æ恆

SIerć§ę„­å‹™ć‚¢ćƒ—ćƒŖä½œć£ć¦ć‚‹ćØꤜē“¢ć—恦ēµęžœć‚’ć‚°ćƒŖ惃惉č”Øē¤ŗ恙悋ē”»é¢ćØć‹ć‚ˆćä½œć‚‹ćØꀝ恆悓恧恙恌态 ćć®éš›ć«å‰ę–¹äø€č‡“ć®ę¤œē“¢ę”件悒ꉱ恆äŗ‹ć‚‚å¤šć„ć®ć§ć™ć€‚

ä¾‹ćˆć°å¾“ę„­å“”ć‚’ę¤œē“¢ć™ć‚‹ćØćć«ę”ä»¶ć«å¾“ę„­å“”ē•Ŗ号ćØę‰€å±žéƒØ門ē•Ŗå·ć‚’ä½æ恈悋ćØć—ć¾ć™ć€‚ åŠ ćˆć¦ć€ć©ć”ć‚‰ć‚‚å‰ę–¹äø€č‡“恧ꤜē“¢ć™ć‚‹ćØć—ć¾ć™ć€‚ ć“ć®ę¤œē“¢ć‚’č”Œć†DAOćƒ”ć‚½ćƒƒćƒ‰ć‚’ä½•ć‚‚č€ƒćˆćšć«ę›ø恏ćØ恓恆ćŖć‚Šć¾ć™ć€‚

@Select
List<Emp> select(EmpId empId, DeptId deptId);

恔ćŖćæ恫SQLćƒ•ć‚”ć‚¤ćƒ«ćÆé›°å›²ę°—ć“ć‚“ćŖꄟ恘恧怂

SELECT /*%expand */*
  FROM emp
 WHERE empId LIKE /* empId */'AA%'
   AND deptId LIKE /* deptId */'BB%'

EmpIdćÆå¾“ę„­å“”ē•Ŗå·ć‚’č”Øć™ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć§ć™ć€‚ ꤜē“¢ę”件ćÆå‰ę–¹äø€č‡“ć€ć¤ć¾ć‚Šå¾“ę„­å“”ē•Ŗå·ć®å¾Œć‚ćŒę¬ ć‘ćŸäø­é€”半ē«ÆćŖēŠ¶ę…‹ć®ć‚‚ć®ćŒęø”恕悌悋åÆčƒ½ę€§ćŒć‚ć‚Šć¾ć™ć€‚ ćć†ć„ć£ćŸé …ē›®ć«EmpId悒ä½æē”Ø恙悋恮ćÆ恊恋恗恄恮恧ćÆćŖ恄恧恗悇恆恋ļ¼Ÿ

String悒ä½æ恆

恝恓恧ꤜē“¢ę”件悒걎ē”Øēš„ćŖåž‹ć§ć‚ć‚‹Stringć«å¤‰ę›“ć—ć¾ć™ć€‚

@Select
List<Emp> select(String empId, String deptId);

EmpId恮äøé©åˆ‡ćŖä½æē”ØćÆćŖ恏ćŖć‚Šć¾ć—ćŸćŒć€ select(deptId, empId) ćØć„ć†ćµć†ć«å¼•ę•°ć®é †ē•Ŗć‚’é–“é•ćˆć¦ć‚‚ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ę™‚ć«ę¤œå‡ŗ恕悌ćŖ恏ćŖć£ć¦ć—ć¾ć„ć¾ć—ćŸć€‚

ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹Prefix<DOMAIN>ć‚’ä½œć‚‹

ćØć„ć†ć‚ć‘ć§č€ƒćˆćŸć®ćŒPrefix<DOMAIN>ćØć„ć†ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć§ć™ć€‚

ę¬”ć«ć‚³ćƒ¼ćƒ‰ć‚’čØ˜č¼‰ć—ć¾ć™ć€‚

import java.util.Optional;

import org.seasar.doma.Domain;

@Domain(valueType = String.class, factoryMethod = "of")
public class Prefix<DOMAIN> {

    private final String value;

    private Prefix(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    public static <T> Prefix<T> of(String value) {
        return Optional.ofNullable(value).map(x -> new Prefix<T>(x)).orElse(null);
    }
}

åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æDOMAIN恫ćÆä»–ć®ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć‚’ćƒć‚¤ćƒ³ćƒ‰ć—ć¾ć™ć€‚

恓恮Prefix<DOMAIN>悒ä½æē”Ø恙悋ćØDAOćƒ”ć‚½ćƒƒćƒ‰ćÆę¬”ć®ć‚ˆć†ć«ćŖć‚Šć¾ć™ć€‚

@Select
List<Emp> select(Prefix<EmpId> empId, Prefix<DeptId> deptId);

恓悌恧态

  • ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć«é©ć—ćŖć„å‰ę–¹äø€č‡“恫ä½æē”Ø恙悋悈恆ćŖäø­é€”半ē«ÆćŖēŠ¶ę…‹ć‚’ęŒć¦ć‚‹
  • DAOćƒ”ć‚½ćƒƒćƒ‰ć®å¼•ę•°ć®é †ć‚’é–“é•ćˆć¦ć‚‚ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ę™‚ć«ę¤œå‡ŗ恧恍悋

ćØć„ć†ę€ć„ć‚’å®Ÿē¾ć™ć‚‹äŗ‹ćŒć§ćć¾ć—ćŸć€‚ ē¾ę™‚ē‚¹ć§ćÆ惙ć‚æćƒ¼ćŖę‰‹ę³•ć ćØę€ć£ć¦ć„ć¾ć™ć€‚

恓悌ćÆćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć‚’ć‚ø悧惍ćƒŖ惃ć‚ÆćŖć‚Æćƒ©ć‚¹ć«å‡ŗę„ć‚‹ćŒę•…ć«ćØć‚ŒćŸę‰‹ę³•ć§ć™ćŒć€ ćć†ć„ć£ćŸäŗ‹ćŒć§ćć‚‹ć‚ˆć†ć«ćŖć£ćŸć®ćÆ実ćÆē§ć®č¦ęœ›ć ć£ćŸć‚Šć—ć¾ć™ć€‚

恂恮ćØ恍ćÆ恓悓ćŖ恓ćØ恫ä½æ恈悋ćØćÆ露ēØ‹ć‚‚ę€ć£ć¦ć„ć¾ć›ć‚“ć§ć—ćŸ(惻Ļ‰<) ļ¾ƒļ¾ļ¾ļ¾Ÿļ¾›

Doma 2č‰Æ恄悈ļ¼

]]>
Sat, 01 Nov 2014 00:00:00 +0900
http://backpaper0.github.io/2014/11/01/funcitonal_programming_in_java.html http://backpaper0.github.io/2014/11/01/funcitonal_programming_in_java.html <![CDATA[怌Javać«ć‚ˆć‚‹é–¢ę•°åž‹ćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°ć€čŖ­ć‚“恠]]> 怌Javać«ć‚ˆć‚‹é–¢ę•°åž‹ćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°ć€čŖ­ć‚“恠

ć•ćć‚‰ć°ć•ć‚“ć«ēŒ®ęœ¬ć—ć¦é ‚ćć¾ć—ćŸć€‚ 恂悊恌ćØć†ć”ć–ć„ć¾ć™ļ¼

ē‰©ē†ēš„ć«č–„ć„ęœ¬ć§ć™ć—ć€ćƒ©ćƒ ćƒ€å¼ćØé–¢ę•°åž‹ćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°ćøć®å…„é–€ćØ恗恦č‰Æć„ęœ¬ć ćØę€ć„ć¾ć™ć€‚ ćƒćƒ¼ćƒ ć®å¾Œč¼©ć«čŖ­ć‚“ć§ę¬²ć—ć„ć€‚

é–¢ę•°åž‹ćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°ćøć®å…„é–€ć«äøåŗ¦ć„恄ćØ恄恆恓ćØć§ć€ę•°å¹“å‰ć«ć‚³ćƒƒćƒ—ęœ¬ć§å…„é–€ć‚’ęøˆć¾ć›ć¦ć„ćŸē§ćØ恗恦ćÆå°‘ć€…ē‰©č¶³ć‚ŠćŖć„ę°—ćŒć—ć¾ć—ćŸć€‚ 恟恠恗7ē« ćÆęœ«å°¾å†åø°ć®ęœ€é©åŒ–ć‚’č”Œć†ćØć„ć†å†…å®¹ć§ć€ćć“ćÆJavać‚³ćƒ³ćƒ‘ć‚¤ćƒ©ćÆć‚µćƒćƒ¼ćƒˆć—ć¦ć„ćŖ恄éƒØ分ćŖć®ć§čˆˆå‘³ę·±ćčŖ­ćæć¾ć—ćŸć€‚ ꁄ恚恋恗ćŖćŒć‚‰ć€ęœ«å°¾å†åø°ć®ęœ€é©åŒ–ć‚’č‡Ŗåˆ†ć§ę›ø恏ćØ恄恆ē™ŗęƒ³ćÆē„”ć‹ć£ćŸć®ć§å‚č€ƒć«ćŖć‚Šć¾ć™ć€‚

仄äø‹ć€ę°—恫ćŖć£ćŸē‚¹ć‚’ęŒ™ć’ć¾ć™ć€‚ ć‚æć‚¤ćƒć‚‚å«ć‚€ć€‚

  • 2怜3ćƒšćƒ¼ć‚øć€‚å®£č؀ēš„ćŖć‚³ćƒ¼ćƒ‰ćØćÆ恩恆恄恆恓ćØ恋悒态 恄恍ćŖć‚Šćƒ©ćƒ ćƒ€å¼ć‚’ē™»å “恕恛悋恮恧ćÆćŖ恏Java 7ć¾ć§ć®čŖžå½™ć§čŖ¬ę˜Žć—ć¦ć„ć‚‹ć®ćŒč‰Æ恄恧恙恭怂

  • 28ćƒšćƒ¼ć‚øć®ä¾‹2-7怂 ć“ć‚Œćƒ”ć‚½ćƒƒćƒ‰å‚ē…§ć«ćŖć£ć¦ć„ćŖć„ć®ć§ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć‚Øćƒ©ćƒ¼ć§ć™ć­ć€‚

  • 70ćƒšćƒ¼ć‚ø怂

    JDK恮ꖰ恗恄 ClosableStream ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹

    ćØć‚ć‚Šć¾ć™ćŒć€ćć®ć‚ˆć†ćŖć‚Æćƒ©ć‚¹ćÆć‚ć‚Šć¾ć›ć‚“ć€‚

    ćƒŖćƒŖćƒ¼ć‚¹å‰ć«ćÆć‚ć£ćŸć‚ˆć†ć§ć™ćŒ be6ca7197e0e ć‚ćŸć‚Šć§å‰Šé™¤ć•ć‚Œć¾ć—ćŸć€‚ 恔ćŖćæ恫 ClosableStream 恘悃ćŖćć¦ CloseableStream 恧恗恟怂

  • 89ćƒšćƒ¼ć‚øć®ä¾‹4-17怂 ć‚³ćƒ¼ćƒ‰ć‚’å¼•ē”Øć—ć¾ć™ć€‚

    try {
      final URL url =
        new URL("http://ichart.finance.yahoo.com/table.csv?s=" + ticker);
    
      final BufferedReader reader =
        new BufferedReader(new InputStreamReader(url.openStream()));
      final String data = reader.lines().skip(1).findFirst().get();
      final String[] dataItems = data.split(",");
      return new BigDecimal(dataItems[dataItems.length - 1]);
    } catch(Exception ex) {
      throw new RuntimeException(ex);
    }
    

    恓悌态reader恌closeć•ć‚Œć¦ć„ć¾ć›ć‚“ć€‚ reader悒try-with-resourcesć§å›²ć‚€ć¹ććØę€ć„ć¾ć™ć€‚

    try {
      final URL url =
        new URL("http://ichart.finance.yahoo.com/table.csv?s=" + ticker);
    
      try(final BufferedReader reader =
          new BufferedReader(new InputStreamReader(url.openStream()))) {
        final String data = reader.lines().skip(1).findFirst().get();
        final String[] dataItems = data.split(",");
        return new BigDecimal(dataItems[dataItems.length - 1]);
      }
    } catch(Exception ex) {
      throw new RuntimeException(ex);
    }
    
  • 130怜135ćƒšćƒ¼ć‚øć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć®é…å»¶ć€‚ 面ē™½ć„ć‚¢ćƒ—ćƒ­ćƒ¼ćƒć§ć™ćŒęœ€ēµ‚ēš„恫å‡ŗę„äøŠćŒć£ćŸć‚³ćƒ¼ćƒ‰ćÆå°‘ć€…åˆ†ć‹ć‚Šć«ćć‹ć£ćŸć—ć€synchronized悒ä½æć£ć¦ć„ćŸć®ć§Concurrency Utilitiesć§ć‚‚ć†ć”ć‚‡ć£ćØč‰Æć„ę„Ÿć˜ć«ę›ø恑悋悓恘悃ļ¼Ÿ ćØę€ć„č‰²ć€…č€ƒćˆćŸęŒ™ć’å„ć€ę¬”ć®ć‚ˆć†ćŖć‚³ćƒ¼ćƒ‰ć‚’ę›ø恄恦ćæć¾ć—ćŸćŒćŸć„ć—ć¦åˆ†ć‹ć‚Šć‚„ć™ććŖć‚Šć¾ć›ć‚“ć§ć—ćŸ_(:3ļ½£āˆ )_

    import java.util.concurrent.ExecutionException;
    import java.util.concurrent.FutureTask;
    import java.util.concurrent.atomic.AtomicReference;
    
    public class HoderNaive {
    
        private final AtomicReference<FutureTask<Heavy>> heavy = new AtomicReference<>();
    
        public Heavy getHeavy() {
            if (heavy.compareAndSet(null, new FutureTask<>(Heavy::new))) {
                heavy.get().run();
            }
            try {
                return heavy.get().get();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw new RuntimeException(e);
            } catch (ExecutionException e) {
                throw new RuntimeException(e.getCause());
            }
        }
    }
    
  • 161ćƒšćƒ¼ć‚ø怂

    ę­£ć—ć„5ć®éšŽä¹—ćØ态120ć®éšŽä¹—ć®äø€éƒØ

    120恧ćÆćŖ恏20000ć®éšŽä¹—ć§ć™ć­ć€‚

ć¾ćØ悁

é–¢ę•°åž‹ćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°ć«ć¾ć£ćŸćč§¦ć‚ŒćŸć“ćØ恌ćŖ恄äŗŗ悄苄ꉋ恫Java 8悒ꕙ恈悋ē«‹å “恫恂悋äŗŗ恫ćÆ恊恙恙悁恧恙怂

ć‚³ćƒƒćƒ—ęœ¬ć‚’čŖ­ć‚“恠ē؋åŗ¦ć«ćÆé–¢ę•°åž‹ćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°ć«č§¦ć‚ŒćŸć“ćØ恌恂悋äŗŗćÆ7ē« ć ć‘čŖ­ćæć¾ć—ć‚‡ć†ć€‚

]]>
Sat, 01 Nov 2014 00:00:00 +0900
http://backpaper0.github.io/2014/10/26/uragamiattack.html http://backpaper0.github.io/2014/10/26/uragamiattack.html <![CDATA[čæŽę’ƒć•ć‚Œć¦ććŸ #uragamiattack]]> čæŽę’ƒć•ć‚Œć¦ććŸ #uragamiattack

åœŸę›œę—„ćÆčæŽę’ƒä¼šć€ę—„ę›œę—„ćÆćƒ—ćƒč¦³å…‰ć§ę±äŗ¬å‹¢ć«ć‚ć”ć‚ƒćć”ć‚ƒē”˜ćˆć•ć›ć¦č²°ć£ć¦å¹øć›ć„ć£ć±ć„ć»ćć»ćć®é€±ęœ«ć§ć—ćŸć€‚

ć“ć®é€±ęœ«ć§ē§ć«é–¢ć‚ć£ć¦ćć‚ŒćŸćæćŖć•ć‚“ć€ęœ¬å½“ć«ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć—ćŸļ¼

ē‰¹ć«ć‚†ćØ悊恕悓ćÆåˆę—„ć«å¹¹äŗ‹ć‚’ć—ć¦ćć‚ŒćŸäøŠć«ēæŒę—„ć‚‚éŠć‚“ć§ćć‚Œć¦ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć—ćŸļ¼

恝悌ćØć—ć‚‡ć¼ć”ć‚€ć‚‚äŗŒę—„連ē¶šć§ę„›äŗŗć‚„ć£ć¦ćć‚Œć¦ć‚ć‚ŠćŒćØć†ć”ć–ć„ć¾ć—ćŸļ¼

恓悓ćŖē§ć§ć™ćŒć€ä»Šå¾ŒćØć‚‚å®œć—ććŠé”˜ć„ć—ć¾ć£ć™ā•­( ćƒ»ć…‚ćƒ»)Łˆ Ģ‘Ģ‘ ļ½øļ¾žļ½Æ !

]]>
Sun, 26 Oct 2014 00:00:00 +0900
http://backpaper0.github.io/2014/10/26/java_8_hotspot_meeting.html http://backpaper0.github.io/2014/10/26/java_8_hotspot_meeting.html <![CDATA[Java 8 HotSpot meetingć‚’é–‹å‚¬ć—ćŸ #kanjava]]> Java 8 HotSpot meetingć‚’é–‹å‚¬ć—ćŸ #kanjava

äøŠć«ćÆäøŠćŒć„悋悂悓恠ćŖ恁态ćØē™½ē›®å‰„恍ćŖćŒć‚‰ć‚»ćƒƒć‚·ćƒ§ćƒ³ć‚’ę‹č¦‹ć—ć¾ć—ćŸć€‚

仄äøŠć€‚

]]>
Sun, 26 Oct 2014 00:00:00 +0900
http://backpaper0.github.io/2014/10/04/stream_collect.html http://backpaper0.github.io/2014/10/04/stream_collect.html <![CDATA[Stream恮collectćƒ”ć‚½ćƒƒćƒ‰ć‚’å­¦ć¶]]> Stream恮collectćƒ”ć‚½ćƒƒćƒ‰ć‚’å­¦ć¶

Stream ć«ć‚ć‚‹ę•°å¤šćć®ćƒ”ć‚½ćƒƒćƒ‰ć®äø­ć§ć‚‚åˆ†ć‹ć‚Šč¾›ć„ę„Ÿć˜ćŒć™ć‚‹ collectćƒ”ć‚½ćƒƒćƒ‰ ć«ć¤ć„ć¦å­¦ć³ć¾ć™ć€‚

collect ćƒ”ć‚½ćƒƒćƒ‰ć®ę¦‚č¦

ē«Æēš„恫čæ°ć¹ć‚‹ćØ collectćƒ”ć‚½ćƒƒćƒ‰ ćÆ Stream<T> 悒 R ć«å¤‰ę›ć™ć‚‹ę“ä½œć§ć™ć€‚

ć‚ˆć‚Šč©³ć—ćčæ°ć¹ć‚‹ćØ态 Stream ć®å„č¦ē“ ( T )悒äø­é–“ć‚³ćƒ³ćƒ†ćƒŠ( A )ć«ęŠ˜ć‚Šē•³ć‚“ć å¾Œć«ęœ€ēµ‚ēš„ćŖēµęžœ( R )ć«å¤‰ę›ć™ć‚‹ę“ä½œć§ć™ć€‚

ę‹¬å¼§å†…ć®ć‚¢ćƒ«ćƒ•ć‚”ćƒ™ćƒƒćƒˆćÆ Collector 恌ꌁ恤3ć¤ć®åž‹å¤‰ę•°ć«åƾåæœć—ć¦ć„ć¾ć™ć€‚

  • T : Stream恮要ē“ ć®åž‹
  • A : ćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ« ćŖäø­é–“ć‚³ćƒ³ćƒ†ćƒŠć®åž‹
  • R : ꜀ēµ‚ēš„恫čæ”ć•ć‚Œć‚‹ēµęžœć®åž‹

ä¾‹ćˆć° Stream<Character> ć‚’å˜ē“”恫ē¹‹ć’恦 String ć«ć™ć‚‹å “åˆćÆ态 Stream ć®å„ Character ( T )悒 StringBuilder ( A )恫 append ć—ćŸå¾Œć« String ( R )ć«å¤‰ę›ć™ć‚‹ć€ ćØć„ć†ęµć‚Œć«ćŖć‚Šć¾ć™ć€‚

Note

é«˜ćƒ‘ćƒ•ć‚©ćƒ¼ćƒžćƒ³ć‚¹ć‚’å¾—ć‚‹ćŸć‚äø­é–“ć‚³ćƒ³ćƒ†ćƒŠćÆ ćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ« ćØćŖć£ć¦ć„ć¾ć™ć€‚ č©³ē“°ćÆ java.util.streamćƒ‘ćƒƒć‚±ćƒ¼ć‚øć®ć€ŒåÆ変ćƒŖ惀ć‚Æć‚·ćƒ§ćƒ³ć€ ć‚’å‚ē…§ćć ć•ć„怂

Collector ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ć®čŖ¬ę˜Ž

collectćƒ”ć‚½ćƒƒćƒ‰ ćÆå¼•ę•°ć« Collector ć‚’å–ć‚Šć¾ć™ć€‚ Collector ćÆć€Œé–¢ę•°ć‚’čæ”恙4ć¤ć®ćƒ”ć‚½ćƒƒćƒ‰ć€ćØ怌ē‰¹ę€§ć‚’čæ”ć™ćƒ”ć‚½ćƒƒćƒ‰ć€ć‚’ęŒć£ćŸć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ć§ć™ć€‚

怌ē‰¹ę€§ć€ć«ć¤ć„恦ćÆ後čæ°ć™ć‚‹ćØć—ć¦ć€ć¾ćšć€Œ4ć¤ć®é–¢ę•°ć€ć‚’čŖ¬ę˜Žć—ć¾ć™ć€‚

  • supplier : äø­é–“ć‚³ćƒ³ćƒ†ćƒŠć‚’ē”Ÿęˆć™ć‚‹é–¢ę•°ć€‚ é †ę¬”å‡¦ē†ć®ćØćęœ€åˆć®1å›žć ć‘å®Ÿč”Œć•ć‚Œć‚‹ć€‚ äø¦åˆ—処ē†ć®ćØ恍ćÆč¤‡ę•°å›žå®Ÿč”Œć•ć‚Œć‚‹ć“ćØ恌恂悋怂
  • accumulator : äø­é–“ć‚³ćƒ³ćƒ†ćƒŠćøå€¤ć‚’ęŠ˜ć‚Šē•³ć‚€é–¢ę•°ć€‚ Stream 恮要ē“ ć®ę•°ć ć‘å®Ÿč”Œć•ć‚Œć‚‹ć€‚
  • combiner : ćµćŸć¤ć®äø­é–“ć‚³ćƒ³ćƒ†ćƒŠć‚’ć²ćØć¤ć«ćƒžćƒ¼ć‚øć™ć‚‹é–¢ę•°ć€‚ äø¦åˆ—処ē†ć®ćØćć«å®Ÿč”Œć•ć‚Œć‚‹ć“ćØ恌恂悋怂
  • finisher : äø­é–“ć‚³ćƒ³ćƒ†ćƒŠć‹ć‚‰ęœ€ēµ‚ēš„ćŖēµęžœćøå¤‰ę›ć™ć‚‹ć€‚ ęœ€å¾Œć®1å›žć ć‘å®Ÿč”Œć•ć‚Œć‚‹ć€‚

Note

ę—„ęœ¬čŖžJavadoc恮čŖ¬ę˜Žę–‡ć§ćÆćć‚Œćžć‚Œć€Œć‚µćƒ—ćƒ©ć‚¤ćƒ¤ć€ć€Œć‚¢ć‚­ćƒ„ćƒ ćƒ¬ćƒ¼ć‚æć€ć€Œć‚³ćƒ³ćƒć‚¤ćƒŠć€ć€Œćƒ•ć‚£ćƒ‹ćƒƒć‚·ćƒ£ć€ćØč”ØčØ˜ć•ć‚Œć¦ć„ć¾ć™ć€‚ 勉強会ćŖ恩恧čŖ­ćæę–¹ć‚’ē‰½åˆ¶ć—åˆć‚ćŖćć¦ęøˆćæć¾ć™ć­ļ¼

ę–‡å­—ć‚’ēµåˆć™ć‚‹ Collector ć®ä¾‹

ä¾‹ćˆć° Character 恮 Stream 悒 StringBuilder ćøꊘ悊ē•³ć‚“ć§ęœ€ēµ‚ēš„恫 String ć«å¤‰ę›ć™ć‚‹ćØć„ć†å‡¦ē†ć‚’č€ƒćˆć¦ćæć¾ć™ć€‚

Collector 恌čæ”ć™é–¢ę•°ćÆćć‚Œćžć‚Œę¬”ć®ć‚ˆć†ćŖ処ē†ć‚’č”Œć†ć‚ˆć†ć«ć—ć¾ć™ć€‚

  • supplier 恧 StringBuilder ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ē”Ÿęˆć™ć‚‹
  • accumulator 恧 StringBuilder ćø Character 悒 append 恙悋
  • combiner ć§ćµćŸć¤ć® StringBuilder ć‚’ć²ćØć¤ć«ćƒžćƒ¼ć‚ø恙悋
  • finisher 恧 StringBuilder 悒 toString 恙悋

å„é–¢ę•°ć®ć‚³ćƒ¼ćƒ‰ć‚’čØ˜č¼‰ć—ć¾ć™ć€‚

  • supplier

    å¼•ę•°ćŖ恗恧 StringBuilder ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’čæ”ć—ć¾ć™ć€‚

    () -> new StringBuilder()
    

    ć¾ćŸćÆć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ参ē…§ć§ć‚‚č‰Æ恄恧恙怂

    StringBuilder::new
    
  • accumulator

    StringBuilder ćØ Character ć‚’å—ć‘å–ć£ć¦ append ć—ć¾ć™ć€‚ ęˆ»ć‚Šå€¤ćÆ void 恧恙怂

    (sb, c) -> sb.append(c)
    

    ć¾ćŸćÆćƒ”ć‚½ćƒƒćƒ‰å‚ē…§ć§ć‚‚č‰Æ恄恧恙怂

    StringBuilder::append
    
  • combiner

    ćµćŸć¤ć® StringBuilder ć‚’å—ć‘å–ć£ć¦ć²ćØ恤恮 StringBuilder ć«ćƒžćƒ¼ć‚ø恗恦čæ”ć—ć¾ć™ć€‚

    (sb1, sb2) -> sb1.append(sb2);
    

    ć¾ćŸćÆćƒ”ć‚½ćƒƒćƒ‰å‚ē…§ć§ć‚‚č‰Æ恄恧恙怂

    StringBuilder::append
    
  • finisher

    StringBuilder ć‚’å—ć‘å–ć£ć¦ String ćøå¤‰ę›ć—ć¦čæ”ć—ć¾ć™ć€‚

    sb -> sb.toString()
    

    ć¾ćŸćÆćƒ”ć‚½ćƒƒćƒ‰å‚ē…§ć§ć‚‚č‰Æ恄恧恙怂

    StringBuilder::toString
    

恓悌悉4ć¤ć®é–¢ę•°ć‚’ć‚‚ćØ恫恗恦 Collector ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ē”Ÿęˆć—ć¾ć™ć€‚ ꄚē›“恫 Collector ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ć‚’å®Ÿč£…ć—ćŸć‚Æćƒ©ć‚¹ć‚’ä½œć£ć¦ć‚‚č‰Æć„ć®ć§ć™ćŒ Collector 恮 ofćƒ”ć‚½ćƒƒćƒ‰ ć‚’åˆ©ē”Øć™ć‚‹ć®ćŒę„½ć§ć™ć€‚

Collector<Character, StringBuilder, String> characterJoiner =
        Collector.of(() -> new StringBuilder(),     //supplier
                     (sb, c) -> sb.append(c),       //accumulator
                     (sb1, sb2) -> sb1.append(sb2), //combiner
                     sb -> sb.toString()));         //finisher

//ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ参ē…§ćƒ»ćƒ”ć‚½ćƒƒćƒ‰å‚ē…§ćƒćƒ¼ć‚øćƒ§ćƒ³
Collector<Character, StringBuilder, String> characterJoiner =
        Collector.of(StringBuilder::new,        //supplier
                     StringBuilder::append,     //accumulator
                     StringBuilder::append,     //combiner
                     StringBuilder::toString)); //finisher

恓恮 Collector 悒ä½æć£ć¦ę–‡å­—ć‚’é€£ēµć—恦ćæć¾ć™ć€‚

String s = Stream.of('h', 'e', 'l', 'l', 'o').collect(characterJoiner);
System.out.println(s); //hello

Collector 恮ē‰¹ę€§

Collector ćÆćƒć‚¹ćƒˆć—ćŸåˆ—ęŒ™åž‹ Characteristics 悒ä½æē”Ø恗恦ćæć£ć¤ć®ē‰¹ę€§ć‚’č”Ø恙恓ćØćŒć§ćć¾ć™ć€‚ 各ē‰¹ę€§ć«ć¤ć„恦čŖ¬ę˜Žć—ć¾ć™ć€‚

  • CONCURRENT : ć²ćØ恤恮ēµęžœć‚³ćƒ³ćƒ†ćƒŠć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć«åÆ¾ć—ć¦č¤‡ę•°ć‚¹ćƒ¬ćƒƒćƒ‰ć‹ć‚‰ accumulator ć‚’å®Ÿč”Œć§ćć‚‹ē‰¹ę€§ć§ć™ć€‚

    ć¤ć¾ć‚Šę¬”ć®ć‚ˆć†ćŖ処ē†ć‚’č”Œć£ć¦ć‚‚äøę•“åˆćŒčµ·ć“ć‚‰ćŖć‘ć‚Œć°ć€ć“ć®ē‰¹ę€§ć‚’ęŒć£ć¦ć„ć‚‹ćØčØ€ćˆć¾ć™ć€‚

    A acc = supplier.get(); //äø­é–“ć‚³ćƒ³ćƒ†ćƒŠ
    
    new Thread(() -> accumulator.accept(acc, t1)).start();
    
    new Thread(() -> accumulator.accept(acc, t2)).start();
    
  • IDENTITY_FINISH : finisher 恌ꁒē­‰é–¢ę•°ć§ć‚悊态ēœē•„恧恍悋ē‰¹ę€§ć§ć™ć€‚

    ć¤ć¾ć‚Š finisher ćŒę¬”ć®ć‚ˆć†ćŖå®Ÿč£…ć«ćŖć‚‹å “åˆć€ć“ć®ē‰¹ę€§ć‚’ęŒć£ć¦ć„ć‚‹ćØčØ€ćˆć¾ć™ć€‚

    Function<A, R> finisher = a -> (R) a;
    
  • UNORDERED : ę“ä½œćŒč¦ē“ ć®é †åŗć«ä¾å­˜ć—ćŖ恄ē‰¹ę€§ć§ć™ć€‚

ć„ćšć‚Œć®ē‰¹ę€§ć‚‚ę€§čƒ½å‘äøŠć®ćŸć‚ć®ć‚‚恮ćØę€ć‚ć‚Œć¾ć™ć€‚ 恧恙恮恧ē‰¹ę€§ć‚’ć²ćØ恤悂ꌁ恟ćŖ恄ćØć—ć¦ć‚‚č‡“å‘½ēš„ćŖ問锌ćÆē„”恕恝恆恧恙怂 悀恗悍č‡Ŗ作 Collector ćŒć©ć®ē‰¹ę€§ć‚’ęŒć£ć¦ć„ć‚‹ć‹åˆ†ć‹ć‚‰ćŖć„ć€ć„ć¾ć„ć”č‡Ŗäæ”恌ē„”恄ćŖć©ć®å “åˆćÆ Characteristics 悒čØ­å®šć—ćŖć„ę–¹ćŒč‰Æ恄恋悂ēŸ„ć‚Œć¾ć›ć‚“ć­ć€‚

Collector ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ē”Ÿęˆć™ć‚‹éš›ć«ē‰¹ę€§ć‚’äøŽćˆćŸć„å “合ćÆ of ćƒ”ć‚½ćƒƒćƒ‰ć®ē¬¬5å¼•ę•°(åÆå¤‰é•·å¼•ę•°ć§ć™)悒ä½æē”Øć—ć¾ć™ć€‚

Collector<T, A, R> collector =
        Collector.of(supplier, accumulator, combiner, finisher,
                     Characteristics.CONCURRENT,
                     Characteristics.IDENTITY_FINISH,
                     Characteristics.UNORDERED);

äø­é–“ć‚³ćƒ³ćƒ†ćƒŠć®åž‹å¤‰ę•°ć«ć¤ć„ć¦

Collector ćÆč‡Ŗåˆ†ć§å®Ÿč£…ć—ć¦ć‚‚č‰Æ恄恧恙恌态悈恏ä½æ悏悌恝恆ćŖå®Ÿč£…ć‚’čæ”恙 static ćƒ”ć‚½ćƒƒćƒ‰ć‚’å¤šę•°å®šē¾©ć—ćŸ Collectors ćØć„ć†ćƒ¦ćƒ¼ćƒ†ć‚£ćƒŖćƒ†ć‚£ć‚Æćƒ©ć‚¹ćŒęä¾›ć•ć‚Œć¦ć„ć¾ć™ć€‚

Collectors ć®ćƒ”ć‚½ćƒƒćƒ‰äø€č¦§ć‚’ēœŗć‚ć¦ęˆ»ć‚Šå€¤ć«ę³Øē›®ć™ć‚‹ćØ恻ćØć‚“ć©ćŒ Collector<T, ?, R> ćØćŖć£ć¦ćŠć‚Šć€ äø­é–“ć‚³ćƒ³ćƒ†ćƒŠć®åž‹ćŒćƒÆć‚¤ćƒ«ćƒ‰ć‚«ćƒ¼ćƒ‰ć§å®£čØ€ć•ć‚Œć¦ć„ć‚‹ć“ćØćŒåˆ†ć‹ć‚Šć¾ć™ć€‚

å†’é ­ć§ć‚‚ę›øćć¾ć—ćŸćŒ Stream 恮 collectćƒ”ć‚½ćƒƒćƒ‰ ćÆ Stream<T> 悒 R ć«å¤‰ę›ć™ć‚‹ę“ä½œć§ć™ć€‚ 恓恮ćØćć® T ćØ R ćÆ Collector<T, A, R> ć®ćć‚Œć«åƾåæœć—ć¾ć™ć€‚ ć¤ć¾ć‚Š collectćƒ”ć‚½ćƒƒćƒ‰ 悒ä½æć†ć²ćØā€•ā€• Collector ć®åˆ©ē”Ø者ā€•ā€•ć«ćØć£ć¦ćÆäø­é–“ć‚³ćƒ³ćƒ†ćƒŠćŒä½•ć§ć‚ć‚‹ć‹ę„č­˜ć™ć‚‹åæ…要ćÆćŖ恄悓恧恙恭怂

ć“ć®ć‚ˆć†ć«åˆ©ē”Ø者恫ćÆäøč¦ćŖäø­é–“ć‚³ćƒ³ćƒ†ćƒŠć®åž‹ćŒč¦‹ćˆć¦ćŠć‚Šć€ å®Ÿéš›ć«ćÆćƒÆć‚¤ćƒ«ćƒ‰ć‚«ćƒ¼ćƒ‰ćŒå®£čØ€ć•ć‚Œć¦ć„ć‚‹ćØ恄恆恮ćÆå°‘ć—ę®‹åæµć§ć‚悊态 collectćƒ”ć‚½ćƒƒćƒ‰ ć‚’ć‚„ć‚„ć“ć—ćę„Ÿć˜ć•ć›ć¦ć„ć‚‹äø€å› ć‹ć‚‚ēŸ„悌ćŖ恄ćŖ态ćØę€ć„ć¾ć™ć€‚

ćØ恄恆悏恑恧 Collectors ć®å„ćƒ”ć‚½ćƒƒćƒ‰ć§ć®ćƒÆć‚¤ćƒ«ćƒ‰ć‚«ćƒ¼ćƒ‰ćÆē©ŗę°—ć®ć‚ˆć†ć«ę‰±ć†ć“ćØć«ć—ć¾ć—ć‚‡ć†ć€‚

ć¾ćØ悁态恝悌ćØč‡Ŗ分ćø恮å®æ锌

  • ä½æć†å“ćØ恗恦ćÆäø­é–“ć‚³ćƒ³ćƒ†ćƒŠć®å­˜åœØćÆē„”視悋
  • ć‚ˆćåˆ†ć‹ć‚‰ć‚“ć‹ć£ćŸć‚‰ Characteristics ćÆ付äøŽć—ćŖ恄
  • 何ćÆćØ悂恂悌 collectćƒ”ć‚½ćƒƒćƒ‰ ä¾æ利

ć“ć£ć‹ć‚‰å®æé”Œć€‚

  • Scala恮 scan ćæ恟恄ćŖć‚„ć¤ć‚’å®Ÿč£…ć—ć¦ćæ悋怂

    恓悓ćŖ悄恤恧恙怂

    //恓悌ćÆScalać‚³ćƒ¼ćƒ‰
    val xs = 1 to 5 toList
    xs.scan(0)(_ + _) //0, 1, 3, 6, 10, 15
    

čæ½čؘļ¼šå®æé”Œć‚„ć£ćŸ

]]>
Sat, 04 Oct 2014 00:00:00 +0900
http://backpaper0.github.io/2014/10/04/stream_methods.html http://backpaper0.github.io/2014/10/04/stream_methods.html <![CDATA[Streamć®ćƒ”ć‚½ćƒƒćƒ‰ć‚’ę“ä½œć®ēØ®é”žåˆ„ć§äø€č¦§ć«ć—ćŸ]]> Streamć®ćƒ”ć‚½ćƒƒćƒ‰ć‚’ę“ä½œć®ēØ®é”žåˆ„ć§äø€č¦§ć«ć—ćŸ

Stream ć®ę“ä½œćÆ äø­é–“ę“ä½œ ćØ ēµ‚ē«Æę“ä½œ ćŒć‚ć‚Šć¾ć™ćŒć€ å„ćƒ”ć‚½ćƒƒćƒ‰ćŒć©ć”ć‚‰ć®ę“ä½œć«ć‚ćŸć‚‹ć®ć‹äø€č¦§ć«ć—恦ćæć¾ć—ćŸć€‚

Note

äø­é–“ę“ä½œćØēµ‚ē«Æę“ä½œć®č©³ē“°ćÆ ć‚¹ćƒˆćƒŖćƒ¼ćƒ ę“ä½œćØćƒ‘ć‚¤ćƒ—ćƒ©ć‚¤ćƒ³ ć‚’å‚ē…§ć—ć¦ćć ć•ć„ć€‚

恔ćŖćæ恫äø€č¦§äø­ć® T ćÆ Stream ćŒå–ć‚‹åž‹å¤‰ę•°ć§ć™ć€‚ ä¾‹ćˆć° String[] ć‚’ć‚¹ćƒˆćƒŖćƒ¼ćƒ åŒ–ć—ćŸå “åˆ T ćÆ String 恫ćŖć‚Šć¾ć™ć€‚

恝悌恋悉 S ćÆ BaseStream ćŒå–ć‚‹åž‹å¤‰ę•°ć§ Stream<T> ć‚’ęŒ‡ć—ć¾ć™ć€‚

ćć®ä»–(äø­é–“ę“ä½œćƒ»ēµ‚ē«Æę“ä½œć®ć©ć”ć‚‰ć«ć‚‚åˆ†é”žć•ć‚ŒćŖ恄悂恮)

]]>
Sat, 04 Oct 2014 00:00:00 +0900
http://backpaper0.github.io/2014/09/30/jersey_rx_client.html http://backpaper0.github.io/2014/09/30/jersey_rx_client.html <![CDATA[Jersey Client恮Rxć‚µćƒćƒ¼ćƒˆć‚’č»½ć€œćč©¦ć™]]> Jersey Client恮Rxć‚µćƒćƒ¼ćƒˆć‚’č»½ć€œćč©¦ć™

Jersey 2.13恌ćƒŖćƒŖćƒ¼ć‚¹ć•ć‚Œć¾ć—ćŸć€‚

ćƒŖćƒŖćƒ¼ć‚¹ćƒŽćƒ¼ćƒˆć‚’č¦‹ć‚‹ćØ [JERSEY-2639] - Jersey Client - Add Support for Rx ćØć„ć†ć®ćŒć‚ć£ćŸć®ć§č©¦ć—ć¦ćæć¾ć—ćŸć‚“ć€‚

pom.xml恫ēŖć£č¾¼ć‚€dependency

jersey-rx-clientć®å®Ÿč£… 恫ćÆ态

  • jersey-rx-client-guava
  • jersey-rx-client-java8
  • jersey-rx-client-jsr166e
  • jersey-rx-client-rxjava

ćŒć‚ć‚‹ć£ć½ć„ć§ć™ćŒRxJavaćØć‹ć‚ˆćåˆ†ć‹ć‚“ćŖć„ć®ć§ä»Šå›žćÆjava8ć§č©¦ć—ć¾ć™ć€‚

<dependency>
  <groupId>org.glassfish.jersey.ext.rx</groupId>
  <artifactId>jersey-rx-client-java8</artifactId>
</dependency>

ć‚Æćƒ©ć‚¤ć‚¢ćƒ³ćƒˆć‚³ćƒ¼ćƒ‰

åå‰ć‚’ęø”ć—ćŸć‚‰ć“ć‚“ć«ć”ćÆčØ€ć£ć¦ćć‚Œć‚‹ć„ć¤ć‚‚ć®ćƒŖć‚½ćƒ¼ć‚¹ć‚Æćƒ©ć‚¹ćŒć‚ć£ćŸćØć—ć¾ć™ć€‚

ć¾ćšćÆ恵恤恆恮JAX-RSć‚Æćƒ©ć‚¤ć‚¢ćƒ³ćƒˆć®ć‚³ćƒ¼ćƒ‰ć€‚

WebTarget target = ClientBuilder.newClient().target("http://localhost:8080/rest/hello");

String resp = target.queryParam("name", "world")
                    .request()
                    .get(String.class);

System.out.println(resp); //Hello, world!

恆悀怂ꙮ通怂

ꬔ恫Rxęæć®ć‚³ćƒ¼ćƒ‰ć§ć™ć€‚

WebTarget target = ClientBuilder.newClient().target("http://localhost:8080/rest/hello");

CompletionStage<String> stage = RxCompletionStage.from(target)
                                    .queryParam("name", "world")
                                    .request()
                                    .rx()
                                    .get(String.class);

stage.thenAccept(s -> System.out.println(s)); //Hello, world!

恔覧恮通悊 CompletionStage ć§ć‚ć‚Œć“ć‚Œć§ćć‚‹ć£ć½ć„ć§ć™ć€‚

ć¾ćØ悁

RxJavaå­¦ć¼ć†ć‹ćŖ怂

]]>
Tue, 30 Sep 2014 00:00:00 +0900
http://backpaper0.github.io/2014/09/26/nullpo.html http://backpaper0.github.io/2014/09/26/nullpo.html <![CDATA[ć¬ć‚‹ć½]]> ć¬ć‚‹ć½

恂ćŖ恟ćØć¬ć‚‹ć½ć€‚

ę‹”å¼µforćƒ«ćƒ¼ćƒ—

int[] xs = null;
for (int x : xs) {
}

é…åˆ—ćƒ»ćƒŖć‚¹ćƒˆćŒ null ćŖć‚‰ę‹”å¼µforćƒ«ćƒ¼ćƒ—ć§ć¬ć‚‹ć½ć£ļ¼

ć‚¢ćƒ³ćƒœć‚Æć‚·ćƒ³ć‚°

Integer x = null;
int y = x;

惗ćƒŖćƒŸćƒ†ć‚£ćƒ–ćƒ©ćƒƒćƒ‘ćƒ¼ć‚’ćƒ—ćƒŖćƒŸćƒ†ć‚£ćƒ–ć«ć‚¢ćƒ³ćƒœć‚Æć‚·ćƒ³ć‚°ć™ć‚‹ćØćć«ć¬ć‚‹ć½ć£ļ¼

ę™®é€šć«ę•°å­—ć®č¶³ć—ē®—ćØć‹ć—ć¦ć¦ć¬ć‚‹ć½ćŒå‡ŗ恟悉恓悌悒ē–‘ć„ć¾ć™ć€‚

throw

UnsupportedOperationException e = null;
throw e;

null 悒 throw ć—ćŸć‚‰ęŠ•ć’ć‚‰ć‚Œć‚‹ä¾‹å¤–ćÆć¬ć‚‹ć½ć£ļ¼

String switch

String x = null;
switch (x) {
}

String 恮switchę–‡ć§ć¬ć‚‹ć½ć£ļ¼

try with resources

try (AutoCloseable x = null) {
}

try with resources恧 AutoCloseable 恌 null ćŖ悉 close 恙悋ćØćć«ć¬ć‚‹ć½ć£ļ¼ć«ćÆ ćŖ悉ćŖ恄 怂

close ć®å‰ć« null 惁悧惃ć‚Æć™ć‚‹ć‚ˆć†ć«ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć•ć‚Œć¾ć™ć€‚

ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ

new Hoge(a -> a.x.length());

ä½•ć®å¤‰å“²ć‚‚ē„”ć„ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æć§ć™ćŒć€ć¬ć‚‹ć½ć£ļ¼ć«ćŖć‚‹ć‚±ćƒ¼ć‚¹ćŒć‚ć‚Šć¾ć™ć€‚

class Hoge {

    final String x;

    public Hoge(Consumer<Hoge> c) {
        c.accept(this);
        this.x = "hoge";
    }
}

ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ x ćÆfinalćŖć®ć«ć¬ć‚‹ć½ć«ćŖ悋ćØć„ć†ć‚¢ćƒ¬ć§ć™ć€‚ ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æēµ‚ć‚ć£ć¦ćŖć„ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ćÆćƒ”ć‚½ćƒƒćƒ‰ć«ęø”恕ćŖć„ć§ćŠćć¾ć—ć‚‡ćƒ¼ć€‚

ćƒ”ć‚½ćƒƒćƒ‰å®Ÿč”Œ

Hoge x = null;
x.foobar();

ć¬ć‚‹ć½ć£ļ¼ 恫ćÆćŖ悉ćŖć„ć‚±ćƒ¼ć‚¹ćŒć‚ć‚Šć¾ć™ 怂

恓悌怂

class Hoge {

    static void foobar() {
    }
}

ć¾ć‚å®Ÿéš›ćÆ恓悓ćŖć‚³ćƒ¼ćƒ‰ć«å‡ŗä¼šć†ć“ćØćÆē„”恄恧恗悇恆怂

ē„”恄恧恗悇恆怂

ęœ¬ę—„ć®ć‚³ćƒ¼ćƒ‰

]]>
Fri, 26 Sep 2014 00:00:00 +0900
http://backpaper0.github.io/2014/09/14/kotlinkansai.html http://backpaper0.github.io/2014/09/14/kotlinkansai.html <![CDATA[関č„æKotlinå‹‰å¼·ä¼šć‚„ć£ćŸ #kotlin]]> 関č„æKotlinå‹‰å¼·ä¼šć‚„ć£ćŸ #kotlin

ę±äŗ¬ć‹ć‚‰Kotlinć‚Øćƒćƒ³ć‚ø悧ćƒŖć‚¹ćƒˆ(č‡Ŗē§°)恮 恟悍恆恕悓 ć‚’ćŠę‹›ćć—ć¦ē„žęˆø恧Kotlinć®å‹‰å¼·ä¼šć‚’ć ć‚‰ć ć‚‰ć‚„ć£ćŸć£ćŸć€‚

ē§ć®ē™ŗč”Ø

要ē“„恙悋ćØ态

  • Kotlin恧JAX-RSćÆę™®é€šć«ć§ćć‚‹ć‘ć‚Œć©Kotlin恮č‰Æć•ć‚’ę“»ć‹ć—ćć‚ŒćŖć„ć®ćŒć”ć‚‡ć£ćØ恏悄恗恄
  • JVMč؀čŖžćÆ꜀ēµ‚ēš„恫ćÆjavapć™ć‚Œć°ć‚¢ćƒ¬
  • ć—ć‚‡ć¼ć”ć‚€ćƒć‚æ恫恗恦恔悁悓ćŖ态今åŗ¦ć”ćÆć‚“ćŠć”ć‚‹ć‚ćƒ¼

ćØ恄恆ꄟ恘恧恙怂

恓恖恑恕悓恮LT

関č„æKotlinå‹‰å¼·ä¼šć®äø€é€±é–“å‰ć«ScalaMatsurić§ćŸć‚ć†ć•ć‚“ć«ć€ŒLTć‚„ć£ć¦ćć ć•ć„ć‚ˆć€ćØē„”čŒ¶ęŒÆ悊恕悌恟 恓恖恑恕悓 恮LT怂

恊金恌nullćŖ恮ćÆ恄恑ćŖ恄ćØę€ć„ć¾ć™ćŒć€ćŠé‡‘ć‚’nullć«ć—ćŸć®ćÆ恔č‡Ŗčŗ«ćŖć®ć§ć‚¢ćƒ¬ć§ć™ć­ć€‚

ćŸć‚ć†ć•ć‚“ć®ē™ŗč”Ø

éŽåŽ»ć®ć‚¹ćƒ©ć‚¤ćƒ‰ć‹ć‚‰ć„ćć¤ć‹ć‚’éøć‚“ć§å¤§äŗ‹ćŖéƒØåˆ†ć‚’ć‹ć„ć¤ć¾ć‚“ć§č©±ć—ć¦ćć‚Œć¾ć—ćŸć€‚

ć¾ć£ćŸć‚Šć—ćŸé›°å›²ę°—ć ć£ćŸćØćÆ恄恈2ę™‚é–“ć»ć©ćƒŽćƒ³ć‚¹ćƒˆćƒƒćƒ—ć§ćŠč©±ć—ć¦ćć ć•ć£ćŸć®ćÆć™ć”ć‹ć£ćŸć€‚

ć™ć”ć„å‹¢ć„ć§Kotlin悒åøåŽć§ććŸę°—ćŒć™ć‚‹ć®ć§ć‚ć‚‹ē؋åŗ¦å®šē€ć™ć‚‹ć‚ˆć†å¾©ēæ’恗恦恊恋恭恰ćŖć‚Šć¾ć›ć‚“ć€‚

ć¾ćØ悁

  • Kotlin面ē™½ć„
  • 恧悂REPLćÆć‚ˆćč½ć”ć‚‹ć‹ć‚‰ Kotlin Web Demo 恧遊恶ćØč‰Æ恄
  • ć‚¤ćƒ™ćƒ³ćƒˆå¾Œć€åŗ—å¤‰ćˆć¤ć¤5ę™‚é–“ćć‚‰ć„é£²ćæé£Ÿć„ć—ć¦ć¦ć‚¤ćƒ™ćƒ³ćƒˆć‚ˆć‚Šć‚‚é•·ć„ć‚„ć‚“ć‘ēš„ćŖ
  • ćć®é£²ćæé£Ÿć„ć‚‚č¾¼ćæć§ć‚ć”ć‚ƒćć”ć‚ƒę„½ć—ć‹ć£ćŸ
]]>
Sun, 14 Sep 2014 00:00:00 +0900
http://backpaper0.github.io/2014/08/27/wildflykansai.html http://backpaper0.github.io/2014/08/27/wildflykansai.html <![CDATA[関č„æWildFlyå‹‰å¼·ä¼šć‚’ć‚„ć£ćŸ #wildflykansai]]> 関č„æWildFlyå‹‰å¼·ä¼šć‚’ć‚„ć£ćŸ #wildflykansai

ć‚„ć‚Šć¾ć—ćŸć€‚

@nekop恕悓 ć«ćŠč¶Šć—é ‚ć„ć¦ćŸć£ć·ć‚ŠćØå–‹ć£ć¦č²°ć£ć¦å¤§ęŗ€č¶³ć§ć—ćŸļ¼

ćØ恄恆恋ē§ćÆćŠę˜¼ć”ćÆ悓悒äø€ē·’ć•ć›ć¦č²°ć£ćŸę™‚ē‚¹ć§ć‹ćŖ悊ęŗ€č¶³ć—ćŸć€‚

ćƒÆć‚æć‚Æć‚·ć®ć‚¹ćƒ©ć‚¤ćƒ‰ć‚“ć€‚

]]>
Wed, 27 Aug 2014 00:00:00 +0900
http://backpaper0.github.io/2014/08/02/glassfish_admingui.html http://backpaper0.github.io/2014/08/02/glassfish_admingui.html <![CDATA[GlassFish 3.1.2.2恮ē®”ē†ć‚³ćƒ³ć‚½ćƒ¼ćƒ«ć§localhostć‚’ćƒ—ćƒ­ć‚­ć‚·ēµŒē”±ć—ć‚ˆć†ćØć—ć¦ć„ć¦å›°ć£ćŸć‘ć©č§£ę±ŗć—ćŸč©±]]> GlassFish 3.1.2.2恮ē®”ē†ć‚³ćƒ³ć‚½ćƒ¼ćƒ«ć§localhostć‚’ćƒ—ćƒ­ć‚­ć‚·ēµŒē”±ć—ć‚ˆć†ćØć—ć¦ć„ć¦å›°ć£ćŸć‘ć©č§£ę±ŗć—ćŸč©±

ē¾č±”

ćƒ­ćƒ¼ć‚«ćƒ«ć§GlassFish 3.1.2.2ć‚’å‹•ć‹ć—ć¦ē®”ē†ć‚³ćƒ³ć‚½ćƒ¼ćƒ«ć‚’開恓恆ćØę€ć£ćŸć‚‰é–‹ć‘ćŖćć¦å›°ć‚Šć¾ć—ćŸć€‚

具体ēš„恫ćÆę¬”ć®ć‚ˆć†ćŖē—‡ēŠ¶ć§ć™ć€‚

  • ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®ćƒ‰ćƒ”ć‚¤ćƒ³ domain1 恧ē®”ē†ć‚³ćƒ³ć‚½ćƒ¼ćƒ«ć®čµ·å‹•ć«ć‹ćŖ悊Ꙃ間恌恋恋悋怂
  • domain1 ćÆē®”ē†ćƒ‘ć‚¹ćƒÆćƒ¼ćƒ‰ćŒčØ­å®šć•ć‚Œć¦ć„ćŖć„ć®ć§ćƒ­ć‚°ć‚¤ćƒ³ćŖ恗恧ē®”ē†ć‚³ćƒ³ć‚½ćƒ¼ćƒ«ć‚’開恑悋ćÆ恚ćŖć®ć«ćƒ­ć‚°ć‚¤ćƒ³ćƒ•ć‚©ćƒ¼ćƒ ćŒč”Øē¤ŗ恕悌悋怂
  • ćƒ¦ćƒ¼ć‚¶ćƒ¼åć ć‘å…„åŠ›ć—ć¦ćƒ­ć‚°ć‚¤ćƒ³ć—ć‚ˆć†ćØ恙悋ćØ恋ćŖć‚Šę™‚é–“ćŒć‹ć‹ć£ćŸęŒ™ć’å„ćƒ­ć‚°ć‚¤ćƒ³ć§ććŖ恄怂

ē’°å¢ƒ

  • GlassFish 3.1.2.2
  • JDK 1.7.0_65
  • Windows 7
  • 惍惃惈ćƒÆćƒ¼ć‚Æ恮čØ­å®šć§ćƒ—ćƒ­ć‚­ć‚·čح定ęøˆćæ

čŖæęŸ»

ć¾ćšē®”ē†ć‚³ćƒ³ć‚½ćƒ¼ćƒ«ć®čµ·å‹•ć«ę™‚é–“ćŒć‹ć‹ć£ć¦ć„ć‚‹éš›ć®ć‚¹ćƒ¬ćƒƒćƒ‰ćƒ€ćƒ³ćƒ—ć‚’å–å¾—ć™ć‚‹ć“ćØć«ć—ć¾ć—ćŸć€‚

GlassFishć‚’čµ·å‹•ć—ć¦ http://localhost:4848 ć‚’ćƒ–ćƒ©ć‚¦ć‚¶ć§é–‹ćć¾ć™ć€‚

ē®”ē†ć‚³ćƒ³ć‚½ćƒ¼ćƒ«ćŒćŖ恋ćŖć‹čµ·å‹•ć•ć‚ŒćŖ恄恓ćØ悒ē¢ŗčŖć—ćŸć‚ćØ JVisualVM恧GlassFish恫ꎄē¶šć—ć¦ćƒœć‚æćƒ³ć½ć”ć£ćØć‚¹ćƒ¬ćƒƒćƒ‰ćƒ€ćƒ³ćƒ—å–å¾—ć—ć¾ć—ćŸć€‚ JVisualVMä¾æåˆ©ć€‚

ć‚¹ćƒ¬ćƒƒćƒ‰ćƒ€ćƒ³ćƒ—ć‚’ć‚Øćƒ‡ć‚£ć‚æć«ć‚³ćƒ”ćƒšć—ć¦ glassfish ćØć„ć†ę–‡å­—åˆ—ć‚’ę¤œē“¢ć—ć¦ćć‚Œć£ć½ć„ć‚¹ćƒ¬ćƒƒćƒ‰ć‚’ęŽ¢ć—ć¾ć—ćŸć€‚

ćć®ēµęžœć€ę¬”恫čØ˜č¼‰ć™ć‚‹ć‚¹ćƒ¬ćƒƒćƒ‰ćŒę€Ŗ恗恝恆恧恗恟怂 ć‚½ć‚±ćƒƒćƒˆć‹ć‚‰ć®ćƒ‡ćƒ¼ć‚æčŖ­ćæč¾¼ćæäø­ć§ę­¢ć¾ć£ć¦ć‚‹ę„Ÿć˜ćŒć—ć¾ć™ć€‚

"admin-thread-pool-4848(3)" daemon prio=6 tid=0x000000000a861800 nid=0xb08 runnable [0x000000001275c000]
   java.lang.Thread.State: RUNNABLE
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:152)
    at java.net.SocketInputStream.read(SocketInputStream.java:122)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
    - locked <0x00000000f7a63a80> (a java.io.BufferedInputStream)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1323)
    - locked <0x00000000f7a47030> (a sun.net.www.protocol.http.HttpURLConnection)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:240)
    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:147)
    at com.sun.jersey.api.client.filter.CsrfProtectionFilter.handle(CsrfProtectionFilter.java:97)
    at com.sun.jersey.api.client.Client.handle(Client.java:648)
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:670)
    at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
    at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:503)
    at org.glassfish.admingui.common.util.RestUtil.get(RestUtil.java:755)
    at org.glassfish.admingui.common.util.RestUtil.restRequest(RestUtil.java:191)
    at org.glassfish.admingui.common.handlers.RestApiHandlers.restRequest(RestApiHandlers.java:223)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.sun.jsftemplating.layout.descriptors.handler.Handler.invoke(Handler.java:442)
    at com.sun.jsftemplating.layout.descriptors.LayoutElementBase.dispatchHandlers(LayoutElementBase.java:420)
    at com.sun.jsftemplating.layout.descriptors.LayoutElementBase.dispatchHandlers(LayoutElementBase.java:394)
    at com.sun.jsftemplating.layout.descriptors.LayoutComponent.beforeCreate(LayoutComponent.java:348)
    at com.sun.jsftemplating.layout.descriptors.LayoutComponent.getChild(LayoutComponent.java:288)
    at com.sun.jsftemplating.layout.LayoutViewHandler.buildUIComponentTree(LayoutViewHandler.java:556)
    at com.sun.jsftemplating.layout.LayoutViewHandler.createView(LayoutViewHandler.java:255)
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:247)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
    at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:809)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:671)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:505)
    at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:476)
    at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:355)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:305)
    at org.glassfish.admingui.common.security.AdminConsoleAuthModule.validateRequest(AdminConsoleAuthModule.java:232)
    at com.sun.enterprise.security.jmac.config.GFServerConfigProvider$GFServerAuthContext.validateRequest(GFServerConfigProvider.java:1171)
    at com.sun.web.security.RealmAdapter.validate(RealmAdapter.java:1452)
    at com.sun.web.security.RealmAdapter.invokeAuthenticateDelegate(RealmAdapter.java:1330)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:551)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:623)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:745)

Jerseyć‚Æćƒ©ć‚¤ć‚¢ćƒ³ćƒˆć§HTTPćƒŖć‚Æć‚Øć‚¹ćƒˆć‚’č”Œć£ć¦ć„ć‚‹ć‚ˆć†ć§ć™ć€‚

RestApiHandlers.java:223 ć«ćƒ–ćƒ¬ćƒ¼ć‚Æćƒć‚¤ćƒ³ćƒˆć‚’ē½®ć„ć¦ćƒ‡ćƒćƒƒć‚°ć—ć¦ćæ悋恓ćØć«ć—ć¾ć—ćŸć€‚ ćƒ‡ćƒćƒƒć‚°ć«ćÆEclipse悒ä½æć„ć¾ć—ćŸć€‚

äø€ę—¦ćƒ‰ćƒ”ć‚¤ćƒ³ć‚’åœę­¢ć—ć¦ćƒ‡ćƒćƒƒć‚°ćƒ¢ćƒ¼ćƒ‰ć§čµ·å‹•ć—ē›“ć—ć¾ć™ć€‚

asadmin start-domain --debug domain1

čµ·å‹•ć—ćŸć‚‰ć‚³ćƒ³ć‚½ćƒ¼ćƒ«ć«ćƒ‡ćƒćƒƒć‚°ćƒćƒ¼ćƒˆćŒč”Øē¤ŗć•ć‚Œć‚‹ć®ć§ćć‚Œć‚’å‚č€ƒć«ćƒŖćƒ¢ćƒ¼ćƒˆćƒ‡ćƒćƒƒć‚°ć—ć¾ć™ć€‚ Eclipseć®ćƒ‡ćƒćƒƒć‚°ć®čØ­å®šć‹ć‚‰ Remote Java Application 悒éøć‚“ć§å®Ÿč”Œć—ć¾ć™ć€‚

惇惐惃悰ē”Øć«é©å½“ć«ćƒ—ćƒ­ć‚ø悧ć‚Æćƒˆć‚’ä½œć‚Šć¾ć—ćŸć€‚ dependency ćÆé©å½“ć«ä½æć£ć¦ćć†ćŖ悄恤悒ēŖć£č¾¼ć‚“ć§ćŠćć¾ć—ćŸć€‚

<dependencies>
  <dependency>
    <groupId>org.glassfish.main.admingui</groupId>
    <artifactId>console-core</artifactId>
    <version>3.1.2.2</version>
  </dependency>
  <dependency>
    <groupId>org.glassfish.main.admingui</groupId>
    <artifactId>console-common</artifactId>
    <version>3.1.2.2</version>
  </dependency>
</dependencies>

Note

恔ćŖćæ恫NetBeansćÆ恓悓ćŖ面倒ćŖ恓ćØ悒恗ćŖćć¦ć‚‚ćƒ—ćƒ­ć‚ø悧ć‚Æćƒˆć‚’ćƒ‡ćƒćƒƒć‚°å®Ÿč”Œć™ć‚Œć°č‡Ŗå‹•ć§GlassFishć‚‚ćƒ‡ćƒćƒƒć‚°ćƒ¢ćƒ¼ćƒ‰ć§čµ·å‹•ć—ćŸćØę€ć„ć¾ć™ć€‚

恝悓ćŖę„Ÿć˜ć§ćƒ‡ćƒćƒƒć‚°ć—ć¦ćæ恟ćØ恓悍 http://localhost:4848/management/domain/anonymous-user-enabled ćø恮GETćƒŖć‚Æć‚Øć‚¹ćƒˆćŒćŖ恋ćŖ恋čæ”ć£ć¦ę„ć¾ć›ć‚“ć§ć—ćŸć€‚

ć‚„ć£ćØ恓恕čæ”ć£ć¦ććŸćƒ¬ć‚¹ćƒćƒ³ć‚¹ćÆ503ć‚Øćƒ©ćƒ¼ć§ć—ćŸć€‚ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒœćƒ‡ć‚£ć‚’č¦‹ć‚‹ćØćƒ—ćƒ­ć‚­ć‚·ć‹ć‚‰åæœē­”ćŒē„”恄ćŖ恩ćØę›øć‹ć‚Œć¦ćŠć‚Š HTTPćƒŖć‚Æć‚Øć‚¹ćƒˆćŒćƒ—ćƒ­ć‚­ć‚·ēµŒē”±ć«ćŖć£ć¦ć„ć‚‹ć®ćŒćƒžć‚ŗ恄悈恆恧恗恟怂

åƾåæœ

localhost ć‚’ćƒ—ćƒ­ć‚­ć‚·ć‚’é€šéŽć™ć‚‹åÆ¾č±”ć‹ć‚‰å¤–ć—ć¦ćæć¾ć—ćŸć€‚

asadmin create-jvm-options -Dhttp.nonProxyHosts=localhost

GlassFishć‚’å†čµ·å‹•ć—ć¦ē®”ē†ć‚³ćƒ³ć‚½ćƒ¼ćƒ«ć«ć‚¢ć‚Æć‚»ć‚¹ć™ć‚‹ćØ問锌ćŖćčµ·å‹•ć—ć¦ćć‚Œć¾ć—ćŸć€‚

ćØć„ć†ć‚ć‘ć§å½“åŗ§ć®å•é”ŒćÆč§£ę±ŗć—ć¾ć—ćŸć€‚

ē–‘問

Windowsć®ćƒ—ćƒ­ć‚­ć‚·čØ­å®šć«ćÆ ā€œćƒ­ćƒ¼ć‚«ćƒ« ć‚¢ćƒ‰ćƒ¬ć‚¹ć«ćÆćƒ—ćƒ­ć‚­ć‚· ć‚µćƒ¼ćƒćƒ¼ć‚’ä½æē”Ø恗ćŖ恄ā€ ćØ恄恆惁悧惃ć‚Æ惜惃ć‚Æć‚¹ćŒć‚ć‚Šć¾ć™ćŒć€ ć“ć‚Œć«ćƒć‚§ćƒƒć‚Æå…„ć‚Œć¦ć‚‚Javać®ć‚½ć‚±ćƒƒćƒˆAPIćÆ localhost ć‚’é™¤å¤–ć—ć¦ćć‚ŒćŖ恄恮恧恗悇恆恋ļ¼Ÿ

ę•™ćˆć¦ć‚Øćƒ­ć„ć²ćØļ¼

]]>
Sat, 02 Aug 2014 00:00:00 +0900
http://backpaper0.github.io/2014/07/21/jersey_standalone.html http://backpaper0.github.io/2014/07/21/jersey_standalone.html <![CDATA[Jersey悒java -jarć§å‹•ć‹ć™]]> Jersey悒java -jarć§å‹•ć‹ć™

JerseyćÆć‚µćƒ¼ćƒ–ćƒ¬ćƒƒćƒˆēµŒē”±ć§ćŖ恏 com.sun.net.httpserver.HttpServer 悄 Grizzly 态Jettyć§å‹•ć‹ć™äŗ‹ć‚‚ć§ćć‚‹ć®ć§maven-shade-pluginćŖć©ć§ć²ćØ恤恮JARć«ć¾ćØć‚ć¦ć—ć¾ćˆć° java -jar ć§å®Ÿč”Œć§ćć‚‹JAX-RSć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć®å®Œęˆć§ć™ć€‚

ä¾‹ćˆć° com.sun.net.httpserver.HttpServer 悒ä½æē”Ø恙悋悄恤悒dependencies恫ēŖć£č¾¼ć‚“恧态

<dependencies>
  <dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-jdk-http</artifactId>
  </dependency>
</dependencies>

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.glassfish.jersey</groupId>
      <artifactId>jersey-bom</artifactId>
      <version>2.10.1</version>
      <scope>import</scope>
      <type>pom</type>
    </dependency>
  </dependencies>
</dependencyManagement>

mavne-shade-plugin悒ēŖć£č¾¼ć‚“恧态

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>2.3</version>
  <executions>
    <execution>
      <id>standalone-jar</id>
      <phase>package</phase>
      <goals>
        <goal>shade</goal>
      </goals>
      <configuration>
        <transformers>
          <transformer
            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
            <mainClass>app.Main</mainClass>
          </transformer>
        </transformers>
       <createDependencyReducedPom>false</createDependencyReducedPom>
      </configuration>
    </execution>
  </executions>
</plugin>

JAX-RSćŖć‚³ćƒ¼ćƒ‰ć‚’ę›ø恄恦态

package app;

import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

@Path("hello")
public class Hello {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String say(@QueryParam("name") @DefaultValue("world") String name) {
        return String.format("Hello, %s!", name);
    }
}

ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ę›ø恄恦态

package app;

import java.net.URI;

import org.glassfish.jersey.filter.LoggingFilter;
import org.glassfish.jersey.jdkhttp.JdkHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;

public class Main {

    public static void main(String[] args) {

        //ćƒ™ćƒ¼ć‚¹ćØćŖ悋URL
        URI uri = URI.create("http://localhost:8080/");

        //ćƒŖć‚½ćƒ¼ć‚¹ć‚Æćƒ©ć‚¹ćŖ恩悒ē™»éŒ²ć™ć‚‹
        //仄äø‹ćÆäø€ä¾‹
        ResourceConfig config = new ResourceConfig();

        //appćƒ‘ćƒƒć‚±ćƒ¼ć‚ø仄äø‹ć®ćƒŖć‚½ćƒ¼ć‚¹ć‚Æćƒ©ć‚¹ćŖ恩JAX-RSć«é–¢äæ‚恙悋ć‚Æćƒ©ć‚¹ć‚’ē™»éŒ²ć™ć‚‹
        //ćƒ‘ćƒƒć‚±ćƒ¼ć‚øćÆ再åø°ēš„ć«ć‚¹ć‚­ćƒ£ćƒ³ć•ć‚Œć‚‹
        config.packages(true, "app");

        //ćƒŖć‚Æć‚Øć‚¹ćƒˆćØćƒ¬ć‚¹ćƒćƒ³ć‚¹ć«é–¢ć™ć‚‹ęƒ…å ±ć‚’ćƒ­ć‚°å‡ŗåŠ›ć™ć‚‹ćƒ•ć‚£ćƒ«ć‚æćƒ¼ć‚’ē™»éŒ²ć™ć‚‹
        config.register(LoggingFilter.class);

        //ć‚µćƒ¼ćƒćƒ¼čµ·å‹•
        JdkHttpServerFactory.createHttpServer(uri, config);

        //http://localhost:8080/hello?name=foobar ć«ć‚¢ć‚Æć‚»ć‚¹ć—ć¦å‹•ä½œē¢ŗčŖ
        //control + c恧JVMč½ćØć—ć¦ć‚µćƒ¼ćƒć‚‚åœę­¢ć™ć‚‹
    }
}

mvn package 恧JARä½œć£ć¦ java -jar hoge.jar ć§å‹•ć‹ć—ć¾ć—ć‚‡ć†ć€‚

ć‚®ćƒƒćƒćƒ–ć«ć‚‚ć‚µćƒ³ćƒ—ćƒ«ē½®ć„ć¦ć„ć¾ć™ć€‚

Gradle恧ćÆć©ć†ć‚„ć£ćŸć‚‰č‰Æ恄悓恧恗悇恆恭ļ¼Ÿ čŖ°ć‹ę›ø恄恦äø‹ć•ć„ćŠé”˜ć„ć—ć¾ć™ć€‚

]]>
Mon, 21 Jul 2014 00:00:00 +0900
http://backpaper0.github.io/2014/07/06/kotlin_default_parameter.html http://backpaper0.github.io/2014/07/06/kotlin_default_parameter.html <![CDATA[Kotlinć®ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆå¼•ę•°ć‚’čŖæć¹ćŸ]]> Kotlinć®ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆå¼•ę•°ć‚’čŖæć¹ćŸ

ć“ć£ćØć‚Šćƒ¼ć‚“ļ¼(ęŒØꋶ)

KotlinćÆ恓悓ćŖę„Ÿć˜ć§ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆå¼•ę•°ćŒä½æćˆć¾ć™ć€‚

class Calc {
  fun add(x: Int = 1, y: Int = 2): Int = x + y
  fun add2() = add(8, 16)
  fun add3() = add(4)
  fun add4() = add()
}

addć®å¼•ę•°ć«ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆå€¤ć‚’čØ­å®šć—ć¦ć„ć‚‹ć®ć§add3悄add4ć§å¼•ę•°ć‚’ēœē•„ć§ćć¦ć„ć¾ć™ć€‚

恧态恓悌悒javapć—ć¾ć—ćŸć€‚

public final int add(int, int);
  descriptor: (II)I
  flags: ACC_PUBLIC, ACC_FINAL
  Code:
    stack=2, locals=3, args_size=3
       0: iload_1
       1: iload_2
       2: iadd
       3: ireturn
    LocalVariableTable:
      Start  Length  Slot  Name   Signature
          0       4     0  this   LCalc;
          0       4     1     x   I
          0       4     2     y   I
    LineNumberTable:
      line 2: 0
  RuntimeVisibleParameterAnnotations:
    parameter 0:
      0: #22(#23=s#24)
    parameter 1:
      0: #22(#23=s#25)

public static int add$default(Calc, int, int, int);
  descriptor: (LCalc;III)I
  flags: ACC_PUBLIC, ACC_STATIC
  Code:
    stack=4, locals=4, args_size=4
       0: aload_0
       1: iload_3
       2: iconst_1
       3: iand
       4: ifeq          9
       7: iconst_1
       8: istore_1
       9: iload_1
      10: iload_3
      11: iconst_2
      12: iand
      13: ifeq          18
      16: iconst_2
      17: istore_2
      18: iload_2
      19: invokevirtual #32                 // Method add:(II)I
      22: ireturn
    LineNumberTable:
      line 2: 7
    StackMapTable: number_of_entries = 2
         frame_type = 73 /* same_locals_1_stack_item */
        stack = [ class Calc ]
         frame_type = 255 /* full_frame */
        offset_delta = 8
        locals = [ class Calc, int, int, int ]
        stack = [ class Calc, int ]


public final int add2();
  descriptor: ()I
  flags: ACC_PUBLIC, ACC_FINAL
  Code:
    stack=3, locals=1, args_size=1
       0: aload_0
       1: bipush        8
       3: bipush        16
       5: invokevirtual #32                 // Method add:(II)I
       8: ireturn
    LocalVariableTable:
      Start  Length  Slot  Name   Signature
          0       9     0  this   LCalc;
    LineNumberTable:
      line 3: 0

public final int add3();
  descriptor: ()I
  flags: ACC_PUBLIC, ACC_FINAL
  Code:
    stack=4, locals=1, args_size=1
       0: aload_0
       1: iconst_4
       2: iconst_0
       3: iconst_2
       4: invokestatic  #37                 // Method add$default:(LCalc;III)I
       7: ireturn
    LocalVariableTable:
      Start  Length  Slot  Name   Signature
          0       8     0  this   LCalc;
    LineNumberTable:
      line 4: 0

public final int add4();
  descriptor: ()I
  flags: ACC_PUBLIC, ACC_FINAL
  Code:
    stack=4, locals=1, args_size=1
       0: aload_0
       1: iconst_0
       2: iconst_0
       3: iconst_3
       4: invokestatic  #37                 // Method add$default:(LCalc;III)I
       7: ireturn
    LocalVariableTable:
      Start  Length  Slot  Name   Signature
          0       8     0  this   LCalc;
    LineNumberTable:
      line 5: 0

public Calc();
  descriptor: ()V
  flags: ACC_PUBLIC
  Code:
    stack=1, locals=1, args_size=1
       0: aload_0
       1: invokespecial #41                 // Method java/lang/Object."<init>":()V
       4: return
    LocalVariableTable:
      Start  Length  Slot  Name   Signature
          0       5     0  this   LCalc;

ć‚³ćƒ³ć‚¹ć‚æćƒ³ćƒˆćƒ—ćƒ¼ćƒ«ć‚„ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æćÆēœē•„ć—ć¾ć—ćŸć€‚

ę³Øē›®ć™ć¹ććÆadd$default(Calc, int, int, int)ćØ恄恆staticćƒ”ć‚½ćƒƒćƒ‰ć§ć™ć­ć€‚ ē¬¬2,3å¼•ę•°ćÆaddćƒ”ć‚½ćƒƒćƒ‰ć®ē¬¬1,2å¼•ę•°ć«åƾåæœć—ć¦ć„ć¾ć™ć€‚

ćć—ć¦ē¬¬4å¼•ę•°ćŒćƒ‡ćƒ•ć‚©ćƒ«ćƒˆå€¤ćŒåæ…č¦ć‹ć©ć†ć‹ć‚’åˆ¤ę–­ć™ć‚‹ćŸć‚ć®ćƒ“ćƒƒćƒˆę¼”ē®—ć‚’åˆ©ē”Øć—ćŸćƒ•ćƒ©ć‚°ć§ć™ć€‚ åˆ¤ę–­ć®ę–¹ę³•ć§ć™ćŒć€ä¾‹ćˆć°ē¬¬4å¼•ę•°ćØ1ćØ恮論ē†ē©ćŒ0ć®å “åˆćÆē¬¬1å¼•ę•°ć«ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆå€¤ć‚’ć€ē¬¬4å¼•ę•°ćØ2ćØ恮論ē†ē©ćŒ0ć®å “åˆćÆē¬¬2å¼•ę•°ć«ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆå€¤ć‚’ä½æē”Ø恙悋态ćØć„ć£ćŸå…·åˆć§ć™ć€‚ ꬔ恫ē¤ŗ恙ē®‡ę‰€ćŒćć‚Œć«å½“ćŸć‚Šć¾ć™ć€‚

1: iload_3
2: iconst_1
3: iand
4: ifeq          9
7: iconst_1
8: istore_1
9: iload_1

intćÆ32惓惃惈ćŖ恮恧33仄äøŠć®å¼•ę•°ć«ćÆ恩恆åƾåæœć—ć¦ć‚‹ć®ć ć‚ć†ćØę€ć£ć¦čŖæć¹ć¦ćæ恟ćØ恓悍ē¬¬33å¼•ę•°ć§ćÆäø€å‘Øå›žć£ć¦1ćØ恮論ē†ē©ć§åˆ¤ę–­ć—ć¦ć„ć¾ć—ćŸć€‚ ćØ恄恆恓ćØćÆē¬¬1å¼•ę•°ć«ę˜Žē¤ŗēš„ć«å€¤ć‚’ęŒ‡å®šć™ć‚‹ćØē¬¬33å¼•ę•°ć«ä½•ć‚‚ęŒ‡å®šć—ć¦ć„ćŖćć¦ć‚‚ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆå€¤ćÆä½æē”Ø恕悌ćŖ恄ćØ恄恆恓ćØ恫ćŖć‚Šć¾ć™ć­ć€‚ 試恗恦ćÆ恄ćŖ恄恧恙恌怂

javapć®ęŠœē²‹ć‚’ęŽ²č¼‰ć—ć¾ć™ćŒć‚¤ćƒ³ćƒ‡ćƒƒć‚Æć‚¹416ä»„é™ćŒćć‚Œć«å½“ćŸć‚Šć¾ć™ć€‚

390: iload         34
392: ldc           #77                 // int 1073741824
394: iand
395: ifeq          401
398: iconst_1
399: istore        31
401: iload         31
403: iload         34
405: ldc           #78                 // int -2147483648
407: iand
408: ifeq          414
411: iconst_1
412: istore        32
414: iload         32
416: iload         34
418: iconst_1
419: iand
420: ifeq          426
423: iconst_1
424: istore        33
426: iload         33
428: invokevirtual #80                 // Method x:(IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII)I
431: ireturn

恟恠恗KotlinćÆć¾ć M8ćŖć®ć§ę”¹å–„ć•ć‚Œć‚‹ć‹ć‚‚ēŸ„ć‚Œć¾ć›ć‚“ć­ć€‚ 恦恄恆恋33ć‚‚å¼•ę•°ä½æć†ć‚“ć˜ć‚ƒć­ćˆć€ć£ć¦č©±ć§ć™ćŒć€‚

恝悓ćŖ恓悓ćŖ恧Kotlinć®ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆå¼•ę•°ć‚’čŖæć¹ć¦ćæć¾ć—ćŸć€‚ 恂ćØć‚„ć£ć±ć‚ŠjavapćÆę„½ć—ć„ć§ć™ć€‚

]]>
Sun, 06 Jul 2014 00:00:00 +0900
http://backpaper0.github.io/2014/07/01/kotlin_jaxrs.html http://backpaper0.github.io/2014/07/01/kotlin_jaxrs.html <![CDATA[Kotlin恧ćÆ恘悁悋JAX-RS]]> Kotlin恧ćÆ恘悁悋JAX-RS

ć“ć£ćØć‚Šćƒ¼ć‚“ļ¼ļ¼ˆęŒØꋶļ¼‰

čŖ¬ę˜ŽćÆć‚‚ć‚ć‚‚ć‚ć™ć£é£›ć°ć—ć¦ćƒŖć‚½ćƒ¼ć‚¹ć‚Æćƒ©ć‚¹ć®ć‚³ćƒ¼ćƒ‰ęŽ²č¼‰ć—ć¾ć™ć€‚

package app

import javax.ws.rs.core.MediaType
import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.Produces
import javax.ws.rs.QueryParam as q

Path("hello")
Produces(MediaType.TEXT_PLAIN)
class Hello {

    GET fun get(q("name") name: String): String = "Hello, ${name}!"
}

ćØć„ć†ę„Ÿć˜ć§ę™®é€šć«JAX-RSć§ćć¾ć—ćŸć€‚

ćØ恄恆恋name恌nullčØ±å®¹ć—ćŖ恄恮恧@DefaultValueć‚’ä»˜ć‘ć‚‹ć¹ććØä»Šę€ć„ć¾ć—ćŸć®ć§ę°—ćŒå‘ć„ćŸć‚‰ē›“ć—ć¦ćŠćć¾ć™ļ¼ˆć‚„悉ćŖ恄惑ć‚æćƒ¼ćƒ³ļ¼‰ć€‚

ć‚µćƒ³ćƒ—ćƒ«ćŒē°”ę˜“ć™ćŽć¦Kotlin恮č‰Æ恕恌å‡ŗ恦恄ćŖć„ć®ćŒę‚²ć—ć„ć§ć™ć­ć€‚

č‰Æć‹ć£ćŸē‚¹ć€‚

  • Maven恧ē°”å˜ć«ćƒ“ćƒ«ćƒ‰ć§ććŸ
  • Maven惗惭ć‚ø悧ć‚Æ惈悒Intellij IDEAć§å®¹ę˜“ćć‚¤ćƒ³ćƒćƒ¼ćƒˆć§ććŸ
  • ćŸć‚ćƒ¼ć•ć‚“ ćØTwitter恧ēµ”悁恟

微妙ćŖē‚¹ć€‚

  • Intellij IDEA恮Kotlinćƒ—ćƒ©ć‚°ć‚¤ćƒ³ć®Organize ImportćŒå¼±ć„ę°—ćŒć™ć‚‹
  • Intellij IDEAć®ć‚³ćƒ¼ćƒ‰ćƒ•ć‚©ćƒ¼ćƒžćƒƒćƒˆćŒ option + command + l 恧äø”ꉋä½æć†ć®ćŒć‚„ć 
  • Intellij IDEA恧 command + w ć§ćƒ•ć‚”ć‚¤ćƒ«ćŒé–‰ć˜ć¦ćć‚ŒćŖć‹ć£ćŸ

恝悓ćŖꄟ恘恧恙怂 要恙悋恫Intellij IDEAć«ę…£ć‚Œć¦ć„ćŖ恄恠恑态ćØ怂

恝悌ćØ ćƒ†ć‚¹ćƒˆć‚Æćƒ©ć‚¹ ćÆJava恧ę›øć„ć¦ć„ć¾ć™ćŒć€ć“ć‚ŒćÆć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ä»˜ćć®staticćƒ”ć‚½ćƒƒćƒ‰ć®ę›øćę–¹ćŒåˆ†ć‹ć‚‰ćŖć‹ć£ćŸć‹ć‚‰ć§ć™ć€‚ ćć£ćØčŖ°ć‹ćŒKotlin恫ē›“ć—ć¦ćƒ—ćƒ«ćƒŖć‚Æć—ć¦ćć‚Œć‚‹ć«é•ć„ćŖ恄(ļ¾ļ¾—ļ½Æ

ęœ¬ę—„ć®ć‚³ćƒ¼ćƒ‰ćÆGitHubć«ć‚ć‚Šć¾ć™ć€‚ Arquillian 恮wildfly-managedć§ćƒ†ć‚¹ćƒˆę›øć„ć¦ć¾ć™ć€‚ ćƒ†ć‚¹ćƒˆå®Ÿč”Œć™ć‚‹ćØå¤šćć®JARćØ WildFly 8.1.0.Final ć‚’ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ć™ć‚‹ć®ć§ę™‚é–“ć®ć‚ć‚‹ćØćć«ć©ć†ćžć€‚

Kotlinć®å‹‰å¼·ä¼šć‚‚ć‚ć‚‹ćæ恟恄恧恙悈怂

]]>
Tue, 01 Jul 2014 00:00:00 +0900
http://backpaper0.github.io/2013/12/30/javafx.html http://backpaper0.github.io/2013/12/30/javafx.html <![CDATA[JavaFX恧ć‚Æćƒ©ć‚µćƒć™ć‚‹äŗ‹ć‚’č€ƒćˆćŸ]]> JavaFX恧ć‚Æćƒ©ć‚µćƒć™ć‚‹äŗ‹ć‚’č€ƒćˆćŸ

ē§ćÆć‚Øć‚¹ć‚¢ć‚¤ćƒ¤ćƒ¼ć§ć‚®ćƒ§ćƒ¼ćƒ ć‚¢ćƒ—ćƒŖä½œć£ć¦ć‚‹ć®ć§ćć®č¾ŗ悊恫JavaFXć¶ć£č¾¼ć‚“ć ć‚‰ć©ć†ćŖć‚‹ć‹č€ƒćˆć¦ćæć¾ć—ćŸć€‚

ćØć‚Šć‚ćˆćšę¬”ć«ęŒ™ć’ćŸę©Ÿčƒ½ćŒåæ…č¦ć£ć½ć„ć‹ćŖćƒ¼ćØę€ć„ć¾ć™ć€‚

  • ē”»é¢é·ē§»
  • ꤜē“¢ēµęžœćŖ恩恮悰ćƒŖ惃惉č”Øē¤ŗ
  • 悰ćƒŖćƒƒćƒ‰ć‹ć‚‰č©³ē“°ē”»é¢ć‚’é–‹ćēš„ćŖ悄恤
  • ćƒ€ć‚¤ć‚¢ćƒ­ć‚°
  • 惐惃ć‚Æć‚°ćƒ©ć‚¦ćƒ³ćƒ‰å‡¦ē†
  • ć‚µćƒ¼ćƒćØ恮通äæ”

ē”»é¢é·ē§»

Hogeé§†å‹•ć®åæ˜å¹“会ćØć„ć†ćć‚ƒć—ćƒé›†ć¾ć‚Šć§ćÆ

ćØć„ć†ę”ˆć‚’ęŒ™ć’ć¦ćæć¾ć—ćŸć€‚ ć“ć®ćµćŸć¤ć®ć†ć”Sceneć‚’å…„ć‚Œę›æćˆć‚‹ę–¹ę³•ć ćØē”»é¢ćŒćƒćƒ©ć¤ć„ć¦ć—ć¾ć„ć¾ć—ćŸć®ć§ ćƒ«ćƒ¼ćƒˆćƒŽćƒ¼ćƒ‰ć‚’å…„ć‚Œę›æćˆć‚‹ę–¹ę³•ćŒćƒ™ć‚æćƒ¼ć‹ćŖćƒ¼ć€ćØę€ć£ć¦ć„ć¾ć—ćŸćŒć€ StackPaneć‚ćŸć‚Šć«åæ…要ćŖ恠恑Node悒ēŖć£č¾¼ć‚“恧visibleć‚’åˆ‡ć‚Šę›æ恈悋态 ćØć„ć†ć®ćŒć‚‚ć£ćØč‰Æ恄悓恘悃ćŖ恄恋ćØē¾ę™‚ē‚¹ć§ćÆę€ć£ć¦ć„ć¾ć™ć€‚

package sample;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class ScreenTransitionSample extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {

        final BorderPane firstPane = new BorderPane();
        Button next = new Button("ꬔćøč”Œć");
        firstPane.setCenter(next);

        final BorderPane secondPane = new BorderPane();
        Button prev = new Button("前ćøęˆ»ć‚‹");
        secondPane.setCenter(prev);
        secondPane.setVisible(false);

        StackPane root = new StackPane();
        root.getChildren().add(firstPane);
        root.getChildren().add(secondPane);

        next.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                firstPane.setVisible(false);
                secondPane.setVisible(true);
            }
        });
        prev.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                firstPane.setVisible(true);
                secondPane.setVisible(false);
            }
        });

        Scene scene = new Scene(root, 400, 300);
        stage.setScene(scene);
        stage.setTitle("ē”»é¢é·ē§»");
        stage.show();
    }
}

ꤜē“¢ē”»é¢ćŖ恩恮悰ćƒŖ惃惉č”Øē¤ŗ

TableView 悒ä½æć„ć¾ć™ć€‚

Scene Builder悒ä½æć£ć¦ē”»é¢ć‚’ēµ„ćæē«‹ć¦ć‚‹å “合ćÆć¾ćšTableView悒惚ć‚æć£ćØē½®ć„恦态 ć‚«ćƒ©ćƒ ć‚’č¶³ć™å “åˆćÆTableColumnć‚’č²¼ä»˜ć‘ćŸTableViewćøćƒšćƒ­ć£ćØē½®ćć¾ć™ć€‚

ćƒ‡ćƒ¼ć‚æ悒č”Øē¤ŗ恙悋ćØ恍ćÆ TableColumn#setCellValueFactory(Callback) 悒ä½æć£ć¦å€¤ć®ćƒ•ć‚”ć‚Æ惈ćƒŖćƒ¼ć‚’čØ­å®šć—ć¦ć€ TableView恮itemsćøaddć—ć¾ć™ć€‚

package sample;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;

public class GridController implements Initializable {

    @FXML
    private TableView<Account> accounts;
    @FXML
    private TableColumn<Account, String> id;
    @FXML
    private TableColumn<Account, String> name;
    @FXML
    private TableColumn<Account, String> desc;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        id.setCellValueFactory(new PropertyValueFactory<Account, String>("id"));
        name.setCellValueFactory(new PropertyValueFactory<Account, String>("name"));
        desc.setCellValueFactory(new PropertyValueFactory<Account, String>("desc"));

        Account account1 = Account.newInstance("backpaper0", "恆悉恌ćæ", "å…Øč£ø");
        Account account2 = Account.newInstance("tan_go238", "恟悓恔", "ć‚«ćƒ¬ćƒ¼");
        Account account3 = Account.newInstance("irof", "ć„ć‚ćµ", "č¶³é¦–");

        accounts.getItems().add(account1);
        accounts.getItems().add(account2);
        accounts.getItems().add(account3);
    }
}

恓悓ćŖę„Ÿć˜ć«ćŖć‚Šć¾ć™ć€‚

../../../_images/GridSample.png

悰ćƒŖćƒƒćƒ‰ć‹ć‚‰č©³ē“°ē”»é¢ć‚’é–‹ćēš„ćŖ悄恤

TableColumn#setCellFactory(Callback) 悒ä½æć„ć¾ć™ć€‚ Callbackå®Ÿč£…ć‚Æćƒ©ć‚¹ć§ćÆć‚»ćƒ«ęÆŽć«callćƒ”ć‚½ćƒƒćƒ‰ćŒå‘¼ć°ć‚Œć‚‹ć‚ˆć†ć§ć™ćŒć€ 恓恓恧TableCellć‚’ä½œęˆć—ć¦čæ”ć—ć¾ć™ć€‚ TableCell恧ćÆsetGraphicćƒ”ć‚½ćƒƒćƒ‰ć§ćƒœć‚æćƒ³ć‚’ć‚»ćƒƒćƒˆć—ć¦ć„ć¾ć™ć€‚ ć“ć‚Œć§ć‚»ćƒ«ć«ćƒœć‚æćƒ³ć‚’ē½®ćäŗ‹ćŒå‡ŗę„ć‚‹ć‚ˆć†ć§ć™ć€‚

public class GridController implements Initializable {

    ...

    @FXML
    private TableColumn<Account, String> opener;

    @Override
    public void initialize(URL location, ResourceBundle resources) {

        opener.setCellFactory(new OpenerFactory());

        opener.setCellValueFactory(new PropertyValueFactory<Account, String>("id"));

        ...
    }
}

class OpenerFactory implements Callback<TableColumn<Account, String>, TableCell<Account, String>> {

    @Override
    public TableCell<Account, String> call(TableColumn<Account, String> param) {
        TableCell<Account, String> tableCell = new TableCell<Account, String>() {

            private Pane pane = createPane();

            private String id;

            private Pane createPane() {
                HBox pane = new HBox();
                pane.setAlignment(Pos.CENTER);

                Button button = new Button("č©³ē“°ć‚’é–‹ć");
                button.setOnAction(new EventHandler<ActionEvent>() {

                    @Override
                    public void handle(ActionEvent event) {
                        System.out.println(id);
                    }
                });
                pane.getChildren().add(button);
                return pane;
            }

            @Override
            protected void updateItem(String id, boolean empty) {
                super.updateItem(id, empty);
                if (empty == false) {
                    this.id = id;
                    setGraphic(pane);
                }
            }
        };
        return tableCell;
    }
}

惜ć‚æćƒ³ćŒē½®ć‘ć¾ć—ćŸć€‚

../../../_images/GridOpenerSample.png

ćƒ€ć‚¤ć‚¢ćƒ­ć‚°

Swing恧čØ€ć†ćØć“ć‚ć®JOptionPaneć®ć‚ˆć†ćŖćŠę‰‹č»½ćƒ€ć‚¤ć‚¢ćƒ­ć‚°ćÆē„”恄悈恆恧恙恌态Stage悒ä½æ恆äŗ‹ć§å®Ÿē¾åÆčƒ½ć£ć½ć„ć§ć™ć€‚

惐惃ć‚Æć‚°ćƒ©ć‚¦ćƒ³ćƒ‰å‡¦ē†

Service 悒ä½æć„ć¾ć™ć€‚ SwingWorkerēš„ćŖ悄恤恧恙怂 恓悓ćŖę„Ÿć˜ć®é›°å›²ę°—ć§ć€‚

Service<String> service = new Service<String>() {

    @Override
    protected Task<String> createTask() {
        Task<String> task = new Task<String>() {

            @Override
            protected String call() throws Exception {
                TimeUnit.SECONDS.sleep(5);
                return "ēµ‚ć‚ć£ćŸć‚ˆćƒ¼ć‚“";
            }

            @Override
            protected void succeeded() {
                text.setText(getValue());
            }
        };
        return task;
    }
};
service.start();

Service#createTask()恧Task悒čæ”ć—ć¦ć„ć¾ć™ć€‚ Task恧ćÆcallćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč£…ć—ć¦ć„ć¾ć™ćŒć€ć“ć‚ŒćŒSwingWorker恧恄恆doInBackgroundć®ć‚ˆć†ć§ć™ć€‚ succeededćƒ”ć‚½ćƒƒćƒ‰ćÆ処ē†ćŒę­£åøøēµ‚äŗ†ć—ćŸćØćć«å‘¼ć°ć‚Œć¾ć™ć€‚ ä»–ć«ć‚­ćƒ£ćƒ³ć‚»ćƒ«ć—ćŸćØćć«å‘¼ć°ć‚Œć‚‹cancelledćƒ”ć‚½ćƒƒćƒ‰ć‚„å¤±ę•—ć—ćŸćØćć«å‘¼ć°ć‚Œć‚‹failedćƒ”ć‚½ćƒƒćƒ‰ćŒć‚ć‚Šć¾ć™ć€‚

恗恋恗ēµęžœćŒć©ć†ć‚ć‚Œåæ…ćšå‘¼ć°ć‚Œć‚‹finallyēš„ćŖćƒ”ć‚½ćƒƒćƒ‰ćŒć‚ć‚Šć¾ć›ć‚“ć€‚ 恓悌ćÆäøä¾æćŖę°—ćŒć—ć¾ć™ć€‚

finallyēš„ćŖć‚¢ćƒ¬ć‚’å®Ÿē¾ć™ć‚‹ę–¹ę³•ćØ恗恦今悓ćØć“ć‚ę€ć„ć¤ć„ć¦ć„ć‚‹ć®ćÆ态Task恫ćÆå®Ÿč”Œäø­ć‹ćć†ć§ćŖ恄恋悒č”Ø恙runningćØ恄恆booleanć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć‚ć‚‹ć®ć§ć€ ćć‚Œć«ćƒŖć‚¹ćƒŠćƒ¼ć‚’čæ½åŠ ć—ć¾ć™ć€‚

task.runningProperty().addListener(
        new ChangeListener<Boolean>() {

            @Override
            public void changed(ObservableValue<? extends Boolean> observable,
                                Boolean oldValue, Boolean newValue) {
                if (!newValue) {
                    System.out.println("ēµ‚ć‚ć£ćŸć‚ˆćƒ¼ć‚“");
                }
            }
        });

ć‚‚ć£ćØč‰Æć„ę–¹ę³•ćŒć‚ć£ćŸć‚‰ę•™ćˆć¦ę¬²ć—ć„ć§ć™ć€‚

恂ćØć€å‡¦ē†äø­ć«ProgressIndicatorćØ恄恆恮悒č”Øē¤ŗć—ć¦ćŠććØč‰Æć„ę„Ÿć˜ć«ćŖ悊恝恆恧恙怂 StackPaneć«ćƒ”ć‚¤ćƒ³ćØćŖ悋PanećØProgressIndicatorć‚’å«ć‚“ć Pane悒ēŖć£č¾¼ć‚“恧visibleć§åˆ‡ć‚Šę›æćˆć¾ć™ć€‚

ćØ恄恆悏恑恧惐惃ć‚Æć‚°ćƒ©ć‚¦ćƒ³ćƒ‰å‡¦ē†ć®ć‚µćƒ³ćƒ—ćƒ«ć‚’ę¬”恫čØ˜č¼‰ć—ć¾ć™ć€‚

package sample;

import java.util.concurrent.TimeUnit;
import javafx.application.Application;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.concurrent.WorkerStateEvent;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class LongTimeTaskSample extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        //ć‚¤ćƒ³ć‚øć‚±ćƒ¼ć‚æć‚’å«ć‚€Pane悒ēµ„ćæē«‹ć¦ć‚‹
        final GridPane progressPane = new GridPane();
        progressPane.setAlignment(Pos.CENTER);

        ProgressIndicator indicator = new ProgressIndicator();
        progressPane.add(indicator, 0, 0);

        //ćƒ”ć‚¤ćƒ³ćØćŖ悋Pane悒ēµ„ćæē«‹ć¦ć‚‹
        GridPane mainPane = new GridPane();
        mainPane.setAlignment(Pos.CENTER);
        mainPane.setHgap(10);
        mainPane.setVgap(10);

        Button button = new Button("é‡ć„å‡¦ē†ć‚’č”Œć†");
        mainPane.add(button, 0, 0);

        final Text text = new Text();
        mainPane.add(text, 0, 1);

        //StackPane恫ēŖć£č¾¼ć‚€
        StackPane root = new StackPane();
        root.getChildren().add(mainPane);
        root.getChildren().add(progressPane);

        //ęœ€åˆćÆć‚¤ćƒ³ć‚øć‚±ćƒ¼ć‚æćÆč¦‹ćˆćŖ恏恙悋
        progressPane.setVisible(false);

        button.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {

                //惜ć‚æćƒ³ćŒęŠ¼ć•ć‚ŒćŸć‚‰ć‚¤ćƒ³ć‚øć‚±ćƒ¼ć‚æ悒見恛悋
                progressPane.setVisible(true);
                text.setText("");
                Service<String> service = new Service<String>() {

                    @Override
                    protected Task<String> createTask() {
                        Task<String> task = new Task<String>() {

                            @Override
                            protected String call() throws Exception {
                                TimeUnit.SECONDS.sleep(5);
                                return "ēµ‚ć‚ć£ćŸć‚ˆćƒ¼ć‚“";
                            }
                        };
                        task.setOnSucceeded(new EventHandler<WorkerStateEvent>() {

                            @Override
                            public void handle(WorkerStateEvent event) {
                                //ć‚æć‚¹ć‚Æ恌ēµ‚ć‚ć£ćŸć‚‰ć‚¤ćƒ³ć‚øć‚±ćƒ¼ć‚æć‚’č¦‹ćˆćŖ恏恙悋
                                progressPane.setVisible(false);
                                text.setText(getValue());
                            }
                        });
                        return task;
                    }
                };
                service.start();
            }
        });

        Scene scene = new Scene(root, 400, 300);
        primaryStage.setScene(scene);
        primaryStage.setTitle("é‡ć„å‡¦ē†");
        primaryStage.show();
    }
}

å®Ÿč”Œć—ćŸć‚‰ć“ć‚“ćŖꄟ恘恧恙怂

ćƒćƒć£ćØ怂

../../../_images/LongTimeTaskSample1.png

ćć‚‹ćć‚‹ćƒ¼ć€‚

../../../_images/LongTimeTaskSample2.png

ć©ćƒ¼ć‚“ļ¼

../../../_images/LongTimeTaskSample3.png

恔ćŖćæć«ć“ć®ć‚³ćƒ¼ćƒ‰ć ćØć‚¤ćƒ³ć‚øć‚±ćƒ¼ć‚æ恌č”Øē¤ŗć•ć‚Œć¦ć„ć‚‹ćØćć«ćƒœć‚æćƒ³ćÆć‚ÆćƒŖ惃ć‚Æ恧恍ćŖ恏ćŖć£ć¦ć„ć¾ć™ćŒć€ ć‚æćƒ–ć§ćƒ•ć‚©ćƒ¼ć‚«ć‚¹ē§»å‹•ć—ć¦ć‚¹ćƒšćƒ¼ć‚¹ć‚­ćƒ¼ć§ęŠ¼ć›ćŸć‚Šć—ć¾ć™ć€‚ ćć£ćØjava.awt.FocusTraversalPolicyć®ć‚ˆć†ćŖć‚‚ć®ćŒć‚ć‚‹ćØę€ć†ć®ć§ć¾ćŸå‹‰å¼·ć—ć¦ćŠćć“ćØć«ć—ć¾ć™ć€‚

ć‚µćƒ¼ćƒćØ恮通äæ”

(怀ļ¾Ÿāˆ€ļ¾Ÿ)oå½”Ā°JAX-RSļ¼JAX-RSļ¼

ć¾ćØ悁

恓恓ꕰꗄJavaFXć‚’č§¦ć£ć¦ćæ恦ć‚Øć‚¹ć‚¢ć‚¤ćƒ¤ćƒ¼ć®ć‚®ćƒ§ćƒ¼ćƒ ć‚¢ćƒ—ćƒŖ悂ꙮ通恫ę›ø恑恝恆恠ćŖćƒ¼ć€ćØę„Ÿć˜ć¾ć—ćŸć€‚

ć¾ćŸä»Šå›žćÆćƒ•ć‚©ćƒ¼ć‚«ć‚¹ć—ć¾ć›ć‚“ć§ć—ćŸćŒFXML恧ē”»é¢ć‚’ēµ„ć‚ć‚‹ć®ćŒć™ć”ćč‰Æ恄恧恙恭怂 Scene Builder恧悵ć‚Æ惃ćØćƒ¢ćƒƒć‚Æć‚’ä½œć£ć¦ć€OKćŖć‚‰ćć®ć¾ć¾å®Ÿč£…ć™ć‚‹ć€ćØć„ć†ć‚¹ć‚æć‚¤ćƒ«ćŒę„½ć«ć§ććć†ć§å¬‰ć—ć„ć§ć™ć€‚

恂ćØScene Builder恌ē‰¹å®šć®IDEć«ä¾å­˜ć—ć¦ć„ćŖć„ć®ć‚‚å¬‰ć—ć„ć§ć™ć­ć€‚ å„½ććŖIDE悒ä½æćˆć¾ć™ć€‚

ćØ恄恆čØ³ć§Java 8恌ćƒŖćƒŖćƒ¼ć‚¹ć•ć‚ŒćŸć‚‰ę˜Æ非ćØ悂JavaFXć§ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ēµ„ćæ恟恄ćŖćƒ¼ć€ćØę€ć£ćŸć®ć§ć—ćŸć€‚

恊悏悊怂

å‚č€ƒč³‡ę–™

]]>
Mon, 30 Dec 2013 00:00:00 +0900
http://backpaper0.github.io/2013/12/22/visitor.html http://backpaper0.github.io/2013/12/22/visitor.html <![CDATA[Visitor惑ć‚æćƒ¼ćƒ³ć«ć¤ć„ć¦č€ƒćˆćŸ]]> Visitor惑ć‚æćƒ¼ćƒ³ć«ć¤ć„ć¦č€ƒćˆćŸ

ćØ恄恆恊話怂ēø¦ć«é•·ć„ć§ć™ć€‚ć‚³ćƒ¼ćƒ‰ćŒć€‚

惝ćƒŖć‚‚ćƒ¼ćŖ悓ćØ恋恧ćŖ悓ćØ恋恙悋

ä¾‹ćˆć°ę•°å€¤ć‚’č”Ø恙NumNodeć€č¶³ć—ē®—ć‚’č”Ø恙AddNodeć€ćć‚Œć‚‰ć®ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ćØćŖ悋Node恌恂悋ćØć—ć¾ć™ć€‚ 恧态č؈ē®—ć‚’å®Ÿč£…ć™ć‚‹å “合Node恫calcćƒ”ć‚½ćƒƒćƒ‰ćØć‹å®šē¾©ć—恦NumNodećØAddNodeć§å®Ÿč£…ć—ć¾ć™ć€‚

package visitor;

public interface Node1 {

    int calc();
}

class NumNode1 implements Node1 {

    public final int value;

    public NumNode1(int value) {
        this.value = value;
    }

    @Override public int calc() {
        return value;
    }
}

class AddNode1 implements Node1 {

    public final Node1 left;
    public final Node1 right;

    public AddNode1(Node1 left, Node1 right) {
        this.left = left;
        this.right = right;
    }

    @Override public int calc() {
        return left.calc() + right.calc();
    }
}

恓恄恤恧2 + 3 + 4悒č؈ē®—ć™ć‚‹å “合ćÆę¬”ć®ć‚ˆć†ć«ä½æć„ć¾ć™ć€‚

package visitor;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import org.junit.Test;

public class Node1Test {

    @Test public void testCalc() throws Exception {
        Node1 node1 = new NumNode1(2);
        Node1 node2 = new NumNode1(3);
        Node1 node3 = new AddNode1(node1, node2);
        Node1 node4 = new NumNode1(4);
        Node1 node5 = new AddNode1(node3, node4);
        int actual = node5.calc();
        int expected = 2 + 3 + 4;
        assertThat(actual, is(expected));
    }
}

恕恦态今åŗ¦ćÆēµ„ćæē«‹ć¦ćŸNode悒Writerćøę›ø恍å‡ŗ恗恟恏ćŖć£ćŸćØć—ć¾ć™ć€‚ Nodećøprintćƒ”ć‚½ćƒƒćƒ‰ć‚’čæ½åŠ ć—ć¾ć™ć€‚

package visitor;

import java.io.IOException;
import java.io.Writer;

public interface Node2 {

    int calc();

    void print(Writer out) throws IOException;
}

class NumNode2 implements Node2 {

    public final int value;

    public NumNode2(int value) {
        this.value = value;
    }

    @Override public int calc() {
        return value;
    }

    @Override public void print(Writer out) throws IOException {
        out.write(String.valueOf(value));
    }
}

class AddNode2 implements Node2 {

    public final Node2 left;
    public final Node2 right;

    public AddNode2(Node2 left, Node2 right) {
        this.left = left;
        this.right = right;
    }

    @Override public int calc() {
        return left.calc() + right.calc();
    }

    @Override public void print(Writer out) throws IOException {
        out.write("(");
        left.print(out);
        out.write("+");
        right.print(out);
        out.write(")");
    }
}

恕恦态ꬔćÆĆ—Ć—å‡¦ē†ć‚’čæ½åŠ ć—ć¾ć™ć®ć§NodećøĆ—Ć—ćƒ”ć‚½ćƒƒćƒ‰ć‚’ā€¦ā€¦ćØć€ć¾ć‚ć€ 恓悌ćÆ恓悌恧č‰Æć„ć‚“ć§ć™ćŒć€å‡¦ē†ć‚’čæ½åŠ ć™ć‚‹ćŸć³ć«NodećŠć‚ˆć³Nodeå®Ÿč£…ć‚Æćƒ©ć‚¹ć«ę‰‹ć‚’åŠ ćˆć‚‹åæ…č¦ćŒć‚ć‚Šć€ćć‚ŒćŒå¬‰ć—ććŖ恄ēŠ¶ę³ć‚‚ć‚ć‚Šć¾ć™ć€‚

処ē†ć‚’å¤–ć‹ć‚‰ęø”恙

Nodeć‹ć‚‰å‡¦ē†ć‚’å–ć‚Šé™¤ć„ć¦å¤–ć‹ć‚‰ęø”恙恓ćØć‚’č€ƒćˆć¦ćæć¾ć™ć€‚

ć¾ćšćÆinstanceofć§åˆ†å²ć—ć¤ć¤å„Nodeå®Ÿč£…ć‚Æćƒ©ć‚¹ć«ć¤ć„ć¦å‡¦ē†ć—恦ćæć¾ć™ć€‚

package visitor;

public interface Node3 {}

class NumNode3 implements Node3 {

    public final int value;

    public NumNode3(int value) {
        this.value = value;
    }
}

class AddNode3 implements Node3 {

    public final Node3 left;
    public final Node3 right;

    public AddNode3(Node3 left, Node3 right) {
        this.left = left;
        this.right = right;
    }
}

class Calclurator3 {

    public int calc(Node3 node) {
        if (node instanceof AddNode3) {
            AddNode3 addNode3 = (AddNode3) node;
            return calc(addNode3.left) + calc(addNode3.right);
        } else if (node instanceof NumNode3) {
            NumNode3 numNode3 = (NumNode3) node;
            return numNode3.value;
        }
        throw new IllegalArgumentException(String.valueOf(node));
    }
}

ć‚ćƒ¼ć„ć“ć‚Œć§å‡¦ē†ć‚’å¤–ć ć—ļ¾ƒļ¾žļ½·ļ¾€ļ¾–ļ½°ć€ć˜ć‚ƒć­ćˆć‚ˆļ¼ćØ恄恆ꄟ恘恧恙恭怂

instanceof恮ꬠē‚¹ćÆć‚±ćƒ¼ć‚¹ć®ę¼ć‚Œć‚’é™ēš„ć«ę¤œå‡ŗ恧恍ćŖ恄恓ćØ恠ćØę€ć£ć¦ć„ć¾ć™ć€‚ ä¾‹ćˆć°ć“ć®ä¾‹ć§čØ€ć†ćØNodeå®Ÿč£…ć‚Æćƒ©ć‚¹ćÆAddNodećØNumNodećŒć‚ć‚Šć¾ć™ćŒć€ NumNodećøć®åˆ†å²ć‚’åæ˜ć‚Œć¦ć„ć¦ć‚‚ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ę™‚ć«ę°—ä»˜ćć¾ć›ć‚“ć€‚ 恕悉恫 node instanceof java.util.Date ćØ恋ē„”関äæ‚ćŖć‚Æćƒ©ć‚¹ć‚’ę›ø恄恦恄恦悂 ć“ć‚Œć‚‚ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ę™‚ć«ę°—ä»˜ćć¾ć›ć‚“ć€‚

ć‚±ćƒ¼ć‚¹ć®ę¼ć‚Œć‚’é™ēš„ć«ę¤œå‡ŗćØ恄恈恰switchćŒć‚ć‚Šć¾ć™ćŒć€ String恋primitiveć¾ćŸćÆenum恗恋ä½æ恈ćŖć„ć®ć§ä»Šå›žć®ä¾‹ć«ćÆäøé©å½“恧恙怂

恄悄恄悄恝悓ćŖć®ćƒćƒŖć‚‚ćƒ¼ćŖ悓ćØć‹ć§ć‚¢ćƒ¬ć™ć‚Œć°č‰Æ恄恘悃悓态ćØ恄恆äŗ‹ć§ę¬”ć®ć‚ˆć†ćŖć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ć‚’ä½œć‚Šć¾ć™ć€‚

interface Visitor4 {

    int visit(NumNode4 node);

    int visit(AddNode4 node);
}

恓悌悒恓恆恄恆é¢Øć«å®Ÿč£…ć™ć‚Œć°ā€¦ā€¦

class Calclurator4 implements Visitor4 {

    public int calc(Node4 node) {
        return visit(node);
    }

    @Override public int visit(NumNode4 node) {
        return node.value;
    }

    @Override public int visit(AddNode4 node) {
        return visit(node.left) + visit(node.left);
    }
}

čÆéŗ—ć«č§£ę±ŗļ¼ćØć„ć†ć‚ć‘ć«ćÆč”Œćć¾ć›ć‚“ć­ć€‚ calcćƒ”ć‚½ćƒƒćƒ‰å†…ć®visit(node)悄AddNode悒ćØ悋visitćƒ”ć‚½ćƒƒćƒ‰å†…ć§ć®visit(node.left)悄visit(node.right)恧ćÆ ęø”恗恦恄悋Nodeå®Ÿč£…ć‚Æćƒ©ć‚¹ćŒćŖ悓ćŖć®ć‹ć€ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ę™‚ć«ćÆåˆ†ć‹ć‚Šć¾ć›ć‚“ć®ć§ę™®é€šć«ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć‚Øćƒ©ćƒ¼ć§ć™ć€‚

ē„”ē†ēŸ¢ē†ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć‚’é€šćć†ćØꀝ恆ćØ恓悓ćŖć‚³ćƒ¼ćƒ‰ć«ćŖć‚Šć¾ć—ćŸć€‚

class Calclurator4 implements Visitor4 {

    public int calc(Node4 node) {
        if (node instanceof NumNode4) {
            return visit((NumNode4) node);
        } else if (node instanceof AddNode4) {
            return visit((AddNode4) node);
        } else {
            throw new IllegalArgumentException(String.valueOf(node));
        }
    }

    @Override public int visit(NumNode4 node) {
        return node.value;
    }

    @Override public int visit(AddNode4 node) {

        //compile error
        //return visit(node.left) + visit(node.left);

        if (node.left instanceof NumNode4) {
            NumNode4 left = (NumNode4) node.left;
            if (node.right instanceof NumNode4) {
                NumNode4 right = (NumNode4) node.right;
                return visit(left) + visit(right);
            } else if (node.right instanceof AddNode4) {
                AddNode4 right = (AddNode4) node.right;
                return visit(left) + visit(right);
            } else {
                throw new IllegalArgumentException(String.valueOf(node));
            }
        } else if (node.left instanceof AddNode4) {
            AddNode4 left = (AddNode4) node.left;
            if (node.right instanceof NumNode4) {
                NumNode4 right = (NumNode4) node.right;
                return visit(left) + visit(right);
            } else if (node.right instanceof AddNode4) {
                AddNode4 right = (AddNode4) node.right;
                return visit(left) + visit(right);
            } else {
                throw new IllegalArgumentException(String.valueOf(node));
            }
        } else {
            throw new IllegalArgumentException(String.valueOf(node));
        }
    }
}

ćÆ恄态恝恓恝恓ć‚Æć‚½ć‚³ćƒ¼ćƒ‰ć«ćŖć‚Šć¾ć—ćŸć­ļ¼Ÿ ć¦ć„ć†ć‹ć¾ćŸinstanceof恌å‡ŗć¦ćć¾ć—ćŸć—ć€‚

恝恓恧Visitor惑ć‚æćƒ¼ćƒ³ć§ć™ć‚ˆ

Node恫acceptćƒ”ć‚½ćƒƒćƒ‰ć‚’čæ½åŠ ć—ć¦å®Ÿč£…ć‚Æćƒ©ć‚¹ć§åƾåæœć™ć‚‹visitćƒ”ć‚½ćƒƒćƒ‰ć‚’å‘¼ć¶ć‚ˆć†ć«ć—ć¾ć™ć€‚

package visitor;

import java.io.IOException;
import java.io.Writer;

public interface Node5 {

    int accept(Visitor5 visitor);
}

class NumNode5 implements Node5 {

    public final int value;

    public NumNode5(int value) {
        this.value = value;
    }

    @Override public int accept(Visitor5 visitor) {
        return visitor.visit(this);
    }
}

class AddNode5 implements Node5 {

    public final Node5 left;
    public final Node5 right;

    public AddNode5(Node5 left, Node5 right) {
        this.left = left;
        this.right = right;
    }

    @Override public int accept(Visitor5 visitor) {
        return visitor.visit(this);
    }
}

interface Visitor5 {

    int visit(NumNode5 node);

    int visit(AddNode5 node);
}

class Calclurator5 implements Visitor5 {

    @Override public int visit(NumNode5 node) {
        return node.value;
    }

    @Override public int visit(AddNode5 node) {
        int left = node.left.accept(this);
        int right = node.right.accept(this);
        return left + right;
    }
}

class Printer5 implements Visitor5 {

    private final Writer out;

    public Printer5(Writer out) {
        this.out = out;
    }

    @Override public int visit(NumNode5 node) {
        try {
            out.write(String.valueOf(node.value));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return 0;
    }

    @Override public int visit(AddNode5 node) {
        try {
            out.write("(");
            node.left.accept(this);
            out.write("+");
            node.right.accept(this);
            out.write(")");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return 0;
    }
}

å…ˆć»ć©ć®ä¾‹ćØćÆē•°ćŖ悊visitćƒ”ć‚½ćƒƒćƒ‰ć‚’å„Nodeå®Ÿč£…ć‚Æćƒ©ć‚¹ć®acceptćƒ”ć‚½ćƒƒćƒ‰å†…ć§å‘¼ć‚“ć§ć„ć‚‹ć®ć§ 恩恮visitćƒ”ć‚½ćƒƒćƒ‰ćŖć®ć‹ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ę™‚ć«åˆ†ć‹ć‚Šć¾ć™ć­ć€‚

恓悌ćÆę¬”ć®ć‚ˆć†ć«ä½æć„ć¾ć™ć€‚

package visitor;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import java.io.StringWriter;
import org.junit.Test;

public class Node5Test {

    @Test public void testCalc() throws Exception {
        Node5 node1 = new NumNode5(2);
        Node5 node2 = new NumNode5(3);
        Node5 node3 = new AddNode5(node1, node2);
        Node5 node4 = new NumNode5(4);
        Node5 node5 = new AddNode5(node3, node4);
        Calclurator5 calclurator = new Calclurator5();
        int actual = node5.accept(calclurator);
        int expected = 2 + 3 + 4;
        assertThat(actual, is(expected));
    }

    @Test public void testPrint() throws Exception {
        Node5 node1 = new NumNode5(2);
        Node5 node2 = new NumNode5(3);
        Node5 node3 = new AddNode5(node1, node2);
        Node5 node4 = new NumNode5(4);
        Node5 node5 = new AddNode5(node3, node4);
        StringWriter out = new StringWriter();
        Printer5 printer = new Printer5(out);
        node5.accept(printer);
        String actual = out.toString();
        String expected = "((2+3)+4)";
        assertThat(actual, is(expected));
    }
}

ć“ć‚Œć§å‡¦ē†ć‚’å¤–ć«å‡ŗć›ć¾ć—ćŸć€‚

恌态visitćƒ”ć‚½ćƒƒćƒ‰ć®ęˆ»ć‚Šå€¤ćŒintć ć£ćŸć‚Šćć‚‚ćć‚‚Printer恧ćÆęˆ»ć‚Šå€¤ćŒę„å‘³ćŖć‹ć£ćŸć‚Šć—ć¦ć‚‚ć‚„ć‚‚ć‚„ć—ć¾ć™ć­ć€‚

ć‚ø悧惍ćƒŖć‚Æć‚¹ć‚’ä½æ恆

ä½æć„ć¾ć—ć‚‡ć†ć€‚ å¼•ę•°ćØęˆ»ć‚Šå€¤ć‚’ć‚ø悧惍ćƒŖć‚Æć‚¹ć§ć‚¢ćƒ¬ć—ć¾ć™ć€‚

package visitor;

import java.io.IOException;
import java.io.Writer;

public interface Node6 {

    <R, P> R accept(Visitor6<R, P> visitor, P parameter);
}

class NumNode6 implements Node6 {

    public final int value;

    public NumNode6(int value) {
        this.value = value;
    }

    @Override public <R, P> R accept(Visitor6<R, P> visitor, P parameter) {
        return visitor.visit(this, parameter);
    }
}

class AddNode6 implements Node6 {

    public final Node6 left;
    public final Node6 right;

    public AddNode6(Node6 left, Node6 right) {
        this.left = left;
        this.right = right;
    }

    @Override public <R, P> R accept(Visitor6<R, P> visitor, P parameter) {
        return visitor.visit(this, parameter);
    }
}

interface Visitor6<R, P> {

    R visit(NumNode6 node, P parameter);

    R visit(AddNode6 node, P parameter);
}

class Calclurator6 implements Visitor6<Integer, Void> {

    @Override public Integer visit(NumNode6 node, Void parameter) {
        return node.value;
    }

    @Override public Integer visit(AddNode6 node, Void parameter) {
        int left = node.left.accept(this, parameter);
        int right = node.right.accept(this, parameter);
        return left + right;
    }
}

class Printer6 implements Visitor6<Void, Writer> {

    @Override public Void visit(NumNode6 node, Writer parameter) {
        try {
            parameter.write(String.valueOf(node.value));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return null;
    }

    @Override public Void visit(AddNode6 node, Writer parameter) {
        try {
            parameter.write("(");
            node.left.accept(this, parameter);
            parameter.write("+");
            node.right.accept(this, parameter);
            parameter.write(")");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return null;
    }
}

ć“ć‚Œć§ć ć„ć¶č‰Æć„ę„Ÿć˜ć«ćŖć£ć¦ćć¾ć—ćŸć€‚

恌态Printer恧IOException悒RuntimeExceptionćøćƒ©ćƒƒćƒ—ć—ć¦ć‚‹ćŠćŖ恘ćæć®ć‚³ćƒ¼ćƒ‰ćŒå“€ę„ć‚’ę¼‚ć‚ć›ć¾ć™ć€‚

ä¾‹å¤–ć‚‚ć‚ø悧惍ćƒŖć‚Æć‚¹ć§

ć‚„ć£ć¦ć—ć¾ć„ć¾ć—ć‚‡ć†ć€‚ Visitorć®å®šē¾©ć‚’å°‘ć—äæ®ę­£ć—ć¾ć™ć€‚

package visitor;

import java.io.IOException;
import java.io.Writer;

public interface Node7 {

    <R, P, E extends Exception> R accept(Visitor7<R, P, E> visitor, P parameter)
            throws E;
}

class NumNode7 implements Node7 {

    public final int value;

    public NumNode7(int value) {
        this.value = value;
    }

    @Override public <R, P, E extends Exception> R accept(
            Visitor7<R, P, E> visitor, P parameter) throws E {
        return visitor.visit(this, parameter);
    }
}

class AddNode7 implements Node7 {

    public final Node7 left;
    public final Node7 right;

    public AddNode7(Node7 left, Node7 right) {
        this.left = left;
        this.right = right;
    }

    @Override public <R, P, E extends Exception> R accept(
            Visitor7<R, P, E> visitor, P parameter) throws E {
        return visitor.visit(this, parameter);
    }
}

interface Visitor7<R, P, E extends Exception> {

    R visit(NumNode7 node, P parameter) throws E;

    R visit(AddNode7 node, P parameter) throws E;
}

class Calclurator7 implements Visitor7<Integer, Void, RuntimeException> {

    @Override public Integer visit(NumNode7 node, Void parameter) {
        return node.value;
    }

    @Override public Integer visit(AddNode7 node, Void parameter) {
        int left = node.left.accept(this, parameter);
        int right = node.right.accept(this, parameter);
        return left + right;
    }
}

class Printer7 implements Visitor7<Void, Writer, IOException> {

    @Override public Void visit(NumNode7 node, Writer parameter)
            throws IOException {
        parameter.write(String.valueOf(node.value));
        return null;
    }

    @Override public Void visit(AddNode7 node, Writer parameter)
            throws IOException {
        parameter.write("(");
        node.left.accept(this, parameter);
        parameter.write("+");
        node.right.accept(this, parameter);
        parameter.write(")");
        return null;
    }
}

悂恆恠恄恶čØ³ć®åˆ†ć‹ć‚‰ćŖ恄ć‚Æć‚½ć‚³ćƒ¼ćƒ‰ćØćŖć£ć¦ććŸę„Ÿć˜ćŒć—ć¾ć™ćŒć€ Calculator恧ćÆ惁悧惃ć‚Æä¾‹å¤–ć‚’ęŠ•ć’ćšć€Printer恧ćÆIOException悒ꊕ恒悋悈恆ćŖč”Øē¾ćŒ ć§ćć¾ć—ćŸć€‚ 恊ē–²ć‚Œę§˜ć§ć—ćŸć€‚

他恮č؀čŖžć§ćÆ恩恆ćŖ恮恋

Groovy恧ćÆć©ć®ćƒ”ć‚½ćƒƒćƒ‰ć‚’å‘¼ć¶ć‹ćÆå®Ÿč”Œę™‚ć«ę±ŗć¾ć‚‹ć®ć§acceptćƒ”ć‚½ćƒƒćƒ‰ćŒäøč¦ć§ć™ć€‚ ćŸć—ć‹å‹•ēš„ćƒ‡ć‚£ć‚¹ćƒ‘ćƒƒćƒćØå‘¼ć°ć‚Œć¦ć„ćŸćØę€ć„ć¾ć™ć€‚

class AddNode {
    def left
    def right
}

class NumNode {
    def value
}

class Calculator {
    def visit(AddNode node) {
        visit(node.left) + visit(node.right)
    }
    def visit(NumNode node) { node.value }
}

def node1 = new NumNode(value: 2)
def node2 = new NumNode(value: 3)
def node3 = new AddNode(left: node1, right: node2)
def node4 = new NumNode(value: 4)
def node5 = new AddNode(left: node3, right: node4)
def calculator = new Calculator()
def actual = calculator.visit(node5)

assert actual == (2 + 3 + 4)

ć¾ćŸScala恧ćÆ惑ć‚æćƒ¼ćƒ³ćƒžćƒƒćƒć‚’ä½æ恈恰č‰Æ恄恧恙怂 ć‚±ćƒ¼ć‚¹ć®ę¼ć‚ŒćÆsealed悒ä½æ恈恰ꤜå‡ŗåÆčƒ½ć ć£ćŸćØę€ć„ć¾ć™ć€‚

sealed trait Node
case class NumNode(value: Int) extends Node
case class AddNode(left: Node, right: Node) extends Node

def calc(node: Node): Int = node match {
  case NumNode(value) => value
  case AddNode(left, right) => calc(left) + calc(right)
}

val node1 = NumNode(2)
val node2 = NumNode(3)
val node3 = AddNode(node1, node2)
val node4 = NumNode(4)
val node5 = AddNode(node3, node4)
val actual = calc(node5)

assert(actual == (2 + 3 + 4))

ćć‚Œć«ć€Nodeć‚’åˆ†č§£ć—ć¦value悄left态rightć‚’å–ć‚Šå‡ŗć—ćŸć‚Šć§ćć¦visitor惑ć‚æćƒ¼ćƒ³ć‚ˆć‚Šč¶…é«˜ę©Ÿčƒ½ć§ć™ć€‚ ć—ć‹ć‚‚ć‚³ćƒ¼ćƒ‰ēŸ­ć„恗怂 静ēš„ćŖć‚¢ćƒ¬ć ć—ć€‚

ć¾ćØ悁

Java恧ćÆćƒ‡ćƒ¼ć‚æćØć‚¢ćƒ«ć‚“ćƒŖć‚ŗćƒ ć‚’åˆ†é›¢ć™ć‚‹ćØ恍态

  • instanceofćÆć‚±ćƒ¼ć‚¹ć®ę¼ć‚Œć‚’é™ēš„ć«ę¤œå‡ŗ恧恍ćŖ恄
  • switchćÆString态primitive态enumć—ć‹å—ć‘ä»˜ć‘ćŖ恄
  • 惑ć‚æćƒ¼ćƒ³ćƒžćƒƒćƒćŒē„”恄

ćŖ恩恮ē†ē”±ć«ć‚ˆć‚ŠVisitor惑ć‚æćƒ¼ćƒ³ć‚’ä½æć‚ć–ć‚‹ć‚’å¾—ćŖć„å “åˆćŒć‚ć‚Šć¾ć™ć€‚ ć—ć‹ć—ę•°ć‚ć‚‹ćƒ‡ć‚¶ć‚¤ćƒ³ćƒ‘ć‚æćƒ¼ćƒ³ć®äø­ć§ć‚‚Visitor惑ć‚æćƒ¼ćƒ³ćÆē†č§£ć™ć‚‹ć®ćŒé›£ć—ć„ć‚ˆć†ć«ę€ć„ć¾ć™ć€‚ ć¾ćŸćć‚ŒćŖ悊恫걎ē”Øēš„ć«ć—ć‚ˆć†ćØꀝ恆ćØć‚ø悧惍ćƒŖć‚Æć‚¹ć‚’ä½æć£ć¦č¤‡é›‘ćŖ定ē¾©ć«ćŖć£ć¦ć—ć¾ć£ćŸć‚Šć€‚

ć‚ˆć£ć¦ć€ä½æ悏ćŖćć¦ęøˆć‚€ćŖć‚‰ćć‚Œć«č¶Šć—ćŸäŗ‹ćÆē„”恏态ä½æć†å “åˆć§ć‚‚ęœ¬å½“ć«Visitor惑ć‚æćƒ¼ćƒ³ćŒåæ…要ćŖć®ć‹ć—ć£ć‹ć‚Šę¤œčØŽć™ć¹ćć ćØę€ć„ć¾ć™ć€‚

ē§ć‚‚ęœ€čæ‘ć€č‰²ć€…ć‚ć£ć¦Visitor惑ć‚æćƒ¼ćƒ³ć‚’ä½æć£ć¦ć—ć¾ć„ć¾ć—ćŸćŒć€ć‚‚ć£ćØč‰Æ恄čØ­čØˆćŒć‚ć£ćŸć‚ˆć†ćŖę°—ćŒć—ć¦ć„ć¾ć™ć€‚

恓悓ćŖć¾ćØ悁恧恈恈悓恋ļ¼Ÿ

ć¾ć‚ć„ć„ć‹ć€‚

]]>
Sun, 22 Dec 2013 00:00:00 +0900
http://backpaper0.github.io/2013/12/03/javaee_advent_calendar_2013.html http://backpaper0.github.io/2013/12/03/javaee_advent_calendar_2013.html <![CDATA[ē§ć®BeanValidation恮ä½æć„ę–¹(Java EE Advent Calendar 2013)]]> ē§ć®BeanValidation恮ä½æć„ę–¹(Java EE Advent Calendar 2013)

恓恮ć‚Øćƒ³ćƒˆćƒŖćÆ Java EE Advent Calendar 2013 恮3ę—„ē›®ć§ć™ć€‚ ę˜Øę—„ćÆ @matsumana ć•ć‚“ć®ć”ę‹…å½“ć§ JAX-RS + mustache - @matsumana ć®ęŠ€č”“ćƒ”ćƒ¢ 恧恗恟怂

今回ćÆBeanValidation恮č‡Ŗ分ćŖ悊恮ä½æć„ę–¹ć‚’ć”ē“¹ä»‹ć—ć¾ć™ć€‚

ćć®å‰ć«

BeanValidation恦ćŖ悓悄ļ¼ŸćØć„ć†ę–¹ćÆ JSR 349 ć®ä»•ę§˜ć‚’čŖ­ć‚€ćØč‰Æ恄恧恗悇恆怂 200ćƒšćƒ¼ć‚øč¶…ćˆć¦ć¾ć™ćŒåŠåˆ†ä»„äøŠć‚³ćƒ¼ćƒ‰ć£ć½ć„ć®ć§ćć‚“ćŖć«ć—ć‚“ć©ććŖ恄悓恘悃ćŖ恄恋ćØꀝ悏ćŖ恏悂ćŖ恄恑恩恩恆恧恗悇恆恋ļ¼Ÿ

悂恗恏ćÆ怌BeanValidation 恗悓恕悓怍恧悰悰悋ćØč‰Æ恄恧恙悈怂

ęœ¬é”Œ

BeanValidation恧ćÆćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć‚„getter恫@NotNullćØ恋@SizećØć‹ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ćƒ¢ćƒŖćƒ¢ćƒŖä»˜ć‘ć¦ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ć™ć‚‹ć‚ć‘ć§ć™ćŒć€čŖæå­ć«ä¹—ć£ć¦ć‚‹ćØć™ćć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³åœ°ē„恫ćŖć£ć¦ć‚­ćƒ„ć„ć®ć§ć™ć€‚ 恧恙恮恧ē‰¹å®šć®ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ć‚’é›†ē“„ć™ć‚‹ę–¹ę³•ćŒę¬²ć—ć„ć‚ć‘ć§ć—ć¦ć€ę­£ę”»ę³•ćÆē‹¬č‡Ŗć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’å°Žå…„ć—ć¦ćć“ć«é›†ē“„恙悋恓ćØ恠ćØę€ć„ć¾ć™ćŒć€ē§ćÆåˆ„ć®ć‚„ć‚Šę–¹ć‚’ęŽ”ē”Øć—ć¦ć„ć¾ć™ć€‚

ć¾ćšć€ę­£ę”»ę³•ćØåŒć˜ćē‹¬č‡Ŗć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćØConstraintValidatorć‚’å°Žå…„ć—ć¾ć™ć€‚ ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćÆ恓悓ćŖꄟ恘怂

package net.hogedriven.backpaper0.javaeeadventcalendar2013;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.validation.Constraint;
import javax.validation.Payload;

@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Constraint(validatedBy = { DomainValidator.class })
public @interface DomainType {

    String message() default "";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
    @Retention(RUNTIME)
    @Documented
    @interface List {

        DomainType[] value();
    }
}

č‡³ć£ć¦ę™®é€šć§ć™ć­ć€‚

ē¶šć„恦ConstraintValidatorćÆ恓悓ćŖꄟ恘恧恙怂

package net.hogedriven.backpaper0.javaeeadventcalendar2013;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class DomainValidator implements
        ConstraintValidator<DomainType, WithValidation> {

    @Override
    public void initialize(DomainType constraintAnnotation) {
    }

    @Override
    public boolean isValid(WithValidation value,
            ConstraintValidatorContext context) {

        if (value == null) {
            return true;
        }

        String message = value.validate();
        if (message == null) {
            return true;
        }

        context.disableDefaultConstraintViolation();
        context.buildConstraintViolationWithTemplate(message)
                .addConstraintViolation();

        return false;
    }
}

isValidćƒ”ć‚½ćƒƒćƒ‰ć§ćÆ具体ēš„ćŖ惐ćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ćÆč”Œć‚ćšWithValidation#validateć«ä»»ć›ć¦ć„ć¾ć™ć€‚

WithValidationå®Ÿč£…ć‚Æćƒ©ć‚¹ćÆä¾‹ćˆć°ć“ć‚“ćŖꄟ恘怂

package net.hogedriven.backpaper0.javaeeadventcalendar2013;

public class UserId implements WithValidation {

    private final String value;

    public UserId(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    @Override
    public String validate() {

        if (value.length() > 10) {
            return "10ę–‡å­—ä»„äø‹ć§ļ½µļ¾…ļ½¼ļ½¬ļ½½";
        }

        for (char c : value.toCharArray()) {
            if (('a' <= c && c <= 'z') == false
                    && ('A' <= c && c <= 'Z') == false
                    && ('0' <= c && c <= '9') == false) {
                return "ć‚¢ćƒ«ćƒ•ć‚”ćƒ™ćƒƒćƒˆćØę•°å­—ć§ć‚ˆć‚ć‚";
            }
        }

        return null;
    }

    public static UserId fromString(String value) {
        if (value == null || value.isEmpty()) {
            return null;
        }
        return new UserId(value);
    }
}

validatećƒ”ć‚½ćƒƒćƒ‰å†…ć§č©³ć—ćå€¤ć‚’ćƒć‚§ćƒƒć‚Æ恗恦ć‚Øćƒ©ćƒ¼ćŒćŖ恑悌恰null悒态ć‚Øćƒ©ćƒ¼ćŒć‚ć£ćŸć‚‰ć‚Øćƒ©ćƒ¼ćƒ”ćƒƒć‚»ćƒ¼ć‚ø悒čæ”ć—ć¦ć„ć¾ć™ć€‚

ConstraintValidator恮isValidćƒ”ć‚½ćƒƒćƒ‰ć§ćÆ恓恮validatećƒ”ć‚½ćƒƒćƒ‰ć§ć‚Øćƒ©ćƒ¼ćŒčæ”ć£ć¦ććŸć‚‰ćć‚Œć‚’ć‚‚ćØ恫ConstraintViolation悒ēµ„ćæē«‹ć¦ć¾ć™ć€‚

ćŖćœć“ć®ę–¹ę³•ć‚’å–ć‚‹ć®ć‹

ē§ć®å¤§å„½ććŖ JAX-RS 恧ćÆćƒŖć‚Æć‚Øć‚¹ćƒˆćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚„ćƒ•ć‚©ćƒ¼ćƒ ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ悒ē‹¬č‡Ŗ恮ć‚Æćƒ©ć‚¹ć§å—ć‘å–ć‚‹ć“ćØ恌å‡ŗę„ć¾ć™ć€‚ 恧态jersey-mvcä½æć£ć¦ē”»é¢ć‚‚ćƒ¢ćƒŖćƒ¢ćƒŖę›øć„ć¦ć‚‹ć®ć§ćć‚ŒćŖć‚Šć®ćƒ”ćƒƒć‚»ćƒ¼ć‚ø恌čæ”ć‚‹ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ć—ćŸć„ć®ć§ć™ć€‚ 恗恋悂悂恮恐恕ćŖ恮恧å‡ŗę„ć‚‹ć ć‘ę„½ć—ćŸć„ćŖćƒ¼ć€ćØ考恈恟悊考恈ćŖć‹ć£ćŸć‚Šć—ćŖćŒć‚‰č‰²ć€…č©¦ć—ć¦ä»Šć“ć“ć€ćØć„ć£ćŸę„Ÿć˜ć§ć™ć€‚ ćć‚Œć«ć—ć¦ć‚‚JAX-RS恄恄悈JAX-RS怂

恔ćŖćæ恫DomainTypećØć„ć†åå‰ć«ć—ć¦ć„ć‚‹ć®ćÆDDDē”±ę„恧ćÆćŖćć¦ē§ć®å¤§å„½ććŖ Doma ćØć„ć†ćƒ•ćƒ¬ćƒ¼ćƒ ćƒÆćƒ¼ć‚Æć®ę©Ÿčƒ½ć§ć‚ć‚‹ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć«åÆ¾ć—ć¦ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ä»˜ć‘ć‚‹ć“ćØćŒå¤šć„ć®ć§ćć†ć„ć†åå‰ć«ć—ć¦ć„ć¾ć™ć€‚ ć„ć‚„ćƒ›ćƒ³ćƒˆDoma恄恄悈Doma怂

惔ćƒŖ惃惈ļ¼†ćƒ‡ćƒ”ćƒŖ惃惈

ć“ć®ę–¹ę³•ć‚’ćØ悋ćØć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćÆ@DomainTypeć‚’ä»˜ć‘ć‚‹ć ć‘ć§č‰Æć„ć®ć§ć©ć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ä½æ恈恰č‰Æ恄恮恋čæ·ć†ć“ćØ悂ćŖć„ć—ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³åœ°ē„ćŒå°‘ć—ćƒžć‚·ć«ćŖć‚Šć¾ć™ć€‚

ćƒ‡ćƒ”ćƒŖćƒƒćƒˆć‚‚ć‚ć£ć¦ć€ć“ć‚ŒćÆč‡Ŗåˆ†ć§ć‚‚ć‚¤ć‚±ć¦ćŖ恄ćØę€ć„ć¾ćć£ć¦ć„ć‚‹ć®ć§ć™ćŒć€WithValidationå®Ÿč£…ć‚Æćƒ©ć‚¹ćŒćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ć™ć‚‹ćŸć‚ć«äøę­£ćŖēŠ¶ę…‹ć‚’čØ±ć—ć¦ć„ć‚‹ć€ćØ恄恆ē‚¹ć§ć™ć€‚ ęœ¬ę„ćŖ悉fromStringćƒ•ć‚”ć‚Æ惈ćƒŖćƒ”ć‚½ćƒƒćƒ‰ć§ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ć—ć¦ćŠć‹ć—ćŖå€¤ć ć£ćŸć‚‰ä¾‹å¤–ęŠ•ć’ć‚‹ć®ćŒę­£é“ćØę€ć„ć¾ć™ć€‚ ć¾ć‚ćƒ”ćƒŖ惃惈ćØćƒ‡ćƒ”ćƒŖ惃惈悒ē§¤ć«ć‹ć‘恦ē¾ēŠ¶ćÆć“ć®ę–¹ę³•ć‚’å–ć£ćØćć®ćŒćƒ™ć‚æćƒ¼ć‚„ćŖ态ćØć„ć£ćŸę‰€ć§ć™ć€‚

ćŠć¾ć‘ļ¼šē›øé–¢ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³

ā€¦ā€¦ćØ恄恆恮恋恩恆恋ćÆēŸ„ć‚Šć¾ć›ć‚“ćŒć€Œé–‹å§‹ę™‚åˆ»ć€ćØ怌ēµ‚äŗ†ę™‚åˆ»ć€ć®å‰å¾Œé–¢äæ‚ćŒę­£ć—ć„ć‹ļ¼Ÿćæ恟恄ćŖćµćŸć¤ä»„äøŠć®å€¤ć‚’ē”Ø恄恟惐ćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ć™ć‚‹ę–¹ę³•ć§ć™ć€‚ ē°”å˜ć§ć™ć€‚

BeanValidationćÆćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć‹getterć«ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ä»˜ć‘ć¦ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ć‚’č”Œć†ć®ć§äø€č¦‹ē›øé–¢ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ćÆč”ŒćˆćŖć„ę°—ćŒć—ć¾ć™ć€‚ ćŒć€ä¾‹ćˆć°ć€ćµćŸć¤ć®å€¤ć‚’ć¾ćØ悁悋TuplećØ恄恆ć‚Æćƒ©ć‚¹ć‚’ä½œć£ć¦ćć‚Œć«åÆ¾ć—ć¦ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ć™ć‚‹ConstraintValidatorć‚’ä½œć‚Œć°ćŠk恧恙怂

č©¦ć—ć«ćµćŸć¤ć®å€¤ćŒåŒć˜ć‹ę¤œčØ¼ć™ć‚‹ć‚„ć¤ć‚’ę›ø恄恦ćæć¾ć—ćŸć€‚

ć¾ćšćÆTuplećØ恄恆ć‚Æćƒ©ć‚¹ć‚’å°Žå…„ć€‚

package net.hogedriven.backpaper0.javaeeadventcalendar2013;

public class Tuple {

    public final String first;

    public final String second;

    public Tuple(String first, String second) {
        this.first = first;
        this.second = second;
    }
}

ꬔ恫ConstraintValidator怂

package net.hogedriven.backpaper0.javaeeadventcalendar2013;

import java.util.Objects;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class EqualValidator implements ConstraintValidator<Equal, Tuple> {

    @Override
    public void initialize(Equal constraintAnnotation) {
    }

    @Override
    public boolean isValid(Tuple value, ConstraintValidatorContext context) {

        if (value == null) {
            return true;
        }

        return Objects.equals(value.first, value.second);
    }
}

ęœ€å¾Œć«ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć€‚

package net.hogedriven.backpaper0.javaeeadventcalendar2013;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.validation.Constraint;
import javax.validation.Payload;

@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Constraint(validatedBy = { EqualValidator.class })
public @interface Equal {

    String message() default "";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
    @Retention(RUNTIME)
    @Documented
    @interface List {

        Equal[] value();
    }
}

ē‰¹åˆ„ćŖ恓ćØćÆćŖ恫悂ćŖć„ć‚³ćƒ¼ćƒ‰ć§ć™ć­ć€‚

ä½æć„ę–¹ćÆę¬”ć®ć‚ˆć†ćŖꄟ恘恧恙怂

private String first;

private String second;

@Equal(message = "é•ć†å€¤ćÆć‚¢ć‚«ćƒ³")
public Tuple getValue() {
    return new Tuple(first, second);
}

ć¾ćŸć€ē›øé–¢ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³ćÆć²ćØć¤ć²ćØć¤ć®å€¤ćŒvalidå‰ęć§ć‚ć‚‹ć“ćØćŒå¤šć„ć§ć—ć‚‡ć†ć‹ć‚‰groups悒äøŠę‰‹ćä½æć£ć¦ć‚¢ćƒ¬ć—ć¦ć‚ć’ć‚Œć°č‰Æ恄恧恙恭怂

ćØ恄恆悏恑恧

č‡Ŗ分ćŖ悊恮BeanValidation恮ä½æć„ę–¹ć§ć—ćŸć€‚

Java EE Advent Calendar 2013ć€ę˜Žę—„ć®ć”ę‹…å½“ćÆ @kazuhira_r 恕悓恧恙怂

]]>
Tue, 03 Dec 2013 00:00:00 +0900
http://backpaper0.github.io/2013/09/26/glassfish_server_xpoweredby.html http://backpaper0.github.io/2013/09/26/glassfish_server_xpoweredby.html <![CDATA[GlassFish v3.1.2.2恧Server惘惃惀ćØX-Powered-By惘惃惀悒čæ”恕ćŖć„ć‚ˆć†ć«ć™ć‚‹]]> GlassFish v3.1.2.2恧Server惘惃惀ćØX-Powered-By惘惃惀悒čæ”恕ćŖć„ć‚ˆć†ć«ć™ć‚‹

ć¾ćšćÆServer惘惃惀怂

asadmin create-jvm-option -Dproduct.name=

JVMć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ćŖ恮恧čØ­å®šć®åę˜ ć«ćÆGlassFishć‚’å†čµ·å‹•ć™ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚

ꬔ态X-Powered-By惘惃惀怂

asadmin set configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.xpowered-by=false

恓恔悉ćÆčح定ćÆå‰‡åę˜ ć•ć‚Œć¾ć™ć€‚

恧态JSP怂 default-web.xml恧JspServlet悒čØ­å®šć—ć¦ć„ć‚‹ćØć“ć‚ć‚’č¦‹ć¤ć‘ć¾ć™ć€‚ ć§ćƒ•ć‚©ćƒ«ćƒˆć§ćÆxpoweredBy恌true恫čØ­å®šć•ć‚Œć¦ć„ć‚‹ć®ć§ć“ć‚Œć‚’falseć«ć—ć¾ć™ć€‚

<servlet>
  <servlet-name>jsp</servlet-name>
  <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
  <init-param>
    <param-name>xpoweredBy</param-name>
    <param-value>false</param-value>
  </init-param>

ęœ€å¾Œć«JSF怂 web.xml恧FacesServlet悒čØ­å®šć™ć‚‹éš›ć«init-param恧com.sun.faces.sendPoweredByHeader悒false恫čØ­å®šć™ć‚‹ćØč‰Æ恄悈恆恧恙怂 試恗恦ćŖ恄怂

]]>
Thu, 26 Sep 2013 00:00:00 +0900
http://backpaper0.github.io/2013/07/17/jaxrs_parameter.html http://backpaper0.github.io/2013/07/17/jaxrs_parameter.html <![CDATA[JAX-RSć§ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®å—ć‘å–ć‚Šę–¹ć‚’ć„ć‚ć„ć‚č©¦ć™]]> JAX-RSć§ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®å—ć‘å–ć‚Šę–¹ć‚’ć„ć‚ć„ć‚č©¦ć™

JAX-RS恧ćÆę¬”ć«ęŒ™ć’ć‚‹ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ćƒ”ć‚½ćƒƒćƒ‰ć®å¼•ę•°ćŖć©ć«ä»˜ć‘ć‚‹ć“ćØ恧ć‚Æć‚ØćƒŖćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚„ćƒ‘ć‚¹ć®äø€éƒØć‚’å—ć‘å–ć‚‹ć“ćØćŒć§ćć¾ć™ć€‚

  • @MatrixParam
  • @QueryParam
  • @PathParam
  • @CookieParam
  • @HeaderParam

ćƒ”ć‚½ćƒƒćƒ‰ć®å¼•ę•°ćÆString悄惗ćƒŖćƒŸćƒ†ć‚£ćƒ–ć‚’ä½æ恆恓ćØćŒć§ćć¾ć™ćŒć€ćć‚Œä»„å¤–ć®ć‚Æćƒ©ć‚¹ć‚‚ä½æē”Øć§ćć¾ć™ć€‚

Stringć®å¼•ę•°ć‚’ć²ćØć¤ć ć‘å—ć‘å–ć‚‹publicćŖć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ悒ꌁ恤ć‚Æćƒ©ć‚¹

ę¬”ć®ć‚ˆć†ćŖć‚Æćƒ©ć‚¹ć§ć‚‚ć‚Æć‚ØćƒŖćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćŖć©ć‚’å—ć‘å–ć‚‹ć“ćØ恌å‡ŗę„ć¾ć™ć€‚

public class Hoge {

    public final String value;

    public Hoge(String value) {
        this.value = value;
    }
}

ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć§ćÆę¬”ć®ć‚ˆć†ć«ä½æć„ć¾ć™ć€‚

@GET
public String get(@QueryParam("abc") Hoge abc) {
    ...

ć“ć®ä¾‹ć§ć„ć†ćØabcćØć„ć†åå‰ć®ć‚Æć‚ØćƒŖćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恌nullć®å “åˆćÆHogećÆć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć•ć‚Œćšå¼•ę•°abcćÆnullćØćŖć‚Šć¾ć™ć€‚ ć‚Æć‚ØćƒŖćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恌nullć®å “åˆćØ恄恆恮ćÆabcćØć„ć†åå‰ć®ć‚Æć‚ØćƒŖćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恌ē„”ć„å “åˆć§ć™ć€‚ ?abc=&def=xyz ćØ恄恆悈恆ćŖć‚Æć‚ØćƒŖćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®å “åˆćÆabcćÆnull恧ćÆćŖ恏ē©ŗę–‡å­—åˆ—ć§ć™ć€‚

Stringć®å¼•ę•°ć‚’ć²ćØć¤ć ć‘å—ć‘å–ć‚‹ā€valueOfā€ćØć„ć†åå‰ć®staticćƒ•ć‚”ć‚Æ惈ćƒŖćƒ”ć‚½ćƒƒćƒ‰ć‚’ęŒć¤ć‚Æćƒ©ć‚¹

ę¬”ć®ć‚ˆć†ćŖć‚Æćƒ©ć‚¹ć‚’ä½æē”Ø恙悋恓ćØ悂åÆčƒ½ć§ć™ć€‚

public class Hoge {

    public final String value;

    private Hoge(String value) {
        this.value = value;
    }

    public static Hoge valueOf(String value) {
        return new Hoge(value);
    }
}

staticćƒ•ć‚”ć‚Æ惈ćƒŖćƒ”ć‚½ćƒƒćƒ‰ć‚’ę›øćåˆ†ć®ę‰‹é–“ćŒå¢—ćˆć¾ć™ćŒć€ä¾‹ćˆć°ć€

  • value恌ē©ŗę–‡å­—åˆ—ć®å “åˆćÆnull悒čæ”恙
  • Integerć®ć‚ˆć†ć«ć‚­ćƒ£ćƒƒć‚·ćƒ„ć™ć‚‹ć“ćØ恌恧恍悋
  • ć‚µćƒ–ć‚Æćƒ©ć‚¹ć‚’čæ”恙恓ćØ恌恧恍悋

ćØ恄恆é¢Øć«ęŸ”č»Ÿć«å®Ÿč£…ć™ć‚‹ć“ćØ恌åÆčƒ½ć§ć™ć€‚ ć¾ćŸć€ć‚Æćƒ©ć‚¹ļ¼ˆć“ć®ä¾‹ć§ć„ć†ćØHogeļ¼‰ć‚’abstract恫恙悋恓ćØ悂åÆčƒ½ć§ć™ć€‚

Stringć®å¼•ę•°ć‚’ć²ćØć¤ć ć‘å—ć‘å–ć‚‹ā€fromStringā€ćØć„ć†åå‰ć®staticćƒ•ć‚”ć‚Æ惈ćƒŖćƒ”ć‚½ćƒƒćƒ‰ć‚’ęŒć¤ć‚Æćƒ©ć‚¹

staticćƒ•ć‚”ć‚Æ惈ćƒŖćƒ”ć‚½ćƒƒćƒ‰ćÆvalueOfä»„å¤–ć«fromStringćØć„ć†åå‰ć«ć™ć‚‹ć“ćØ悂åÆčƒ½ć§ć™ć€‚

ć²ćØ恤恮ć‚Æćƒ©ć‚¹ć«valueOfćØfromString恮äø”ę–¹ćŒå®šē¾©ć•ć‚Œć¦ć„ć‚‹å “合ćÆvalueOfćŒå‘¼ć°ć‚Œć¾ć™ć€‚ ćŸć ć—åˆ—ęŒ™åž‹ć®å “åˆćÆvalueOfćŒęš—é»™ēš„ć«å®Ÿč£…ć•ć‚Œć¦ćŠć‚ŠęŒ™å‹•ć‚’äøŠę›ø恍恧恍ćŖ恄恟悁恋态fromStringćŒå‘¼ć°ć‚Œć¾ć™ć€‚ åˆ—ęŒ™åž‹ć§ćŖ恏ćØ悂fromString悒å„Ŗå…ˆć«ć—ć¦ćŠć‘ć°č‰Æć‹ć£ćŸć®ć§ćÆ态ćØꀝ悏ćŖ恏悂ćŖ恄恧恙怂

ParamConverter悒ä½æē”Ø恙悋

JAX-RS 2恋悉

ćØć„ć†ćµćŸć¤ć®ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ćŒčæ½åŠ ć•ć‚Œć¾ć—ćŸć€‚

ParamConverterć®å®Ÿč£…ć‚Æćƒ©ć‚¹ć§ćÆStringć‹ć‚‰ä»»ę„ć®ć‚Æćƒ©ć‚¹ć«å¤‰ę›ć™ć‚‹ćƒ­ć‚ø惃ć‚Æ悒ę›øćć¾ć™ć€‚

public class HogeParamConverter implements ParamConverter<Hoge> {

    @Override
    public Hoge fromString(String value) {
        return new Hoge(value);
    }

    @Override
    public String toString(Hoge hoge) {
        return hoge.value;
    }
}

ParamConverterProviderć®å®Ÿč£…ć‚Æćƒ©ć‚¹ć§ćÆćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć®å¼•ę•°ć®åž‹ć‚„ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ć‚‚ćØ恫ParamConverter悒éøꊞ恗恦čæ”ć—ć¾ć™ć€‚

public class HogeParamConverterProvider implements ParamConverterProvider {

    @Override
    public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
        if (rawType == Hoge.class) {
            return (ParamConverter<T>) new HogeParamConverter();
        }
        return null;
    }
}

ć“ć®ę–¹ę³•ćÆäø€ē•Ŗę‰‹é–“ćŒć‹ć‹ć‚Šć¾ć™ćŒstaticćƒ•ć‚”ć‚Æ惈ćƒŖćƒ”ć‚½ćƒƒćƒ‰ć‚’ē”Øć„ć‚‹ę–¹ę³•ćØęÆ”ć¹ć¦

  • Hogeć‚’ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ć«ć™ć‚‹ć“ćØ恌åÆčƒ½
  • åŒć˜åž‹ć«åÆ¾ć—ć¦ć‚‚ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć«ć‚ˆć£ć¦ē•°ćŖ悋ParamConverter悒ä½æē”Ø恧恍悋
  • javać‹ć‚‰å§‹ć¾ć‚‹ćƒ‘ćƒƒć‚±ćƒ¼ć‚ø恮ć‚Æćƒ©ć‚¹ćŖć©ę—¢å­˜ć®ć‚Æćƒ©ć‚¹ć‚‚ä½æē”Ø恧恍悋

ćØć„ć£ćŸć“ćØćŒåˆ©ē‚¹ć ćØę€ć„ć¾ć™ć€‚

ć¾ćØ悁

JAX-RS 2恋悉ParamConverterćŒå…„ć£ćŸäŗ‹ć§ć‚ÆćƒŖć‚Øćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ悄ćƒŖć‚Æć‚Øć‚¹ćƒˆćƒ˜ćƒƒćƒ€ć‚’ć©ć‚“ćŖåž‹ć§ć‚‚å—ć‘å–ć‚‹ć“ćØćŒć§ćć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚ ć‚¤ćƒ³ć‚æćƒ¼ć‚»ćƒ—ć‚æćƒ¼ć‚„ć‚Æćƒ©ć‚¤ć‚¢ćƒ³ćƒˆAPI恫ęÆ”ć¹ć‚‹ćØåœ°å‘³ć«č¦‹ćˆć¾ć™ćŒć€ćŖ恋ćŖ恋ē“ ę™“ć‚‰ć—ć„é€²åŒ–ć ćØ個äŗŗēš„恫ćÆę€ć£ć¦ć„ć¾ć™ć€‚

ć‚µćƒ³ćƒ—ćƒ«ę›øćć¾ć—ćŸć€‚

]]>
Wed, 17 Jul 2013 00:00:00 +0900
http://backpaper0.github.io/2013/07/15/websocket_pathparam.html http://backpaper0.github.io/2013/07/15/websocket_pathparam.html <![CDATA[Java API for WebSocket恮@PathParam悒試恙]]> Java API for WebSocket恮@PathParam悒試恙

@PathParam ćØć„ć†ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć§ćƒ‘ć‚¹ć®äø€éƒØć‚’ćƒ”ć‚½ćƒƒćƒ‰ć®å¼•ę•°ć§å—ć‘å–ć‚‹ć“ćØ恌恧恍悋悈恆ćŖ恮恧試恗恦ćæć¾ć—ćŸć€‚

package chat;

import java.io.IOException;
import java.util.concurrent.CopyOnWriteArraySet;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;

@ServerEndpoint(value = "/chat/{guest-id}")
public class ChatEndPoint {

    private static CopyOnWriteArraySet<Session> sessions = new CopyOnWriteArraySet<>();

    @OnOpen
    public void onOpen(@PathParam("guest-id") String guestId, Session session) {
        sessions.add(session);
        for (Session s : sessions) {
            s.getAsyncRemote().sendText(guestId + "ć•ć‚“ćŒå…„å®¤ć—ć¾ć—ćŸ");
        }
    }

    @OnMessage
    public void onMessage(@PathParam("guest-id") String guestId, String text) throws
            IOException {
        for (Session s : sessions) {
            s.getAsyncRemote().sendText("[" + guestId + "] " + text);
        }
    }

    @OnClose
    public void onClose(@PathParam("guest-id") String guestId, Session session) {
        sessions.remove(session);
        for (Session s : sessions) {
            s.getAsyncRemote().sendText(guestId + "ć•ć‚“ćŒé€€å®¤ć—ć¾ć—ćŸ");
        }
    }
}

ć‚Æćƒ©ć‚¹ć«ä»˜ć‘ćŸServerEndpoint恫ę›øć‹ć‚ŒćŸćƒ‘ć‚¹ć®äø€éƒØ恌 {guest-id} ćØćŖć£ć¦ć„ć¾ć™ć­ć€‚ ćć‚Œć‚’ćƒ”ć‚½ćƒƒćƒ‰ć®å¼•ę•°ć« @PathParam(ā€œguest-idā€) ćØä»˜ć‘ć¦å—ć‘å–ć£ć¦ć„ć¾ć™ć€‚ ē°”å˜ć§ć™ć­ć€‚

ä»Šå›žć®ć‚½ćƒ¼ć‚¹

ä»Šå›žä½œć£ćŸć‚Æćƒ©ć‚¹ćÆchatćØć„ć†ćƒ‘ćƒƒć‚±ćƒ¼ć‚øć«ć—ć¦ć„ć¾ć™ć€‚ ć¾ćŸć€mvn -Pchat exec:java ćØć™ć‚Œć°ć‚µćƒ¼ćƒćŒē«‹ć”äøŠćŒć‚‹ć‚ˆć†ć«ć—ć¦ć„ć¾ć™ć€‚ ć‚Æćƒ©ć‚¤ć‚¢ćƒ³ćƒˆćÆchat.html恧恙怂 Chromeć§ä½•ćØćŖćå‹•ćć“ćØ悒ē¢ŗčŖć—ć¦ć„ć¾ć™ć€‚ ć‚µćƒ¼ćƒć‚’ēµ‚äŗ†ć—ćŸć„å “合ćÆć‚³ćƒ³ć‚½ćƒ¼ćƒ«ć§ä½•ć‹ć‚­ćƒ¼ć‚’ęŠ¼ć—ć¦ćć ć•ć„ć€‚

ćŖćŠć€ä»Šå›žć®ć‚³ćƒ¼ćƒ‰ćÆ恍恗恠恕悓恌äø‹čؘć‚Øćƒ³ćƒˆćƒŖ恧ę›øć‹ć‚ŒćŸć‚‚ć®ć‚’å‚č€ƒć«ć—ć¾ć—ćŸć€‚

]]>
Mon, 15 Jul 2013 00:00:00 +0900
http://backpaper0.github.io/2013/07/14/websocket.html http://backpaper0.github.io/2013/07/14/websocket.html <![CDATA[Java SE恧WebSocketć‚µćƒ¼ćƒć‚’ē«‹ć¦ć¦éŠć¶]]> Java SE恧WebSocketć‚µćƒ¼ćƒć‚’ē«‹ć¦ć¦éŠć¶

å…ˆć ć£ć¦ćƒŖćƒŖćƒ¼ć‚¹ć•ć‚ŒćŸJava EE 7恫 JSR 356: Java API for WebSocket ćŒå…„ć‚Šć¾ć—ćŸć€‚ GlassFish v4ćŖć©ć‚’åˆ©ē”Ø恙悌恰WebSocketć§éŠć¹ć¾ć™ć€‚

ćŒć€ć‚„ć£ć±Java SEć§å‹•ć‹ć—ćŸć„ć§ć™ć‚ˆć­ļ¼Ÿ 恭ļ¼Ÿ

ćØ恄恆悏恑恧JSR 356ć®å‚ē…§å®Ÿč£…恧恂悋Tyrus悒ä½æć„ć¾ć™ć€‚

ć‚µćƒ¼ćƒå“ć®ć‚Øćƒ³ćƒ‰ćƒć‚¤ćƒ³ćƒˆć‚’ä½œęˆć—ć¾ć™ć€‚ POJOć«ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ä»˜ć‘ć‚‹ę„Ÿć˜ć§ć™ć€‚

import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

@ServerEndpoint("/echo")
public class EchoServerEndPoint {

    @OnOpen
    public void onOpen(Session session) {
        System.out.println("[open] " + session);
    }

    @OnMessage
    public String onMessage(String message, Session session) {
        System.out.println("[" + message + "] " + session);
        return message;
    }

    @OnClose
    public void onClose(Session session) {
        System.out.println("[close] " + session);
    }
}

@OnOpenćÆć‚»ćƒƒć‚·ćƒ§ćƒ³ćŒē¢ŗē«‹ć—ćŸćØ恍态@OnMessagećÆć‚Æćƒ©ć‚¤ć‚¢ćƒ³ćƒˆć‹ć‚‰ćƒ”ćƒƒć‚»ćƒ¼ć‚øćŒå±Šć„ćŸćØ恍态@OnClosećÆć‚»ćƒƒć‚·ćƒ§ćƒ³ćŒåˆ‡ę–­ć•ć‚ŒćŸćØćć«å‘¼ć°ć‚Œć¾ć™ć€‚ @OnMessageć‚’ä»˜ć‘ćŸćƒ”ć‚½ćƒƒćƒ‰ć§ćÆć‚Æćƒ©ć‚¤ć‚¢ćƒ³ćƒˆćŒé€äæ”ć—ćŸćƒ†ć‚­ć‚¹ćƒˆć‚’Stringć®å¼•ę•°ć§å—ć‘å–ć‚‹ć“ćØćŒć§ćć¾ć™ć€‚ ćŖ恊态惐悤惊ćƒŖćƒ”ćƒƒć‚»ćƒ¼ć‚ø恠ćØbyte[]悄ByteBufferć§å—ć‘å–ć‚Œć‚‹ć‚ˆć†ć§ć™ć€‚ ć¾ćŸć€ć“ć®ćƒ”ć‚½ćƒƒćƒ‰ćÆString悒čæ”ć—ć¦ć„ć¾ć™ćŒć“ć‚ŒćÆć‚Æćƒ©ć‚¤ć‚¢ćƒ³ćƒˆćø送äæ”ć•ć‚Œć‚‹ćƒ†ć‚­ć‚¹ćƒˆćƒ”ćƒƒć‚»ćƒ¼ć‚øćØćŖć‚Šć¾ć™ć€‚

恧ćÆę¬”ć«ć“ć‚Œć‚’Java SEć§å‹•ć‹ć™ćŸć‚ć®ć‚³ćƒ¼ćƒ‰ć‚’ę›øćć¾ć™ć€‚

import java.io.IOException;
import javax.websocket.DeploymentException;
import org.glassfish.tyrus.server.Server;

public class EchoMain {

    public static void main(String[] args) throws Exception {
        Server server = new Server("localhost", 8080, "/ws", EchoServerEndPoint.class);
        try {
            server.start();
            System.in.read();
        } finally {
            server.stop();
        }
    }
}

Serverć®ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æć«ćƒ›ć‚¹ćƒˆć€ćƒćƒ¼ćƒˆć€ćƒ«ćƒ¼ćƒˆćƒ‘ć‚¹ć€ć‚Øćƒ³ćƒ‰ćƒć‚¤ćƒ³ćƒˆć®ć‚Æćƒ©ć‚¹ć‚’ęø”ć—ć¦ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć—ć€startćƒ”ć‚½ćƒƒćƒ‰ć‚’å‘¼ć¹ć°WebSocketć‚µćƒ¼ćƒć®å‡ŗę„äøŠćŒć‚Šć§ć™ć€‚ 恂ćØćÆć‚Æćƒ©ć‚¤ć‚¢ćƒ³ćƒˆć‹ć‚‰ ws://localhost:8080/ws/echo 恫ꎄē¶šć™ć‚Œć°OK恧恙怂 ē°”å˜ć§ć™ć­ć€‚

]]>
Sun, 14 Jul 2013 00:00:00 +0900
http://backpaper0.github.io/2013/07/07/devkan_jaxrs.html http://backpaper0.github.io/2013/07/07/devkan_jaxrs.html <![CDATA[DevLOVE関č„æ怌開ē™ŗć‚¹ć‚æćƒ¼ć‚æćƒ¼ć‚­ćƒƒćƒˆć€ć«ćŠć‘ć‚‹JAX-RS恮ē°”単ćŖč§£čŖ¬]]> DevLOVE関č„æ怌開ē™ŗć‚¹ć‚æćƒ¼ć‚æćƒ¼ć‚­ćƒƒćƒˆć€ć«ćŠć‘ć‚‹JAX-RS恮ē°”単ćŖč§£čŖ¬

恩恆悂态GlassFishćØJAX-RS悒ļ¼ˆćƒ»āˆ€ćƒ»ļ¼‰ļ½²ļ½²ļ¾–ļ½²ļ½²ļ¾–ļ½°ćØčØ€ć£ć¦ć„ćŸ2ē•Ŗćƒ†ćƒ¼ćƒ–ćƒ«TAć®ć†ć‚‰ćŒćæ恧恙怂

ćØć„ć†ć‚ć‘ć§å‚åŠ ć•ć‚ŒćŸćæćŖ恕悓态恊ē–²ć‚Œę§˜ć§ć—ćŸć€‚ 恄恄悈恄恄悈ćØčØ€ć„ć¾ćć£ć¦ćŸę‰‹å‰ć€ä»Šå›žć®JAX-RSć‚’åˆ©ē”Øć—ć¦ć„ćŸć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ć‚’ć‹ć‚‹ćƒ¼ćč§£čŖ¬ć—恦恊恓恆ćØę€ć„ć¾ć™ć€‚

ć¾ćšćÆDevKanApplication.java恧恙怂

@ApplicationPath("/services")
public class DevKanApplication extends Application {
}

Application悒ē¶™ę‰æ恗恦@ApplicationPath恧ę³Øé‡ˆć—ć¦ć„ć¾ć™ćŒć€ć“ć®ć‚Æćƒ©ć‚¹ćŒć‚ć‚Œć°GlassFish恕悓恌 怌恊态恓悌ćÆJAX-RS恮å‡ŗē•Ŗ悄ćŖ( ļ½°`Š“ļ½°Ā“)ļ½·ļ¾˜ļ½Æ怍 ćØ恄恆ꄟ恘恧čŖč­˜ć—ć¦ćć‚Œć¾ć™ć€‚ ćŖ恊@ApplicationPath恫čØ­å®šć—ć¦ć„ć‚‹ /services 恌åŸŗē‚¹ćØćŖć‚‹ćƒ‘ć‚¹ć«ćŖć‚Šć¾ć™ć€‚

ꬔ恄恧Calculator.java恧恙怂

@Path("/calc")
@Produces(MediaType.TEXT_PLAIN)
public class Calculator {

    @GET
    @Path("add")
    public String add(@QueryParam("a")int a, @QueryParam("b")int b){
        return "2";
    }
}

ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćŒć‚‚ć‚Šć‚‚ć‚Šę›øć‹ć‚Œć¦ć„ć¾ć™ćŒć€ć“ć‚Œć‚‰ćÆHTTPćƒŖć‚Æć‚Øć‚¹ćƒˆ/ćƒ¬ć‚¹ćƒćƒ³ć‚¹ć«åƾåæœć—ć¦ć„ć¾ć™ć€‚ č¶³ć—ē®—恮HTTPćƒŖć‚Æć‚Øć‚¹ćƒˆ/ćƒ¬ć‚¹ćƒćƒ³ć‚¹ćÆ恓悓ćŖę„Ÿć˜ć«ćŖć‚Šć¾ć™ć‚ˆćƒ¼ć€ć£ć¦ć„ć†ć®ć‚’ä½•ćØćŖ恏ę›ø恍å‡ŗć—ć¾ć™ć€‚

ćƒŖć‚Æć‚Øć‚¹ćƒˆćÆ恓悓ćŖꄟ恘怂

GET /devkan-calc/services/calc/add?a=2&b=3 HTTP/1.1

ćƒ¬ć‚¹ćƒćƒ³ć‚¹ćÆ恓悓ćŖꄟ恘怂

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 1

2

見ęÆ”ć¹ć‚‹ćØć‚ˆćåˆ†ć‹ć‚Šć¾ć™ćŒć€

  • ćƒ”ć‚½ćƒƒćƒ‰ć«ę›ø恋悌恟@GETćÆćƒŖć‚Æć‚Øć‚¹ćƒˆćƒ”ć‚½ćƒƒćƒ‰ć«ć€
  • ć‚Æćƒ©ć‚¹ćØćƒ”ć‚½ćƒƒćƒ‰ć«ę›ø恋悌恟@PathćÆćƒŖć‚Æć‚Øć‚¹ćƒˆć®ćƒ‘ć‚¹ć«ć€
  • ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ę›ø恋悌恟@QueryParamćÆćƒŖć‚Æć‚Øć‚¹ćƒˆć®ć‚Æć‚ØćƒŖćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫态
  • ć‚Æćƒ©ć‚¹ć«ę›ø恋悌恟@ProducesćÆćƒ¬ć‚¹ćƒćƒ³ć‚¹ć®Content-Type恫态

恝悌恞悌åƾåæœć—ć¦ć„ć¾ć™ć€‚ 恤恄恧恫čØ€ć†ćØć€ęˆ»ć‚Šå€¤ćÆćƒ¬ć‚¹ćƒćƒ³ć‚¹ć®ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒœćƒ‡ć‚£ć«åƾåæœć—ć¦ć„ć¾ć™ć­ć€‚ HTTP悒ēŸ„ć£ć¦ć„ć‚Œć°JAX-RSćÆä½æćˆć‚‹ć‚ˆćƒ¼ć€ćØ恄恆ꄟ恘恧恙恭怂

仄äøŠć€JAX-RS恮ē°”単ćŖč§£čŖ¬ćŠć‚ć‚Šć€‚

WARć‚’č¦—ć

jar -tf build/libs/devkan-calc.war ćØę‰“ć£ć¦WAR恮äø­čŗ«ć‚’覗恄恦ćæć¾ć—ć‚‡ć†ć€‚ WARćƒ•ć‚”ć‚¤ćƒ«ć®äø­čŗ«ć€WEB-INFćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ恮äø‹ć«ć‚悋恮ćÆ DevKanApplication.class ćØ Calculator.class 恠恑恧恙怂 ćƒ•ćƒ¬ćƒ¼ćƒ ćƒÆćƒ¼ć‚Æ恮JARćƒ•ć‚”ć‚¤ćƒ«ćÆ恊悍恋态web.xmlć™ć‚‰ć‚ć‚Šć¾ć›ć‚“ć€‚

JAX-RSćÆJava EE恮äø€éƒØ恧恂悊态Java EEć®ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć‚µćƒ¼ćƒć§ć‚ć‚‹GlassFishć«ćƒ‡ćƒ—ćƒ­ć‚¤ć™ć‚‹å “åˆćÆćƒ•ćƒ¬ćƒ¼ćƒ ćƒÆćƒ¼ć‚Æ恮JARćƒ•ć‚”ć‚¤ćƒ«ćÆäøč¦ć§ć™ć€‚

ć¾ćŸć€ęœ€čæ‘恧ćÆć‚µćƒ¼ćƒ–ćƒ¬ćƒƒćƒˆć®ē™»éŒ²ć«ć‚‚web.xmlćÆåæ…é ˆć§ćÆć‚ć‚Šć¾ć›ć‚“ć€‚ @WebServletćØć„ć†ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć§ē™»éŒ²ć™ć‚‹ć‹ć€ServletContext恮addServletćƒ”ć‚½ćƒƒćƒ‰ć§å‹•ēš„恫ē™»éŒ²ć§ćć¾ć™ć€‚

恓恮č¾ŗ悊ćÆć¾ćŸåˆ„ć®ę©Ÿä¼šć«č©³ć—ćē“¹ä»‹ć™ć‚‹ćØ恗恦(悄悉ćŖć„ćƒ•ćƒ©ć‚°)ć€å¤§äŗ‹ćŖ恮ćÆ怌JAX-RSćŖ悉2ć‚Æćƒ©ć‚¹ć§Webć‚¢ćƒ—ćƒŖä½œć‚Œć‚‹ć§ć™ć‚ˆ(ļ½€ćƒ»Ļ‰ćƒ»Ā“)ļ½¼ļ½¬ļ½·ļ½°ļ¾ć€ćØ恄恆恓ćØ恧恙怂 ćŠę‰‹č»½ć§ć™ć­ć€‚

JAX-RSć‚’ć‚‚ć£ćØēŸ„ć‚ŠćŸć„å “åˆćÆ

@btnrouge恕悓 ć®ćƒ–ćƒ­ć‚° Programming Studio 悒čŖ­ć‚€ćØč‰Æ恄恧恗悇恆怂 JAX-RS恮ć‚æć‚°ćŒä»˜ć‘ć‚‰ć‚ŒćŸć‚Øćƒ³ćƒˆćƒŖ悒恖恏恖恏čŖ­ć‚“ć§č”Œć‘ć°ć‚‚ć‚Šć‚‚ć‚ŠēŸ„識恌恤恏ćØę€ć„ć¾ć™ć€‚

恝悌ćØć€ę‰‹å‰å‘³å™Œć§ć™ćŒć€ē§ć‚‚JAX-RS悒äø€é€šć‚Šē“¹ä»‹ć™ć‚‹ć‚Øćƒ³ćƒˆćƒŖ悒ę›øćć¾ć—ćŸć€‚

恟恠恗åÆ¾č±”ćƒćƒ¼ć‚øćƒ§ćƒ³ćÆć”ć‚‡ć£ćØå¤ć„ć§ć™ć€‚ ć‚Øćƒ³ćƒˆćƒŖćÆ1.1怂 ꜀ꖰćÆ2.0怂 ćć®ć†ć”ć‚Øćƒ³ćƒˆćƒŖ悂2.0ć«ć‚¢ćƒƒćƒ—ćƒ‡ćƒ¼ćƒˆć—ćŸć„ć§ć™(悄悉ćŖć„ćƒ•ćƒ©ć‚°)怂

ę›øē±ćŖ悉怌Javać«ć‚ˆć‚‹RESTfulć‚·ć‚¹ćƒ†ćƒ ę§‹ēÆ‰ć€(ISBN:978-4873114675)恌č‰Æć„ć§ć™ć‹ć­ćƒ¼ć€‚ ę—„ęœ¬čŖžčØ³ćŒ2010å¹“ć«å‡ŗē‰ˆć•ć‚ŒćŸę›øē±ć§ć€ć“ć”ć‚‰ć‚‚å†…å®¹ćÆJAX-RS 1ē³»ć§ć™ćŒä»Šć§ć‚‚通ē”Øć™ć‚‹ęƒ…å ±ćŒč¼‰ć£ć¦ć„ć‚‹ćØćÆę€ć„ć¾ć™ć€‚

恝悓ćŖꄟ恘恧态JAX-RSć®å›žć—č€…ć€ć†ć‚‰ćŒćæ恧恗恟(惻āˆ€ćƒ»)

]]>
Sun, 07 Jul 2013 00:00:00 +0900
http://backpaper0.github.io/2013/06/02/jsr330.html http://backpaper0.github.io/2013/06/02/jsr330.html <![CDATA[JSR 330ć‚’å®Ÿč£…ć—ć¦ćæ恟]]> JSR 330ć‚’å®Ÿč£…ć—ć¦ćæ恟

JSR 330ćÆDIć®ä»•ę§˜ć§ć™ć€‚ 参ē…§å®Ÿč£…ćÆGuice恧恙怂

ä»•ę§˜ćÆ薄恄恗TCKć‚‚ć‚ć‚‹ć®ć§å®Ÿč£…ć—ć¦ćæć¾ć—ćŸć€‚

ć¾ć‚ä½•ćØ恋TCK通恗恟恠恑恧恙恌恌恌怂

JSR 330ć®ä»•ę§˜ć§ćÆ@Inject恧ę³Øé‡ˆć—ć¦ć„ć‚‹ćƒ”ć‚½ćƒƒćƒ‰ćŒć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³åÆ¾č±”ćØćŖć‚Šć¾ć™ćŒć€ć‚µćƒ–ć‚Æćƒ©ć‚¹ć§ć‚Ŗćƒ¼ćƒćƒ¼ćƒ©ć‚¤ćƒ‰ć•ć‚Œć¦ćŠć‚Šć€ć‚Ŗćƒ¼ćƒćƒ¼ćƒ©ć‚¤ćƒ‰ć•ć‚ŒćŸćć®ćƒ”ć‚½ćƒƒćƒ‰ćŒ@Inject恧ę³Øé‡ˆć•ć‚Œć¦ć„ćŖć‘ć‚Œć°ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³åÆ¾č±”ćØćÆćŖć‚Šć¾ć›ć‚“ć€‚

ć§ć€ćƒ”ć‚½ćƒƒćƒ‰ćŒć‚¹ćƒ¼ćƒ‘ćƒ¼ć‚Æćƒ©ć‚¹ć®ćƒ”ć‚½ćƒƒćƒ‰ć‚’ć‚Ŗćƒ¼ćƒćƒ¼ćƒ©ć‚¤ćƒ‰ć—ć¦ć„ć‚‹ć®ć‹ć©ć†ć‹ćÆćƒŖćƒ•ćƒ¬ć‚Æć‚·ćƒ§ćƒ³ć§å–å¾—ć§ćć‚‹ć ć‚ćƒ¼ć€ćØę€ć£ć¦ćŸć‘ć©ć§ćć¾ć›ć‚“ć§ć—ćŸć€‚

ć‚“ć§ć€ć‚¹ćƒ¼ćƒ‘ćƒ¼ć‚Æćƒ©ć‚¹ć«åŒć˜ć‚·ć‚°ćƒćƒćƒ£ć®ćƒ”ć‚½ćƒƒćƒ‰ćŒć‚ć‚Œć°ć‚Ŗćƒ¼ćƒćƒ¼ćƒ©ć‚¤ćƒ‰ć—ć¦ć„ć‚‹ćØåˆ¤ę–­ć—ć¦ćˆćˆć˜ć‚ƒć‚ć€ćØę€ć£ć¦ćŸć‘ć©ćć‚“ćŖē°”単ćŖć‚¢ćƒ¬ć˜ć‚ƒć‚ć‚Šć¾ć›ć‚“ć§ć—ćŸć€‚ ćƒ”ć‚½ćƒƒćƒ‰åćØå¼•ę•°ć®ę•°ćƒ»åž‹ćŒåŒć˜ć§ć‚‚ä¾‹ćˆć°åÆč¦–ę€§ćŒpackage privateć§ć‚¹ćƒ¼ćƒ‘ćƒ¼ć‚Æćƒ©ć‚¹ćØć‚µćƒ–ć‚Æćƒ©ć‚¹ćŒē•°ćŖć‚‹ćƒ‘ćƒƒć‚±ćƒ¼ć‚ø恧恂悌恰ć‚Ŗćƒ¼ćƒćƒ¼ćƒ©ć‚¤ćƒ‰ć—ć¦ć„ć¾ć›ć‚“ć€‚ ćƒ‘ćƒƒć‚±ćƒ¼ć‚ø恌äø€ē·’ć§ć‚‚ć‚¹ćƒ¼ćƒ‘ćƒ¼ć‚Æćƒ©ć‚¹ć®ę–¹ć§å®šē¾©ć•ć‚ŒćŸćƒ”ć‚½ćƒƒćƒ‰ćŒprivate恠ćØć‚„ć£ć±ć‚Šć‚Ŗćƒ¼ćƒćƒ¼ćƒ©ć‚¤ćƒ‰ć—ć¦ć„ć¾ć›ć‚“ć€‚

ćØ恄恆悏恑恧ć‚Ŗćƒ¼ćƒćƒ¼ćƒ©ć‚¤ćƒ‰ć—ć¦ć‚‹ć‹ć©ć†ć‹ć®åˆ¤å®šćŒé¢å€’ć§ę³„č‡­ććŖć£ć¦ć„ć¾ć™ć€‚ ć‚‚ć£ćØč‰Æć„ę–¹ę³•ćŒć‚ć‚Œć°ę•™ćˆć¦ćć ć•ć„ć€ēš„ćŖ怂

]]>
Sun, 02 Jun 2013 00:00:00 +0900
http://backpaper0.github.io/2013/05/02/jaxrs.html http://backpaper0.github.io/2013/05/02/jaxrs.html <![CDATA[JAX-RSćØ恋恮話]]> JAX-RSćØ恋恮話

恓悌ćÆ2013-04-19ć«č”Œć‚ć‚ŒćŸć€Œć„ć„ć­ļ¼Java EEļ¼ć€ć§ä½æē”Øć—ćŸč³‡ę–™ć‚’åŠ ē­†äæ®ę­£ć—ćŸć‚‚ć®ć§ć™ć€‚

JAX-RSć£ć¦ļ¼Ÿ

  • Webć‚¢ćƒ—ćƒŖć‚’ä½œć‚‹ćŸć‚ć®API
  • JSR 311 (JAX-RS 1.x)
  • JSR 339 (JAX-RS 2.x)
  • Java EE 6 Full Profile ć«å…„ć£ć¦ć‚‹(ćŖ恜恋Web Profile恘悃ćŖ恄)
  • Java EE 7 恋悉ćÆ Web Profile ć«å…„ć‚‹
  • Jersey(参ē…§å®Ÿč£…)态RESTEasy态Apache CXFćŖć©ć®å®Ÿč£…ćŒć‚ć‚Šć€ćæ悓ćŖå¤§å„½ćTomcat恧悂ä½æ恈悋
  • ä»•ę§˜ę›ø(PDF)ćÆ41ćƒšćƒ¼ć‚ø恧ē›®ć«å„Ŗ恗恄(恔ćŖćæ恫EJB 3.1ćÆ626ćƒšćƒ¼ć‚ø)

開ē™ŗęŗ–å‚™

  • NetBeans 悒ä½æć„ć¾ć—ć‚‡ć†ļ¼

仄äøŠ

Maven

Mavenć§ć‚¢ćƒ¬ć™ć‚‹ćŖć‚‰ę¬”ć®ć‚ˆć†ćŖdependency悒ę›ø恑恰č‰Æ恄恧恙怂

<dependency>
  <groupId>com.sun.jersey</groupId>
  <artifactId>jersey-bundle</artifactId>
  <version>1.11.1</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>com.sun.jersey.jersey-test-framework</groupId>
  <artifactId>jersey-test-framework-http</artifactId>
  <version>1.11.1</version>
  <scope>test</scope>
</dependency>

Jersey恮artifactćÆjersey-server悄jersey-jsonćŖć©ć„ćć¤ć‹ć«åˆ†ć‹ć‚Œć¦ć„ć‚‹ć®ć§ć™ćŒć€jersey-bundlećÆćć‚Œć‚‰ćŒć¾ćØć‚ć‚‰ć‚ŒćŸć‚‚ć®ć§ć€ć“ć„ć¤ć‚’ęŒ‡å®šć™ć‚‹ć®ćŒę„½ć”ć‚“ć§ć™ć€‚

jersey-test-framework-http ćÆJerseyć®ćƒ†ć‚¹ćƒ†ć‚£ćƒ³ć‚°ćƒ•ćƒ¬ćƒ¼ćƒ ćƒÆćƒ¼ć‚Æ恧态Hotspotć«å…„ć£ć¦ć‚‹ com.sun.net.httpserver.HttpServer ć§å®Ÿč”Œć—ć¾ć™ć€‚

artifactId ć®ęœ«å°¾ć® -http 悒 -grizzly 恫恙悋ćØGrizzly(GlassFish恮HTTP悒ꍌ恏éƒØ分)ć§å‹•ć‹ć™äŗ‹ć‚‚ć§ćć¾ć™ć—ć€-inmemory 恫恙悋ćØć‚½ć‚±ćƒƒćƒˆć‚’ä»‹ć•ćšć‚¤ćƒ³ćƒ”ćƒ¢ćƒŖć§å‹•ć‹ć™äŗ‹ć‚‚ć§ćć¾ć™ć€‚

ćÆć˜ć‚ć¦ć®JAX-RS

ć‚Æć‚ØćƒŖćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć§åå‰ć‚’ęø”恙ćØHello, xxx!恌čæ”ć‚‹Web API悒ę›øćć¾ć—ć‚‡ć†ć€‚

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;

@Path("hello")
public class HelloResource {

    @GET
    public String say(
            @QueryParam("name") String name) {
        return "Hello, " + name + "!";
    }
}

恓悌ćÆę¬”ć®ć‚ˆć†ćŖHTTPćƒŖć‚Æć‚Øć‚¹ćƒˆć‚’å‡¦ē†ć™ć‚‹ć“ćØćŒć§ćć¾ć™ć€‚

GET /rest/hello?name=world HTTP/1.1

/rest ćŒć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć®ćƒ«ćƒ¼ćƒˆćØćŖć‚Šć¾ć™ć€‚ 恓悌ćÆ後čæ°ć™ć‚‹Applicationć‚µćƒ–ć‚Æćƒ©ć‚¹ć«ę³Ø釈恙悋@ApplicationPathć§ęŒ‡å®šć™ć‚‹å€¤ćŒåƾåæœć—ć¾ć™ć€‚ 恂ćØćÆ何ćØćŖćč¦‹ćŸć‚‰åˆ†ć‹ć‚‹ę„Ÿć˜ć§ćÆć‚ć‚Šć¾ć™ćŒć€/hello 恌 @Path(ā€œhelloā€) 恫态?name=world 恌 @QueryParam(ā€œnameā€) ć«ć€ćć‚Œć‹ć‚‰ćƒŖć‚Æć‚Øć‚¹ćƒˆćƒ”ć‚½ćƒƒćƒ‰ćŒGET恧恙恌 @GET 恌åƾåæœć—ć¦ć„ć¾ć™ć€‚

恓恄恤悒ćØć‚Šć‚ćˆćšć‚µć‚Æ惃ćØå‹•ć‹ć™ćŖ悉jersey-test-framework悒ä½æć†ć®ćŒć‚‰ćć”ć‚“ć§ć™ć€‚ JUnitć§ć¶ć‚“å›žć™ć“ćØćŒć§ćć¾ć™ć€‚

import com.sun.jersey.test.framework.AppDescriptor;
import com.sun.jersey.test.framework.JerseyTest;
import com.sun.jersey.test.framework.LowLevelAppDescriptor.Builder;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import org.junit.Test;

public class HelloResourceTest extends JerseyTest {

    @Test
    public void test_say() throws Exception {
        String response = resource()
                .path("hello")
                .queryParam("name", "world")
                .get(String.class);
        assertThat(response, is("Hello, world!"));
    }

    @Override
    protected AppDescriptor configure() {
        return new Builder(HelloResource.class).build();
    }
}

ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć‚µćƒ¼ćƒć‚„ć‚µćƒ¼ćƒ–ćƒ¬ćƒƒćƒˆć‚³ćƒ³ćƒ†ćƒŠć§å‹•ć‹ć™

GlassFish ćŖ恩恮Java EEć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć‚µćƒ¼ćƒć§å‹•ć‹ć™ć«ćÆApplicationć‚µćƒ–ć‚Æćƒ©ć‚¹ć‚’ä½œć‚Šć¾ć™ć€‚

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("rest")
public class JaxrsActivator extends Application {
}

Application悒ē¶™ę‰æ恗恦@ApplicationPath恧ę³Ø釈恙悋恠恑恧恙怂 恂ćØćÆHelloResourcećØ恓恮JaxrsActivator悒WARć«ćƒ‘ćƒƒć‚±ćƒ¼ć‚øćƒ³ć‚°ć—ć¦ćƒ‡ćƒ—ćƒ­ć‚¤ć™ć‚Œć°ćŠk恧恙怂

TomcatćŖć©ć®ć‚µćƒ¼ćƒ–ćƒ¬ćƒƒćƒˆć‚³ćƒ³ćƒ†ćƒŠć ćØ専ē”Øć®ć‚µćƒ¼ćƒ–ćƒ¬ćƒƒćƒˆć‚’ē™»éŒ²ć™ć‚‹åæ…č¦ćŒć‚ć‚‹ā€¦ā€¦ćØ見恛恋恑恦Servlet 3åƾåæœć®ć‚³ćƒ³ćƒ†ćƒŠćŖ悉Jersey恮JAR悒ēŖć£č¾¼ć‚€ć ć‘恧web.xml悒ę›ø恏åæ…要ćÆć‚ć‚Šć¾ć›ć‚“ć€‚ web.xml悒ę›ø恋ćŖćć¦ć‚‚ServletContainerInitializerć‚’åˆ©ē”Øć—ć¦å‹•ēš„ć«ć‚µćƒ¼ćƒ–ćƒ¬ćƒƒćƒˆć‚’čæ½åŠ ć—ć¦ćć‚Œć¾ć™ć€‚

ćƒŖć‚½ćƒ¼ć‚¹ć‚Æćƒ©ć‚¹ć€ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰

ćƒŖć‚½ćƒ¼ć‚¹ć‚Æćƒ©ć‚¹ćÆ@Path恧ę³Ø釈恗恟ć‚Æćƒ©ć‚¹ć§å…ˆć®ä¾‹ć§ć„ć†ćØHelloResource恌ćƒŖć‚½ćƒ¼ć‚¹ć‚Æćƒ©ć‚¹ć«ćŖć‚Šć¾ć™ć€‚ ć‚Æćƒ©ć‚¹åć«åˆ¶ē“„ćÆćŖ恄恮恧Hello恧悂Foobarć§ć‚‚ä½•ć§ć‚‚č‰Æ恄恧恙怂 @Path恫ćÆ恓恮ćƒŖć‚½ćƒ¼ć‚¹ć‚Æćƒ©ć‚¹ć§å‡¦ē†ć™ć‚‹ćƒ‘ć‚¹ć‚’ęŒ‡å®šć—ć¾ć™ć€‚ ćƒŖć‚½ćƒ¼ć‚¹ć‚Æćƒ©ć‚¹ćÆpublicćŖć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ恌åæ…要恧恙怂

@Path("hello")
public class HelloResource { ... }

ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ćÆćƒŖć‚½ćƒ¼ć‚¹ć‚Æćƒ©ć‚¹ć«å®šē¾©ć•ć‚ŒćŸćƒ”ć‚½ćƒƒćƒ‰ć§@GET悄@POSTćØć„ć£ćŸHTTPćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć™ć‚‹ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć§ę³Øé‡ˆć—ć¾ć™ć€‚ ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć§ćÆ@Consumesć§å—ć‘å–ć‚‹ćƒŖć‚Æć‚Øć‚¹ćƒˆćƒœćƒ‡ć‚£ć®Content-Typeć‚’ęŒ‡å®šć§ćć¾ć™ć€‚ åŒć˜ć‚ˆć†ć«@Produces恧送悊čæ”ć™ćƒ¬ć‚¹ćƒćƒ³ć‚¹ćƒœćƒ‡ć‚£ć®Content-Typeć‚’ęŒ‡å®šć§ćć¾ć™ć€‚ ć¾ćŸå¼•ę•°ć«@QueryParam悄@HeaderParam悒ę³Ø釈恙悋恓ćØ恧ć‚Æć‚ØćƒŖćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ悄ćƒŖć‚Æć‚Øć‚¹ćƒˆćƒ˜ćƒƒćƒ€ć‚’ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹ć“ćØćŒć§ćć¾ć™ć€‚

@GET
@Consumes("text/plain")
@Produces("text/plain")
public String say(
        @QueryParam("name") @DefaultValue("world") String name) {
    return "Hello, " + name + "!";
}

ćŖ恊态@QueryParamćŖć©ć§ćƒžćƒƒćƒ”ćƒ³ć‚°å‡ŗę„ć‚‹ć®ćÆćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć®å¼•ę•°ć ć‘ć˜ć‚ƒćŖćć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æć®å¼•ę•°ć‚„

@Path("hello")
public class HelloResource {

    private final String name;

    public HelloResource(
            @QueryParam("name") String name) {
        this.name = name;
    }

    ...

ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć€

@Path("hello")
public class HelloResource {

    @QueryParam("name")
    private String name;

    ...

setterćŖ恩悂ä½æē”Øć§ćć¾ć™ć€‚

@Path("hello")
public class HelloResource {

    private String name;

    @QueryParam("name")
    public void setName(String name) {
        this.name = name;
    }

    ...

個äŗŗēš„恫ćÆćƒ”ć‚½ćƒƒćƒ‰ć®å¼•ę•°ć‚’ä½æē”Øć™ć‚‹ć®ćŒå„½ćć§ć™ć€‚

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®ćƒžćƒƒćƒ”ćƒ³ć‚°

ę—¢ć«ć‚Æć‚ØćƒŖćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ悒@QueryParamć§ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹ä¾‹ćÆęŒ™ć’ć¾ć—ćŸćŒć€ä»–ć«ćÆćƒŖć‚Æć‚Øć‚¹ćƒˆćƒ˜ćƒƒćƒ€ć‚„ćƒ‘ć‚¹ć®äø€éƒØ态Cookieć®å€¤ćŖć©ć‚’ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć§ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹ć“ćØćŒć§ćć¾ć™ć€‚

@QueryParam

  • ć‚Æć‚ØćƒŖćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚’ćƒžćƒƒćƒ”ćƒ³ć‚°
  • /hoge?name=value
@GET
public String sayHello(
        @QueryParam("name") String name) {
    ...

@FormParam

  • ćƒ•ć‚©ćƒ¼ćƒ ć®POSTćƒŖć‚Æć‚Øć‚¹ćƒˆć§é€äæ”ć™ć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚’ćƒžćƒƒćƒ”ćƒ³ć‚°
  • <input type=ā€textā€ name=ā€nameā€>
@POST
public String sayHello(
        @FormParam("name") String name) {
    ...

@PathParam

  • ćƒ‘ć‚¹ć®äø€éƒØć‚’ćƒžćƒƒćƒ”ćƒ³ć‚°
  • /hoge/value
@GET
@Path("{name}")
public String sayHello(
        @PathParam("name") String name) {
    ...

ć‚³ćƒ­ćƒ³ć§åŒŗåˆ‡ć£ć¦ę­£č¦č”Øē¾ć‚’ę›ø恏äŗ‹ć‚‚ć§ćć¾ć™ć€‚

@GET
@Path("{id:[0-9]{1,10}}")
public String findById(
        @PathParam("id") Long id) {
    ...

@MatrixParam

  • 惞惈ćƒŖ惃ć‚Æć‚¹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ
  • ć‚»ćƒŸć‚³ćƒ­ćƒ³ć§åŒŗåˆ‡ć£ćŸå½¢å¼
  • /hoge;foo=1;bar=2
@GET
@Produces("text/plain")
public String sayHello(
        @MatrixParam("left") String left,
        @MatrixParam("right") String right) {
    ...

@CookieParam

  • Cookieć‚’ćƒžćƒƒćƒ”ćƒ³ć‚°
@GET
@Produces("text/plain")
public String sayHello(
        @Cookie("name") String name) {
    ...

@HeaderParam

  • ćƒŖć‚Æć‚Øć‚¹ćƒˆćƒ˜ćƒƒćƒ€ć‚’ćƒžćƒƒćƒ”ćƒ³ć‚°
@GET
@Produces("text/plain")
public String sayHello(
        @HeaderParam("name") String name) {
    ...

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚’ć¾ćØ悁悋

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćŒć²ćØć¤ćµćŸć¤ćŖ悉č‰Æć„ć§ć™ćŒć€ć‚‚ć£ćØå¤šććŖ悋ćØå¼•ę•°ć«åˆ—ęŒ™ć™ć‚‹ć®ćÆć‚·ć‚°ćƒćƒćƒ£ćŒć†ć‚‹ć•ććŖć‚Šć¾ć™ć­ć€‚ JerseyćŖ悉@InjectParam悒ä½æ恆恓ćØć§ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ悒POJOć«ć¾ćØ悁悋恓ćØćŒć§ćć¾ć™ć€‚ 恟恠恗态JAX-RSć®ä»•ę§˜ć˜ć‚ƒćŖćć¦Jerseyć®å®Ÿč£…ä¾å­˜ć®ę©Ÿčƒ½ć§ć™ć®ć§ć€ćć“ć‚“ćØ恓ę³Øꄏ恧恙怂

@GET
@Produces("text/plain")
public String sayHello(
        @InjectParam HogeBean bean) {
    ...

public class HogeBean {

    @QueryParam("foo")
    public String foo;

    @QueryParam("bar")
    public String bar;

    ...

恔ćŖćæ恫JAX-RS 2恋悉ćÆ恓恮@InjectParamćØåŒę§˜ć®ę©Ÿčƒ½ć‚’ć‚‚ć¤@BeanParamćØć„ć†ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćŒčæ½åŠ ć•ć‚Œć¾ć™ć€‚

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ悒POJOć§å—ć‘å–ć‚‹

ć“ć“ć¾ć§@QueryParamćŖć©ć§å—ć‘å–ć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆString悒ä½æē”Øć—ć¦ć„ć¾ć—ćŸćŒć€č‡Ŗä½œć®ć‚Æćƒ©ć‚¹ć‚’ä½æē”Ø恙悋恓ćØ悂åÆčƒ½ć§ć™ć€‚ ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚’å—ć‘å–ć‚Œć‚‹ć‚Æćƒ©ć‚¹ćÆ态valueOfć¾ćŸćÆfromStringćØć„ć†åå‰ć®é™ēš„ćƒ•ć‚”ć‚Æ惈ćƒŖćƒ”ć‚½ćƒƒćƒ‰ć‚’å®šē¾©ć™ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚ å¼•ę•°ćÆString恧恙怂

public class Fullname {

   ...

    //public static Fullname valueOf(String value) {
    public static Fullname fromString(String value) {
        return new Fullname(value);
    }
}

ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć§ćÆStringć§ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚’å—ć‘ć‚‹ćØ恍ćØåŒć˜ę„Ÿč¦šć§ä½æćˆć¾ć™ć€‚

@GET
@Produces("text/plain")
public String sayHello(
        @QueryParam("name") Fullname name) {
    ...

XML恧通äæ”恙悋

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒœćƒ‡ć‚£ćŒXMLć®å “åˆć€JAXB恧č‡Ŗä½œć®ć‚Æćƒ©ć‚¹ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹ę©Ÿčƒ½ćŒJAX-RS恫ćÆć‚ć‚Šć¾ć™ć€‚

ä¾‹ćˆć°ć“ć®ć‚ˆć†ćŖXML悒态

<hogeBean>
  <foo>hello</foo>
  <bar>world</bar>
</hogeBean>

ć“ć®ć‚ˆć†ćŖć‚Æćƒ©ć‚¹ć§å—ć‘å–ć‚‹ć“ćØ恌åÆčƒ½ć§ć™ć€‚ @XmlRootElementćÆJAXB恮API恧恙怂

@XmlRootElement
public class HogeBean {

    public String foo;

    public String bar;
}

ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ćÆć“ć®ć‚ˆć†ć«ćŖć‚Šć¾ć™ć€‚ @Consumes恧XMLć‚’å—ć‘å–ć‚‹äŗ‹ć‚’ę˜Žē¤ŗć—ć¦ć„ć¾ć™ć€‚

@POST
@Consumes("application/xml")
public void doHoge(HogeBean bean) {
    ...

ćƒ¬ć‚¹ćƒćƒ³ć‚¹ć‚’XML恫恙悋恓ćØ悂åÆčƒ½ć§ć™ć€‚ ćć®å “åˆć€ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ćÆę¬”ć®ć‚ˆć†ć«ćŖć‚Šć¾ć™ć€‚ 今åŗ¦ćÆ@Produces恧XML悒čæ”恙恓ćØ悒꘎ē¤ŗć—ć¦ć„ć¾ć™ć€‚

@GET
@Produces("application/xml")
public HogeBean getHoge() {
    ...

前čæ°ć®é€šć‚ŠXMLćØć‚Æćƒ©ć‚¹ć®ē›øäŗ’å¤‰ę›ć‚’č”Œć†éƒØ分ćÆJAX-RS恧ćÆćŖ恏JAXBć®ä»•ę§˜ć§ć™ć€‚ JAXBćÆJava SEć«å…„ć£ć¦ć„ć‚‹ć®ć§å‹•ä½œē¢ŗčŖćÆę‰‹č»½ć«ć§ćć¾ć™ć€‚

HogeBean obj = ...
StringWriter out = new StringWriter();
JAXB.marshal(obj, out);
String xml = out.toString();

...

String xml = ...
StringReader in = new StringReader(xml);
HogeBean obj = JAXB.unmarshal(xml, HogeBean.class);

JSON恧通äæ”恙悋

前čæ°ć®ć‚ˆć†ć«JAXB恧XML通äæ”ć—ć¦ć„ć‚‹å “åˆć€JerseyćŖ悉@Consumes悄@Producesć§ć®ćƒ”ćƒ‡ć‚£ć‚¢ć‚æć‚¤ćƒ—ć®ęŒ‡å®šć‚’application/jsonć«å¤‰ę›“ć™ć‚‹ć ć‘ć§JSON恧通äæ”恙悋恓ćØ恌åÆčƒ½ć§ć™ć€‚

@POST
//@Consumes("application/xml")
//@Produces("application/xml")
@Consumes("application/json")
@Produces("application/json")
public HogeBean doHoge(HogeBean bean) {
    ...

å…ƒć€…ćÆXML恧通äæ”ć—ć¦ć„ć¾ć—ćŸćŒć€ćŸć£ćŸć“ć‚Œć ć‘ć§ę¬”ć®ć‚ˆć†ćŖJSON恧通äæ”ć™ć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć™ć€‚

{ "foo" : "hello",
  "bar" : "world" }

JSON通äæ”ć§ć®å•é”Œē‚¹

ćƒŖć‚¹ćƒˆć‚’å«ć‚€ę¬”ć®ć‚ˆć†ćŖć‚Æćƒ©ć‚¹ć®ć€

@XmlRootElement
public class Hoge {

    public List<String> foobar;
}

ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ä½œęˆć—ć¦ć€

Hoge obj = new Hoge();
obj.foobar = Arrays.asList("a", "b", "c");

XML通äæ”恙悋ćØę¬”ć®ć‚ˆć†ćŖXML恫ćŖć‚Šć¾ć™ć€‚

<hoge>
  <foobar>a</foobar>
  <foobar>b</foobar>
  <foobar>c</foobar>
</hoge>

foobar要ē“ ćŒćƒŖć‚¹ćƒˆć®č¦ē“ åˆ†ć€ćƒ•ćƒ©ćƒƒćƒˆć«äø¦ć‚“ć§ć„ć¾ć™ć­ć€‚

恓悌恌JSON通äæ”ć®å “åˆć ćØę¬”ć®ć‚ˆć†ćŖJSON恫ćŖć‚Šć¾ć™ć€‚

{ "foobar" : [ "a", "b", "c" ] }

XML恧ćÆćƒ•ćƒ©ćƒƒćƒˆć«äø¦ć‚“ć§ć„ćŸfoobar要ē“ ćŒē©ŗ갗悒čŖ­ć‚“恧ćƒŖć‚¹ćƒˆć«ćŖć£ć¦ć„ć¾ć™ć­ć€‚

恧态ꬔćÆ恓悓ćŖę„Ÿć˜ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ć€

Hoge obj = new Hoge();
obj.foobar = Arrays.asList("x");

JSON通äæ”恙悋ćØę¬”ć®ć‚ˆć†ćŖJSON恫ćŖć‚Šć¾ć™ć€‚

{ "foobar" : "x" }

ćƒŖć‚¹ćƒˆć˜ć‚ƒćŖ恏ćŖć£ć¦ć„ć¾ć™ć­ć€‚ ćŖ悓恧悄恭悓态ćØ怂

foobar要ē“ ćŒäø€ć¤ć®XMLć‚’ęƒ³åƒć™ć‚‹ćØćŖ悓ćØćŖ恏ē“å¾—ć§ćć¾ć™ć€‚

<hoge>
  <foobar>x</foobar>
</hoge>

ć“ć®ć‚ˆć†ć«ć€č¦ē“ ćŒć²ćØ恤恠ćØćƒŖć‚¹ćƒˆćŖ恮恋ćƒŖć‚¹ćƒˆć˜ć‚ƒćŖć„ć®ć‹åˆ†ć‹ć‚‰ćŖ恄恮恧恙怂 Jersey恮JAXBēµŒē”±ć®JSONå¤‰ę›ćÆ态XMLć«å¤‰ę›ć™ć‚‹éŽēØ‹ć«ęØŖå…„ć‚Šć—ć¦č”Œć£ć¦ć„ć‚‹ć®ć§ć“ć®å½±éŸæć‚’ćƒ¢ćƒ­ć«å—ć‘ć¦ćƒŖć‚¹ćƒˆć˜ć‚ƒćŖ恏ćŖć£ć¦ć—ć¾ć†ć£ć½ć„ć§ć™ć€‚

ć‚Æćƒ©ć‚¤ć‚¢ćƒ³ćƒˆå“ć‚‚Jersey悒ä½æć£ć¦ć„ćŸć‚Šć™ć‚‹ćØć“ć‚ŒćŒå•é”Œć«ćŖ悋恓ćØćÆē„”恄恧恙恌态Webć‚¢ćƒ—ćƒŖ恧jQueryćŖ悓恋悒ä½æć£ć¦ćŸć‚Šć™ć‚‹ćØćƒŖć‚¹ćƒˆć®ć¤ć‚‚ć‚Šć§å—ć‘å–ć£ćŸć‚‰ćƒŖć‚¹ćƒˆć˜ć‚ƒćŖć‹ć£ćŸć§ć”ć–ć‚‹ć€ćØ恄恆ēŠ¶ę³ć«ćŖć£ć¦å›°ć‚Šć¾ć™ć€‚ ćØć„ć†ć‹å›°ć‚Šć¾ć—ćŸć€å®Ÿéš›ć«ć€‚

Jackson恧JSON通äæ”恙悋

前čæ°ć®ć€Œč¦ē“ ćŒć²ćØć¤ć®å “åˆć«ćƒŖć‚¹ćƒˆć˜ć‚ƒćŖ恏ćŖć£ć”ć‚ƒć†å•é”Œć€ć«åÆ¾å‡¦ć™ć‚‹ć«ćÆJacksonć‚’åˆ©ē”Ø恗恟JSONå¤‰ę›ć‚’č”Œć†ćØč‰Æ恄恧恙怂

Jackson悒ä½æ恆ćØfoobar要ē“ ćŒć²ćØ恤恗恋ćŖć„å “åˆć§ć‚‚ę¬”ć®ć‚ˆć†ćŖJSONć«å¤‰ę›ć•ć‚Œć¾ć™ć€‚

{ "foobar" : [ "x" ] }

ć¾ćŸć€Jackson悒ä½æ恆ćØ态

  • ć‚Æćƒ©ć‚¹ć‚’@XmlRootElement恧ę³Ø釈恙悋åæ…č¦ćŒćŖ恄
  • ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć®ęˆ»ć‚Šå€¤ć‚’java.util.List恫恙悋äŗ‹ćŒåÆčƒ½

ćŖć©ć®åˆ©ē‚¹ćŒć‚ć‚Šć¾ć™ć€‚

Jersey恧Jackson悒ä½æ恆恫ćÆåˆęœŸćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ com.sun.jersey.api.json.POJOMappingFeature 悒 true 恫čØ­å®šć—ć¾ć™ć€‚

jersey-test-framework悒ä½æć£ćŸć‚ŠJDK恮HttpServerć§å‹•ć‹ć™å “åˆćÆResourceConfigćØ恄恆ć‚Æćƒ©ć‚¹ć§čØ­å®šć™ć‚‹ćØč‰Æ恄恧恙怂

ResourceConfig rc = ...
rc.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, true);

ę›øćć¾ć§ć‚‚ćŖć„ć§ć™ćŒć€ć“ć®ć‚³ćƒ¼ćƒ‰ć«ć‚ć‚‹JSONConfiguration.FEATURE_POJO_MAPPINGćÆę–‡å­—åˆ—ć®å®šę•°ć§ć€ā€com.sun.jersey.json.POJOMappingFeatureā€ć§ć™ć€‚

ć‚µćƒ¼ćƒ–ćƒ¬ćƒƒćƒˆēµŒē”±ć§å‹•ć‹ć™ćŖ悉web.xml恧čØ­å®šć™ć‚‹ć“ćØ悂åÆčƒ½ć§ć™ć€‚

<servlet>
  <servlet-name>Jersey</servlet-name>
  <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
  <init-param>
    <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
    <param-value>true</param-value>
  </init-param>
</servlet>

個äŗŗēš„恫ćÆJersey恧JSON通äæ”恙悋ćŖ悉Jackson悒ä½æć†ć®ćŒč‰Æ恄ćØę€ć„ć¾ć™ć€‚

XML恧悂JSON恧悂通äæ”恙悋

ć“ć‚Œć¾ć§XML恋JSON恮恩恔悉恋ē‰‡ę–¹ć§é€šäæ”恙悋čØ­å®šę–¹ę³•ć‚’ē“¹ä»‹ć—ć¾ć—ćŸćŒć€ć²ćØć¤ć®ćƒ”ć‚½ćƒƒćƒ‰ć§XML恧悂JSON恧悂通äæ”恙悋恓ćØ悂åÆčƒ½ć§ć™ć€‚ čح定ćÆ単ē“”恧@Consumes悄@Producesć«č¤‡ę•°ć®ćƒ”ćƒ‡ć‚£ć‚¢ć‚æ悤惗悒ę›ø恑恰č‰Æ恄恧恙怂

@POST
@Consumes({ "application/json", "application/xml" })
@Produces({ "application/json", "application/xml" })
public HogeBean doHoge(HogeBean bean) {
    ...

恓恮ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ćÆć‚Æćƒ©ć‚¤ć‚¢ćƒ³ćƒˆćŒAccept惘惃惀恧application/jsonć‚’č¦ę±‚ć™ć‚Œć°JSON恧通äæ”恗态application/xmlć‚’č¦ę±‚ć™ć‚Œć°XML恧通äæ”ć—ć¾ć™ć€‚ ć“ć®ć‚ˆć†ć«ćƒ”ć‚½ćƒƒćƒ‰ć®å†…å®¹ćÆć¾ć£ćŸćåŒć˜ć ć‘ć©ć€HTTPćƒŖć‚Æć‚Øć‚¹ćƒˆć®å†…å®¹ć«ć‚ˆć£ć¦é€šäæ”ć®ćƒ•ć‚©ćƒ¼ćƒžćƒƒćƒˆć‚’åˆ‡ć‚Šę›æćˆć‚‰ć‚Œć‚‹ć®ćÆJAX-RSć®å¼·ćæ恧恙恭怂

MessageBodyReader/MessageBodyWriter

JAX-RS恧通äæ”ć§ćć‚‹ć®ćÆXML悄JSON恠恑恧ćÆć‚ć‚Šć¾ć›ć‚“ć€‚ MessageBodyReader悄MessageBodyWriterć‚’å®Ÿč£…ć™ć‚Œć°ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒœćƒ‡ć‚£ć‚’å„½ćć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹ć“ćØ恌åÆčƒ½ć§ć™ć€‚

ä¾‹ćˆć°ć€String[][]悒CSV恧å‡ŗåŠ›ć™ć‚‹MessageBodyWriterć‚’å®Ÿč£…ć—ć¦ćæć¾ć™ć€‚

@Provider
@Produces("text/csv")
public class CsvWriter implements MessageBodyWriter<String[][]> {

    @Override
    public boolean isWriteable(Class<?> type, Type genericType,
            Annotation[] annotations, MediaType mediaType) {
        return type == String[][].class;
    }

    @Override
    public long getSize(String[][] t, Class<?> type, Type genericType,
            Annotation[] annotations, MediaType mediaType) {
        return -1;
    }

    @Override
    public void writeTo(String[][] t, Class<?> type, Type genericType,
            Annotation[] annotations, MediaType mediaType,
            MultivaluedMap<String, Object> httpHeaders,
            OutputStream entityStream) throws IOException, WebApplicationException {
        try (PrintWriter out = new PrintWriter(entityStream)) {
            for (String[] row : t) {
                for (String column : row) {
                    out.printf("%s,", column);
                }
                out.println();
            }
        }
    }
}

@Provider恧ę³Øé‡ˆć—ć¦ć„ć¾ć™ćŒć€ć“ć‚Œć‚’ä»˜ć‘ć¦ćŠććØć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚¹ć‚­ćƒ£ćƒ³ć§ę‹¾ć£ć¦ćć‚Œć¾ć™ć€‚ 恂悋恄ćÆć‚Æćƒ©ć‚¹ćƒ‘ć‚¹äøŠć«META-INF/services/javax.ws.rs.ext.MessageBodyWriterćØć„ć†ćƒ•ć‚”ć‚¤ćƒ«ć‚’ä½œć£ć¦ć€äø­ć«CsvWriter恮FQDN悒ę›ø恄恦ServiceLoaderć«ę‹¾ć£ć¦ć‚‚ć‚‰ć„ć¾ć™ć€‚

@Produces恧ę³Ø釈恙悋恓ćØ恧态恓恮MessageBodyWriterćŒå‡¦ē†ć™ć‚‹åÆ¾č±”ćØćŖ悋Content-Typeć‚’ęŒ‡å®šć—ć¦ć„ć¾ć™ć€‚ 恕悉恫isWritablećƒ”ć‚½ćƒƒćƒ‰ć§ć“ć®MessageBodyWriter悒ä½æć†ć¹ćć‹åˆ¤ę–­ć™ć‚‹ć“ćØ恌åÆčƒ½ć§ć™ć€‚

getSizećƒ”ć‚½ćƒƒćƒ‰ćÆę›ø恍å‡ŗ恙ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒœćƒ‡ć‚£ć®ćƒć‚¤ćƒˆć‚µć‚¤ć‚ŗ恧恙怂 ē®—å‡ŗ恧恍ćŖ恄ļ¼ˆć—č¾›ć„ļ¼‰å “合ćÆ-1悒čæ”ć—ć¦ćŠććØč‰Æćć«čØˆć‚‰ć£ć¦ćć‚Œć¾ć™ć€‚

ęœ€å¾Œć«writeToćƒ”ć‚½ćƒƒćƒ‰ć§ć™ćŒć€ć“ć‚ŒćŒå®Ÿéš›ć«ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒœćƒ‡ć‚£ć«ę›ø恍å‡ŗć™ćƒ”ć‚½ćƒƒćƒ‰ć«ćŖć‚Šć¾ć™ć€‚

恓恮CsvWriter恫åƾåæœć™ć‚‹ćƒ¬ć‚¹ćƒćƒ³ć‚¹ć‚’čæ”恙ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ćÆ恓悓ćŖꄟ恘恧恙怂

@GET
@Produces("text/csv")
public String[][] getCsv() {
    ...

ć‚Ŗ惖ć‚ø悧ć‚Æćƒˆć‹ć‚‰å®Ÿéš›ć®é€šäæ”形式ćøå¤‰ę›ć™ć‚‹ę–¹ę³•ć‚’MessageBodyWriterć«åˆ†é›¢ć—ć¦ć„ć‚‹ć®ć§ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ćÆć‚·ćƒ³ćƒ—ćƒ«ć«äæćŸć‚Œć¦ć„ć¾ć™ć­ć€‚

WebApplicationException

å “åˆć«ć‚ˆć£ć¦ćÆćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć§å‡¦ē†äø­ć«ć€Œć‚„ć£ć±ć‚Š404čæ”ć—ćŸć„ć‚ćƒ¼ć€ćŖ恩ćØ恄恆ćØ恍悂恂悋ćØę€ć„ć¾ć™ćŒć€WebApplicationExceptionć‚’ęŠ•ć’ć‚‹ć®ćŒę„½ć”ć‚“ć§ć™ć€‚

@GET
@Path("{isbn}")
@Produces("application/json")
public Book get(@PathParam("isbn") Isbn isbn) {
    Book book = bookBean.get(isbn);
    if(book == null) {
        throw new WebApplicationException(404);
    }
    ...

ExceptionMapper

ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć‹ć‚‰ęŠ•ć’ć‚‰ć‚ŒćŸē‰¹å®šć®ä¾‹å¤–ć‚’å—ć‘å–ć£ć¦å‡¦ē†ć—ćŸć„å “合ćÆExceptionMapperć‚’å®Ÿč£…ć—ćŸć‚µćƒ–ć‚Æćƒ©ć‚¹ć‚’ä½œć‚Šć¾ć™ć€‚

ä¾‹ćˆć°JPAć®ę„½č¦³ęŽ’ä»–ę©Ÿčƒ½ć§ę›“ę–°ć—ćŸć„ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćŒę—¢ć«åˆ„ć®ć²ćØć«ę›“ę–°ć•ć‚Œć¦ć„ćŸå “åˆć€OptimisticLockExceptionćŒęŠ•ć’ć‚‰ć‚Œć¾ć™ćŒć€ć“ć‚Œć‚’å—ć‘å–ć£ć¦å‡¦ē†ć‚’恙悋ExceptionMapper悒ę›ø恄恦ćæć¾ć™ć€‚

@Provider
public class OptimisticLockExceptionMapper implements ExceptionMapper<OptimisticLockException> {

    @Override
    public Response toResponse(OptimisticLockException exception) {
        return Response.status(400).entity("ę›“ę–°ć•ć‚ŒćØć£ćŸļ¼žļ¼œ").type("text/plain").build();
    }
}

@Contextć§č‰²ć€…ćŖęƒ…å ±ć‚’å‚ē…§ć™ć‚‹

前čæ°ć®OptimisticLockExceptionMapper恧恙恌态EJB悒ä½æć£ć¦ć„ć‚‹å “åˆćÆOptimisticLockException恌RollbackExceptionć«åŒ…ć¾ć‚Œć¦ęŠ•ć’ć‚‰ć‚Œć¾ć™ć€‚ RollbackExceptionćÆOptimisticLockExceptionćØē¶™ę‰æ関äæ‚ćÆē„”恄恮恧OptimisticLockExceptionMapperć§å‡¦ē†ć§ćć¾ć›ć‚“怂

恝悓ćŖ堓合ćÆProviders悒ä½æć„ć¾ć™ć€‚

public static class RollbackExceptionMapper implements ExceptionMapper<RollbackException> {

    @Context
    private Providers p;

    @Override
    public Response toResponse(RollbackException exception) {
        Throwable cause = exception.getCause();
        Class<Throwable> type = (Class<Throwable>) cause.getClass();
        return p.getExceptionMapper(type).toResponse(cause);
    }
}

@Context恧Providersć‚’ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć—ć¾ć™ć€‚ ProvidersćÆć‚Æćƒ©ć‚¹ć‚„ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ęø”恙ćØćć‚Œć«åƾåæœć™ć‚‹ExceptionMapper悄MessageBodyReaderć‚’å–ć£ć¦ć“ć‚Œć‚‹ä¾æ利ćŖ悂恮恧恙怂 ć“ć®ć‚ˆć†ćŖä¾æ利ć‚Æćƒ©ć‚¹ć‚’@Contextć§ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć§ćć¾ć™ć€‚

ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć§ćć‚‹ä¾æ利ć‚Æćƒ©ć‚¹ćÆProviders恮他恫ć‚Æć‚ØćƒŖćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚„ćƒ‘ć‚¹ć®ęƒ…å ±ć‚’å–ć£ć¦ę„ć‚Œć‚‹UriInfo悄态HTTPćƒ˜ćƒƒćƒ€ć‚’å–ć‚Œć‚‹HttpHeaders态čŖčØ¼ęƒ…å ±ć‚’å–ć‚Œć‚‹SecurityContextćŖć©ćŒć‚ć‚Šć¾ć™ć€‚

他恫悂DI恗恟恄

EJB恧DI

ćƒŖć‚½ćƒ¼ć‚¹ć‚Æćƒ©ć‚¹ć‚’Stateless Session Beanć«ć—ć¾ć™ć€‚ @EJB恧Session Bean悒态@PersistenceContext恧EntityManagerćŖć©ć‚’ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć§ćć¾ć™ć€‚

@Path("hello")
@Stateless
public class HelloResource {

    @EJB
    private HelloBean helloBean;

    @GET
    public String say(@QueryParam("name") String name) {
        return helloBean.say(name);
    }
}

個äŗŗēš„ćŖ利ē‚¹ćÆ宣č؀ēš„ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ć§ć—ć‚‡ć†ć‹ć€‚

ꬠē‚¹ćÆSession Bean恋EntityManager恐悉恄恗恋DIć™ć‚‹ć‚‚ć®ćŒćŖ恄恓ćØ恧恙恋恭怂

CDI恧DI

WEB-INF/beans.xmlć‚’ä½œęˆć—ć¾ć™ć€‚ ē©ŗć®ćƒ•ć‚”ć‚¤ćƒ«ć§ć‚‚OK恧恙怂

@Path("hello")
@RequestScoped
public class HelloResource {

    @Inject
    private HelloBean helloBean;

    @GET
    public String say(@QueryParam("name") String name) {
        return helloBean.say(name);
    }
}

åŸŗęœ¬ēš„ć«ä½•ć§ć‚‚DIć§ćć‚‹ć®ćŒåˆ©ē‚¹ć§ć™ć€‚ CDI恧ćÆꮆ恩恮ć‚Æćƒ©ć‚¹ćŒē®”ē†Bean恫ćŖć‚Šć¾ć™ć€‚

ꬠē‚¹ćÆEJB恧ćÆä½æćˆć¦ć„ćŸå®£č؀ēš„ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ä½æ恈ćŖ恄恓ćØ恧恙怂 ć¾ć‚č‡Ŗåˆ†ć§CDIć®ć‚¤ćƒ³ć‚æćƒ¼ć‚»ćƒ—ć‚æćƒ¼ć‚’ę›ø恄恦適ē”Ø恙悌恰č‰Æć„ć‚“ć§ć™ćŒć€ć”ć‚‡ć£ćØé¢å€’ć§ć™ć€‚

EJBćØCDIć‚’ä½µē”Ø恙悋

ćØ恄恆悏恑恧EJBćØCDIć‚’ä½µē”Øć—ć¾ć™ć€‚

@Stateless
@Path("hello")
public class HelloResource {

    @Inject
    private HelloBean helloBean;

    @GET
    public String say(@QueryParam("name") String name) {
        return helloBean.say(name);
    }
}

利ē‚¹ćÆDI悒@Inject恧ēµ±äø€ć§ćć‚‹ć“ćØ恧恙怂 CDIē®”ē†BeanćÆ当ē„¶ć§ć™ćŒć€ļ¼ˆå°‘ć—ę‰‹ć‚’åŠ ćˆć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ćŒļ¼‰EntityManager悂DataSource悂@Injectć§ć¶ć£č¾¼ć‚€ć“ćØ恌åÆčƒ½ć§ć™ć€‚

ꬠē‚¹ćÆJersey 1.11.1ć®ćƒć‚°ć§ć™ć€‚

ćć®ä»–ć€DIć®åˆ©ē‚¹

  • ć‚¤ćƒ³ć‚æćƒ¼ć‚»ćƒ—ć‚æć‚’ć‹ć¾ć›ć‚‹ļ¼ˆJAX-RS 2.0恋悉ćÆJAX-RSć®ä»•ę§˜ć«ć‚¤ćƒ³ć‚æćƒ¼ć‚»ćƒ—ć‚æćƒ¼ćŒå…„ć‚Šć¾ć™ćŒļ¼‰
  • ćƒ¢ćƒƒć‚Æ恫恙恒ę›æ恈悄恙恄
  • Arquillianć§ćƒ†ć‚¹ćƒˆć—ć‚„ć™ć„

Arquillian

ArquillianćÆJBossćŒęä¾›ć—ć¦ć„ć‚‹Java EEå‘ć‘ć®ēµåˆćƒ†ć‚¹ćƒˆćƒ•ćƒ¬ćƒ¼ćƒ ćƒÆćƒ¼ć‚Æ恧恙怂 仄äø‹ć®ä¾‹ć®ć‚ˆć†ć«ćƒ†ć‚¹ćƒˆć‚³ćƒ¼ćƒ‰ć‚’ę›ø恏äŗ‹ćŒåÆčƒ½ć§ć™ć€‚

@RunWith(Arquillian.class)
public class CalcTest {

    @Inject
    CalcBean calcBean;

    @Test
    public void test_add() throws Exception {
        int answer = calcBean.add(2, 3);
        assertThat(answer, is(5));
    }

    @Deployment
    public static WebArchive createDeployment() {
        return ShrinkWrap.create(WebArchive.class)
            .addClass(CalcBean.class)
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}

JAX-RS 2.0ć®ę–°ę©Ÿčƒ½

JAX-RS 2.0恋悉ćÆ仄äø‹ć®ć‚ˆć†ćŖę©Ÿčƒ½ćŒčæ½åŠ ć•ć‚Œć¾ć™ć€‚

  • ćƒ•ć‚£ćƒ«ć‚æćƒ¼
  • ć‚¤ćƒ³ć‚æćƒ¼ć‚»ćƒ—ć‚æćƒ¼
  • éžåŒęœŸå‡¦ē†
  • ć‚Æćƒ©ć‚¤ć‚¢ćƒ³ćƒˆAPI
  • Bean ValidationćØ恮ēµ±åˆ

ćƒ•ć‚£ćƒ«ć‚æćƒ¼

ćƒŖć‚Æć‚Øć‚¹ćƒˆćƒ»ćƒ¬ć‚¹ćƒćƒ³ć‚¹ćć‚Œćžć‚Œć«åƾåæœć™ć‚‹ćƒ•ć‚£ćƒ«ć‚æćƒ¼ć‚’ę›øć‘ć¾ć™ć€‚

@Provider
public class LoggingFilter implements ContainerRequestFilter, ContainerResponseFilter {

    @Override
    public void filter(ContainerRequestContext requestContext) throws IOException {
        Logger.getLogger("request");
    }

    @Override
    public void filter(ContainerRequestContext requestContext,
            ContainerResponseContext responseContext) throws IOException {
        Logger.getLogger("response");
    }
}

ć‚¤ćƒ³ć‚æćƒ¼ć‚»ćƒ—ć‚æćƒ¼

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒœćƒ‡ć‚£ć‚’čŖ­ćæę›ø恍恙悋ćØć“ć‚ć«ęØŖå…„ć‚Šć—ć¦ć”ć«ć‚‡ć”ć«ć‚‡ć§ćć¾ć™ć€‚

@Provider
public class StarInterceptor implements ReaderInterceptor, WriterInterceptor {

    @Override
    public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException,
        WebApplicationException {
        Object entity = context.proceed();
        return "+" + entity + "+";
    }

    @Override
    public void aroundWriteTo(WriterInterceptorContext context) throws IOException,
        WebApplicationException {
        Object entity = context.getEntity();
        context.setEntity("*" + entity + "*");
        context.proceed();
    }
}

ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć§é©ē”Ø恙悋ēÆ„å›²ć‚’ę±ŗ悁悋

CDIć‚‚ä¼¼ćŸć‚ˆć†ćŖę„Ÿć˜ć§ć™ćŒć€ćƒ•ć‚£ćƒ«ć‚æćƒ¼ļ¼ˆć‚¤ćƒ³ć‚æćƒ¼ć‚»ćƒ—ć‚æćƒ¼ļ¼‰ć«ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ä»˜ć‘ć¦ćŠććØåŒć˜ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćŒä»˜ć„ć¦ć„ć‚‹ćƒŖć‚½ćƒ¼ć‚¹ć‚Æćƒ©ć‚¹ćƒ»ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć«ćć®ćƒ•ć‚£ćƒ«ć‚æćƒ¼ļ¼ˆć‚¤ćƒ³ć‚æćƒ¼ć‚»ćƒ—ć‚æćƒ¼ļ¼‰ć‚’å™›ć¾ć›ć‚‹ć“ćØ恌å‡ŗę„ć‚‹ć‚ˆć†ć§ć™ć€‚

@NameBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE,
         ElementType.METHOD})
public static @interface Logged {
}

@Logged
@Provider
public class LoggingFilter implements ContainerRequestFilter, ContainerResponseFilter {
    ...

ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ćÆ恓悓ćŖꄟ恘怂

@POST
@Logged
public String post(String s) {
    ...

éžåŒęœŸå‡¦ē†

Servlet 3.xć«ć‚‚éžåŒęœŸå‡¦ē†ćŒå…„ć‚Šć¾ć—ćŸćŒć€JAX-RSć«ć‚‚ć‚„ć£ć¦ćć¾ć—ćŸć€‚ 仄äø‹ć®ć‚µćƒ³ćƒ—ćƒ«ćÆJSR 339ć«ä¹—ć£ć¦ć„ćŸć‚‚ć®ć§ć™ć€‚

private static final BlockingQueue<AsyncResponse> suspended =
    new ArrayBlockingQueue<AsyncResponse>(5);

@GET
@Produces("text/plain")
public void readMessage(@Suspended AsyncResponse ar) throws InterruptedException {
    suspended.put(ar);
}

@POST
@Produces("text/plain")
public String postMessage(final String message) throws InterruptedException {
    final AsyncResponse ar = suspended.take();
    ar.resume(message); // resumes the processing of one GET request
    return "Message sent";
}

恆悓态ä½æć„ć©ć“ć‚ćŒć‚ć‹ć‚Šć¾ć›ć‚“ļ¼

ä½æć£ć¦ćæ恟恄

ćØ恄恆悏恑恧态JAX-RS 2.0恮ćƒŖćƒŖćƒ¼ć‚¹ćÆć¾ć ć§ć™ćŒć€ć„ć”ę—©ćč©¦ć—ćŸć„å “åˆćÆJersey 2.x悒ä½æć£ć¦ćæć¾ć—ć‚‡ć†ļ¼

<dependencies>
  <dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-server</artifactId>
    <version>2.0-rc1</version>
  </dependency>
  <dependency>
    <groupId>org.glassfish.jersey.test-framework.providers</groupId>
    <artifactId>jersey-test-framework-provider-jdk-http</artifactId>
    <version>2.0-rc1</version>
    <scope>test</scope>
  </dependency>
</dependencies>

ć¾ćØ悁

  • JAX-RS恄恄恭ļ¼
  • 悂恆ServletćÆ要悉ćŖ恄恧恙恭
  • ćØ恓悍恧怌恄恄恭ļ¼Java EEļ¼ć€ć®ē¬¬äŗŒå›žćÆ恂悋悓恧恙恋恭ļ¼Ÿ

č³‡ę–™ć®ę‰‹ē›“ć—ć€ęœ€å¾Œć®ę–¹ē–²ć‚ŒćŸć®ć§ęŠ•ć’悄悊恧恙怂 ć¾ć‚ć€ć¾ćŸJAX-RSćÆč©±é”Œć«å‡ŗ恙ćØę€ć„ć¾ć™ć®ć§ę›ø恍恍悌ćŖć‹ć£ćŸļ¼ˆę›ø恍åæ˜ć‚ŒćŸļ¼‰ć‚¢ćƒ¬ćØć‹ć‚½ćƒ¬ćÆć¾ćŸć®ę©Ÿä¼šć«ćƒ¼ć€‚

]]>
Thu, 02 May 2013 00:00:00 +0900
http://backpaper0.github.io/2013/04/01/shigatsubaka.html http://backpaper0.github.io/2013/04/01/shigatsubaka.html <![CDATA[é€€č·ć—ć¾ć—ćŸ]]> é€€č·ć—ć¾ć—ćŸ

ęœ¬ę—„4/1ć‚’ć‚‚ć£ć¦ę Ŗ式会ē¤¾HOGEDRIVENć‚’é€€č·ć—ć¾ć—ćŸć€‚

HOGEDRIVEN恧ćÆäø¦č”Œćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°ļ¼ˆē„¼č‚‰ļ¼‰ć€ORćƒžćƒƒćƒ‘ćƒ¼ļ¼ˆćƒ•ć‚°ļ¼‰ć€ęš—号ļ¼ˆē„¼č‚‰ļ¼‰ć€Java 8ć®ćƒ©ćƒ ćƒ€ļ¼ˆć‚¹ćƒ†ćƒ¼ć‚­ļ¼‰ćŖć©ć€ę§˜ć€…ćŖꊀ蔓悒ēµŒéØ“ć•ć›ć¦č²°ć„ć™ć”ćę„Ÿč¬ć—ć¦ć„ć¾ć™ļ¼ˆć”ć”ćć†ć•ć¾ć§ć—ćŸļ¼‰ć€‚

恗恋恗态HOGEDRIVENćÆć€Œć—ć‚ƒć¶ć—ć‚ƒć¶ć€ć€Œćƒ­ćƒ¼ć‚¹ćƒˆćƒć‚­ćƒ³ć€ć€Œć‚·ć‚·ć‚±ćƒćƒ–ć€ćŖć©ć€ć“ć‚Œć‹ć‚‰ć‚‚č‚‰ę–™ē†ć«åŠ›ć‚’å…„ć‚Œć¦č”Œćć‚ˆć†ć§ć€é­šę–™ē†ć«ć‚‚ęŒ‘ęˆ¦ć—ćŸć„ćØ恄恆ē§ć®ę€ć„ćØćÆē›®ęŒ‡ć™ę–¹å‘ćŒē•°ćŖć‚‹ćŸć‚ć€é€€č·ćØ恄恆道悒éøęŠžć—ć¾ć—ćŸć€‚

ä»Šå¾Œć®äŗ‹ćÆć¾ć ä½•ć‚‚ę±ŗć¾ć£ć¦ć„ć¾ć›ć‚“ćŒć€ćƒ™ć‚æćŖćØ恓悍恧ćÆćƒžć‚°ćƒ­ć€ć‚«ćƒ‹ć€ć‚ć‚‹ć„ćÆęØć¦ć‚‹ę‰€ćŒē„”恄ćØčØ€ć‚ć‚Œć‚‹ć‚¢ćƒ³ć‚³ć‚¦ć‚ćŸć‚Šć«čˆˆå‘³ćŒć‚ć‚‹ć®ć§ć€ę©Ÿä¼šć‚’č¦‹ć¤ć‘ć¦ćƒćƒ£ćƒ¬ćƒ³ć‚øć—ć¦č”ŒććŸć„ćØę€ć„ć¾ć™ć€‚

今後ćØć‚‚å®œć—ććŠé”˜ć„ćŸć ćć¾ć™ć€‚

]]>
Mon, 01 Apr 2013 00:00:00 +0900
http://backpaper0.github.io/2013/03/03/like_bdd_by_java8.html http://backpaper0.github.io/2013/03/03/like_bdd_by_java8.html <![CDATA[Java8恧BDDć£ć½ććƒ†ć‚¹ćƒˆć‚’ę›ø恑悋恋悂恗悌ćŖć„ć‚¢ć‚¤ćƒ‡ć‚¢]]> Java8恧BDDć£ć½ććƒ†ć‚¹ćƒˆć‚’ę›ø恑悋恋悂恗悌ćŖć„ć‚¢ć‚¤ćƒ‡ć‚¢

Jasmine恧JavaScriptć®ćƒ†ć‚¹ćƒˆę›ø恄恟悊Java8ć®ćƒ©ćƒ ćƒ€ć«ę€ć„ć‚’é¦³ć›ć¦ć„ćŸć‚‰ćŖ悓ćØćŖćę€ć„ć¤ćć¾ć—ćŸć€‚ ćƒ©ćƒ ćƒ€ć«ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚¤ćƒ‹ć‚·ćƒ£ćƒ©ć‚¤ć‚¶ć‚’ēµ„ćæåˆć‚ć›ćŸć‚‰ć“ć‚“ćŖę„Ÿć˜ć§ćƒ†ć‚¹ćƒˆćŒę›ø恑恝恆恧恙怂

package app;

public class CalcSpec extends Specs {{

    it("1 č¶³ć™ 2 ćÆ 3", () -> {
        expect(() -> 1 + 2).toEqual(3);
    });

    it("1 å‰²ć‚‹ 0 ćÆ例外", () -> {
        expect(() -> 1 / 0).toThrow(ArithmeticException.class);
    });

}}

恆悀态Jasmineć½ć„ć€‚ ć¾ć‚å®ŸćÆBDDć½ć„ćØć‹ć‚ˆćåˆ†ć‹ć£ć¦ć„ć¾ć›ć‚“ćŒć€‚

itćƒ”ć‚½ćƒƒćƒ‰ć‚’å‘¼ć¶ćØē¬¬äø€å¼•ę•°ć®ćƒ†ć‚¹ćƒˆåć‚’key态ē¬¬äŗŒå¼•ę•°ć®Runnableć®ć‚ˆć†ćŖć‚Ŗ惖ć‚ø悧ć‚Æ惈悒valuećØć™ć‚‹ćƒžćƒƒćƒ—ć«ēŖć£č¾¼ćæć¾ć™ć€‚ ć“ć®ćƒžćƒƒćƒ—ć®ć²ćØ恤恮EntryćŒć²ćØć¤ć®ćƒ†ć‚¹ćƒˆć«ćŖć‚Šć¾ć™ć€‚ itćƒ”ć‚½ćƒƒćƒ‰ćÆć‚¹ćƒ¼ćƒ‘ćƒ¼ć‚Æćƒ©ć‚¹ć®Specsć«å®šē¾©ć•ć‚Œć¦ć„ć¾ć™ć€‚ ćć®Specsč‡Ŗä½“ć«@RunWith恌ę³Øé‡ˆć—ć¦ćŠć‚Šć€ćƒ†ć‚¹ćƒˆćÆSpecRunnerćØć„ć†ćƒ†ć‚¹ćƒˆćƒ©ćƒ³ćƒŠćƒ¼ć§å®Ÿč”Œć•ć‚Œć¾ć™ć€‚ SpecRunnerćÆSpecsć«é›†ć‚ć‚‰ć‚ŒćŸćƒ†ć‚¹ćƒˆć‚’å®Ÿč”Œć—ć¾ć™ć€‚

ćŖ恩ćØꖇē« ć«ć—ć¦ć‚‚ä¼ćˆć‚‰ć‚Œć‚‹ę°—ćŒć¾ć£ćŸćē„”恄恮恧SpecsćØSpecRunnerć®ć‚³ćƒ¼ćƒ‰ę™’ć—ć¾ć™ć€‚

SpecsćÆ恓悓ćŖꄟ恘怂

package app;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import org.junit.Assert;
import org.junit.runner.RunWith;

@RunWith(SpecRunner.class)
public class Specs {

    public Map<String, Spec> specs = new LinkedHashMap<>();

    protected void it(String name, Spec spec) {
        specs.put(name, spec);
    }

    protected <T> Expect<T> expect(Callable<T> c) {
        return new Expect<>(c);
    }

    public interface Spec {

        void run() throws Exception;
    }

    public static class Expect<T> {

        private final Callable<T> c;

        public Expect(Callable<T> c) {
            this.c = c;
        }

        public void toEqual(T value) throws Exception {
            Assert.assertEquals(value, c.call());
        }

        public void toThrow(Class<? extends Exception> exceptionClass) throws Exception {
            try {
                c.call();
                Assert.fail();
            } catch (Exception e) {
                if (!exceptionClass.isAssignableFrom(e.getClass())) {
                    Assert.fail();
                }
            }
        }
    }
}

SpecRunnerćÆ恓悓ćŖꄟ恘怂

package app;

import org.junit.runner.Description;
import org.junit.runner.Runner;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;

public class SpecRunner extends Runner {

    private final Specs spec;

    public SpecRunner(Class<Specs> specClass) throws InstantiationException, IllegalAccessException {
        spec = specClass.newInstance();
    }

    @Override
    public Description getDescription() {
        Description desc = Description.createSuiteDescription(spec.getClass());
        for (String name : spec.specs.keySet()) {
            desc.addChild(Description.createSuiteDescription(name));
        }
        return desc;
    }

    @Override
    public void run(RunNotifier notifier) {
        for (String name : spec.specs.keySet()) {
            Description desc = Description.createSuiteDescription(name);
            notifier.fireTestStarted(desc);
            try {
                spec.specs.get(name).run();
            } catch (Exception ex) {
                Failure f = new Failure(desc, ex);
                notifier.fireTestFailure(f);
            } finally {
                notifier.fireTestFinished(desc);
            }
        }
    }
}

ć“ć‚Œć‚‰ć®ć‚³ćƒ¼ćƒ‰ć‚’ć€Java8恫åƾåæœć—恦恄悋NetBeans恮開ē™ŗē‰ˆć‚’ä½æē”Ø恗恦試恗恦ćæć¾ć—ćŸć€‚

../../../_images/test-result.png

ć„ć„ę„Ÿć˜ć§å®Ÿč”Œć§ćć¾ć—ćŸć€‚

ćØć„ć†ć‚ć‘ć§ć€ćµć‚ć£ćØć—ćŸę€ć„ć¤ćć‚’ć‚µć‚Æ惃ćØ試恗恦ćæ恟恠恑恧恙恌态ćŖ恋ćŖ恋Java8恮åÆčƒ½ę€§ć‚’ę„Ÿć˜ć‚ŒćŸę°—ćŒć—ć¾ć™ć€‚ ćƒ†ć‚¹ćƒ†ć‚£ćƒ³ć‚°ćƒ•ćƒ¬ćƒ¼ćƒ ćƒÆćƒ¼ć‚Æć«é™ć‚‰ćšć­ć€č‰²ć€…å‡ŗć¦ćć¦ćć‚Œćć†ć§ć™ć­ć€‚

ę„½ć—ćæ恠怂ćÆ悈恓恄Java8怂

ć‚®ćƒƒćƒˆćƒćƒ–ć«ć‚‚ē½®ć„ćŸć‚ˆ

]]>
Sun, 03 Mar 2013 00:00:00 +0900
http://backpaper0.github.io/2013/01/30/httpserver_jaxb.html http://backpaper0.github.io/2013/01/30/httpserver_jaxb.html <![CDATA[HttpServerćØJAXB恧API悒ēµ„č¾¼ć‚€]]> HttpServerćØJAXB恧API悒ēµ„č¾¼ć‚€

å‰ć«å°é…’ć•ć‚“ćØJavać®ćƒ—ćƒ­ć‚»ć‚¹é–“é€šäæ”ć«ć¤ć„ć¦ćŠč©±ć—ć¾ć—ćŸć€‚

悓恧态ē§ć‚‚ē›£č¦–ćØ恄恆恋APIćØ恄恆恋态恝悓ćŖę„Ÿć˜ć®ć‚¢ćƒ¬ć‚’ē°”ꘓ恧č‰Æ恄恮恧悵ć‚Æ惃ćØēµ„č¾¼ć‚€åæ…č¦ćŒå‡ŗć¦ćć¾ć—ćŸć€‚ ćØ恄恆čØ³ć§ HttpServer ćØJAXB恧悵ć‚Æ惃ćØēµ„č¾¼ć‚‚ć†ćØę€ć„ć¾ć™ć€‚

ć»ć„ć€ć‚µćƒ³ćƒ—ćƒ«ć‚³ćƒ¼ćƒ‰ć€‚

import com.sun.net.httpserver.HttpContext;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.util.Date;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.xml.bind.JAXB;
import javax.xml.bind.annotation.XmlRootElement;

public class Monitor {

    public static void main(String[] args) throws Exception {
        InetSocketAddress address = new InetSocketAddress(8080);
        int backlog = -1;
        HttpServer server = HttpServer.create();
        server.bind(address, backlog);
        try {
            HttpContext context = server.createContext("/log");
            HttpHandler handler = new LogHandler();
            context.setHandler(handler);
            server.start();

            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    String message = "ćƒ€ć‚¤ć‚¢ćƒ­ć‚°ć‚’é–‰ć˜ć‚‹ćØéƖēµ‚äŗ†";
                    JOptionPane.showMessageDialog(null, message);
                }
            });
        } finally {
            server.stop(10);
        }
    }

    public static class LogHandler implements HttpHandler {

        @Override
        public void handle(HttpExchange exchange) throws IOException {
            Log log = new Log();
            log.result = Result.SUCCESS;
            log.timestamp = new Date();

            int statusCode = 200;
            int chunked = 0;
            exchange.sendResponseHeaders(statusCode, chunked);

            try (OutputStream out = exchange.getResponseBody()) {
                JAXB.marshal(log, out);
                out.flush();
            }
        }
    }

    @XmlRootElement
    public static class Log {

        public Result result;

        public Date timestamp;

    }

    public enum Result {

        SUCCESS, FAILURE

    }
}

HttpServerćÆć‚¢ćƒ‰ćƒ¬ć‚¹ęø”恗恦ęŗ–å‚™ć—ć¦ć€ćƒ‘ć‚¹ęø”ć—ć¦ć‚³ćƒ³ćƒ†ć‚­ć‚¹ćƒˆä½œć£ć¦ć€ćƒćƒ³ćƒ‰ćƒ©ē™»éŒ²ć™ć‚Œć°ćŠk怂 Java SE恧悂HTTPéƖē«‹ć¦ć‚‹ć®ē°”å˜ć§ć™ć­ć€‚ ć‚ćƒ¼ć„ć€‚

今回ćÆć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć®å‡¦ē†ēµęžœćØć‚æć‚¤ćƒ ć‚¹ć‚æćƒ³ćƒ—ć‚’ęŒć£ćŸćƒ­ć‚°ć‚’čæ”ć™ę„Ÿć˜ć®ćƒćƒ³ćƒ‰ćƒ©ć‚’ę›ø恄恦ćæć¾ć—ćŸć€‚ 惭悰ćÆPOJO恧č”Øē¾ć—ć¦ć„ć¾ć™ćŒć€JAXB恧XMLć«å¤‰ę›ć—ć¦ćƒ¬ć‚¹ćƒćƒ³ć‚¹ć«ę›ø恍å‡ŗć—ć¦ć„ć¾ć™ć€‚ ć“ć®ćƒćƒ³ćƒ‰ćƒ©ćÆę¬”ć®ć‚ˆć†ćŖXML悒čæ”ć—ć¾ć™ć€‚

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<log>
    <result>SUCCESS</result>
    <timestamp>2013-01-30T23:08:37.482+09:00</timestamp>
</log>

XMLćƒ™ćƒ¼ć‚¹ć®Web APIćŖ悉꧋ēÆ‰ć™ć‚‹ć®ćÆē°”å˜ć§ć™ć­ć€‚ ć‚ćƒ¼ć„ć€‚

ć¾ć‚ć‚‚ć†ć”ć‚‡ć„å¤šę©Ÿčƒ½ćŖAPI悒꧋ēÆ‰ć—ćŸć‹ć£ćŸć‚‰Jersey悒ēŖć£č¾¼ćæć¾ć™ćŒč¦ä»¶ć«ć‚ˆć£ć¦ćÆć“ć‚Œć§ååˆ†ć‹ćŖćƒ¼ć€ćØć‹ę€ć£ćŸć‚Šć—ć¾ć—ćŸć€‚

]]>
Wed, 30 Jan 2013 00:00:00 +0900
http://backpaper0.github.io/2013/01/23/netbeans_jpql.html http://backpaper0.github.io/2013/01/23/netbeans_jpql.html <![CDATA[NetBeans 7.2.1恧JPQLć®č£œå®Œć™ć‚‹ćƒ¼]]> NetBeans 7.2.1恧JPQLć®č£œå®Œć™ć‚‹ćƒ¼

恓悓恰悓ćÆļ¼ em.cQ ćØę‰“ć£ć¦ control + space 恧 createQuery ć‚’č£œå®Œć™ć‚‹ć†ć‚‰ćŒćæ恧恙怂

ć‚‚ć†ć‚­ćƒ£ćƒ”ćƒ«ć‚±ćƒ¼ć‚¹ć§ć®č£œå®ŒćŒē„”ć‹ć£ćŸć‚‰ē”Ÿćć¦č”Œć‘ć¾ć›ć‚“ć€‚ 恓悌ćÆEclićŖ悓ćØ恋恧悂å‡ŗę„ć¾ć™ć€‚ ćŸć¶ć‚“IDEA恧悂å‡ŗę„ć‚‹ć§ć—ć‚‡ć†ć€‚

ęœ¬é”Œć€‚ NetBeans恧ćÆJPQLć®č£œå®Œć‚‚ć§ćć¾ć™ć€ćØ恄恆話怂

../../../_images/compl1.png

FROM 悂怂

../../../_images/compl2.png

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£åć‚‚ć€‚

../../../_images/compl3.png

WHERE 悄态

../../../_images/compl4.png

ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć‚‚ć€‚

../../../_images/compl5.png

ę¼”ē®—å­ć‚‚ć€‚

../../../_images/compl6.png

ćØ恄恆ꄟ恘恧恙怂 ć§ć‚‚ć“ć‚Œćƒ­ćƒ¼ć‚«ćƒ«å¤‰ę•°ć«ēŖć£č¾¼ć‚€ćØč£œå®Œć—ć¦ćć‚ŒćŖć„ć®ćŒę®‹åæµć§ć™ć€‚

../../../_images/compl7.png

恂ćØ@NamedQuery恫ę›ø恏JPQLć§ć‚‚č£œå®Œć§ćć¾ć™ć€‚

../../../_images/compl8.png

ćƒ­ćƒ¼ć‚«ćƒ«å¤‰ę•°ć«ēŖć£č¾¼ć‚“恠ćØćć‚‚č£œå®ŒćŒåŠ¹ć„ć¦ćć‚Œć‚‹ć‚ˆć†ć«ćŖ悋ćØć‚‚ć£ćØå¬‰ć—ć„ć§ć™ć­ćƒ¼ć€‚ ē°”å˜ć§ć™ćŒć€ćć‚“ćŖę„Ÿć˜ć§ćƒ¼ć€‚

]]>
Wed, 23 Jan 2013 00:00:00 +0900
http://backpaper0.github.io/2013/01/12/http_trace.html http://backpaper0.github.io/2013/01/12/http_trace.html <![CDATA[GlassFish v3.1.2.2恧TRACEćƒ”ć‚½ćƒƒćƒ‰ć‚’čرåÆ恗ćŖ恄]]> GlassFish v3.1.2.2恧TRACEćƒ”ć‚½ćƒƒćƒ‰ć‚’čرåÆ恗ćŖ恄

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§čرåÆ恗ćŖć„ć‚ˆć†ć«ćŖć£ć¦ć„ć¾ć™ćŒå‚™åæ˜éŒ²ēš„恫äø€åæœę›øć„ć¦ćŠćć¾ć™ć€‚ asadminć‚³ćƒžćƒ³ćƒ‰ć§čØ­å®šć—ć¾ć™ć€‚

asadmin set configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.trace-enabled=false

ć‚‚ć”ć‚ć‚“GUIē®”ē†ć‚³ćƒ³ć‚½ćƒ¼ćƒ«ć‹ć‚‰ć‚‚čح定åÆčƒ½ć§ć€ę§‹ęˆ -> server-config -> 惍惃惈ćƒÆćƒ¼ć‚Æ꧋ꈐ -> ćƒ—ćƒ­ćƒˆć‚³ćƒ« -> http-listener-1 ć®ć€ŒHTTP怍ć‚æćƒ–ć‚’é–‹ć„ć¦ćƒˆćƒ¬ćƒ¼ć‚¹ć®ćƒć‚§ćƒƒć‚Æć‚’å¤–ć—ć¾ć™ć€‚

恓恮ēŠ¶ę…‹ć§TRACEćƒŖć‚Æć‚Øć‚¹ćƒˆć‚’ęŠ•ć’ć‚‹ćØ405 Method Not Allowed恌čæ”ć£ć¦ćć¾ć™ć€‚

]]>
Sat, 12 Jan 2013 00:00:00 +0900
http://backpaper0.github.io/2013/01/11/cookie.html http://backpaper0.github.io/2013/01/11/cookie.html <![CDATA[GlassFish 3.1.2.2恧Cookie恫secureå±žę€§ćØhttpOnlyå±žę€§ć‚’ć¤ć‘ć‚‹]]> GlassFish 3.1.2.2恧Cookie恫secureå±žę€§ćØhttpOnlyå±žę€§ć‚’ć¤ć‘ć‚‹

ä½•ć‚‚ć—ćŖćć¦ć‚‚httpOnlyå±žę€§ćÆä»˜ć„ć¦ć‚‹ę„Ÿć˜ć§ć™ćŒć€ćć‚ŒćÆGrizzlyć®ę©Ÿčƒ½ćŖ恮恧恗悇恆恋恭怂 恝悌ćÆćć‚Œć§ć¾ćŸčŖæć¹ć¦ćŠćć“ćØć«ć—ć¾ć™ć€‚

ćƒ—ćƒ­ć‚°ćƒ©ćƒ ć§čØ­å®šć™ć‚‹

javax.servlet.SessionCookieConfig 悒ä½æē”Øć—ć¾ć™ć€‚

package example;

import java.util.Set;
import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.SessionCookieConfig;

public class CookieSettings implements ServletContainerInitializer {

    @Override
    public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
        SessionCookieConfig scc = ctx.getSessionCookieConfig();
        scc.setHttpOnly(true);
        scc.setSecure(true);
    }
}

GlassFish Server Deployment Descriptor恧čØ­å®šć™ć‚‹

cookie-properties - Oracle GlassFish Server 3.1 Application Deployment Guide ć‚’å‚ē…§ć€‚

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC
  "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN"
  "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
 <session-config>
  <cookie-properties>
   <property name="cookieSecure" value="true"/>
   <property name="cookieHttpOnly" value="true"/>
  </cookie-properties>
 </session-config>
</glassfish-web-app>
]]>
Fri, 11 Jan 2013 00:00:00 +0900
http://backpaper0.github.io/2013/01/06/welcome_to_tinkerer.html http://backpaper0.github.io/2013/01/06/welcome_to_tinkerer.html <![CDATA[Welcome to Tinkerer]]> Welcome to Tinkerer

恂恑恊悁ļ¼

恝悓ćŖć‚¢ćƒ¬ć§ćÆ恦ćŖćƒ€ć‚¤ć‚¢ćƒŖćƒ¼ć‹ć‚‰ä¹—ć‚Šę›ćˆć‚‹ä½•ć‹ć‚’ęØ”ē“¢äø­ćŖ恮恧恙怂 TinkererćØ恄恆Sphinx恧惖惭悰恌ę›øć‘ć‚‹ę‹”å¼µć‚’č¦‹ć¤ć‘ćŸć®ć§ä½•ćØćŖ恏ä½æć£ć¦ćæ悈恆恋ćØ怂 恓恮ć‚Øćƒ³ćƒˆćƒŖ恧ćÆć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«ć‹ć‚‰backpaper0.github.comć§ć®å…¬é–‹ć¾ć§ć®ę‰‹é †ć‚’é©å½“ć«ę›øćć¾ć™ć€‚ ćŖ恊态ć‚Øćƒ³ćƒˆćƒŖ恮ć‚æć‚¤ćƒˆćƒ«ćÆć‚¦ć‚§ćƒ«ć‚«ćƒ ćƒ»ćƒˆć‚„ćƒ»ć‚Ŗć‚Æćƒˆćƒ—ćƒ¬ć‚¹ć‚’ćƒ‘ć‚Æć£ćŸć§ć™ć€‚

Tinkererć‚’ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«ć™ć‚‹

easy_install恧äø€ē™ŗć§ć™ć‚ˆå„„ć•ć‚“ć€‚

easy_install -U Tinkerer

ć‚»ćƒƒćƒˆć‚¢ćƒƒćƒ—ć™ć‚‹

é©å½“ć«ćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖä½œć£ć¦ć‹ć‚‰tinker -sć—ć¾ć™ć€‚

mkdir blog
cd blog
tinker -s

conf.pyćŒä½œęˆć•ć‚Œć‚‹ć®ć§ćƒ–ćƒ­ć‚°ć®åå‰ćØ恋čØ­å®šć—ć¾ć™ć€‚

čؘäŗ‹ć‚’ę›ø恏

ć‚Øćƒ³ćƒˆćƒŖä½œć‚Šć¾ć™ć€‚

tinker -p "Welcome to Tinkerer"

ę—„ä»˜ć‚’č”Øć™ćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ恫ē¶šćć‚Øćƒ³ćƒˆćƒŖ恮rstćƒ•ć‚”ć‚¤ćƒ«ćŒä½œęˆć•ć‚Œć¾ć™ć®ć§ć“ć‚Œć‚’ē·Øé›†ć—ć¾ć™ć€‚

ćƒ“ćƒ«ćƒ‰ć™ć‚‹

tinker -b

blog/htmlćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖć«ć‚‚ć‚ć‚‚ć‚å‡ŗåŠ›ć•ć‚Œć¾ć™ć€‚

å…¬é–‹ć™ć‚‹

blog/html仄äø‹ć‚’backpaper0.github.comć«ćƒ—ćƒƒć‚·ćƒ„ć—ć¾ć™ć€‚ ć¾ć‚ć¶ć£ć”ć‚ƒć‘ć“ć‚Œć‹ć‚‰ć‚„ć‚‹ć“ćØćŖ恮恧恓恮čؘäŗ‹ę›ø恄恦悋ꮵ階恧ćÆ恝悌恧č‰Æć„ć®ć‹åˆ†ć‹ć‚Šć¾ć›ć‚“ćŒć€‚

ć¾ćØ悁

  • rst恧ę›øć‘ć‚‹ć‹ć‚‰å¬‰ć—ć„
  • Sphinxå„½ććŖć®ć§å¬‰ć—ć„
  • ćŖć‚“ć‹ęŽ¢ć™ćØ恍ćÆgrepå‡ŗę„ć‚‹ć‹ć‚‰å¬‰ć—ć„
  • Tinkererē°”å˜ćć†ć§å¬‰ć—ć„

ćØ恄恆ꄟ恘恧恗恰悉恏ä½æć£ć¦ćæ悈恆ćØę€ć„ć¾ć™ć€‚

]]>
Sun, 06 Jan 2013 00:00:00 +0900