@Override
  public TextGraphics putString(int column, int row, String string) {
    if (string.contains("\n")) {
      string = string.substring(0, string.indexOf("\n"));
    }
    if (string.contains("\r")) {
      string = string.substring(0, string.indexOf("\r"));
    }
    string = tabBehaviour.replaceTabs(string, column);
    int offset = 0;
    for (int i = 0; i < string.length(); i++) {
      char character = string.charAt(i);
      setCharacter(
          column + offset,
          row,
          new TextCharacter(character, foregroundColor, backgroundColor, activeModifiers.clone()));

      if (CJKUtils.isCharCJK(character)) {
        // CJK characters are twice the normal characters in width, so next character position is
        // two columns forward
        offset += 2;
      } else {
        // For "normal" characters we advance to the next column
        offset += 1;
      }
    }
    return this;
  }
 /** Returns the intersection of two enumsets */
 public static <E extends Enum<E>> EnumSet<E> intersection(EnumSet<E> s1, EnumSet<E> s2) {
   // We have to clone, since retainAll modifies the set
   EnumSet<E> s = s1.clone();
   s.retainAll(s2);
   // I tried coding this for arbitrary sets, but it failed because
   // the interface Cloneable does not make sure that the clone-method
   // is visible (!)
   return (s);
 }
Beispiel #3
0
  /**
   * Create a bind rule that matches a desire when the desired type equals <tt>depType</tt> and the
   * desire's qualifier matches <tt>qualifier</tt> .
   *
   * @param depType The dependency type this bind rule matches
   * @param satisfaction The Satisfaction used by applied desires
   * @param policy The CachePolicy for nodes created by this bind rule
   * @param qualifier The Qualifier the bind rule applies to
   * @param flags The flags to apply to this bind rule and its results.
   * @throws NullPointerException if arguments are null
   */
  public BindRuleImpl(
      @Nonnull Class<?> depType,
      @Nonnull Satisfaction satisfaction,
      @Nonnull CachePolicy policy,
      @Nonnull QualifierMatcher qualifier,
      EnumSet<BindingFlag> flags) {
    Preconditions.notNull("dependency type", depType);
    Preconditions.notNull("satisfaction", satisfaction);
    Preconditions.notNull("policy", policy);
    Preconditions.notNull("qualifier matcher", qualifier);

    this.qualifier = qualifier;
    this.satisfaction = satisfaction;
    this.implType = satisfaction.getErasedType();
    this.policy = policy;
    this.depType = Types.box(depType);
    this.flags = flags.clone();

    // verify that the satisfaction produces proper types
    Preconditions.isAssignable(this.depType, this.implType);
  }
Beispiel #4
0
  /**
   * As the other constructor, but this is used for type to type bindings where the implementation
   * type is not yet instantiable, so there is no satisfaction for the applied desires.
   *
   * @param depType The dependency type this bind rule matches
   * @param implType The implementation type that is bound
   * @param policy The CachePolicy for nodes created by this bind rule
   * @param qualifier The Qualifier the bind rule applies to
   * @param flags The flags to apply to this bind rule and its results.
   * @throws NullPointerException if arguments are null
   */
  public BindRuleImpl(
      @Nonnull Class<?> depType,
      @Nonnull Class<?> implType,
      @Nonnull CachePolicy policy,
      @Nonnull QualifierMatcher qualifier,
      EnumSet<BindingFlag> flags) {
    Preconditions.notNull("dependency type", depType);
    Preconditions.notNull("implementation type", implType);
    Preconditions.notNull("policy", policy);
    Preconditions.notNull("qualifier matcher", qualifier);

    this.qualifier = qualifier;
    this.satisfaction = null;
    this.implType = Types.box(implType);
    this.policy = policy;
    this.depType = Types.box(depType);
    this.flags = flags.clone();

    // verify that implType extends depType
    Preconditions.isAssignable(this.depType, this.implType);
  }
Beispiel #5
0
  @SuppressWarnings("unchecked")
  NotifyingFuture<V> getAsync(
      final K key, final EnumSet<Flag> explicitFlags, final ClassLoader explicitClassLoader) {
    final Transaction tx = getOngoingTransaction();
    final NotifyingNotifiableFuture f = new DeferredReturnFuture();

    // Optimization to not start a new thread only when the operation is cheap:
    if (asyncSkipsThread(explicitFlags, key)) {
      return wrapInFuture(get(key, explicitFlags, explicitClassLoader));
    } else {
      // Make sure the flags are cleared
      final EnumSet<Flag> appliedFlags;
      if (explicitFlags == null) {
        appliedFlags = null;
      } else {
        appliedFlags = explicitFlags.clone();
        explicitFlags.clear();
      }
      Callable<V> c =
          new Callable<V>() {
            @Override
            public V call() throws Exception {
              assertKeyNotNull(key);
              InvocationContext ctx =
                  getInvocationContextForRead(tx, appliedFlags, explicitClassLoader);
              GetKeyValueCommand command =
                  commandsFactory.buildGetKeyValueCommand(key, appliedFlags);
              Object ret = invoker.invoke(ctx, command);
              f.notifyDone();
              return (V) ret;
            }
          };
      f.setNetworkFuture(asyncExecutor.submit(c));
      return f;
    }
  }
 static {
   FIRST_SET = EnumSet.of(CONST, VAR, PROC, FUNC, TYPE);
   FOLLOW_SET = EnumSet.of(SEMICOLON, IN);
   FIRST_FOLLOW_SET = FIRST_SET.clone();
   FIRST_FOLLOW_SET.addAll(FOLLOW_SET);
 }
 /** Returns the union of two enumsets */
 public static <E extends Enum<E>> EnumSet<E> union(EnumSet<E> s1, EnumSet<E> s2) {
   EnumSet<E> s = s1.clone();
   s.addAll(s2);
   return (s);
 }