Example usage for java.util ListIterator previous

List of usage examples for java.util ListIterator previous

Introduction

In this page you can find the example usage for java.util ListIterator previous.

Prototype

E previous();

Source Link

Document

Returns the previous element in the list and moves the cursor position backwards.

Usage

From source file:com.psiphon3.psiphonlibrary.StatusList.java

/**
 * @return Returns the last non-DEBUG, non-WARN(ing) item, or null if there is none.
 */// w ww  . j a  v a2s.  com
public static StatusEntry getLastStatusEntryForDisplay() {
    synchronized (m_statusHistory) {
        ListIterator<StatusEntry> iterator = m_statusHistory.listIterator(m_statusHistory.size());

        while (iterator.hasPrevious()) {
            StatusEntry current_item = iterator.previous();
            if (current_item.priority() != Log.DEBUG && current_item.priority() != Log.WARN) {
                return current_item;
            }
        }

        return null;
    }
}

From source file:com.qualogy.qafe.core.errorhandling.ErrorProcessor.java

private static void goBackToItemPosition(ListIterator<? extends Item> itrItem, Item targetItem,
        ApplicationContext context, Window window) {
    if (itrItem != null) {
        boolean found = false;
        while (itrItem.hasPrevious()) {
            Item item = itrItem.previous();
            if (item == targetItem) {
                found = true;// w  ww .j  av  a  2s .c  o  m
            } else if (item instanceof EventRef) {
                found = containsItem((EventRef) item, targetItem, context, window);
            }
            if (found) {
                itrItem.next();
                break;
            }
        }
    }
}

From source file:Alias2.java

public static void verify(List output, List expected) {
    verifyLength(output.size(), expected.size(), Test.EXACT);
    if (!expected.equals(output)) {
        //find the line of mismatch
        ListIterator it1 = expected.listIterator();
        ListIterator it2 = output.listIterator();
        while (it1.hasNext() && it2.hasNext() && it1.next().equals(it2.next()))
            ;/*ww  w. java  2  s.  co  m*/
        throw new LineMismatchException(it1.nextIndex(), it1.previous().toString(), it2.previous().toString());
    }
}

From source file:com.projity.algorithm.buffer.GroupedCalculatedValues.java

public static GroupedCalculatedValues union(GroupedCalculatedValues values1, GroupedCalculatedValues values2) {
    GroupedCalculatedValues c1, c2;/* w  w  w.  j av  a  2s.  c om*/
    if (values1.size() >= values2.size()) {
        c1 = values1;
        c2 = values2;
    } else {
        c1 = values2;
        c2 = values1;
    }
    GroupedCalculatedValues c = new GroupedCalculatedValues();
    ListIterator i1 = c1.values.listIterator();
    ListIterator i2 = c2.values.listIterator();
    Point p1, p2 = null;
    while (i1.hasNext()) {
        p1 = (Point) i1.next();
        while (i2.hasNext()) {
            p2 = (Point) i2.next();
            if (p2.date < p1.date) {
                c.values.add(p2);
            } else if (p2.date > p1.date) {
                i2.previous();
                break;
            } else
                break;
        }
        if (p2 != null && p1.date == p2.date)
            c.values.add(new Point(p1.date, p1.value + p2.value));
        else
            c.values.add(p1);
    }
    while (i2.hasNext()) {
        c.values.add((Point) i2.next());
    }
    return c;
}

From source file:org.smssecure.smssecure.notifications.MessageNotifier.java

private static void sendSingleThreadNotification(Context context, MasterSecret masterSecret,
        NotificationState notificationState, int flags, boolean bundled) {
    if (notificationState.getNotifications().isEmpty()) {
        if (!bundled)
            cancelActiveNotifications(context);
        return;/*w w  w . j a  va 2s  . c  o  m*/
    }

    SingleRecipientNotificationBuilder builder = new SingleRecipientNotificationBuilder(context, masterSecret,
            SilencePreferences.getNotificationPrivacy(context));
    List<NotificationItem> notifications = notificationState.getNotifications();
    Recipients recipients = notifications.get(0).getRecipients();
    int notificationId = (int) (SUMMARY_NOTIFICATION_ID + (bundled ? notifications.get(0).getThreadId() : 0));

    builder.setThread(notifications.get(0).getRecipients());
    builder.setMessageCount(notificationState.getMessageCount());
    builder.setPrimaryMessageBody(recipients, notifications.get(0).getIndividualRecipient(),
            notifications.get(0).getText(), notifications.get(0).getSlideDeck());
    builder.setContentIntent(notifications.get(0).getPendingIntent(context));
    builder.setGroup(NOTIFICATION_GROUP);
    builder.setDeleteIntent(notificationState.getDeleteIntent(context));

    long timestamp = notifications.get(0).getTimestamp();
    if (timestamp != 0)
        builder.setWhen(timestamp);

    builder.addActions(masterSecret, notificationState.getMarkAsReadIntent(context, notificationId),
            notificationState.getQuickReplyIntent(context, notifications.get(0).getRecipients()),
            notificationState.getRemoteReplyIntent(context, notifications.get(0).getRecipients()));

    ListIterator<NotificationItem> iterator = notifications.listIterator(notifications.size());

    while (iterator.hasPrevious()) {
        NotificationItem item = iterator.previous();
        builder.addMessageBody(item.getRecipients(), item.getIndividualRecipient(), item.getText());
    }

    if (notificationsRequested(flags)) {
        triggerNotificationAlarms(builder, notificationState, flags);

        builder.setTicker(notifications.get(0).getIndividualRecipient(), notifications.get(0).getText());
    }

    if (!bundled) {
        builder.setGroupSummary(true);
    }

    NotificationManagerCompat.from(context).notify(notificationId, builder.build());
}

