Exemplo n.º 1
0
  @Override
  public String toString() {
    StringBuilder builder = new StringBuilder();

    for (Type type : Type.values()) {
      if (scores[type.ordinal()] > 0) {
        if (builder.length() > 0) {
          builder.append(", ");
        }
        builder.append(String.format("%s: %f", type.name(), scores[type.ordinal()]));
      }
    }

    return builder.toString();
  }
Exemplo n.º 2
0
 /**
  * Creates a new Event.
  *
  * @param entityKey key of the entity bound to the event
  * @param type type of the event
  * @param comment comment
  */
 public Event(final Key entityKey, final Type type, final String comment) {
   this.entityKey = entityKey;
   this.type = type.ordinal();
   this.name = type.name();
   this.comment = comment;
   setV(1);
 }
  public WrapImpl(WrapType type, boolean wrapFirstElement) {
    Type myType;

    switch (type) {
      case NORMAL:
        myType = Type.WRAP_AS_NEEDED;
        break;
      case NONE:
        myType = Type.DO_NOT_WRAP;
        break;
      case ALWAYS:
        myType = Type.WRAP_ALWAYS;
        break;
      case CHOP_DOWN_IF_LONG:
      default:
        myType = Type.CHOP_IF_NEEDED;
    }

    int myId = ourId++;
    assert myId < ID_MAX;
    myFlags |=
        (wrapFirstElement ? WRAP_FIRST_ELEMENT_MASK : 0)
            | (myType.ordinal() << TYPE_SHIFT)
            | (myId << ID_SHIFT);
  }
Exemplo n.º 4
0
 public void writeTo(DataOutput out) throws Exception {
   out.writeByte(type.ordinal());
   Util.writeString(lock_name, out);
   Util.writeStreamable(owner, out);
   out.writeLong(timeout);
   out.writeBoolean(is_trylock);
 }
Exemplo n.º 5
0
  public static Set<String> getEntitiesNames(SQLConnection sql, Type type, boolean defaultOnly)
      throws SQLException {
    Set<String> entities = new HashSet<>();

    ResultSet result =
        sql.prepAndBind(
                "SELECT name FROM `{permissions_entity}` WHERE `type` = ? "
                    + (defaultOnly ? " AND `default` = 1" : ""),
                type.ordinal())
            .executeQuery();

    while (result.next()) {
      entities.add(result.getString("name"));
    }

    result.close();

    return Collections.unmodifiableSet(entities);
  }
Exemplo n.º 6
0
 public void writeTo(DataOutput out) throws Exception {
   out.writeByte(type.ordinal());
   // We can't use Util.writeObject since it's size is limited to 2^15-1
   try {
     if (object instanceof Streamable) {
       out.writeShort(-1);
       Util.writeGenericStreamable((Streamable) object, out);
     } else {
       byte[] bytes = Util.objectToByteBuffer(object);
       out.writeInt(bytes.length);
       out.write(bytes);
     }
   } catch (IOException e) {
     throw e;
   } catch (Exception e) {
     throw new IOException("Exception encountered while serializing execution request", e);
   }
   out.writeLong(request);
 }
Exemplo n.º 7
0
  /**
   * Get information about the current memory status of the JVM.
   *
   * @param unit used for formatting. Valid values are:
   *     <ul>
   *       <li>{@link Unit#BYTES}
   *       <li>{@link Unit#KILOBYTES}
   *       <li>{@link Unit#KIBIBYTES}
   *       <li>{@link Unit#MEGABYTES}
   *       <li>{@link Unit#MEBIBYTES}
   *     </ul>
   *     If no value is given, {@link Unit#BYTES} will be used. No decimal place will be calculated,
   *     plain integer values are returned.
   * @return a string with the current memory information
   */
  public static String getMemoryInfo(final Unit unit) {
    final long[] memory = getMemoryInfo();

    for (final Type type : Type.values()) {
      memory[type.ordinal()] /= unit.getDenominator();
    }

    final StringBuilder sb = new StringBuilder(100);
    sb.append("Memory (free/total/max): ");
    sb.append(memory[Type.FREE.ordinal()]);
    sb.append(unit.getUnitString());
    sb.append("/");
    sb.append(memory[Type.TOTAL.ordinal()]);
    sb.append(unit.getUnitString());
    sb.append("/");
    sb.append(memory[Type.MAX.ordinal()]);
    sb.append(unit.getUnitString());
    return sb.toString();
  }
Exemplo n.º 8
0
 @Override
 public int hashCode() {
   return Arrays.hashCode(bytes) + type.ordinal();
 }
 @Override
 public void writeToParcel(Parcel dest, int flags) {
   dest.writeString(token);
   dest.writeInt(type == null ? -1 : type.ordinal());
 }
Exemplo n.º 10
0
 /**
  * Returns true if score factor uses given type
  *
  * @param type
  * @return
  */
 public boolean usesType(Type type) {
   return scores[type.ordinal()] > 0;
 }
Exemplo n.º 11
0
 /**
  * Returns score for given type
  *
  * @param type
  * @return
  */
 public float getScore(Type type) {
   return scores[type.ordinal()];
 }
Exemplo n.º 12
0
  /**
   * Adds factor with given score to score factor.
   *
   * @param type
   * @param score
   * @return
   */
  public ScoreFactor addFactor(Type type, float score) {
    scores[type.ordinal()] = score;

    return this;
  }
 @Override
 public Object[] getParameters() {
   return new Object[] {(byte) type.ordinal(), getOrigin(), topologyId, segments};
 }
 @Override
 public Object[] getParameters() {
   return new Object[] {(byte) type.ordinal(), sender, viewId, state, locks};
 }
Exemplo n.º 15
0
 public AlignmentImpl(final Type type) {
   myFlags = ((ourId++) >> ID_SHIFT) | type.ordinal();
 }
Exemplo n.º 16
0
 int get_index(Type type) {
   return votes_[type.ordinal()];
 }