示例#1
0
 @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()));
 }
示例#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();
    }
  }
示例#3
0
文件: ADate.java 项目: jefferya/basex
  /**
   * 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);
  }
示例#4
0
 @Test
 public void sortByExample2() {
   List<Integer> example = asList(1, 3, 5, 2, 4, 6);
   assertEquals(
       example,
       Algorithms.sortByExample(example, Strings.<Integer>string(), asList(6, 5, 4, 3, 2, 1)));
   assertEquals(
       asList(3, 5, 4),
       Algorithms.sortByExample(example, Strings.<Integer>string(), asList(5, 4, 3)));
   assertEquals(
       example,
       Algorithms.sortByExample(
           example, Strings.<Integer>string(), asList(1, 2, 3, 4, 5, 6, 7, 8, 9)));
 }
示例#5
0
文件: ADate.java 项目: jefferya/basex
  /**
   * Initializes the timezone.
   *
   * @param matcher matcher
   * @param pos first matching position
   * @param value value
   * @param ii input info
   * @throws QueryException query exception
   */
  final void zone(final Matcher matcher, final int pos, final byte[] value, final InputInfo ii)
      throws QueryException {

    final String z = matcher.group(pos);
    if (z == null) return;
    if ("Z".equals(z)) {
      tz = 0;
    } else {
      final int th = Strings.toInt(matcher.group(pos + 2));
      final int tm = Strings.toInt(matcher.group(pos + 3));
      if (th > 14 || tm > 59 || th == 14 && tm != 0) throw INVALIDZONE_X.get(ii, value);
      final int mn = th * 60 + tm;
      tz = (short) ("-".equals(matcher.group(pos + 1)) ? -mn : mn);
    }
  }
示例#6
0
  public void loadGridNet(String mapGrid) throws IOException {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(mapGrid));

    logger.debug("loading {}...", mapGrid);

    CSVReader reader = new CSVReader(new FileReader(mapGrid), ',', '"', 1);
    String[] row;
    while ((row = reader.readNext()) != null) {
      String gridId = row[1].trim();
      String dmRoads = row[2].trim();
      String gjRoads = row[3].trim();

      Set<String> x =
          Sets.newHashSet(Splitter.on('|').trimResults().omitEmptyStrings().split(dmRoads));
      Set<String> y =
          Sets.newHashSet(Splitter.on('|').trimResults().omitEmptyStrings().split(gjRoads));
      if (x.size() > 0 || y.size() > 0) {
        MapGrid grid = new MapGrid();
        grid.dmRoads = x;
        grid.gjRoads = y;

        gridNet.put(gridId, grid);
        //                logger.debug("{},{},{}", gridId, x, y);
      }
    }

    reader.close();
  }
示例#7
0
 public Table addCell(Object value, String attributes) {
   if (!inHeaders) {
     if (currentCells.size() == headers.size()) {
       throw new ElasticSearchIllegalArgumentException(
           "can't add more cells to a row than the header");
     }
   }
   Map<String, String> mAttr;
   if (attributes.length() == 0) {
     if (inHeaders) {
       mAttr = ImmutableMap.of();
     } else {
       // get the attributes of the header cell we are going to add to
       mAttr = headers.get(currentCells.size()).attr;
     }
   } else {
     mAttr = new HashMap<String, String>();
     if (!inHeaders) {
       // get the attributes of the header cell we are going to add
       mAttr.putAll(headers.get(currentCells.size()).attr);
     }
     String[] sAttrs = Strings.splitStringToArray(attributes, ';');
     for (String sAttr : sAttrs) {
       if (sAttr.length() == 0) {
         continue;
       }
       int idx = sAttr.indexOf(':');
       mAttr.put(sAttr.substring(0, idx), sAttr.substring(idx + 1));
     }
   }
   addCell(new Cell(value, mAttr));
   return this;
 }
 void put(final URI uri, ArtifactData data) throws Exception {
   reporter.trace("put %s %s", uri, data);
   File tmp = createTempFile(repoDir, "mtp", ".whatever");
   tmp.deleteOnExit();
   try {
     copy(uri.toURL(), tmp);
     byte[] sha = SHA1.digest(tmp).digest();
     reporter.trace("SHA %s %s", uri, Hex.toHexString(sha));
     ArtifactData existing = get(sha);
     if (existing != null) {
       reporter.trace("existing");
       xcopy(existing, data);
       return;
     }
     File meta = new File(repoDir, Hex.toHexString(sha) + ".json");
     File file = new File(repoDir, Hex.toHexString(sha));
     rename(tmp, file);
     reporter.trace("file %s", file);
     data.file = file.getAbsolutePath();
     data.sha = sha;
     data.busy = false;
     CommandData cmddata = parseCommandData(data);
     if (cmddata.bsn != null) {
       data.name = cmddata.bsn + "-" + cmddata.version;
     } else data.name = Strings.display(cmddata.title, cmddata.bsn, cmddata.name, uri);
     codec.enc().to(meta).put(data);
     reporter.trace("TD = " + data);
   } finally {
     tmp.delete();
     reporter.trace("puted %s %s", uri, data);
   }
 }
