/**
   * Returns a flyweight relation.
   *
   * @param pEncoding The full encoding of the relation, prefixed in the case of a transposed
   *     relation.
   * @return The unique relation object corresponding to pEncoding.
   * @exception UnsupportedRelationException if the encoding does not resolve to a known exception
   */
  public static Relation getRelation(final String pEncoding) throws UnsupportedRelationException {
    String lCode = pEncoding;
    // if
    if (lCode.startsWith(Relation.TRANSPOSE_CODE)) //
    {
      lCode = pEncoding.substring(Relation.TRANSPOSE_CODE.length(), pEncoding.length());
      for (final Type relationType : Type.values())
        if (lCode.equals(relationType.getCode()))
          return Relation.tRelationMap.get(relationType); // return the transpose relation
    } else
      for (final Type lRelationType : Type.values())
        if (lCode.equals(lRelationType.getCode())) return Relation.aRelationMap.get(lRelationType);

    throw new UnsupportedRelationException("Code: " + lCode);
  }
Beispiel #2
0
  private FlowLayoutContainer createButtons(Category cat) {
    VerticalPanel vp = new VerticalPanel();
    vp.setSpacing(10);
    vp.setWidth("400px");

    for (Type type : Type.values()) {
      vp.add(format(type.getText()));

      HorizontalPanel hp = new HorizontalPanel();
      hp.setSpacing(5);

      CellButtonBase<?> small = createButton(cat, type);
      CellButtonBase<?> medium = createButton(cat, type);
      CellButtonBase<?> large = createButton(cat, type);

      configureButton(small, type, ButtonScale.SMALL);
      configureButton(medium, type, ButtonScale.MEDIUM);
      configureButton(large, type, ButtonScale.LARGE);

      hp.add(small);
      hp.add(medium);
      hp.add(large);

      vp.add(hp);
    }

    FlowLayoutContainer f = new FlowLayoutContainer();
    f.getScrollSupport().setScrollMode(ScrollMode.AUTO);
    f.add(vp);

    con.add(f);

    return f;
  }
    static Type getTypeFromNativeType(int nativeType) {
      for (Type t : Type.values()) {
        if (t.mNativeType == nativeType) return t;
      }

      return URL_WHAT_YOU_TYPED;
    }
Beispiel #4
0
 private static long[] getMemoryInfo() {
   final long[] memory = new long[Type.values().length];
   memory[Type.FREE.ordinal()] = Runtime.getRuntime().freeMemory();
   memory[Type.TOTAL.ordinal()] = Runtime.getRuntime().totalMemory();
   memory[Type.MAX.ordinal()] = Runtime.getRuntime().maxMemory();
   return memory;
 }
Beispiel #5
0
 @VisibleForTesting
 void init(Profile profile, int timeoutMs) {
   for (Type t : Type.values()) {
     SingleTypeTask task = new SingleTypeTask(t);
     task.start(profile, timeoutMs);
   }
 }
Beispiel #6
0
 public void readFrom(DataInput in) throws Exception {
   type = Type.values()[in.readByte()];
   lock_name = Util.readString(in);
   owner = (Owner) Util.readStreamable(Owner.class, in);
   timeout = in.readLong();
   is_trylock = in.readBoolean();
 }
 private static boolean isBuiltinType(String storeType) {
   for (Type type : Type.values()) {
     if (type.match(storeType)) {
       return true;
     }
   }
   return false;
 }
Beispiel #8
0
  public ScoreFactor() {
    this.scores = new float[Type.values().length];

    // initialize scores
    for (int i = 0; i < scores.length; i++) {
      scores[i] = 0f;
    }
  }
 private Combo createTypeCombo() {
   final Combo c = new Combo(this, SWT.NONE);
   for (final Type type : Type.values()) {
     c.add(type.name());
   }
   c.select(0);
   return c;
 }
