List of usage examples for java.util LinkedList get
public E get(int index)
From source file:net.noio.Reminder.NotificationService.java
@Override protected void onHandleIntent(Intent intent) { Log.v("NotificationService", "Starting NotificationService run"); LinkedList<String[]> list; list = ReminderDB.getReminderTimes(getApplicationContext()); long system_time = System.currentTimeMillis(); // Alarm notification AlarmManager ream = (AlarmManager) getSystemService(Context.ALARM_SERVICE); PendingIntent repi = PendingIntent.getService(this, 6600, intent, 0); ream.set(AlarmManager.RTC_WAKEUP, system_time + 60000, repi); for (int i = 0; i < list.size(); i++) { String[] data = list.get(i); if (data[2].equals("N")) { long delta = Long.parseLong(data[1]) - System.currentTimeMillis(); Log.v("NotificationService", "TIME REMAINING: " + delta); Log.v("NotificationService", "1 HOUR: " + this.ONE_HOUR * 1000); Log.v("NotificationService", "6 HOUR: " + this.SIX_HOUR * 1000); Log.v("NotificationService", "12 HOUR: " + this.TWELVE_HOUR * 1000); Log.v("NotificationService", "24 HOUR: " + this.TWENTYFOUR_HOUR * 1000); Log.v("NotificationService", "In reminder loop"); Intent intent1 = new Intent(this, MainActivity.class); intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (delta < this.ONE_HOUR * 1000) { Log.v("NotificationService", "IN 1"); if (ReminderDB.checkNotify(getApplicationContext(), 1, data[0])) { System.out.println("IN 1b"); intent1.putExtra("string", data[0]); intent1.putExtra("reminder", "One-hour Reminder"); intent1.putExtra("id", Integer.parseInt(10 + ReminderDB.getID(getApplicationContext(), data[0]))); this.Notify(intent1); ReminderDB.disableNotification(getApplicationContext(), 1, data[0]); }/*ww w . j a va 2 s.com*/ } else if (delta < this.SIX_HOUR * 1000 && delta > this.ONE_HOUR * 1000) { Log.v("NotificationService", "IN 6"); if (ReminderDB.checkNotify(getApplicationContext(), 2, data[0])) { intent1.putExtra("string", data[0]); intent1.putExtra("reminder", "Six-hour Reminder"); intent1.putExtra("id", Integer.parseInt(10 + ReminderDB.getID(getApplicationContext(), data[0]))); this.Notify(intent1); ReminderDB.disableNotification(getApplicationContext(), 2, data[0]); } } else if (delta < this.TWELVE_HOUR * 1000 && delta > this.SIX_HOUR * 1000) { Log.v("NotificationService", "IN 12"); if (ReminderDB.checkNotify(getApplicationContext(), 3, data[0])) { intent1.putExtra("string", data[0]); intent1.putExtra("reminder", "Twelve-hour Reminder"); intent1.putExtra("id", Integer.parseInt(10 + ReminderDB.getID(getApplicationContext(), data[0]))); this.Notify(intent1); ReminderDB.disableNotification(getApplicationContext(), 3, data[0]); } } else if (delta < this.TWENTYFOUR_HOUR * 1000 && delta > this.TWELVE_HOUR * 1000) { Log.v("NotificationService", "IN 24"); if (ReminderDB.checkNotify(getApplicationContext(), 4, data[0])) { intent1.putExtra("string", data[0]); intent1.putExtra("reminder", "Twentyfour-hour Reminder"); intent1.putExtra("id", Integer.parseInt(10 + ReminderDB.getID(getApplicationContext(), data[0]))); this.Notify(intent1); ReminderDB.disableNotification(getApplicationContext(), 4, data[0]); } } } else if (data[2].equals("Y")) { // every minute if (data[3].equals("Y")) { Log.v("NotificationService", "Every minute reminder for " + data[0]); intent.putExtra("string", data[0]); intent.putExtra("reminder", "Every minute reminder"); intent.putExtra("id", Integer.parseInt(10 + ReminderDB.getID(getApplicationContext(), data[0]))); this.Notify(intent); } // every hour if (data[4].equals("Y")) { // fix to be hourly Log.v("NotificationService", "Hourly reminder for " + data[0]); if (this.loopcounter == 60) { this.loopcounter = 0; intent.putExtra("string", data[0]); intent.putExtra("reminder", "Hourly reminder"); intent.putExtra("id", Integer.parseInt(10 + ReminderDB.getID(getApplicationContext(), data[0]))); this.Notify(intent); } this.loopcounter += 1; } } } Log.v("NotificationService", "Ending NotificationService run"); }
From source file:util.method.java
public static boolean isIDInVMList(String ID, LinkedList<VM> VMList) { if (VMList == null) return false; for (int i = 0; i < VMList.size(); i++) { if (VMList.get(i).getID().equals(ID)) return true; }//from w ww. j av a2 s . c om return false; }
From source file:de.vandermeer.asciitable.AT_Renderer.java
/** * Renders an {@link AsciiTable}.//from w w w.j a v a 2 s . c o m * @param rows table rows to render, cannot be null * @param colNumbers number of columns in the table * @param ctx context of the original table with relevant settings, cannot be null * @param width maximum line width, excluding any extra padding * @return collection of lines, each as a {@link StrBuilder} * @throws {@link NullPointerException} if rows or context where null */ default Collection<StrBuilder> renderAsCollection(LinkedList<AT_Row> rows, int colNumbers, AT_Context ctx, int width) { Validate.notNull(rows); Validate.notNull(ctx); ArrayList<Object> table = new ArrayList<>(); int[] colWidth = this.getCWC().calculateColumnWidths(rows, colNumbers, ctx.getTextWidth(width)); for (AT_Row row : rows) { int ruleset = 0; switch (row.getStyle()) { case NORMAL: ruleset = TA_GridConfig.RULESET_NORMAL; break; case STRONG: ruleset = TA_GridConfig.RULESET_STRONG; break; case LIGHT: ruleset = TA_GridConfig.RULESET_LIGHT; break; case HEAVY: ruleset = TA_GridConfig.RULESET_HEAVY; break; case UNKNOWN: throw new AsciiTableException("AT_Renderer: cannot render unknown row style", "table row style set to 'unknown'"); default: throw new AsciiTableException("AT_Renderer: cannot render unknown row style", "table row style not specified or type not processed"); } switch (row.getType()) { case RULE: table.add(ruleset); break; case CONTENT: String[][] cAr = new String[colNumbers][]; LinkedList<AT_Cell> cells = row.getCells(); if (cells == null) { throw new AsciiTableException("cannot render table", "row content (cells) was null"); } int length = 0; for (int i = 0; i < cells.size(); i++) { length += colWidth[i]; Object content = cells.get(i).getContent(); if (content == null) { length++; continue; } int realWidth = length; length -= cells.get(i).getContext().getPaddingLeft(); length -= cells.get(i).getContext().getPaddingRight(); if (content instanceof RendersToClusterWidth) { cAr[i] = ((RendersToClusterWidth) content).renderAsArray(length); } if (content instanceof DoesRenderToWidth) { cAr[i] = new StrTokenizer(((DoesRenderToWidth) content).render(length)) .setDelimiterChar('\n').setIgnoreEmptyTokens(false).getTokenArray(); } else { //create text from cell object String text = Object_To_StrBuilder.convert(content).toString().replaceAll("\\s+", " "); //check for translators, use what is available if (cells.get(i).getContext().getTargetTranslator() != null) { if (cells.get(i).getContext().getTargetTranslator().getCombinedTranslator() != null) { text = cells.get(i).getContext().getTargetTranslator().getCombinedTranslator() .translate(text); } } else if (cells.get(i).getContext().getHtmlElementTranslator() != null) { text = cells.get(i).getContext().getHtmlElementTranslator().translateHtmlElements(text); } else if (cells.get(i).getContext().getCharTranslator() != null) { text = cells.get(i).getContext().getCharTranslator().translateCharacters(text); } Collection<StrBuilder> csb = Text_To_FormattedText .create(length, cells.get(i).getContext().getTextAlignment().getMapping(), TextFormat.NONE.getMapping(), null, null, null, 0, 0, null, 0, 0, null) .transform(text); for (StrBuilder sb : csb) { sb.insert(0, new StrBuilder().appendPadding(cells.get(i).getContext().getPaddingLeft(), cells.get(i).getContext().getPaddingLeftChar())); sb.appendPadding(cells.get(i).getContext().getPaddingRight(), cells.get(i).getContext().getPaddingRightChar()); } for (int k = 0; k < cells.get(i).getContext().getPaddingTop(); k++) { ((ArrayList<StrBuilder>) csb).add(0, new StrBuilder().appendPadding(realWidth, cells.get(i).getContext().getPaddingTopChar())); } for (int k = 0; k < cells.get(i).getContext().getPaddingBottom(); k++) { ((ArrayList<StrBuilder>) csb).add(new StrBuilder().appendPadding(realWidth, cells.get(i).getContext().getPaddingBottomChar())); } cAr[i] = ClusterElementTransformer.create() .transform(csb, StrBuilder_To_String.create(), ArrayListStrategy.create()) .toArray(new String[0]); } length = 0; } cAr = Array2D_To_NormalizedArray.create(colNumbers).transform(cAr); cAr = Array2D_To_FlipArray.create().transform(cAr); table.add(Pair.of(ruleset, cAr)); break; case UNKNOWN: throw new AsciiTableException("AT_Renderer: cannot render unknown row type", "table row type set to 'unknown'"); default: throw new AsciiTableException("AT_Renderer: cannot render unknown row type", "table row type not specified or type not processed"); } } ArrayList<StrBuilder> ret = ctx.getGrid().addGrid(table, ctx.getGridTheme() | ctx.getGridThemeOptions()); int max = ret.get(0).length() + ctx.getFrameLeftMargin() + ctx.getFrameRightMargin(); for (StrBuilder sb : ret) { sb.insert(0, new StrBuilder().appendPadding(ctx.getFrameLeftMargin(), ctx.getFrameLeftChar())); sb.appendPadding(ctx.getFrameRightMargin(), ctx.getFrameRightChar()); } for (int k = 0; k < ctx.getFrameTopMargin(); k++) { ret.add(0, new StrBuilder().appendPadding(max, ctx.getFrameTopChar())); } for (int k = 0; k < ctx.getFrameBottomMargin(); k++) { ret.add(new StrBuilder().appendPadding(max, ctx.getFrameBottomChar())); } return ret; }
From source file:m.c.m.proxyma.context.ProxyFolderBean.java
/** * Add the a plugin to the specified list using the execution priority * to define the position of the plugin into the list. * @param pluginName the plugin name to add to the list * @param list the list to update.//w w w . j av a 2 s . com */ private void addPluginUsingExecutionPriority(String pluginName, String baseXPath, ConcurrentLinkedQueue<String> list) { String pluginPriorityXPath = baseXPath + "[@class='" + pluginName + "']/@executionPriority"; int pluginPriority = 0; try { pluginPriority = Integer.parseInt(context.getSingleValueParameter(pluginPriorityXPath)); } catch (Exception x) { log.warning("executionPiority not an integer in \"" + pluginPriorityXPath + "\""); } //put the new object in the correct position based upon its execution priority LinkedList<String> tmpList = new LinkedList(list); String currentPlugin = null; int currentPluginPriority = 0; boolean inserted = false; for (int i = 0; (i < tmpList.size() && !inserted); i++) { currentPlugin = tmpList.get(i); pluginPriorityXPath = baseXPath + "[@class='" + currentPlugin + "']/@executionPriority"; try { currentPluginPriority = Integer.parseInt(context.getSingleValueParameter(pluginPriorityXPath)); } catch (Exception x) { currentPluginPriority = 0; } if (pluginPriority < currentPluginPriority) { tmpList.add(i, pluginName); inserted = true; } } //If a place for the plugin was not found the plugin is addedd on the tail if (!inserted) tmpList.add(pluginName); //Update the thread-safe queue list.removeAll(tmpList); list.addAll(tmpList); }
From source file:org.jpos.space.HzlSpace.java
private Object getHead(Object key, boolean remove) { Object obj = null;/* ww w. j av a2 s . c o m*/ LinkedList<Object> l = this.entries.get(key); boolean wasExpirable = false; while (obj == null && l != null && l.size() > 0) { obj = l.get(0); if (obj == null) { l.remove(0); if (l.size() == 0) { entries.remove(key); } } } if (obj != null && remove) { l.remove(0); if (l.size() == 0) { this.entries.remove(key); if (wasExpirable) unregisterExpirable(key); } } this.entries.replace(key, l); return obj; }
From source file:ubic.BAMSandAllen.visualization.GraphFromABAMS.java
public DoubleMatrix<String, String> thresholdMatrix(DoubleMatrix<String, String> matrix, double fraction) { DoubleMatrix<String, String> result = matrix.copy(); LinkedList<Double> allValues = new LinkedList<Double>(); for (int i = 0; i < matrix.rows(); i++) { for (int j = 0; j < matrix.columns(); j++) { allValues.add(matrix.get(i, j)); }/*from w ww . j a va2 s . c om*/ } Collections.sort(allValues); double threshold = allValues.get((int) (fraction * allValues.size())); log.info("threshold:" + threshold); for (int i = 0; i < matrix.rows(); i++) { for (int j = 0; j < matrix.columns(); j++) { if (result.get(i, j) < threshold) { result.set(i, j, 0d); } } } return result; }
From source file:net.erdfelt.android.sdkfido.configer.ConfigCmdLineParser.java
public void parse(String[] args) throws CmdLineParseException { LinkedList<String> arglist = new LinkedList<String>(); arglist.addAll(Arrays.asList(args)); // Quick Help if (arglist.contains("--" + OPT_HELP)) { usage();//from ww w . j a v a 2s . c o m return; } // Configuration File Option int idx = arglist.indexOf("--" + OPT_CONFIG); if (idx >= 0) { if (idx + 1 > arglist.size()) { throw new CmdLineParseException("Expected <File> parameter for option: --" + OPT_CONFIG); } String value = arglist.get(idx + 1); File file = (File) ConvertUtils.convert(value, File.class); this.configer.setPersistFile(file); arglist.remove(idx + 1); arglist.remove(idx); } // Save Options Option boolean saveOptions = false; idx = arglist.indexOf("--" + OPT_SAVE); if (idx >= 0) { saveOptions = true; arglist.remove(idx); } // Restore from persist first. try { configer.restore(); } catch (IOException e) { throw new CmdLineParseException("Unable to load configuration: " + e.getMessage(), e); } // Set values from command line now. String value; ListIterator<String> iter = arglist.listIterator(); while (iter.hasNext()) { String arg = iter.next(); if (arg.startsWith("--")) { // Its an option. String optname = arg.substring(2); Configurable cfgrbl = configer.getConfigurable(optname); if (cfgrbl == null) { throw new CmdLineParseException("Invalid Option: " + arg); } if (!iter.hasNext()) { throw new CmdLineParseException( "Expected <" + cfgrbl.getType() + "> parameter for option: " + arg); } value = iter.next(); configer.setValue(optname, value); continue; // process next arg } // All others are considered args. addToRawArgs(arg); } // Save options (if specified) if (saveOptions) { try { configer.persist(); } catch (IOException e) { throw new CmdLineParseException("Unable to save configuration: " + e.getMessage(), e); } } }
From source file:org.apache.flink.streaming.connectors.kinesis.internals.ShardConsumerTest.java
@Test public void testCorrectNumOfCollectedRecordsAndUpdatedState() { KinesisStreamShard fakeToBeConsumedShard = new KinesisStreamShard("fakeStream", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(0)) .withHashKeyRange(new HashKeyRange().withStartingHashKey("0") .withEndingHashKey(new BigInteger(StringUtils.repeat("FF", 16), 16).toString()))); LinkedList<KinesisStreamShardState> subscribedShardsStateUnderTest = new LinkedList<>(); subscribedShardsStateUnderTest//from ww w . j a va 2 s .c o m .add(new KinesisStreamShardState(fakeToBeConsumedShard, new SequenceNumber("fakeStartingState"))); TestableKinesisDataFetcher fetcher = new TestableKinesisDataFetcher(Collections.singletonList("fakeStream"), new Properties(), 10, 2, new AtomicReference<Throwable>(), subscribedShardsStateUnderTest, KinesisDataFetcher.createInitialSubscribedStreamsToLastDiscoveredShardsState( Collections.singletonList("fakeStream")), Mockito.mock(KinesisProxyInterface.class)); new ShardConsumer<>(fetcher, 0, subscribedShardsStateUnderTest.get(0).getKinesisStreamShard(), subscribedShardsStateUnderTest.get(0).getLastProcessedSequenceNum(), FakeKinesisBehavioursFactory.totalNumOfRecordsAfterNumOfGetRecordsCalls(1000, 9)).run(); assertTrue(fetcher.getNumOfElementsCollected() == 1000); assertTrue(subscribedShardsStateUnderTest.get(0).getLastProcessedSequenceNum() .equals(SentinelSequenceNumber.SENTINEL_SHARD_ENDING_SEQUENCE_NUM.get())); }
From source file:org.apache.flink.streaming.connectors.kinesis.internals.ShardConsumerTest.java
@Test public void testCorrectNumOfCollectedRecordsAndUpdatedStateWithUnexpectedExpiredIterator() { KinesisStreamShard fakeToBeConsumedShard = new KinesisStreamShard("fakeStream", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(0)) .withHashKeyRange(new HashKeyRange().withStartingHashKey("0") .withEndingHashKey(new BigInteger(StringUtils.repeat("FF", 16), 16).toString()))); LinkedList<KinesisStreamShardState> subscribedShardsStateUnderTest = new LinkedList<>(); subscribedShardsStateUnderTest/*from ww w. j a va 2 s .co m*/ .add(new KinesisStreamShardState(fakeToBeConsumedShard, new SequenceNumber("fakeStartingState"))); TestableKinesisDataFetcher fetcher = new TestableKinesisDataFetcher(Collections.singletonList("fakeStream"), new Properties(), 10, 2, new AtomicReference<Throwable>(), subscribedShardsStateUnderTest, KinesisDataFetcher.createInitialSubscribedStreamsToLastDiscoveredShardsState( Collections.singletonList("fakeStream")), Mockito.mock(KinesisProxyInterface.class)); new ShardConsumer<>(fetcher, 0, subscribedShardsStateUnderTest.get(0).getKinesisStreamShard(), subscribedShardsStateUnderTest.get(0).getLastProcessedSequenceNum(), // Get a total of 1000 records with 9 getRecords() calls, // and the 7th getRecords() call will encounter an unexpected expired shard iterator FakeKinesisBehavioursFactory .totalNumOfRecordsAfterNumOfGetRecordsCallsWithUnexpectedExpiredIterator(1000, 9, 7)).run(); assertTrue(fetcher.getNumOfElementsCollected() == 1000); assertTrue(subscribedShardsStateUnderTest.get(0).getLastProcessedSequenceNum() .equals(SentinelSequenceNumber.SENTINEL_SHARD_ENDING_SEQUENCE_NUM.get())); }
From source file:org.eclipse.wb.internal.swing.model.layout.gbl.DimensionOperations.java
/** * @return the {@link ClipboardCommand} for copying dimensions information. *///from ww w . j ava 2 s.co m public ClipboardCommand getClipboardCommand() { LinkedList<T> dimensions = getDimensions(); final boolean forColumns = this instanceof DimensionOperationsColumn; final int count = dimensions.size(); final int[] sizeArray = new int[count]; final double[] weightArray = new double[count]; for (int i = 0; i < count; i++) { T dimension = dimensions.get(i); sizeArray[i] = dimension.getSize(); weightArray[i] = dimension.getWeight(); } // create command return new ComponentClipboardCommand<ContainerInfo>() { private static final long serialVersionUID = 0L; @Override @SuppressWarnings("unchecked") protected void execute(ContainerInfo container) throws Exception { AbstractGridBagLayoutInfo layout = (AbstractGridBagLayoutInfo) container.getLayout(); DimensionOperations<T> operations = (DimensionOperations<T>) (forColumns ? layout.getColumnOperations() : layout.getRowOperations()); operations.prepare(count - 1, false); LinkedList<T> dimensions = operations.getDimensions(); for (int i = 0; i < count; i++) { T dimension = dimensions.get(i); dimension.setSize(sizeArray[i]); dimension.setWeight(weightArray[i]); } } }; }