private void addNonPreferredNameButtonActionPerformed() {
    Names namesModel = (Names) this.getModel();
    NonPreferredNames newNonPreferredName;
    DomainEditor dialogNonPreferredNames = null;
    try {
      dialogNonPreferredNames =
          DomainEditorFactory.getInstance()
              .createDomainEditorWithParent(NonPreferredNames.class, this.getParentEditor(), false);
    } catch (DomainEditorCreationException e) {
      new ErrorDialog(getParentEditor(), "Error creating editor for NonPreferredNames", e)
          .showDialog();
    }
    dialogNonPreferredNames.setNewRecord(true);

    int returnStatus;
    Boolean done = false;
    while (!done) {
      newNonPreferredName = new NonPreferredNames(namesModel);
      newNonPreferredName.setNameType(namesModel.getNameType());
      dialogNonPreferredNames.setModel(newNonPreferredName, null);
      returnStatus = dialogNonPreferredNames.showDialog();
      if (returnStatus == JOptionPane.OK_OPTION) {
        namesModel.addNonPreferredName(newNonPreferredName);
        nonPreferredNamesTable.getEventList().add(newNonPreferredName);
        done = true;
      } else if (returnStatus == StandardEditor.OK_AND_ANOTHER_OPTION) {
        namesModel.addNonPreferredName(newNonPreferredName);
        nonPreferredNamesTable.getEventList().add(newNonPreferredName);
      } else {
        done = true;
      }
    }
  }
Ejemplo n.º 2
0
  /** Test names? */
  public void testTheNames() {
    Names.getInstance()
        .init(
            getNameElement(
                SettingsHandler.getPcgenSystemDir()
                    + File.separator
                    + "bio"
                    + File.separator
                    + "names"
                    + File.separator,
                "orc"),
            getCharacter());

    //    for (Iterator iterator = Names.getInstance().getRuleList().iterator();
    // iterator.hasNext();) {
    //      String rule = (String) iterator.next();
    //      System.out.println("rule = " + rule);
    //    }
    //    for (Iterator iterator = Names.getInstance().getSyllablesByName("[SYL1]").iterator();
    // iterator.hasNext();) {
    //      String syl1 = (String) iterator.next();
    //      System.out.println("syl1 = " + syl1);
    //    }
    assertTrue("I got null rules!", Names.getInstance().getRuleDefinitions() != null);
    assertTrue("I didn't get any rules!", Names.getInstance().getRuleDefinitions().length > 0);
    assertTrue(
        "There was nothing in syl1", Names.getInstance().getSyllablesByName("[SYL1]").length > 0);
  }
 private static void addSetterDeclaration(
     Names names, JDefinedClass paramType, JDefinedClass setterReturnType) {
   JMethod method = setterReturnType.method(JMod.NONE, setterReturnType, names.getSetterName());
   method.param(paramType, names.getParamName());
   JDocComment javadoc = method.javadoc();
   javadoc.append(names.getJavadoc());
 }
Ejemplo n.º 4
0
  /** @throws Exception */
  public void testGettingNameFiles() throws Exception {
    assertTrue("got null back!", Names.findAllNamesFiles() != null);
    List<NameElement> nameList = Names.findAllNamesFiles();
    assertTrue("got empty array back!", nameList.size() > 0);

    for (int i = 0; i < nameList.size(); i++) {
      final NameElement e = nameList.get(i);
      System.out.println("s = " + e);
    }
  }
  public static void addGetterSetterDeclaration(
      Names names, JClass type, JDefinedClass jDefinedClass) {
    addGetterDeclaration(names, type, jDefinedClass);

    JMethod method = jDefinedClass.method(JMod.NONE, jDefinedClass, names.getSetterName());
    method.param(type, names.getParamName());

    JDocComment javadoc = method.javadoc();
    javadoc.append(names.getJavadoc());
  }
Ejemplo n.º 6
0
 public static RDouble exclude(int excludeIndex, RDouble orig) {
   Names names = orig.names();
   if (names == null) {
     return new RDoubleExclusion(excludeIndex, orig);
   }
   int size = orig.size();
   int nsize = size - 1;
   double[] content = new double[nsize];
   for (int i = 0; i < excludeIndex; i++) {
     content[i] = orig.getDouble(i);
   }
   for (int i = excludeIndex; i < nsize; i++) {
     content[i] = orig.getDouble(i + 1);
   }
   return RDoubleFactory.getFor(content, null, names.exclude(excludeIndex));
 }
Ejemplo n.º 7
0
 private void fillMyPhoneBook(MyPhoneBook myPhoneBook, int count) {
   for (int i = 0; i < count; i++) {
     String name = Names.values()[i].toString();
     String phone = Phones.values()[i].toString().substring(1);
     myPhoneBook.addPhoneNumber(name, phone);
   }
 }
Ejemplo n.º 8
0
 /** Test female name */
 public void testASFemale() {
   Names.getInstance()
       .init(
           getNameElement(
               SettingsHandler.getPcgenSystemDir()
                   + File.separator
                   + "bio"
                   + File.separator
                   + "names"
                   + File.separator,
               "rw_Anglo_Saxon_Female"),
           getCharacter());
   assertTrue("got a null name!", Names.getInstance().getRandomName() != null);
   assertTrue("got a zero-length name!", Names.getInstance().getRandomName().length() > 0);
   System.out.println("random Anglo Saxon Female name: " + Names.getInstance().getRandomName());
 }
Ejemplo n.º 9
0
  @Override
  public void visitTopLevel(JCCompilationUnit tree) {
    JavaFileObject prev = log.useSource(tree.sourcefile);
    boolean addEnv = false;
    boolean isPkgInfo =
        tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE);
    if (tree.pid != null) {
      tree.packge = reader.enterPackage(TreeInfo.fullName(tree.pid));
      if (tree.packageAnnotations.nonEmpty() || pkginfoOpt == PkgInfo.ALWAYS) {
        if (isPkgInfo) {
          addEnv = true;
        } else {
          log.error(tree.packageAnnotations.head.pos(), "pkg.annotations.sb.in.package-info.java");
        }
      }
    } else {
      tree.packge = syms.unnamedPackage;
    }
    tree.packge.complete(); // Find all classes in package.
    Env<AttrContext> topEnv = topLevelEnv(tree);

    // Save environment of package-info.java file.
    if (isPkgInfo) {
      Env<AttrContext> env0 = typeEnvs.get(tree.packge);
      if (env0 == null) {
        typeEnvs.put(tree.packge, topEnv);
      } else {
        JCCompilationUnit tree0 = env0.toplevel;
        if (!fileManager.isSameFile(tree.sourcefile, tree0.sourcefile)) {
          log.warning(
              tree.pid != null ? tree.pid.pos() : null, "pkg-info.already.seen", tree.packge);
          if (addEnv
              || (tree0.packageAnnotations.isEmpty()
                  && tree.docComments != null
                  && tree.docComments.get(tree) != null)) {
            typeEnvs.put(tree.packge, topEnv);
          }
        }
      }

      for (Symbol q = tree.packge; q != null && q.kind == PCK; q = q.owner) q.flags_field |= EXISTS;

      Name name = names.package_info;
      ClassSymbol c = reader.enterClass(name, tree.packge);
      c.flatname = names.fromString(tree.packge + "." + name);
      c.sourcefile = tree.sourcefile;
      c.completer = null;
      c.members_field = new Scope(c);
      tree.packge.package_info = c;
    }
    classEnter(tree.defs, topEnv);
    if (addEnv) {
      todo.append(topEnv);
    }
    log.useSource(prev);
    result = null;
  }
Ejemplo n.º 10
0
  private void addNote(String whereString) {

    Names namesModel = (Names) super.getModel();
    NameContactNotes newNote;
    DomainEditor dialog = null;
    try {
      dialog =
          DomainEditorFactory.getInstance()
              .createDomainEditorWithParent(NameContactNotes.class, this.getParentEditor(), false);
    } catch (DomainEditorCreationException e) {
      new ErrorDialog(getParentEditor(), "Error creating editor for NameContactNotes", e)
          .showDialog();
    }
    dialog.setNewRecord(true);
    Boolean done = false;
    int sequenceNumber = 0;
    Boolean first = true;
    int returnStatus;

    while (!done) {
      newNote = new NameContactNotes(namesModel);
      if (first) {
        sequenceNumber =
            SequencedObjectsUtils.determineSequenceOfNewItem(whereString, nameContactNotesTable);
        first = false;
      } else {
        sequenceNumber++;
      }
      newNote.setSequenceNumber(sequenceNumber);
      dialog.setModel(newNote, null);
      returnStatus = dialog.showDialog();
      if (returnStatus == javax.swing.JOptionPane.OK_OPTION) {
        namesModel.addNameContactNote(newNote);
        nameContactNotesTable.getEventList().add(newNote);
        done = true;
      } else if (returnStatus == StandardEditor.OK_AND_ANOTHER_OPTION) {
        namesModel.addNameContactNote(newNote);
        nameContactNotesTable.getEventList().add(newNote);
      } else {
        done = true;
      }
    }
    dialog.setNewRecord(false);
  }
Ejemplo n.º 11
0
  private Names createPartitionNames(Mfs mfs) throws Exception {
    // try creating a proper MFS app partition name like "MFS application region 3"
    List<PartitionEntry> partitions = (mfs.getMfs() == null) ? null : mfs.getMfs().getPartitions();
    if ((partitions == null) || partitions.isEmpty())
      throw new Exception("No MFS partitions - MFS has not been initialized");

    int mediaPartitionIdx = 1;
    for (PartitionEntry pe : partitions) {
      if (pe == null) continue;
      String name = pe.getName();
      if (name == null) continue;
      Matcher m = MEDIA_PARTITION_NAME.matcher(name);
      if (m.matches()) mediaPartitionIdx = Integer.parseInt(m.group(1));
    }

    Names names = new Names();
    names.descriptor = APP_PARTITION_NAME_PREFIX + ' ' + (++mediaPartitionIdx);
    names.data = DATA_PARTITION_NAME_PREFIX + ' ' + mediaPartitionIdx;

    return names;
  }
Ejemplo n.º 12
0
  public Method lookupJavaMethod(
      IEvaluator<Result<IValue>> eval,
      FunctionDeclaration func,
      Environment env,
      boolean hasReflectiveAccess) {
    if (!func.isAbstract()) {
      throw new NonAbstractJavaFunction(func);
    }

    String className = getClassName(func);
    String name = Names.name(func.getSignature().getName());

    if (className.length() == 0) { // TODO: Can this ever be thrown since the Class instance has
      // already been identified via the javaClass tag.
      throw new MissingTag(JAVA_CLASS_TAG, func);
    }

    for (ClassLoader loader : loaders) {
      try {
        Class<?> clazz = loader.loadClass(className);
        Parameters parameters = func.getSignature().getParameters();
        Class<?>[] javaTypes = getJavaTypes(parameters, env, hasReflectiveAccess);

        try {
          Method m;

          if (javaTypes.length > 0) { // non-void
            m = clazz.getMethod(name, javaTypes);
          } else {
            m = clazz.getMethod(name);
          }

          return m;
        } catch (SecurityException e) {
          throw RuntimeExceptionFactory.permissionDenied(
              vf.string(e.getMessage()), eval.getCurrentAST(), eval.getStackTrace());
        } catch (NoSuchMethodException e) {
          throw new UndeclaredJavaMethod(e.getMessage(), func);
        }
      } catch (ClassNotFoundException e) {
        continue;
      }
    }

    throw new UndeclaredJavaMethod(className + "." + name, func);
  }
Ejemplo n.º 13
0
  /**
   * Sets the model for this editor.
   *
   * @param model the model to be used
   */
  public final void setModel(final DomainObject model, InfiniteProgressPanel progressPanel) {
    super.setModel(model, progressPanel);

    Names namesModel = (Names) model;
    resourcesTable.updateCollection(namesModel.getResources());
    accessionsTable.updateCollection(namesModel.getAccessions());
    digitalObjectsTable.updateCollection(namesModel.getDigitalObjects());
    nameContactNotesTable.updateCollection(namesModel.getRelatedCollection(NameContactNotes.class));
    nonPreferredNamesTable.updateCollection(
        namesModel.getRelatedCollection(NonPreferredNames.class));

    setPluginModel(); // update any plugins with this new domain object
  }
Ejemplo n.º 14
0
 protected StringFieldMapper(
     Names names,
     float boost,
     FieldType fieldType,
     FieldType defaultFieldType,
     Boolean docValues,
     String nullValue,
     NamedAnalyzer indexAnalyzer,
     NamedAnalyzer searchAnalyzer,
     NamedAnalyzer searchQuotedAnalyzer,
     int positionOffsetGap,
     int ignoreAbove,
     SimilarityProvider similarity,
     Loading normsLoading,
     @Nullable Settings fieldDataSettings,
     Settings indexSettings,
     MultiFields multiFields,
     CopyTo copyTo) {
   super(
       names,
       boost,
       fieldType,
       docValues,
       indexAnalyzer,
       searchAnalyzer,
       similarity,
       normsLoading,
       fieldDataSettings,
       indexSettings,
       multiFields,
       copyTo);
   if (fieldType.tokenized() && fieldType.indexOptions() != IndexOptions.NONE && hasDocValues()) {
     throw new MapperParsingException(
         "Field [" + names.fullName() + "] cannot be analyzed and have doc values");
   }
   this.defaultFieldType = defaultFieldType;
   this.nullValue = nullValue;
   this.positionOffsetGap = positionOffsetGap;
   this.searchQuotedAnalyzer =
       searchQuotedAnalyzer != null ? searchQuotedAnalyzer : this.searchAnalyzer;
   this.ignoreAbove = ignoreAbove;
 }
Ejemplo n.º 15
0
  private String getClassName(FunctionDeclaration declaration) {
    Tags tags = declaration.getTags();

    if (tags.hasTags()) {
      for (Tag tag : tags.getTags()) {
        if (Names.name(tag.getName()).equals(JAVA_CLASS_TAG)) {
          if (tag.hasContents()) {
            String contents = ((TagString.Lexical) tag.getContents()).getString();

            if (contents.length() > 2 && contents.startsWith("{")) {
              contents = contents.substring(1, contents.length() - 1);
            }
            return contents;
          }
        }
      }
    }

    return "";
  }
Ejemplo n.º 16
0
  public static Type typeOf(
      List<TypeArg> args, Environment env, boolean instantiateTypeParameters) {
    Type[] fieldTypes = new Type[args.size()];
    String[] fieldLabels = new String[args.size()];

    int i = 0;
    boolean allLabeled = true;
    boolean someLabeled = false;

    for (TypeArg arg : args) {
      fieldTypes[i] = arg.getType().typeOf(env, instantiateTypeParameters, null);

      if (arg.isNamed()) {
        fieldLabels[i] = Names.name(arg.getName());
        someLabeled = true;
      } else {
        fieldLabels[i] = null;
        allLabeled = false;
      }
      i++;
    }

    if (someLabeled && !allLabeled) {
      // TODO: this ast is not the root of the cause
      throw new PartiallyLabeledFields(args.get(0));
    }

    if (!allLabeled) {
      return TF.tupleType(fieldTypes);
    }
    for (int j = 0; j < fieldLabels.length - 1; j++) {
      for (int k = j + 1; k < fieldLabels.length; k++) {
        if (fieldLabels[j].equals(fieldLabels[k])) {
          throw new RedeclaredField(fieldLabels[j], args.get(k));
        }
      }
    }

    return TF.tupleType(fieldTypes, fieldLabels);
  }
Ejemplo n.º 17
0
  protected Enter(Context context) {
    context.put(enterKey, this);

    log = Log.instance(context);
    reader = ClassReader.instance(context);
    make = TreeMaker.instance(context);
    syms = Symtab.instance(context);
    chk = Check.instance(context);
    memberEnter = MemberEnter.instance(context);
    types = Types.instance(context);
    annotate = Annotate.instance(context);
    lint = Lint.instance(context);
    names = Names.instance(context);

    predefClassDef =
        make.ClassDef(make.Modifiers(PUBLIC), syms.predefClass.name, null, null, null, null);
    predefClassDef.sym = syms.predefClass;
    todo = Todo.instance(context);
    fileManager = context.get(JavaFileManager.class);

    Options options = Options.instance(context);
    pkginfoOpt = PkgInfo.get(options);
  }
Ejemplo n.º 18
0
 public FunctionRot13(Solver solver) {
   super(solver);
   Names.add(new LocalNames("Rot13", "en"));
 }
Ejemplo n.º 19
0
Archivo: Person.java Proyecto: Rsgm/ISA
 public Person() {
   citizen = Math.random() <= .7;
   name = Names.GenerateName();
 }
 public static void addGetterDeclaration(Names names, Class<?> type, JDefinedClass jDefinedClass) {
   JMethod method = jDefinedClass.method(JMod.NONE, type, names.getGetterName());
   JDocComment javadoc = method.javadoc();
   javadoc.append(names.getJavadoc());
 }
Ejemplo n.º 21
0
 private String getHandlerConfigFileName(String fullName) {
   String name = Names.stripQualifier(fullName);
   return name + "_handler.xml";
 }
Ejemplo n.º 22
0
 /** Convert contents to name. */
 public Name toName(Names names) {
   return names.fromUtf(elems, 0, length);
 }
Ejemplo n.º 23
0
 protected void log(String msg) {
   if (options.verbose) {
     System.out.println("[" + Names.stripQualifier(this.getClass().getName()) + ": " + msg + "]");
   }
 }
Ejemplo n.º 24
0
public interface RDouble extends RNumber {

  String TYPE_STRING = "double";
  long NA_LONGBITS = 0x7ff00000000007a2L; // R's NA is a special instance of IEEE's NaN
  int NA_LOWBITS = (int) NA_LONGBITS;
  double NA = Double.longBitsToDouble(NA_LONGBITS);
  double NaN = Double.NaN;
  double EPSILON = Math.pow(2.0, -52.0);
  double NEG_INF = Double.NEGATIVE_INFINITY;
  double POS_INF = Double.POSITIVE_INFINITY;

  DoubleImpl EMPTY = (DoubleImpl) RArrayUtils.markShared(RDoubleFactory.getUninitializedArray(0));
  ScalarDoubleImpl BOXED_ZERO =
      (ScalarDoubleImpl) RArrayUtils.markShared(RDoubleFactory.getScalar(0));
  ScalarDoubleImpl BOXED_NA =
      (ScalarDoubleImpl) RArrayUtils.markShared(RDoubleFactory.getScalar(NA));
  ScalarDoubleImpl BOXED_NEG_INF =
      (ScalarDoubleImpl) RArrayUtils.markShared(RDoubleFactory.getScalar(Double.NEGATIVE_INFINITY));
  ScalarDoubleImpl BOXED_POS_INF =
      (ScalarDoubleImpl) RArrayUtils.markShared(RDoubleFactory.getScalar(Double.POSITIVE_INFINITY));

  DoubleImpl EMPTY_NAMED_NA =
      (DoubleImpl)
          RArrayUtils.markShared(
              RDoubleFactory.getFor(
                  new double[] {}, null, Names.create(new RSymbol[] {RSymbol.NA_SYMBOL})));
  DoubleImpl NA_NAMED_NA =
      (DoubleImpl)
          RArrayUtils.markShared(
              RDoubleFactory.getFor(
                  new double[] {NA}, null, Names.create(new RSymbol[] {RSymbol.NA_SYMBOL})));

  RDouble set(int i, double val);

  double getDouble(int i);

  RDouble materialize();

  double[] getContent();

  public class RDoubleUtils {
    private static final boolean ARITH_NA_CHECKS = false;
    // should have explicit checks with floating point arithmetics to avoid NAs turning into NaNs?
    // NOTE: GNU-R does not have these checks

    public static boolean isNA(double d) {
      return ((int) Double.doubleToRawLongBits(d)) == NA_LOWBITS;
    }

    public static boolean arithIsNA(double d) {
      return ARITH_NA_CHECKS ? isNA(d) : false;
    }

    public static boolean fitsRInt(double d) {
      return d >= Integer.MIN_VALUE && d <= Integer.MAX_VALUE;
    }

    public static boolean isNAorNaN(double d) {
      return Double.isNaN(d);
    }

    public static boolean isFinite(double d) {
      return !isNAorNaN(d) && !Double.isInfinite(d);
    }

    public static RInt double2int(
        RDouble value, ConversionStatus warn) { // eager to keep error semantics eager
      int size = value.size();
      int[] content = new int[size];
      for (int i = 0; i < size; i++) {
        double d = value.getDouble(i);
        content[i] = Convert.double2int(d, warn);
      }
      return RInt.RIntFactory.getFor(content, value.dimensions(), value.names());
    }

    public static RRaw doubleToRaw(
        RDouble value, ConversionStatus warn) { // eager to keep error semantics eager
      int size = value.size();
      byte[] content = new byte[size];
      for (int i = 0; i < size; i++) {
        double dval = value.getDouble(i);
        content[i] = Convert.double2raw(dval, warn);
      }
      return RRaw.RRawFactory.getFor(content, value.dimensions(), value.names());
    }

    public static double[] copyAsDoubleArray(RDouble d) {
      int size = d.size();
      if (size == 1) {
        return new double[] {d.getDouble(0)};
      } else {
        double[] res = new double[size];

        if (d instanceof DoubleImpl) {
          System.arraycopy(((DoubleImpl) d).getContent(), 0, res, 0, size);
        } else {
          for (int i = 0; i < size; i++) {
            res[i] = d.getDouble(i);
          }
        }
        return res;
      }
    }

    public static boolean hasNAorNaN(RDouble d) {
      int size = d.size();
      for (int i = 0; i < size; i++) {
        if (isNAorNaN(d.getDouble(i))) {
          return true;
        }
      }
      return false;
    }

    public static RDouble convertNAandNaNtoZero(RDouble d) {
      if (d instanceof ScalarDoubleImpl) {
        ScalarDoubleImpl sd = (ScalarDoubleImpl) d;
        if (sd.isNAorNaN()) {
          return BOXED_ZERO;
        } else {
          return sd;
        }
      } else {
        RDouble res = d.materialize();
        double[] content = res.getContent();
        for (int i = 0; i < content.length; i++) {
          if (isNAorNaN(content[i])) {
            content[i] = 0;
          }
        }
        return res;
      }
    }
  }

  public class RDoubleFactory {
    public static ScalarDoubleImpl getScalar(double value) {
      return new ScalarDoubleImpl(value);
    }

    public static RDouble getScalar(
        double value, int[] dimensions, Names names, Attributes attributes) {
      if (dimensions == null && names == null && attributes == null) {
        return new ScalarDoubleImpl(value);
      } else {
        return getFor(new double[] {value}, dimensions, names, attributes);
      }
    }

    public static RDouble getArray(double... values) {
      if (values.length == 1) {
        return new ScalarDoubleImpl(values[0]);
      }
      return new DoubleImpl(values);
    }

    public static RDouble getArray(double[] values, int[] dimensions) {
      if (dimensions == null && values.length == 1) {
        return new ScalarDoubleImpl(values[0]);
      }
      return new DoubleImpl(values, dimensions, null);
    }

    public static RDouble getUninitializedArray(int size) {
      if (size == 1) {
        return new ScalarDoubleImpl(0);
      }
      return new DoubleImpl(size);
    }

    public static RDouble getUninitializedNonScalarArray(int size) {
      return new DoubleImpl(size);
    }

    public static RDouble getUninitializedArray(
        int size, int[] dimensions, Names names, Attributes attributes) {
      if (size == 1 && dimensions == null && names == null && attributes == null) {
        return new ScalarDoubleImpl(0);
      }
      return new DoubleImpl(new double[size], dimensions, names, attributes, false);
    }

    public static RDouble getNAArray(int size) {
      return getNAArray(size, null);
    }

    public static RDouble getNAArray(int size, int[] dimensions) {
      if (size == 1 && dimensions == null) {
        return BOXED_NA;
      }
      double[] content = new double[size];
      Arrays.fill(content, NA);
      return new DoubleImpl(content, dimensions, null, null, false);
    }

    public static DoubleImpl getMatrixFor(double[] values, int m, int n) {
      return new DoubleImpl(values, new int[] {m, n}, null, null, false);
    }

    public static RDouble copy(RDouble d) {
      if (d.size() == 1 && d.dimensions() == null && d.names() == null && d.attributes() == null) {
        return new ScalarDoubleImpl(d.getDouble(0));
      }
      return new DoubleImpl(d, false);
    }

    public static RDouble strip(RDouble v) {
      if (v.size() == 1) {
        return new ScalarDoubleImpl(v.getDouble(0));
      }
      return new DoubleImpl(v, true);
    }

    public static RDouble stripKeepNames(RDouble v) {
      Names names = v.names();
      if (v.size() == 1 && names == null) {
        return new ScalarDoubleImpl(v.getDouble(0));
      }
      return new DoubleImpl(v, null, names, null);
    }

    public static RDouble getFor(double[] values) { // re-uses values!
      return getFor(values, null, null);
    }

    public static RDouble getFor(
        double[] values, int[] dimensions, Names names) { // re-uses values!
      if (values.length == 1 && dimensions == null && names == null) {
        return new ScalarDoubleImpl(values[0]);
      }
      return new DoubleImpl(values, dimensions, names, null, false);
    }

    public static RDouble getFor(
        double[] values, int[] dimensions, Names names, Attributes attributes) { // re-uses values!
      if (values.length == 1 && dimensions == null && names == null && attributes == null) {
        return new ScalarDoubleImpl(values[0]);
      }
      return new DoubleImpl(values, dimensions, names, attributes, false);
    }

    public static RDouble getEmpty(boolean named) {
      return named ? EMPTY_NAMED_NA : EMPTY;
    }

    public static RDouble getNA(boolean named) {
      return named ? NA_NAMED_NA : BOXED_NA;
    }

    public static RDouble exclude(int excludeIndex, RDouble orig) {
      Names names = orig.names();
      if (names == null) {
        return new RDoubleExclusion(excludeIndex, orig);
      }
      int size = orig.size();
      int nsize = size - 1;
      double[] content = new double[nsize];
      for (int i = 0; i < excludeIndex; i++) {
        content[i] = orig.getDouble(i);
      }
      for (int i = excludeIndex; i < nsize; i++) {
        content[i] = orig.getDouble(i + 1);
      }
      return RDoubleFactory.getFor(content, null, names.exclude(excludeIndex));
    }

    public static RDouble subset(RDouble value, RInt index) {
      return new RDoubleSubset(value, index);
    }
  }

  public static class RStringView extends View.RStringProxy<RDouble> implements RString {

    public RStringView(RDouble orig) {
      super(orig);
    }

    @Override
    public RComplex asComplex() {
      return orig.asComplex();
    }

    @Override
    public RDouble asDouble() {
      return orig;
    }

    @Override
    public RInt asInt() {
      return orig.asInt();
    }

    @Override
    public RRaw asRaw() {
      return orig.asRaw();
    }

    @Override
    public RComplex asComplex(ConversionStatus warn) {
      return orig.asComplex();
    }

    @Override
    public RDouble asDouble(ConversionStatus warn) {
      return orig;
    }

    @Override
    public RInt asInt(ConversionStatus warn) {
      return orig.asInt(warn);
    }

    @Override
    public RRaw asRaw(ConversionStatus warn) {
      return orig.asRaw(warn);
    }

    @Override
    public String getString(int i) {
      return Convert.double2string(orig.getDouble(i));
    }
  }

  public static class RComplexView extends View.RComplexProxy<RDouble> implements RComplex {

    public RComplexView(RDouble orig) {
      super(orig);
    }

    @Override
    public RDouble asDouble() {
      return orig;
    }

    @Override
    public RInt asInt() {
      return orig.asInt();
    }

    @Override
    public RLogical asLogical() {
      return orig.asLogical();
    }

    @Override
    public RRaw asRaw() {
      return orig.asRaw();
    }

    @Override
    public RDouble asDouble(ConversionStatus warn) {
      return orig;
    }

    @Override
    public RInt asInt(ConversionStatus warn) {
      return orig.asInt(warn);
    }

    @Override
    public RLogical asLogical(ConversionStatus warn) {
      return orig.asLogical();
    }

    @Override
    public RRaw asRaw(ConversionStatus warn) {
      return orig.asRaw(warn);
    }

    @Override
    public double getReal(int i) {
      double d = orig.getDouble(i);
      if (RDoubleUtils.isNAorNaN(d)) {
        return RDouble.NA;
      } else {
        return d;
      }
    }

    @Override
    public double getImag(int i) {
      double d = orig.getDouble(i);
      if (RDoubleUtils.isNAorNaN(d)) {
        return RDouble.NA;
      } else {
        return 0;
      }
    }
  }

  public static class RIntView extends View.RIntProxy<RDouble> implements RInt {

    public RIntView(RDouble orig) {
      super(orig);
    }

    @Override
    public int getInt(int i) {
      return Convert.double2int(orig.getDouble(i));
    }
  }

  public static class RLogicalView extends View.RLogicalProxy<RDouble> implements RLogical {

    public RLogicalView(RDouble orig) {
      super(orig);
    }

    @Override
    public int getLogical(int i) {
      return Convert.double2logical(orig.getDouble(i));
    }
  }

  public static class RRawView extends View.RRawProxy<RDouble>
      implements RRaw { // FIXME: remove this? it breaks warnings

    public RRawView(RDouble orig) {
      super(orig);
    }

    @Override
    public byte getRaw(int i) {
      return Convert.double2raw(orig.getDouble(i));
    }
  }

  public static class RDoubleExclusion extends View.RDoubleView implements RDouble {

    final RDouble orig;
    final int excludeIndex;
    final int size;

    public RDoubleExclusion(int excludeIndex, RDouble orig) {
      this.orig = orig;
      this.excludeIndex = excludeIndex;
      this.size = orig.size() - 1;
    }

    @Override
    public int size() {
      return size;
    }

    @Override
    public double getDouble(int i) {
      assert Utils.check(i < size, "bounds check");
      assert Utils.check(i >= 0, "bounds check");

      if (i < excludeIndex) {
        return orig.getDouble(i);
      } else {
        return orig.getDouble(i + 1);
      }
    }

    @Override
    public boolean isSharedReal() {
      return orig.isShared();
    }

    @Override
    public void ref() {
      orig.ref();
    }

    @Override
    public boolean dependsOn(RAny value) {
      return orig.dependsOn(value);
    }
  }

  // indexes must all be positive
  //   but can be out of bounds ==> NA's are returned in that case
  public static class RDoubleSubset extends View.RDoubleView implements RDouble {

    final RDouble value;
    final int vsize;
    final RInt index;
    final int isize;

    public RDoubleSubset(RDouble value, RInt index) {
      this.value = value;
      this.index = index;
      this.isize = index.size();
      this.vsize = value.size();
    }

    @Override
    public int size() {
      return isize;
    }

    @Override
    public double getDouble(int i) {
      int j = index.getInt(i);
      assert Utils.check(j > 0);
      if (j > vsize) {
        return RDouble.NA;
      } else {
        return value.getDouble(j - 1);
      }
    }

    @Override
    public boolean isSharedReal() {
      return value.isShared() || index.isShared();
    }

    @Override
    public void ref() {
      value.ref();
      index.ref();
    }

