Example #1
0
  /**
   * Parse a value.
   *
   * @param tb Source.
   * @param type The type of the array, may be any..
   * @param valueList Result added here.
   * @return Return true if a value has been added to the valueList and the cursor advanced or false
   *     and the cursor is as it was.
   */
  private static boolean value(Text t, DataType type, List<Object> valueList) {
    boolean result;

    if (t.isEof()) {
      result = false;
    } else if (t.consume("null")) {
      valueList.add(null);
      result = true;
    } else {
      switch (type) {
        case z:
        case Z:
        case f:
        case F:
          result = number(t, type, valueList);
          break;

        case text:
          result = text(t, valueList);
          break;

        case identifier:
          result = identifier(t, valueList);
          break;

        case path:
          result = path(t, valueList);
          break;

        case datetime:
          result = datetime(t, valueList);
          break;

        case date:
          result = date(t, valueList);
          break;

        case time:
          result = time(t, valueList);
          break;

        case bool:
          result = bool(t, valueList);
          break;

        case cardinality:
          result = cardinality(t, valueList);
          break;

        case any:
          result = any(t, valueList);
          break;

        default:
          throw new UnexpectedException("value: " + type);
      }
    }

    return result;
  }
  /** Method to set default values of abstract dialog */
  public void setDefaultQueryDialogOptions() {
    // To prevent selecting current view as it is the default value
    if (!currentViewButton.isEnabled()) {
      currentViewButton.setSelection(false);
      newViewButton.setSelection(true);
    } else {
      currentViewButton.setSelection(true);
      newViewButton.setSelection(false);
    }

    lengthLimit.setText(String.valueOf(DEFAULT_LENGTH_LIMIT));

    if (bothButton != null) {
      bothButton.setSelection(true);
      downstreamButton.setSelection(false);
      upstreamButton.setSelection(false);
    } else if (downstreamButton != null) {
      downstreamButton.setSelection(true);
      upstreamButton.setSelection(false);
    }

    if (shortestPlusK != null) {
      shortestPlusK.setText(String.valueOf(DEFAULT_SHORTEST_PLUS_K));
      shortestPlusKButton.setSelection(false);
      strictButton.setSelection(false);
    }
  }
Example #3
0
  /**
   * Parse a string value and covert it to its proper data type.
   *
   * @param value
   * @return The parsed value.
   * @throws ParsingException Thrown if not Advisory is available and there was an error parsing.
   */
  @SuppressWarnings("unchecked")
  public static <T> T parseValue(String value) throws ParsingException {
    final T result;

    assert value != null;

    /*
     * todo Restructure the whole class so I've got parse and parseArray as
     * static methods and the share code properly.
     */
    if ("null".equals(value)) {
      result = null;
    } else {
      final List<Object> list = new ArrayList<>();
      final Text t = new Text();
      t.append(value);

      if (any(t, list) && t.isEof()) {
        result = (T) list.get(0);
      } else {
        error("Count not parse value: " + value);
        result = null;
      }
    }

    return result;
  }
