Exemple #1
0
 /**
  * @param groupName allow groupName is null
  * @param charsetName
  * @param cmd
  * @param errorNo
  * @return
  * @throws FdfsException
  */
 public static byte[] createRequest(String groupName, String charsetName, byte cmd, byte errorNo)
     throws FdfsException {
   byte[] groupNameByteArr = null;
   int headerLength = 10;
   int bodyLength = 0;
   if (Strings.isNotBlank(groupName)) { //
     bodyLength = FDFS_GROUP_NAME_MAX_LEN;
     groupNameByteArr = Strings.getBytes(groupName, charsetName);
   }
   int totalLength = headerLength + bodyLength;
   WriteByteArrayFragment request = new WriteByteArrayFragment(totalLength);
   // writeHeader
   {
     request.writeLong(bodyLength);
     request.writeByte(cmd);
     request.writeByte(errorNo);
   }
   // writeBody
   {
     if (Strings.isNotBlank(groupName)) { //
       request.writeLimitedBytes(groupNameByteArr, FDFS_GROUP_NAME_MAX_LEN);
     }
   }
   return request.getData();
 }
Exemple #2
0
  /*
   * return 0 is success, otherwise failure
   */
  public final int runAdminCommandOnRemoteNode(
      Node thisNode, StringBuilder output, List<String> args, List<String> stdinLines)
      throws SSHCommandExecutionException, IllegalArgumentException, UnsupportedOperationException {

    String humanreadable = null;
    try {
      this.node = thisNode;
      dcomInfo = new DcomInfo(node);
      List<String> fullcommand = new ArrayList<String>();
      WindowsRemoteAsadmin asadmin = dcomInfo.getAsadmin();

      if (stdinLines != null && !stdinLines.isEmpty()) setupAuthTokenFile(fullcommand, stdinLines);

      fullcommand.addAll(args);
      humanreadable = dcomInfo.getNadminPath() + " " + commandListToString(fullcommand);

      // This is where the rubber meets the road...
      String out = asadmin.run(fullcommand);
      output.append(out);
      logger.info(Strings.get("remote.command.summary", humanreadable, out));
      return determineStatus(args);
    } catch (WindowsException ex) {
      throw new SSHCommandExecutionException(
          Strings.get("remote.command.error", ex.getMessage(), humanreadable), ex);
    } finally {
      teardownAuthTokenFile();
    }
  }
Exemple #3
0
  void moveNearMuffin() {
    if (getTitle().equals(Strings.getString("muffin.title"))) {
      return;
    }

    Dimension screenSize = getToolkit().getScreenSize();
    MuffinFrame muffin = getFrame(Strings.getString("muffin.title"));
    Dimension muffinSize = muffin.getSize();
    Point muffinLocation = muffin.getLocationOnScreen();
    Dimension size = getSize();
    int x = 0, y = 0;

    x = muffinLocation.x + muffinSize.width;
    y = muffinLocation.y;

    if (x + size.width > screenSize.width) {
      x = muffinLocation.x - size.width;
      if (x < 0) x = 0;
    }
    if (y + size.height > screenSize.height) {
      y -= (y + size.height) - screenSize.height;
      if (y < 0) y = 0;
    }

    setLocation(x, y);
  }
Exemple #4
0
public interface StdAttr {
  Attribute<Direction> FACING = Attributes.forDirection("facing", Strings.getter("stdFacingAttr"));

  Attribute<BitWidth> WIDTH = Attributes.forBitWidth("width", Strings.getter("stdDataWidthAttr"));

  AttributeOption TRIG_RISING = new AttributeOption("rising", Strings.getter("stdTriggerRising"));
  AttributeOption TRIG_FALLING =
      new AttributeOption("falling", Strings.getter("stdTriggerFalling"));
  AttributeOption TRIG_HIGH = new AttributeOption("high", Strings.getter("stdTriggerHigh"));
  AttributeOption TRIG_LOW = new AttributeOption("low", Strings.getter("stdTriggerLow"));
  Attribute<AttributeOption> TRIGGER =
      Attributes.forOption(
          "trigger",
          Strings.getter("stdTriggerAttr"),
          new AttributeOption[] {TRIG_RISING, TRIG_FALLING, TRIG_HIGH, TRIG_LOW});
  Attribute<AttributeOption> EDGE_TRIGGER =
      Attributes.forOption(
          "trigger",
          Strings.getter("stdTriggerAttr"),
          new AttributeOption[] {TRIG_RISING, TRIG_FALLING});

