Exemplo n.º 1
1
  @Override
  protected void actionPerformed(GuiButton button) throws IOException {
    switch (button.id) {
      case 0: // Means Done
        ErrorHandling.CleanErrors();
        /* Closes the text editor, saves the .oc file and attempts to compile and load it */
        mc.thePlayer.closeScreen();
        text.deleteCharAt(cursorLocation);
        saveFile();
        try {
          Compiler.main(
              String.format(System.getProperty("user.dir") + "/ObsidiCode/Test/SimpleMiner.oc"));
        } catch (Exception e) {
          e.printStackTrace();
        }
        ArrayList<String> currentErrors = (ArrayList<String>) ErrorHandling.GetErrors().clone();
        if (currentErrors.size() == 0) {
          loadRobot();
        } else {
          ErrorBook eb = ObsidiSkriveMaskineMod.errorBook();
          ObsidiCodingMachine.dropErrorLog(eb);
        }
        break;
      case 1: // Means reset
        // Resets the text on the screen.
        text = text.delete(0, text.toString().length());
        cursorLocation = 0;
        break;
      default:
        break;
    }

    super.actionPerformed(button);
  }
Exemplo n.º 2
1
 public static OMElement serializeHandlerConfiguration(HandlerConfigurationBean bean) {
   OMFactory factory = OMAbstractFactory.getOMFactory();
   OMElement handler = factory.createOMElement("handler", null);
   handler.addAttribute(factory.createOMAttribute("class", null, bean.getHandlerClass()));
   if (bean.getTenant() != null) {
     handler.addAttribute(factory.createOMAttribute("tenant", null, bean.getTenant()));
   }
   StringBuilder sb = new StringBuilder();
   for (String method : bean.getMethods()) {
     if (method != null && method.length() > 0) {
       sb.append(method).append(",");
     }
   }
   // Remove last ","
   if (sb.length() > 0) {
     sb.deleteCharAt(sb.length() - 1);
     handler.addAttribute(factory.createOMAttribute("methods", null, sb.toString()));
   }
   for (String property : bean.getPropertyList()) {
     OMElement temp = factory.createOMElement("property", null);
     temp.addAttribute(factory.createOMAttribute("name", null, property));
     OMElement xmlProperty = bean.getXmlProperties().get(property);
     if (xmlProperty != null) {
       //                The serialization happens by adding the whole XML property value to the
       // bean.
       //                Therefore if it is a XML property, we take that whole element.
       handler.addChild(xmlProperty);
     } else {
       String nonXMLProperty = bean.getNonXmlProperties().get(property);
       if (nonXMLProperty != null) {
         temp.setText(nonXMLProperty);
         handler.addChild(temp);
       }
     }
   }
   OMElement filter = factory.createOMElement("filter", null);
   filter.addAttribute(
       factory.createOMAttribute("class", null, bean.getFilter().getFilterClass()));
   for (String property : bean.getFilter().getPropertyList()) {
     OMElement temp = factory.createOMElement("property", null);
     temp.addAttribute(factory.createOMAttribute("name", null, property));
     OMElement xmlProperty = bean.getFilter().getXmlProperties().get(property);
     if (xmlProperty != null) {
       temp.addAttribute(factory.createOMAttribute("type", null, "xml"));
       temp.addChild(xmlProperty);
       filter.addChild(temp);
     } else {
       String nonXMLProperty = bean.getFilter().getNonXmlProperties().get(property);
       if (nonXMLProperty != null) {
         temp.setText(nonXMLProperty);
         filter.addChild(temp);
       }
     }
   }
   handler.addChild(filter);
   return handler;
 }
Exemplo n.º 3
1
  @Contract("null, _, _ -> null")
  private static String toCanonicalPath(
      @Nullable String path, char separatorChar, boolean removeLastSlash) {
    if (path == null || path.isEmpty()) {
      return path;
    } else if (".".equals(path)) {
      return "";
    }

    path = path.replace(separatorChar, '/');
    if (path.indexOf('/') == -1) {
      return path;
    }

    int start = pathRootEnd(path) + 1, dots = 0;
    boolean separator = true;

    StringBuilder result = new StringBuilder(path.length());
    result.append(path, 0, start);

    for (int i = start; i < path.length(); ++i) {
      char c = path.charAt(i);
      if (c == '/') {
        if (!separator) {
          processDots(result, dots, start);
          dots = 0;
        }
        separator = true;
      } else if (c == '.') {
        if (separator || dots > 0) {
          ++dots;
        } else {
          result.append('.');
        }
        separator = false;
      } else {
        if (dots > 0) {
          StringUtil.repeatSymbol(result, '.', dots);
          dots = 0;
        }
        result.append(c);
        separator = false;
      }
    }

    if (dots > 0) {
      processDots(result, dots, start);
    }

    int lastChar = result.length() - 1;
    if (removeLastSlash && lastChar >= 0 && result.charAt(lastChar) == '/' && lastChar > start) {
      result.deleteCharAt(lastChar);
    }

    return result.toString();
  }
