Java Code Examples for java.util.EnumMap#containsKey()

The following examples show how to use java.util.EnumMap#containsKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlanetChartData.java    From Astrosoft with GNU General Public License v2.0 6 votes vote down vote up
public static EnumMap<Rasi, List<Planet>> calcPlanetsInRasi(EnumMap<Planet, Integer> planetPosition){
	
	EnumMap<Rasi, List<Planet>> planetsInRasi = new EnumMap<Rasi, List<Planet>>(Rasi.class);
	
	List<Planet> planetList = null;
	
	for (Planet p : Planet.planetsAsc()) {
		Rasi r = Rasi.ofIndex(planetPosition.get(p) - 1);
		
		if (planetsInRasi.containsKey(r)){
			planetList = planetsInRasi.get(r);
			planetList.add(p);
		}else{
			planetList = new ArrayList<Planet>();
			planetList.add(p);
			planetsInRasi.put(r, planetList);
		}	
	}
	
	return planetsInRasi;
}
 
Example 2
Source File: CompileStringsStep.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Scrapes string resource names and values from the list of xml nodes passed and populates {@code
 * stringsMap}, ignoring resource names that are already present in the map.
 *
 * @param stringNodes A list of {@code <string></string>} nodes.
 * @param stringsMap Map from string resource id to its values.
 */
@VisibleForTesting
void scrapeStringNodes(NodeList stringNodes, Map<Integer, EnumMap<Gender, String>> stringsMap) {
  for (int i = 0; i < stringNodes.getLength(); ++i) {
    Element element = (Element) stringNodes.item(i);
    String resourceName = element.getAttribute("name");
    Gender gender = getGender(element);

    Integer resId = getResourceId(resourceName, gender, stringResourceNameToIdMap);
    // Ignore a resource if R.txt does not contain an entry for it.
    if (resId == null) {
      continue;
    }

    EnumMap<Gender, String> genderMap = stringsMap.get(resId);
    if (genderMap == null) {
      genderMap = Maps.newEnumMap(Gender.class);
    } else if (genderMap.containsKey(gender)) { // Ignore a resource if it has already been found
      continue;
    }

    genderMap.put(gender, element.getTextContent());
    stringsMap.put(resId, genderMap);
  }
}
 
Example 3
Source File: DOMBuilder.java    From symja_android_library with GNU General Public License v3.0 6 votes vote down vote up
public void appendSimpleMathElement(Element parentElement, Token token) {
    EnumMap<InterpretationType, Interpretation> interpretationMap = token.getInterpretationMap();
    if (interpretationMap.containsKey(InterpretationType.MATH_IDENTIFIER)) {
        MathIdentifierInterpretation identifierInterp = (MathIdentifierInterpretation) interpretationMap.get(InterpretationType.MATH_IDENTIFIER);
        appendMathMLIdentifierElement(parentElement, identifierInterp.getName());
    }
    else if (interpretationMap.containsKey(InterpretationType.MATH_NUMBER)) {
        MathNumberInterpretation numberInterp = (MathNumberInterpretation) interpretationMap.get(InterpretationType.MATH_NUMBER);
        appendMathMLNumberElement(parentElement, numberInterp.getNumber().toString());
    }
    else if (interpretationMap.containsKey(InterpretationType.MATH_OPERATOR)) {
        MathOperatorInterpretation operatorInterp = (MathOperatorInterpretation) interpretationMap.get(InterpretationType.MATH_OPERATOR);
        appendMathMLOperatorElement(parentElement, operatorInterp.getMathMLOperatorContent());
    }
    else if (interpretationMap.containsKey(InterpretationType.MATH_FUNCTION)) {
        MathFunctionInterpretation functionInterp = (MathFunctionInterpretation) interpretationMap.get(InterpretationType.MATH_FUNCTION);
        appendMathMLIdentifierElement(parentElement, functionInterp.getName());
    }
    else {
        throw new SnuggleLogicException("Unexpected logic branch based on InterpretationMap, which was: " + interpretationMap);
    }
}
 
Example 4
Source File: CompileStringsStep.java    From buck with Apache License 2.0 5 votes vote down vote up
/** Similar to {@code scrapeStringNodes}, but for plurals nodes. */
@VisibleForTesting
void scrapePluralsNodes(
    NodeList pluralNodes,
    Map<Integer, EnumMap<Gender, ImmutableMap<String, String>>> pluralsMap) {

  for (int i = 0; i < pluralNodes.getLength(); ++i) {
    Element element = (Element) pluralNodes.item(i);
    String resourceName = element.getAttribute("name");
    Gender gender = getGender(element);

    Integer resourceId = getResourceId(resourceName, gender, pluralsResourceNameToIdMap);
    // Ignore a resource if R.txt does not contain an entry for it.
    if (resourceId == null) {
      continue;
    }

    EnumMap<Gender, ImmutableMap<String, String>> genderMap = pluralsMap.get(resourceId);
    if (genderMap == null) {
      genderMap = Maps.newEnumMap(Gender.class);
    } else if (genderMap.containsKey(gender)) { // Ignore a resource if it has already been found
      continue;
    }

    ImmutableMap.Builder<String, String> quantityToStringBuilder = ImmutableMap.builder();

    NodeList itemNodes = element.getElementsByTagName("item");
    for (int j = 0; j < itemNodes.getLength(); ++j) {
      Node itemNode = itemNodes.item(j);
      String quantity = itemNode.getAttributes().getNamedItem("quantity").getNodeValue();
      quantityToStringBuilder.put(quantity, itemNode.getTextContent());
    }

    genderMap.put(gender, quantityToStringBuilder.build());
    pluralsMap.put(resourceId, genderMap);
  }
}
 
Example 5
Source File: CompileStringsStep.java    From buck with Apache License 2.0 5 votes vote down vote up
/** Similar to {@code scrapeStringNodes}, but for string array nodes. */
@VisibleForTesting
void scrapeStringArrayNodes(
    NodeList arrayNodes, Map<Integer, EnumMap<Gender, ImmutableList<String>>> arraysMap) {

  for (int i = 0; i < arrayNodes.getLength(); ++i) {
    Element element = (Element) arrayNodes.item(i);
    String resourceName = element.getAttribute("name");
    Gender gender = getGender(element);

    Integer resourceId = getResourceId(resourceName, gender, arrayResourceNameToIdMap);
    // Ignore a resource if R.txt does not contain an entry for it.
    if (resourceId == null) {
      continue;
    }

    EnumMap<Gender, ImmutableList<String>> genderMap = arraysMap.get(resourceId);
    if (genderMap == null) {
      genderMap = Maps.newEnumMap(Gender.class);
    } else if (genderMap.containsKey(gender)) { // Ignore a resource if it has already been found
      continue;
    }

    ImmutableList.Builder<String> arrayValues = ImmutableList.builder();
    NodeList itemNodes = element.getElementsByTagName("item");
    if (itemNodes.getLength() == 0) {
      continue;
    }
    for (int j = 0; j < itemNodes.getLength(); ++j) {
      arrayValues.add(itemNodes.item(j).getTextContent());
    }

    genderMap.put(gender, arrayValues.build());
    arraysMap.put(resourceId, genderMap);
  }
}
 
Example 6
Source File: UniqueServiceFilter.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public List<TrustedServiceWrapper> filter(List<TrustedServiceWrapper> trustServices) {
	TrustedServiceWrapper selectedTrustedService = null;

	if (Utils.collectionSize(trustServices) == 1) {
		selectedTrustedService = trustServices.get(0);
	} else if (Utils.isCollectionNotEmpty(trustServices)) {
		LOG.info("More than one selected trust services");

		EnumMap<CertificateQualification, List<String>> qualificationResults = new EnumMap<>(
				CertificateQualification.class);
		for (TrustedServiceWrapper trustService : trustServices) {
			CertificateQualificationCalculation calculator = new CertificateQualificationCalculation(endEntityCert, trustService);
			CertificateQualification certQualification = calculator.getQualification();
			if (!qualificationResults.containsKey(certQualification)) {
				qualificationResults.put(certQualification, trustService.getServiceNames());
			}
		}

		if (qualificationResults.size() > 1) {
			LOG.warn("Unable to select the trust service ! Several possible conclusions {}", qualificationResults);
		} else {
			LOG.info("All trust services conclude with the same result");
			selectedTrustedService = trustServices.get(0);
		}
	}

	if (selectedTrustedService != null) {
		return Collections.singletonList(selectedTrustedService);
	} else {
		return Collections.emptyList();
	}
}
 
Example 7
Source File: OptionCodec.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public Map<T, Object> decode(ByteBuf body, int version)
{
    EnumMap<T, Object> options = new EnumMap<T, Object>(klass);
    int n = body.readUnsignedShort();
    for (int i = 0; i < n; i++)
    {
        T opt = fromId(body.readUnsignedShort());
        Object value = opt.readValue(body, version);
        if (options.containsKey(opt))
            throw new ProtocolException(String.format("Duplicate option %s in message", opt.name()));
        options.put(opt, value);
    }
    return options;
}
 
Example 8
Source File: FileSourceXML.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Check if all required attributes are present.
 *
 * @param <T>        type of the enumeration describing attributes
 * @param e          the event
 * @param attributes extracted attributes
 * @param required   array of required attributes
 * @throws XMLStreamException if at least one required attribute is not found
 */
protected <T extends Enum<T>> void checkRequiredAttributes(XMLEvent e,
                                                           EnumMap<T, String> attributes, T... required)
        throws XMLStreamException {
    if (required != null) {
        for (int i = 0; i < required.length; i++) {
            if (!attributes.containsKey(required[i]))
                newParseError(e, true, "'%s' attribute is required for <%s> element",
                        required[i].name().toLowerCase(), e.asStartElement().getName().getLocalPart());
        }
    }
}
 
Example 9
Source File: FileSourceGPX.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * <pre>
 * name       : EMAIL
 * attributes : EMAILAttribute
 * structure  :
 * </pre>
 * 
 * @throws IOException
 * @throws XMLStreamException
 */
private String __email() throws IOException, XMLStreamException {
	XMLEvent e;
	EnumMap<EMAILAttribute, String> attributes;
	String email = "";

	e = getNextEvent();
	checkValid(e, XMLEvent.START_ELEMENT, "email");

	attributes = getAttributes(EMAILAttribute.class, e.asStartElement());

	if (!attributes.containsKey(EMAILAttribute.ID)) {
		newParseError(e, false, "attribute 'version' is required");
	} else
		email += attributes.get(EMAILAttribute.ID);

	email += "@";

	if (!attributes.containsKey(EMAILAttribute.DOMAIN)) {
		newParseError(e, false, "attribute 'version' is required");
	} else
		email += attributes.get(EMAILAttribute.DOMAIN);

	e = getNextEvent();
	checkValid(e, XMLEvent.END_ELEMENT, "email");

	return email;
}
 
Example 10
Source File: FileSourceGPX.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * <pre>
 * name       : COPYRIGHT
 * attributes : COPYRIGHTAttribute
 * structure  : YEAR? LICENCE?
 * </pre>
 * 
 * @throws IOException
 * @throws XMLStreamException
 */
private String __copyright() throws IOException, XMLStreamException {
	String copyright;
	XMLEvent e;
	EnumMap<COPYRIGHTAttribute, String> attributes;

	e = getNextEvent();
	checkValid(e, XMLEvent.START_ELEMENT, "copyright");

	attributes = getAttributes(COPYRIGHTAttribute.class, e
			.asStartElement());

	if (!attributes.containsKey(COPYRIGHTAttribute.AUTHOR)) {
		newParseError(e, false, "attribute 'author' is required");
		copyright = "unknown";
	} else
		copyright = attributes.get(COPYRIGHTAttribute.AUTHOR);

	e = getNextEvent();

	if (isEvent(e, XMLEvent.START_ELEMENT, "year")) {
		pushback(e);
		copyright += " " + __year();

		e = getNextEvent();
	}

	if (isEvent(e, XMLEvent.START_ELEMENT, "license")) {
		pushback(e);
		copyright += " " + __license();

		e = getNextEvent();
	}

	checkValid(e, XMLEvent.END_ELEMENT, "copyright");

	return copyright;
}
 
Example 11
Source File: FileSourceGPX.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * <pre>
 * name       : LINK
 * attributes : LINKAttribute
 * structure  : TEXT? TYPE?
 * </pre>
 * 
 * @throws IOException
 * @throws XMLStreamException
 */
private String __link() throws IOException, XMLStreamException {
	String link;
	XMLEvent e;
	EnumMap<LINKAttribute, String> attributes;

	e = getNextEvent();
	checkValid(e, XMLEvent.START_ELEMENT, "link");

	attributes = getAttributes(LINKAttribute.class, e.asStartElement());

	if (!attributes.containsKey(LINKAttribute.HREF)) {
		newParseError(e, false, "attribute 'href' is required");
		link = "unknown";
	} else
		link = attributes.get(LINKAttribute.HREF);

	e = getNextEvent();

	if (isEvent(e, XMLEvent.START_ELEMENT, "text")) {
		pushback(e);
		__text();

		e = getNextEvent();
	}

	if (isEvent(e, XMLEvent.START_ELEMENT, "type")) {
		pushback(e);
		__type();

		e = getNextEvent();
	}

	checkValid(e, XMLEvent.END_ELEMENT, "link");

	return link;
}
 
Example 12
Source File: FileSourceGPX.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * <pre>
 * name       : BOUNDS
 * attributes : BOUNDSAttribute
 * structure  :
 * </pre>
 * 
 * @throws IOException
 * @throws XMLStreamException
 */
private void __bounds() throws IOException, XMLStreamException {
	XMLEvent e;
	EnumMap<BOUNDSAttribute, String> attributes;
	double minlat, maxlat, minlon, maxlon;

	e = getNextEvent();
	checkValid(e, XMLEvent.START_ELEMENT, "bounds");

	attributes = getAttributes(BOUNDSAttribute.class, e
			.asStartElement());

	if (!attributes.containsKey(BOUNDSAttribute.MINLAT)) {
		newParseError(e, false, "attribute 'minlat' is required");
	}

	if (!attributes.containsKey(BOUNDSAttribute.MAXLAT)) {
		newParseError(e, false, "attribute 'maxlat' is required");
	}

	if (!attributes.containsKey(BOUNDSAttribute.MINLON)) {
		newParseError(e, false, "attribute 'minlon' is required");
	}

	if (!attributes.containsKey(BOUNDSAttribute.MAXLON)) {
		newParseError(e, false, "attribute 'maxlon' is required");
	}

	minlat = Double.parseDouble(attributes.get(BOUNDSAttribute.MINLAT));
	maxlat = Double.parseDouble(attributes.get(BOUNDSAttribute.MAXLAT));
	minlon = Double.parseDouble(attributes.get(BOUNDSAttribute.MINLON));
	maxlon = Double.parseDouble(attributes.get(BOUNDSAttribute.MAXLON));

	sendGraphAttributeAdded(sourceId, "gpx.bounds", new double[] {
			minlat, minlon, maxlat, maxlon });

	e = getNextEvent();
	checkValid(e, XMLEvent.END_ELEMENT, "bounds");
}
 
Example 13
Source File: FileSourceGPX.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
/**
 * <pre>
 * name       : GPX
 * attributes : GPXAttribute
 * structure  : METADATA? WPT* RTE* TRK* EXTENSIONS?
 * </pre>
 * 
 * @throws IOException
 * @throws XMLStreamException
 */