  Attribute<String> LABEL = Attributes.forString("label", Strings.getter("stdLabelAttr"));

  Attribute<Font> LABEL_FONT = Attributes.forFont("labelfont", Strings.getter("stdLabelFontAttr"));
  Font DEFAULT_LABEL_FONT = new Font("SansSerif", Font.PLAIN, 12);
}
Exemple #5
0
  /**
   * Constructor.
   * @param picture variable marker (info picture)
   * @param def default presentation modifier
   * @param info input info
   * @throws QueryException query exception
   */
  DateFormat(final byte[] picture, final byte[] def, final InputInfo info) throws QueryException {
    super(info);

    // split variable marker
    final int comma = lastIndexOf(picture, ',');
    byte[] pres = comma == -1 ? picture : substring(picture, 0, comma);
    // extract second presentation modifier
    final int pl = pres.length;
    if(pl > 1) {
      final int p = pres[pl - 1];
      if(p == 'a' || p == 'c' || p == 'o' || p == 't') {
        pres = substring(pres, 0, pl - 1);
        if(p == 'o') ordinal = EMPTY;
        if(p == 't') trad = true;
      }
    }

    // choose first character and case
    finish(pres.length == 0 ? def : presentation(pres, def, true));

    // check width modifier
    final byte[] width = comma == -1 ? null : substring(picture, comma + 1);
    if(width != null) {
      final Matcher m = WIDTH.matcher(string(width));
      if(!m.find()) throw PICDATE_X.get(info, width);
      int i = Strings.toInt(m.group(1));
      if(i != Integer.MIN_VALUE) min = i;
      final String mc = m.group(3);
      i = mc != null ? Strings.toInt(mc) : Integer.MIN_VALUE;
      if(i != Integer.MIN_VALUE) max = i;
    }
  }
 @Test
 public void sortByExample4() {
   List<Integer> example = asList(1, 3, 5, 2, 4, 6);
   final List<String> expected = asList("1", "3", "5", "2", "4", "6");
   assertEquals(
       expected,
       Algorithms.sortByExample(
           example,
           Strings.<Integer>string(),
           asList("6", "5", "4", "3", "2", "1"),
           Functions.<String>identity()));
   assertEquals(
       asList("3", "5", "4"),
       Algorithms.sortByExample(
           example,
           Strings.<Integer>string(),
           asList("5", "4", "3"),
           Functions.<String>identity()));
   assertEquals(
       expected,
       Algorithms.sortByExample(
           example,
           Strings.<Integer>string(),
           asList("1", "2", "3", "4", "5", "6", "7", "8", "9"),
           Functions.<String>identity()));
 }
  /** Wait for the server to die. */
  private void waitForDeath() throws CommandException {
    if (!programOpts.isTerse()) {
      // use stdout because logger always appends a newline
      System.out.print(Strings.get("StopInstance.waitForDeath") + " ");
    }
    long startWait = System.currentTimeMillis();
    boolean alive = true;
    int count = 0;

    while (!timedOut(startWait)) {
      if (!isRunning()) {
        alive = false;
        break;
      }
      try {
        Thread.sleep(100);
        if (!programOpts.isTerse() && count++ % 10 == 0) System.out.print(".");
      } catch (InterruptedException ex) {
        // don't care
      }
    }

    if (!programOpts.isTerse()) System.out.println();

    if (alive) {
      throw new CommandException(
          Strings.get("StopInstance.instanceNotDead", (CLIConstants.DEATH_TIMEOUT_MS / 1000)));
    }
  }
  @Test
  public final void testSplitIgnoreInQuotes() {

    Collection<String> split = Strings.splitIgnoreWithinQuotes("tritra  tru lala", ' ');
    assertEquals(3, split.size());
    Iterator<String> it = split.iterator();
    assertEquals("tritra", it.next());
    assertEquals("tru", it.next());
    assertEquals("lala", it.next());

    split = Strings.splitIgnoreWithinQuotes("  tri\"tra tru \" lala", ' ');
    it = split.iterator();
    assertEquals(2, split.size());
    assertEquals("tri\"tra tru \"", it.next());
    assertEquals("lala", it.next());

    split = Strings.splitIgnoreWithinQuotes("aa,\"bb,bb\",cc\",dd\"ee", ',');
    it = split.iterator();
    assertEquals(3, split.size());
    assertEquals("aa", it.next());
    assertEquals("\"bb,bb\"", it.next());
    assertEquals("cc\",dd\"ee", it.next());

    split =
        Strings.splitIgnoreWithinQuotes(
            "xxx  /tmp/demox\"Hello Dolly\"xthisxxxxisxxxx\" a test \"xxx", 'x');
    it = split.iterator();
    assertEquals(5, split.size());
    assertEquals("  /tmp/demo", it.next());
    assertEquals("\"Hello Dolly\"", it.next());
    assertEquals("this", it.next());
    assertEquals("is", it.next());
    assertEquals("\" a test \"", it.next());
  }
  /**
   * Sanity checks code generation by performing it once, parsing the result, then generating code
   * from the second parse tree to verify that it matches the code generated from the first parse
   * tree.
   *
   * @return The regenerated parse tree. Null on error.
   */
  private Node sanityCheckCodeGeneration(Node root) {
    if (compiler.hasHaltingErrors()) {
      // Don't even bother checking code generation if we already know the
      // the code is bad.
      return null;
    }

    String source = compiler.toSource(root);
    Node root2 = compiler.parseSyntheticCode(source);
    if (compiler.hasHaltingErrors()) {
      compiler.report(
          JSError.make(
              CANNOT_PARSE_GENERATED_CODE, Strings.truncateAtMaxLength(source, 100, true)));

      // Throw an exception, so that the infrastructure will tell us
      // which pass violated the sanity check.
      throw new IllegalStateException("Sanity Check failed");
    }

    String source2 = compiler.toSource(root2);
    if (!source.equals(source2)) {
      compiler.report(
          JSError.make(
              GENERATED_BAD_CODE,
              Strings.truncateAtMaxLength(source, 1000, true),
              Strings.truncateAtMaxLength(source2, 1000, true)));

      // Throw an exception, so that the infrastructure will tell us
      // which pass violated the sanity check.
      throw new IllegalStateException("Sanity Check failed");
    }

    return root2;
  }
