示例#1
0
  public PullToolsVisitor(RequestHandlerContext context, ExplorerVisitor v, PullService tools) {
    super(context, v);
    this.tools = tools;
    this.rootEntry = new Entry(null);

    PullContext pullContext = tools.getContext();
    boolean parentEntry = false;

    String[] names = pullContext.getQualifiedToolNames().toArray(EMPTY_STRING_ARRAY);

    Arrays.sort(
        names,
        new Comparator<String>() {
          public int compare(String o1, String o2) {
            int p1 = o1.startsWith("/_parent/") ? 1 : 0;
            int p2 = o2.startsWith("/_parent/") ? 1 : 0;

            if (p1 == p2) {
              return o1.compareTo(o2);
            } else {
              return p1 - p2;
            }
          }
        });

    for (String path : names) {
      Entry entry = rootEntry;
      String[] pathsegs = split(path, "/");
      String name = null;

      for (String pathseg : pathsegs) {
        name = pathseg;
        Entry subEntry = entry.subEntries.get(name);

        if (subEntry == null) {
          subEntry = new Entry(name);
          entry.subEntries.put(name, subEntry);
        }

        entry = subEntry;

        if (!parentEntry) {
          if ("_parent".equals(entry.name)) {
            parentEntry = true;
          }
        }

        entry.parentEntry = parentEntry;
      }

      try {
        entry.value = pullContext.pull(name);
      } catch (Exception e) {
        entry.value = e;
      }
    }
  }
示例#2
0
  /**
   * Clear this configuration and reset to the contents of the parsed string.
   *
   * @param text Git style text file listing configuration properties.
   * @throws ConfigInvalidException the text supplied is not formatted correctly. No changes were
   *     made to {@code this}.
   */
  public void fromText(final String text) throws ConfigInvalidException {
    final List<Entry> newEntries = new ArrayList<Entry>();
    final StringReader in = new StringReader(text);
    Entry last = null;
    Entry e = new Entry();
    for (; ; ) {
      int input = in.read();
      if (-1 == input) break;

      final char c = (char) input;
      if ('\n' == c) {
        // End of this entry.
        newEntries.add(e);
        if (e.section != null) last = e;
        e = new Entry();

      } else if (e.suffix != null) {
        // Everything up until the end-of-line is in the suffix.
        e.suffix += c;

      } else if (';' == c || '#' == c) {
        // The rest of this line is a comment; put into suffix.
        e.suffix = String.valueOf(c);

      } else if (e.section == null && Character.isWhitespace(c)) {
        // Save the leading whitespace (if any).
        if (e.prefix == null) e.prefix = "";
        e.prefix += c;

      } else if ('[' == c) {
        // This is a section header.
        e.section = readSectionName(in);
        input = in.read();
        if ('"' == input) {
          e.subsection = readValue(in, true, '"');
          input = in.read();
        }
        if (']' != input) throw new ConfigInvalidException(JGitText.get().badGroupHeader);
        e.suffix = "";

      } else if (last != null) {
        // Read a value.
        e.section = last.section;
        e.subsection = last.subsection;
        in.reset();
        e.name = readKeyName(in);
        if (e.name.endsWith("\n")) {
          e.name = e.name.substring(0, e.name.length() - 1);
          e.value = MAGIC_EMPTY_VALUE;
        } else e.value = readValue(in, false, -1);

      } else throw new ConfigInvalidException(JGitText.get().invalidLineInConfigFile);
    }

    state.set(newState(newEntries));
  }