Beispiel #10
0
 public static Type readFromStream(StreamInput in) throws IOException {
   int ord = in.readVInt();
   for (Type type : Type.values()) {
     if (type.ordinal == ord) {
       return type;
     }
   }
   throw new ElasticsearchException("unknown serialized type [" + ord + "]");
 }
 @Override
 @SuppressWarnings("unchecked")
 public void setParameters(int commandId, Object[] parameters) {
   int i = 0;
   type = Type.values()[(Byte) parameters[i++]];
   setOrigin((Address) parameters[i++]);
   topologyId = (Integer) parameters[i++];
   segments = (Set<Integer>) parameters[i];
 }
 @Override
 @SuppressWarnings("unchecked")
 public void setParameters(int commandId, Object[] parameters) {
   int i = 0;
   type = Type.values()[(Byte) parameters[i++]];
   sender = (Address) parameters[i++];
   viewId = (Integer) parameters[i++];
   state = (Collection<InternalCacheEntry>) parameters[i++];
   locks = (Collection<LockInfo>) parameters[i];
 }
Beispiel #13
0
 public TypeSampleMap(final Collection<String> samples) {
   super(Type.class);
   for (Type type : Type.values()) {
     Map<String, Integer> bySample = new HashMap<String, Integer>(samples.size());
     for (final String sample : samples) {
       bySample.put(sample, 0);
     }
     bySample.put(ALL, 0);
     this.put(type, bySample);
   }
 }
    /**
     * @param runtimeType the Teiid runtime type being converted (never <code>null</code> or empty)
     * @return the model extension property definition type (newver <code>null</code>)
     * @throws IllegalArgumentException if argument cannot be converted to a valid type
     */
    public static Type convertRuntimeType(String runtimeType) {
      CoreArgCheck.isNotEmpty(runtimeType, "runtimeType is empty"); // $NON-NLS-1$

      for (Type type : Type.values()) {
        if (type.getRuntimeType().equals(runtimeType)) {
          return type;
        }
      }

      throw new IllegalArgumentException(NLS.bind(Messages.invalidRuntimeType, runtimeType));
    }
Beispiel #15
0
 public void decode(ByteBuffer buf) {
   type = Type.values()[buf.getInt()];
   keySize = buf.getInt();
   valueSize = buf.getInt();
   keyCount = buf.getLong();
   order = Order.values()[buf.getInt()];
   distribution = Distribution.values()[buf.getInt()];
   start = buf.getLong();
   end = buf.getLong();
   scanBufferSize = buf.getInt();
 }
    /**
     * Compares the 'xmlValue' with the internal XML value for each of the types until a match is
     * found, which is returned. If no match is found an exception is thrown.
     *
     * @param xmlValue The value to be compared to the Types' XML values.
     * @return A Type that is equivalent to the XML type of one of the Types.
     * @throws IllegalArgumentException Thrown if no Type has the XML type 'xmlValue'.
     */
    public static Type getValue(final String xmlValue) {
      Type[] types = Type.values();

      for (int i = 0; i < types.length; i++) {
        if (types[i].xmlValue.equals(xmlValue)) {
          return types[i];
        }
      }

      throw new IllegalArgumentException("Unknown type.");
    }
 private TreeMap<Integer, Type> buildIndexMap(String msg) {
   int lastIndexOftypes = 0;
   TreeMap<Integer, Type> typesLastIndexInMsg = new TreeMap<Integer, Type>();
   Type[] types = Type.values();
   for (Type t : types) {
     lastIndexOftypes = getIndexOfType(msg, t);
     if (lastIndexOftypes >= 0) {
       typesLastIndexInMsg.put(lastIndexOftypes, t);
     }
   }
   return typesLastIndexInMsg;
 }
 private Type getType(String msg) {
   if (msg == null) {
     return Type.TEXT;
   }
   Type[] types = type.values();
   TreeMap<Integer, Type> typesLastIndexInMsg = buildIndexMap(msg);
   if (typesLastIndexInMsg.size() == 0) {
     return Type.TEXT;
   } else {
     Map.Entry<Integer, Type> lastType = typesLastIndexInMsg.firstEntry();
     return lastType.getValue();
   }
 }
