List of usage examples for org.apache.commons.lang3.mutable MutableInt getValue
@Override
public Integer getValue()
From source file:demo.enumj.EnumeratorDemo.java
private static void demoOfSupplier(String pre) { final MutableInt it = new MutableInt(1); final Supplier<Optional<Integer>> supl = () -> { final int val = it.getValue(); if (val > 3) { return Optional.empty(); }/* www .j av a 2 s. co m*/ it.add(1); return Optional.of(val); }; final Enumerator<Integer> en = Enumerator.of(supl); printLn(Enumerator.of(supl), "Elements in supplied enumerator:", pre); }
From source file:com.addthis.hydra.data.util.JSONFetcher.java
private byte[] request(String url, MutableInt retry) throws URISyntaxException, IOException { if (retry.getValue() > 0) { log.info("Attempting to fetch {}. Retry {}", url, retry.getValue()); }/* w ww .j a v a2s . c o m*/ retry.increment(); try { return HttpUtil.httpGet(url, timeout).getBody(); } catch (URISyntaxException u) { log.error("URISyntaxException on url {}", url, u); throw u; } }
From source file:com.addthis.hydra.task.output.HttpOutputWriter.java
@Nonnull private Integer request(String[] endpoints, String body, MutableInt retry) throws IOException { rotation = (rotation + 1) % endpoints.length; String endpoint = endpoints[rotation]; if (retry.getValue() > 0) { log.info("Attempting to send to {}. Retry {}", endpoint, retry.getValue()); }/* w w w . j a va 2s. c o m*/ retry.increment(); CloseableHttpResponse response = null; try { HttpEntity entity = new StringEntity(body, ContentType.APPLICATION_JSON); HttpUriRequest request = buildRequest(requestType, endpoint, entity); response = httpClient.execute(request); EntityUtils.consume(response.getEntity()); return response.getStatusLine().getStatusCode(); } finally { if (response != null) { response.close(); } } }
From source file:com.mgmtp.jfunk.data.excel.ExcelDataSource.java
@Override public boolean hasMoreData(final String dataSetKey) { for (ExcelFile excelFile : getExcelFiles()) { Map<String, List<Map<String, String>>> data = excelFile.getData(); List<Map<String, String>> dataList = data.get(dataSetKey); if (dataList != null) { MutableInt counter = dataSetIndices.get(dataSetKey); int size = dataList.size(); return counter == null && size > 0 || size > counter.getValue(); }/*w w w . ja va 2 s. c o m*/ } return false; }
From source file:io.cloudslang.lang.cli.services.ConsolePrinterImplTest.java
@Test public void testConsolePrint() throws Exception { final List<Runnable> runnableList = new ArrayList<>(); final MutableInt mutableInt = new MutableInt(0); doAnswer(new Answer() { @Override// w w w . j a v a 2 s . co m public Object answer(InvocationOnMock invocationOnMock) throws Throwable { mutableInt.increment(); Object[] arguments = invocationOnMock.getArguments(); runnableList.add((Runnable) arguments[0]); if (mutableInt.getValue() == 1) { return ConcurrentUtils.constantFuture("firstMessage"); } else if (mutableInt.getValue() == 2) { return ConcurrentUtils.constantFuture("secondMessage"); } else { return null; } } }).when(singleThreadExecutor).submit(Mockito.any(Runnable.class)); consolePrinter.printWithColor(GREEN, "firstMessage"); Future lastFuture = consolePrinter.printWithColor(GREEN, "secondMessage"); assertEquals("secondMessage", lastFuture.get()); assertEquals(2, runnableList.size()); assertTrue(runnableList.get(0) instanceof ConsolePrinterImpl.ConsolePrinterRunnable); assertTrue(runnableList.get(1) instanceof ConsolePrinterImpl.ConsolePrinterRunnable); assertEquals(new ConsolePrinterImpl.ConsolePrinterRunnable(GREEN, "firstMessage"), runnableList.get(0)); assertEquals(new ConsolePrinterImpl.ConsolePrinterRunnable(GREEN, "secondMessage"), runnableList.get(1)); }
From source file:io.cloudslang.lang.logging.LoggingServiceImplTest.java
@Test public void testLogEventWithTwoParams() { final List<Runnable> runnableList = new ArrayList<>(); final MutableInt mutableInt = new MutableInt(0); doAnswer(new Answer() { @Override/*from w w w . j a va2s . c om*/ public Object answer(InvocationOnMock invocationOnMock) throws Throwable { mutableInt.increment(); Object[] arguments = invocationOnMock.getArguments(); runnableList.add((Runnable) arguments[0]); if (mutableInt.getValue() == 1) { return ConcurrentUtils.constantFuture("aaa"); } else if (mutableInt.getValue() == 2) { return ConcurrentUtils.constantFuture("bbb"); } else { return null; } } }).when(singleThreadExecutor).submit(Mockito.any(Runnable.class)); // Tested calls loggingService.logEvent(Level.INFO, "aaa"); loggingService.logEvent(Level.ERROR, "bbb"); assertEquals(2, runnableList.size()); assertTrue(runnableList.get(0) instanceof LoggingServiceImpl.LoggingDetailsRunnable); assertTrue(runnableList.get(1) instanceof LoggingServiceImpl.LoggingDetailsRunnable); assertEquals(new LoggingServiceImpl.LoggingDetailsRunnable(Level.INFO, "aaa"), runnableList.get(0)); assertEquals(new LoggingServiceImpl.LoggingDetailsRunnable(Level.ERROR, "bbb"), runnableList.get(1)); }
From source file:com.mgmtp.jfunk.data.excel.ExcelDataSource.java
/** * Goes through all configured Excel files until data for the specified key is found. All sheets * of a file a check before the next file is considered. *///from www . j a v a 2s. com @Override protected DataSet getNextDataSetImpl(final String dataSetKey) { for (ExcelFile excelFile : getExcelFiles()) { Map<String, List<Map<String, String>>> data = excelFile.getData(); List<Map<String, String>> dataList = data.get(dataSetKey); if (dataList != null) { MutableInt counter = dataSetIndices.get(dataSetKey); if (counter == null) { counter = new MutableInt(0); dataSetIndices.put(dataSetKey, counter); } if (counter.getValue() >= dataList.size()) { // no more data available return null; } // turn data map into a data set Map<String, String> dataMap = dataList.get(counter.getValue()); DataSet dataSet = new DefaultDataSet(dataMap); // advance the counter for the next dataset counter.increment(); return dataSet; } } return null; }
From source file:com.norconex.jefmon.instances.InstancesPanel.java
private ListView<JobState> createJobStateListView(final InstanceSummary instance) { return new ListView<JobState>("statuses", Arrays.asList(STATUSES)) { private static final long serialVersionUID = -716585245859081922L; @Override//w w w. java 2 s . c o m protected void populateItem(ListItem<JobState> item) { JobState status = item.getModelObject(); MutableInt count = instance.getStatuses().get(status); if (count == null) { count = new MutableInt(0); } String css = ""; if (instance.isInvalid()) { css = "fa fa-exclamation-circle nx-jef-status-error"; } else if (status == null || count.getValue() == 0) { css = "jef-tree-job-blank"; } else { switch (status) { case COMPLETED: css = "fa fa-check-circle nx-jef-status-ok"; break; case RUNNING: css = "fa fa-spinner fa-spin nx-jef-status-running"; break; default: css = "fa fa-exclamation-circle nx-jef-status-error"; break; } } Label icon = new Label("statusIcon"); icon.add(new CssClass(css)); String countLabel = count.toString(); if (instance.isInvalid()) { icon.setVisible(false); countLabel = StringUtils.EMPTY; } item.add(new Label("statusCount", countLabel)); item.add(icon); } }; }
From source file:com.ibm.jaggr.core.impl.cache.GzipCacheImplTest.java
@Test public void testGetInputStream() throws Exception { GzipCacheImpl impl = new GzipCacheImpl(); EasyMock.replay(mockAggregator, mockCacheManager); impl.setAggregator(mockAggregator);/* www . j av a2 s .co m*/ MutableInt retLength = new MutableInt(); // Get the input stream. Should be a ByteArrayInputStream until // the async thread waiting on latch1 gets to write the cache file. InputStream is = impl.getInputStream("key", tempfile.toURI(), retLength); Assert.assertTrue(is instanceof ByteArrayInputStream); // Validate the gzipped data Assert.assertEquals(testData, unzipInputStream(is, retLength.getValue())); // Validate the cache entry fields IGzipCache.ICacheEntry cacheEntry = impl.get("key"); Assert.assertNotNull(Whitebox.getInternalState(cacheEntry, "bytes")); Assert.assertEquals(Long.valueOf(tempfile.lastModified()), (Long) Whitebox.getInternalState(cacheEntry, "lastModified")); Assert.assertNull(Whitebox.getInternalState(cacheEntry, "ex")); Assert.assertNull(Whitebox.getInternalState(cacheEntry, "file")); // Request the input stream again. Make sure we get a new ByteArrayInputStream // to the same content. is = impl.getInputStream("key", tempfile.toURI(), retLength); Assert.assertTrue(is instanceof ByteArrayInputStream); Assert.assertEquals(testData, unzipInputStream(is, retLength.getValue())); // now release the cache file writer thread and wait for it to complete latch1.countDown(); latch2.await(); // The input stream this time should be a FileInputStream is = impl.getInputStream("key", tempfile.toURI(), retLength); Assert.assertTrue(is instanceof FileInputStream); // validate the data Assert.assertEquals(testData, unzipInputStream(is, retLength.getValue())); // validate the cache entry to make sure the fields were updated as expected Assert.assertSame(cacheEntry, impl.get("key")); Assert.assertNull(Whitebox.getInternalState(cacheEntry, "bytes")); Assert.assertNull(Whitebox.getInternalState(cacheEntry, "ex")); File cacheFile = (File) Whitebox.getInternalState(cacheEntry, "file"); Assert.assertTrue(cacheFile.getName().startsWith("source.gzip.")); Assert.assertTrue(cacheFile.getName().endsWith(".cache")); Assert.assertEquals(tempfile.lastModified(), cacheFile.lastModified()); }
From source file:de.sanandrew.mods.turretmod.client.gui.tcu.GuiTcuHelper.java
void initGui(IGuiTcuInst<?> gui) { this.tabs.clear(); MutableInt currIndex = new MutableInt(0); GuiTcuRegistry.GUI_RESOURCES.forEach(location -> { GuiTcuRegistry.GuiEntry entry = GuiTcuRegistry.INSTANCE.getGuiEntry(location); if (entry != null && entry.showTab(gui)) { GuiButton btn = new GuiButtonTcuTab(gui.getNewButtonId(), 0, gui.getPosY() + 213, entry.getIcon(), Lang.translate(/*w ww. j a v a 2 s . co m*/ Lang.TCU_PAGE_TITLE.get(location.getResourceDomain(), location.getResourcePath()))); btn.visible = false; btn.enabled = !location.equals(gui.getRegistryKey()); if (btn.enabled && (currIndex.getValue() < currTabScroll || currIndex.getValue() >= currTabScroll + MAX_TABS)) { currTabScroll = Math.min(Math.max(currIndex.getValue() - MathHelper.floor(MAX_TABS / 2.0F), 0), this.tabs.size() - MAX_TABS + 1); } gui.addNewButton(btn); this.tabs.put(btn, location); currIndex.increment(); } }); this.tabNavLeft = gui.addNewButton(new GuiButtonIcon(gui.getNewButtonId(), 0, gui.getPosY() + 213, 18, 0, Resources.GUI_TCU_BUTTONS.getResource(), "")); this.tabNavLeft.visible = false; this.tabNavRight = gui.addNewButton(new GuiButtonIcon(gui.getNewButtonId(), 0, gui.getPosY() + 213, 36, 0, Resources.GUI_TCU_BUTTONS.getResource(), "")); this.tabNavRight.visible = false; }