Example #4
0
  /** Check whether the file list have duplication. */
  private static void checkDuplication(FileSystem fs, Path file, Path sorted, Configuration conf)
      throws IOException {
    SequenceFile.Reader in = null;
    try {
      SequenceFile.Sorter sorter =
          new SequenceFile.Sorter(fs, new Text.Comparator(), Text.class, Text.class, conf);
      sorter.sort(file, sorted);
      in = new SequenceFile.Reader(fs, sorted, conf);

      Text prevdst = null, curdst = new Text();
      Text prevsrc = null, cursrc = new Text();
      for (; in.next(curdst, cursrc); ) {
        if (prevdst != null && curdst.equals(prevdst)) {
          throw new DuplicationException(
              "Invalid input, there are duplicated files in the sources: "
                  + prevsrc
                  + ", "
                  + cursrc);
        }
        prevdst = curdst;
        curdst = new Text();
        prevsrc = cursrc;
        cursrc = new Text();
      }
    } finally {
      checkAndClose(in);
    }
  }
  private void parseSampleURL(DBPDriver driver) {
    metaURL = null;

    if (!CommonUtils.isEmpty(driver.getSampleURL())) {
      isCustom = false;
      try {
        metaURL = DriverDescriptor.parseSampleURL(driver.getSampleURL());
      } catch (DBException e) {
        setErrorMessage(e.getMessage());
      }
      final Set<String> properties = metaURL.getAvailableProperties();
      urlText.setEditable(false);
      // urlText.setBackground(urlText.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));

      showControlGroup(GROUP_HOST, properties.contains(DriverDescriptor.PROP_HOST));
      showControlGroup(GROUP_SERVER, properties.contains(DriverDescriptor.PROP_SERVER));
      showControlGroup(GROUP_DB, properties.contains(DriverDescriptor.PROP_DATABASE));
      showControlGroup(
          GROUP_PATH,
          properties.contains(DriverDescriptor.PROP_FOLDER)
              || properties.contains(DriverDescriptor.PROP_FILE));
    } else {
      isCustom = true;
      showControlGroup(GROUP_HOST, false);
      showControlGroup(GROUP_SERVER, false);
      showControlGroup(GROUP_DB, false);
      showControlGroup(GROUP_PATH, false);
      urlText.setEditable(true);
      urlText.setBackground(null);
    }
    showControlGroup(GROUP_LOGIN, !driver.isAnonymousAccess());
    updateCreateButton(driver);

    settingsGroup.layout();
  }
Example #6
0
  private static boolean number(Text t, DataType requiredType, List<Object> valueList) {
    // posNumber
    // : cardinality
    // | '0b' BinaryDigits+ [zZ]?
    // | '0x' HexDigit+ [zZ]?
    // | '-'? Pint? ( '.' Digit+ ) ('e' Pint) [fF]
    // | '-'? Pint [zZfF]?
    // ;
    final boolean result;

    assert !t.isEof() : "Should have been checked by caller";

    if (binary(t, valueList, requiredType) || hex(t, valueList, requiredType)) {
      // ?todo I could allow negatives here
      // ( binary | hex | '0' )
      result = true;
    } else {
      // ( Int DecPart | Int | DecPart ) ( 'e' Int )? [zZfF]?

      final int start = t.cursor();

      if ((t.consumeInt() && (decPart(t) || true) && (exponent(t) || true))
          || (t.consume('-') || true) && decPart(t) && (exponent(t) || true)) {
        final String string = t.getString(start);
        final Object value = deriveType(string, requiredType, t, 10);
        valueList.add(value);
        result = true;
      } else {
        result = false;
      }
    }
    return result;
  }
Example #7
0
    // specify input and out keys
    public void map(
        LongWritable key, Text value, OutputCollector<Text, Text> output, Reporter reporter)
        throws IOException {
      String line = value.toString(); // define new variable to be string

      ArrayList<Integer> range = new ArrayList<Integer>();
      for (int i = 2000; i <= 2010; i++) {
        range.add(i);
      }

      // String[] inputs = line.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
      String[] inputs = line.split(",");

      try {

        int year = Integer.parseInt(inputs[165]);

        if (range.contains(year)) {
          String dur = inputs[3];
          String artist_name = inputs[2];
          String song_title = inputs[1];
          String final_input = artist_name + ',' + dur + ',' + song_title;
          Final_Value.set(final_input);
          output.collect(Final_Value, dummy);
        }
      } catch (NumberFormatException e) {
        // do nothing
      }
    }