Exemple #10
0
  /**
   * 如果通过了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP值,
   * 那么真正的用户端的真实IP则是取X-Forwarded-For中第一个非unknown的有效IP字符串。
   *
   * @param request
   * @return
   */
  public static String getIp(HttpServletRequest request) {
    try {
      request.setCharacterEncoding("UTF-8");
    } catch (UnsupportedEncodingException e) {
    }

    String ip = request.getHeader("X-Forwarder-For");
    if ((Strings.isBlank(ip)) || "unknown".equalsIgnoreCase(ip)) {
      ip = request.getHeader("Proxy-Client-Ip");
      if (Strings.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("WL-Proxy-Client-Ip");
      }
    } else {
      String[] ipArr = ip.split(",");
      for (String IP : ipArr) {
        if (!"unknown".equalsIgnoreCase(IP)) {
          ip = IP;
          break;
        }
      }
    }
    if ((Strings.isBlank(ip)) || "unknown".equalsIgnoreCase(ip)) {
      ip = request.getRemoteAddr();
    }
    if ("0:0:0:0:0:0:0:1".equals(ip) || "localhost".equals(ip) || "0.0.0.1".equals(ip))
      ip = "127.0.0.1";
    return ip;
  }
 /**
  * Assert that the given text does not contain the given substring.
  *
  * <pre class="code">
  * Assert.notContains(name, &quot;rod&quot;, &quot;Name must not contain 'rod'&quot;);
  * </pre>
  *
  * @param textToSearch the text to search
  * @param substring the substring to find within the text
  * @param message the exception message to use if the assertion fails
  */
 public static void notContains(String textToSearch, String substring, String message) {
   if (Strings.isNotBlank(textToSearch)
       && Strings.isNotBlank(substring)
       && textToSearch.indexOf(substring) != -1) {
     throw new IllegalArgumentException(message);
   }
 }
  //
  // graphics methods
  //
  @Override
  public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    FontMetrics fm = g.getFontMetrics();
    int asc = fm.getAscent();

    painter.drawBounds();

    String s0;
    String type = getType(painter.getAttributeSet());
    if (type.equals("zero")) s0 = Strings.get("extenderZeroLabel");
    else if (type.equals("one")) s0 = Strings.get("extenderOneLabel");
    else if (type.equals("sign")) s0 = Strings.get("extenderSignLabel");
    else if (type.equals("input")) s0 = Strings.get("extenderInputLabel");
    else s0 = "???"; // should never happen
    String s1 = Strings.get("extenderMainLabel");
    Bounds bds = painter.getBounds();
    int x = bds.getX() + bds.getWidth() / 2;
    int y0 = bds.getY() + (bds.getHeight() / 2 + asc) / 2;
    int y1 = bds.getY() + (3 * bds.getHeight() / 2 + asc) / 2;
    GraphicsUtil.drawText(g, s0, x, y0, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
    GraphicsUtil.drawText(g, s1, x, y1, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);

    BitWidth w0 = painter.getAttributeValue(ATTR_OUT_WIDTH);
    BitWidth w1 = painter.getAttributeValue(ATTR_IN_WIDTH);
    painter.drawPort(0, "" + w0.getWidth(), Direction.WEST);
    painter.drawPort(1, "" + w1.getWidth(), Direction.EAST);
    if (type.equals("input")) painter.drawPort(2);
  }
 @Test
 public void replace_last() {
   assertThat(Strings.replaceLast("", "", "")).isEqualTo("");
   assertThat(Strings.replaceLast("", ".jar", ".txt")).isEqualTo("");
   assertThat(Strings.replaceLast("name.jar", ".jar", ".txt")).isEqualTo("name.txt");
   assertThat(Strings.replaceLast("name.jar", ".toto", ".txt")).isEqualTo("name.jar");
 }
  /**
   * Inserts a given string into another padding it with spaces. Is aware if the insertion point has
   * a space on either end and does not add extra spaces. If the string-to-insert is already present
   * (and not part of another word) we return the original string unchanged.
   *
   * @param s the string to insert into
   * @param insertAt the position to insert the string
   * @param stringToInsert the string to insert
   * @return the result of inserting the stringToInsert into the passed in string
   * @throws IndexOutOfBoundsException if the insertAt is negative, or insertAt is larger than the
   *     length of s String object
   */
  public static String insertPaddedIfNeeded(String s, int insertAt, String stringToInsert) {
    if (Strings.isEmptyOrNull(stringToInsert)) {
      return s;
    }

    boolean found = false;
    int startPos = 0;

    while ((startPos < s.length()) && (!found)) {
      int pos = s.indexOf(stringToInsert, startPos);

      if (pos < 0) break;

      startPos = pos + 1;
      int before = pos - 1;
      int after = pos + stringToInsert.length();

      if (((pos == 0) || (Character.isWhitespace(s.charAt(before))))
          && ((after >= s.length()) || (Character.isWhitespace(s.charAt(after))))) found = true;
    }

    if (found) {
      StringBuilder newText = new StringBuilder(s);

      if (newText.lastIndexOf(SINGLE_SPACE) != newText.length() - 1) {
        newText.append(SINGLE_SPACE);
      }

      return (newText.toString());
    } else return (Strings.insertPadded(s, insertAt, stringToInsert));
  }
