id
stringlengths
36
36
text
stringlengths
1
1.25M
6670fc56-b817-4a7c-99c5-04c9f239b602
public boolean hasPrev(Cursor c) throws Exception;
87d30d31-ff2c-4c1f-8f3e-bbb1829e03e7
public void swap(Cursor c1, Cursor c2) throws Exception;
d2bec8d4-c5f4-4133-9f4d-a9f8a16e066a
public boolean search(Cursor c, Predicate<T> pred) throws Exception;
8f42f2eb-8eeb-4440-8b60-f9e80935b5fd
public ListOf<T> subList(Cursor start, Cursor end) throws Exception;
2895d3ee-b339-470f-8bc0-c463556a40b5
public boolean precedes(Cursor c1, Cursor c2) throws Exception;
e544316b-bb7a-4b02-878b-7137b2197d21
public static <T> void printList(PrintWriter pen, DoublyLinkedList<T> list) throws Exception { pen.print("[" + list.front.val + " "); // don't know why it doesn't // print front for (T val : list) { // on its own. Our error? Sam's? pen.print(val); pen.print(" "); } // for pen.println("]"); pen.flush(); } // printList(PrintWriter, LinkedList<Object>)
e8e9174a-990a-4c8d-878c-d7e9a0f4c778
public static void main(String[] args) throws Exception { // Set up output PrintWriter pen = new PrintWriter(System.out, true); // Create some lists DoublyLinkedList<String> strings = new DoublyLinkedList<String>(); DoublyLinkedList<Integer> numbers = new DoublyLinkedList<Integer>(); // Prepend a few elements numbers.prepend(42); numbers.prepend(77); numbers.prepend(11); printList(pen, numbers); // Append a few elements numbers.append(1); numbers.append(2); numbers.append(3); printList(pen, numbers); // Delete the first element pen.println("Deleting first"); Cursor c = numbers.front(); numbers.delete(c); pen.println(numbers.get(c)); printList(pen, numbers); // Delete the third element pen.println("Deleting third"); Cursor d = numbers.front(); numbers.advance(d); numbers.advance(d); numbers.delete(d); printList(pen, numbers); // Insert and get some elements Cursor f = strings.front(); // Insert into null list strings.insert("world", f); printList(pen, strings); pen.println(strings.get(f)); // Insert at front of list strings.insert("hello", f); // Expected output: // "[hello world ]/hello/world/hello/hello/[hello world ]" printList(pen, strings); pen.println(strings.get(f)); strings.advance(f); pen.println(strings.get(f)); if (strings.hasPrev(f)) { pen.println(strings.getPrev(f)); } else { pen.println("hasPrev false negative"); } strings.retreat(f); if (strings.hasPrev(f)) { pen.println("hasPrev false positive"); } pen.println(strings.get(f)); pen.flush(); printList(pen, strings); // Insert mid-list strings.advance(f); strings.insert("foo", f); printList(pen, strings); pen.println(strings.get(f)); strings.advance(f); strings.insert("bar", f); printList(pen, strings); pen.println(strings.get(f)); // Testing Swap /* * pen.println(); pen.println("Testing swap(c1, c2):"); * pen.print(" Current list: "); printList(pen, strings); Cursor s1 = * strings.front(); Cursor s2 = strings.front(); * * // Swap first two: * * * Thread.sleep(1000); System.out.println("ONE"); Thread.sleep(1000); * * strings.advance(s2); strings.swap(s1, s2); * pen.print(" [foo hello bar world ] = "); printList(pen, strings); * pen.println(" s1 = " + strings.get(s1) + "; s2 = " + * strings.get(s2)); * * Thread.sleep(1000); System.out.println("TWO"); Thread.sleep(1000); * * strings.advance(s1); * * strings.advance(s2); strings.advance(s2); pen.println(" s1 = " + * strings.get(s1) + "; s2 = " + strings.get(s2)); strings.swap(s1, s2); * pen.print(" [foo bar hello world ] = "); printList(pen, strings); * pen.print(" s1 = " + strings.get(s1) + "; s2 = " + * strings.get(s2)); */ // Testing Search pen.println(); pen.println("Testing search(c, pred):"); pen.print(" Current list: "); printList(pen, numbers); Cursor g = numbers.front(); Even even = new Even(); Seven seven = new Seven(); System.out.println(" cursor @ " + numbers.get(g)); System.out.println(" " + numbers.search(g, even)); System.out.println(" cursor @ " + numbers.get(g)); pen.print(" Current list: "); printList(pen, numbers); numbers.advance(g); System.out.println(" cursor @ " + numbers.get(g)); System.out.println(" " + numbers.search(g, even)); System.out.println(" cursor @ " + numbers.get(g)); pen.print(" Current list: "); printList(pen, numbers); System.out.println(" cursor @ " + numbers.get(g)); System.out.println(" " + numbers.search(g, seven)); System.out.println(" cursor @ " + numbers.get(g)); System.out.println(" cursor @ " + numbers.get(g)); System.out.println(" " + numbers.search(g, even)); System.out.println(" cursor @ " + numbers.get(g)); //Testing select /* Odd odd = new Odd(); pen.println("Testing select(pred):"); pen.print(" Current list: "); System.out.print("even numbers: "); DoublyLinkedList<T> sevens = (DoublyLinkedList) numbers.select(even); PrintList(pen, sevens); System.out.println("odd numbers: " + numbers.select(odd)); System.out.println("sevens: " + numbers.select(seven)); // And we're done pen.close(); */ } // main(String[])
7d3ad5f9-1da8-46b5-acff-30443dee8f52
@Override public boolean test(Integer val) { return (val.intValue() % 2) == 0; } // test
01235d09-95a2-4cd8-b531-dbc8734f396f
public Applicant() { }
450facc5-3800-4814-9bf9-41a360c566a4
public Applicant(Short id) { this.id = id; }
124c1027-e0d6-4120-a9e1-4caf34e362db
public Short getId() { return id; }
8aa06362-a3d3-479c-a62b-2a7e1a3f9133
public void setId(Short id) { this.id = id; }
9d9724d9-c68d-4ba9-ab8e-e3ac2dfd5820
public String getFirstName() { return firstName; }
27406500-55a9-44ec-b399-661c5a5c119c
public void setFirstName(String firstName) { this.firstName = firstName; }
747f3426-4b9f-48df-9559-90ba53b13330
public String getMiddleName() { return middleName; }
fe1b8b09-b36e-42bd-9eb9-e23cb83c5b75
public void setMiddleName(String middleName) { this.middleName = middleName; }
2b556ea8-b196-490a-85ba-fde57ac4b0c5
public String getLastName() { return lastName; }
12eca73b-d71b-4933-9e08-315a5f9a8c53
public void setLastName(String lastName) { this.lastName = lastName; }
fa736873-14c4-4855-b04e-389c278bf4d1
public String getBirthDate() { return birthDate; }
57f5d4c1-3b77-40b4-a006-a1f6ceecd63d
public void setBirthDate(String birthDate) { this.birthDate = birthDate; }
f0ce57df-5d0b-4189-88d7-dcaf9429adb0
public String getHomephone() { return homephone; }
0f5cd192-878f-47a0-8e36-ec8707ae4be2
public void setHomephone(String homephone) { this.homephone = homephone; }
bfcd7742-0ff0-47f7-947e-35228cabff16
public String getMobilephone() { return mobilephone; }
b3d4f030-51db-41c5-b161-40d94a1dd088
public void setMobilephone(String mobilephone) { this.mobilephone = mobilephone; }
9ba8bc64-8cd6-416e-8c0e-011aa4fe2c7e
public String getWorkphone() { return workphone; }
516e9c19-ab93-4319-ac9c-7cd94e5d9097
public void setWorkphone(String workphone) { this.workphone = workphone; }
b7b8ba40-eafe-42a5-8e1c-92adb103de9d
public String getEmail() { return email; }
04b86cfe-d776-44e0-8ad3-b7ec8abb69bc
public void setEmail(String email) { this.email = email; }
f7a1b14c-22fd-4dbc-95f2-a95edf66463e
@Override public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; }
861b557b-bba9-4cd4-b1e0-7db437826e29
@Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Applicant)) { return false; } Applicant other = (Applicant) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; }
a0d3be4d-d69b-4238-a40c-1cd155979682
@Override public String toString() { return "edu.MUM.ComproAppForm.Model.Applicant[ id=" + id + " ]"; }
52e7737b-0434-45ed-8d94-ddd455664733
public ApplicantJpaController(UserTransaction utx, EntityManagerFactory emf) { this.utx = utx; this.emf = emf; }
cf390eee-5d43-4e02-9c5b-146886de99f8
public EntityManager getEntityManager() { return emf.createEntityManager(); }
58477910-5f34-417f-9cf5-7050d6d9d45d
public void create(Applicant applicant) throws RollbackFailureException, Exception { EntityManager em = null; try { utx.begin(); em = getEntityManager(); em.persist(applicant); utx.commit(); } catch (Exception ex) { try { utx.rollback(); } catch (Exception re) { throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); } throw ex; } finally { if (em != null) { em.close(); } } }
571648d9-e925-4ba8-a56b-57e6055e68af
public void edit(Applicant applicant) throws NonexistentEntityException, RollbackFailureException, Exception { EntityManager em = null; try { utx.begin(); em = getEntityManager(); applicant = em.merge(applicant); utx.commit(); } catch (Exception ex) { try { utx.rollback(); } catch (Exception re) { throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); } String msg = ex.getLocalizedMessage(); if (msg == null || msg.length() == 0) { Short id = applicant.getId(); if (findApplicant(id) == null) { throw new NonexistentEntityException("The applicant with id " + id + " no longer exists."); } } throw ex; } finally { if (em != null) { em.close(); } } }
4780ccdc-ff56-470d-a75c-40a986be1706
public void destroy(Short id) throws NonexistentEntityException, RollbackFailureException, Exception { EntityManager em = null; try { utx.begin(); em = getEntityManager(); Applicant applicant; try { applicant = em.getReference(Applicant.class, id); applicant.getId(); } catch (EntityNotFoundException enfe) { throw new NonexistentEntityException("The applicant with id " + id + " no longer exists.", enfe); } em.remove(applicant); utx.commit(); } catch (Exception ex) { try { utx.rollback(); } catch (Exception re) { throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); } throw ex; } finally { if (em != null) { em.close(); } } }
28432c01-37f4-4022-9ea9-82826d08c822
public List<Applicant> findApplicantEntities() { return findApplicantEntities(true, -1, -1); }
5580aa34-78d4-472b-96a4-24057307cdcb
public List<Applicant> findApplicantEntities(int maxResults, int firstResult) { return findApplicantEntities(false, maxResults, firstResult); }
b60d14db-7b6e-49e8-bca1-de058b62a6cb
private List<Applicant> findApplicantEntities(boolean all, int maxResults, int firstResult) { EntityManager em = getEntityManager(); try { CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); cq.select(cq.from(Applicant.class)); Query q = em.createQuery(cq); if (!all) { q.setMaxResults(maxResults); q.setFirstResult(firstResult); } return q.getResultList(); } finally { em.close(); } }
e1f9b371-c62c-4c2b-b6b2-eef5f268c73b
public Applicant findApplicant(Short id) { EntityManager em = getEntityManager(); try { return em.find(Applicant.class, id); } finally { em.close(); } }
b4afffc0-4878-472a-808c-263863149658
public int getApplicantCount() { EntityManager em = getEntityManager(); try { CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); Root<Applicant> rt = cq.from(Applicant.class); cq.select(em.getCriteriaBuilder().count(rt)); Query q = em.createQuery(cq); return ((Long) q.getSingleResult()).intValue(); } finally { em.close(); } }
9ad899c1-0090-449b-8314-6d9191fc4532
public AbstractFacade(Class<T> entityClass) { this.entityClass = entityClass; }
e1defd23-40af-45c1-9940-9e3eedf634f2
protected abstract EntityManager getEntityManager();
8f6d8e86-7861-49e6-a2ca-1471d3e9ed48
public void create(T entity) { getEntityManager().persist(entity); }
01d2f194-8422-4ddc-932d-a5bfa48e7aa5
public void edit(T entity) { getEntityManager().merge(entity); }
dff0fd5f-f69a-4733-abb7-3d375c6868e9
public void remove(T entity) { getEntityManager().remove(getEntityManager().merge(entity)); }
3956d839-79f6-4a5b-85dc-a838056a0537
public T find(Object id) { return getEntityManager().find(entityClass, id); }
f4f44e66-8e45-4f24-beaa-f4e4ab8499f8
public List<T> findAll() { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); return getEntityManager().createQuery(cq).getResultList(); }
319cd7fc-bab4-4cc6-90a3-253a7e0d1f1c
public List<T> findRange(int[] range) { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); javax.persistence.Query q = getEntityManager().createQuery(cq); q.setMaxResults(range[1] - range[0] + 1); q.setFirstResult(range[0]); return q.getResultList(); }
0a9aae12-8f4b-463d-86b0-203c35c2c3a1
public int count() { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); javax.persistence.criteria.Root<T> rt = cq.from(entityClass); cq.select(getEntityManager().getCriteriaBuilder().count(rt)); javax.persistence.Query q = getEntityManager().createQuery(cq); return ((Long) q.getSingleResult()).intValue(); }
d55fe14f-de4c-42b7-b04b-2430cdcba5bd
public PaginationHelper(int pageSize) { this.pageSize = pageSize; }
1f4c5f92-f943-4faf-a7a8-aa5109aad848
public abstract int getItemsCount();
d096e6b5-5b8f-4d3d-8302-147903243c82
public abstract DataModel createPageDataModel();
9f6620e6-3aef-45d4-9092-e84dcce509f7
public int getPageFirstItem() { return page * pageSize; }
02b573ee-feb8-4a23-b7e7-b69d573c72b2
public int getPageLastItem() { int i = getPageFirstItem() + pageSize - 1; int count = getItemsCount() - 1; if (i > count) { i = count; } if (i < 0) { i = 0; } return i; }
8a95effc-9620-464c-8e92-88cd602934ac
public boolean isHasNextPage() { return (page + 1) * pageSize + 1 <= getItemsCount(); }
9bca6dbb-57d9-4450-8b79-e628c1c7b476
public void nextPage() { if (isHasNextPage()) { page++; } }
9449cf08-c8a3-4970-bc41-2613fc96b3d3
public boolean isHasPreviousPage() { return page > 0; }
db74cc32-0437-4ee1-bf33-493e27d3a394
public void previousPage() { if (isHasPreviousPage()) { page--; } }
c2848a88-77de-4cb9-9601-ca0543fe8db6
public int getPageSize() { return pageSize; }
442b2dce-39cb-4cae-8d42-d4b1bd8dc479
public static SelectItem[] getSelectItems(List<?> entities, boolean selectOne) { int size = selectOne ? entities.size() + 1 : entities.size(); SelectItem[] items = new SelectItem[size]; int i = 0; if (selectOne) { items[0] = new SelectItem("", "---"); i++; } for (Object x : entities) { items[i++] = new SelectItem(x, x.toString()); } return items; }
ecde48e8-cfcd-4f65-a4d8-58e6a25abf9b
public static void addErrorMessage(Exception ex, String defaultMsg) { String msg = ex.getLocalizedMessage(); if (msg != null && msg.length() > 0) { addErrorMessage(msg); } else { addErrorMessage(defaultMsg); } }
c46d2164-bfa7-4ae4-bad1-fbb9e320b700
public static void addErrorMessages(List<String> messages) { for (String message : messages) { addErrorMessage(message); } }
9033a587-0f24-4bdb-92d7-2c22d25e701a
public static void addErrorMessage(String msg) { FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg); FacesContext.getCurrentInstance().addMessage(null, facesMsg); }
fafb7ef1-8fbf-473f-8876-3304d2dfc274
public static void addSuccessMessage(String msg) { FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg); FacesContext.getCurrentInstance().addMessage("successInfo", facesMsg); }
fb085de6-8cab-4bd1-bb60-53339ff35a44
public static String getRequestParameter(String key) { return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(key); }
5d477b05-f1ef-4fcf-9223-398a4d1f96bf
public static Object getObjectFromRequestParameter(String requestParameterName, Converter converter, UIComponent component) { String theId = JsfUtil.getRequestParameter(requestParameterName); return converter.getAsObject(FacesContext.getCurrentInstance(), component, theId); }
f5ae2d86-0b97-41c3-91a4-9aa2a75db4f3
public IllegalOrphanException(List<String> messages) { super((messages != null && messages.size() > 0 ? messages.get(0) : null)); if (messages == null) { this.messages = new ArrayList<String>(); } else { this.messages = messages; } }
0d496328-ec94-4bb1-bcbc-f7909b39cd38
public List<String> getMessages() { return messages; }
86e98812-af58-4e1b-979b-7eefb6a1af2d
public PreexistingEntityException(String message, Throwable cause) { super(message, cause); }
f89186b1-d4be-4e9c-a83f-f86ca770092f
public PreexistingEntityException(String message) { super(message); }
0eff06bb-b18e-475e-9cee-3b9e98ca4f4e
public NonexistentEntityException(String message, Throwable cause) { super(message, cause); }
feab30ba-2e1c-49f5-9fb5-eb35e2f65439
public NonexistentEntityException(String message) { super(message); }
a656d19d-b761-4ad3-b6d7-3659ed7566e5
public RollbackFailureException(String message, Throwable cause) { super(message, cause); }
f48d81ab-77d9-4d3a-9745-1a52e7228ed4
public RollbackFailureException(String message) { super(message); }
bd28cf8e-81ae-441b-b5bf-17a78a7cc59d
@Override protected EntityManager getEntityManager() { return em; }
56d35f0a-776f-483d-bc42-ce4e05e0c74c
public ApplicantFacade() { super(Applicant.class); }
6d5472b8-4291-4a8a-a0bf-0244590a023e
public Applicant() { }
e7b9dc9e-c12c-4563-955e-dc7120b63a10
public Date getBirthDate() { return birthDate; }
0f4668f0-b1ad-409c-ae33-f4b343168026
public void setBirthDate(Date birthDate) { this.birthDate = birthDate; }
c6ae4c91-df17-422c-b8dd-465dd92556fe
public String getFormattedBirthDate() { String formattedDate = ""; if (birthDate != null) { formattedDate = sdf.format(birthDate); } return formattedDate; }
9bde0d57-d562-461d-a8e1-ef744d4323e6
public String getFirstName() { return firstName; }
47c6007e-8fd5-4499-87cd-30ef20f37bd7
public void setFirstName(String firstName) { this.firstName = firstName; }
6f119597-76f8-4d08-bffe-6c437154ab9c
public String getLastName() { return lastName; }
636a15b0-bd02-4898-9a22-986e30c56ced
public void setLastName(String lastName) { this.lastName = lastName; }
9443b5ed-2481-4632-8d60-5830994dfd60
public String getMiddleName() { return middleName; }
6ea4f2a3-b9cc-4004-8846-8a25990bfdce
public void setMiddleName(String middleName) { this.middleName = middleName; }
6859c46d-0289-4c70-a4af-d79f66b92a1e
public String getHomePhone() { return homePhone; }
116c1f91-bfea-47f3-8c64-e38bbad0ae6a
public void setHomePhone(String homePhone) { this.homePhone = homePhone; }
387b0066-3b74-4ccf-adb9-c2eeaa01ebb5
public String getMobilePhone() { return mobilePhone; }
78bf85dd-e785-41c7-9a14-81430d3191ab
public void setMobilePhone(String mobilePhone) { this.mobilePhone = mobilePhone; }
9cf7614b-909b-48ae-8618-f66fc8f9ef0e
public String getWorkPhone() { return workPhone; }
89b2d840-3a2a-4b24-a142-111306728965
public void setWorkPhone(String workPhone) { this.workPhone = workPhone; }
643a2fcd-89bc-4112-9a34-4471c453061d
public String getEmail() { return email; }
d4f52fe5-aa2c-44c9-a1aa-81cd297639de
public void setEmail(String email) { this.email = email; }
20e75553-6c32-4464-bdf5-d8a53e71ea9a
public Dispatcher() { this.bootstrap(); }
6439a166-65fe-4e09-a935-fbc64180e12d
public Dispatcher(Account acc) { this.account=acc; this.bootstrap(); }
47e5f3dd-e674-4def-95d8-8cd570886368
private void bootstrap() { Properties props=new Properties(); try { InputStream file=this.getClass().getResourceAsStream("/resources/config.properties"); props.load(file); this.configuration=props; } catch(IOException e) { e.printStackTrace(); } this.nav=new Navigator(this.configuration); }
76c928fa-02be-4d48-b194-3f0668c16231
public boolean connect() { try { URL url=new URL("http://www.way2sms.com/"); nav.setCurrentDomain(url); } catch(IOException e) { e.printStackTrace(); return false; } Response response=nav.get("", null); if(response.isRedirect()) { String loc=response.getHeaderValue("Location"); try { URL url=new URL(loc); nav.setCurrentDomain(url); } catch(IOException e) { e.printStackTrace(); } nav.setReferer(loc); response=nav.get("content/prehome.jsp", null); nav.setCookies(response.getCookies()); return true; } else return false; }
fd2ac143-762b-443d-bf39-5c5d38959ecb
public boolean login() { if(this.getAccount()==null) return false; Map post=new HashMap<String,String>(); post.put("username", this.getAccount().getUserName()); post.put("password", this.getAccount().getPassword()); post.put("userLogin", "no"); post.put("button", "Login"); nav.setReferer(nav.getCurrentDomain().toExternalForm()+"content/index.html"); Response response=nav.post("w2sauth.action", post, false); if(response.isRedirect()) { String loc=response.getHeaderValue("Location"); try { URL url=new URL(loc); this.token=url.getQuery().substring(3); Map params=new HashMap(); params.put("id", url.getQuery().substring(3)); nav.get(url.getPath(), params); } catch(IOException e) { e.printStackTrace(); return false; } return true; } else return false; }