Exemplo n.º 4
1
  public static long solution1() {
    TreeSet<Long> triangleNums = Util.getTriangleNumbersByCount(1000);
    HashSet<String> triangleWords = new HashSet<String>();
    FileInputStream fileStream;
    try {
      fileStream = new FileInputStream("src/main/resources/words.txt");
      DataInputStream dataStream = new DataInputStream(fileStream);
      BufferedReader bufferedReader =
          new BufferedReader(new InputStreamReader(dataStream, "UTF-8"));
      String line = bufferedReader.readLine();
      if (null != line) {
        String[] words = line.split(",");
        dataStream.close();

        for (String word : words) {
          StringBuilder tempName = new StringBuilder(word);
          tempName.deleteCharAt(0);
          tempName.deleteCharAt(tempName.length() - 1);
          long score = 0;
          for (int i = 0; i < tempName.length(); i++) {
            // Assuming the names contains only A-Z
            score = score + (tempName.charAt(i) % 'A') + 1;
          }
          if (score > triangleNums.last()) {
            System.out.println(word + "\t" + score);
          }
          if (triangleNums.contains(Long.valueOf(score))) {
            triangleWords.add(word);
          }
        }
      }
      bufferedReader.close();
      dataStream.close();
      fileStream.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
      System.out.println(e.getMessage());
    } catch (IOException e) {
      e.printStackTrace();
      System.out.println(e.getMessage());
    }
    return triangleWords.size();
  }
Exemplo n.º 5
1
 private static String prs(String str, boolean rotate) {
   StringBuilder val = new StringBuilder(str);
   for (int i = 0; i < val.length(); ) {
     int c = val.charAt(i);
     if (c < 48 || c > 57) {
       val.deleteCharAt(i);
     } else i++;
   }
   return (rotate ? val.reverse() : val).toString();
 }
Exemplo n.º 6
1
 public static String concatSortedPercentEncodedParams(Map<String, String> params) {
   StringBuilder target = new StringBuilder();
   for (String key : params.keySet()) {
     target.append(key);
     target.append(PAIR_SEPARATOR);
     target.append(params.get(key));
     target.append(PARAM_SEPARATOR);
   }
   return target.deleteCharAt(target.length() - 1).toString();
 }
Exemplo n.º 7
1
  @Override
  public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    this.drawDefaultBackground();

    mc.getTextureManager().bindTexture(skrivemaskinegui);

    this.drawTexturedModalRect(this.width / 2 - 128, this.height / 2 - 128, 0, 0, 256, 256);

    /* this is where the editor reads keys and writes to the screen */
    if (org.lwjgl.input.Keyboard.getEventKeyState()) {
      //
      if (isAllowedDeletion()) {
        text.deleteCharAt(cursorLocation);
        cursorLocation--;
        text.deleteCharAt(cursorLocation);
        text.insert(cursorLocation, cursor); // moving cursor
      } else if (isAllowedNewLine()) {
        text.deleteCharAt(cursorLocation);
        text.insert(cursorLocation, '\n');
        cursorLocation++;
        text.insert(cursorLocation, cursor); // moving cursor
      } else if (isAllowedLeftArrowNavigation()) {
        text.deleteCharAt(cursorLocation);
        cursorLocation--;
        text.insert(cursorLocation, cursor); // moving cursor

      } else if (isAllowedRightArrowNavigation()) {
        text.deleteCharAt(cursorLocation);
        cursorLocation++;
        text.insert(cursorLocation, cursor); // moving cursor

      } else if (Keyboard.getEventKey() == Keyboard.KEY_TAB) {
        text.deleteCharAt(cursorLocation);
        for (int i = 0; i < 3; i++) {
          text.insert(cursorLocation, " ");
          cursorLocation++;
        }
        text.insert(cursorLocation, cursor); // moving cursor

      } else {
        if (isAllowedCharacters()) {
          // System.out.println(org.lwjgl.input.Keyboard.getEventKey());
          text.deleteCharAt(cursorLocation);
          text.insert(cursorLocation, org.lwjgl.input.Keyboard.getEventCharacter());
          cursorLocation++;
          text.insert(cursorLocation, cursor); // moving cursor
        }
      }

      org.lwjgl.input.Keyboard.destroy();
    } else if (!org.lwjgl.input.Keyboard.isCreated()) {
      try {
        org.lwjgl.input.Keyboard.create();
      } catch (Exception e) {
      }
    }

    /* writes the text string to the screen */
    renderer.drawSplitString(
        text.toString(), this.width / 2 - 118, this.height / 2 - 119, 238, 0xFFFFF0);

    super.drawScreen(mouseX, mouseY, partialTicks);
  }