Exemple #15
0
  public static byte[] createRequest(
      String groupName, String fileName, String charsetName, byte cmd, byte errorNo)
      throws FdfsException {
    byte[] groupNameByteArr = Strings.getBytes(groupName, charsetName);
    byte[] fileNameByteArr = Strings.getBytes(fileName, charsetName);

    int headerLenght = 10;
    int bodyLength = FDFS_GROUP_NAME_MAX_LEN + fileNameByteArr.length;
    int totalLength = headerLenght + bodyLength;
    WriteByteArrayFragment request = new WriteByteArrayFragment(totalLength);
    // 填充header
    {
      /**
       * FDFS_PROTO_PKG_LEN_SIZE + FDFS_PROTO_CMD_SIZE + FDFS_PROTO_ERR_NO_SIZE = 10
       *
       * <p>head有10个字节,8个字节存消息体的长度,1个字节的cmd,1个字节的errno。
       *
       * <p>|---8bytes(bodyLength)---|---1byte(cmd)---|---1byte(errno)---|
       */
      request.writeLong(bodyLength);
      request.writeByte(cmd);
      request.writeByte(errorNo);
    }
    // 填充body
    {
      request.writeLimitedBytes(groupNameByteArr, FDFS_GROUP_NAME_MAX_LEN);
      request.writeBytes(fileNameByteArr);
    }
    return request.getData();
  }
 @Test
 public void substring_before_last() {
   assertThat(Strings.substringBeforeLast("", "")).isEmpty();
   assertThat(Strings.substringBeforeLast("name.jar", ".")).isEqualTo("name");
   assertThat(Strings.substringBeforeLast("name.jar", ".jar")).isEqualTo("name");
   assertThat(Strings.substringBeforeLast("name.jar", "name.jar")).isEmpty();
   assertThat(Strings.substringBeforeLast("name.jar", "unknown")).isEqualTo("name.jar");
 }
 /**
  * Assert that the given argument String is not empty; that is, it must not be <code>null</code>
  * and not the empty String.
  *
  * <pre class="code">
  * Assert.notEmpty("id",id);
  * </pre>
  *
  * @param argumentName the name of argument to check
  * @param argumentValue the String value to check
  * @throws IllegalArgumentException if the value is <code>null</code> or empty
  */
 public static void notEmptyArgument(String argumentName, String argumentValue) {
   if (Strings.isEmpty(argumentValue)) {
     throw new IllegalArgumentException(
         Strings.format(
             "[Assertion failed] - the argument '{0}' is required, it must not be null or empty",
             argumentName));
   }
 }
 @Test
 public void substring_after() {
   assertThat(Strings.substringAfter("", "")).isEmpty();
   assertThat(Strings.substringAfter("name.jar", ".")).isEqualTo("jar");
   assertThat(Strings.substringAfter("name.jar", ".jar")).isEmpty();
   assertThat(Strings.substringAfter("name.jar", "name.jar")).isEmpty();
   assertThat(Strings.substringAfter("name.jar", "unknown")).isEmpty();
 }
 @Test
 public void strip_quotes() {
   assertThat(Strings.stripQuotes(null)).isNull();
   assertThat(Strings.stripQuotes("")).isEmpty();
   assertThat(Strings.stripQuotes("TEXT")).isEqualTo("TEXT");
   assertThat(Strings.stripQuotes("\"\"")).isEmpty();
   assertThat(Strings.stripQuotes("\"TEXT\"")).isEqualTo("TEXT");
 }
