View Javadoc
1   package fr.ifremer.tutti.ichtyometer.feed.record;
2   
3   /*
4    * #%L
5    * Tutti :: Ichtyometer API
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2012 - 2014 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU General Public License as
13   * published by the Free Software Foundation, either version 3 of the
14   * License, or (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU General Public
22   * License along with this program.  If not, see
23   * <http://www.gnu.org/licenses/gpl-3.0.html>.
24   * #L%
25   */
26  
27  import org.apache.commons.lang3.builder.ToStringBuilder;
28  
29  import java.util.regex.Matcher;
30  import java.util.regex.Pattern;
31  
32  /**
33   * A measure record.
34   *
35   * Format is <pre>%l,v#</pre>.
36   *
37   * Created on 12/9/14.
38   *
39   * @author Tony Chemit - chemit@codelutin.com
40   * @since 3.10
41   */
42  public class IchtyometerFeedReaderMeasureRecord extends IchtyometerFeedReaderRecordSupport {
43  
44      private static final long serialVersionUID = 1L;
45  
46      protected static final Pattern RECORD_PATTERN = Pattern.compile("%l\\,(\\w+)?#");
47  
48      public static boolean acceptRecord(String record) {
49  
50          Matcher matcher = RECORD_PATTERN.matcher(record);
51          return matcher.matches();
52  
53      }
54  
55      protected final int measure;
56  
57      IchtyometerFeedReaderMeasureRecord(String record) {
58          super(record);
59          Matcher matcher = RECORD_PATTERN.matcher(record);
60          matcher.find();
61          String measureStr = matcher.group(1);
62          measure = Integer.valueOf(measureStr);
63      }
64  
65      public int getMeasure() {
66          return measure;
67      }
68  
69      @Override
70      public boolean isValid() {
71          return acceptRecord(record);
72      }
73  
74      @Override
75      public String toString() {
76          return new ToStringBuilder(this)
77                  .append("record", measure)
78                  .append("measure", measure)
79                  .toString();
80      }
81  }