Updates the priority queue according to the change...

@param digram the digram string.
@param newFreq new frequency.

@return the pointer onto updated element.
358986
public RepairDigramRecord updateDigramFrequency(String digram, int newFreq) {

    // if the key exists
    if (!this.elements.containsKey(digram)) {
      return null;
    }

    // get a pointer on that node
    RepairQueueNode alteredNode = elements.get(digram);

    // the trivial case
    if (newFreq == alteredNode.payload.freq) {
      return alteredNode.payload;
    }

    // simply evict the node if the freq is too low
    if (2 > newFreq) {
      removeNodeFromList(alteredNode);
      this.elements.remove(alteredNode.payload.str);
      // System.out.println(this);
      return null;
    }

    // update the frequency
    int oldFreq = alteredNode.payload.freq;
    alteredNode.payload.freq = newFreq;

    // if the list is just too damn short
    if (1 == this.elements.size()) {
      // System.out.println(this);
      return alteredNode.payload;
    }

    // if we have to push the element up in the list
    if (newFreq > oldFreq) {

      // going up here
      RepairQueueNode currentNode = alteredNode.prev;
      if (null == alteredNode.prev) {
        currentNode = alteredNode.next;
      }

      removeNodeFromList(alteredNode);
      alteredNode.next = null;
      alteredNode.prev = null;

      while ((null != currentNode) && (currentNode.payload.freq < alteredNode.payload.freq)) {
        currentNode = currentNode.prev;
      }

      // we hit the head, oops... make it the new head
      if (null == currentNode) {
        alteredNode.next = this.head;
        this.head.prev = alteredNode;
        this.head = alteredNode;
      }
      else {
        if (null == currentNode.next) {
          currentNode.next = alteredNode;
          alteredNode.prev = currentNode;
        }
        else {
          currentNode.next.prev = alteredNode;
          alteredNode.next = currentNode.next;
          currentNode.next = alteredNode;
          alteredNode.prev = currentNode;
        }
      }
    }
    else {

      // what if this is a tail already?
      if (alteredNode.next == null) {
        // System.out.println(this);
        return alteredNode.payload;
      }
      // or if we got to stay in the head
      if (this.head == alteredNode && alteredNode.payload.freq >= this.head.next.payload.freq) {
        // System.out.println(this);
        return alteredNode.payload;
      }

      // going down..
      RepairQueueNode currentNode = alteredNode.next;
      removeNodeFromList(alteredNode);
      alteredNode.next = null;
      alteredNode.prev = null;

      while (null != currentNode.next && currentNode.payload.freq > alteredNode.payload.freq) {
        currentNode = currentNode.next;
      }

      if (null == currentNode.next) { // we hit the tail
        if (alteredNode.payload.freq > currentNode.payload.freq) {
          // place before tail
          if (this.head.equals(currentNode)) {
            alteredNode.next = currentNode;
            currentNode.prev = alteredNode;
            this.head = alteredNode;
          }
          else {
            alteredNode.next = currentNode;
            alteredNode.prev = currentNode.prev;
            currentNode.prev.next = alteredNode;
            currentNode.prev = alteredNode;
          }
        }
        else {
          currentNode.next = alteredNode;
          alteredNode.prev = currentNode;
        }
      }
      else { // place element just before of cp
        alteredNode.next = currentNode;
        alteredNode.prev = currentNode.prev;
        if (null == currentNode.prev) {
          // i.e. we are in da head...
          this.head = alteredNode;
        }
        else {
          currentNode.prev.next = alteredNode;
          currentNode.prev = alteredNode;
        }
      }
    }
    // System.out.println(this);
    return alteredNode.payload;

  }
376088
public void updateFragment(DisplayedResultQuery q)
  {
    List<String> args = Helper.citationFragment(q.getQuery(), q.getCorpora(),
      q.getLeftContext(), q.getRightContext(),
      q.getSegmentation(), q.getBaseText(), q.getOffset(), q.getLimit(), q.getOrder(),
      q.getSelectedMatches());

    // set our fragment
    lastEvaluatedFragment = StringUtils.join(args, "&");
    UI.getCurrent().getPage().setUriFragment(lastEvaluatedFragment, false);

    // reset title
    Page.getCurrent().setTitle(
      ui.getInstanceConfig().getInstanceDisplayName() + " (ANNIS Corpus Search)");
  }