Beispiel #19
0
 /**
  * Retrieves the connectivity that has been collected up until this call. This method fills in
  * {@link ConnectivityCheckResult#UNKNOWN} for results that have not been retrieved yet.
  *
  * @return the {@link FeedbackData}.
  */
 public FeedbackData get() {
   ThreadUtils.assertOnUiThread();
   Map<Type, Integer> result = new EnumMap<Type, Integer>(Type.class);
   // Ensure the map is filled with a result for all {@link Type}s.
   for (Type type : Type.values()) {
     if (mResult.containsKey(type)) {
       result.put(type, mResult.get(type));
     } else {
       result.put(type, ConnectivityCheckResult.UNKNOWN);
     }
   }
   long elapsedTimeMs = SystemClock.elapsedRealtime() - mStartCheckTimeMs;
   int connectionType = NetworkChangeNotifier.getInstance().getCurrentConnectionType();
   return new FeedbackData(result, mTimeoutMs, elapsedTimeMs, connectionType);
 }
Beispiel #20
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();
  }
  private void initAttrs(Context context, AttributeSet attrs) {
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RealmRecyclerView);

    isRefreshable = typedArray.getBoolean(R.styleable.RealmRecyclerView_rrvIsRefreshable, false);
    emptyViewId = typedArray.getResourceId(R.styleable.RealmRecyclerView_rrvEmptyLayoutId, 0);
    int typeValue = typedArray.getInt(R.styleable.RealmRecyclerView_rrvLayoutType, -1);
    if (typeValue != -1) {
      type = Type.values()[typeValue];
    }
    gridSpanCount = typedArray.getInt(R.styleable.RealmRecyclerView_rrvGridLayoutSpanCount, -1);
    gridWidthPx =
        typedArray.getDimensionPixelSize(R.styleable.RealmRecyclerView_rrvGridLayoutItemWidth, -1);
    swipeToDelete = typedArray.getBoolean(R.styleable.RealmRecyclerView_rrvSwipeToDelete, false);
    typedArray.recycle();
  }
Beispiel #22
0
 private void setKMSACLs(Configuration conf) {
   Map<Type, AccessControlList> tempAcls = new HashMap<Type, AccessControlList>();
   Map<Type, AccessControlList> tempBlacklist = new HashMap<Type, AccessControlList>();
   for (Type aclType : Type.values()) {
     String aclStr = conf.get(aclType.getAclConfigKey(), ACL_DEFAULT);
     tempAcls.put(aclType, new AccessControlList(aclStr));
     String blacklistStr = conf.get(aclType.getBlacklistConfigKey());
     if (blacklistStr != null) {
       // Only add if blacklist is present
       tempBlacklist.put(aclType, new AccessControlList(blacklistStr));
       LOG.info("'{}' Blacklist '{}'", aclType, blacklistStr);
     }
     LOG.info("'{}' ACL '{}'", aclType, aclStr);
   }
   acls = tempAcls;
   blacklistedAcls = tempBlacklist;
 }
 /**
  * Magic is like %html %text.
  *
  * @param msg
  * @return
  */
 private String getData(String msg) {
   if (msg == null) {
     return null;
   }
   Type[] types = type.values();
   TreeMap<Integer, Type> typesLastIndexInMsg = buildIndexMap(msg);
   if (typesLastIndexInMsg.size() == 0) {
     return msg;
   } else {
     Map.Entry<Integer, Type> lastType = typesLastIndexInMsg.firstEntry();
     // add 1 for the % char
     int magicLength = lastType.getValue().name().length() + 1;
     // 1 for the last \n or space after magic
     int subStringPos = magicLength + lastType.getKey() + 1;
     return msg.substring(subStringPos);
   }
 }
Beispiel #24
0
 static {
   f5091a = new int[Type.values().length];
   try {
     f5091a[Type.command.ordinal()] = 1;
   } catch (NoSuchFieldError e) {
   }
   try {
     f5091a[Type.result.ordinal()] = 2;
   } catch (NoSuchFieldError e2) {
   }
   try {
     f5091a[Type.conversation.ordinal()] = 3;
   } catch (NoSuchFieldError e3) {
   }
   try {
     f5091a[Type.event.ordinal()] = 4;
   } catch (NoSuchFieldError e4) {
   }
 }