Exemple #20
0
 /**
  * 将一个秒数(天中),转换成一个格式为 HH:mm:ss 的字符串
  *
  * @param sec 秒数
  * @return 格式为 HH:mm:ss 的字符串
  */
 public static String sT(int sec) {
   int[] ss = T(sec);
   return Strings.alignRight(ss[0], 2, '0')
       + ":"
       + Strings.alignRight(ss[1], 2, '0')
       + ":"
       + Strings.alignRight(ss[2], 2, '0');
 }
Exemple #21
0
  @Test
  public void hasLengthWithRange() {
    assert Strings.hasLength("XXX", 0);
    assert Strings.hasLength("XXX", 1);
    assert Strings.hasLength("XXX", 2);
    assert Strings.hasLength("XXX", 3);

    assert !Strings.hasLength("XXX", 4);
  }
  // Use for sort order test for MergeJoin
  // Where attrs is the left "attrnames" or right "attrnames" of MergeJoin
  // check if the first attribute of any key is among "attrnames"
  boolean satisfyOrder(Strings attrNames) {
    if (kind == Kind.ANY) return false;

    if (attrNames.size() == 0) return true;

    if (this.attrNames.size() == 0) return false;

    // Whether the first attribute names match
    return (getAttrName() == attrNames.get(0));
  }
  @Test
  public final void testSplitIgnoreInQuotesEmptyReturns() {

    Collection<String> split = Strings.splitIgnoreWithinQuotes("", ' ');
    assertEquals(0, split.size());
    split = Strings.splitIgnoreWithinQuotes("x", 'x');
    assertEquals(0, split.size());
    split = Strings.splitIgnoreWithinQuotes("   ", ' ');
    assertEquals(0, split.size());
  }
