GlueGen: src/java/com/jogamp/gluegen/cgram/types/AliasedSymbol.java Source File

GlueGen v2.6.0-rc-20250706 GlueGen, Native Binding Generator for Java™ (public API).

AliasedSymbol.java
Go to the documentation of this file.
1/**
2 * Copyright 2015 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28 package com.jogamp.gluegen.cgram.types;
29
30import java.util.HashSet;
31import java.util.Set;
32
33/**
34 * Supports symbol aliasing, i.e. renaming,
35 * while preserving all its original names, i.e. aliases.
36 */
37 public interface AliasedSymbol {
38 /**
39 * Rename this symbol with the given {@code newName} if not equal {@link #getName() current-name}.
40 * <p>
41 * Before renaming the {@link #getName() current-name} will be added
42 * to the list of {@link #getAliasedNames() aliases}.
43 * while the given {@code newName} will be removed.
44 * </p>
45 * <p>
46 * Operation will be ignored if {@code newName} is {@code null}.
47 * </p>
48 * @param newName the new {@link #getName() current-name}, maybe {@code null}
49 */
50 void rename(final String newName);
51 /**
52 * Add the given {@code origName} to the list of {@link #getAliasedNames() aliases}
53 * if not equal {@link #getName() current-name}.
54 * <p>
55 * Operation will be ignored if {@code newName} is {@code null}.
56 * </p>
57 * @param origName the new alias to be added, maybe {@code null}
58 */
59 void addAliasedName(final String origName);
60 /**
61 *
62 * Returns {@code true} if this symbol has aliases, i.e. either being {@link #rename(String) renamed}
63 * or {@link #addAliasedName(String) aliases-added}.
64 * <p>
65 * Otherwise {@code false} is being returned.
66 * </p>
67 */
68 boolean hasAliases();
69 /**
70 * Return all aliases for this symbol, i.e. original names, for this symbol.
71 * <p>
72 * Inclusive {@link #getOrigName() original-name}, if {@link #rename(String) renamed},
73 * </p>
74 * <p>
75 * Exclusive {@link #getName() current-name}.
76 * </p>
77 * <p>
78 * May return {@code null} or a zero sized {@link Set} for no aliases.
79 * </p>
80 */
81 Set<String> getAliasedNames();
82 /**
83 * Return the original-name as set at creation.
84 */
85 String getOrigName();
86 /**
87 * Return the current-name, which is the last {@link #rename(String) renamed-name} if issued,
88 * or the {@link #getOrigName() original-name}.
89 */
90 String getName();
91 /**
92 * Return this object's {@link #toString()} wrapped w/ the {@link #getName() current-name}
93 * and all {@link #getAliasedNames() aliases}.
94 */
95 String getAliasedString();
96
97 public static class AliasedSymbolImpl implements AliasedSymbol {
98 private final String origName;
99 private final HashSet<String> aliasedNames;
100 private String name;
101
102 public AliasedSymbolImpl(final String origName) {
103 if( null == origName ) {
104 throw new IllegalArgumentException("Null origName not allowed");
105 }
106 this.origName = origName;
107 this.aliasedNames=new HashSet<String>();
108 this.name = origName;
109 }
110 public AliasedSymbolImpl(final AliasedSymbolImpl o) {
111 this.origName = o.origName;
112 this.aliasedNames = new HashSet<String>(o.aliasedNames);
113 this.name = o.name;
114 }
115 @Override
116 public void rename(final String newName) {
117 if( null != newName && !name.equals(newName) ) {
118 aliasedNames.add(name);
119 aliasedNames.remove(newName);
120 name = newName;
121 }
122 }
123 @Override
124 public void addAliasedName(final String origName) {
125 if( null != origName && !name.equals(origName) ) {
126 aliasedNames.add(origName);
127 }
128 }
129 @Override
130 public boolean hasAliases() {
131 return aliasedNames.size() > 0;
132 }
133 @Override
134 public Set<String> getAliasedNames() {
135 return aliasedNames;
136 }
137 @Override
138 public String getOrigName() {
139 return origName;
140 }
141 @Override
142 public String getName() {
143 return name;
144 }
145 @Override
146 public String getAliasedString() {
147 return "["+name+", aliases "+aliasedNames.toString()+", "+toString()+"]";
148 }
149 }
150 public static class NoneAliasedSymbol implements AliasedSymbol {
151 private final String name;
152
153 public NoneAliasedSymbol(final String origName) {
154 this.name = origName;
155 }
156 @Override
157 public void rename(final String newName) {
158 throw new UnsupportedOperationException();
159 }
160 @Override
161 public void addAliasedName(final String origName) {
162 throw new UnsupportedOperationException();
163 }
164 @Override
165 public boolean hasAliases() {
166 return false;
167 }
168 @Override
169 public Set<String> getAliasedNames() {
170 return null;
171 }
172 @Override
173 public String getOrigName() {
174 return name;
175 }
176 @Override
177 public String getName() {
178 return name;
179 }
180 @Override
181 public String getAliasedString() {
182 return toString();
183 }
184 }
185}
com.jogamp.gluegen.cgram.types.AliasedSymbol.AliasedSymbolImpl
Definition: AliasedSymbol.java:97
com.jogamp.gluegen.cgram.types.AliasedSymbol.AliasedSymbolImpl.getAliasedNames
Set< String > getAliasedNames()
Return all aliases for this symbol, i.e.
Definition: AliasedSymbol.java:134
com.jogamp.gluegen.cgram.types.AliasedSymbol.AliasedSymbolImpl.AliasedSymbolImpl
AliasedSymbolImpl(final AliasedSymbolImpl o)
Definition: AliasedSymbol.java:110
com.jogamp.gluegen.cgram.types.AliasedSymbol.AliasedSymbolImpl.rename
void rename(final String newName)
Rename this symbol with the given newName if not equal current-name.
Definition: AliasedSymbol.java:116
com.jogamp.gluegen.cgram.types.AliasedSymbol.AliasedSymbolImpl.getName
String getName()
Return the current-name, which is the last renamed-name if issued, or the original-name.
Definition: AliasedSymbol.java:142
com.jogamp.gluegen.cgram.types.AliasedSymbol.AliasedSymbolImpl.hasAliases
boolean hasAliases()
Returns true if this symbol has aliases, i.e.
Definition: AliasedSymbol.java:130
com.jogamp.gluegen.cgram.types.AliasedSymbol.AliasedSymbolImpl.getOrigName
String getOrigName()
Return the original-name as set at creation.
Definition: AliasedSymbol.java:138
com.jogamp.gluegen.cgram.types.AliasedSymbol.AliasedSymbolImpl.addAliasedName
void addAliasedName(final String origName)
Add the given origName to the list of aliases if not equal current-name.
Definition: AliasedSymbol.java:124
com.jogamp.gluegen.cgram.types.AliasedSymbol.AliasedSymbolImpl.getAliasedString
String getAliasedString()
Return this object's toString() wrapped w/ the current-name and all aliases.
Definition: AliasedSymbol.java:146
com.jogamp.gluegen.cgram.types.AliasedSymbol.AliasedSymbolImpl.AliasedSymbolImpl
AliasedSymbolImpl(final String origName)
Definition: AliasedSymbol.java:102
com.jogamp.gluegen.cgram.types.AliasedSymbol.NoneAliasedSymbol
Definition: AliasedSymbol.java:150
com.jogamp.gluegen.cgram.types.AliasedSymbol.NoneAliasedSymbol.hasAliases
boolean hasAliases()
Returns true if this symbol has aliases, i.e.
Definition: AliasedSymbol.java:165
com.jogamp.gluegen.cgram.types.AliasedSymbol.NoneAliasedSymbol.NoneAliasedSymbol
NoneAliasedSymbol(final String origName)
Definition: AliasedSymbol.java:153
com.jogamp.gluegen.cgram.types.AliasedSymbol.NoneAliasedSymbol.getOrigName
String getOrigName()
Return the original-name as set at creation.
Definition: AliasedSymbol.java:173
com.jogamp.gluegen.cgram.types.AliasedSymbol.NoneAliasedSymbol.addAliasedName
void addAliasedName(final String origName)
Add the given origName to the list of aliases if not equal current-name.
Definition: AliasedSymbol.java:161
com.jogamp.gluegen.cgram.types.AliasedSymbol.NoneAliasedSymbol.getAliasedString
String getAliasedString()
Return this object's toString() wrapped w/ the current-name and all aliases.
Definition: AliasedSymbol.java:181
com.jogamp.gluegen.cgram.types.AliasedSymbol.NoneAliasedSymbol.rename
void rename(final String newName)
Rename this symbol with the given newName if not equal current-name.
Definition: AliasedSymbol.java:157
com.jogamp.gluegen.cgram.types.AliasedSymbol.NoneAliasedSymbol.getName
String getName()
Return the current-name, which is the last renamed-name if issued, or the original-name.
Definition: AliasedSymbol.java:177
com.jogamp.gluegen.cgram.types.AliasedSymbol.NoneAliasedSymbol.getAliasedNames
Set< String > getAliasedNames()
Return all aliases for this symbol, i.e.
Definition: AliasedSymbol.java:169
com.jogamp.gluegen.cgram.types.AliasedSymbol
Supports symbol aliasing, i.e.
Definition: AliasedSymbol.java:37
com.jogamp.gluegen.cgram.types.AliasedSymbol.getAliasedString
String getAliasedString()
Return this object's toString() wrapped w/ the current-name and all aliases.
com.jogamp.gluegen.cgram.types.AliasedSymbol.getOrigName
String getOrigName()
Return the original-name as set at creation.
com.jogamp.gluegen.cgram.types.AliasedSymbol.getAliasedNames
Set< String > getAliasedNames()
Return all aliases for this symbol, i.e.
com.jogamp.gluegen.cgram.types.AliasedSymbol.hasAliases
boolean hasAliases()
Returns true if this symbol has aliases, i.e.
com.jogamp.gluegen.cgram.types.AliasedSymbol.addAliasedName
void addAliasedName(final String origName)
Add the given origName to the list of aliases if not equal current-name.
com.jogamp.gluegen.cgram.types.AliasedSymbol.rename
void rename(final String newName)
Rename this symbol with the given newName if not equal current-name.
com.jogamp.gluegen.cgram.types.AliasedSymbol.getName
String getName()
Return the current-name, which is the last renamed-name if issued, or the original-name.