From source file:org.thoughtcrime.SMP.notifications.MessageNotifier.java

private static void sendMultipleThreadNotification(Context context, MasterSecret masterSecret,
        NotificationState notificationState, boolean signal) {
    List<NotificationItem> notifications = notificationState.getNotifications();
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    builder.setColor(context.getResources().getColor(R.color.textsecure_primary));
    builder.setSmallIcon(R.drawable.icon_notification);
    builder.setContentTitle(context.getString(R.string.app_name));
    builder.setSubText(context.getString(R.string.MessageNotifier_d_messages_in_d_conversations,
            notificationState.getMessageCount(), notificationState.getThreadCount()));
    builder.setContentText(context.getString(R.string.MessageNotifier_most_recent_from_s,
            notifications.get(0).getIndividualRecipientName()));
    builder.setContentIntent(/*from w w w  .  jav a  2s  .c  o  m*/
            PendingIntent.getActivity(context, 0, new Intent(context, ConversationListActivity.class), 0));

    builder.setContentInfo(String.valueOf(notificationState.getMessageCount()));
    builder.setNumber(notificationState.getMessageCount());
    builder.setCategory(NotificationCompat.CATEGORY_MESSAGE);

    long timestamp = notifications.get(0).getTimestamp();
    if (timestamp != 0)
        builder.setWhen(timestamp);

    builder.setDeleteIntent(
            PendingIntent.getBroadcast(context, 0, new Intent(DeleteReceiver.DELETE_REMINDER_ACTION), 0));

    if (masterSecret != null) {
        Action markAllAsReadAction = new Action(R.drawable.check,
                context.getString(R.string.MessageNotifier_mark_all_as_read),
                notificationState.getMarkAsReadIntent(context, masterSecret));
        builder.addAction(markAllAsReadAction);
        builder.extend(new NotificationCompat.WearableExtender().addAction(markAllAsReadAction));
    }

    InboxStyle style = new InboxStyle();

    ListIterator<NotificationItem> iterator = notifications.listIterator(notifications.size());
    while (iterator.hasPrevious()) {
        NotificationItem item = iterator.previous();
        style.addLine(item.getTickerText());
        if (item.getIndividualRecipient().getContactUri() != null) {
            builder.addPerson(item.getIndividualRecipient().getContactUri().toString());
        }
    }

    builder.setStyle(style);

    setNotificationAlarms(context, builder, signal, notificationState.getRingtone(),
            notificationState.getVibrate());

    if (signal) {
        builder.setTicker(notifications.get(0).getTickerText());
    }

    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID,
            builder.build());
}

From source file:org.thoughtcrime.SMP.notifications.MessageNotifier.java