Example #8
0
 public void draw(GOut g) {
   g.chcolor(0, 0, 0, 160);
   if (ctl == null || csz == null) {
     return;
   }
   g.frect(ctl, csz);
   g.chcolor();
   cdraw(g.reclip(xlate(Coord.z, true), asz));
   if (cap != null) {
     topless.draw(g, new Coord(0, th), sz.sub(0, th));
     g.image(tleft, Coord.z);
     Coord tmul = new Coord(tleft.sz().x, tdh);
     Coord tmbr = new Coord(sz.x - tright.sz().x, th);
     for (int x = tmul.x; x < tmbr.x; x += tmain.sz().x) {
       g.image(tmain, new Coord(x, tdh), tmul, tmbr);
     }
     g.image(tright, new Coord(sz.x - tright.sz().x, tdh));
     g.image(cap.tex(), capc.sub(0, cap.sz().y));
   } else {
     wbox.draw(g, Coord.z, sz);
   }
   /*
   if(cap != null) {
       GOut cg = og.reclip(new Coord(0, -7), sz.add(0, 7));
       int w = cap.tex().sz().x;
       cg.image(cl, new Coord((sz.x / 2) - (w / 2) - cl.sz().x, 0));
       cg.image(cm, new Coord((sz.x / 2) - (w / 2), 0), new Coord(w, cm.sz().y));
       cg.image(cr, new Coord((sz.x / 2) + (w / 2), 0));
       cg.image(cap.tex(), new Coord((sz.x / 2) - (w / 2), 0));
   }
   */
   super.draw(g);
 }
  /** Method for creating Length Limit Label and Text */
  protected void createLengthLimit(
      int horizontalSpanLabel,
      int verticalSpanLabel,
      int horizontalSpanText,
      int verticalSpanText,
      int minTextWidth) {
    // Length Limit Label

    lengthLimitLabel = new Label(shell, SWT.NONE);
    lengthLimitLabel.setText("Length limit");
    GridData gridData = new GridData(GridData.END, GridData.CENTER, false, false);
    gridData.horizontalSpan = horizontalSpanLabel;
    gridData.verticalSpan = verticalSpanLabel;
    lengthLimitLabel.setLayoutData(gridData);

    // Length Limit Text

    lengthLimit = new Text(shell, SWT.BORDER);
    lengthLimit.addKeyListener(keyAdapter);
    gridData = new GridData(GridData.BEGINNING, GridData.CENTER, false, false);
    gridData.horizontalSpan = horizontalSpanText;
    gridData.verticalSpan = verticalSpanText;
    gridData.widthHint = minTextWidth;
    lengthLimit.setLayoutData(gridData);
  }
Example #10
0
    public void map(LongWritable key, Text value, Context context)
        throws IOException, InterruptedException {
      String line = value.toString();
      String[] arr = line.split(",");

      word.set(arr[0]);
      context.write(word, one);
    }