示例#9
0
 private static void createDefaultMetaModules(MetaApplication app) {
   for (String className : AnnotatedClassParser.getManagedClassNames()) {
     if (className.endsWith(".GalleryImage") || className.endsWith(".AttachedFile")) continue;
     if (isEmbeddable(className)) continue;
     app.getMetaModule(Strings.lastToken(className, "."));
   }
 }
示例#10
0
文件: ADate.java 项目: jefferya/basex
  /**
   * Initializes the time format.
   *
   * @param d input format
   * @param e expected format
   * @param ii input info
   * @throws QueryException query exception
   */
  final void time(final byte[] d, final String e, final InputInfo ii) throws QueryException {
    final Matcher mt = TIME.matcher(Token.string(d).trim());
    if (!mt.matches()) throw dateError(d, e, ii);

    hou = (byte) Strings.toInt(mt.group(1));
    min = (byte) Strings.toInt(mt.group(2));
    sec = toDecimal(mt.group(3), false, ii);
    if (min >= 60
        || sec.compareTo(BD60) >= 0
        || hou > 24
        || hou == 24 && (min > 0 || sec.compareTo(BigDecimal.ZERO) > 0)) throw dateError(d, e, ii);
    zone(mt, 5, d, ii);
    if (hou == 24) {
      hou = 0;
      add(DAYSECONDS);
    }
  }
示例#11
0
 private void teardownAuthTokenFile() {
   if (authTokenFile != null)
     try {
       authTokenFile.delete();
     } catch (WindowsException ex) {
       logger.warning(Strings.get("cant.delete", dcomInfo.getHost(), authTokenFilePath));
     }
 }
 private String getHQLCondition(boolean order) throws XavaException {
   StringBuffer sb = new StringBuffer("from ");
   sb.append(getMetaModel().getName());
   sb.append(" as o");
   if (!Is.emptyString(this.condition)) {
     sb.append(" where ");
     String condition = transformAggregateProperties(getCondition());
     condition = Strings.change(condition, getArgumentsToHQL());
     sb.append(Strings.change(condition, getTokensToChangeDollarsAndNL()));
   }
   if (order && !Is.emptyString(this.order)) {
     sb.append(" order by ");
     sb.append(
         Strings.change(
             transformAggregateProperties(this.order), getTokensToChangeDollarsAndNL()));
   }
   return sb.toString();
 }
 public ExtensionResourceNameIterator(final String extension, final char separatorChar) {
   super();
   String[] extensions = Strings.split(extension, separatorChar);
   if (extensions.length == 0) {
     extensions = new String[] {""};
   }
   this.extensions = extensions;
   this.index = 0;
 }
示例#14
0
 /**
  * Turn the shas into a readable form
  *
  * @param dependencies
  * @return
  * @throws Exception
  */
 public List<?> toString(List<byte[]> dependencies) throws Exception {
   List<String> out = new ArrayList<String>();
   for (byte[] dependency : dependencies) {
     ArtifactData data = get(dependency);
     if (data == null) out.add(Hex.toHexString(dependency));
     else {
       out.add(Strings.display(data.name, Hex.toHexString(dependency)));
     }
   }
   return out;
 }
