id
stringlengths
36
36
text
stringlengths
1
1.25M
5ea21ab7-42e2-43dc-b8d2-3c9c0697d8e2
public Part(int start) { end = this.start = start; }
7bcb67d0-c4ec-4788-8b60-b30f153eb9bc
public boolean append(int ch) { CharType charType = CharType.getCharType(ch); if (charType == CharType.WHITESPACE) { return type == null; } if (isSamePart(charType)) { buffer.append((char) ch); if (type == null) { type = getPartType(charType); } end++; return true; } else { return false; } }
ce9bda3e-de7a-4b3c-9342-0c3615555e3b
public boolean isSamePart(CharType charType) { return type == null || getPartType(charType) == type; }
d5f3eb0d-5e49-4f6a-8065-42567848e385
public char[] getText() { return buffer.toString().toCharArray(); }
b145ca68-e775-4b1a-b93b-39a4ed59b930
public int getStart() { return start; }
6705e118-398b-4acd-8180-c598537975f0
public int getEnd() { return end; }
cc567f58-0bd1-4c11-a3a0-232f7ae8907d
public PartType getType() { return type; }
db02585f-18ce-44e9-89ea-5405a6a7ca83
public static PartType getPartType(CharType charType) { switch (charType) { case DOT: case LETTER: case NUMBER: case OTHER_ASCII: case WHITESPACE: return PartType.NON_CHINESE; default: return PartType.CHINESE; } }
7f069b1d-25cb-4492-a0f4-ab844011b340
FileManager(String name) { f1=new File(name); JFileChooser fileopen = new JFileChooser(); fileopen.setSelectedFile(f1); fileopen.showSaveDialog(null); f1=fileopen.getSelectedFile(); f=new File(f1.getAbsolutePath()); try { out=new FileOutputStream(f); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
60b927c7-c981-49a3-8567-cd86cd9d01a5
public void add(byte[] data) throws IOException { for(int i=0;i<data.length;i++) { this.out.write(data[i]); } }
96a795af-1129-4fd8-9bac-3aa1c0698718
public void close() throws IOException { out.close(); }
548bb86c-5d79-46bb-9a93-d394ddb656ac
public Output(PortConnect connect,MainForm form) { try { this.f=form; out = connect.serialPort.getOutputStream(); } catch (IOException e) {} try { connect.serialPort.notifyOnOutputEmpty(true); } catch (Exception e) { System.out.println("Error setting event notification"); System.out.println(e.toString()); } }
a60805e7-e2e6-44f9-80cd-c3fc4f0e5fd7
public void start(int i) { whatToDo=i; if (m_MyThread == null) { m_MyThread = new Thread(this); m_MyThread.start(); } }
cf1aa5e7-b038-4e27-b784-3fa43033d82b
@SuppressWarnings("deprecation") public void suspend() { m_MyThread.suspend(); }
be494d3a-ee43-4968-b734-5762a1d78573
@SuppressWarnings("deprecation") public void resume(Boolean bool) { if(bool==true) { this.status=true; m_MyThread.resume(); } else { this.status=false; m_MyThread.resume(); } }
df7a43ad-0519-4834-9898-47d28478e314
public void stop() { m_MyThread.interrupt(); m_MyThread = null; }
2e4c3adc-b4bd-4fab-b77d-5da91ba2d54e
@Override public void run() { if(whatToDo==1) { send(); } if(whatToDo==0) { connect(); } if(whatToDo==2) { disconnect(); } }
e0bf88f7-9b4c-4b45-b725-c1bb93d4f01b
public void setNameOfFile(String name) { this.nameOfFile=name; }
b5bce609-981f-4a5b-bb1b-ea92d295f1c2
public void setWayOfFile(String way) { this.wayOfFile=way; }
678ced91-fb63-4524-b9c4-df4210de0b5f
public void setSizeOfFile(long siz) { size=siz; }
a69af4b8-cb29-4b79-9148-d6e560ae34a5
public void setSizeOfBar(long siz) { f.progressBar.setMaximum((int) siz); }
b1b68cad-7539-453d-8f01-ba7dff941997
public void setValueOfFile(int n) { f.progressBar.setValue(n); }
58957873-9a82-4574-bbfe-b97051fd12cb
public void send() { try { InputStream inputStream= new FileInputStream(wayOfFile); byte buf[]=new byte[2045]; int len = inputStream.read(buf); Frame fr,fr1,fr2; do { fr1 = new Frame('H',nameOfFile,size); this.out.write(fr1.frToByte(fr1.frameSize()-3),0,fr1.frameSize()*2); suspend(); } while(status==false); int len1=0; do { fr = new Frame('I',buf); len1=len1+len; f.progressBar.setValue(len1); this.out.write(fr.frToByte(len),0,(len+3)*2); suspend(); if(this.status==true) { len=inputStream.read(buf); } } while(len>0); do { fr2 = new Frame('H'); this.out.write(fr2.specFrToByte()); suspend(); } while(status==false); stop(); } catch (IOException e) {} f.b1.setVisible(true); f.b4.setEnabled(true); f.b2.setEnabled(true); }
c067b713-ca36-4386-b5af-ba390db72942
public void connect() { Frame fr; fr = new Frame('L'); System.out.println(fr.type); try { this.out.write(fr.specFrToByte()); } catch (IOException e) {e.printStackTrace();} }
66731f89-f90f-4a5e-a5c6-988e3e291c45
public void disconnect() { Frame fr1; fr1 = new Frame('U'); System.out.println(fr1.type); try { this.out.write(fr1.specFrToByte()); } catch (IOException e) {e.printStackTrace();} }
69e559e5-d945-4eb4-99ae-337bed30bb2e
public Item() { }
1557e0db-9724-484b-8e56-b0c86f593a17
public Item(String itemID, String itemName, String itemURL, String itemPrice, String itemStock, String itemDescription) { super(); this.itemID = itemID; this.itemName = itemName; this.itemURL = itemURL; this.itemPrice = itemPrice; this.itemStock = itemStock; this.itemDescription = itemDescription; }
a6066a54-f69d-4fd9-9bf0-c366ead1626a
public String getItemID() { return itemID; }
3bb40814-0cdd-491e-8e2b-b48d3155412a
public void setItemID(String itemID) { this.itemID = itemID; }
d9cd4150-e384-4f4e-a0e6-1b6f6156bc2b
public String getItemName() { return itemName; }
ccf88cd2-f3fa-4164-a44b-889dcb435e95
public void setItemName(String itemName) { this.itemName = itemName; }
4dd7b0cf-64d8-49a1-90de-2baaf4b3f3d2
public String getItemURL() { return itemURL; }
eb3e8976-cb9f-4f07-b9ac-55619bdb341d
public void setItemURL(String itemURL) { this.itemURL = itemURL; }
ffe50fca-b413-4b00-8295-8c681e38a737
public String getItemPrice() { return itemPrice; }
2e7d96ce-dea6-4d1c-b102-bc7cd8447fff
public void setItemPrice(String itemPrice) { this.itemPrice = itemPrice; }
dc734fd6-8f99-456b-b4e7-da693c4db30f
public String getItemStock() { return itemStock; }
28967b23-2db3-4ec4-8429-7a81c5418b95
public void setItemStock(String itemStock) { this.itemStock = itemStock; }
368d60d6-7287-49b0-9e29-c46d3f407ed6
public String getItemDescription() { return itemDescription; }
5e1886bb-59e2-4b5e-b2b6-0e6df97e4960
public void setItemDescription(String itemDescription) { this.itemDescription = itemDescription; }
57d087b1-5347-4993-9a88-f148becccc27
public void ModifyItem() { System.out.println(this.itemID); Items itemlist = new Items(); itemlist.init(); for (Item item : itemlist.getItemList()) { if (item.itemID.equals(this.itemID)) { System.out.println("itemFound"); this.itemName = item.itemName; this.itemDescription = item.itemDescription; this.itemPrice = item.itemPrice; this.itemURL = item.itemURL; } } }
f9058c1c-43f2-44f8-973e-7f5eb5537cc9
public String SaveModifiedItem() { HttpHandler handler = new HttpHandler(); Element modifyitem = new Element("modifyItem"); modifyitem.addNamespaceDeclaration(WEBTEKNS); modifyitem.setNamespace(WEBTEKNS); System.out.println(this.itemURL); modifyitem.addContent(new Element("shopKey").setText( "C8E481850B11C7BDB7727390").setNamespace(WEBTEKNS)); modifyitem.addContent(new Element("itemID").setText(this.itemID) .setNamespace(WEBTEKNS)); modifyitem.addContent(new Element("itemName").setText(this.itemName) .setNamespace(WEBTEKNS)); modifyitem.addContent(new Element("itemPrice").setText(this.itemPrice) .setNamespace(WEBTEKNS)); modifyitem.addContent(new Element("itemURL").setText(this.itemURL) .setNamespace(WEBTEKNS)); // modifyitem.addContent(new // Element("itemDescription").setText(this.itemDescription).setNamespace(ApplicationConstants.WEBTEKNAMESPACE)); modifyitem.addContent(new Element("itemDescription").addContent( new Element("document").setText(this.itemDescription) .setNamespace(WEBTEKNS)).setNamespace(WEBTEKNS)); Document document = new Document(modifyitem); XMLOutputter outputter = new XMLOutputter(); try { outputter.output(document, System.out); handler.outputXMLonHTTP("POST", new URL("http://services.brics.dk/java4/cloud" + "/modifyItem"), document); return "Modified"; // if (handler.outputXMLonHTTP("POST", new URL("http://services.brics.dk/java4/cloud" + "/modifyItem"), document) != false) // { // // } } catch (Exception e) { e.printStackTrace(); return "NotModified"; } //return "NotModified"; }
8cda3fcf-c3bf-4771-a653-308256498b06
@PostConstruct public void init() { httpHandler = new HttpHandler(); try { URL requestUrl = new URL("http://services.brics.dk/java4/cloud" + "/listItems?shopID=" + "195"); Element responseRoot = httpHandler.HttpRequest("GET", requestUrl) .getRootElement(); if (responseRoot == null) { throw new Exception("Response from itemList request was null"); } else { itemList = new ArrayList<Item>(); for (Element itemChild : responseRoot.getChildren()) { Element description = itemChild.getChild("itemDescription", WEBTEKNS); String descriptionStr = ""; for (Element descriptionChild : description.getChildren()) { descriptionChild.setNamespace(null); switch (descriptionChild.getName()) { case "document": descriptionChild.setName("div"); break; case "bold": descriptionChild.setName("b"); break; case "italics": descriptionChild.setName("i"); break; case "list": descriptionChild.setName("ul"); break; case "item": descriptionChild.setName("li"); break; default: break; } descriptionStr += descriptionChild.getValue(); } itemList.add(new Item(itemChild.getChildText("itemID", WEBTEKNS), itemChild.getChildText("itemName", WEBTEKNS), itemChild.getChildText("itemURL", WEBTEKNS), itemChild.getChildText("itemPrice", WEBTEKNS), itemChild.getChildText("itemStock", WEBTEKNS), descriptionStr)); } } } catch (Exception e) { System.out.println("An error occurred: " + e.getMessage()); } }
eb2a0bd1-a095-4353-8686-87f8ed83ff3c
public ArrayList<Item> getItemList() { return itemList; }
32655089-a8c1-4bc2-8424-d183b0034254
public void setItemList(ArrayList<Item> itemList) { this.itemList = itemList; }
feab1145-f596-438e-9ce8-96252d722d00
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String username = request.getParameter("username"); String password = request.getParameter("password"); if(username.equals(user1) && password.equals(pass1)){ HttpSession session = request.getSession(); session.setMaxInactiveInterval(expireTime); System.out.println("login succesfull"); Cookie userCookie = new Cookie("user", username); userCookie.setMaxAge(expireTime); // response.addCookie(userCookie); response.sendRedirect("Admin/adminProductList.jsf"); // response.sendRedirect("http://www.google.com"); } else{ System.out.println("Wrong Login"); } }
a1900374-a60f-4bc3-8f37-ae240dbc9055
public String getName () { return name; }
9c5d33b3-ec98-4623-b618-9fcfb49eda03
public void setName (final String name) { this.name = name; }
2d430265-2a7e-4eee-9ac4-0c42187446aa
public String getPassword () { return password; }
f2992393-a2f3-4154-af36-68a33eaf745b
public void setPassword (final String password) { this.password = password; }
b70f22e9-37df-4560-b725-eef66522b271
public Document outputXMLonHTTP(String httpRequestType, URL url, Document docToOutput) throws ProtocolException, IOException, JDOMException { XMLOutputter outputter = new XMLOutputter(); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod(httpRequestType); con.setDoOutput(true); con.setDoInput(true); con.connect(); outputter.output(docToOutput, con.getOutputStream()); Document responseDocument = null; try { SAXBuilder builder = new SAXBuilder(); responseDocument = builder.build((InputStream) con.getContent()); } catch (Exception e) { } if (con.getResponseCode() != 200) { System.out.print("An network error occurred: " + con.getResponseCode() + " - " + con.getResponseMessage()); } con.disconnect(); return responseDocument; }
03cccad0-3cc3-4ada-af1f-c9d7f22a7003
public Document HttpRequest(String httpRequestType, URL url) throws IOException { HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod(httpRequestType); con.setDoOutput(true); con.setDoInput(true); con.connect(); Document responseDocument = null; try { SAXBuilder builder = new SAXBuilder(); responseDocument = builder.build(con.getInputStream()); } catch (Exception e) { // TODO: handle exception } if (con.getResponseCode() != 200) { System.out.print("An network error occurred: " + con.getResponseCode() + " - " + con.getResponseMessage()); } con.disconnect(); return responseDocument; }
e81bd85f-8788-49aa-923c-74c8dd43fd3e
public void init(FilterConfig c) throws ServletException { context = c.getServletContext(); }
0cd157c3-9f71-4e87-8b01-af7d44a24209
public void destroy() { }
b6f7433e-d284-4798-849f-afa9a3c574d3
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; String uri = request.getRequestURI(); HttpSession session = request.getSession(false); if (uri.endsWith("login.jsf") || uri.endsWith("LoginServlet") || session != null) { chain.doFilter(request, response); } else { System.out.println("Redirected to login"); response.sendRedirect("login.jsf"); } }
0b78ec16-c042-4584-ab31-95e50c978b43
@TestAspectAnnotation public void test() { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } }
eab3715a-ffaa-4988-97e2-463b7f777a04
@Around("@annotation(com.ms.aop.aspect.TestAspectAnnotation)") public Object doBasicProfiling(final ProceedingJoinPoint pjp) throws Throwable { final StopWatch stopWatch = new StopWatch(); stopWatch.start(); try { Object result = pjp.proceed(); return result; } finally { stopWatch.stop(); LOG.info("{} took {} ", new Object[]{pjp.toShortString(), stopWatch}); } }
0442d0ce-01d4-4add-8076-a1c8a53ddd94
public static void main(String[] args_) { ApplicationContext context = new ClassPathXmlApplicationContext( "/com/ms/aop/applicationContext.xml"); TestBean tb = context.getBean("testBean", TestBean.class); tb.test(); System.out.println("Main End"); }
1fb4f4f4-62f0-4040-ad16-4d89e7a966c4
public static void main(String[] args) throws IOException { //http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dbaby-products /*Document document = Jsoup.connect("http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dbaby-products").get(); Elements elements = document.select("ul[data-typeid=n]"); if(elements != null) { Element ul = elements.first(); if(ul != null) { System.out.println(ul.select("div").size()); Elements liElements = ul.select("li"); if(liElements != null) { boolean child = false; for(Element li : liElements) { if(li.select("strong").size() > 0) { child = true; } else { if(child) { } } } } } System.out.println(elements.size()); }*/ //List<CategoryNode> categoryNodes = Utils.buildCategoryByUrl("http://www.amazon.com/s/ref=sr_ex_n_1?rh=n%3A165796011%2Cn%3A%21165797011%2Cn%3A405369011&bbn=405369011&ie=UTF8&qid=1407486836"); List<CategoryNode> categoryNodes = Utils.buildCategoryByUrl("http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dbaby-products"); for(CategoryNode node : categoryNodes) { System.out.println(node); } }
727d9502-e8e7-41af-9f1d-4cb81152c24c
public CategoryNode() { }
a41ed3c8-20a0-4ed2-8aeb-704e8a8e5f39
public CategoryNode(CategoryNode pre, CategoryNode next, String categoryName) { this.pre = pre; this.next = next; this.categoryName = categoryName; }
698f6bb4-03b4-4955-bb14-0d0d9ea1be8a
public CategoryNode getPre() { return pre; }
843dfd4e-464d-4879-ae7a-56adc70198ab
public void setPre(CategoryNode pre) { this.pre = pre; }
fa6735bb-954a-4e2c-8cfd-770c7c91a5df
public CategoryNode getNext() { return next; }
82abc650-0590-4c4e-9696-3c866c4a583e
public void setNext(CategoryNode next) { this.next = next; }
e22d945d-0b14-4057-b13c-54fe8982e670
public String getCategoryName() { return categoryName; }
a4f83592-78a4-4de6-9dd0-ec1d32d542f9
public void setCategoryName(String categoryName) { this.categoryName = categoryName; }
64bda926-c5ac-4d42-8023-fc555e0c348b
@Override public String toString() { StringBuilder sb = new StringBuilder(); CategoryNode root = this; while(root.pre != null) { root = root.pre; } while(root != null) { sb.append("-> " + root.getCategoryName()); root = root.next; } return sb.toString(); }
bb4d371f-3180-42ef-9091-ea71af3e86ac
public static CategoryNode buildCategoryChain(Elements liElements) { int size = liElements.size(); int i = 0; CategoryNode root = null; CategoryNode current = null; CategoryNode pre = null; for(i = 0; i < size; i++) { Element li = liElements.get(i); current = new CategoryNode(); if(i < size - 1) { Element spanLast = li.select("span").last(); current.setCategoryName(spanLast.text()); } else { Element strongElement = li.select("strong").first(); current.setCategoryName(strongElement.text()); } if(i == 0) { root = current; pre = current; } else { pre.setNext(current); current.setPre(pre); pre = current; } } return root; }
7499d1c5-356e-411d-9626-2cd188034654
public static List<CategoryNode> buildCategoryByUrl(String url) throws IOException { System.out.println("Trying to get url: " + url); Document document; try { document = Jsoup.connect(url).get(); } catch(IOException e) { throw new IOException("Error when get " + url, e); } Elements elements = document.select("ul[data-typeid=n]"); List<CategoryNode> nodes = new ArrayList<CategoryNode>(); if(!elements.isEmpty()) { Element ul = elements.first(); Elements liElements = ul.select("li"); if(!liElements.isEmpty()) { Iterator<Element> iterator = liElements.iterator(); while(iterator.hasNext()) { Element li = iterator.next(); if(li.select("strong").size() > 0) { if(!iterator.hasNext()) { nodes.add(buildCategoryChain(liElements)); break; } while(iterator.hasNext()) { Element childLi = iterator.next(); String link = childLi.select("a").first().attr("href"); if(!link.startsWith("http")) { link = AMAZON_HOME + link; } nodes.addAll(buildCategoryByUrl(link)); } } } } } return nodes; }
f4114533-3a13-4adf-9d76-397d969a894b
public String establishConnection() { String connection = "MySql Connection"; return connection; }
d533f7c3-17b0-4c27-9956-dbe4da18da1e
public String terminateConnection() { String terminateConnection = "MySql Connection Terminated"; return terminateConnection; }
c2d9aef8-11fb-49fe-b383-3784dfe1fe06
public String getConnectionStatus() { String connectionStatus = "MySql connection status"; return connectionStatus; }
fef4d9fd-f6ea-46e4-8203-8d29b99c3fc7
public String establishConnection() { String connection = "Oracle Connection"; return connection; }
65635a74-19af-47ea-99ed-7942c6d2057f
public String terminateConnection() { String terminateConnection = "Oracle Connection Terminated"; return terminateConnection; }
fc074737-0ed1-4ae1-b04a-1014661771d8
public String getConnectionStatus() { String connectionStatus = "Oracle connection status"; return connectionStatus; }
f5e6f72b-5c1d-4533-9b05-987c1d1f54f5
@Inject public Client(Datasource datasource) { this.datasource = datasource; }
28379bea-4323-4edd-836d-f4add1211465
public static void callDataSourceMethods() { System.out.println(datasource.establishConnection()); System.out.println(datasource.getConnectionStatus()); System.out.println(datasource.terminateConnection()); }
88527a82-be05-4958-8f60-4ddd3fcb6ad2
protected void configure() { /** * bind the service to each of the implementation classes * * i.e. * * bind DataSource to MongoDBDataSource implementation */ bind(Datasource.class).to(MongoDdDataSource.class); }
5e68bfac-198f-41b0-b943-e90e985f8246
public String establishConnection();
3d72866e-4d7d-441e-80b4-12483bdde5ff
public String terminateConnection();
fc71def3-f26f-4fd7-b95a-0ee842265fe5
public String getConnectionStatus();
2469ff41-7d43-4010-8085-4281c16461f4
public String establishConnection() { String connection = "MondoDB Connection"; return connection; }
ef448057-0d9c-4c58-bfd2-c33aad18a082
public String terminateConnection() { String terminateConnection = "MondoDB Connection Terminated"; return terminateConnection; }
fd8893d3-020d-4b6c-a111-99f73f0f5814
public String getConnectionStatus() { String connectionStatus = "MondoDB connection status"; return connectionStatus; }
6c987955-5ae7-4eba-a923-e6d4859e93a7
public static void main(String[]args) { Injector injector = Guice.createInjector(new ApplicationInjector()); Client client = injector.getInstance(Client.class); client.callDataSourceMethods(); }
dba5f914-0d9e-4c64-804a-fd38103b6fb6
@GET @Produces("text/plain") public String getIt() { return "Hi there!"; }
71c6bc49-593c-44c0-bc17-f05ccce90304
public int getMenuId() { return menuId; }
3368ff8a-36c1-4bc8-97d5-dbc203233b20
public void setMenuId(int menuId) { this.menuId = menuId; }
e2bf4344-ff65-4a3a-b01a-4f2c4356805f
public String getMenuName() { return menuName; }
a29896ed-ff3c-4636-b77b-794f5323ae85
public void setMenuName(String menuName) { this.menuName = menuName; }
3e9f93e7-5b72-4b41-acf4-17214d415c6a
public String getCategory() { return category; }
0ea19dc8-294f-484e-b243-3ec0c2fe1a2b
public void setCategory(String category) { this.category = category; }
6ca73cd4-a59e-49dd-950d-2f35a6f1b88a
public String getImageId() { return imageId; }
d0e3adbb-b72b-4505-bd97-3e896e030bd9
public void setImageId(String imageId) { this.imageId = imageId; }
08e43fc3-e4cf-49f7-a039-622e56cdfb59
@Override public MenuItem get(Integer menuId) { return (MenuItem) sessionFactory.getCurrentSession().get(MenuItem.class, menuId); }
7e7147cf-590f-423c-bd7b-f2b4b6604185
@SuppressWarnings("unchecked") @Override public List<MenuItem> getMenuItemList() { return (List<MenuItem>) sessionFactory.getCurrentSession().createCriteria(MenuItem.class).list(); }
72910784-797f-41c6-a4ee-ee593d83b77e
@Override public void update(MenuItem menuItem) { System.out.println("Calling saveOrUpdate"); sessionFactory.getCurrentSession().saveOrUpdate(menuItem); }
42b3fd7b-ffea-49df-bc8a-9b7741fd79bc
@Override public void delete(MenuItem menuItem) { //sessionFactory.getCurrentSession().createQuery("DELETE FROM menuitems WHERE empid = "+menuItem.getMenuId()).executeUpdate(); sessionFactory.getCurrentSession().delete(menuItem); }
cfbd6a12-2fda-46cb-9480-5f245ccd376b
MenuItem get(Integer menuId);
93effc98-9a0b-4216-8576-f60612eb69a1
List <MenuItem> getMenuItemList();