Example #11
0
 /**
  * @param text element definition
  * @return pattern element for text
  */
 private ProcPatternElement create(Text text) {
   Scope scope = text.getScope();
   if (scope != null) {
     return new ProcText(text.getName(), createScope(scope), text.isTransparent());
   } else {
     return new ProcText(text.getName(), text.isTransparent());
   }
 }
  /**
   * @param sourceFile File to read from
   * @return List of String objects with the shas
   */
  public static FileRequestFileContent readRequestFile(final File sourceFile) {
    if (!sourceFile.isFile() || !(sourceFile.length() > 0)) {
      return null;
    }
    Document d = null;
    try {
      d = XMLTools.parseXmlFile(sourceFile.getPath());
    } catch (final Throwable t) {
      logger.log(Level.SEVERE, "Exception in readRequestFile, during XML parsing", t);
      return null;
    }

    if (d == null) {
      logger.log(Level.SEVERE, "Could'nt parse the request file");
      return null;
    }

    final Element rootNode = d.getDocumentElement();

    if (rootNode.getTagName().equals(TAG_FrostFileRequestFile) == false) {
      logger.severe(
          "Error: xml request file does not contain the root tag '"
              + TAG_FrostFileRequestFile
              + "'");
      return null;
    }

    final String timeStampStr = XMLTools.getChildElementsTextValue(rootNode, TAG_timestamp);
    if (timeStampStr == null) {
      logger.severe("Error: xml file does not contain the tag '" + TAG_timestamp + "'");
      return null;
    }
    final long timestamp = Long.parseLong(timeStampStr);

    final List<Element> nodelist = XMLTools.getChildElementsByTagName(rootNode, TAG_shaList);
    if (nodelist.size() != 1) {
      logger.severe("Error: xml request files must contain only one element '" + TAG_shaList + "'");
      return null;
    }

    final Element rootShaNode = nodelist.get(0);

    final List<String> shaList = new LinkedList<String>();
    final List<Element> xmlKeys = XMLTools.getChildElementsByTagName(rootShaNode, TAG_sha);
    for (final Element el : xmlKeys) {

      final Text txtname = (Text) el.getFirstChild();
      if (txtname == null) {
        continue;
      }

      final String sha = txtname.getData();
      shaList.add(sha);
    }

    final FileRequestFileContent content = new FileRequestFileContent(timestamp, shaList);
    return content;
  }
 public void map(LongWritable key, Text value, Context context)
     throws IOException, InterruptedException {
   String line = value.toString();
   StringTokenizer tokenizer = new StringTokenizer(line);
   while (tokenizer.hasMoreTokens()) {
     word.set(tokenizer.nextToken());
     context.write(word, one);
   }
 }
 public void map(LongWritable key, Text value, Context context)
     throws IOException, InterruptedException {
   Text word = new Text();
   StringTokenizer s = new StringTokenizer(value.toString());
   while (s.hasMoreTokens()) {
     word.set(s.nextToken());
     context.write(word, one);
   }
 }
 public void map(LongWritable key, Text value, OutputCollector output, Reporter reporter)
     throws IOException {
   String line = value.toString();
   StringTokenizer tokenizer = new StringTokenizer(line);
   while (tokenizer.hasMoreTokens()) {
     word.set(tokenizer.nextToken());
     output.collect(word, one);
   }
 }
Example #16
0
  public void draw(GOut g) {
    Coord c = new Coord(xoff, 0);
    for (Spec s : inputs) {
      GOut sg = g.reclip(c, Inventory.invsq.sz());
      sg.image(Inventory.invsq, Coord.z);
      s.draw(sg);
      c = c.add(Inventory.sqsz.x, 0);
    }
    if (qmod != null) {
      g.image(qmodl.tex(), new Coord(0, qmy + 4));
      c = new Coord(xoff, qmy);
      int mx = -1;
      int pw = 0;
      int vl = 1;
      for (Indir<Resource> qm : qmod) {
        try {
          Tex t = qm.get().layer(Resource.imgc).tex();
          g.image(t, c);
          c = c.add(t.sz().x + 1, 0);
          if (c.x > mx) mx = c.x;

          try {
            Glob.CAttr attr = ui.gui.chrwdg.findattr(qm.get().basename());
            if (attr != null) {
              pw++;
              vl *= attr.comp;
              Tex txt = attr.comptex();
              g.image(txt, c);
              c = c.add(txt.sz().x + 8, 0);
            }
          } catch (Exception ignored) {
          }

        } catch (Loading l) {
        }
      }
      if (pw > 0) {
        g.image(
            Text.renderstroked(
                    String.format("Cap: %.0f", Math.floor(Math.pow(vl, 1.0f / pw))),
                    Color.WHITE,
                    Color.BLACK,
                    new Text.Foundry(Text.fraktur, 14).aa(true))
                .tex(),
            new Coord(mx + 30, qmy));
      }
    }
    c = new Coord(xoff, outy);
    for (Spec s : outputs) {
      GOut sg = g.reclip(c, Inventory.invsq.sz());
      sg.image(Inventory.invsq, Coord.z);
      s.draw(sg);
      c = c.add(Inventory.sqsz.x, 0);
    }
    super.draw(g);
  }