示例#15
0
 public String changePropertiesByCMPAttributes(String source) throws XavaException {
   StringBuffer r = new StringBuffer(source);
   int i = r.toString().indexOf("${");
   int f = 0;
   while (i >= 0) {
     f = r.toString().indexOf("}", i + 2);
     if (f < 0) break;
     String property = r.substring(i + 2, f);
     String cmpAttribute = null;
     if (property.indexOf('.') >= 0) {
       cmpAttribute = "o._" + Strings.firstUpper(Strings.change(property, ".", "_"));
     } else {
       MetaProperty metaProperty = getMetaModel().getMetaProperty(property);
       if (metaProperty.getMapping().hasConverter()) {
         cmpAttribute = "o._" + Strings.firstUpper(property);
       } else {
         cmpAttribute = "o." + property;
       }
     }
     r.replace(i, f + 1, cmpAttribute);
     i = r.toString().indexOf("${");
   }
   return r.toString();
 }
 public String getEJBQLCondition() throws XavaException {
   StringBuffer sb = new StringBuffer("SELECT OBJECT(o) FROM ");
   sb.append(getMetaModel().getName());
   sb.append(" o");
   if (!Is.emptyString(this.condition)) {
     sb.append(" WHERE ");
     String attributesCondition =
         getMetaModel().getMapping().changePropertiesByCMPAttributes(this.condition);
     sb.append(Strings.change(attributesCondition, getArgumentsJBoss11ToEJBQL()));
   }
   if (!Is.emptyString(this.order)) {
     sb.append(" ORDER BY ");
     sb.append(getMetaModel().getMapping().changePropertiesByCMPAttributes(this.order));
   }
   return sb.toString();
 }
 private Url decryptUrl(final Request request, final Url encryptedUrl) {
   if (encryptedUrl.getSegments().isEmpty()) {
     return encryptedUrl;
   }
   final List<String> encryptedSegments = (List<String>) encryptedUrl.getSegments();
   if (encryptedSegments.size() < 1) {
     return null;
   }
   Url url = new Url(request.getCharset());
   try {
     final String encryptedUrlString = (String) encryptedSegments.get(0);
     if (Strings.isEmpty((CharSequence) encryptedUrlString)) {
       return null;
     }
     final String decryptedUrl = this.getCrypt().decryptUrlSafe(encryptedUrlString);
     if (decryptedUrl == null) {
       return null;
     }
     final Url originalUrl = Url.parse(decryptedUrl, request.getCharset());
     final int originalNumberOfSegments = originalUrl.getSegments().size();
     final int encryptedNumberOfSegments = encryptedUrl.getSegments().size();
     final HashedSegmentGenerator generator = new HashedSegmentGenerator(encryptedUrlString);
     int segNo;
     for (segNo = 1; segNo < encryptedNumberOfSegments; ++segNo) {
       if (segNo > originalNumberOfSegments) {
         break;
       }
       final String next = generator.next();
       final String encryptedSegment = (String) encryptedSegments.get(segNo);
       if (!next.equals(encryptedSegment)) {
         break;
       }
       url.getSegments().add(originalUrl.getSegments().get(segNo - 1));
     }
     while (segNo < encryptedNumberOfSegments) {
       url.getSegments().add(encryptedUrl.getSegments().get(segNo));
       ++segNo;
     }
     url.getQueryParameters().addAll(originalUrl.getQueryParameters());
   } catch (Exception e) {
     CryptoMapper.log.error("Error decrypting URL", e);
     url = null;
   }
   return url;
 }