Beispiel #25
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();
  }
  /** Initialize the configuration directory for the VTN Manager. */
  public void init() {
    File parent = getDirectory();
    for (Type type : Type.values()) {
      File dir = new File(parent, type.toString());
      if (dir.isDirectory()) {
        continue;
      }

      if (delete(dir)) {
        LOG.warn("Deleted unexpected configuration file: {}", dir);
      }

      if (dir.mkdirs()) {
        LOG.info("Created configuration directory: {}", dir);
      } else {
        LOG.error("Failed to create configuration directory: {}", dir);
      }
    }
  }
Beispiel #27
0
  @Override
  public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
      if (!scriptEntry.hasObject("type")
          && arg.matchesPrefix("type")
          && arg.matchesEnum(Type.values())) scriptEntry.addObject("type", arg.asElement());
      else if (!scriptEntry.hasObject("file") && arg.matchesPrefix("file"))
        scriptEntry.addObject("file", arg.asElement());
      else if (!scriptEntry.hasObject("message")) scriptEntry.addObject("message", arg.asElement());
      else arg.reportUnhandled();
    }

    if (!scriptEntry.hasObject("message"))
      throw new InvalidArgumentsException("Must specify a message.");

    if (!scriptEntry.hasObject("file")) throw new InvalidArgumentsException("Must specify a file.");

    if (!scriptEntry.hasObject("type")) scriptEntry.addObject("type", new Element("INFO"));
  }
  public static Node read(DataInput in) throws IOException {
    Type type = Type.values()[in.readInt()];
    Node node;

    switch (type) {
      case LEAF:
        node = new Leaf();
        break;
      case NUMERICAL:
        node = new NumericalNode();
        break;
      case CATEGORICAL:
        node = new CategoricalNode();
        break;
      default:
        throw new IllegalStateException("This implementation is not currently supported");
    }

    node.readFields(in);

    return node;
  }
    @Override
    public void handleMessage(final Message msg) {
      final Type[] types = Type.values();
      final Type msgType = types[msg.what];
      final Bundle data = msg.getData();

      switch (msgType) {
        case DOWNLOADING_TEXT_UPDATE:
          final String downloadingText = data.getString(DOWNLOADING_TEXT);
          _activity._downloadingText.setText(downloadingText);
          break;

        case TOTAL_SIZE_UPDATE:
          final long totalSize = data.getLong(TOTAL_SIZE);
          _size = totalSize;
          break;

        case PROGRESS_UPDATE:
          final long progress = data.getLong(PROGRESS);
          _progress += progress;
          final int currentProgress = (int) (_progress * 100 / _size);
          _activity._progressBar.setProgress(currentProgress);
          _activity._progressText.setText(currentProgress + "%");
          break;

        case DOWNLOAD_SUCCESS:
          _activity._downloadingTextTimer.cancel();
          _activity._downloadingText.setText(_activity.getString(R.string.download_success));
          _activity._progressBar.setProgress(100);
          _activity._progressText.setText(100 + "%");
          break;

        case DOWNLOAD_FAILED:
          _activity._downloadingTextTimer.cancel();
          _activity._downloadingText.setText(_activity.getString(R.string.download_failed));
          break;
      }
    }
Beispiel #30
0
    public void readFrom(DataInput in) throws Exception {
      type = Type.values()[in.readByte()];
      // We can't use Util.readObject since it's size is limited to 2^15-1
      try {
        short first = in.readShort();
        if (first == -1) {
          object = Util.readGenericStreamable(in);
        } else {
          ByteBuffer bb = ByteBuffer.allocate(4);
          bb.putShort(first);
          bb.putShort(in.readShort());

          int size = bb.getInt(0);
          byte[] bytes = new byte[size];
          in.readFully(bytes, 0, size);
          object = Util.objectFromByteBuffer(bytes);
        }
      } catch (IOException e) {
        throw e;
      } catch (Exception e) {
        throw new IOException("Exception encountered while serializing execution request", e);
      }
      request = in.readLong();
    }