示例#3
0
 /** Note the same entry instance is returned each time this method is called. */
 public Entry next() {
   if (!hasNext) throw new NoSuchElementException();
   if (!valid) throw new GdxRuntimeException("#iterator() cannot be used nested.");
   int[] keyTable = map.keyTable;
   if (nextIndex == INDEX_ZERO) {
     entry.key = 0;
     entry.value = map.zeroValue;
   } else {
     entry.key = keyTable[nextIndex];
     entry.value = map.valueTable[nextIndex];
   }
   currentIndex = nextIndex;
   findNextIndex();
   return entry;
 }
  private boolean setEntry(Entry<K, V> node, Entry[] table) {
    int index = indexFor(node.hash, table);
    Entry<K, V> entry = table[index];

    if (null != entry) {
      while (null != entry) {
        if ((node.key == entry.key || node.key.equals(entry.key))
            && node.hash == entry.hash
            && (node.value == entry.value || node.value.equals(entry.value))) {
          return false;
        } else if (node.key == entry.key && node.value != entry.value) {
          entry.value = node.value;
          return true;
        } else if (node.key != entry.key) {
          if (null == entry.next) {
            break;
          }
          entry = entry.next;
        }
      }
      addEntryLast(entry, node);
      return true;
    }
    setFirstEntry(node, index, table);
    return true;
  }
 /**
  * Evict cold entries (resident and non-resident) until the memory limit is reached. The new
  * entry is added as a cold entry, except if it is the only entry.
  *
  * @param newCold a new cold entry
  */
 private void evict(Entry<V> newCold) {
   // ensure there are not too many hot entries: right shift of 5 is
   // division by 32, that means if there are only 1/32 (3.125%) or
   // less cold entries, a hot entry needs to become cold
   while (queueSize <= (mapSize >>> 5) && stackSize > 0) {
     convertOldestHotToCold();
   }
   if (stackSize > 0) {
     // the new cold entry is at the top of the queue
     addToQueue(queue, newCold);
   }
   // the oldest resident cold entries become non-resident
   // but at least one cold entry (the new one) must stay
   while (usedMemory > maxMemory && queueSize > 1) {
     Entry<V> e = queue.queuePrev;
     usedMemory -= e.memory;
     removeFromQueue(e);
     e.value = null;
     e.memory = 0;
     addToQueue(queue2, e);
     // the size of the non-resident-cold entries needs to be limited
     while (queue2Size + queue2Size > stackSize) {
       e = queue2.queuePrev;
       int hash = getHash(e.key);
       remove(e.key, hash);
     }
   }
 }
 /**
  * Add an entry to the cache. The entry may or may not exist in the cache yet. This method will
  * usually mark unknown entries as cold and known entries as hot.
  *
  * @param key the key (may not be null)
  * @param hash the hash
  * @param value the value (may not be null)
  * @param memory the memory used for the given entry
  * @return the old value, or null if there was no resident entry
  */
 synchronized V put(long key, int hash, V value, int memory) {
   if (value == null) {
     throw DataUtils.newIllegalArgumentException("The value may not be null");
   }
   V old;
   Entry<V> e = find(key, hash);
   if (e == null) {
     old = null;
   } else {
     old = e.value;
     remove(key, hash);
   }
   e = new Entry<V>();
   e.key = key;
   e.value = value;
   e.memory = memory;
   int index = hash & mask;
   e.mapNext = entries[index];
   entries[index] = e;
   usedMemory += memory;
   if (usedMemory > maxMemory && mapSize > 0) {
     // an old entry needs to be removed
     evict(e);
   }
   mapSize++;
   // added entries are always added to the stack
   addToStack(e);
   return old;
 }
示例#7
0
  public List<Entry> getLastPoints(int nb) throws IOException {
    File file = getFile();
    RandomAccessFile raf = null;
    List<Entry> result = null;

    try {
      raf = new RandomAccessFile(file, "r");
      long pos = raf.length() - (nb * DATA_LEN);
      if (pos < 0) {
        nb = nb + (int) (pos / DATA_LEN);
        pos = 0;
      }
      raf.seek(pos);

      result = new ArrayList<Entry>(nb);
      Entry next = null;
      for (int i = 0; i < nb; i++) {
        next = new Entry();
        next.timestamp = (long) raf.readInt();
        next.value = raf.readFloat();
        result.add(0, next);
      }
    } finally {
      if (raf != null) raf.close();
    }
    return result;
  }
示例#8
0
 public final VALUE remove(int index) {
   final Entry<KEY, VALUE> entry = removeList(index);
   final VALUE value = entry.value;
   removeMap(entry.key);
   entry.value = null;
   return value;
 }
  @SuppressWarnings("unchecked")
  private void expungeStaleEntries() {
    Entry<K, V> e;

    while ((e = (Entry<K, V>) queue.poll()) != null) {
      int h = e.hash;
      int i = indexFor(h, table.length);

      Entry<K, V> prev = table[i];
      Entry<K, V> p = prev;

      while (p != null) {
        Entry<K, V> next = p.next;
        if (p == e) {
          if (prev == e) {
            table[i] = next;
          } else {
            prev.next = next;
          }
          e.next = null;
          e.value = null;
          size--;
          break;
        }
        prev = p;
        p = next;
      }
    }
  }
