Ejemplo n.º 1
1
    public static <T> Prop<T> cannonicalize(Prop<T> p) {
      Prop<T> prop = cannon.computeIfAbsent(p.name, x -> p);
      if (p.isCannon() && !prop.isCannon()) {
        cannon.put(p.name, p);
        prop = p;
      } else if (p.isCannon() && prop.isCannon() && p != prop) {
        // should be an Error?
        System.err.println(" WARNING: two competing canonical definitions of a Prop <" + p + ">");
        if (p.typeInformation != null && prop.typeInformation == null) {
          cannon.put(p.name, p);
          prop = p;
        } else if (p.typeInformation == null && prop.typeInformation != null) {

        } else if (p.typeInformation != null && prop.typeInformation != null) {
          if (!Conversions.typeInformationEquals(p.typeInformation, prop.typeInformation)) {
            System.err.println(
                " ERROR: the two competing canonical definitions of "
                    + p
                    + " have different type information");
            throw new IllegalArgumentException(
                p.typeInformation + " " + prop.typeInformation + " " + p + " " + prop);
          }
        }
      }
      prop.setCannon();
      return prop;
    }
Ejemplo n.º 2
0
  @Transactional
  public OffersInfo updateOffersInfo(int companyId, int offerId, OffersInfo offersInfo)
      throws Exception {
    try {
      OfferInfoPrimaryKey id = Conversions.getOfferInfoPrimaryKey(companyId, offerId);
      OfferInfoDbType dbEntry = offersInfoDao.find(id);

      updateOfferInfoDbEntry(dbEntry, offersInfo);

      return offersInfo;
    } catch (Exception e) {
      logger.error(
          "error updating offers for : "
              + companyId
              + " and : "
              + offersInfo.getBranchId()
              + " : "
              + e.getMessage());
      throw new Exception(
          "error updating offers for : "
              + companyId
              + " and : "
              + offersInfo.getBranchId()
              + " : "
              + e.getMessage());
    }
  }
Ejemplo n.º 3
0
  @Transactional
  public OffersInfo addOffersInfo(int companyId, OffersInfo offersInfo) throws Exception {
    try {
      int offerId = offersInfoDao.getMaxIdValue(companyId) + 1;
      OfferInfoDbType offerInfoDbType =
          Conversions.getOfferInfoDbEntry(companyId, offersInfo.getBranchId(), offerId, offersInfo);
      offersInfoDao.add(offerInfoDbType);

      offersInfo.setOfferId(offerId);
      return offersInfo;
    } catch (Exception e) {
      logger.error(
          "error adding offers for : "
              + companyId
              + " and : "
              + offersInfo.getBranchId()
              + " : "
              + e.getMessage());
      throw new Exception(
          "error adding offers for : "
              + companyId
              + " and : "
              + offersInfo.getBranchId()
              + " : "
              + e.getMessage());
    }
  }
Ejemplo n.º 4
0
 /**
  * Returns a NonEmptyList of the sublists of this list.
  *
  * @return a NonEmptyList of the sublists of this list.
  */
 public NonEmptyList<NonEmptyList<A>> sublists() {
   return fromList(
           somes(
               toList()
                   .toStream()
                   .substreams()
                   .map(F1Functions.o(list -> fromList(list), Conversions.<A>Stream_List()))
                   .toList()))
       .some();
 }
Ejemplo n.º 5
0
  public List<OffersInfo> getOffersInfo() throws Exception {
    try {
      List<OfferInfoDbType> listDbEntries = offersInfoDao.findAll();
      List<OffersInfo> out = new ArrayList<OffersInfo>(listDbEntries.size());

      for (OfferInfoDbType dbEntry : listDbEntries) {
        out.add(Conversions.getOffersInfo(dbEntry));
      }
      return out;
    } catch (Exception e) {
      logger.error("error getting all offers for : " + e.getMessage());
      throw new Exception("error getting all offers for : " + e.getMessage());
    }
  }