示例#18
0
  private void loadDatabaseMetadata() {
    if (!databaseMetadataLoaded) {
      String componentName = "UNKNOWN";
      Connection con = null;
      try {
        componentName = getMetaComponent().getName();

        con = DataSourceConnectionProvider.getByComponent(componentName).getConnection();
        DatabaseMetaData metaData = con.getMetaData();
        supportsSchemasInDataManipulation = metaData.supportsSchemasInDataManipulation();
        Collection timeDateFunctions =
            Strings.toCollection(metaData.getTimeDateFunctions().toUpperCase());

        //
        // another solution instead of the use of 'if' would be to use a xml with
        //	the information of the functions from each BBDD
        if ("DB2 UDB for AS/400".equals(metaData.getDatabaseProductName())
            || "Oracle".equals(metaData.getDatabaseProductName())
            || "PostgresSQL".equals(metaData.getDatabaseProductName())) {
          supportsTranslateFunction = true;
        }
        if ("Oracle".equals(metaData.getDatabaseProductName())
            || "PostgreSQL".equals(metaData.getDatabaseProductName())) {
          supportsYearFunction = supportsMonthFunction = false;
        } else {
          supportsYearFunction = timeDateFunctions.contains("YEAR");
          supportsMonthFunction = timeDateFunctions.contains("MONTH");
        }
        databaseMetadataLoaded = true;
      } catch (Exception ex) {
        log.warn(XavaResources.getString("load_database_metadata_warning"));
      } finally {
        try {
          if (con != null) {
            con.close();
          }
        } catch (SQLException e) {
          log.warn(XavaResources.getString("close_connection_warning"));
        }
      }
    }
  }
示例#19
0
 private String changePropertiesByColumns(String source, boolean qualified) throws XavaException {
   StringBuffer r = new StringBuffer(source);
   int i = r.toString().indexOf("${");
   int f = 0;
   while (i >= 0) {
     f = r.toString().indexOf("}", i + 2);
     if (f < 0) break;
     String property = r.substring(i + 2, f);
     String column = "0"; // thus it remained if it is calculated
     if (!getMetaModel().isCalculated(property)) {
       column =
           Strings.isModelName(property)
               ? getTable(property)
               : qualified ? getQualifiedColumn(property) : getColumn(property);
     }
     r.replace(i, f + 1, column);
     i = r.toString().indexOf("${");
   }
   return r.toString();
 }
示例#20
0
  @Override
  public Item item(final QueryContext qc, final InputInfo ii) throws QueryException {
    checkCreate(qc);
    // URL to relational database
    final String url = string(toToken(exprs[0], qc));
    final JDBCConnections jdbc = jdbc(qc);
    try {
      if (exprs.length > 2) {
        // credentials
        final String user = string(toToken(exprs[1], qc));
        final String pass = string(toToken(exprs[2], qc));
        if (exprs.length == 4) {
          // connection options
          final Options opts = toOptions(3, Q_OPTIONS, new Options(), qc);
          // extract auto-commit mode from options
          boolean ac = true;
          final HashMap<String, String> options = opts.free();
          final String commit = options.get(AUTO_COMM);
          if (commit != null) {
            ac = Strings.yes(commit);
            options.remove(AUTO_COMM);
          }
          // connection properties
          final Properties props = connProps(options);
          props.setProperty(USER, user);
          props.setProperty(PASS, pass);

          // open connection
          final Connection conn = getConnection(url, props);
          // set auto/commit mode
          conn.setAutoCommit(ac);
          return Int.get(jdbc.add(conn));
        }
        return Int.get(jdbc.add(getConnection(url, user, pass)));
      }
      return Int.get(jdbc.add(getConnection(url)));
    } catch (final SQLException ex) {
      throw BXSQ_ERROR_X.get(info, ex);
    }
  }
示例#21
0
 private String createSelect() throws XavaException {
   if (hasBaseCondition()) {
     String baseCondition = getBaseCondition();
     if (baseCondition.trim().toUpperCase().startsWith("SELECT ")) {
       return baseCondition;
     }
   }
   // basic select
   StringBuffer select = new StringBuffer("select ");
   Iterator itProperties = getPropertiesNames().iterator();
   while (itProperties.hasNext()) {
     String property = (String) itProperties.next();
     if (Strings.isModelName(property))
       select.append("0"); // the property is a table name not column name
     else {
       select.append("${");
       select.append(property);
       select.append('}');
     }
     if (itProperties.hasNext()) select.append(", ");
   }
   Iterator itHiddenProperties = getHiddenPropertiesNames().iterator();
   while (itHiddenProperties.hasNext()) {
     select.append(", ");
     select.append("${");
     select.append(itHiddenProperties.next());
     select.append('}');
   }
   select.append(" from ${");
   select.append(getModelName());
   select.append('}');
   select.append(' ');
   if (hasBaseCondition()) {
     select.append(" where ");
     select.append(getBaseCondition());
   }
   return select.toString();
 }
 public String getColumnName(int c) {
   return labelAsHeader
       ? getMetaProperty(c).getLabel(locale)
       : Strings.change(getMetaProperty(c).getQualifiedName(), ".", "_");
 }
 public String getArguments() {
   arguments = Strings.change(arguments, "String", "java.lang.String");
   arguments = Strings.change(arguments, "java.lang.java.lang.String", "java.lang.String");
   return arguments;
 }
示例#24
0
 String getCMPAttributeForColumn(String column) throws XavaException {
   PropertyMapping mapping = getMappingForColumn(column);
   if (!mapping.hasConverter()) return Strings.change(mapping.getProperty(), ".", "_");
   return "_" + Strings.change(Strings.firstUpper(mapping.getProperty()), ".", "_");
 }
示例#25
0
 public final boolean assertEquals(String $label, byte[] $expected, byte[] $actual) {
   return assertEquals($label, Strings.toHex($expected), Strings.toHex($actual));
 }
示例#26
0
 /**
  * Return the type for this instruction. If the type has not been set, this method will return
  * null.
  */
 public Class getType() {
   String type = getTypeName();
   if (type == null) return null;
   return Strings.toClass(type, getClassLoader());
 }
示例#27
0
  private String getTableColumn(String modelProperty, boolean qualifyReferenceMappingColumn)
      throws XavaException {

    PropertyMapping propertyMapping = (PropertyMapping) propertyMappings.get(modelProperty);
    if (propertyMapping == null) {
      int idx = modelProperty.indexOf('.');
      if (idx >= 0) {
        String referenceName = modelProperty.substring(0, idx);
        String propertyName = modelProperty.substring(idx + 1);
        if (getMetaModel().getMetaReference(referenceName).isAggregate()
            && !Strings.firstUpper(referenceName).equals(getMetaModel().getContainerModelName())) {
          propertyMapping =
              (PropertyMapping) propertyMappings.get(referenceName + "_" + propertyName);
          if (propertyMapping == null) {
            int idx2 = propertyName.indexOf('.');
            if (idx2 >= 0) {
              String referenceName2 = propertyName.substring(0, idx2);
              String propertyName2 = propertyName.substring(idx2 + 1);
              return getTableColumn(
                  referenceName + "_" + referenceName2 + "." + propertyName2,
                  qualifyReferenceMappingColumn);
            } else {
              throw new ElementNotFoundException(
                  "property_mapping_not_found", referenceName + "_" + propertyName, getModelName());
            }
          }
          return propertyMapping.getColumn();
        }
        ReferenceMapping referenceMapping = getReferenceMapping(referenceName);

        if (referenceMapping.hasColumnForReferencedModelProperty(propertyName)) {
          if (qualifyReferenceMappingColumn) {
            return getTableToQualifyColumn()
                + "."
                + referenceMapping.getColumnForReferencedModelProperty(propertyName);
          } else {
            return referenceMapping.getColumnForReferencedModelProperty(propertyName);
          }
        } else {
          ModelMapping referencedMapping = referenceMapping.getReferencedMapping();

          String tableName = referencedMapping.getTableToQualifyColumn();
          boolean secondLevel = propertyName.indexOf('.') >= 0;
          String columnName = referencedMapping.getTableColumn(propertyName, secondLevel);
          boolean hasFormula = referencedMapping.getPropertyMapping(propertyName).hasFormula();

          if (qualifyReferenceMappingColumn && !secondLevel && !hasFormula) {
            return tableName + "." + columnName;
          } else if (hasFormula) {
            String formula = referencedMapping.getPropertyMapping(propertyName).getFormula();
            referencePropertyWithFormula = true;
            return qualifyFormulaWithReferenceName(
                formula, referencedMapping.getModelName(), modelProperty);
          } else {
            return columnName;
          }
        }
      }
      throw new ElementNotFoundException(
          "property_mapping_not_found", modelProperty, getModelName());
    }
    if (propertyMapping.hasFormula()) return propertyMapping.getFormula();
    return propertyMapping.getColumn();
  }
示例#28
0
 public Char get(int index) {
   return Char.valueOf(Strings.characterAt(base, start, end, index + start));
 }
示例#29
0
  public List<RoadLink> loadRoadNet(String mif, String mid) throws IOException {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(mif));
    Preconditions.checkArgument(!Strings.isNullOrEmpty(mid));

    logger.debug("loading {}...", mid);

    CSVReader reader = new CSVReader(new FileReader(mid), ',', '"', 0);
    String[] row;
    List<RoadLink> links = new ArrayList();

    while ((row = reader.readNext()) != null) {
      RoadLink link = new RoadLink();
      link.no = Integer.valueOf(row[0]);
      link.fromNode = Integer.valueOf(row[1]);
      link.toNode = Integer.valueOf(row[2]);
      link.name = row[3];
      link.length = Double.valueOf(row[4]);
      link.ft = row[5];
      link.tf = row[6];
      link.combine = row[7];
      link.overhead = row[8];
      link.xmin = Double.valueOf(row[9]);
      link.ymin = Double.valueOf(row[10]);
      link.xmax = Double.valueOf(row[11]);
      link.ymax = Double.valueOf(row[12]);
      links.add(link);

      roadNet.put(link.no, link);
    }

    Charset charset = Charset.forName("UTF-8");
    BufferedReader mifReader = Files.newBufferedReader(Paths.get(mif), charset);
    String line;
    int index = -1;
    int pos = -1;
    int segs = -1;
    Point2D prePoint = null;

    while ((line = mifReader.readLine()) != null) {
      List<String> cols =
          Lists.newArrayList(
              Splitter.on(CharMatcher.BREAKING_WHITESPACE)
                  .trimResults()
                  .omitEmptyStrings()
                  .split(line));

      //            logger.debug("{}", line);

      if (cols.get(0).compareTo("PLINE") == 0) {
        index++;
        segs = Integer.valueOf(cols.get(1));
        pos = 0;
        prePoint = null;
      } else if (cols.get(0).compareTo("LINE") == 0) {
        index++;
        RoadLink link = links.get(index);

        //                link.segments.add(new Point2D.Double(Double.valueOf(cols.get(1)),
        // Double.valueOf(cols.get(2))));
        //                link.segments.add(new Point2D.Double(Double.valueOf(cols.get(3)),
        // Double.valueOf(cols.get(4))));

        Segment seg = new Segment();
        seg.start = new Point2D.Double(Double.valueOf(cols.get(1)), Double.valueOf(cols.get(2)));
        seg.end = new Point2D.Double(Double.valueOf(cols.get(3)), Double.valueOf(cols.get(4)));
        seg.length = seg.start.distance(seg.end);

        link.segments.add(seg);

      } else if (index >= 0) {

        if (prePoint == null) {
          prePoint = new Point2D.Double(Double.valueOf(cols.get(0)), Double.valueOf(cols.get(1)));
        } else {
          Segment seg = new Segment();
          seg.start = prePoint;
          prePoint = new Point2D.Double(Double.valueOf(cols.get(0)), Double.valueOf(cols.get(1)));
          seg.end = prePoint;
          seg.length = seg.start.distance(seg.end);

          RoadLink link = links.get(index);
          link.segments.add(seg);
        }

        //                RoadLink link = links.get(index);
        //                link.segments.add(new Point2D.Double(Double.valueOf(cols.get(0)),
        // Double.valueOf(cols.get(1))));
      }
    }

    return links;
  }
示例#30
0
 /**
  * Retrieves parts of speech from feature.
  *
  * @return parts of speech(coding in Japanese)
  */
 private String getPos() {
   return Strings.split(mFeature, ',')[0];
 }