private static void sendSingleThreadNotification(Context context, MasterSecret masterSecret,
        NotificationState notificationState, boolean signal) {
    if (notificationState.getNotifications().isEmpty()) {
        ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).cancel(NOTIFICATION_ID);
        return;//from  w  ww .ja  v a  2 s. c  o  m
    }

    List<NotificationItem> notifications = notificationState.getNotifications();
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    Recipient recipient = notifications.get(0).getIndividualRecipient();
    Drawable recipientPhoto = recipient.getContactPhoto();
    int largeIconTargetSize = context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size);

    if (recipientPhoto != null) {
        Bitmap recipientPhotoBitmap = BitmapUtil.createFromDrawable(recipientPhoto, largeIconTargetSize,
                largeIconTargetSize);
        if (recipientPhotoBitmap != null)
            builder.setLargeIcon(recipientPhotoBitmap);
    }

    builder.setSmallIcon(R.drawable.icon_notification);
    builder.setColor(context.getResources().getColor(R.color.textsecure_primary));
    builder.setContentTitle(recipient.toShortString());
    builder.setContentText(notifications.get(0).getText());
    builder.setContentIntent(notifications.get(0).getPendingIntent(context));
    builder.setContentInfo(String.valueOf(notificationState.getMessageCount()));
    builder.setPriority(NotificationCompat.PRIORITY_HIGH);
    builder.setNumber(notificationState.getMessageCount());
    builder.setCategory(NotificationCompat.CATEGORY_MESSAGE);
    builder.setDeleteIntent(
            PendingIntent.getBroadcast(context, 0, new Intent(DeleteReceiver.DELETE_REMINDER_ACTION), 0));
    if (recipient.getContactUri() != null)
        builder.addPerson(recipient.getContactUri().toString());

    long timestamp = notifications.get(0).getTimestamp();
    if (timestamp != 0)
        builder.setWhen(timestamp);

    if (masterSecret != null) {
        Action markAsReadAction = new Action(R.drawable.check,
                context.getString(R.string.MessageNotifier_mark_as_read),
                notificationState.getMarkAsReadIntent(context, masterSecret));
        builder.addAction(markAsReadAction);
        builder.extend(new NotificationCompat.WearableExtender().addAction(markAsReadAction));
    }

    SpannableStringBuilder content = new SpannableStringBuilder();

    ListIterator<NotificationItem> iterator = notifications.listIterator(notifications.size());
    while (iterator.hasPrevious()) {
        NotificationItem item = iterator.previous();
        content.append(item.getBigStyleSummary());
        content.append('\n');
    }

    builder.setStyle(new BigTextStyle().bigText(content));

    setNotificationAlarms(context, builder, signal, notificationState.getRingtone(),
            notificationState.getVibrate());

    if (signal) {
        builder.setTicker(notifications.get(0).getTickerText());
    }

    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID,
            builder.build());
}

From source file:org.xchain.framework.lifecycle.Lifecycle.java

/**
 * Stop all current lifecycle steps.  The first step to be stopped is the last one started.
 *//*from  w w w  .  j  a va  2 s .c o  m*/
private static void stopLifecycleSteps() {
    ListIterator<LifecycleStep> iterator = lifecycleStepList.listIterator(lifecycleStepList.size());
    while (iterator.hasPrevious()) {
        LifecycleStep step = iterator.previous();
        try {
            if (log.isInfoEnabled()) {
                log.info("Stopping Lifecycle Step '" + step.getQName() + "'.");
            }
            step.stopLifecycle(context);
            if (log.isInfoEnabled()) {
                log.info("Finished Lifecycle Step '" + step.getQName() + "'.");
            }
        } catch (Throwable t) {
            if (log.isWarnEnabled()) {
                log.warn("An exception was thrown while stopping a lifecycle exception.", t);
            }
        }
    }
    lifecycleStepList.clear();
}

From source file:com.ettrema.zsync.UploadMakerEx.java

/**
 * Returns a Range representing a sequence of contiguous server blocks, beginning at blockIndex, that 
 * are to be relocated as a single chunk.
 * // w  w w.j a  v a2s .  c  o m
 * @param iter An iterator positioned immediately after the first match of the sequence
 * @param localOffset The local byte offset of the first matching block of the sequence
 * @param blockIndex The server block index of the first matching block of the sequence
 * @param blockSize The number of bytes in a block
 * @return A Range of contiguous blocks that are to be relocated to localOffset
 */
private static Range consecMatchesEx(ListIterator<OffsetPair> iter, long localOffset, long blockIndex,
        int blockSize) {

    long currBlock = blockIndex;
    long currByte = localOffset;

    while (iter.hasNext()) {

        OffsetPair pair = iter.next();

        currByte += blockSize;
        currBlock++;

        if (pair.localOffset != currByte || pair.remoteBlock != currBlock) {

            iter.previous();
            return new Range(blockIndex, currBlock);

        }

    }
    return new Range(blockIndex, currBlock + 1);
}

From source file:com.example.app.support.service.AppUtil.java

/**
 * Get a valid source component from the component path.  This is similar to
 * {@link ApplicationRegistry#getValidSourceComponent(Component)} but is able to find the source component even
 * when a pesky dialog is in the in way as long as the dialog had {@link #recordDialogsAncestorComponent(Dialog, Component)}
 * call on it.//from  w  ww .java2s  .  com
 *
 * @param component the component to start the search on
 *
 * @return a valid source component that has an ApplicationFunction annotation.
 *
 * @throws IllegalArgumentException if a valid source component could not be found.
 */
@Nonnull
public static Component getValidSourceComponentAcrossDialogs(Component component) {
    LinkedList<Component> path = new LinkedList<>();
    do {
        path.add(component);

        if (component.getClientProperty(CLIENT_PROP_DIALOGS_ANCESTRY) instanceof Component)
            component = (Component) component.getClientProperty(CLIENT_PROP_DIALOGS_ANCESTRY);
        else
            component = component.getParent();

    } while (component != null);

    final ListIterator<Component> listIterator = path.listIterator(path.size());
    while (listIterator.hasPrevious()) {
        final Component previous = listIterator.previous();
        if (previous.getClass().isAnnotationPresent(ApplicationFunction.class))
            return previous;
    }
    throw new IllegalArgumentException("Component path does not contain an application function.");
}