MessageDefinitionTupleParser.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
00015  */
00016 
00017 package org.ros.internal.message.definition;
00018 
00019 import com.google.common.base.Preconditions;
00020 import com.google.common.collect.Lists;
00021 
00022 import java.util.List;
00023 
00030 public class MessageDefinitionTupleParser {
00031 
00032   private static final String SEPARATOR = "---";
00033 
00044   public static List<String> parse(String definition, int size) {
00045     Preconditions.checkNotNull(definition);
00046     List<String> definitions = Lists.newArrayList();
00047     StringBuilder current = new StringBuilder();
00048     for (String line : definition.split("\n")) {
00049       if (line.startsWith(SEPARATOR)) {
00050         definitions.add(current.toString());
00051         current = new StringBuilder();
00052         continue;
00053       }
00054       current.append(line);
00055       current.append("\n");
00056     }
00057     if (current.length() > 0) {
00058       current.deleteCharAt(current.length() - 1);
00059     }
00060     definitions.add(current.toString());
00061     Preconditions.checkState(size == -1 || definitions.size() <= size,
00062         String.format("Message tuple exceeds expected size: %d > %d", definitions.size(), size));
00063     while (definitions.size() < size) {
00064       definitions.add("");
00065     }
00066     return definitions;
00067   }
00068 }


rosjava_bootstrap
Author(s): Daniel Stonier , Damon Kohler
autogenerated on Fri Aug 28 2015 12:41:44