List of usage examples for org.apache.commons.collections.map LinkedMap isEmpty
public boolean isEmpty()
From source file:de.innovationgate.wgpublisher.webtml.portlet.TMLPortletStateSessionStorage.java
@Override public TMLPortletState getState(TMLPortlet portlet) throws WGAPIException { String completeKey = getSessionContextKey(portlet); synchronized (_session) { // Get - conditionally create session context map Map<String, TMLPortletState> contexts = getSessionMap(); // Get - conditionally create individual session context TMLPortletState context = (TMLPortletState) contexts.get(completeKey); if (context == null) { context = portlet.createState(this); // Set event index to current last index, so events fired before creation of this context are not executed for it LinkedMap list = TMLPortlet.getFiredEventsQueue(_session); if (!list.isEmpty()) { PortletEvent event = (PortletEvent) list.get(list.lastKey()); context.setLastProcessedEventIndex(event.getIndex()); }/* w w w . j av a 2 s . c o m*/ contexts.put(completeKey, context); } return context; } }
From source file:net.rptools.maptool.client.ui.ChatTypingNotification.java
/** * This component is only made visible when there are notifications to be displayed. That means the first couple of * IF statements in this method are redundant since paintComponent() will not be called unless the component is * visible, and it will only be visible when there are notifications... *//*from w w w.j ava2s . com*/ @Override protected void paintComponent(Graphics g) { // System.out.println("Chat panel is painting itself..."); if (AppPreferences.getTypingNotificationDuration() == 0) { return; } LinkedMap chatTypers = MapTool.getFrame().getChatNotificationTimers().getChatTypers(); if (chatTypers == null || chatTypers.isEmpty()) { return; } Boolean showBackground = AppPreferences.getChatNotificationShowBackground(); Graphics2D statsG = (Graphics2D) g.create(); Font boldFont = AppStyle.labelFont.deriveFont(Font.BOLD); Font font = AppStyle.labelFont; FontMetrics valueFM = g.getFontMetrics(font); FontMetrics keyFM = g.getFontMetrics(boldFont); int PADDING7 = 7; int PADDING3 = 3; int PADDING2 = 2; BufferedImage img = AppStyle.panelTexture; int rowHeight = Math.max(valueFM.getHeight(), keyFM.getHeight()); setBorder(null); int width = AppStyle.miniMapBorder.getRightMargin() + AppStyle.miniMapBorder.getLeftMargin(); int height = getHeight() - PADDING2 + AppStyle.miniMapBorder.getTopMargin() + AppStyle.miniMapBorder.getBottomMargin(); statsG.setFont(font); SwingUtil.useAntiAliasing(statsG); Rectangle bounds = new Rectangle(AppStyle.miniMapBorder.getLeftMargin(), height - getHeight() - AppStyle.miniMapBorder.getTopMargin(), getWidth() - width, getHeight() - AppStyle.miniMapBorder.getBottomMargin() - AppStyle.miniMapBorder.getTopMargin() + PADDING2); int y = bounds.y + rowHeight; rowHeight = Math.max(rowHeight, AppStyle.chatImage.getHeight()); setSize(getWidth(), ((chatTypers.size() * (PADDING3 + rowHeight)) + AppStyle.miniMapBorder.getTopMargin() + AppStyle.miniMapBorder.getBottomMargin())); if (showBackground) { g.drawImage(img, 0, 0, getWidth(), getHeight() + PADDING7, this); AppStyle.miniMapBorder.paintAround(statsG, bounds); } Rectangle rightRow = new Rectangle(AppStyle.miniMapBorder.getLeftMargin() + PADDING7, AppStyle.miniMapBorder.getTopMargin() + PADDING7, AppStyle.chatImage.getWidth(), AppStyle.chatImage.getHeight()); Set<?> keySet = chatTypers.keySet(); @SuppressWarnings("unchecked") Set<String> playerTimers = (Set<String>) keySet; for (String playerNamer : playerTimers) { if (showBackground) { statsG.setColor(new Color(249, 241, 230, 140)); statsG.fillRect(bounds.x + PADDING3, y - keyFM.getAscent(), (bounds.width - PADDING7 / 2) - PADDING3, rowHeight); statsG.setColor(new Color(175, 163, 149)); statsG.drawRect(bounds.x + PADDING3, y - keyFM.getAscent(), (bounds.width - PADDING7 / 2) - PADDING3, rowHeight); } g.drawImage(AppStyle.chatImage, bounds.x + 5, y - keyFM.getAscent(), (int) rightRow.getWidth(), (int) rightRow.getHeight(), this); // Values statsG.setColor(MapTool.getFrame().getChatTypingLabelColor()); statsG.setFont(boldFont); statsG.drawString(I18N.getText("msg.commandPanel.liveTyping", playerNamer), bounds.x + AppStyle.chatImage.getWidth() + PADDING7 * 2, y + 5); y += PADDING2 + rowHeight; } if (showBackground) { AppStyle.shadowBorder.paintWithin(statsG, bounds); } else { setOpaque(false); } }
From source file:org.apache.flink.streaming.connectors.kafka.KafkaConsumerTest.java
@Test public void testSnapshot() { try {//from ww w. j a v a 2 s . com Field offsetsField = FlinkKafkaConsumerBase.class.getDeclaredField("offsetsState"); Field runningField = FlinkKafkaConsumerBase.class.getDeclaredField("running"); Field mapField = FlinkKafkaConsumerBase.class.getDeclaredField("pendingCheckpoints"); offsetsField.setAccessible(true); runningField.setAccessible(true); mapField.setAccessible(true); FlinkKafkaConsumer08<?> consumer = mock(FlinkKafkaConsumer08.class); when(consumer.snapshotState(anyLong(), anyLong())).thenCallRealMethod(); HashMap<KafkaTopicPartition, Long> testOffsets = new HashMap<>(); long[] offsets = new long[] { 43, 6146, 133, 16, 162, 616 }; int j = 0; for (long i : offsets) { KafkaTopicPartition ktp = new KafkaTopicPartition("topic", j++); testOffsets.put(ktp, i); } LinkedMap map = new LinkedMap(); offsetsField.set(consumer, testOffsets); runningField.set(consumer, true); mapField.set(consumer, map); assertTrue(map.isEmpty()); // make multiple checkpoints for (long checkpointId = 10L; checkpointId <= 2000L; checkpointId += 9L) { HashMap<KafkaTopicPartition, Long> checkpoint = consumer.snapshotState(checkpointId, 47 * checkpointId); assertEquals(testOffsets, checkpoint); // change the offsets, make sure the snapshot did not change HashMap<KafkaTopicPartition, Long> checkpointCopy = (HashMap<KafkaTopicPartition, Long>) checkpoint .clone(); for (Map.Entry<KafkaTopicPartition, Long> e : testOffsets.entrySet()) { testOffsets.put(e.getKey(), e.getValue() + 1); } assertEquals(checkpointCopy, checkpoint); assertTrue(map.size() > 0); assertTrue(map.size() <= FlinkKafkaConsumer08.MAX_NUM_PENDING_CHECKPOINTS); } } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }