Android Open Source - saostar Reader






From Project

Back to project page saostar.

License

The source code is released under:

Apache License

If you think the Android project saostar listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.azyobuzi.azyotter.saostar.d_aqa;
//from  w w  w.  j a va  2s .  c om
import java.io.EOFException;
import java.util.ArrayList;
import java.util.GregorianCalendar;

import net.azyobuzi.azyotter.saostar.ContextAccess;
import net.azyobuzi.azyotter.saostar.R;
import net.azyobuzi.azyotter.saostar.d_aqa.operators.*;
import net.azyobuzi.azyotter.saostar.d_aqa.properties.*;
import net.azyobuzi.azyotter.saostar.linq.Enumerable;
import net.azyobuzi.azyotter.saostar.system.Func2;

public class Reader {
  //
  // Public Static Members
  //

  public static final PropertyFactory[] properties = new PropertyFactory[] {
    new IdProperty.Factory(),
    new CreatedAtProperty.Factory(),
    new TextProperty.Factory(),
    new SourceProperty.Factory(),
    new FromIdProperty.Factory(),
    new FromScreenNameProperty.Factory(),
    new FromNameProperty.Factory(),
    new FromCreatedAtProperty.Factory(),
    new FromProtectedProperty.Factory(),
    new FromVerifiedProperty.Factory(),
    new RetweetedProperty.Factory(),
    new RetweetedIdProperty.Factory(),
    new RetweetedCreatedAtProperty.Factory(),
    new OriginalTextProperty.Factory(),
    new RetweetedSourceProperty.Factory(),
    new RetweetedUserIdProperty.Factory(),
    new RetweetedUserScreenNameProperty.Factory(),
    new RetweetedUserNameProperty.Factory(),
    new RetweetedUserCreatedAtProperty.Factory(),
    new RetweetedUserVerifiedProperty.Factory(),
    new InReplyToProperty.Factory(),
    new IsHomeTweetProperty.Factory()
  };

  public static final OperatorFactory[] operators = new OperatorFactory[] {
    new EqualityOperator.Factory(),
    new InequalityOperator.Factory(),
    new GreaterThanOperator.Factory(),
    new GreaterThanOrEqualOperator.Factory(),
    new LessThanOperator.Factory(),
    new LessThanOrEqualOperator.Factory()
  };

  public static final FunctionFactory[] functions = new FunctionFactory[] {
    //??????
  };

  public static Invokable read(String query) throws EOFException, IllegalArgumentException {
    return read(new Reader(query));
  }

  //
  // Private Static Members
  //

  private static void endedInUnexpectedPosition() throws EOFException {
    throw new EOFException(ContextAccess.getText(R.string.query_ended_in_unexpected_position).toString());
  }

  private static final String space = " ?\r\n\t";