Exemplo n.º 8
1
  public static int serDiccGroupByToWriter(
      ResultSet rs,
      Writer writer,
      int maxRows,
      String idPor,
      String[] idAcumulados,
      String campoAcumuladoNombre) {
    int rowsCount = 0;

    try {

      ArrayList<String> acumulado = null;
      String idActual = null;
      StringBuilder reg = null;
      reg = new StringBuilder();
      String value = "";

      if (rs != null) {
        ResultSetMetaData rsm = rs.getMetaData();
        int countCol = rsm.getColumnCount();
        String name = "";
        for (int i = 1; i <= countCol; i++) {
          name = rsm.getColumnName(i);
          reg.append(name.toLowerCase()).append("\t");
        }
        reg.append(campoAcumuladoNombre);

        writer.write(reg.toString() + EOL);

        while (rs.next()) {
          if (idActual == null) {
            reg = new StringBuilder();
            acumulado = new ArrayList<String>();
            idActual = rs.getString(idPor);

            for (int i = 1; i <= countCol; i++) {
              reg.append(rs.getString(i)).append("\t");
            }

            for (String id : idAcumulados) {
              value = rs.getString(id);
              if (!rs.wasNull()) {
                acumulado.add(rs.getString(id));
              }
            }

          } else {

            if (idActual.equals(rs.getString(idPor))) {
              for (String id : idAcumulados) {
                value = rs.getString(id);
                if (!rs.wasNull()) {
                  acumulado.add(rs.getString(id));
                }
              }
            } else {
              if (acumulado.size() > 0) {
                for (String str : acumulado) {
                  reg.append(str).append(",");
                }
                reg.deleteCharAt(reg.length() - 1);
              }
              reg.append(EOL);

              writer.write(reg.toString());
              rowsCount++;
              if (maxRows == rowsCount) {
                break;
              }

              idActual = rs.getString(idPor);
              reg = new StringBuilder();
              acumulado = new ArrayList<String>();

              for (int i = 1; i <= countCol; i++) {
                reg.append(rs.getString(i)).append("\t");
              }

              for (String id : idAcumulados) {
                value = rs.getString(id);
                if (!rs.wasNull()) {
                  acumulado.add(rs.getString(id));
                }
              }
            }
          }
        }

        if (acumulado.size() > 0) {
          for (String str : acumulado) {
            reg.append(str).append(",");
          }
          reg.deleteCharAt(reg.length() - 1);
        }
        reg.append(EOL);

        writer.write(reg.toString());
        rowsCount++;
      }
    } catch (SQLException e) {
      logm("ERR", 1, "Error al escribir registros", e);
    } catch (IOException e) {
      logm("ERR", 1, "Error al escribir registros", e);
    }
    return rowsCount;
  }
Exemplo n.º 9
0
 private String trimLeadingSlash(String path) {
   StringBuilder builder = new StringBuilder(path);
   while (builder.length() > 0) {
     if (builder.charAt(0) == '/') {
       builder.deleteCharAt(0);
     } else {
       break;
     }
   }
   return builder.toString();
 }
 public void writeTBTshortTXT(File outFile) {
   Arrays.sort(tagDs, new sortByCount());
   try {
     BufferedWriter br = new BufferedWriter(new FileWriter(outFile), 65536);
     StringBuilder sb = new StringBuilder();
     sb.append(String.valueOf(taxaNum)).append("\t").append(String.valueOf(tagNum));
     br.write(sb.toString());
     br.newLine();
     sb = new StringBuilder("Sum\t");
     for (int i = 0; i < taxaNum; i++) {
       String name = taxaNames[i];
       name = name.replaceFirst("_.+", "");
       sb.append(name).append("\t");
     }
     sb.deleteCharAt(sb.length() - 1);
     br.write(sb.toString());
     br.newLine();
     sb = new StringBuilder(String.valueOf(totalCount) + "\t");
     for (int i = 0; i < taxaNum; i++) {
       sb.append(String.valueOf(totalCountsByTaxa[i])).append("\t");
     }
     sb.deleteCharAt(sb.length() - 1);
     br.write(sb.toString());
     br.newLine();
     for (int i = 0; i < tagNum; i++) {
       sb = new StringBuilder(baseEncoder.getSeqFromByteArray(tagDs[i].tag));
       sb.append("\t").append(tagDs[i].count).append("\t");
       for (int j = 0; j < taxaNum; j++) {
         sb.append(String.valueOf(tagDs[i].dist[j])).append("\t");
       }
       sb.deleteCharAt(sb.length() - 1);
       br.write(sb.toString());
       br.newLine();
     }
     br.flush();
     br.close();
   } catch (Exception e) {
     System.out.println("Error occurred while writing TBT " + e.toString());
   }
 }