private void __gpx() throws IOException, XMLStreamException {
	XMLEvent e;
	EnumMap<GPXAttribute, String> attributes;

	e = getNextEvent();
	checkValid(e, XMLEvent.START_ELEMENT, "gpx");

	attributes = getAttributes(GPXAttribute.class, e.asStartElement());

	if (!attributes.containsKey(GPXAttribute.VERSION)) {
		newParseError(e, false, "attribute 'version' is required");
	} else {
		sendGraphAttributeAdded(sourceId, "gpx.version", attributes
				.get(GPXAttribute.VERSION));
	}

	if (!attributes.containsKey(GPXAttribute.CREATOR)) {
		newParseError(e, false, "attribute 'creator' is required");
	} else {
		sendGraphAttributeAdded(sourceId, "gpx.creator", attributes
				.get(GPXAttribute.CREATOR));
	}

	e = getNextEvent();

	if (isEvent(e, XMLEvent.START_ELEMENT, "metadata")) {
		pushback(e);
		__metadata();

		e = getNextEvent();
	}

	while (isEvent(e, XMLEvent.START_ELEMENT, "wpt")) {
		pushback(e);
		__wpt();

		e = getNextEvent();
	}

	while (isEvent(e, XMLEvent.START_ELEMENT, "rte")) {
		pushback(e);
		__rte();

		e = getNextEvent();
	}

	while (isEvent(e, XMLEvent.START_ELEMENT, "trk")) {
		pushback(e);
		__trk();

		e = getNextEvent();
	}

	if (isEvent(e, XMLEvent.START_ELEMENT, "extensions")) {
		pushback(e);
		__extensions();

		e = getNextEvent();
	}

	checkValid(e, XMLEvent.END_ELEMENT, "gpx");
}
 
Example 14
Source File: Strong.java    From calcite with Apache License 2.0 4 votes vote down vote up
private static Map<SqlKind, Policy> createPolicyMap() {
  EnumMap<SqlKind, Policy> map = new EnumMap<>(SqlKind.class);

  map.put(SqlKind.INPUT_REF, Policy.AS_IS);
  map.put(SqlKind.LOCAL_REF, Policy.AS_IS);
  map.put(SqlKind.DYNAMIC_PARAM, Policy.AS_IS);
  map.put(SqlKind.OTHER_FUNCTION, Policy.AS_IS);

  // The following types of expressions could potentially be custom.
  map.put(SqlKind.CASE, Policy.AS_IS);
  map.put(SqlKind.DECODE, Policy.AS_IS);
  // NULLIF(1, NULL) yields 1, but NULLIF(1, 1) yields NULL
  map.put(SqlKind.NULLIF, Policy.AS_IS);
  // COALESCE(NULL, 2) yields 2
  map.put(SqlKind.COALESCE, Policy.AS_IS);
  map.put(SqlKind.NVL, Policy.AS_IS);
  // FALSE AND NULL yields FALSE
  // TRUE AND NULL yields NULL
  map.put(SqlKind.AND, Policy.AS_IS);
  // TRUE OR NULL yields TRUE
  // FALSE OR NULL yields NULL
  map.put(SqlKind.OR, Policy.AS_IS);

  // Expression types with custom handlers.
  map.put(SqlKind.LITERAL, Policy.CUSTOM);

  map.put(SqlKind.EXISTS, Policy.NOT_NULL);
  map.put(SqlKind.IS_DISTINCT_FROM, Policy.NOT_NULL);
  map.put(SqlKind.IS_NOT_DISTINCT_FROM, Policy.NOT_NULL);
  map.put(SqlKind.IS_NULL, Policy.NOT_NULL);
  map.put(SqlKind.IS_NOT_NULL, Policy.NOT_NULL);
  map.put(SqlKind.IS_TRUE, Policy.NOT_NULL);
  map.put(SqlKind.IS_NOT_TRUE, Policy.NOT_NULL);
  map.put(SqlKind.IS_FALSE, Policy.NOT_NULL);
  map.put(SqlKind.IS_NOT_FALSE, Policy.NOT_NULL);

  map.put(SqlKind.NOT, Policy.ANY);
  map.put(SqlKind.EQUALS, Policy.ANY);
  map.put(SqlKind.NOT_EQUALS, Policy.ANY);
  map.put(SqlKind.LESS_THAN, Policy.ANY);
  map.put(SqlKind.LESS_THAN_OR_EQUAL, Policy.ANY);
  map.put(SqlKind.GREATER_THAN, Policy.ANY);
  map.put(SqlKind.GREATER_THAN_OR_EQUAL, Policy.ANY);
  map.put(SqlKind.LIKE, Policy.ANY);
  map.put(SqlKind.SIMILAR, Policy.ANY);
  map.put(SqlKind.PLUS, Policy.ANY);
  map.put(SqlKind.PLUS_PREFIX, Policy.ANY);
  map.put(SqlKind.MINUS, Policy.ANY);
  map.put(SqlKind.MINUS_PREFIX, Policy.ANY);
  map.put(SqlKind.TIMES, Policy.ANY);
  map.put(SqlKind.DIVIDE, Policy.ANY);
  map.put(SqlKind.CAST, Policy.ANY);
  map.put(SqlKind.REINTERPRET, Policy.ANY);
  map.put(SqlKind.TRIM, Policy.ANY);
  map.put(SqlKind.LTRIM, Policy.ANY);
  map.put(SqlKind.RTRIM, Policy.ANY);
  map.put(SqlKind.CEIL, Policy.ANY);
  map.put(SqlKind.FLOOR, Policy.ANY);
  map.put(SqlKind.EXTRACT, Policy.ANY);
  map.put(SqlKind.GREATEST, Policy.ANY);
  map.put(SqlKind.LEAST, Policy.ANY);
  map.put(SqlKind.TIMESTAMP_ADD, Policy.ANY);
  map.put(SqlKind.TIMESTAMP_DIFF, Policy.ANY);
  map.put(SqlKind.ITEM, Policy.ANY);

  // Assume that any other expressions cannot be simplified.
  for (SqlKind k
      : Iterables.concat(SqlKind.EXPRESSION, SqlKind.AGGREGATE)) {
    if (!map.containsKey(k)) {
      map.put(k, Policy.AS_IS);
    }
  }
  return map;
}
 
