@Override public boolean removeFromStore(Store store, int amount) { Integer newQuant = store.getQuantity() - amount; store.setQuantity(newQuant); return menu.getStoreDao().update(store); }
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 void sort(String sortKey, boolean asc) { for (int i = 0; i < this.size(); i++) { Store temp = this.getStore(i); temp.setCompare(sortKey, asc); } Collections.sort(this); }
@Test public void failedTransaction2() throws ExecutionException, InterruptedException { Stage stage = createStage(); Bank bank = Actor.getReference(Bank.class, "jimmy"); Inventory inventory = Actor.getReference(Inventory.class, "jimmy"); Store store = Actor.getReference(Store.class, "all"); bank.increment(15).join(); fakeSync.put("proceed", "ok"); // this item is invalid but the bank balance is decreased first. store.buyItem(bank, inventory, "candy", 10).join(); store.buyItem(bank, inventory, "chocolate", 1).join(); try { store.buyItem(bank, inventory, "ice cream", 50).join(); fail("expecting an exception"); } catch (CompletionException ex) { System.out.println(ex.getCause().getMessage()); } // the bank credits must be restored. eventually(() -> assertEquals((Integer) 4, bank.getBalance().join())); // no items were given eventually(() -> assertEquals(2, inventory.getItems().join().size())); dumpMessages(); }
public static void main(String[] args) throws MessagingException, IOException { IMAPFolder folder = null; Store store = null; String subject = null; Flag flag = null; try { Properties props = System.getProperties(); props.setProperty("mail.store.protocol", "imaps"); props.setProperty("mail.imap.host", "imap.googlemail.com"); SimpleAuthenticator authenticator = new SimpleAuthenticator("*****@*****.**", "hhy8611hhyy"); Session session = Session.getDefaultInstance(props, null); // Session session = Session.getDefaultInstance(props, authenticator); store = session.getStore("imaps"); // store.connect("imap.googlemail.com","*****@*****.**", "hhy8611hhyy"); // store.connect("imap.googlemail.com","*****@*****.**", "hhy8611hhyy"); store.connect("*****@*****.**", "hhy8611hhy"); // folder = (IMAPFolder) store.getFolder("[Gmail]/Spam"); // This doesn't work for other email // account folder = (IMAPFolder) store.getFolder("inbox"); // This works for both email account if (!folder.isOpen()) folder.open(Folder.READ_WRITE); Message[] messages = messages = folder.getMessages(150, 150); // folder.getMessages(); System.out.println("No of get Messages : " + messages.length); System.out.println("No of Messages : " + folder.getMessageCount()); System.out.println("No of Unread Messages : " + folder.getUnreadMessageCount()); System.out.println("No of New Messages : " + folder.getNewMessageCount()); System.out.println(messages.length); for (int i = 0; i < messages.length; i++) { System.out.println( "*****************************************************************************"); System.out.println("MESSAGE " + (i + 1) + ":"); Message msg = messages[i]; // System.out.println(msg.getMessageNumber()); // Object String; // System.out.println(folder.getUID(msg) subject = msg.getSubject(); System.out.println("Subject: " + subject); System.out.println("From: " + msg.getFrom()[0]); System.out.println("To: " + msg.getAllRecipients()[0]); System.out.println("Date: " + msg.getReceivedDate()); System.out.println("Size: " + msg.getSize()); System.out.println(msg.getFlags()); System.out.println("Body: \n" + msg.getContent()); System.out.println(msg.getContentType()); } } finally { if (folder != null && folder.isOpen()) { folder.close(true); } if (store != null) { store.close(); } } }
@Override public PhysicalOperator visitStore(Store store, Object obj) throws OptimizerException { if (!store.iterator().hasNext()) { throw new OptimizerException("Store node in logical plan does not have a child."); } return new Screen(store.iterator().next().accept(this, obj), context.getCurrentEndpoint()); }
public Location getLocation(Store store, City city) { Location toReturn = null; connect(); try { // Create a stmt object stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); // Query the database, storing the result // in an object of type ResultSet rs = stmt.executeQuery( "SELECT LocationId from Location, Store, City WHERE " + "Store.StoreId='" + store.getStoreId() + "' AND City.CityId='" + city.getCityId() + "'"); // Check if User is already in the database while (rs.next()) { String locationId = rs.getString("LocationId"); toReturn = new Location(locationId, store.getStoreId(), city.getCityId()); } // end while loop } catch (Exception e) { e.printStackTrace(); } // end catch finally { disconnect(); } return toReturn; }
@Test public void testGetFolder() throws MessagingException { Properties props; Session session; Folder folder; props = new Properties(); props.put("mail.host", "pop.gmail.com"); props.put("mail.store.protocol", "pop3s"); props.put("mail.pop3s.auth", "true"); props.put("mail.pop3s.port", 995); session = Session.getInstance(props, null); Store instance; // with wrong param instance = session.getStore(); instance.connect("*****@*****.**", "spamreturn"); try { folder = instance.getFolder(""); } catch (MessagingException ex) { assertTrue(true); } // with valid param try { folder = instance.getFolder("INBOX"); assertTrue(true); } catch (MessagingException ex) { fail("Should not throw MessagingException"); } }
protected void loadChildren() { try { // connect to the Store if we need to if (!store.isConnected()) { store.connect(); } // get the default folder, and list the // subscribed folders on it folder = store.getDefaultFolder(); // Folder[] sub = folder.listSubscribed(); Folder[] sub = folder.list(); // add a FolderTreeNode for each Folder int num = sub.length; for (int i = 0; i < num; i++) { FolderTreeNode node = new FolderTreeNode(sub[i]); // we used insert here, since add() would make // another recursive call to getChildCount(); insert(node, i); } } catch (MessagingException me) { me.printStackTrace(); } }
private void migrate(Store oldStore, FileSystemStore newStore) throws IOException { for (Path path : oldStore.listAllPaths()) { INode inode = oldStore.retrieveINode(path); oldStore.deleteINode(path); newStore.storeINode(path, inode); } }
public String[] getKeys() { if (this.size() > 0) { Store store = this.getStore(0); return store.getKeys(); } else { return null; } }
private void changeItemListInventory(String name, int quantity) { for (Iterator<Store> i = items.getItemList().iterator(); i.hasNext(); ) { Store item = (Store) i.next(); if (item.getItem().matches(name)) { item.setQuantity(item.getQuantity() + quantity); } } }
@Test public void storeIsDeleted() { Store newStore = new Store("Foot Traffic"); newStore.save(); goTo("http://localhost:4567/stores"); find("a", withText("Delete")).click(); assertThat(pageSource()).doesNotContain("Foot Traffic"); }
/** * This is where we can add markers or lines, add listeners or move the camera. In this case, we * just add a marker near Africa. * * <p>This should only be called once and when we are sure that {@link #mMap} is not null. */ private void setUpMap() { long mLat = Long.parseLong(mCurStore.getmLatitude()); long mLong = Long.parseLong(mCurStore.getmLongitude()); mMap.addMarker( new MarkerOptions().position(new LatLng(mLat, mLong)).title(mCurStore.getmName())); }
public Panel getAccordionNav() { Panel accordion = new Panel(); accordion.setTitle("Accordion"); accordion.setLayout(new AccordionLayout(true)); Store store = getStore(); Record[] records = store.getRecords(); for (int i = 0; i < records.length; i++) { Record record = records[i]; String id = record.getAsString("id"); final String category = record.getAsString("category"); String title = record.getAsString("title"); final String iconCls = record.getAsString("iconCls"); String thumbnail = record.getAsString("thumbnail"); String qtip = record.getAsString("qtip"); final ShowcasePanel panel = (ShowcasePanel) record.getAsObject("screen"); if (category == null) { Panel categoryPanel = new Panel(); categoryPanel.setAutoScroll(true); categoryPanel.setLayout(new FitLayout()); categoryPanel.setId(id + "-acc"); categoryPanel.setTitle(title); categoryPanel.setIconCls(iconCls); accordion.add(categoryPanel); } else { Panel categoryPanel = (Panel) accordion.findByID(category + "-acc"); TreePanel treePanel = (TreePanel) categoryPanel.findByID(category + "-acc-tree"); TreeNode root = null; if (treePanel == null) { treePanel = new TreePanel(); treePanel.setAutoScroll(true); treePanel.setId(category + "-acc-tree"); treePanel.setRootVisible(false); root = new TreeNode(); treePanel.setRootNode(root); categoryPanel.add(treePanel); } else { root = treePanel.getRootNode(); } TreeNode node = new TreeNode(); node.setText(title); node.setId(id); if (iconCls != null) node.setIconCls(iconCls); if (qtip != null) node.setTooltip(qtip); root.appendChild(node); addNodeClickListener(node, panel, iconCls); } } return accordion; }
@Override public boolean equals(Object otherStore) { if (!(otherStore instanceof Store)) { return false; } else { Store newStore = (Store) otherStore; return this.getName().equals(newStore.getName()) && this.getId() == newStore.getId(); } }
@Test public void brandsAndStoresDisplayedCorrectly() { Brand newBrand = new Brand("Nike"); newBrand.save(); Store newStore = new Store("Foot Traffic"); newStore.save(); goTo("http://localhost:4567/"); assertThat(pageSource()).contains("Nike"); assertThat(pageSource()).contains("Foot Traffic"); }
@Test public void brandIsAddedToStore() { Brand newBrand = new Brand("Asics"); newBrand.save(); Store newStore = new Store("Foot Traffic"); newStore.save(); newStore.addBrand(newBrand.getId()); goTo("http://localhost:4567/stores/" + newStore.getId()); assertThat(pageSource()).contains("Asics"); }
@Test public void storeIsUpdated() { Store newStore = new Store("Foot Traffic"); newStore.save(); String storePath = String.format("http://localhost:4567/stores/%d/update", newStore.getId()); goTo(storePath); fill("#name").with("Road Runner Sports"); submit("#update_name"); assertThat(pageSource()).contains("Road Runner Sports"); }
@Before public void setUp() throws Exception { Store store = new Store(); store.setDbName("gwdp"); store.setCollectionName("files_done"); s = store; fr = new FileRecorder(store); }
/** * expand super types after scanning, for super types that were not scanned. this is helpful in * finding the transitive closure without scanning all 3rd party dependencies. it uses {@link * ReflectionUtils#getSuperTypes(Class)}. * * <p>for example, for classes A,B,C where A supertype of B, B supertype of C: * * <ul> * <li>if scanning C resulted in B (B->C in store), but A was not scanned (although A supertype * of B) - then getSubTypes(A) will not return C * <li>if expanding supertypes, B will be expanded with A (A->B in store) - then getSubTypes(A) * will return C * </ul> */ public void expandSuperTypes() { if (store.keySet().contains(index(SubTypesScanner.class))) { Multimap<String, String> mmap = store.get(index(SubTypesScanner.class)); Sets.SetView<String> keys = Sets.difference(mmap.keySet(), Sets.newHashSet(mmap.values())); Multimap<String, String> expand = HashMultimap.create(); for (String key : keys) { expandSupertypes(expand, key, forName(key)); } mmap.putAll(expand); } }
@Override public Long sale(Long storeId, int amount) { Store store = menu.getStoreDao().read(storeId); Integer curAmount = store.getQuantity(); Integer newAmount = curAmount - amount; store.setQuantity(newAmount); Sales nwSale = new Sales(store, new java.util.Date(), amount); Long id = salesDao.create(nwSale); return id; }
void isInterrupted(final Store store, final StoreFile.Writer writer) throws IOException { if (store.getHRegion().areWritesEnabled()) return; // Else cleanup. writer.close(); store.getFileSystem().delete(writer.getPath(), false); throw new InterruptedIOException( "Aborting compaction of store " + store + " in region " + store.getHRegion() + " because user requested stop."); }
@Test public void testGetStore() throws Exception { StoreFactory storeFactory = StoreFactory.getInstance(); Store store = storeFactory.getStore("test"); Assert.assertNotNull(store); String[] fileNames = store.getFileNames(0, 0); Assert.assertEquals(1, fileNames.length); Assert.assertEquals("TestStore", fileNames[0]); }
/** Build a Store operator and validate each field */ @Test public void testBuild() { String storageEngine = "mock-storage"; PartitionDef partition = new PartitionDef(PartitionDef.PartitionType.RANGE, null, null); JSONOptions target = null; Store storeOp = Store.builder().storageEngine(storageEngine).partition(partition).target(target).build(); assertEquals(storeOp.getStorageEngine(), storageEngine); assertEquals(storeOp.getPartition(), partition); assertEquals(storeOp.getTarget(), target); }
/** * <b>使用IMAP协议接收邮件</b><br> * * <p>POP3和IMAP协议的区别: <b>POP3</b>协议允许电子邮件客户端下载服务器上的邮件,但是在客户端的操作(如移动邮件、标记已读等),不会反馈到服务器上,<br> * 比如通过客户端收取了邮箱中的3封邮件并移动到其它文件夹,邮箱服务器上的这些邮件是没有同时被移动的。<br> * * <p><b>IMAP</b>协议提供webmail与电子邮件客户端之间的双向通信,客户端的操作都会同步反应到服务器上,对邮件进行的操作,服务 * 上的邮件也会做相应的动作。比如在客户端收取了邮箱中的3封邮件,并将其中一封标记为已读,将另外两封标记为删除,这些操作会 即时反馈到服务器上。 * * <p>两种协议相比,IMAP 整体上为用户带来更为便捷和可靠的体验。POP3更易丢失邮件或多次下载相同的邮件,但IMAP通过邮件客户端 * 与webmail之间的双向同步功能很好地避免了这些问题。 */ public static void main(String[] args) throws Exception { // 准备连接服务器的会话信息 Properties props = new Properties(); props.setProperty("mail.store.protocol", "imap"); props.setProperty("mail.imap.host", "imap.qq.com"); props.setProperty("mail.imap.port", "143"); // 创建Session实例对象 Session session = Session.getInstance(props); // 创建IMAP协议的Store对象 Store store = session.getStore("imap"); // 连接邮件服务器 store.connect("*****@*****.**", "asdasd"); // 获得收件箱 Folder folder = store.getFolder("INBOX"); // 以读写模式打开收件箱 folder.open(Folder.READ_WRITE); // 获得收件箱的邮件列表 Message[] messages = folder.getMessages(); // 打印不同状态的邮件数量 System.out.println("收件箱中共" + messages.length + "封邮件!"); System.out.println("收件箱中共" + folder.getUnreadMessageCount() + "封未读邮件!"); System.out.println("收件箱中共" + folder.getNewMessageCount() + "封新邮件!"); System.out.println("收件箱中共" + folder.getDeletedMessageCount() + "封已删除邮件!"); System.out.println("------------------------开始解析邮件----------------------------------"); // 解析邮件 for (Message message : messages) { IMAPMessage msg = (IMAPMessage) message; String subject = MimeUtility.decodeText(msg.getSubject()); System.out.println("[" + subject + "]未读,是否需要阅读此邮件(yes/no)?"); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String answer = reader.readLine(); if ("yes".equalsIgnoreCase(answer)) { Pop3ReceiveMailUtil.parseMessage(msg); // 解析邮件 // 第二个参数如果设置为true,则将修改反馈给服务器。false则不反馈给服务器 msg.setFlag(Flags.Flag.SEEN, true); // 设置已读标志 } } // 关闭资源 folder.close(false); store.close(); }
public static void main(String[] args) { Store bleh = new Store(); Scanner scan = new Scanner(System.in); System.out.println( "Enter in the name of a customer,hit enter, then enter in the price of what he bought"); while (true) { String customer = scan.next(); double price = scan.nextDouble(); if (price == 0.0 || customer.equals("0")) { break; } bleh.addSale(customer, price); } System.out.println(bleh.nameOfBestCustomer()); }
@Override public void close() throws IOException { flushBufferToCache(); closeInternal(); store.putBuffer(buffer); buffer = null; }
public ReusedBufferedIndexOutput(String resourceDescription, String name, int bufferSize) { super(resourceDescription, name); checkBufferSize(bufferSize); this.bufferSize = bufferSize; store = BufferStore.instance(bufferSize); buffer = store.takeBuffer(this.bufferSize); }
protected void put2(DataIO.DataOutputByteArray out, long ioRecid, long[] indexVals) { assert (disableLocks || locks[Store.lockPos(ioRecid)].writeLock().isHeldByCurrentThread()); index.putLong(ioRecid, indexVals[0] | MASK_ARCHIVE); // write stuff if (indexVals.length == 1 || indexVals[1] == 0) { // is more then one? ie linked // write single phys.putData(indexVals[0] & MASK_OFFSET, out.buf, 0, out.pos); } else { int outPos = 0; // write linked for (int i = 0; i < indexVals.length; i++) { final int c = i == indexVals.length - 1 ? 0 : 8; final long indexVal = indexVals[i]; final boolean isLast = (indexVal & MASK_LINKED) == 0; assert (isLast == (i == indexVals.length - 1)); final int size = (int) (indexVal >>> 48); final long offset = indexVal & MASK_OFFSET; // write data phys.putData(offset + c, out.buf, outPos, size - c); outPos += size - c; if (c > 0) { // write position of next linked record phys.putLong(offset, indexVals[i + 1]); } } if (outPos != out.pos) throw new AssertionError(); } }