Ejemplo n.º 6
0
 public OffersInfo getOfferOrInfo(int companyId, int offerId) throws Exception {
   try {
     OfferInfoDbType dbEntry =
         offersInfoDao.find(Conversions.getOfferInfoPrimaryKey(companyId, offerId));
     OffersInfo out = Conversions.getOffersInfo(dbEntry);
     return out;
   } catch (Exception e) {
     logger.error(
         "error getting offer for : "
             + companyId
             + " and : offer id"
             + offerId
             + " : "
             + e.getMessage());
     throw new Exception(
         "error getting offers for : "
             + companyId
             + " and : offer id"
             + offerId
             + " : "
             + e.getMessage());
   }
 }
Ejemplo n.º 7
0
  public List<OffersInfo> getOffersInfo(int companyId) throws Exception {
    try {
      List<OfferInfoDbType> listDbEntries = offersInfoDao.getOffersAndInfo(companyId);
      List<OffersInfo> out = new ArrayList<OffersInfo>(listDbEntries.size());

      for (OfferInfoDbType dbEntry : listDbEntries) {
        out.add(Conversions.getOffersInfo(dbEntry));
      }
      return out;
    } catch (Exception e) {
      logger.error("error getting offers for : " + companyId + " and : " + " : " + e.getMessage());
      throw new Exception(
          "error getting offers for : " + companyId + " and : " + " : " + e.getMessage());
    }
  }
Ejemplo n.º 8
0
    @CallerSensitive
    public <T> Prop<T> type() {

      Prop on = this;
      if (!isCannon()) {
        Prop<T> already = (Prop<T>) findCannon();
        if (already == null) {
          toCannon();
          on.setCannon();
        } else {
          on = already;
        }
      }

      Class c = sun.reflect.Reflection.getCallerClass(2);

      on.definedInClass = c;

      Field f = null;
      try {
        f = c.getField(name);
      } catch (NoSuchFieldException e) {

        try {
          f = c.getField("_" + name);
        } catch (NoSuchFieldException e3) {
          if (name.startsWith("_"))
            try {
              f = c.getField(name.substring(1));
            } catch (NoSuchFieldException e1) {
              if (name.startsWith("__"))
                try {
                  f = c.getField(name.substring(1));
                } catch (NoSuchFieldException e2) {
                }
            }
        }
      }
      if (f == null)
        throw new IllegalStateException(
            " cannot type a Dict.Prop<T> that we can't find. Name is :" + name + " class is :" + c);

      on.typeInformation = Conversions.linearize(f.getGenericType());

      on.typeInformation.remove(0);

      return (Prop<T>) on;
    }
Ejemplo n.º 9
0
 /**
  * Returns a NonEmptyList of the sublists of this list.
  *
  * @return a NonEmptyList of the sublists of this list.
  */
 public NonEmptyList<NonEmptyList<A>> sublists() {
   return fromList(
           somes(
               toList()
                   .toStream()
                   .substreams()
                   .map(
                       F1Functions.o(
                           new F<List<A>, Option<NonEmptyList<A>>>() {
                             public Option<NonEmptyList<A>> f(final List<A> list) {
                               return fromList(list);
                             }
                           },
                           Conversions.<A>Stream_List()))
                   .toList()))
       .some();
 }
Ejemplo n.º 10
0
  private static String _sysProp(String key, Object defaultValue) {
    String property = (String) systemProperties.get(key);
    if (property == null) {
      property = env.get(key);

      if (property == null) {
        String newKey = Str.underBarCase(key);
        property = env.get(newKey);

        if (property == null && defaultValue != DEFAULT_NULL_NOT_EMPTY) {
          property = Conversions.toString(defaultValue);
        }
      }
    }

    return property;
  }
Ejemplo n.º 11
0
  public static <T extends Enum> T sysProp(Class<T> cls, String key, T defaultValue) {

    String property = (String) systemProperties.get(key);
    if (property == null) {
      property = env.get(key);
    }

    if (property == null) {
      String newKey = Str.underBarCase(key);
      property = env.get(newKey);
    }

    if (property == null) {
      return defaultValue;
    }

    return Conversions.toEnum(cls, property);
  }
Ejemplo n.º 12
0
  public static BigInteger sysPropBigInteger(String key, BigInteger defaultValue) {

    String property = (String) systemProperties.get(key);
    if (property == null) {
      property = env.get(key);
    }

    if (property == null) {
      String newKey = Str.underBarCase(key);
      property = env.get(newKey);
    }

    if (property == null) {
      return defaultValue;
    }

    return Conversions.toBigInteger(property);
  }