Example #17
0
  /**
   * Given the parsing context and what numerical data type is expected convert a string to the
   * correct type. Note no attempt is made to let the magnitude of the number influence our choice.
   *
   * @param string The string to convert to a number. E.g. "123.3e2". If it contains a '.' or an 'e'
   *     then the type must either be f or F.
   * @param requiredType Either z, Z, f, F or any.
   * @param tb The source. The cursor will be at the end of the number but any type specifier will
   *     not have been consumed. If there is one then we'll eat it.
   * @return The derived type.
   * @throws ParsingException If there is a clash of types.
   */
  private static Object deriveType(String string, DataType requiredType, Text t, int radix) {
    final Object result;

    // Figure out the correct type...
    final DataType derivedType;
    if (t.isEof()) {
      if (requiredType == DataType.any) {
        if (string.indexOf('.') >= 0 || string.indexOf('e') >= 0) {
          derivedType = DataType.f;
        } else {
          derivedType = DataType.z;
        }
      } else {
        derivedType = requiredType;
      }
    } else {
      final char c = t.peek();
      if (c == 'z' || c == 'Z' || c == 'f' || c == 'F') {
        t.consume(c);
        derivedType = DataType.valueOf(String.valueOf(c));
        if (!(requiredType == DataType.any || requiredType == derivedType)) {
          throw new ParsingException("Incompatible type: " + string + c);
        }
      } else {
        if (requiredType == DataType.any) {
          if (string.indexOf('.') >= 0 || string.indexOf('e') >= 0) {
            derivedType = DataType.f;
          } else {
            derivedType = DataType.z;
          }
        } else {
          derivedType = requiredType;
        }
      }
    }

    switch (derivedType) {
      case z:
        result = new Long(Long.parseLong(string, radix));
        break;
      case Z:
        result = new BigInteger(string, radix);
        break;
      case f:
        result = new Double(string);
        break;
      case F:
        result = new BigDecimal(string);
        break;
        // $CASES-OMITTED$
      default:
        throw new UnexpectedException("toType: " + derivedType);
    }

    return result;
  }
 public void map(
     IntWritable key, Text value, OutputCollector<IntWritable, Text> output, Reporter reporter)
     throws IOException {
   String dataRow = value.toString();
   StringTokenizer tk = new StringTokenizer(dataRow);
   String label = tk.nextToken();
   String image = tk.nextToken();
   dataString.set(label + "\t" + image);
   output.collect(sameKey, dataString);
 }
  protected void createLimitTypesGroup() {
    GridData gridData; // Group for lengthLimitButton and shortestPlusKButton

    Group limitTypeGroup = new Group(shell, SWT.NONE);
    limitTypeGroup.setText("Stop distance");
    gridData = new GridData(GridData.FILL, GridData.BEGINNING, false, false);
    gridData.horizontalSpan = 2;
    gridData.verticalSpan = 2;
    limitTypeGroup.setLayoutData(gridData);
    limitTypeGroup.setLayout(new GridLayout(2, true));

    // Length limit radio button

    lengthLimitLabel = new Label(limitTypeGroup, SWT.NONE);
    lengthLimitLabel.setText("Length limit");
    gridData = new GridData(GridData.BEGINNING, GridData.CENTER, false, false);
    lengthLimitLabel.setLayoutData(gridData);

    // Length limit text

    lengthLimit = new Text(limitTypeGroup, SWT.BORDER);
    lengthLimit.addKeyListener(keyAdapter);
    gridData = new GridData(GridData.FILL, GridData.CENTER, false, false);
    lengthLimit.setLayoutData(gridData);

    // Shortest+k radio button

    shortestPlusKButton = new Button(limitTypeGroup, SWT.CHECK);
    shortestPlusKButton.setText("Shortest+k");
    gridData = new GridData(GridData.BEGINNING, GridData.CENTER, false, false);
    shortestPlusKButton.setLayoutData(gridData);
    shortestPlusKButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            shortestPlusK.setEnabled(shortestPlusKButton.getSelection());
          }
        });

    // Shortest+k text

    shortestPlusK = new Text(limitTypeGroup, SWT.BORDER);
    shortestPlusK.addKeyListener(keyAdapter);
    gridData = new GridData(GridData.FILL, GridData.CENTER, false, false);
    shortestPlusK.setLayoutData(gridData);

    // Strict check box

    strictButton = new Button(shell, SWT.CHECK | SWT.WRAP);
    strictButton.setText("Ignore source-source/target-target paths");
    gridData = new GridData(GridData.CENTER, GridData.CENTER, false, false);
    gridData.verticalSpan = 2;
    gridData.horizontalSpan = 4;
    strictButton.setLayoutData(gridData);
  }
