").append(b.parseHTML(e)).find(i):e)}).complete(r&&function(e,t){s.each(r,o||[e.responseText,t,e])}),this},b.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(e,t){b.fn[t]=function(e){return this.on(t,e)}}),b.each(["get","post"],function(e,n){b[n]=function(e,r,i,o){return b.isFunction(r)&&(o=o||i,i=r,r=t),b.ajax({url:e,type:n,dataType:o,data:r,success:i})}}),b.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:yn,type:"GET",isLocal:Nn.test(mn[1]),global:!0,processData:!0,async:!0,contentType:"application/x-www-form-urlencoded; charset=UTF-8",accepts:{"*":Dn,text:"text/plain",html:"text/html",xml:"application/xml, text/xml",json:"application/json, text/javascript"},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":e.String,"text html":!0,"text json":b.parseJSON,"text xml":b.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(e,t){return t?Mn(Mn(e,b.ajaxSettings),t):Mn(b.ajaxSettings,e)},ajaxPrefilter:Hn(An),ajaxTransport:Hn(jn),ajax:function(e,n){"object"==typeof e&&(n=e,e=t),n=n||{};var r,i,o,a,s,u,l,c,p=b.ajaxSetup({},n),f=p.context||p,d=p.context&&(f.nodeType||f.jquery)?b(f):b.event,h=b.Deferred(),g=b.Callbacks("once memory"),m=p.statusCode||{},y={},v={},x=0,T="canceled",N={readyState:0,getResponseHeader:function(e){var t;if(2===x){if(!c){c={};while(t=Tn.exec(a))c[t[1].toLowerCase()]=t[2]}t=c[e.toLowerCase()]}return null==t?null:t},getAllResponseHeaders:function(){return 2===x?a:null},setRequestHeader:function(e,t){var n=e.toLowerCase();return x||(e=v[n]=v[n]||e,y[e]=t),this},overrideMimeType:function(e){return x||(p.mimeType=e),this},statusCode:function(e){var t;if(e)if(2>x)for(t in e)m[t]=[m[t],e[t]];else N.always(e[N.status]);return this},abort:function(e){var t=e||T;return l&&l.abort(t),k(0,t),this}};if(h.promise(N).complete=g.add,N.success=N.done,N.error=N.fail,p.url=((e||p.url||yn)+"").replace(xn,"").replace(kn,mn[1]+"//"),p.type=n.method||n.type||p.method||p.type,p.dataTypes=b.trim(p.dataType||"*").toLowerCase().match(w)||[""],null==p.crossDomain&&(r=En.exec(p.url.toLowerCase()),p.crossDomain=!(!r||r[1]===mn[1]&&r[2]===mn[2]&&(r[3]||("http:"===r[1]?80:443))==(mn[3]||("http:"===mn[1]?80:443)))),p.data&&p.processData&&"string"!=typeof p.data&&(p.data=b.param(p.data,p.traditional)),qn(An,p,n,N),2===x)return N;u=p.global,u&&0===b.active++&&b.event.trigger("ajaxStart"),p.type=p.type.toUpperCase(),p.hasContent=!Cn.test(p.type),o=p.url,p.hasContent||(p.data&&(o=p.url+=(bn.test(o)?"&":"?")+p.data,delete p.data),p.cache===!1&&(p.url=wn.test(o)?o.replace(wn,"$1_="+vn++):o+(bn.test(o)?"&":"?")+"_="+vn++)),p.ifModified&&(b.lastModified[o]&&N.setRequestHeader("If-Modified-Since",b.lastModified[o]),b.etag[o]&&N.setRequestHeader("If-None-Match",b.etag[o])),(p.data&&p.hasContent&&p.contentType!==!1||n.contentType)&&N.setRequestHeader("Content-Type",p.contentType),N.setRequestHeader("Accept",p.dataTypes[0]&&p.accepts[p.dataTypes[0]]?p.accepts[p.dataTypes[0]]+("*"!==p.dataTypes[0]?", "+Dn+"; q=0.01":""):p.accepts["*"]);for(i in p.headers)N.setRequestHeader(i,p.headers[i]);if(p.beforeSend&&(p.beforeSend.call(f,N,p)===!1||2===x))return N.abort();T="abort";for(i in{success:1,error:1,complete:1})N[i](p[i]);if(l=qn(jn,p,n,N)){N.readyState=1,u&&d.trigger("ajaxSend",[N,p]),p.async&&p.timeout>0&&(s=setTimeout(function(){N.abort("timeout")},p.timeout));try{x=1,l.send(y,k)}catch(C){if(!(2>x))throw C;k(-1,C)}}else k(-1,"No Transport");function k(e,n,r,i){var c,y,v,w,T,C=n;2!==x&&(x=2,s&&clearTimeout(s),l=t,a=i||"",N.readyState=e>0?4:0,r&&(w=_n(p,N,r)),e>=200&&300>e||304===e?(p.ifModified&&(T=N.getResponseHeader("Last-Modified"),T&&(b.lastModified[o]=T),T=N.getResponseHeader("etag"),T&&(b.etag[o]=T)),204===e?(c=!0,C="nocontent"):304===e?(c=!0,C="notmodified"):(c=Fn(p,w),C=c.state,y=c.data,v=c.error,c=!v)):(v=C,(e||!C)&&(C="error",0>e&&(e=0))),N.status=e,N.statusText=(n||C)+"",c?h.resolveWith(f,[y,C,N]):h.rejectWith(f,[N,C,v]),N.statusCode(m),m=t,u&&d.trigger(c?"ajaxSuccess":"ajaxError",[N,p,c?y:v]),g.fireWith(f,[N,C]),u&&(d.trigger("ajaxComplete",[N,p]),--b.active||b.event.trigger("ajaxStop")))}return N},getScript:function(e,n){return b.get(e,t,n,"script")},getJSON:function(e,t,n){return b.get(e,t,n,"json")}});function _n(e,n,r){var i,o,a,s,u=e.contents,l=e.dataTypes,c=e.responseFields;for(s in c)s in r&&(n[c[s]]=r[s]);while("*"===l[0])l.shift(),o===t&&(o=e.mimeType||n.getResponseHeader("Content-Type"));if(o)for(s in u)if(u[s]&&u[s].test(o)){l.unshift(s);break}if(l[0]in r)a=l[0];else{for(s in r){if(!l[0]||e.converters[s+" "+l[0]]){a=s;break}i||(i=s)}a=a||i}return a?(a!==l[0]&&l.unshift(a),r[a]):t}function Fn(e,t){var n,r,i,o,a={},s=0,u=e.dataTypes.slice(),l=u[0];if(e.dataFilter&&(t=e.dataFilter(t,e.dataType)),u[1])for(i in e.converters)a[i.toLowerCase()]=e.converters[i];for(;r=u[++s];)if("*"!==r){if("*"!==l&&l!==r){if(i=a[l+" "+r]||a["* "+r],!i)for(n in a)if(o=n.split(" "),o[1]===r&&(i=a[l+" "+o[0]]||a["* "+o[0]])){i===!0?i=a[n]:a[n]!==!0&&(r=o[0],u.splice(s--,0,r));break}if(i!==!0)if(i&&e["throws"])t=i(t);else try{t=i(t)}catch(c){return{state:"parsererror",error:i?c:"No conversion from "+l+" to "+r}}}l=r}return{state:"success",data:t}}b.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/(?:java|ecma)script/},converters:{"text script":function(e){return b.globalEval(e),e}}}),b.ajaxPrefilter("script",function(e){e.cache===t&&(e.cache=!1),e.crossDomain&&(e.type="GET",e.global=!1)}),b.ajaxTransport("script",function(e){if(e.crossDomain){var n,r=o.head||b("head")[0]||o.documentElement;return{send:function(t,i){n=o.createElement("script"),n.async=!0,e.scriptCharset&&(n.charset=e.scriptCharset),n.src=e.url,n.onload=n.onreadystatechange=function(e,t){(t||!n.readyState||/loaded|complete/.test(n.readyState))&&(n.onload=n.onreadystatechange=null,n.parentNode&&n.parentNode.removeChild(n),n=null,t||i(200,"success"))},r.insertBefore(n,r.firstChild)},abort:function(){n&&n.onload(t,!0)}}}});var On=[],Bn=/(=)\?(?=&|$)|\?\?/;b.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var e=On.pop()||b.expando+"_"+vn++;return this[e]=!0,e}}),b.ajaxPrefilter("json jsonp",function(n,r,i){var o,a,s,u=n.jsonp!==!1&&(Bn.test(n.url)?"url":"string"==typeof n.data&&!(n.contentType||"").indexOf("application/x-www-form-urlencoded")&&Bn.test(n.data)&&"data");return u||"jsonp"===n.dataTypes[0]?(o=n.jsonpCallback=b.isFunction(n.jsonpCallback)?n.jsonpCallback():n.jsonpCallback,u?n[u]=n[u].replace(Bn,"$1"+o):n.jsonp!==!1&&(n.url+=(bn.test(n.url)?"&":"?")+n.jsonp+"="+o),n.converters["script json"]=function(){return s||b.error(o+" was not called"),s[0]},n.dataTypes[0]="json",a=e[o],e[o]=function(){s=arguments},i.always(function(){e[o]=a,n[o]&&(n.jsonpCallback=r.jsonpCallback,On.push(o)),s&&b.isFunction(a)&&a(s[0]),s=a=t}),"script"):t});var Pn,Rn,Wn=0,$n=e.ActiveXObject&&function(){var e;for(e in Pn)Pn[e](t,!0)};function In(){try{return new e.XMLHttpRequest}catch(t){}}function zn(){try{return new e.ActiveXObject("Microsoft.XMLHTTP")}catch(t){}}b.ajaxSettings.xhr=e.ActiveXObject?function(){return!this.isLocal&&In()||zn()}:In,Rn=b.ajaxSettings.xhr(),b.support.cors=!!Rn&&"withCredentials"in Rn,Rn=b.support.ajax=!!Rn,Rn&&b.ajaxTransport(function(n){if(!n.crossDomain||b.support.cors){var r;return{send:function(i,o){var a,s,u=n.xhr();if(n.username?u.open(n.type,n.url,n.async,n.username,n.password):u.open(n.type,n.url,n.async),n.xhrFields)for(s in n.xhrFields)u[s]=n.xhrFields[s];n.mimeType&&u.overrideMimeType&&u.overrideMimeType(n.mimeType),n.crossDomain||i["X-Requested-With"]||(i["X-Requested-With"]="XMLHttpRequest");try{for(s in i)u.setRequestHeader(s,i[s])}catch(l){}u.send(n.hasContent&&n.data||null),r=function(e,i){var s,l,c,p;try{if(r&&(i||4===u.readyState))if(r=t,a&&(u.onreadystatechange=b.noop,$n&&delete Pn[a]),i)4!==u.readyState&&u.abort();else{p={},s=u.status,l=u.getAllResponseHeaders(),"string"==typeof u.responseText&&(p.text=u.responseText);try{c=u.statusText}catch(f){c=""}s||!n.isLocal||n.crossDomain?1223===s&&(s=204):s=p.text?200:404}}catch(d){i||o(-1,d)}p&&o(s,c,p,l)},n.async?4===u.readyState?setTimeout(r):(a=++Wn,$n&&(Pn||(Pn={},b(e).unload($n)),Pn[a]=r),u.onreadystatechange=r):r()},abort:function(){r&&r(t,!0)}}}});var Xn,Un,Vn=/^(?:toggle|show|hide)$/,Yn=RegExp("^(?:([+-])=|)("+x+")([a-z%]*)$","i"),Jn=/queueHooks$/,Gn=[nr],Qn={"*":[function(e,t){var n,r,i=this.createTween(e,t),o=Yn.exec(t),a=i.cur(),s=+a||0,u=1,l=20;if(o){if(n=+o[2],r=o[3]||(b.cssNumber[e]?"":"px"),"px"!==r&&s){s=b.css(i.elem,e,!0)||n||1;do u=u||".5",s/=u,b.style(i.elem,e,s+r);while(u!==(u=i.cur()/a)&&1!==u&&--l)}i.unit=r,i.start=s,i.end=o[1]?s+(o[1]+1)*n:n}return i}]};function Kn(){return setTimeout(function(){Xn=t}),Xn=b.now()}function Zn(e,t){b.each(t,function(t,n){var r=(Qn[t]||[]).concat(Qn["*"]),i=0,o=r.length;for(;o>i;i++)if(r[i].call(e,t,n))return})}function er(e,t,n){var r,i,o=0,a=Gn.length,s=b.Deferred().always(function(){delete u.elem}),u=function(){if(i)return!1;var t=Xn||Kn(),n=Math.max(0,l.startTime+l.duration-t),r=n/l.duration||0,o=1-r,a=0,u=l.tweens.length;for(;u>a;a++)l.tweens[a].run(o);return s.notifyWith(e,[l,o,n]),1>o&&u?n:(s.resolveWith(e,[l]),!1)},l=s.promise({elem:e,props:b.extend({},t),opts:b.extend(!0,{specialEasing:{}},n),originalProperties:t,originalOptions:n,startTime:Xn||Kn(),duration:n.duration,tweens:[],createTween:function(t,n){var r=b.Tween(e,l.opts,t,n,l.opts.specialEasing[t]||l.opts.easing);return l.tweens.push(r),r},stop:function(t){var n=0,r=t?l.tweens.length:0;if(i)return this;for(i=!0;r>n;n++)l.tweens[n].run(1);return t?s.resolveWith(e,[l,t]):s.rejectWith(e,[l,t]),this}}),c=l.props;for(tr(c,l.opts.specialEasing);a>o;o++)if(r=Gn[o].call(l,e,c,l.opts))return r;return Zn(l,c),b.isFunction(l.opts.start)&&l.opts.start.call(e,l),b.fx.timer(b.extend(u,{elem:e,anim:l,queue:l.opts.queue})),l.progress(l.opts.progress).done(l.opts.done,l.opts.complete).fail(l.opts.fail).always(l.opts.always)}function tr(e,t){var n,r,i,o,a;for(i in e)if(r=b.camelCase(i),o=t[r],n=e[i],b.isArray(n)&&(o=n[1],n=e[i]=n[0]),i!==r&&(e[r]=n,delete e[i]),a=b.cssHooks[r],a&&"expand"in a){n=a.expand(n),delete e[r];for(i in n)i in e||(e[i]=n[i],t[i]=o)}else t[r]=o}b.Animation=b.extend(er,{tweener:function(e,t){b.isFunction(e)?(t=e,e=["*"]):e=e.split(" ");var n,r=0,i=e.length;for(;i>r;r++)n=e[r],Qn[n]=Qn[n]||[],Qn[n].unshift(t)},prefilter:function(e,t){t?Gn.unshift(e):Gn.push(e)}});function nr(e,t,n){var r,i,o,a,s,u,l,c,p,f=this,d=e.style,h={},g=[],m=e.nodeType&&nn(e);n.queue||(c=b._queueHooks(e,"fx"),null==c.unqueued&&(c.unqueued=0,p=c.empty.fire,c.empty.fire=function(){c.unqueued||p()}),c.unqueued++,f.always(function(){f.always(function(){c.unqueued--,b.queue(e,"fx").length||c.empty.fire()})})),1===e.nodeType&&("height"in t||"width"in t)&&(n.overflow=[d.overflow,d.overflowX,d.overflowY],"inline"===b.css(e,"display")&&"none"===b.css(e,"float")&&(b.support.inlineBlockNeedsLayout&&"inline"!==un(e.nodeName)?d.zoom=1:d.display="inline-block")),n.overflow&&(d.overflow="hidden",b.support.shrinkWrapBlocks||f.always(function(){d.overflow=n.overflow[0],d.overflowX=n.overflow[1],d.overflowY=n.overflow[2]}));for(i in t)if(a=t[i],Vn.exec(a)){if(delete t[i],u=u||"toggle"===a,a===(m?"hide":"show"))continue;g.push(i)}if(o=g.length){s=b._data(e,"fxshow")||b._data(e,"fxshow",{}),"hidden"in s&&(m=s.hidden),u&&(s.hidden=!m),m?b(e).show():f.done(function(){b(e).hide()}),f.done(function(){var t;b._removeData(e,"fxshow");for(t in h)b.style(e,t,h[t])});for(i=0;o>i;i++)r=g[i],l=f.createTween(r,m?s[r]:0),h[r]=s[r]||b.style(e,r),r in s||(s[r]=l.start,m&&(l.end=l.start,l.start="width"===r||"height"===r?1:0))}}function rr(e,t,n,r,i){return new rr.prototype.init(e,t,n,r,i)}b.Tween=rr,rr.prototype={constructor:rr,init:function(e,t,n,r,i,o){this.elem=e,this.prop=n,this.easing=i||"swing",this.options=t,this.start=this.now=this.cur(),this.end=r,this.unit=o||(b.cssNumber[n]?"":"px")},cur:function(){var e=rr.propHooks[this.prop];return e&&e.get?e.get(this):rr.propHooks._default.get(this)},run:function(e){var t,n=rr.propHooks[this.prop];return this.pos=t=this.options.duration?b.easing[this.easing](e,this.options.duration*e,0,1,this.options.duration):e,this.now=(this.end-this.start)*t+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),n&&n.set?n.set(this):rr.propHooks._default.set(this),this}},rr.prototype.init.prototype=rr.prototype,rr.propHooks={_default:{get:function(e){var t;return null==e.elem[e.prop]||e.elem.style&&null!=e.elem.style[e.prop]?(t=b.css(e.elem,e.prop,""),t&&"auto"!==t?t:0):e.elem[e.prop]},set:function(e){b.fx.step[e.prop]?b.fx.step[e.prop](e):e.elem.style&&(null!=e.elem.style[b.cssProps[e.prop]]||b.cssHooks[e.prop])?b.style(e.elem,e.prop,e.now+e.unit):e.elem[e.prop]=e.now}}},rr.propHooks.scrollTop=rr.propHooks.scrollLeft={set:function(e){e.elem.nodeType&&e.elem.parentNode&&(e.elem[e.prop]=e.now)}},b.each(["toggle","show","hide"],function(e,t){var n=b.fn[t];b.fn[t]=function(e,r,i){return null==e||"boolean"==typeof e?n.apply(this,arguments):this.animate(ir(t,!0),e,r,i)}}),b.fn.extend({fadeTo:function(e,t,n,r){return this.filter(nn).css("opacity",0).show().end().animate({opacity:t},e,n,r)},animate:function(e,t,n,r){var i=b.isEmptyObject(e),o=b.speed(t,n,r),a=function(){var t=er(this,b.extend({},e),o);a.finish=function(){t.stop(!0)},(i||b._data(this,"finish"))&&t.stop(!0)};return a.finish=a,i||o.queue===!1?this.each(a):this.queue(o.queue,a)},stop:function(e,n,r){var i=function(e){var t=e.stop;delete e.stop,t(r)};return"string"!=typeof e&&(r=n,n=e,e=t),n&&e!==!1&&this.queue(e||"fx",[]),this.each(function(){var t=!0,n=null!=e&&e+"queueHooks",o=b.timers,a=b._data(this);if(n)a[n]&&a[n].stop&&i(a[n]);else for(n in a)a[n]&&a[n].stop&&Jn.test(n)&&i(a[n]);for(n=o.length;n--;)o[n].elem!==this||null!=e&&o[n].queue!==e||(o[n].anim.stop(r),t=!1,o.splice(n,1));(t||!r)&&b.dequeue(this,e)})},finish:function(e){return e!==!1&&(e=e||"fx"),this.each(function(){var t,n=b._data(this),r=n[e+"queue"],i=n[e+"queueHooks"],o=b.timers,a=r?r.length:0;for(n.finish=!0,b.queue(this,e,[]),i&&i.cur&&i.cur.finish&&i.cur.finish.call(this),t=o.length;t--;)o[t].elem===this&&o[t].queue===e&&(o[t].anim.stop(!0),o.splice(t,1));for(t=0;a>t;t++)r[t]&&r[t].finish&&r[t].finish.call(this);delete n.finish})}});function ir(e,t){var n,r={height:e},i=0;for(t=t?1:0;4>i;i+=2-t)n=Zt[i],r["margin"+n]=r["padding"+n]=e;return t&&(r.opacity=r.width=e),r}b.each({slideDown:ir("show"),slideUp:ir("hide"),slideToggle:ir("toggle"),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(e,t){b.fn[e]=function(e,n,r){return this.animate(t,e,n,r)}}),b.speed=function(e,t,n){var r=e&&"object"==typeof e?b.extend({},e):{complete:n||!n&&t||b.isFunction(e)&&e,duration:e,easing:n&&t||t&&!b.isFunction(t)&&t};return r.duration=b.fx.off?0:"number"==typeof r.duration?r.duration:r.duration in b.fx.speeds?b.fx.speeds[r.duration]:b.fx.speeds._default,(null==r.queue||r.queue===!0)&&(r.queue="fx"),r.old=r.complete,r.complete=function(){b.isFunction(r.old)&&r.old.call(this),r.queue&&b.dequeue(this,r.queue)},r},b.easing={linear:function(e){return e},swing:function(e){return.5-Math.cos(e*Math.PI)/2}},b.timers=[],b.fx=rr.prototype.init,b.fx.tick=function(){var e,n=b.timers,r=0;for(Xn=b.now();n.length>r;r++)e=n[r],e()||n[r]!==e||n.splice(r--,1);n.length||b.fx.stop(),Xn=t},b.fx.timer=function(e){e()&&b.timers.push(e)&&b.fx.start()},b.fx.interval=13,b.fx.start=function(){Un||(Un=setInterval(b.fx.tick,b.fx.interval))},b.fx.stop=function(){clearInterval(Un),Un=null},b.fx.speeds={slow:600,fast:200,_default:400},b.fx.step={},b.expr&&b.expr.filters&&(b.expr.filters.animated=function(e){return b.grep(b.timers,function(t){return e===t.elem}).length}),b.fn.offset=function(e){if(arguments.length)return e===t?this:this.each(function(t){b.offset.setOffset(this,e,t)});var n,r,o={top:0,left:0},a=this[0],s=a&&a.ownerDocument;if(s)return n=s.documentElement,b.contains(n,a)?(typeof a.getBoundingClientRect!==i&&(o=a.getBoundingClientRect()),r=or(s),{top:o.top+(r.pageYOffset||n.scrollTop)-(n.clientTop||0),left:o.left+(r.pageXOffset||n.scrollLeft)-(n.clientLeft||0)}):o},b.offset={setOffset:function(e,t,n){var r=b.css(e,"position");"static"===r&&(e.style.position="relative");var i=b(e),o=i.offset(),a=b.css(e,"top"),s=b.css(e,"left"),u=("absolute"===r||"fixed"===r)&&b.inArray("auto",[a,s])>-1,l={},c={},p,f;u?(c=i.position(),p=c.top,f=c.left):(p=parseFloat(a)||0,f=parseFloat(s)||0),b.isFunction(t)&&(t=t.call(e,n,o)),null!=t.top&&(l.top=t.top-o.top+p),null!=t.left&&(l.left=t.left-o.left+f),"using"in t?t.using.call(e,l):i.css(l)}},b.fn.extend({position:function(){if(this[0]){var e,t,n={top:0,left:0},r=this[0];return"fixed"===b.css(r,"position")?t=r.getBoundingClientRect():(e=this.offsetParent(),t=this.offset(),b.nodeName(e[0],"html")||(n=e.offset()),n.top+=b.css(e[0],"borderTopWidth",!0),n.left+=b.css(e[0],"borderLeftWidth",!0)),{top:t.top-n.top-b.css(r,"marginTop",!0),left:t.left-n.left-b.css(r,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var e=this.offsetParent||o.documentElement;while(e&&!b.nodeName(e,"html")&&"static"===b.css(e,"position"))e=e.offsetParent;return e||o.documentElement})}}),b.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(e,n){var r=/Y/.test(n);b.fn[e]=function(i){return b.access(this,function(e,i,o){var a=or(e);return o===t?a?n in a?a[n]:a.document.documentElement[i]:e[i]:(a?a.scrollTo(r?b(a).scrollLeft():o,r?o:b(a).scrollTop()):e[i]=o,t)},e,i,arguments.length,null)}});function or(e){return b.isWindow(e)?e:9===e.nodeType?e.defaultView||e.parentWindow:!1}b.each({Height:"height",Width:"width"},function(e,n){b.each({padding:"inner"+e,content:n,"":"outer"+e},function(r,i){b.fn[i]=function(i,o){var a=arguments.length&&(r||"boolean"!=typeof i),s=r||(i===!0||o===!0?"margin":"border");return b.access(this,function(n,r,i){var o;return b.isWindow(n)?n.document.documentElement["client"+e]:9===n.nodeType?(o=n.documentElement,Math.max(n.body["scroll"+e],o["scroll"+e],n.body["offset"+e],o["offset"+e],o["client"+e])):i===t?b.css(n,r,s):b.style(n,r,i,s)},n,a?i:t,a,null)}})}),e.jQuery=e.$=b,"function"==typeof define&&define.amd&&define.amd.jQuery&&define("jquery",[],function(){return b})})(window);
\ No newline at end of file
diff --git a/java-async-servlet/src/main/webapp/js/myfunctions.js b/java-async-servlet/src/main/webapp/js/myfunctions.js
new file mode 100644
index 00000000..17bef8c5
--- /dev/null
+++ b/java-async-servlet/src/main/webapp/js/myfunctions.js
@@ -0,0 +1,37 @@
+function sendAsync(seq) {
+ var data = new Object();
+ data.seq = seq;
+ $.ajax({
+ url: "/async",
+ type: 'GET',
+ data: data,
+
+ success: function (data) {
+ $("#ares-"+data).text("reponse "+data);
+ },
+ error:function(data,status,er) {
+ alert("error: "+data+" status: "+status+" er:"+er);
+ }
+ });
+}
+
+
+$(document).ready(function(){
+ $("#start").click(function(){
+
+ $("tr:has(td)").remove();
+
+ for(i = 1 ; i < 5 ; i++){
+ $("#asyncResponse").append($('
|
')
+ .append($('
| ').text("request -"+i))
+ .append($("
| ").text("processing.."))
+ );
+ sendAsync(i);
+ }
+ });
+
+
+ $("#exit").click(function(){
+ sendAsync("exit");
+ });
+})
diff --git a/java-combinations/Combination.java b/java-combinations/Combination.java
new file mode 100644
index 00000000..ebe54224
--- /dev/null
+++ b/java-combinations/Combination.java
@@ -0,0 +1,95 @@
+package com.hmkcode;
+
+
+
+public class Combination {
+
+
+ public static void main(String[] args){
+ Object[] elements = new Object[] {'A','B','C','D','E'};
+ combination(elements,3);
+ }
+
+
+ public static void combination(Object[] elements, int K){
+
+ // get the length of the array
+ // e.g. for {'A','B','C','D'} => N = 4
+ int N = elements.length;
+
+ if(K > N){
+ System.out.println("Invalid input, K > N");
+ return;
+ }
+
+ // calculate the possible combinations
+ c(N,K);
+
+ // init combination index array
+ int combination[] = new int[K];
+
+
+ int r = 0; // index for combination array
+ int i = 0; // index for elements array
+
+ while(r >= 0){
+
+ // forward step if i < (N + (r-K))
+ if(i <= (N + (r - K))){
+ combination[r] = i;
+
+ // if combination array is full print and increment i;
+ if(r == K-1){
+ print(combination, elements);
+ i++;
+ }
+ else{
+ // if combination is not full yet, select next element
+ i = combination[r]+1;
+ r++;
+ }
+
+ }
+
+ // backward step
+ else{
+ r--;
+ if(r >= 0)
+ i = combination[r]+1;
+
+ }
+ }
+ }
+
+
+
+ private static int c(int n, int r){
+ int nf=fact(n);
+ int rf=fact(r);
+ int nrf=fact(n-r);
+ int npr=nf/nrf;
+ int ncr=npr/rf;
+
+ System.out.println("C("+n+","+r+") = "+ ncr);
+
+ return ncr;
+ }
+
+ private static int fact(int n)
+ {
+ if(n == 0)
+ return 1;
+ else
+ return n * fact(n-1);
+ }
+
+
+ private static void print(int[] combination, Object[] elements){
+
+ String output = "";
+ for(int z = 0 ; z < combination.length;z++){
+ output += elements[combination[z]];
+ }
+ System.out.println(output);
+ }
+}
diff --git a/java-combinations/README.md b/java-combinations/README.md
new file mode 100644
index 00000000..402992b5
--- /dev/null
+++ b/java-combinations/README.md
@@ -0,0 +1,8 @@
+Algorithms for Finding all Possible Combinations of k Elements in an Array with Java Implementation
+===================================================================================================
+
+Refer to the [http://hmkcode.github.io/calculate-find-all-possible-combinations-of-an-array-using-java/](http://hmkcode.github.io/calculate-find-all-possible-combinations-of-an-array-using-java/) for more info.
+
+Given an array of size N e.g. `e={'A','B','C','D','E'}` **N=5**, we want to find all possible combinations of K elements in that array. For example, if K=3 then one possible combination is of array **e** is `{'A','B','C'}. Here we have three different algorithms for finding *k*-combinations of an array.
+
+
diff --git a/java-combinations/src/main/java/com/hmkcode/ForwardBackward.java b/java-combinations/src/main/java/com/hmkcode/ForwardBackward.java
new file mode 100644
index 00000000..42f94932
--- /dev/null
+++ b/java-combinations/src/main/java/com/hmkcode/ForwardBackward.java
@@ -0,0 +1,95 @@
+package com.hmkcode;
+
+
+
+public class ForwardBackward {
+
+
+ public static void main(String[] args){
+ Object[] e = new Object[] {'A','B','C','D','E'};
+ int k = 3;
+ combination(e,k);
+ }
+
+
+ public static void combination(Object[] elements, int k){
+
+ // get the length of the array
+ // e.g. for {'A','B','C','D'} => N = 4
+ int N = elements.length;
+
+ if(k > N){
+ System.out.println("Invalid input, K > N");
+ return;
+ }
+
+ // calculate the possible combinations
+ c(N,k);
+
+ // init combination index array
+ int pointers[] = new int[k];
+
+
+ int r = 0; // index for combination array
+ int i = 0; // index for elements array
+
+ while(r >= 0){
+
+ // forward step if i < (N + (r-K))
+ if(i <= (N + (r - k))){
+ pointers[r] = i;
+
+ // if combination array is full print and increment i;
+ if(r == k-1){
+ print(pointers, elements);
+ i++;
+ }
+ else{
+ // if combination is not full yet, select next element
+ i = pointers[r]+1;
+ r++;
+ }
+ }
+
+ // backward step
+ else{
+ r--;
+ if(r >= 0)
+ i = pointers[r]+1;
+
+ }
+ }
+ }
+
+
+
+ private static int c(int n, int r){
+ int nf=fact(n);
+ int rf=fact(r);
+ int nrf=fact(n-r);
+ int npr=nf/nrf;
+ int ncr=npr/rf;
+
+ System.out.println("C("+n+","+r+") = "+ ncr);
+
+ return ncr;
+ }
+
+ private static int fact(int n)
+ {
+ if(n == 0)
+ return 1;
+ else
+ return n * fact(n-1);
+ }
+
+
+ private static void print(int[] combination, Object[] elements){
+
+ String output = "";
+ for(int z = 0 ; z < combination.length;z++){
+ output += elements[combination[z]];
+ }
+ System.out.println(output);
+ }
+}
diff --git a/java-combinations/src/main/java/com/hmkcode/Recursive.java b/java-combinations/src/main/java/com/hmkcode/Recursive.java
new file mode 100644
index 00000000..a4acc9ac
--- /dev/null
+++ b/java-combinations/src/main/java/com/hmkcode/Recursive.java
@@ -0,0 +1,45 @@
+package com.hmkcode;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class Recursive {
+
+ public static void main(String[] args) {
+
+ List
e = Arrays.asList("A", "B", "C", "D", "E");
+ int k = 3;
+ combination(e, k, "");
+
+ }
+ static int counter = 0;
+ public static void combination(List e, int k, String accumulated){
+
+ // 1. stop
+ if(e.size() < k)
+ return;
+
+ // 2. add each element in e to accumulated
+ if(k == 1)
+ for(String s:e)
+ print(accumulated+s);
+
+ // 3. add all elements in e to accumulated
+ else if(e.size() == k){
+ for(String s:e)
+ accumulated+=s;
+ print(accumulated);
+ }
+
+ // 4. for each element, call combination
+ else if(e.size() > k)
+ for(int i = 0 ; i < e.size() ; i++)
+ combination(e.subList(i+1, e.size()), k-1, accumulated+e.get(i));
+
+ }
+
+ public static void print(String c){
+ counter++;
+ System.out.println(counter+"\t"+c);
+ }
+}
diff --git a/java-combinations/src/main/java/com/hmkcode/Shifting.java b/java-combinations/src/main/java/com/hmkcode/Shifting.java
new file mode 100644
index 00000000..d81ce2b5
--- /dev/null
+++ b/java-combinations/src/main/java/com/hmkcode/Shifting.java
@@ -0,0 +1,66 @@
+package com.hmkcode;
+
+public class Shifting
+{
+ public static void main( String[] args )
+ {
+ String[] e = {"A","B","C","D","E"};
+ int k = 3;
+ combination(e,k);
+ }
+ public static void combination(Object[] e, int k){
+
+ int[] ignore = new int[e.length-k]; // --> [0][0]
+ int[] combination = new int[k]; // --> [][][]
+
+ // set initial ignored elements
+ //(last k elements will be ignored)
+ for(int w = 0; w < ignore.length; w++)
+ ignore[w] = e.length - k +(w+1);
+
+ int i = 0, r = 0, g = 0;
+
+ boolean terminate = false;
+ while(!terminate){
+
+ // selecting N-k non-ignored elements
+ while(i < e.length && r < k){
+
+ if(i != ignore[g]){
+ combination[r] = i;
+ r++; i++;
+ }
+ else{
+ if(g != ignore.length-1)
+ g++;
+ i++;
+ }
+ }
+ print(combination, e);
+ i = 0; r = 0; g = 0;
+
+ terminate = true;
+
+ // shifting ignored indices
+ for(int w = 0 ; w < ignore.length; w++){
+ if(ignore[w] > w){
+ ignore[w]--;
+
+ if(w > 0)
+ ignore[w-1] = ignore[w]-1;
+ terminate = false;
+ break;
+ }
+ }
+ }
+ }
+
+ private static void print(int[] combination, Object[] elements){
+
+ String output = "";
+ for(int z = 0 ; z < combination.length;z++){
+ output += elements[combination[z]];
+ }
+ System.out.println(output);
+ }
+}
\ No newline at end of file
diff --git a/java-jasper/pom.xml b/java-jasper/pom.xml
new file mode 100644
index 00000000..37666f32
--- /dev/null
+++ b/java-jasper/pom.xml
@@ -0,0 +1,36 @@
+
+
+
+ 4.0.0
+
+ com.hmkcode
+ java-jasper
+ 1.0-SNAPSHOT
+
+ java-jasper
+
+ http://www.example.com
+
+
+ UTF-8
+ 1.7
+ 1.7
+
+
+
+
+ net.sf.jasperreports
+ jasperreports
+ 6.10.0
+
+
+
+
+ org.springframework
+ spring-core
+ 5.2.3.RELEASE
+
+
+
+
diff --git a/java-jasper/src/main/java/com/hmkcode/App.java b/java-jasper/src/main/java/com/hmkcode/App.java
new file mode 100644
index 00000000..72853237
--- /dev/null
+++ b/java-jasper/src/main/java/com/hmkcode/App.java
@@ -0,0 +1,61 @@
+package com.hmkcode;
+
+import net.sf.jasperreports.engine.*;
+import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
+import org.springframework.util.ResourceUtils;
+
+import java.io.*;
+import java.util.*;
+
+public class App
+{
+ // name and destination of output file e.g. "report.pdf"
+ private static String destFileName = "report.pdf";
+ public static void main( String[] args ) throws FileNotFoundException, JRException {
+
+ System.out.println( "generating jasper report..." );
+
+ // 1. compile template ".jrxml" file
+ JasperReport jasperReport = getJasperReport();
+
+ // 2. parameters "empty"
+ Map parameters = getParameters();
+
+ // 3. datasource "java object"
+ JRDataSource dataSource = getDataSource();
+
+ JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource);
+ JasperExportManager.exportReportToPdfFile(jasperPrint, destFileName);
+
+ }
+
+ private static JasperReport getJasperReport() throws FileNotFoundException, JRException {
+ File template = ResourceUtils.getFile("classpath:report.jrxml");
+ return JasperCompileManager.compileReport(template.getAbsolutePath());
+ }
+ private static Map getParameters(){
+ Map parameters = new HashMap<>();
+ parameters.put("createdBy", "hmkcode");
+ return parameters;
+ }
+
+ private static JRDataSource getDataSource(){
+
+ List countries = new LinkedList<>();
+
+ countries.add(new Country("IS", "Iceland", "https://i.pinimg.com/originals/72/b4/49/72b44927f220151547493e528a332173.png"));
+ countries.add(new Country("TR", "Turkey", "https://i.pinimg.com/originals/82/63/23/826323bba32e6e5a5996062c3a3c662f.png"));
+ countries.add(new Country("ZA", "South Africa", "https://i.pinimg.com/originals/f5/c7/8d/f5c78da001b46e26481c04fb93473454.png"));
+ countries.add(new Country("PL", "Poland", "https://i.pinimg.com/originals/7f/ae/21/7fae21c4854010b11127218ead743863.png"));
+ countries.add(new Country("CA", "Canada", "https://i.pinimg.com/originals/4d/d4/01/4dd401733ba25e6442fc8696e04e5846.png"));
+
+ countries.add(new Country("PA", "Panama", "https://i.pinimg.com/originals/84/dc/e4/84dce49e52ebfb5b3814393069807e0a.png"));
+ countries.add(new Country("HR", "Croatia", "https://i.pinimg.com/originals/f5/8c/94/f58c94a2a2b3221328fc1e2b7acfa656.png"));
+ countries.add(new Country("JP", "Japan", "https://i.pinimg.com/originals/a5/d6/88/a5d688289cd6850016f14fe93b17da01.png"));
+ countries.add(new Country("DE", "Germany", "https://i.pinimg.com/originals/af/c9/b2/afc9b2592a9f1cf591e8a52256ae1e9f.png"));
+ countries.add(new Country("BR", "Brazil", "https://i.pinimg.com/originals/e4/03/c4/e403c4447a3bd8940459ae4f50856bed.png"));
+
+
+ return new JRBeanCollectionDataSource(countries);
+ }
+}
diff --git a/java-jasper/src/main/java/com/hmkcode/Country.java b/java-jasper/src/main/java/com/hmkcode/Country.java
new file mode 100644
index 00000000..ecbc501d
--- /dev/null
+++ b/java-jasper/src/main/java/com/hmkcode/Country.java
@@ -0,0 +1,47 @@
+package com.hmkcode;
+
+public class Country {
+
+ private String code;
+ private String name;
+ private String url;
+
+ public Country(String code, String name, String url) {
+ this.code = code;
+ this.name = name;
+ this.url = url;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ @Override
+ public String toString() {
+ return "Country{" +
+ "code='" + code + '\'' +
+ ", name='" + name + '\'' +
+ ", url='" + url + '\'' +
+ '}';
+ }
+}
diff --git a/java-jasper/src/main/resources/report.jrxml b/java-jasper/src/main/resources/report.jrxml
new file mode 100644
index 00000000..113a787a
--- /dev/null
+++ b/java-jasper/src/main/resources/report.jrxml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java-lambda/README.md b/java-lambda/README.md
new file mode 100644
index 00000000..8213fe8e
--- /dev/null
+++ b/java-lambda/README.md
@@ -0,0 +1,151 @@
+Using Lambda to Implement Functional Interface Method
+====================================================
+
+- We have a *virtual* `Button` that when clicked will call an abstract method **onClick()** of a listener interface `OnClickListener`.
+- We need to implement the **onClick()** so that it prints the `Button` name.
+
+`OnClickListener.java`
+
+```java
+package com.hmkcode;
+
+public interface OnClickListener {
+ void onClick(Button button);
+}
+```
+
+`Button.java`
+
+```java
+package com.hmkcode;
+
+public class Button {
+
+ private OnClickListener onClickListener;
+ private String name;
+
+ // click the button
+ public void click(){
+ this.onClickListener.onClick(this);
+ }
+
+ // getters & setters
+}
+```
+
+- We have three ways to achieve that:
+ 1. **Implement** `OnClickListener` and override **onClick()** method.
+ 2. Use `OnClickListener` as an anonymous class.
+ 3. Use Lambda.
+
+- Our main class is `App.java`
+
+```java
+package com.hmkcode;
+
+public class App
+{
+ public static void main( String[] args ){
+ System.out.println( "Running App..." );
+ new App().run();
+ }
+
+ public void run(){
+
+ Button myButton = new Button();
+ myButton.setName("MyButton");
+
+ // 1. implements onClickListener
+
+ // 2. anonymous class
+
+ // 3. lambda
+
+
+ // click the button
+ myButton.click();
+ }
+}
+```
+
+### 1. **Implement** `OnClickListener` and override **onClick()** method
+
+```java
+public class App implements OnClickListener
+{
+ public static void main( String[] args ){...}
+
+ public void run(){
+
+ Button myButton = new Button();
+ myButton.setName("MyButton");
+
+ // 1. implements onClickListener
+ myButton.setOnClickListener(this);
+
+ // click the button
+ myButton.click();
+ }
+
+ @Override
+ public void onClick(Button button) {
+ System.out.println(button.getName() +" Clicked! - implements interface");
+
+ }
+}
+```
+
+### 2. Use `OnClickListener` as an anonymous class
+
+```java
+public class App
+{
+ public static void main( String[] args ){...}
+
+ public void run(){
+
+ Button myButton = new Button();
+ myButton.setName("MyButton");
+
+ // 2. anonymous class
+ myButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(Button button) {
+ System.out.println(button.getName() +" Clicked! - anonymous class");
+ }
+ });
+
+ // click the button
+ myButton.click();
+ }
+}
+```
+
+### 3. Use Lambda
+
+```java
+public class App
+{
+ public static void main( String[] args ){...}
+
+ public void run(){
+
+ Button myButton = new Button();
+ myButton.setName("MyButton");
+
+ // 3. lambda
+ OnClickListener lambda = button -> { System.out.println(button.getName()+" Clicked! - lambda"); } ;
+ myButton.setOnClickListener(lambda);
+
+ // click the button
+ myButton.click();
+ }
+}
+```
+
+*To run the code use*
+
+```
+java-lambda>mvn exec:java
+```
+
diff --git a/java-lambda/pom.xml b/java-lambda/pom.xml
new file mode 100644
index 00000000..8240ec70
--- /dev/null
+++ b/java-lambda/pom.xml
@@ -0,0 +1,34 @@
+
+
+
+ 4.0.0
+
+ com.hmkcode
+ java-lambda
+ 1.0-SNAPSHOT
+
+ java-lambda
+
+
+
+
+ maven-compiler-plugin
+ 3.8.0
+
+ 1.8
+ 1.8
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.6.0
+
+ com.hmkcode.App
+
+
+
+
+
+
diff --git a/java-lambda/src/main/java/com/hmkcode/App.java b/java-lambda/src/main/java/com/hmkcode/App.java
new file mode 100644
index 00000000..c1cdd001
--- /dev/null
+++ b/java-lambda/src/main/java/com/hmkcode/App.java
@@ -0,0 +1,42 @@
+package com.hmkcode;
+
+
+public class App implements OnClickListener
+{
+ public static void main( String[] args ){
+ System.out.println( "Running App..." );
+ new App().run();
+ }
+
+ public void run(){
+
+ Button myButton = new Button();
+ myButton.setName("MyButton");
+
+ // 1. implements onClickListener
+ //myButton.setOnClickListener(this);
+
+ // 2. anonymous class
+ /*myButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(Button button) {
+ System.out.println(button.getName() +" Clicked! - anonymous class");
+ }
+ }); */
+
+ // 3. lambda
+ OnClickListener lambda = button -> { System.out.println(button.getName()+" Clicked! - lambda"); } ;
+ myButton.setOnClickListener(lambda);
+
+
+ // click the button
+ myButton.click();
+ }
+
+
+ @Override
+ public void onClick(Button button) {
+ System.out.println(button.getName() +" Clicked! - implements interface");
+
+ }
+}
diff --git a/java-lambda/src/main/java/com/hmkcode/Button.java b/java-lambda/src/main/java/com/hmkcode/Button.java
new file mode 100644
index 00000000..adc65baf
--- /dev/null
+++ b/java-lambda/src/main/java/com/hmkcode/Button.java
@@ -0,0 +1,31 @@
+package com.hmkcode;
+
+public class Button {
+
+ private OnClickListener onClickListener;
+ private String name;
+
+ public void click(){
+ this.onClickListener.onClick(this);
+ }
+
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public OnClickListener getOnClickListener() {
+ return onClickListener;
+ }
+
+ public void setOnClickListener(OnClickListener onClickListener) {
+ this.onClickListener = onClickListener;
+ }
+
+
+
+}
diff --git a/java-lambda/src/main/java/com/hmkcode/OnClickListener.java b/java-lambda/src/main/java/com/hmkcode/OnClickListener.java
new file mode 100644
index 00000000..662f65c7
--- /dev/null
+++ b/java-lambda/src/main/java/com/hmkcode/OnClickListener.java
@@ -0,0 +1,7 @@
+package com.hmkcode;
+
+
+public interface OnClickListener {
+ void onClick(Button button);
+
+}
diff --git a/java-servlet-json/.classpath b/java-servlet-json/.classpath
index fd0d555d..3579da99 100644
--- a/java-servlet-json/.classpath
+++ b/java-servlet-json/.classpath
@@ -1,11 +1,10 @@
-
-
-
-
+
+
+
\ No newline at end of file
diff --git a/java-servlet-json/pom.xml b/java-servlet-json/pom.xml
index dd7dc447..f37f61f0 100644
--- a/java-servlet-json/pom.xml
+++ b/java-servlet-json/pom.xml
@@ -5,7 +5,7 @@
com.hmkcode
java-servlet-json
1.0-SNAPSHOT
- jar
+ war
java-servlet-json
http://maven.apache.org
@@ -15,36 +15,39 @@
-
+
javax.servlet
javax.servlet-api
3.1.0
+ provided
+
+
com.fasterxml.jackson.core
jackson-core
- 2.2.2
+ 2.9.6
com.fasterxml.jackson.core
jackson-databind
- 2.2.2
+ 2.9.6
com.fasterxml.jackson.core
jackson-annotations
- 2.2.2
+ 2.9.6
java-servlet-json
-
- org.eclipse.jetty
+
+ org.eclipse.jetty
jetty-maven-plugin
- 9.0.4.v20130625
-
+ 9.4.11.v20180605
+
diff --git a/java-servlet-json/src/main/java/com/hmkcode/JSONServlet.java b/java-servlet-json/src/main/java/com/hmkcode/JSONServlet.java
index afccf9b4..67415b87 100644
--- a/java-servlet-json/src/main/java/com/hmkcode/JSONServlet.java
+++ b/java-servlet-json/src/main/java/com/hmkcode/JSONServlet.java
@@ -6,6 +6,7 @@
import java.util.LinkedList;
import java.util.List;
import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -13,6 +14,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hmkcode.vo.Article;
+@WebServlet("/jsonservlet")
public class JSONServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@@ -32,21 +34,22 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
String json = "";
if(br != null){
json = br.readLine();
+ System.out.println(json);
}
// 2. initiate jackson mapper
- ObjectMapper mapper = new ObjectMapper();
+ ObjectMapper mapper = new ObjectMapper();
- // 3. Convert received JSON to Article
- Article article = mapper.readValue(json, Article.class);
+ // 3. Convert received JSON to Article
+ Article article = mapper.readValue(json, Article.class);
// 4. Set response type to JSON
response.setContentType("application/json");
- // 5. Add article to List
+ // 5. Add article to List
articles.add(article);
// 6. Send List as JSON to client
- mapper.writeValue(response.getOutputStream(), articles);
+ mapper.writeValue(response.getOutputStream(), articles);
}
}
diff --git a/java-simple-text-file-reader/src/main/java/com/hmkcode/TextFileReader.java b/java-simple-text-file-reader/src/main/java/com/hmkcode/TextFileReader.java
new file mode 100644
index 00000000..6959ad74
--- /dev/null
+++ b/java-simple-text-file-reader/src/main/java/com/hmkcode/TextFileReader.java
@@ -0,0 +1,63 @@
+package com.hmkcode;
+
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+
+public class TextFileReader {
+
+ private BufferedReader buffer;
+ private String currentLine = "";
+ public TextFileReader(){
+
+ }
+
+ public void open(String file){
+
+ try {
+ close();
+
+ buffer = new BufferedReader(new FileReader(file));
+
+ } catch (FileNotFoundException e1) {
+ e1.printStackTrace();
+
+ }
+
+ }
+
+ public void close(){
+
+ try {
+ if(buffer != null){
+ buffer.close();
+ buffer = null;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ public String readLine() throws Exception{
+ if(buffer != null){
+ currentLine = buffer.readLine();
+
+ if(currentLine == null)
+ close();
+
+ return currentLine;
+ }
+ else
+ throw new Exception("No file to read...");
+ }
+
+ public String getCurrent(){
+ return this.currentLine;
+ }
+
+ public boolean isReadable(){
+ return (buffer != null && this.currentLine != null);
+ }
+}
diff --git a/java-spi/java-spi-api/pom.xml b/java-spi/java-spi-api/pom.xml
new file mode 100644
index 00000000..e7c1e87d
--- /dev/null
+++ b/java-spi/java-spi-api/pom.xml
@@ -0,0 +1,27 @@
+
+
+
+ 4.0.0
+
+ com.hmkcode.api
+ java-spi-api
+ 1.0-SNAPSHOT
+
+ java-spi-api
+
+ http://www.example.com
+
+
+ UTF-8
+ 1.7
+ 1.7
+
+
+
+
+
+
+
+
+
diff --git a/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyService.java b/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyService.java
new file mode 100644
index 00000000..4928f453
--- /dev/null
+++ b/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyService.java
@@ -0,0 +1,6 @@
+package com.hmkcode.api;
+
+public interface MyService {
+
+ void doSomething();
+}
diff --git a/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyServiceProviderInterface.java b/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyServiceProviderInterface.java
new file mode 100644
index 00000000..8e166424
--- /dev/null
+++ b/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyServiceProviderInterface.java
@@ -0,0 +1,6 @@
+package com.hmkcode.api;
+
+public interface MyServiceProviderInterface {
+
+ MyService getService();
+}
diff --git a/java-spi/java-spi-app/lib/java-spi-api-1.0-SNAPSHOT.jar b/java-spi/java-spi-app/lib/java-spi-api-1.0-SNAPSHOT.jar
new file mode 100644
index 00000000..23a1c6be
Binary files /dev/null and b/java-spi/java-spi-app/lib/java-spi-api-1.0-SNAPSHOT.jar differ
diff --git a/java-spi/java-spi-app/lib/java-spi-impl1-1.0-SNAPSHOT.jar b/java-spi/java-spi-app/lib/java-spi-impl1-1.0-SNAPSHOT.jar
new file mode 100644
index 00000000..c8007874
Binary files /dev/null and b/java-spi/java-spi-app/lib/java-spi-impl1-1.0-SNAPSHOT.jar differ
diff --git a/java-spi/java-spi-app/pom.xml b/java-spi/java-spi-app/pom.xml
new file mode 100644
index 00000000..74906a4f
--- /dev/null
+++ b/java-spi/java-spi-app/pom.xml
@@ -0,0 +1,40 @@
+
+
+
+ 4.0.0
+
+ com.hmkcode.app
+ java-spi-app
+ 1.0-SNAPSHOT
+
+ java-spi-app
+
+ http://www.example.com
+
+
+ UTF-8
+ 1.7
+ 1.7
+
+
+
+
+
+ com.hmkcode.api
+ java-spi-api
+ 1.0-SNAPSHOT
+ system
+ ${project.basedir}/lib/java-spi-api-1.0-SNAPSHOT.jar
+
+
+ com.hmkcode.impl
+ java-spi-impl1
+ 1.0-SNAPSHOT
+ system
+ ${project.basedir}/lib/java-spi-impl1-1.0-SNAPSHOT.jar
+
+
+
+
+
diff --git a/java-spi/java-spi-app/src/main/java/com/hmkcode/app/App.java b/java-spi/java-spi-app/src/main/java/com/hmkcode/app/App.java
new file mode 100644
index 00000000..8e46d684
--- /dev/null
+++ b/java-spi/java-spi-app/src/main/java/com/hmkcode/app/App.java
@@ -0,0 +1,9 @@
+package com.hmkcode.app;
+
+public class App
+{
+ public static void main( String[] args )
+ {
+ MyServiceLoader.defaultProvider().getService().doSomething();
+ }
+}
diff --git a/java-spi/java-spi-app/src/main/java/com/hmkcode/app/MyServiceLoader.java b/java-spi/java-spi-app/src/main/java/com/hmkcode/app/MyServiceLoader.java
new file mode 100644
index 00000000..2efc5d74
--- /dev/null
+++ b/java-spi/java-spi-app/src/main/java/com/hmkcode/app/MyServiceLoader.java
@@ -0,0 +1,31 @@
+package com.hmkcode.app;
+
+import java.nio.file.ProviderNotFoundException;
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+import com.hmkcode.api.MyServiceProviderInterface;
+
+
+public class MyServiceLoader {
+
+ private static final String DEFAULT_PROVIDER = "com.hmkcode.impl.MyServiceProviderImpl1";
+
+ public static MyServiceProviderInterface defaultProvider() {
+ return provider(DEFAULT_PROVIDER);
+ }
+
+ public static MyServiceProviderInterface provider(String providerName) {
+ ServiceLoader loader = ServiceLoader.load(MyServiceProviderInterface.class);
+
+ Iterator it = loader.iterator();
+ while (it.hasNext()) {
+ MyServiceProviderInterface provider = it.next();
+ if (providerName.equals(provider.getClass().getName())) {
+ return provider;
+ }
+ }
+ throw new ProviderNotFoundException("provider " + providerName + " not found");
+ }
+
+}
diff --git a/java-spi/java-spi-impl1/lib/java-spi-api-1.0-SNAPSHOT.jar b/java-spi/java-spi-impl1/lib/java-spi-api-1.0-SNAPSHOT.jar
new file mode 100644
index 00000000..23a1c6be
Binary files /dev/null and b/java-spi/java-spi-impl1/lib/java-spi-api-1.0-SNAPSHOT.jar differ
diff --git a/java-spi/java-spi-impl1/pom.xml b/java-spi/java-spi-impl1/pom.xml
new file mode 100644
index 00000000..2e234c96
--- /dev/null
+++ b/java-spi/java-spi-impl1/pom.xml
@@ -0,0 +1,31 @@
+
+
+
+ 4.0.0
+
+ com.hmkcode.impl
+ java-spi-impl1
+ 1.0-SNAPSHOT
+
+ java-spi-impl1
+
+ http://www.example.com
+
+
+ UTF-8
+ 1.7
+ 1.7
+
+
+
+
+ com.hmkcode.api
+ java-spi-api
+ 1.0-SNAPSHOT
+ system
+ ${project.basedir}/lib/java-spi-api-1.0-SNAPSHOT.jar
+
+
+
+
diff --git a/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceImpl1.java b/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceImpl1.java
new file mode 100644
index 00000000..24afcfa4
--- /dev/null
+++ b/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceImpl1.java
@@ -0,0 +1,12 @@
+package com.hmkcode.impl;
+
+import com.hmkcode.api.MyService;
+
+public class MyServiceImpl1 implements MyService{
+
+ @Override
+ public void doSomething() {
+ System.out.println("MyServiceImpl1");
+
+ }
+}
diff --git a/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceProviderImpl1.java b/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceProviderImpl1.java
new file mode 100644
index 00000000..252b7a3e
--- /dev/null
+++ b/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceProviderImpl1.java
@@ -0,0 +1,13 @@
+package com.hmkcode.impl;
+
+import com.hmkcode.api.MyService;
+import com.hmkcode.api.MyServiceProviderInterface;
+
+public class MyServiceProviderImpl1 implements MyServiceProviderInterface {
+
+ @Override
+ public MyService getService() {
+ return new MyServiceImpl1();
+ }
+
+}
diff --git a/java-spi/java-spi-impl1/src/main/resources/META-INF/services/com.hmkcode.api.MyServiceProviderInterface b/java-spi/java-spi-impl1/src/main/resources/META-INF/services/com.hmkcode.api.MyServiceProviderInterface
new file mode 100644
index 00000000..008c8c11
--- /dev/null
+++ b/java-spi/java-spi-impl1/src/main/resources/META-INF/services/com.hmkcode.api.MyServiceProviderInterface
@@ -0,0 +1 @@
+com.hmkcode.impl.MyServiceProviderImpl1
\ No newline at end of file
diff --git a/java-stream/src/main/java/com/hmkcode/App.java b/java-stream/src/main/java/com/hmkcode/App.java
new file mode 100644
index 00000000..b97bbd63
--- /dev/null
+++ b/java-stream/src/main/java/com/hmkcode/App.java
@@ -0,0 +1,87 @@
+package com.hmkcode;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class App
+{
+ public static void main( String[] args )
+ {
+ String[] arr = new String[]{"a", "b", "c", "d"};
+ Stream stream = Arrays.stream(arr);
+
+ stream = Stream.of("a", "b", "c", "d");
+
+ List list = new LinkedList();
+ list.add("a");
+ list.add("b");
+ stream = list.stream();
+
+ // forEach()
+ stream = Stream.of("a", "b", "c", "d");
+ stream.forEach(e -> System.out.println(e));
+
+ // distinct() | count()
+ stream = Stream.of("a", "b", "c", "d");
+ System.out.println(stream.distinct().count());
+
+ // anyMatch()
+ stream = Stream.of("a", "b", "c", "d");
+ System.out.println(stream.anyMatch(e -> e.contains("a")));
+
+ // filter()
+ stream = Stream.of("a", "b", "c", "d");
+ stream.filter(e -> e.contains("b")).forEach(e -> System.out.println(e));
+
+ // map()
+ stream = Stream.of("a", "b", "c", "d");
+ stream.map(e -> e.toUpperCase()).forEach(e -> System.out.println(e));
+
+ // flatMap()
+ stream = getBigList().stream().flatMap(lst -> lst.stream());
+ stream.forEach(e -> System.out.println(e));
+
+ //[any|all|none]Match()
+ System.out.println(Stream.of("a", "b", "c", "d").allMatch( e -> (e.length() == 1)));
+ System.out.println(Stream.of("a", "b", "c", "d").noneMatch(e -> (e.length() == 2)));
+ System.out.println(Stream.of("a", "b", "c", "d").anyMatch( e -> e.equals("a") ));
+
+ //reduce()
+ stream = Stream.of("a", "b", "c", "d");
+ System.out.println(stream.reduce("", (x,y) -> apply(x,y)));
+
+ //collect(Collectors)
+ stream = Stream.of("a", "b", "c", "d");
+ System.out.println(stream.collect(Collectors.toList()));
+
+
+ }
+
+ private static String apply(String a, String b){
+ System.out.println(a+"->"+b);
+ return a+b;
+ }
+
+ private static List> getBigList(){
+
+ List> bigList = new LinkedList>();
+
+ List list1 = new LinkedList();
+ list1.add("a");
+ list1.add("b");
+
+ List list2 = new LinkedList();
+ list2.add("c");
+ list2.add("d");
+
+ bigList.add(list1);
+ bigList.add(list2);
+
+ return bigList;
+ }
+
+
+}
diff --git a/java-unzip/src/main/java/com/hmkcode/Unzip.java b/java-unzip/src/main/java/com/hmkcode/Unzip.java
new file mode 100644
index 00000000..11a9802f
--- /dev/null
+++ b/java-unzip/src/main/java/com/hmkcode/Unzip.java
@@ -0,0 +1,71 @@
+package com.hmkcode;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+public class Unzip {
+
+ public static void unzip(String zipFile,String outputPath){
+
+ if(outputPath == null)
+ outputPath = "";
+ else
+ outputPath+=File.separator;
+
+ // 1.0 Create output directory
+ File outputDirectory = new File(outputPath);
+
+ if(outputDirectory.exists())
+ outputDirectory.delete();
+
+ outputDirectory.mkdir();
+
+
+ // 2.0 Unzip (create folders & copy files)
+ try {
+
+ // 2.1 Get zip input stream
+ ZipInputStream zip = new ZipInputStream(new FileInputStream(zipFile));
+
+ ZipEntry entry = null;
+ int len;
+ byte[] buffer = new byte[1024];
+
+ // 2.2 Go over each entry "file/folder" in zip file
+ while((entry = zip.getNextEntry()) != null){
+
+ if(!entry.isDirectory()){
+ System.out.println("-"+entry.getName());
+
+ // create a new file
+ File file = new File(outputPath +entry.getName());
+
+ // create file parent directory if does not exist
+ if(!new File(file.getParent()).exists())
+ new File(file.getParent()).mkdirs();
+
+ // get new file output stream
+ FileOutputStream fos = new FileOutputStream(file);
+
+ // copy bytes
+ while ((len = zip.read(buffer)) > 0) {
+ fos.write(buffer, 0, len);
+ }
+
+ fos.close();
+ }
+
+ }
+
+ }catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}