Exemple #24
0
 @Override
 public void mouseReleased(Canvas canvas, Graphics g, MouseEvent e) {
   Project proj = canvas.getProject();
   if (state == MOVING) {
     setState(proj, IDLE);
     computeDxDy(proj, e, g);
     int dx = curDx;
     int dy = curDy;
     if (dx != 0 || dy != 0) {
       if (!proj.getLogisimFile().contains(canvas.getCircuit())) {
         canvas.setErrorMessage(Strings.getter("cannotModifyError"));
       } else if (proj.getSelection().hasConflictWhenMoved(dx, dy)) {
         canvas.setErrorMessage(Strings.getter("exclusiveError"));
       } else {
         boolean connect = shouldConnect(canvas, e.getModifiersEx());
         drawConnections = false;
         ReplacementMap repl;
         if (connect) {
           MoveGesture gesture = moveGesture;
           if (gesture == null) {
             gesture =
                 new MoveGesture(
                     new MoveRequestHandler(canvas),
                     canvas.getCircuit(),
                     canvas.getSelection().getAnchoredComponents());
           }
           canvas.setErrorMessage(new ComputingMessage(dx, dy), COLOR_COMPUTING);
           MoveResult result = gesture.forceRequest(dx, dy);
           clearCanvasMessage(canvas, dx, dy);
           repl = result.getReplacementMap();
         } else {
           repl = null;
         }
         Selection sel = proj.getSelection();
         proj.doAction(SelectionActions.translate(sel, dx, dy, repl));
       }
     }
     moveGesture = null;
     proj.repaintCanvas();
   } else if (state == RECT_SELECT) {
     Bounds bds = Bounds.create(start).add(start.getX() + curDx, start.getY() + curDy);
     Circuit circuit = canvas.getCircuit();
     Selection sel = proj.getSelection();
     Collection<Component> in_sel = sel.getComponentsWithin(bds, g);
     for (Component comp : circuit.getAllWithin(bds, g)) {
       if (!in_sel.contains(comp)) sel.add(comp);
     }
     Action act = SelectionActions.drop(sel, in_sel);
     if (act != null) {
       proj.doAction(act);
     }
     setState(proj, IDLE);
     proj.repaintCanvas();
   }
 }
Exemple #25
0
 /**
  * 根据一个当天的绝对秒数,得到一个时间字符串,格式为 "HH:mm:ss"
  *
  * @param ms 当天的绝对秒数
  * @return 时间字符串
  */
 public static String secs(int sec) {
   int hh = sec / 3600;
   sec -= hh * 3600;
   int mm = sec / 60;
   sec -= mm * 60;
   return Strings.alignRight(hh, 2, '0')
       + ":"
       + Strings.alignRight(mm, 2, '0')
       + ":"
       + Strings.alignRight(sec, 2, '0');
 }