Example 15
Source File: Strong.java    From Bats with Apache License 2.0 4 votes vote down vote up
private static Map<SqlKind, Policy> createPolicyMap() {
  EnumMap<SqlKind, Policy> map = new EnumMap<>(SqlKind.class);

  map.put(SqlKind.INPUT_REF, Policy.AS_IS);
  map.put(SqlKind.LOCAL_REF, Policy.AS_IS);
  map.put(SqlKind.DYNAMIC_PARAM, Policy.AS_IS);
  map.put(SqlKind.OTHER_FUNCTION, Policy.AS_IS);

  // The following types of expressions could potentially be custom.
  map.put(SqlKind.CASE, Policy.AS_IS);
  map.put(SqlKind.DECODE, Policy.AS_IS);
  // NULLIF(1, NULL) yields 1, but NULLIF(1, 1) yields NULL
  map.put(SqlKind.NULLIF, Policy.AS_IS);
  // COALESCE(NULL, 2) yields 2
  map.put(SqlKind.COALESCE, Policy.AS_IS);
  map.put(SqlKind.NVL, Policy.AS_IS);
  // FALSE AND NULL yields FALSE
  // TRUE AND NULL yields NULL
  map.put(SqlKind.AND, Policy.AS_IS);
  // TRUE OR NULL yields TRUE
  // FALSE OR NULL yields NULL
  map.put(SqlKind.OR, Policy.AS_IS);

  // Expression types with custom handlers.
  map.put(SqlKind.LITERAL, Policy.CUSTOM);

  map.put(SqlKind.EXISTS, Policy.NOT_NULL);
  map.put(SqlKind.IS_DISTINCT_FROM, Policy.NOT_NULL);
  map.put(SqlKind.IS_NOT_DISTINCT_FROM, Policy.NOT_NULL);
  map.put(SqlKind.IS_NULL, Policy.NOT_NULL);
  map.put(SqlKind.IS_NOT_NULL, Policy.NOT_NULL);
  map.put(SqlKind.IS_TRUE, Policy.NOT_NULL);
  map.put(SqlKind.IS_NOT_TRUE, Policy.NOT_NULL);
  map.put(SqlKind.IS_FALSE, Policy.NOT_NULL);
  map.put(SqlKind.IS_NOT_FALSE, Policy.NOT_NULL);

  map.put(SqlKind.NOT, Policy.ANY);
  map.put(SqlKind.EQUALS, Policy.ANY);
  map.put(SqlKind.NOT_EQUALS, Policy.ANY);
  map.put(SqlKind.LESS_THAN, Policy.ANY);
  map.put(SqlKind.LESS_THAN_OR_EQUAL, Policy.ANY);
  map.put(SqlKind.GREATER_THAN, Policy.ANY);
  map.put(SqlKind.GREATER_THAN_OR_EQUAL, Policy.ANY);
  map.put(SqlKind.LIKE, Policy.ANY);
  map.put(SqlKind.SIMILAR, Policy.ANY);
  map.put(SqlKind.PLUS, Policy.ANY);
  map.put(SqlKind.PLUS_PREFIX, Policy.ANY);
  map.put(SqlKind.MINUS, Policy.ANY);
  map.put(SqlKind.MINUS_PREFIX, Policy.ANY);
  map.put(SqlKind.TIMES, Policy.ANY);
  map.put(SqlKind.DIVIDE, Policy.ANY);
  map.put(SqlKind.CAST, Policy.ANY);
  map.put(SqlKind.REINTERPRET, Policy.ANY);
  map.put(SqlKind.TRIM, Policy.ANY);
  map.put(SqlKind.LTRIM, Policy.ANY);
  map.put(SqlKind.RTRIM, Policy.ANY);
  map.put(SqlKind.CEIL, Policy.ANY);
  map.put(SqlKind.FLOOR, Policy.ANY);
  map.put(SqlKind.EXTRACT, Policy.ANY);
  map.put(SqlKind.GREATEST, Policy.ANY);
  map.put(SqlKind.LEAST, Policy.ANY);
  map.put(SqlKind.TIMESTAMP_ADD, Policy.ANY);
  map.put(SqlKind.TIMESTAMP_DIFF, Policy.ANY);

  // Assume that any other expressions cannot be simplified.
  for (SqlKind k
      : Iterables.concat(SqlKind.EXPRESSION, SqlKind.AGGREGATE)) {
    if (!map.containsKey(k)) {
      map.put(k, Policy.AS_IS);
    }
  }
  return map;
}
 
