public TerminalWriter(final JavaFileInfo javaFileInfo) {
   Preconditions.checkNotNull(javaFileInfo, "Missing 'javaFileInfo'.");
   this.javaFileInfo = javaFileInfo;
   packageName = javaFileInfo.packageName();
   terminalName = javaFileInfo.entityName();
   prime = javaFileInfo.prime();
   tag = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, terminalName);
   simpleName =
       CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, terminalName).replace('_', ' ');
   terminalTypeName = ClassName.get(packageName, terminalName);
 }
  public DataConverter(Class<T> clazz)
      throws TooManyPrimaryKeys, NotAnnotatedAsTableClassException, PrimaryKeyIsNotColumnException,
          NoPrimaryKeyException {
    if (clazz.getAnnotation(Table.class) == null) {
      throw new NotAnnotatedAsTableClassException();
    } else {
      if (!clazz.getDeclaredAnnotation(Table.class).name().equals("")) {
        tableName = clazz.getDeclaredAnnotation(Table.class).name();
      } else {
        tableName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, clazz.getSimpleName());
      }
    }
    fields = new ArrayList<FieldConverter>();
    for (Field field : clazz.getDeclaredFields()) {
      Class<?> type = field.getType();
      Annotation primaryKeyAnnotation = field.getDeclaredAnnotation(PrimaryKey.class),
          columnAnnotation = field.getDeclaredAnnotation(Column.class);

      if (primaryKeyAnnotation != null) {
        if (columnAnnotation == null) {
          throw new PrimaryKeyIsNotColumnException();
        }
        if (primaryKeyField != null) {
          throw new TooManyPrimaryKeys();
        }
        primaryKeyField = field;
      }
      if (columnAnnotation != null) {
        String name = null;
        if (!field.getDeclaredAnnotation(Column.class).name().equals("")) {
          name = field.getDeclaredAnnotation(Column.class).name();
        } else {
          name = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, field.getName());
        }
        FieldConverter currentFieldConverter = new FieldConverter(name, field);
        fields.add(currentFieldConverter);
        if (field.equals(primaryKeyField)) {
          primaryKeyFieldConverter = currentFieldConverter;
        }
      }
      Annotation[] annotations = field.getDeclaredAnnotations();
      for (Annotation annotation : annotations) {
        annotation.getClass();
      }
    }
    if (primaryKeyField == null) {
      throw new NoPrimaryKeyException();
    }
  }
  public static double getMass(Composable source, Composed target) {

    double wynik = 0;

    BeanWrapper wrapper = new BeanWrapperImpl(source);

    for (Substance substance : target) {

      String propName =
          CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, substance.getSubstanceName());

      if (wrapper.isReadableProperty(propName)) {
        Object propValue = wrapper.getPropertyValue(propName);

        if (propValue != null) {

          if (propValue instanceof Composable) {
            wynik += Compositions.getMass((Composable) propValue, (Composed) substance);
          } else if (propValue instanceof Double) {
            wynik += (Double) propValue;
          }
        }
      }
    }

    return wynik;
  }
Exemple #4
0
 protected String trim(String name, String prefix) {
   if (name.startsWith(prefix)) {
     name = name.substring(prefix.length());
     return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, name);
   }
   return null;
 }
Exemple #5
0
 public static Type fromValue(String type) {
   try {
     return valueOf(
         CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type")));
   } catch (IllegalArgumentException e) {
     return UNRECOGNIZED;
   }
 }
 public static PublicIPStatus fromValue(String status) {
   try {
     return valueOf(
         CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(status, "status")));
   } catch (IllegalArgumentException e) {
     return UNRECOGNIZED;
   }
 }
  @Override
  @BeforeClass(groups = "live")
  public void setupContext() {
    super.setupContext();
    instanceName =
        VIRTUALBOX_IMAGE_PREFIX
            + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName());

    StorageController ideController =
        StorageController.builder()
            .name("IDE Controller")
            .bus(StorageBus.IDE)
            .attachISO(0, 0, operatingSystemIso)
            .attachHardDisk(
                HardDisk.builder()
                    .diskpath(adminDisk(instanceName))
                    .controllerPort(0)
                    .deviceSlot(1)
                    .autoDelete(true)
                    .build())
            .attachISO(1, 1, guestAdditionsIso)
            .build();

    VmSpec instanceVmSpec =
        VmSpec.builder()
            .id(instanceName)
            .name(instanceName)
            .osTypeId("")
            .memoryMB(512)
            .cleanUpMode(CleanupMode.Full)
            .controller(ideController)
            .forceOverwrite(true)
            .build();

    Injector injector = view.utils().injector();
    Function<String, String> configProperties =
        injector.getInstance(ValueOfConfigurationKeyOrNull.class);
    IsoSpec isoSpec =
        IsoSpec.builder()
            .sourcePath(operatingSystemIso)
            .installationScript(
                configProperties
                    .apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE)
                    .replace("HOSTNAME", instanceVmSpec.getVmName()))
            .build();

    NetworkAdapter networkAdapter =
        NetworkAdapter.builder()
            .networkAttachmentType(NetworkAttachmentType.NAT)
            .tcpRedirectRule("127.0.0.1", 2222, "", 22)
            .build();
    NetworkInterfaceCard networkInterfaceCard =
        NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter).build();

    NetworkSpec networkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build();
    machineSpec = MasterSpec.builder().iso(isoSpec).vm(instanceVmSpec).network(networkSpec).build();
  }
  @Override
  public String toOperationId(String operationId) {
    // throw exception if method name is empty
    if (StringUtils.isEmpty(operationId)) {
      throw new RuntimeException("Empty method name (operationId) not allowed");
    }

    return super.toOperationId(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, operationId));
  }
  /**
   * Gets token type of ParseTree node from JavadocTokenTypes class.
   *
   * @param node ParseTree node.
   * @return token type from JavadocTokenTypes
   */
  private static int getTokenType(ParseTree node) {
    final int tokenType;

    if (node.getChildCount() == 0) {
      tokenType = ((TerminalNode) node).getSymbol().getType();
    } else {
      final String className = getNodeClassNameWithoutContext(node);
      final String typeName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, className);
      tokenType = JavadocUtils.getTokenId(typeName);
    }

    return tokenType;
  }
  protected Optional<Path> exportApiDocument(Table table, List<String> lines) {
    Path baseFolder = projectHome.resolve("api");

    String pkgName = getPackageName(table);
    String folder = StringUtils.replace(pkgName, ".", "/");
    Path path = Paths.get(folder).getParent().getFileName();

    String className = getClassName(table);
    Path file =
        baseFolder
            .resolve(path)
            .resolve(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, className) + ".md");
    return createFile(file, lines);
  }
 private static void copyInternal(Composable source, Composed target, BeanWrapper parent) {
   // copy(source, target);
   if (target instanceof Mixture) {
     Mixture mixture = (Mixture) target;
     String totalPropName =
         CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, mixture.getSubstanceName() + "Total");
     if (parent.isReadableProperty(totalPropName)
         && parent.getPropertyType(totalPropName) == Double.class) {
       Double total = (Double) parent.getPropertyValue(totalPropName);
       if (total != null) {
         if (mixture.isComplete()) {
           double t = mixture.getAmount();
           mixture.setRemains(Math.max(total - t, 0.0));
         } else {
           mixture.setAmount(total);
         }
       }
     }
   }
 }
    /**
     * Logs parser errors in Checkstyle manner. Parser can generate error messages. There is special
     * error that parser can generate. It is missed close HTML tag. This case is special because
     * parser prints error like {@code "no viable alternative at input 'b \n *\n'"} and it is not
     * clear that error is about missed close HTML tag. Other error messages are not special and
     * logged simply as "Parse Error...".
     *
     * <p>{@inheritDoc}
     */
    @Override
    public void syntaxError(
        Recognizer<?, ?> recognizer,
        Object offendingSymbol,
        int line,
        int charPositionInLine,
        String msg,
        RecognitionException ex) {
      final int lineNumber = offset + line;
      final Token token = (Token) offendingSymbol;

      if (MSG_JAVADOC_MISSED_HTML_CLOSE.equals(msg)) {
        errorMessage =
            new ParseErrorMessage(
                lineNumber, MSG_JAVADOC_MISSED_HTML_CLOSE, charPositionInLine, token.getText());

        throw new ParseCancellationException(msg);
      } else if (MSG_JAVADOC_WRONG_SINGLETON_TAG.equals(msg)) {
        errorMessage =
            new ParseErrorMessage(
                lineNumber, MSG_JAVADOC_WRONG_SINGLETON_TAG, charPositionInLine, token.getText());

        throw new ParseCancellationException(msg);
      } else {
        final int ruleIndex = ex.getCtx().getRuleIndex();
        final String ruleName = recognizer.getRuleNames()[ruleIndex];
        final String upperCaseRuleName =
            CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, ruleName);

        errorMessage =
            new ParseErrorMessage(
                lineNumber,
                MSG_JAVADOC_PARSE_RULE_ERROR,
                charPositionInLine,
                msg,
                upperCaseRuleName);
      }
    }
  public static void copy(NutritionInfo source, Composed target) {

    for (Substance substance : target) {
      String propName =
          CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, substance.getSubstanceName());
      if (!propName.equals(null)) {
        Double value = 0.0;
        switch (propName) {
          case "fiber":
            value = source.getFiber();
            break;
          case "ash":
            value = source.getAsh();
            break;
          case "carbohydrates":
            value = source.getCarbohydratesTotal();
            break;
          case "cholesterol":
            value = source.getCholesterol();
            break;
          case "ethanol":
            value = source.getEthanol();
            break;
          case "water":
            value = source.getWater();
            break;
          case "fats":
            value = source.getFatsTotal();
            break;
          case "proteins":
            value = source.getProteinsTotal();
            break;
            //					case ": sodium": value = source.get;break;
            //					case ": potassium": value = source.getPo;break;
            //					case ": calcium": value = source.getFiber();break;
            //					case ": phosphorus": value = source.getFiber();break;
            //					case ": magnesium": value = source.getFiber();break;
            //					case ": iron": value = source.getFiber();break;
            //					case ": zinc": value = source.getFiber();break;
            //					case ": copper": value = source.getFiber();break;
            //					case ": manganese": value = source.getFiber();break;
            //					case ": iodine": value = source.getFiber();break;
            //					case ": vitaminA": value = source.getFiber();break;
            //					case ": retinol": value = source.getFiber();break;
            //					case ": betaCarotene": value = source.getFiber();break;
            //					case ": vitaminD": value = source.getFiber();break;
            //					case ": vitaminE": value = source.getFiber();break;
            //					case ": thiamine": value = source.getFiber();break;
            //					case ": riboflavin": value = source.getFiber();break;
            //					case ": niacin": value = source.getFiber();break;
            //					case ": vitaminB6": value = source.getFiber();break;
            //					case ": folicAcid": value = source.getFiber();break;
            //					case ": vitaminB12": value = source.getFiber();break;
            //					case ": vitaminC": value = source.getFiber();break;
          default:
            break;
        }

        if (value != null && value >= 0) {
          if (value > 0)
            //								write.addToText(substance.getSubstanceName()+" -> "+value);
            substance.setAmount(value);
        } else {
          substance.setAmount(Double.NaN);
          if (target instanceof Mixture) {
            ((Mixture) target).setComplete(false);
          }
        }
      }
    }
  }
Exemple #14
0
 @Override
 public String camelCasedName() {
   return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, memberName);
 }
Exemple #15
0
 /**
  * Create a new alias proxy of the given type
  *
  * @param cl type of the alias
  * @return alias instance
  */
 public static <A> A alias(Class<A> cl) {
   return alias(cl, CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, cl.getSimpleName()));
 }
Exemple #16
0
 public static String getRmTypeName(@Nonnull Class<?> clazz) {
   return CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, clazz.getSimpleName());
 }
Exemple #17
0
 @Override
 public String snakeCasedName() {
   return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, memberName);
 }
 /**
  * Obtains an instance from the specified unique name.
  *
  * @param uniqueName the unique name
  * @return the type
  * @throws IllegalArgumentException if the name is not known
  */
 @FromString
 public static CompoundedRateType of(String uniqueName) {
   ArgChecker.notNull(uniqueName, "uniqueName");
   return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, uniqueName));
 }