Example #20
0
  /** Creates a text that controls whether a border radius is set on the registered controls. */
  protected void cteateRoundedBorderGroup() {
    Group group = new Group(styleComp, SWT.NONE);
    group.setText("Rounded Border");
    group.setLayout(new GridLayout(2, false));
    new Label(group, SWT.NONE).setText("Width");
    final Text textWidth = new Text(group, SWT.SINGLE | SWT.BORDER);
    textWidth.setLayoutData(new GridData(20, SWT.DEFAULT));
    new Label(group, SWT.NONE).setText("Color");
    final Button buttonColor = new Button(group, SWT.PUSH);
    buttonColor.setLayoutData(new GridData(20, 20));
    buttonColor.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(final SelectionEvent event) {
            rbIndex = (rbIndex + 1) % bgColors.length;
            if (bgColors[rbIndex] == null) {
              buttonColor.setText("");
            } else {
              buttonColor.setText("\u2588");
            }
            buttonColor.setForeground(bgColors[rbIndex]);
          }
        });
    new Label(group, SWT.NONE).setText("Radius ");
    Composite radiusGroup = new Composite(group, SWT.NONE);
    radiusGroup.setLayout(new GridLayout(4, false));
    new Label(radiusGroup, SWT.NONE).setText("T-L");
    final Text textTopLeft = new Text(radiusGroup, SWT.SINGLE | SWT.BORDER);
    textTopLeft.setLayoutData(new GridData(20, SWT.DEFAULT));
    new Label(radiusGroup, SWT.NONE).setText("T-R");
    final Text textTopRight = new Text(radiusGroup, SWT.SINGLE | SWT.BORDER);
    textTopRight.setLayoutData(new GridData(20, SWT.DEFAULT));
    new Label(radiusGroup, SWT.NONE).setText("B-L");
    final Text textBottomLeft = new Text(radiusGroup, SWT.SINGLE | SWT.BORDER);
    textBottomLeft.setLayoutData(new GridData(20, SWT.DEFAULT));
    new Label(radiusGroup, SWT.NONE).setText("B-R");
    final Text textBottomRight = new Text(radiusGroup, SWT.SINGLE | SWT.BORDER);
    textBottomRight.setLayoutData(new GridData(20, SWT.DEFAULT));
    Button button = new Button(group, SWT.PUSH);
    button.setText("Set");
    button.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(final SelectionEvent e) {
            int width = parseInt(textWidth.getText());
            Color color = buttonColor.getBackground();
            int topLeft = parseInt(textTopLeft.getText());
            int topRight = parseInt(textTopRight.getText());
            int bottomRight = parseInt(textBottomRight.getText());
            int bottomLeft = parseInt(textBottomLeft.getText());
            updateRoundedBorder(width, color, topLeft, topRight, bottomRight, bottomLeft);
          }
        });
  }
    public void reduce(Text key, Iterable<Text> values, Context context)
        throws IOException, InterruptedException {
      String input[];
      double result = 0.0;

      /* adds all the values corresponding to a key */
      for (Text value : values) {
        result += Double.parseDouble(value.toString());
      }

      context.write(null, new Text(key + "," + Double.toString(result)));
    }
  /**
   * After creating the dialog box, initial values are assigned to the fields with data in opt
   * OptionsPack
   */
  public void setInitialValues(QueryOptionsPack opt) {
    if (main.getPathwayGraph() == null) {
      newViewButton.setSelection(true);
      currentViewButton.setSelection(false);
      currentViewButton.setEnabled(false);
      opt.setCurrentView(false);
    }

    if (opt.isCurrentView()) {
      currentViewButton.setSelection(true);
    } else {
      newViewButton.setSelection(true);
    }

    lengthLimit.setText(String.valueOf(opt.getLengthLimit()));

    if (sourceST != null && opt.getSourceList() != null) {
      sourceST.symbolText.setText(opt.getOneStringSources());
    }
    if (targetST != null && opt.getTargetList() != null) {
      targetST.symbolText.setText(opt.getOneStringTargets());
    }

    if (downstreamButton != null) {
      // Downstream, Upstream or Both

      if (opt.isDownstream() && opt.isUpstream() && bothButton != null) {
        bothButton.setSelection(true);
      } else if (opt.isDownstream()) {
        downstreamButton.setSelection(true);
      } else if (opt.isUpstream()) {
        upstreamButton.setSelection(true);
      }
    }

    if (strictButton != null) {
      // Strict
      if (opt.isStrict()) {
        strictButton.setSelection(true);
      }
    }

    // Set both texts' values

    if (shortestPlusK != null) {
      shortestPlusK.setText(String.valueOf(opt.getShortestPlusKLimit()));
    }

    if (shortestPlusKButton != null) {
      shortestPlusKButton.setSelection(!opt.getLimitType());
    }
  }
 private Text createTextInput(
     Composite parent, String labelKey, String configKey, String defaultValue, int widthHint) {
   // TODO: use this method to create all text inputs
   createLabel(parent, labelKey);
   final Text t = new Text(parent, SWT.BORDER);
   final GridData gd = new GridData();
   if (widthHint > 0) gd.widthHint = widthHint;
   t.setLayoutData(gd);
   String val = controller.getConfig().getString(configKey);
   if ("".equals(val) && defaultValue != null) val = defaultValue;
   t.setText(String.valueOf(val));
   return t;
 }