Exemple #26
0
  /**
   * {@link MessageFormat#format(String, Object...)}をラップしているだけですが、
   * 呼び出しに伴い発生する例外は警告レベルでログに出して全て無視します。<br>
   * これは、例外送出時のメッセージなど、フォーマットエラーがあっても処理を続行したい場合に使います。
   *
   * @param pattern NULL
   * @param arguments NULL
   * @return NOT NULL
   */
  public static String format(String pattern, Object... arguments) {
    try {
      return MessageFormat.format(pattern, arguments);

    } catch (Throwable t) { //
      log_s_.log(LogLevel.WARN, t, pattern, arguments);
      return Strings.nullToNullMark(pattern).toString()
          + "; "
          + Strings.concatWithComma(arguments).toString(); // $NON-NLS-1$
    }
  }
  public void getRowData(int firstRow, int numRows, ValueTable.Cell[][] rowData) {
    Model model = getModel();
    TestException[] results = model.getResults();
    int numPass = model.getPass();
    int numFail = model.getFail();
    TestVector vec = model.getVector();
    int columns = vec.columnName.length;
    String msg[] = new String[columns];
    Value[] altdata = new Value[columns];
    String passMsg = Strings.get("passStatus");
    String failMsg = Strings.get("failStatus");

    for (int i = firstRow; i < firstRow + numRows; i++) {
      int row = model.sortedIndex(i);
      Value[] data = vec.data.get(row);
      String rowmsg = null;
      String status = null;
      boolean failed = false;
      if (row < numPass + numFail) {
        TestException err = results[row];
        if (err != null && err instanceof FailException) {
          failed = true;
          for (FailException e = (FailException) err; e != null; e = e.getMore()) {
            int col = e.getColumn();
            msg[col] =
                StringUtil.format(
                    Strings.get("expectedValueMessage"),
                    e.getExpected().toDisplayString(getColumnValueRadix(col + 1)));
            altdata[col] = e.getComputed();
          }
        } else if (err != null) {
          failed = true;
          rowmsg = err.getMessage();
        }
        status = failed ? failMsg : passMsg;
      }

      rowData[i - firstRow][0] =
          new ValueTable.Cell(status, rowmsg != null ? failColor : null, null, rowmsg);

      for (int col = 0; col < columns; col++) {
        rowData[i - firstRow][col + 1] =
            new ValueTable.Cell(
                altdata[col] != null ? altdata[col] : data[col],
                msg[col] != null ? failColor : null,
                null,
                msg[col]);
        msg[col] = null;
        altdata[col] = null;
      }
    }
  }
  @Test
  public final void testSizeInBytes() {
    Assert.assertEquals(0, Strings.getSizeInBytes(""));

    final String normal1 = "Wir koennen spueren, wie wir die Form verlieren.";
    Assert.assertEquals(normal1.getBytes().length, Strings.getSizeInBytes(normal1));
    final String normal2 = "1234567890!@#$%^&*()-_=+`~{}[]\\|'\";:,.<>/?";
    Assert.assertEquals(normal2.getBytes().length, Strings.getSizeInBytes(normal2));

    final String freak =
        "€‚ƒ„…†‡�‰�‹��‘’“”•–—�™�›��� ΅Ά£¤¥¦§¨©�«¬­®―°±²³΄µ¶·ΈΉΊ»Ό½ΎΏΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡ�ΣΤΥΦΧΨΩΪΫάέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώ�";
    Assert.assertEquals(freak.getBytes().length, Strings.getSizeInBytes(freak));
  }
Exemple #29
0
 public void localeChanged() {
   this.setText(Strings.get("fileMenu"));
   newi.setText(Strings.get("fileNewItem"));
   open.setText(Strings.get("fileOpenItem"));
   openRecent.localeChanged();
   close.setText(Strings.get("fileCloseItem"));
   save.setText(Strings.get("fileSaveItem"));
   saveAs.setText(Strings.get("fileSaveAsItem"));
   exportImage.setText(Strings.get("fileExportImageItem"));
   print.setText(Strings.get("filePrintItem"));
   prefs.setText(Strings.get("filePreferencesItem"));
   quit.setText(Strings.get("fileQuitItem"));
 }
Exemple #30
0
  /**
   * Initializes the date format.
   *
   * @param d input
   * @param e example format
   * @param ii input info
   * @throws QueryException query exception
   */
  final void date(final byte[] d, final String e, final InputInfo ii) throws QueryException {
    final Matcher mt = DATE.matcher(Token.string(d).trim());
    if (!mt.matches()) throw dateError(d, e, ii);
    yea = toLong(mt.group(1), false, ii);
    // +1 is added to BC values to simplify computations
    if (yea < 0) yea++;
    mon = (byte) (Strings.toInt(mt.group(3)) - 1);
    day = (byte) (Strings.toInt(mt.group(4)) - 1);

    if (mon < 0 || mon >= 12 || day < 0 || day >= dpm(yea, mon)) throw dateError(d, e, ii);
    if (yea <= MIN_YEAR || yea > MAX_YEAR) throw DATERANGE_X_X.get(ii, type, chop(d, ii));
    zone(mt, 5, d, ii);
  }