示例#10
0
  @SuppressWarnings({"unchecked", "rawtypes", "unused"})
  @Override
  public V put(K key, V value) {
    K k = (K) maskNull(key);
    int h = HashMap.hash(k.hashCode());
    Entry[] tab = getTable();
    int i = indexFor(h, tab.length);

    for (Entry<K, V> e = tab[i]; e != null; e = e.next) {
      if (h == e.hash && eq(k, e.get())) {
        V oldValue = e.value;
        if (value != oldValue) {
          e.value = value;
        }
        return oldValue;
      }
    }

    modCount++;
    Entry<K, V> e = tab[i];
    //		tab[i] = new Entry<K,V>(k, value, queue, h, e);
    if (++size >= threshold) {
      resize(tab.length * 2);
    }
    return null;
  }
示例#11
0
    public boolean hasNext() {
      if (raf == null || !raf.getChannel().isOpen()) return false;

      if (flagNext == true) return true; // Déjà lue

      flagNext = true;
      try {
        next = new Entry();
        next.timestamp = (long) raf.readInt();
        next.value = raf.readFloat();
        if (this.end != null && next.timestamp > this.end) {
          next = null;
          close();
          return false;
        }
        return true;
      } catch (IOException e) {
        // EOF ou autre erreur d'IO
        if (!(e instanceof EOFException)) logger.log(Level.WARNING, e.getMessage(), e);
        next = null;
        try {
          close();
        } catch (IOException e1) {
          logger.log(Level.WARNING, e.getMessage(), e);
        }
        return false;
      }
    }
  /**
   * {@inheritDoc}
   *
   * <p>This method will, on a best-effort basis, throw a {@link
   * java.util.ConcurrentModificationException} if the remapping function modified this map during
   * computation.
   *
   * @throws ConcurrentModificationException if it is detected that the remapping function modified
   *     this map
   */
  @Override
  public synchronized V computeIfPresent(
      K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
    Objects.requireNonNull(remappingFunction);

    Entry<?, ?> tab[] = table;
    int hash = key.hashCode();
    int index = (hash & 0x7FFFFFFF) % tab.length;
    @SuppressWarnings("unchecked")
    Entry<K, V> e = (Entry<K, V>) tab[index];
    for (Entry<K, V> prev = null; e != null; prev = e, e = e.next) {
      if (e.hash == hash && e.key.equals(key)) {
        int mc = modCount;
        V newValue = remappingFunction.apply(key, e.value);
        if (mc != modCount) {
          throw new ConcurrentModificationException();
        }
        if (newValue == null) {
          if (prev != null) {
            prev.next = e.next;
          } else {
            tab[index] = e.next;
          }
          modCount = mc + 1;
          count--;
        } else {
          e.value = newValue;
        }
        return newValue;
      }
    }
    return null;
  }
	protected Entry insert(long key, Object value) {
		if (value == null)
			throw new IllegalArgumentException("Illegal value: null");
		int idx = hash(key) % tabSize;
		if(idx < 0)
			idx *= -1;
		// look for an empty bucket
		if (values[idx] == null) {
			keys[idx] = key;
			values[idx] = new Entry(key, value);
			++items;
			return values[idx];
        }
        
        Entry next = values[idx];
        while (next != null) {
            if (next.key == key) {
                // duplicate value
                next.value = value;
                removeEntry(next);
                return next;
            }
            next = next.nextDup;
        }
        
        // add a new entry to the chain
        next = new Entry(key, value);
        next.nextDup = values[idx];
        values[idx].prevDup = next;
        values[idx] = next;
        ++items;
        return next;
	}