  private static Invokable read(Reader reader) throws EOFException, IllegalArgumentException {
    char firstChar;

    while (true) {
      int i = reader.read();
      if (i == -1) endedInUnexpectedPosition();

      char c = (char)i;
      if (!space.contains(String.valueOf(c))) {
        firstChar = c;
        break;
      }
    }

    StringBuilder sb = new StringBuilder();
    switch (firstChar) {
      case '"':
        while (true) {
          int c = reader.read();
          if (c == -1) endedInUnexpectedPosition();
          if (c == '"') break;
          if (c == '\\') {
            int c2 = reader.read();
            if (c2 == -1) endedInUnexpectedPosition();
            switch (c2) {
              case 'r':
                c = '\r';
                break;
              case 'n':
                c = '\n';
                break;
              case 't':
                c = '\t';
                break;
              default:
                c = c2;
                break;
            }
          }
          sb.append((char)c);
        }
        return new Constant(Invokable.TYPE_STRING, sb.toString());

      case '0':
      case '1':
      case '2':
      case '3':
      case '4':
      case '5':
      case '6':
      case '7':
      case '8':
      case '9':
        sb.append(firstChar);
        while (true) {
          int i = reader.peek();
          if (i == -1) break;

          char c = (char)i;
          if (!"0123456789".contains(String.valueOf(c))) break;

          sb.append(c);
          reader.read();
        }
        return new Constant(Invokable.TYPE_NUMBER, Long.valueOf(sb.toString()));

      case 't':
      case 'f':
        sb.append(firstChar);
        while (true) {
          int i = reader.peek();
          if (i == -1) break;

          char c = (char)i;
          if ((space + ")").contains(String.valueOf(c))) break;

          sb.append(c);
          reader.read();
        }
        return new Constant(Invokable.TYPE_BOOLEAN, Boolean.valueOf(sb.toString()));

      case 'd':
        boolean timeFlag = false;
        while (true) {
          int i = reader.peek();
          if (i == -1) break;

          char c = (char)i;
          if (!"/-0123456789".contains(String.valueOf(c))) break;
          if (c == '-') {
            timeFlag = true;
            reader.read();
            break;
          }

          sb.append(c);
          reader.read();
        }

        String[] splittedDate = sb.toString().split("/");
        int year = Integer.valueOf(splittedDate[0]);
        int month = Integer.valueOf(splittedDate[1]);
        int day = Integer.valueOf(splittedDate[2]);

        if (!timeFlag) {
          return new Constant(Invokable.TYPE_DATETIME, new GregorianCalendar(year, month, day).getTime());
        } else {
          sb = new StringBuilder();
          while (true) {
            int i = reader.peek();
            if (i == -1) break;

            char c = (char)i;
            if (!":0123456789".contains(String.valueOf(c))) break;

            sb.append(c);
            reader.read();
          }

          String[] splittedTime = sb.toString().split(":");
          int hour = Integer.valueOf(splittedTime[0]);
          int minute = Integer.valueOf(splittedTime[1]);

          if (splittedTime.length == 3) {
            int second = Integer.valueOf(splittedTime[2]);
            return new Constant(Invokable.TYPE_DATETIME, new GregorianCalendar(year, month, day, hour, minute, second).getTime());
          } else {
            return new Constant(Invokable.TYPE_DATETIME, new GregorianCalendar(year, month, day, hour, minute).getTime());
          }
        }

      case '(':
        final Invokable left = read(reader);

        if (left instanceof Function) {
          ArrayList<Invokable> args = new ArrayList<Invokable>();
          while (true) {
            Invokable arg = read(reader);
            if (arg != null) args.add(arg);
            else break;
          }
          ((Function)left).setArguments(args);
          return left;
        } else {
          while (true) {
            int i = reader.read();
            if (i == -1) endedInUnexpectedPosition();

            char c = (char)i;
            if (!space.contains(String.valueOf(c))) {
              sb.append(c);

              while (true) {
                i = reader.read();
                if (i == -1) endedInUnexpectedPosition();

                c = (char)i;
                if (space.contains(String.valueOf(c))) break;
                sb.append(c);
              }

              final Invokable right = read(reader);
              read(reader); // )??????????????

              final String opId = sb.toString();

              try {
                return Enumerable.from(operators).where(new Func2<OperatorFactory, Integer, Boolean>() {
                  @Override
                  public Boolean invoke(OperatorFactory arg0, Integer arg1) {
                    return arg0.getOperatorIdentifier().equals(opId)
                      && arg0.getParameterTypes().get(left.getResultType()) == right.getResultType();
                  }
                }).firstOrDefault(null).createOperator(left, right);
              } catch (NullPointerException ex) {
                ex.printStackTrace();
                throw new IllegalArgumentException(
                  ContextAccess.getText(R.string.operator_is_not_found_or_type_has_not_matched)
                    .toString().replace("$opId$", opId),
                  ex
                );
              }
            }
          }
        }

      case ')':
        return null;

      default:
        sb.append(firstChar);

        while (true) {
          int i = reader.read();
          if (i == -1) endedInUnexpectedPosition();
          if (i == ':') break;
          sb.append((char)i);
        }

        String type = sb.toString();

        sb = new StringBuilder();
        while (true) {
          int i = reader.read();
          if (i == -1) break;

          char c = (char)i;
          if (space.contains(String.valueOf(c))) break;
          sb.append(c);
        }

        final String id = sb.toString();

        if (type.equals("prop")) {
          return Enumerable.from(properties).where(new Func2<PropertyFactory, Integer, Boolean>() {
            @Override
            public Boolean invoke(PropertyFactory arg0, Integer arg1) {
              return arg0.getPropertyName().equals(id);
            }
          }).firstOrDefault(null).createProperty();
        } else if (type.equals("func")) {
          return Enumerable.from(functions).where(new Func2<FunctionFactory, Integer, Boolean>() {
            @Override
            public Boolean invoke(FunctionFactory arg0, Integer arg1) {
              return arg0.getFunctionName().equals(id);
            }
          }).firstOrDefault(null).createFunction();
        } else {
          throw new IllegalArgumentException(ContextAccess.getText(R.string.cannot_use_other_than_prop_and_func).toString());
        }
    }
  }

  //
  // Private Instance Members
  //

  private Reader(String s) {
    this.s = s;
  }

  private String s;
  private int position = 0;

  private int peek() {
    if (s.length() > position)
      return s.charAt(position);
    else
      return -1;
  }

  private int read() {
    if (s.length() > position)
    {
      return s.charAt(position++);
    } else {
      return -1;
    }
  }
}




Java Source Code List