740278
void updateQueue(String queue) throws ManagerCommunicationException
    {
        ResponseEvents re;

        try
        {
            QueueStatusAction queueStatusAction = new QueueStatusAction();
            queueStatusAction.setQueue(queue);
            re = server.sendEventGeneratingAction(queueStatusAction);
        }
        catch (ManagerCommunicationException e)
        {
            final Throwable cause = e.getCause();

            if (cause instanceof EventTimeoutException)
            {
                // this happens with Asterisk 1.0.x as it doesn't send a
                // QueueStatusCompleteEvent
                re = ((EventTimeoutException) cause).getPartialResult();
            }
            else
            {
                throw e;
            }
        }

        for (ManagerEvent event : re.getEvents())
        {
            // 101119 OLB: solo actualizamos el QUEUE por ahora
            if (event instanceof QueueParamsEvent)
            {
                handleQueueParamsEvent((QueueParamsEvent) event);
            }

            else if (event instanceof QueueMemberEvent)
            {
                handleQueueMemberEvent((QueueMemberEvent) event);
            }
            else if (event instanceof QueueEntryEvent)
            {
                handleQueueEntryEvent((QueueEntryEvent) event);
            }

        }
    }
1054704
public void push (final T newVal)
  {
    final int index = (int) (m_aCurrentIndex.incrementAndGet () % m_nMaxSize);
    m_aCircularArray[index].set (newVal);
  }
809940
public <R extends Request<T>> R setPriority(Priority priority) {
        this.priority = priority;
        return (R) this;
    }
212044
public void setDigestFrequency(int frequency) {
        addField(SubscribeOptionFields.digest_frequency, FormField.Type.text_single);
        setAnswer(SubscribeOptionFields.digest_frequency.getFieldName(), frequency);
    }
422023
public void update (T value)
    {
        // store our new current value
        _value = value;

        // notify our listeners; we snapshot our listeners before iterating to avoid problems if
        // listeners add or remove themselves while we're dispatching this notification
        for (Listener<T> listener : new ArrayList<Listener<T>>(_listeners)) {
            listener.valueChanged(value);
        }
    }
846479
public void setPriority(int newPriority)
    {
        JsMessage localMsg = getJSMessage(true);
        msgPriority = newPriority;
        localMsg.setPriority(newPriority);
    }
593771
public void add (Schedulable schedulable, int frequency, int phase, float priority) {
		// Compile the record and add it to the list
		schedulableRecords.add(new PrioritySchedulableRecord(schedulable, frequency, phase, priority));
	}