示例#14
0
  /**
   * Maps the specified <code>key</code> to the specified <code>value</code> in this hashtable.
   * Neither the key nor the value can be <code>null</code>.
   *
   * <p>The value can be retrieved by calling the <code>get</code> method with a key that is equal
   * to the original key.
   *
   * @param key the hashtable key
   * @param value the value
   * @return the previous value of the specified key in this hashtable, or <code>null</code> if it
   *     did not have one
   * @exception NullPointerException if the key or value is <code>null</code>
   * @see Object#equals(Object)
   * @see #get(Object)
   */
  public synchronized V put(K key, V value) {
    // Make sure the value is not null
    if (value == null) {
      throw new NullPointerException();
    }

    // Makes sure the key is not already in the hashtable.
    Entry tab[] = table;
    int hash = key.hashCode();
    int index = (hash & 0x7FFFFFFF) % tab.length;
    for (Entry<K, V> e = tab[index]; e != null; e = e.next) {
      if ((e.hash == hash) && e.key.equals(key)) {
        V old = e.value;
        e.value = value;
        return old;
      }
    }

    modCount++;
    if (count >= threshold) {
      // Rehash the table if the threshold is exceeded
      rehash();

      tab = table;
      index = (hash & 0x7FFFFFFF) % tab.length;
    }

    // Creates the new entry.
    Entry<K, V> e = tab[index];
    tab[index] = new Entry<>(hash, key, value, e);
    count++;
    return null;
  }
  /**
   * Maps the specified <code>key</code> to the specified <code>value</code> in this hashtable. The
   * key cannot be <code>null</code>.
   *
   * <p>The value can be retrieved by calling the <code>get</code> method with a key that is equal
   * to the original key.
   *
   * @param key the hashtable key.
   * @param value the value.
   * @return the previous value of the specified key in this hashtable, or <code>null</code> if it
   *     did not have one.
   * @throws NullPointerException if the key is <code>null</code>.
   * @see #get(int)
   */
  public Object put(int key, Object value) {
    // Makes sure the key is not already in the hashtable.
    Entry tab[] = table;
    int index = (key & 0x7FFFFFFF) % tab.length;
    for (Entry e = tab[index]; e != null; e = e.next) {
      if (e.key == key) {
        Object old = e.value;
        e.value = value;
        return old;
      }
    }

    if (count >= threshold) {
      // Rehash the table if the threshold is exceeded
      rehash();

      tab = table;
      index = (key & 0x7FFFFFFF) % tab.length;
    }

    // Creates the new entry.
    Entry e = new Entry(key, value, tab[index]);
    tab[index] = e;
    count++;
    return null;
  }
示例#16
0
 public Object put(int key, Object value) {
   int length = this.table.length;
   int location = (key % length + length) % length;
   synchronized (this.mutex[(location % 32)]) {
     if (length == this.table.length) {
       Entry bucket = this.table[location];
       while (bucket != null) {
         if (key == bucket.key) {
           Object previous = bucket.value;
           bucket.value = value;
           bucket.preIncrementCount();
           return previous;
         }
         bucket = bucket.next;
       }
       this.table[location] = new Entry(key, value, this.table[location]);
       synchronized (this.mutex) {
         if (++this.size > this.threshold) {
           rehash(true);
         }
       }
       return null;
     }
   }
   return put(key, value);
 }
示例#17
0
  /**
   * Maps the specified <code>key</code> to the specified <code>value</code> in this hashtable. The
   * key cannot be <code>null</code>.
   *
   * <p>The value can be retrieved by calling the <code>get</code> method with a key that is equal
   * to the original key.
   *
   * @param key the hashtable key.
   * @param value the value.
   * @return the previous value of the specified key in this hashtable, or <code>null</code> if it
   *     did not have one.
   * @throws NullPointerException if the key is <code>null</code>.
   * @see #get(int)
   */
  public T put(int key, T value) {
    // Makes sure the key is not already in the hashtable.
    Entry<T> tab[] = table;
    int index = getIndex(key);
    for (Entry<T> e = tab[getIndex(key)]; e != null; e = e.next) {
      if (e.hash == key) {
        T old = e.value;
        e.value = value;
        return old;
      }
    }

    if (count >= threshold) {
      // Rehash the table if the threshold is exceeded
      rehash();

      tab = table;
      index = getIndex(key);
    }

    // Creates the new entry.

    Entry<T> e = new Entry<T>(key, value, tab[index]);
    tab[index] = e;
    count++;
    return null;
  }
示例#18
0
 public final Object remove(int index) {
   Entry e = removeList(index);
   Object value = e.value;
   removeMap(e.key);
   e.value = null;
   return value;
 }
 private static <V> Entry<V> copy(Entry<V> old) {
   Entry<V> e = new Entry<V>();
   e.key = old.key;
   e.value = old.value;
   e.memory = old.memory;
   e.topMove = old.topMove;
   return e;
 }
示例#20
0
 /** Note the same entry instance is returned each time this method is called. */
 public Entry<K> next() {
   if (!hasNext) throw new NoSuchElementException();
   K[] keyTable = map.keyTable;
   entry.key = keyTable[nextIndex];
   entry.value = map.valueTable[nextIndex];
   currentIndex = nextIndex;
   findNextIndex();
   return entry;
 }
  public void put(String key, int value) {
    int hash = key.hashCode();
    int index = hash % 10;

    if (array[index] == null) {
      array[index] = new Entry(key, value);
    } else {
      Entry e = array[index];
      if (e.key.equals(key)) e.value = value;
      else {
        while (e.next != null) {
          if (e.key.equals(key)) e.value = value;
          e = e.next;
        }
        e.next = new Entry(key, value);
      }
    }
  }