jp.ne.hatena.d.shogo0809.widget.SortableListView.java
net.azyobuzi.azyotter.saostar.ActivityUtil.java
net.azyobuzi.azyotter.saostar.ContextAccess.java
net.azyobuzi.azyotter.saostar.NotificationCenter.java
net.azyobuzi.azyotter.saostar.SaostarApplication.java
net.azyobuzi.azyotter.saostar.StringUtil.java
net.azyobuzi.azyotter.saostar.Twitter4JFactories.java
net.azyobuzi.azyotter.saostar.TwitterUriGenerator.java
net.azyobuzi.azyotter.saostar.activities.AccountPreferenceActivity.java
net.azyobuzi.azyotter.saostar.activities.AccountPreferenceFragment.java
net.azyobuzi.azyotter.saostar.activities.AccountsActivity.java
net.azyobuzi.azyotter.saostar.activities.AccountsFragment.java
net.azyobuzi.azyotter.saostar.activities.ExpandLinkActivity.java
net.azyobuzi.azyotter.saostar.activities.LoginActivity.java
net.azyobuzi.azyotter.saostar.activities.MainActivity.java
net.azyobuzi.azyotter.saostar.activities.RetryActivity.java
net.azyobuzi.azyotter.saostar.activities.SettingActivity.java
net.azyobuzi.azyotter.saostar.activities.SettingFragment.java
net.azyobuzi.azyotter.saostar.activities.TabFilterSettingFragment.java
net.azyobuzi.azyotter.saostar.activities.TabGeneralSettingFragment.java
net.azyobuzi.azyotter.saostar.activities.TabPreferenceActivity.java
net.azyobuzi.azyotter.saostar.activities.TabsActivity.java
net.azyobuzi.azyotter.saostar.activities.TabsFragment.java
net.azyobuzi.azyotter.saostar.activities.TimelineTabFragment.java
net.azyobuzi.azyotter.saostar.activities.TweetDetailActivity.java
net.azyobuzi.azyotter.saostar.activities.TwitterUriHookActivity.java
net.azyobuzi.azyotter.saostar.activities.UpdateStatusActivity.java
net.azyobuzi.azyotter.saostar.configuration.Account.java
net.azyobuzi.azyotter.saostar.configuration.Accounts.java
net.azyobuzi.azyotter.saostar.configuration.Command.java
net.azyobuzi.azyotter.saostar.configuration.Setting.java
net.azyobuzi.azyotter.saostar.configuration.Tab.java
net.azyobuzi.azyotter.saostar.configuration.Tabs.java
net.azyobuzi.azyotter.saostar.d_aqa.Constant.java
net.azyobuzi.azyotter.saostar.d_aqa.FunctionFactory.java
net.azyobuzi.azyotter.saostar.d_aqa.Function.java
net.azyobuzi.azyotter.saostar.d_aqa.Invokable.java
net.azyobuzi.azyotter.saostar.d_aqa.OperatorFactory.java
net.azyobuzi.azyotter.saostar.d_aqa.Operator.java
net.azyobuzi.azyotter.saostar.d_aqa.PropertyFactory.java
net.azyobuzi.azyotter.saostar.d_aqa.Property.java
net.azyobuzi.azyotter.saostar.d_aqa.Reader.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.EqualityOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.GreaterThanOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.GreaterThanOrEqualOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.InequalityOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.LessThanOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.LessThanOrEqualOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.CreatedAtProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromCreatedAtProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromIdProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromNameProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromProtectedProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromScreenNameProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromVerifiedProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.IdProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.InReplyToProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.IsHomeTweetProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.OriginalTextProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedCreatedAtProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedIdProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedSourceProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserCreatedAtProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserIdProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserNameProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserScreenNameProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserVerifiedProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.SourceProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.TextProperty.java
net.azyobuzi.azyotter.saostar.linq.Enumerable.java
net.azyobuzi.azyotter.saostar.linq.Enumerator.java
net.azyobuzi.azyotter.saostar.services.FavoriteService.java
net.azyobuzi.azyotter.saostar.services.RetweetService.java
net.azyobuzi.azyotter.saostar.services.TimelineReceiveService.java
net.azyobuzi.azyotter.saostar.services.UpdateStatusService.java
net.azyobuzi.azyotter.saostar.system.Action1.java
net.azyobuzi.azyotter.saostar.system.Action2.java
net.azyobuzi.azyotter.saostar.system.Action3.java
net.azyobuzi.azyotter.saostar.system.Action.java
net.azyobuzi.azyotter.saostar.system.Func1.java
net.azyobuzi.azyotter.saostar.system.Func2.java
net.azyobuzi.azyotter.saostar.system.Func.java
net.azyobuzi.azyotter.saostar.timeline_data.TimelineItemCollection.java
net.azyobuzi.azyotter.saostar.timeline_data.TimelineItemId.java
net.azyobuzi.azyotter.saostar.timeline_data.TimelineItem.java
net.azyobuzi.azyotter.saostar.timeline_data.TweetEntities.java
net.azyobuzi.azyotter.saostar.timeline_data.UserCollection.java
net.azyobuzi.azyotter.saostar.timeline_data.UserInfo.java
net.azyobuzi.azyotter.saostar.widget.AccountSelector.java
net.azyobuzi.azyotter.saostar.widget.CustomizedUrlImageView.java