Ejemplo n.º 13
0
  public static byte sysProp(String key, byte defaultValue) {

    String property = (String) systemProperties.get(key);
    if (property == null) {
      property = env.get(key);
    }

    if (property == null) {
      String newKey = Str.underBarCase(key);
      property = env.get(newKey);
    }

    if (property == null) {
      return defaultValue;
    }

    return Conversions.toByte(property);
  }
  /**
   * Builder for {@link PatternMatchingConversion} used to configure it.
   *
   * @param <Source> type to be converted
   * @param <Result> type of the conversion result
   */
  public static class Builder<Source, Result> {
    private final List<Map.Entry<Predicate<Source>, Conversion<Source, Result>>> cases =
        new ArrayList<>();
    private Conversion<Source, Result> defaultConversion =
        Conversions.throwing("Can't find conversion for the given source");

    /**
     * Specify specification on the conversion source and corresponding object for such case.
     *
     * @param condition predicate on conversion source returning true if the given conversion should
     *     be applied.
     * @param conversion conversion to be applied on sources satisfying the given predicate
     * @return this instance
     */
    public Builder<Source, Result> inCaseOf(
        Predicate<Source> condition, Conversion<Source, Result> conversion) {
      cases.add(new AbstractMap.SimpleEntry<>(condition, conversion));

      return this;
    }

    /**
     * Specify default conversion which will be called when there is no match for the given source.
     *
     * @param defaultConversion default conversion
     * @return this instance
     */
    public Builder<Source, Result> otherwise(Conversion<Source, Result> defaultConversion) {
      this.defaultConversion = defaultConversion;

      return this;
    }

    /**
     * Build a {@link PatternMatchingConversion} based on the given configuration.
     *
     * @return initialized pattern matching conversion
     */
    public Conversion<Source, Result> build() {
      return new PatternMatchingConversion<>(cases, defaultConversion);
    }
  }