Example 16
Source File: FileSourceGEXF.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
/**
 * <pre>
 * name 		: NODESHAPE
 * attributes 	: NODESHAPEAttributes { VALUE!, URI, START, STARTOPEN, END, ENDOPEN }
 * structure 	: SPELLS ?
 * </pre>
 */
private void __node_shape(final String nodeId) throws IOException, XMLStreamException {
	XMLEvent e;
	EnumMap<NODESHAPEAttribute, String> attributes;
	NodeShapeType type = null;
	String uri;

	e = getNextEvent();
	checkValid(e, XMLEvent.START_ELEMENT, "shape");

	attributes = getAttributes(NODESHAPEAttribute.class, e.asStartElement());

	checkRequiredAttributes(e, attributes, NODESHAPEAttribute.VALUE);

	try {
		type = NodeShapeType.valueOf(toConstantName(attributes.get(NODESHAPEAttribute.VALUE)));
	} catch (final IllegalArgumentException ex) {
		newParseError(e, true, "'value' should be one of 'disc', 'diamond', 'triangle', 'square' or 'image'");
	}

	switch (type) {
		case IMAGE:
			if (!attributes.containsKey(NODESHAPEAttribute.URI)) {
				newParseError(e, true, "'image' shape type needs 'uri' attribute");
			}

			uri = attributes.get(NODESHAPEAttribute.URI);
			sendNodeAttributeAdded(sourceId, nodeId, "ui.style",
					String.format("fill-mode: image-scaled; fill-image: url('%s');", uri));

			break;
		default:
			sendNodeAttributeAdded(sourceId, nodeId, "ui.style",
					String.format("shape: %s;", type.name().toLowerCase()));
	}

	e = getNextEvent();

	if (isEvent(e, XMLEvent.START_ELEMENT, "spells")) {
		pushback(e);

		__spells();
		e = getNextEvent();
	}

	checkValid(e, XMLEvent.END_ELEMENT, "shape");
}
 
Example 17
Source File: FileSourceGEXF.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
/**
 * <pre>
 * name 		: NODE
 * attributes 	: NODEAttribute { 'pid', 'id', 'label', 'start', 'startopen', 'end', 'endopen' }
 * structure 	: ( ATTVALUES | SPELLS | ( NODES | EDGES ) | PARENTS | ( COLOR | POSITION | SIZE | NODESHAPE ) ) *
 * </pre>
 */
private void __node() throws IOException, XMLStreamException {
	XMLEvent e;
	EnumMap<NODEAttribute, String> attributes;
	String id;
	final HashSet<String> defined = new HashSet<>();

	e = getNextEvent();
	checkValid(e, XMLEvent.START_ELEMENT, "node");

	attributes = getAttributes(NODEAttribute.class, e.asStartElement());

	checkRequiredAttributes(e, attributes, NODEAttribute.ID);

	id = attributes.get(NODEAttribute.ID);
	sendNodeAdded(sourceId, id);

	if (attributes.containsKey(NODEAttribute.LABEL)) {
		sendNodeAttributeAdded(sourceId, id, "label", attributes.get(NODEAttribute.LABEL));
	}

	e = getNextEvent();

	while (!isEvent(e, XMLEvent.END_ELEMENT, "node")) {
		try {
			final Balise b = Balise.valueOf(toConstantName(e.asStartElement().getName().getLocalPart()));

			pushback(e);

			switch (b) {
				case ATTVALUES:
					defined.addAll(__attvalues(ClassType.NODE, id));
					break;
				case COLOR:
					__color(ClassType.NODE, id);
					break;
				case POSITION:
					__position(id);
					break;
				case SIZE:
					__size(id);
					break;
				case SHAPE:
					__node_shape(id);
					break;
				case SPELLS:
					__spells();
					break;
				case NODES:
					__nodes();
					break;
				case EDGES:
					__edges();
					break;
				case PARENTS:
					__parents(id);
					break;
				default:
					newParseError(e, true,
							"attribute children should be one of 'attvalues', 'color', 'position', 'size', shape', 'spells', 'nodes, 'edges' or 'parents'");
			}
		} catch (final IllegalArgumentException ex) {
			newParseError(e, true, "unknown element '%s'", e.asStartElement().getName().getLocalPart());
		}

		e = getNextEvent();
	}

	for (final Attribute theAttribute : nodeAttributesDefinition.values()) {
		if (!defined.contains(theAttribute.id)) {
			sendNodeAttributeAdded(sourceId, id, theAttribute.title, theAttribute.def);
		}
	}

	checkValid(e, XMLEvent.END_ELEMENT, "node");
}
 
Example 18
Source File: AclTransformation.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Calculates mask entries required for the ACL.  Mask calculation is performed
 * separately for each scope: access and default.  This method is responsible
 * for handling the following cases of mask calculation:
 * 1. Throws an exception if the caller attempts to remove the mask entry of an
 *   existing ACL that requires it.  If the ACL has any named entries, then a
 *   mask entry is required.
 * 2. If the caller supplied a mask in the ACL spec, use it.
 * 3. If the caller did not supply a mask, but there are ACL entry changes in
 *   this scope, then automatically calculate a new mask.  The permissions of
 *   the new mask are the union of the permissions on the group entry and all
 *   named entries.
 *
 * @param aclBuilder ArrayList<AclEntry> containing entries to build
 * @param providedMask EnumMap<AclEntryScope, AclEntry> mapping each scope to
 *   the mask entry that was provided for that scope (if provided)
 * @param maskDirty EnumSet<AclEntryScope> which contains a scope if the mask
 *   entry is dirty (added or deleted) in that scope
 * @param scopeDirty EnumSet<AclEntryScope> which contains a scope if any entry
 *   is dirty (added or deleted) in that scope
 * @throws AclException if validation fails
 */