Exemplo n.º 11
0
  private String getHapMapRecord(
      ReadsByTaxa rbt, int ID, int queryIndex, int hitIndex, float coverRate) {
    StringBuilder sb = new StringBuilder();
    sb.append(queryIndex)
        .append("|")
        .append(hitIndex)
        .append("\tA/C\t")
        .append(1)
        .append("\t")
        .append(ID)
        .append("\t+\tNA\tSWGDiv\tGBS\tSWGV1\tSWGPop\tQC+\t");
    int countN = 0;
    int totalA = 0, totalC = 0;
    for (int i = 0; i < rbt.taxaNum; i++) {
      if (rbt.hapDist[queryIndex][i] > 0) {
        totalA += rbt.hapDist[queryIndex][i];
        if (rbt.hapDist[hitIndex][i] > 0) {
          totalC += rbt.hapDist[hitIndex][i];
          sb.append("R").append("\t");
        } else {
          sb.append("A").append("\t");
        }
      } else {
        if (rbt.hapDist[hitIndex][i] > 0) {
          totalC += rbt.hapDist[hitIndex][i];
          sb.append("C").append("\t");
        } else {
          sb.append("N").append("\t");
          countN++;
        }
      }
    }

    if (1 - (float) countN / (float) rbt.taxaNum < coverRate) {
      return null;
    }
    sb.deleteCharAt(sb.length() - 1);
    return sb.toString();
  }
Exemplo n.º 12
0
 public static StringBuilder fixTrailingCommaList(StringBuilder sb) {
   if (sb.charAt(sb.length() - 1) == ',') {
     sb.deleteCharAt(sb.length() - 1);
   }
   return sb;
 }
Exemplo n.º 13
0
  public static boolean postContent(String deviceAddress, String postPath, String... parameters) {
    logger.entry(deviceAddress, postPath, parameters);

    StringBuilder postParameters = new StringBuilder();
    for (String parameter : parameters) {
      postParameters.append(parameter);
      postParameters.append("&");
    }

    if (postParameters.length() > 0) {
      postParameters.deleteCharAt(postParameters.length() - 1);
    }

    byte postBytes[];
    try {
      postBytes = postParameters.toString().getBytes(Config.STD_BYTE);
    } catch (UnsupportedEncodingException e) {
      logger.error("Unable to convert '{}' into bytes.", postParameters.toString());
      return logger.exit(false);
    }

    URL url = null;
    try {
      url = new URL("http://" + deviceAddress + postPath);
    } catch (MalformedURLException e) {
      logger.error("Unable to create a valid URL using 'http://{}{}'", deviceAddress, postPath);
      return logger.exit(false);
    }
    logger.info("Connecting to InfiniTV tuner using the URL '{}'", url);

    HttpURLConnection httpURLConnection = null;
    try {
      httpURLConnection = (HttpURLConnection) url.openConnection();
    } catch (IOException e) {
      logger.error("Unable to open an HTTP connection => {}", e);
      return logger.exit(false);
    }

    httpURLConnection.setDoOutput(true);

    try {
      httpURLConnection.setRequestMethod("POST");
    } catch (ProtocolException e) {
      logger.error("Unable to change request method to POST => {}", e);
      return logger.exit(false);
    }

    httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    httpURLConnection.setRequestProperty("charset", Config.STD_BYTE.toLowerCase());
    httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postBytes.length));

    DataOutputStream dataOutputStream = null;
    try {
      httpURLConnection.connect();
      dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream());
      dataOutputStream.write(postBytes);
      dataOutputStream.flush();
    } catch (IOException e) {
      logger.error("Unable to write POST bytes => {}", e);
      return logger.exit(false);
    }

    String line = null;
    BufferedReader bufferedReader = null;
    try {
      bufferedReader =
          new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
      /*while ((line = bufferedReader.readLine()) != null) {
          //logger.debug("POST returned: {}", line);
      }*/

      dataOutputStream.close();
      bufferedReader.close();
    } catch (IOException e) {
      logger.error("Unable to read reply => {}", e);
      return logger.exit(false);
    }
    return logger.exit(true);
  }