Ejemplo n.º 15
0
 public static String putSysProp(String key, Object value) {
   return (String) systemProperties.put(key, Conversions.toString(value));
 }
  public List<PropertyDeclaration> buildDeclarations(
      final CSSName cssName,
      final List<PropertyValue> values,
      final CSSOrigin origin,
      final boolean important,
      final boolean inheritAllowed) {
    List<PropertyDeclaration> result =
        checkInheritAll(ALL, values, origin, important, inheritAllowed);
    if (result != null) {
      return result;
    }

    PropertyDeclaration fontStyle = null;
    PropertyDeclaration fontVariant = null;
    PropertyDeclaration fontWeight = null;
    PropertyDeclaration fontSize = null;
    PropertyDeclaration lineHeight = null;
    PropertyDeclaration fontFamily = null;

    boolean keepGoing = false;

    final ListIterator<PropertyValue> i = values.listIterator();
    while (i.hasNext()) {
      PropertyValue value = (PropertyValue) i.next();
      final CSSPrimitiveUnit type = value.getPrimitiveTypeN();
      if (type == CSSPrimitiveUnit.CSS_IDENT) {
        // The parser will have given us ident values as they appear
        // (case-wise) in the CSS text since we might be creating
        // a font-family list out of them.  Here we want the normalized
        // (lowercase) version though.
        final String lowerCase = value.getStringValue().toLowerCase();
        value = new PropertyValueImp(CSSPrimitiveUnit.CSS_IDENT, lowerCase, lowerCase);
        final IdentValue ident = checkIdent(cssName, value);
        if (ident == IdentValue.NORMAL) { // skip to avoid double set false positives
          continue;
        }
        if (IdentSet.FONT_STYLES.contains(ident)) {
          if (fontStyle != null) {
            throw new CSSParseException(LangId.NO_TWICE, -1, "font-style");
          }
          fontStyle = new PropertyDeclaration(CSSName.FONT_STYLE, value, important, origin);
        } else if (IdentSet.FONT_VARIANTS.contains(ident)) {
          if (fontVariant != null) {
            throw new CSSParseException(LangId.NO_TWICE, -1, "font-variant");
          }
          fontVariant = new PropertyDeclaration(CSSName.FONT_VARIANT, value, important, origin);
        } else if (IdentSet.FONT_WEIGHTS.contains(ident)) {
          if (fontWeight != null) {
            throw new CSSParseException(LangId.NO_TWICE, -1, "font-weight");
          }
          fontWeight = new PropertyDeclaration(CSSName.FONT_WEIGHT, value, important, origin);
        } else {
          keepGoing = true;
          break;
        }
      } else if (type == CSSPrimitiveUnit.CSS_NUMBER && value.getFloatValue() > 0) {
        if (fontWeight != null) {
          throw new CSSParseException(LangId.NO_TWICE, -1, "font-weight");
        }

        final IdentValue weight = Conversions.getNumericFontWeight(value.getFloatValue());
        if (weight == null) {
          throw new CSSParseException(LangId.INVALID_FONT_WEIGHT, -1, value.getCssText());
        }

        final PropertyValue replacement =
            new PropertyValueImp(CSSPrimitiveUnit.CSS_IDENT, weight.toString(), weight.toString());
        replacement.setIdentValue(weight);

        fontWeight = new PropertyDeclaration(CSSName.FONT_WEIGHT, replacement, important, origin);
      } else {
        keepGoing = true;
        break;
      }
    }

    if (keepGoing) {
      i.previous();
      PropertyValue value = (PropertyValue) i.next();

      if (value.getPrimitiveTypeN() == CSSPrimitiveUnit.CSS_IDENT) {
        final String lowerCase = value.getStringValue().toLowerCase();
        value = new PropertyValueImp(CSSPrimitiveUnit.CSS_IDENT, lowerCase, lowerCase);
      }

      final PropertyBuilder fontSizeBuilder = CSSName.getPropertyBuilder(CSSName.FONT_SIZE);
      List<PropertyDeclaration> l =
          fontSizeBuilder.buildDeclarations(
              CSSName.FONT_SIZE, Collections.singletonList(value), origin, important, true);

      fontSize = (PropertyDeclaration) l.get(0);

      if (i.hasNext()) {
        value = (PropertyValue) i.next();
        if (value.getOperator() == Token.TK_VIRGULE) {
          final PropertyBuilder lineHeightBuilder = CSSName.getPropertyBuilder(CSSName.LINE_HEIGHT);
          l =
              lineHeightBuilder.buildDeclarations(
                  CSSName.LINE_HEIGHT, Collections.singletonList(value), origin, important, true);
          lineHeight = (PropertyDeclaration) l.get(0);
        } else {
          i.previous();
        }
      }

      if (i.hasNext()) {
        final List<PropertyValue> families = new ArrayList<PropertyValue>();
        while (i.hasNext()) {
          families.add(i.next());
        }
        final PropertyBuilder fontFamilyBuilder = CSSName.getPropertyBuilder(CSSName.FONT_FAMILY);
        l =
            fontFamilyBuilder.buildDeclarations(
                CSSName.FONT_FAMILY, families, origin, important, true);
        fontFamily = (PropertyDeclaration) l.get(0);
      }
    }

    if (fontStyle == null) {
      fontStyle =
          new PropertyDeclaration(
              CSSName.FONT_STYLE, new PropertyValueImp(IdentValue.NORMAL), important, origin);
    }

    if (fontVariant == null) {
      fontVariant =
          new PropertyDeclaration(
              CSSName.FONT_VARIANT, new PropertyValueImp(IdentValue.NORMAL), important, origin);
    }

    if (fontWeight == null) {
      fontWeight =
          new PropertyDeclaration(
              CSSName.FONT_WEIGHT, new PropertyValueImp(IdentValue.NORMAL), important, origin);
    }

    if (fontSize == null) {
      throw new CSSParseException(LangId.FONT_SIZE_REQUIRED, -1);
    }

    if (lineHeight == null) {
      lineHeight =
          new PropertyDeclaration(
              CSSName.LINE_HEIGHT, new PropertyValueImp(IdentValue.NORMAL), important, origin);
    }

    // XXX font-family should be reset too (although does this really make sense?)

    result = new ArrayList<PropertyDeclaration>(ALL.length);
    result.add(fontStyle);
    result.add(fontVariant);
    result.add(fontWeight);
    result.add(fontSize);
    result.add(lineHeight);
    if (fontFamily != null) {
      result.add(fontFamily);
    }

    return result;
  }