private static List<ObjectIdentifier> processObjectPath(
     final List<ObjectIdentity> objPath, final boolean isToPath) {
   int refcount = isToPath ? 1 : 2;
   final List<ObjectIdentifier> ret = new LinkedList<>();
   for (final ObjectIdentity oi : objPath) {
     try {
       ret.add(processObjectIdentifier(oi));
     } catch (IllegalArgumentException | NullPointerException e) {
       throw new IllegalArgumentException(
           String.format(
               "Invalid object id at position #%s: %s", refcount, e.getLocalizedMessage()),
           e);
     }
     refcount++;
   }
   return ret;
 }
 private static List<ObjectIdentifier> processRefPath(
     final List<String> objRefPath, final boolean isToPath) {
   int refcount = isToPath ? 1 : 2;
   final List<ObjectIdentifier> ret = new LinkedList<>();
   for (final String r : objRefPath) {
     try {
       ret.add(ObjectIdentifier.parseObjectReference(r));
     } catch (IllegalArgumentException | NullPointerException e) {
       throw new IllegalArgumentException(
           String.format(
               "Invalid object reference (%s) at position #%s: %s",
               r, refcount, e.getLocalizedMessage()),
           e);
     }
     refcount++;
   }
   return ret;
 }
 public static List<ObjectIdentifier> processObjectIdentifiers(List<ObjectIdentity> objectIDs) {
   if (objectIDs == null) {
     throw new NullPointerException("The object identifier list cannot be null");
   }
   if (objectIDs.isEmpty()) {
     throw new IllegalArgumentException("No object identifiers provided");
   }
   final List<ObjectIdentifier> loi = new ArrayList<ObjectIdentifier>();
   int objcount = 1;
   for (ObjectIdentity oi : objectIDs) {
     try {
       loi.add(processObjectIdentifier(oi));
     } catch (IllegalArgumentException | NullPointerException e) {
       throw new IllegalArgumentException(
           "Error on ObjectIdentity #" + objcount + ": " + e.getLocalizedMessage(), e);
     }
     objcount++;
   }
   return loi;
 }
