List of usage examples for java.lang.ref WeakReference WeakReference
public WeakReference(T referent)
From source file:com.trellmor.berrytube.BerryTube.java
/** * Set the callback handler/*from w w w. j av a 2 s. c om*/ * * @param callback * Callback implementation instance */ public void setCallback(BerryTubeCallback callback) { mCallback = new WeakReference<>(callback); // Clear old notifications mMessageNotificationText.clear(); mMessageNotificationCount = 0; }
From source file:de.sanandrew.mods.turretmod.registry.assembly.RecipeEntry.java
@Override @SideOnly(Side.CLIENT)/* www . ja v a 2 s . c o m*/ public ItemStack[] getEntryItemStacks() { if (this.cachedEntryStacks == null || this.cachedEntryStacks.get() == null) { NonNullList<ItemStack> stacks = NonNullList.create(); NonNullList<ItemStack> fltStacks = NonNullList.create(); for (ItemStack stack : this.normalAlternatives) { if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) { stack.getItem().getSubItems(CreativeTabs.SEARCH, stacks); } else { stacks.add(stack); } } for (String oreDictName : this.oreDictAlternatives) { OreDictionary.getOres(oreDictName).forEach(stack -> { if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) { stack.getItem().getSubItems(CreativeTabs.SEARCH, stacks); } else { stacks.add(stack); } }); } for (ItemStack stack : stacks) { ItemStack valid = stack.copy(); for (ItemStack fltStack : fltStacks) { if (fltStack.isItemEqual(valid)) { valid = null; break; } } if (valid != null) { valid.setCount(this.stackSize); fltStacks.add(valid); } } this.cachedEntryStacks = new WeakReference<>(fltStacks.toArray(new ItemStack[fltStacks.size()])); } return this.cachedEntryStacks.get(); }
From source file:ch.entwine.weblounge.common.impl.content.file.LazyFileResourceImpl.java
/** * Loads the file body only.//from w w w . j a va 2 s .c om */ protected void loadFileBody() { try { // Get a hold of the file reader FileResourceReader reader = (readerRef != null) ? readerRef.get() : null; if (reader == null) { reader = new FileResourceReader(); readerRef = new WeakReference<FileResourceReader>(reader); } // Load the file body file = reader.readBody(IOUtils.toInputStream(fileXml, "utf-8"), uri.getSite()); isBodyLoaded = true; if (isHeaderLoaded && isBodyLoaded) cleanupAfterLoading(); else if (headerXml != null) fileXml = null; } catch (Throwable e) { logger.error("Failed to lazy-load body of {}: {}", uri, e.getMessage()); throw new IllegalStateException(e); } }
From source file:blue.soundObject.jmask.ItemList.java
public void addTableModelListener(TableModelListener l) { if (listeners == null) { listeners = new Vector<WeakReference<TableModelListener>>(); }/*from ww w .j ava2 s . c o m*/ for (WeakReference<TableModelListener> ref : listeners) { if (ref.get() == l) { return; } } listeners.add(new WeakReference<TableModelListener>(l)); }
From source file:ch.entwine.weblounge.common.impl.content.movie.LazyMovieResourceImpl.java
/** * Loads the audio visual body only.//from w w w . ja v a 2 s .c om */ protected void loadAudioVisualBody() { try { // Get a hold of the audio visual reader MovieResourceReader reader = (readerRef != null) ? readerRef.get() : null; if (reader == null) { reader = new MovieResourceReader(); readerRef = new WeakReference<MovieResourceReader>(reader); } // Load the audio visual body audioVisual = reader.readBody(IOUtils.toInputStream(audiovisualXml, "utf-8"), uri.getSite()); isBodyLoaded = true; if (isHeaderLoaded && isBodyLoaded) cleanupAfterLoading(); else if (headerXml != null) audiovisualXml = null; } catch (Throwable e) { logger.error("Failed to lazy-load body of {}: {}", uri, e.getMessage()); throw new IllegalStateException(e); } }
From source file:com.appassit.common.Utils.java
public static String getTodayDate() { if (calendar == null || calendar.get() == null) { calendar = new WeakReference<Calendar>(Calendar.getInstance()); }//from www. ja v a 2 s.c om Calendar today = calendar.get(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.format(today.getTime()); }
From source file:com.honeywell.printer.net.autobaln_websocket.WebSocketConnection.java
public void connect(String wsUri, String[] wsSubprotocols, WebSocket.ConnectionHandler wsHandler, WebSocketOptions options, List<BasicNameValuePair> headers) throws WebSocketException { try {/*from w ww . j a v a 2s .co m*/ this.mWebSocketURI = new URI(wsUri); if (!mWebSocketURI.getScheme().equals(WS_URI_SCHEME) && !mWebSocketURI.getScheme().equals(WSS_URI_SCHEME)) { throw new WebSocketException("unsupported scheme for WebSockets URI"); } this.mWebSocketSubprotocols = wsSubprotocols; this.mWebSocketConnectionObserver = new WeakReference<ConnectionHandler>(wsHandler); this.mWebSocketOptions = new WebSocketOptions(options); mWsHeaders = headers; connect(); } catch (Exception e) { e.printStackTrace(); } }
From source file:ch.entwine.weblounge.common.impl.content.page.PageReader.java
/** * This method is called when a <code>Page</code> object is instantiated. * //ww w .j a va2s .co m * @param is * the xml input stream * @param site * the page's site * @throws ParserConfigurationException * if the SAX parser setup failed * @throws IOException * if reading the input stream fails * @throws SAXException * if an error occurs while parsing */ public PageImpl readBody(InputStream is, Site site) throws SAXException, IOException, ParserConfigurationException { if (page == null) { page = new PageImpl(new PageURIImpl(site, "/")); } readHeader = false; readBody = true; SAXParser parser = parserRef.get(); if (parser == null) { parser = parserFactory.newSAXParser(); parserRef = new WeakReference<SAXParser>(parser); } parser.parse(is, this); return page; }
From source file:ch.entwine.weblounge.common.impl.content.page.LazyPageImpl.java
/** * Loads the page body only.// w ww . j a v a 2 s. com */ protected void loadPageBody() { try { // Get a hold of the page reader PageReader reader = (readerRef != null) ? readerRef.get() : null; if (reader == null) { reader = new PageReader(); readerRef = new WeakReference<PageReader>(reader); } // Load the page body page = reader.readBody(IOUtils.toInputStream(pageXml, "utf-8"), uri.getSite()); isBodyLoaded = true; if (isHeaderLoaded && isBodyLoaded) cleanupAfterLoading(); else if (headerXml != null) pageXml = null; } catch (Throwable e) { logger.error("Failed to lazy-load body of {}: {}", uri, e.getMessage()); throw new IllegalStateException(e); } }
From source file:ch.entwine.weblounge.common.impl.content.AbstractResourceReaderImpl.java
/** * This method is called to read the body of a resource. * /*ww w . j av a2s.c o m*/ * @param is * the xml input stream * @param site * the site * @throws ParserConfigurationException * if the SAX parser setup failed * @throws IOException * if reading the input stream fails * @throws SAXException * if an error occurs while parsing */ public T readBody(InputStream is, Site site) throws SAXException, IOException, ParserConfigurationException { if (resource == null) { resource = createResource(site); } readHeader = false; readBody = true; SAXParser parser = parserRef.get(); if (parser == null) { parser = parserFactory.newSAXParser(); parserRef = new WeakReference<SAXParser>(parser); } parser.parse(is, this); return resource; }