/** * Create the entity by combining the stored key and data. This "tricky" binding returns the * stored data as the entity, but first it sets the transient key fields from the stored key. */ public Object entryToObject(TupleInput keyInput, Object dataInput) { String number = keyInput.readString(); Supplier supplier = (Supplier) dataInput; supplier.setKey(number); return supplier; }
public static void main(String[] args) { // 1. Create storage: Storage storage = new Storage("Sklada na Mecho"); // 2. Create supplier: Supplier supplier = new Supplier("Ezhko Bezhko OOD"); supplier.addStorage(storage); supplier.start(); // 3. Create store: Store store = new Store("Magazina na Baba Metsa"); store.addStorage(storage); store.start(); ArrayList<String> productsToBuyFromStorage = new ArrayList<String>(); productsToBuyFromStorage.add("Potato"); Thread t = new Thread( new Runnable() { @Override public void run() { while (true) { storage.sellStock(productsToBuyFromStorage); } } }); t.start(); }
public Supplier searchSupplier(String search) { for (Supplier supplier : supplierCatalog) { if (supplier.getSupplierName().equals(search)) { return supplier; } } return null; }
public void delete() { for (int i = supplierOrderLineItems.size(); i > 0; i--) { SupplierOrderLineItem aSupplierOrderLineItem = supplierOrderLineItems.get(i - 1); aSupplierOrderLineItem.delete(); } Supplier placeholderSupplier = supplier; this.supplier = null; placeholderSupplier.removeOrderToSupplier(this); }
private static int getTotalCapitalSalesRevanue( String supplierName, List<ProductGroup> productGroups) { int total = 0; for (ProductGroup productGroup : productGroups) { for (Supplier supplier : productGroup.getSuppliers()) { if (supplier.getName().equals(supplierName)) { total += supplier.getEstimatedCapitalSalesRevanue2012(); } } } return total; }
public boolean setSupplier(Supplier aSupplier) { boolean wasSet = false; if (aSupplier == null) { return wasSet; } Supplier existingSupplier = supplier; supplier = aSupplier; if (existingSupplier != null && !existingSupplier.equals(aSupplier)) { existingSupplier.removeOrderToSupplier(this); } supplier.addOrderToSupplier(this); wasSet = true; return wasSet; }
public synchronized T get() { if (!initialized) { value = delegate.get(); initialized = true; } return value; }
public Stream<FieldInfo> getFieldStream() { return type.get() .getMembers() .stream() .filter(x -> x instanceof FieldDeclaration) .map(x -> new FieldDeclarationWrapper((FieldDeclaration) x)); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Article other = (Article) obj; if (barcode == null) { if (other.barcode != null) return false; } else if (!barcode.equals(other.barcode)) return false; if (comment == null) { if (other.comment != null) return false; } else if (!comment.equals(other.comment)) return false; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (price == null) { if (other.price != null) return false; } else if (!price.equals(other.price)) return false; if (supplier == null) { if (other.supplier != null) return false; } else if (!supplier.equals(other.supplier)) return false; if (type == null) { if (other.type != null) return false; } else if (!type.equals(other.type)) return false; if (unit == null) { if (other.unit != null) return false; } else if (!unit.equals(other.unit)) return false; return true; }
public Stream<MethodInfo> getMethodStream() { return type.get() .getMembers() .stream() .map(this::getMethodInfoWrapper) .filter(Objects::nonNull); }
@Override public List<Type> getInterfaceTypes() { return type.get() .getImplements() .stream() .map(getContext()::resolve) .collect(Collectors.toList()); }
@Override public Type getSuperType() { val extends_ = type.get().getExtends(); if (extends_ == null || extends_.isEmpty()) return null; return getContext().resolve(extends_.get(0)); }
@Override public void setName(String name) { String packageName = getPackageName(); if (name.startsWith(packageName)) { type.get().setName(name.replace(packageName, "")); } else { throw new TransformationException("Name '" + name + "' must be in package: " + packageName); } }
@Test public void testEquals() throws Exception { DpiFile d1 = new DpiFile(); d1.setFileName("f1"); d1.setReportingPeriod(new ParmsReportingPeriod(11, 2010)); Supplier s1 = new Supplier("s1"); d1.setSupplier(s1); GridSupplyPoint g1 = new GridSupplyPoint("g1", d1); g1.setHalfHourMpans2ndMonth(true); DpiFile d2 = new DpiFile(); d2.setFileName("f1"); d2.setReportingPeriod(new ParmsReportingPeriod(11, 2010)); Supplier s2 = new Supplier("s1"); s2.setSupplierId("s1"); d2.setSupplier(s2); GridSupplyPoint g2 = new GridSupplyPoint("g1", d2); g2.setHalfHourMpans2ndMonth(true); assertTrue(g1.equals(g2)); }
private <T, R> R testAvg(T[] values, Aggregation<String, T, R> aggregation) throws Exception { String mapName = randomMapName(); MultiMap<String, T> map = HAZELCAST_INSTANCE.getMultiMap(mapName); for (int i = 0; i < values.length; i++) { map.put("key-" + i, values[i]); } Supplier<String, T, T> supplier = Supplier.all(); return map.aggregate(supplier, aggregation); }
public static void main(String[] args) { // how many sales? long saleCount = saleStream().count(); System.out.println("Count of sales: " + saleCount); // any sales over $100? Supplier<DoubleStream> totalStream = () -> saleStream().mapToDouble(Sale::total); boolean bigSaleDay = totalStream.get().anyMatch(total -> total > 100.00); System.out.println("Big sale day? " + bigSaleDay); // maximum sale amount? DoubleSummaryStatistics stats = totalStream.get().summaryStatistics(); System.out.println("Max sale amount: " + stats.getMax()); System.out.println("Stats on total: " + stats); // how many items were sold today? Supplier<Stream<Item>> itemStream = () -> saleStream().flatMap(sale -> sale.items.stream()); long itemCount = itemStream.get().count(); System.out.println("Count of items: " + itemCount); // which different items were sold today? String uniqueItems = itemStream.get().map(item -> item.identity).distinct().collect(Collectors.joining(" & ")); System.out.println("Distinct items: " + uniqueItems); // summarize sales by store ConcurrentMap<String, DoubleSummaryStatistics> summary = saleStream() .parallel() .collect( Collectors.groupingByConcurrent( sale -> Thread.currentThread().getName(), Collectors.summarizingDouble(Sale::total))); System.out.println("Summary by thread: " + summary); summary .keySet() .stream() .sorted() .forEach(store -> System.out.println(store + " stats: " + summary.get(store))); }
public void run() { Gson gson = new Gson(); ExtendList<Supplier> supplierList = new ExtendArrayList<Supplier>(); ExtendList<Price> priceList = new ExtendArrayList<Price>(); ExtendList<ElementInfo> elementInfoList = new ExtendArrayList<ElementInfo>(); for (Long i = fromPageIndex; i < toPageIndex; i++) { TCountAndTablePrice tCountAndTablePrice = DataObjectUtil.getPriceData(gson, factory.fid, "", "", i); if (tCountAndTablePrice != null) { List<Price> prices = tCountAndTablePrice.Table; if (prices != null && prices.size() > 0) { priceList.addAndInsertAllIntoDB(prices); for (Price price : prices) { ElementInfo elementInfo = DataObjectUtil.getElementInfo(gson, price.F_Class_ID, price.F_InnerModel); elementInfoList.addAndInsertIntoDB(elementInfo); TCountAndTableSupplier tCountAndTableSupplier = DataObjectUtil.getSupplierData(gson, price.F_Class_ID); List<Supplier> suppliers = tCountAndTableSupplier.Table; if (suppliers != null && suppliers.size() > 0) { for (Supplier supplier : suppliers) { supplier.param_cid = price.F_Class_ID; } supplierList.addAndInsertAllIntoDB(suppliers); } } } } } supplierList.insertAllIntoDB(); priceList.insertAllIntoDB(); elementInfoList.insertAllIntoDB(); }
@Override public void remove(FieldInfo field) { FieldDeclarationWrapper fieldDeclarationWrapper = !(field instanceof FieldDeclarationWrapper) ? (FieldDeclarationWrapper) get(field) : (FieldDeclarationWrapper) field; if (fieldDeclarationWrapper == null) throw new TransformationException( "Field " + field + " can not be removed as it is not present"); type.get().getMembers().remove(fieldDeclarationWrapper.declaration); }
@Override public void remove(MethodInfo method) { MethodDeclarationWrapper methodDeclarationWrapper = !(method instanceof MethodDeclarationWrapper) ? (MethodDeclarationWrapper) get(method) : (MethodDeclarationWrapper) method; if (methodDeclarationWrapper == null) throw new TransformationException( "Method " + method + " can not be removed as it is not present"); type.get().getMembers().remove(methodDeclarationWrapper.declaration); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((barcode == null) ? 0 : barcode.hashCode()); result = prime * result + ((comment == null) ? 0 : comment.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((price == null) ? 0 : price.hashCode()); result = prime * result + ((supplier == null) ? 0 : supplier.hashCode()); result = prime * result + ((type == null) ? 0 : type.hashCode()); result = prime * result + ((unit == null) ? 0 : unit.hashCode()); return result; }
public static <TYPE> void await( Supplier<TYPE> supplier, Predicate<TYPE> predicate, long timeout, TimeUnit unit) throws TimeoutException, InterruptedException { long sleep = Math.max(unit.toMillis(timeout) / 100, 1); long deadline = System.currentTimeMillis() + unit.toMillis(timeout); do { if (predicate.test(supplier.get())) { return; } Thread.sleep(sleep); } while (System.currentTimeMillis() < deadline); throw new TimeoutException( "Waited for " + timeout + " " + unit + ", but " + predicate + " was not accepted."); }
public Employee createEmployee(String name, Organization organization) { if (organization.getOrganizationName().equals(TypeOfOrg.Customer.getValue())) { Customer customer = new Customer(); customer.setName(name); employeeList.add(customer); return customer; } else if (organization.getOrganizationName().equals(TypeOfOrg.Supplier.getValue())) { Supplier supplier = new Supplier(); supplier.setName(name); employeeList.add(supplier); return supplier; } else if (organization.getOrganizationName().equals(TypeOfOrg.SalesSpecialist.getValue())) { SalesSpecialist salesSpecialist = new SalesSpecialist(); salesSpecialist.setName(name); employeeList.add(salesSpecialist); return salesSpecialist; } else if (organization.getOrganizationName().equals(TypeOfOrg.ShippingSpecialist.getValue())) { ShippingSpecialist shippingSpecialist = new ShippingSpecialist(); shippingSpecialist.setName(name); employeeList.add(shippingSpecialist); return shippingSpecialist; } return null; }
public T get() { switch (state) { case NOT_YET: state = MemoizationState.COMPUTING; try { value = delegate.get(); } finally { state = MemoizationState.NOT_YET; } state = MemoizationState.DONE; break; case COMPUTING: throw new CyclicDependencyException(); } return value; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((comment == null) ? 0 : comment.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((manager == null) ? 0 : manager.hashCode()); result = prime * result + ((orderDate == null) ? 0 : orderDate.hashCode()); result = prime * result + ((orderDoneDate == null) ? 0 : orderDoneDate.hashCode()); // result = prime * result // + ((orderstruct == null) ? 0 : orderstruct.hashCode()); result = prime * result + ((status == null) ? 0 : status.hashCode()); result = prime * result + ((supplier == null) ? 0 : supplier.hashCode()); result = prime * result + ((type == null) ? 0 : type.hashCode()); return result; }
@SuppressWarnings("unchecked") public <M> M read( Json json, JsonValue jsonData, Supplier<M> newInstance, KeyValueConsumer<M, K, V> put) { M values = newInstance.get(); JsonValue entry = jsonData.getChild(name); while (entry != null) { JsonValue keyValue = entry.get("key"); K key = json.readValue((Class<K>) map.key(), keyValue); JsonValue valueValue = entry.get("value"); V value = json.readValue((Class<V>) map.value(), valueValue); put.accept(values, key, value); entry = entry.next; } return values; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; SupplierOrder other = (SupplierOrder) obj; if (comment == null) { if (other.comment != null) return false; } else if (!comment.equals(other.comment)) return false; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; if (manager == null) { if (other.manager != null) return false; } else if (!manager.equals(other.manager)) return false; if (orderDate == null) { if (other.orderDate != null) return false; } else if (!orderDate.equals(other.orderDate)) return false; if (orderDoneDate == null) { if (other.orderDoneDate != null) return false; } else if (!orderDoneDate.equals(other.orderDoneDate)) return false; // if (orderstruct == null) { // if (other.orderstruct != null) // return false; // } else if (!orderstruct.equals(other.orderstruct)) // return false; if (status == null) { if (other.status != null) return false; } else if (!status.equals(other.status)) return false; if (supplier == null) { if (other.supplier != null) return false; } else if (!supplier.equals(other.supplier)) return false; if (type == null) { if (other.type != null) return false; } else if (!type.equals(other.type)) return false; return true; }
public T get() { return function.apply(first.get()); }
public void _jspService( final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException { final javax.servlet.jsp.PageContext pageContext; javax.servlet.http.HttpSession session = null; final javax.servlet.ServletContext application; final javax.servlet.ServletConfig config; javax.servlet.jsp.JspWriter out = null; final java.lang.Object page = this; javax.servlet.jsp.JspWriter _jspx_out = null; javax.servlet.jsp.PageContext _jspx_page_context = null; try { response.setContentType("text/html;charset=GBK"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; out.write("\r\n"); out.write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n"); out.write("<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("<head>\r\n"); out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />\r\n"); out.write("<meta http-equiv=\"pragma\" content=\"no-cache\" />\r\n"); out.write("<meta http-equiv=\"cache-control\" content=\"no-cache\" />\r\n"); out.write("<meta http-equiv=\"expires\" content=\"0\" /> \r\n"); out.write(" \r\n"); out.write("<title>超市管理系统</title>\r\n"); out.write("<script type=text/javascript>\r\n"); out.write(" function check(form){\r\n"); out.write("\t if(form.supplierid.value==\"\"){\r\n"); out.write("\t\talert(\"编号不能为空\"); \r\n"); out.write("\t\treturn false;\r\n"); out.write("\t }\r\n"); out.write("\t if(form.suppliername.value==\"\"){\r\n"); out.write("\t\talert(\"供应商名称不能为空\"); \r\n"); out.write("\t\treturn false;\r\n"); out.write("\t }\r\n"); out.write("\t if(form.supplierdescription.value==\"\"){\r\n"); out.write("\t\talert(\"供应商描述不能为空\"); \r\n"); out.write("\t\treturn false;\r\n"); out.write("\t }\r\n"); out.write("\t if(form.linkedman.value==\"\"){\r\n"); out.write("\t\talert(\"联系人不能为空\"); \r\n"); out.write("\t\treturn false;\r\n"); out.write("\t }\r\n"); out.write("\t if(form.telphone.value==\"\"){\r\n"); out.write("\t\talert(\"电话不能为空\"); \r\n"); out.write("\t\treturn false;\r\n"); out.write("\t }\r\n"); out.write("\t if(form.address.value==\"\"){\r\n"); out.write("\t\talert(\"地址不能为空\"); \r\n"); out.write("\t\treturn false;\r\n"); out.write("\t }\r\n"); out.write("\t if(!window.confirm(\"确定更改?\")){\r\n"); out.write("\t\t return false;\r\n"); out.write("\t }\r\n"); out.write("\t return true;\r\n"); out.write(" }\r\n"); out.write("</script>\r\n"); out.write("\r\n"); out.write("</head>\r\n"); if (session.getAttribute("username") == null) { out.println("<script type=\"text/javascript\">"); out.println("alert(\"您还没有登陆!请登陆!\");"); out.println("open(\"index.jsp\",\"_parent\");"); out.println("</script>"); return; } out.write('\r'); out.write('\n'); request.setCharacterEncoding("gbk"); long supplierid = Long.valueOf(request.getParameter("supplierid")); String suppliername = request.getParameter("suppliername"); String supplierdescription = request.getParameter("supplierdescription"); String linkedman = request.getParameter("linkedman"); String telphone = request.getParameter("telphone"); String address = request.getParameter("address"); pageContext.setAttribute("supplierid", supplierid); pageContext.setAttribute("suppliername", suppliername); pageContext.setAttribute("supplierdescription", supplierdescription); pageContext.setAttribute("linkedman", linkedman); pageContext.setAttribute("telphone", telphone); pageContext.setAttribute("address", address); if (request.getParameter("change") != null) { Supplier supplier = new Supplier(); supplier.setSupplierid(supplierid); supplier.setSuppliername(suppliername); supplier.setSupplierdescription(supplierdescription); supplier.setLinkedman(linkedman); supplier.setTelphone(telphone); supplier.setAddress(address); boolean consequence = new SupplierOperation().supplierinfochange(supplier); if (consequence) { out.println("<script type=\"text/javascript\">"); out.println("alert(\"更新成功!\");"); out.println("open(\"suppliermanage.jsp\",\"_self\");"); out.println("</script>"); return; } else { out.println("<script type=\"text/javascript\">"); out.println("alert(\"更新失败!\");"); out.println("open(\"suppliermanage.jsp\",\"_self\");"); out.println("</script>"); return; } } out.write("\r\n"); out.write("<body>\r\n"); out.write( " <form action=supplierinfochange.jsp method=post onSubmit=\"return check(this);\">\r\n"); out.write(" <input type=hidden name=change />\r\n"); out.write(" <div style=\"border:10px solid #4169E1;width:80%;\" >\r\n"); out.write(" <table>\r\n"); out.write(" <tr><td><pre> </pre></td><td><input name=supplierid type=\"hidden\" value="); out.write( (java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate( "${supplierid}", java.lang.String.class, (javax.servlet.jsp.PageContext) _jspx_page_context, null, false)); out.write(" /></td></tr>\r\n"); out.write(" <tr><td>供应商名称:</td><td><input name=suppliername type=\"text\" value="); out.write( (java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate( "${suppliername}", java.lang.String.class, (javax.servlet.jsp.PageContext) _jspx_page_context, null, false)); out.write(" /></td></tr>\r\n"); out.write(" \r\n"); out.write("<tr><td>供应商描述:</td><td><textarea name=supplierdescription>"); out.write( (java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate( "${supplierdescription}", java.lang.String.class, (javax.servlet.jsp.PageContext) _jspx_page_context, null, false)); out.write("</textarea></td></tr>\r\n"); out.write(" <tr><td>联系人:</td><td><input name=linkedman type=\"text\" value="); out.write( (java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate( "${linkedman}", java.lang.String.class, (javax.servlet.jsp.PageContext) _jspx_page_context, null, false)); out.write(" /></td></tr>\r\n"); out.write(" <tr><td>电话:</td><td><input name=telphone type=\"text\" value="); out.write( (java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate( "${telphone}", java.lang.String.class, (javax.servlet.jsp.PageContext) _jspx_page_context, null, false)); out.write(" /></td></tr>\r\n"); out.write(" <tr><td>地址:</td><td><textarea name=address >"); out.write( (java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate( "${address}", java.lang.String.class, (javax.servlet.jsp.PageContext) _jspx_page_context, null, false)); out.write("</textarea></td></tr>\r\n"); out.write(" </table>\r\n"); out.write(" </div>\r\n"); out.write( " <input onclick=\"window.open('suppliermanage.jsp','_self')\" type=\"button\" value=返回 /><input type=\"submit\" value=修改数据 /><input onclick=\"window.open('supplierdelete.jsp?supplierid="); out.write( (java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate( "${supplierid}", java.lang.String.class, (javax.servlet.jsp.PageContext) _jspx_page_context, null, false)); out.write("','_self')\" type=button value=删除 />\r\n"); out.write("</form>\r\n"); out.write("</body>\r\n"); out.write("</html>"); } catch (java.lang.Throwable t) { if (!(t instanceof javax.servlet.jsp.SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) try { out.clearBuffer(); } catch (java.io.IOException e) { } if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); else throw new ServletException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } }
/** * 接受Lambda函数,延迟执行 * * @param logger * @param message */ public static void info(Logger logger, Supplier<String> message) { if (logger.isLoggable(Level.INFO)) logger.info(message.get()); }
public Supplier addSupplier(String name) { Supplier s = new Supplier(); s.setSupplierName(name); supplierCatalog.add(s); return s; }