private static void calculateMasks(List<AclEntry> aclBuilder,
    EnumMap<AclEntryScope, AclEntry> providedMask,
    EnumSet<AclEntryScope> maskDirty, EnumSet<AclEntryScope> scopeDirty)
    throws AclException {
  EnumSet<AclEntryScope> scopeFound = EnumSet.noneOf(AclEntryScope.class);
  EnumMap<AclEntryScope, FsAction> unionPerms =
    Maps.newEnumMap(AclEntryScope.class);
  EnumSet<AclEntryScope> maskNeeded = EnumSet.noneOf(AclEntryScope.class);
  // Determine which scopes are present, which scopes need a mask, and the
  // union of group class permissions in each scope.
  for (AclEntry entry: aclBuilder) {
    scopeFound.add(entry.getScope());
    if (entry.getType() == GROUP || entry.getName() != null) {
      FsAction scopeUnionPerms = Objects.firstNonNull(
        unionPerms.get(entry.getScope()), FsAction.NONE);
      unionPerms.put(entry.getScope(),
        scopeUnionPerms.or(entry.getPermission()));
    }
    if (entry.getName() != null) {
      maskNeeded.add(entry.getScope());
    }
  }
  // Add mask entry if needed in each scope.
  for (AclEntryScope scope: scopeFound) {
    if (!providedMask.containsKey(scope) && maskNeeded.contains(scope) &&
        maskDirty.contains(scope)) {
      // Caller explicitly removed mask entry, but it's required.
      throw new AclException(
        "Invalid ACL: mask is required and cannot be deleted.");
    } else if (providedMask.containsKey(scope) &&
        (!scopeDirty.contains(scope) || maskDirty.contains(scope))) {
      // Caller explicitly provided new mask, or we are preserving the existing
      // mask in an unchanged scope.
      aclBuilder.add(providedMask.get(scope));
    } else if (maskNeeded.contains(scope) || providedMask.containsKey(scope)) {
      // Otherwise, if there are maskable entries present, or the ACL
      // previously had a mask, then recalculate a mask automatically.
      aclBuilder.add(new AclEntry.Builder()
        .setScope(scope)
        .setType(MASK)
        .setPermission(unionPerms.get(scope))
        .build());
    }
  }
}
 
Example 19
Source File: RequestPreviewItem.java    From L2jOrg with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void runImpl() {
    if (_items == null) {
        return;
    }

    // Get the current player and return if null
    final Player activeChar = client.getPlayer();
    if (activeChar == null) {
        return;
    }

    if (!client.getFloodProtectors().getTransaction().tryPerformAction("buy")) {
        activeChar.sendMessage("You are buying too fast.");
        return;
    }

    // If Alternate rule Karma punishment is set to true, forbid Wear to player with Karma
    if (!Config.ALT_GAME_KARMA_PLAYER_CAN_SHOP && (activeChar.getReputation() < 0)) {
        return;
    }

    // Check current target of the player and the INTERACTION_DISTANCE
    final WorldObject target = activeChar.getTarget();
    // No target (i.e. GM Shop)
    if (!activeChar.isGM() && (!((target instanceof Merchant)) // Target not a merchant
            || !isInsideRadius2D(activeChar, target, Npc.INTERACTION_DISTANCE) // Distance is too far
    )) {
        return;
    }

    if ((_count < 1) || (_listId >= 4000000)) {
        client.sendPacket(ActionFailed.STATIC_PACKET);
        return;
    }

    // Get the current merchant targeted by the player
    final Merchant merchant = (target instanceof Merchant) ? (Merchant) target : null;
    if (merchant == null) {
        LOGGER.warn("Null merchant!");
        return;
    }

    final ProductList buyList = BuyListData.getInstance().getBuyList(_listId);
    if (buyList == null) {
        GameUtils.handleIllegalPlayerAction(activeChar, "Warning!! Character " + activeChar.getName() + " of account " + activeChar.getAccountName() + " sent a false BuyList list_id " + _listId);
        return;
    }

    long totalPrice = 0;
    final EnumMap<InventorySlot, Integer> items = new EnumMap<>(InventorySlot.class);

    for (int i = 0; i < _count; i++) {
        final int itemId = _items[i];

        final Product product = buyList.getProductByItemId(itemId);
        if (product == null) {
            GameUtils.handleIllegalPlayerAction(activeChar, "Warning!! Character " + activeChar.getName() + " of account " + activeChar.getAccountName() + " sent a false BuyList list_id " + _listId + " and item_id " + itemId);
            return;
        }

        var slot = product.getBodyPart().slot();
        if (isNull(slot)) {
            continue;
        }

        if (items.containsKey(slot)) {
            activeChar.sendPacket(SystemMessageId.YOU_CAN_NOT_TRY_THOSE_ITEMS_ON_AT_THE_SAME_TIME);
            return;
        }

        items.put(slot, itemId);
        totalPrice += Config.WEAR_PRICE;
        if (totalPrice > Inventory.MAX_ADENA) {
            GameUtils.handleIllegalPlayerAction(activeChar, "Warning!! Character " + activeChar.getName() + " of account " + activeChar.getAccountName() + " tried to purchase over " + Inventory.MAX_ADENA + " adena worth of goods.");
            return;
        }
    }

    // Charge buyer and add tax to castle treasury if not owned by npc clan because a Try On is not Free
    if ((totalPrice < 0) || !activeChar.reduceAdena("Wear", totalPrice, activeChar.getLastFolkNPC(), true)) {
        activeChar.sendPacket(SystemMessageId.YOU_DO_NOT_HAVE_ENOUGH_ADENA_POPUP);
        return;
    }

    if (!items.isEmpty()) {
        activeChar.sendPacket(new ShopPreviewInfo(items));
        // Schedule task
        ThreadPool.schedule(new RemoveWearItemsTask(activeChar), Config.WEAR_DELAY * 1000);
    }
}
 