Example #24
0
 /**
  * This is just a helper function for the fromXML method.
  *
  * @param child
  */
 public void importHelper(Node child) {
   if (child.getFirstChild() instanceof Text) {
     Text text = (Text) child.getFirstChild();
     String data = text.getData();
     if (child.getNodeName().equals("description")) {
       setDescription(data);
     }
     if (child.getNodeName().equals("refChildPattern")) {
       int decID = Integer.parseInt(data.substring(1));
       subPatternsID.add(decID);
     }
   }
 }
  /** After clicking execute button, all data in dialog is saved to GoIOptionsPack */
  public void storeValuesToOptionsPack(QueryOptionsPack opt) {
    // store Length Limit
    opt.setLengthLimit(Integer.parseInt(lengthLimit.getText()));

    // if currentView is selected
    if (currentViewButton.getSelection()) {
      opt.setCurrentView(true);
    }
    // if newView is selected
    else {
      opt.setCurrentView(false);
    }

    if (downstreamButton != null) {
      // if downstream is selected
      if (downstreamButton.getSelection()) {
        opt.setDownstream(true);
        opt.setUpstream(false);
      }
      // if upstream is selected
      else if (upstreamButton.getSelection()) {
        opt.setDownstream(false);
        opt.setUpstream(true);
      }
      // if both is selected
      else {
        opt.setDownstream(true);
        opt.setUpstream(true);
      }
    }

    // store stop distance according to user's selection
    if (shortestPlusKButton != null) {
      opt.setLimitType(!shortestPlusKButton.getSelection());
      opt.setShortestPlusKLimit(Integer.parseInt(shortestPlusK.getText()));
    }

    // if strict is selected.
    if (strictButton != null && strictButton.getSelection()) {
      opt.setStrict(true);
    } else {
      opt.setStrict(false);
    }

    if (sourceST != null) opt.setSourceList(sourceST.getSymbols());
    if (targetST != null) opt.setTargetList(targetST.getSymbols());

    if (forSIF) {
      opt.setSifTypes(selectedTypes);
    }
  }
  public void reduce(LongWritable key, Iterable<Text> values, Context context)
      throws IOException, InterruptedException {
    LongWritable curNodeId = key;
    double previousPRValue = 1;
    double nextPRValue = 0;
    double localResidual = 0;
    String edgeListOfCurNode = "";
    long localResidualTransformed = 0;

    for (Text value : values) {
      String[] inputInfo = value.toString().split("\\s+");

      // incoming pagerank value
      if (inputInfo.length == 1) {
        nextPRValue += Double.parseDouble(inputInfo[0]);
      }
      // current node info
      else if (inputInfo.length == 3) {
        edgeListOfCurNode = inputInfo[2];
        previousPRValue = Double.parseDouble(inputInfo[1]);
      } else if (inputInfo.length == 2) {
        previousPRValue = Double.parseDouble(inputInfo[1]);
      } else {
        System.out.println("ERROR: received unexpected TEXT in length");
      }
    }
    if (previousPRValue == 1) System.out.println("No node info has been received by a reducer");
    // calculate the pagerank value according to the given formula
    nextPRValue = pagerankFormula(nextPRValue);

    // should also iterate sink nodes list, add the evenly splitted value

    // reducer should store the updated node info(NPR) to output directory
    context.write(null, new Text(curNodeId + " " + nextPRValue + " " + edgeListOfCurNode));

    // then compare PPR with NPR
    try {
      localResidual = Math.abs(previousPRValue - nextPRValue) / nextPRValue;
      localResidualTransformed = (long) (localResidual * 10000);
      // System.out.println("Make sure you got the right transformed residual :
      // "+localResidualTransformed);

    } catch (ArithmeticException e) {
      System.out.println("PPR is zero. Check where you get the value!");
    }

    // assume there is a global counter called residualCounter;

    context.getCounter(myCounter.ResidualCounter.RESIDUAL_SUM).increment(localResidualTransformed);
  }