示例#22
0
 Entry forValue(final String newValue) {
   final Entry e = new Entry();
   e.prefix = prefix;
   e.section = section;
   e.subsection = subsection;
   e.name = name;
   e.value = newValue;
   e.suffix = suffix;
   return e;
 }
示例#23
0
 /** Note the same entry instance is returned each time this method is called. */
 public Entry<K> next() {
   if (!hasNext) throw new NoSuchElementException();
   if (!valid) throw new GdxRuntimeException("#iterator() cannot be used nested.");
   K[] keyTable = map.keyTable;
   entry.key = keyTable[nextIndex];
   entry.value = map.valueTable[nextIndex];
   currentIndex = nextIndex;
   findNextIndex();
   return entry;
 }
示例#24
0
 public int compareTo(Entry e) {
   double v1 = value(), v2 = e.value();
   if (v1 < v2) {
     return -1;
   }
   if (v1 > v2) {
     return 1;
   }
   return 0;
 }
示例#25
0
  public void post(long timestamp, float value) throws IOException {
    File file = getFile();
    RandomAccessFile rdf = null;

    try {
      rdf = new RandomAccessFile(file, "rw");

      // On vérifie que la longueur est cohérente
      long len = rdf.length();
      if (len > 0) {
        int mod = (int) (len % DATA_LEN);
        if (mod != 0) {
          logger.warning(
              "Taille de fichier incoherence ("
                  + len / DATA_LEN
                  + "x"
                  + DATA_LEN
                  + ", reste "
                  + mod
                  + "). retour a "
                  + (len - mod));
          len = len - mod;
        }

        if (timestamp < getLast(rdf).timestamp) {
          logger.warning(
              "la nouvelle valeur anterieure a la derniere (prev:"
                  + sdf.format(new Date((long) last.timestamp * 1000))
                  + " new:"
                  + sdf.format(new Date((long) timestamp * 1000))
                  + ")");
        }

        // Positionnement en fin de fichier
        rdf.seek(len);
      }

      // On écrit l'enregistrement
      if (timestamp > Integer.MAX_VALUE) {
        logger.warning("timestamp tronqué : " + timestamp + "/" + (int) timestamp);
      }

      if (last == null) last = new Entry();
      last.timestamp = (int) timestamp;
      last.value = value;

      logger.fine("write: " + value + "(" + sdf.format(new Date(timestamp * 1000)) + ")");
      rdf.writeInt((int) last.timestamp);
      rdf.writeFloat(last.value);
    } finally {
      if (rdf != null) rdf.close();
    }
  }
示例#26
0
	private V putForNullKey(V value){
		for (Entry<K, V> e = table[0]; e != null; e = e.next){
			if (e.key == null){
				V oldValue = e.value;
				e.value = value;
				return oldValue;
			}
		}

		addEntry(0, null, value, 0);
		return null;
	}
  /**
   * Express a BinaryTreeNode as a String.
   *
   * @return a String representing the BinaryTreeNode.
   */
  public String toString() {
    String s = "";

    if (leftChild != null) {
      s = "(" + leftChild.toString() + ")";
    }
    s = s + entry.key().toString() + entry.value();
    if (rightChild != null) {
      s = s + "(" + rightChild.toString() + ")";
    }
    return s;
  }
示例#28
0
 /** Offloaded version of put for null keys */
 private V putForNullKey(V value) {
   for (Entry<K, V> e = table[0]; e != null; e = e.next) {
     if (e.key == null) {
       V oldValue = e.value;
       e.value = value;
       e.recordAccess(this);
       return oldValue;
     }
   }
   modCount++;
   addEntry(0, null, value, 0);
   return null;
 }
 @Override
 public void put(Long key, String value) {
   if (key == null) return;
   int hash = hash(key);
   int i = indexFor(hash, table.length);
   FileBucket fb = table[i];
   for (Entry e = fb.getEntry(); e != null; e = e.next) {
     Long k;
     if (e.hash == hash && ((k = e.key) == key || key.equals(k))) {
       e.value = value;
       return;
     }
   }
   addEntry(hash, key, value, i);
 }
示例#30
0
 /** Removes all mappings from this map. */
 public void clear() {
   // We don't need all locks at once so long as locks
   //   are obtained in low to high order
   for (int s = 0; s < segments.length; ++s) {
     Segment seg = segments[s];
     synchronized (seg) {
       Entry[] tab = table;
       for (int i = s; i < tab.length; i += segments.length) {
         for (Entry e = tab[i]; e != null; e = e.next) e.value = null;
         tab[i] = null;
         seg.count = 0;
       }
     }
   }
 }