Example 20
Source File: Strong.java    From Quicksql with MIT License 4 votes vote down vote up
private static Map<SqlKind, Policy> createPolicyMap() {
  EnumMap<SqlKind, Policy> map = new EnumMap<>(SqlKind.class);

  map.put(SqlKind.INPUT_REF, Policy.AS_IS);
  map.put(SqlKind.LOCAL_REF, Policy.AS_IS);
  map.put(SqlKind.DYNAMIC_PARAM, Policy.AS_IS);
  map.put(SqlKind.OTHER_FUNCTION, Policy.AS_IS);

  // The following types of expressions could potentially be custom.
  map.put(SqlKind.CASE, Policy.AS_IS);
  map.put(SqlKind.DECODE, Policy.AS_IS);
  // NULLIF(1, NULL) yields 1, but NULLIF(1, 1) yields NULL
  map.put(SqlKind.NULLIF, Policy.AS_IS);
  // COALESCE(NULL, 2) yields 2
  map.put(SqlKind.COALESCE, Policy.AS_IS);
  map.put(SqlKind.NVL, Policy.AS_IS);
  // FALSE AND NULL yields FALSE
  // TRUE AND NULL yields NULL
  map.put(SqlKind.AND, Policy.AS_IS);
  // TRUE OR NULL yields TRUE
  // FALSE OR NULL yields NULL
  map.put(SqlKind.OR, Policy.AS_IS);

  // Expression types with custom handlers.
  map.put(SqlKind.LITERAL, Policy.CUSTOM);

  map.put(SqlKind.EXISTS, Policy.NOT_NULL);
  map.put(SqlKind.IS_DISTINCT_FROM, Policy.NOT_NULL);
  map.put(SqlKind.IS_NOT_DISTINCT_FROM, Policy.NOT_NULL);
  map.put(SqlKind.IS_NULL, Policy.NOT_NULL);
  map.put(SqlKind.IS_NOT_NULL, Policy.NOT_NULL);
  map.put(SqlKind.IS_TRUE, Policy.NOT_NULL);
  map.put(SqlKind.IS_NOT_TRUE, Policy.NOT_NULL);
  map.put(SqlKind.IS_FALSE, Policy.NOT_NULL);
  map.put(SqlKind.IS_NOT_FALSE, Policy.NOT_NULL);

  map.put(SqlKind.NOT, Policy.ANY);
  map.put(SqlKind.EQUALS, Policy.ANY);
  map.put(SqlKind.NOT_EQUALS, Policy.ANY);
  map.put(SqlKind.LESS_THAN, Policy.ANY);
  map.put(SqlKind.LESS_THAN_OR_EQUAL, Policy.ANY);
  map.put(SqlKind.GREATER_THAN, Policy.ANY);
  map.put(SqlKind.GREATER_THAN_OR_EQUAL, Policy.ANY);
  map.put(SqlKind.LIKE, Policy.ANY);
  map.put(SqlKind.SIMILAR, Policy.ANY);
  map.put(SqlKind.PLUS, Policy.ANY);
  map.put(SqlKind.PLUS_PREFIX, Policy.ANY);
  map.put(SqlKind.MINUS, Policy.ANY);
  map.put(SqlKind.MINUS_PREFIX, Policy.ANY);
  map.put(SqlKind.TIMES, Policy.ANY);
  map.put(SqlKind.DIVIDE, Policy.ANY);
  map.put(SqlKind.CAST, Policy.ANY);
  map.put(SqlKind.REINTERPRET, Policy.ANY);
  map.put(SqlKind.TRIM, Policy.ANY);
  map.put(SqlKind.LTRIM, Policy.ANY);
  map.put(SqlKind.RTRIM, Policy.ANY);
  map.put(SqlKind.CEIL, Policy.ANY);
  map.put(SqlKind.FLOOR, Policy.ANY);
  map.put(SqlKind.EXTRACT, Policy.ANY);
  map.put(SqlKind.GREATEST, Policy.ANY);
  map.put(SqlKind.LEAST, Policy.ANY);
  map.put(SqlKind.TIMESTAMP_ADD, Policy.ANY);
  map.put(SqlKind.TIMESTAMP_DIFF, Policy.ANY);

  // Assume that any other expressions cannot be simplified.
  for (SqlKind k
      : Iterables.concat(SqlKind.EXPRESSION, SqlKind.AGGREGATE)) {
    if (!map.containsKey(k)) {
      map.put(k, Policy.AS_IS);
    }
  }
  return map;
}