示例#4
0
  /**
   * Assigns the data to the buffer. This is the bare minimum constructor. Calls super constructor
   * for setting all values that weren't defined here.
   *
   * @param data the data to store into the buffer
   */
  public GLBuffer(ArrayList<N> data) {
    this.glBindType = DEFAULT_BIND;
    this.glDrawType = DEFAULT_DRAW;

    // Setup the buffer data
    try {
      if (data == null) {
        throw new NullPointerException();
      } else if (data.size() < 1) {
        throw new IllegalArgumentException("Data list is zero length.");
      }
      this.type = BufferType.getType(data.get(0));
      this.byteSize = type.getByteSize();

      // Default to empty buffer
    } catch (IllegalArgumentException | NullPointerException ex) {
      System.err.println(ex.toString() + "Creating empty default buffer...");
      // Create empty buffer
      data = new ArrayList<>();

      // Set getType of buffer by checking the instantiated variable
      N val = (N) (Number) 1;
      this.type = BufferType.getType(val);

      // Get byte size from getType
      this.byteSize = type.getByteSize();

      // Create the buffer with the setup data
      // Probably should NOT put this code into finally but it's so convenient
    } finally {
      this.buffer = ByteBuffer.allocateDirect(data.size() * this.byteSize);
      for (Number n : data) {
        switch (this.type) {
          case BYTE_BUFFER:
            this.buffer.put((Byte) n);
            break;
          case DOUBLE_BUFFER:
            this.buffer.putDouble((Double) n);
            break;
          case FLOAT_BUFFER:
            this.buffer.putFloat((Float) n);
            break;
          case INT_BUFFER:
            this.buffer.putInt((Integer) n);
            break;
          case SHORT_BUFFER:
            this.buffer.putShort((Short) n);
            break;
          default:
            // Should NOT execute. If it does, something's broke.
            // System.err.println("Something's broke.");;
            System.err.println(this.type.toString() + " does not match any predefined type.");
        }
      }
      this.buffer.flip();
      this.bufferSize = this.buffer.capacity() / this.byteSize;
      if (this.bufferSize != data.size()) {
        System.err.println("Data was not transferred correctly to buffer.");
      }
    }
  }
 /**
  * Reads a given line and decides what to do with it depending on the contents of the line Calls
  * find, add, or sell depending on what the line says
  *
  * @param line - a single command
  */
 public void parse(String line) {
   // Splits the input by commas into an array for easier parsing
   String[] delimited = line.split(",");
   AudioFormat audioFormat = null;
   try {
     if (delimited[0].equals(MusicStoreInventory.ADD)) { // ADD command
       // Creates a new CD, Vinyl, or Cassette depending on the input
       if (delimited[4].equals("CD")) {
         audioFormat = new CD(delimited[1], delimited[2], this.convertStringToInt(delimited[3]));
       } else if (delimited[4].equals("VINYL")) {
         audioFormat =
             new Vinyl(delimited[1], delimited[2], this.convertStringToInt(delimited[3]));
       } else if (delimited[4].equals("CASSETTE")) {
         audioFormat =
             new Cassette(delimited[1], delimited[2], this.convertStringToInt(delimited[3]));
       } else {
         // If it's not any of the three types, throws an exception
         throw new IllegalArgumentException("Invalid input: not a valid record type (ADD).");
       }
       // Adds the item to the inventory
       this.addItem(
           audioFormat,
           this.convertStringToInt(delimited[5]),
           this.convertStringToDouble(delimited[6]));
     } else if (delimited[0].equals(MusicStoreInventory.SELL)) { // SELL command
       // Creates a new CD, Vinyl, or Cassette depending on the input
       if (delimited[4].equals("CD")) {
         audioFormat = new CD(delimited[1], delimited[2], this.convertStringToInt(delimited[3]));
       } else if (delimited[4].equals("VINYL")) {
         audioFormat =
             new Vinyl(delimited[1], delimited[2], this.convertStringToInt(delimited[3]));
       } else if (delimited[4].equals("CASSETTE")) {
         audioFormat =
             new Cassette(delimited[1], delimited[2], this.convertStringToInt(delimited[3]));
       } else {
         // If it's not any of the three types, throws an exception
         throw new IllegalArgumentException("Invalid input: not a valid record type (SELL)");
       }
       // Sells the item
       this.sellItem(audioFormat, this.convertStringToInt(delimited[5]));
     } else if (delimited[0].equals(MusicStoreInventory.FIND)) { // FIND command
       // There should only be 2 parameters for a FIND command
       if (delimited.length != 2) {
         throw new IllegalArgumentException("Invalid input: wrong number of commands (FIND).");
       }
       this.findItemsByArtist(delimited[1]);
     } else {
       // The only thing that can remain is the initial input of data, which has exactly 6 commands
       if (delimited.length != 6) {
         throw new IllegalArgumentException("Invalid input: wrong number of commands.");
       }
       // Creates a new CD, Vinyl, or Cassette depending on the input
       if (delimited[3].equals("CD")) {
         audioFormat = new CD(delimited[0], delimited[1], this.convertStringToInt(delimited[2]));
       } else if (delimited[3].equals("VINYL")) {
         audioFormat =
             new Vinyl(delimited[0], delimited[1], this.convertStringToInt(delimited[2]));
       } else if (delimited[3].equals("CASSETTE")) {
         audioFormat =
             new Cassette(delimited[0], delimited[1], this.convertStringToInt(delimited[2]));
       } else {
         // If it's not any of the three types, throws an exception
         throw new IllegalArgumentException("Invalid input: not a valid record type (ADD)");
       }
       // Adds the item to the inventory
       this.addItem(
           audioFormat,
           this.convertStringToInt(delimited[4]),
           this.convertStringToDouble(delimited[5]));
     }
   } catch (NumberFormatException e) {
     System.out.println("Invalid input: price or year is not valid.");
     e.printStackTrace();
   } catch (IllegalArgumentException | NullPointerException e) {
     e.printStackTrace();
   }
 }