663261
public void increasePriority(int overrideId, int ordinal, int pathId, String clientUUID) {
        logger.info("Increase priority");

        int origPriority = -1;
        int newPriority = -1;
        int origId = 0;
        int newId = 0;

        PreparedStatement statement = null;
        ResultSet results = null;
        try (Connection sqlConnection = sqlService.getConnection()) {
            results = null;
            statement = sqlConnection.prepareStatement(
                "SELECT * FROM " + Constants.DB_TABLE_ENABLED_OVERRIDE +
                    " WHERE " + Constants.ENABLED_OVERRIDES_PATH_ID + " = ?" +
                    " AND " + Constants.GENERIC_CLIENT_UUID + " = ?" +
                    " ORDER BY " + Constants.ENABLED_OVERRIDES_PRIORITY
            );
            statement.setInt(1, pathId);
            statement.setString(2, clientUUID);
            results = statement.executeQuery();

            int ordinalCount = 0;
            while (results.next()) {
                if (results.getInt(Constants.ENABLED_OVERRIDES_OVERRIDE_ID) == overrideId) {
                    ordinalCount++;
                    if (ordinalCount == ordinal) {
                        origPriority = results.getInt(Constants.ENABLED_OVERRIDES_PRIORITY);
                        origId = results.getInt(Constants.GENERIC_ID);
                        break;
                    }
                }
                newPriority = results.getInt(Constants.ENABLED_OVERRIDES_PRIORITY);
                newId = results.getInt(Constants.GENERIC_ID);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (results != null) {
                    results.close();
                }
            } catch (Exception e) {
            }
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }

        try (Connection sqlConnection = sqlService.getConnection()) {
            // update priorities
            if (origPriority != -1 && newPriority != -1) {
                statement = sqlConnection.prepareStatement(
                    "UPDATE " + Constants.DB_TABLE_ENABLED_OVERRIDE +
                        " SET " + Constants.ENABLED_OVERRIDES_PRIORITY + "=?" +
                        " WHERE " + Constants.GENERIC_ID + "=?"
                );
                statement.setInt(1, origPriority);
                statement.setInt(2, newId);
                statement.executeUpdate();
                statement.close();

                statement = sqlConnection.prepareStatement(
                    "UPDATE " + Constants.DB_TABLE_ENABLED_OVERRIDE +
                        " SET " + Constants.ENABLED_OVERRIDES_PRIORITY + "=?" +
                        " WHERE " + Constants.GENERIC_ID + "=?"
                );
                statement.setInt(1, newPriority);
                statement.setInt(2, origId);
                statement.executeUpdate();
            }
        } catch (Exception e) {
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
    }
1346077
@SuppressWarnings("unchecked")
    public static UniversalIdStrQueueMessage newInstance() {
        Date now = new Date();
        UniversalIdStrQueueMessage msg = new UniversalIdStrQueueMessage();
        msg.setQueueTimestamp(now).setNumRequeues(0)
                .setId(QueueUtils.IDGEN.generateId128Hex().toLowerCase()).setTimestamp(now);
        return msg;
    }
1034705
function(newProps) {
        if (this.getInitialState) {
            if (this.getInitialProps) {
                newProps = this.getInitialProps(newProps) || {};
            }
            var newState = this.getInitialState(newProps);
            this.replaceState(newState);
            return;
        }

        if (!this.__newProps) {
            updateManager.queueWidgetUpdate(this);
        }

        this.__newProps = newProps;
    }
261993
@SuppressWarnings("unchecked")
	public static <T extends Levenshtein> T NGram(String baseTarget, String compareTarget, Integer n) {
		return (T) new NGram(baseTarget, n).update(compareTarget);
	}
549539
private void triggerQueuedRequests() {
		if (triggerRequestQueued) {
			triggerRequestQueued = false;

			// trigger the checkpoint from the trigger timer, to finish the work of this thread before
			// starting with the next checkpoint
			if (periodicScheduling) {
				if (currentPeriodicTrigger != null) {
					currentPeriodicTrigger.cancel(false);
				}
				currentPeriodicTrigger = timer.scheduleAtFixedRate(
						new ScheduledTrigger(),
						0L, baseInterval, TimeUnit.MILLISECONDS);
			}
			else {
				timer.execute(new ScheduledTrigger());
			}
		}
	}
213795
public void decreasePriority(Entry entry, P newPriority) {
        Preconditions.checkArgument(
                comparator.compare(newPriority, entry.priority) <= 0,
                "Cannot increase priority"
        );

        assert oMinEntry != null;

        entry.priority = newPriority;
        Entry oParent = entry.oParent;

        if (oParent != null && (comparator.compare(newPriority, oParent.priority) < 0)) {
            cutAndMakeRoot(entry);
        }

        if (comparator.compare(newPriority, oMinEntry.priority) < 0) {
            oMinEntry = entry;
        }
    }
568760
public void enqueue(RepairDigramRecord digramRecord) {
    
    // System.out.println("before == " + this.toString());
    // if the same key element is in the queue - something went wrong with tracking...
    if (elements.containsKey(digramRecord.str)) {
      throw new IllegalArgumentException(
          "Element with payload " + digramRecord.str + " already exists in the queue...");
    }
    else {

      // create a new node
      RepairQueueNode nn = new RepairQueueNode(digramRecord);
      // System.out.println(nn.payload);

      // place it into the queue if it's empty
      if (this.elements.isEmpty()) {
        this.head = nn;
      }
      
      // if new node has _higher than_ or _equal to_ the head frequency... this going to be the new head
      else if (nn.getFrequency() >= this.head.getFrequency()) {
        this.head.prev = nn;
        nn.next = this.head;
        this.head = nn;
      }
      
      // in all other cases find an appropriate place in the existing queue, starting from the head
      else {
        
        RepairQueueNode currentNode = head;
        
        while (null != currentNode.next) {
          // the intent is to slide down the list finding a place at new node is greater than a node
          // a tracking pointer points to...
          // ABOVE we just checked that at this loop start that the current node is greater than new
          // node
          //
          if (nn.getFrequency() >= currentNode.getFrequency()) {
            RepairQueueNode prevN = currentNode.prev;
            prevN.next = nn;
            nn.prev = prevN;
            currentNode.prev = nn;
            nn.next = currentNode;
            break; // the element has been placed
          }
          currentNode = currentNode.next;
        }
        
        // check if loop was broken by the TAIL condition, not by placement
        if (null == currentNode.next) {
          // so, currentNode points on the tail...
          if (nn.getFrequency() >= currentNode.getFrequency()) {
            // insert just before...
            RepairQueueNode prevN = currentNode.prev;
            prevN.next = nn;
            nn.prev = prevN;
            currentNode.prev = nn;
            nn.next = currentNode;
          }
          else {
            // or make a new tail
            nn.prev = currentNode;
            currentNode.next = nn;
          }
        }

      }
      // also save the element in the index store
      this.elements.put(nn.payload.str, nn);

    }
    // System.out.println("before == " + this.toString());
  }
1058926
private void updateLocalityWaitTimes(long currentTime) {
    long timeSinceLastHeartbeat =
      (lastHeartbeatTime == 0 ? 0 : currentTime - lastHeartbeatTime);
    lastHeartbeatTime = currentTime;
    for (JobInfo info: infos.values()) {
      if (info.skippedAtLastHeartbeat) {
        info.timeWaitedForLocalMap += timeSinceLastHeartbeat;
        // We reset the flag so that timeWaitedForLocalMap is increment only
        // once. It will be increment again if skippedAtLastHeartbeat is set
        // to true next time.
        info.skippedAtLastHeartbeat = false;
      }
    }
  }