Example #27
0
  private static boolean identifier(Text t, List<Object> valueList) {
    final boolean result;

    final int start = t.cursor();
    if (Identifier.consume(t)) {
      final String string = t.getString(start);
      valueList.add(new Identifier(string));
      result = true;
    } else {
      result = false;
    }

    return result;
  }
Example #28
0
  private static boolean exponent(Text t) {
    final boolean result;

    // 'e' Int
    final int save = t.cursor();
    if (t.consume('e') && t.consumeInt()) {
      result = true;
    } else {
      t.setCursor(save);
      result = false;
    }

    return result;
  }
Example #29
0
  private static boolean decPart(Text t) {
    final boolean result;

    // '.' Digits+
    final int save = t.cursor();
    if (t.consume('.') && t.consumeAscii(Text.ASCII_0_9)) {
      result = true;
    } else {
      t.setCursor(save);
      result = false;
    }

    return result;
  }
Example #30
0
  @Test
  public void testTextWholeText() throws Exception {
    String xml =
        "<?xml version=\"1.0\"?>" + "<root>" + "<item><inner>handle</inner>foo</item>" + "</root>";

    DocumentBuilder builder = builderFactory.newDocumentBuilder();

    Document doc = builder.parse(Utils.createInputSource(xml));
    Node item = doc.getDocumentElement().getFirstChild();
    Text textBar = (Text) item.getChildNodes().item(1);
    item.appendChild(doc.createTextNode("bar"));

    Assert.assertEquals("wholeText", "foobar", textBar.getWholeText());
    Assert.assertEquals("nodeValue", "foo", textBar.getNodeValue());
  }