    @Override
    public boolean dependsOn(RAny v) {
      return value.dependsOn(v) || index.dependsOn(v);
    }
  }
}
Ejemplo n.º 25
0
  private Names lookupName(NamesDAO namesDao, NameComplexType nameFromImport)
      throws IllegalAccessException, InvocationTargetException, UnknownLookupListException,
          PersistenceException, NoSuchAlgorithmException, UnsupportedEncodingException {
    Names name = new Names();
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_NAME_TYPE, nameFromImport.getNameType());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_SORT_NAME, nameFromImport.getSortName());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_NAME_RULE, nameFromImport.getNameRule());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_NUMBER, nameFromImport.getNumber());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_QUALIFIER, nameFromImport.getQualifier());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_DESCRIPTION_TYPE, nameFromImport.getDescriptionType());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_DESCRIPTION_NOTE, nameFromImport.getDescriptionNote());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_CITATION, nameFromImport.getCitation());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_SALUTATION, nameFromImport.getSalutation());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_CONTACT_ADDRESS_1, nameFromImport.getContactAddress1());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_CONTACT_ADDRESS_2, nameFromImport.getContactAddress2());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_CONTACT_CITY, nameFromImport.getContactCity());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_CONTACT_REGION, nameFromImport.getContactRegion());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_CONTACT_COUNTRY, nameFromImport.getContactCountry());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_CONTACT_MAIL_CODE, nameFromImport.getContactMailCode());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_CONTACT_PHONE, nameFromImport.getContactPhone());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_CONTACT_FAX, nameFromImport.getContactFax());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_CONTACT_EMAIL, nameFromImport.getContactEmail());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_CONTACT_NAME, nameFromImport.getContactName());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_FAMILY_NAME, nameFromImport.getFamilyName());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_FAMILY_NAME_PREFIX, nameFromImport.getFamilyNamePrefix());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_CORPORATE_PRIMARY_NAME, nameFromImport.getCorporatePrimaryName());
    ImportUtils.nullSafeSet(
        name,
        Names.PROPERTYNAME_CORPORATE_SUBORDINATE_1,
        nameFromImport.getCorporateSubordinate1());
    ImportUtils.nullSafeSet(
        name,
        Names.PROPERTYNAME_CORPORATE_SUBORDINATE_2,
        nameFromImport.getCorporateSubordinate2());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_PERSONAL_PRIMARY_NAME, nameFromImport.getPersonalPrimaryName());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_PERSONAL_REST_OF_NAME, nameFromImport.getPersonalRestOfName());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_PERSONAL_PREFIX, nameFromImport.getPersonalPrefix());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_PERSONAL_SUFFIX, nameFromImport.getPersonalSuffix());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_PERSONAL_FULLER_FORM, nameFromImport.getPersonalFullerForm());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_PERSONAL_TITLE, nameFromImport.getPersonalTitle());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_PERSONAL_DATES, nameFromImport.getPersonalDates());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_PERSONAL_DIRECT_ORDER, nameFromImport.isPersonalDirectOrder());
    if (nameFromImport.getNameSource() == null) {
      name.setNameSource("ingest");
    } else {
      name.setNameSource(nameFromImport.getNameSource());
    }
    if (name.getSortName() == null || name.getSortName().length() == 0) {
      name.createSortName();

      // check to see if sort name is still empty. If so, set it to " " so that
      // this record can be inserted into an Oracle DB without throwing an error
      if (name.getSortName().length() == 0) {
        name.setSortName(" ");
      }
    }
    NameUtils.setMd5Hash(name);

    return namesDao.lookupName(name, true);
  }
Ejemplo n.º 26
0
 public FunctionAlphaPos(Solver solver) {
   super(solver);
   Names.add(new LocalNames("AlphaPos", "en"));
   Names.add(new LocalNames("AP", "en"));
 }
  @SuppressWarnings("unchecked")
  public <IFD extends IndexFieldData<?>> IFD getForField(MappedFieldType fieldType) {
    final Names fieldNames = fieldType.names();
    final FieldDataType type = fieldType.fieldDataType();
    if (type == null) {
      throw new IllegalArgumentException(
          "found no fielddata type for field [" + fieldNames.fullName() + "]");
    }
    final boolean docValues = fieldType.hasDocValues();
    IndexFieldData.Builder builder = null;
    String format = type.getFormat(indexSettings);
    if (format != null && FieldDataType.DOC_VALUES_FORMAT_VALUE.equals(format) && !docValues) {
      logger.warn(
          "field ["
              + fieldNames.fullName()
              + "] has no doc values, will use default field data format");
      format = null;
    }
    if (format != null) {
      builder = buildersByTypeAndFormat.get(Tuple.tuple(type.getType(), format));
      if (builder == null) {
        logger.warn(
            "failed to find format ["
                + format
                + "] for field ["
                + fieldNames.fullName()
                + "], will use default");
      }
    }
    if (builder == null && docValues) {
      builder = docValuesBuildersByType.get(type.getType());
    }
    if (builder == null) {
      builder = buildersByType.get(type.getType());
    }
    if (builder == null) {
      throw new IllegalArgumentException(
          "failed to find field data builder for field "
              + fieldNames.fullName()
              + ", and type "
              + type.getType());
    }

    IndexFieldDataCache cache;
    synchronized (this) {
      cache = fieldDataCaches.get(fieldNames.indexName());
      if (cache == null) {
        //  we default to node level cache, which in turn defaults to be unbounded
        // this means changing the node level settings is simple, just set the bounds there
        String cacheType =
            type.getSettings()
                .get("cache", indexSettings.get(FIELDDATA_CACHE_KEY, FIELDDATA_CACHE_VALUE_NODE));
        if (FIELDDATA_CACHE_VALUE_NODE.equals(cacheType)) {
          cache = indicesFieldDataCache.buildIndexFieldDataCache(listener, index, fieldNames, type);
        } else if ("none".equals(cacheType)) {
          cache = new IndexFieldDataCache.None();
        } else {
          throw new IllegalArgumentException(
              "cache type not supported ["
                  + cacheType
                  + "] for field ["
                  + fieldNames.fullName()
                  + "]");
        }
        fieldDataCaches.put(fieldNames.indexName(), cache);
      }
    }

    return (IFD)
        builder.build(index, indexSettings, fieldType, cache, circuitBreakerService, mapperService);
  }